21extern u8 loader_elf[];
22extern int size_loader_elf;
25#define ELF_MAGIC 0x464c457f
28static bool file_exists(
const char *filename) {
30 return (stat (filename, &buffer) == 0);
42static void wipe_bramMem(
void) {
45 for (i = 0x00084000; i < 0x100000; i += 64) {
50 "\tsq $0, 48(%0) \n" ::
"r"(i));
53 memset((
void *)0x00084000, 0, 0x100000 - 0x00084000);
57static int LoadELFFromFileResetCommon(
const char *filename,
const char *
partition,
int reset,
int argc,
char *argv[]) {
63 int new_argc = argc + 3;
66 if (!file_exists(filename)) {
73 char *new_argv[argc + 3];
75 new_argv[1] = (
char *)filename;
76 new_argv[2] = reset ?
"1" :
"0";
77 for (i = 0; i < argc; i++) {
78 new_argv[i + 3] = argv[i];
82 boot_elf = (u8 *)loader_elf;
84 if (_lw((u32)&eh->ident) != ELF_MAGIC)
90 for (i = 0; i < eh->phnum; i++) {
91 if (eph[i].type != ELF_PT_LOAD)
94 pdata = (
void *)(boot_elf + eph[i].offset);
95 memcpy(eph[i].vaddr, pdata, eph[i].filesz);
97 if (eph[i].memsz > eph[i].filesz)
98 memset((
void *)((u8 *)(eph[i].vaddr) + eph[i].filesz), 0, eph[i].memsz - eph[i].filesz);
106 return ExecPS2((
void *)eh->entry, NULL, new_argc, new_argv);
110 return LoadELFFromFileResetCommon(filename,
partition, 1, argc, argv);
113int LoadELFFromFileWithPartitionNoReset(
const char *filename,
const char *
partition,
int argc,
char *argv[]) {
114 return LoadELFFromFileResetCommon(filename,
partition, 0, argc, argv);
117int LoadELFFromFile(
const char *filename,
int argc,
char *argv[])
int LoadELFFromFileWithPartition(const char *filename, const char *partition, int argc, char *argv[])