From 70c1f666c6710bef0cb24785ffc9beaa7e21205f Mon Sep 17 00:00:00 2001 From: ice-bit Date: Mon, 8 Jul 2019 20:36:53 +0200 Subject: [PATCH] Improved logging system --- kernel/drivers/timer.c | 5 ++- kernel/drivers/timer.h | 2 +- kernel/kernel_main.c | 24 ++++++++++--- kernel/shell/shell.c | 81 ++++++++++++++++++++++++++++++++---------- 4 files changed, 85 insertions(+), 27 deletions(-) diff --git a/kernel/drivers/timer.c b/kernel/drivers/timer.c index 5375cac..f6756e3 100644 --- a/kernel/drivers/timer.c +++ b/kernel/drivers/timer.c @@ -9,13 +9,12 @@ uint32_t tick = 0; static void timer_callback(registers_t regs) { tick++; - uint8_t buf[8]; + /* uint8_t buf[8]; itoa(tick, buf, 10); kprint((uint8_t*)"Time: "); uitoa(tick, buf, 10); kprint((uint8_t*)buf); - kprint((uint8_t*)"\n"); - + kprint((uint8_t*)"\n");*/ // Cast to void unused parameter UNUSED_PAR(regs); } diff --git a/kernel/drivers/timer.h b/kernel/drivers/timer.h index 95a7bc2..a8c0de9 100644 --- a/kernel/drivers/timer.h +++ b/kernel/drivers/timer.h @@ -31,7 +31,7 @@ */ void init_timer(uint32_t frequency); - +uint32_t tick; /* Since regs parameter(from timer_callback) will be unused * GCC(with -Werror flag) will dump an error, so we avoid this * using the following macro diff --git a/kernel/kernel_main.c b/kernel/kernel_main.c index 5ea48c1..8373436 100644 --- a/kernel/kernel_main.c +++ b/kernel/kernel_main.c @@ -11,15 +11,29 @@ #include "drivers/timer.h" #include "drivers/keyboard.h" #include "shell/shell.h" +#include "libc/stdio.h" void kernel_main() { - gdt_setup(); // Setup Global Descriptor Table - idt_setup(); // Setup Interrupt Descriptor Table + printf_color("\n[STATUS]", LIGHT_GREEN, BLACK); + printf_color(" - Loading kernel, wait please...", WHITE, BLACK); - clear_prompt(); + gdt_setup(); // Setup Global Descriptor Table + printf_color("\n[INFO]", LIGHT_CYAN, BLACK); + printf_color(" - Loaded GDT", WHITE, BLACK); + + idt_setup(); // Setup Interrupt Descriptor Table + printf_color("\n[INFO]", LIGHT_CYAN, BLACK); + printf_color(" - Loaded IDT", WHITE, BLACK); + + init_timer(1); // Initialize PIT driver + printf_color("\n[INFO]", LIGHT_CYAN, BLACK); + printf_color(" - Loaded PIT", WHITE, BLACK); + + init_keyboard(); // Initialize keyboard driver + printf_color("\n[INFO]", LIGHT_CYAN, BLACK); + printf_color(" - Loaded PS/2 driver", WHITE, BLACK); + iceos_ascii_logo(); init_prompt(); // Initialize frame buffer - init_keyboard(); // Initialize keyboard driver - // init_timer(1); // Only for debug purposes } \ No newline at end of file diff --git a/kernel/shell/shell.c b/kernel/shell/shell.c index 9f23faa..0b9e6b0 100644 --- a/kernel/shell/shell.c +++ b/kernel/shell/shell.c @@ -3,6 +3,7 @@ #include "../libc/stdio.h" #include "../drivers/tty.h" #include "../drivers/ports.h" +#include "../drivers/timer.h" void helper() { puts("\nList of available commands:\n" @@ -10,6 +11,8 @@ void helper() { "\nint - Test some interrupts" "\nbanner - Show banner" "\nclear, cls - Clear the screen" + "\nregs - Prints register dump" + "\ntimer - Prints timer tick" "\nabout - About this kernel" "\nreboot - Reboot the system" ); @@ -42,6 +45,44 @@ void about() { LIGHT_GREEN, BLACK); } +void register_dump() { + register uint32_t eax_v asm("eax"); + register uint32_t ebx_v asm("ebx"); + register uint32_t ecx_v asm("ecx"); + register uint32_t edx_v asm("edx"); + register uint32_t esx_v asm("esi"); + register uint32_t edi_v asm("edi"); + register uint32_t ebp_v asm("ebp"); + register uint32_t esp_v asm("esp"); + + printf_color("\n===================================\n" + " BEGIN 32 BITS CPU REGISTER DUMP \n" + "===================================\n", + LIGHT_BROWN, BLACK); + printf(" EAX: %x\n" + " EBX: %x\n" + " ECX: %x\n" + " EDX: %x\n" + " ESX: %x\n" + " EDI: %x\n" + " EBP: %x\n" + " ESP: %x\n", + eax_v, ebx_v, ecx_v, edx_v, esx_v, edi_v, ebp_v, esp_v); + printf_color("\n==================================\n" + " END 32 BITS CPU REGISTER DUMP \n" + "==================================\n", + LIGHT_BROWN, BLACK); +} + +void timer_dump() { + uint8_t buf[8]; + uitoa(tick, buf, 10); + + printf_color("\nTicks since boot: ", + LIGHT_GREEN, BLACK); + printf_color((const char*)buf, + LIGHT_CYAN, BLACK); +} void reboot() { uint8_t tmp; asm("cli"); // First disable all interrupts @@ -56,6 +97,27 @@ void reboot() { outb(0x64, 0xFE); // Reset the CPU } +void processCommand(uint8_t *cmd) { + if(strcmp(cmd, (uint8_t*)"help") == 0) + helper(); + else if(strcmp(cmd, (uint8_t*)"int") == 0) + test_interrupts(); + else if(strcmp(cmd, (uint8_t*)"clear") == 0 || strcmp(cmd, (uint8_t*)"cls") == 0) + clear_prompt(); + else if(strcmp(cmd, (uint8_t*)"about") == 0) + about(); + else if(strcmp(cmd, (uint8_t*)"regs") == 0) + register_dump(); + else if(strcmp(cmd, (uint8_t*)"timer") == 0) + timer_dump(); + else if(strcmp(cmd, (uint8_t*)"banner") == 0) + iceos_ascii_logo(); + else if(strcmp(cmd, (uint8_t*)"reboot") == 0) + reboot(); + else + puts("\nCommand not found!"); +} + void iceos_ascii_logo() { printf_color( "\n\n### ##### ####### ####### #####\n" @@ -67,21 +129,4 @@ void iceos_ascii_logo() { "### ##### ####### ####### ##### \n" "\n (c) Marco Cetica 2019\n", LIGHT_MAGENTA, BLACK); - } - -void processCommand(uint8_t *cmd) { - if(strcmp(cmd, (uint8_t*)"help") == 0) - helper(); - else if(strcmp(cmd, (uint8_t*)"int") == 0) - test_interrupts(); - else if(strcmp(cmd, (uint8_t*)"clear") == 0 || strcmp(cmd, (uint8_t*)"cls") == 0) - clear_prompt(); - else if(strcmp(cmd, (uint8_t*)"about") == 0) - about(); - else if(strcmp(cmd, (uint8_t*)"banner") == 0) - iceos_ascii_logo(); - else if(strcmp(cmd, (uint8_t*)"reboot") == 0) - reboot(); - else - puts("\nCommand not found!"); -} \ No newline at end of file + } \ No newline at end of file