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
58 changes: 58 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Generated from CLion C/C++ Code Style settings
---
Language: Cpp
BasedOnStyle: LLVM
AccessModifierOffset: -4
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignOperands: true
AlignTrailingComments: false
AlwaysBreakTemplateDeclarations: Yes
BraceWrapping:
AfterCaseLabel: false
AfterClass: false
AfterControlStatement: false
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterStruct: false
AfterUnion: false
AfterExternBlock: false
BeforeCatch: false
BeforeElse: false
BeforeLambdaBody: false
BeforeWhile: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakBeforeBraces: Custom
BreakConstructorInitializers: AfterColon
BreakConstructorInitializersBeforeComma: false
ColumnLimit: 120
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ContinuationIndentWidth: 8
IncludeCategories:
- Regex: '^<.*'
Priority: 1
- Regex: '^".*'
Priority: 2
- Regex: '.*'
Priority: 3
IncludeIsMainRegex: '([-_](test|unittest))?$'
IndentCaseLabels: true
IndentWidth: 4
InsertNewlineAtEOF: true
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 2
NamespaceIndentation: All
SpaceAfterCStyleCast: true
SpaceAfterTemplateKeyword: false
SpaceBeforeRangeBasedForLoopColon: false
SpaceInEmptyParentheses: false
SpacesInAngles: false
SpacesInConditionalStatement: false
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
TabWidth: 4
...
15 changes: 7 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@

- [x] Physical memory manager (free list or bitmap)
- [x] Page table setup (paging enabled)
- [ ] Virtual memory mapping API (`vmem_map()`, etc.)
- [ ] Kernel heap (virtual, malloc/free)
- [x] Virtual memory mapping API (`vmem_map()`, etc.)
- [x] Kernel heap (virtual, malloc/free)
- [ ] Per-process page tables
- [ ] User-mode memory protection

Expand All @@ -42,7 +42,7 @@

---

## 🔐 Ring 3 Support (Userspace) (unmaintained)
## 🔐 Ring 3 Support (Userspace) (uhhh)

- [ ] User-mode process flag
- [ ] IRETQ from syscall/interrupt
Expand All @@ -56,7 +56,7 @@
## 🧩 Module System

- [x] Multiboot2 module loading
- [ ] Basic kernel extensions (`vmod`)
- [ ] Basic kernel extensions
- [ ] Signature/token validation
- [ ] Hot module unloading (optional)
- [ ] Module registration system
Expand All @@ -76,16 +76,15 @@

## 🧠 Init System

- [x] Boot SKIS (SecureKernelIntegritySubsystem)
- [ ] Create `init` process from `vmod` or ELF
- [x] Init spawns userland shell or TUI
- [x] Init spawns shell or TUI

---

## 💬 IPC / Syscalls

- [x] Syscall dispatch system
- [ ] Basic message passing (pipe, queue, or buffer)
- [x] Basic message passing (pipe, queue, or buffer)
- [ ] Shared memory region
- [ ] Signals or async delivery
- [ ] Named channels or sockets
Expand Down Expand Up @@ -115,7 +114,7 @@
## 🔧 Debug & Developer Features

- [x] Print kernel logs to VGA
- [ ] Serial logging
- [x] Serial logging
- [x] `dmesg`-style kernel log buffer
- [ ] Stack backtrace / panic debug dump
- [ ] Memory usage counters
Expand Down
4 changes: 1 addition & 3 deletions arch/x86_64/interrupts/Interrupts.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ void InterruptHandler(Registers* regs) {
}

// Handle CPU exceptions (0-31)
PrintKernelError("\n!! CPU EXCEPTION !!\n");

switch (regs->interrupt_number) {
case 6: // Invalid Opcode
Expand All @@ -53,8 +52,7 @@ void InterruptHandler(Registers* regs) {
PrintKernelHex(regs->rip);
PrintKernelError("\n Error Code: ");
PrintKernelHex(regs->error_code);
PrintKernelError(" (often segment related)\n");
PANIC_CODE("General Protection Fault", regs->error_code);
PANIC_CODE(" General Protection Fault\n", regs->error_code);
break;

case 14: // Page Fault
Expand Down
35 changes: 35 additions & 0 deletions drivers/Serial.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include "Serial.h"
#include "Io.h"

#define COM1 0x3f8 // COM1

void SerialInit(void) {
outb(COM1 + 1, 0x00); // Disable all interrupts
outb(COM1 + 3, 0x80); // Enable DLAB (set baud rate divisor)
outb(COM1 + 0, 0x03); // Set divisor to 3 (lo byte) -> 38400 baud
outb(COM1 + 1, 0x00); // (hi byte)
outb(COM1 + 3, 0x03); // 8 bits, no parity, one stop bit
// FIFO: enable (bit0), clear RX (bit1), clear TX (bit2), trigger=14 bytes (bits 6-7=11)
outb(COM1 + 2, 0xC7);
// Modem Control: DTR | RTS | OUT2 (keeps IRQ line enabled at PIC; actual serial IRQs still disabled since IER=0)
outb(COM1 + 4, 0x0B);
}
int is_transmit_empty(void) {
return inb(COM1 + 5) & 0x20;
}

void SerialWriteChar(const char a) {
// If newline, emit CR first, then LF
if (a == '\n') {
while ((inb(COM1 + 5) & 0x20) == 0) {}
outb(COM1, '\r');
}
while ((inb(COM1 + 5) & 0x20) == 0) {}
outb(COM1, a);
}

void SerialWrite(const char* str) {
for (int i = 0; str[i] != '\0'; i++) {
SerialWriteChar(str[i]);
}
}
8 changes: 8 additions & 0 deletions drivers/Serial.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#ifndef VOIDFRAME_SERIAL_H
#define VOIDFRAME_SERIAL_H

void SerialInit(void);
void SerialWriteChar(char c);
void SerialWrite(const char* str);

#endif // VOIDFRAME_SERIAL_H
1 change: 0 additions & 1 deletion grub.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ set timeout=0
set default=0

menuentry "VoidFrame" {
set gfxpayload=keep
multiboot2 /boot/voidframe.krnl
boot
}
19 changes: 12 additions & 7 deletions kernel/core/Kernel.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "Console.h"
#include "Gdt.h"
#include "Idt.h"
#include "Io.h"
#include "KernelHeap.h"
#include "Keyboard.h"
#include "MemOps.h"
Expand All @@ -11,7 +12,9 @@
#include "Panic.h"
#include "Pic.h"
#include "Process.h"
#include "Serial.h"
#include "Shell.h"
#include "Spinlock.h"
#include "Syscall.h"
#include "VMem.h"
#include "stdbool.h"
Expand Down Expand Up @@ -203,6 +206,10 @@ static InitResultT CoreInit(void) {
ProcessInit(); // void function - assume success
PrintKernelSuccess("[SYSTEM] Process management initialized\n");

PrintKernel("[INFO] Initializing serial driver management...\n");
SerialInit();
PrintKernelSuccess("[SYSTEM] Serial driver initialized\n");

// Setup memory protection LAST - after all systems are ready
SetupMemoryProtection();
return INIT_SUCCESS;
Expand All @@ -217,6 +224,7 @@ void KernelMain(const uint32_t magic, const uint32_t info) {
}

console.buffer = (volatile uint16_t*)VGA_BUFFER_ADDR;

ClearScreen();
PrintKernelSuccess("[SYSTEM] VoidFrame Kernel - Version 0.0.1-beta loaded\n");
PrintKernel("Magic: ");
Expand All @@ -228,7 +236,7 @@ void KernelMain(const uint32_t magic, const uint32_t info) {

// Initialize physical memory manager first
MemoryInit(g_multiboot_info_addr);

// Create new PML4 with memory validation
void* pml4_phys = AllocPage();
if (!pml4_phys) PANIC("Failed to allocate PML4");
Expand Down Expand Up @@ -267,15 +275,12 @@ void KernelMain(const uint32_t magic, const uint32_t info) {
PrintKernelSuccess("[SYSTEM] Bootstrap: Mapping kernel stack with guard pages...\n");
uint64_t stack_phys_start = (uint64_t)kernel_stack & ~0xFFF;
uint64_t stack_phys_end = ((uint64_t)kernel_stack + KERNEL_STACK_SIZE + 0xFFF) & ~0xFFF;

// Create guard page BEFORE stack (unmapped)
PrintKernel("[GUARD] Stack guard page before stack (unmapped)\n");


// Map actual stack
for (uint64_t paddr = stack_phys_start; paddr < stack_phys_end; paddr += PAGE_SIZE) {
BootstrapMapPage(pml4_addr, paddr + KERNEL_VIRTUAL_OFFSET, paddr, PAGE_WRITABLE);
}

// Create guard page AFTER stack (unmapped)
PrintKernel("[GUARD] Stack guard page after stack (unmapped)\n");

Expand Down Expand Up @@ -323,7 +328,7 @@ void KernelMainHigherHalf(void) {

PrintKernelSuccess("[SYSTEM] Kernel initialization complete\n");
PrintKernelSuccess("[SYSTEM] Initializing interrupts...\n\n");

asm volatile("sti");
while (1) {
if (ShouldSchedule()) {
Expand Down
7 changes: 5 additions & 2 deletions kernel/core/Panic.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "Panic.h"
#include "Kernel.h"
#include "Io.h"

#include "Serial.h"
#include "stdint.h"

#define likely(x) __builtin_expect(!!(x), 1)
Expand Down Expand Up @@ -195,6 +195,9 @@ void KernelPanicHandler(const char* message, uint64_t error_code, PanicContext*

PanicPrintCentered(23, "SYSTEM HALTED", COLOR_BRIGHT_WHITE_ON_RED);

SerialWrite("\n[FATAL] - [KERNEL PANIC] -- ");
if (message) SerialWrite(message);
SerialWrite("\n");
// Standard practice is to halt indefinitely, allowing the user to read the screen.
// Forcing a reboot might lose valuable diagnostic info.
while (1) {
Expand Down
15 changes: 14 additions & 1 deletion kernel/etc/Console.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#include "Console.h"

#include "Serial.h"
#include "Spinlock.h"
#include "stdint.h"
#include "stdbool.h"
#include "stdint.h"

static volatile int lock = 0;
// Inline functions for better performance
Expand Down Expand Up @@ -67,6 +69,16 @@ static void ConsolePutchar(char c) {
console.line++;
console.column = 0;
}
} else if (c == '\b') {
if (console.column > 0) {
console.column--;
ConsolePutcharAt(' ' , console.column, console.line, console.color);
} else if (console.line > 0) {
console.line--;
console.column = VGA_WIDTH - 1;
ConsolePutcharAt(' ', console.column, console.line, console.color);
}
// Do not scroll on backspace
} else if (c >= 32) { // Printable characters only
ConsolePutcharAt(c, console.column, console.line, console.color);
console.column++;
Expand Down Expand Up @@ -96,6 +108,7 @@ void PrintKernel(const char* str) {

console.color = original_color;
SpinUnlock(&lock);
SerialWrite(str);
}

// Colored output variants
Expand Down
5 changes: 3 additions & 2 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,17 @@ c_sources = [
src_root + '/kernel/process/Process.c',
src_root + '/kernel/process/UserMode.c',
src_root + '/kernel/etc/Shell.c',
src_root + '/kernel/etc/Console.c',
arch_root + '/idt/Idt.c',
arch_root + '/gdt/Gdt.c',
arch_root + '/syscall/Syscall.c',
arch_root + '/interrupts/Interrupts.c',
src_root + '/drivers/Pic.c',
src_root + '/drivers/Serial.c',
src_root + '/drivers/Keyboard.c',
arch_root + '/cpu/Cpu.c',
src_root + '/kernel/atomic/Atomics.c',
src_root + '/kernel/ipc/Ipc.c',
src_root + '/kernel/etc/Console.c'
src_root + '/kernel/ipc/Ipc.c'
]

# Build include flags
Expand Down