From c5afc6ec618461a7b1af24b372938b07e139f559 Mon Sep 17 00:00:00 2001 From: Nero <41307858+nero@users.noreply.github.com> Date: Sat, 26 Dec 2020 16:03:15 +0000 Subject: [PATCH] Add printf facility for kernel to allow debug messages on phys. system --- boot/kernel.asm | 14 +++------- kernel/drive.asm | 20 +++++++++++--- kernel/printf.asm | 66 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 87 insertions(+), 13 deletions(-) create mode 100644 kernel/printf.asm diff --git a/boot/kernel.asm b/boot/kernel.asm index e190edf..c806402 100644 --- a/boot/kernel.asm +++ b/boot/kernel.asm @@ -16,13 +16,9 @@ init: cli mov ss, ax mov sp, ( stack+stacksize ) -print_banner: mov si, banner - mov ah, 0x0e - xor bx, bx -.loop: lodsb - int 0x10 - cmp al, 0x0D - jnz .loop + call printf +%defstr VERSIONSTR VERSION + db "RDOS ", VERSIONSTR, 0x0A, 0x0D, 0 push dx call dinit @@ -50,12 +46,10 @@ hlt: hlt %include "kernel/far.asm" %include "kernel/fcb.asm" %include "kernel/drive.asm" +%include "kernel/printf.asm" section .data -%defstr VERSIONSTR VERSION -banner: db "RDOS ", VERSIONSTR, 0x0A, 0x0D - testfcb: db 0 db "HELLO ", "COM" times 30 db 0 diff --git a/kernel/drive.asm b/kernel/drive.asm index 7f9a0eb..d49f869 100644 --- a/kernel/drive.asm +++ b/kernel/drive.asm @@ -46,9 +46,21 @@ dinit: ; copy previously set DPT to our data area ; int 13 stub ; place reserved for stack switches -int13: ;int 3 +int13: ; debug output + push bx + push dx + push cx + push ax + call printf + db "int13 CALL AX=",2," CX=",2," DX=",2," BX=",2,0x0A,0x0D,0 + ; do the call int 0x13 - ;int 3 + jc .err + ret +.err: push ax + call printf + db "int13 ERR AX=",2,0x0A,0x0D,0 + stc ret ; restore DPT to default values if possible @@ -156,7 +168,9 @@ read: push ax mov [dskseek+2], dx ; do the actual read - ; set the operation code and back it up to the stack + ; low level read and write + ; call again to retry, no input registers + ; read or write is configured in cx _read: mov ch, 2 db 0x3D ; cmp ax, imm16: causes next instr to be skipped _write: mov ch, 3 diff --git a/kernel/printf.asm b/kernel/printf.asm new file mode 100644 index 0000000..bda3f30 --- /dev/null +++ b/kernel/printf.asm @@ -0,0 +1,66 @@ +section .bss + +printr: +.ax: resw 1 +.cx: resw 1 +.dx: resw 1 +.bx: resw 1 + +section .text + +; Stack contents +; ret-addr arg1 arg2 arg3 ... + +printf: mov [printr.ax], ax + mov [printr.cx], cx + mov [printr.dx], dx + mov [printr.bx], bx + pop bx + +.loop: mov al, [cs:bx] + inc bx + + cmp al, 0 + je .end + cmp al, 2 + je .word + + call pputc + + jmp .loop + +.end: push bx + mov ax, [printr.ax] + mov cx, [printr.cx] + mov dx, [printr.dx] + mov bx, [printr.bx] + ret + +.word: pop dx + call pdx + jmp printf.loop + +pdx: ; this double-call is essentially a 4 times repeating loop + call .l1 +.l1: call .l2 +.l2: ; set up cl for bit shifts + mov cl, 4 + ; grab highest nibble from dx + mov al, dh + ; remove highest nibble from dx + shl dx, cl + ; shift away second-highest nibble that we accidentally copied + shr al, cl + ; map 0-9 to ascii codes for '0' to '9' + add al, 0x30 + ; if result is larger than '9', ... + cmp al, 0x3a + jl pputc + ; ... add 7 so we continue at 'A' + add al, 7 +pputc: push bx + mov ah, 0x0e + xor bx, bx + int 0x10 + pop bx + ret