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 xor cx, cx
mov ds, 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 word [0x21*4+2], ax
mov ax, 0x200 | NUMSEG mov ax, 0x200 | NUMSEG

View File

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

View File

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

View File

@ -2,7 +2,7 @@
[map symbols kernel.map] [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 jmp kernel_entry
%include "int21/int21.s" %include "int21/int21.s"
@ -10,6 +10,11 @@ kernel_entry:
mov si, hello_string mov si, hello_string
mov bl, 0x70 mov bl, 0x70
call print_string call print_string
mov ah, 0x2
mov dl, '!'
int 0x21
jmp $ jmp $
hello_string: db "hello world!", 13, 10, '$' hello_string: db "hello world!", 13, 10, '$'

View File

@ -52,3 +52,32 @@ print_string:
pop es pop es
popa popa
ret 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