From f7e7a6661d05efb9386266b3314090afc30996b8 Mon Sep 17 00:00:00 2001 From: apio Date: Sun, 18 Sep 2022 09:43:58 +0200 Subject: [PATCH] Use kernel logging in interrupts instead of plain old printf() --- kernel/src/interrupts/Entry.cpp | 20 ++++++++++++++------ kernel/src/interrupts/IRQ.cpp | 8 ++++++-- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/kernel/src/interrupts/Entry.cpp b/kernel/src/interrupts/Entry.cpp index 0e313472..7344bd87 100644 --- a/kernel/src/interrupts/Entry.cpp +++ b/kernel/src/interrupts/Entry.cpp @@ -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; } \ No newline at end of file diff --git a/kernel/src/interrupts/IRQ.cpp b/kernel/src/interrupts/IRQ.cpp index b356aa44..008f5486 100644 --- a/kernel/src/interrupts/IRQ.cpp +++ b/kernel/src/interrupts/IRQ.cpp @@ -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);