From 187cd0fbd40764eb3bf88418952f07e74788180d Mon Sep 17 00:00:00 2001 From: mothcompute Date: Wed, 2 Nov 2022 17:28:53 -0700 Subject: [PATCH] a couple bugfixes --- src/boot.s | 17 +++++-------- src/int21.s | 72 ++++++++++++++++++++++++++++++++++++++++++----------- 2 files changed, 63 insertions(+), 26 deletions(-) diff --git a/src/boot.s b/src/boot.s index eaac5a6..974e70e 100644 --- a/src/boot.s +++ b/src/boot.s @@ -1,33 +1,28 @@ -; foxdos boot sector. should load kernel into segment 0x50 at 0x00. max size -; would be 64k but i doubt a dos needs more than that. stack is placed at -; 0x10500. i would suggest changing this to load the kernel into extended -; a20-gate memory so as not to overwrite the boot sector with larger kernels -; but i will leave that for you to do. code is public domain as always. i -; have not tested any of this so your mileage using it may vary +; foxdos boot sector %include "config.s" [org 0x7C00] [bits 16] -mov ax, K_ADDR << 4 +mov ax, K_ADDR >> 4 push ax ; setup for ds mov es, ax mov gs, ax mov fs, ax -xor bx, bx -mov ds, bx +xor cx, cx +mov ds, cx mov word [0x21*4], 2 ; see kernel_entry mov word [0x21*4+2], ax -pop ds mov ax, 0x200 | NUMSEG -mov cl, 2 +mov cl, ah xor dh, dh int 13h ; 64kb stack +pop ds mov ax, STACK_SEG mov ss, ax xor sp, sp diff --git a/src/int21.s b/src/int21.s index 75222d9..4538e74 100644 --- a/src/int21.s +++ b/src/int21.s @@ -2,14 +2,56 @@ int21: push ds push cs pop ds - ; your handler goes here - ; you could maybe make a jump table that takes ah as input? - pop ds + + ; this probably works + mov word [tmp], bx ; cannot use stack for this + movzx bx, ah + shl bx, 1 + add bx, fn + push end21 ; the proper return address + ; generated return address. should avoid any issues + ; with things like prefetch or instruction caches + push bx + mov bx, word [tmp] + ret + +end21: pop ds iret +nul: stc + ret + +; TODO figure out a way to format this table. maybe it can be autogenerated? +; this table is misaligned for me and im the one who made it + ; 0 1 2 3 4 5 6 7 8 9 A B C D E F +fn: dw nul, rdin_echo, nul, nul, nul, nul, nul, nul, nul, nul, nul, nul, nul, nul, nul, nul ; 0 + dw nul, nul, nul, nul, nul, nul, nul, nul, nul, nul, nul, nul, nul, nul, nul, nul ; 1 + dw nul, nul, nul, nul, nul, setint, nul, nul, nul, nul, nul, nul, gettime, settime, setverify, nul ; 2 + dw getver, nul, nul, nul, nul, nul, nul, nul, nul, nul, nul, nul, nul, nul, nul, nul ; 3 + dw nul, nul, nul, nul, nul, nul, nul, nul, nul, nul, nul, nul, nul, getret, nul, nul ; 4 + dw nul, nul, nul, nul, setverify, nul, nul, nul, nul, nul, nul, nul, nul, nul, nul, nul ; 5 + dw nul, nul, nul, nul, nul, nul, nul, nul, nul, nul, nul, nul, nul, nul, nul, nul ; 6 + dw nul, nul, nul, nul, nul, nul, nul, nul, nul, nul, nul, nul, nul, nul, nul, nul ; 7 + dw nul, nul, nul, nul, nul, nul, nul, nul, nul, nul, nul, nul, nul, nul, nul, nul ; 8 + dw nul, nul, nul, nul, nul, nul, nul, nul, nul, nul, nul, nul, nul, nul, nul, nul ; 9 + dw nul, nul, nul, nul, nul, nul, nul, nul, nul, nul, nul, nul, nul, nul, nul, nul ; A + dw nul, nul, nul, nul, nul, nul, nul, nul, nul, nul, nul, nul, nul, nul, nul, nul ; B + dw nul, nul, nul, nul, nul, nul, nul, nul, nul, nul, nul, nul, nul, nul, nul, nul ; C + dw nul, nul, nul, nul, nul, nul, nul, nul, nul, nul, nul, nul, nul, nul, nul, nul ; D + dw nul, nul, nul, nul, nul, nul, nul, nul, nul, nul, nul, nul, nul, nul, nul, nul ; E + dw nul, nul, nul, nul, nul, nul, nul, nul, nul, nul, nul, nul, nul, nul, nul, nul ; F + +tmp: dw 0 retcode: dw 0 verify: db 0 +rdin_echo:; ah=01h + push ax + mov ah, 8 + int 0x21 + ; TODO does echo go to stdout or to screen? + pop ax + ; AH = 4dh ; get return code ; inputs: @@ -17,11 +59,10 @@ verify: db 0 ; outputs: ; AH: termination type (0 = normal, 1 = control-C abort, 2 = critical error abort, 3 = terminate and stay resident) ; AL: return code -get_retcode: - mov ax, [retcode] +getret: xor ax, ax - mov [retcode], ax - retf + xchg [retcode], ax + ret ; AH = 30h ; get the DOS version number @@ -30,11 +71,12 @@ get_retcode: ; outputs: ; AL: major version ; AH: minor version -get_version: +getver: mov ax, 8 ; if it is not zero indexed this indicates windows ME xor bx, bx ; update: what does that comment mean mov cx, bx - retf + ret + ; AH = 54h ; get disk verify flag @@ -44,7 +86,7 @@ get_version: ; AL: 0 if off, 1 if on getverify: mov al, [verify] - retf + ret ; AH = 2eh ; set disk verify flag @@ -54,7 +96,7 @@ getverify: ; none setverify: mov [verify], al - retf + ret ; AH = 35h ; get interrupt vector @@ -76,7 +118,7 @@ getint: mov word es, [di+2] pop di pop ds - retf + ret ; AH = 25h ; set interrupt vector @@ -97,7 +139,7 @@ setint: mov word [di+2], ds pop ds popa - retf + ret ; read from CMOS register ; inputs: @@ -168,7 +210,7 @@ gettime: add ch, 12 .end: pop ax - retf + ret ; AH = 2dh ; set system time in the CMOS @@ -194,4 +236,4 @@ settime: call wrcmos xor al, al ; it probably succeeded, its fine. TODO: am i missing return codes anywhere else pop bx - iret + ret