2012-01-21 21:57:41 +01:00
|
|
|
/* Copyright 2011 Dimok
|
|
|
|
This code is licensed to you under the terms of the GNU GPL, version 2;
|
|
|
|
see file COPYING or http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt */
|
|
|
|
#include <gccore.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include "string.h"
|
|
|
|
|
|
|
|
#include "dolloader.h"
|
|
|
|
#include "elfloader.h"
|
|
|
|
#include "sync.h"
|
|
|
|
|
2013-01-21 18:12:18 +01:00
|
|
|
#define EXECUTABLE_MEM_ADDR 0x92000000
|
2014-06-24 15:33:54 +02:00
|
|
|
#define SYSTEM_ARGV ((struct __argv *)0x93300800)
|
2012-01-21 21:57:41 +01:00
|
|
|
|
2014-03-23 21:14:59 +01:00
|
|
|
void _main(void)
|
2012-01-21 21:57:41 +01:00
|
|
|
{
|
2012-12-30 15:11:16 +01:00
|
|
|
void *exeBuffer = (void *)EXECUTABLE_MEM_ADDR;
|
2012-01-21 21:57:41 +01:00
|
|
|
u32 exeEntryPointAddress = 0;
|
|
|
|
entrypoint exeEntryPoint;
|
|
|
|
|
2012-12-30 15:11:16 +01:00
|
|
|
if(valid_elf_image(exeBuffer) == 1)
|
2012-01-21 21:57:41 +01:00
|
|
|
exeEntryPointAddress = load_elf_image(exeBuffer);
|
|
|
|
else
|
|
|
|
exeEntryPointAddress = load_dol_image(exeBuffer);
|
|
|
|
|
2012-12-30 15:11:16 +01:00
|
|
|
exeEntryPoint = (entrypoint)exeEntryPointAddress;
|
|
|
|
if(!exeEntryPoint)
|
2012-01-21 21:57:41 +01:00
|
|
|
return;
|
|
|
|
|
2012-12-30 15:11:16 +01:00
|
|
|
if(SYSTEM_ARGV->argvMagic == ARGV_MAGIC)
|
2012-01-21 21:57:41 +01:00
|
|
|
{
|
|
|
|
void *new_argv = (void *) (exeEntryPointAddress + 8);
|
|
|
|
memcpy(new_argv, SYSTEM_ARGV, sizeof(struct __argv));
|
|
|
|
sync_before_exec(new_argv, sizeof(struct __argv));
|
|
|
|
}
|
|
|
|
|
2012-12-30 15:11:16 +01:00
|
|
|
exeEntryPoint();
|
2012-01-21 21:57:41 +01:00
|
|
|
}
|