# 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启动分区的代码保存到_FAKE(%bp)(bp-0)处,也就是说,上图(二)的bp处保存的是FreeBSD启动分区的代码(_FAKE=0) 。“callw putn一句在屏幕上打印“回车和“换行,“pushw %dx一句把启动分区的值压入堆栈 。#
# 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指向分区表partbl的的第四个字节,这里存放的是分区类型,如82表示Linux Native分区83表示Linux Swap 分区,有关分区表的细节请详见本文的尾部 。然后dx清零,此后,dx将作为遍历磁盘分区的列举代号使用 。启动分区代码dl的原来的值在上面已经压入了堆栈保存 。#
# Loop around on the partition table, printing values until we
# pass a 256 byte boundary. The end of loop test is at main.5.
#
main.3:
movb %ch,-0x4(%bx) # Zero active flag (ch == 0)
btw %dx,_FLAGS(%bp) # Entry enabled?
jnc main.5 # No上面首先使得第一个分区的活动标志为0,标志它不为活动标志,因为ch的值为0 。至于第二句“btw %dx,_FLAGS(%bp)中的_FLAGS(%bp)是上面我们说到的“手动指定我们实际安装FreeBSD的分区代码 。其中的bit 0x20我们在上面已经提到过 。_FLAGS(%bp)中的其他位表示是否我们需要检查相应的磁盘分区 。缺省情况下,我们需要检查所有的磁盘分区 。检查磁盘分区看是否有可以启动的磁盘分区,例如,可能磁盘上的某个分区为WindowsXP或者是Linux等 。如果我们没有改变在磁盘上该处的值,则相应的bit位的值为0,表示所有的分区都要检查(因为此时_FLAGS(%bp)中的值为0),否则,只针对FLAGS(%bp)中相应的bit位未被设置为1的分区进行检查 。大家知道,FreeBSD Manager启动时可能出现以下的提示:F1FreeBSD
F2??
F3BSD
F4??
DefaultF1其中,上面的提示中出现了令人讨厌的“??,为了避免出现“??的提示,我们可以设置相应的第一分区和第四分区不检查,就需要正确设置_FLAGS(%bp)中的bit位 。设置好后,屏幕可能出现以下的提示:F1FreeBSD
F2BSD
DefaultF1
#
# If any of the entries in the table are
# the same as the 'type' in the slice table entry,
# then this is an empty or non bootable partition. Skip it.
#
movb (%bx),%al # Load type
movw $tables,%di # Lookup tables
movb $TBL0SZ,%cl # Number of entries
repne # Exclude
scasb # partition?
je main.5 # Yes我们从上面已经知道起始(%bx)指向的是MBR中分区信息1(16字节)的位置(见图(三)),以上代码在“忽略的分区类型$tables中查找看是否本分区是不可启动的或者不合法的分区 。不可启动的或者不合法的分区类型有3($TBL0SZ=3)个,它们是“0x0, 0x5, 0xf,见下面的$tables处 。如果是不可启动的或者不合法的分区类型则跳转到main.5,进行下一轮循环 。#
# Now scan the table of known types
#
movb $TBL1SZ,%cl # Number of entries
repne # Known
scasb # type?
jne main.4 # No
#
# If it matches get the matching element in the
# next array. if it doesn't, we are already
# pointing at its first element which points to a "?".
#
addw $TBL1SZ,%di # Adjust
推荐阅读
- FreeBSD的Loader和内核初始化
- FreeBSD系统安装与配置之准备篇
- FreeBSD的磁盘和BIOS的关系
- 浅谈FreeBSD 5.2常用操作的改变
- freebsd7.0 安装记录
- freebsd 7 pkg_add -r kde 4
- 加快FreeBSD中pkg_add的速度
- 红米note7pro中将应用自启动关掉具体操作方法
- 在FreeBSD5.0上配置DNS服务手记
- 04 FreeBSD连载:FreeBSD的相关资源
