debug: First steps on instruction decoding

This commit is contained in:
Nero 2020-05-19 23:10:20 +02:00
parent e60e49735c
commit 04a7087d79
4 changed files with 108 additions and 11 deletions

View File

@ -1,9 +1,95 @@
; Prints instruction at ES:BX in human-readable form
disasm: call print_esbx
call space
mov si, instr.db
; 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
call crlf
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

View File

@ -40,6 +40,15 @@ printregs:
.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

View File

@ -4,10 +4,17 @@ rnames: ; general purpose 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"
instr:
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

View File

@ -40,11 +40,6 @@ int3entry:
mov sp, stack
call crlf
call printregs
push es
mov es, [reg_cs]
mov bx, [reg_ip]
call disasm
pop es
loop: ; show prompt
mov al, '-'