fix int 21h handler

This commit is contained in:
'mr software' 2022-11-04 00:48:42 -07:00
parent d115299508
commit 3b417b1794
5 changed files with 56 additions and 12 deletions

View File

@ -13,7 +13,7 @@ mov fs, ax
xor cx, cx
mov ds, cx
mov word [0x21*4], 2 ; see kjmp in kernel.s
mov word [0x21*4], 3 ; see kjmp in kernel.s
mov word [0x21*4+2], ax
mov ax, 0x200 | NUMSEG

View File

@ -22,6 +22,10 @@ wrout:
; TODO handle ^C and stuff
; TODO handle stdout properly
push bx
cmp dl, 9
jnz .print
mov dl, ' ' ; "tabs are expanded to blanks"
.print:
mov al, dl
mov bl, 0x70
call print_character

View File

@ -1,22 +1,27 @@
; TODO: change to use a stack frame instead of global variables for reentrancy
int21:
push ds
push cs
pop ds
push ax
mov ax, ds
mov cs:[callerds], ax
mov ax, cs
mov ds, ax
pop ax
; this probably works
mov word [tmp], bx ; cannot use stack for this
mov word [tmp], bx
movzx bx, ah
shl bx, 1
add bx, fn
mov bx, word [bx]
push end21 ; the proper return address
; generated return address. should avoid any issues
; with things like prefetch or instruction caches
push end21
push bx
mov bx, word [tmp]
ret
end21: pop ds
end21:
push ax
mov ax, [callerds]
mov ds, ax
pop ax
iret
nul: stc
@ -42,6 +47,7 @@ fn: dw nul, rdin_echo, wrout, nul, nul, nul, nul, nul, nul, nul, nul, nul, nul,
dw nul, nul, nul, nul, nul, nul, nul, nul, nul, nul, nul, nul, nul, nul, nul, nul ; Ex
dw nul, nul, nul, nul, nul, nul, nul, nul, nul, nul, nul, nul, nul, nul, nul, nul ; Fx
callerds: dw 0
tmp: dw 0
retcode: dw 0
verify: db 0

View File

@ -2,7 +2,7 @@
[map symbols kernel.map]
kjmp: ; MUST be a short jump due to loader config
kjmp: ; MUST be a jmp due to loader config
jmp kernel_entry
%include "int21/int21.s"
@ -10,6 +10,11 @@ kernel_entry:
mov si, hello_string
mov bl, 0x70
call print_string
mov ah, 0x2
mov dl, '!'
int 0x21
jmp $
hello_string: db "hello world!", 13, 10, '$'

View File

@ -52,3 +52,32 @@ print_string:
pop es
popa
ret
; print a u16 to the screen in hex
; inputs:
; BX: value to print
; outputs:
; none
print_hex:
push ax
push bx
push cx
mov cx, 4
.loop:
mov al, bh
shr al, 4
cmp al, 9
jng .num
add al, 'A' - 10
jmp .eloop
.num:
add al, '0'
.eloop:
call print_character
shl bx, 4
dec cx
jnz .loop
pop cx
pop bx
pop ax
ret