Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ practices while remaining approachable to contributors and learners alike.

- [x] Serial output
- [x] Framebuffer abstraction + character output
- [ ] Panic functions + Assertion system
- [ ] Logging system (both visual + serial)
- [x] Panic functions + Assertion system
- [x] Logging system (both visual + serial)
- [ ] Halt loop
- [ ] Basics of the kernel + GDT, IDT and interrupt handlers
- [ ] PIC, timer and keyboard support
Expand Down
4 changes: 2 additions & 2 deletions include/console.h → include/kernel/console.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

#ifndef AVERY_CONSOLE_H
#define AVERY_CONSOLE_H
#include "types.h"
#include "graphics/graphicsTypes.h"
#include "../types.h"
#include "../graphics/graphicsTypes.h"

#pragma once

Expand Down
47 changes: 47 additions & 0 deletions include/kernel/debug.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* debug.h
* As part of the Avery project
* Created by Max Van den Eynde in 2026
* --------------------------------------
* Description: ${FILE_DESCRIPTION}
* Copyright (c) 2026 Max Van den Eynde
*/

#ifndef AVERY_DEBUG_H
#define AVERY_DEBUG_H

#pragma once

enum class LogType {
Console,
Serial,
};

#define PANIC(msg) debug::kernelPanic(msg, __FILE__, __LINE__, __func__)

#define VERIFY(expr) \
do { \
if (!(expr)) { \
debug::kernelPanic( \
"VERIFY failed: " #expr, \
__FILE__, \
__LINE__, \
__func__ \
); \
} \
} while (0)

#ifndef NDEBUG
#define ASSERT(expr) VERIFY(expr)
#else
#define ASSERT(expr) do { } while (0)
#endif

namespace debug {
[[noreturn]] void kernelPanic(const char* message, const char* file, int line, const char* function);
void log(const char* message, LogType logType = LogType::Serial);
void warn(const char* message, LogType logType = LogType::Serial);
void error(const char* message, LogType logType = LogType::Serial);
}

#endif //AVERY_DEBUG_H
83 changes: 83 additions & 0 deletions kernel/core/debug.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
* debug.cpp
* As part of the Avery project
* Created by Max Van den Eynde in 2026
* --------------------------------------
* Description: Debugging functions and more
* Copyright (c) 2026 Max Van den Eynde
*/

#include "../../include/kernel/debug.h"

#include "io/serial.h"
#include "kernel/console.h"

[[noreturn]] void debug::kernelPanic(const char* message, const char* file,
[[maybe_unused]] int line, const char* function) {
out::setColor(Color::white, Color::red);
out::clear();

out::println("");
out::println("The Avery Kernel panicked!");
out::println("Avery entered a bad execution state that resulted in an unrecoverable state.");
out::println("Restart your computer and contact the developers if the problem keeps happening");
out::println("=================");
out::println("Crash Information:");
out::println(message);
out::println("");
out::print("At file: ");
out::println(file);
out::println("");
out::print("At function: ");
out::println(function);

asm volatile("cli");

while (true) {
asm volatile("hlt");
}
}

void debug::log(const char* message, LogType logType) {
if (logType == LogType::Serial) {
io::serialWrite("(LOG) -> ");
io::serialWrite(message);
io::serialWrite("\n");
}
else {
out::setColor(Color::green, Color::black);
out::print("(LOG): ");
out::println(message);
}
}


void debug::warn(const char* message, LogType logType) {
if (logType == LogType::Serial) {
io::serialWrite("(WARNING) -> ");
io::serialWrite(message);
io::serialWrite("\n");
}
else {
out::setColor(Color::yellow, Color::black);
out::print("(WARNING): ");
out::println(message);
}
}


void debug::error(const char* message, LogType logType) {
if (logType == LogType::Serial) {
io::serialWrite("(ERROR) -> ");
io::serialWrite(message);
io::serialWrite("\n");
}
else {
out::setColor(Color::red, Color::black);
out::print("(ERROR): ");
out::println(message);
}
}



9 changes: 3 additions & 6 deletions kernel/graphics/framebuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
#include <limine.h>

#include "graphics/graphicsTypes.h"
#include "types.h"
#include "../../include/types.h"
#include "kernel/debug.h"

namespace {
u64 fontScale(float scale) {
Expand Down Expand Up @@ -66,11 +67,7 @@ Framebuffer Framebuffer::createFromLimineRequest(
) {
Framebuffer framebuffer;

if (request.response == nullptr || request.response->framebuffer_count < 1) {
while (true) {
asm volatile("hlt");
}
}
ASSERT(request.response == nullptr || request.response->framebuffer_count < 1);

framebuffer.fb = request.response->framebuffers[0];
framebuffer.fb_ptr = static_cast<volatile u32*>(framebuffer.fb->address);
Expand Down
2 changes: 1 addition & 1 deletion kernel/io/console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/

#include "graphics/framebuffer.h"
#include "console.h"
#include "../../include/kernel/console.h"

#include "io/serial.h"

Expand Down
2 changes: 1 addition & 1 deletion kernel/io/serial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* Copyright (c) 2026 Max Van den Eynde
*/

#include "types.h"
#include "../../include/types.h"
#include "io/serial.h"
#include "io/io.h"

Expand Down
7 changes: 6 additions & 1 deletion kernel/main.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#include <limine.h>

#include "console.h"
#include "../include/kernel/console.h"
#include "core/regs.h"
#include "graphics/framebuffer.h"
#include "io/serial.h"
#include "kernel/debug.h"

__attribute__((used, section(".limine_requests")))
static volatile uint64_t limine_base_revision[] = LIMINE_BASE_REVISION(6);
Expand All @@ -30,9 +31,13 @@ extern "C" [[noreturn]] void _start() {
}
}


Framebuffer framebuffer = Framebuffer::createFromLimineRequest(framebuffer_request);
out::initFramebufferConsole(framebuffer);

ASSERT(false == true);


out::println("Hello, World!");
out::switchTo(ConsoleOutputMode::Serial);
out::println("Hello, World!");
Expand Down
Loading