vbr: CHS reading seems to work so far

This commit is contained in:
Nero 2019-03-26 20:46:40 +00:00
parent 96234c2a40
commit 391a1aa7d5
2 changed files with 91 additions and 31 deletions

View File

@ -7,8 +7,7 @@ vbr.bin: boot/vbr.asm
nasm -s -o $@ -I lib $< nasm -s -o $@ -I lib $<
fdimage.img: vbr.bin kernel.com fdimage.img: vbr.bin kernel.com
dd if=/dev/zero bs=512 count=720 of=$@ cat vbr.bin kernel.com > $@
dd if=vbr.bin bs=512 count=1 conv=notrunc of=$@
clean: clean:
rm -f *.com rm -f *.com

View File

@ -29,15 +29,66 @@ bpb:
dd 0 ; number of hidden sectors dd 0 ; number of hidden sectors
.lrgsectors: .lrgsectors:
dd 0 ; large sector count dd 0 ; large sector count
.drivenum:
db 0 ; drive number
.winntflags:
db 0
.signature:
db 0x28
times (0x3E - ($-$$)) nop times (0x5A - ($-$$)) nop
_startup: _startup:
call printgeo call adjust_bpb
mov ax, 0x0500
mov es, ax
mov si, 1
mov di, 0x7D00
mov cx, 0x10
call loadblk
call dump
.end:
hlt
jmp .end
dump:
mov si, 0x0000
mov cx, 0x10
.nextline:
mov ax, si
call print16
mov al, 0x3A
call printc
mov al, 0x20
call printc
push cx
mov cx, 0x0020
.words:
es lodsb
call print8
loop .words
pop cx
mov al, 0x0A
call printc
mov al, 0x0D
call printc
loop .nextline
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 mov ah, 0x08
mov dl, 0x00
int 0x13 ; required, QEMU detects 360kB as 1200kB with CHS 80 2 15 int 0x13 ; required, QEMU detects 360kB as 1200kB with CHS 80 2 15
jc .noadjust jc .end ; skip if function does not exist
inc dh inc dh
mov [bpb.heads], dh mov [bpb.heads], dh
mov ax, cx mov ax, cx
@ -51,39 +102,49 @@ _startup:
mul word [bpb.heads] ; number of tracks = number of cylinders * heads mul word [bpb.heads] ; number of tracks = number of cylinders * heads
mul word [bpb.spt] ; number of sectors = number of tracks * sectors per track mul word [bpb.spt] ; number of sectors = number of tracks * sectors per track
mov [bpb.sectors], ax mov [bpb.sectors], ax
.noadjust:
call printgeo
.end: .end:
hlt pop dx
jmp .end 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
printgeo:
mov ax, [bpb.heads]
call print16
mov ax, [bpb.spt]
call print16
mov ax, [bpb.sectors]
call print16 call print16
lahf
xchg ah, al
call print8
mov al, 0x0A mov al, 0x0A
call printc call printc
mov al, 0x0D mov al, 0x0D
call printc 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)
pop cx
pop bx
ret ret
%include "print.asm" %include "print.asm"