Store all registers in interrupt stack frame

Do not clear console when printing interrupt stack frame
This commit is contained in:
Josh Holtrop 2023-11-02 16:32:42 -04:00
parent 4f9206af91
commit 31bf82e2ae

View File

@ -14,14 +14,55 @@ import hulk.kfont;
struct Idt struct Idt
{ {
static struct ExceptionStackFrame /** Interrupt stack frame indices. */
private static enum
{ {
ulong rip; ISF_RBP,
ulong cs; ISF_R15,
ulong rflags; ISF_R14,
ulong rsp; ISF_R13,
ulong ss; ISF_R12,
ISF_R11,
ISF_R10,
ISF_R9,
ISF_R8,
ISF_RDI,
ISF_RSI,
ISF_RDX,
ISF_RCX,
ISF_RBX,
ISF_RAX,
ISF_ERROR_CODE,
ISF_RIP,
ISF_CS,
ISF_RFLAGS,
ISF_RSP,
ISF_SS,
ISF_COUNT,
} }
private static __gshared string[ISF_COUNT] ISF_NAMES = [
"RBP",
"R15",
"R14",
"R13",
"R12",
"R11",
"R10",
"R9",
"R8",
"RDI",
"RSI",
"RDX",
"RCX",
"RBX",
"RAX",
"Error Code",
"RIP",
"CS",
"RFLAGS",
"RSP",
"SS",
];
public static enum ulong EXC_PAGE_FAULT = 14; public static enum ulong EXC_PAGE_FAULT = 14;
@ -84,7 +125,9 @@ struct Idt
movabs $$1f, %rax movabs $$1f, %rax
jmp 2f jmp 2f
1: 1:
" ~ (isr_has_error_code(isr) ? "" : "pushq $$0") ~ "
pushq %rax pushq %rax
pushq %rbx
pushq %rcx pushq %rcx
pushq %rdx pushq %rdx
pushq %rsi pushq %rsi
@ -93,16 +136,23 @@ struct Idt
pushq %r9 pushq %r9
pushq %r10 pushq %r10
pushq %r11 pushq %r11
pushq %r12
pushq %r13
pushq %r14
pushq %r15
pushq %rbp pushq %rbp
mov %rsp, %rbp mov %rsp, %rbp
mov %rsp, %rsi
and $$0xFFFFFFFFFFFFFFF0, %rsp and $$0xFFFFFFFFFFFFFFF0, %rsp
mov $$", isr, ", %rdi mov $$", isr, ", %rdi
" ~ (isr_has_error_code(isr) ? "mov 0x50(%rbp), %rsi" : "") ~ "
" ~ (isr_has_error_code(isr) ? "lea 0x58(%rbp), %rdx" : "lea 0x50(%rbp), %rdx") ~ "
movabs $$isr, %rax movabs $$isr, %rax
callq *%rax callq *%rax
mov %rbp, %rsp mov %rbp, %rsp
popq %rbp popq %rbp
popq %r15
popq %r14
popq %r13
popq %r12
popq %r11 popq %r11
popq %r10 popq %r10
popq %r9 popq %r9
@ -111,8 +161,9 @@ struct Idt
popq %rsi popq %rsi
popq %rdx popq %rdx
popq %rcx popq %rcx
popq %rbx
popq %rax popq %rax
" ~ (isr_has_error_code(isr) ? "add $$8, %rsp" : "") ~ " add $$8, %rsp
iretq iretq
2:`, `={rax}`);"); 2:`, `={rax}`);");
mixin("set_descriptor(", isr, ", 0u, " ~ mixin("set_descriptor(", isr, ", 0u, " ~
@ -133,7 +184,7 @@ struct Idt
} }
} }
public extern(C) void isr(ulong vector, ulong arg, Idt.ExceptionStackFrame * stack_frame) public extern(C) void isr(ulong vector, ulong * stack_frame)
{ {
if ((vector >= Idt.INT_APIC_BASE) && (vector < (Idt.INT_APIC_BASE + Idt.INT_APIC_COUNT))) if ((vector >= Idt.INT_APIC_BASE) && (vector < (Idt.INT_APIC_BASE + Idt.INT_APIC_COUNT)))
{ {
@ -151,14 +202,13 @@ public extern(C) void isr(ulong vector, ulong arg, Idt.ExceptionStackFrame * sta
break; break;
default: default:
Console.clear();
Fb.rect(0, 0, Fb.width, Kfont.line_height, 0xCC0000u); Fb.rect(0, 0, Fb.width, Kfont.line_height, 0xCC0000u);
Klog.writefln("ISR %u, error code 0x%x", vector, arg); Klog.writefln("\n **** Unhandled ISR %u ****", vector);
Klog.writefln("RIP = 0x%p", stack_frame.rip); for (size_t i = 0u; i < Idt.ISF_COUNT; i++)
Klog.writefln("CS = 0x%x", stack_frame.cs); {
Klog.writefln("RFLAGS = 0x%x", stack_frame.rflags); Klog.writef(Idt.ISF_NAMES[i]);
Klog.writefln("RSP = 0x%x", stack_frame.rsp); Klog.writefln(" = 0x%x", stack_frame[i]);
Klog.writefln("SS = 0x%x", stack_frame.ss); }
Klog.writefln("CR2 = 0x%p", read_cr2()); Klog.writefln("CR2 = 0x%p", read_cr2());
__asm("cli", ""); __asm("cli", "");
for (;;) for (;;)