2009-10-01 01:10:58 +02:00
|
|
|
#include <malloc.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <ogc/machine/processor.h>
|
|
|
|
#include <gccore.h>
|
|
|
|
#include <dirent.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#include "dolloader.h"
|
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
typedef struct _dolheader
|
|
|
|
{
|
2009-10-01 01:10:58 +02:00
|
|
|
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;
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
u32 load_dol(const void *dolstart, struct __argv *argv)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2009-10-01 01:10:58 +02:00
|
|
|
u32 i;
|
|
|
|
dolheader *dolfile;
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
if (dolstart)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
dolfile = (dolheader *) dolstart;
|
|
|
|
for (i = 0; i < 7; i++)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
if ((!dolfile->text_size[i]) || (dolfile->text_start[i] < 0x100)) continue;
|
|
|
|
ICInvalidateRange((void *) dolfile->text_start[i], dolfile->text_size[i]);
|
|
|
|
memcpy((void *) dolfile->text_start[i], dolstart + dolfile->text_pos[i], dolfile->text_size[i]);
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
for (i = 0; i < 11; i++)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
if ((!dolfile->data_size[i]) || (dolfile->data_start[i] < 0x100)) continue;
|
|
|
|
memcpy((void *) dolfile->data_start[i], dolstart + dolfile->data_pos[i], dolfile->data_size[i]);
|
|
|
|
DCFlushRangeNoSync((void *) dolfile->data_start[i], dolfile->data_size[i]);
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
memset((void *) dolfile->bss_start, 0, dolfile->bss_size);
|
|
|
|
DCFlushRange((void *) dolfile->bss_start, dolfile->bss_size);
|
2009-10-01 01:10:58 +02:00
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
if (argv && argv->argvMagic == ARGV_MAGIC)
|
2010-09-19 01:16:05 +02:00
|
|
|
{
|
2010-09-24 02:48:03 +02:00
|
|
|
void *new_argv = (void *) (dolfile->entry_point + 8);
|
|
|
|
memcpy(new_argv, argv, sizeof(*argv));
|
|
|
|
DCFlushRange(new_argv, sizeof(*argv));
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return dolfile->entry_point;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|