From 1981a8efba2e6d63faf993a854940b106f7b19a5 Mon Sep 17 00:00:00 2001 From: Nero <41307858+nero@users.noreply.github.com> Date: Tue, 31 Mar 2020 20:03:05 +0000 Subject: [PATCH] fat32 bs: use BPB include header and base off BP We now set BP once at the start to point to the beginning of the BPB. Encoding an direct address access can then be done relative to BP, which saves an immediate byte per access. --- boot/fat32.asm | 61 ++++++++++++++++++-------------------------------- 1 file changed, 22 insertions(+), 39 deletions(-) diff --git a/boot/fat32.asm b/boot/fat32.asm index 60dad99..d1523ae 100644 --- a/boot/fat32.asm +++ b/boot/fat32.asm @@ -4,29 +4,12 @@ jmp short init nop - ; WORD reserved sector count -rsc: equ ( $$ + 0x00E ) + %include "inc/bpb.asm" - ; BYTE number of sectors per cluster -sc: equ ( $$ + 0x00D ) - - ; BYTE number of FATs -fn: equ ( $$ + 0x010 ) - - ; WORD number of root directory entries -rde: equ ( $$ + 0x011 ) - - ; DWORD hidden sector count (partition offset) -po: equ ( $$ + 0x01C ) - - ; DWORD sectors per FAT -sf: equ ( $$ + 0x024 ) - - ; BYTE drive number (we set it from dl) -dn: equ ( $$ + 0x040 ) +bpb: equ 0x080B ; Area for BPB - times (0x5A - ($-$$)) db 0 + times ( 0x5A - ($-$$) ) db 0 init: xor ax, ax mov ss, ax @@ -66,7 +49,7 @@ hlt: hlt ; offsets relative to FS readd: ; add offset of cluster data area to DX:AX push cx - mov di, [rde] + mov di, [bp+bpb_rde] mov cl, 4 shr di, cl ; 32 bytes per entry add ax, di @@ -75,17 +58,17 @@ readd: ; add offset of cluster data area to DX:AX readr: ; add offset to rootdir to DX:AX (FAT12/FAT16 only) push cx xor ch, ch - mov cl, byte [fn] -fatlp: add ax, [sf] - adc dx, [sf+2] + mov cl, byte [bp+bpb_fn] +fatlp: add ax, [bp+bpb7_lsf] + adc dx, [bp+bpb7_lsf+2] loop fatlp pop cx readf: ; add offset to FAT table to DX:AX - add ax, word [rsc] + add ax, word [bp+bpb_rsc] adc dx, 0 readp: ; read sector DX:AX from partition - add ax, word [po] - adc dx, word [po+2] + add ax, word [bp+bpb_po] + adc dx, word [bp+bpb_po+2] jc err read_: ; read sector DX:AX from disk ; qword sector number DX:AX @@ -102,17 +85,17 @@ read_: ; read sector DX:AX from disk push cx ; size & passing - mov bp, 0x10 - push bp + mov di, 0x10 + push di mov si, sp mov ah, 0x42 - mov dl, [dn] + mov dl, [bp+bpb7_dn] stc int 0x13 jc dskerr - add sp, bp + add sp, di ret @@ -159,7 +142,7 @@ readc: ; load cluster number ; convert cluster number to sector number ; this is some cheapo multiplication with 2^n - mov cl, [sc] + mov cl, [bp+bpb_sc] l02: shr cl, 1 jz l02e clc @@ -168,15 +151,15 @@ l02: shr cl, 1 jmp l02 l02e: ; dx:ax is now sector num in data area - mov cx, [sc] + mov cx, [bp+bpb_sc] xor ch, ch call readd - xchg bp, cx + xchg di, cx mov cl, 5 - sal bp, cl - add bx, bp + sal di, cl + add bx, di pop dx pop ax @@ -219,7 +202,8 @@ loadf: call search mov dx, [si+0x14] jmp load -main: mov [dn], dl +main: mov bp, bpb + mov [bp+bpb7_dn], dl ; load root directory call loadr ; search for first system directory @@ -234,10 +218,9 @@ main: mov [dn], dl xor dx, dx xor bx, bx xor di, di - xor bp, bp ; restore drive number - mov dl, [dn] + mov dl, [bp+bpb7_dn] ; restore potential partition table pop si