Add printf facility for kernel to allow debug messages on phys. system
This commit is contained in:
parent
424e174523
commit
c5afc6ec61
@ -16,13 +16,9 @@ init: cli
|
|||||||
mov ss, ax
|
mov ss, ax
|
||||||
mov sp, ( stack+stacksize )
|
mov sp, ( stack+stacksize )
|
||||||
|
|
||||||
print_banner: mov si, banner
|
call printf
|
||||||
mov ah, 0x0e
|
%defstr VERSIONSTR VERSION
|
||||||
xor bx, bx
|
db "RDOS ", VERSIONSTR, 0x0A, 0x0D, 0
|
||||||
.loop: lodsb
|
|
||||||
int 0x10
|
|
||||||
cmp al, 0x0D
|
|
||||||
jnz .loop
|
|
||||||
|
|
||||||
push dx
|
push dx
|
||||||
call dinit
|
call dinit
|
||||||
@ -50,12 +46,10 @@ hlt: hlt
|
|||||||
%include "kernel/far.asm"
|
%include "kernel/far.asm"
|
||||||
%include "kernel/fcb.asm"
|
%include "kernel/fcb.asm"
|
||||||
%include "kernel/drive.asm"
|
%include "kernel/drive.asm"
|
||||||
|
%include "kernel/printf.asm"
|
||||||
|
|
||||||
section .data
|
section .data
|
||||||
|
|
||||||
%defstr VERSIONSTR VERSION
|
|
||||||
banner: db "RDOS ", VERSIONSTR, 0x0A, 0x0D
|
|
||||||
|
|
||||||
testfcb: db 0
|
testfcb: db 0
|
||||||
db "HELLO ", "COM"
|
db "HELLO ", "COM"
|
||||||
times 30 db 0
|
times 30 db 0
|
||||||
|
@ -46,9 +46,21 @@ dinit: ; copy previously set DPT to our data area
|
|||||||
|
|
||||||
; int 13 stub
|
; int 13 stub
|
||||||
; place reserved for stack switches
|
; 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 0x13
|
||||||
;int 3
|
jc .err
|
||||||
|
ret
|
||||||
|
.err: push ax
|
||||||
|
call printf
|
||||||
|
db "int13 ERR AX=",2,0x0A,0x0D,0
|
||||||
|
stc
|
||||||
ret
|
ret
|
||||||
|
|
||||||
; restore DPT to default values if possible
|
; restore DPT to default values if possible
|
||||||
@ -156,7 +168,9 @@ read: push ax
|
|||||||
mov [dskseek+2], dx
|
mov [dskseek+2], dx
|
||||||
; do the actual read
|
; 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
|
_read: mov ch, 2
|
||||||
db 0x3D ; cmp ax, imm16: causes next instr to be skipped
|
db 0x3D ; cmp ax, imm16: causes next instr to be skipped
|
||||||
_write: mov ch, 3
|
_write: mov ch, 3
|
||||||
|
66
kernel/printf.asm
Normal file
66
kernel/printf.asm
Normal file
@ -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
|
Loading…
Reference in New Issue
Block a user