Files
2026-05-03 21:57:20 +04:00

71 lines
1.7 KiB
C

// SPDX-License-Identifier: GPL-3.0-or-later
// Copyright (c) 2026 0xKSor
#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 {
UInt64 id;
OSTaskState state;
Address* l0Table;
Address heapStart;
Address heapCurrent;
struct OSProcess* parent;
ASCII name[32];
OSHandle handles[kOSMaxHandlesPerProcess];
} OSProcess;
typedef struct OSTask {
Address stackPointer;
UInt32 id;
UInt32 sleepTicks;
OSTaskState state;
Address kernelStackTop;
Pointer kernelStackBase;
OSProcess* process;
Int32 waitingForProcessId;
struct OSTask* next;
struct OSTask* senderWaiting;
} OSTask;
extern UInt32 gOSSchedulerNextProcessID;
void SchedulerInitialize();
OSTask* SchedulerSpawn(void(*entryPoint)(), OSProcess* owner, Boolean isUser, Address fixedUserStackAddress);
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);