Skip to content

Commit

Permalink
Small Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
maxtyson123 committed Jan 15, 2024
1 parent 2452708 commit 7835362
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 1 deletion.
5 changes: 5 additions & 0 deletions kernel/include/drivers/console/serial.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ namespace MaxOS {

namespace drivers {


/**
* @class SerialConsole
* @brief A driver for the serial output
*/
class SerialConsole : public Driver {

private:
Expand Down
15 changes: 14 additions & 1 deletion kernel/src/common/kprint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -44,13 +44,23 @@ 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;
for (; str[len] != '\0'; len++);
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
Expand All @@ -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
Expand Down
4 changes: 4 additions & 0 deletions kernel/src/drivers/console/serial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
36 changes: 36 additions & 0 deletions toolchain/MaxOS.sh
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 7835362

Please sign in to comment.