panic dumps more registers, panic type arg
This commit is contained in:
1 parent
035bba16f6
commit
d362758b4d
1 file changed
+109
-34
@@ -198,6 +198,12 @@ panic_simple:
|
||||
%endif
|
||||
|
||||
|
||||
%macro panic 1
|
||||
push word %1
|
||||
call panic_fancy
|
||||
%endmacro
|
||||
|
||||
|
||||
main:
|
||||
; Set VGA mode
|
||||
; https://mendelson.org/wpdos/videomodes.txt
|
||||
@@ -216,14 +222,6 @@ main:
|
||||
mov ax, msg_boot1_loaded
|
||||
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
|
||||
test ax, ax
|
||||
jnz .a20_enabled
|
||||
@@ -231,6 +229,14 @@ main:
|
||||
mov ax, msg_a20_disabled
|
||||
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
|
||||
hlt
|
||||
|
||||
@@ -243,48 +249,70 @@ main:
|
||||
|
||||
; Print a panic message then terminate.
|
||||
; Arguments:
|
||||
; - [sp + 2]: panic message segment
|
||||
; - [sp]: panic message offset
|
||||
; - word [sp]: panic type
|
||||
; Does not return
|
||||
panic_fancy:
|
||||
push bp
|
||||
mov bp, sp
|
||||
|
||||
; Flags first so we don't cobber them when we sub (uwu)
|
||||
pushfd ; Temp flags: bp - 0x04
|
||||
sub sp, 16 ; Buffer: bp - 0x14
|
||||
push eax ; eax: bp - 0x18
|
||||
push ebx ; ebx: bp - 0x1c
|
||||
push ecx ; ecx: bp - 0x20
|
||||
push edx ; edx: bp - 0x24
|
||||
push esi ; esi: bp - 0x28
|
||||
push edi ; edi: bp - 0x2c
|
||||
sub sp, 4 ; Flags: bp - 0x30
|
||||
mov eax, [bp - 0x04]
|
||||
mov [bp - 0x30], eax
|
||||
pushfd ; Temp flags: bp - 0x04
|
||||
sub sp, 16 ; Buffer: bp - 0x14
|
||||
push dword 0 ; Registers: bp - 0x18
|
||||
push eax
|
||||
push ebx
|
||||
push ecx
|
||||
push edx
|
||||
push esi
|
||||
push edi
|
||||
push esp
|
||||
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
|
||||
call vga_clear
|
||||
|
||||
mov ax, ss
|
||||
mov es, ax
|
||||
mov ax, VGA_WIDTH + 1
|
||||
mov cx, msg_panic
|
||||
mov dx, VGA_WIDTH - 1
|
||||
call vga_print_raw
|
||||
|
||||
xor bx, bx
|
||||
mov di, VGA_WIDTH * 3
|
||||
mov di, VGA_WIDTH * 4
|
||||
.loop_dump_regs:
|
||||
cmp bx, 7
|
||||
cmp bx, 16
|
||||
jae .loop_dump_regs_done
|
||||
|
||||
mov ax, bx
|
||||
shl ax, 1
|
||||
mov si, table_reg_msgs
|
||||
add si, ax
|
||||
mov si, bx
|
||||
shl si, 1
|
||||
add si, table_reg_msgs
|
||||
mov cx, [si]
|
||||
mov ax, di
|
||||
add ax, 1
|
||||
mov dx, 6
|
||||
mov dx, 3
|
||||
call vga_print_raw
|
||||
|
||||
push es
|
||||
mov ax, ss
|
||||
mov es, ax
|
||||
|
||||
; Format the current saved register value as hex
|
||||
lea si, [bp - 0x18]
|
||||
mov ax, bx
|
||||
@@ -295,17 +323,35 @@ panic_fancy:
|
||||
call dump_reg
|
||||
|
||||
mov ax, di
|
||||
add ax, 7
|
||||
add ax, 5
|
||||
lea cx, [bp - 0x14]
|
||||
mov dx, 8
|
||||
call vga_print_raw
|
||||
|
||||
|
||||
pop es
|
||||
inc bx
|
||||
add di, VGA_WIDTH
|
||||
add di, VGA_WIDTH / 5
|
||||
jmp .loop_dump_regs
|
||||
|
||||
.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:
|
||||
hlt
|
||||
; Handle non-maskable interrupts
|
||||
@@ -597,24 +643,53 @@ msg_a20_enabled db "a20 enabled", 0
|
||||
msg_a20_disabled db "a20 not enabled", 0
|
||||
msg_panic db "panic!", 0
|
||||
|
||||
msg_reg_eip db "eip", 0
|
||||
msg_reg_eax db "eax", 0
|
||||
msg_reg_ebx db "ebx", 0
|
||||
msg_reg_ecx db "ecx", 0
|
||||
msg_reg_edx db "edx", 0
|
||||
msg_reg_esi db "esi", 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:
|
||||
dw msg_reg_eip
|
||||
dw msg_reg_eax
|
||||
dw msg_reg_ebx
|
||||
dw msg_reg_ecx
|
||||
dw msg_reg_edx
|
||||
dw msg_reg_esi
|
||||
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 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_TOTAL_LEN equ $ - $$
|
||||
|
||||
Reference in new issue
Block a user