Remove attempt of rom-based debugger
This commit is contained in:
parent
d6b5792ff7
commit
c604fd43e7
@ -1,95 +0,0 @@
|
||||
|
||||
; Prints instruction at DS:SI in human-readable form
|
||||
disasm: lodsb
|
||||
mov bx, opcodes
|
||||
jmp .scan
|
||||
|
||||
.next: add bx, 8
|
||||
.scan: push ax
|
||||
and al, [cs:bx]
|
||||
cmp al, [cs:bx+1]
|
||||
pop ax
|
||||
jne .next
|
||||
|
||||
push si
|
||||
push ax
|
||||
mov si, [cs:bx+2]
|
||||
call putcs
|
||||
pop ax
|
||||
pop si
|
||||
|
||||
cmp word [cs:bx+4], 0
|
||||
je .ret
|
||||
|
||||
push ax
|
||||
call space
|
||||
pop ax
|
||||
push ax
|
||||
call [cs:bx+4]
|
||||
pop ax
|
||||
|
||||
cmp word [cs:bx+6], 0
|
||||
je .ret
|
||||
|
||||
push ax
|
||||
call print_sep
|
||||
pop ax
|
||||
jmp [cs:bx+6]
|
||||
.ret: ret
|
||||
|
||||
opcodes:
|
||||
; word 1: H=opcode value after AND L
|
||||
; word 2: ptr to memonic
|
||||
; word 3: procedure to print first operand
|
||||
; word 4: procedure to print second operand
|
||||
dw 0x50F8, mnem.push, operand.inr16, 0
|
||||
dw 0x58F8, mnem.pop, operand.inr16, 0
|
||||
dw 0xB0F8, mnem.mov, operand.inr8, 0
|
||||
dw 0xB8F8, mnem.mov, operand.inr16, operand.imm16
|
||||
dw 0xA4FF, mnem.movsb, 0, 0
|
||||
dw 0xA5FF, mnem.movsw, 0, 0
|
||||
dw 0x0000, mnem.db, operand.self, 0
|
||||
|
||||
print_sep:
|
||||
mov al, ','
|
||||
call putc
|
||||
jmp space
|
||||
|
||||
print_r8:
|
||||
push di
|
||||
mov di, bnames
|
||||
call print_r
|
||||
pop di
|
||||
ret
|
||||
|
||||
print_r16:
|
||||
push di
|
||||
mov di, rnames
|
||||
call print_r
|
||||
pop di
|
||||
ret
|
||||
|
||||
print_r:
|
||||
push bx
|
||||
mov bl, al
|
||||
xor bh, bh
|
||||
add bx, bx
|
||||
mov bx, [cs:bx+di]
|
||||
mov al, bl
|
||||
call putc
|
||||
mov al, bh
|
||||
call putc
|
||||
pop bx
|
||||
ret
|
||||
|
||||
operand:
|
||||
.inr8: and al, 7
|
||||
jmp print_r8
|
||||
.inr16: and al, 7
|
||||
jmp print_r16
|
||||
.self: mov dl, al
|
||||
jmp print_dl
|
||||
.imm8: mov dl, [si]
|
||||
jmp print_dl
|
||||
.imm16: mov dx, [si]
|
||||
jmp print_dx
|
163
debug/chario.asm
163
debug/chario.asm
@ -1,163 +0,0 @@
|
||||
; Print AL
|
||||
space: mov al, ' '
|
||||
putc: push bx
|
||||
xor bx, bx
|
||||
mov ah, 0x0e
|
||||
int 0x10
|
||||
pop bx
|
||||
ret
|
||||
|
||||
; Print code string CS:SI
|
||||
putcs: push ds
|
||||
push cs
|
||||
pop ds
|
||||
call putds
|
||||
pop ds
|
||||
ret
|
||||
|
||||
; Print data string DS:SI
|
||||
putds: lodsb
|
||||
test al, al
|
||||
jz .ret
|
||||
call putc
|
||||
jmp putds
|
||||
.ret: ret
|
||||
|
||||
crlf: mov al, 0x0A
|
||||
call putc
|
||||
mov al, 0x0D
|
||||
jmp putc
|
||||
|
||||
print_dl:
|
||||
mov cl, 4
|
||||
; repeat 2 times
|
||||
call .c
|
||||
.c: mov al, dl
|
||||
shl dx, cl
|
||||
shr al, cl
|
||||
add al, 0x30
|
||||
cmp al, 0x3a
|
||||
jl putc
|
||||
add al, 7
|
||||
jmp putc
|
||||
|
||||
print_dx:
|
||||
mov cl, 4
|
||||
; this double-call is essentially a 4 times repeating loop
|
||||
call .c1
|
||||
.c1: call .c2
|
||||
.c2: ; 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 putc
|
||||
; ... add 7 so we continue at 'A'
|
||||
add al, 7
|
||||
jmp putc
|
||||
|
||||
print_esbx:
|
||||
push cx
|
||||
push dx
|
||||
mov dx, es
|
||||
call print_dx
|
||||
mov al, ':'
|
||||
call putc
|
||||
mov dx, bx
|
||||
call print_dx
|
||||
pop dx
|
||||
pop cx
|
||||
ret
|
||||
|
||||
; Read character
|
||||
getc: xor ax, ax
|
||||
int 0x16
|
||||
test al, al
|
||||
jz getc
|
||||
test al, 0x80
|
||||
jnz getc
|
||||
ret
|
||||
|
||||
; Read uppercased character
|
||||
getcu: call getc
|
||||
cmp al, 'a'
|
||||
jc .ret
|
||||
cmp al, 'z'
|
||||
ja .ret
|
||||
and al, 0xDF
|
||||
.ret: ret
|
||||
|
||||
; Read hexadecimal character
|
||||
getch: call getcu
|
||||
; everything above F is invalid
|
||||
cmp al, 'F'
|
||||
ja getch
|
||||
; everything above or equal A is ok
|
||||
cmp al, 'A'
|
||||
jae .ret
|
||||
; everything above 9 is invalid
|
||||
cmp al, '9'
|
||||
ja getc
|
||||
; everything above or equal 0 is valid
|
||||
cmp al, '0'
|
||||
jae .ret
|
||||
; everything above or equal ' ' is invalid
|
||||
cmp al, ' '
|
||||
jae getch
|
||||
.ret: ret
|
||||
|
||||
; Read string into inbuf
|
||||
; IN ingetc ptr to getc function
|
||||
; inlen max number of chars
|
||||
gets: push bx
|
||||
mov di, inbuf
|
||||
; calculate max pointer for writing
|
||||
mov dx, [inmin]
|
||||
.loop: call [ingetc]
|
||||
; test for Ctrl+C, Enter and Backspace
|
||||
cmp al, 0x03
|
||||
je .can
|
||||
cmp al, 0x0D
|
||||
je .enter
|
||||
cmp al, 0x08
|
||||
je .bs
|
||||
; ignore other ctl chars
|
||||
cmp al, 0x20
|
||||
jc .loop
|
||||
; check if we are full
|
||||
mov bx, di
|
||||
sub bx, inbuf
|
||||
; bl is now number of characters we have
|
||||
cmp bl, dh
|
||||
jnc .loop
|
||||
stosb
|
||||
call putc
|
||||
jmp .loop
|
||||
; backspace: print, print space, print backspace again
|
||||
.bs: cmp di, inbuf
|
||||
jbe .loop
|
||||
push ax
|
||||
call putc
|
||||
call space
|
||||
pop ax
|
||||
call putc
|
||||
dec di
|
||||
jmp .loop
|
||||
; ctrl+c: return with carry set
|
||||
.can: stc
|
||||
pop bx
|
||||
ret
|
||||
; enter: if enough chars, return
|
||||
.enter: mov bx, di
|
||||
sub bx, inbuf
|
||||
cmp bl, dl
|
||||
jc .loop
|
||||
xor al, al
|
||||
stosb
|
||||
pop bx
|
||||
ret
|
@ -1,90 +0,0 @@
|
||||
; 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 space
|
||||
|
||||
push ds
|
||||
mov ds, [es:reg_cs]
|
||||
mov si, [es:reg_ip]
|
||||
call disasm
|
||||
pop ds
|
||||
|
||||
call crlf
|
||||
ret
|
||||
|
||||
printreg:
|
||||
push ax
|
||||
mov al, dl
|
||||
call putc
|
||||
mov al, dh
|
||||
call putc
|
||||
mov al, '='
|
||||
call putc
|
||||
pop dx
|
||||
call print_dx
|
||||
call space
|
||||
ret
|
||||
|
||||
; let the user edit the word at ES:BX
|
||||
edit_word:
|
||||
push bx
|
||||
mov dx, [es:bx]
|
||||
call print_dx
|
||||
mov al, '.'
|
||||
call putc
|
||||
mov byte [inmin], 4
|
||||
mov byte [inmax], 4
|
||||
mov word [ingetc], getch
|
||||
call gets
|
||||
pop bx
|
||||
jc .ret
|
||||
|
||||
mov si, inbuf
|
||||
call eat_hex_word
|
||||
jc .err
|
||||
mov [es:bx], dx
|
||||
|
||||
.ret: ret
|
||||
.err: call crlf
|
||||
mov di, eat_hex_word.emsg
|
||||
jmp parse_error
|
@ -1,20 +0,0 @@
|
||||
rnames: ; general purpose regs
|
||||
db "AXCXDXBXSPBPSIDI"
|
||||
; segment regs
|
||||
db "ESCSSSDS"
|
||||
; special regs
|
||||
db "IPFL"
|
||||
bnames: ; 8-bit registers
|
||||
db "ALCLDLBLAHCHDHBH"
|
||||
fnames: ; control flags
|
||||
db "++++ODIT"
|
||||
; status flags
|
||||
db "SZ+A+P+C"
|
||||
|
||||
mnem:
|
||||
.db: db "DB", 0
|
||||
.push: db "PUSH", 0
|
||||
.pop: db "POP", 0
|
||||
.mov: db "MOV", 0
|
||||
.movsb: db "MOVSB", 0
|
||||
.movsw: db "MOVSW", 0
|
119
debug/parse.asm
119
debug/parse.asm
@ -1,119 +0,0 @@
|
||||
; IN DS:SI remaining unparsed string
|
||||
; CS:DI error message
|
||||
parse_error:
|
||||
push si
|
||||
mov si, .str1
|
||||
call putcs
|
||||
mov si, di
|
||||
call putcs
|
||||
mov si, .str2
|
||||
call putcs
|
||||
pop si
|
||||
call putds
|
||||
jmp crlf
|
||||
.str1: db "Not a ", 0
|
||||
.str2: db ": ", 0
|
||||
|
||||
; Advance over whitespace
|
||||
; IN DS:SI
|
||||
eat_whitespace:
|
||||
.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
|
||||
; OUT CF set if no match
|
||||
; BX register number * 2 if CF clear
|
||||
eat_register:
|
||||
push si
|
||||
push es
|
||||
lodsw
|
||||
and ax, 0xDFDF
|
||||
; ES := CS
|
||||
push cs
|
||||
pop es
|
||||
mov di, rnames
|
||||
mov cx, 14
|
||||
repne scasw
|
||||
pop es
|
||||
jne .fail
|
||||
pop bx
|
||||
mov bx, di
|
||||
sub bx, (rnames+2)
|
||||
clc
|
||||
ret
|
||||
.fail: pop si
|
||||
stc
|
||||
ret
|
||||
.emsg: db "register name", 0
|
||||
|
||||
; Parse hex digit
|
||||
; IN DS:SI
|
||||
; OUT AL
|
||||
eat_hex_digit:
|
||||
push si
|
||||
lodsb
|
||||
sub al, '0'
|
||||
jc .err
|
||||
cmp al, 9
|
||||
jna .ret
|
||||
sub al, 7
|
||||
cmp al, 0xF
|
||||
ja .err
|
||||
.ret: add sp, 2
|
||||
ret
|
||||
.err: pop si
|
||||
stc
|
||||
ret
|
||||
.emsg: db "hex digit", 0
|
||||
|
||||
; Parse hexadecimal byte
|
||||
; IN DS:SI
|
||||
; OUT DL or carry set
|
||||
eat_hex_byte:
|
||||
push si
|
||||
mov cl, 4
|
||||
xor dl, dl
|
||||
|
||||
call eat_hex_digit
|
||||
jc .err
|
||||
or dl, al
|
||||
shl dl, cl
|
||||
call eat_hex_digit
|
||||
jc .err
|
||||
or dl, al
|
||||
|
||||
add sp, 2
|
||||
ret
|
||||
.err: pop si
|
||||
stc
|
||||
ret
|
||||
.emsg: db "hex byte", 0
|
||||
|
||||
; Parse hexadecimal word
|
||||
; OUT DX or carry set
|
||||
eat_hex_word:
|
||||
push si
|
||||
xor dx, dx
|
||||
|
||||
call eat_hex_byte
|
||||
jc .err
|
||||
mov dh, dl
|
||||
call eat_hex_byte
|
||||
jc .err
|
||||
|
||||
add sp, 2
|
||||
ret
|
||||
.err: pop si
|
||||
stc
|
||||
ret
|
||||
.emsg: db "hex word", 0
|
@ -1,83 +0,0 @@
|
||||
; 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
|
@ -1,35 +0,0 @@
|
||||
; 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 print_dx
|
||||
call space
|
||||
pop dx
|
||||
|
||||
sub dx, bx
|
||||
call print_dx
|
||||
|
||||
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
|
||||
|
114
rom/debug.asm
114
rom/debug.asm
@ -1,114 +0,0 @@
|
||||
cpu 8086
|
||||
org 0x0000
|
||||
|
||||
; interrupt vector we store addr of data segment in
|
||||
bssvec: equ 0xB6
|
||||
|
||||
db 0x55, 0xAA
|
||||
db 0x00
|
||||
jmp near init
|
||||
|
||||
times (0x18 - ($-$$)) db 0
|
||||
dw 0
|
||||
dw pnp
|
||||
|
||||
pnp: db "$PnP"
|
||||
db 1 ; version 1
|
||||
db 2 ; 2 * 16 length
|
||||
dw 0 ; offset of next header
|
||||
db 0
|
||||
db 0 ; checksum (filled by fix-rom)
|
||||
dd 0 ; device identifier
|
||||
dw 0 ; manufacturer string
|
||||
dw name ; product name string
|
||||
db 0,0,0 ; device type string
|
||||
db 0x20 ; device indicator, bit for "read cacheable" set
|
||||
dw 0 ; boot connection vector
|
||||
dw 0 ; boot disconnect vector
|
||||
dw 0 ; bootstrap entry point
|
||||
dw 0 ; reserved
|
||||
zero: dw 0
|
||||
|
||||
name: db "rdos debug", 0
|
||||
|
||||
init: push ds
|
||||
push ax
|
||||
push cx
|
||||
|
||||
; DS := 0
|
||||
xor ax, ax
|
||||
mov ds, ax
|
||||
; allocate a single kilobyte from end of lowmem
|
||||
dec word [0x413]
|
||||
; calculate segment from kilobytes
|
||||
mov ax, [0x413]
|
||||
mov cl, 6
|
||||
shl ax, cl
|
||||
; store ptr to our data segment in B6h vector
|
||||
mov word [bssvec*4], ax
|
||||
; set entry points vectors
|
||||
mov word [1*4], int3entry
|
||||
mov word [1*4+2], cs
|
||||
mov word [3*4], int3entry
|
||||
mov word [3*4+2], cs
|
||||
|
||||
pop cx
|
||||
pop ax
|
||||
pop ds
|
||||
retf
|
||||
|
||||
; 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'
|
||||
je cmd_t
|
||||
cmp al, '?'
|
||||
je cmd_?
|
||||
cerr: mov al, '?'
|
||||
call putc
|
||||
jmp crlf
|
||||
|
||||
%include "debug/chario.asm"
|
||||
%include "debug/parse.asm"
|
||||
%include "debug/names.asm"
|
||||
|
||||
%include "debug/edit.asm"
|
||||
%include "debug/run.asm"
|
||||
%include "debug/util.asm"
|
||||
%include "debug/asm.asm"
|
||||
|
||||
align 512
|
||||
|
||||
absolute 0
|
||||
reg_ax: resw 1
|
||||
reg_cx: resw 1
|
||||
reg_dx: resw 1
|
||||
reg_bx: resw 1
|
||||
reg_sp: resw 1
|
||||
reg_bp: resw 1
|
||||
reg_si: resw 1
|
||||
reg_di: resw 1
|
||||
|
||||
reg_es: resw 1
|
||||
reg_cs: resw 1
|
||||
reg_ss: resw 1
|
||||
reg_ds: resw 1
|
||||
|
||||
reg_ip: resw 1
|
||||
reg_fl: resw 1
|
||||
|
||||
ingetc: resw 1
|
||||
inmin: resb 1
|
||||
inmax: resb 1
|
||||
inbuf: resb 0x20
|
||||
|
||||
; reserve at least 80h words for stack
|
||||
resw 0x80
|
||||
alignb 1024
|
||||
stack:
|
Loading…
Reference in New Issue
Block a user