feat(scheduler): working scheduler

This commit is contained in:
karina
2026-04-29 17:00:11 +04:00
parent 3f51d93a4e
commit e06abbcb23
12 changed files with 220 additions and 17 deletions
+13
View File
@@ -73,3 +73,16 @@ static inline void CPUEnableMMU(Address l0PhysicalAddress) {
: "=r"(sctlr) : "r"(sctlr_flags) : "memory"
);
}
static inline void CPUSwitchAddressSpace(Address l0Physical) {
__asm__ volatile(
"dsb ishst\n" // wait till all previous writes are finished physically
"msr ttbr0_el1, %0\n" // Update TTBR0_EL1 (userspace)
"tlbi vmalle1is\n" // Reset TLB cache
"dsb ish\n" // wait for tlb cache to reset
"isb\n" // Clear instruction pipeline
:: "r" (l0Physical) : "memory"
);
}
#define CPUException(number) __asm__ volatile ("svc %0" :: "i" (number) : "memory")
+2
View File
@@ -36,6 +36,8 @@ typedef struct ExceptionsContext {
UInt64 elr_el1; // pc
UInt64 spsr_el1; // cpu status
UInt64 esr_el1; // error reason
UInt64 sp_el0; // user's stack
UInt64 padding; // align to 16 bytes
} ExceptionsContext;
typedef enum ExceptionsType {
+1 -1
View File
@@ -25,4 +25,4 @@ enum {
void GICInitialize(Pointer gicdVirtBase, Pointer giccVirtBase);
void GICEnableInterrupt(UInt32 irqID);
void GICDispatch(ExceptionsType type);
Address GICDispatch(ExceptionsContext* frame, ExceptionsType type);
+4 -1
View File
@@ -1,8 +1,11 @@
#pragma once
#include <Types.h>
#include <Arch/Exceptions.h>
static const UInt64 kTimerFrequency = 1000; // 1ms
static const UInt8 kTimerIRQ = 27;
void TimerInitialize();
void TimerReset(UInt64 interval);
void TimerReset(UInt64 interval);
Address TimerHandler(ExceptionsContext* frame);
UInt64 TimerGetCounter();
+42
View File
@@ -0,0 +1,42 @@
#pragma once
#include <Types.h>
typedef enum OSTaskState {
OSTaskStateDead,
OSTaskStateRunning,
OSTaskStateReady,
OSTaskStateBlocked,
OSTaskStateSleeping,
} OSTaskState;
typedef struct OSProcess {
UInt64 id;
OSTaskState state;
Address* l0Table;
Address heapStart;
Address heapCurrent;
struct OSProcess* parent;
ASCII name[32];
} OSProcess;
typedef struct OSTask {
Address stackPointer;
struct OSTask* next;
UInt32 id;
UInt32 sleepTicks;
OSTaskState state;
Address kernelStackTop;
Pointer kernelStackBase;
OSProcess* process;
Int32 waitingForProcessId;
} OSTask;
enum {
kOSSchedulerTaskStackSize = 16 * 1024,
kOSSchedulerExceptionNumber = 0xF0F0
};
void SchedulerInitialize();
OSTask* SchedulerSpawn(void(*entryPoint)(), OSProcess* owner, Boolean isUser, Address fixedUserStackAddress);
Address SchedulerNext(Address stackPointer);
void SchedulerYield(UInt64 ticks);