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

View File

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