From 04a7087d79c1965c734799ed9f7e1b88f9004aa8 Mon Sep 17 00:00:00 2001 From: Ain <41307858+nero@users.noreply.github.com> Date: Tue, 19 May 2020 23:10:20 +0200 Subject: [PATCH] debug: First steps on instruction decoding --- debug/asm.asm | 96 ++++++++++++++++++++++++++++++++++++++++++++++--- debug/edit.asm | 9 +++++ debug/names.asm | 9 ++++- debug/run.asm | 5 --- 4 files changed, 108 insertions(+), 11 deletions(-) diff --git a/debug/asm.asm b/debug/asm.asm index b822346..bd8b8f7 100644 --- a/debug/asm.asm +++ b/debug/asm.asm @@ -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 diff --git a/debug/edit.asm b/debug/edit.asm index 60d2114..17cf561 100644 --- a/debug/edit.asm +++ b/debug/edit.asm @@ -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 diff --git a/debug/names.asm b/debug/names.asm index f9e0a88..06ca76e 100644 --- a/debug/names.asm +++ b/debug/names.asm @@ -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 diff --git a/debug/run.asm b/debug/run.asm index 98bb634..d110254 100644 --- a/debug/run.asm +++ b/debug/run.asm @@ -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, '-'