Use kernel logging in interrupts instead of plain old printf()

This commit is contained in:
apio 2022-09-18 09:43:58 +02:00
parent 783af21a7e
commit f7e7a6661d
2 changed files with 20 additions and 8 deletions

View File

@ -1,27 +1,35 @@
#define MODULE "isr"
#include "interrupts/IRQ.h"
#include "interrupts/SavedContext.h"
#include "log/Log.h"
#include "panic/hang.h"
#include "std/stdio.h"
extern "C" void common_handler(SavedContext* context)
{
if (context->number >= 0x20 && context->number < 0x30)
{
IRQ::interrupt_handler(context);
return;
}
if (context->number == 13)
{
printf("General protection fault at %zx, %ld, %ld, %zx, %ld, %zx\n", context->rip, context->cs, context->ss,
context->rsp, context->error_code, context->cr2);
kerrorln("General protection fault at RIP %lx, cs %ld, ss %ld, RSP %lx, error code %ld\n", context->rip,
context->cs, context->ss, context->rsp, context->error_code);
while (1) halt();
}
if (context->number == 14)
{
printf("Page fault (RIP 0x%lx), while trying to access %lx, error code %lx\n", context->rip, context->cr2,
context->error_code);
kerrorln("Page fault in %s (RIP %lx), while trying to access %lx, error code %ld\n",
context->cs == 8 ? "ring 0" : "ring 3", context->rip, context->cr2, context->error_code);
hang();
}
if (context->number == 8)
{
printf("Double fault");
kerrorln("Double fault, halting");
hang();
}
if (context->number >= 0x20 && context->number < 0x30) { IRQ::interrupt_handler(context); }
if (context->number == 256) { kwarnln("Unused interrupt"); }
return;
}

View File

@ -1,6 +1,9 @@
#define MODULE "irq"
#include "interrupts/IRQ.h"
#include "io/IO.h"
#include "io/PIC.h"
#include "log/Log.h"
#include "rand/Init.h"
#include "scheduling/PIT.h"
#include "std/stdio.h"
@ -12,10 +15,11 @@ void IRQ::interrupt_handler(SavedContext* context)
case 0: PIT::tick(); break;
case 1: {
[[maybe_unused]] volatile unsigned char scancode = IO::inb(0x60);
printf("Keyboard key pressed, seconds since boot: %ld\n", PIT::ms_since_boot / 1000);
kdbgln("Keyboard key pressed, seconds since boot: %ld.%ld", PIT::ms_since_boot / 1000,
PIT::ms_since_boot % 1000);
break;
}
default: printf("Unhandled IRQ: %ld", context->irq_number); break;
default: kwarnln("Unhandled IRQ: %ld", context->irq_number); break;
}
Mersenne::reseed();
PIC::send_eoi(context->irq_number);