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
33 changes: 18 additions & 15 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

cmake_minimum_required(VERSION 3.25)
project(Avery LANGUAGES CXX)
project(Avery LANGUAGES CXX ASM_NASM)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
Expand All @@ -10,8 +10,11 @@ set(ISO_ROOT ${CMAKE_BINARY_DIR}/iso)
set(ISO_FILE ${CMAKE_BINARY_DIR}/avery.iso)
set(LIMINE_DIR ${CMAKE_BINARY_DIR}/limine)

set(CMAKE_ASM_NASM_OBJECT_FORMAT elf64)

file(GLOB_RECURSE KERNEL_SOURCES CONFIGURE_DEPENDS
kernel/*.cpp
kernel/*.asm
include/*.h
include/*.hpp
)
Expand All @@ -27,20 +30,20 @@ target_include_directories(avery_objects PRIVATE
)

target_compile_options(avery_objects PRIVATE
-ffreestanding
-fno-exceptions
-fno-rtti
-fno-stack-protector
-fno-pic
-m64
-mno-red-zone
-mcmodel=kernel
-Wall
-Wextra
-Wpedantic
-Wconversion
-Wshadow
-Werror
$<$<COMPILE_LANGUAGE:CXX>:-ffreestanding>
$<$<COMPILE_LANGUAGE:CXX>:-fno-exceptions>
$<$<COMPILE_LANGUAGE:CXX>:-fno-rtti>
$<$<COMPILE_LANGUAGE:CXX>:-fno-stack-protector>
$<$<COMPILE_LANGUAGE:CXX>:-fno-pic>
$<$<COMPILE_LANGUAGE:CXX>:-m64>
$<$<COMPILE_LANGUAGE:CXX>:-mno-red-zone>
$<$<COMPILE_LANGUAGE:CXX>:-mcmodel=kernel>
$<$<COMPILE_LANGUAGE:CXX>:-Wall>
$<$<COMPILE_LANGUAGE:CXX>:-Wextra>
$<$<COMPILE_LANGUAGE:CXX>:-Wpedantic>
$<$<COMPILE_LANGUAGE:CXX>:-Wconversion>
$<$<COMPILE_LANGUAGE:CXX>:-Wshadow>
$<$<COMPILE_LANGUAGE:CXX>:-Werror>
)

set(KERNEL_ELF ${CMAKE_BINARY_DIR}/avery.elf)
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ practices while remaining approachable to contributors and learners alike.
- [x] Framebuffer abstraction + character output
- [x] Panic functions + Assertion system
- [x] Logging system (both visual + serial)
- [ ] Halt loop
- [ ] Basics of the kernel + GDT, IDT and interrupt handlers
- [x] Halt loop
- [x] Basics of the kernel + GDT, IDT and interrupt handlers
- [ ] PIC, timer and keyboard support
- [ ] Stack tracing support

### Memory

- [ ] Limine Memory map parsion
- [ ] Limine Memory map parsing
- [ ] Physical memory manager
- [ ] Virtual memory manager
- [ ] Kernel heap (malloc, free)
Expand Down
41 changes: 41 additions & 0 deletions include/core/gdt.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* gdt.h
* As part of the Avery project
* Created by Max Van den Eynde in 2026
* --------------------------------------
* Description: Managers for the Global Descriptor Table
* Copyright (c) 2026 Max Van den Eynde
*/

#ifndef AVERY_GDT_H
#define AVERY_GDT_H
#include "../types.h"

#pragma once

struct GDTEntry {
u16 limit_low;
u16 base_low;
u8 base_middle;
u8 access;
u8 granularity;
u8 base_high;
} __attribute__((packed));

struct GDTPtr {
u16 limit;
uptr base;
} __attribute__((packed));

// Defined in assembly
extern "C" void gdt_flush();

namespace core {
void initGdt();
}

namespace gdt {
void setGate(i32 num, u64 base, u64 limit, u8 access, u8 granularity);
}

#endif //AVERY_GDT_H
42 changes: 42 additions & 0 deletions include/core/idt.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* idt.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_IDT_H
#define AVERY_IDT_H

#pragma once
#include "../types.h"

struct IDTEntry {
u16 offsetLow;
u16 selector;
u8 ist;
u8 flags;
u16 offsetMid;
u32 offsetHigh;
u32 zero;
} __attribute__((packed));

struct IDTPtr {
u16 limit;
uptr base;
} __attribute__((packed));

extern "C" void idt_load();

namespace core {
void initIdt();
}

namespace idt {
void setGate(u8 num, u64 base, u16 sel, u8 flags);
}


#endif //AVERY_IDT_H
48 changes: 48 additions & 0 deletions include/core/irq.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* irq.h
* As part of the Avery project
* Created by Max Van den Eynde in 2026
* --------------------------------------
* Description: Interrupt Requests handler
* Copyright (c) 2026 Max Van den Eynde
*/

#ifndef AVERY_IRQ_H
#define AVERY_IRQ_H

#define IRQ_EXTERN_FUNCTION(N) extern "C" void irq##N()
#include "isr.h"

namespace irq {
IRQ_EXTERN_FUNCTION(0);
IRQ_EXTERN_FUNCTION(1);
IRQ_EXTERN_FUNCTION(2);
IRQ_EXTERN_FUNCTION(3);
IRQ_EXTERN_FUNCTION(4);
IRQ_EXTERN_FUNCTION(5);
IRQ_EXTERN_FUNCTION(6);
IRQ_EXTERN_FUNCTION(7);
IRQ_EXTERN_FUNCTION(8);
IRQ_EXTERN_FUNCTION(9);
IRQ_EXTERN_FUNCTION(10);
IRQ_EXTERN_FUNCTION(11);
IRQ_EXTERN_FUNCTION(12);
IRQ_EXTERN_FUNCTION(13);
IRQ_EXTERN_FUNCTION(14);
IRQ_EXTERN_FUNCTION(15);

using IRQHandler = void (*)(isr::Registers*);

void installHandler(int irq, IRQHandler);
void uninstallHandler(int irq);
void remap();
}

namespace core {
void initIrq();
}

extern "C" void irq_handler(isr::Registers* regs);


#endif //AVERY_IRQ_H
69 changes: 69 additions & 0 deletions include/core/isr.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* isr.h
* As part of the Avery project
* Created by Max Van den Eynde in 2026
* --------------------------------------
* Description: Interrupt Subroutines
* Copyright (c) 2026 Max Van den Eynde
*/

#ifndef AVERY_ISR_H
#define AVERY_ISR_H

#define ISR_EXTERN_FUNCTION(N) extern "C" void isr##N()
#include "../types.h"

namespace isr {
ISR_EXTERN_FUNCTION(0);
ISR_EXTERN_FUNCTION(1);
ISR_EXTERN_FUNCTION(2);
ISR_EXTERN_FUNCTION(3);
ISR_EXTERN_FUNCTION(4);
ISR_EXTERN_FUNCTION(5);
ISR_EXTERN_FUNCTION(6);
ISR_EXTERN_FUNCTION(7);
ISR_EXTERN_FUNCTION(8);
ISR_EXTERN_FUNCTION(9);
ISR_EXTERN_FUNCTION(10);
ISR_EXTERN_FUNCTION(11);
ISR_EXTERN_FUNCTION(12);
ISR_EXTERN_FUNCTION(13);
ISR_EXTERN_FUNCTION(14);
ISR_EXTERN_FUNCTION(15);
ISR_EXTERN_FUNCTION(16);
ISR_EXTERN_FUNCTION(17);
ISR_EXTERN_FUNCTION(18);
ISR_EXTERN_FUNCTION(19);
ISR_EXTERN_FUNCTION(20);
ISR_EXTERN_FUNCTION(21);
ISR_EXTERN_FUNCTION(22);
ISR_EXTERN_FUNCTION(23);
ISR_EXTERN_FUNCTION(24);
ISR_EXTERN_FUNCTION(25);
ISR_EXTERN_FUNCTION(26);
ISR_EXTERN_FUNCTION(27);
ISR_EXTERN_FUNCTION(28);
ISR_EXTERN_FUNCTION(29);
ISR_EXTERN_FUNCTION(30);
ISR_EXTERN_FUNCTION(31);

struct Registers {
u64 r15, r14, r13, r12, r11, r10, r9, r8;
u64 rsi, rdi, rbp, rdx, rcx, rbx, rax;
u64 int_no;
u64 err_code;
u64 rip;
u64 cs;
u64 rflags;
u64 rsp;
u64 ss;
};

void fault_handler(Registers* regs);
};

namespace core {
void initIsrs();
}

#endif //AVERY_ISR_H
17 changes: 17 additions & 0 deletions include/core/systems.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* systems.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_SYSTEMS_H
#define AVERY_SYSTEMS_H

namespace core {
void initSystems();
}

#endif //AVERY_SYSTEMS_H
1 change: 1 addition & 0 deletions include/kernel/console.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ namespace out {
void initFramebufferConsole(const Framebuffer& framebuffer);
void print(string str);
void println(string str);
void printHex(u64 num);
void putChar(char c);
void clear();

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

#ifndef AVERY_MEMORY_H
#define AVERY_MEMORY_H
#include "../types.h"

namespace memory {
void copy(u8* dest, const u8* src, int count);

template <typename T>
void set(T* dest, T val, int count) {
for (int i = 0; i < count; i++) {
dest[i] = val;
}
}
}

#endif //AVERY_MEMORY_H
1 change: 1 addition & 0 deletions include/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ using u16 = unsigned short;
using u32 = unsigned int;
using u64 = unsigned long long;
using usize = decltype(sizeof(0));
using uptr = decltype(sizeof(0));

using i8 = char;
using i16 = short;
Expand Down
12 changes: 6 additions & 6 deletions kernel/core/debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,41 +40,41 @@

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


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


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