Add a bunch of coreinit functions.

This commit is contained in:
James Benton 2016-01-07 12:07:13 +00:00
parent 9cd1940bc8
commit 9f42cfa12e
23 changed files with 1490 additions and 2 deletions

122
include/coreinit/alarm.h Normal file
View File

@ -0,0 +1,122 @@
#pragma once
#include <wut.h>
#include "thread.h"
#include "threadqueue.h"
#include "time.h"
#ifdef __cplusplus
extern "C" {
#endif
struct OSThread;
typedef struct OSAlarm OSAlarm;
typedef struct OSAlarmLink OSAlarmLink;
typedef struct OSAlarmQueue OSAlarmQueue;
typedef void (*OSAlarmCallback)(OSAlarm *, OSContext *);
struct OSAlarmQueue
{
static const uint32_t Tag = 0x614C6D51;
uint32_t tag;
const char *name;
UNKNOWN(4);
OSThreadQueue threadQueue;
OSAlarm *head;
OSAlarm *tail;
};
CHECK_OFFSET(OSAlarmQueue, 0x00, tag);
CHECK_OFFSET(OSAlarmQueue, 0x04, name);
CHECK_OFFSET(OSAlarmQueue, 0x0c, threadQueue);
CHECK_OFFSET(OSAlarmQueue, 0x1c, head);
CHECK_OFFSET(OSAlarmQueue, 0x20, tail);
CHECK_SIZE(OSAlarmQueue, 0x24);
struct OSAlarmLink
{
OSAlarm *prev;
OSAlarm *next;
};
CHECK_OFFSET(OSAlarmLink, 0x00, prev);
CHECK_OFFSET(OSAlarmLink, 0x04, next);
CHECK_SIZE(OSAlarmLink, 0x08);
struct OSAlarm
{
static const uint32_t Tag = 0x614C724D;
uint32_t tag;
const char *name;
UNKNOWN(4);
OSAlarmCallback callback;
uint32_t group;
UNKNOWN(4);
OSTime nextFire;
OSAlarmLink link;
OSTime period;
OSTime tbrStart;
void *userData;
uint32_t state;
OSThreadQueue threadQueue;
OSAlarmQueue *alarmQueue;
OSContext *context;
};
CHECK_OFFSET(OSAlarm, 0x00, tag);
CHECK_OFFSET(OSAlarm, 0x04, name);
CHECK_OFFSET(OSAlarm, 0x0c, callback);
CHECK_OFFSET(OSAlarm, 0x10, group);
CHECK_OFFSET(OSAlarm, 0x18, nextFire);
CHECK_OFFSET(OSAlarm, 0x20, link);
CHECK_OFFSET(OSAlarm, 0x28, period);
CHECK_OFFSET(OSAlarm, 0x30, tbrStart);
CHECK_OFFSET(OSAlarm, 0x38, userData);
CHECK_OFFSET(OSAlarm, 0x3c, state);
CHECK_OFFSET(OSAlarm, 0x40, threadQueue);
CHECK_OFFSET(OSAlarm, 0x50, alarmQueue);
CHECK_OFFSET(OSAlarm, 0x54, context);
CHECK_SIZE(OSAlarm, 0x58);
BOOL
OSCancelAlarm(OSAlarm *alarm);
void
OSCancelAlarms(uint32_t group);
void
OSCreateAlarm(OSAlarm *alarm);
void
OSCreateAlarmEx(OSAlarm *alarm,
const char *name);
void *
OSGetAlarmUserData(OSAlarm *alarm);
void
OSInitAlarmQueue(OSAlarmQueue *queue);
BOOL
OSSetAlarm(OSAlarm *alarm,
OSTime time,
AlarmCallback callback);
BOOL
OSSetPeriodicAlarm(OSAlarm *alarm,
OSTime start,
OSTime interval,
AlarmCallback callback);
void
OSSetAlarmTag(OSAlarm *alarm,
uint32_t group);
void
OSSetAlarmUserData(OSAlarm *alarm,
void *data);
BOOL
OSWaitAlarm(OSAlarm *alarm);
#ifdef __cplusplus
}
#endif

View File

@ -0,0 +1,56 @@
#pragma once
#include <wut.h>
#ifdef __cplusplus
extern "C" {
#endif
uint64_t
OSGetAtomic64(uint64_t *ptr);
uint64_t
OSSetAtomic64(uint64_t *ptr,
uint64_t value);
BOOL
OSCompareAndSwapAtomic64(uint64_t *ptr,
uint64_t compare,
uint64_t value);
BOOL
OSCompareAndSwapAtomicEx64(uint64_t *ptr,
uint64_t compare,
uint64_t value,
uint64_t *old);
uint64_t
OSSwapAtomic64(uint64_t *ptr,
uint64_t value);
int64_t
OSAddAtomic64(int64_t *ptr,
int64_t value);
uint64_t
OSAndAtomic64(uint64_t *ptr,
uint64_t value);
uint64_t
OSOrAtomic64(uint64_t *ptr,
uint64_t value);
uint64_t
OSXorAtomic64(uint64_t *ptr,
uint64_t value);
BOOL
OSTestAndClearAtomic64(uint64_t *ptr,
uint32_t bit);
BOOL
OSTestAndSetAtomic64(uint64_t *ptr,
uint32_t bit);
#ifdef __cplusplus
}
#endif

31
include/coreinit/cache.h Normal file
View File

@ -0,0 +1,31 @@
#pragma once
#include <wut.h>
#ifdef __cplusplus
extern "C" {
#endif
void
DCInvalidateRange(void *addr, uint32_t size);
void
DCFlushRange(void *addr, uint32_t size);
void
DCStoreRange(void *addr, uint32_t size);
void
DCFlushRangeNoSync(void *addr, uint32_t size);
void
DCStoreRangeNoSync(void *addr, uint32_t size);
void
DCZeroRange(void *addr, uint32_t size);
void
DCTouchRange(void *addr, uint32_t size);
#ifdef __cplusplus
}
#endif

View File

@ -0,0 +1,49 @@
#pragma once
#include <wut.h>
#include "threadqueue.h"
#ifdef __cplusplus
extern "C" {
#endif
struct OSMutex;
typedef struct OSCondition OSCondition;
struct OSCondition
{
static const uint32_t Tag = 0x634E6456;
// OSCondition::Tag
uint32_t tag;
// Name set by OSInitCondEx(condition, name)
const char *name;
UNKNOWN(4);
// Queue of threads waiting on condition
OSThreadQueue queue;
};
CHECK_OFFSET(OSCondition, 0x00, tag);
CHECK_OFFSET(OSCondition, 0x04, name);
CHECK_OFFSET(OSCondition, 0x0c, queue);
CHECK_SIZE(OSCondition, 0x1c);
void
OSInitCond(OSCondition *condition);
void
OSInitCondEx(OSCondition *condition,
const char *name);
void
OSWaitCond(OSCondition *condition,
OSMutex *mutex);
void
OSSignalCond(OSCondition *condition);
#ifdef __cplusplus
}
#endif

22
include/coreinit/core.h Normal file
View File

@ -0,0 +1,22 @@
#pragma once
#include <wut.h>
#ifdef __cplusplus
extern "C" {
#endif
uint32_t
OSGetCoreCount();
uint32_t
OSGetCoreId();
uint32_t
OSGetMainCoreId();
BOOL
OSIsMainCore();
#ifdef __cplusplus
}
#endif

View File

@ -1,5 +1,5 @@
#pragma once
#include <stdint.h>
#include <wut.h>
#ifdef __cplusplus
extern "C" {

View File

@ -0,0 +1,46 @@
#pragma once
#include <wut.h>
#include "thread.h"
#include "time.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef void *OSDynLoadModule;
typedef int (*OSDynLoadAllocFn)(int size, int align, void **outAddr);
typedef void (*OSDynLoadFreeFn)(void *addr);
int32_t
OSDynLoad_SetAllocator(OSDynLoadAllocFn allocFn,
OSDynLoadFreeFn freeFn);
int32_t
OSDynLoad_GetAllocator(OSDynLoadAllocFn *outAllocFn,
OSDynLoadFreeFn *outFreeFn);
int32_t
OSDynLoad_MemAlloc(int32_t size,
int32_t alignment,
void **outAddr);
void
OSDynLoad_MemFree(void *addr);
int32_t
OSDynLoad_Acquire(char const *name,
OSDynLoadModule *outModule);
int32_t
OSDynLoad_FindExport(OSDynLoadModule module,
int32_t isData,
char const *name,
void **outAddr);
void
OSDynLoad_Release(OSDynLoadModule module);
#ifdef __cplusplus
}
#endif

69
include/coreinit/event.h Normal file
View File

@ -0,0 +1,69 @@
#pragma once
#include <wut.h>
#include "thread.h"
#include "threadqueue.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct OSEvent OSEvent;
typedef enum OSEventMode OSEventMode;
enum OSEventMode
{
OS_EVENT_MODE_MANUAL = 0,
OS_EVENT_MODE_AUTO = 1,
};
struct OSEvent
{
static const uint32_t Tag = 0x65566E54;
uint32_t tag;
const char *name;
UNKNOWN(4);
BOOL value;
OSThreadQueue queue;
OSEventMode mode;
};
CHECK_OFFSET(OSEvent, 0x0, tag);
CHECK_OFFSET(OSEvent, 0x4, name);
CHECK_OFFSET(OSEvent, 0xc, value);
CHECK_OFFSET(OSEvent, 0x10, queue);
CHECK_OFFSET(OSEvent, 0x20, mode);
CHECK_SIZE(OSEvent, 0x24);
#pragma pack(pop)
void
OSInitEvent(OSEvent *event,
BOOL value,
OSEventMode mode);
void
OSInitEventEx(OSEvent *event,
BOOL value,
OSEventMode mode,
char *name);
void
OSSignalEvent(OSEvent *event);
void
OSSignalEventAll(OSEvent *event);
void
OSWaitEvent(OSEvent *event);
void
OSResetEvent(OSEvent *event);
BOOL
OSWaitEventWithTimeout(OSEvent *event,
OSTime timeout);
#ifdef __cplusplus
}
#endif

View File

@ -0,0 +1,42 @@
#pragma once
#include <wut.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef enum OSExceptionType OSExceptionType;
typedef BOOL (*OSExceptionCallbackFn)(OSContext *context);
enum OSExceptionType
{
OS_EXCEPTION_TYPE_SYSTEM_RESET = 0,
OS_EXCEPTION_TYPE_MACHINE_CHECK = 1,
OS_EXCEPTION_TYPE_DSI = 2,
OS_EXCEPTION_TYPE_ISI = 3,
OS_EXCEPTION_TYPE_EXTERNAL_INTERRUPT = 4,
OS_EXCEPTION_TYPE_ALIGNMENT = 5,
OS_EXCEPTION_TYPE_PROGRAM = 6,
OS_EXCEPTION_TYPE_FLOATING_POINT = 7,
OS_EXCEPTION_TYPE_DECREMENTER = 8,
OS_EXCEPTION_TYPE_SYSTEM_CALL = 9,
OS_EXCEPTION_TYPE_TRACE = 10,
OS_EXCEPTION_TYPE_PERFORMANCE_MONITOR = 11,
OS_EXCEPTION_TYPE_BREAKPOINT = 12,
OS_EXCEPTION_TYPE_SYSTEM_INTERRUPT = 13,
OS_EXCEPTION_TYPE_ICI = 14,
};
OSExceptionCallbackFn
OSSetExceptionCallback(OSExceptionType exceptionType,
OSExceptionCallbackFn callback);
OSExceptionCallbackFn
OSSetExceptionCallbackEx(UNKNOWN_ARG,
OSExceptionType exceptionType,
OSExceptionCallbackFn callback);
#ifdef __cplusplus
}
#endif

View File

@ -1,4 +1,5 @@
#pragma once
#include <wut.h>
#ifdef __cplusplus
extern "C" {

View File

@ -0,0 +1,76 @@
#pragma once
#include <wut.h>
#include "threadqueue.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct OSFastMutex OSFastMutex;
typedef struct OSFastMutexLink OSFastMutexLink;
typedef struct OSFastCondition OSFastCondition;
struct OSFastMutexLink
{
OSFastMutex *next;
OSFastMutex *prev;
};
CHECK_OFFSET(OSFastMutexLink, 0x00, next);
CHECK_OFFSET(OSFastMutexLink, 0x04, prev);
CHECK_SIZE(OSFastMutexLink, 0x08);
struct OSFastMutex
{
static const uint32_t Tag = 0x664D7458;
uint32_t tag;
const char *name;
UNKNOWN(4);
OSThreadSimpleQueue queue;
OSFastMutexLink link;
UNKNOWN(16);
};
CHECK_OFFSET(OSFastMutex, 0x00, tag);
CHECK_OFFSET(OSFastMutex, 0x04, name);
CHECK_OFFSET(OSFastMutex, 0x0c, queue);
CHECK_OFFSET(OSFastMutex, 0x14, link);
CHECK_SIZE(OSFastMutex, 0x2c);
struct OSFastCondition
{
static const uint32_t Tag = 0x664E6456;
uint32_t tag;
const char *name;
UNKNOWN(4);
OSThreadQueue queue;
};
CHECK_OFFSET(OSFastCondition, 0x00, tag);
CHECK_OFFSET(OSFastCondition, 0x04, name);
CHECK_OFFSET(OSFastCondition, 0x0c, queue);
CHECK_SIZE(OSFastCondition, 0x1c);
void
OSFastMutex_Init(OSFastMutex *mutex, const char *name);
void
OSFastMutex_Lock(OSFastMutex *mutex);
void
OSFastMutex_Unlock(OSFastMutex *mutex);
BOOL
OSFastMutex_TryLock(OSFastMutex *mutex);
void
OSFastCond_Init(OSFastCondition *condition, const char *name);
void
OSFastCond_Wait(OSFastCondition *condition, OSFastMutex *mutex);
void
OSFastCond_Signal(OSFastCondition *condition);
#ifdef __cplusplus
}
#endif

View File

@ -0,0 +1,89 @@
#pragma once
#include <wut.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef struct MEMExpandedHeap MEMExpandedHeap;
typedef enum MEMExpHeapMode MEMExpHeapMode;
typedef enum MEMExpHeapDirection MEMExpHeapDirection;
struct MEMExpandedHeap
{
};
UNKNOWN_SIZE(MEMExpandedHeap);
enum MEMExpHeapMode
{
MEM_EXP_HEAP_MODE_FIRST_FREE = 0,
MEM_EXP_HEAP_MODE_NEAREST_SIZE = 1,
};
enum MEMExpHeapDirection
{
MEM_EXP_HEAP_DIR_FROM_TOP = 0,
MEM_EXP_HEAP_DIR_FROM_BOTTOM = 1,
};
MEMExpandedHeap *
MEMCreateExpHeap(MEMExpandedHeap *heap, uint32_t size);
MEMExpandedHeap *
MEMCreateExpHeapEx(MEMExpandedHeap *heap, uint32_t size, uint16_t flags);
MEMExpandedHeap *
MEMDestroyExpHeap(MEMExpandedHeap *heap);
void
MEMiDumpExpHeap(MEMExpandedHeap *heap);
void *
MEMAllocFromExpHeap(MEMExpandedHeap *heap, uint32_t size);
void *
MEMAllocFromExpHeapEx(MEMExpandedHeap *heap, uint32_t size, int alignment);
void
MEMFreeToExpHeap(MEMExpandedHeap *heap, uint8_t *block);
MEMExpHeapMode
MEMSetAllocModeForExpHeap(MEMExpandedHeap *heap, MEMExpHeapMode mode);
MEMExpHeapMode
MEMGetAllocModeForExpHeap(MEMExpandedHeap *heap);
uint32_t
MEMAdjustExpHeap(MEMExpandedHeap *heap);
uint32_t
MEMResizeForMBlockExpHeap(MEMExpandedHeap *heap, uint8_t *address, uint32_t size);
uint32_t
MEMGetTotalFreeSizeForExpHeap(MEMExpandedHeap *heap);
uint32_t
MEMGetAllocatableSizeForExpHeap(MEMExpandedHeap *heap);
uint32_t
MEMGetAllocatableSizeForExpHeapEx(MEMExpandedHeap *heap, int alignment);
uint16_t
MEMSetGroupIDForExpHeap(MEMExpandedHeap *heap, uint16_t id);
uint16_t
MEMGetGroupIDForExpHeap(MEMExpandedHeap *heap);
uint32_t
MEMGetSizeForMBlockExpHeap(uint8_t *addr);
uint16_t
MEMGetGroupIDForMBlockExpHeap(uint8_t *addr);
MEMExpHeapDirection
MEMGetAllocDirForMBlockExpHeap(uint8_t *addr);
#ifdef __cplusplus
}
#endif

99
include/coreinit/mutex.h Normal file
View File

@ -0,0 +1,99 @@
#pragma once
#include <wut.h>
#include "threadqueue.h"
#ifdef __cplusplus
extern "C" {
#endif
struct OSThread;
typedef struct OSCondition OSCondition;
typedef struct OSMutex OSMutex;
typedef struct OSMutexLink OSMutexLink;
struct OSMutexLink
{
OSMutex *next;
OSMutex *prev;
};
CHECK_OFFSET(OSMutexLink, 0x00, next);
CHECK_OFFSET(OSMutexLink, 0x04, prev);
CHECK_SIZE(OSMutexLink, 0x8);
struct OSMutex
{
static const uint32_t Tag = 0x6D557458;
// OSMutex::Tag
uint32_t tag;
// Name set by OSInitMutexEx(mutex, name)
const char *name;
UNKNOWN(4);
// Queue of threads waiting for this mutex to unlock
OSThreadQueue queue;
// Current owner of mutex
OSThread *owner;
// Current recursion lock count of mutex
int32_t count;
// Link used inside OSThread's mutex queue
OSMutexLink link;
};
CHECK_OFFSET(OSMutex, 0x00, tag);
CHECK_OFFSET(OSMutex, 0x04, name);
CHECK_OFFSET(OSMutex, 0x0c, queue);
CHECK_OFFSET(OSMutex, 0x1c, owner);
CHECK_OFFSET(OSMutex, 0x20, count);
CHECK_OFFSET(OSMutex, 0x24, link);
CHECK_SIZE(OSMutex, 0x2c);
struct OSCondition
{
static const uint32_t Tag = 0x634E6456;
// OSCondition::Tag
uint32_t tag;
// Name set by OSInitCondEx(condition, name)
const char *name;
UNKNOWN(4);
// Queue of threads waiting on condition
OSThreadQueue queue;
};
CHECK_OFFSET(OSCondition, 0x00, tag);
CHECK_OFFSET(OSCondition, 0x04, name);
CHECK_OFFSET(OSCondition, 0x0c, queue);
CHECK_SIZE(OSCondition, 0x1c);
void
OSInitMutex(OSMutex *mutex);
void
OSInitMutexEx(OSMutex *mutex,
const char *name);
void
OSLockMutex(OSMutex *mutex);
void
OSLockMutexNoLock(OSMutex *mutex);
void
OSUnlockMutex(OSMutex *mutex);
void
OSUnlockMutexNoLock(OSMutex *mutex);
BOOL
OSTryLockMutex(OSMutex *mutex);
#ifdef __cplusplus
}
#endif

View File

@ -0,0 +1,34 @@
#pragma once
#include <wut.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef struct OSRendezvous OSRendezvous;
struct OSRendezvous
{
uint32_t core[3];
UNKNOWN(4);
};
CHECK_OFFSET(OSRendezvous, 0x00, core);
CHECK_SIZE(OSRendezvous, 0x10);
#pragma pack(pop)
void
OSInitRendezvous(OSRendezvous *rendezvous);
BOOL
OSWaitRendezvous(OSRendezvous *rendezvous,
uint32_t coreMask);
BOOL
OSWaitRendezvousWithTimeout(OSRendezvous *rendezvous,
uint32_t coreMask,
OSTime timeout);
#ifdef __cplusplus
}
#endif

View File

@ -0,0 +1,50 @@
#pragma once
#include <wut.h>
#include "threadqueue.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct OSSemaphore OSSemaphore;
struct OSSemaphore
{
static const uint32_t Tag = 0x73506852;
uint32_t tag;
const char *name;
UNKNOWN(4);
int32_t count;
OSThreadQueue queue;
};
CHECK_OFFSET(OSSemaphore, 0x00, tag);
CHECK_OFFSET(OSSemaphore, 0x04, name);
CHECK_OFFSET(OSSemaphore, 0x0C, count);
CHECK_OFFSET(OSSemaphore, 0x10, queue);
CHECK_SIZE(OSSemaphore, 0x20);
void
OSInitSemaphore(OSSemaphore *semaphore,
int32_t count);
void
OSInitSemaphoreEx(OSSemaphore *semaphore,
int32_t count,
const char *name);
int32_t
OSGetSemaphoreCount(OSSemaphore *semaphore);
int32_t
OSSignalSemaphore(OSSemaphore *semaphore);
int32_t
OSWaitSemaphore(OSSemaphore *semaphore);
int32_t
OSTryWaitSemaphore(OSSemaphore *semaphore);
#ifdef __cplusplus
}
#endif

View File

@ -0,0 +1,55 @@
#pragma once
#include <wut.h>
#include "time.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct OSSpinLock OSSpinLock;
struct OSSpinLock
{
uint32_t owner;
UNKNOWN(0x4);
uint32_t recursion;
UNKNOWN(0x4);
};
CHECK_OFFSET(OSSpinLock, 0x0, owner);
CHECK_OFFSET(OSSpinLock, 0x8, recursion);
CHECK_SIZE(OSSpinLock, 0x10);
#pragma pack(pop)
void
OSInitSpinLock(OSSpinLock *spinlock);
BOOL
OSAcquireSpinLock(OSSpinLock *spinlock);
BOOL
OSTryAcquireSpinLock(OSSpinLock *spinlock);
BOOL
OSTryAcquireSpinLockWithTimeout(OSSpinLock *spinlock,
OSTime timeout);
BOOL
OSReleaseSpinLock(OSSpinLock *spinlock);
BOOL
OSUninterruptibleSpinLock_Acquire(OSSpinLock *spinlock);
BOOL
OSUninterruptibleSpinLock_TryAcquire(OSSpinLock *spinlock);
BOOL
OSUninterruptibleSpinLock_TryAcquireWithTimeout(OSSpinLock *spinlock,
OSTime timeout);
BOOL
OSUninterruptibleSpinLock_Release(OSSpinLock *spinlock);
#ifdef __cplusplus
}
#endif

324
include/coreinit/thread.h Normal file
View File

@ -0,0 +1,324 @@
#pragma once
#include <wut.h>
#include "time.h"
#include "threadqueue.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef struct OSContext OSContext;
typedef struct OSFastMutex OSFastMutex;
typedef struct OSFastMutexQueue OSFastMutexQueue;
typedef struct OSMutex OSMutex;
typedef struct OSThread OSThread;
typedef enum OSThreadState OSThreadState;
typedef enum OSThreadRequest OSThreadRequest;
typedef enum OSThreadAttributes OSThreadAttributes;
typedef int32_t (*OSThreadEntryPointFn)(int32_t argc, char *arv);
typedef void (*OSThreadCleanupCallbackFn)(OSThread *thread, void *stack);
typedef void (*OSThreadDeallocatorFn)(OSThread *thread, void *stack);
enum OSThreadState
{
OS_THREAD_STATE_NONE = 0,
OS_THREAD_STATE_READY = 1 << 0,
OS_THREAD_STATE_RUNNING = 1 << 1,
OS_THREAD_STATE_WAITING = 1 << 2,
OS_THREAD_STATE_MORIBUND = 1 << 3,
};
enum OSThreadRequest
{
OS_THREAD_REQUEST_NONE = 0,
OS_THREAD_REQUEST_SUSPEND = 1,
OS_THREAD_REQUEST_CANCEL = 2,
};
enum OSThreadAttributes
{
OS_THREAD_ATTRIB_AFFINITY_CPU0 = 1 << 0,
OS_THREAD_ATTRIB_AFFINITY_CPU1 = 1 << 1,
OS_THREAD_ATTRIB_AFFINITY_CPU2 = 1 << 2,
OS_THREAD_ATTRIB_AFFINITY_ANY = 1 << 3,
OS_THREAD_ATTRIB_DETACHED = 1 << 4
};
struct OSContext
{
static const uint64_t Tag1 = 0x4F53436F6E747874ull;
uint64_t tag;
uint32_t gpr[32];
uint32_t cr;
uint32_t lr;
uint32_t ctr;
uint32_t xer;
uint32_t srr0;
uint32_t srr1;
UNKNOWN(0x14);
uint32_t fpscr;
double fpr[32];
uint16_t spinLockCount;
uint16_t state;
uint32_t gqr[8];
UNKNOWN(4);
double psf[32];
uint64_t coretime[3];
uint64_t starttime;
uint32_t error;
UNKNOWN(4);
uint32_t pmc1;
uint32_t pmc2;
uint32_t pmc3;
uint32_t pmc4;
uint32_t mmcr0;
uint32_t mmcr1;
};
CHECK_OFFSET(OSContext, 0x00, tag);
CHECK_OFFSET(OSContext, 0x08, gpr);
CHECK_OFFSET(OSContext, 0x88, cr);
CHECK_OFFSET(OSContext, 0x8c, lr);
CHECK_OFFSET(OSContext, 0x90, ctr);
CHECK_OFFSET(OSContext, 0x94, xer);
CHECK_OFFSET(OSContext, 0x98, srr0);
CHECK_OFFSET(OSContext, 0x9c, srr1);
CHECK_OFFSET(OSContext, 0xb4, fpscr);
CHECK_OFFSET(OSContext, 0xb8, fpr);
CHECK_OFFSET(OSContext, 0x1b8, spinLockCount);
CHECK_OFFSET(OSContext, 0x1ba, state);
CHECK_OFFSET(OSContext, 0x1bc, gqr);
CHECK_OFFSET(OSContext, 0x1e0, psf);
CHECK_OFFSET(OSContext, 0x2e0, coretime);
CHECK_OFFSET(OSContext, 0x2f8, starttime);
CHECK_OFFSET(OSContext, 0x300, error);
CHECK_OFFSET(OSContext, 0x308, pmc1);
CHECK_OFFSET(OSContext, 0x30c, pmc2);
CHECK_OFFSET(OSContext, 0x310, pmc3);
CHECK_OFFSET(OSContext, 0x314, pmc4);
CHECK_OFFSET(OSContext, 0x318, mmcr0);
CHECK_OFFSET(OSContext, 0x31c, mmcr1);
CHECK_SIZE(OSContext, 0x320);
struct OSMutexQueue
{
OSMutex *head;
OSMutex *tail;
void *parent;
UNKNOWN(4);
};
CHECK_OFFSET(OSMutexQueue, 0x0, head);
CHECK_OFFSET(OSMutexQueue, 0x4, tail);
CHECK_OFFSET(OSMutexQueue, 0x8, parent);
CHECK_SIZE(OSMutexQueue, 0x10);
struct OSFastMutexQueue
{
OSFastMutex *head;
OSFastMutex *tail;
};
CHECK_OFFSET(OSFastMutexQueue, 0x00, head);
CHECK_OFFSET(OSFastMutexQueue, 0x04, tail);
CHECK_SIZE(OSFastMutexQueue, 0x08);
struct OSThread
{
static const uint32_t Tag = 0x74487244;
OSContext context;
uint32_t tag;
OSThreadState state;
OSThreadAttributes attr;
uint16_t id;
int32_t suspendCounter;
int32_t priority; // Actual priority of thread
int32_t basePriority; // Base priority of thread
int32_t exitValue; // Value from OSExitThread
UNKNOWN(0x354 - 0x340);
OSThreadQueue *queue; // Queue the thread is on
OSThreadLink link; // Thread queue link
OSThreadQueue joinQueue; // Queue of threads waiting to join this
OSMutex *mutex; // Mutex we are waiting to lock
OSMutexQueue mutexQueue; // Mutexes owned by this thread
OSThreadLink activeLink; // Link on active thread queue
void *stackStart; // Stack starting value (top, highest address)
void *stackEnd; // Stack end value (bottom, lowest address)
OSThreadEntryPointFn entryPoint; // Entry point from OSCreateThread
UNKNOWN(0x57c - 0x3a0);
uint32_t specific[0x10]; // OSSetThreadSpecific / OSGetThreadSpecific
UNKNOWN(0x5c0 - 0x5bc);
const char *name; // Thread name
UNKNOWN(0x4);
void *userStackPointer; // The stack specified in OSCreateThread
OSThreadCleanupCallbackFn cleanupCallback; // Set with OSSetThreadCleanupCallback
OSThreadDeallocatorFn deallocator; // Set with OSSetThreadDeallocator
uint32_t cancelState; // Is listening to requestFlag enabled
OSThreadRequest requestFlag; // Request flag for cancel or suspend
int32_t needSuspend; // How many pending suspends we have
int32_t suspendResult; // Result of suspend
OSThreadQueue suspendQueue; // Queue of threads waiting for suspend to finish
UNKNOWN(0x69c - 0x5f4);
};
CHECK_OFFSET(OSThread, 0x320, tag);
CHECK_OFFSET(OSThread, 0x324, state);
CHECK_OFFSET(OSThread, 0x325, attr);
CHECK_OFFSET(OSThread, 0x326, id);
CHECK_OFFSET(OSThread, 0x328, suspendCounter);
CHECK_OFFSET(OSThread, 0x32c, priority);
CHECK_OFFSET(OSThread, 0x330, basePriority);
CHECK_OFFSET(OSThread, 0x334, exitValue);
CHECK_OFFSET(OSThread, 0x35c, queue);
CHECK_OFFSET(OSThread, 0x360, link);
CHECK_OFFSET(OSThread, 0x368, joinQueue);
CHECK_OFFSET(OSThread, 0x378, mutex);
CHECK_OFFSET(OSThread, 0x37c, mutexQueue);
CHECK_OFFSET(OSThread, 0x38c, activeLink);
CHECK_OFFSET(OSThread, 0x394, stackStart);
CHECK_OFFSET(OSThread, 0x398, stackEnd);
CHECK_OFFSET(OSThread, 0x39c, entryPoint);
CHECK_OFFSET(OSThread, 0x57c, specific);
CHECK_OFFSET(OSThread, 0x5c0, name);
CHECK_OFFSET(OSThread, 0x5c8, userStackPointer);
CHECK_OFFSET(OSThread, 0x5cc, cleanupCallback);
CHECK_OFFSET(OSThread, 0x5d0, deallocator);
CHECK_OFFSET(OSThread, 0x5d4, cancelState);
CHECK_OFFSET(OSThread, 0x5d8, requestFlag);
CHECK_OFFSET(OSThread, 0x5dc, needSuspend);
CHECK_OFFSET(OSThread, 0x5e0, suspendResult);
CHECK_OFFSET(OSThread, 0x5e4, suspendQueue);
CHECK_SIZE(OSThread, 0x69c);
void
OSCancelThread(OSThread *thread);
int32_t
OSCheckActiveThreads();
int32_t
OSCheckThreadStackUsage(OSThread *thread);
void
OSClearThreadStackUsage(OSThread *thread);
void
OSContinueThread(OSThread *thread);
BOOL
OSCreateThread(OSThread *thread,
OSThreadEntryPointFn entry,
int32_t argc,
char *argv,
void *stack,
uint32_t stackSize,
int32_t priority,
OSThreadAttributes attributes);
void
OSDetachThread(OSThread *thread);
void
OSExitThread(int32_t result);
void
OSGetActiveThreadLink(OSThread *thread,
OSThreadLink *link);
OSThread *
OSGetCurrentThread();
OSThread *
OSGetDefaultThread(uint32_t coreID);
uint32_t
OSGetStackPointer();
uint32_t
OSGetThreadAffinity(OSThread *thread);
const char *
OSGetThreadName(OSThread *thread);
int32_t
OSGetThreadPriority(OSThread *thread);
uint32_t
OSGetThreadSpecific(uint32_t id);
BOOL
OSIsThreadSuspended(OSThread *thread);
BOOL
OSIsThreadTerminated(OSThread *thread);
BOOL
OSJoinThread(OSThread *thread,
int32_t *threadResult);
void
OSPrintCurrentThreadState();
int32_t
OSResumeThread(OSThread *thread);
BOOL
OSRunThread(OSThread *thread,
OSThreadEntryPointFn entry,
int32_t argc,
char *argv);
BOOL
OSSetThreadAffinity(OSThread *thread,
uint32_t affinity);
BOOL
OSSetThreadCancelState(BOOL state);
OSThreadCleanupCallbackFn
OSSetThreadCleanupCallback(OSThread *thread,
OSThreadCleanupCallbackFn callback);
OSThreadDeallocatorFn
OSSetThreadDeallocator(OSThread *thread,
OSThreadDeallocatorFn deallocator);
void
OSSetThreadName(OSThread *thread,
const char *name);
BOOL
OSSetThreadPriority(OSThread *thread,
int32_t priority);
BOOL
OSSetThreadRunQuantum(OSThread *thread,
uint32_t quantum);
void
OSSetThreadSpecific(uint32_t id,
uint32_t value);
BOOL
OSSetThreadStackUsage(OSThread *thread);
void
OSSleepThread(OSThreadQueue *queue);
void
OSSleepTicks(OSTime ticks);
uint32_t
OSSuspendThread(OSThread *thread);
void
OSTestThreadCancel();
void
OSWakeupThread(OSThreadQueue *queue);
void
OSYieldThread();
#ifdef __cplusplus
}
#endif

View File

@ -0,0 +1,53 @@
#pragma once
#include <wut.h>
#ifdef __cplusplus
extern "C" {
#endif
struct OSThread;
typedef struct OSThreadLink OSThreadLink;
typedef struct OSThreadQueue OSThreadQueue;
typedef struct OSThreadSimpleQueue OSThreadSimpleQueue;
struct OSThreadLink
{
OSThread *prev;
OSThread *next;
};
CHECK_OFFSET(OSThreadLink, 0x00, prev);
CHECK_OFFSET(OSThreadLink, 0x04, next);
CHECK_SIZE(OSThreadLink, 0x8);
struct OSThreadQueue
{
OSThread *head;
OSThread *tail;
void *parent;
UNKNOWN(4);
};
CHECK_OFFSET(OSThreadQueue, 0x00, head);
CHECK_OFFSET(OSThreadQueue, 0x04, tail);
CHECK_OFFSET(OSThreadQueue, 0x08, parent);
CHECK_SIZE(OSThreadQueue, 0x10);
struct OSThreadSimpleQueue
{
OSThread *head;
OSThread *tail;
};
CHECK_OFFSET(OSThreadSimpleQueue, 0x00, head);
CHECK_OFFSET(OSThreadSimpleQueue, 0x04, tail);
CHECK_SIZE(OSThreadSimpleQueue, 0x08);
void
OSInitThreadQueue(OSThreadQueue *queue);
void
OSInitThreadQueueEx(OSThreadQueue *queue,
void *parent);
#ifdef __cplusplus
}
#endif

51
include/coreinit/time.h Normal file
View File

@ -0,0 +1,51 @@
#pragma once
#include <wut.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef struct OSCalendarTime OSCalendarTime;
typedef int32_t OSTick;
typedef int64_t OSTime;
struct OSCalendarTime
{
int32_t tm_sec;
int32_t tm_min;
int32_t tm_hour;
int32_t tm_mday;
int32_t tm_mon;
int32_t tm_year;
};
CHECK_OFFSET(OSCalendarTime, 0x00, tm_sec);
CHECK_OFFSET(OSCalendarTime, 0x04, tm_min);
CHECK_OFFSET(OSCalendarTime, 0x08, tm_hour);
CHECK_OFFSET(OSCalendarTime, 0x0C, tm_mday);
CHECK_OFFSET(OSCalendarTime, 0x10, tm_mon);
CHECK_OFFSET(OSCalendarTime, 0x14, tm_year);
CHECK_SIZE(OSCalendarTime, 0x18);
OSTime
OSGetTime();
OSTime
OSGetSystemTime();
OSTick
OSGetTick();
OSTick
OSGetSystemTick();
OSTime
OSCalendarTimeToTicks(OSCalendarTime *calendarTime);
void
OSTicksToCalendarTime(OSTime time,
OSCalendarTime *calendarTime);
#ifdef __cplusplus
}
#endif

3
include/wut.h Normal file
View File

@ -0,0 +1,3 @@
#pragma once
#include "wut_structsize.h"
#include "wut_types.h"

27
include/wut_structsize.h Normal file
View File

@ -0,0 +1,27 @@
#pragma once
#include <assert.h>
#include <stddef.h>
// Ensure structs are correct size & offsets
#define CHECK_SIZE(Type, Size) \
static_assert(sizeof(Type) == Size, \
#Type " must be " #Size " bytes")
#define CHECK_OFFSET(Type, Offset, Field) \
static_assert(offsetof(Type, Field) == Offset, \
#Type "::" #Field " must be at offset " #Offset)
// Workaround weird macro concat ## behaviour
#define PP_CAT(a, b) PP_CAT_I(a, b)
#define PP_CAT_I(a, b) PP_CAT_II(~, a ## b)
#define PP_CAT_II(p, res) res
// Allow us to easily add UNKNOWN / PADDING bytes into our structs,
// generates unique variable names using __COUNTER__
#define UNKNOWN(Size) char PP_CAT(__unk, __COUNTER__) [Size]
#define PADDING(Size) UNKNOWN(Size)
// Just some placeholder defines
#define UNKNOWN_ARG uint32_t
#define UNKNOWN_ARGS void
#define UNKNOWN_SIZE(x)

12
include/wut_types.h Normal file
View File

@ -0,0 +1,12 @@
#pragma once
#include <stdint.h>
typedef int BOOL;
#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif

View File

@ -1,9 +1,186 @@
// coreinit/alarm.h
EXPORT(OSCancelAlarm);
EXPORT(OSCancelAlarms);
EXPORT(OSCreateAlarm);
EXPORT(OSCreateAlarmEx);
EXPORT(OSGetAlarmUserData);
EXPORT(OSInitAlarmQueue);
EXPORT(OSSetAlarm);
EXPORT(OSSetPeriodicAlarm);
EXPORT(OSSetAlarmTag);
EXPORT(OSSetAlarmUserData);
EXPORT(OSWaitAlarm);
// coreinit/atomic64.h
EXPORT(OSGetAtomic64);
EXPORT(OSSetAtomic64);
EXPORT(OSCompareAndSwapAtomic64);
EXPORT(OSCompareAndSwapAtomicEx64);
EXPORT(OSSwapAtomic64);
EXPORT(OSAddAtomic64);
EXPORT(OSAndAtomic64);
EXPORT(OSOrAtomic64);
EXPORT(OSXorAtomic64);
EXPORT(OSTestAndClearAtomic64);
EXPORT(OSTestAndSetAtomic64);
// coreinit/cache.h
EXPORT(DCInvalidateRange);
EXPORT(DCFlushRange);
EXPORT(DCStoreRange);
EXPORT(DCFlushRangeNoSync);
EXPORT(DCStoreRangeNoSync);
EXPORT(DCZeroRange);
EXPORT(DCTouchRange);
// coreinit/condition.h
EXPORT(OSInitCond);
EXPORT(OSInitCondEx);
EXPORT(OSWaitCond);
EXPORT(OSSignalCond);
// coreinit/debug.h
EXPORT(OSConsoleWrite);
EXPORT(OSReport);
EXPORT(OSPanic);
EXPORT(OSFatal);
// coreinit/dynload.h
EXPORT(OSDynLoad_SetAllocator);
EXPORT(OSDynLoad_GetAllocator);
EXPORT(OSDynLoad_MemAlloc);
EXPORT(OSDynLoad_MemFree);
EXPORT(OSDynLoad_Acquire);
EXPORT(OSDynLoad_FindExport);
EXPORT(OSDynLoad_Release);
// coreinit/event.h
EXPORT(OSInitEvent);
EXPORT(OSInitEventEx);
EXPORT(OSSignalEvent);
EXPORT(OSSignalEventAll);
EXPORT(OSWaitEvent);
EXPORT(OSResetEvent);
EXPORT(OSWaitEventWithTimeout);
// coreinit/exception.h
EXPORT(OSSetExceptionCallback);
EXPORT(OSSetExceptionCallbackEx);
// coreinit/exit.h
EXPORT(exit);
EXPORT(_Exit);
EXPORT(_Exit);
// coreinit/fastmutex.h
EXPORT(OSFastMutex_Init);
EXPORT(OSFastMutex_Lock);
EXPORT(OSFastMutex_Unlock);
EXPORT(OSFastMutex_TryLock);
EXPORT(OSFastCond_Init);
EXPORT(OSFastCond_Wait);
EXPORT(OSFastCond_Signal);
// coreinit/memexpandedheap.h
EXPORT(MEMCreateExpHeap);
EXPORT(MEMCreateExpHeapEx);
EXPORT(MEMDestroyExpHeap);
EXPORT(MEMiDumpExpHeap);
EXPORT(MEMAllocFromExpHeap);
EXPORT(MEMAllocFromExpHeapEx);
EXPORT(MEMFreeToExpHeap);
EXPORT(MEMSetAllocModeForExpHeap);
EXPORT(MEMGetAllocModeForExpHeap);
EXPORT(MEMAdjustExpHeap);
EXPORT(MEMResizeForMBlockExpHeap);
EXPORT(MEMGetTotalFreeSizeForExpHeap);
EXPORT(MEMGetAllocatableSizeForExpHeap);
EXPORT(MEMGetAllocatableSizeForExpHeapEx);
EXPORT(MEMSetGroupIDForExpHeap);
EXPORT(MEMGetGroupIDForExpHeap);
EXPORT(MEMGetSizeForMBlockExpHeap);
EXPORT(MEMGetGroupIDForMBlockExpHeap);
EXPORT(MEMGetAllocDirForMBlockExpHeap);
// coreinit/mutex.h
EXPORT(OSInitMutex);
EXPORT(OSInitMutexEx);
EXPORT(OSLockMutex);
EXPORT(OSLockMutexNoLock);
EXPORT(OSUnlockMutex);
EXPORT(OSUnlockMutexNoLock);
EXPORT(OSTryLockMutex);
// coreinit/rendezvous.h
EXPORT(OSInitRendezvous);
EXPORT(OSWaitRendezvous);
EXPORT(OSWaitRendezvousWithTimeout);
// coreinit/semaphore.h
EXPORT(OSInitSemaphore);
EXPORT(OSInitSemaphoreEx);
EXPORT(OSGetSemaphoreCount);
EXPORT(OSSignalSemaphore);
EXPORT(OSWaitSemaphore);
EXPORT(OSTryWaitSemaphore);
// coreinit/spinlock.h
EXPORT(OSInitSpinLock);
EXPORT(OSAcquireSpinLock);
EXPORT(OSTryAcquireSpinLock);
EXPORT(OSTryAcquireSpinLockWithTimeout);
EXPORT(OSReleaseSpinLock);
EXPORT(OSUninterruptibleSpinLock_Acquire);
EXPORT(OSUninterruptibleSpinLock_TryAcquire);
EXPORT(OSUninterruptibleSpinLock_TryAcquireWithTimeout);
EXPORT(OSUninterruptibleSpinLock_Release);
// coreinit/thread.h
EXPORT(OSCancelThread);
EXPORT(OSCheckActiveThreads);
EXPORT(OSCheckThreadStackUsage);
EXPORT(OSClearThreadStackUsage);
EXPORT(OSContinueThread);
EXPORT(OSCreateThread);
EXPORT(OSDetachThread);
EXPORT(OSExitThread);
EXPORT(OSGetActiveThreadLink);
EXPORT(OSGetCurrentThread);
EXPORT(OSGetDefaultThread);
EXPORT(OSGetStackPointer);
EXPORT(OSGetThreadAffinity);
EXPORT(OSGetThreadName);
EXPORT(OSGetThreadPriority);
EXPORT(OSGetThreadSpecific);
EXPORT(OSIsThreadSuspended);
EXPORT(OSIsThreadTerminated);
EXPORT(OSJoinThread);
EXPORT(OSPrintCurrentThreadState);
EXPORT(OSResumeThread);
EXPORT(OSRunThread);
EXPORT(OSSetThreadAffinity);
EXPORT(OSSetThreadCancelState);
EXPORT(OSSetThreadCleanupCallback);
EXPORT(OSSetThreadDeallocator);
EXPORT(OSSetThreadName);
EXPORT(OSSetThreadPriority);
EXPORT(OSSetThreadRunQuantum);
EXPORT(OSSetThreadSpecific);
EXPORT(OSSetThreadStackUsage);
EXPORT(OSSleepThread);
EXPORT(OSSleepTicks);
EXPORT(OSSuspendThread);
EXPORT(OSTestThreadCancel);
EXPORT(OSWakeupThread);
EXPORT(OSYieldThread);
// coreinit/threadqueue.h
EXPORT(OSInitThreadQueue);
EXPORT(OSInitThreadQueueEx);
// coreinit/time.h
EXPORT(OSGetTime);
EXPORT(OSGetSystemTime);
EXPORT(OSGetTick);
EXPORT(OSGetSystemTick);
EXPORT(OSCalendarTimeToTicks);
EXPORT(OSTicksToCalendarTime);