Drop debug.drv, rework debug rom instead
This commit is contained in:
parent
2569dde385
commit
c8adeb35d2
4
Makefile
4
Makefile
@ -73,10 +73,6 @@ fate.bs: boot/fat.asm
|
||||
%.rom: rom/%.asm utils/fix-rom
|
||||
$(NASM) $(NASM_ARGS) -o $@ $< && utils/fix-rom $@
|
||||
|
||||
# rdos drivers
|
||||
%.drv: driver/%.asm
|
||||
$(NASM) $(NASM_ARGS) -o $@ $<
|
||||
|
||||
fdimage.img: fat1.bs $(DISTFILES)
|
||||
mformat -C -i $@ -f $(FLOPPY) -B fat1.bs ::
|
||||
mmd -i $@ ::rdos
|
||||
|
@ -1,76 +0,0 @@
|
||||
jmp init
|
||||
align 4
|
||||
db "rDos"
|
||||
align 8
|
||||
; hook interrupt 3
|
||||
db 3
|
||||
db 0
|
||||
dw int3entry
|
||||
dd 0
|
||||
; end of header
|
||||
db 0
|
||||
|
||||
stacksize: equ 0x20
|
||||
|
||||
init:
|
||||
mov ax, 0x0e33
|
||||
xor bx, bx
|
||||
int 0x10
|
||||
retf
|
||||
|
||||
int3entry:
|
||||
; save DS and AX
|
||||
mov [cs:reg_ds], ds
|
||||
mov [cs:reg_ax], ax
|
||||
; use AX to load DS=CS
|
||||
mov ax, cs
|
||||
mov ds, ax
|
||||
; pop IP, CS and flags from stack
|
||||
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 es, ax
|
||||
mov ss, ax
|
||||
mov sp, (stack+stacksize)
|
||||
|
||||
hlt: hlt
|
||||
jmp hlt
|
||||
|
||||
reg_ax: dw 0
|
||||
reg_cx: dw 0
|
||||
reg_dx: dw 0
|
||||
reg_bx: dw 0
|
||||
reg_sp: dw 0
|
||||
reg_bp: dw 0
|
||||
reg_si: dw 0
|
||||
reg_di: dw 0
|
||||
|
||||
reg_es: dw 0
|
||||
reg_cs: dw 0
|
||||
reg_ss: dw 0
|
||||
reg_ds: dw 0
|
||||
|
||||
reg_ip: dw 0
|
||||
reg_fl: dw 0
|
||||
|
||||
names: db "AXCXDXBXSPBPSIDI"
|
||||
db "DSESSSCSIPFL"
|
||||
|
||||
stack: times stacksize dw 0
|
||||
|
||||
align 16
|
374
rom/debug.asm
374
rom/debug.asm
@ -1,71 +1,26 @@
|
||||
cpu 8086
|
||||
org 0x0000
|
||||
cpu 8086
|
||||
org 0x0000
|
||||
|
||||
%macro push8086 0
|
||||
push ss
|
||||
push es
|
||||
push ds
|
||||
push di
|
||||
push si
|
||||
push bp
|
||||
push sp
|
||||
push bx
|
||||
push dx
|
||||
push cx
|
||||
push ax
|
||||
stacksize: equ 0x20
|
||||
|
||||
; adjust stored SP to be value before interrupt
|
||||
mov bp, sp
|
||||
mov [bp+08], bp
|
||||
add WORD [bp+08], 28
|
||||
%endmacro
|
||||
|
||||
%macro pop8086 0
|
||||
pop ax
|
||||
pop cx
|
||||
pop dx
|
||||
pop bx
|
||||
add sp, 2 ; skip SP
|
||||
pop bp
|
||||
pop si
|
||||
pop di
|
||||
pop ds
|
||||
pop es
|
||||
add sp, 2 ; skip SS
|
||||
%endmacro
|
||||
|
||||
rom:
|
||||
db 0x55, 0xAA
|
||||
.sectors:
|
||||
db 0x00
|
||||
.init:
|
||||
jmp init
|
||||
nop
|
||||
|
||||
.name:
|
||||
db "RDOS DEBUG", 0
|
||||
|
||||
times (0x18 - ($-$$)) db 0
|
||||
.pcir_ptr:
|
||||
dw 0
|
||||
|
||||
times (0x1A - ($-$$)) db 0
|
||||
.pnp_ptr:
|
||||
dw pnp
|
||||
|
||||
pnp:
|
||||
db "$PnP"
|
||||
.version:
|
||||
pnp: db "$PnP"
|
||||
db 1 ; version 1
|
||||
.length:
|
||||
db 2 ; 2 * 16 length
|
||||
dw 0 ; offset of next header
|
||||
db 0
|
||||
.checksum:
|
||||
db 0 ; checksum (filled by fix-rom)
|
||||
dd 0 ; device identifier
|
||||
dw 0 ; manufacturer string
|
||||
dw rom.name ; product name 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
|
||||
@ -74,221 +29,152 @@ pnp:
|
||||
dw 0 ; reserved
|
||||
dw 0
|
||||
|
||||
init:
|
||||
mov bx, 0
|
||||
mov dx, isr_divide_error
|
||||
call hook_int
|
||||
name: db "rdos debug"
|
||||
|
||||
mov bx, 1
|
||||
mov dx, isr_singlestep
|
||||
call hook_int
|
||||
|
||||
mov bx, 2
|
||||
mov dx, isr_nmi
|
||||
call hook_int
|
||||
|
||||
mov bx, 3
|
||||
mov dx, isr_breakpoint
|
||||
call hook_int
|
||||
|
||||
mov bx, 4
|
||||
mov dx, isr_overflow
|
||||
call hook_int
|
||||
|
||||
; 5 left out
|
||||
|
||||
mov bx, 6
|
||||
mov dx, isr_invalid_opcode
|
||||
call hook_int
|
||||
init: push ds
|
||||
push es
|
||||
push si
|
||||
push di
|
||||
push ax
|
||||
push cx
|
||||
xor ax, ax
|
||||
mov si, ax
|
||||
mov di, ax
|
||||
; load DS for
|
||||
mov ds, ax
|
||||
|
||||
mov al, [cs:2]
|
||||
inc ax
|
||||
shr ax, 1
|
||||
; move down int 0x12 ptr to make space for us
|
||||
sub [0x413], ax
|
||||
; calculate segment from kilobytes
|
||||
mov ax, [0x413]
|
||||
mov cl, 6
|
||||
shl ax, cl
|
||||
; load ES for relocate
|
||||
mov es, ax
|
||||
; store interrupt vector
|
||||
mov word [3*4], int3entry
|
||||
mov word [3*4+2], es
|
||||
; load DS for relocate
|
||||
push cs
|
||||
pop ds
|
||||
mov si, rom.name
|
||||
push cs
|
||||
push si
|
||||
call printf
|
||||
db "%S %X", 0x0A, 0x0D, 0
|
||||
add sp, 4
|
||||
; calculate our length
|
||||
mov cx, codeend
|
||||
rep movsb
|
||||
|
||||
pop cx
|
||||
pop ax
|
||||
pop di
|
||||
pop si
|
||||
pop es
|
||||
pop ds
|
||||
retf
|
||||
|
||||
; Hook interrupt
|
||||
hook_int:
|
||||
; bx times 4
|
||||
add bx, bx
|
||||
add bx, bx
|
||||
; store offset
|
||||
mov [bx], dx
|
||||
; store segment
|
||||
push ax
|
||||
mov ax, cs
|
||||
mov [bx+2], ax
|
||||
pop ax
|
||||
print16:
|
||||
; setup bx and ah for int 10h call
|
||||
xor bx, bx
|
||||
mov ah, 0x0e
|
||||
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
|
||||
|
||||
putc:
|
||||
push bx
|
||||
push cx
|
||||
printregs:
|
||||
mov cx, 14
|
||||
xor bx, bx
|
||||
mov ah, 0x0e
|
||||
mov bx, 0x0000
|
||||
mov si, reg_ax
|
||||
.loop: push cx
|
||||
mov dx, [si+(names-reg_ax)]
|
||||
mov al, dl
|
||||
int 0x10
|
||||
mov al, dh
|
||||
int 0x10
|
||||
mov al, '='
|
||||
int 0x10
|
||||
lodsw
|
||||
mov dx, ax
|
||||
call print16
|
||||
mov al, ' '
|
||||
int 0x10
|
||||
pop cx
|
||||
pop bx
|
||||
loop .loop
|
||||
ret
|
||||
|
||||
; Names for words in debug frame
|
||||
; Two characters per word, 14 words total
|
||||
debug_frame_names:
|
||||
; general-purpose registers
|
||||
db "AXCXDXBXSPBPSIDI"
|
||||
; extra registers
|
||||
db "DSESSSIPCSFL"
|
||||
int3entry:
|
||||
; save DS and AX
|
||||
mov [cs:reg_ds], ds
|
||||
mov [cs:reg_ax], ax
|
||||
; use AX to load DS=CS
|
||||
mov ax, cs
|
||||
mov ds, ax
|
||||
; pop IP, CS and flags from stack
|
||||
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 es, ax
|
||||
mov ss, ax
|
||||
mov sp, (stack+stacksize)
|
||||
|
||||
; Names for bits in debug_frame+26 (FL/Flags register)
|
||||
; One character per bit, 16 bits total
|
||||
debug_frame_flags:
|
||||
db "++++ODIT"
|
||||
db "SZ+A+P+C"
|
||||
call printregs
|
||||
|
||||
; Print a single register from the frame
|
||||
; in SI frame offset for register
|
||||
debug_frame_register_print:
|
||||
mov bx, debug_frame_names
|
||||
mov al, [cs:bx+si] ; first name char load
|
||||
call putc
|
||||
mov al, [cs:bx+si+1] ; second name char load
|
||||
call putc
|
||||
mov al, '='
|
||||
call putc
|
||||
mov ax, [ss:bp+si] ; value load
|
||||
; prepare call to print_number
|
||||
push bx
|
||||
push cx
|
||||
mov bx, 0x0010
|
||||
mov cx, 3
|
||||
call print_number_padded
|
||||
pop cx
|
||||
pop bx
|
||||
mov al, ' '
|
||||
call putc
|
||||
ret
|
||||
hlt: hlt
|
||||
jmp hlt
|
||||
|
||||
debug_frame_print:
|
||||
mov si, 0
|
||||
mov cx, 8
|
||||
.reg1loop:
|
||||
call debug_frame_register_print
|
||||
add si, 2
|
||||
loop .reg1loop
|
||||
names: db "AXCXDXBXSPBPSIDI"
|
||||
db "DSESSSCSIPFL"
|
||||
|
||||
mov dx, [ss:bp+26]
|
||||
mov di, debug_frame_flags
|
||||
mov cx, 0x0010
|
||||
.flag_loop:
|
||||
mov al, [cs:di]
|
||||
inc di
|
||||
cmp al, '+'
|
||||
je .next
|
||||
test dx, 0x8000
|
||||
jnz .write
|
||||
mov al, '-'
|
||||
.write:
|
||||
call putc
|
||||
.next:
|
||||
sal dx, 1
|
||||
loop .flag_loop
|
||||
codeend:
|
||||
|
||||
call printf
|
||||
db 0x0A, 0x0D, 0
|
||||
reg_ax: dw 0
|
||||
reg_cx: dw 0
|
||||
reg_dx: dw 0
|
||||
reg_bx: dw 0
|
||||
reg_sp: dw 0
|
||||
reg_bp: dw 0
|
||||
reg_si: dw 0
|
||||
reg_di: dw 0
|
||||
|
||||
mov si, 16
|
||||
mov cx, 5
|
||||
.reg2loop:
|
||||
call debug_frame_register_print
|
||||
add si, 2
|
||||
loop .reg2loop
|
||||
reg_es: dw 0
|
||||
reg_cs: dw 0
|
||||
reg_ss: dw 0
|
||||
reg_ds: dw 0
|
||||
|
||||
call printf
|
||||
db 0x0A, 0x0D, 0
|
||||
reg_ip: dw 0
|
||||
reg_fl: dw 0
|
||||
|
||||
ret
|
||||
|
||||
isr_divide_error:
|
||||
push8086
|
||||
|
||||
call printf
|
||||
db 0x0A, 0x0D, "INT 0 - DIVIDE ERROR", 0x0A, 0x0D, 0
|
||||
|
||||
call debug_frame_print
|
||||
|
||||
jmp halt
|
||||
|
||||
isr_singlestep:
|
||||
push8086
|
||||
|
||||
call printf
|
||||
db 0x0A, 0x0D, 0
|
||||
|
||||
call debug_frame_print
|
||||
|
||||
; wait for keypress
|
||||
xor ax, ax
|
||||
int 0x16
|
||||
|
||||
; enable trace flag so we fire again after next instruction
|
||||
or word [ss:bp+26], 0x0100
|
||||
|
||||
pop8086
|
||||
iret
|
||||
|
||||
isr_nmi:
|
||||
push8086
|
||||
|
||||
call printf
|
||||
db 0x0A, 0x0D, "INT 2 - NON-MASKABLE INTERRUPT", 0x0A, 0x0D, 0
|
||||
|
||||
call debug_frame_print
|
||||
|
||||
jmp halt
|
||||
|
||||
isr_breakpoint:
|
||||
push8086
|
||||
|
||||
call printf
|
||||
db 0x0A, 0x0D, 0
|
||||
|
||||
call debug_frame_print
|
||||
|
||||
pop8086
|
||||
iret
|
||||
|
||||
isr_overflow:
|
||||
push8086
|
||||
|
||||
call printf
|
||||
db 0x0A, 0x0D, "INT 4 - OVERFLOW", 0x0A, 0x0D, 0
|
||||
|
||||
call debug_frame_print
|
||||
|
||||
jmp halt
|
||||
|
||||
isr_invalid_opcode:
|
||||
push8086
|
||||
|
||||
call printf
|
||||
db 0x0A, 0x0D, "INT 6 - INVALID OPCODE", 0x0A, 0x0D, 0
|
||||
|
||||
call debug_frame_print
|
||||
|
||||
jmp halt
|
||||
|
||||
halt:
|
||||
call printf
|
||||
db "HALTED", 0x0A, 0x0D, 0
|
||||
.loop:
|
||||
hlt
|
||||
jmp halt
|
||||
|
||||
%include "printf.asm"
|
||||
stack: times stacksize dw 0
|
||||
|
||||
align 512
|
||||
|
@ -1,43 +0,0 @@
|
||||
cpu 8086
|
||||
org 0x0000
|
||||
|
||||
db 0x55, 0xAA
|
||||
db 0x00
|
||||
jmp init
|
||||
nop
|
||||
|
||||
times (0x18 - ($-$$)) db 0
|
||||
dw 0
|
||||
dw pnp
|
||||
|
||||
pnp:
|
||||
db "$PnP"
|
||||
.version:
|
||||
db 1 ; version 1
|
||||
.length:
|
||||
db 2 ; 2 * 16 length
|
||||
dw 0 ; offset of next header
|
||||
db 0
|
||||
.checksum:
|
||||
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 "rdos drv loader"
|
||||
|
||||
init:
|
||||
mov ax, 0x0e37
|
||||
xor bx, bx
|
||||
int 0x10
|
||||
retf
|
||||
|
||||
align 512
|
Loading…
Reference in New Issue
Block a user