# Busy loop, looking for keystrokes but
# keeping one eye on the time.
#
main.8:
movb $0x1,%ah # BIOS: Check
int $0x16 # for keypress
jnz main.11 # Have one
xorb %ah,%ah # BIOS: Get
int $0x1a # system time
cmpw %di,%dx # Timeout?
jb main.8 # No等待用户按下“Fx键,同时检查当前等待是否超时,如果有用户按键则跳转到main.11,如果超时时间不到则继续等待 。#
# If timed out or defaulting, come here.
#
main.9:
movb _OPT(%bp),%al # Load default
jmp main.12 # Join common code超时时间到,此时表示用户使用缺省分区启动,把缺省的启动分区号置入al中,然后跳转到main.12 。#
# User's last try was bad, beep in displeasure.
# Since nothing was printed, just continue on as if the user
# hadn't done anything. This gives the effect of the user getting a beep
# for all bad keystrokes but no action until either the timeout
# occurs or the user hits a good key.
#
main.10:
movb $0x7,%al # Signal
callw putchr # error用户输入错误,只是响铃提示,其他什么也不发生 。#
# Get the keystroke.
#
main.11:
xorb %ah,%ah # BIOS: Get
int $0x16 # keypress
movb %ah,%al # Scan code用户按下了一个键,把键值扫描码放到al中 。#
# If it's CR act as if timed out.
#
cmpb $KEY_ENTER,%al # Enter pressed?
je main.9 # Yes如果用户按下“Enter键,和超时等同处理,这样,就启动缺省的boot分区 。#
# Otherwise check if legal
# If not ask again.
#
subb $KEY_F1,%al # Less F1 scan code
cmpb $0x4,%al # F1..F5?
jna main.12 # Yes
subb $(KEY_1 - KEY_F1),%al # Less #1 scan code
cmpb $0x4,%al # #1..#5?
ja main.10 # No如果是除“Enter键外其他的键,则检查是不是F1...F5键,如果不是,表示输入不合法,跳回到main.10处理 。#
# We have a selection.
# but if it's a bad selection go back to complain.
# The bits in MNUOPT were set when the options were printed.
# Anything not printed is not an option.
#
main.12:
cbtw # Option
btw %ax,_MNUOPT(%bp)# enabled?
jnc main.10 # No如果是F1...F5键,则检查是否在我们提示的范围内,其中,_MNUOPT(%bp)的相应bit位为1,表示是一个合法的选项,如果不是,跳回到 main.10处理 。#
# Save the info in the original tables
# for rewriting to the disk.
#
movb %al,_OPT(%bp) # Save option把我们按下的F1...F5键保存到_OPT(%bp)位置 。movw $FAKE,%si # Partition for write
movb (%si),%dl # Drive number把原来的启动分区代码取回到dl中 。movw %si,%bx # Partition for read
cmpb $0x4,%al # F5 pressed?
pushf # Save
je main.13 # Yes如果我们按下的是F5键则直接跳转到main.13处理 。shlb $0x4,%al # Point to
addw $partbl,%ax # selected
xchgw %bx,%ax# partition
movb $0x80,(%bx) # Flag active上面,我们从按键Fx选择中得到图(三)中的我们选择的四个分区信息中的某一分区信息,上面计算出的bx为我们选择的分区信息的首地址,我们把此选择到的分区信息的第一个个字节置为0x80表示它是当前的活动分区 。#
# If not asked to do a write-back (flags 0x40) don't do one.
#
main.13:
pushw %bx # Save
testb $0x40,_FLAGS(%bp) # No updates?
jnz main.14 # Yes
movw $start,%bx # Data to write
movb $0x3,%ah # Write sector
callw intx13 # to disk检查回写标志_FLAGS(%bp)的bit位0x40为,如果设置的是可回写,则把当前选择到的boot分区作为下次缺省的启动分区 。main.14:
popw %si # Restore
popf # Restore
#
# If going to next drive, replace drive with selected one.
# Remember to un-ascii it. Hey 0x80 is already set, cool!
推荐阅读
- 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的相关资源