From c86fdf1b34af269b4423d28ad71c686a8ab9ec93 Mon Sep 17 00:00:00 2001 From: Braiden Vasco Date: Mon, 6 Nov 2017 04:21:18 +0000 Subject: [PATCH] Allow to specify log source --- arch/exception.c | 2 +- arch/hwint.c | 2 +- arch/logger.c | 15 +++++++++++++-- arch/logger.h | 12 ++++++++---- arch/main.c | 22 +++++++++++++--------- arch/protected.c | 14 +++++++------- arch/syscall.c | 4 ++-- arch/timer.c | 2 +- 8 files changed, 46 insertions(+), 27 deletions(-) diff --git a/arch/exception.c b/arch/exception.c index ea35547..4cb3d7a 100644 --- a/arch/exception.c +++ b/arch/exception.c @@ -46,7 +46,7 @@ void exception_handler(struct IsrRegisters regs) return; } - logger_fail("Unhandled protected-mode exception:\n%s", messages[regs.int_no]); + logger_fail_from("exception", "Unhandled protected-mode exception:\n%s", messages[regs.int_no]); asm volatile("cli"); while (1) {} diff --git a/arch/hwint.c b/arch/hwint.c index 9e510ba..03f207a 100644 --- a/arch/hwint.c +++ b/arch/hwint.c @@ -50,7 +50,7 @@ void hwint_handler(struct IsrRegisters regs) const hwint_handler_t handler = handlers[hwint_no]; if (!handler) { - logger_warn(messages[hwint_no]); + logger_warn_from("hwint", messages[hwint_no]); return; } diff --git a/arch/logger.c b/arch/logger.c index 2249a84..b41505c 100644 --- a/arch/logger.c +++ b/arch/logger.c @@ -20,7 +20,7 @@ static const char *const level_text[LEVELS_COUNT] = { static void print_level(unsigned char level); -void logger_log(unsigned char level, const char *format, ...) +void logger_log(unsigned char level, const char *const source, const char *format, ...) { if (level >= LEVELS_COUNT) { level = LEVELS_COUNT - 1; @@ -28,7 +28,11 @@ void logger_log(unsigned char level, const char *format, ...) print_level(level); - console_setcolor(VGA_COLOR_WHITE); + if (source) { + console_setcolor(VGA_COLOR_BROWN); + console_print(source); + console_print(": "); + } char **arg = (char **) &format; int c; @@ -44,6 +48,13 @@ void logger_log(unsigned char level, const char *format, ...) if (c == '\n') { console_putc('\n'); print_level(level); + + if (source) { + console_setcolor(VGA_COLOR_BROWN); + console_print(source); + console_print(": "); + } + color = VGA_COLOR_LIGHT_GREY; } else if (c != '%') { diff --git a/arch/logger.h b/arch/logger.h index 3510d83..ece4338 100644 --- a/arch/logger.h +++ b/arch/logger.h @@ -1,10 +1,14 @@ #ifndef KERNELMQ_INCLUDED_LOGGER #define KERNELMQ_INCLUDED_LOGGER 1 -#define logger_info(...) logger_log(0, __VA_ARGS__) -#define logger_warn(...) logger_log(1, __VA_ARGS__) -#define logger_fail(...) logger_log(2, __VA_ARGS__) +#define logger_info_from(source, ...) logger_log(0, source, __VA_ARGS__) +#define logger_warn_from(source, ...) logger_log(1, source, __VA_ARGS__) +#define logger_fail_from(source, ...) logger_log(2, source, __VA_ARGS__) -void logger_log(unsigned char level, const char *format, ...); +#define logger_info(...) logger_info_from(0, __VA_ARGS__) +#define logger_warn(...) logger_warn_from(0, __VA_ARGS__) +#define logger_fail(...) logger_fail_from(0, __VA_ARGS__) + +void logger_log(unsigned char level, const char *source, const char *format, ...); #endif diff --git a/arch/main.c b/arch/main.c index 6279a48..d4c27e8 100644 --- a/arch/main.c +++ b/arch/main.c @@ -21,25 +21,28 @@ void main(const struct KernelMQ_Info *const kinfo_ptr) kmemset(&kinfo, 0, sizeof(struct KernelMQ_Info)); if (!kernelmq_info_validate_and_copy(&kinfo, kinfo_ptr)) { - logger_fail("Invalid kernel information. Halt."); + logger_fail_from("main", "Invalid kernel information. Halt."); return; } - logger_info("Kernel command line: %s", kinfo.cmdline); + logger_info_from("main", "Kernel command line: %s", kinfo.cmdline); - logger_info( + logger_info_from( + "main", "Kernel phys base 0x%x, limit 0x%x", kinfo.kernel_phys_base, kinfo.kernel_phys_limit ); - logger_info( + logger_info_from( + "main", "Kernel virt base 0x%x, limit 0x%x", kinfo.kernel_virt_base, kinfo.kernel_virt_limit ); - logger_info( + logger_info_from( + "main", "Kernel size 0x%x, offset 0x%x", kinfo.kernel_size, kinfo.kernel_offset @@ -48,7 +51,8 @@ void main(const struct KernelMQ_Info *const kinfo_ptr) for (unsigned int i = 0; i < kinfo.modules_count; ++i) { struct KernelMQ_Info_Module *module = &kinfo.modules[i]; - logger_info( + logger_info_from( + "main", "Module at 0x%x, size 0x%x, command line: %s", module->base, module->size, @@ -75,11 +79,11 @@ void main(const struct KernelMQ_Info *const kinfo_ptr) timer_register_handler(on_timer); timer_initialize(50); - logger_warn("Nothing to do."); - logger_fail("Halt."); + logger_warn_from("main", "Nothing to do."); + logger_fail_from("main", "Halt."); } void on_timer() { - logger_info("Timer tick."); + logger_info_from("main", "Timer tick."); } diff --git a/arch/protected.c b/arch/protected.c index 6158577..84f564a 100644 --- a/arch/protected.c +++ b/arch/protected.c @@ -55,7 +55,7 @@ void idt_flush(const struct IdtPointer *pointer); void protected_initialize(const struct KernelMQ_Info *const kinfo) { - logger_info("Remap the IRQ table."); + logger_info_from("protected", "Remap the IRQ table."); outportb(0x20, 0x11); outportb(0xA0, 0x11); @@ -68,7 +68,7 @@ void protected_initialize(const struct KernelMQ_Info *const kinfo) outportb(0x21, 0x00); outportb(0xA1, 0x00); - logger_info("Setup GDT."); + logger_info_from("protected", "Setup GDT."); gdt_set_gate(GDT_NULL_INDEX, 0, 0x00000000, 0, 0); gdt_set_gate(GDT_KERNEL_CS_INDEX, 0, 0xFFFFFFFF, 0x9A, 0xCF); @@ -78,7 +78,7 @@ void protected_initialize(const struct KernelMQ_Info *const kinfo) tss_write_to_gdt(kinfo, &gdt_entries[GDT_TSS_INDEX]); - logger_info("Setup IDT."); + logger_info_from("protected", "Setup IDT."); kmemset(idt_entries, 0, sizeof(idt_entries)); @@ -134,25 +134,25 @@ void protected_initialize(const struct KernelMQ_Info *const kinfo) idt_set_gate(INT_SYSCALL, (unsigned int)interrupt_0x80, 0x08, 0x8E | 0x60); - logger_info("Load GDT."); + logger_info_from("protected", "Load GDT."); gdt_pointer.limit = sizeof(struct GdtEntry) * GDT_SIZE - 1; gdt_pointer.base = (unsigned int)&gdt_entries; gdt_flush(&gdt_pointer); - logger_info("Load IDT."); + logger_info_from("protected", "Load IDT."); idt_pointer.limit = sizeof(struct IdtEntry) * IDT_SIZE - 1; idt_pointer.base = (unsigned int)&idt_entries; idt_flush(&idt_pointer); - logger_info("Load TSS."); + logger_info_from("protected", "Load TSS."); tss_flush(); - logger_info("Enable interrupts."); + logger_info_from("protected", "Enable interrupts."); asm volatile ("sti"); } diff --git a/arch/syscall.c b/arch/syscall.c index e56bc60..3642c4b 100644 --- a/arch/syscall.c +++ b/arch/syscall.c @@ -13,10 +13,10 @@ void syscall_handler(const struct IsrRegisters regs) case KERNELMQ_SYSCALL_EXIT: return syscall_do_exit(regs); } - logger_info("syscall %u", id); + logger_info_from("syscall", "number %u", id); } void syscall_do_exit(const struct IsrRegisters regs) { - logger_warn("process try to exit with error code %u, haha", regs.ebx & 0xFFFF); + logger_warn_from("syscall", "process try to exit with error code %u, haha", regs.ebx & 0xFFFF); } diff --git a/arch/timer.c b/arch/timer.c index 3abb0a5..19ee05f 100644 --- a/arch/timer.c +++ b/arch/timer.c @@ -5,7 +5,7 @@ void timer_initialize(unsigned int frequency) { - logger_info("Initialize timer."); + logger_info_from("timer", "Initialize timer."); const unsigned int divisor = 1193180 / frequency;