Use uppercase non-struct constants for BPB
This commit is contained in:
parent
dc6035fe9d
commit
50aa6e4eec
30
boot/fat.asm
30
boot/fat.asm
@ -19,7 +19,7 @@ bootsect: equ 0x7C00 ; our origin before reloc
|
|||||||
|
|
||||||
times ( 0x0B - ($-$$) ) db 0
|
times ( 0x0B - ($-$$) ) db 0
|
||||||
|
|
||||||
params: times bpb_size db 0
|
bpb: times BPBSIZ4 db 0
|
||||||
|
|
||||||
; Area for BPB
|
; Area for BPB
|
||||||
times ( 0x3E - ($-$$) ) db 0
|
times ( 0x3E - ($-$$) ) db 0
|
||||||
@ -54,15 +54,15 @@ read: push ax
|
|||||||
push dx
|
push dx
|
||||||
|
|
||||||
xchg ax, bx
|
xchg ax, bx
|
||||||
mov al, byte [bp+bpb.heads]
|
mov al, byte [bp+BPBNOS]
|
||||||
mul byte [bp+bpb.tracksectors]
|
mul byte [bp+BPBSPT]
|
||||||
xchg ax, bx
|
xchg ax, bx
|
||||||
|
|
||||||
; dx:ax = lba
|
; dx:ax = lba
|
||||||
div word bx
|
div word bx
|
||||||
xchg ax, dx
|
xchg ax, dx
|
||||||
; dx = cylinder, ax = head * tracksectors + sector
|
; dx = cylinder, ax = head * tracksectors + sector
|
||||||
div byte [bp+bpb.tracksectors]
|
div byte [bp+BPBSPT]
|
||||||
; dx = cylinder, al = head, ah = sector
|
; dx = cylinder, al = head, ah = sector
|
||||||
xchg dl, dh
|
xchg dl, dh
|
||||||
ror dl, 1
|
ror dl, 1
|
||||||
@ -92,7 +92,7 @@ read: push ax
|
|||||||
loop read
|
loop read
|
||||||
ret
|
ret
|
||||||
|
|
||||||
rootdirsects: mov bx, [bp+bpb.direntries]
|
rootdirsects: mov bx, [bp+BPBRDE]
|
||||||
mov cl, 4
|
mov cl, 4
|
||||||
shr bx, cl ; 32 bytes per entry
|
shr bx, cl ; 32 bytes per entry
|
||||||
ret
|
ret
|
||||||
@ -103,16 +103,16 @@ offset_cluster: ; add offset of cluster data area to DX:AX
|
|||||||
adc dx, 0
|
adc dx, 0
|
||||||
offset_rootdir: ; add length of fat table times number of fats
|
offset_rootdir: ; add length of fat table times number of fats
|
||||||
xor ch, ch
|
xor ch, ch
|
||||||
mov cl, byte [bp+bpb.fatnumber]
|
mov cl, byte [bp+BPBFN]
|
||||||
.loop: add ax, [bp+bpb.fatsectors]
|
.loop: add ax, [bp+BPBFS]
|
||||||
adc dx, 0
|
adc dx, 0
|
||||||
loop .loop
|
loop .loop
|
||||||
offset_fat: ; add reserved sectors
|
offset_fat: ; add reserved sectors
|
||||||
add ax, [bp+bpb.reservedsects]
|
add ax, [bp+BPBRSC]
|
||||||
adc dx, 0
|
adc dx, 0
|
||||||
offset_part: ; add partition offset
|
offset_part: ; add partition offset
|
||||||
add ax, [bp+bpb.sectoroffset]
|
add ax, [bp+BPBHS]
|
||||||
add dx, [bp+bpb.sectoroffset+2]
|
add dx, [bp+BPBHS]
|
||||||
ret
|
ret
|
||||||
|
|
||||||
resetbuf: ; DS = ES
|
resetbuf: ; DS = ES
|
||||||
@ -127,7 +127,7 @@ resetbuf: ; DS = ES
|
|||||||
xor dx, dx
|
xor dx, dx
|
||||||
ret
|
ret
|
||||||
|
|
||||||
main: mov bp, params
|
main: mov bp, bpb
|
||||||
mov [bp-1], dl
|
mov [bp-1], dl
|
||||||
|
|
||||||
; load root directory
|
; load root directory
|
||||||
@ -140,7 +140,7 @@ main: mov bp, params
|
|||||||
|
|
||||||
; search for file
|
; search for file
|
||||||
pop bx
|
pop bx
|
||||||
mov cx, [bp+bpb.direntries]
|
mov cx, [bp+BPBRDE]
|
||||||
.loop: push cx
|
.loop: push cx
|
||||||
mov si, filename
|
mov si, filename
|
||||||
mov di, bx
|
mov di, bx
|
||||||
@ -156,7 +156,7 @@ main: mov bp, params
|
|||||||
call resetbuf
|
call resetbuf
|
||||||
push di
|
push di
|
||||||
call offset_fat
|
call offset_fat
|
||||||
mov cx, [bp+bpb.fatsectors]
|
mov cx, [bp+BPBFS]
|
||||||
call read
|
call read
|
||||||
|
|
||||||
; fetch cluster numbers (FAT12-specific)
|
; fetch cluster numbers (FAT12-specific)
|
||||||
@ -189,10 +189,10 @@ readfat: stosw
|
|||||||
loadclus: lodsw
|
loadclus: lodsw
|
||||||
sub ax, 2
|
sub ax, 2
|
||||||
jc .jump
|
jc .jump
|
||||||
mul byte [bp+bpb.clustersects]
|
mul byte [bp+BPBSC]
|
||||||
call offset_cluster
|
call offset_cluster
|
||||||
xor cx, cx
|
xor cx, cx
|
||||||
mov cl, [bp+bpb.clustersects]
|
mov cl, [bp+BPBSC]
|
||||||
call read
|
call read
|
||||||
jmp loadclus
|
jmp loadclus
|
||||||
|
|
||||||
|
12
boot/mbr.asm
12
boot/mbr.asm
@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
%include "inc/bpb.asm"
|
%include "inc/bpb.asm"
|
||||||
|
|
||||||
%define params bs+0x0B
|
%define bpb bs+0x0B
|
||||||
|
|
||||||
cpu 8086
|
cpu 8086
|
||||||
org 0x0600
|
org 0x0600
|
||||||
@ -72,11 +72,11 @@ main: ; find active partition
|
|||||||
|
|
||||||
; FAT bpb has "bytes per sector" at this place
|
; FAT bpb has "bytes per sector" at this place
|
||||||
; we support only 512 byte sectors anyways
|
; we support only 512 byte sectors anyways
|
||||||
cmp word [params+bpb.sectorsize], 512
|
cmp word [bpb+BPBSS], 512
|
||||||
jne chain
|
jne chain
|
||||||
|
|
||||||
; Media descriptor byte is never smaller than 0xF0
|
; Media descriptor byte is never smaller than 0xF0
|
||||||
cmp byte [params+bpb.mediadesc], 0xF0
|
cmp byte [bpb+BPBMD], 0xF0
|
||||||
jc chain
|
jc chain
|
||||||
|
|
||||||
; ask BIOS what our disk geometry is
|
; ask BIOS what our disk geometry is
|
||||||
@ -92,17 +92,17 @@ main: ; find active partition
|
|||||||
; update sectors per track
|
; update sectors per track
|
||||||
xor ax, ax
|
xor ax, ax
|
||||||
mov al, cl
|
mov al, cl
|
||||||
mov [params+bpb.tracksectors], ax
|
mov [bpb+BPBSPT], ax
|
||||||
|
|
||||||
; update number of sides
|
; update number of sides
|
||||||
xor ax, ax
|
xor ax, ax
|
||||||
mov al, dh
|
mov al, dh
|
||||||
mov [params+bpb.heads], ax
|
mov [bpb+BPBNOS], ax
|
||||||
|
|
||||||
; update partition offset
|
; update partition offset
|
||||||
push si
|
push si
|
||||||
add si, 0x08
|
add si, 0x08
|
||||||
mov di, params+bpb.sectoroffset
|
mov di, bpb+BPBHS
|
||||||
movsw
|
movsw
|
||||||
movsw
|
movsw
|
||||||
pop si
|
pop si
|
||||||
|
40
inc/bpb.asm
40
inc/bpb.asm
@ -1,14 +1,26 @@
|
|||||||
struc bpb
|
BPBOFF equ 0xB
|
||||||
.sectorsize: resw 1 ; WORD sector size
|
|
||||||
.clustersects: resb 1 ; BYTE sector / cluster
|
; DOS 2.0 BPB
|
||||||
.reservedsects: resw 1 ; WORD reserved sector count
|
BPBSS equ 0 ; word
|
||||||
.fatnumber: resb 1 ; BYTE fat number
|
BPBSC equ 2 ; byte
|
||||||
.direntries: resw 1 ; WORD root dir entries
|
BPBRSC equ 3 ; word
|
||||||
.total: resw 1 ; WORD total sectors
|
BPBFN equ 5 ; byte
|
||||||
.mediadesc: resb 1 ; BYTE media descriptor
|
BPBRDE equ 6 ; word
|
||||||
.fatsectors: resw 1 ; WORD sectors / fat
|
BPBTS equ 8 ; word
|
||||||
.tracksectors: resw 1 ; WORD sectors per track
|
BPBMD equ 10 ; byte
|
||||||
.heads: resw 1 ; WORD number of sides
|
BPBFS equ 11 ; word
|
||||||
.sectoroffset: resd 1 ; DWORD partition offset
|
BPBSIZ2 equ 13 ; size constant
|
||||||
.longtotal: resd 1 ; DWORD large total sectors
|
|
||||||
endstruc
|
; 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
|
||||||
|
@ -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
|
|
Loading…
Reference in New Issue
Block a user