From e34accfcff969c617fb84ace814fdb6c24642dd9 Mon Sep 17 00:00:00 2001 From: Nero <41307858+nero@users.noreply.github.com> Date: Sat, 4 Apr 2020 21:05:44 +0000 Subject: [PATCH] Improve support for auto-selecting LBA addressing --- boot/fat32.asm | 87 +++++++++++++++++++++++++++----------------------- 1 file changed, 47 insertions(+), 40 deletions(-) diff --git a/boot/fat32.asm b/boot/fat32.asm index 77d61ba..8531cf1 100644 --- a/boot/fat32.asm +++ b/boot/fat32.asm @@ -54,7 +54,39 @@ readp: ; read sector DX:AX from partition add ax, word [bp+bpb_po] adc dx, word [bp+bpb_po+2] jc dskerr - jmp [bp-2] + + ; This jump is overwritten with NOP's if LBA support +dskjmp: jmp rchs + +rebios: ; read sector DX:AX from disk + ; this uses the EBIOS extensions + ; qword sector number DX:AX + push cs + push cs + push dx + push ax + + ; dword target buffer: BX:0 + push bx + push cs + + ; word sector number + push cx + + ; size & passing + mov di, 0x10 + push di + + mov si, sp + mov ah, 0x42 + mov dl, [bp+bpb7_dn] + stc + int 0x13 + jc dskerr + + add sp, di + + ret rchs: ; read sector DX:AX from disk ; uses basic CHS disk IO @@ -98,36 +130,6 @@ chslp: push ax loop chslp ret -rebios: ; read sector DX:AX from disk - ; this uses the EBIOS extensions - ; qword sector number DX:AX - push cs - push cs - push dx - push ax - - ; dword target buffer: BX:0 - push bx - push cs - - ; word sector number - push cx - - ; size & passing - mov di, 0x10 - push di - - mov si, sp - mov ah, 0x42 - mov dl, [bp+bpb7_dn] - stc - int 0x13 - jc dskerr - - add sp, di - - ret - ; error handling for disk errors dskerr: call errcll @@ -231,23 +233,28 @@ lloop: call readc jne lloop ret -main: mov bp, bpb +main: ; Set up BP to point to BPB + ; Relative addressing saves one instruction byte per access + mov bp, bpb + ; Save DL contents mov [bp+bpb7_dn], dl - ; check if EBIOS is supported + ; EBIOS is ignored for floppies (dl < 80h) + test dl, 0x80 + jz noebio + + ; check for EBIOS support mov bx, 0x55AA mov ah, 0x41 + ; set carry to assume failure if int didnt do anything stc int 0x13 - ; default: use CHS read - mov ax, rchs jc noebio - ; if EBIOS: use LBA read - mov ax, rebios -noebio: lea di, [bp-2] - stosw - ; load root directory + ; disable CHS routine, fall into LBA routine instead + mov word [dskjmp], 0x9090 + +noebio: ; load root directory call loadr ; search for first system directory mov ah, 0x14