mirror of
https://github.com/tailix/kernel.git
synced 2024-10-30 12:03:52 -04:00
Allow to specify log source
This commit is contained in:
parent
31d51bc38c
commit
c86fdf1b34
8 changed files with 46 additions and 27 deletions
|
@ -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) {}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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 != '%') {
|
||||
|
|
|
@ -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
|
||||
|
|
22
arch/main.c
22
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.");
|
||||
}
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
Loading…
Reference in a new issue