From d6b5792ff702d694a8ddccfd3a716909f9d295b2 Mon Sep 17 00:00:00 2001 From: Nero <41307858+nero@users.noreply.github.com> Date: Sat, 15 Aug 2020 20:58:40 +0000 Subject: [PATCH] Make dprintf the default debugging facility --- Makefile | 4 +- rom/dprintf.asm | 159 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 161 insertions(+), 2 deletions(-) create mode 100644 rom/dprintf.asm diff --git a/Makefile b/Makefile index a1a5db9..d83cba9 100644 --- a/Makefile +++ b/Makefile @@ -18,7 +18,7 @@ QEMU_ARGS += --enable-kvm endif ifdef DEBUG -ROMS += debug.rom +ROMS += dprintf.rom NASM_ARGS += -l $(basename $@).lst endif @@ -65,7 +65,7 @@ fate.bs: boot/fat.asm $(NASM) $(NASM_ARGS) -DFAT16 -DLBA -DLARGE -o $@ $< # BIOS option roms -%.rom: rom/%.asm %/*.asm utils/fix-rom +%.rom: rom/%.asm utils/fix-rom $(NASM) $(NASM_ARGS) -o $@ $< && utils/fix-rom $@ fdimage.img: fat1.bs $(DISTFILES) diff --git a/rom/dprintf.asm b/rom/dprintf.asm new file mode 100644 index 0000000..b781fbb --- /dev/null +++ b/rom/dprintf.asm @@ -0,0 +1,159 @@ + cpu 8086 + org 0x0000 + + db 0x55, 0xAA + db 0x00 + jmp init + nop + + 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 + dw 0 + +name: db "dprintf" + +init: push ds + push ax + xor ax, ax + mov ds, ax + + mov word [1*4], int3entry + mov word [1*4+2], cs + mov word [3*4], int3entry + mov word [3*4+2], cs + + pop ax + pop ds + retf + +crlf: xor bx, bx + mov ax, 0x0e0a + int 0x10 + mov al, 0x0d + int 0x10 + ret + +printr: mov al, cl + int 0x10 + mov al, ch + int 0x10 + mov al, '=' + int 0x10 + call printd + mov al, ' ' + int 0x10 + ret + +printd: 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 .noadj + ; ... add 7 so we continue at 'A' + add al, 7 +.noadj: int 0x10 + ret + +int3entry: + push bx + push dx + push cx + push ax + push bp + mov bp, sp + + call crlf + + xor bx, bx + mov ah, 0x0e + mov cx, 'AX' + mov dx, [bp+2] + call printr + + mov cx, 'CX' + mov dx, [bp+4] + call printr + + mov cx, 'DX' + mov dx, [bp+6] + call printr + + mov cx, 'BX' + mov dx, [bp+8] + call printr + + mov cx, 'BP' + mov dx, [bp] + call printr + + mov cx, 'SP' + lea dx, [bp+16] + call printr + + mov cx, 'SI' + mov dx, si + call printr + + mov cx, 'DI' + mov dx, di + call printr + + call crlf + + mov cx, 'ES' + mov dx, es + call printr + + mov cx, 'CS' + mov dx, [bp+12] + call printr + + mov cx, 'SS' + mov dx, ss + call printr + + mov cx, 'DS' + mov dx, ds + call printr + + mov cx, 'IP' + mov dx, [bp+10] + call printr + + call crlf + + pop bp + pop ax + pop cx + pop dx + pop bx + iret + +align 512