From 1e99086fc628a9e8928bd3c3cb540b70f1d1953a Mon Sep 17 00:00:00 2001 From: Nero <41307858+nero@users.noreply.github.com> Date: Sat, 4 Apr 2020 14:29:33 +0000 Subject: [PATCH] Add CHS+LBA dual support for boot sector --- boot/fat32.asm | 82 ++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 70 insertions(+), 12 deletions(-) diff --git a/boot/fat32.asm b/boot/fat32.asm index 0f1b9dd..fe5d20c 100644 --- a/boot/fat32.asm +++ b/boot/fat32.asm @@ -54,7 +54,52 @@ readp: ; read sector DX:AX from partition add ax, word [bp+bpb_po] adc dx, word [bp+bpb_po+2] jc dskerr -read_: ; read sector DX:AX from disk + jmp [bp-2] + +rchs: ; read sector DX:AX from disk + ; uses basic CHS disk IO + ; this cant reliable read over track boundaries + ; so we read each single sector in loop over CX +chslp: push ax + push cx + push dx + push bx + + ; calculate CHS data + div word [bp+bpb_spt] ; ax:temp = (lba / spt) + inc dx ; dx:sector = (lba % spt) + 1 + mov cl, dl ; sector number + xor dx, dx + div word [bp+bpb_nos] ; ax:cylinder = (tmp / heads) + ; dx:head = (tmp % heads) + mov ch, al ; cylinder number + mov dh, dl ; head number + mov dl, [bp+bpb7_dn] ; drive number + + ; set up read buffer + mov es, bx + xor bx, bx + + ; call bios + mov ax, 0x0201 + int 0x13 + jc dskerr + + pop bx + pop dx + pop cx + pop ax + + ; increment sector num + write offset + add ax, 1 + adc dx, 0 + add bx, 0x20 + ; loop on CX + loop chslp + ret + +rebios: ; read sector DX:AX from disk + ; this uses the EBIOS extensions ; qword sector number DX:AX push cs push cs @@ -153,6 +198,15 @@ l02e: ret +loadr: mov ax, 2 + xor dx, dx + jmp load + +loadf: call search + jne fserr + mov ax, [si+0x1A] + mov dx, [si+0x14] + ; load cluster chain DX:AX to [dest]:0 load: mov bx, 0x07C0 lloop: call readc @@ -179,18 +233,22 @@ loop: add si, 0x20 jne loop ret -loadr: mov ax, 2 - xor dx, dx - jmp load - -loadf: call search - jne fserr - mov ax, [si+0x1A] - mov dx, [si+0x14] - jmp load - main: mov bp, bpb mov [bp+bpb7_dn], dl + + ; check if EBIOS is supported + mov bx, 0x55AA + mov ah, 0x41 + 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 call loadr ; search for first system directory @@ -213,7 +271,7 @@ main: mov bp, bpb pop si pop ds - jmp 0:0x7C00 + jmp 0x7C00 ; error handling for file not found fserr: call errcll