diff --git a/kernel/Makefile b/kernel/Makefile index 2e6c7d5..cdfab63 100644 --- a/kernel/Makefile +++ b/kernel/Makefile @@ -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: diff --git a/kernel/kernel.cpp b/kernel/kernel.cpp index e91bc87..4ac7889 100644 --- a/kernel/kernel.cpp +++ b/kernel/kernel.cpp @@ -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 diff --git a/kernel/klog.cpp b/kernel/klog.cpp new file mode 100644 index 0000000..df954b8 --- /dev/null +++ b/kernel/klog.cpp @@ -0,0 +1,58 @@ +// +// Created by nigel on 10/28/23. +// +#include "klog.h" +#include "terminal/kterm.h" +#include + +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)); +} diff --git a/kernel/klog.h b/kernel/klog.h new file mode 100644 index 0000000..d121dc3 --- /dev/null +++ b/kernel/klog.h @@ -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, ...);