s32 __MLoad_System(void) { u32 perms; /* Invalidate cache */ ICInvalidate(); /* Apply permissions */ perms = Perms_Read(); Perms_Write(0xFFFFFFFF); /* Detect modules */ __MLoad_Detect(); /* Apply patches */ Patch_DipModule(ios.dipVersion); Patch_EsModule (ios.esVersion); Patch_FfsModule(ios.ffsVersion); Patch_IopModule(ios.iopVersion); /* Disable MEM2 protection */ MEM2_Prot(0); /* Restore permissions */ Perms_Write(perms); return 0; }
s32 __ES_System(u32 arg1, u32 arg2) { u32 perms; /* Invalidate cache */ ICInvalidate(); /* Apply permissions */ perms = Perms_Read(); Perms_Write(0xFFFFFFFF); /* Patch modules */ Patch_EsModule(ios.esVersion); /* Restore permissions */ Perms_Write(perms); return 0; }
s32 Swi_Handler(u32 arg0, u32 arg1, u32 arg2, u32 arg3) { u8 cmd; /* Check alignment */ SwiAddr -= (SwiAddr[-4] == 0xDF) ? 3 : 1; /* Get command */ cmd = SwiAddr[0]; /* Check command */ if(SwiAddr[0] != 0xcc) { if (SwiTable[cmd]) return SwiTable[cmd](arg0, arg1, arg2, arg3); else return arg0; } /* Check argument */ switch (arg0) { /** Add SWI handler **/ case 0: { SwiTable[arg1]= (void *)arg2; break; } /** Memcpy (cached to cached) **/ case 2: { void *src = (void *)arg2; void *dst = (void *)arg1; u32 len = arg3; u32 perms; /* Apply permissions */ perms = Perms_Read(); Perms_Write(0xFFFFFFFF); /* Copy data */ memcpy(dst, src, len); DCFlushRange(dst, len); /* Restore permissions */ Perms_Write(perms); break; } /** Get register **/ case 3: return *(vu32 *)arg1; /** Set register **/ case 4: *(vu32 *)arg1 = arg2; break; /** Set register **/ case 5: *(vu32 *)arg1 |= arg2; break; /** Clear register **/ case 6: *(vu32 *)arg1 &= ~arg2; break; /** Memcpy (uncached to cached) **/ case 9: { void *src = (void *)arg2; void *dst = (void *)arg1; u32 len = arg3; u32 perms; /* Apply permissions */ perms = Perms_Read(); Perms_Write(0xFFFFFFFF); /* Copy data */ DCInvalidateRange(src, len); memcpy(dst, src, len); DCFlushRange(dst, len); /* Restore permissions */ Perms_Write(perms); break; } /** Call function **/ case 16: { s32 (*Function)(void *in, void *out); /* Set function */ Function = (void *)arg1; /* Call function */ return Function((void *)arg2, (void *)arg3); } /** Get syscall base */ case 17: return ios.syscall; /** Get IOS info **/ case 18: { iosInfo *buffer = (iosInfo *)arg1; /* Copy IOS info */ memcpy(buffer, &ios, sizeof(ios)); DCFlushRange(buffer, sizeof(ios)); break; } /** Get MLOAD version **/ case 19: return (MLOAD_VER << 4) | MLOAD_SUBVER; /** Led on **/ case 128: *(vu32 *)0x0d8000c0 |= 0x20; break; /** Led off **/ case 129: *(vu32 *)0x0d8000c0 &=~ 0x20; break; /** Led blink **/ case 130: *(vu32 *)0x0d8000c0 ^= 0x20; break; default: break; } return 0; }