What's wrong with this DOL launcher?
Hey, all!
I'm using libwiigui to sort of create an "onboard operating system", but right now, I'm having trouble with launching DOLs.
I tried to launch a DOL...and the bg music on libwiigui started "lagging", like
ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ
I don't really know how to explain it. O_O
I also need the console to debug my load function, so I'll know what's wrong.
Is there a problem with my code?
Or do I have to "exit" libwiigui?
dol.c
PHP Code:
/*
* @author: Tonyyyyyyy
*
* @summary: This file provides functions for launching DOLs.
* @origin: Based off of *cough* ripped off of *cough* geckoloader.
*
* @date: 7.19.2010
*/
#include "dol.h"
// This is from geckoloader...
// this code was contributed by shagkur of the devkitpro team, thx!
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;
\
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;
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);
return dolfile->entry_point;
}
return 0;
}
launch.cpp
PHP Code:
#include "launch.h"
//extern void __exception_closeall();
//extern s32 __IOS_ShutdownSubsystems();
s32 getImageType(void * addr)
{
Elf32_Ehdr *ehdr; /* Elf header structure pointer */
ehdr = (Elf32_Ehdr *) addr;
if (!IS_ELF (*ehdr))
return 0;
if (ehdr->e_type != ET_EXEC)
return -1;
if (ehdr->e_machine != EM_PPC)
return -1;
return 1;
}
int launch(char locdir[999], char filname[13])
{
/*
//Set this...
unsigned int i;
for(i = 0; i < strlen(locdir); i++)
{
if((i+1) != strlen(locdir))
locdir[i] = locdir[i +1];
else
locdir[i] = '/';
}
printf("%s", locdir);
sleep(5000);*/
//Variables
/*
FATFS ffs;
DIR appdir;
char filename[50+1];
char thefile[1][50];
FILINFO finfo;
FIL fp;
WORD bytes_read;
u32 bytes_read_total;
u8 *data = (u8 *)0x92000000;
*/
s32 res;
u32 level;
if(!fatInitDefault())
{
//Error handler here...
}
//ELF/DOL buffer
void * buffer;
//Entry point
void (*ep)();
char formatted[999];
sprintf(formatted, "%s/%s", locdir, filname);
//Mount FAT FS
//if(f_mount(0, &ffs) != FR_OK)
//return -1;
//res = f_opendir(&appdir, locdir);
//if(res != FR_OK)
//return -1;
FILE * inputFile;
inputFile = fopen(formatted, "rb");
/*
memset(&finfo, 0, sizeof(finfo));
f_readdir(&appdir, &finfo);
while(strlen(finfo.fname) != 0)
{
if(strtoupper(finfo.fname) == strtoupper(filname))
{
memcpy(thefile[0], finfo.fname, strlen(finfo.fname));
printf(thefile[0]);
sleep(5000);
}
f_readdir(&appdir, &finfo);
}
snprintf(filename, 50, "%s%s", locdir, filname);
//"Pre-checking" phase
if(f_stat(filename, &finfo) != FR_OK)
return -1;
if(f_open(&fp, filename, FA_READ) != FR_OK)
return -1;
*/
int pos = ftell(inputFile);
fseek(inputFile, 0, SEEK_END);
int size = ftell(inputFile);
fseek(inputFile, pos, SEEK_SET);
buffer = malloc(size);
fread(buffer, 1, size, inputFile);
//Now that we're done with our checks, let's start reading the file.
//bytes_read = bytes_read_total = 0;
res = getImageType(buffer);
if(res == 1)//ELF
{
}
else//Probably a DOL...
{
ep = (void(*)())load_dol_image(buffer);
}
fclose(inputFile);
__IOS_ShutdownSubsystems();
_CPU_ISR_Disable (level);
__exception_closeall ();
//This is it!
ep();
//And we're back.
_CPU_ISR_Restore (level);
//Successful?
return 0;
}
int test()
{
return 1;
}