From d23bba5bddc6a2cec2b89a06b537ba83246cbf95 Mon Sep 17 00:00:00 2001 From: Ain <41307858+nero@users.noreply.github.com> Date: Thu, 19 Sep 2019 20:02:16 +0000 Subject: [PATCH] Add attempt for drive table to kernel --- kernel/drive.asm | 50 ++++++++++++++++++++++++++++++++++++++++++++++++ kernel/main.asm | 16 +++++++++------- 2 files changed, 59 insertions(+), 7 deletions(-) create mode 100644 kernel/drive.asm diff --git a/kernel/drive.asm b/kernel/drive.asm new file mode 100644 index 0000000..9f0b714 --- /dev/null +++ b/kernel/drive.asm @@ -0,0 +1,50 @@ +%define drive_struct_len 0x0C + +drive_table: + dw 0 +.count: + dw 4 + +; Drive table +; 00 BYTE DL number +; 01 BYTE file system type +; 02 BYTE CHS heads (ignored if LBA) +; 03 BYTE CHS sectors per track (ignored if LBA) +; 04 DWORD total number of sectors +; 08 DWORD partition offset + +; DI is incremented for the space taken +; IN ES:DI +drive_setup: + xor cx, cx + mov [drive_table], di + mov al, drive_struct_len + mov ah, BYTE [drive_table.count] + mul ah + xchg cx, ax + ; this increments DI and also fills table with zeros + rep stosb + ret + +; Load a drive table entry +; IN DL drive number +; OUT DS:SI ptr to table item +drive_load: + ; bail out if number too high + cmp dl, [cs:drive_table.count] + jnc .err + + push cs + pop ds + mov si, [drive_table] + + push ax + mov al, drive_struct_len + mul dl + add si, ax + pop ax + + ret +.err: + stc + ret diff --git a/kernel/main.asm b/kernel/main.asm index 98a2bdd..ebc54d1 100644 --- a/kernel/main.asm +++ b/kernel/main.asm @@ -31,28 +31,30 @@ isr_error: isr_return: iret +%include "drive.asm" + init: mov ax, cs mov ds, ax mov es, ax + mov di, kernel_end + call drive_setup + mov dx, isr_dos_main mov ax, 0x2521 pushf push cs call isr_dos_main - mov cx, WORD [0x80] - xor ch, ch - mov si, 0x81 -.loop: - lodsb - call putc - loop .loop + mov dl, 0x37 + mov ah, 0x02 + int 0x21 cli .halt: hlt jmp .halt + kernel_end: