2022-09-18 09:43:58 +02:00
|
|
|
#define MODULE "isr"
|
|
|
|
|
2022-09-20 19:56:43 +02:00
|
|
|
#include "interrupts/Context.h"
|
2022-09-05 16:13:51 +02:00
|
|
|
#include "interrupts/IRQ.h"
|
2022-09-20 17:16:23 +02:00
|
|
|
#include "interrupts/Interrupts.h"
|
2022-09-25 20:35:05 +02:00
|
|
|
#include "io/Serial.h"
|
2022-09-18 09:43:58 +02:00
|
|
|
#include "log/Log.h"
|
2022-11-06 18:12:25 +01:00
|
|
|
#include "memory/VMM.h"
|
2022-09-21 17:56:53 +02:00
|
|
|
#include "misc/hang.h"
|
2022-09-25 16:56:00 +02:00
|
|
|
#include "panic/Panic.h"
|
2022-10-19 17:41:23 +02:00
|
|
|
#include "std/assert.h"
|
2022-09-05 16:13:51 +02:00
|
|
|
#include "std/stdio.h"
|
2022-09-29 19:17:43 +02:00
|
|
|
#include "sys/Syscall.h"
|
2022-09-20 19:58:04 +02:00
|
|
|
#include "thread/Scheduler.h"
|
2022-09-19 21:11:43 +02:00
|
|
|
#include "trace/StackTracer.h"
|
2022-11-06 18:12:25 +01:00
|
|
|
#include "utils/PageFaultReason.h"
|
2022-09-05 16:13:51 +02:00
|
|
|
|
2022-09-20 19:56:43 +02:00
|
|
|
extern "C" void common_handler(Context* context)
|
2022-09-05 16:13:51 +02:00
|
|
|
{
|
2022-11-02 19:38:15 +01:00
|
|
|
ensure(Interrupts::is_in_handler());
|
2022-09-18 09:43:58 +02:00
|
|
|
if (context->number >= 0x20 && context->number < 0x30)
|
|
|
|
{
|
|
|
|
IRQ::interrupt_handler(context);
|
|
|
|
return;
|
|
|
|
}
|
2022-09-05 16:13:51 +02:00
|
|
|
if (context->number == 13)
|
|
|
|
{
|
2022-09-25 16:56:00 +02:00
|
|
|
Interrupts::disable();
|
2022-09-19 21:11:43 +02:00
|
|
|
|
2022-09-25 16:56:00 +02:00
|
|
|
if (context->cs == 0x8) { int_panic(context, "GPF in kernel task"); }
|
2022-09-21 21:06:00 +02:00
|
|
|
else
|
|
|
|
{
|
2022-11-06 18:12:25 +01:00
|
|
|
VMM::enter_syscall_context();
|
|
|
|
|
2022-09-25 16:56:00 +02:00
|
|
|
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);
|
2022-10-08 17:56:40 +02:00
|
|
|
Scheduler::task_misbehave(context, -2);
|
2022-09-21 21:06:00 +02:00
|
|
|
}
|
2022-09-05 16:13:51 +02:00
|
|
|
}
|
2022-09-06 18:08:15 +02:00
|
|
|
if (context->number == 14)
|
|
|
|
{
|
2022-09-21 21:06:00 +02:00
|
|
|
Interrupts::disable();
|
2022-09-19 21:11:43 +02:00
|
|
|
|
2022-09-25 16:56:00 +02:00
|
|
|
if (context->cs == 0x8) { int_panic(context, "Page fault in kernel task"); }
|
2022-09-21 21:06:00 +02:00
|
|
|
else
|
|
|
|
{
|
2022-11-06 18:12:25 +01:00
|
|
|
VMM::enter_syscall_context();
|
|
|
|
|
2022-09-25 16:56:00 +02:00
|
|
|
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);
|
|
|
|
|
2022-11-06 18:12:25 +01:00
|
|
|
determine_user_page_fault_reason(context->cr2);
|
|
|
|
|
2022-10-08 17:56:40 +02:00
|
|
|
Scheduler::task_misbehave(context, -3);
|
2022-09-21 21:06:00 +02:00
|
|
|
}
|
2022-09-11 08:23:32 +02:00
|
|
|
}
|
2022-09-25 16:56:00 +02:00
|
|
|
if (context->number == 8) { int_panic(context, "Double fault, halting"); }
|
2022-09-29 19:17:43 +02:00
|
|
|
if (context->number == 66) { Syscall::entry(context); }
|
2022-09-18 09:43:58 +02:00
|
|
|
if (context->number == 256) { kwarnln("Unused interrupt"); }
|
2022-09-05 16:13:51 +02:00
|
|
|
return;
|
|
|
|
}
|