现在的位置: 首页 >> 操作系统 >> FreeBSD >> FreeBSD 5.2.1 boot0(启动扇区代码分析)
添加时间:2005-8-21 来源:网教中国 作者:
FreeBSD 5.2.1 boot0(启动扇区代码分析)

#
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
os_dos: .ascii "DO"; .byte 'S'|0x80
os_linux: .ascii "Linu"; .byte 'x'|0x80
os_freebsd: .ascii "Free"
os_bsd: .ascii "BS"; .byte 'D'|0x80

.org PRT_OFF-0xe,0x90

.word B0MAGIC # Magic number

#
# These values are sometimes changed before writing back to the drive
# Be especially careful that nxtdrv: must come after drive:, as it
# is part of the same string.
#
drive:
.ascii "Drive "
nxtdrv:
.byte 0x0 # Next drive number
opt:
.byte 0x0 # Option
setdrv:
.byte 0x80 # Drive to force
flags:
.byte FLAGS # Flags
ticks:
.word TICKS # Delay

#
# here is the 64 byte partition table that fdisk would fiddle with.
#
partbl: .fill 0x40,0x1,0x0 # Partition table
.word MAGIC # Magic number MAGIC=0x55AA
以上保留0x40(十进制为64)个字节“伪”分区空间,且全部清零。partbl相对引导
山区代码的位置为0x1BE(见下图)。
MBR(Main Boot Record),按其字面上的理解即为主引导记录区,位于整个硬盘的0磁道0
柱面1扇区。不过,在总共512字节的主引导扇区中,MBR只占用了其中的446个字节(偏移
0--偏移1BDH),另外的64个字节(偏移1BEH--偏移1FDH)交给了DPT(Disk Partition Table
硬盘分区表)(见下表),最后两个字节"0x55aa"(偏移1FEH-偏移1FFH)是分区的结束标志。
这个整体构成了硬盘的主引导扇区。大致的结构如图(二):详见王巍的文章:《第一讲
操作系统简介及Win98安装》

0000┏━━━━━━━━━━━━━━━━━━┓
┃ ┃
┃ ┃
┃ ┃
┃ ┃
┃ ┃
┃ 主引导记录(MBR) 446字节 ┃
┃ ┃
┃ ┃
┃ ┃
┃ ┃
01BD┃ ┃
┣━━━━━━━━━━━━━━━━━━┫
01BE┃ 分区信息1(16字节) ┃<--partbl指向这里。
┣━━━━━━━━━━━━━━━━━━┫
01CE┃ 分区信息2(16字节) ┃
┣━━━━━━━━━━━━━━━━━━┫
01DE┃ 分区信息3(16字节) ┃
┣━━━━━━━━━━━━━━━━━━┫
01EE┃ 分区信息4(16字节) ┃
┣━━━━━━━━┳━━━━━━━━━┫
01FE┃ 0x55 ┃ 0xAA ┃
┗━━━━━━━━┻━━━━━━━━━┛

图(三)

其中,分区信息1-4的内容如下图所示:
偏移
长度
所表达的意义
0
字节
分区状态:如0-->非活动分区
       80--> 活动分区
1
字节
该分区起始头(HEAD)
2

该分区起始扇区和起始柱面
4
字节
该分区类型:如82--> Linux Native分区
        83--> Linux Swap 分区
5
字节
该分区终止头(HEAD)
6

该分区终止扇区和终止柱面
8


上一页 [1] [2] [3] [4] [5] [6]  下一页


上一篇:网桥原理及源代码详解 下一篇:FreeBSD中的设备命名规则
大部分文章摘自网上,如有侵犯您的权益请与我们联系,我们会第一时间进行处理,谢谢! [ 打印文章 ] [ 关闭窗口 ]
推荐文章
·FreeBSD handbook中文版 9 配制F
·FreeBSD 升级系统
·Ports & Package
·FreeBSD kernel 编译大法(二)ker
·FreeBSD 上使用Kerberos 5认证
·FreeBSD 5.x 中 gbfs 的修正,及
·FreeBSD 安装Linuxigd
·FreeBSD 使用cvsd创建安全的cvs
·FreeBSD trafcount命令介绍
·FreeBSD入门安装及汉化
相关文章
 
最新文章
·FreeBSD连载(94):基于NAT的负载
·FreeBSD连载(93):反向代理负载
·FreeBSD连载(92):基于DNS的负载
·FreeBSD连载(91):提升静态网页
·FreeBSD连载(90):单服务器性能
·FreeBSD连载(89):CGI和SSI的安
·FreeBSD连载(88):安全连接方式S
·FreeBSD连载(87):基于用户的访
·FreeBSD连载(86):对IP地址和域
·FreeBSD连载(85):配置Apache服(
Google