From 36b98320534a7029e3afc578eff30b5b3ce50595 Mon Sep 17 00:00:00 2001 From: Gabriel Date: Sat, 15 Feb 2025 22:19:08 +0100 Subject: [PATCH] core/x86_64: Add general protection fault handler --- core/src/arch/x86_64/interrupts.zig | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/core/src/arch/x86_64/interrupts.zig b/core/src/arch/x86_64/interrupts.zig index 4befa36..128f5c7 100644 --- a/core/src/arch/x86_64/interrupts.zig +++ b/core/src/arch/x86_64/interrupts.zig @@ -74,6 +74,7 @@ export fn asmInterruptEntry() callconv(.Naked) void { } const Exceptions = enum(u64) { + GeneralProtectionFault = 0xd, PageFault = 0xe, }; @@ -87,6 +88,17 @@ const PageFaultCodes = enum(u64) { const SYSCALL_INTERRUPT = 66; +fn generalProtectionFault(frame: *InterruptStackFrame) void { + debug.print("General protection fault!\n", .{}); + debug.print("Faulting instruction: {x}\n", .{frame.rip}); + + const code = frame.error_or_irq; + + debug.print("Error code: {d}\n", .{code}); + + while (true) {} +} + fn pageFault(frame: *InterruptStackFrame) void { var fault_address: u64 = undefined; asm volatile ("mov %%cr2, %[cr2]" @@ -132,6 +144,9 @@ export fn interruptEntry(frame: *InterruptStackFrame) callconv(.C) void { @intFromEnum(Exceptions.PageFault) => { pageFault(frame); }, + @intFromEnum(Exceptions.GeneralProtectionFault) => { + generalProtectionFault(frame); + }, SYSCALL_INTERRUPT => { var args = sys.Arguments{ .arg0 = frame.rdi, .arg1 = frame.rsi, .arg2 = frame.rdx, .arg3 = frame.r10, .arg4 = frame.r8, .arg5 = frame.r9 }; sys.invokeSyscall(frame.rax, frame, &args, @ptrFromInt(@as(usize, @intFromPtr(&frame.rax))));