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