Use optimized error handling for boot sector

This commit is contained in:
Nero 2020-04-03 17:38:33 +00:00
parent cb48e628db
commit 3da473a00c
2 changed files with 27 additions and 23 deletions

View File

@ -28,23 +28,7 @@ init: xor ax, ax
rep movsw
jmp 0x0:main
msg: pop si
mloop: lodsb
test al, al
jz mend
mov ah, 0x0e
mov bx, 7
int 0x10
jmp mloop
mend: push si
ret
dskerr: call msg
db "DISK", 0
err: call msg
db "ERR", 0x0A, 0x0D, 0
hlt: hlt
jmp hlt
%include "inc/booterr.asm"
; offsets relative to FS
readd: ; add offset of cluster data area to DX:AX
@ -69,7 +53,7 @@ readf: ; add offset to FAT table to DX:AX
readp: ; read sector DX:AX from partition
add ax, word [bp+bpb_po]
adc dx, word [bp+bpb_po+2]
jc err
jc dskerr
read_: ; read sector DX:AX from disk
; qword sector number DX:AX
push cs
@ -99,6 +83,9 @@ read_: ; read sector DX:AX from disk
ret
; error handling for disk errors
dskerr: call errcll
next: ; Advances DX:AX to next FAT entry
push ax
push bx
@ -181,7 +168,7 @@ loop: add si, 0x20
mov al, [si]
; unallocated direntry
test al, al
jz end
jz fserr
; deleted files
cmp al, 0xE2
je loop
@ -197,7 +184,7 @@ loadr: mov ax, 2
jmp load
loadf: call search
jne end
jne fserr
mov ax, [si+0x1A]
mov dx, [si+0x14]
jmp load
@ -228,9 +215,8 @@ main: mov bp, bpb
jmp 0:0x7C00
end: call msg
db "DIR", 0
jmp err
; error handling for file not found
fserr: call errcll
; Padding and signature
times (0x1FE - ($-$$)) db 0

18
inc/booterr.asm Normal file
View File

@ -0,0 +1,18 @@
errcll: pop dx
errjmp: call dmpdx
hlt: hlt
jmp hlt
dmpdx: xor bx, bx
mov ah, 0x0e
mov cl, 4
call dmpdx1
dmpdx1: call dmpdx2
dmpdx2: mov al, dh
shl dx, cl
shr al, cl
add al, 0x30
cmp al, 0x3a
jl dmpdx3
add al, 7
dmpdx3: int 0x10
ret