📄 bootsect.s
字号:
# Boot Sector for XSFS
# Loaded at 0000:7C00
.text
.global _start
.code16
.align 1
.org 0
_start:
jmp entry0
xsfs_desc:
.asciz "XSFS " # signature
.long 0 # version
.word 0 # sector_size
.word 0 # n_scale
.long 0 # n_sectors
.long 0 # n_units
n_rsv: .word 0 # n_reserved
.word 0 # n_ss_desc
.word 0 # n_bitmap
.word 0 # pad
# following goes some private data
# in XSFS specification, these are reserved bytes, totally 32 bytes
# these must be set by formatter
.equ EXT_INT13, 0x8000
w_ext: .word 0x8000 # highest bit (bit 15) indicates whether
# extended INT 13H should be used
l_base: .long 0x3f # start sector of this partition
# first word will be used if no extension
# is used
l_part: .long 0x8100 # higher 16 bits indicate drive (FD 0-1, HD 80-83)
# lower 16 bits indicate partition number (start with 0)
.space 32 # pad
entry0: ljmp $0x07c0, $entry1 # use far jmp to reload CS:IP
# following is the real start point
# INPUT: DX = head:drive (BIOS will set it)
entry1:
# reload segment registers
movw %cs, %ax
movw %ax, %ds
movw %ax, %es
movw %ax, %ss
movw $0x02f0, %sp
pushw %dx
leaw sz_stage1, %si
call display
popw %dx
# AX = sectors to load
movw n_rsv, %ax
decw %ax
jz err_n_rsv
cmpw $64, %ax # loader cannot exceeds 32K
jg err_n_rsv
pushw %dx # save DX
movw w_ext, %bx
andw $EXT_INT13, %bx
jnz ext_read
# load with normal INT 13H
movw $0x0800, %bx # target segment
movw %bx, %es
movw $0x0000, %bx
movw l_base, %cx
incw %cx # skip boot sector
movb $0x02, %ah # AH = 02H read sectors
int $0x13
jb err_read
jmp switch
# load with extended INT 13H
ext_read:
movw n_rsv, %ax
movw %ax, n_blocks
movl l_base, %eax
incl %eax
movl %eax, l_sector
leaw disk_pack, %si
movw $0x4200, %ax
int $0x13
jb err_read
jmp switch
# switch to loader
# OUTPUT: DX = head:drive
# SI = xsfs_desc
# ECX = l_base
# EAX = l_part
# BX = w_ext
# DS = this segment
switch:
leaw sz_done, %si
call display
movw w_ext, %bx
movl l_base, %ecx
movl l_part, %eax
leaw xsfs_desc, %si
popw %dx
ljmp $0x0800, $0
# error routines
err_n_rsv:
leaw sz_err_n_rsv, %si
call display
jmp d_halt
err_read:
leaw sz_err_read, %si
call display
jmp d_halt
d_halt: jmp d_halt
# functions
display:
lodsb
cmpb $0, %al
jz dispe
pushw %si
movw $0x0007, %bx
movb $0x0e, %ah
int $0x10
popw %si
jmp display
dispe: ret
# data goes here
disk_pack: .byte 0x10
.byte 0
n_blocks: .word 0
l_address: .long 0x08000000
l_sector: .long 0, 0
sz_err_n_rsv: .asciz "Incorrect number of reserved sectors"
sz_err_read: .asciz "Disk read error"
sz_stage1: .asciz "Stage1..."
sz_done: .asciz "OK\r\n"
# boot sector signature
.org 0x1fe
.byte 0x55, 0xaa
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -