Revamp debugger, including support for printing padded numbers
This commit is contained in:
parent
dab565ee41
commit
8aafa98c6a
117
kernel/debug.asm
117
kernel/debug.asm
@ -1,3 +1,93 @@
|
||||
; Names for words in debug frame
|
||||
; Two characters per word, 14 words total
|
||||
debug_frame_names:
|
||||
; general-purpose registers
|
||||
db "AXBXCXDXSPBPSIDI"
|
||||
; extra registers
|
||||
db "DSESSSIPCSFL"
|
||||
|
||||
; Names for bits in debug_frame+26 (FL/Flags register)
|
||||
; One character per bit, 16 bits total
|
||||
debug_frame_flags:
|
||||
db "++++ODIT"
|
||||
db "SZ+A+P+C"
|
||||
|
||||
; Print a single register from the frame
|
||||
; in SI frame offset for register
|
||||
debug_frame_register_print:
|
||||
mov bx, debug_frame_names
|
||||
mov al, [cs:bx+si] ; first name char load
|
||||
call putc
|
||||
mov al, [cs:bx+si+1] ; second name char load
|
||||
call putc
|
||||
mov al, '='
|
||||
call putc
|
||||
mov ax, [ss:bp+si] ; value load
|
||||
; prepare call to print_number
|
||||
push bx
|
||||
push cx
|
||||
mov bx, 0x0010
|
||||
mov cx, 3
|
||||
call print_number_padded
|
||||
pop cx
|
||||
pop bx
|
||||
mov al, ' '
|
||||
call putc
|
||||
ret
|
||||
|
||||
debug_frame_print:
|
||||
mov si, 0
|
||||
mov cx, 8
|
||||
.reg1loop:
|
||||
call debug_frame_register_print
|
||||
add si, 2
|
||||
loop .reg1loop
|
||||
|
||||
mov dx, [ss:bp+26]
|
||||
mov di, debug_frame_flags
|
||||
mov cx, 0x0010
|
||||
.flag_loop:
|
||||
mov al, [cs:di]
|
||||
inc di
|
||||
cmp al, '+'
|
||||
je .next
|
||||
test dx, 0x8000
|
||||
jnz .write
|
||||
mov al, '-'
|
||||
.write:
|
||||
call putc
|
||||
.next:
|
||||
sal dx, 1
|
||||
loop .flag_loop
|
||||
|
||||
call printf
|
||||
db 0x0A, 0x0D, 0
|
||||
|
||||
mov si, 16
|
||||
mov cx, 3
|
||||
.reg2loop:
|
||||
call debug_frame_register_print
|
||||
add si, 2
|
||||
loop .reg2loop
|
||||
|
||||
mov ax, [bp+24]
|
||||
mov bx, 0x0010
|
||||
mov cx, 3
|
||||
call print_number_padded
|
||||
|
||||
mov al, ':'
|
||||
call putc
|
||||
|
||||
mov ax, [bp+22]
|
||||
mov bx, 0x0010
|
||||
mov cx, 3
|
||||
call print_number_padded
|
||||
|
||||
call printf
|
||||
db 0x0A, 0x0D, 0
|
||||
|
||||
ret
|
||||
|
||||
; this prints registers
|
||||
; expect to be called as interrupt routine
|
||||
isr_debug:
|
||||
@ -13,34 +103,20 @@ isr_debug:
|
||||
push bx
|
||||
push ax
|
||||
|
||||
call printf
|
||||
db "AX=%X BX=%X CX=%X DX=%X", 0x20
|
||||
db "SP=%X BP=%X SI=%X DI=%X", 0x0A, 0x0D
|
||||
db "DS=%X ES=%X SS=%X IP=%X CS=%X", 0x20, 0
|
||||
|
||||
mov bp, sp
|
||||
mov bx, [ss:bp+26]
|
||||
mov si, .flags
|
||||
mov cx, 0x0010
|
||||
.loop:
|
||||
mov al, [cs:si]
|
||||
inc si
|
||||
test bx, 0x8000
|
||||
jnz .write
|
||||
mov al, '-'
|
||||
.write:
|
||||
sal bx, 1
|
||||
call putc
|
||||
loop .loop
|
||||
mov [bp+08], bp
|
||||
add WORD [bp+08], 28
|
||||
|
||||
call printf
|
||||
db 0x0A, 0x0D, 0
|
||||
|
||||
call debug_frame_print
|
||||
|
||||
pop ax
|
||||
pop bx
|
||||
pop cx
|
||||
pop dx
|
||||
pop sp
|
||||
pop bp ; sp to be ignored
|
||||
pop bp
|
||||
pop si
|
||||
pop di
|
||||
@ -48,6 +124,3 @@ isr_debug:
|
||||
pop es
|
||||
pop ss
|
||||
iret
|
||||
.flags:
|
||||
; 16 letters for each bit in flags register
|
||||
db "++++ODITSZ+A+P+C"
|
@ -48,24 +48,46 @@ printf:
|
||||
call print_string
|
||||
jmp .loop
|
||||
|
||||
; converts a integer to ascii
|
||||
; in ax input integer
|
||||
; bx base
|
||||
; cx minimum number of digits
|
||||
; out bx garbled
|
||||
; dx garbled
|
||||
print_number_padded:
|
||||
xor dx, dx
|
||||
div bx
|
||||
push dx
|
||||
dec cx
|
||||
jz .nopad
|
||||
call print_number_padded
|
||||
jmp print_number.end
|
||||
.nopad:
|
||||
call print_number
|
||||
jmp print_number.end
|
||||
|
||||
; converts a integer to ascii
|
||||
; in ax input integer
|
||||
; bx base
|
||||
; out bx garbled
|
||||
; dx garbled
|
||||
print_number:
|
||||
xor dx, dx
|
||||
div bx ; ax = dx:ax / 10, dx = dx:ax % 10
|
||||
and ax, ax
|
||||
jz .print
|
||||
push dx
|
||||
and ax, ax
|
||||
jz .end
|
||||
call print_number
|
||||
pop dx
|
||||
.print:
|
||||
mov al, dl
|
||||
add al, 0x30
|
||||
cmp al, 0x3A
|
||||
jl .noadj
|
||||
add al, 0x07
|
||||
.noadj:
|
||||
.end:
|
||||
pop bx
|
||||
xor bh, bh
|
||||
add bx, print_chars
|
||||
mov al, [cs:bx]
|
||||
call putc
|
||||
ret
|
||||
|
||||
; putc's a string
|
||||
; in DS:AX null-terminated string
|
||||
print_string:
|
||||
push si
|
||||
mov si, ax
|
||||
@ -78,3 +100,6 @@ print_string:
|
||||
.end:
|
||||
pop si
|
||||
ret
|
||||
|
||||
print_chars:
|
||||
db "0123456789ABCDEF"
|
Loading…
Reference in New Issue
Block a user