Use uppercase non-struct constants for BPB
This commit is contained in:
parent
dc6035fe9d
commit
50aa6e4eec
4 changed files with 47 additions and 95 deletions
30
boot/fat.asm
30
boot/fat.asm
|
@ -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
|
||||
|
||||
|
|
12
boot/mbr.asm
12
boot/mbr.asm
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue