stage1: hdd bootsect: Properly guard against image being booted as floppy drive

This commit is contained in:
mintsuki 2021-05-20 23:19:24 +02:00
parent 110d2dc7d4
commit d67ce23b77
1 changed files with 12 additions and 17 deletions

View File

@ -16,29 +16,24 @@ start:
cld cld
jmp 0x0000:.initialise_cs jmp 0x0000:.initialise_cs
.initialise_cs: .initialise_cs:
xor ax, ax xor bx, bx
mov ds, ax mov ds, bx
mov es, ax mov es, bx
mov ss, ax mov ss, bx
mov sp, 0x7c00 mov sp, 0x7c00
sti sti
; Some BIOSes don't pass the correct boot drive number,
; so we need to do the job
.check_drive:
; Limine isn't made for floppy disks, these are dead anyways. ; Limine isn't made for floppy disks, these are dead anyways.
; So if the value the BIOS passed is <0x80, just assume it has passed ; So if the value the BIOS passed is <0x80, just assume it has passed
; an incorrect value ; an incorrect value.
test dl, 0x80 cmp dl, 0x80
jz .fix_drive jae .continue
; Drive numbers from 0x80..0x8f should be valid ; Error out (BX zeroed out above)
test dl, 0x70 push 0xb800
jz .continue pop es
mov dword [es:bx], 'F ! '
.fix_drive: jmp err
; Try to fix up the mess the BIOS have done
mov dl, 0x80
.continue: .continue:
; Make sure int 13h extensions are supported ; Make sure int 13h extensions are supported