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
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ target_compile_options(avery_objects PRIVATE
$<$<COMPILE_LANGUAGE:CXX>:-Wconversion>
$<$<COMPILE_LANGUAGE:CXX>:-Wshadow>
$<$<COMPILE_LANGUAGE:CXX>:-Werror>
$<$<COMPILE_LANGUAGE:CXX>:-ffile-prefix-map=${CMAKE_SOURCE_DIR}/=>
$<$<COMPILE_LANGUAGE:CXX>:-fno-omit-frame-pointer>
)

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

### Memory
Expand All @@ -30,6 +30,15 @@ practices while remaining approachable to contributors and learners alike.
- [ ] Physical memory manager
- [ ] Virtual memory manager
- [ ] Kernel heap (malloc, free)
- [ ] Move to Limine 6 (APIC or x2APIC)

### Internal Driver Framework

- [ ] Device objects
- [ ] Driver registration
- [ ] Driver lifecycle
- [ ] MMIO port I/O helpers
- [ ] Block device abstraction

### Hardware discovery

Expand All @@ -38,12 +47,12 @@ practices while remaining approachable to contributors and learners alike.

### Storage

- [ ] Driver system
- [ ] Filesystem VFS layer
- [ ] FAT32 support
- [ ] ext2 support
- [ ] Read from filesystem
- [ ] Write to filesystem
- [ ] ATA driver
- [ ] Block device layer
- [ ] VFS
- [ ] FAT32
- [ ] ext2
- [ ] Read & Write files

### Processes

Expand All @@ -55,19 +64,95 @@ practices while remaining approachable to contributors and learners alike.

## Roadmap (for Beta)

### Toolchain
### Beta 1

- [ ] Avery Kernel SDK
- [ ] Driver build system
- [ ] Driver templates
- [ ] Driver documentation
- [ ] Loadable modules
- [ ] Driver manifest format
- [ ] Sample PCI driver
- [ ] Sample block driver
- [ ] Sample character driver
- [ ] Stable kernel driver API

### Beta 2

- [ ] ACPI
- [ ] MADT parsing
- [ ] x2APIC
- [ ] APIC timer
- [ ] IPIs

### Beta 3

- [ ] xHCI
- [ ] USB enumeration
- [ ] USB keyboard
- [ ] USB mouse
- [ ] USB mass storage
- [ ] USB hubs

### Beta 4

- [ ] Ethernet driver (E1000 first)
- [ ] Ethernet layer
- [ ] ARP
- [ ] IPv4
- [ ] ICMP
- [ ] UCP
- [ ] TCP
- [ ] DNS
- [ ] DHCP

### Beta 5

- [ ] USB Bluetooth adapter support
- [ ] HCI layer
- [ ] L2CAP
- [ ] HID over Bluetooth
- [ ] Bluetooth keyboard and mouse

### Beta 6

- [ ] Intel HDA
- [ ] Audio Mixer
- [ ] PCM playback
- [ ] Basic Sound API

### Beta 7

- [ ] Better graphics abstraction
- [ ] Font renderer
- [ ] Mouse cursor
- [ ] Window manager
- [ ] Simple compositor
- [ ] Terminal app
- [ ] File manager

- [ ] Migrate a C compiler
- [ ] Create a libc port
- [ ] Build C examples
### Beta 8

### Hardware
- [ ] Port binutils
- [ ] Port Clang
- [ ] libc
- [ ] C examples
- [ ] Build programs for Avery

- [ ] USB support
- [ ] Ethernet / networking
### Beta 9

### Graphics
- [ ] Self-hosting

- [ ] Graphics abstraction
- [ ] Font renderer
- [ ] Simple compositor
### Beta 10

- [ ] Graphics API

### Beta 11

- [ ] Users/groups
- [ ] Permissions
- [ ] Process isolation
- [ ] ASLR
- [ ] NX
- [ ] Sandboxing
- [ ] Driver permissions/signing
39 changes: 39 additions & 0 deletions include/core/apic.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* apic.h
* As part of the Avery project
* Created by Max Van den Eynde in 2026
* --------------------------------------
* Description: Advanced PIC implementation
* Copyright (c) 2026 Max Van den Eynde
*/

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

namespace lapic {
inline u64 rdmsr(u32 msr) {
u32 lo, hi;
asm volatile("rdmsr" : "=a"(lo), "=d"(hi) : "c"(msr));
return (static_cast<u64>(hi) << 32) | lo;
}

inline void wrmsr(u32 msr, u64 value) {
u32 lo = value & 0xffffffff;
u32 hi = value >> 32;

asm volatile("wrmsr" : : "c"(msr), "a"(lo), "d"(hi));
}

void initBase();
void write(u32 reg, u32 value);
u32 read(u32 reg);

constexpr u32 LAPIC_SRV = 0xF0;
void enable();

constexpr u32 LAPIC_LVT_LINT0 = 0x350;
void enableLegacyMode();
}

#endif //AVERY_APIC_H
28 changes: 28 additions & 0 deletions include/drivers/driver.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* driver.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_DRIVER_H
#define AVERY_DRIVER_H
#include "../types.h"

using DriverInitFunction = void (*)();

enum class DriverType {
Generic
};

class Driver {
public:
string name;
DriverType type;

DriverInitFunction init;
};

#endif //AVERY_DRIVER_H
25 changes: 25 additions & 0 deletions include/drivers/keyboard.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* keyboard.h
* As part of the Avery project
* Created by Max Van den Eynde in 2026
* --------------------------------------
* Description: Basic PS/2 driver support
* Copyright (c) 2026 Max Van den Eynde
*/

#ifndef AVERY_KEYBOARD_H
#define AVERY_KEYBOARD_H
#include "../core/isr.h"

namespace keyboard {
extern const unsigned char es[128];
extern const unsigned char esShift[128];
extern const unsigned char* activeLayout;

bool hasChar();
char getChar();
void handler(isr::Registers* regs);
void init();
}

#endif //AVERY_KEYBOARD_H
25 changes: 25 additions & 0 deletions include/drivers/pit.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* pit.h
* As part of the Avery project
* Created by Max Van den Eynde in 2026
* --------------------------------------
* Description: Programmable Interval Timer setup
* Copyright (c) 2026 Max Van den Eynde
*/

#ifndef AVERY_PIT_H
#define AVERY_PIT_H
#include "../core/isr.h"

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

namespace time {
u64 getUptime();
void wait(u64 ticksMs);
}

namespace core {
void initPit();
}

#endif //AVERY_PIT_H
5 changes: 5 additions & 0 deletions include/graphics/framebuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,11 @@ class FramebufferConsole {
void writeLn(string str);
void newline();
void backspace();
void backspace(char c);

void setColor(Color foreground, Color background);
void setCursor(u64 x, u64 y);
void updateCursor();

private:
void drawCursor();
Expand All @@ -68,6 +70,9 @@ class FramebufferConsole {

u64 cursorX = 0;
u64 cursorY = 0;
bool cursorVisible = true;
bool cursorDrawn = false;
u64 cursorBlinkTimestamp = 0;

u64 rows;
};
Expand Down
5 changes: 5 additions & 0 deletions include/kernel/console.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,10 @@ namespace out {
void setColor(Color fg, Color bg);
};

namespace in {
string getLine(string prompt = nullptr);
char getChar();
}


#endif //AVERY_CONSOLE_H
20 changes: 20 additions & 0 deletions include/kernel/debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,26 @@ __func__ \
} \
} while (0)

#define CHECK(expr) \
do \
{ \
if (!(expr)) { \
debug::warn( \
"Condition not met" #expr "in" __FILE__ \
); \
} \
} while (0)

#define EXPECT(expr) \
do \
{ \
if (!(expr)) { \
debug::error( \
"Condition not met" #expr "in" __FILE__ \
); \
} \
} while (0)

#ifndef NDEBUG
#define ASSERT(expr) VERIFY(expr)
#else
Expand Down
6 changes: 6 additions & 0 deletions include/kernel/memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#define AVERY_MEMORY_H
#include "../types.h"

struct limine_hhdm_request;

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

Expand All @@ -20,6 +22,10 @@ namespace memory {
dest[i] = val;
}
}

void setHHDM(volatile limine_hhdm_request& request);
u64 getHHDMOffset();
}


#endif //AVERY_MEMORY_H
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
36 changes: 36 additions & 0 deletions kernel/core/interrupts/pic/lapic.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* lapic.cpp
* As part of the Avery project
* Created by Max Van den Eynde in 2026
* --------------------------------------
* Description: Local Advanced Programmable Interrupt Controler interfaces
* Copyright (c) 2026 Max Van den Eynde
*/

#include "core/apic.h"
#include "kernel/memory.h"

static volatile u32* LapicBase = nullptr;

void lapic::initBase() {
u64 apicBaseMsr = rdmsr(0x1B);
uptr phys = apicBaseMsr & 0xFFFFF000;
u64 hhdm = memory::getHHDMOffset();
LapicBase = reinterpret_cast<volatile u32*>(hhdm + phys);
}

void lapic::write(u32 reg, u32 value) {
*reinterpret_cast<volatile u32*>(reinterpret_cast<uptr>(LapicBase) + reg) = value;
}

u32 lapic::read(u32 reg) {
return *reinterpret_cast<volatile u32*>(reinterpret_cast<uptr>(LapicBase) + reg);
}

void lapic::enable() {
write(LAPIC_SRV, read(LAPIC_SRV) | 0x100 | 0xFF);
}

void lapic::enableLegacyMode() {
write(LAPIC_LVT_LINT0, 0x700);
}
Loading
Loading