Working kernel written on C and userspace-ready #1

Merged
sonya merged 61 commits from dev into main 2026-05-03 09:13:20 +00:00
10 changed files with 12 additions and 14 deletions
Showing only changes of commit 272b9c8998 - Show all commits
-1
View File
@@ -1,6 +1,5 @@
#pragma once #pragma once
#include <Types.h> #include <Types.h>
#include <Arch/IO.h>
#include <Arch/Exceptions.h> #include <Arch/Exceptions.h>
enum { enum {
+4 -2
View File
@@ -2,8 +2,10 @@
#include <Types.h> #include <Types.h>
#include <Arch/Exceptions.h> #include <Arch/Exceptions.h>
static const UInt64 kTimerFrequency = 1000; // 1ms enum {
static const UInt8 kTimerIRQ = 27; kTimerFrequency = 1000, // 1ms
kTimerIRQ = 27,
};
void TimerInitialize(); void TimerInitialize();
void TimerReset(UInt64 interval); void TimerReset(UInt64 interval);
+1 -1
View File
@@ -15,7 +15,7 @@ typedef struct __attribute__((aligned(16))) VMHeapBlockHeader {
struct VMHeapBlockHeader* next; struct VMHeapBlockHeader* next;
struct VMHeapBlockHeader* previous; struct VMHeapBlockHeader* previous;
UInt64 size; UInt64 size;
bool isFree; Boolean isFree;
} VMHeapBlockHeader; } VMHeapBlockHeader;
void HeapInitialize(); void HeapInitialize();
-1
View File
@@ -1,6 +1,5 @@
#pragma once #pragma once
#include <Types.h> #include <Types.h>
#include "../Common/bootinfo.h"
enum { enum {
kVMPageSize = 4096, kVMPageSize = 4096,
+2 -1
View File
@@ -25,11 +25,12 @@ enum {
kVMKernelVMA = 0xFFFFFFFF80000000, kVMKernelVMA = 0xFFFFFFFF80000000,
kHHDMOffset = 0xFFFF888000000000, kHHDMOffset = 0xFFFF888000000000,
kVMFbVirtBase = 0xFFFFFFFFFC000000, kVMFbVirtBase = 0xFFFFFFFFFC000000,
kKernelPhysBase = 0x40100000,
}; };
static inline Address VMKernelVirtToPhys(Address virt) { static inline Address VMKernelVirtToPhys(Address virt) {
return virt - 0xFFFFFFFF80100000 + 0x40100000; // TODO: hardcode is awful return virt - 0xFFFFFFFF80100000 + kKernelPhysBase;
} }
static inline Address VMPhysToHHDM(Address phys) { static inline Address VMPhysToHHDM(Address phys) {
-1
View File
@@ -1,6 +1,5 @@
#include <Arch/DTB.h> #include <Arch/DTB.h>
#include <OS/Panic.h> #include <OS/Panic.h>
#include <OS/Log.h>
#include <Lib/Bytes.h> #include <Lib/Bytes.h>
#include <Lib/Align.h> #include <Lib/Align.h>
#include <Lib/String.h> #include <Lib/String.h>
-2
View File
@@ -1,7 +1,5 @@
#include <Arch/Exceptions.h> #include <Arch/Exceptions.h>
#include <Arch/CPU.h>
#include <Arch/GIC.h> #include <Arch/GIC.h>
#include <IO/Serial.h>
#include <OS/Panic.h> #include <OS/Panic.h>
Address ExceptionsHandler(ExceptionsContext* frame, ExceptionsType type) { Address ExceptionsHandler(ExceptionsContext* frame, ExceptionsType type) {
+1 -1
View File
@@ -10,7 +10,7 @@ static void CombineForward(VMHeapBlockHeader* current) {
if (!current->next || !current->next->isFree) return; if (!current->next || !current->next->isFree) return;
current->size += sizeof(VMHeapBlockHeader) + current->next->size; current->size += sizeof(VMHeapBlockHeader) + current->next->size;
current->next = current->next->next; current->next = current->next->next;
if (current->next) current->next->previous = current; // what the fuck if (current->next) current->next->previous = current;
} }
void HeapInitialize() { void HeapInitialize() {
+3 -3
View File
@@ -54,9 +54,9 @@ void PMMInitialize(VMBootMemoryMap* bootMap) {
Size pagesToReserve = (regionSize + kVMPageSize - 1) / kVMPageSize; Size pagesToReserve = (regionSize + kVMPageSize - 1) / kVMPageSize;
for (Size p = 0; p < pagesToReserve; p++) { for (Size p = 0; p < pagesToReserve; p++) {
Address pageAdress = regionBase + (p * kVMPageSize); Address pageAddress = regionBase + (p * kVMPageSize);
if (pageAdress >= sPMMRamBase && pageAdress < (sPMMRamBase + bootMap->totalRAM.size)) { if (pageAddress >= sPMMRamBase && pageAddress < (sPMMRamBase + bootMap->totalRAM.size)) {
BitmapSet(sPMMBitmap, pageAdress); BitmapSet(sPMMBitmap, pageAddress);
} }
} }
} }
+1 -1
View File
@@ -159,7 +159,7 @@ void VMMInitialize(VMBootMemoryMap* bootMap, Bootinfo* info) {
Size kernelSize = ((Address)_kernelEnd - (Address)_kernelStart) + pmmBitmapSize; Size kernelSize = ((Address)_kernelEnd - (Address)_kernelStart) + pmmBitmapSize;
kernelSize = (kernelSize + kVMPageSize - 1) & ~(kVMPageSize - 1); kernelSize = (kernelSize + kVMPageSize - 1) & ~(kVMPageSize - 1);
Address kernelPhysStart = 0x40100000; // TODO: hardcode is awful Address kernelPhysStart = kKernelPhysBase;
for (Address offset = 0; offset < kernelSize; offset += kVMPageSize) { for (Address offset = 0; offset < kernelSize; offset += kVMPageSize) {
Address phys = kernelPhysStart + offset; Address phys = kernelPhysStart + offset;