From d305958ea478e456061914c9e1bdc86f1e9230ef Mon Sep 17 00:00:00 2001 From: Maschell Date: Sat, 16 Nov 2019 15:01:36 +0100 Subject: [PATCH] Add new functions to the dynamic_libs --- src/dynamic_libs/coreinit.c | 24 +++++++++++++++++++ src/dynamic_libs/coreinit.h | 48 +++++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+) diff --git a/src/dynamic_libs/coreinit.c b/src/dynamic_libs/coreinit.c index c460e6b..9c98aa2 100644 --- a/src/dynamic_libs/coreinit.c +++ b/src/dynamic_libs/coreinit.c @@ -24,10 +24,15 @@ EXPORT_DECL(uint32_t,OSGetThreadAffinity,OSThread * thread); EXPORT_DECL(int32_t,OSGetThreadPriority,OSThread * thread); EXPORT_DECL(void,OSSetThreadName,OSThread * thread, const char *name); EXPORT_DECL(int32_t, OSGetCoreId, void); + +EXPORT_DECL(int32_t, OSEnableInterrupts, void); +EXPORT_DECL(void, OSRestoreInterrupts, int32_t); + EXPORT_DECL(int32_t, MEMCreateExpHeapEx, void *heap, uint32_t size, uint16_t flags); EXPORT_DECL(void*, MEMAllocFromExpHeapEx, int32_t heap, uint32_t size, int alignment); EXPORT_DECL(void, MEMFreeToExpHeap, int32_t heap, void * block); +EXPORT_DECL(OSMessageQueue *, OSGetSystemMessageQueue, void); EXPORT_DECL(void, OSEnableHomeButtonMenu, int32_t); EXPORT_VAR(uint32_t *, pMEMAllocFromDefaultHeapEx); @@ -50,6 +55,14 @@ EXPORT_DECL(void, OSLockMutex, void* mutex); EXPORT_DECL(void, OSUnlockMutex, void* mutex); EXPORT_DECL(int32_t, OSTryLockMutex, void* mutex); +EXPORT_DECL(void, OSInitEvent, OSEvent *event, int32_t value, OSEventMode mode); +EXPORT_DECL(void, OSSignalEvent, OSEvent *event); +EXPORT_DECL(void, OSWaitEvent, OSEvent *event); +EXPORT_DECL(void, OSResetEvent, OSEvent *event); + +EXPORT_DECL(int32_t, OSReceiveMessage, OSMessageQueue *, OSMessage * , int32_t); +EXPORT_DECL(int32_t, OSSendMessage, OSMessageQueue *, OSMessage * , int32_t); + void _os_find_export(uint32_t handle, const char *funcName, void *funcPointer) { OSDynLoad_FindExport(handle, 0, funcName, funcPointer); @@ -108,6 +121,7 @@ void InitOSFunctionPointers(void) { OS_FIND_EXPORT(coreinit_handle, OSScreenClearBufferEx); OS_FIND_EXPORT(coreinit_handle, OSEnableHomeButtonMenu); + OS_FIND_EXPORT(coreinit_handle, OSGetSystemMessageQueue); OS_FIND_EXPORT(coreinit_handle, OSIsHomeButtonMenuEnabled); OS_FIND_EXPORT(coreinit_handle, DCInvalidateRange); OS_FIND_EXPORT(coreinit_handle, DCFlushRange); @@ -136,6 +150,16 @@ void InitOSFunctionPointers(void) { OS_FIND_EXPORT(coreinit_handle, OSSetThreadName); OS_FIND_EXPORT(coreinit_handle, OSGetCoreId); + OS_FIND_EXPORT(coreinit_handle, OSEnableInterrupts); + OS_FIND_EXPORT(coreinit_handle, OSRestoreInterrupts); + + OS_FIND_EXPORT(coreinit_handle, OSInitEvent); + OS_FIND_EXPORT(coreinit_handle, OSSignalEvent); + OS_FIND_EXPORT(coreinit_handle, OSWaitEvent); + OS_FIND_EXPORT(coreinit_handle, OSResetEvent); + OS_FIND_EXPORT(coreinit_handle, OSSendMessage); + OS_FIND_EXPORT(coreinit_handle, OSReceiveMessage); + OSDynLoad_FindExport(coreinit_handle, 1, "MEMAllocFromDefaultHeapEx", &pMEMAllocFromDefaultHeapEx); OSDynLoad_FindExport(coreinit_handle, 1, "MEMAllocFromDefaultHeap", &pMEMAllocFromDefaultHeap); OSDynLoad_FindExport(coreinit_handle, 1, "MEMFreeToDefaultHeap", &pMEMFreeToDefaultHeap); diff --git a/src/dynamic_libs/coreinit.h b/src/dynamic_libs/coreinit.h index 12e7103..095e746 100644 --- a/src/dynamic_libs/coreinit.h +++ b/src/dynamic_libs/coreinit.h @@ -141,6 +141,43 @@ typedef struct OSMessageQueue_ { int usedCount; } OSMessageQueue; + +typedef struct OSEvent OSEvent; + +typedef enum OSEventMode +{ + //! A manual event will only reset when OSResetEvent is called. + OS_EVENT_MODE_MANUAL = 0, + + //! An auto event will reset everytime a thread is woken. + OS_EVENT_MODE_AUTO = 1, +} OSEventMode; + +#define OS_EVENT_TAG 0x65566E54u + +struct OSEvent +{ + //! Should always be set to the value OS_EVENT_TAG. + uint32_t tag; + + //! Name set by OSInitEventEx. + const char *name; + + char unknwn[4]; + + //! The current value of the event object. + int32_t value; + + //! The threads currently waiting on this event object with OSWaitEvent. + OSThreadQueue queue; + + //! The mode of the event object, set by OSInitEvent. + OSEventMode mode; +}; + +extern OSMessageQueue * (*OSGetSystemMessageQueue)(void); +extern int32_t (*OSReceiveMessage)(OSMessageQueue *, OSMessage * , int32_t); +extern int32_t (*OSSendMessage)(OSMessageQueue *, OSMessage * , int32_t); extern void (*DCInvalidateRange)(void *buffer, uint32_t length); extern void (* DCFlushRange)(const void *addr, uint32_t length); extern void (* DCStoreRange)(const void *addr, uint32_t length); @@ -149,6 +186,11 @@ extern void* (* OSEffectiveToPhysical)(uint32_t); extern void* (* OSSleepTicks)(uint64_t ticks); extern void (* OSEnableHomeButtonMenu)(int32_t); +extern void (* OSInitEvent)(OSEvent *event, int32_t value, OSEventMode mode); +extern void (* OSSignalEvent)(OSEvent *event); +extern void (* OSWaitEvent)(OSEvent *event); +extern void (* OSResetEvent)(OSEvent *event); + extern int32_t (* OSCreateThread)(OSThread *thread, int32_t (*callback)(int32_t, void*), int32_t argc, void *args, uint32_t stack, uint32_t stack_size, int32_t priority, uint32_t attr); extern int32_t (* OSResumeThread)(OSThread *thread); @@ -165,6 +207,10 @@ extern void (* OSGetActiveThreadLink)(OSThread * thread, void* link); extern uint32_t (* OSGetThreadAffinity)(OSThread * thread); extern int32_t (* OSGetThreadPriority)(OSThread * thread); extern void (* OSSetThreadName)(OSThread * thread, const char *name); + +extern int32_t (* OSEnableInterrupts)(void); +extern void (* OSRestoreInterrupts)(int32_t); + extern int32_t (* OSGetCoreId)(void); extern uint64_t (* OSGetTitleID)(void); @@ -195,6 +241,8 @@ extern uint32_t *pMEMAllocFromDefaultHeapEx; extern uint32_t *pMEMAllocFromDefaultHeap; extern uint32_t *pMEMFreeToDefaultHeap; + + void InitAcquireOS(); void InitOSFunctionPointers(void);