debug: Split commands into thematically organized files
This commit is contained in:
parent
8056ad5cfb
commit
a31e574b3a
@ -1,3 +1,61 @@
|
||||
; Commands and utils related to displaying or editing memory or registers
|
||||
|
||||
cmd_r: cmp byte [si], 0
|
||||
je printregs
|
||||
call eat_register
|
||||
jc .err
|
||||
mov al, [cs:bx+rnames]
|
||||
call putc
|
||||
mov al, [cs:bx+rnames+1]
|
||||
call putc
|
||||
call space
|
||||
call edit_word
|
||||
call crlf
|
||||
ret
|
||||
.err: mov di, eat_register.emsg
|
||||
jmp parse_error
|
||||
|
||||
printregs:
|
||||
mov cx, 13
|
||||
xor bx, bx
|
||||
mov ah, 0x0e
|
||||
mov si, reg_ax
|
||||
.loop: push cx
|
||||
mov dx, [cs:si+rnames]
|
||||
lodsw
|
||||
call printreg
|
||||
pop cx
|
||||
loop .loop
|
||||
|
||||
mov dx, [reg_fl]
|
||||
mov si, fnames
|
||||
mov cx, 16
|
||||
.floop: mov al, [cs:si]
|
||||
inc si
|
||||
cmp al, '+'
|
||||
je .fskip
|
||||
test dx, 0x8000
|
||||
jnz .fprnt
|
||||
mov al, '-'
|
||||
.fprnt: int 0x10
|
||||
.fskip: shl dx, 1
|
||||
loop .floop
|
||||
call crlf
|
||||
ret
|
||||
|
||||
printreg:
|
||||
push ax
|
||||
mov al, dl
|
||||
call putc
|
||||
mov al, dh
|
||||
call putc
|
||||
mov al, '='
|
||||
call putc
|
||||
pop dx
|
||||
call print16
|
||||
call space
|
||||
ret
|
||||
|
||||
; let the user edit the word at ES:BX
|
||||
edit_word:
|
||||
push bx
|
||||
|
@ -17,23 +17,17 @@ parse_error:
|
||||
; Advance over whitespace
|
||||
; IN DS:SI
|
||||
eat_whitespace:
|
||||
; peek on next char
|
||||
mov al, [si]
|
||||
; ES := CS
|
||||
push es
|
||||
push cs
|
||||
pop es
|
||||
; string search
|
||||
mov di, .chars
|
||||
mov cx, 4
|
||||
scasb
|
||||
; restore bss segment
|
||||
pop es
|
||||
jne .ret
|
||||
inc si
|
||||
jmp eat_whitespace
|
||||
.chars: db 0x09, 0x0A, 0x0D, 0x20
|
||||
.ret: ret
|
||||
.loop: lodsb
|
||||
cmp al, 0x20
|
||||
je .loop
|
||||
cmp al, 0x0A
|
||||
je .loop
|
||||
cmp al, 0x0D
|
||||
je .loop
|
||||
cmp al, 0x09
|
||||
je .loop
|
||||
dec si
|
||||
ret
|
||||
|
||||
; Parse a register name
|
||||
; IN DS:SI string to read
|
||||
|
83
debug/run.asm
Normal file
83
debug/run.asm
Normal file
@ -0,0 +1,83 @@
|
||||
; Commands related to executing debugged code
|
||||
|
||||
cmd_g: and word [reg_fl+1], 0xfe
|
||||
jmp return
|
||||
|
||||
cmd_t: or word [reg_fl+1], 0x03
|
||||
jmp return
|
||||
|
||||
int3entry:
|
||||
; save DS and load bss segment from IVT
|
||||
push ds
|
||||
mov ds, [cs:zero]
|
||||
mov ds, [bssvec*4]
|
||||
; save AX so we can work with it
|
||||
mov [reg_ax], ax
|
||||
; pop DS, IP, CS and flags from stack
|
||||
pop ax
|
||||
mov [reg_ds], ax
|
||||
pop ax
|
||||
mov [reg_ip], ax
|
||||
pop ax
|
||||
mov [reg_cs], ax
|
||||
pop ax
|
||||
mov [reg_fl], ax
|
||||
; save the other registers
|
||||
mov [reg_cx], cx
|
||||
mov [reg_dx], dx
|
||||
mov [reg_bx], bx
|
||||
mov [reg_sp], sp
|
||||
mov [reg_bp], bp
|
||||
mov [reg_si], si
|
||||
mov [reg_di], di
|
||||
; save other segment registers we can access
|
||||
mov [reg_ss], ss
|
||||
mov [reg_es], es
|
||||
; initialize other segments and setup stack
|
||||
mov ax, ds
|
||||
mov es, ax
|
||||
mov ss, ax
|
||||
mov sp, stack
|
||||
call crlf
|
||||
call printregs
|
||||
|
||||
loop: ; show prompt
|
||||
mov al, '-'
|
||||
call putc
|
||||
; read data
|
||||
mov byte [inmin], 1
|
||||
mov byte [inmax], 16
|
||||
mov word [ingetc], getcu
|
||||
call gets
|
||||
pushf
|
||||
call crlf
|
||||
popf
|
||||
jc loop
|
||||
; execute
|
||||
call runcmd
|
||||
jmp loop
|
||||
|
||||
return: ; restore stack pointer
|
||||
mov ss, [reg_ss]
|
||||
mov sp, [reg_sp]
|
||||
; push flags, CS and IP
|
||||
mov ax, [reg_fl]
|
||||
push ax
|
||||
mov ax, [reg_cs]
|
||||
push ax
|
||||
mov ax, [reg_ip]
|
||||
push ax
|
||||
; restore GPR
|
||||
mov ax, [reg_ax]
|
||||
mov cx, [reg_cx]
|
||||
mov dx, [reg_dx]
|
||||
mov bx, [reg_bx]
|
||||
mov bp, [reg_bp]
|
||||
mov si, [reg_si]
|
||||
mov di, [reg_di]
|
||||
; restore segment registers
|
||||
; DS must be last
|
||||
mov es, [reg_es]
|
||||
mov ds, [reg_ds]
|
||||
; final jump back
|
||||
iret
|
35
debug/util.asm
Normal file
35
debug/util.asm
Normal file
@ -0,0 +1,35 @@
|
||||
; Utility commands
|
||||
|
||||
cmd_h: call eat_whitespace
|
||||
call eat_hex_word
|
||||
jc .err
|
||||
|
||||
mov bx, dx
|
||||
|
||||
call eat_whitespace
|
||||
call eat_hex_word
|
||||
jc .err
|
||||
|
||||
xchg bx, dx
|
||||
|
||||
push dx
|
||||
add dx, bx
|
||||
call print16
|
||||
call space
|
||||
pop dx
|
||||
|
||||
sub dx, bx
|
||||
call print16
|
||||
|
||||
jmp crlf
|
||||
.err: mov di, eat_hex_word.emsg
|
||||
jmp parse_error
|
||||
|
||||
cmd_?: mov si, .txt
|
||||
jmp putcs
|
||||
.txt: db "G Go", 0x0A, 0x0D
|
||||
db "H w w Add and subtract two values", 0x0A, 0x0D
|
||||
db "R[r] Print register values", 0x0A, 0x0D
|
||||
db "T Single-Step", 0x0A, 0x0D
|
||||
db 0
|
||||
|
157
rom/debug.asm
157
rom/debug.asm
@ -57,93 +57,13 @@ init: push ds
|
||||
pop ds
|
||||
retf
|
||||
|
||||
%include "debug/parse.asm"
|
||||
%include "debug/chario.asm"
|
||||
%include "debug/edit.asm"
|
||||
|
||||
int3entry:
|
||||
; save DS and load bss segment from IVT
|
||||
push ds
|
||||
mov ds, [cs:zero]
|
||||
mov ds, [bssvec*4]
|
||||
; save AX so we can work with it
|
||||
mov [reg_ax], ax
|
||||
; pop DS, IP, CS and flags from stack
|
||||
pop ax
|
||||
mov [reg_ds], ax
|
||||
pop ax
|
||||
mov [reg_ip], ax
|
||||
pop ax
|
||||
mov [reg_cs], ax
|
||||
pop ax
|
||||
mov [reg_fl], ax
|
||||
; save the other registers
|
||||
mov [reg_cx], cx
|
||||
mov [reg_dx], dx
|
||||
mov [reg_bx], bx
|
||||
mov [reg_sp], sp
|
||||
mov [reg_bp], bp
|
||||
mov [reg_si], si
|
||||
mov [reg_di], di
|
||||
; save other segment registers we can access
|
||||
mov [reg_ss], ss
|
||||
mov [reg_es], es
|
||||
; initialize other segments and setup stack
|
||||
mov ax, ds
|
||||
mov es, ax
|
||||
mov ss, ax
|
||||
mov sp, stack
|
||||
call crlf
|
||||
call printregs
|
||||
|
||||
loop: ; show prompt
|
||||
mov al, '-'
|
||||
call putc
|
||||
; read data
|
||||
mov byte [inmin], 1
|
||||
mov byte [inmax], 16
|
||||
mov word [ingetc], getcu
|
||||
call gets
|
||||
pushf
|
||||
call crlf
|
||||
popf
|
||||
jc loop
|
||||
; execute
|
||||
call runcmd
|
||||
jmp loop
|
||||
|
||||
return: ; restore stack pointer
|
||||
mov ss, [reg_ss]
|
||||
mov sp, [reg_sp]
|
||||
; push flags, CS and IP
|
||||
mov ax, [reg_fl]
|
||||
push ax
|
||||
mov ax, [reg_cs]
|
||||
push ax
|
||||
mov ax, [reg_ip]
|
||||
push ax
|
||||
; restore GPR
|
||||
mov ax, [reg_ax]
|
||||
mov cx, [reg_cx]
|
||||
mov dx, [reg_dx]
|
||||
mov bx, [reg_bx]
|
||||
mov bp, [reg_bp]
|
||||
mov si, [reg_si]
|
||||
mov di, [reg_di]
|
||||
; restore segment registers
|
||||
; DS must be last
|
||||
mov es, [reg_es]
|
||||
mov ds, [reg_ds]
|
||||
; final jump back
|
||||
iret
|
||||
|
||||
%include "debug/names.asm"
|
||||
|
||||
; Expects DI to mark end of command
|
||||
runcmd: mov si, inbuf
|
||||
lodsb
|
||||
cmp al, 'G'
|
||||
je cmd_g
|
||||
cmp al, 'H'
|
||||
je cmd_h
|
||||
cmp al, 'R'
|
||||
je cmd_r
|
||||
cmp al, 'T'
|
||||
@ -154,74 +74,13 @@ cerr: mov al, '?'
|
||||
call putc
|
||||
jmp crlf
|
||||
|
||||
cmd_?: mov si, .txt
|
||||
jmp putcs
|
||||
.txt: db "G Go", 0x0A, 0x0D
|
||||
db "R[r] Print register values", 0x0A, 0x0D
|
||||
db "T Single-Step", 0x0A, 0x0D
|
||||
db 0
|
||||
%include "debug/chario.asm"
|
||||
%include "debug/parse.asm"
|
||||
%include "debug/names.asm"
|
||||
|
||||
cmd_g: and word [reg_fl+1], 0xfe
|
||||
jmp return
|
||||
|
||||
cmd_r: cmp byte [si], 0
|
||||
je printregs
|
||||
call eat_register
|
||||
jc .err
|
||||
mov al, [cs:bx+rnames]
|
||||
call putc
|
||||
mov al, [cs:bx+rnames+1]
|
||||
call putc
|
||||
call space
|
||||
call edit_word
|
||||
call crlf
|
||||
ret
|
||||
.err: mov di, eat_register.emsg
|
||||
jmp parse_error
|
||||
|
||||
cmd_t: or word [reg_fl+1], 0x03
|
||||
jmp return
|
||||
|
||||
printregs:
|
||||
mov cx, 13
|
||||
xor bx, bx
|
||||
mov ah, 0x0e
|
||||
mov si, reg_ax
|
||||
.loop: push cx
|
||||
mov dx, [cs:si+rnames]
|
||||
lodsw
|
||||
call printreg
|
||||
pop cx
|
||||
loop .loop
|
||||
|
||||
mov dx, [reg_fl]
|
||||
mov si, fnames
|
||||
mov cx, 16
|
||||
.floop: mov al, [cs:si]
|
||||
inc si
|
||||
cmp al, '+'
|
||||
je .fskip
|
||||
test dx, 0x8000
|
||||
jnz .fprnt
|
||||
mov al, '-'
|
||||
.fprnt: int 0x10
|
||||
.fskip: shl dx, 1
|
||||
loop .floop
|
||||
call crlf
|
||||
ret
|
||||
|
||||
printreg:
|
||||
push ax
|
||||
mov al, dl
|
||||
call putc
|
||||
mov al, dh
|
||||
call putc
|
||||
mov al, '='
|
||||
call putc
|
||||
pop dx
|
||||
call print16
|
||||
call space
|
||||
ret
|
||||
%include "debug/edit.asm"
|
||||
%include "debug/run.asm"
|
||||
%include "debug/util.asm"
|
||||
|
||||
align 512
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user