diff --git a/src/boot.s b/src/boot.s index ace3604..9ee92cc 100644 --- a/src/boot.s +++ b/src/boot.s @@ -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 diff --git a/src/int21/0.s b/src/int21/0.s index ce2c3e1..3aca334 100644 --- a/src/int21/0.s +++ b/src/int21/0.s @@ -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 diff --git a/src/int21/int21.s b/src/int21/int21.s index 636b405..7867ecb 100644 --- a/src/int21/int21.s +++ b/src/int21/int21.s @@ -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 diff --git a/src/kernel.s b/src/kernel.s index 448bbc1..b49eae8 100644 --- a/src/kernel.s +++ b/src/kernel.s @@ -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, '$' diff --git a/src/vga.s b/src/vga.s index 46389e3..ddd7d47 100644 --- a/src/vga.s +++ b/src/vga.s @@ -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