Split up kernel and debug rom

This commit is contained in:
Nero 2019-09-06 23:42:39 +00:00
parent 4fa383bb2e
commit 11b4d07dc1
4 changed files with 240 additions and 54 deletions

View File

@ -13,6 +13,8 @@ endif
ifdef DEBUG ifdef DEBUG
QEMU_ARGS += -chardev file,path=debugcon.log,id=seabios QEMU_ARGS += -chardev file,path=debugcon.log,id=seabios
QEMU_ARGS += -device isa-debugcon,iobase=0x402,chardev=seabios QEMU_ARGS += -device isa-debugcon,iobase=0x402,chardev=seabios
QEMU_ARGS += -option-rom debug.rom
DEBUGROM = debug.rom
endif endif
ifndef DISPLAY ifndef DISPLAY
@ -26,6 +28,9 @@ default: kernel.rom
kernel.rom: kernel/*.asm lib/*.inc kernel.rom: kernel/*.asm lib/*.inc
nasm -s -o $@ -I lib -I kernel kernel/main.asm && scripts/fix-rom.sh $@ nasm -s -o $@ -I lib -I kernel kernel/main.asm && scripts/fix-rom.sh $@
debug.rom: debug/*.asm lib/*.inc
nasm -s -o $@ -I lib -I debug debug/main.asm && scripts/fix-rom.sh $@
boot/%.bin: boot/%.asm lib/*.inc boot/%.bin: boot/%.asm lib/*.inc
nasm -s -o $@ -I boot -I lib $< nasm -s -o $@ -I boot -I lib $<
@ -38,11 +43,11 @@ fdimage.img: boot/floppy.bin kernel.rom
clean: clean:
rm -f *.com *.bin *.rom *.img *.log boot/*.bin rm -f *.com *.bin *.rom *.img *.log boot/*.bin
qemu-rom: kernel.rom qemu-rom: kernel.rom $(DEBUGROM)
$(QEMU) $(QEMU_ARGS) -option-rom kernel.rom $(QEMU) $(QEMU_ARGS) -option-rom kernel.rom
qemu-floppy: fdimage.img qemu-floppy: fdimage.img $(DEBUGROM)
$(QEMU) $(QEMU_ARGS) -boot c -hda fdimage.img $(QEMU) $(QEMU_ARGS) -boot c -hda fdimage.img
qemu-serial: boot/serial.bin qemu-serial: boot/serial.bin $(DEBUGROM)
$(QEMU) $(QEMU_ARGS) -hda boot/serial.bin $(QEMU) $(QEMU_ARGS) -hda boot/serial.bin

View File

@ -116,11 +116,12 @@ isr_debug:
pop cx pop cx
pop dx pop dx
pop bx pop bx
pop bp ; sp to be ignored add sp, 2 ; ignore SP
pop bp
pop bp pop bp
pop si pop si
pop di pop di
pop ds pop ds
pop es pop es
pop ss add sp, 2 ; ignore SS
iret iret

206
debug/main.asm Normal file
View File

@ -0,0 +1,206 @@
cpu 8086
org 0x0000
rom:
db 0x55, 0xAA
.sectors:
db 0x00
.init:
mov dx, isr_debug
mov al, 0x1
call intr_register
mov al, 0x03
call intr_register
retf
.name:
db "rDebug", 0
times (0x18 - ($-$$)) db 0
.pcir_ptr:
dw 0
times (0x1A - ($-$$)) db 0
.pnp_ptr:
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 rom.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
putc:
push bx
push cx
mov ah, 0x0e
mov bx, 0x0000
int 0x10
pop cx
pop bx
ret
intr_register:
; DI = AL * 4
mov ah, 4
mul ah
mov di, ax
; ES = 0
xor ax, ax
mov es, ax
; store offset
mov ax, dx
stosw
; store segment
mov ax, cs
stosw
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"
; 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"
; 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
debug_frame_print:
mov si, 0
mov cx, 8
.reg1loop:
call debug_frame_register_print
add si, 2
loop .reg1loop
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
call printf
db 0x0A, 0x0D, 0
mov si, 16
mov cx, 3
.reg2loop:
call debug_frame_register_print
add si, 2
loop .reg2loop
mov ax, [bp+24]
mov bx, 0x0010
mov cx, 3
call print_number_padded
mov al, ':'
call putc
mov ax, [bp+22]
mov bx, 0x0010
mov cx, 3
call print_number_padded
call printf
db 0x0A, 0x0D, 0
ret
; this prints registers
; expect to be called as interrupt routine
isr_debug:
push ss
push es
push ds
push di
push si
push bp
push sp
push bx
push dx
push cx
push ax
mov bp, sp
mov [bp+08], bp
add WORD [bp+08], 28
call printf
db 0x0A, 0x0D, 0
call debug_frame_print
pop ax
pop cx
pop dx
pop bx
pop bp
pop bp
pop si
pop di
pop ds
pop es
pop ss
iret
%include "printf.inc"
align 512

View File

@ -1,15 +1,29 @@
cpu 8086 cpu 8086
org 0x0000 org 0x0000
rom:
db 0x55, 0xAA db 0x55, 0xAA
optrom_length: .sectors:
db 0x00 db 0x00
jmp optrom_init .init:
push cs
pop es
; reserved area mov di, start
times (0x1A - ($-$$)) db 0 mov ax, 0x18
call intr_register
retf
.name:
db "ROM DOS", 0
times (0x18 - ($-$$)) db 0
.pcir_ptr:
dw 0
times (0x1A - ($-$$)) db 0
.pnp_ptr:
dw pnp dw pnp
align 16
pnp: pnp:
db "$PnP" db "$PnP"
.version: .version:
@ -21,8 +35,8 @@ pnp:
.checksum: .checksum:
db 0 ; checksum (filled by fix-rom) db 0 ; checksum (filled by fix-rom)
dd 0 ; device identifier dd 0 ; device identifier
dw str_vendor ; manufacturer string dw 0 ; manufacturer string
dw str_product ; product name string dw rom.name ; product name string
db 0,0,0 ; device type string db 0,0,0 ; device type string
db 0x20 ; device indicator, bit for "read cacheable" set db 0x20 ; device indicator, bit for "read cacheable" set
dw 0 ; boot connection vector dw 0 ; boot connection vector
@ -31,40 +45,6 @@ pnp:
dw 0 ; reserved dw 0 ; reserved
dw 0 dw 0
str_vendor:
db "Nero", 0
str_product:
db "Nero DOS ", 60, 234, 62, 0
optrom_init:
push cs
pop es
mov di, isr_debug
mov ax, 0x1
call intr_register
mov ax, 0x3
call intr_register
mov di, start
mov ax, 0x18
call intr_register
retf
announce:
push ds
push cs
push cs
pop ds
mov ax, str_product
push ax
call printf
db "%S (CS=%Xh)", 0x0A, 0x0D, 0x00
add sp, 4
pop ds
ret
start: start:
xor ax, ax xor ax, ax
mov ds, ax mov ds, ax
@ -73,8 +53,6 @@ start:
mov sp, 0x800 mov sp, 0x800
mov di, sp mov di, sp
call announce
call drvtab_create call drvtab_create
push cs push cs
@ -86,6 +64,7 @@ start:
.loop: .loop:
mov ah, 0x01 mov ah, 0x01
int 0x21 int 0x21
int3
jmp .loop jmp .loop
cli cli
@ -112,9 +91,4 @@ isr_return:
%include "chario.asm" %include "chario.asm"
%include "printf.inc"
%include "print.asm"
%include "debug.asm"
align 512 align 512