diff --git a/kernelmq/Makefile b/kernelmq/Makefile index 2bfda32..9614779 100644 --- a/kernelmq/Makefile +++ b/kernelmq/Makefile @@ -21,9 +21,6 @@ OBJS += info.c.o OBJS += pic.c.o OBJS += timer.c.o -# For debugging -OBJS += logger.c.o - OBJS += protected.c.o protected.asm.cpp.o OBJS += tss.c.o tss.asm.cpp.o diff --git a/kernelmq/exception.c b/kernelmq/exception.c index 0a22c63..f3a215f 100644 --- a/kernelmq/exception.c +++ b/kernelmq/exception.c @@ -1,8 +1,9 @@ #include "interrupt.h" #include "config.h" -#include "logger.h" #include "panic.h" +#include + static const char *const messages[] = { "0 #DE - Divide Error Exception", "1 #DB - Debug Exception", @@ -47,7 +48,7 @@ void exception_handler(struct IsrRegisters regs) return; } - logger_fail_from("exception", "Unhandled protected-mode exception:\n%s", messages[regs.int_no]); + kernaux_console_printf("[FAIL] exception: Unhandled protected-mode exception: %s\n", messages[regs.int_no]); panic("Can not continue."); } diff --git a/kernelmq/hwint.c b/kernelmq/hwint.c index c23a709..e73ed9a 100644 --- a/kernelmq/hwint.c +++ b/kernelmq/hwint.c @@ -2,9 +2,10 @@ #include "interrupt.h" #include "config.h" -#include "logger.h" #include "pic.h" +#include + static hwint_handler_t handlers[INT_HWINT_COUNT] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; void hwint_handler(struct IsrRegisters regs) @@ -18,7 +19,7 @@ void hwint_handler(struct IsrRegisters regs) const hwint_handler_t handler = handlers[hwint_no]; if (!handler) { - logger_warn_from("hwint", "Unhandled hardware interrupt: %u", hwint_no); + kernaux_console_printf("[WARN] hwint: Unhandled hardware interrupt: %u\n", hwint_no); return; } diff --git a/kernelmq/logger.c b/kernelmq/logger.c deleted file mode 100644 index 68a4b80..0000000 --- a/kernelmq/logger.c +++ /dev/null @@ -1,94 +0,0 @@ -#include "logger.h" - -#include -#include - -#define LEVELS_COUNT 4 - -static const char *const level_text[LEVELS_COUNT] = { - "DBUG", - "INFO", - "WARN", - "FAIL", -}; - -static void print_prefix(unsigned char level, const char *source); - -void logger_log(unsigned char level, const char *const source, const char *format, ...) -{ - if (level >= LEVELS_COUNT) { - level = LEVELS_COUNT - 1; - } - - print_prefix(level, source); - - char **arg = (char **) &format; - int c; - char buf[20]; - arg++; - - while ((c = *format++) != 0) - { - if (c == '\n') { - kernaux_console_putc('\n'); - print_prefix(level, source); - } - else if (c != '%') { - kernaux_console_putc(c); - } - else { - char *p, *p2; - int pad0 = 0, pad = 0; - c = *format++; - if (c == '0') - { - pad0 = 1; - c = *format++; - } - if (c >= '0' && c <= '9') - { - pad = c - '0'; - c = *format++; - } - switch (c) - { - case 'd': - case 'u': - case 'x': - kernaux_itoa(*((int*)arg++), buf, c); - p = buf; - goto string; - break; - case 's': - p = *arg++; - if (! p) - p = "(null)"; -string: - for (p2 = p; *p2; p2++); - for (; p2 < p + pad; p2++) - kernaux_console_putc(pad0 ? '0' : ' '); - while (*p) - kernaux_console_putc(*p++); - break; - default: - kernaux_console_putc(*((int *) arg++)); - break; - } - } - } - - kernaux_console_putc('\n'); -} - -void print_prefix(const unsigned char level, const char *const source) -{ - kernaux_console_putc('['); - kernaux_console_print(level_text[level]); - kernaux_console_putc(']'); - kernaux_console_putc(' '); - - if (source) { - kernaux_console_print(source); - kernaux_console_print(": "); - } -} diff --git a/kernelmq/logger.h b/kernelmq/logger.h deleted file mode 100644 index 6893fff..0000000 --- a/kernelmq/logger.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef KERNELMQ_INCLUDED_LOGGER -#define KERNELMQ_INCLUDED_LOGGER 1 - -#define logger_debug_from(source, ...) logger_log(0, source, __VA_ARGS__) -#define logger_info_from(source, ...) logger_log(1, source, __VA_ARGS__) -#define logger_warn_from(source, ...) logger_log(2, source, __VA_ARGS__) -#define logger_fail_from(source, ...) logger_log(3, source, __VA_ARGS__) - -#define logger_debug(...) logger_debug_from(0, __VA_ARGS__) -#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/kernelmq/main.c b/kernelmq/main.c index da9b7c3..d360d57 100644 --- a/kernelmq/main.c +++ b/kernelmq/main.c @@ -7,7 +7,6 @@ #include "tasks.h" #include "elf.h" -#include "logger.h" #include #include @@ -177,7 +176,7 @@ void main( tasks_switch_to_user(real_entrypoint); } else { - logger_warn_from("init", "Invalid ELF header"); + kernaux_console_print("[WARN] init: Invalid ELF header.\n"); } } } diff --git a/kernelmq/panic.c b/kernelmq/panic.c index be13e09..c618ff9 100644 --- a/kernelmq/panic.c +++ b/kernelmq/panic.c @@ -1,12 +1,11 @@ #include "panic.h" -#include "logger.h" - #include +#include void panic(const char *const s) { - logger_fail_from("panic", s); + kernaux_console_printf("[FAIL] panic: %s\n", s); kernaux_arch_x86_hang(); } diff --git a/kernelmq/pic.c b/kernelmq/pic.c index 034214d..c712c20 100644 --- a/kernelmq/pic.c +++ b/kernelmq/pic.c @@ -1,8 +1,7 @@ #include "pic.h" -#include "logger.h" - #include +#include #define MASTER_COMMAND 0x20 #define MASTER_DATA 0x21 @@ -18,7 +17,7 @@ static unsigned char slave_irq_start = 8; void pic_enable_all() { - logger_info_from("pic", "Enable all IRQs."); + kernaux_console_print("[INFO] pic: Enable all IRQs.\n"); kernaux_arch_x86_outportb(MASTER_DATA, 0); kernaux_arch_x86_outportb(SLAVE_DATA, 0); @@ -26,7 +25,7 @@ void pic_enable_all() void pic_disable_all() { - logger_info_from("pic", "Disable all IRQs."); + kernaux_console_print("[INFO] pic: Disable all IRQs.\n"); kernaux_arch_x86_outportb(MASTER_DATA, 0xFF); kernaux_arch_x86_outportb(SLAVE_DATA, 0xFF); @@ -35,11 +34,11 @@ void pic_disable_all() void pic_enable(const unsigned char line) { if (line >= IRQS_TOTAL) { - logger_warn_from("pic", "Invalid line %u.", line); + kernaux_console_printf("[WARN] pic: Invalid line %u.\n", line); return; } - logger_info_from("pic", "Enable line %u.", line); + kernaux_console_printf("[INFO] pic: Enable line %u.\n", line); if (line < IRQS_COUNT) { const unsigned char mask = kernaux_arch_x86_inportb(MASTER_DATA); @@ -54,11 +53,11 @@ void pic_enable(const unsigned char line) void pic_disable(const unsigned char line) { if (line >= IRQS_TOTAL) { - logger_warn_from("pic", "Invalid line %u.", line); + kernaux_console_printf("[WARN] pic: Invalid line %u.\n", line); return; } - logger_info_from("pic", "Disable line %u.", line); + kernaux_console_printf("[INFO] pic: Disable line %u.\n", line); if (line < IRQS_COUNT) { const unsigned char mask = kernaux_arch_x86_inportb(MASTER_DATA); @@ -73,7 +72,7 @@ void pic_disable(const unsigned char line) void pic_remap(const unsigned char new_master_irq_start, const unsigned char new_slave_irq_start) { - logger_info_from("pic", "Remap the IRQ table."); + kernaux_console_print("[INFO] pic: Remap the IRQ table.\n"); // Remember IRQ numbers master_irq_start = new_master_irq_start; diff --git a/kernelmq/protected.c b/kernelmq/protected.c index a7544ae..9365c5a 100644 --- a/kernelmq/protected.c +++ b/kernelmq/protected.c @@ -1,12 +1,12 @@ #include "protected.h" #include "config.h" -#include "logger.h" #include "interrupt.h" #include "hwint.h" #include "tss.h" #include "pic.h" +#include #include struct GdtPointer { @@ -56,7 +56,7 @@ void protected_initialize(const struct KernelMQ_Info *const kinfo) pic_remap(32, 40); pic_disable_all(); - logger_info_from("protected", "Setup GDT."); + kernaux_console_print("[INFO] protected: Setup GDT.\n"); gdt_set_gate(GDT_NULL_INDEX, 0, 0x00000000, 0, 0); gdt_set_gate(GDT_KERNEL_CS_INDEX, 0, 0xFFFFFFFF, 0x9A, 0xCF); @@ -66,7 +66,7 @@ void protected_initialize(const struct KernelMQ_Info *const kinfo) tss_write_to_gdt(kinfo, &gdt_entries[GDT_TSS_INDEX]); - logger_info_from("protected", "Setup IDT."); + kernaux_console_print("[INFO] protected: Setup IDT.\n"); kernaux_memset(idt_entries, 0, sizeof(idt_entries)); @@ -125,25 +125,25 @@ void protected_initialize(const struct KernelMQ_Info *const kinfo) idt_set_gate(INT_SYSCALL, (unsigned int)interrupt_0x80, 0x08, 0x8E | 0x60); - logger_info_from("protected", "Load GDT."); + kernaux_console_print("[INFO] protected: Load GDT.\n"); gdt_pointer.limit = sizeof(struct GdtEntry) * GDT_SIZE - 1; gdt_pointer.base = (unsigned int)&gdt_entries; gdt_flush(&gdt_pointer); - logger_info_from("protected", "Load IDT."); + kernaux_console_print("[INFO] protected: Load IDT.\n"); idt_pointer.limit = sizeof(struct IdtEntry) * IDT_SIZE - 1; idt_pointer.base = (unsigned int)&idt_entries; idt_flush(&idt_pointer); - logger_info_from("protected", "Load TSS."); + kernaux_console_print("[INFO] protected: Load TSS.\n"); tss_flush(); - logger_info_from("protected", "Enable interrupts."); + kernaux_console_print("[INFO] protected: Enable interrupts.\n"); asm volatile ("sti"); } diff --git a/kernelmq/syscall.c b/kernelmq/syscall.c index d302e53..5f0430b 100644 --- a/kernelmq/syscall.c +++ b/kernelmq/syscall.c @@ -1,15 +1,16 @@ #include "interrupt.h" -#include "logger.h" #include "syscall.h" +#include + static void syscall_do_exit(struct IsrRegisters regs); void syscall_handler(const struct IsrRegisters regs) { const unsigned int id = regs.eax << 16 >> 16; - logger_info_from("syscall", "number %u", id); + kernaux_console_printf("[INFO] syscall: number %u\n", id); switch (id) { case KERNELMQ_SYSCALL_EXIT: return syscall_do_exit(regs); @@ -20,5 +21,5 @@ void syscall_do_exit(const struct IsrRegisters regs) { const unsigned int exit_code = regs.ebx << 16 >> 16; - logger_warn_from("syscall", "process try to exit with error code %u, haha", exit_code); + kernaux_console_printf("[WARN] syscall: process try to exit with error code %u, haha\n", exit_code); } diff --git a/kernelmq/timer.c b/kernelmq/timer.c index 832a825..480a763 100644 --- a/kernelmq/timer.c +++ b/kernelmq/timer.c @@ -1,12 +1,11 @@ #include "timer.h" -#include "logger.h" - #include +#include void timer_initialize(unsigned int frequency) { - logger_info_from("timer", "Initialize timer."); + kernaux_console_print("[INFO] timer: Initialize timer.\n"); const unsigned int divisor = 1193180 / frequency;