From fc1aa47039da8e6abc7c9b5ddc7199cc460573e6 Mon Sep 17 00:00:00 2001 From: Ain <41307858+nero@users.noreply.github.com> Date: Mon, 18 May 2020 20:05:06 +0200 Subject: [PATCH] debug: Implement parsing of register names --- Makefile | 2 +- debug/names.asm | 10 ++++ debug/parse.asm | 58 +++++++++++++++++++++ rom/debug.asm | 131 ++++++++++++++++++++++++++---------------------- 4 files changed, 140 insertions(+), 61 deletions(-) create mode 100644 debug/names.asm create mode 100644 debug/parse.asm diff --git a/Makefile b/Makefile index 38adf3a..1380c71 100644 --- a/Makefile +++ b/Makefile @@ -65,7 +65,7 @@ fate.bs: boot/fat.asm $(NASM) $(NASM_ARGS) -DFAT16 -DLBA -DLARGE -o $@ $< # BIOS option roms -%.rom: rom/%.asm utils/fix-rom +%.rom: rom/%.asm %/*.asm utils/fix-rom $(NASM) $(NASM_ARGS) -o $@ $< && utils/fix-rom $@ fdimage.img: fat1.bs $(DISTFILES) diff --git a/debug/names.asm b/debug/names.asm new file mode 100644 index 0000000..8633faa --- /dev/null +++ b/debug/names.asm @@ -0,0 +1,10 @@ +rnames: ; general purpose regs + db "AXCXDXBXSPBPSIDI" + ; segment regs + db "ESCSSSDS" + ; special regs + db "IPFL" +fnames: ; control flags + db "++++ODIT" + ; status flags + db "SZ+A+P+C" diff --git a/debug/parse.asm b/debug/parse.asm new file mode 100644 index 0000000..a99f9e4 --- /dev/null +++ b/debug/parse.asm @@ -0,0 +1,58 @@ + ; IN DS:SI remaining unparsed string + ; CS:DI error message +parse_error: + push si + mov si, di + call putcs + mov al, ':' + call putc + mov al, ' ' + call putc + pop si + call putds + jmp crlf + +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 + + ; 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 "Not a register name", 0 diff --git a/rom/debug.asm b/rom/debug.asm index 8424bb3..7d74f0e 100644 --- a/rom/debug.asm +++ b/rom/debug.asm @@ -6,8 +6,7 @@ bssvec: equ 0xB6 db 0x55, 0xAA db 0x00 - jmp init - nop + jmp near init times (0x18 - ($-$$)) db 0 dw 0 @@ -58,6 +57,8 @@ init: push ds pop ds retf + %include "debug/parse.asm" + ; Print AL space: mov al, ' ' putc: xor bx, bx @@ -65,17 +66,21 @@ putc: xor bx, bx int 0x10 ret - ; Print CS:SI -puts: push ds + ; Print code string CS:SI +putcs: push ds push cs pop ds -.loop: lodsb + call putds + pop ds + ret + + ; Print data string DS:SI +putds: lodsb test al, al jz .ret call putc - jmp .loop -.ret: pop ds - ret + jmp putds +.ret: ret crlf: mov al, 0x0A call putc @@ -106,6 +111,47 @@ print16: .noadj: int 0x10 ret +getc: xor ax, ax + int 0x16 + test al, al + jz getc + ret + +read: mov di, cmdbuf +.loop: call getc + cmp al, 0x03 + je .can + cmp al, 0x0D + je .enter + cmp al, 0x08 + je .bs + cmp di, cmdbuf+cmdlen-1 + jnc .loop + stosb + mov ah, 0x0e + xor bx, bx + int 0x10 + jmp .loop + ret +.bs: cmp di, cmdbuf + jbe .loop + xor bx, bx + mov ax, 0x0e08 + int 0x10 + mov al, 0x20 + int 0x10 + mov al, 0x08 + int 0x10 + dec di + jmp .loop +.can: xor al, al + stosb + stc + ret +.enter: xor al, al + stosb + ret + int3entry: ; save DS and load bss segment from IVT push ds @@ -143,7 +189,7 @@ int3entry: loop: ; show prompt mov al, '-' - int 0x10 + call putc ; read data call read pushf @@ -179,54 +225,11 @@ return: ; restore stack pointer ; final jump back iret -names: ; general purpose regs - db "AXCXDXBXSPBPSIDI" - ; segment regs - db "ESCSSSDS" - ; special regs - db "IPFL" -fnames: ; control flags - db "++++ODIT" - ; status flags - db "SZ+A+P+C" + %include "debug/names.asm" -getc: xor ax, ax - int 0x16 - test al, al - jz getc - ret - -read: mov di, cmdbuf -.loop: call getc - cmp al, 0x03 - je .can - cmp al, 0x0D - je .enter - cmp al, 0x08 - je .bs - cmp di, cmdbuf+cmdlen - jnc .loop - stosb - mov ah, 0x0e - xor bx, bx - int 0x10 - jmp .loop - ret -.bs: cmp di, cmdbuf - jbe .loop - xor bx, bx - mov ax, 0x0e08 - int 0x10 - mov al, 0x20 - int 0x10 - mov al, 0x08 - int 0x10 - dec di - jmp .loop -.can: stc -.enter: ret - -runcmd: mov al, [cmdbuf] + ; Expects DI to mark end of command +runcmd: mov si, cmdbuf + lodsb cmp al, 'g' je cmd_g cmp al, 'r' @@ -235,12 +238,12 @@ runcmd: mov al, [cmdbuf] je cmd_t cmp al, '?' je cmd_? - mov al, '?' +cerr: mov al, '?' call putc jmp crlf cmd_?: mov si, .txt - jmp puts + jmp putcs .txt: db "g Go", 0x0A, 0x0D db "r Print register values", 0x0A, 0x0D db "t Single-Step", 0x0A, 0x0D @@ -249,7 +252,15 @@ cmd_?: mov si, .txt cmd_g: and word [reg_fl+1], 0xfe jmp return -cmd_r: jmp printregs +cmd_r: cmp di, si + je printregs + call eat_register + jc .err + mov dx, si + call print16 + ret +.err: mov di, eat_register.emsg + jmp parse_error cmd_t: or word [reg_fl+1], 0x03 jmp return @@ -260,7 +271,7 @@ printregs: mov ah, 0x0e mov si, reg_ax .loop: push cx - mov dx, [cs:si+names] + mov dx, [cs:si+rnames] lodsw call printreg pop cx