Compare commits
3 Commits
591fe91f93
...
4dc7266f6a
Author | SHA1 | Date |
---|---|---|
Juhani Krekelä | 4dc7266f6a | |
Juhani Krekelä | de098cb9f3 | |
Juhani Krekelä | 8d67cdf201 |
91
bootsect.asm
91
bootsect.asm
|
@ -121,8 +121,15 @@ search_root:
|
||||||
je .end
|
je .end
|
||||||
|
|
||||||
test byte [si + 11], 0x08 + 0x10
|
test byte [si + 11], 0x08 + 0x10
|
||||||
jz .isfile
|
jnz .skipentry
|
||||||
|
|
||||||
|
; Make sure the file has non-zero size
|
||||||
|
cmp word [si + 28], 0
|
||||||
|
jne .isfile
|
||||||
|
cmp word [si + 30], 0
|
||||||
|
jne .isfile
|
||||||
|
|
||||||
|
.skipentry:
|
||||||
add si, 32
|
add si, 32
|
||||||
jmp .entry
|
jmp .entry
|
||||||
|
|
||||||
|
@ -154,18 +161,12 @@ search_root:
|
||||||
.end:
|
.end:
|
||||||
|
|
||||||
notfound:
|
notfound:
|
||||||
; TODO: Better error messages
|
mov si, notfound_msg
|
||||||
mov ax, 0x0e00 + '?'
|
jmp fatal_error
|
||||||
int 0x10
|
|
||||||
|
|
||||||
hang:
|
|
||||||
hlt
|
|
||||||
jmp hang
|
|
||||||
|
|
||||||
found:
|
found:
|
||||||
; SI points to 11 bytes after the start of the entry, so adjust all
|
; SI points to 11 bytes after the start of the entry, so adjust all
|
||||||
; offsets
|
; offsets
|
||||||
; TODO: Handle zero-length files
|
|
||||||
mov ax, [si - 11 + 26] ; First cluster
|
mov ax, [si - 11 + 26] ; First cluster
|
||||||
push ax
|
push ax
|
||||||
|
|
||||||
|
@ -248,8 +249,13 @@ loadsectors:
|
||||||
push ax
|
push ax
|
||||||
push cx
|
push cx
|
||||||
push dx
|
push dx
|
||||||
|
push di
|
||||||
|
|
||||||
.loop:
|
.loop:
|
||||||
|
mov di, 3 ; Retry thrice
|
||||||
|
|
||||||
|
.retry:
|
||||||
|
|
||||||
push ax
|
push ax
|
||||||
push cx
|
push cx
|
||||||
|
|
||||||
|
@ -282,45 +288,62 @@ loadsectors:
|
||||||
and al, 0xC0
|
and al, 0xC0
|
||||||
or cl, al
|
or cl, al
|
||||||
|
|
||||||
; Copy number of sectors to still read to ax and cap at 127
|
mov ah, 2
|
||||||
pop ax
|
mov al, 1
|
||||||
push ax
|
mov dl, [drivenumber]
|
||||||
cmp al, 127
|
int 0x13
|
||||||
jbe .read
|
|
||||||
mov al, 127
|
|
||||||
|
|
||||||
.read:
|
; TODO: Handle reset & retry
|
||||||
mov ah, 2
|
jc .error
|
||||||
mov dl, [drivenumber]
|
|
||||||
int 0x13
|
|
||||||
|
|
||||||
; Decrement cx by the number of sectors read
|
|
||||||
pop cx
|
pop cx
|
||||||
xor ah, ah
|
pop ax
|
||||||
sub cx, ax
|
|
||||||
|
|
||||||
; Increment bx by the number of sectors read times 512
|
inc ax
|
||||||
xor dx, dx
|
add bx, 512
|
||||||
mov dh, al
|
|
||||||
shl dx, 1
|
|
||||||
add bx, dx
|
|
||||||
|
|
||||||
; Increment ax by the number of sectors read
|
loop .loop
|
||||||
pop dx
|
|
||||||
add ax, dx
|
|
||||||
|
|
||||||
test cx, cx
|
|
||||||
jnz .loop
|
|
||||||
|
|
||||||
|
pop di
|
||||||
pop dx
|
pop dx
|
||||||
pop cx
|
pop cx
|
||||||
pop ax
|
pop ax
|
||||||
ret
|
ret
|
||||||
|
|
||||||
%include "hexprint.inc"
|
.error:
|
||||||
|
; Do we still have retries remaining?
|
||||||
|
mov si, diskerror_msg
|
||||||
|
test di, di
|
||||||
|
jz fatal_error ; No, fail
|
||||||
|
dec di
|
||||||
|
|
||||||
|
; Yes, reset disk
|
||||||
|
xor ah, ah
|
||||||
|
int 0x13
|
||||||
|
|
||||||
|
; Execute the loop again
|
||||||
|
pop cx
|
||||||
|
pop ax
|
||||||
|
jmp .retry
|
||||||
|
|
||||||
|
fatal_error:
|
||||||
|
lodsb
|
||||||
|
test al, al
|
||||||
|
jz hang
|
||||||
|
mov ah, 0xe
|
||||||
|
int 0x10
|
||||||
|
jmp fatal_error
|
||||||
|
|
||||||
|
hang:
|
||||||
|
hlt
|
||||||
|
jmp hang
|
||||||
|
|
||||||
|
|
||||||
kernel_name: db "KERNEL BIN"
|
kernel_name: db "KERNEL BIN"
|
||||||
|
|
||||||
|
notfound_msg: db "Kernel not found", 0
|
||||||
|
diskerror_msg: db "Disk error", 0
|
||||||
|
|
||||||
times 510-($-$$) db 0
|
times 510-($-$$) db 0
|
||||||
db 0x55, 0xaa
|
db 0x55, 0xaa
|
||||||
_end:
|
_end:
|
||||||
|
|
|
@ -10,18 +10,19 @@ hexprint8:
|
||||||
mov cl, al
|
mov cl, al
|
||||||
xor bx, bx
|
xor bx, bx
|
||||||
|
|
||||||
mov ah, 0xe
|
|
||||||
shr al, 1
|
shr al, 1
|
||||||
shr al, 1
|
shr al, 1
|
||||||
shr al, 1
|
shr al, 1
|
||||||
shr al, 1
|
shr al, 1
|
||||||
mov bl, al
|
mov bl, al
|
||||||
mov al, [.digits + bx]
|
mov al, [.digits + bx]
|
||||||
|
mov ah, 0xe
|
||||||
int 0x10
|
int 0x10
|
||||||
|
|
||||||
mov bl, 0xf
|
mov bl, 0xf
|
||||||
and bl, cl
|
and bl, cl
|
||||||
mov al, [.digits + bx]
|
mov al, [.digits + bx]
|
||||||
|
mov ah, 0xe
|
||||||
int 0x10
|
int 0x10
|
||||||
|
|
||||||
pop cx
|
pop cx
|
||||||
|
|
Loading…
Reference in New Issue