Allow also loading EttinOS with the bootloader
This commit is contained in:
parent
b17a416bc6
commit
1c61708c85
120
boot.asm
120
boot.asm
|
@ -134,19 +134,34 @@ search_root:
|
|||
jmp .entry
|
||||
|
||||
.isfile:
|
||||
mov cx, 11
|
||||
mov bx, kernel_name
|
||||
.nor86:
|
||||
cmp word [si + 8], 'KR'
|
||||
jne .ettinos
|
||||
cmp byte [si + 10], 'N'
|
||||
jne .ettinos
|
||||
|
||||
.compare:
|
||||
lodsb
|
||||
cmp al, [bx]
|
||||
jne .nomatch
|
||||
inc bx
|
||||
loop .compare
|
||||
mov ax, [si + 26] ; First cluster
|
||||
mov [kernel_cluster], ax
|
||||
|
||||
jmp found
|
||||
jmp .skipentry
|
||||
|
||||
.nomatch:
|
||||
.ettinos:
|
||||
mov cx, 11
|
||||
mov bx, ettinos_kernel_name
|
||||
|
||||
.compare:
|
||||
lodsb
|
||||
cmp al, [bx]
|
||||
jne .nextentry
|
||||
inc bx
|
||||
loop .compare
|
||||
|
||||
; SI points to 11 bytes after the start of the
|
||||
; entry, so adjust offset
|
||||
mov ax, [si - 11 + 26] ; First cluster
|
||||
mov [ettinos_kernel_cluster], ax
|
||||
|
||||
.nextentry:
|
||||
; Each entry is 32 bytes long
|
||||
; During each iteration of the compare loop, si is
|
||||
; incremented and cx is decremented
|
||||
|
@ -160,14 +175,47 @@ search_root:
|
|||
|
||||
.end:
|
||||
|
||||
which_found:
|
||||
mov bx, [kernel_cluster]
|
||||
mov cx, [ettinos_kernel_cluster]
|
||||
|
||||
test bx, bx
|
||||
jz .no_nor86
|
||||
test cx, cx
|
||||
jz found
|
||||
|
||||
mov si, choose_msg
|
||||
.loop:
|
||||
lodsb
|
||||
test al, al
|
||||
jz .end
|
||||
|
||||
mov ah, 0xe
|
||||
int 0x10
|
||||
jmp .loop
|
||||
|
||||
.end:
|
||||
|
||||
xor ax, ax
|
||||
int 0x16
|
||||
|
||||
cmp ah, 0x12 ; E-key
|
||||
je found_cx
|
||||
jmp found
|
||||
|
||||
.no_nor86:
|
||||
test cx, cx
|
||||
jnz found_cx
|
||||
|
||||
notfound:
|
||||
mov si, notfound_msg
|
||||
jmp fatal_error
|
||||
|
||||
found_cx:
|
||||
mov bx, cx
|
||||
|
||||
found:
|
||||
; SI points to 11 bytes after the start of the entry, so adjust all
|
||||
; offsets
|
||||
mov ax, [si - 11 + 26] ; First cluster
|
||||
mov ax, bx
|
||||
push ax
|
||||
|
||||
; Load OS at the start of the memory
|
||||
|
@ -178,7 +226,8 @@ found:
|
|||
.tosector:
|
||||
; Adjust the cluster number to account for first two
|
||||
; "clusters" in the FAT being used for metadata
|
||||
sub ax, 2
|
||||
dec ax
|
||||
dec ax
|
||||
|
||||
; Scale by number of sectors per cluster
|
||||
xor bx, bx
|
||||
|
@ -217,11 +266,7 @@ found:
|
|||
; ^ where we start reading on odd cluster numbers
|
||||
; ^^^^^ loading word: 0xXYZA
|
||||
test ax, 1
|
||||
jnz .odd
|
||||
|
||||
.even:
|
||||
and dx, 0x0fff
|
||||
jmp .check_cluster
|
||||
jz .even
|
||||
|
||||
.odd:
|
||||
shr dx, 1
|
||||
|
@ -229,6 +274,9 @@ found:
|
|||
shr dx, 1
|
||||
shr dx, 1
|
||||
|
||||
.even:
|
||||
and dx, 0x0fff
|
||||
|
||||
.check_cluster:
|
||||
mov ax, dx
|
||||
|
||||
|
@ -245,14 +293,12 @@ execute_kernel:
|
|||
jmp 0:0x500
|
||||
|
||||
; Note: bx will point to after the read data
|
||||
; Note: ax, cx, and di will be clobbered
|
||||
loadsectors:
|
||||
push ax
|
||||
push cx
|
||||
push dx
|
||||
push di
|
||||
|
||||
.loop:
|
||||
mov di, 3 ; Retry thrice
|
||||
mov di, 3 + 1 ; Retry thrice, + 1 is since we dec first
|
||||
|
||||
.retry:
|
||||
|
||||
|
@ -283,17 +329,15 @@ loadsectors:
|
|||
|
||||
; cylinder (track)
|
||||
mov ch, al
|
||||
shr ax, 1
|
||||
shr ax, 1
|
||||
and al, 0xC0
|
||||
or cl, al
|
||||
;shr ax, 1
|
||||
;shr ax, 1
|
||||
;and al, 0xC0
|
||||
;or cl, al
|
||||
|
||||
mov ah, 2
|
||||
mov al, 1
|
||||
mov ax, 0x0201
|
||||
mov dl, [drivenumber]
|
||||
int 0x13
|
||||
|
||||
; TODO: Handle reset & retry
|
||||
jc .error
|
||||
|
||||
pop cx
|
||||
|
@ -304,18 +348,14 @@ loadsectors:
|
|||
|
||||
loop .loop
|
||||
|
||||
pop di
|
||||
pop dx
|
||||
pop cx
|
||||
pop ax
|
||||
ret
|
||||
|
||||
.error:
|
||||
; Do we still have retries remaining?
|
||||
mov si, diskerror_msg
|
||||
test di, di
|
||||
jz fatal_error ; No, fail
|
||||
dec di
|
||||
jz fatal_error ; No, fail
|
||||
|
||||
; Yes, reset disk
|
||||
xor ah, ah
|
||||
|
@ -339,10 +379,14 @@ hang:
|
|||
jmp hang
|
||||
|
||||
|
||||
kernel_name: db "NOR86 KRN"
|
||||
kernel_cluster dw 0
|
||||
ettinos_kernel_cluster dw 0
|
||||
|
||||
notfound_msg: db "Kernel not found", 0
|
||||
diskerror_msg: db "Disk error", 0
|
||||
ettinos_kernel_name db "SYSTEM BIN"
|
||||
|
||||
notfound_msg db "No kernel", 0
|
||||
diskerror_msg db "Disk error", 0
|
||||
choose_msg db "(E)ttinOS/Nor86?", 0
|
||||
|
||||
times 510-($-$$) db 0
|
||||
db 0x55, 0xaa
|
||||
|
|
Loading…
Reference in New Issue