2010-09-19 01:04:39 +02:00
|
|
|
#if 0
|
2010-09-16 21:59:41 +02:00
|
|
|
#include <gccore.h>
|
|
|
|
#include <ogcsys.h>
|
|
|
|
#include <malloc.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <ogc/machine/processor.h>
|
|
|
|
#include <wiiuse/wpad.h>
|
|
|
|
#include <vector>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
#include "usbloader/usbstorage2.h"
|
|
|
|
#include "dolloader.h"
|
|
|
|
#include "fatmounter.h"
|
|
|
|
#include "sys.h"
|
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
extern const u8 app_booter_dol[];
|
2010-09-16 21:59:41 +02:00
|
|
|
extern const u32 app_booter_dol_size;
|
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
static u8 *homebrewbuffer = ( u8 * ) 0x92000000;
|
2010-09-16 21:59:41 +02:00
|
|
|
static int homebrewsize = 0;
|
|
|
|
static std::vector<std::string> Arguments;
|
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
void AddBootArgument( const char * argv )
|
2010-09-16 21:59:41 +02:00
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
std::string arg( argv );
|
|
|
|
Arguments.push_back( arg );
|
2010-09-16 21:59:41 +02:00
|
|
|
}
|
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
int CopyHomebrewMemory( u8 *temp, u32 pos, u32 len )
|
2010-09-16 21:59:41 +02:00
|
|
|
{
|
|
|
|
homebrewsize += len;
|
2010-09-19 01:16:05 +02:00
|
|
|
memcpy( ( homebrewbuffer ) + pos, temp, len );
|
2010-09-16 21:59:41 +02:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void FreeHomebrewBuffer()
|
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
homebrewbuffer = ( u8 * )0x92000000;
|
2010-09-16 21:59:41 +02:00
|
|
|
homebrewsize = 0;
|
|
|
|
}
|
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
static int SetupARGV( struct __argv * args )
|
2010-09-16 21:59:41 +02:00
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
if ( !args )
|
2010-09-16 21:59:41 +02:00
|
|
|
return -1;
|
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
bzero( args, sizeof( struct __argv ) );
|
2010-09-16 21:59:41 +02:00
|
|
|
args->argvMagic = ARGV_MAGIC;
|
|
|
|
|
|
|
|
u32 stringlength = 1;
|
|
|
|
|
|
|
|
/** Append Arguments **/
|
2010-09-19 01:16:05 +02:00
|
|
|
for ( u32 i = 0; i < Arguments.size(); i++ )
|
2010-09-16 21:59:41 +02:00
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
stringlength += Arguments[i].size() + 1;
|
2010-09-16 21:59:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
args->length = stringlength;
|
2010-09-19 01:16:05 +02:00
|
|
|
args->commandLine = ( char* ) malloc( args->length );
|
|
|
|
if ( !args->commandLine )
|
2010-09-16 21:59:41 +02:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
u32 argc = 0;
|
|
|
|
u32 position = 0;
|
|
|
|
|
|
|
|
/** Append Arguments **/
|
2010-09-19 01:16:05 +02:00
|
|
|
for ( u32 i = 0; i < Arguments.size(); i++ )
|
2010-09-16 21:59:41 +02:00
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
strcpy( &args->commandLine[position], Arguments[i].c_str() );
|
|
|
|
position += Arguments[i].size() + 1;
|
2010-09-16 21:59:41 +02:00
|
|
|
argc++;
|
|
|
|
}
|
|
|
|
|
|
|
|
args->argc = argc;
|
|
|
|
|
|
|
|
args->commandLine[args->length - 1] = '\0';
|
|
|
|
args->argv = &args->commandLine;
|
|
|
|
args->endARGV = args->argv + 1;
|
|
|
|
|
|
|
|
Arguments.clear();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int BootHomebrew()
|
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
if ( homebrewsize <= 0 )
|
2010-09-16 21:59:41 +02:00
|
|
|
Sys_BackToLoader();
|
|
|
|
|
|
|
|
SDCard_deInit();
|
|
|
|
USBDevice_deInit();
|
|
|
|
USBStorage2_Deinit();
|
|
|
|
|
|
|
|
struct __argv args;
|
2010-09-19 01:16:05 +02:00
|
|
|
SetupARGV( &args );
|
2010-09-16 21:59:41 +02:00
|
|
|
|
|
|
|
u32 cpu_isr;
|
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
entrypoint entry = ( entrypoint ) load_dol( app_booter_dol, &args );
|
2010-09-16 21:59:41 +02:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
if ( !entry )
|
2010-09-16 21:59:41 +02:00
|
|
|
Sys_BackToLoader();
|
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
VIDEO_SetBlack( true );
|
2010-09-19 01:04:39 +02:00
|
|
|
VIDEO_Flush();
|
|
|
|
VIDEO_WaitVSync();
|
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
SYS_ResetSystem( SYS_SHUTDOWN, 0, 0 );
|
|
|
|
_CPU_ISR_Disable ( cpu_isr );
|
2010-09-16 21:59:41 +02:00
|
|
|
__exception_closeall();
|
|
|
|
entry();
|
2010-09-19 01:16:05 +02:00
|
|
|
_CPU_ISR_Restore ( cpu_isr );
|
2010-09-16 21:59:41 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
int BootHomebrew( const char * filepath )
|
2010-09-16 21:59:41 +02:00
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
FILE * file = fopen( filepath, "rb" );
|
|
|
|
if ( !file )
|
2010-09-16 21:59:41 +02:00
|
|
|
Sys_BackToLoader();
|
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
fseek( file, 0, SEEK_END );
|
2010-09-16 21:59:41 +02:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
int size = ftell( file );
|
|
|
|
rewind( file );
|
2010-09-16 21:59:41 +02:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
homebrewsize = fread( homebrewbuffer, 1, size, file );
|
|
|
|
fclose( file );
|
2010-09-16 21:59:41 +02:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
AddBootArgument( filepath );
|
2010-09-16 21:59:41 +02:00
|
|
|
|
|
|
|
return BootHomebrew();
|
|
|
|
}
|
2010-09-19 01:04:39 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <gccore.h>
|
|
|
|
#include <ogcsys.h>
|
|
|
|
#include <malloc.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <ogc/machine/processor.h>
|
|
|
|
#include <wiiuse/wpad.h>
|
|
|
|
#include <vector>
|
|
|
|
#include <string>
|
|
|
|
#include "../lstub.h"
|
|
|
|
#include "../sys.h"
|
|
|
|
#include "../gecko.h"
|
|
|
|
|
|
|
|
#include "fatmounter.h"
|
|
|
|
#include "dolloader.h"
|
|
|
|
|
|
|
|
|
|
|
|
void *innetbuffer = NULL;
|
2010-09-19 01:16:05 +02:00
|
|
|
static u8 *homebrewbuffer = ( u8 * )0x92000000;
|
2010-09-19 01:04:39 +02:00
|
|
|
u32 homebrewsize = 0;
|
|
|
|
static std::vector<std::string> Arguments;
|
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
extern const u8 app_booter_dol[];
|
2010-09-19 01:04:39 +02:00
|
|
|
|
|
|
|
int AllocHomebrewMemory( u32 filesize )
|
|
|
|
{
|
|
|
|
|
|
|
|
innetbuffer = malloc( filesize );
|
|
|
|
|
|
|
|
if ( !innetbuffer )
|
2010-09-19 01:16:05 +02:00
|
|
|
return -1;
|
2010-09-19 01:04:39 +02:00
|
|
|
|
|
|
|
homebrewsize = filesize;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void AddBootArgument( const char * argv )
|
|
|
|
{
|
|
|
|
std::string arg( argv );
|
|
|
|
Arguments.push_back( arg );
|
|
|
|
}
|
|
|
|
|
|
|
|
int CopyHomebrewMemory( u8 *temp, u32 pos, u32 len )
|
|
|
|
{
|
|
|
|
homebrewsize += len;
|
2010-09-19 01:16:05 +02:00
|
|
|
memcpy( ( homebrewbuffer ) + pos, temp, len );
|
2010-09-19 01:04:39 +02:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void FreeHomebrewBuffer()
|
|
|
|
{
|
|
|
|
homebrewbuffer = ( u8 * ) 0x92000000;
|
|
|
|
homebrewsize = 0;
|
|
|
|
|
|
|
|
if ( innetbuffer )
|
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
free( innetbuffer );
|
|
|
|
innetbuffer = NULL;
|
2010-09-19 01:04:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Arguments.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
static int SetupARGV( struct __argv * args )
|
|
|
|
{
|
|
|
|
if ( !args )
|
2010-09-19 01:16:05 +02:00
|
|
|
return -1;
|
2010-09-19 01:04:39 +02:00
|
|
|
|
|
|
|
bzero( args, sizeof( struct __argv ) );
|
|
|
|
args->argvMagic = ARGV_MAGIC;
|
|
|
|
|
|
|
|
u32 stringlength = 1;
|
|
|
|
|
|
|
|
/** Append Arguments **/
|
|
|
|
for ( u32 i = 0; i < Arguments.size(); i++ )
|
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
stringlength += Arguments[i].size() + 1;
|
2010-09-19 01:04:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
args->length = stringlength;
|
|
|
|
args->commandLine = ( char* ) malloc( args->length );
|
|
|
|
|
|
|
|
if ( !args->commandLine )
|
2010-09-19 01:16:05 +02:00
|
|
|
return -1;
|
2010-09-19 01:04:39 +02:00
|
|
|
|
|
|
|
u32 argc = 0;
|
|
|
|
u32 position = 0;
|
|
|
|
|
|
|
|
/** Append Arguments **/
|
|
|
|
for ( u32 i = 0; i < Arguments.size(); i++ )
|
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
strcpy( &args->commandLine[position], Arguments[i].c_str() );
|
|
|
|
position += Arguments[i].size() + 1;
|
|
|
|
argc++;
|
2010-09-19 01:04:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
args->argc = argc;
|
|
|
|
|
|
|
|
args->commandLine[args->length - 1] = '\0';
|
|
|
|
args->argv = &args->commandLine;
|
|
|
|
args->endARGV = args->argv + 1;
|
|
|
|
|
|
|
|
Arguments.clear();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int RunAppbooter()
|
|
|
|
{
|
|
|
|
if ( homebrewsize == 0 )
|
2010-09-19 01:16:05 +02:00
|
|
|
return -1;
|
2010-09-19 01:04:39 +02:00
|
|
|
|
|
|
|
struct __argv args;
|
|
|
|
SetupARGV( &args );
|
|
|
|
|
|
|
|
u32 cpu_isr;
|
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
entrypoint entry = ( entrypoint ) load_dol( ( void* ) app_booter_dol, &args );
|
2010-09-19 01:04:39 +02:00
|
|
|
|
|
|
|
if ( !entry )
|
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
FreeHomebrewBuffer();
|
|
|
|
return -1;
|
2010-09-19 01:04:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
u64 currentStub = getStubDest();
|
|
|
|
loadStub();
|
|
|
|
|
|
|
|
if ( Set_Stub_Split( 0x00010001, "UNEO" ) < 0 )
|
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
if ( Set_Stub_Split( 0x00010001, "ULNR" ) < 0 )
|
|
|
|
{
|
|
|
|
if ( !currentStub )
|
|
|
|
currentStub = 0x100000002ULL;
|
2010-09-19 01:04:39 +02:00
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
Set_Stub( currentStub );
|
|
|
|
}
|
2010-09-19 01:04:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
SDCard_deInit();
|
|
|
|
USBDevice_deInit();
|
|
|
|
|
|
|
|
WPAD_Flush( 0 );
|
|
|
|
WPAD_Disconnect( 0 );
|
|
|
|
WPAD_Shutdown();
|
|
|
|
|
|
|
|
SYS_ResetSystem( SYS_SHUTDOWN, 0, 0 );
|
|
|
|
_CPU_ISR_Disable( cpu_isr );
|
|
|
|
__exception_closeall();
|
|
|
|
entry();
|
|
|
|
_CPU_ISR_Restore( cpu_isr );
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int BootHomebrew( char * filepath )
|
|
|
|
{
|
|
|
|
void *buffer = NULL;
|
|
|
|
u32 filesize = 0;
|
|
|
|
|
|
|
|
FILE *file = fopen( filepath, "rb" );
|
|
|
|
|
|
|
|
if ( !file )
|
2010-09-19 01:16:05 +02:00
|
|
|
Sys_BackToLoader();
|
2010-09-19 01:04:39 +02:00
|
|
|
|
|
|
|
fseek( file, 0, SEEK_END );
|
|
|
|
filesize = ftell( file );
|
|
|
|
rewind( file );
|
|
|
|
|
|
|
|
buffer = malloc( filesize );
|
|
|
|
|
|
|
|
if ( fread( buffer, 1, filesize, file ) != filesize )
|
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
fclose( file );
|
|
|
|
free( buffer );
|
|
|
|
SDCard_deInit();
|
|
|
|
USBDevice_deInit();
|
|
|
|
Sys_BackToLoader();
|
2010-09-19 01:04:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
fclose( file );
|
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
CopyHomebrewMemory( ( u8* ) buffer, 0, filesize );
|
2010-09-19 01:04:39 +02:00
|
|
|
|
|
|
|
if ( buffer )
|
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
free( buffer );
|
|
|
|
buffer = NULL;
|
2010-09-19 01:04:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
AddBootArgument( filepath );
|
|
|
|
return RunAppbooter();
|
|
|
|
}
|
|
|
|
|
|
|
|
int BootHomebrewFromMem()
|
|
|
|
{
|
|
|
|
gprintf( "BootHomebrewFromMem()\n %p, %08x\n", innetbuffer, homebrewsize );
|
|
|
|
|
|
|
|
if ( !innetbuffer )
|
|
|
|
{
|
2010-09-19 01:16:05 +02:00
|
|
|
gprintf( "!innetbuffer\n" );
|
|
|
|
SDCard_deInit();
|
|
|
|
USBDevice_deInit();
|
|
|
|
Sys_BackToLoader();
|
2010-09-19 01:04:39 +02:00
|
|
|
}
|
|
|
|
|
2010-09-19 01:16:05 +02:00
|
|
|
CopyHomebrewMemory( ( u8* ) innetbuffer, 0, homebrewsize );
|
2010-09-19 01:04:39 +02:00
|
|
|
free( innetbuffer );
|
|
|
|
|
|
|
|
return RunAppbooter();
|
|
|
|
}
|