From 7835362d7d324fdaed5cd538638d3dd3f5da3816 Mon Sep 17 00:00:00 2001 From: Max Tyson <98maxt98@gmail.com> Date: Tue, 16 Jan 2024 10:29:23 +1300 Subject: [PATCH] Small Fixes --- kernel/include/drivers/console/serial.h | 5 ++++ kernel/src/common/kprint.cpp | 15 ++++++++++- kernel/src/drivers/console/serial.cpp | 4 +++ toolchain/MaxOS.sh | 36 +++++++++++++++++++++++++ 4 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 toolchain/MaxOS.sh diff --git a/kernel/include/drivers/console/serial.h b/kernel/include/drivers/console/serial.h index c330b273..de4a2264 100644 --- a/kernel/include/drivers/console/serial.h +++ b/kernel/include/drivers/console/serial.h @@ -13,6 +13,11 @@ namespace MaxOS { namespace drivers { + + /** + * @class SerialConsole + * @brief A driver for the serial output + */ class SerialConsole : public Driver { private: diff --git a/kernel/src/common/kprint.cpp b/kernel/src/common/kprint.cpp index 620d6e7c..56281806 100644 --- a/kernel/src/common/kprint.cpp +++ b/kernel/src/common/kprint.cpp @@ -11,7 +11,7 @@ using namespace MaxOS::drivers; * @brief Converts integer to string * * @param buffer The buffer to store the converted string - * @param base The base (d for decimal, x gor hex) + * @param base The base of the number (10 for decimal, 16 for hex) * @param number The number to convert */ char* itoa(int base, int number) @@ -44,6 +44,12 @@ char* itoa(int base, int number) return &buffer[i + 1]; } +/** + * @brief Gets the length of a string + * + * @param str The string to get the length of + * @return The length of the string + */ int strlen(const char* str) { int len = 0; @@ -51,6 +57,10 @@ int strlen(const char* str) return len; } +/** + * @brief Prints a character to the serial output if it is initialized + * @param c The character to print + */ static void putchar (int c) { // Check if the active serial console is null @@ -61,6 +71,9 @@ static void putchar (int c) SerialConsole::s_active_serial_console->put_character(c); } +/** + * @ brief Prints a debug prefix (in yellow) to the serial output + */ void pre_kprintf() { // Print the kernel header with yellow text diff --git a/kernel/src/drivers/console/serial.cpp b/kernel/src/drivers/console/serial.cpp index d39ae153..20cbdd19 100644 --- a/kernel/src/drivers/console/serial.cpp +++ b/kernel/src/drivers/console/serial.cpp @@ -56,6 +56,10 @@ MaxOS::drivers::SerialConsole::~SerialConsole() { } +/** + * @brief Waits for the serial port to be ready, then writes a character to it + * @param c The character to write + */ void MaxOS::drivers::SerialConsole::put_character(char c) { // Wait for the serial port to be ready diff --git a/toolchain/MaxOS.sh b/toolchain/MaxOS.sh new file mode 100644 index 00000000..9005dae2 --- /dev/null +++ b/toolchain/MaxOS.sh @@ -0,0 +1,36 @@ +err () { + printf "\e[31m[ERROR] $1 \e[39m\n" +} + +msg () { + printf "\e[36m[INFO] $1 \e[39m\n" +} + +warn () { + printf "\e[33m[WARN] $1 \e[39m\n" +} + +success () { + printf "\e[32m[SUCCESS] $1 \e[39m\n" +} + +fail () { + + # Print error message + err "$1" + + # If there is something to do on fail, do it (and only once) + if [ -z "$FAILING" ]; then + FAILING=1 + if [ ! -z "$ON_FAIL" ]; then + $ON_FAIL + fi + fi + + # Exit with error code + if [ $? -eq 0 ]; then + exit 1 + else + exit $? + fi +} \ No newline at end of file