From fde87d651c2fbad48dcd27b91a38814746f856e2 Mon Sep 17 00:00:00 2001 From: Nero <41307858+nero@users.noreply.github.com> Date: Sat, 15 Aug 2020 21:15:31 +0000 Subject: [PATCH] kernel: read A: geometry from BIOS --- boot/kernel.asm | 8 +++--- kernel/drive.asm | 71 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+), 4 deletions(-) create mode 100644 kernel/drive.asm diff --git a/boot/kernel.asm b/boot/kernel.asm index 3641b8e..bf7b869 100644 --- a/boot/kernel.asm +++ b/boot/kernel.asm @@ -48,10 +48,7 @@ intlp: movsw mov bx, 0 call fd_write - call dnconv - mov al, dl - call select - call load_bpb + call drives_init loop: int 0x28 jmp loop @@ -241,9 +238,12 @@ fputc: push ax %include "kernel/fd.asm" %include "kernel/con.asm" + %include "kernel/drive.asm" %include "kernel/diskio.asm" %include "kernel/fat.asm" +zero: dw 0 + section .data vects: dw int20h, int21h, retf, retf diff --git a/kernel/drive.asm b/kernel/drive.asm new file mode 100644 index 0000000..3712f51 --- /dev/null +++ b/kernel/drive.asm @@ -0,0 +1,71 @@ +section .bss + +drives: equ 16 + +; drive table entry +struc drive +.biosnum: resb 1 +.flag: resb 1 +.spc: resw 1 +.cylinders: resw 1 +.dpt: resb dpt_size +endstruc + + ; ptr into currently selected drive +drive_ptr: resw 1 + +drive_table: resb (drives * drive_size) + +section .text + +drives_init: int 0x11 + mov cl, 6 + shr ax, cl + inc ax + and ax, 3 + mov cx, ax + + mov bx, drive_table + xor dx, dx + + mov [bx+drive.biosnum], dl + ; defaults if 13h,AH=8 fails (XT 360kb) + les di, [0x1e * 4] + mov cx, 0x2709 ; 40 cylinders, 9 sectors + mov dh, 1 ; 2 heads + ; ask bios + push bx + mov ah, 8 + int 0x13 + pop bx + ; copy dpt + push es + push ds + pop es + pop ds + push cx + mov si, di + lea di, [bx+drive.dpt] + mov cx, 11 + rep movsb + pop cx + ; restore ds + push cs + pop ds + ; get and save number of cylinders + mov ax, cx + xchg al, ah + rol ah, 1 + rol ah, 1 + and ax, 0x03FF + inc ax + mov [bx+drive.cylinders], ax + ; save spt + mov ax, cx + and al, 0x3F + mov [bx+drive.dpt+dpt.lastsector], al + ; multiply with heads and save sectors per cylinder + inc dh + mul dh ; ax = al * dh + mov [bx+drive.spc], ax + ret