2016-12-12 19:31:02 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Copyright (C) 2015
|
|
|
|
* by Dimok
|
|
|
|
*
|
|
|
|
* This software is provided 'as-is', without any express or implied
|
|
|
|
* warranty. In no event will the authors be held liable for any
|
|
|
|
* damages arising from the use of this software.
|
|
|
|
*
|
|
|
|
* Permission is granted to anyone to use this software for any
|
|
|
|
* purpose, including commercial applications, and to alter it and
|
|
|
|
* redistribute it freely, subject to the following restrictions:
|
|
|
|
*
|
|
|
|
* 1. The origin of this software must not be misrepresented; you
|
|
|
|
* must not claim that you wrote the original software. If you use
|
|
|
|
* this software in a product, an acknowledgment in the product
|
|
|
|
* documentation would be appreciated but is not required.
|
|
|
|
*
|
|
|
|
* 2. Altered source versions must be plainly marked as such, and
|
|
|
|
* must not be misrepresented as being the original software.
|
|
|
|
*
|
|
|
|
* 3. This notice may not be removed or altered from any source
|
|
|
|
* distribution.
|
|
|
|
***************************************************************************/
|
|
|
|
#include "common/common.h"
|
|
|
|
#include "os_functions.h"
|
|
|
|
|
|
|
|
unsigned int coreinit_handle __attribute__((section(".data"))) = 0;
|
|
|
|
|
|
|
|
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
//! Lib handle functions
|
|
|
|
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
EXPORT_DECL(int, OSDynLoad_Acquire, const char* rpl, u32 *handle);
|
|
|
|
EXPORT_DECL(int, OSDynLoad_FindExport, u32 handle, int isdata, const char *symbol, void *address);
|
|
|
|
|
|
|
|
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
//! Security functions
|
|
|
|
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
EXPORT_DECL(int, OSGetSecurityLevel, void);
|
|
|
|
EXPORT_DECL(int, OSForceFullRelaunch, void);
|
2021-12-30 20:14:25 +01:00
|
|
|
EXPORT_DECL(void, OSShutdown, void);
|
2016-12-12 19:31:02 +01:00
|
|
|
|
|
|
|
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
//! Thread functions
|
|
|
|
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
EXPORT_DECL(int, OSCreateThread, void *thread, s32 (*callback)(s32, void*), s32 argc, void *args, u32 stack, u32 stack_size, s32 priority, u32 attr);
|
|
|
|
EXPORT_DECL(int, OSResumeThread, void *thread);
|
|
|
|
EXPORT_DECL(int, OSSuspendThread, void *thread);
|
|
|
|
EXPORT_DECL(int, OSIsThreadTerminated, void *thread);
|
|
|
|
EXPORT_DECL(int, OSIsThreadSuspended, void *thread);
|
|
|
|
EXPORT_DECL(int, OSSetThreadPriority, void * thread, int priority);
|
|
|
|
EXPORT_DECL(int, OSJoinThread, void * thread, int * ret_val);
|
|
|
|
EXPORT_DECL(void, OSDetachThread, void * thread);
|
|
|
|
EXPORT_DECL(void, OSSleepTicks, u64 ticks);
|
|
|
|
EXPORT_DECL(u64, OSGetTick, void);
|
|
|
|
EXPORT_DECL(u64, OSGetTime, void);
|
|
|
|
EXPORT_DECL(void, OSTicksToCalendarTime, u64 time, OSCalendarTime * calendarTime);
|
|
|
|
|
|
|
|
|
|
|
|
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
//! Mutex functions
|
|
|
|
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
EXPORT_DECL(void, OSInitMutex, void* mutex);
|
|
|
|
EXPORT_DECL(void, OSLockMutex, void* mutex);
|
|
|
|
EXPORT_DECL(void, OSUnlockMutex, void* mutex);
|
|
|
|
EXPORT_DECL(int, OSTryLockMutex, void* mutex);
|
|
|
|
|
|
|
|
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
//! System functions
|
|
|
|
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
EXPORT_DECL(u64, OSGetTitleID, void);
|
|
|
|
EXPORT_DECL(void, OSGetArgcArgv, int* argc, char*** argv);
|
2020-12-15 22:29:45 +01:00
|
|
|
EXPORT_DECL(void, __Exit, int);
|
2020-12-14 20:48:49 +01:00
|
|
|
EXPORT_DECL(void, OSSavesDone_ReadyToRelease, void);
|
2016-12-12 19:31:02 +01:00
|
|
|
EXPORT_DECL(void, OSFatal, const char* msg);
|
|
|
|
EXPORT_DECL(void, OSSetExceptionCallback, u8 exceptionType, exception_callback newCallback);
|
|
|
|
EXPORT_DECL(void, DCFlushRange, const void *addr, u32 length);
|
|
|
|
EXPORT_DECL(void, DCStoreRange, const void *addr, u32 length);
|
|
|
|
EXPORT_DECL(void, DCInvalidateRange, const void *addr, u32 length);
|
|
|
|
EXPORT_DECL(void, ICInvalidateRange, const void *addr, u32 length);
|
|
|
|
EXPORT_DECL(void*, OSEffectiveToPhysical, const void*);
|
|
|
|
EXPORT_DECL(int, __os_snprintf, char* s, int n, const char * format, ...);
|
|
|
|
EXPORT_DECL(int *, __gh_errno_ptr, void);
|
|
|
|
|
|
|
|
EXPORT_DECL(void, OSScreenInit, void);
|
|
|
|
EXPORT_DECL(void, OSScreenShutdown, void);
|
|
|
|
EXPORT_DECL(unsigned int, OSScreenGetBufferSizeEx, unsigned int bufferNum);
|
|
|
|
EXPORT_DECL(int, OSScreenSetBufferEx, unsigned int bufferNum, void * addr);
|
|
|
|
EXPORT_DECL(int, OSScreenClearBufferEx, unsigned int bufferNum, unsigned int temp);
|
|
|
|
EXPORT_DECL(int, OSScreenFlipBuffersEx, unsigned int bufferNum);
|
|
|
|
EXPORT_DECL(int, OSScreenPutFontEx, unsigned int bufferNum, unsigned int posX, unsigned int posY, const char * buffer);
|
|
|
|
EXPORT_DECL(int, OSScreenEnableEx, unsigned int bufferNum, int enable);
|
|
|
|
|
|
|
|
EXPORT_DECL(int, IOS_Ioctl,int fd, unsigned int request, void *input_buffer,unsigned int input_buffer_len, void *output_buffer, unsigned int output_buffer_len);
|
|
|
|
EXPORT_DECL(int, IOS_Open,char *path, unsigned int mode);
|
|
|
|
EXPORT_DECL(int, IOS_Close,int fd);
|
|
|
|
|
|
|
|
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
//! Memory functions
|
|
|
|
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
EXPORT_VAR(unsigned int *, pMEMAllocFromDefaultHeapEx);
|
|
|
|
EXPORT_VAR(unsigned int *, pMEMAllocFromDefaultHeap);
|
|
|
|
EXPORT_VAR(unsigned int *, pMEMFreeToDefaultHeap);
|
|
|
|
|
|
|
|
EXPORT_DECL(int, MEMGetBaseHeapHandle, int mem_arena);
|
|
|
|
EXPORT_DECL(unsigned int, MEMGetAllocatableSizeForFrmHeapEx, int heap, int align);
|
|
|
|
EXPORT_DECL(void *, MEMAllocFromFrmHeapEx, int heap, unsigned int size, int align);
|
|
|
|
EXPORT_DECL(void, MEMFreeToFrmHeap, int heap, int mode);
|
|
|
|
EXPORT_DECL(void *, MEMAllocFromExpHeapEx, int heap, unsigned int size, int align);
|
|
|
|
EXPORT_DECL(int , MEMCreateExpHeapEx, void* address, unsigned int size, unsigned short flags);
|
|
|
|
EXPORT_DECL(void *, MEMDestroyExpHeap, int heap);
|
|
|
|
EXPORT_DECL(void, MEMFreeToExpHeap, int heap, void* ptr);
|
|
|
|
|
|
|
|
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
//! MCP functions
|
|
|
|
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
EXPORT_DECL(int, MCP_Open, void);
|
|
|
|
EXPORT_DECL(int, MCP_Close, int handle);
|
|
|
|
EXPORT_DECL(int, MCP_GetOwnTitleInfo, int handle, void * data);
|
|
|
|
|
|
|
|
|
|
|
|
void InitAcquireOS(void)
|
|
|
|
{
|
|
|
|
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
//! Lib handle functions
|
|
|
|
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
2020-12-14 20:48:49 +01:00
|
|
|
EXPORT_FUNC_WRITE(OSDynLoad_Acquire, (int (*)(const char*, unsigned *))0x0102A3B4);
|
|
|
|
EXPORT_FUNC_WRITE(OSDynLoad_FindExport, (int (*)(u32, int, const char *, void *))0x0102B828);
|
2016-12-12 19:31:02 +01:00
|
|
|
|
|
|
|
OSDynLoad_Acquire("coreinit.rpl", &coreinit_handle);
|
|
|
|
}
|
|
|
|
|
|
|
|
void InitOSFunctionPointers(void)
|
|
|
|
{
|
|
|
|
unsigned int *funcPointer = 0;
|
|
|
|
|
|
|
|
InitAcquireOS();
|
|
|
|
|
|
|
|
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
//! Security functions
|
|
|
|
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
OS_FIND_EXPORT(coreinit_handle, OSGetSecurityLevel);
|
|
|
|
OS_FIND_EXPORT(coreinit_handle, OSForceFullRelaunch);
|
2021-12-30 20:14:25 +01:00
|
|
|
OS_FIND_EXPORT(coreinit_handle, OSShutdown);
|
2016-12-12 19:31:02 +01:00
|
|
|
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
//! System functions
|
|
|
|
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
OS_FIND_EXPORT(coreinit_handle, OSFatal);
|
|
|
|
OS_FIND_EXPORT(coreinit_handle, OSGetTitleID);
|
|
|
|
OS_FIND_EXPORT(coreinit_handle, OSGetArgcArgv);
|
2020-12-14 20:48:49 +01:00
|
|
|
OS_FIND_EXPORT(coreinit_handle, OSSavesDone_ReadyToRelease);
|
2016-12-12 19:31:02 +01:00
|
|
|
OS_FIND_EXPORT(coreinit_handle, OSSetExceptionCallback);
|
|
|
|
OS_FIND_EXPORT(coreinit_handle, DCFlushRange);
|
|
|
|
OS_FIND_EXPORT(coreinit_handle, DCStoreRange);
|
|
|
|
OS_FIND_EXPORT(coreinit_handle, DCInvalidateRange);
|
|
|
|
OS_FIND_EXPORT(coreinit_handle, ICInvalidateRange);
|
|
|
|
OS_FIND_EXPORT(coreinit_handle, OSEffectiveToPhysical);
|
|
|
|
OS_FIND_EXPORT(coreinit_handle, __os_snprintf);
|
|
|
|
OS_FIND_EXPORT(coreinit_handle, __gh_errno_ptr);
|
|
|
|
|
2020-12-15 22:29:45 +01:00
|
|
|
OSDynLoad_FindExport(coreinit_handle, 0, "exit", &__Exit);
|
2016-12-12 19:31:02 +01:00
|
|
|
|
|
|
|
OS_FIND_EXPORT(coreinit_handle, OSScreenInit);
|
|
|
|
OS_FIND_EXPORT(coreinit_handle, OSScreenShutdown);
|
|
|
|
OS_FIND_EXPORT(coreinit_handle, OSScreenGetBufferSizeEx);
|
|
|
|
OS_FIND_EXPORT(coreinit_handle, OSScreenSetBufferEx);
|
|
|
|
OS_FIND_EXPORT(coreinit_handle, OSScreenClearBufferEx);
|
|
|
|
OS_FIND_EXPORT(coreinit_handle, OSScreenFlipBuffersEx);
|
|
|
|
OS_FIND_EXPORT(coreinit_handle, OSScreenPutFontEx);
|
|
|
|
OS_FIND_EXPORT(coreinit_handle, OSScreenEnableEx);
|
|
|
|
|
|
|
|
OS_FIND_EXPORT(coreinit_handle, IOS_Ioctl);
|
|
|
|
OS_FIND_EXPORT(coreinit_handle, IOS_Open);
|
|
|
|
OS_FIND_EXPORT(coreinit_handle, IOS_Close);
|
|
|
|
|
|
|
|
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
//! Thread functions
|
|
|
|
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
OS_FIND_EXPORT(coreinit_handle, OSCreateThread);
|
|
|
|
OS_FIND_EXPORT(coreinit_handle, OSResumeThread);
|
|
|
|
OS_FIND_EXPORT(coreinit_handle, OSSuspendThread);
|
|
|
|
OS_FIND_EXPORT(coreinit_handle, OSIsThreadTerminated);
|
|
|
|
OS_FIND_EXPORT(coreinit_handle, OSIsThreadSuspended);
|
|
|
|
OS_FIND_EXPORT(coreinit_handle, OSJoinThread);
|
|
|
|
OS_FIND_EXPORT(coreinit_handle, OSSetThreadPriority);
|
|
|
|
OS_FIND_EXPORT(coreinit_handle, OSDetachThread);
|
|
|
|
OS_FIND_EXPORT(coreinit_handle, OSSleepTicks);
|
|
|
|
OS_FIND_EXPORT(coreinit_handle, OSGetTick);
|
|
|
|
OS_FIND_EXPORT(coreinit_handle, OSGetTime);
|
|
|
|
OS_FIND_EXPORT(coreinit_handle, OSTicksToCalendarTime);
|
|
|
|
|
|
|
|
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
//! Mutex functions
|
|
|
|
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
OS_FIND_EXPORT(coreinit_handle, OSInitMutex);
|
|
|
|
OS_FIND_EXPORT(coreinit_handle, OSLockMutex);
|
|
|
|
OS_FIND_EXPORT(coreinit_handle, OSUnlockMutex);
|
|
|
|
OS_FIND_EXPORT(coreinit_handle, OSTryLockMutex);
|
|
|
|
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
//! MCP functions
|
|
|
|
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
OS_FIND_EXPORT(coreinit_handle, MCP_Open);
|
|
|
|
OS_FIND_EXPORT(coreinit_handle, MCP_Close);
|
|
|
|
OS_FIND_EXPORT(coreinit_handle, MCP_GetOwnTitleInfo);
|
|
|
|
|
|
|
|
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
//! Memory functions
|
|
|
|
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
|
|
|
OSDynLoad_FindExport(coreinit_handle, 1, "MEMAllocFromDefaultHeapEx", &pMEMAllocFromDefaultHeapEx);
|
|
|
|
OSDynLoad_FindExport(coreinit_handle, 1, "MEMAllocFromDefaultHeap", &pMEMAllocFromDefaultHeap);
|
|
|
|
OSDynLoad_FindExport(coreinit_handle, 1, "MEMFreeToDefaultHeap", &pMEMFreeToDefaultHeap);
|
|
|
|
|
|
|
|
OS_FIND_EXPORT(coreinit_handle, MEMGetBaseHeapHandle);
|
|
|
|
OS_FIND_EXPORT(coreinit_handle, MEMGetAllocatableSizeForFrmHeapEx);
|
|
|
|
OS_FIND_EXPORT(coreinit_handle, MEMAllocFromFrmHeapEx);
|
|
|
|
OS_FIND_EXPORT(coreinit_handle, MEMFreeToFrmHeap);
|
|
|
|
OS_FIND_EXPORT(coreinit_handle, MEMAllocFromExpHeapEx);
|
|
|
|
OS_FIND_EXPORT(coreinit_handle, MEMCreateExpHeapEx);
|
|
|
|
OS_FIND_EXPORT(coreinit_handle, MEMDestroyExpHeap);
|
|
|
|
OS_FIND_EXPORT(coreinit_handle, MEMFreeToExpHeap);
|
|
|
|
}
|