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