Skip to content

Commit

Permalink
(WiiU) added basic libiosuhax support
Browse files Browse the repository at this point in the history
  • Loading branch information
FIX94 committed Dec 17, 2016
1 parent d364e50 commit c0b023a
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 8 deletions.
8 changes: 4 additions & 4 deletions Makefile.wiiu
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ LD := $(CXX)

ELF2RPL := $(WUT_ROOT)/tools/bin/elf2rpl

INCDIRS := -I. -Ideps/zlib -Ideps/7zip -Ilibretro-common/include -Iwiiu -I$(WUT_ROOT)/include
LIBDIRS := -L.
INCDIRS := -I. -Ideps/zlib -Ideps/7zip -Ilibretro-common/include -Iwiiu -I$(WUT_ROOT)/include -I$(DEVKITPRO)/portlibs/ppc/include
LIBDIRS := -L. -L$(DEVKITPRO)/portlibs/ppc/lib

CFLAGS := -mrvl -mcpu=750 -meabi -mhard-float
LDFLAGS :=
Expand All @@ -117,7 +117,7 @@ CFLAGS += -ffast-math -Werror=implicit-function-declaration
#CFLAGS += -fomit-frame-pointer -mword-relocations
#CFLAGS += -Wall
CFLAGS += -Dstatic_assert=_Static_assert
CFLAGS += -DWIIU -DMSB_FIRST
CFLAGS += -DWIIU -D__wiiu__ -DMSB_FIRST
CFLAGS += -DHAVE_MAIN
CFLAGS += -DRARCH_INTERNAL -DRARCH_CONSOLE
CFLAGS += -DHAVE_FILTERS_BUILTIN $(DEFINES)
Expand All @@ -138,7 +138,7 @@ CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions

LDFLAGS += -Wl,--gc-sections

LIBS := $(WHOLE_START) -lretro_wiiu $(WHOLE_END) -lm
LIBS := $(WHOLE_START) -lretro_wiiu $(WHOLE_END) -lm -lfat -liosuhax


RPX_OBJ = wiiu/system/stubs_rpl.o
Expand Down
103 changes: 99 additions & 4 deletions frontend/drivers/platform_wiiu.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@
#include <vpad/input.h>
#include <sysapp/launch.h>

#include <fat.h>
#include <iosuhax.h>
#include "ios.h"

#include "wiiu_dbg.h"

#ifdef HAVE_MENU
Expand All @@ -58,6 +62,7 @@

//#define WIIU_SD_PATH "/vol/external01/"
#define WIIU_SD_PATH "sd:/"
#define WIIU_USB_PATH "usb:/"

static enum frontend_fork wiiu_fork_mode = FRONTEND_FORK_NONE;
static const char* elf_path_cst = WIIU_SD_PATH "retroarch/retroarch.elf";
Expand Down Expand Up @@ -143,6 +148,11 @@ static int frontend_wiiu_parse_drive_list(void *data)
MENU_ENUM_LABEL_FILE_DETECT_CORE_LIST_PUSH_DIR,
MENU_SETTING_ACTION, 0, 0);

menu_entries_append_enum(list, WIIU_USB_PATH,
msg_hash_to_str(MENU_ENUM_LABEL_FILE_DETECT_CORE_LIST_PUSH_DIR),
MENU_ENUM_LABEL_FILE_DETECT_CORE_LIST_PUSH_DIR,
MENU_SETTING_ACTION, 0, 0);

return 0;
}

Expand Down Expand Up @@ -340,18 +350,80 @@ void __fini(void)
(*ctor++)();
}

/* libiosuhax related */

//just to be able to call async
void someFunc(void *arg)
{
(void)arg;
}

static int mcp_hook_fd = -1;
int MCPHookOpen()
{
//take over mcp thread
mcp_hook_fd = IOS_Open("/dev/mcp", 0);
if(mcp_hook_fd < 0)
return -1;
IOS_IoctlAsync(mcp_hook_fd, 0x62, (void*)0, 0, (void*)0, 0, someFunc, (void*)0);
//let wupserver start up
retro_sleep(1000);
if(IOSUHAX_Open("/dev/mcp") < 0)
{
IOS_Close(mcp_hook_fd);
mcp_hook_fd = -1;
return -1;
}
return 0;
}

void MCPHookClose()
{
if(mcp_hook_fd < 0)
return;
//close down wupserver, return control to mcp
IOSUHAX_Close();
//wait for mcp to return
retro_sleep(1000);
IOS_Close(mcp_hook_fd);
mcp_hook_fd = -1;
}

/* HBL elf entry point */
int __entry_menu(int argc, char **argv)
{
InitFunctionPointers();
memoryInitialize();
mount_sd_fat("sd");

int iosuhaxMount = 0;
int res = IOSUHAX_Open(NULL);
if(res < 0)
res = MCPHookOpen();

if(res < 0)
mount_sd_fat("sd");
else
{
iosuhaxMount = 1;
fatInitDefault();
}

__init();
int ret = main(argc, argv);
__fini();

unmount_sd_fat("sd");
if(iosuhaxMount)
{
fatUnmount("sd:");
fatUnmount("usb:");
if(mcp_hook_fd >= 0)
MCPHookClose();
else
IOSUHAX_Close();
}
else
unmount_sd_fat("sd");

memoryRelease();
return ret;
}
Expand All @@ -361,13 +433,36 @@ __attribute__((noreturn))
void _start(int argc, char **argv)
{
memoryInitialize();
mount_sd_fat("sd");

int iosuhaxMount = 0;
int res = IOSUHAX_Open(NULL);
if(res < 0)
res = MCPHookOpen();

if(res < 0)
mount_sd_fat("sd");
else
{
iosuhaxMount = 1;
fatInitDefault();
}

__init();
int ret = main(argc, argv);
__fini();

unmount_sd_fat("sd");
if(iosuhaxMount)
{
fatUnmount("sd:");
fatUnmount("usb:");
if(mcp_hook_fd >= 0)
MCPHookClose();
else
IOSUHAX_Close();
}
else
unmount_sd_fat("sd");

memoryRelease();
SYSRelaunchTitle(argc, argv);
exit(ret);
Expand Down
10 changes: 10 additions & 0 deletions wiiu/ios.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

#ifndef _IOS_H_
#define _IOS_H_

int IOS_Open(char *path, unsigned int mode);
int IOS_Close(int fd);
int IOS_Ioctl(int fd, unsigned int request, void *input_buffer, unsigned int input_buffer_len, void *output_buffer, unsigned int output_buffer_len);
int IOS_IoctlAsync(int fd, unsigned int request, void *input_buffer, unsigned int input_buffer_len, void *output_buffer, unsigned int output_buffer_len, void *cb, void *cbarg);

#endif
5 changes: 5 additions & 0 deletions wiiu/system/imports.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ IMPORT(FSGetMountSource);
IMPORT(FSMount);
IMPORT(FSUnmount);

IMPORT(IOS_Open);
IMPORT(IOS_Close);
IMPORT(IOS_Ioctl);
IMPORT(IOS_IoctlAsync);

IMPORT_END();

/* nsysnet */
Expand Down

0 comments on commit c0b023a

Please sign in to comment.