69 lines
2.1 KiB
C++
69 lines
2.1 KiB
C++
#define MODULE "isr"
|
|
|
|
#include "interrupts/Context.h"
|
|
#include "interrupts/IRQ.h"
|
|
#include "interrupts/Interrupts.h"
|
|
#include "io/Serial.h"
|
|
#include "log/Log.h"
|
|
#include "memory/VMM.h"
|
|
#include "misc/hang.h"
|
|
#include "panic/Panic.h"
|
|
#include "std/assert.h"
|
|
#include "std/stdio.h"
|
|
#include "sys/Syscall.h"
|
|
#include "thread/Scheduler.h"
|
|
#include "trace/StackTracer.h"
|
|
#include "utils/PageFaultReason.h"
|
|
|
|
extern "C" void common_handler(Context* context)
|
|
{
|
|
ensure(Interrupts::is_in_handler());
|
|
if (context->number >= 0x20 && context->number < 0x30)
|
|
{
|
|
IRQ::interrupt_handler(context);
|
|
return;
|
|
}
|
|
if (context->number == 13)
|
|
{
|
|
Interrupts::disable();
|
|
|
|
if (context->cs == 0x8) { int_panic(context, "GPF in kernel task"); }
|
|
else
|
|
{
|
|
VMM::enter_syscall_context();
|
|
|
|
kerrorln("General protection fault at RIP %lx, cs %ld, ss %ld, RSP %lx, error code %ld", context->rip,
|
|
context->cs, context->ss, context->rsp, context->error_code);
|
|
kinfoln("Stack trace:");
|
|
|
|
StackTracer tracer(context->rbp);
|
|
tracer.trace_with_ip(context->rip);
|
|
Scheduler::task_misbehave(context, -2);
|
|
}
|
|
}
|
|
if (context->number == 14)
|
|
{
|
|
Interrupts::disable();
|
|
|
|
if (context->cs == 0x8) { int_panic(context, "Page fault in kernel task"); }
|
|
else
|
|
{
|
|
VMM::enter_syscall_context();
|
|
|
|
kerrorln("Page fault in ring 3 (RIP %lx), while trying to access %lx, error code %ld", context->rip,
|
|
context->cr2, context->error_code);
|
|
kinfoln("Stack trace:");
|
|
|
|
StackTracer tracer(context->rbp);
|
|
tracer.trace_with_ip(context->rip);
|
|
|
|
determine_user_page_fault_reason(context->cr2);
|
|
|
|
Scheduler::task_misbehave(context, -3);
|
|
}
|
|
}
|
|
if (context->number == 8) { int_panic(context, "Double fault, halting"); }
|
|
if (context->number == 66) { Syscall::entry(context); }
|
|
if (context->number == 256) { kwarnln("Unused interrupt"); }
|
|
return;
|
|
} |