wip: IPC and Runtime

This commit is contained in:
karina
2026-05-03 21:57:20 +04:00
parent 5f343c991b
commit 39b2af7626
25 changed files with 371 additions and 66 deletions
+14 -4
View File
@@ -2,6 +2,7 @@
// Copyright (c) 2026 0xKSor
#pragma once
#include "Arch/Exceptions.h"
#include <Types.h>
static inline void CPUYield() {
@@ -63,7 +64,7 @@ static inline void CPUEnableMMU(Address l0PhysicalAddress) {
// MAIR_EL1 (Memory Attribute Indirection Register)
// kPTENormalMem is index 0 and kPTEDeviceMem is index 1
// 0xFF = Normal, 0x00 = Device
UInt64 mair = (0xFFULL << 0) | (0x00ULL << 8);
UInt64 mair = (0xFFULL << 0) | (0x00ULL << 8);
// TCR_EL1 (Translation Control Register)
// configures the mmu for 4kb pages and 48bit virtual addresses
@@ -82,11 +83,11 @@ static inline void CPUEnableMMU(Address l0PhysicalAddress) {
"msr tcr_el1, %1\n"
"msr ttbr0_el1, %2\n" // set userspace root
"msr ttbr1_el1, %2\n" // set kernelspace root
"tlbi vmalle1is\n"
"tlbi vmalle1is\n"
"isb\n" // Instruction Synchronization Barrier
:: "r"(mair), "r"(tcr), "r"(l0PhysicalAddress) : "memory"
);
// turn on the MMU in SCTLR_EL1 (System Control Register)
// Bit 0 = M (MMU Enable), Bit 2 = C (Data Cache Enable), Bit 12 = I (Instruction Cache Enable)
UInt64 sctlr;
@@ -111,4 +112,13 @@ static inline void CPUSwitchAddressSpace(Address l0Physical) {
);
}
#define CPUException(number) __asm__ volatile ("svc %0" :: "i" (number) : "memory")
static inline void CPUCopyIPCRegisters(ExceptionsContext* source, ExceptionsContext* destination) {
destination->x2 = source->x2;
destination->x3 = source->x3;
destination->x4 = source->x4;
destination->x5 = source->x5;
destination->x6 = source->x6;
destination->x7 = source->x7;
}
#define CPUException(number) __asm__ volatile ("svc %0" :: "i" (number) : "memory")
+1 -1
View File
@@ -14,4 +14,4 @@ static inline UInt32 IOAddressRead32(Address address) {
UInt32 value = *(volatile UInt32*)address;
__asm__ volatile ("dsb ld" ::: "memory"); // wait till my read is finished physically
return value;
}
}
+7
View File
@@ -0,0 +1,7 @@
#pragma once
#include "Arch/Exceptions.h"
#include <Types.h>
#include <OS/Scheduler.h>
UInt64 IPCSend(OSTask* sender, UInt64 handleID, UInt64 data);
void IPCReceive(ExceptionsContext* receiverFrame);
+2 -1
View File
@@ -1,5 +1,6 @@
#pragma once
#include <Types.h>
#include "../Common/bootinfo.h"
#include <OS/Scheduler.h>
void ModuleLoad(BootModule* module);
OSTask* ModuleLoad(BootModule* module);
+28 -6
View File
@@ -4,12 +4,31 @@
#pragma once
#include <Types.h>
typedef enum {
kOSHandleTypeNone = 0,
kOSHandleTypeTask
} OSHandleType;
typedef struct {
OSHandleType type;
Pointer object;
} OSHandle;
enum {
kOSSchedulerTaskStackSize = 16 * 1024,
kOSSchedulerExceptionNumber = 0xF0F0,
kOSMaxHandlesPerProcess = 256,
};
typedef enum OSTaskState {
OSTaskStateDead,
OSTaskStateRunning,
OSTaskStateReady,
OSTaskStateBlocked,
OSTaskStateSleeping,
OSTaskStateBlockedReceive,
OSTaskStateBlockedSend,
} OSTaskState;
typedef struct OSProcess {
@@ -20,11 +39,12 @@ typedef struct OSProcess {
Address heapCurrent;
struct OSProcess* parent;
ASCII name[32];
OSHandle handles[kOSMaxHandlesPerProcess];
} OSProcess;
typedef struct OSTask {
Address stackPointer;
struct OSTask* next;
UInt32 id;
UInt32 sleepTicks;
OSTaskState state;
@@ -32,12 +52,10 @@ typedef struct OSTask {
Pointer kernelStackBase;
OSProcess* process;
Int32 waitingForProcessId;
} OSTask;
enum {
kOSSchedulerTaskStackSize = 16 * 1024,
kOSSchedulerExceptionNumber = 0xF0F0
};
struct OSTask* next;
struct OSTask* senderWaiting;
} OSTask;
extern UInt32 gOSSchedulerNextProcessID;
@@ -46,3 +64,7 @@ OSTask* SchedulerSpawn(void(*entryPoint)(), OSProcess* owner, Boolean isUser, Ad
Address SchedulerNext(Address stackPointer);
void SchedulerYield(UInt64 ticks);
UInt64 SchedulerGetNextProcessID();
void SchedulerBlockCurrentTask(UInt32 newState);
OSTask* SchedulerGetCurrentTask();
Int32 SchedulerProcessAllocateHandle(OSProcess* process, OSHandleType type, Pointer object);
Pointer SchedulerProcessGetHandle(OSProcess* process, UInt32 handleId, OSHandleType expectedType);
+10
View File
@@ -0,0 +1,10 @@
#pragma once
#include <Types.h>
#include <Arch/Exceptions.h>
enum Syscalls {
kSyscallSend,
kSyscallReceive,
};
Address SyscallDispatch(ExceptionsContext* frame);