From a90f613e50b1677b03d19793039e0769a09caf9f Mon Sep 17 00:00:00 2001 From: dzwdz Date: Sat, 10 Jul 2021 19:36:50 +0200 Subject: abstract away logging Now, the kernel only interfaces with the architecture dependent stuff via functions declared in generic.h. I'll write a linter enforcing this soon. --- src/arch/generic.h | 2 ++ src/arch/i386/boot.c | 7 ++++--- src/arch/i386/interrupts/isr.c | 6 +++--- src/arch/i386/log.c | 6 ++++++ src/arch/i386/tty.h | 2 -- src/arch/log.h | 7 +++++++ src/kernel/main.c | 8 ++++---- src/kernel/panic.h | 7 +++---- 8 files changed, 29 insertions(+), 16 deletions(-) create mode 100644 src/arch/i386/log.c create mode 100644 src/arch/log.h (limited to 'src') diff --git a/src/arch/generic.h b/src/arch/generic.h index 7807316..f9617ab 100644 --- a/src/arch/generic.h +++ b/src/arch/generic.h @@ -1,5 +1,7 @@ #pragma once +#include + // i have no idea where else to put it #define PAGE_SIZE 4096 diff --git a/src/arch/i386/boot.c b/src/arch/i386/boot.c index b2b84f0..37e1aff 100644 --- a/src/arch/i386/boot.c +++ b/src/arch/i386/boot.c @@ -1,3 +1,4 @@ +#include #include #include #include @@ -6,11 +7,11 @@ void kmain_early() { tty_clear(); - tty_const("gdt..."); + log_const("gdt..."); gdt_init(); - tty_const("idt..."); + log_const("idt..."); idt_init(); - tty_const("sysenter..."); + log_const("sysenter..."); sysenter_setup(); kmain(); } diff --git a/src/arch/i386/interrupts/isr.c b/src/arch/i386/interrupts/isr.c index 03399ea..1603fba 100644 --- a/src/arch/i386/interrupts/isr.c +++ b/src/arch/i386/interrupts/isr.c @@ -1,5 +1,5 @@ #include -#include +#include #include #include #include @@ -8,13 +8,13 @@ bool isr_test_interrupt_called = false; __attribute__((interrupt)) void isr_double_fault(struct interrupt_frame *frame) { - tty_const("#DF"); + log_const("#DF"); panic(); } __attribute__((interrupt)) void isr_general_protection_fault(struct interrupt_frame *frame) { - tty_const("#GP"); + log_const("#GP"); panic(); } diff --git a/src/arch/i386/log.c b/src/arch/i386/log.c new file mode 100644 index 0000000..fc82023 --- /dev/null +++ b/src/arch/i386/log.c @@ -0,0 +1,6 @@ +#include +#include + +void log_write(const char *buf, size_t len) { + tty_write(buf, len); +} diff --git a/src/arch/i386/tty.h b/src/arch/i386/tty.h index 3dc1525..cbb8efc 100644 --- a/src/arch/i386/tty.h +++ b/src/arch/i386/tty.h @@ -4,5 +4,3 @@ void tty_putchar(char c); void tty_write(const char *buf, size_t len); void tty_clear(); - -#define tty_const(str) tty_write(str, sizeof(str) - 1) diff --git a/src/arch/log.h b/src/arch/log.h new file mode 100644 index 0000000..6365c20 --- /dev/null +++ b/src/arch/log.h @@ -0,0 +1,7 @@ +#pragma once +#include + +void log_write(const char *buf, size_t len); + +// used for static strings +#define log_const(str) log_write(str, sizeof(str) - 1) diff --git a/src/kernel/main.c b/src/kernel/main.c index aa67d7c..d2d7dda 100644 --- a/src/kernel/main.c +++ b/src/kernel/main.c @@ -6,17 +6,17 @@ void r3_test(); void kmain() { - tty_const("mem..."); + log_const("mem..."); mem_init(); - tty_const("creating process..."); + log_const("creating process..."); struct process *proc = process_new(r3_test); - tty_const("switching..."); + log_const("switching..."); process_switch(proc); } void r3_test() { - tty_const("ok"); + log_const("ok"); asm("cli"); panic(); } diff --git a/src/kernel/panic.h b/src/kernel/panic.h index 54a0b8b..12d26fd 100644 --- a/src/kernel/panic.h +++ b/src/kernel/panic.h @@ -1,14 +1,13 @@ #pragma once #include -#include // TODO abstract away // dumb c shit #define panic_tostr2(x) #x #define panic_tostr(x) panic_tostr2(x) #define panic() do { \ - tty_const(" PANIC! at the "); \ - tty_const(__func__); \ - tty_const(" (" __FILE__ ":" panic_tostr(__LINE__) ") "); \ + log_const(" PANIC! at the "); \ + log_const(__func__); \ + log_const(" (" __FILE__ ":" panic_tostr(__LINE__) ") "); \ halt_cpu(); \ } while (0) -- cgit v1.2.3