启动扇区代码分析 FreeBSD 5.2.1 boot0( 七 )



cmpw $MAGIC,0x1fe(%bx) # Bootable?
jne main.10 # No
判断引导扇区的最后两个字节是否是“0x55AA”,如果不是,则表示此扇区是不可引导的,或
不合法的引导扇区则直接跳转到main.10 。使用户重新选择启动分区 。

pushw %si # Save
movw $crlf,%si # Leave some
callw puts # space
popw %si # Restore

打印“回车”和“换行” 。

jmp *%bx # Invoke bootstrap

跳转到我们选择的引导扇区去执行 。整个Boot Manager代码到此执行完毕 。

#
# Display routines
#

putkey:
movb $"F",%al # Display
callw putchr # "F"
movb $"1",%al # Prepare
addb %dl,%al # digit
jmp putstr.1 # Display the rest
“putkey”函数在屏幕上打印“F1”、“F2”或“F3”等 。如果dl为0则打印“F1”,
如果dl为1则打印“F2”,如果dl为3则打印“F3” 。和调用“putstr”在屏幕上打印
es:si指向的以最高位置1为结束字符的字符串 。
#
# Display the option and note that it is a valid option.
# That last point is a bit tricky..
#
putx: #首先,把_MNUOPT(%bp)的第dx位(bit)置1,表示此菜单选项被显示 。然后在
屏幕上打印空格和es:di指向的以最高位置1为结束字符的字符串 。
btsw %dx,_MNUOPT(%bp) # Enable menu option
movw $item,%si # Display
callw putkey # key
movw %di,%si # Display the rest

puts: #调用“putstr”在屏幕上打印es:si指向的以最高位置1为结束字符的字符串 。
callw putstr # Display string

putn: #“putn”打印“回车/换行”后在屏幕上打印es:si指向的以最高位置1为结束字符的字符串 。
movw $crlf,%si # To next line

putstr: #“putstr”在屏幕上打印es:si指向的以最高位置1为结束字符的字符串 。
lodsb # Get byte
testb $0x80,%al # End of string?
jnz putstr.2 # Yes
putstr.1:
callw putchr # Display char
jmp putstr # Continue
putstr.2:
andb $~0x80,%al # Clear MSB

putchr:
pushw %bx # Save
movw $0x7,%bx # Page:attribute
movb $0xe,%ah # BIOS: Display
int $0x10 # character
popw %bx # Restore
retw # To caller
“putchr”在屏幕上显示“al”中的字符 。
# One-sector disk I/O routine

intx13:
movb 0x1(%si),%dh # Load head
movw 0x2(%si),%cx # Load cylinder:sector
movb $0x1,%al # Sector count
pushw %si # Save
movw %sp,%di # Save
testb $0x80,_FLAGS(%bp) # Use packet interface?
jz intx13.1 # No
pushl $0x0 # Set the
pushl 0x8(%si) # LBA address
pushw %es # Set the transfer
pushw %bx # buffer address
push $0x1 # Block count
push $0x10 # Packet size
movw %sp,%si # Packet pointer
decw %ax # Verify off
orb $0x40,%ah # Use disk packet
intx13.1:
int $0x13 # BIOS: Disk I/O
movw %di,%sp # Restore
popw %si # Restore
retw # To caller

# Menu strings

item:
.ascii " "; .byte " "|0x80
prompt:
.ascii "nDefault:"; .byte " "|0x80
crlf:
.ascii "r"; .byte "n"|0x80

# Partition type tables

tables:
#
# These entries identify invalid or NON BOOT types and partitions.
#
.byte 0x0, 0x5, 0xf
#
# These values indicate bootable types we know the names of
#
.byte 0x1, 0x4, 0x6, 0xb, 0xc, 0xe, 0x83
.byte 0x9f, 0xa5, 0xa6, 0xa9
#
# These are offsets that match the known names above and point to the strings
# that will be printed.
#
.byte os_misc-. # Unknown
.byte os_dos-. # DOS
.byte os_dos-. # DOS
.byte os_dos-. # DOS
.byte os_dos-. # Windows
.byte os_dos-. # Windows
.byte os_dos-. # Windows
.byte os_linux-. # Linux
.byte os_bsd-. # BSD/OS
.byte os_freebsd-. # FreeBSD
.byte os_bsd-. # OpenBSD
.byte os_bsd-. # NetBSD
#
# And here are the strings themselves. 0x80 or"d into a byte indicates
# the end of the string. (not so great for Russians but...)
#
os_misc: .ascii "?"; .byte "?"|0x80

推荐阅读