;正式开始加载内核
read_begin:
;from sector x, track 0, drive 0, head 0, 其中x 的值存放在 [current_sector]中
xor cx, cx
mov cl, byte [current_sector]
mov ch, byte [current_track]
;每次加载一个扇区
xor ax, ax
mov al, #0x1; one sector
mov ah, #0x2;service 2
int 0x13
jc dead_loop_before
;如果加载一个扇区成功则打印.
call print_dot
;刷新并检查是否所有的扇区都加载完毕
dec byte [kernel_sectors]
jz read_finish
;刷新 current_sector并检查是否需要跳到下一个磁道
cmp cl, #18
je next_track
inc byte [current_sector]
same_track:
;refresh bx register for offset
add bx, #512
;if bx = 0x0,
cmp bx, #0x0
je next_64k
jmp read_begin
next_track:
;刷新 current_track
push ax
mov al, #0x1
mov byte [current_sector], al
pop ax
inc dh
and dh, #0x01
cmp dh, #0x0
jnz same_track
inc byte [current_track]
jmp same_track
next_64k:
push ax
mov ax, es
add ax, #0x1000
mov es, ax
pop ax
jmp read_begin
dead_loop_before:
;print err message
dead_loop:
jmp dead_loop
read_finish:
;还原最初的kernel_secotrs值
pop ax
mov byte [kernel_sectors], al