mirror of
https://gitlab.com/bztsrc/bootboot.git
synced 2023-02-13 20:54:32 -05:00
Removed int13/AX=4B01 as it's buggy on some BIOSes
This commit is contained in:
parent
0cab242a9d
commit
dd0d222cc4
5 changed files with 55 additions and 54 deletions
BIN
dist/boot.bin
vendored
BIN
dist/boot.bin
vendored
Binary file not shown.
BIN
dist/bootboot.bin
vendored
BIN
dist/bootboot.bin
vendored
Binary file not shown.
File diff suppressed because one or more lines are too long
|
@ -33,6 +33,7 @@
|
|||
;*********************************************************************
|
||||
|
||||
;LBA packet fields
|
||||
lba_packet equ 07E00h
|
||||
virtual at lba_packet
|
||||
lbapacket.size: dw ?
|
||||
lbapacket.count:dw ?
|
||||
|
@ -72,10 +73,9 @@ end if
|
|||
bootboot_record:
|
||||
jmp short .skipid
|
||||
nop
|
||||
.system: db "BOOTBOOT",0
|
||||
;skip BPB area so that we can use this
|
||||
;boot code on a FAT volume if needed
|
||||
db 05Ah-($-$$) dup 0
|
||||
;boot code on a FAT / exFAT volume if needed
|
||||
db 120-($-$$) dup 0
|
||||
.skipid: ;relocate our code to offset 0h:600h
|
||||
cli
|
||||
cld
|
||||
|
@ -105,9 +105,6 @@ bootboot_record:
|
|||
|
||||
.start: ;save boot drive code
|
||||
mov byte [drive], dl
|
||||
;initialize lba packet
|
||||
mov byte [lbapacket.size], 16
|
||||
mov byte [lbapacket.addr0+1], 08h ;to address 800h
|
||||
;check for lba presistance - floppy not supported any more
|
||||
;we use USB sticks as removable media for a long time
|
||||
cmp dl, byte 80h
|
||||
|
@ -125,27 +122,23 @@ bootboot_record:
|
|||
jmp diefunc
|
||||
.lbaok: ;try to load stage2 - it's a continous area on disk
|
||||
;started at given sector with maximum size of 7000h bytes
|
||||
mov di, lba_packet
|
||||
mov cx, 8
|
||||
xor ax, ax
|
||||
repnz stosw
|
||||
mov si, stage2_addr
|
||||
mov di, lbapacket.sect0
|
||||
push bx
|
||||
push di
|
||||
;set up for hard-drive
|
||||
movsw
|
||||
movsw
|
||||
mov byte [lbapacket.size], 16
|
||||
mov byte [lbapacket.addr0+1], 08h ;to address 800h
|
||||
mov byte [lbapacket.count], 56
|
||||
;query cdrom status to see if it's a cdrom
|
||||
mov ax, word 4B01h
|
||||
mov dl, byte [drive]
|
||||
mov si, spc_packet
|
||||
mov byte [si], 13h
|
||||
mov byte [si+2], 0h ;clear drive number
|
||||
clc
|
||||
int 13h
|
||||
pop di
|
||||
jc @f
|
||||
;some buggy BIOSes (like bochs') fail to set carry flag and ax properly
|
||||
cmp byte [spc_packet+2], 0h
|
||||
jz @f
|
||||
;if it's a CDROM with 2048 byte sectors
|
||||
cmp dl, 0E0h
|
||||
jl @f
|
||||
sub di, 4
|
||||
;lba=lba/4
|
||||
clc
|
||||
rcr word [di+2], 1
|
||||
|
@ -153,28 +146,33 @@ bootboot_record:
|
|||
clc
|
||||
rcr word [di+2], 1
|
||||
rcr word [di], 1
|
||||
mov byte [lbapacket.count], 14
|
||||
shr word [lbapacket.count], 2
|
||||
;load sectors
|
||||
@@: mov ah, byte 42h
|
||||
mov dl, byte [drive]
|
||||
mov si, lba_packet
|
||||
int 13h
|
||||
pop bx
|
||||
|
||||
;do we have a 2nd stage loader?
|
||||
.chk: cmp word [ldr.header], bx
|
||||
.chk: cmp word [ldr.header], 0AA55h
|
||||
jne .nostage2
|
||||
cmp byte [ldr.header+3], 0E9h
|
||||
jne .nostage2
|
||||
mov dl, byte [drive]
|
||||
;invoke stage2 real mode code
|
||||
mov ax, [ldr.executor]
|
||||
add ax, ldr.executor+3
|
||||
jmp ax
|
||||
|
||||
.nostage2: ;try to load stage2 from a RAID mirror
|
||||
inc byte [drive]
|
||||
cmp byte [drive], 8Fh
|
||||
jle .lbaok
|
||||
mov al, byte [drive]
|
||||
inc al
|
||||
cmp al, 87h
|
||||
jle @f
|
||||
mov al, 80h
|
||||
@@: mov byte [drive], al
|
||||
inc byte [cnt]
|
||||
cmp byte [cnt], 8
|
||||
jl .lbaok
|
||||
.nostage2err:
|
||||
mov si, stage2notf
|
||||
;fall into the diefunc code
|
||||
|
@ -184,7 +182,6 @@ bootboot_record:
|
|||
;*********************************************************************
|
||||
;writes the reason, waits for a key and reboots.
|
||||
diefunc:
|
||||
print bootboot_record.system
|
||||
print panic
|
||||
call printfunc
|
||||
mov si, found
|
||||
|
@ -211,13 +208,12 @@ printfunc:
|
|||
;* data area *
|
||||
;*********************************************************************
|
||||
|
||||
panic: db "-PANIC: ",0
|
||||
panic: db "BOOTBOOT-PANIC: ",0
|
||||
lbanotf: db "LBA support",0
|
||||
stage2notf: db "FS0:\BOOTBOOT\LOADER",0
|
||||
found: db " not found",10,13,0
|
||||
found: db " not found",0
|
||||
cnt: db 0
|
||||
drive: db 0
|
||||
lba_packet: db 16 dup 0
|
||||
spc_packet: db 13h dup 0
|
||||
db 01B0h-($-$$) dup 0
|
||||
|
||||
;right before the partition table some data
|
||||
|
|
|
@ -804,6 +804,8 @@ real_diefunc:
|
|||
real_print panic
|
||||
pop si
|
||||
call real_printfunc
|
||||
mov si, crlf
|
||||
call real_printfunc
|
||||
call real_getchar
|
||||
mov al, 0FEh
|
||||
out 64h, al
|
||||
|
@ -908,23 +910,17 @@ prot_readsectorfunc:
|
|||
;load 8 sectors (1 page) or more in low memory
|
||||
mov dword [lbapacket.sect0], eax
|
||||
prot_realmode
|
||||
;try all drives from bootdev-8F to support RAID mirror
|
||||
;try all drives from bootdev-87 to support RAID mirror
|
||||
mov dl, byte [bootdev]
|
||||
mov byte [readdev], dl
|
||||
mov byte [cntdev], 0
|
||||
mov byte [iscdrom], 0
|
||||
.again: mov ax, word [lbapacket.count]
|
||||
mov word [origcount], ax
|
||||
;query cdrom status to see if it's a cdrom
|
||||
mov ax, word 4B01h
|
||||
mov dl, byte [readdev]
|
||||
mov esi, spc_packet
|
||||
mov byte [si], 13h
|
||||
mov byte [si+2], 0h ;clear drive number
|
||||
clc
|
||||
int 13h
|
||||
jc @f
|
||||
;some buggy BIOSes (like bochs') fail to set carry flag and ax properly
|
||||
cmp byte [spc_packet+2], 0h
|
||||
jz @f
|
||||
;don't use INT 13h / AX=4B01h, that's buggy on many BIOSes
|
||||
cmp dl, 0E0h
|
||||
jl @f
|
||||
;use 2048 byte sectors instead of 512 if it's a cdrom
|
||||
mov al, byte [lbapacket.sect0]
|
||||
and al, 011b
|
||||
|
@ -932,7 +928,7 @@ prot_readsectorfunc:
|
|||
jz .cdok
|
||||
;this should never happen.
|
||||
; - GPT is loaded from PMBR, from LBA 0 (%4==0)
|
||||
; - ESP is at LBA 128 (%4==0)
|
||||
; - ESP is at LBA 128 or 2048 (%4==0)
|
||||
; - root dir is at LBA 172 (%4==0) for FAT16, and it's cluster aligned for FAT32
|
||||
; - cluster size is multiple of 4 sectors
|
||||
mov si, notcdsect
|
||||
|
@ -941,16 +937,23 @@ prot_readsectorfunc:
|
|||
add word [lbapacket.count], 3
|
||||
shr word [lbapacket.count], 2
|
||||
mov byte [iscdrom], 1
|
||||
@@: mov dl, byte [readdev]
|
||||
inc byte [readdev]
|
||||
mov ah, byte 42h
|
||||
@@: mov ah, byte 42h
|
||||
mov esi, lbapacket
|
||||
clc
|
||||
int 13h
|
||||
jnc @f
|
||||
cmp byte [readdev], 08Fh
|
||||
jnc .rdok
|
||||
;we do not expect this to fail, but if so, load sector from another
|
||||
;drive assuming we have a RAID mirror. This will fail for non-RAIDs
|
||||
mov al, byte [readdev]
|
||||
inc al
|
||||
cmp al, 87h
|
||||
jle @f
|
||||
mov al, 80h
|
||||
@@: mov byte [readdev], al
|
||||
inc byte [cntdev]
|
||||
cmp byte [cntdev], 8
|
||||
jle .again
|
||||
@@: xor ebx, ebx
|
||||
.rdok: xor ebx, ebx
|
||||
mov bl, ah
|
||||
real_protmode
|
||||
pop edi
|
||||
|
@ -2662,6 +2665,7 @@ clu_sec: dd 0 ;sector per cluster
|
|||
origcount: dw 0
|
||||
bootdev: db 0
|
||||
readdev: db 0
|
||||
cntdev: db 0
|
||||
hasinitrd: db 0
|
||||
hasconfig: db 0
|
||||
iscdrom: db 0
|
||||
|
@ -2690,7 +2694,8 @@ backup: db " * Backup initrd",10,13,0
|
|||
passphrase: db " * Passphrase? ",0
|
||||
decrypting: db 13," * Decrypting...",0
|
||||
clrdecrypt: db 13," ",13,0
|
||||
starting: db "Booting OS...",10,13,0
|
||||
starting: db "Booting OS..."
|
||||
crlf: db 10,13,0
|
||||
panic: db "-PANIC: ",0
|
||||
noarch: db "Hardware not supported",0
|
||||
a20err: db "Failed to enable A20",0
|
||||
|
|
Loading…
Reference in a new issue