Merge pull request #3877 from aliaspider/master

(WIIU) update.
This commit is contained in:
Twinaphex 2016-10-28 01:53:43 +02:00 committed by GitHub
commit 453155ade3
40 changed files with 1484 additions and 132 deletions

View File

@ -12,6 +12,7 @@ OBJ += wiiu/dynamic_libs/fs_functions.o
OBJ += wiiu/dynamic_libs/padscore_functions.o
OBJ += wiiu/dynamic_libs/vpad_functions.o
OBJ += wiiu/system/memory.o
OBJ += wiiu/system/exception_handler.o
OBJ += wiiu/dynamic_libs/gx2_functions.o
OBJ += wiiu/dynamic_libs/socket_functions.o
OBJ += wiiu/fs/fs_utils.o
@ -100,20 +101,20 @@ LIBDIRS := -L.
CFLAGS := -mrvl -mcpu=750 -meabi -mhard-float
LDFLAGS :=
#LDFLAGS := $(CFLAGS)
ifeq ($(DEBUG), 1)
CFLAGS += -O0 -g
else
CFLAGS += -O3
endif
LDFLAGS := $(CFLAGS)
ASFLAGS := $(CFLAGS) -mregnames
CFLAGS += -ffast-math -Werror=implicit-function-declaration
#CFLAGS += -fomit-frame-pointer -mword-relocations
#CFLAGS += -Wall
CFLAGS += -DWIIU
CFLAGS += -DWIIU -DMSB_FIRST
CFLAGS += -DHAVE_MAIN
CFLAGS += -DRARCH_INTERNAL -DRARCH_CONSOLE -DSINC_LOWEST_QUALITY
CFLAGS += -DHAVE_FILTERS_BUILTIN $(DEFINES)

View File

@ -43,10 +43,15 @@
#include "dynamic_libs/vpad_functions.h"
#include "dynamic_libs/padscore_functions.h"
#include "dynamic_libs/socket_functions.h"
//#include "dynamic_libs/curl_functions.h"
#include "dynamic_libs/ax_functions.h"
//#include "dynamic_libs/aoc_functions.h"
//#include "dynamic_libs/acp_functions.h"
#include "fs/fs_utils.h"
#include "fs/sd_fat_devoptab.h"
#include "system/memory.h"
#include "system/exception_handler.h"
#include "system/exception.h"
#include "utils/logger.h"
#include "utils/utils.h"
#include "common/common.h"
@ -224,6 +229,10 @@ static int log_write(struct _reent *r, int fd, const char *ptr, size_t len)
return len;
}
void net_print(const char* str)
{
log_write(NULL, 0, str, strlen(str));
}
static devoptab_t dotab_stdout = {
"stdout", // device name
@ -257,13 +266,24 @@ int __entry_menu(int argc, char **argv)
InitSocketFunctionPointers();
log_init("10.42.0.1");
devoptab_list[STD_OUT] = &dotab_stdout;
devoptab_list[STD_ERR] = &dotab_stdout;
InitFSFunctionPointers();
InitGX2FunctionPointers();
InitSysFunctionPointers();
InitVPadFunctionPointers();
InitPadScoreFunctionPointers();
InitAXFunctionPointers();
// InitCurlFunctionPointers();
// InitAocFunctionPointers();
// InitACPFunctionPointers();
memoryInitialize();
mount_sd_fat("sd");
// setup_os_exceptions();
InstallExceptionHandler();
VPADInit();
OSScreenInit();
@ -287,8 +307,8 @@ int __entry_menu(int argc, char **argv)
unsigned sleep_ms = 0;
int ret = runloop_iterate(&sleep_ms);
if (ret == 1 && sleep_ms > 0)
retro_sleep(sleep_ms);
// if (ret == 1 && sleep_ms > 0)
// retro_sleep(sleep_ms);
task_queue_ctl(TASK_QUEUE_CTL_CHECK, NULL);
if (ret == -1)
break;

View File

@ -37,6 +37,9 @@ static frontend_ctx_driver_t *frontend_ctx_drivers[] = {
#if defined(GEKKO)
&frontend_ctx_gx,
#endif
#if defined(WIIU)
&frontend_ctx_wiiu,
#endif
#if defined(__QNX__)
&frontend_ctx_qnx,
#endif

View File

@ -92,6 +92,7 @@ typedef struct frontend_ctx_driver
} frontend_ctx_driver_t;
extern frontend_ctx_driver_t frontend_ctx_gx;
extern frontend_ctx_driver_t frontend_ctx_wiiu;
extern frontend_ctx_driver_t frontend_ctx_ps3;
extern frontend_ctx_driver_t frontend_ctx_xdk;
extern frontend_ctx_driver_t frontend_ctx_qnx;

View File

@ -39,22 +39,23 @@ typedef struct
int width;
int height;
bool enable;
}menu;
} menu;
void* texture;
int tex_width;
int tex_height;
}wiiu_video_t;
} wiiu_video_t;
static void *wiiu_gfx_init(const video_info_t *video,
const input_driver_t **input, void **input_data)
static void* wiiu_gfx_init(const video_info_t* video,
const input_driver_t** input, void** input_data)
{
*input = NULL;
*input_data = NULL;
wiiu_video_t* wiiu = calloc(1, sizeof(*wiiu));
if(!wiiu)
if (!wiiu)
return NULL;
wiiu->screen_buffer0_size = OSScreenGetBufferSizeEx(0);
@ -101,11 +102,11 @@ static void *wiiu_gfx_init(const video_info_t *video,
return wiiu;
}
static void wiiu_gfx_free(void *data)
static void wiiu_gfx_free(void* data)
{
wiiu_video_t* wiiu = (wiiu_video_t*) data;
if(!wiiu)
if (!wiiu)
return;
MEM1_free(wiiu->screen_buffer0);
@ -117,9 +118,9 @@ static void wiiu_gfx_free(void *data)
}
static bool wiiu_gfx_frame(void *data, const void *frame,
unsigned width, unsigned height, uint64_t frame_count,
unsigned pitch, const char *msg)
static bool wiiu_gfx_frame(void* data, const void* frame,
unsigned width, unsigned height, uint64_t frame_count,
unsigned pitch, const char* msg)
{
(void)frame;
(void)width;
@ -135,33 +136,51 @@ static bool wiiu_gfx_frame(void *data, const void *frame,
snprintf(frames_str, sizeof(frames_str), "frames : %i", frames++);
OSScreenClearBufferEx(1, 0);
// OSScreenPutFontEx(1, 0, 0, "Hello world on DRC!!!");
const uint16_t* src = (uint16_t*)wiiu->menu.texture;
uint32_t* dst = (uint32_t*)((uint8_t*)wiiu->screen_buffer1 + wiiu->screen_buffer1_id * wiiu->screen_buffer1_size / 2);
// for (i = 0; i < wiiu->menu.height; i++)
// {
// memcpy(dst, src, wiiu->menu.width * sizeof(uint16_t));
// dst += 896;
// src += wiiu->menu.tex_width;
// }
dst += 896 * (480 - wiiu->menu.height) / 2 + (896 - wiiu->menu.width) / 2;
int x, y;
for(y = 0; y < wiiu->menu.height; y++)
if (wiiu->menu.enable)
{
for(x = 0; x < wiiu->menu.width; x++)
const uint16_t* src = (uint16_t*)wiiu->menu.texture;
uint32_t* dst = (uint32_t*)((uint8_t*)wiiu->screen_buffer1 + wiiu->screen_buffer1_id * wiiu->screen_buffer1_size / 2);
dst += 896 * (480 - wiiu->menu.height) / 2 + (896 - wiiu->menu.width) / 2;
int x, y;
for (y = 0; y < wiiu->menu.height; y++)
{
int r = ((src[x] >> 12) & 0xF) << 4;
int g = ((src[x] >> 8) & 0xF) << 4;
int b = ((src[x] >> 4) & 0xF) << 4;
// r = 0;
// g = 0;
// b = 0;
dst[x] = (r << 0) | (b << 8) | (g << 16);
for (x = 0; x < wiiu->menu.width; x++)
{
int r = ((src[x] >> 12) & 0xF) << 4;
int g = ((src[x] >> 8) & 0xF) << 4;
int b = ((src[x] >> 4) & 0xF) << 4;
dst[x] = (r << 0) | (b << 8) | (g << 16);
}
src += wiiu->menu.tex_width;
dst += 896;
}
}
else
{
const uint16_t* src = (uint16_t*)frame;
uint32_t* dst = (uint32_t*)((uint8_t*)wiiu->screen_buffer1 + wiiu->screen_buffer1_id * wiiu->screen_buffer1_size / 2);
dst += (896 * (480 - height) + width) / 2;
int x, y;
for (y = 0; y < height; y++)
{
for (x = 0; x < width; x++)
{
int r = ((src[x] >> 11) & 0x1F) << 3;
int g = ((src[x] >> 5) & 0x3F) << 2;
int b = ((src[x] >> 0) & 0x1F) << 3;
dst[x] = (r << 0) | (b << 8) | (g << 16);
}
src += pitch/2;
dst += 896;
}
src += wiiu->menu.tex_width;
dst += 896;
}
@ -177,39 +196,39 @@ static bool wiiu_gfx_frame(void *data, const void *frame,
return true;
}
static void wiiu_gfx_set_nonblock_state(void *data, bool toggle)
static void wiiu_gfx_set_nonblock_state(void* data, bool toggle)
{
(void)data;
(void)toggle;
}
static bool wiiu_gfx_alive(void *data)
static bool wiiu_gfx_alive(void* data)
{
(void)data;
return true;
}
static bool wiiu_gfx_focus(void *data)
static bool wiiu_gfx_focus(void* data)
{
(void)data;
return true;
}
static bool wiiu_gfx_suppress_screensaver(void *data, bool enable)
static bool wiiu_gfx_suppress_screensaver(void* data, bool enable)
{
(void)data;
(void)enable;
return false;
}
static bool wiiu_gfx_has_windowed(void *data)
static bool wiiu_gfx_has_windowed(void* data)
{
(void)data;
return true;
}
static bool wiiu_gfx_set_shader(void *data,
enum rarch_shader_type type, const char *path)
static bool wiiu_gfx_set_shader(void* data,
enum rarch_shader_type type, const char* path)
{
(void)data;
(void)type;
@ -218,21 +237,21 @@ static bool wiiu_gfx_set_shader(void *data,
return false;
}
static void wiiu_gfx_set_rotation(void *data,
unsigned rotation)
static void wiiu_gfx_set_rotation(void* data,
unsigned rotation)
{
(void)data;
(void)rotation;
}
static void wiiu_gfx_viewport_info(void *data,
struct video_viewport *vp)
static void wiiu_gfx_viewport_info(void* data,
struct video_viewport* vp)
{
(void)data;
(void)vp;
}
static bool wiiu_gfx_read_viewport(void *data, uint8_t *buffer)
static bool wiiu_gfx_read_viewport(void* data, uint8_t* buffer)
{
(void)data;
(void)buffer;
@ -240,12 +259,12 @@ static bool wiiu_gfx_read_viewport(void *data, uint8_t *buffer)
return true;
}
static uintptr_t wiiu_load_texture(void *video_data, void *data,
bool threaded, enum texture_filter_type filter_type)
static uintptr_t wiiu_load_texture(void* video_data, void* data,
bool threaded, enum texture_filter_type filter_type)
{
return 0;
}
static void wiiu_unload_texture(void *data, uintptr_t handle)
static void wiiu_unload_texture(void* data, uintptr_t handle)
{
}
@ -271,19 +290,21 @@ static void wiiu_viewport_info(void* data, struct video_viewport* vp)
vp->y = 0;
}
static void wiiu_set_texture_frame(void* data, const void* frame, bool rgb32,
unsigned width, unsigned height, float alpha)
unsigned width, unsigned height, float alpha)
{
int i;
wiiu_video_t* wiiu = (wiiu_video_t*) data;
if(!wiiu)
if (!wiiu)
return;
if(!frame || !width || !height)
if (!frame || !width || !height)
return;
if(width > wiiu->menu.tex_width)
if (width > wiiu->menu.tex_width)
width = wiiu->menu.tex_width;
if(height > wiiu->menu.tex_height)
if (height > wiiu->menu.tex_height)
height = wiiu->menu.tex_height;
wiiu->menu.width = width;
@ -291,6 +312,7 @@ static void wiiu_set_texture_frame(void* data, const void* frame, bool rgb32,
const uint16_t* src = frame;
uint16_t* dst = (uint16_t*)wiiu->menu.texture;
for (i = 0; i < height; i++)
{
memcpy(dst, src, width * sizeof(uint16_t));
@ -307,8 +329,8 @@ static void wiiu_set_texture_enable(void* data, bool state, bool full_screen)
}
static void wiiu_set_osd_msg(void *data, const char *msg,
const struct font_params *params, void *font)
static void wiiu_set_osd_msg(void* data, const char* msg,
const struct font_params* params, void* font)
{
}
@ -337,8 +359,8 @@ static const video_poke_interface_t wiiu_poke_interface =
NULL
};
static void wiiu_gfx_get_poke_interface(void *data,
const video_poke_interface_t **iface)
static void wiiu_gfx_get_poke_interface(void* data,
const video_poke_interface_t** iface)
{
(void)data;
*iface = &wiiu_poke_interface;
@ -362,7 +384,7 @@ video_driver_t video_wiiu =
wiiu_gfx_read_viewport,
NULL, /* read_frame_raw */
#ifdef HAVE_OVERLAY
NULL, /* overlay_interface */
NULL, /* overlay_interface */
#endif
wiiu_gfx_get_poke_interface,
wiiu_gfx_get_poke_interface,
};

View File

@ -29,6 +29,7 @@
#include "string.h"
#include "dynamic_libs/vpad_functions.h"
#include "wiiu_dbg.h"
#ifndef MAX_PADS
#define MAX_PADS 1

View File

@ -0,0 +1,40 @@
/****************************************************************************
* 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 "os_functions.h"
#include "acp_functions.h"
unsigned int acp_handle __attribute__((section(".data"))) = 0;
EXPORT_DECL(void, GetMetaXml, void * _ACPMetaXml);
void InitAcquireACP(void)
{
OSDynLoad_Acquire("nn_acp.rpl", &acp_handle);
}
void InitACPFunctionPointers(void)
{
InitAcquireACP();
OSDynLoad_FindExport(acp_handle,0,"GetMetaXml__Q2_2nn3acpFP11_ACPMetaXml",&GetMetaXml);
}

View File

@ -0,0 +1,42 @@
/****************************************************************************
* 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.
***************************************************************************/
#ifndef __ACP_FUNCTIONS_H_
#define __ACP_FUNCTIONS_H_
#ifdef __cplusplus
extern "C" {
#endif
#include <gctypes.h>
extern unsigned int acp_handle;
void InitACPFunctionPointers(void);
void InitAcquireACP(void);
#ifdef __cplusplus
}
#endif
#endif // __VPAD_FUNCTIONS_H_

View File

@ -0,0 +1,58 @@
/****************************************************************************
* 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 "os_functions.h"
#include "aoc_functions.h"
unsigned int aoc_handle __attribute__((section(".data"))) = 0;
EXPORT_DECL(s32, AOC_Initialize, void);
EXPORT_DECL(s32, AOC_Finalize, void);
EXPORT_DECL(u32, AOC_CalculateWorkBufferSize, u32 num_titles);
EXPORT_DECL(s32, AOC_ListTitle, u32 * num_titles, void * titles, u32 max_titles, void * buffer, u32 buffer_size);
EXPORT_DECL(s32, AOC_OpenTitle, char* aoc_path, void * title, void * buffer, u32 buffer_size);
EXPORT_DECL(s32, AOC_CloseTitle, void * title);
EXPORT_DECL(s32, AOC_DeleteContent, u64 title_id, u16 contentIndexes[], u32 numberOfContent, void* buffer, u32 buffer_size);
EXPORT_DECL(s32, AOC_GetPurchaseInfo, u32 * bResult, u64 title_id, u16 contentIndexes[], u32 numberOfContent, void * buffer, u32 buffer_size);
void InitAcquireAoc(void)
{
OSDynLoad_Acquire("nn_aoc.rpl", &aoc_handle);
}
void InitAocFunctionPointers(void)
{
InitAcquireAoc();
if(aoc_handle == 0)
return;
//! assigning those is not mandatory and it does not always work to load them
OSDynLoad_FindExport(aoc_handle, 0, "AOC_Initialize", &AOC_Initialize);
OSDynLoad_FindExport(aoc_handle, 0, "AOC_Finalize", &AOC_Finalize);
OSDynLoad_FindExport(aoc_handle, 0, "AOC_CalculateWorkBufferSize", &AOC_CalculateWorkBufferSize);
OSDynLoad_FindExport(aoc_handle, 0, "AOC_ListTitle", &AOC_ListTitle);
OSDynLoad_FindExport(aoc_handle, 0, "AOC_OpenTitle", &AOC_OpenTitle);
OSDynLoad_FindExport(aoc_handle, 0, "AOC_CloseTitle", &AOC_CloseTitle);
OSDynLoad_FindExport(aoc_handle, 0, "AOC_DeleteContent", &AOC_DeleteContent);
OSDynLoad_FindExport(aoc_handle, 0, "AOC_GetPurchaseInfo", &AOC_GetPurchaseInfo);
}

View File

@ -0,0 +1,58 @@
/****************************************************************************
* 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.
***************************************************************************/
#ifndef __AOC_FUNCTIONS_H_
#define __AOC_FUNCTIONS_H_
#ifdef __cplusplus
extern "C" {
#endif
extern unsigned int aoc_handle;
#define AOC_TITLE_SIZE 104
typedef struct {
u64 title_ID;
u32 group_ID;
u16 version;
char path[88];
} AOC_TitleListType;
void InitAocFunctionPointers(void);
void InitAcquireAoc(void);
extern s32 (* AOC_Initialize)(void);
extern s32 (* AOC_Finalize)(void);
extern u32 (* AOC_CalculateWorkBufferSize)(u32 num_titles);
extern s32 (* AOC_ListTitle)(u32 * num_titles, void * titles, u32 max_titles, void * buffer, u32 buffer_size);
extern s32 (* AOC_OpenTitle)(char* aoc_path, void * title, void * buffer, u32 buffer_size);
extern s32 (* AOC_CloseTitle)(void * title);
extern s32 (* AOC_DeleteContent)(u64 title_id, u16 contentIndexes[], u32 numberOfContent, void * buffer, u32 buffer_size);
extern s32 (* AOC_GetPurchaseInfo)(u32 * bResult, u64 title_id, u16 contentIndexes[], u32 numberOfContent, void * buffer, u32 buffer_size);
#ifdef __cplusplus
}
#endif
#endif // __AOC_FUNCTIONS_H_

View File

@ -21,10 +21,14 @@
* 3. This notice may not be removed or altered from any source
* distribution.
***************************************************************************/
#include "common/common.h"
#include "os_functions.h"
#include "ax_functions.h"
unsigned int sound_handle __attribute__((section(".data"))) = 0;
EXPORT_DECL(void, AXInitWithParams, u32 * params);
EXPORT_DECL(void, AXInit, void);
EXPORT_DECL(void, AXQuit, void);
EXPORT_DECL(u32, AXGetInputSamplesPerSec, void);
EXPORT_DECL(u32, AXGetInputSamplesPerFrame, void);
@ -45,15 +49,35 @@ EXPORT_DECL(u32, AXGetVoiceLoopCount, void *v);
EXPORT_DECL(void, AXSetVoiceEndOffset, void *v, u32 offset);
EXPORT_DECL(void, AXSetVoiceLoopOffset, void *v, u32 offset);
void InitAcquireAX(void)
{
unsigned int *funcPointer = 0;
if(OS_FIRMWARE >= 400)
{
AXInit = 0;
OSDynLoad_Acquire("sndcore2.rpl", &sound_handle);
OS_FIND_EXPORT(sound_handle, AXInitWithParams);
OS_FIND_EXPORT(sound_handle, AXGetInputSamplesPerSec);
}
else
{
AXInitWithParams = 0;
AXGetInputSamplesPerSec = 0;
OSDynLoad_Acquire("snd_core.rpl", &sound_handle);
OS_FIND_EXPORT(sound_handle, AXInit);
}
}
void InitAXFunctionPointers(void)
{
unsigned int *funcPointer = 0;
unsigned int sound_handle;
OSDynLoad_Acquire("sndcore2.rpl", &sound_handle);
OS_FIND_EXPORT(sound_handle, AXInitWithParams);
InitAcquireAX();
OS_FIND_EXPORT(sound_handle, AXQuit);
OS_FIND_EXPORT(sound_handle, AXGetInputSamplesPerSec);
OS_FIND_EXPORT(sound_handle, AXVoiceBegin);
OS_FIND_EXPORT(sound_handle, AXVoiceEnd);
OS_FIND_EXPORT(sound_handle, AXSetVoiceType);
@ -72,3 +96,23 @@ void InitAXFunctionPointers(void)
OS_FIND_EXPORT(sound_handle, AXSetVoiceLoopOffset);
}
void ProperlyEndTransitionAudio(void)
{
bool (* check_os_audio_transition_flag_old)(void);
void (* AXInit_old)(void);
void (* AXQuit_old)(void);
unsigned int *funcPointer = 0;
unsigned int sound_handle;
OSDynLoad_Acquire("snd_core.rpl", &sound_handle);
OS_FIND_EXPORT_EX(sound_handle, check_os_audio_transition_flag, check_os_audio_transition_flag_old);
OS_FIND_EXPORT_EX(sound_handle, AXInit, AXInit_old);
OS_FIND_EXPORT_EX(sound_handle, AXQuit, AXQuit_old);
if (check_os_audio_transition_flag_old())
{
AXInit_old();
AXQuit_old();
}
}

View File

@ -30,9 +30,14 @@ extern "C" {
#include <gctypes.h>
extern unsigned int sound_handle;
void InitAXFunctionPointers(void);
void InitAcquireAX(void);
void ProperlyEndTransitionAudio(void);
extern void (* AXInitWithParams)(u32 * params);
extern void (* AXInit)(void);
extern void (* AXQuit)(void);
extern u32 (* AXGetInputSamplesPerSec)(void);
extern s32 (* AXVoiceBegin)(void *v);

View File

@ -0,0 +1,54 @@
/****************************************************************************
* 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 "os_functions.h"
#include "curl_functions.h"
unsigned int libcurl_handle __attribute__((section(".data"))) = 0;
EXPORT_DECL(CURLcode, n_curl_global_init, long flags);
EXPORT_DECL(CURL *, n_curl_easy_init, void);
EXPORT_DECL(CURLcode, n_curl_easy_setopt, CURL *curl, CURLoption option, ...);
EXPORT_DECL(CURLcode, n_curl_easy_perform, CURL *curl);
EXPORT_DECL(void, n_curl_easy_cleanup, CURL *curl);
EXPORT_DECL(CURLcode, n_curl_easy_getinfo, CURL *curl, CURLINFO info, ...);
void InitAcquireCurl(void)
{
OSDynLoad_Acquire("nlibcurl", &libcurl_handle);
}
void InitCurlFunctionPointers(void)
{
InitAcquireCurl();
unsigned int *funcPointer = 0;
OS_FIND_EXPORT_EX(libcurl_handle, curl_global_init, n_curl_global_init);
OS_FIND_EXPORT_EX(libcurl_handle, curl_easy_init, n_curl_easy_init);
OS_FIND_EXPORT_EX(libcurl_handle, curl_easy_setopt, n_curl_easy_setopt);
OS_FIND_EXPORT_EX(libcurl_handle, curl_easy_perform, n_curl_easy_perform);
OS_FIND_EXPORT_EX(libcurl_handle, curl_easy_cleanup, n_curl_easy_cleanup);
OS_FIND_EXPORT_EX(libcurl_handle, curl_easy_getinfo, n_curl_easy_getinfo);
n_curl_global_init(CURL_GLOBAL_ALL);
}

View File

@ -0,0 +1,51 @@
/****************************************************************************
* 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.
***************************************************************************/
#ifndef __CURL_FUNCTIONS_H_
#define __CURL_FUNCTIONS_H_
#ifdef __cplusplus
extern "C" {
#endif
#include <gctypes.h>
#include "socket_functions.h"
typedef int socklen_t;
#include <curl/curl.h>
#include <curl/easy.h>
void InitCurlFunctionPointers(void);
void InitAcquireCurl(void);
extern CURLcode (* n_curl_global_init)(long flags);
extern CURL * (* n_curl_easy_init)(void);
extern CURLcode (* n_curl_easy_setopt)(CURL *curl, CURLoption option, ...);
extern CURLcode (* n_curl_easy_perform)(CURL *curl);
extern void (* n_curl_easy_cleanup)(CURL *curl);
extern CURLcode (* n_curl_easy_getinfo)(CURL *curl, CURLINFO info, ...);
#ifdef __cplusplus
}
#endif
#endif // __CURL_FUNCTIONS_H_

View File

@ -0,0 +1,61 @@
#ifndef FS_DEFS_H
#define FS_DEFS_H
#include <gctypes.h>
#ifdef __cplusplus
extern "C" {
#endif
/* FS defines and types */
#define FS_MAX_LOCALPATH_SIZE 511
#define FS_MAX_MOUNTPATH_SIZE 128
#define FS_MAX_FULLPATH_SIZE (FS_MAX_LOCALPATH_SIZE + FS_MAX_MOUNTPATH_SIZE)
#define FS_MAX_ARGPATH_SIZE FS_MAX_FULLPATH_SIZE
#define FS_STATUS_OK 0
#define FS_RET_UNSUPPORTED_CMD 0x0400
#define FS_RET_NO_ERROR 0x0000
#define FS_RET_ALL_ERROR (unsigned int)(-1)
#define FS_STAT_FLAG_IS_DIRECTORY 0x80000000
/* max length of file/dir name */
#define FS_MAX_ENTNAME_SIZE 256
#define FS_SOURCETYPE_EXTERNAL 0
#define FS_SOURCETYPE_HFIO 1
#define FS_MOUNT_SOURCE_SIZE 0x300
#define FS_CLIENT_SIZE 0x1700
#define FS_CMD_BLOCK_SIZE 0xA80
typedef struct
{
uint32_t flag;
uint32_t permission;
uint32_t owner_id;
uint32_t group_id;
uint32_t size;
uint32_t alloc_size;
uint64_t quota_size;
uint32_t ent_id;
uint64_t ctime;
uint64_t mtime;
uint8_t attributes[48];
} __attribute__((packed)) FSStat;
typedef struct
{
FSStat stat;
char name[FS_MAX_ENTNAME_SIZE];
} FSDirEntry;
#ifdef __cplusplus
}
#endif
#endif /* FS_DEFS_H */

View File

@ -23,7 +23,6 @@
***************************************************************************/
#include "fs_functions.h"
#include "os_functions.h"
#include "utils/utils.h"
EXPORT_DECL(int, FSInit, void);
EXPORT_DECL(int, FSShutdown, void);
@ -69,6 +68,12 @@ EXPORT_DECL(int, FSGetStatFile, void *pClient, void *pCmd, int fd, void *buffer,
EXPORT_DECL(int, FSSetPosFile, void *pClient, void *pCmd, int fd, int pos, int error);
EXPORT_DECL(int, FSWriteFile, void *pClient, void *pCmd, const void *source, int block_size, int block_count, int fd, int flag, int error);
EXPORT_DECL(int, FSBindMount, void *pClient, void *pCmd, char *source, char *target, int error);
EXPORT_DECL(int, FSBindUnmount, void *pClient, void *pCmd, char *target, int error);
EXPORT_DECL(int, FSMakeQuota, void *pClient, void *pCmd, const char *path,u32 mode, u64 size, int errHandling);
EXPORT_DECL(int, FSMakeQuotaAsync ,void *pClient, void *pCmd, const char *path,u32 mode, u64 size, int errHandling,const void *asyncParams);
void InitFSFunctionPointers(void)
{
unsigned int *funcPointer = 0;
@ -117,4 +122,10 @@ void InitFSFunctionPointers(void)
OS_FIND_EXPORT(coreinit_handle, FSGetStatFile);
OS_FIND_EXPORT(coreinit_handle, FSSetPosFile);
OS_FIND_EXPORT(coreinit_handle, FSWriteFile);
OS_FIND_EXPORT(coreinit_handle, FSBindMount);
OS_FIND_EXPORT(coreinit_handle, FSBindUnmount);
OS_FIND_EXPORT(coreinit_handle, FSMakeQuota);
OS_FIND_EXPORT(coreinit_handle, FSMakeQuotaAsync);
}

View File

@ -28,7 +28,8 @@
extern "C" {
#endif
#include "common/fs_defs.h"
#include <gctypes.h>
#include "fs_defs.h"
void InitFSFunctionPointers(void);
@ -80,6 +81,13 @@ extern int (* FSGetStatFile)(void *pClient, void *pCmd, int fd, void *buffer, in
extern int (* FSSetPosFile)(void *pClient, void *pCmd, int fd, int pos, int error);
extern int (* FSWriteFile)(void *pClient, void *pCmd, const void *source, int block_size, int block_count, int fd, int flag, int error);
extern int (* FSBindMount)(void *pClient, void *pCmd, char *source, char *target, int error);
extern int (* FSBindUnmount)(void *pClient, void *pCmd, char *target, int error);
extern int (* FSMakeQuota)( void *pClient, void *pCmd, const char *path,u32 mode, u64 size, int errHandling);
extern int (* FSMakeQuotaAsync)(void *pClient, void *pCmd, const char *path,u32 mode, u64 size, int errHandling,const void *asyncParams);
#ifdef __cplusplus
}
#endif

View File

@ -23,7 +23,8 @@
***************************************************************************/
#include "os_functions.h"
#include "gx2_types.h"
#include "utils/utils.h"
unsigned int gx2_handle __attribute__((section(".data"))) = 0;
EXPORT_DECL(void, GX2Init, u32 * init_attribs);
EXPORT_DECL(void, GX2Shutdown, void);
@ -37,6 +38,7 @@ EXPORT_DECL(void, GX2SetContextState, const GX2ContextState* state);
EXPORT_DECL(void, GX2DrawEx, s32 primitive_type, u32 count, u32 first_vertex, u32 instances_count);
EXPORT_DECL(void, GX2DrawIndexedEx, s32 primitive_type, u32 count, s32 index_format, const void* idx, u32 first_vertex, u32 instances_count);
EXPORT_DECL(void, GX2ClearDepthStencilEx, GX2DepthBuffer *depthBuffer, f32 depth_value, u8 stencil_value, s32 clear_mode);
EXPORT_DECL(void, GX2SetClearDepthStencil, GX2DepthBuffer *depthBuffer, f32 depth_value, u8 stencil_value);
EXPORT_DECL(void, GX2CopyColorBufferToScanBuffer, const GX2ColorBuffer *colorBuffer, s32 scan_target);
EXPORT_DECL(void, GX2SwapScanBuffers, void);
EXPORT_DECL(void, GX2SetTVEnable, s32 enable);
@ -89,13 +91,19 @@ EXPORT_DECL(void, GX2SetDRCGamma, f32 gam);
EXPORT_DECL(s32, GX2GetSystemTVScanMode, void);
EXPORT_DECL(s32, GX2GetSystemDRCScanMode, void);
EXPORT_DECL(void, GX2RSetAllocator, void * (* allocFunc)(u32, u32, u32), void (* freeFunc)(u32, void*));
EXPORT_DECL(void, GX2CopySurface, GX2Surface * srcSurface,u32 srcMip,u32 srcSlice,GX2Surface * dstSurface,u32 dstMip,u32 dstSlice );
EXPORT_DECL(void, GX2ClearBuffersEx, GX2ColorBuffer * colorBuffer,GX2DepthBuffer * depthBuffer,f32 r, f32 g, f32 b, f32 a,f32 depthValue,u8 stencilValue,int clearFlags);
void InitAcquireGX2(void)
{
OSDynLoad_Acquire("gx2.rpl", &gx2_handle);
}
void InitGX2FunctionPointers(void)
{
unsigned int *funcPointer = 0;
unsigned int gx2_handle;
OSDynLoad_Acquire("gx2.rpl", &gx2_handle);
InitAcquireGX2();
OS_FIND_EXPORT(gx2_handle, GX2Init);
OS_FIND_EXPORT(gx2_handle, GX2Shutdown);
@ -159,4 +167,7 @@ void InitGX2FunctionPointers(void)
OS_FIND_EXPORT(gx2_handle, GX2GetSystemTVScanMode);
OS_FIND_EXPORT(gx2_handle, GX2GetSystemDRCScanMode);
OS_FIND_EXPORT(gx2_handle, GX2RSetAllocator);
OS_FIND_EXPORT(gx2_handle, GX2CopySurface);
OS_FIND_EXPORT(gx2_handle, GX2ClearBuffersEx);
OS_FIND_EXPORT(gx2_handle, GX2SetClearDepthStencil);
}

View File

@ -30,7 +30,10 @@ extern "C" {
#include "gx2_types.h"
extern unsigned int gx2_handle;
void InitGX2FunctionPointers(void);
void InitAcquireGX2(void);
extern void (* GX2Init)(u32 * init_attribs);
extern void (* GX2Shutdown)(void);
@ -44,6 +47,7 @@ extern void (* GX2SetContextState)(const GX2ContextState* state);
extern void (* GX2DrawEx)(s32 primitive_type, u32 count, u32 first_vertex, u32 instances_count);
extern void (* GX2DrawIndexedEx)(s32 primitive_type, u32 count, s32 index_format, const void* idx, u32 first_vertex, u32 instances_count);
extern void (* GX2ClearDepthStencilEx)(GX2DepthBuffer *depthBuffer, f32 depth_value, u8 stencil_value, s32 clear_mode);
extern void (* GX2SetClearDepthStencil)(GX2DepthBuffer *depthBuffer, f32 depth_value, u8 stencil_value);
extern void (* GX2CopyColorBufferToScanBuffer)(const GX2ColorBuffer *colorBuffer, s32 scan_target);
extern void (* GX2SwapScanBuffers)(void);
extern void (* GX2SetTVEnable)(s32 enable);
@ -96,6 +100,8 @@ extern void (* GX2SetDRCGamma)(f32 val);
extern s32 (* GX2GetSystemTVScanMode)(void);
extern s32 (* GX2GetSystemDRCScanMode)(void);
extern void (* GX2RSetAllocator)(void * (*allocFunc)(u32, u32, u32), void (*freeFunc)(u32, void*));
extern void (* GX2CopySurface)(GX2Surface * srcSurface,u32 srcMip,u32 srcSlice,GX2Surface * dstSurface,u32 dstMip,u32 dstSlice );
extern void (* GX2ClearBuffersEx)(GX2ColorBuffer * colorBuffer,GX2DepthBuffer * depthBuffer,f32 r, f32 g, f32 b, f32 a,f32 depthValue,u8 stencilValue,int clearFlags);
static inline void GX2InitDepthBuffer(GX2DepthBuffer *depthBuffer, s32 dimension, u32 width, u32 height, u32 depth, s32 format, s32 aa)
{

View File

@ -24,7 +24,7 @@
#include "common/common.h"
#include "os_functions.h"
unsigned int coreinit_handle = 0;
unsigned int coreinit_handle __attribute__((section(".data"))) = 0;
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//! Lib handle functions
@ -32,6 +32,11 @@ unsigned int coreinit_handle = 0;
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);
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//! Thread functions
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
@ -45,6 +50,9 @@ 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
@ -58,6 +66,7 @@ EXPORT_DECL(int, OSTryLockMutex, void* mutex);
//! System functions
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
EXPORT_DECL(u64, OSGetTitleID, void);
EXPORT_DECL(void, OSGetArgcArgv, int* argc, char*** argv);
EXPORT_DECL(void, __Exit, void);
EXPORT_DECL(void, OSFatal, const char* msg);
EXPORT_DECL(void, OSSetExceptionCallback, u8 exceptionType, exception_callback newCallback);
@ -65,6 +74,7 @@ EXPORT_DECL(void, DCFlushRange, 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(unsigned int, OSScreenGetBufferSizeEx, unsigned int bufferNum);
@ -81,6 +91,7 @@ EXPORT_VAR(unsigned int *, pMEMAllocFromDefaultHeapEx);
EXPORT_VAR(unsigned int *, pMEMAllocFromDefaultHeap);
EXPORT_VAR(unsigned int *, pMEMFreeToDefaultHeap);
EXPORT_DECL(int, MEMGetSizeForMBlockExpHeap, void* ptr);
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);
@ -90,33 +101,79 @@ EXPORT_DECL(int , MEMCreateExpHeapEx, void* address, unsigned int size, unsigned
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);
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//! Loader functions (not real rpl)
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
EXPORT_DECL(int, LiWaitIopComplete, int unknown_syscall_arg_r3, int * remaining_bytes);
EXPORT_DECL(int, LiWaitIopCompleteWithInterrupts, int unknown_syscall_arg_r3, int * remaining_bytes);
EXPORT_DECL(void, addr_LiWaitOneChunk, void);
EXPORT_DECL(void, addr_sgIsLoadingBuffer, void);
EXPORT_DECL(void, addr_gDynloadInitialized, void);
void InitOSFunctionPointers(void)
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//! Kernel function addresses
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
EXPORT_DECL(void, addr_PrepareTitle_hook, void);
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//! Other function addresses
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
EXPORT_DECL(void, DCInvalidateRange, void *buffer, uint32_t length);
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//! Energy Saver functions
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//Burn-in Reduction
EXPORT_DECL(int, IMEnableDim,void);
EXPORT_DECL(int, IMDisableDim,void);
EXPORT_DECL(int, IMIsDimEnabled,int * result);
//Auto power down
EXPORT_DECL(int, IMEnableAPD,void);
EXPORT_DECL(int, IMDisableAPD,void);
EXPORT_DECL(int, IMIsAPDEnabled,int * result);
EXPORT_DECL(int, IMIsAPDEnabledBySysSettings,int * result);
void InitAcquireOS(void)
{
unsigned int *funcPointer = 0;
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//! Lib handle functions
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
EXPORT_FUNC_WRITE(OSDynLoad_Acquire, (int (*)(const char*, unsigned *))OS_SPECIFICS->addr_OSDynLoad_Acquire);
EXPORT_FUNC_WRITE(OSDynLoad_FindExport, (int (*)(u32, int, const char *, void *))OS_SPECIFICS->addr_OSDynLoad_FindExport);
OSDynLoad_Acquire("coreinit.rpl", &coreinit_handle);
}
void InitOSFunctionPointers(void)
{
unsigned int *funcPointer = 0;
InitAcquireOS();
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//! Security functions
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
OS_FIND_EXPORT(coreinit_handle, OSGetSecurityLevel);
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//! System functions
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
OS_FIND_EXPORT(coreinit_handle, OSFatal);
OS_FIND_EXPORT(coreinit_handle, OSGetTitleID);
OS_FIND_EXPORT(coreinit_handle, OSGetArgcArgv);
OS_FIND_EXPORT(coreinit_handle, OSSetExceptionCallback);
OS_FIND_EXPORT(coreinit_handle, DCFlushRange);
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);
OSDynLoad_FindExport(coreinit_handle, 0, "_Exit", &__Exit);
OS_FIND_EXPORT(coreinit_handle, OSScreenInit);
@ -139,6 +196,9 @@ void InitOSFunctionPointers(void)
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
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
@ -146,6 +206,12 @@ void InitOSFunctionPointers(void)
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
@ -154,6 +220,7 @@ void InitOSFunctionPointers(void)
OSDynLoad_FindExport(coreinit_handle, 1, "MEMAllocFromDefaultHeap", &pMEMAllocFromDefaultHeap);
OSDynLoad_FindExport(coreinit_handle, 1, "MEMFreeToDefaultHeap", &pMEMFreeToDefaultHeap);
OS_FIND_EXPORT(coreinit_handle, MEMGetSizeForMBlockExpHeap);
OS_FIND_EXPORT(coreinit_handle, MEMGetBaseHeapHandle);
OS_FIND_EXPORT(coreinit_handle, MEMGetAllocatableSizeForFrmHeapEx);
OS_FIND_EXPORT(coreinit_handle, MEMAllocFromFrmHeapEx);
@ -162,5 +229,100 @@ void InitOSFunctionPointers(void)
OS_FIND_EXPORT(coreinit_handle, MEMCreateExpHeapEx);
OS_FIND_EXPORT(coreinit_handle, MEMDestroyExpHeap);
OS_FIND_EXPORT(coreinit_handle, MEMFreeToExpHeap);
}
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//! Other function addresses
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
OS_FIND_EXPORT(coreinit_handle, DCInvalidateRange);
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//! Energy Saver functions
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//Burn-in Reduction
OS_FIND_EXPORT(coreinit_handle, IMEnableDim);
OS_FIND_EXPORT(coreinit_handle, IMDisableDim);
OS_FIND_EXPORT(coreinit_handle, IMIsDimEnabled);
//Auto power down
OS_FIND_EXPORT(coreinit_handle, IMEnableAPD);
OS_FIND_EXPORT(coreinit_handle, IMDisableAPD);
OS_FIND_EXPORT(coreinit_handle, IMIsAPDEnabled);
OS_FIND_EXPORT(coreinit_handle, IMIsAPDEnabledBySysSettings);
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//! Special non library functions
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
if(OS_FIRMWARE == 532 || OS_FIRMWARE == 540)
{
EXPORT_FUNC_WRITE(LiWaitIopComplete, (int (*)(int, int *))0x0100FFA4); // loader.elf
EXPORT_FUNC_WRITE(LiWaitIopCompleteWithInterrupts, (int (*)(int, int *))0x0100FE90); // loader.elf
EXPORT_FUNC_WRITE(addr_LiWaitOneChunk, (int (*)(int, int *))0x010007EC); // loader.elf
EXPORT_FUNC_WRITE(addr_PrepareTitle_hook, (int (*)(int, int *))0xFFF18558); // kernel.elf
EXPORT_FUNC_WRITE(addr_sgIsLoadingBuffer, (int (*)(int, int *))0xEFE19D00); // loader.elf
EXPORT_FUNC_WRITE(addr_gDynloadInitialized, (int (*)(int, int *))0xEFE13C3C); // loader.elf
}
else if(OS_FIRMWARE == 500 || OS_FIRMWARE == 510)
{
EXPORT_FUNC_WRITE(LiWaitIopComplete, (int (*)(int, int *))0x0100FBC4);
EXPORT_FUNC_WRITE(LiWaitIopCompleteWithInterrupts, (int (*)(int, int *))0x0100FAB0);
EXPORT_FUNC_WRITE(addr_LiWaitOneChunk, (int (*)(int, int *))0x010007EC);
EXPORT_FUNC_WRITE(addr_PrepareTitle_hook, (int (*)(int, int *))0xFFF18534);
EXPORT_FUNC_WRITE(addr_sgIsLoadingBuffer, (int (*)(int, int *))0xEFE19D00);
EXPORT_FUNC_WRITE(addr_gDynloadInitialized, (int (*)(int, int *))0xEFE13C3C);
}
else if(OS_FIRMWARE == 410)
{
EXPORT_FUNC_WRITE(LiWaitIopComplete, (int (*)(int, int *))0x0100F78C);
EXPORT_FUNC_WRITE(LiWaitIopCompleteWithInterrupts, (int (*)(int, int *))0x0100F678);
EXPORT_FUNC_WRITE(addr_LiWaitOneChunk, (int (*)(int, int *))0x010007F8);
EXPORT_FUNC_WRITE(addr_PrepareTitle_hook, (int (*)(int, int *))0xFFF166DC);
EXPORT_FUNC_WRITE(addr_sgIsLoadingBuffer, (int (*)(int, int *))0xEFE19CC0);
EXPORT_FUNC_WRITE(addr_gDynloadInitialized, (int (*)(int, int *))0xEFE13BFC);
}
else if(OS_FIRMWARE == 400) //same for 402 and 403
{
EXPORT_FUNC_WRITE(LiWaitIopComplete, (int (*)(int, int *))0x0100F78C);
EXPORT_FUNC_WRITE(LiWaitIopCompleteWithInterrupts, (int (*)(int, int *))0x0100F678);
EXPORT_FUNC_WRITE(addr_LiWaitOneChunk, (int (*)(int, int *))0x010007F8);
EXPORT_FUNC_WRITE(addr_PrepareTitle_hook, (int (*)(int, int *))0xFFF15E70);
EXPORT_FUNC_WRITE(addr_sgIsLoadingBuffer, (int (*)(int, int *))0xEFE19CC0);
EXPORT_FUNC_WRITE(addr_gDynloadInitialized, (int (*)(int, int *))0xEFE13BFC);
}
else if(OS_FIRMWARE == 550)
{
EXPORT_FUNC_WRITE(LiWaitIopComplete, (int (*)(int, int *))0x01010180);
EXPORT_FUNC_WRITE(LiWaitIopCompleteWithInterrupts, (int (*)(int, int *))0x0101006C);
EXPORT_FUNC_WRITE(addr_LiWaitOneChunk, (int (*)(int, int *))0x0100080C);
EXPORT_FUNC_WRITE(addr_PrepareTitle_hook, (int (*)(int, int *))0xFFF184E4);
EXPORT_FUNC_WRITE(addr_sgIsLoadingBuffer, (int (*)(int, int *))0xEFE19E80);
EXPORT_FUNC_WRITE(addr_gDynloadInitialized, (int (*)(int, int *))0xEFE13DBC);
}
else if(OS_FIRMWARE == 310)
{
EXPORT_FUNC_WRITE(LiWaitIopComplete, (int (*)(int, int *))0x0100C4E4);
EXPORT_FUNC_WRITE(LiWaitIopCompleteWithInterrupts, (int (*)(int, int *))0x0100C3D4);
EXPORT_FUNC_WRITE(addr_LiWaitOneChunk, (int (*)(int, int *))0x010004D8);
EXPORT_FUNC_WRITE(addr_PrepareTitle_hook, (int (*)(int, int *))0xFFF15A0C);
EXPORT_FUNC_WRITE(addr_sgIsLoadingBuffer, (int (*)(int, int *))0xEFE19340);
EXPORT_FUNC_WRITE(addr_gDynloadInitialized, (int (*)(int, int *))0xEFE1329C);
}
else if(OS_FIRMWARE == 300)
{
EXPORT_FUNC_WRITE(LiWaitIopComplete, (int (*)(int, int *))0x0100C4E4);
EXPORT_FUNC_WRITE(LiWaitIopCompleteWithInterrupts, (int (*)(int, int *))0x0100C3D4);
EXPORT_FUNC_WRITE(addr_LiWaitOneChunk, (int (*)(int, int *))0x010004D8);
EXPORT_FUNC_WRITE(addr_PrepareTitle_hook, (int (*)(int, int *))0xFFF15974);
EXPORT_FUNC_WRITE(addr_sgIsLoadingBuffer, (int (*)(int, int *))0xEFE19340);
EXPORT_FUNC_WRITE(addr_gDynloadInitialized, (int (*)(int, int *))0xEFE1329C);
}
else
{
OSFatal("Missing all OS specific addresses.");
}
}

View File

@ -26,6 +26,7 @@
#include <gctypes.h>
#include "common/os_defs.h"
#include "os_types.h"
#ifdef __cplusplus
extern "C" {
@ -33,10 +34,8 @@ extern "C" {
#define BUS_SPEED 248625000
//#define SECS_TO_TICKS(sec) (((unsigned long long)(sec)) * (BUS_SPEED/4))
#define SECS_TO_TICKS(sec) sec
#define MILLISECS_TO_TICKS(msec) (SECS_TO_TICKS(msec) / 1000)
//#define MILLISECS_TO_TICKS(msec) (SECS_TO_TICKS(msec) / 1000)
//#define MICROSECS_TO_TICKS(usec) (SECS_TO_TICKS(usec) / 1000000)
#define MICROSECS_TO_TICKS(usec) usec
//#define usleep(usecs) OSSleepTicks(MICROSECS_TO_TICKS(usecs))
//#define sleep(secs) OSSleepTicks(SECS_TO_TICKS(secs))
@ -68,6 +67,7 @@ extern "C" {
/* Handle for coreinit */
extern unsigned int coreinit_handle;
void InitOSFunctionPointers(void);
void InitAcquireOS(void);
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//! Lib handle functions
@ -75,6 +75,11 @@ void InitOSFunctionPointers(void);
extern int (* OSDynLoad_Acquire)(const char* rpl, u32 *handle);
extern int (* OSDynLoad_FindExport)(u32 handle, int isdata, const char *symbol, void *address);
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//! Security functions
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
extern int (* OSGetSecurityLevel)(void);
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//! Thread functions
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
@ -88,6 +93,8 @@ extern int (* OSSetThreadPriority)(void * thread, int priority);
extern void (* OSDetachThread)(void * thread);
extern void (* OSSleepTicks)(u64 ticks);
extern u64 (* OSGetTick)(void);
extern u64 (* OSGetTime)(void);
extern void (*OSTicksToCalendarTime)(u64 time, OSCalendarTime *calendarTime);
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//! Mutex functions
@ -101,12 +108,14 @@ extern int (* OSTryLockMutex)(void* mutex);
//! System functions
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
extern u64 (* OSGetTitleID)(void);
extern void (* OSGetArgcArgv)(int* argc, char*** argv);
extern void (* __Exit)(void);
extern void (* OSFatal)(const char* msg);
extern void (* DCFlushRange)(const void *addr, u32 length);
extern void (* ICInvalidateRange)(const void *addr, u32 length);
extern void* (* OSEffectiveToPhysical)(const void*);
extern int (* __os_snprintf)(char* s, int n, const char * format, ...);
extern int * (* __gh_errno_ptr)(void);
extern void (*OSScreenInit)(void);
extern unsigned int (*OSScreenGetBufferSizeEx)(unsigned int bufferNum);
@ -119,9 +128,44 @@ extern int (*OSScreenEnableEx)(unsigned int bufferNum, int enable);
typedef unsigned char (*exception_callback)(void * interruptedContext);
extern void (* OSSetExceptionCallback)(u8 exceptionType, exception_callback newCallback);
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//! MCP functions
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
extern int (* MCP_Open)(void);
extern int (* MCP_Close)(int handle);
extern int (* MCP_GetOwnTitleInfo)(int handle, void * data);
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//! LOADER functions
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
extern int (* LiWaitIopComplete)(int unknown_syscall_arg_r3, int * remaining_bytes);
extern int (* LiWaitIopCompleteWithInterrupts)(int unknown_syscall_arg_r3, int * remaining_bytes);
extern void (* addr_LiWaitOneChunk)(void);
extern void (* addr_sgIsLoadingBuffer)(void);
extern void (* addr_gDynloadInitialized)(void);
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//! Kernel function addresses
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
extern void (* addr_PrepareTitle_hook)(void);
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//! Other function addresses
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
extern void (*DCInvalidateRange)(void *buffer, uint32_t length);
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
//! Energy Saver functions
//!----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
////Burn-in Reduction
extern int (*IMEnableDim)(void);
extern int (*IMDisableDim)(void);
extern int (*IMIsDimEnabled)(int * result);
//Auto power down
extern int (*IMEnableAPD)(void);
extern int (*IMDisableAPD)(void);
extern int (*IMIsAPDEnabled)(int * result);
extern int (*IMIsAPDEnabledBySysSettings)(int * result);
#ifdef __cplusplus
}

View File

@ -0,0 +1,27 @@
#ifndef _OS_TYPES_H_
#define _OS_TYPES_H_
#ifdef __cplusplus
extern "C" {
#endif
#include <gctypes.h>
typedef struct _OSCalendarTime {
int sec;
int min;
int hour;
int mday;
int mon;
int year;
int wday;
int yday;
int msec;
int usec;
} OSCalendarTime;
#ifdef __cplusplus
}
#endif
#endif

View File

@ -24,27 +24,38 @@
#include "os_functions.h"
#include "padscore_functions.h"
unsigned int padscore_handle __attribute__((section(".data"))) = 0;
EXPORT_DECL(void, KPADInit, void);
EXPORT_DECL(void, WPADInit, void);
EXPORT_DECL(s32, WPADProbe, s32 chan, u32 * pad_type);
EXPORT_DECL(s32, WPADSetDataFormat, s32 chan, s32 format);
EXPORT_DECL(void, WPADEnableURCC, s32 enable);
EXPORT_DECL(void, WPADRead, s32 chan, void * data);
EXPORT_DECL(s32, KPADRead, s32 chan, void * data, u32 size);
EXPORT_DECL(void,WPADSetAutoSleepTime,u8 minute);
EXPORT_DECL(void,WPADDisconnect,s32 chan);
void InitAcquirePadScore(void)
{
OSDynLoad_Acquire("padscore.rpl", &padscore_handle);
}
void InitPadScoreFunctionPointers(void)
{
unsigned int *funcPointer = 0;
unsigned int padscore_handle;
OSDynLoad_Acquire("padscore.rpl", &padscore_handle);
InitAcquirePadScore();
OS_FIND_EXPORT(padscore_handle, WPADInit);
OS_FIND_EXPORT(padscore_handle, KPADInit);
OS_FIND_EXPORT(padscore_handle, WPADProbe);
OS_FIND_EXPORT(padscore_handle, WPADSetDataFormat);
OS_FIND_EXPORT(padscore_handle, WPADEnableURCC);
OS_FIND_EXPORT(padscore_handle, WPADRead);
OS_FIND_EXPORT(padscore_handle, KPADRead);
OS_FIND_EXPORT(padscore_handle, WPADSetAutoSleepTime);
OS_FIND_EXPORT(padscore_handle, WPADDisconnect);
KPADInit();
WPADEnableURCC(1);
}

View File

@ -28,6 +28,10 @@
extern "C" {
#endif
#include "dynamic_libs/vpad_functions.h"
extern unsigned int padscore_handle;
#include <gctypes.h>
#define WPAD_BUTTON_LEFT 0x0001
@ -60,8 +64,34 @@ extern "C" {
#define WPAD_CLASSIC_BUTTON_DOWN 0x4000
#define WPAD_CLASSIC_BUTTON_RIGHT 0x8000
void InitPadScoreFunctionPointers(void);
#define WPAD_PRO_BUTTON_UP 0x00000001
#define WPAD_PRO_BUTTON_LEFT 0x00000002
#define WPAD_PRO_TRIGGER_ZR 0x00000004
#define WPAD_PRO_BUTTON_X 0x00000008
#define WPAD_PRO_BUTTON_A 0x00000010
#define WPAD_PRO_BUTTON_Y 0x00000020
#define WPAD_PRO_BUTTON_B 0x00000040
#define WPAD_PRO_TRIGGER_ZL 0x00000080
#define WPAD_PRO_RESERVED 0x00000100
#define WPAD_PRO_TRIGGER_R 0x00000200
#define WPAD_PRO_BUTTON_PLUS 0x00000400
#define WPAD_PRO_BUTTON_HOME 0x00000800
#define WPAD_PRO_BUTTON_MINUS 0x00001000
#define WPAD_PRO_TRIGGER_L 0x00002000
#define WPAD_PRO_BUTTON_DOWN 0x00004000
#define WPAD_PRO_BUTTON_RIGHT 0x00008000
#define WPAD_PRO_BUTTON_STICK_R 0x00010000
#define WPAD_PRO_BUTTON_STICK_L 0x00020000
#define WPAD_PRO_STICK_L_EMULATION_UP 0x00200000
#define WPAD_PRO_STICK_L_EMULATION_DOWN 0x00100000
#define WPAD_PRO_STICK_L_EMULATION_LEFT 0x00040000
#define WPAD_PRO_STICK_L_EMULATION_RIGHT 0x00080000
#define WPAD_PRO_STICK_R_EMULATION_UP 0x02000000
#define WPAD_PRO_STICK_R_EMULATION_DOWN 0x01000000
#define WPAD_PRO_STICK_R_EMULATION_LEFT 0x00400000
#define WPAD_PRO_STICK_R_EMULATION_RIGHT 0x00800000
typedef struct _KPADData
{
@ -78,7 +108,7 @@ typedef struct _KPADData
u8 device_type;
u8 wpad_error;
u8 pos_valid;
u8 unused_4[1];
u8 format;
union
{
@ -101,19 +131,38 @@ typedef struct _KPADData
f32 rtrigger;
} classic;
struct
{
u32 btns_h;
u32 btns_d;
u32 btns_r;
f32 lstick_x;
f32 lstick_y;
f32 rstick_x;
f32 rstick_y;
int charging;
int wired;
} pro;
u32 unused_6[20];
};
u32 unused_7[16];
} KPADData;
void InitPadScoreFunctionPointers(void);
void InitAcquirePadScore(void);
typedef void (* wpad_connect_callback_t)(s32 chan, s32 status);
extern void (* KPADInit)(void);
extern void (* WPADInit)(void);
extern s32 (* WPADProbe)(s32 chan, u32 * pad_type);
extern s32 (* WPADSetDataFormat)(s32 chan, s32 format);
extern void (* WPADEnableURCC)(s32 enable);
extern void (* WPADRead)(s32 chan, void * data);
extern s32 (* KPADRead)(s32 chan, void * data, u32 size);
extern s32 (* KPADReadEx)(s32 chan, KPADData * data, u32 size, s32 *error);
extern void (*WPADSetAutoSleepTime)(u8 time);
extern void (*WPADDisconnect)( s32 chan );
#ifdef __cplusplus
}

View File

@ -26,6 +26,8 @@
u32 hostIpAddress = 0;
unsigned int nsysnet_handle __attribute__((section(".data"))) = 0;
EXPORT_DECL(void, socket_lib_init, void);
EXPORT_DECL(int, socket, int domain, int type, int protocol);
EXPORT_DECL(int, socketclose, int s);
@ -35,27 +37,26 @@ EXPORT_DECL(int, listen, s32 s,u32 backlog);
EXPORT_DECL(int, accept, s32 s,struct sockaddr *addr,s32 *addrlen);
EXPORT_DECL(int, send, int s, const void *buffer, int size, int flags);
EXPORT_DECL(int, recv, int s, void *buffer, int size, int flags);
EXPORT_DECL(int, recvfrom,int sockfd, void *buf, int len, int flags,struct sockaddr *src_addr, int *addrlen);
EXPORT_DECL(int, sendto, int s, const void *buffer, int size, int flags, const struct sockaddr *dest, int dest_len);
EXPORT_DECL(int, setsockopt, int s, int level, int optname, void *optval, int optlen);
EXPORT_DECL(char *, inet_ntoa, struct in_addr in);
EXPORT_DECL(int, inet_aton, const char *cp, struct in_addr *inp);
EXPORT_DECL(int, NSSLWrite, int connection, const void* buf, int len,int * written);
EXPORT_DECL(int, NSSLRead, int connection, const void* buf, int len,int * read);
EXPORT_DECL(int, NSSLCreateConnection, int context, const char* host, int hotlen,int options,int sock,int block);
void InitAcquireSocket(void)
{
OSDynLoad_Acquire("nsysnet.rpl", &nsysnet_handle);
}
void InitSocketFunctionPointers(void)
{
unsigned int nsysnet_handle;
unsigned int *funcPointer = 0;
OSDynLoad_Acquire("nsysnet.rpl", &nsysnet_handle);
unsigned int nn_ac_handle;
int(*ACInitialize)();
int(*ACGetStartupId) (unsigned int *id);
int(*ACConnectWithConfigId) (unsigned int id);
int(*ACGetAssignedAddress) (u32 * ip);
OSDynLoad_Acquire("nn_ac.rpl", &nn_ac_handle);
OSDynLoad_FindExport(nn_ac_handle, 0, "ACInitialize", &ACInitialize);
OSDynLoad_FindExport(nn_ac_handle, 0, "ACGetStartupId", &ACGetStartupId);
OSDynLoad_FindExport(nn_ac_handle, 0, "ACConnectWithConfigId",&ACConnectWithConfigId);
OSDynLoad_FindExport(nn_ac_handle, 0, "ACGetAssignedAddress",&ACGetAssignedAddress);
InitAcquireSocket();
OS_FIND_EXPORT(nsysnet_handle, socket_lib_init);
OS_FIND_EXPORT(nsysnet_handle, socket);
@ -66,17 +67,15 @@ void InitSocketFunctionPointers(void)
OS_FIND_EXPORT(nsysnet_handle, accept);
OS_FIND_EXPORT(nsysnet_handle, send);
OS_FIND_EXPORT(nsysnet_handle, recv);
OS_FIND_EXPORT(nsysnet_handle, recvfrom);
OS_FIND_EXPORT(nsysnet_handle, sendto);
OS_FIND_EXPORT(nsysnet_handle, setsockopt);
OS_FIND_EXPORT(nsysnet_handle, inet_ntoa);
OS_FIND_EXPORT(nsysnet_handle, inet_aton);
unsigned int nn_startupid;
ACInitialize();
ACGetStartupId(&nn_startupid);
ACConnectWithConfigId(nn_startupid);
ACGetAssignedAddress(&hostIpAddress);
OS_FIND_EXPORT(nsysnet_handle, NSSLWrite);
OS_FIND_EXPORT(nsysnet_handle, NSSLRead);
OS_FIND_EXPORT(nsysnet_handle, NSSLCreateConnection);
socket_lib_init();
}

View File

@ -28,6 +28,8 @@
extern "C" {
#endif
extern unsigned int nsysnet_handle;
#include <gctypes.h>
#define INADDR_ANY 0
@ -47,6 +49,10 @@ extern "C" {
#define SO_REUSEADDR 0x0004
#define SO_NONBLOCK 0x1016
#define SO_MYADDR 0x1013
#define SO_RCVTIMEO 0x1006
#define SOL_SOCKET -1
#define MSG_DONTWAIT 32
#define htonl(x) x
#define htons(x) x
@ -72,6 +78,7 @@ struct sockaddr
void InitSocketFunctionPointers(void);
void InitAcquireSocket(void);
extern void (*socket_lib_init)(void);
extern int (*socket)(int domain, int type, int protocol);
@ -82,9 +89,15 @@ extern int (*listen)(s32 s,u32 backlog);
extern int (*accept)(s32 s,struct sockaddr *addr,s32 *addrlen);
extern int (*send)(int s, const void *buffer, int size, int flags);
extern int (*recv)(int s, void *buffer, int size, int flags);
extern int (*recvfrom)(int sockfd, void *buf, int len, int flags,struct sockaddr *src_addr, int *addrlen);
extern int (*sendto)(int s, const void *buffer, int size, int flags, const struct sockaddr *dest, int dest_len);
extern int (*setsockopt)(int s, int level, int optname, void *optval, int optlen);
extern int (* NSSLWrite)(int connection, const void* buf, int len,int * written);
extern int (* NSSLRead)(int connection, const void* buf, int len,int * read);
extern int (* NSSLCreateConnection)(int context, const char* host, int hotlen,int options,int sock,int block);
extern char * (*inet_ntoa)(struct in_addr in);
extern int (*inet_aton)(const char *cp, struct in_addr *inp);

View File

@ -23,18 +23,27 @@
***************************************************************************/
#include "os_functions.h"
EXPORT_DECL(void, _SYSLaunchTitleByPathFromLauncher, const char* path, int len, int zero);
EXPORT_DECL(int, SYSRelaunchTitle, int argc, char* argv);
unsigned int sysapp_handle __attribute__((section(".data"))) = 0;
EXPORT_DECL(int, _SYSLaunchTitleByPathFromLauncher, const char* path, int len, int zero);
EXPORT_DECL(int, SYSRelaunchTitle, int argc, char** argv);
EXPORT_DECL(int, SYSLaunchMenu, void);
EXPORT_DECL(int, SYSCheckTitleExists, u64 titleId);
EXPORT_DECL(int, SYSLaunchTitle, u64 titleId);
void InitAcquireSys(void)
{
OSDynLoad_Acquire("sysapp.rpl", &sysapp_handle);
}
void InitSysFunctionPointers(void)
{
unsigned int *funcPointer = 0;
unsigned int sysapp_handle;
OSDynLoad_Acquire("sysapp.rpl", &sysapp_handle);
InitAcquireSys();
OS_FIND_EXPORT(sysapp_handle, _SYSLaunchTitleByPathFromLauncher);
OS_FIND_EXPORT(sysapp_handle, SYSRelaunchTitle);
OS_FIND_EXPORT(sysapp_handle, SYSLaunchMenu);
OS_FIND_EXPORT(sysapp_handle, SYSCheckTitleExists);
OS_FIND_EXPORT(sysapp_handle, SYSLaunchTitle);
}

View File

@ -28,11 +28,16 @@
extern "C" {
#endif
void InitSysFunctionPointers(void);
extern unsigned int sysapp_handle;
extern void(*_SYSLaunchTitleByPathFromLauncher)(const char* path, int len, int zero);
extern int (* SYSRelaunchTitle)(int argc, char* argv);
void InitSysFunctionPointers(void);
void InitAcquireSys(void);
extern int(*_SYSLaunchTitleByPathFromLauncher)(const char* path, int len, int zero);
extern int (* SYSRelaunchTitle)(int argc, char** argv);
extern int (* SYSLaunchMenu)(void);
extern int (* SYSCheckTitleExists)(u64 titleId);
extern int (* SYSLaunchTitle)(u64 titleId);
#ifdef __cplusplus

View File

@ -0,0 +1,78 @@
/****************************************************************************
* 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 "os_functions.h"
#include "syshid_functions.h"
unsigned int syshid_handle __attribute__((section(".data"))) = 0;
EXPORT_DECL(int, HIDSetup,void);
EXPORT_DECL(int, HIDTeardown,void);
EXPORT_DECL(int, HIDAddClient,HIDClient *p_client, HIDAttachCallback attach_callback);
EXPORT_DECL(int, HIDDelClient,HIDClient *p_client);
EXPORT_DECL(int, HIDGetDescriptor,unsigned int handle,u8 descriptor_type,u8 descriptor_index, u16 language_id, unsigned char *p_buffer, unsigned int buffer_length, HIDCallback hc, void *p_user);
EXPORT_DECL(int, HIDSetDescriptor,unsigned int handle,u8 descriptor_type,u8 descriptor_index, u16 language_id, unsigned char *p_buffer, unsigned int buffer_length, HIDCallback hc, void *p_user);
EXPORT_DECL(int, HIDSetProtocol,unsigned int handle,u8 interface_index,u8 protocol, HIDCallback hc, void *p_user);
EXPORT_DECL(int, HIDGetProtocol,unsigned int handle,u8 interface_index,u8 * protocol, HIDCallback hc, void *p_user);
EXPORT_DECL(int, HIDGetReport,u32 handle, u8 report_type, u8 report_id, u8 *p_buffer, u32 buffer_length, HIDCallback hc, void *p_user);
EXPORT_DECL(int, HIDSetReport,u32 handle, u8 report_type, u8 report_id, u8 *p_buffer, u32 buffer_length, HIDCallback hc, void *p_user);
EXPORT_DECL(int, HIDSetIdle,unsigned int handle, u8 interface_index,u8 duration, HIDCallback hc, void *p_user);
EXPORT_DECL(int, HIDRead,unsigned int handle, unsigned char *p_buffer, unsigned int buffer_length, HIDCallback hc, void *p_user);
EXPORT_DECL(int, HIDWrite,unsigned int handle, unsigned char *p_buffer, unsigned int buffer_length, HIDCallback hc, void *p_user);
void InitAcquireSysHID(void)
{
OSDynLoad_Acquire("nsyshid.rpl", &syshid_handle);
}
void InitSysHIDFunctionPointers(void)
{
InitAcquireSysHID();
if(syshid_handle == 0){
return;
}
unsigned int funcPointer = 0;
//! assigning those is not mandatory and it does not always work to load them
OS_FIND_EXPORT(syshid_handle, HIDSetup);
OS_FIND_EXPORT(syshid_handle, HIDTeardown);
OS_FIND_EXPORT(syshid_handle, HIDAddClient);
OS_FIND_EXPORT(syshid_handle, HIDDelClient);
OS_FIND_EXPORT(syshid_handle, HIDGetDescriptor);
OS_FIND_EXPORT(syshid_handle, HIDSetDescriptor);
OS_FIND_EXPORT(syshid_handle, HIDRead);
OS_FIND_EXPORT(syshid_handle, HIDWrite);
OS_FIND_EXPORT(syshid_handle, HIDSetProtocol);
OS_FIND_EXPORT(syshid_handle, HIDGetProtocol);
OS_FIND_EXPORT(syshid_handle, HIDSetIdle);
OS_FIND_EXPORT(syshid_handle, HIDGetReport);
OS_FIND_EXPORT(syshid_handle, HIDSetReport);
}

View File

@ -0,0 +1,90 @@
/****************************************************************************
* 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.
***************************************************************************/
#ifndef __SYSHID_FUNCTIONS_H_
#define __SYSHID_FUNCTIONS_H_
#ifdef __cplusplus
extern "C" {
#endif
extern unsigned int syshid_handle;
typedef struct
{
unsigned int handle;
unsigned int physical_device_inst;
unsigned short vid;
unsigned short pid;
unsigned char interface_index;
unsigned char sub_class;
unsigned char protocol;
unsigned short max_packet_size_rx;
unsigned short max_packet_size_tx;
} HIDDevice;
typedef struct _HIDClient HIDClient;
#define HID_DEVICE_DETACH 0
#define HID_DEVICE_ATTACH 1
typedef int (*HIDAttachCallback)(HIDClient *p_hc,HIDDevice *p_hd,unsigned int attach);
struct _HIDClient
{
HIDClient *next;
HIDAttachCallback attach_cb;
};
typedef void (*HIDCallback)(unsigned int handle,int error,unsigned char *p_buffer,unsigned int bytes_transferred,void *p_user);
void InitSysHIDFunctionPointers(void);
void InitAcquireSysHID(void);
extern int(*HIDSetup)(void);
extern int(*HIDTeardown)(void);
extern int(*HIDAddClient)(HIDClient *p_client, HIDAttachCallback attach_callback);
extern int(*HIDDelClient)(HIDClient *p_client);
extern int(*HIDGetDescriptor)(unsigned int handle,u8 descriptor_type,u8 descriptor_index, u16 language_id, unsigned char *p_buffer, unsigned int buffer_length, HIDCallback hc, void *p_user);
extern int(*HIDSetDescriptor)(unsigned int handle,u8 descriptor_type,u8 descriptor_index, u16 language_id, unsigned char *p_buffer, unsigned int buffer_length, HIDCallback hc, void *p_user);
extern int(*HIDGetReport)(u32 handle, u8 report_type, u8 report_id, u8 *p_buffer, u32 buffer_length, HIDCallback hc, void *p_user);
extern int(*HIDSetReport)(u32 handle, u8 report_type, u8 report_id, u8 *p_buffer, u32 buffer_length, HIDCallback hc, void *p_user);
extern int(*HIDSetIdle)(unsigned int handle, u8 interface_index,u8 duration, HIDCallback hc, void *p_user);
extern int(* HIDSetProtocol)(unsigned int handle,u8 interface_index,u8 protocol, HIDCallback hc, void *p_user);
extern int(* HIDGetProtocol)(unsigned int handle,u8 interface_index,u8 * protocol, HIDCallback hc, void *p_user);
extern int(*HIDRead)(unsigned int handle, unsigned char *p_buffer, unsigned int buffer_length, HIDCallback hc, void *p_user);
extern int(*HIDWrite)(unsigned int handle, unsigned char *p_buffer, unsigned int buffer_length, HIDCallback hc, void *p_user);
#ifdef __cplusplus
}
#endif
#endif // __SYSHID_FUNCTIONS_H_

View File

@ -24,16 +24,32 @@
#include "os_functions.h"
#include "vpad_functions.h"
unsigned int vpad_handle __attribute__((section(".data"))) = 0;
unsigned int vpadbase_handle __attribute__((section(".data"))) = 0;
EXPORT_DECL(void, VPADInit, void);
EXPORT_DECL(void, VPADRead, int chan, VPADData *buffer, u32 buffer_size, s32 *error);
EXPORT_DECL(int, VPADRead, int chan, VPADData *buffer, u32 buffer_size, s32 *error);
EXPORT_DECL(int, VPADGetLcdMode, int padnum, int *lcdmode);
EXPORT_DECL(int, VPADSetLcdMode, int padnum, int lcdmode);
EXPORT_DECL(int, VPADBASEGetMotorOnRemainingCount, int padnum);
EXPORT_DECL(int, VPADBASESetMotorOnRemainingCount, int padnum, int counter);
void InitAcquireVPad(void)
{
OSDynLoad_Acquire("vpad.rpl", &vpad_handle);
OSDynLoad_Acquire("vpadbase.rpl", &vpadbase_handle);
}
void InitVPadFunctionPointers(void)
{
unsigned int *funcPointer = 0;
unsigned int vpad_handle;
OSDynLoad_Acquire("vpad.rpl", &vpad_handle);
InitAcquireVPad();
OS_FIND_EXPORT(vpad_handle, VPADInit);
OS_FIND_EXPORT(vpad_handle, VPADRead);
OS_FIND_EXPORT(vpad_handle, VPADGetLcdMode);
OS_FIND_EXPORT(vpad_handle, VPADSetLcdMode);
OS_FIND_EXPORT(vpadbase_handle, VPADBASEGetMotorOnRemainingCount);
OS_FIND_EXPORT(vpadbase_handle, VPADBASESetMotorOnRemainingCount);
}

View File

@ -28,6 +28,9 @@
extern "C" {
#endif
extern unsigned int vpad_handle;
extern unsigned int vpadbase_handle;
#include <gctypes.h>
#define VPAD_BUTTON_A 0x8000
@ -50,16 +53,20 @@ extern "C" {
#define VPAD_BUTTON_STICK_L 0x00040000
#define VPAD_BUTTON_TV 0x00010000
#define VPAD_STICK_R_EMULATION_LEFT 0x04000000
#define VPAD_STICK_R_EMULATION_RIGHT 0x02000000
#define VPAD_STICK_R_EMULATION_UP 0x01000000
#define VPAD_STICK_R_EMULATION_DOWN 0x00800000
#define VPAD_STICK_R_EMULATION_LEFT 0x04000000
#define VPAD_STICK_R_EMULATION_RIGHT 0x02000000
#define VPAD_STICK_R_EMULATION_UP 0x01000000
#define VPAD_STICK_R_EMULATION_DOWN 0x00800000
#define VPAD_STICK_L_EMULATION_LEFT 0x40000000
#define VPAD_STICK_L_EMULATION_RIGHT 0x20000000
#define VPAD_STICK_L_EMULATION_UP 0x10000000
#define VPAD_STICK_L_EMULATION_DOWN 0x08000000
#define VPAD_STICK_L_EMULATION_LEFT 0x40000000
#define VPAD_STICK_L_EMULATION_RIGHT 0x20000000
#define VPAD_STICK_L_EMULATION_UP 0x10000000
#define VPAD_STICK_L_EMULATION_DOWN 0x08000000
//! Own definitions
#define VPAD_BUTTON_TOUCH 0x00080000
#define VPAD_MASK_EMULATED_STICKS 0x7F800000
#define VPAD_MASK_BUTTONS ~VPAD_MASK_EMULATED_STICKS
typedef struct
{
@ -91,9 +98,14 @@ typedef struct
} VPADData;
void InitVPadFunctionPointers(void);
void InitAcquireVPad(void);
extern int (* VPADRead)(int chan, VPADData *buffer, u32 buffer_size, s32 *error);
extern int (* VPADGetLcdMode)(int padnum, int *lcdmode);
extern int (* VPADSetLcdMode)(int padnum, int lcdmode);
extern void (* VPADInit)(void);
extern void (* VPADRead)(int chan, VPADData *buffer, u32 buffer_size, s32 *error);
extern int (* VPADBASEGetMotorOnRemainingCount)(int lcdmode);
extern int (* VPADBASESetMotorOnRemainingCount)(int lcdmode,int counter);
#ifdef __cplusplus
}

View File

@ -3,7 +3,6 @@
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include "common/fs_defs.h"
#include "dynamic_libs/fs_functions.h"

View File

@ -278,6 +278,7 @@ static ssize_t sd_fat_write_r (struct _reent *r, int fd, const char *ptr, size_t
memcpy(tmpBuf, ptr + done, write_size);
int result = FSWriteFile(file->dev->pClient, file->dev->pCmd, tmpBuf, 0x01, write_size, file->fd, 0, -1);
FSFlushFile(file->dev->pClient, file->dev->pCmd, file->fd, -1);
if(result < 0)
{
r->_errno = result;

View File

@ -31,9 +31,6 @@ SECTIONS {
}
__CODE_END = .;
/DISCARD/ : {
*(*);
}
}
/******************************************************** FS ********************************************************/

View File

@ -1,2 +1,4 @@
python2 wiiu/wiiload.py retroarch_wiiu.elf sd:/zz.gb
netcat -p 4405 -l 10.42.0.170
export WIILOAD=tcp:$1
powerpc-eabi-strip retroarch_wiiu.elf -o retroarch_wiiu_stripped.elf
wiiload retroarch_wiiu_stripped.elf
netcat -p 4405 -l $1

52
wiiu/system/exception.h Normal file
View File

@ -0,0 +1,52 @@
/* source: https://github.com/QuarkTheAwesome/URetro */
#include "wiiu/dynamic_libs/os_functions.h"
#ifndef __EXCEPTION_H__
#define __EXCEPTION_H__
void exception_disassembly_helper(char *fmt, int addr,int opcode, char* s)
{
char* *store = (char**)0x1ab5d140;
char *buffer = (char *)store[0];
if (addr == ((int*)store)[1]) {
store[0] += __os_snprintf(buffer,512,"> 0x%08X 0x%08X %s\n", addr,opcode,s);
} else {
store[0] += __os_snprintf(buffer,512," 0x%08X 0x%08X %s\n", addr,opcode,s);
}
}
unsigned char exception_handler(void* contextIn) {
//Temporary hacky fix, please ignore me.
unsigned int coreinit_handle;
OSDynLoad_Acquire("coreinit.rpl", &coreinit_handle);
void (*DisassemblePPCRange)(void *start, void *end, void *printf_func, int *find_symbol_func, int flags);
OSDynLoad_FindExport(coreinit_handle, 0, "DisassemblePPCRange", &DisassemblePPCRange);
int* context = (int*)contextIn;
char buf2[512];
int* store = (int*)0x1AB5D140;
store[0] = (int)buf2;
store[1] = (int)context[38];
DisassemblePPCRange((void*)context[38]-0x18, (void*)context[38]+0x4, (void*)exception_disassembly_helper, 0, 0);
char buf[2048];
__os_snprintf(buf, 2048, "SP:%08X LR:%08X PC:%08X CR:%08X CTR:%08X\nXER:%08X SR0:%08X SR1:%08X EX0:%08X EX1:%08X\nr0:%08X r2:%08X r3:%08X r4:%08X r5:%08X\nr6:%08X r7:%08X r8:%08X r9:%08X r10:%08X\nr11:%08X r12:%08X r13:%08X r14:%08X r15:%08X\nr16:%08X r17:%08X r18:%08X r19:%08X r20:%08X\nr21:%08X r22:%08X r23:%08X r24:%08X r25:%08X\nr26:%08X r27:%08X r28:%08X r29:%08X r30:%08X\nr31:%08X\n%s", context[3], context[35], context[38], context[34], context[36], context[37], context[38], context[39], context[40], context[41], context[2], context[4], context[5], context[6], context[7], context[8], context[9], context[10], context[11], context[12], context[13], context[14], context[15], context[16], context[17], context[18], context[19], context[20], context[21], context[22], context[23], context[24], context[25], context[26], context[27], context[28], context[29], context[30], context[31], context[32], context[33], buf2);
void net_print(const char* str);
net_print(buf);
OSFatal(buf);
return 0;
}
void InstallExceptionHandler() {
OSSetExceptionCallback(2, &exception_handler);
OSSetExceptionCallback(3, &exception_handler);
OSSetExceptionCallback(6, &exception_handler);
}
#endif //__EXCEPTION_H__

View File

@ -0,0 +1,171 @@
#include <stdio.h>
#include "dynamic_libs/os_functions.h"
#include "exception_handler.h"
#include "wiiu/wiiu_dbg.h"
#define OS_EXCEPTION_MODE_GLOBAL_ALL_CORES 4
#define OS_EXCEPTION_DSI 2
#define OS_EXCEPTION_ISI 3
#define OS_EXCEPTION_PROGRAM 6
/* Exceptions */
typedef struct OSContext
{
/* OSContext identifier */
uint32_t tag1;
uint32_t tag2;
/* GPRs */
uint32_t gpr[32];
/* Special registers */
uint32_t cr;
uint32_t lr;
uint32_t ctr;
uint32_t xer;
/* Initial PC and MSR */
uint32_t srr0;
uint32_t srr1;
/* Only valid during DSI exception */
uint32_t exception_specific0;
uint32_t exception_specific1;
/* There is actually a lot more here but we don't need the rest*/
} OSContext;
#define CPU_STACK_TRACE_DEPTH 10
#define __stringify(rn) #rn
#define mfspr(_rn) \
({ register uint32_t _rval = 0; \
asm volatile("mfspr %0," __stringify(_rn) \
: "=r" (_rval));\
_rval; \
})
typedef struct _framerec {
struct _framerec *up;
void *lr;
} frame_rec, *frame_rec_t;
static const char *exception_names[] = {
"DSI",
"ISI",
"PROGRAM"
};
static const char exception_print_formats[18][45] = {
"Exception type %s occurred!\n", // 0
"GPR00 %08X GPR08 %08X GPR16 %08X GPR24 %08X\n", // 1
"GPR01 %08X GPR09 %08X GPR17 %08X GPR25 %08X\n", // 2
"GPR02 %08X GPR10 %08X GPR18 %08X GPR26 %08X\n", // 3
"GPR03 %08X GPR11 %08X GPR19 %08X GPR27 %08X\n", // 4
"GPR04 %08X GPR12 %08X GPR20 %08X GPR28 %08X\n", // 5
"GPR05 %08X GPR13 %08X GPR21 %08X GPR29 %08X\n", // 6
"GPR06 %08X GPR14 %08X GPR22 %08X GPR30 %08X\n", // 7
"GPR07 %08X GPR15 %08X GPR23 %08X GPR31 %08X\n", // 8
"LR %08X SRR0 %08x SRR1 %08x\n", // 9
"DAR %08X DSISR %08X\n", // 10
"STACK DUMP:", // 11
" --> ", // 12
" -->\n", // 13
"\n", // 14
"%p", // 15
"\nCODE DUMP:\n", // 16
"%p: %08X %08X %08X %08X\n", // 17
};
static unsigned char exception_cb(void * c, unsigned char exception_type) {
char buf[4096];
int pos = 0;
OSContext *context = (OSContext *) c;
/*
* This part is mostly from libogc. Thanks to the devs over there.
*/
pos += sprintf(buf + pos, exception_print_formats[0], exception_names[exception_type]);
pos += sprintf(buf + pos, exception_print_formats[1], context->gpr[0], context->gpr[8], context->gpr[16], context->gpr[24]);
pos += sprintf(buf + pos, exception_print_formats[2], context->gpr[1], context->gpr[9], context->gpr[17], context->gpr[25]);
pos += sprintf(buf + pos, exception_print_formats[3], context->gpr[2], context->gpr[10], context->gpr[18], context->gpr[26]);
pos += sprintf(buf + pos, exception_print_formats[4], context->gpr[3], context->gpr[11], context->gpr[19], context->gpr[27]);
pos += sprintf(buf + pos, exception_print_formats[5], context->gpr[4], context->gpr[12], context->gpr[20], context->gpr[28]);
pos += sprintf(buf + pos, exception_print_formats[6], context->gpr[5], context->gpr[13], context->gpr[21], context->gpr[29]);
pos += sprintf(buf + pos, exception_print_formats[7], context->gpr[6], context->gpr[14], context->gpr[22], context->gpr[30]);
pos += sprintf(buf + pos, exception_print_formats[8], context->gpr[7], context->gpr[15], context->gpr[23], context->gpr[31]);
pos += sprintf(buf + pos, exception_print_formats[9], context->lr, context->srr0, context->srr1);
//if(exception_type == OS_EXCEPTION_DSI) {
pos += sprintf(buf + pos, exception_print_formats[10], context->exception_specific1, context->exception_specific0); // this freezes
//}
void *pc = (void*)context->srr0;
void *lr = (void*)context->lr;
void *r1 = (void*)context->gpr[1];
register uint32_t i = 0;
register frame_rec_t l,p = (frame_rec_t)lr;
l = p;
p = r1;
if(!p)
asm volatile("mr %0,%%r1" : "=r"(p));
pos += sprintf(buf + pos, exception_print_formats[11]);
for(i = 0; i < CPU_STACK_TRACE_DEPTH-1 && p->up; p = p->up, i++) {
if(i % 4)
pos += sprintf(buf + pos, exception_print_formats[12]);
else {
if(i > 0)
pos += sprintf(buf + pos, exception_print_formats[13]);
else
pos += sprintf(buf + pos, exception_print_formats[14]);
}
switch(i) {
case 0:
if(pc)
pos += sprintf(buf + pos, exception_print_formats[15],pc);
break;
case 1:
if(!l)
l = (frame_rec_t)mfspr(8);
pos += sprintf(buf + pos, exception_print_formats[15],(void*)l);
break;
default:
pos += sprintf(buf + pos, exception_print_formats[15],(void*)(p->up->lr));
break;
}
}
//if(exception_type == OS_EXCEPTION_DSI) {
uint32_t *pAdd = (uint32_t*)context->srr0;
pos += sprintf(buf + pos, exception_print_formats[16]);
// TODO by Dimok: this was actually be 3 instead of 2 lines in libogc .... but there is just no more space anymore on the screen
for (i = 0; i < 8; i += 4)
pos += sprintf(buf + pos, exception_print_formats[17], &(pAdd[i]),pAdd[i], pAdd[i+1], pAdd[i+2], pAdd[i+3]);
//}
void net_print(const char* str);
net_print(buf);
OSFatal(buf);
return 1;
}
static unsigned char dsi_exception_cb(void * context) {
return exception_cb(context, 0);
}
static unsigned char isi_exception_cb(void * context) {
return exception_cb(context, 1);
}
static unsigned char program_exception_cb(void * context) {
return exception_cb(context, 2);
}
void setup_os_exceptions(void) {
OSSetExceptionCallback(OS_EXCEPTION_DSI, &dsi_exception_cb);
OSSetExceptionCallback(OS_EXCEPTION_ISI, &isi_exception_cb);
OSSetExceptionCallback(OS_EXCEPTION_PROGRAM, &program_exception_cb);
}

View File

@ -0,0 +1,14 @@
#ifndef __EXCEPTION_HANDLER_H_
#define __EXCEPTION_HANDLER_H_
#ifdef __cplusplus
extern "C" {
#endif
void setup_os_exceptions(void);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -38,6 +38,7 @@ extern unsigned int * pMEMAllocFromDefaultHeapEx;
extern unsigned int * pMEMAllocFromDefaultHeap;
extern unsigned int * pMEMFreeToDefaultHeap;
extern int (*MEMGetSizeForMBlockExpHeap)(void *ptr);
extern int (* MEMGetBaseHeapHandle)(int mem_arena);
extern unsigned int (* MEMGetAllocatableSizeForFrmHeapEx)(int heap, int align);
extern void *(* MEMAllocFromFrmHeapEx)(int heap, unsigned int size, int align);
@ -76,12 +77,15 @@ void memoryRelease(void)
bucket_heap = -1;
}
#if 0
//!-------------------------------------------------------------------------------------------
//! wraps
//!-------------------------------------------------------------------------------------------
void *__wrap_malloc(size_t size)
{
// pointer to a function resolve
if(!size)
return NULL;
return ((void * (*)(size_t))(*pMEMAllocFromDefaultHeap))(size);
}
@ -89,7 +93,8 @@ void *__wrap_memalign(size_t align, size_t size)
{
if (align < 4)
align = 4;
if(!size)
return NULL;
// pointer to a function resolve
return ((void * (*)(size_t, size_t))(*pMEMAllocFromDefaultHeapEx))(size, align);
}
@ -159,7 +164,106 @@ void *__wrap__realloc_r(struct _reent *r, void *p, size_t size)
{
return __wrap_realloc(p, size);
}
#else
void *
__wrap_memalign(size_t alignment, size_t size) {
return MEMAllocFromExpHeapEx(MEMGetBaseHeapHandle(MEMORY_ARENA_2), size, alignment);
}
void *
__wrap_malloc(size_t size) {
return __wrap_memalign(4, size);
}
void
__wrap_free(void *ptr) {
if (ptr) {
MEMFreeToExpHeap(MEMGetBaseHeapHandle(MEMORY_ARENA_2), ptr);
}
}
size_t
__wrap_malloc_usable_size(void *ptr) {
return MEMGetSizeForMBlockExpHeap(ptr);
}
void *
__wrap_realloc(void *ptr, size_t size) {
if (!ptr) {
return __wrap_malloc(size);
}
if (__wrap_malloc_usable_size(ptr) >= size) {
return ptr;
}
void *realloc_ptr = __wrap_malloc(size);
if(!realloc_ptr) {
return NULL;
}
memcpy(realloc_ptr, ptr, __wrap_malloc_usable_size(ptr));
__wrap_free(ptr);
return realloc_ptr;
}
void *
__wrap_calloc(size_t num, size_t size) {
void *ptr = __wrap_malloc(num*size);
if(ptr) {
memset(ptr, 0, num*size);
}
return ptr;
}
void *
__wrap_valloc(size_t size) {
return __wrap_memalign(64, size);
}
void *
__wrap__memalign_r(struct _reent *r, size_t alignment, size_t size) {
return __wrap_memalign(alignment, size);
}
void *
__wrap__malloc_r(struct _reent *r, size_t size) {
return __wrap_malloc(size);
}
void
__wrap__free_r(struct _reent *r, void *ptr) {
return __wrap_free(ptr);
}
void *
__wrap__realloc_r(struct _reent *r, void *ptr, size_t size) {
return __wrap_realloc(ptr, size);
}
void *
__wrap__calloc_r(struct _reent *r, size_t num, size_t size) {
return __wrap_calloc(num, size);
}
size_t
__wrap__malloc_usable_size_r(struct _reent *r, void *ptr) {
return __wrap_malloc_usable_size(ptr);
}
void *
__wrap__valloc_r(struct _reent *r, size_t size) {
return __wrap_valloc(size);
}
#endif
//!-------------------------------------------------------------------------------------------
//! some wrappers
//!-------------------------------------------------------------------------------------------