Files
tp/include/os/OS.h
T

200 lines
4.6 KiB
C
Raw Normal View History

2020-12-26 11:31:49 -05:00
// at some point: we should split this up into various OS/... headers. but not yet, since barely any
// files include this atm.
2020-12-06 06:40:34 +01:00
2020-12-07 14:05:20 -06:00
#ifndef __OS_H__
#define __OS_H__
2020-12-06 06:40:34 +01:00
#include "dolphin/types.h"
2020-12-07 14:05:20 -06:00
/* TODO: more structs, and get rid of the ones that are faked! */
2020-12-06 06:40:34 +01:00
2021-01-03 11:29:50 +01:00
#define OS_MESSAGE_NON_BLOCKING 0
#define OS_MESSAGE_BLOCKING 1
struct OSThread;
2020-12-06 06:40:34 +01:00
struct OSMutex {
2020-12-07 14:05:20 -06:00
u8 unk[24];
};
struct OSMutexLink {
2020-12-26 11:31:49 -05:00
struct OSMutex* prev;
struct OSMutex* next;
2020-12-07 14:05:20 -06:00
};
struct OSMutexQueue {
2020-12-26 11:31:49 -05:00
struct OSMutex* prev;
struct OSMutex* next;
2020-12-07 14:05:20 -06:00
};
struct OSContext {
u32 gpr[32];
u32 cr;
u32 lr;
u32 ctr;
u32 xer;
double fpr[32];
u32 padding_1;
u32 fpscr;
u32 srr0;
u32 srr1;
u16 mode;
u16 state;
u32 gqr[8];
u32 padding_2;
double ps[32];
2020-12-07 14:05:20 -06:00
};
2020-12-26 11:31:49 -05:00
typedef void (*OSSwitchThreadCallback)(OSThread* from, OSThread* to);
2020-12-07 14:05:20 -06:00
struct OSThreadLink {
2020-12-26 11:31:49 -05:00
struct OSThread* prev;
struct OSThread* next;
2020-12-07 14:05:20 -06:00
};
struct OSThreadQueue {
2020-12-26 11:31:49 -05:00
struct OSThread* head;
struct OSThread* tail;
2020-12-07 14:05:20 -06:00
};
struct OSCond {
struct OSThreadQueue queue;
2020-12-06 06:40:34 +01:00
};
typedef void* OSMessage;
2020-12-07 14:05:20 -06:00
struct OSMessageQueue {
struct OSThreadQueue sending_queue;
struct OSThreadQueue receiving_queue;
2020-12-26 11:31:49 -05:00
void** message_array;
2020-12-07 14:05:20 -06:00
s32 num_messages;
s32 first_index;
s32 num_used;
};
typedef u32 OSTick;
typedef s64 OSTime;
struct OSCalendarTime {
s32 seconds;
s32 minutes;
s32 hours;
s32 day_of_month;
s32 month;
s32 year;
s32 week_day;
s32 year_day;
s32 milliseconds;
s32 microseconds;
};
typedef s32 OSHeapHandle;
typedef enum OSSoundMode {
2020-12-26 11:31:49 -05:00
SOUND_MODE_MONO = 0,
SOUND_MODE_STEREO = 1,
2020-12-07 14:05:20 -06:00
} OSSoundMode;
typedef u16 OSThreadState;
#define OS_THREAD_STATE_UNINITIALIZED 0
#define OS_THREAD_STATE_READY 1
#define OS_THREAD_STATE_RUNNING 2
#define OS_THREAD_STATE_WAITING 4
#define OS_THREAD_STATE_DEAD 8
struct OSThread {
OSContext context;
OSThreadState state;
u16 attributes;
s32 suspend_count;
u32 effective_priority;
u32 base_priority;
void* exit_value;
OSThreadQueue* queue;
OSThreadLink link;
OSThreadQueue join_queue;
OSMutex* mutex;
OSMutexQueue owned_mutexes;
OSThreadLink active_threads_link;
u8* stack_base;
u8* stack_end;
u8* error_code;
void* data[2];
};
2020-12-06 06:40:34 +01:00
extern "C" {
2020-12-26 11:31:49 -05:00
s32 OSEnableScheduler(void);
s32 OSDisableScheduler(void);
s32 OSCheckActiveThreads(void);
OSThread* OSGetCurrentThread(void);
2020-12-07 14:05:20 -06:00
2020-12-26 11:31:49 -05:00
s32 OSSuspendThread(OSThread* thread);
s32 OSSetThreadPriority(OSThread* thread, u32 pri);
s32 OSGetThreadPriority(OSThread* thread);
s32 OSCreateThread(OSThread* thread, void* (*func)(void*), void* param, void* stack, u32 stackSize,
int param_6, int param_7);
void OSCancelThread(OSThread* thread);
void OSDetachThread(OSThread* thread);
s32 OSResumeThread(OSThread* thread);
void OSExitThread(void* exit_val);
bool OSIsThreadSuspended(OSThread* thread);
BOOL OSIsThreadTerminated(OSThread* thread);
2020-12-26 11:31:49 -05:00
OSSwitchThreadCallback OSSetSwitchThreadCallback(OSSwitchThreadCallback* callback);
2020-12-07 14:05:20 -06:00
2020-12-26 11:31:49 -05:00
void OSInitMessageQueue(OSMessageQueue* queue, OSMessage* messages, int message_count);
2021-01-03 11:29:50 +01:00
BOOL OSReceiveMessage(OSMessageQueue* queue, OSMessage message, int flags);
2021-01-03 22:19:54 +01:00
BOOL OSSendMessage(OSMessageQueue* queue, OSMessage message, int flags);
BOOL OSJamMessage(OSMessageQueue* queue, OSMessage message, int flags);
2020-12-07 14:05:20 -06:00
2020-12-26 11:31:49 -05:00
s32 OSGetConsoleType(void);
s32 OSGetResetCode(void);
2020-12-07 14:05:20 -06:00
2021-01-07 02:39:56 +01:00
u32 OSGetSoundMode(void);
2020-12-26 11:31:49 -05:00
void OSSetSoundMode(OSSoundMode mode);
2020-12-07 14:05:20 -06:00
2020-12-26 11:31:49 -05:00
void OSReportInit(void);
void OSAttention(char* msg, ...);
void OSPanic(char* file, s32 line, char* fmt, ...);
void OSReport(char* fmt, ...);
void OSReport_Error(char* fmt, ...);
void OSReport_FatalError(char* fmt, ...);
void OSReport_System(char* fmt, ...);
void OSReport_Warning(char* fmt, ...);
void OSReportDisable(void);
void OSReportEnable(void);
void OSReportForceEnableOff(void);
void OSReportForceEnableOn(void);
void OSReportInit(void);
void OSSwitchFiberEx(u32, u32, u32, u32, u32, u32);
void OSVAttention(char*, /*__gnuc_va_list*/ void*);
2020-12-07 14:05:20 -06:00
2020-12-26 11:31:49 -05:00
void OSTicksToCalendarTime(OSTime ticks, OSCalendarTime* out_time);
OSTime OSGetTime(void);
OSTick OSGetTick(void);
2020-12-06 06:40:34 +01:00
2020-12-26 11:31:49 -05:00
u32 OSGetArenaLo();
u32 OSGetArenaHi();
u32 OSInitAlloc(u32 low, u32 high, int param_3);
void OSSetArenaLo(u32 param_1);
void OSSetArenaHi(u32 param_1);
void OSAllocFromArenaLo(u32 size, int alignment);
2020-12-06 06:40:34 +01:00
2020-12-26 11:31:49 -05:00
// void OSCancelAlarm(OSAlarm *alarm);
2020-12-06 06:40:34 +01:00
2020-12-26 11:31:49 -05:00
void OSInitMutex(OSMutex* mutex);
void OSLockMutex(OSMutex* mutex);
void OSTryLockMutex(OSMutex* mutex);
void OSUnlockMutex(OSMutex* mutex);
2020-12-06 06:40:34 +01:00
2020-12-26 11:31:49 -05:00
s32 OSDisableInterrupts();
s32 OSEnableInterrupts();
s32 OSRestoreInterrupts(s32 level);
2020-12-25 19:59:52 -06:00
2020-12-26 11:31:49 -05:00
void OSResetSystem(s32 param_1, u32 param_2, s32 param_3);
2020-12-25 19:59:52 -06:00
2020-12-26 11:31:49 -05:00
void OSSetSaveRegion(void* start, void* end);
2020-12-25 19:59:52 -06:00
2020-12-26 11:31:49 -05:00
void LCDisable(void);
2020-12-07 14:05:20 -06:00
};
2020-12-06 06:40:34 +01:00
#endif