Improved logging system

This commit is contained in:
ice-bit 2019-07-08 20:36:53 +02:00
parent 52bb2609ae
commit 70c1f666c6
4 changed files with 85 additions and 27 deletions

View File

@ -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);
}

View File

@ -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

View File

@ -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
}

View File

@ -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!");
}
}