s32 __attribute__((weak)) __IOS_LoadStartupIOS() { #if 0 int version; int res; res = __ES_Init(); if(res < 0) return res; version = IOS_GetPreferredVersion(); if(version < 0) { #ifdef DEBUG_IOS printf("GetPreferredVersion failed: %d\n",version); #endif __ES_Close(); return version; } #ifdef DEBUG_IOS printf("Loading startup IOS: %d\n",version); #endif res = __IOS_LaunchNewIOS(version); if(res < 0) return res; #endif return 0; }
s32 __IOS_ShutdownSubsystems(void) { s32 res; s32 ret = 0; #ifdef DEBUG_IOS printf("IOS Subsystem Close\n"); #endif res = __STM_Close(); if(res < 0) ret = res; res = __ES_Close(); if(res < 0) ret = res; #ifdef DEBUG_IOS printf("IOS Subsystem Close Done: %d\n",ret); #endif return ret; }
s32 IOS_ReloadIOS(int version) { int ret = 0; int res; #ifdef DEBUG_IOS printf("Reloading to IOS%d\n",version); #endif res = __IOS_ShutdownSubsystems(); if(res < 0) { #ifdef DEBUG_IOS printf("__IOS_ShutdownSubsystems failed: %d\n", res); #endif ret = res; } res = __ES_Init(); if(res < 0) { #ifdef DEBUG_IOS printf("__ES_Init failed: %d\n", res); #endif ret = res; } else { res = __IOS_LaunchNewIOS(version); if(res < 0) { #ifdef DEBUG_IOS printf("__IOS_LaunchNewIOS failed: %d\n", res); #endif ret = res; __ES_Close(); } } res = __IOS_InitializeSubsystems(); if(res < 0) { #ifdef DEBUG_IOS printf("__IOS_InitializeSubsystems failed: %d\n", res); #endif ret = res; } return ret; }
s32 ES_GetTitleID(u64 *tid) { s32 fd, ret; /* Open ES */ fd = __ES_Init(); if (fd < 0) return fd; /* Setup vector */ vector[0].data = tid; vector[0].len = sizeof(u64); /* Get title ID */ ret = os_ioctlv(fd, IOCTL_ES_GETTITLEID, 0, 1, vector); /* Close ES */ __ES_Close(fd); return ret; }
s32 __DI_LoadStub(void) { int ret = 0; int res; #ifdef DEBUG_IOS dprintf("Reloading to IOS%d\n",version); #endif res = __IOS_ShutdownSubsystems(); if(res < 0) ret = res; res = __ES_Init(); if(res < 0) ret = res; else { res = __DI_StubLaunch(); if(res < 0) { ret = res; __ES_Close(); } } res = __IOS_InitializeSubsystems(); if(res < 0) ret = res; return ret; }
int main(int argc, char **argv) { // Exit after 10 seconds if there is an error __exception_setreload(10); // u64 timeout = 0; CheckForGecko(); DCInvalidateRange(loader_stub, 0x1800); memcpy(loader_stub, (void*)0x80001800, 0x1800); RAMInit(); //Meh, doesnt do anything anymore anyways //STM_RegisterEventHandler(HandleSTMEvent); Initialise(); // Checking for storage devices... ShowMessageScreen("Checking storage devices..."); u32 u; //Disables MEMPROT for patches write16(MEM_PROT, 0); //Patches FS access for( u = 0x93A00000; u < 0x94000000; u+=2 ) { if( memcmp( (void*)(u), FSAccessPattern, sizeof(FSAccessPattern) ) == 0 ) { // gprintf("FSAccessPatch:%08X\r\n", u ); memcpy( (void*)u, FSAccessPatch, sizeof(FSAccessPatch) ); DCFlushRange((void*)u, sizeof(FSAccessPatch)); break; } } //for BT.c CONF_GetPadDevices((conf_pads*)0x932C0000); DCFlushRange((void*)0x932C0000, sizeof(conf_pads)); *(vu32*)0x932C0490 = CONF_GetIRSensitivity(); *(vu32*)0x932C0494 = CONF_GetSensorBarPosition(); DCFlushRange((void*)0x932C0490, 8); if(LoadKernel() < 0) { ClearScreen(); gprintf("Failed to load kernel from NAND!\r\n"); ShowMessageScreenAndExit("Failed to load kernel from NAND!", 1); } InsertModule((char*)kernel_bin, kernel_bin_size); memset( (void*)0x92f00000, 0, 0x100000 ); DCFlushRange( (void*)0x92f00000, 0x100000 ); DCInvalidateRange( (void*)0x939F02F0, 0x20 ); memcpy( (void*)0x939F02F0, Boot2Patch, sizeof(Boot2Patch) ); DCFlushRange( (void*)0x939F02F0, 0x20 ); //libogc still has that, lets close it __ES_Close(); s32 fd = IOS_Open( "/dev/es", 0 ); memset( STATUS, 0xFFFFFFFF, 0x20 ); DCFlushRange( STATUS, 0x20 ); memset( (void*)0x91000000, 0xFFFFFFFF, 0x20 ); DCFlushRange( (void*)0x91000000, 0x20 ); *(vu32*)0xD3003420 = 0; //make sure kernel doesnt reload raw_irq_handler_t irq_handler = BeforeIOSReload(); IOS_IoctlvAsync( fd, 0x1F, 0, 0, &IOCTL_Buf, NULL, NULL ); AfterIOSReload( irq_handler, FoundVersion ); while(1) { DCInvalidateRange( STATUS, 0x20 ); if((STATUS_LOADING > 0 || abs(STATUS_LOADING) > 1) && STATUS_LOADING < 20) { gprintf("Kernel sent signal\n"); break; } } /* For slow USB HDDs */ time_t timeout = time(NULL); while(time(NULL) - timeout < 10) { if(__io_custom_usbstorage.startup() && __io_custom_usbstorage.isInserted()) break; usleep(50000); } fatInitDefault(); gprintf("Nintendont at your service!\r\n%s\r\n", NIN_BUILD_STRING); KernelLoaded = 1; char* first_slash = strrchr(argv[0], '/'); if (first_slash != NULL) strncpy(launch_dir, argv[0], first_slash-argv[0]+1); gprintf("launch_dir = %s\r\n", launch_dir); FPAD_Init(); FPAD_Update(); /* Read IPL Font before doing any patches */ void *fontbuffer = memalign(32, 0x50000); __SYS_ReadROM((void*)fontbuffer,0x50000,0x1AFF00); memcpy((void*)0xD3100000, fontbuffer, 0x50000); DCInvalidateRange( (void*)0x93100000, 0x50000 ); free(fontbuffer); //gprintf("Font: 0x1AFF00 starts with %.4s, 0x1FCF00 with %.4s\n", (char*)0x93100000, (char*)0x93100000 + 0x4D000); // Simple code to autoupdate the meta.xml in Nintendont's folder FILE *meta = fopen("meta.xml", "w"); if(meta != NULL) { fprintf(meta, "%s\r\n<app version=\"1\">\r\n\t<name>%s</name>\r\n", META_XML, META_NAME); fprintf(meta, "\t<coder>%s</coder>\r\n\t<version>%d.%d</version>\r\n", META_AUTHOR, NIN_VERSION>>16, NIN_VERSION&0xFFFF); fprintf(meta, "\t<release_date>20150531000000</release_date>\r\n"); fprintf(meta, "\t<short_description>%s</short_description>\r\n", META_SHORT); fprintf(meta, "\t<long_description>%s\r\n\r\n%s</long_description>\r\n", META_LONG1, META_LONG2); fprintf(meta, "\t<ahb_access/>\r\n</app>"); fclose(meta); }