2012-07-28 14:35:07 +00:00
|
|
|
/* RetroArch - A frontend for libretro.
|
2013-01-01 00:37:37 +00:00
|
|
|
* Copyright (C) 2010-2013 - Hans-Kristian Arntzen
|
|
|
|
* Copyright (C) 2011-2013 - Daniel De Matteis
|
2012-07-28 14:35:07 +00:00
|
|
|
*
|
|
|
|
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
|
|
|
* of the GNU General Public License as published by the Free Software Found-
|
|
|
|
* ation, either version 3 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
|
|
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE. See the GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with RetroArch.
|
|
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2012-07-28 16:26:30 +00:00
|
|
|
#include <stdio.h>
|
2012-07-28 14:35:07 +00:00
|
|
|
|
|
|
|
#if defined(__CELLOS_LV2__)
|
|
|
|
#include <cell/sysmodule.h>
|
|
|
|
#include <sys/process.h>
|
|
|
|
#include <sysutil/sysutil_common.h>
|
|
|
|
#include <netex/net.h>
|
|
|
|
#include <np.h>
|
|
|
|
#include <np/drm.h>
|
|
|
|
#elif defined(_XBOX)
|
|
|
|
#include <xtl.h>
|
2012-09-03 22:05:23 +00:00
|
|
|
#elif defined(HW_RVL)
|
2012-08-30 22:59:21 +00:00
|
|
|
#include <string.h>
|
2012-08-05 22:36:03 +00:00
|
|
|
#include <fat.h>
|
2012-08-30 22:59:21 +00:00
|
|
|
#include <gctypes.h>
|
|
|
|
#include <ogc/cache.h>
|
2012-08-05 22:36:03 +00:00
|
|
|
#include <ogc/lwp_threads.h>
|
2012-08-06 00:36:41 +00:00
|
|
|
#include <ogc/system.h>
|
2012-08-22 19:56:20 +00:00
|
|
|
#include <ogc/usbstorage.h>
|
2012-08-30 22:59:21 +00:00
|
|
|
#include <sdcard/wiisd_io.h>
|
2012-08-31 23:38:12 +00:00
|
|
|
|
2012-08-30 22:59:21 +00:00
|
|
|
#define EXECUTE_ADDR ((uint8_t *) 0x91800000)
|
|
|
|
#define BOOTER_ADDR ((uint8_t *) 0x93000000)
|
|
|
|
#define ARGS_ADDR ((uint8_t *) 0x93200000)
|
|
|
|
|
2012-09-03 22:05:23 +00:00
|
|
|
extern uint8_t _binary_wii_app_booter_app_booter_bin_start[];
|
|
|
|
extern uint8_t _binary_wii_app_booter_app_booter_bin_end[];
|
|
|
|
#define booter_start _binary_wii_app_booter_app_booter_bin_start
|
|
|
|
#define booter_end _binary_wii_app_booter_app_booter_bin_end
|
2012-08-31 23:38:12 +00:00
|
|
|
|
2012-09-03 22:05:23 +00:00
|
|
|
#elif defined(HW_DOL)
|
|
|
|
#include "../ngc/sidestep.h"
|
2012-08-31 23:38:12 +00:00
|
|
|
#endif
|
|
|
|
|
2012-09-03 22:05:23 +00:00
|
|
|
#include "rarch_console_exec.h"
|
|
|
|
#include "../retroarch_logger.h"
|
|
|
|
|
2012-08-31 23:38:12 +00:00
|
|
|
#ifdef HW_RVL
|
2012-08-30 22:59:21 +00:00
|
|
|
// NOTE: this does not update the path to point to the new loading .dol file.
|
|
|
|
// we only need it for keeping the current directory anyway.
|
|
|
|
void dol_copy_argv_path(void)
|
|
|
|
{
|
|
|
|
struct __argv *argv = (struct __argv *) ARGS_ADDR;
|
|
|
|
memset(ARGS_ADDR, 0, sizeof(struct __argv));
|
|
|
|
char *cmdline = (char *) ARGS_ADDR + sizeof(struct __argv);
|
|
|
|
argv->argvMagic = ARGV_MAGIC;
|
|
|
|
argv->commandLine = cmdline;
|
|
|
|
size_t len = strlen(__system_argv->argv[0]);
|
|
|
|
memcpy(cmdline, __system_argv->argv[0], ++len);
|
|
|
|
cmdline[len++] = 0;
|
|
|
|
cmdline[len++] = 0;
|
|
|
|
argv->length = len;
|
|
|
|
DCFlushRange(ARGS_ADDR, sizeof(struct __argv) + argv->length);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-07-28 16:26:30 +00:00
|
|
|
void rarch_console_exec(const char *path)
|
2012-07-28 14:35:07 +00:00
|
|
|
{
|
2012-07-28 16:26:30 +00:00
|
|
|
RARCH_LOG("Attempt to load executable: [%s].\n", path);
|
2012-07-28 14:35:07 +00:00
|
|
|
#if defined(_XBOX)
|
2012-07-28 16:26:30 +00:00
|
|
|
XLaunchNewImage(path, NULL);
|
2012-07-28 14:35:07 +00:00
|
|
|
#elif defined(__CELLOS_LV2__)
|
2012-07-28 16:26:30 +00:00
|
|
|
char spawn_data[256];
|
|
|
|
for(unsigned int i = 0; i < sizeof(spawn_data); ++i)
|
|
|
|
spawn_data[i] = i & 0xff;
|
|
|
|
|
|
|
|
char spawn_data_size[16];
|
|
|
|
snprintf(spawn_data_size, sizeof(spawn_data_size), "%d", 256);
|
|
|
|
|
|
|
|
const char * const spawn_argv[] = {
|
|
|
|
spawn_data_size,
|
|
|
|
"test argv for",
|
|
|
|
"sceNpDrmProcessExitSpawn2()",
|
|
|
|
NULL
|
|
|
|
};
|
2012-07-28 14:35:07 +00:00
|
|
|
|
2012-07-28 16:26:30 +00:00
|
|
|
SceNpDrmKey * k_licensee = NULL;
|
|
|
|
int ret = sceNpDrmProcessExitSpawn2(k_licensee, path, (const char** const)spawn_argv, NULL, (sys_addr_t)spawn_data, 256, 1000, SYS_PROCESS_PRIMARY_STACK_SIZE_1M);
|
2012-07-28 14:35:07 +00:00
|
|
|
|
2012-07-28 16:26:30 +00:00
|
|
|
if(ret < 0)
|
|
|
|
{
|
|
|
|
RARCH_WARN("SELF file is not of NPDRM type, trying another approach to boot it...\n");
|
|
|
|
sys_game_process_exitspawn(path, NULL, NULL, NULL, 0, 1000, SYS_PROCESS_PRIMARY_STACK_SIZE_1M);
|
|
|
|
}
|
2012-07-28 14:35:07 +00:00
|
|
|
|
2012-07-28 16:26:30 +00:00
|
|
|
sceNpTerm();
|
|
|
|
sys_net_finalize_network();
|
|
|
|
cellSysmoduleUnloadModule(CELL_SYSMODULE_SYSUTIL_NP);
|
|
|
|
cellSysmoduleUnloadModule(CELL_SYSMODULE_NET);
|
2012-09-03 22:05:23 +00:00
|
|
|
#elif defined(HW_RVL)
|
2012-08-05 22:01:10 +00:00
|
|
|
FILE * fp = fopen(path, "rb");
|
|
|
|
if (fp == NULL)
|
|
|
|
{
|
|
|
|
RARCH_ERR("Could not execute DOL file.\n");
|
|
|
|
return;
|
|
|
|
}
|
2012-08-31 23:38:12 +00:00
|
|
|
|
2012-08-05 22:01:10 +00:00
|
|
|
fseek(fp, 0, SEEK_END);
|
|
|
|
size_t size = ftell(fp);
|
|
|
|
fseek(fp, 0, SEEK_SET);
|
2012-08-30 22:59:21 +00:00
|
|
|
fread(EXECUTE_ADDR, 1, size, fp);
|
2012-08-05 22:01:10 +00:00
|
|
|
fclose(fp);
|
2012-08-30 22:59:21 +00:00
|
|
|
DCFlushRange(EXECUTE_ADDR, size);
|
2012-08-31 23:38:12 +00:00
|
|
|
|
2012-08-30 22:59:21 +00:00
|
|
|
dol_copy_argv_path();
|
|
|
|
|
2012-08-05 22:36:03 +00:00
|
|
|
fatUnmount("carda:");
|
|
|
|
fatUnmount("cardb:");
|
2012-08-30 22:59:21 +00:00
|
|
|
fatUnmount("sd:");
|
|
|
|
fatUnmount("usb:");
|
2012-08-22 19:56:20 +00:00
|
|
|
__io_wiisd.shutdown();
|
|
|
|
__io_usbstorage.shutdown();
|
2012-08-06 17:35:14 +00:00
|
|
|
|
2012-08-31 23:38:12 +00:00
|
|
|
size_t booter_size = booter_end - booter_start;
|
|
|
|
memcpy(BOOTER_ADDR, booter_start, booter_size);
|
2012-08-30 22:59:21 +00:00
|
|
|
DCFlushRange(BOOTER_ADDR, booter_size);
|
2012-08-05 22:36:03 +00:00
|
|
|
|
2012-08-31 23:38:12 +00:00
|
|
|
RARCH_LOG("jumping to %08x\n", (unsigned) BOOTER_ADDR);
|
2012-08-05 22:36:03 +00:00
|
|
|
SYS_ResetSystem(SYS_SHUTDOWN,0,0);
|
2012-08-30 22:59:21 +00:00
|
|
|
__lwp_thread_stopmultitasking((void (*)(void)) BOOTER_ADDR);
|
2012-09-03 22:05:23 +00:00
|
|
|
#elif defined(HW_DOL)
|
|
|
|
DOLtoARAM(path);
|
2012-07-28 14:35:07 +00:00
|
|
|
#else
|
2012-07-28 16:26:30 +00:00
|
|
|
RARCH_WARN("External loading of executables is not supported for this platform.\n");
|
2012-07-28 14:35:07 +00:00
|
|
|
#endif
|
|
|
|
}
|