panic dumps more registers, panic type arg

main
pantonshire 1 year ago
parent 035bba16f6
commit d362758b4d

@ -198,6 +198,12 @@ panic_simple:
%endif %endif
%macro panic 1
push word %1
call panic_fancy
%endmacro
main: main:
; Set VGA mode ; Set VGA mode
; https://mendelson.org/wpdos/videomodes.txt ; https://mendelson.org/wpdos/videomodes.txt
@ -216,14 +222,6 @@ main:
mov ax, msg_boot1_loaded mov ax, msg_boot1_loaded
call vga_println call vga_println
mov eax, 0xa1b2c3d4
mov ebx, 0x12345678
mov ecx, 0xdeadbeef
mov edx, 0xcafebabe
mov esi, 0xfeedface
mov edi, 0x66778899
call panic_fancy
call test_a20 call test_a20
test ax, ax test ax, ax
jnz .a20_enabled jnz .a20_enabled
@ -231,6 +229,14 @@ main:
mov ax, msg_a20_disabled mov ax, msg_a20_disabled
call vga_println call vga_println
mov eax, 0xa1b2c3d4
mov ebx, 0x12345678
mov ecx, 0xdeadbeef
mov edx, 0xcafebabe
mov esi, 0xfeedface
mov edi, 0x66778899
panic PANIC_TYPE_A20
; TODO: enable a20 ; TODO: enable a20
hlt hlt
@ -243,48 +249,70 @@ main:
; Print a panic message then terminate. ; Print a panic message then terminate.
; Arguments: ; Arguments:
; - [sp + 2]: panic message segment ; - word [sp]: panic type
; - [sp]: panic message offset
; Does not return ; Does not return
panic_fancy: panic_fancy:
push bp push bp
mov bp, sp mov bp, sp
; Flags first so we don't cobber them when we sub (uwu) ; Flags first so we don't cobber them when we sub (uwu)
pushfd ; Temp flags: bp - 0x04 pushfd ; Temp flags: bp - 0x04
sub sp, 16 ; Buffer: bp - 0x14 sub sp, 16 ; Buffer: bp - 0x14
push eax ; eax: bp - 0x18 push dword 0 ; Registers: bp - 0x18
push ebx ; ebx: bp - 0x1c push eax
push ecx ; ecx: bp - 0x20 push ebx
push edx ; edx: bp - 0x24 push ecx
push esi ; esi: bp - 0x28 push edx
push edi ; edi: bp - 0x2c push esi
sub sp, 4 ; Flags: bp - 0x30 push edi
mov eax, [bp - 0x04] push esp
mov [bp - 0x30], eax push ebp
xor eax, eax
mov ax, cs
push eax
mov ax, ds
push eax
mov ax, es
push eax
mov ax, fs
push eax
mov ax, gs
push eax
mov ax, ss
push eax
mov ax, word [bp - 0x04]
push eax
mov ax, [bp + 0x02]
mov [bp - 0x18], eax
mov word [GLOBALS + VGA_COL], 0x4f00 mov word [GLOBALS + VGA_COL], 0x4f00
call vga_clear call vga_clear
mov ax, ss mov ax, VGA_WIDTH + 1
mov es, ax mov cx, msg_panic
mov dx, VGA_WIDTH - 1
call vga_print_raw
xor bx, bx xor bx, bx
mov di, VGA_WIDTH * 3 mov di, VGA_WIDTH * 4
.loop_dump_regs: .loop_dump_regs:
cmp bx, 7 cmp bx, 16
jae .loop_dump_regs_done jae .loop_dump_regs_done
mov ax, bx mov si, bx
shl ax, 1 shl si, 1
mov si, table_reg_msgs add si, table_reg_msgs
add si, ax
mov cx, [si] mov cx, [si]
mov ax, di mov ax, di
add ax, 1 add ax, 1
mov dx, 6 mov dx, 3
call vga_print_raw call vga_print_raw
push es
mov ax, ss
mov es, ax
; Format the current saved register value as hex ; Format the current saved register value as hex
lea si, [bp - 0x18] lea si, [bp - 0x18]
mov ax, bx mov ax, bx
@ -295,17 +323,35 @@ panic_fancy:
call dump_reg call dump_reg
mov ax, di mov ax, di
add ax, 7 add ax, 5
lea cx, [bp - 0x14] lea cx, [bp - 0x14]
mov dx, 8 mov dx, 8
call vga_print_raw call vga_print_raw
pop es
inc bx inc bx
add di, VGA_WIDTH add di, VGA_WIDTH / 5
jmp .loop_dump_regs jmp .loop_dump_regs
.loop_dump_regs_done: .loop_dump_regs_done:
mov bx, [bp + 0x04]
cmp bx, PANIC_TYPE_MAX
jae .print_panic_type_done
shl bx, 1
add bx, panic_type_msgs
mov cx, [bx]
mov ax, VGA_WIDTH * 2 + 1
mov dx, VGA_WIDTH - 1
call vga_print_raw
.print_panic_type_done:
; TODO: unwind stack
; - Load saved bp and ip from [bp] and [bp + 2], respectively
; - Load bp and ip before that from [prev_bp], [prev_bp + 2]
; - Repeat
.halt: .halt:
hlt hlt
; Handle non-maskable interrupts ; Handle non-maskable interrupts
@ -597,24 +643,53 @@ msg_a20_enabled db "a20 enabled", 0
msg_a20_disabled db "a20 not enabled", 0 msg_a20_disabled db "a20 not enabled", 0
msg_panic db "panic!", 0 msg_panic db "panic!", 0
msg_reg_eip db "eip", 0
msg_reg_eax db "eax", 0 msg_reg_eax db "eax", 0
msg_reg_ebx db "ebx", 0 msg_reg_ebx db "ebx", 0
msg_reg_ecx db "ecx", 0 msg_reg_ecx db "ecx", 0
msg_reg_edx db "edx", 0 msg_reg_edx db "edx", 0
msg_reg_esi db "esi", 0 msg_reg_esi db "esi", 0
msg_reg_edi db "edi", 0 msg_reg_edi db "edi", 0
msg_reg_flags db "flags", 0 msg_reg_esp db "esp", 0
msg_reg_ebp db "ebp", 0
msg_reg_cs db "cs", 0
msg_reg_ds db "ds", 0
msg_reg_es db "es", 0
msg_reg_fs db "fs", 0
msg_reg_gs db "gs", 0
msg_reg_ss db "ss", 0
msg_reg_flags db "flg", 0
table_reg_msgs: table_reg_msgs:
dw msg_reg_eip
dw msg_reg_eax dw msg_reg_eax
dw msg_reg_ebx dw msg_reg_ebx
dw msg_reg_ecx dw msg_reg_ecx
dw msg_reg_edx dw msg_reg_edx
dw msg_reg_esi dw msg_reg_esi
dw msg_reg_edi dw msg_reg_edi
dw msg_reg_esp
dw msg_reg_ebp
dw msg_reg_cs
dw msg_reg_ds
dw msg_reg_es
dw msg_reg_fs
dw msg_reg_gs
dw msg_reg_ss
dw msg_reg_flags dw msg_reg_flags
dw 0 dw 0
msg_panic_generic db "generic panic", 0
msg_panic_a20 db "failed to enable a20 line", 0
panic_type_msgs:
PANIC_TYPE_GENERIC equ ($ - panic_type_msgs) / 2
dw msg_panic_generic
PANIC_TYPE_A20 equ ($ - panic_type_msgs) / 2
dw msg_panic_a20
PANIC_TYPE_MAX equ ($ - panic_type_msgs) / 2
dw 0
boot1_magic dd BOOT1_MAGIC boot1_magic dd BOOT1_MAGIC
BOOT1_TOTAL_LEN equ $ - $$ BOOT1_TOTAL_LEN equ $ - $$

Loading…
Cancel
Save