mirror of
https://github.com/limine-bootloader/limine
synced 2025-01-06 04:42:16 +03:00
Add protective BPB in bootsector and check for the presence of int 13h extensions before using them
This commit is contained in:
parent
b16f63458d
commit
8760c0b3d6
@ -1,10 +1,17 @@
|
|||||||
org 0x7c00
|
org 0x7c00
|
||||||
bits 16
|
bits 16
|
||||||
|
|
||||||
jmp start ; Workaround for some BIOSes that require this stub
|
|
||||||
nop
|
|
||||||
|
|
||||||
start:
|
start:
|
||||||
|
jmp .skip_bpb ; Workaround for some BIOSes that require this stub
|
||||||
|
nop
|
||||||
|
|
||||||
|
; Some BIOSes will do a funny and decide to overwrite bytes of code in
|
||||||
|
; the section where a FAT BPB would be, potentially overwriting
|
||||||
|
; bootsector code.
|
||||||
|
; Avoid that by filling the BPB area with 0s
|
||||||
|
times 87 db 0
|
||||||
|
|
||||||
|
.skip_bpb:
|
||||||
cli
|
cli
|
||||||
cld
|
cld
|
||||||
jmp 0x0000:.initialise_cs
|
jmp 0x0000:.initialise_cs
|
||||||
@ -12,10 +19,8 @@ start:
|
|||||||
xor ax, ax
|
xor ax, ax
|
||||||
mov ds, ax
|
mov ds, ax
|
||||||
mov es, ax
|
mov es, ax
|
||||||
mov fs, ax
|
|
||||||
mov gs, ax
|
|
||||||
mov ss, ax
|
mov ss, ax
|
||||||
mov esp, 0x4000
|
mov sp, 0x4000
|
||||||
sti
|
sti
|
||||||
|
|
||||||
; Some BIOSes don't pass the correct boot drive number,
|
; Some BIOSes don't pass the correct boot drive number,
|
||||||
@ -41,19 +46,26 @@ start:
|
|||||||
|
|
||||||
; ****************** Load stage 1.5 ******************
|
; ****************** Load stage 1.5 ******************
|
||||||
|
|
||||||
mov si, Stage15Msg
|
; Make sure int 13h extensions are supported
|
||||||
call simple_print
|
mov ah, 0x41
|
||||||
|
mov bx, 0x55aa
|
||||||
|
int 0x13
|
||||||
|
jc err_reading_disk
|
||||||
|
cmp bx, 0xaa55
|
||||||
|
jne err_reading_disk
|
||||||
|
|
||||||
|
; If int 13h extensions are supported, then we are definitely running on
|
||||||
|
; a 386+. We have no idea whether the upper 16 bits of esp are cleared, so
|
||||||
|
; make sure that is the case now.
|
||||||
|
mov esp, 0x4000
|
||||||
|
|
||||||
mov eax, dword [stage15_sector]
|
mov eax, dword [stage15_sector]
|
||||||
mov ebx, 0x7e00
|
mov bx, 0x7e00
|
||||||
mov ecx, 1
|
mov cx, 1
|
||||||
call read_sectors
|
call read_sectors
|
||||||
|
|
||||||
jc err_reading_disk
|
jc err_reading_disk
|
||||||
|
|
||||||
mov si, DoneMsg
|
|
||||||
call simple_print
|
|
||||||
|
|
||||||
jmp 0x7e00
|
jmp 0x7e00
|
||||||
|
|
||||||
err_reading_disk:
|
err_reading_disk:
|
||||||
@ -73,10 +85,8 @@ halt:
|
|||||||
; Data
|
; Data
|
||||||
|
|
||||||
LoadingMsg db 0x0D, 0x0A, 'Limine', 0x0D, 0x0A, 0x0A, 0x00
|
LoadingMsg db 0x0D, 0x0A, 'Limine', 0x0D, 0x0A, 0x0A, 0x00
|
||||||
Stage15Msg db 'Loading stage 1.5...', 0x00
|
ErrReadDiskMsg db 0x0D, 0x0A, 'Disk err', 0x00
|
||||||
ErrReadDiskMsg db 0x0D, 0x0A, 'Disk read error, system halted', 0x00
|
ErrEnableA20Msg db 0x0D, 0x0A, 'A20 err', 0x00
|
||||||
ErrEnableA20Msg db 0x0D, 0x0A, 'A20 enable error, system halted', 0x00
|
|
||||||
DoneMsg db ' DONE', 0x0D, 0x0A, 0x00
|
|
||||||
|
|
||||||
times 0xda-($-$$) db 0
|
times 0xda-($-$$) db 0
|
||||||
times 6 db 0
|
times 6 db 0
|
||||||
@ -101,8 +111,8 @@ stage15:
|
|||||||
pop es
|
pop es
|
||||||
mov eax, dword [stage15_sector]
|
mov eax, dword [stage15_sector]
|
||||||
inc eax
|
inc eax
|
||||||
xor ebx, ebx
|
xor bx, bx
|
||||||
mov ecx, 62
|
mov cx, 62
|
||||||
call read_sectors
|
call read_sectors
|
||||||
pop es
|
pop es
|
||||||
jc err_reading_disk
|
jc err_reading_disk
|
||||||
|
Loading…
Reference in New Issue
Block a user