Use uppercase non-struct constants for BPB

This commit is contained in:
Nero 2020-10-25 09:15:33 +00:00
parent dc6035fe9d
commit 50aa6e4eec
4 changed files with 47 additions and 95 deletions

View File

@ -19,7 +19,7 @@ bootsect: equ 0x7C00 ; our origin before reloc
times ( 0x0B - ($-$$) ) db 0
params: times bpb_size db 0
bpb: times BPBSIZ4 db 0
; Area for BPB
times ( 0x3E - ($-$$) ) db 0
@ -54,15 +54,15 @@ read: push ax
push dx
xchg ax, bx
mov al, byte [bp+bpb.heads]
mul byte [bp+bpb.tracksectors]
mov al, byte [bp+BPBNOS]
mul byte [bp+BPBSPT]
xchg ax, bx
; dx:ax = lba
div word bx
xchg ax, dx
; dx = cylinder, ax = head * tracksectors + sector
div byte [bp+bpb.tracksectors]
div byte [bp+BPBSPT]
; dx = cylinder, al = head, ah = sector
xchg dl, dh
ror dl, 1
@ -92,7 +92,7 @@ read: push ax
loop read
ret
rootdirsects: mov bx, [bp+bpb.direntries]
rootdirsects: mov bx, [bp+BPBRDE]
mov cl, 4
shr bx, cl ; 32 bytes per entry
ret
@ -103,16 +103,16 @@ offset_cluster: ; add offset of cluster data area to DX:AX
adc dx, 0
offset_rootdir: ; add length of fat table times number of fats
xor ch, ch
mov cl, byte [bp+bpb.fatnumber]
.loop: add ax, [bp+bpb.fatsectors]
mov cl, byte [bp+BPBFN]
.loop: add ax, [bp+BPBFS]
adc dx, 0
loop .loop
offset_fat: ; add reserved sectors
add ax, [bp+bpb.reservedsects]
add ax, [bp+BPBRSC]
adc dx, 0
offset_part: ; add partition offset
add ax, [bp+bpb.sectoroffset]
add dx, [bp+bpb.sectoroffset+2]
add ax, [bp+BPBHS]
add dx, [bp+BPBHS]
ret
resetbuf: ; DS = ES
@ -127,7 +127,7 @@ resetbuf: ; DS = ES
xor dx, dx
ret
main: mov bp, params
main: mov bp, bpb
mov [bp-1], dl
; load root directory
@ -140,7 +140,7 @@ main: mov bp, params
; search for file
pop bx
mov cx, [bp+bpb.direntries]
mov cx, [bp+BPBRDE]
.loop: push cx
mov si, filename
mov di, bx
@ -156,7 +156,7 @@ main: mov bp, params
call resetbuf
push di
call offset_fat
mov cx, [bp+bpb.fatsectors]
mov cx, [bp+BPBFS]
call read
; fetch cluster numbers (FAT12-specific)
@ -189,10 +189,10 @@ readfat: stosw
loadclus: lodsw
sub ax, 2
jc .jump
mul byte [bp+bpb.clustersects]
mul byte [bp+BPBSC]
call offset_cluster
xor cx, cx
mov cl, [bp+bpb.clustersects]
mov cl, [bp+BPBSC]
call read
jmp loadclus

View File

@ -10,7 +10,7 @@
%include "inc/bpb.asm"
%define params bs+0x0B
%define bpb bs+0x0B
cpu 8086
org 0x0600
@ -72,11 +72,11 @@ main: ; find active partition
; FAT bpb has "bytes per sector" at this place
; we support only 512 byte sectors anyways
cmp word [params+bpb.sectorsize], 512
cmp word [bpb+BPBSS], 512
jne chain
; Media descriptor byte is never smaller than 0xF0
cmp byte [params+bpb.mediadesc], 0xF0
cmp byte [bpb+BPBMD], 0xF0
jc chain
; ask BIOS what our disk geometry is
@ -92,17 +92,17 @@ main: ; find active partition
; update sectors per track
xor ax, ax
mov al, cl
mov [params+bpb.tracksectors], ax
mov [bpb+BPBSPT], ax
; update number of sides
xor ax, ax
mov al, dh
mov [params+bpb.heads], ax
mov [bpb+BPBNOS], ax
; update partition offset
push si
add si, 0x08
mov di, params+bpb.sectoroffset
mov di, bpb+BPBHS
movsw
movsw
pop si

View File

@ -1,14 +1,26 @@
struc bpb
.sectorsize: resw 1 ; WORD sector size
.clustersects: resb 1 ; BYTE sector / cluster
.reservedsects: resw 1 ; WORD reserved sector count
.fatnumber: resb 1 ; BYTE fat number
.direntries: resw 1 ; WORD root dir entries
.total: resw 1 ; WORD total sectors
.mediadesc: resb 1 ; BYTE media descriptor
.fatsectors: resw 1 ; WORD sectors / fat
.tracksectors: resw 1 ; WORD sectors per track
.heads: resw 1 ; WORD number of sides
.sectoroffset: resd 1 ; DWORD partition offset
.longtotal: resd 1 ; DWORD large total sectors
endstruc
BPBOFF equ 0xB
; DOS 2.0 BPB
BPBSS equ 0 ; word
BPBSC equ 2 ; byte
BPBRSC equ 3 ; word
BPBFN equ 5 ; byte
BPBRDE equ 6 ; word
BPBTS equ 8 ; word
BPBMD equ 10 ; byte
BPBFS equ 11 ; word
BPBSIZ2 equ 13 ; size constant
; DOS 3.31 BPB
BPBSPT equ 0x0D ; word
BPBNOS equ 0x0F ; word
BPBHS equ 0x11 ; dword
BPBLTS equ 0x15 ; dword
BPBSIZ3 equ 25 ; size constant
; DOS 3.4 EBPB
BPBDN equ 0x19 ; byte
BPBFALG equ 0x1A ; byte
BPBSIG equ 0x1B ; byte
BPBSER equ 0x1C ; dword serial number
BPBSIZ4 equ 32 ; size constant

View File

@ -1,60 +0,0 @@
section .text
load_bpb: mov bx, [drive_ptr]
; read word for "sectors per fat"
mov ax, [diskbuf+0x016]
xor dx, dx
; if zero, we need to check dword in BPB 7.1
test ax, ax
jnz .short_sf
; fail if BPB 7.1 signature is not present
mov cl, [diskbuf+0x042]
or cl, 1
cmp cl, 0x29
jne .err
; load dword
mov ax, [diskbuf+0x024]
mov dx, [diskbuf+0x026]
.short_sf:
; store local value
mov [bx+drive.fat_size], ax
mov [bx+drive.fat_size+2], dx
; copy number of fat's
xor ah, ah
mov al, [diskbuf+0x010]
mov [bx+drive.fat_num], ax
; copy number of root directory entries
mov ax, [diskbuf+0x011]
mov cl, 4
shr ax, cl
mov [bx+drive.dir_size], ax
; calculate offsets for everything
xor ax, ax
xor dx, dx
; add reserved sectors
add ax, [diskbuf+0x0B+bpb_rsc]
adc ax, 0
; save begin of FAT tables
mov [bx+drive.fat_offset], ax
mov [bx+drive.fat_offset+2], dx
; add FAT size * FAT number
mov cx, [bx+drive.fat_num]
.floop: add ax, [bx+drive.fat_size]
adc dx, [bx+drive.fat_size+2]
loop .floop
; save begin of root directories
mov [bx+drive.dir_offset], ax
mov [bx+drive.dir_offset+2], dx
; add root directory size (might be zero)
add ax, [bx+drive.dir_size]
adc dx, 0
; save start of data area
mov [bx+drive.clus_offset], ax
mov [bx+drive.clus_offset+2], dx
ret
.err: stc
ret