From a472c396e7a17a29602eaa9023ce772227a29b69 Mon Sep 17 00:00:00 2001 From: Nero <41307858+nero@users.noreply.github.com> Date: Thu, 7 May 2020 22:56:37 +0000 Subject: [PATCH] Implement reading of BPB from FAT partition --- kernel/diskio.asm | 34 +++++++++++++++++++++++++++------- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/kernel/diskio.asm b/kernel/diskio.asm index 1536985..1ff7504 100644 --- a/kernel/diskio.asm +++ b/kernel/diskio.asm @@ -65,6 +65,7 @@ select: mov byte [disk_current], 0xFF jmp select_hdd select_floppy: + push dx call seek_zero call read ; load disk geometry @@ -76,17 +77,30 @@ select_floppy: ; we dont rely on the 'total sectors' given in the BPB ; instead, we assume maximum cylinder ; 1023 is the maximum encodable for int 13h - mov di, 1023 - mul di - mov [part_size], ax - mov [part_size+2], dx - ; set partition offset to zero + lea di, [part_offset] xor ax, ax - mov [part_offset], ax - mov [part_offset+2], ax + ; partition offset = 0 + stosw + stosw + ; partition size = 0x00010000 = 32MB + stosw + inc ax + stosw + + pop dx ret select_hdd: + push dx + ; load CHS geometry for drive + mov ah, 0x8 + int 0x13 + xor ah, ah + mov al, cl + mov [disk_spt], ax + mul byte dh + mov [disk_spc], ax + ; load offset and size of first partition call seek_zero call read mov bx, disk_buffer+0x1BE @@ -94,6 +108,12 @@ select_hdd: lea di, [part_offset] mov cx, 4 rep movsw + ; read bpb + mov dx, [part_offset+2] + mov ax, [part_offset] + call seek + call read + pop dx ret ; Set absolute sector number