vbr: work in progress on block reading
This commit is contained in:
parent
391a1aa7d5
commit
c88395c12d
184
boot/vbr.asm
184
boot/vbr.asm
@ -1,57 +1,104 @@
|
|||||||
org 0x7C00
|
org 0x7C00
|
||||||
|
|
||||||
bpb:
|
fdc: ; FDC Descriptor as per ECMA-107
|
||||||
jmp _startup ; 2 bytes
|
jmp _startup
|
||||||
nop ; 1 byte
|
times (0x03 - ($-$$)) nop
|
||||||
.oem:
|
.oem:
|
||||||
db "OEM " ; OEM
|
db "2B" ; creating system identifier
|
||||||
.bps:
|
times (0x0B - ($-$$)) db " " ; space-padded
|
||||||
dw 0x200 ; bytes per sector
|
.ss:
|
||||||
.spc:
|
dw 0x200 ; sector size
|
||||||
db 1 ; sectors per cluster
|
.sc:
|
||||||
.rsectors:
|
db 0 ; sectors per cluster
|
||||||
dw 2 ; number of reserved sectors
|
.rsc:
|
||||||
.fats:
|
dw 2 ; reserved sector count
|
||||||
db 2 ; number of file allocation tables
|
.fn:
|
||||||
.dirents:
|
db 0 ; number of file allocation tables
|
||||||
dw 2 ; Number of directory entries
|
.rde:
|
||||||
.sectors:
|
dw 0 ; number of root directory entries
|
||||||
dw 720 ; total number of sectors
|
.ts_old:
|
||||||
.mtd: ; media descriptor type
|
dw 0 ; legacy: total number of sectors
|
||||||
|
.mi: ; medium identifier
|
||||||
db 0xFD ; 5.25-inch Double sided, 40 tracks per side, 9 sectors per track (360 KB)
|
db 0xFD ; 5.25-inch Double sided, 40 tracks per side, 9 sectors per track (360 KB)
|
||||||
.spfat: ; sectors per fat
|
.sf: ; sectors per fat
|
||||||
dw 0
|
dw 0
|
||||||
.spt:
|
.spt:
|
||||||
dw 9 ; sectors per track
|
dw 9 ; sectors per track
|
||||||
.heads:
|
.nos:
|
||||||
dw 2 ; number of heads
|
dw 2 ; number of sides (heads)
|
||||||
.hidsecs:
|
.po:
|
||||||
dd 0 ; number of hidden sectors
|
dd 0 ; partition offset (in LBA blocks)
|
||||||
.lrgsectors:
|
.ts:
|
||||||
dd 0 ; large sector count
|
dw 720
|
||||||
.drivenum:
|
.drv:
|
||||||
db 0 ; drive number
|
db 0 ; drive number
|
||||||
.winntflags:
|
|
||||||
db 0
|
db 0
|
||||||
.signature:
|
db 0x29 ; efdc signature
|
||||||
db 0x28
|
.vid:
|
||||||
|
dd 0 ; volume id
|
||||||
times (0x5A - ($-$$)) nop
|
.vlabel:
|
||||||
|
db "2B"
|
||||||
|
times (54 - ($-$$)) db " "
|
||||||
|
.fstype:
|
||||||
|
db "FAT12"
|
||||||
|
times (62 - ($-$$)) db " "
|
||||||
|
|
||||||
_startup:
|
_startup:
|
||||||
call adjust_bpb
|
mov [fdc.drv], dl ; backup driver number
|
||||||
|
mov ah, 0x08
|
||||||
|
int 0x13 ; required, QEMU detects 360kB as 1200kB with CHS 80 2 15
|
||||||
|
jc .noadjust ; skip if function does not exist
|
||||||
|
inc dh
|
||||||
|
mov [fdc.nos], dh
|
||||||
|
mov ax, cx
|
||||||
|
and ax, 0x003F
|
||||||
|
mov [fdc.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 [fdc.nos] ; number of tracks = number of cylinders * heads
|
||||||
|
mul word [fdc.spt] ; number of sectors = number of tracks * sectors per track
|
||||||
|
mov [fdc.ts], ax
|
||||||
|
.noadjust:
|
||||||
mov ax, 0x0500
|
mov ax, 0x0500
|
||||||
mov es, ax
|
mov es, ax
|
||||||
|
mov bx, 0x0000
|
||||||
mov si, 1
|
mov ax, 1
|
||||||
mov di, 0x7D00
|
|
||||||
mov cx, 0x10
|
|
||||||
call loadblk
|
call loadblk
|
||||||
call dump
|
call dump
|
||||||
|
|
||||||
|
mov al, [fdc.sc]
|
||||||
|
call print8
|
||||||
.end:
|
.end:
|
||||||
hlt
|
hlt
|
||||||
jmp .end
|
jmp .end
|
||||||
|
|
||||||
|
; Load a cluster from cluster offset
|
||||||
|
loadcluster:
|
||||||
|
ret
|
||||||
|
|
||||||
|
; Load a single cluster into memory
|
||||||
|
; in ax sector number
|
||||||
|
; es:bx buffer
|
||||||
|
; out al error code,
|
||||||
|
; carry set if error
|
||||||
|
loadblk:
|
||||||
|
xor dx, dx
|
||||||
|
div word [fdc.spt] ; ax:temp = (lba / spt)
|
||||||
|
inc dx ; dx:sector = (lba % spt) + 1
|
||||||
|
mov cl, dl ; sector number
|
||||||
|
xor dx, dx
|
||||||
|
div word [fdc.nos] ; ax:cylinder = (tmp / heads)
|
||||||
|
; dx:head = (tmp % heads)
|
||||||
|
mov ch, al ; cylinder number
|
||||||
|
mov dh, dl ; head number
|
||||||
|
mov dl, [fdc.drv] ; driver number
|
||||||
|
mov ax, 0x0201 ; ah=0x02 al=0x01
|
||||||
|
int 0x13
|
||||||
|
ret
|
||||||
|
|
||||||
dump:
|
dump:
|
||||||
mov si, 0x0000
|
mov si, 0x0000
|
||||||
mov cx, 0x10
|
mov cx, 0x10
|
||||||
@ -80,73 +127,6 @@ dump:
|
|||||||
|
|
||||||
ret
|
ret
|
||||||
|
|
||||||
; Adjust the bdp data from BIOS-supplied data (if)
|
|
||||||
; No args, no output
|
|
||||||
adjust_bpb:
|
|
||||||
push ax
|
|
||||||
push cx
|
|
||||||
push dx
|
|
||||||
mov ah, 0x08
|
|
||||||
int 0x13 ; required, QEMU detects 360kB as 1200kB with CHS 80 2 15
|
|
||||||
jc .end ; skip if function does not exist
|
|
||||||
inc dh
|
|
||||||
mov [bpb.heads], dh
|
|
||||||
mov ax, cx
|
|
||||||
and ax, 0x003F
|
|
||||||
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
|
|
||||||
.end:
|
|
||||||
pop dx
|
|
||||||
pop cx
|
|
||||||
pop ax
|
|
||||||
ret
|
|
||||||
|
|
||||||
; in si sector number,
|
|
||||||
; dl drive number
|
|
||||||
; es:0000 buffer
|
|
||||||
; out al error code,
|
|
||||||
; carry set if error
|
|
||||||
loadblk:
|
|
||||||
push bx
|
|
||||||
push cx
|
|
||||||
push dx
|
|
||||||
xor dx, dx
|
|
||||||
mov ax, si
|
|
||||||
div word [bpb.spt] ; ax:temp = (lba / spt)
|
|
||||||
inc dx ; dx:sector = (lba % spt) + 1
|
|
||||||
mov cl, dl ; for int 0x13
|
|
||||||
xor dx, dx
|
|
||||||
div word [bpb.heads] ; ax:cylinder = (tmp / heads)
|
|
||||||
; dx:head = (tmp % heads)
|
|
||||||
mov ch, al ; for int 0x13
|
|
||||||
mov ax, dx
|
|
||||||
pop dx ; drive number comes back into dl
|
|
||||||
mov dh, al ; for int 0x13
|
|
||||||
|
|
||||||
mov bx, 0x0000
|
|
||||||
mov ax, 0x0201 ; ah=0x02 al=0x01
|
|
||||||
int 0x13
|
|
||||||
|
|
||||||
call print16
|
|
||||||
lahf
|
|
||||||
xchg ah, al
|
|
||||||
call print8
|
|
||||||
mov al, 0x0A
|
|
||||||
call printc
|
|
||||||
mov al, 0x0D
|
|
||||||
call printc
|
|
||||||
|
|
||||||
pop cx
|
|
||||||
pop bx
|
|
||||||
ret
|
|
||||||
|
|
||||||
%include "print.asm"
|
%include "print.asm"
|
||||||
|
|
||||||
times (0x1FE - ($-$$)) nop
|
times (0x1FE - ($-$$)) nop
|
||||||
|
Loading…
Reference in New Issue
Block a user