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

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

<-bp指向這里(0:0x800),以此開(kāi)始的16字節(jié)被清零 。
┃ ┣━━━━━┫以下所稱(chēng)的fake partition entry就是指這里 。
┃ ┃ 0 ┃
┃ ┣━━━━━┫
┃ ┃ 0 ┃
┃ ┣━━━━━┫
┃ ┃ 0 ┃
┃ ┣━━━━━┫
┃ ┃ 0 ┃
┃ ┣━━━━━┫
┃ ┃ 0 ┃
┃ ┣━━━━━┫
┃ ┃ 0 ┃
┃ ┣━━━━━┫
┃ ┃ 0 ┃
┃ ┣━━━━━┫
┃ ┃ 0 ┃
┃ ┣━━━━━┫
┃ ┃ 0 ┃
┃ ┣━━━━━┫
┃ ┃ 0 ┃
┃ ┣━━━━━┫
┃ ┃ 0 ┃
┃ ┣━━━━━┫
┃ ┃ 0 ┃
┃ ┣━━━━━┫
┃ ┃ 0 ┃
┃ ┣━━━━━┫
┃ ┃ 0 ┃
┃ ┣━━━━━┫
┃ ┃ 0 ┃
┃ ┗━━━━━┛
0:0x7c00 ┏━━━━━┓ ┛
┃ ┃
┃ 搬 ┃
┃ 移 ┃
┃ 之 ┃
┃ 前 ┃
┃ 的 ┃
┃ 代 ┃
┃ 碼 ┃
┃ ┃
0:0x7dff ┗━━━━━┛

圖(二)
#
# Relocate to the new copy of the code.
#
incb -0xe(%di) # Sector number
jmp main-LOAD ORIGIN # To relocated code

把以上清零的16字節(jié)的第二個(gè)字節(jié)置為1,表示我們已經(jīng)讀取了一個(gè)分區(qū) 。然后跳轉(zhuǎn)到搬
移之后的新代碼的main處執(zhí)行 。

#
# Check what flags were loaded with us, specifically, Use a predefined Drive.
# If what the bios gives us is bad, use the "0" in the block instead, as well.
#
main:
testb $0x20,_FLAGS(%bp) # Set number drive?
jnz main.1 # Yes
testb %dl,%dl # Drive number valid?
js main.2 # Possibly (0x80 set)
main.1:
movb _SETDRV(%bp),%dl # Drive number to use
上面說(shuō)過(guò),BIOS把磁盤(pán)的引導(dǎo)扇區(qū)讀入到內(nèi)存之后,其dl的內(nèi)容表示啟動(dòng)設(shè)備,但我們 安裝好FreeBSD
之后,我們可以改變此引導(dǎo)扇區(qū)的內(nèi)容,其中的一個(gè)改變就是可以使我們可以“手動(dòng)指定”我們實(shí)際安
裝FreeBSD的分區(qū),如果我們希望指定FreeBSD所在的boot分區(qū),那么我們?cè)赽p-0x45處的位置
(即_FLAGS(%bp)處)的bit 0x20置1,那么上面的“movb _SETDRV(%bp),%dl”一句中movb
_SETDRV(%bp),%dl(即bp-0x46)即指向我們“手動(dòng)指定”FreeBSD所在分區(qū) 代碼,例如,IDE的C、D
盤(pán)(嚴(yán)格來(lái)說(shuō)是第一個(gè)物理磁 盤(pán)的第一個(gè)和第二個(gè)分區(qū))的代碼分別為 0x80和0x81 。如果沒(méi)有“手動(dòng)指
定”啟動(dòng)分區(qū),那么,我們 缺省使用機(jī)器當(dāng)前啟動(dòng)的分區(qū),上面說(shuō)過(guò),機(jī)器當(dāng)前啟動(dòng)的分區(qū)代碼放在dl中 。

因?yàn)镕reeBSD Boot Manager 不可能安裝到軟盤(pán)(如果從軟盤(pán)啟動(dòng)則dl為0),所以,使用testb %dl,%dl
來(lái)判斷驅(qū)動(dòng)器代碼是否合法(volid) 。

有關(guān)_FLAGS(%bp)中其他bit位表示的意義,在隨后的代碼分析中慢慢給你道來(lái) 。

#
# Whatever we decided to use, now store it into the fake
# partition entry that lives in the data space above us.
#
main.2:
movb %dl,_FAKE(%bp) # Save drive number
callw putn # To new line
pushw %dx # Save drive number

以上第一句把FreeBSD啟動(dòng)分區(qū)的代碼保存到_FAKE(%bp)(bp-0)處,也就是說(shuō),上圖(二)的bp
處保存的是FreeBSD啟動(dòng)分區(qū)的代碼(_FAKE=0) 。

“callw putn”一句在屏幕上打印“回車(chē)”和“換行”,“pushw %dx”一句把啟動(dòng)分區(qū)
的值壓入堆棧 。
#
# Start out with a pointer to the 4th byte of the first table entry
# so that after 4 iterations it"s beyond the end of the sector.
# and beyond a 256 byte boundary and has overflowed 8 bits (see next comment).
# (remember that the table starts 2 bytes earlier than you would expect
# as the bootable flag is after it in the block)
#
movw $(partbl 0x4),%bx # Partition table ( 4)
xorw %dx,%dx # Item number

以上代碼首先把%bx指向分區(qū)表partbl的的第四個(gè)字節(jié),這里存放的是分區(qū)類(lèi)型,如82表示

推薦閱讀