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
{
static struct ExceptionStackFrame
/** Interrupt stack frame indices. */
private static enum
{
ulong rip;
ulong cs;
ulong rflags;
ulong rsp;
ulong ss;
ISF_RBP,
ISF_R15,
ISF_R14,
ISF_R13,
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;
@ -84,7 +125,9 @@ struct Idt
movabs $$1f, %rax
jmp 2f
1:
" ~ (isr_has_error_code(isr) ? "" : "pushq $$0") ~ "
pushq %rax
pushq %rbx
pushq %rcx
pushq %rdx
pushq %rsi
@ -93,16 +136,23 @@ struct Idt
pushq %r9
pushq %r10
pushq %r11
pushq %r12
pushq %r13
pushq %r14
pushq %r15
pushq %rbp
mov %rsp, %rbp
mov %rsp, %rsi
and $$0xFFFFFFFFFFFFFFF0, %rsp
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
callq *%rax
mov %rbp, %rsp
popq %rbp
popq %r15
popq %r14
popq %r13
popq %r12
popq %r11
popq %r10
popq %r9
@ -111,8 +161,9 @@ struct Idt
popq %rsi
popq %rdx
popq %rcx
popq %rbx
popq %rax
" ~ (isr_has_error_code(isr) ? "add $$8, %rsp" : "") ~ "
add $$8, %rsp
iretq
2:`, `={rax}`);");
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)))
{
@ -151,14 +202,13 @@ public extern(C) void isr(ulong vector, ulong arg, Idt.ExceptionStackFrame * sta
break;
default:
Console.clear();
Fb.rect(0, 0, Fb.width, Kfont.line_height, 0xCC0000u);
Klog.writefln("ISR %u, error code 0x%x", vector, arg);
Klog.writefln("RIP = 0x%p", stack_frame.rip);
Klog.writefln("CS = 0x%x", stack_frame.cs);
Klog.writefln("RFLAGS = 0x%x", stack_frame.rflags);
Klog.writefln("RSP = 0x%x", stack_frame.rsp);
Klog.writefln("SS = 0x%x", stack_frame.ss);
Klog.writefln("\n **** Unhandled ISR %u ****", vector);
for (size_t i = 0u; i < Idt.ISF_COUNT; i++)
{
Klog.writef(Idt.ISF_NAMES[i]);
Klog.writefln(" = 0x%x", stack_frame[i]);
}
Klog.writefln("CR2 = 0x%p", read_cr2());
__asm("cli", "");
for (;;)