Added klog as a new logging system

* The logging system sends the message to both VGA and serial
* The serial print uses color to indicate the category of the message

Message Categories  |  Colours
Debug			Green
Info			Blue
Error			Red
This commit is contained in:
Nigel Barink 2023-10-28 22:28:21 +02:00
parent 9c5667c454
commit 6086b04054
4 changed files with 85 additions and 14 deletions

View File

@ -35,7 +35,8 @@ OFILES = $(OBJ_DIR)/boot.o \
$(OBJ_DIR)/rsdp.o \
$(OBJ_DIR)/acpi.o \
$(OBJ_DIR)/fat.o \
$(OBJ_DIR)/serial.o
$(OBJ_DIR)/serial.o \
$(OBJ_DIR)/klog.o
OBJ_LINK_LIST = $(CRTI_OBJ) $(CRTBEGIN_OBJ) $(OFILES) $(CRTEND_OBJ) $(CRTN_OBJ)
INTERNAL_OBJS = $(CRTI_OBJ) $(OFILES) $(CRTN_OBJ)
@ -125,7 +126,8 @@ $(OBJ_DIR)/fat.o:
$(OBJ_DIR)/serial.o:
$(CPP) -c drivers/serial/serial.cpp -o $(OBJ_DIR)/serial.o $(CFLAGS) -fno-exceptions -fno-rtti
$(OBJ_DIR)/klog.o:
$(CPP) -c klog.cpp -o $(OBJ_DIR)/klog.o $(CFLAGS) -fno-exceptions -fno-rtti
# Assembly -> Object files
$(OBJ_DIR)/boot.o:

View File

@ -16,7 +16,8 @@
#include "storage/filesystems/FAT/FAT.h"
#include "acpi/acpi.h"
#include "memory/VirtualMemoryManager.h"
#include "drivers/serial/serial.h"
#include "klog.h"
extern BootInfoBlock* BIB;
extern "C" void LoadGlobalDescriptorTable();
@ -45,9 +46,14 @@ extern "C" void kernel ()
initidt();
LoadGlobalDescriptorTable();
flush_tss();
printf("Memory setup complete!\n");
print_info("Memory setup complete!\n");
// Enable interrupts
asm volatile("STI");
initHeap();
//pit_initialise();
@ -59,16 +65,9 @@ extern "C" void kernel ()
initBootDrive();
VirtualFileSystem::initialize();
// Test new serial driver
SerialConfig debug_com1_config{
COM1,
0x03,
0x00
};
Serial com1 = Serial(debug_com1_config);
com1.write((void*)"Hello world!\n", 14);
print_dbg("Hello debug!\n");
print_info("Hello info!\n");
print_err("Hello error!\n");
#define VFS_EXAMPLE
#ifdef VFS_EXAMPLE

58
kernel/klog.cpp Normal file
View File

@ -0,0 +1,58 @@
//
// Created by nigel on 10/28/23.
//
#include "klog.h"
#include "terminal/kterm.h"
#include <CoreLib/Memory.h>
const char* ForeGroundColourReset = "\e[39m";
void print_dbg(const char* message, ...){
auto **arg = (unsigned char**)&message;
// Send it to the VGA
printf(message, arg);
// Now send the message to the serial
Serial com1= Serial({
COM1,
0x03,
0x00
});
const char* ForeGroundColour = "\e[32m";
com1.write((void*)ForeGroundColour, strlen(ForeGroundColour));
com1.write((void*)message, strlen(message));
com1.write((void*)ForeGroundColourReset, strlen(ForeGroundColourReset));
}
void print_info(const char* message, ...){
auto **arg = (unsigned char**)&message;
// Send it to the VGA
printf(message, arg);
Serial com1 = Serial({
COM1,
0x03,
0x00
});
const char* ForeGroundColour = "\e[34m";
com1.write((void*)ForeGroundColour, strlen(ForeGroundColour));
com1.write((void*)message, strlen(message));
com1.write((void*)ForeGroundColourReset, strlen(ForeGroundColourReset));
}
void print_err(const char* message, ...){
auto **arg = (unsigned char**)&message;
// Send it to the VGA
printf(message, arg);
Serial com1 = Serial({
COM1,
0x03,
0x00
});
const char* ForeGroundColour = "\e[31m";
com1.write((void*)ForeGroundColour, strlen(ForeGroundColour));
com1.write((void*)message, strlen(message));
com1.write((void*)ForeGroundColourReset, strlen(ForeGroundColourReset));
}

12
kernel/klog.h Normal file
View File

@ -0,0 +1,12 @@
//
// Created by nigel on 10/28/23.
//
#pragma once
#include "drivers/serial/serial.h"
void print_dbg(const char* message, ...);
void print_info(const char* message, ...);
void print_err(const char* message, ...);