a couple bugfixes

This commit is contained in:
'mr software' 2022-11-02 17:28:53 -07:00
parent 3971b4602f
commit 187cd0fbd4
2 changed files with 63 additions and 26 deletions

View File

@ -1,33 +1,28 @@
; foxdos boot sector. should load kernel into segment 0x50 at 0x00. max size ; foxdos boot sector
; 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
%include "config.s" %include "config.s"
[org 0x7C00] [org 0x7C00]
[bits 16] [bits 16]
mov ax, K_ADDR << 4 mov ax, K_ADDR >> 4
push ax ; setup for ds push ax ; setup for ds
mov es, ax mov es, ax
mov gs, ax mov gs, ax
mov fs, ax mov fs, ax
xor bx, bx xor cx, cx
mov ds, bx mov ds, cx
mov word [0x21*4], 2 ; see kernel_entry mov word [0x21*4], 2 ; see kernel_entry
mov word [0x21*4+2], ax mov word [0x21*4+2], ax
pop ds
mov ax, 0x200 | NUMSEG mov ax, 0x200 | NUMSEG
mov cl, 2 mov cl, ah
xor dh, dh xor dh, dh
int 13h int 13h
; 64kb stack ; 64kb stack
pop ds
mov ax, STACK_SEG mov ax, STACK_SEG
mov ss, ax mov ss, ax
xor sp, sp xor sp, sp

View File

@ -2,14 +2,56 @@ int21:
push ds push ds
push cs push cs
pop ds pop ds
; your handler goes here
; you could maybe make a jump table that takes ah as input? ; this probably works
pop ds 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 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 retcode: dw 0
verify: db 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 ; AH = 4dh
; get return code ; get return code
; inputs: ; inputs:
@ -17,11 +59,10 @@ verify: db 0
; outputs: ; outputs:
; AH: termination type (0 = normal, 1 = control-C abort, 2 = critical error abort, 3 = terminate and stay resident) ; AH: termination type (0 = normal, 1 = control-C abort, 2 = critical error abort, 3 = terminate and stay resident)
; AL: return code ; AL: return code
get_retcode: getret:
mov ax, [retcode]
xor ax, ax xor ax, ax
mov [retcode], ax xchg [retcode], ax
retf ret
; AH = 30h ; AH = 30h
; get the DOS version number ; get the DOS version number
@ -30,11 +71,12 @@ get_retcode:
; outputs: ; outputs:
; AL: major version ; AL: major version
; AH: minor version ; AH: minor version
get_version: getver:
mov ax, 8 ; if it is not zero indexed this indicates windows ME mov ax, 8 ; if it is not zero indexed this indicates windows ME
xor bx, bx ; update: what does that comment mean xor bx, bx ; update: what does that comment mean
mov cx, bx mov cx, bx
retf ret
; AH = 54h ; AH = 54h
; get disk verify flag ; get disk verify flag
@ -44,7 +86,7 @@ get_version:
; AL: 0 if off, 1 if on ; AL: 0 if off, 1 if on
getverify: getverify:
mov al, [verify] mov al, [verify]
retf ret
; AH = 2eh ; AH = 2eh
; set disk verify flag ; set disk verify flag
@ -54,7 +96,7 @@ getverify:
; none ; none
setverify: setverify:
mov [verify], al mov [verify], al
retf ret
; AH = 35h ; AH = 35h
; get interrupt vector ; get interrupt vector
@ -76,7 +118,7 @@ getint:
mov word es, [di+2] mov word es, [di+2]
pop di pop di
pop ds pop ds
retf ret
; AH = 25h ; AH = 25h
; set interrupt vector ; set interrupt vector
@ -97,7 +139,7 @@ setint:
mov word [di+2], ds mov word [di+2], ds
pop ds pop ds
popa popa
retf ret
; read from CMOS register ; read from CMOS register
; inputs: ; inputs:
@ -168,7 +210,7 @@ gettime:
add ch, 12 add ch, 12
.end: pop ax .end: pop ax
retf ret
; AH = 2dh ; AH = 2dh
; set system time in the CMOS ; set system time in the CMOS
@ -194,4 +236,4 @@ settime:
call wrcmos call wrcmos
xor al, al ; it probably succeeded, its fine. TODO: am i missing return codes anywhere else xor al, al ; it probably succeeded, its fine. TODO: am i missing return codes anywhere else
pop bx pop bx
iret ret