Add CHS+LBA dual support for boot sector
This commit is contained in:
parent
dc5e437c2d
commit
1e99086fc6
@ -54,7 +54,52 @@ readp: ; read sector DX:AX from partition
|
|||||||
add ax, word [bp+bpb_po]
|
add ax, word [bp+bpb_po]
|
||||||
adc dx, word [bp+bpb_po+2]
|
adc dx, word [bp+bpb_po+2]
|
||||||
jc dskerr
|
jc dskerr
|
||||||
read_: ; read sector DX:AX from disk
|
jmp [bp-2]
|
||||||
|
|
||||||
|
rchs: ; read sector DX:AX from disk
|
||||||
|
; uses basic CHS disk IO
|
||||||
|
; this cant reliable read over track boundaries
|
||||||
|
; so we read each single sector in loop over CX
|
||||||
|
chslp: push ax
|
||||||
|
push cx
|
||||||
|
push dx
|
||||||
|
push bx
|
||||||
|
|
||||||
|
; calculate CHS data
|
||||||
|
div word [bp+bpb_spt] ; ax:temp = (lba / spt)
|
||||||
|
inc dx ; dx:sector = (lba % spt) + 1
|
||||||
|
mov cl, dl ; sector number
|
||||||
|
xor dx, dx
|
||||||
|
div word [bp+bpb_nos] ; ax:cylinder = (tmp / heads)
|
||||||
|
; dx:head = (tmp % heads)
|
||||||
|
mov ch, al ; cylinder number
|
||||||
|
mov dh, dl ; head number
|
||||||
|
mov dl, [bp+bpb7_dn] ; drive number
|
||||||
|
|
||||||
|
; set up read buffer
|
||||||
|
mov es, bx
|
||||||
|
xor bx, bx
|
||||||
|
|
||||||
|
; call bios
|
||||||
|
mov ax, 0x0201
|
||||||
|
int 0x13
|
||||||
|
jc dskerr
|
||||||
|
|
||||||
|
pop bx
|
||||||
|
pop dx
|
||||||
|
pop cx
|
||||||
|
pop ax
|
||||||
|
|
||||||
|
; increment sector num + write offset
|
||||||
|
add ax, 1
|
||||||
|
adc dx, 0
|
||||||
|
add bx, 0x20
|
||||||
|
; loop on CX
|
||||||
|
loop chslp
|
||||||
|
ret
|
||||||
|
|
||||||
|
rebios: ; read sector DX:AX from disk
|
||||||
|
; this uses the EBIOS extensions
|
||||||
; qword sector number DX:AX
|
; qword sector number DX:AX
|
||||||
push cs
|
push cs
|
||||||
push cs
|
push cs
|
||||||
@ -153,6 +198,15 @@ l02e:
|
|||||||
|
|
||||||
ret
|
ret
|
||||||
|
|
||||||
|
loadr: mov ax, 2
|
||||||
|
xor dx, dx
|
||||||
|
jmp load
|
||||||
|
|
||||||
|
loadf: call search
|
||||||
|
jne fserr
|
||||||
|
mov ax, [si+0x1A]
|
||||||
|
mov dx, [si+0x14]
|
||||||
|
|
||||||
; load cluster chain DX:AX to [dest]:0
|
; load cluster chain DX:AX to [dest]:0
|
||||||
load: mov bx, 0x07C0
|
load: mov bx, 0x07C0
|
||||||
lloop: call readc
|
lloop: call readc
|
||||||
@ -179,18 +233,22 @@ loop: add si, 0x20
|
|||||||
jne loop
|
jne loop
|
||||||
ret
|
ret
|
||||||
|
|
||||||
loadr: mov ax, 2
|
|
||||||
xor dx, dx
|
|
||||||
jmp load
|
|
||||||
|
|
||||||
loadf: call search
|
|
||||||
jne fserr
|
|
||||||
mov ax, [si+0x1A]
|
|
||||||
mov dx, [si+0x14]
|
|
||||||
jmp load
|
|
||||||
|
|
||||||
main: mov bp, bpb
|
main: mov bp, bpb
|
||||||
mov [bp+bpb7_dn], dl
|
mov [bp+bpb7_dn], dl
|
||||||
|
|
||||||
|
; check if EBIOS is supported
|
||||||
|
mov bx, 0x55AA
|
||||||
|
mov ah, 0x41
|
||||||
|
stc
|
||||||
|
int 0x13
|
||||||
|
; default: use CHS read
|
||||||
|
mov ax, rchs
|
||||||
|
jc noebio
|
||||||
|
; if EBIOS: use LBA read
|
||||||
|
mov ax, rebios
|
||||||
|
noebio: lea di, [bp-2]
|
||||||
|
stosw
|
||||||
|
|
||||||
; load root directory
|
; load root directory
|
||||||
call loadr
|
call loadr
|
||||||
; search for first system directory
|
; search for first system directory
|
||||||
@ -213,7 +271,7 @@ main: mov bp, bpb
|
|||||||
pop si
|
pop si
|
||||||
pop ds
|
pop ds
|
||||||
|
|
||||||
jmp 0:0x7C00
|
jmp 0x7C00
|
||||||
|
|
||||||
; error handling for file not found
|
; error handling for file not found
|
||||||
fserr: call errcll
|
fserr: call errcll
|
||||||
|
Loading…
Reference in New Issue
Block a user