From cd258ccbe466be4e754fe9e1ebac0dfad44d5d16 Mon Sep 17 00:00:00 2001 From: Ain <41307858+nero@users.noreply.github.com> Date: Sun, 8 Sep 2019 15:18:37 +0000 Subject: [PATCH] Work on interrupt subfunctions, remove drvtab experiments --- Makefile | 2 +- kernel/chario.asm | 29 ++++++++++++++++---- kernel/drvtab.asm | 51 ---------------------------------- kernel/main.asm | 70 ++++++++++++++++++++++++++++++++++++++++------- 4 files changed, 84 insertions(+), 68 deletions(-) delete mode 100644 kernel/drvtab.asm diff --git a/Makefile b/Makefile index 188447a..4b70531 100644 --- a/Makefile +++ b/Makefile @@ -26,7 +26,7 @@ endif default: kernel.rom kernel.com: kernel/*.asm lib/*.inc - nasm -s -o $@ -I lib -I kernel kernel/main.asm + nasm -s -o $@ -l kernel.lst -I lib -I kernel kernel/main.asm debug.rom: debug/*.asm lib/*.inc nasm -s -o $@ -I lib -I debug debug/main.asm && scripts/fix-rom.sh $@ diff --git a/kernel/chario.asm b/kernel/chario.asm index 8993cd1..40788ce 100644 --- a/kernel/chario.asm +++ b/kernel/chario.asm @@ -1,18 +1,35 @@ -putc: - pushf - push cs - call isr_putc - ret +; Reads a single character with echo +; out AL character +isr_getc_echo: + xor ax, ax + int 0x16 + test al, al + jz isr_getc_echo + call putc + iret +; Reads a single character without echo +; out AL character isr_getc: xor ax, ax int 0x16 test al, al jz isr_getc + iret + +; Prints a single character +; in DL character isr_putc: + push ax + mov al, dl + call putc + pop ax + iret + +putc: push bx mov ah, 0x0e mov bx, 0x0000 int 0x10 pop bx - iret + ret diff --git a/kernel/drvtab.asm b/kernel/drvtab.asm deleted file mode 100644 index f7615dd..0000000 --- a/kernel/drvtab.asm +++ /dev/null @@ -1,51 +0,0 @@ -; Drive table -; Header: -; byte number of drives -; Item (type BIOS CHS): -; byte type (1) -; byte drive number -; word number of cylinders -; byte number of heads -; word number of sectors per cylinder -; 3 bytes padding -; Item (type BIOS LBA): -; byte type (2) -; byte drive number -; dword offset -; dword size - -; Create a drive table at ES:DI -drvtab_create: - mov ax, 0x2B - call intr_register - - mov al, 8 ; 8 drives per default - mov ah, 10 ; 10 bytes per drive - stosb - mul ah - - xor cx, cx - xchg cx, ax - rep stosb - - ret - -; Get drive table item -; IN DL drive number (A=0, B=1, ...) -; OUT DS:SI ptr to drive struct -drvtab_load: - push ax - mov ax, 0x2B - call intr_load - cmp dl, [ds:si] - jnb .err - mov al, 10 - mul dl - inc ax - add si, ax - pop ax - ret -.err: - pop ax - stc - ret diff --git a/kernel/main.asm b/kernel/main.asm index 5791244..1688548 100644 --- a/kernel/main.asm +++ b/kernel/main.asm @@ -6,10 +6,7 @@ org 0x0100 mov ax, 0x21 call intr_register -.loop: - mov ah, 0x01 - int 0x21 - jmp .loop + int3 cli .halt: @@ -17,10 +14,41 @@ org 0x0100 jmp .halt isr_dos_main: - cmp ah, 0x01 - je isr_getc - cmp ah, 0x02 - je isr_putc + ; Bail out if subfunction number too high + cmp ah, 0x0F + jnc isr_invalid + + ; allocate our return address + push bx + ; actual BX backup + push bx + + ; transfer subfunction number into BX + xor bx, bx + mov bl, ah + ; table offset = AH * 2 + shl bx, 1 + ; fetch from table + mov bx, [dos_functions+bx] + + ; inject our address into the stack + add sp, 4 + push bx + sub sp, 2 + + ; restore BX + pop bx + ; reads our address from the stack and jumps there + ret + +; ISR for invalid subfunctions or unimplemented +isr_invalid: + mov bp, 0xFEFE + int3 +.hlt: + hlt + jmp .hlt +; ISR tail to set carry flag to signal error isr_error: push bp mov bp, sp @@ -30,9 +58,31 @@ isr_error: isr_return: iret +; Table for DOS subfunctions +dos_functions: + ; AH 00-03 + dw isr_invalid + dw isr_getc_echo + dw isr_putc + dw isr_invalid + ; AH 04-07 + dw isr_invalid + dw isr_invalid + dw isr_invalid + dw isr_invalid + ; AH 08-0B + dw isr_invalid + dw isr_invalid + dw isr_invalid + dw isr_invalid + ; AH 0C-0F + dw isr_invalid + dw isr_invalid + dw isr_invalid + dw isr_invalid + %include "intr.asm" -%include "drvtab.asm" %include "chario.asm" -times 1000 db 0xEA +kernel_end: