From cc52ee9754f9c4e64a00e983b66a81075b8ad940 Mon Sep 17 00:00:00 2001 From: Toad King Date: Mon, 6 Aug 2012 13:35:14 -0400 Subject: [PATCH] (Wii) forward arguments to loaded DOL files, fixes paths --- console/exec/dol.c | 28 +++++++++++++++++++++------- console/exec/dol.h | 6 ++---- console/rarch_console_exec.c | 11 ++++++++--- wii/salamander/main.c | 16 ++++++++-------- 4 files changed, 39 insertions(+), 22 deletions(-) diff --git a/console/exec/dol.c b/console/exec/dol.c index 280bade59f..343cf218fa 100644 --- a/console/exec/dol.c +++ b/console/exec/dol.c @@ -5,6 +5,7 @@ #include #include +#include #include #include "../../retroarch_logger.h" @@ -22,7 +23,9 @@ typedef struct _dolheader uint32_t entry_point; } dolheader; -uint32_t load_dol_image (void *dolstart) +static char dol_argv_commandline[1024]; + +uint32_t *load_dol_image (void *dolstart) { uint32_t i; dolheader *dolfile; @@ -35,7 +38,7 @@ uint32_t load_dol_image (void *dolstart) if ((!dolfile->text_size[i]) || (dolfile->text_start[i] < 0x100)) continue; - RARCH_LOG("loading text section %u @ 0x%08x (0x%08x bytes)\n", + RARCH_LOG("loading text section %u @ 0x%08x (0x%08x bytes)\n", i, dolfile->text_start[i], dolfile->text_size[i]); ICInvalidateRange ((void *) dolfile->text_start[i], @@ -50,13 +53,13 @@ uint32_t load_dol_image (void *dolstart) if ((!dolfile->data_size[i]) || (dolfile->data_start[i] < 0x100)) continue; - RARCH_LOG("loading data section %u @ 0x%08x (0x%08x bytes)\n", i, + RARCH_LOG("loading data section %u @ 0x%08x (0x%08x bytes)\n", i, dolfile->data_start[i], dolfile->data_size[i]); - memmove ((void*) dolfile->data_start[i], dolstart+dolfile->data_pos[i], + memmove ((void*) dolfile->data_start[i], dolstart+dolfile->data_pos[i], dolfile->data_size[i]); - DCFlushRangeNoSync ((void *) dolfile->data_start[i], dolfile->data_size[i]); + DCFlushRangeNoSync ((void *) dolfile->data_start[i], dolfile->data_size[i]); } RARCH_LOG("clearing bss\n"); @@ -64,9 +67,20 @@ uint32_t load_dol_image (void *dolstart) memset ((void *) dolfile->bss_start, 0, dolfile->bss_size); DCFlushRange((void *) dolfile->bss_start, dolfile->bss_size); - return dolfile->entry_point; + return (uint32_t *) dolfile->entry_point; } - return 0; + return NULL; } +// NOTE: this does not update the path to point to the new loading .dol file. +// we only ues it for keeping the current path anyway. +void dol_copy_argv(struct __argv *argv) +{ + memcpy(dol_argv_commandline, __system_argv->commandLine, __system_argv->length); + DCFlushRange((void *) dol_argv_commandline, sizeof(dol_argv_commandline)); + argv->argvMagic = ARGV_MAGIC; + argv->commandLine = dol_argv_commandline; + argv->length = __system_argv->length; + DCFlushRange((void *) argv, sizeof(struct __argv)); +} diff --git a/console/exec/dol.h b/console/exec/dol.h index f686bc4138..ca21b56d77 100644 --- a/console/exec/dol.h +++ b/console/exec/dol.h @@ -24,10 +24,8 @@ #include -uint32_t load_dol_image (void *dolstart); - -extern void __exception_closeall(void); -extern int32_t __IOS_ShutdownSubSystems(void); +uint32_t *load_dol_image (void *dolstart); +void dol_copy_argv(struct __argv *argv); #endif diff --git a/console/rarch_console_exec.c b/console/rarch_console_exec.c index e863808ede..29b94fdbbe 100644 --- a/console/rarch_console_exec.c +++ b/console/rarch_console_exec.c @@ -29,6 +29,7 @@ #include #include #include +#include #include "exec/dol.h" #endif @@ -87,12 +88,16 @@ void rarch_console_exec(const char *path) #endif fatUnmount("carda:"); fatUnmount("cardb:"); - void (*ep)() = (void(*)())load_dol_image(mem); - RARCH_LOG("jumping to 0x%08X\n", (uint32_t)ep); + uint32_t *ep = load_dol_image(mem); + + if (ep[1] == ARGV_MAGIC) + dol_copy_argv((struct __argv *) &ep[2]); + + RARCH_LOG("jumping to 0x%08X\n", (uint32_t) ep); SYS_ResetSystem(SYS_SHUTDOWN,0,0); - __lwp_thread_stopmultitasking(ep); + __lwp_thread_stopmultitasking((void(*)()) ep); #else RARCH_WARN("External loading of executables is not supported for this platform.\n"); #endif diff --git a/wii/salamander/main.c b/wii/salamander/main.c index b24187fdd8..262904199b 100644 --- a/wii/salamander/main.c +++ b/wii/salamander/main.c @@ -48,11 +48,11 @@ static void find_and_set_first_file(void) //Last fallback - we'll need to start the first executable file // we can find in the RetroArch cores directory - char first_file[512]; + char first_file[512] = {0}; rarch_manage_libretro_set_first_file(first_file, sizeof(first_file), LIBRETRO_DIR_PATH, "dol"); - if(first_file) + if(first_file[0]) strlcpy(libretro_path, first_file, sizeof(libretro_path)); else RARCH_ERR("Failed last fallback - RetroArch Salamander will exit.\n"); @@ -89,8 +89,8 @@ static void init_settings(void) if(config_file_exists) { config_file_t * conf = config_file_new(SYS_CONFIG_FILE); - config_get_array(conf, "libretro_path", tmp_str, sizeof(tmp_str)); - snprintf(libretro_path, sizeof(libretro_path), tmp_str); + config_get_array(conf, "libretro_path", tmp_str, sizeof(tmp_str)); + snprintf(libretro_path, sizeof(libretro_path), tmp_str); } if(!config_file_exists || !strcmp(libretro_path, "")) @@ -111,14 +111,14 @@ static void get_environment_settings(void) int main(int argc, char *argv[]) { -#ifdef HAVE_LOGGER - logger_init(); -#endif - #ifdef HW_RVL L2Enhance(); #endif +#ifdef HAVE_LOGGER + logger_init(); +#endif + fatInitDefault(); getcwd(app_dir, sizeof(app_dir));