vbr: Parse CHS from BIOS to optionally overwrite hardcoded CHS data
This commit is contained in:
parent
2229c319b6
commit
96234c2a40
59
boot/vbr.asm
59
boot/vbr.asm
@ -4,18 +4,18 @@ bpb:
|
||||
jmp _startup ; 2 bytes
|
||||
nop ; 1 byte
|
||||
.oem:
|
||||
db "2A " ; OEM
|
||||
db "OEM " ; OEM
|
||||
.bps:
|
||||
dw 0x200 ; bytes per sector
|
||||
.spc:
|
||||
db 1 ; sectors per cluster
|
||||
.rsectors:
|
||||
dw 2 ; number of reserved sectors
|
||||
.fatcnt:
|
||||
.fats:
|
||||
db 2 ; number of file allocation tables
|
||||
.dirents:
|
||||
dw 2 ; Number of directory entries
|
||||
.seccnt:
|
||||
.sectors:
|
||||
dw 720 ; total number of sectors
|
||||
.mtd: ; media descriptor type
|
||||
db 0xFD ; 5.25-inch Double sided, 40 tracks per side, 9 sectors per track (360 KB)
|
||||
@ -23,26 +23,69 @@ bpb:
|
||||
dw 0
|
||||
.spt:
|
||||
dw 9 ; sectors per track
|
||||
.headcnt:
|
||||
.heads:
|
||||
dw 2 ; number of heads
|
||||
.hidseccnt:
|
||||
.hidsecs:
|
||||
dd 0 ; number of hidden sectors
|
||||
.lrgseccnt:
|
||||
.lrgsectors:
|
||||
dd 0 ; large sector count
|
||||
|
||||
times (0x3E - ($-$$)) nop
|
||||
|
||||
_startup:
|
||||
call printgeo
|
||||
mov ah, 0x08
|
||||
mov dl, 0x00
|
||||
int 0x13
|
||||
int 0x13 ; required, QEMU detects 360kB as 1200kB with CHS 80 2 15
|
||||
jc .noadjust
|
||||
inc dh
|
||||
mov [bpb.heads], dh
|
||||
mov ax, cx
|
||||
and ax, 0x003F
|
||||
call print16
|
||||
mov [bpb.spt], ax ; no adjustment because sectors are 1-indexed
|
||||
mov ax, cx
|
||||
xchg al, ah
|
||||
mov cl,6
|
||||
shr ah,cl
|
||||
inc ax ; convert from maximum number (0-based) to total number (1-based) of cylinders
|
||||
mul word [bpb.heads] ; number of tracks = number of cylinders * heads
|
||||
mul word [bpb.spt] ; number of sectors = number of tracks * sectors per track
|
||||
mov [bpb.sectors], ax
|
||||
.noadjust:
|
||||
call printgeo
|
||||
.end:
|
||||
hlt
|
||||
jmp .end
|
||||
|
||||
printgeo:
|
||||
mov ax, [bpb.heads]
|
||||
call print16
|
||||
mov ax, [bpb.spt]
|
||||
call print16
|
||||
mov ax, [bpb.sectors]
|
||||
call print16
|
||||
mov al, 0x0A
|
||||
call printc
|
||||
mov al, 0x0D
|
||||
call printc
|
||||
ret
|
||||
|
||||
; in bx sector number,
|
||||
; dl drive number
|
||||
; ds:di buffer
|
||||
; out al error code,
|
||||
; carry set if error
|
||||
loadblk:
|
||||
mov ax, bx
|
||||
div byte [bpb.spt]
|
||||
call print16
|
||||
; Temp = LBA / (Sectors per Track)
|
||||
; Sector = (LBA % (Sectors per Track)) + 1
|
||||
; Head = Temp % (Number of Heads)
|
||||
; Cylinder = Temp / (Number of Heads)
|
||||
|
||||
ret
|
||||
|
||||
%include "print.asm"
|
||||
|
||||
times (0x1FE - ($-$$)) nop
|
||||
|
Loading…
Reference in New Issue
Block a user