feat: scheduling, usermode, shell

This commit is contained in:
2026-02-17 19:17:01 +01:00
parent 20fa8a9be2
commit 605fbcbe42
46 changed files with 2622 additions and 98 deletions
+59
View File
@@ -0,0 +1,59 @@
/*
* Scheduler.hpp
* Preemptive process scheduler with user-mode support
* Copyright (c) 2025 Daniel Hammer
*/
#pragma once
#include <cstdint>
namespace Sched {
static constexpr int MaxProcesses = 16;
static constexpr uint64_t StackPages = 4; // 16 KiB kernel stack per process
static constexpr uint64_t StackSize = StackPages * 0x1000;
static constexpr uint64_t UserStackPages = 4; // 16 KiB user stack
static constexpr uint64_t UserStackSize = UserStackPages * 0x1000;
static constexpr uint64_t UserStackTop = 0x7FFFFFF000ULL; // User stack top VA
static constexpr uint64_t UserHeapBase = 0x40000000ULL; // User heap start VA
static constexpr uint64_t ExitStubAddr = 0x3FF000ULL; // User-space exit stub page
static constexpr uint64_t TimeSliceMs = 10; // 10 ms time slice
enum class ProcessState {
Free,
Ready,
Running,
Terminated
};
struct Process {
int pid;
ProcessState state;
const char* name;
uint64_t savedRsp;
uint64_t stackBase; // Bottom of allocated kernel stack (lowest address)
uint64_t entryPoint;
uint64_t sliceRemaining; // Ticks left in current time slice
uint64_t pml4Phys; // Physical address of per-process PML4
uint64_t kernelStackTop; // Top of kernel stack (for TSS RSP0 / SYSCALL)
uint64_t userStackTop; // User-space stack top
uint64_t heapNext; // Simple bump allocator for user heap
};
void Initialize();
void Spawn(const char* vfsPath);
void Schedule();
// Called from the APIC timer handler on every tick.
void Tick();
// Get the PID of the currently running process (-1 if idle)
int GetCurrentPid();
// Get a pointer to the currently running process (nullptr if idle)
Process* GetCurrentProcessPtr();
// Called by terminated processes to mark themselves done
void ExitProcess();
}