From 124c3f05ed9e1f304c4503b8af2948bed0eb2c1c Mon Sep 17 00:00:00 2001 From: dimok321 <15055714+dimok789@users.noreply.github.com> Date: Mon, 15 Jun 2009 23:11:36 +0000 Subject: [PATCH] Forwarder changes: *Fixed Codedumps from Preload *Fixed USB not working *Changed back to old LoadMii dolloader (which is working with preloader too now) --- source/cfg.c | 2 +- source/dolloader.c | 128 +++++++++++++++++++-------------------------- source/dolloader.h | 16 ------ source/main.cpp | 81 ++++++++++++++++++---------- 4 files changed, 108 insertions(+), 119 deletions(-) diff --git a/source/cfg.c b/source/cfg.c index 83a26541..85bc8a88 100644 --- a/source/cfg.c +++ b/source/cfg.c @@ -8,7 +8,7 @@ #include "cfg.h" -char update_path[150]=""; +char update_path[150]; static char *cfg_name, *cfg_val; diff --git a/source/dolloader.c b/source/dolloader.c index ae5b4b95..7a6629d9 100644 --- a/source/dolloader.c +++ b/source/dolloader.c @@ -1,74 +1,54 @@ -// this code was contributed by shagkur of the devkitpro team, thx! - -#include -#include - -#include -#include - -typedef struct _dolheader { - u32 text_pos[7]; - u32 data_pos[11]; - u32 text_start[7]; - u32 data_start[11]; - u32 text_size[7]; - u32 data_size[11]; - u32 bss_start; - u32 bss_size; - u32 entry_point; -} dolheader; - -u32 load_dol_image (void *dolstart) { - u32 i; - dolheader *dolfile; - - if (dolstart) { - dolfile = (dolheader *) dolstart; - for (i = 0; i < 7; i++) { - if ((!dolfile->text_size[i]) || - (dolfile->text_start[i] < 0x100)) - continue; - - /*printf ("loading text section %u @ 0x%08x " - "(0x%08x bytes)\n", - i, dolfile->text_start[i], - dolfile->text_size[i]);*/ - VIDEO_WaitVSync(); - - ICInvalidateRange ((void *) dolfile->text_start[i], - dolfile->text_size[i]); - memmove ((void *) dolfile->text_start[i], - dolstart+dolfile->text_pos[i], - dolfile->text_size[i]); - } - - for(i = 0; i < 11; i++) { - if ((!dolfile->data_size[i]) || - (dolfile->data_start[i] < 0x100)) - continue; - - /*printf ("loading data section %u @ 0x%08x " - "(0x%08x bytes)\n", - i, dolfile->data_start[i], - dolfile->data_size[i]);*/ - VIDEO_WaitVSync(); - - 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]); - } - - //printf ("clearing bss\n"); - VIDEO_WaitVSync(); - - memset ((void *) dolfile->bss_start, 0, dolfile->bss_size); - DCFlushRange((void *) dolfile->bss_start, dolfile->bss_size); - - return dolfile->entry_point; - } - - return 0; -} - +#include +#include +#include +#include +#include +#include +#include + +#include "dolloader.h" + +typedef struct _dolheader { + u32 text_pos[7]; + u32 data_pos[11]; + u32 text_start[7]; + u32 data_start[11]; + u32 text_size[7]; + u32 data_size[11]; + u32 bss_start; + u32 bss_size; + u32 entry_point; +} dolheader; + +u32 load_dol_image (void *dolstart, struct __argv *argv) { + u32 i; + dolheader *dolfile; + + if (dolstart) { + dolfile = (dolheader *) dolstart; + for (i = 0; i < 7; i++) { + if ((!dolfile->text_size[i]) || (dolfile->text_start[i] < 0x100)) continue; + VIDEO_WaitVSync(); + ICInvalidateRange ((void *) dolfile->text_start[i],dolfile->text_size[i]); + memmove ((void *) dolfile->text_start[i],dolstart+dolfile->text_pos[i],dolfile->text_size[i]); + } + + for(i = 0; i < 11; i++) { + if ((!dolfile->data_size[i]) || (dolfile->data_start[i] < 0x100)) continue; + VIDEO_WaitVSync(); + 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]); + } + + memset ((void *) dolfile->bss_start, 0, dolfile->bss_size); + DCFlushRange((void *) dolfile->bss_start, dolfile->bss_size); + + if (argv && argv->argvMagic == ARGV_MAGIC) { + void *new_argv = (void *)(dolfile->entry_point + 8); + memmove(new_argv, argv, sizeof(*argv)); + DCFlushRange(new_argv, sizeof(*argv)); + } + return dolfile->entry_point; + } + return 0; +} diff --git a/source/dolloader.h b/source/dolloader.h index 52c12e46..7dcc2921 100644 --- a/source/dolloader.h +++ b/source/dolloader.h @@ -1,8 +1,6 @@ #ifndef _DOLLOADER_H_ #define _DOLLOADER_H_ -#include - #ifdef __cplusplus extern "C" { @@ -12,23 +10,9 @@ extern "C" #define EXECUTABLE_MEM_ADDR 0x92000000 /* dol header */ - extern void __exception_closeall(); typedef void (*entrypoint) (void); - -typedef struct _dolheader { - u32 text_pos[7]; - u32 data_pos[11]; - u32 text_start[7]; - u32 data_start[11]; - u32 text_size[7]; - u32 data_size[11]; - u32 bss_start; - u32 bss_size; - u32 entry_point; -} dolheader; - u32 load_dol_image (void *dolstart, struct __argv *argv); diff --git a/source/main.cpp b/source/main.cpp index 1d90785a..7750d15c 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -25,13 +25,10 @@ */ #include -#include -#include -#include #include #include -#include #include +#include #include #include "pngu/pngu.h" @@ -43,8 +40,8 @@ #include "fatmounter.h" -PNGUPROP imgProp; -IMGCTX ctx; +static PNGUPROP imgProp; +static IMGCTX ctx; u8 * GetImageData(void) { @@ -108,49 +105,65 @@ int main(int argc, char **argv) /* check devices */ SDCard_Init(); USBDevice_Init(); + char cfgpath[256]; + bool result = false; sprintf(cfgpath, "SD:/config/GXGlobal.cfg"); - if(!cfg_parsefile(cfgpath, &cfg_set)) //no cfg-File on SD: try USB: + result = cfg_parsefile(cfgpath, &cfg_set); + if(!result) //no cfg-File on SD: try USB: { sprintf(cfgpath, "USB:/config/GXGlobal.cfg"); - cfg_parsefile(cfgpath, &cfg_set); + result = cfg_parsefile(cfgpath, &cfg_set); } - if(update_path[0] == '\0') // non cfg-File loaded or update_path not set + + if(result) + { + sprintf(cfgpath, "%sboot.dol", update_path); + /* Open dol File and check exist */ + exeFile = fopen (cfgpath, "rb"); + if (exeFile==NULL) + { + sprintf(cfgpath, "%sboot.elf", update_path); + exeFile = fopen (cfgpath,"rb"); + } + if (exeFile==NULL) + result = false; + else + result = true; + } + + if(!result) // non cfg-File loaded or update_path not set { /* Open dol File and check exist */ - strcpy(cfgpath, "SD:/apps/usbloader_gx/boot.dol"); + sprintf(cfgpath, "SD:/apps/usbloader_gx/boot.dol"); exeFile = fopen (cfgpath ,"rb"); if (exeFile==NULL) { - strcpy(cfgpath, "SD:/apps/usbloader_gx/boot.elf"); + sprintf(cfgpath, "SD:/apps/usbloader_gx/boot.elf"); exeFile = fopen (cfgpath ,"rb"); } if (exeFile==NULL) { - strcpy(cfgpath, "USB:/apps/usbloader_gx/boot.dol"); + sprintf(cfgpath, "USB:/apps/usbloader_gx/boot.dol"); exeFile = fopen (cfgpath ,"rb"); } if (exeFile==NULL) { - strcpy(cfgpath, "USB:/apps/usbloader_gx/boot.elf"); + sprintf(cfgpath, "USB:/apps/usbloader_gx/boot.elf"); exeFile = fopen (cfgpath ,"rb"); } - if (exeFile==NULL) + // if nothing found exiting + if (exeFile==NULL) { + printf("\n\n\t\tCan't find DOL File...\n"); + Menu_Render(); + sleep(3); + fclose (exeFile); + SDCard_deInit(); + USBDevice_deInit(); + StopGX(); SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0); - } - else - { - sprintf(cfgpath, "%sboot.dol", update_path); - /* Open dol File and check exist */ - exeFile = fopen (cfgpath, "rb"); - if (exeFile==NULL) - { - sprintf(cfgpath, "%sboot.elf", update_path); - exeFile = fopen (cfgpath,"rb"); } - if (exeFile==NULL) - SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0); } fseek (exeFile, 0, SEEK_END); @@ -159,7 +172,13 @@ int main(int argc, char **argv) if(fread (exeBuffer, 1, exeSize, exeFile) != (unsigned int) exeSize) { - printf("Can't open DOL File...\n"); + printf("\n\n\t\tCan't open DOL File...\n"); + Menu_Render(); + fclose (exeFile); + sleep(3); + SDCard_deInit(); + USBDevice_deInit(); + StopGX(); SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0); } fclose (exeFile); @@ -172,7 +191,7 @@ int main(int argc, char **argv) args.commandLine = (char*)malloc(args.length); if (!args.commandLine) SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0); strcpy(args.commandLine, cfgpath); - args.commandLine[args.length - 1] = '\x00'; + args.commandLine[args.length - 1] = '\0'; args.argc = 1; args.argv = &args.commandLine; args.endARGV = args.argv + 1; @@ -195,6 +214,12 @@ int main(int argc, char **argv) StopGX(); if (exeEntryPointAddress == 0) { printf("EntryPointAddress failed...\n"); + Menu_Render(); + sleep(3); + fclose (exeFile); + SDCard_deInit(); + USBDevice_deInit(); + StopGX(); SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0);; } exeEntryPoint = (entrypoint) exeEntryPointAddress;