日本免费全黄少妇一区二区三区-高清无码一区二区三区四区-欧美中文字幕日韩在线观看-国产福利诱惑在线网站-国产中文字幕一区在线-亚洲欧美精品日韩一区-久久国产精品国产精品国产-国产精久久久久久一区二区三区-欧美亚洲国产精品久久久久

FreeBSD啟動(dòng)扇區(qū)代碼分析

FreeBSD完整的內(nèi)核代碼在FreeBSD的“/sys目錄下 。其中,F(xiàn)reeBSD 的 Boot Manager代碼是 sysbooti386boot0boot0.s,它是FreeBSD自帶的Boot Manager,其功能雖然不如Linux的lilo和Grub功能強(qiáng)大,但它只需按一個(gè)鍵就可以引導(dǎo),界面直觀 。小小的512字節(jié),可以給你一個(gè)簡(jiǎn)單明了的啟動(dòng)選擇界面,還能記住你上次的選擇 。以下,就對(duì)此代碼進(jìn)行詳細(xì)分析:
當(dāng)我們打開計(jì)算機(jī)電源時(shí),計(jì)算機(jī)嘰嘰嘎嘎進(jìn)行設(shè)備和內(nèi)存檢測(cè)過后就讀取硬盤或者軟盤的引導(dǎo)扇區(qū),這個(gè)扇區(qū)只有512字節(jié),顯然這512字節(jié)不能夠有多大作用,這512字節(jié)的代碼被BIOS放在地址從0x0000:0x7c00開始處 。然后直接跳轉(zhuǎn)到0x0000:0x7c00處去執(zhí)行 。以上工作是BIOS 干的,你什么也不用作 。操作系統(tǒng)需要通過這個(gè)引導(dǎo)扇區(qū)代碼再裝載操作系統(tǒng)的其他部分 。在還沒有跳轉(zhuǎn)到這段代碼之前,也就是BIOS把磁盤的引導(dǎo)扇區(qū)讀入到內(nèi)存之后,其DL和ES、SI寄存器的內(nèi)容如下: DL:表示啟動(dòng)設(shè)備,例如,如果計(jì)算機(jī)是從軟盤啟動(dòng)的則DL=0,若是從IDE的C、D盤(嚴(yán)格來(lái)說(shuō)是物理磁盤一和物理磁盤二,而不是邏輯磁盤分區(qū))啟動(dòng)的則DL分別為0x80和0x81 。如果是從硬盤啟動(dòng)的話,ES:SI是指向BIOS中的硬盤分區(qū)表存放的地址 。
【FreeBSD啟動(dòng)扇區(qū)代碼分析】好了,我們現(xiàn)在已經(jīng)知道,計(jì)算機(jī)的BIOS已經(jīng)把引導(dǎo)扇區(qū)的512字節(jié)的內(nèi)容讀入到了0:0x7c00處,然后就跳轉(zhuǎn)到0:0x7C00處去執(zhí)行,也就是執(zhí)行引導(dǎo)扇區(qū)代碼,引導(dǎo)扇區(qū)代碼boot0執(zhí)行代碼dump如下(它很有用,以后我們還不時(shí)回頭來(lái)看):
上圖中的4x16個(gè)字節(jié)是保留的4個(gè)分區(qū)信息下面,我們對(duì)FreeBSD啟動(dòng)扇區(qū)代碼boot0.s進(jìn)行逐步分析 。boot0.s代碼如下:
#
# Copyright (c) 1998 Robert NordIEr
# All rights reserved.
#
# Redistribution and use in source and binary forms are freely
# permitted provided that the above copyright notice and this
# paragraph and the following disclaimer are duplicated in all
# such forms.
#
# This software is provided "AS IS" and without any express or
# implied warranties, including, without limitation, the implied
# warranties of merchantability and fitness for a particular
# purpose.
#以上的Coyright就不用翻譯了 。# $FreeBSD: src/sys/boot/i386/boot0/boot0.s,v 1.27 2003/11/20 20:28:18 jhb Exp $以上供版本管理軟件使用 # A 512-byte boot manager.
.set NHRDRV,0x475 # Number of hard drives
.set ORIGIN,0x600 # Execution address
.set FAKE,0x800# Partition entry
.set LOAD,0x7c00 # Load address
.set PRT_OFF,0x1be # Partition table
.set TBL0SZ,0x3 # Table 0 size
.set TBL1SZ,0xb # Table 1 size
.set MAGIC,0xaa55 # Magic: bootable
.set B0MAGIC,0xbb66 # Identification
.set KEY_ENTER,0x1c # Enter key scan code
.set KEY_F1,0x3b # F1 key scan code
.set KEY_1,0x02 # #1 key scan code
#
# Addresses in the sector of embedded data values.
# Accessed with negative offsets from the end of the relocated sector (雙).
#
.set _NXTDRV,-0x48 # Next drive
.set _OPT,-0x47 # Default option
.set _SETDRV,-0x46 # Drive to force
.set _FLAGS,-0x45 # Flags
.set _TICKS,-0x44 # Timeout ticks
.set _FAKE,0x0 # Fake partition entry
.set _MNUOPT,0xc # Menu options 以上是定義相關(guān)的參數(shù)值,例如“.set NHRDRV,0x475類似于C語(yǔ)言中的“#define NHRDRV 0x475.globl start # Entry point
.code16 # This runs in real mode
#
# Initialise segments and registers to known values.
# segments start at 0.
# The stack is immediately below the address we were loaded to.
#
start:
cld # String ops inc
xorw %ax,%ax # Zero
movw %ax,%es # Address
movw %ax,%ds # data
movw %ax,%ss # Set up

推薦閱讀