Message1 db "HD Boot "; 9字节, 不够则用空格补齐. 序号 1
Message2 db "No LOADER"; 9字节, 不够则用空格补齐. 序号 2
Message3 db "Error 0 "; 9字节, 不够则用空格补齐. 序号 3
;============================================================================ clear_screen:
mov ax, 0x600 ; AH = 6, AL = 0
mov bx, 0x700 ; 黑底白字(BL = 0x7)
mov cx, 0 ; 左上角: (0, 0)
mov dx, 0x184f ; 右下角: (80, 50)
int 0x10 ; int 0x10
ret ;----------------------------------------------------------------------------
; 函数名: disp_str
;----------------------------------------------------------------------------
; 作用:
; 显示一个字符串, 函数开始时 dh 中应该是字符串序号(0-based)
disp_str:
mov ax, MessageLength
mul dh
add ax, BootMessage
mov bp, ax ; `.
mov ax, ds ; | ES:BP = 串地址
mov es, ax ; /
mov cx, MessageLength ; CX = 串长度
mov ax, 0x1301 ; AH = 0x13, AL = 0x1
mov bx, 0x7 ; 页号为0(BH = 0) 黑底白字(BL = 0x7)
mov dl, 0
int 0x10 ; int 0x10
ret ;----------------------------------------------------------------------------
; read_sector
;----------------------------------------------------------------------------
; Entry:
; - fields disk_address_packet should have been filled
; before invoking the routine
; Exit:
; - es:bx -> data read
; registers changed:
; - eax, ebx, dl, si, es
read_sector:
xor ebx, ebx mov ah, 0x42
mov dl, 0x80
mov si, disk_address_packet
int 0x13 mov ax, [disk_address_packet + 6]
mov es, ax
mov bx, [disk_address_packet + 4] ret ;----------------------------------------------------------------------------
; get_inode
;----------------------------------------------------------------------------
; Entry:
; - eax : inode nr.
; Exit:
; - eax : sector nr.
; - ecx : the_inode.i_size
; - es:ebx : inodes sector buffer
; registers changed:
; - eax, ebx, ecx, edx
get_inode:
dec eax ; eax <- inode_nr -1
mov bl, [fs:SB_INODE_SIZE]
mul bl ; eax <- (inode_nr - 1) * INODE_SIZE
mov edx, SECT_BUF_SIZE
sub edx, dword [fs:SB_INODE_SIZE]
cmp eax, edx
jg err
push eax mov ebx, [fs:SB_NR_IMAP_SECTS]
mov edx, [fs:SB_NR_SMAP_SECTS]
lea eax, [ebx+edx+ROOT_BASE+2]
mov dword [disk_address_packet + 8], eax
call read_sector pop eax ; [es:ebx+eax] -> the inode mov edx, dword [fs:SB_INODE_ISIZE_OFF]
add edx, ebx
add edx, eax ; [es:edx] -> the_inode.i_size
mov ecx, [es:edx] ; ecx <- the_inode.i_size ; es:[ebx+eax] -> the_inode.i_start_sect
add ax, word [fs:SB_INODE_START_OFF] add bx, ax
mov eax, [es:bx]
add eax, ROOT_BASE ; eax <- the_inode.i_start_sect
ret
times 510-($-$$) db 0 ; 填充剩下的空间,使生成的二进制代码恰好为512字节
dw 0xaa55 ; 结束标志