diff --git a/retail/bootloaderi/include/find.h b/retail/bootloaderi/include/find.h index e284f6510..1e6a59a17 100644 --- a/retail/bootloaderi/include/find.h +++ b/retail/bootloaderi/include/find.h @@ -107,7 +107,8 @@ u32* findWaitSysCyclesOffset(const tNDSHeader* ndsHeader); u32* findSleepOffset(const tNDSHeader* ndsHeader, const module_params_t* moduleParams, bool usesThumb, u32* usesThumbPtr); u32* findCardEndReadDma(const tNDSHeader* ndsHeader, const module_params_t* moduleParams, bool usesThumb, const u32* cardReadDmaEndOffset, u32* offsetDmaHandler); u32* findCardSetDma(const tNDSHeader* ndsHeader, const module_params_t* moduleParams, bool usesThumb); -u32* findResetOffset(const tNDSHeader* ndsHeader, const module_params_t* moduleParams, bool* softResetMb); +u32* findSrlStartOffset9(const tNDSHeader* ndsHeader); +u32* findResetOffset(const tNDSHeader* ndsHeader, const module_params_t* moduleParams, const bool softResetMb); u32* findNandTmpJumpFuncOffset(const tNDSHeader* ndsHeader, const module_params_t* moduleParams); u32* findMbkWramBOffset(const tNDSHeader* ndsHeader, const module_params_t* moduleParams); u16* findMbkWramBOffsetThumb(const tNDSHeader* ndsHeader, const module_params_t* moduleParams); @@ -140,6 +141,6 @@ u32* findCardIrqEnableOffset(const tNDSHeader* ndsHeader, const module_params_t* u32* findSdCardResetOffset(const tNDSHeader* ndsHeader, const module_params_t* moduleParams); u32* findSdCardFuncsOffset(const tNDSHeader* ndsHeader); u32* findAutoPowerOffOffset(const tNDSHeader* ndsHeader); -u32* findResetOffset7(const tNDSHeader* ndsHeader); +u32* findSrlStartOffset7(const tNDSHeader* ndsHeader); #endif // FIND_H diff --git a/retail/bootloaderi/include/patch.h b/retail/bootloaderi/include/patch.h index 2b8d37e2c..9c2770628 100644 --- a/retail/bootloaderi/include/patch.h +++ b/retail/bootloaderi/include/patch.h @@ -50,7 +50,7 @@ //extern bool cardReadFound; // patch_arm9.c -#define patchOffsetCacheFileVersion 111 // Change when new functions are being patched, some offsets removed, +#define patchOffsetCacheFileVersion 112 // Change when new functions are being patched, some offsets removed, // the offset order changed, and/or the function signatures changed (not added) typedef struct patchOffsetCacheContents { @@ -65,7 +65,6 @@ typedef struct patchOffsetCacheContents { u32* heapPointerOffset; u32 a9IsThumb; u32* cardHashInitOffset; - u32* cardRomInitOffset; // Unused, remove when updating cache version u32* cardReadStartOffset; u32* cardReadEndOffset; u32* cardPullOutOffset; @@ -93,8 +92,9 @@ typedef struct patchOffsetCacheContents { u32* fileIoReadOffset; u32* a9CardIrqEnableOffset; u32 a9CardIrqIsThumb; + u32* srlStartOffset9; + u32 srlStartOffsetChecked; u32* resetOffset; - u32 resetMb; u32 resetChecked; u32* nandTmpJumpFuncOffset; u32 nandTmpJumpFuncChecked; diff --git a/retail/bootloaderi/source/arm7/find_arm7.c b/retail/bootloaderi/source/arm7/find_arm7.c index 81ab9c1cc..bf7f4c9ef 100644 --- a/retail/bootloaderi/source/arm7/find_arm7.c +++ b/retail/bootloaderi/source/arm7/find_arm7.c @@ -119,8 +119,8 @@ static const u16 irqEnableStartSignatureThumb[5] = {0xB530, 0xB081, 0x4D07, 0x8 static const u16 irqEnableStartSignatureThumb3[5] = {0xB510, 0x1C04, 0xF7FF, 0xFFF4, 0x4B05}; // SDK 3 static const u16 irqEnableStartSignatureThumb5[5] = {0xB510, 0x1C04, 0xF7FF, 0xFFE4, 0x4B05}; // SDK 5 -// Reset -static const u32 resetSignature3Eoo[] = {0xE92D4070, 0xE59F0098, 0xE5904004, 0xE3540000}; // eoo.dat (Pokemon) +// SRL start +static const u32 srlStartSignature3[4] = {0xE92D4070, 0xE59F0098, 0xE5904004, 0xE3540000}; // eoo.dat (Pokemon) // ARM7i start (SDK 5) //static const u32 a7iStartSignatureConstant[3] = {0x6F696473, 0x616C775F, 0x0000006E}; // 'sdio_wlan' @@ -1407,23 +1407,22 @@ u32* findCardIrqEnableOffset(const tNDSHeader* ndsHeader, const module_params_t* return cardIrqEnableOffset; } -u32* findResetOffset7(const tNDSHeader* ndsHeader) { - // dbg_printf("findResetOffset\n"); +u32* findSrlStartOffset7(const tNDSHeader* ndsHeader) { + dbg_printf("findSrlStartOffset7\n"); - u32* resetOffset = findOffset( + u32* offset = findOffset( ndsHeader->arm7destination, newArm7ibinarySize, - resetSignature3Eoo, 4 + srlStartSignature3, 4 ); - if (resetOffset) { - dbg_printf("Reset found\n"); - dbg_printf("\n"); - return resetOffset; + if (offset) { + dbg_printf("SRL start function found\n"); } else { - dbg_printf("Reset not found\n"); + dbg_printf("SRL start function not found\n"); } - return NULL; + dbg_printf("\n"); + return offset; } /*u32* findA7iStartOffset(void) { diff --git a/retail/bootloaderi/source/arm7/find_arm9.c b/retail/bootloaderi/source/arm7/find_arm9.c index cc0ae670e..2b4facdf6 100644 --- a/retail/bootloaderi/source/arm7/find_arm9.c +++ b/retail/bootloaderi/source/arm7/find_arm9.c @@ -230,7 +230,7 @@ static const u32 waitSysCyclesSignatureTwl[3] = {0xE92D4008, 0xE59F1028, 0x static const u16 waitSysCyclesSignatureThumb[3] = {0xB508, 0x0040, 0x2810}; static const u16 waitSysCyclesSignatureTwlThumb[3] = {0xB508, 0x4907, 0x2201}; -// Threads management +// Threads management static const u32 sleepSignature2[4] = {0xE92D4010, 0xE24DD030, 0xE1A04000, 0xE28D0004}; // sdk2 static const u16 sleepSignatureThumb2[4] = {0x4010, 0xE92D, 0xD030, 0xE24D}; // sdk2 static const u32 sleepSignature4[4] = {0xE92D4030, 0xE24DD034, 0xE1A04000, 0xE28D0008}; // sdk4 @@ -267,7 +267,7 @@ static const u32 resetSignature2Alt1[4] = {0xE92D000F, 0xE92D4010, 0xEB000026, 0 static const u32 resetSignature2Alt2[4] = {0xE92D4010, 0xE59F1078, 0xE1A04000, 0xE1D100B0}; // sdk2 static const u32 resetSignature3[4] = {0xE92D4010, 0xE59F106C, 0xE1A04000, 0xE1D100B0}; // sdk3 static const u32 resetSignature3Alt[4] = {0xE92D4010, 0xE59F1068, 0xE1A04000, 0xE1D100B0}; // sdk3 and sdk4 -static const u32 resetSignature3Eoo[4] = {0xE92D4010, 0xE59F003C, 0xE5904000, 0xE3540000}; // eoo.dat (Pokemon) +static const u32 resetSignature3Eoo[2] = {0xE92D4010, 0xE1A04000}; // eoo.dat (Pokemon) static const u32 resetSignature4[4] = {0xE92D4070, 0xE59F10A0, 0xE1A04000, 0xE1D100B0}; // sdk4 static const u32 resetSignature4Alt[4] = {0xE92D4010, 0xE59F1084, 0xE1A04000, 0xE1D100B0}; // sdk4 static const u32 resetSignature5[4] = {0xE92D4038, 0xE59F1054, 0xE1A05000, 0xE1D100B0}; // sdk5 @@ -279,6 +279,9 @@ static const u32 resetSignature5Alt4[4] = {0xE92D4038, 0xE59F1090, 0xE1A05000, 0 static const u32 resetConstant[1] = {RESET_PARAM}; static const u32 resetConstant5[1] = {RESET_PARAM_SDK5}; +// SRL start +static const u32 srlStartSignature3[4] = {0xE92D4010, 0xE59F003C, 0xE5904000, 0xE3540000}; // eoo.dat (Pokemon) + // Reset (TWL) static const u32 nandTmpJumpFuncStart30[1] = {0xE92D000F}; static const u32 nandTmpJumpFuncStart3[1] = {0xE92D4008}; @@ -655,7 +658,7 @@ u16* findCardReadEndOffsetThumb5Type0(const tNDSHeader* ndsHeader, const module_ if (moduleParams->sdk_version < 0x5000000) { return NULL; } - + dbg_printf("findCardReadEndOffsetThumb5Type0:\n"); //usesThumb = true; @@ -765,7 +768,7 @@ u32* findCardReadStartOffset5(const module_params_t* moduleParams, const u32* ca if (moduleParams->sdk_version < 0x5000000) { return NULL; } - + if (!cardReadEndOffset) { return NULL; } @@ -993,7 +996,7 @@ u32* findCardPullOutOffset(const tNDSHeader* ndsHeader, const module_params_t* m dbg_printf("findCardPullOutOffset:\n"); //if (!usesThumb) { - + u32* cardPullOutOffset = 0; if (moduleParams->sdk_version > 0x5000000) { // SDK 5 cardPullOutOffset = findOffset( @@ -1114,7 +1117,7 @@ u16* findCardPullOutOffsetThumb(const tNDSHeader* ndsHeader) { dbg_printf("findCardPullOutOffsetThumb:\n"); //if (usesThumb) { - + u16* cardPullOutOffset = findOffsetThumb( (u16*)ndsHeader->arm9destination, iUncompressedSize,//ndsHeader->arm9binarySize, cardPullOutSignatureThumb, 5 @@ -1160,7 +1163,7 @@ u16* findCardPullOutOffsetThumb5Type0(const tNDSHeader* ndsHeader, const module_ } dbg_printf("findCardPullOutOffsetThumbType0:\n"); - + u16* cardPullOutOffset = findOffsetThumb( (u16*)ndsHeader->arm9destination, iUncompressedSize,//, ndsHeader->arm9binarySize, cardPullOutSignatureThumb5, 4 @@ -1180,9 +1183,9 @@ u16* findCardPullOutOffsetThumb5Type1(const tNDSHeader* ndsHeader, const module_ if (moduleParams->sdk_version < 0x5000000) { return NULL; } - + dbg_printf("findCardPullOutOffsetThumbType1:\n"); - + u16* cardPullOutOffset = findOffsetThumb( (u16*)ndsHeader->arm9destination, iUncompressedSize,//, ndsHeader->arm9binarySize, cardPullOutSignatureThumb5Alt, 4 @@ -1201,7 +1204,7 @@ u32* findCardTerminateForPullOutOffset(const tNDSHeader* ndsHeader, const module dbg_printf("findCardTerminateForCardPullOutOffset:\n"); //if (!usesThumb) { - + u32* cardTerminateForPullOutOffset = findOffset( (u32*)ndsHeader->arm9destination, iUncompressedSize,//ndsHeader->arm9binarySize, cardTerminateForPullOutSignature1, 4 @@ -1338,7 +1341,7 @@ u16* findCardIdEndOffsetThumb(const tNDSHeader* ndsHeader, const module_params_t dbg_printf("findCardIdEndOffsetThumb:\n"); //if (usesThumb) { - + u16* cardIdEndOffset = findOffsetThumb( (u16*)ndsHeader->arm9destination, iUncompressedSize, cardIdEndSignatureThumb, 6 @@ -1440,7 +1443,7 @@ u16* findCardIdStartOffsetThumb(const module_params_t* moduleParams, const u16* dbg_printf("findCardIdStartOffsetThumb:\n"); //if (usesThumb) { - + u16* cardIdStartOffset = findOffsetBackwardsThumb4( (u16*)cardIdEndOffset, 0x50, cardIdStartSignatureThumb, cardIdStartSignatureThumbAlt1, cardIdStartSignatureThumbAlt2, cardIdStartSignatureThumbAlt3, 2 @@ -1633,7 +1636,7 @@ u16* findCardReadDmaStartOffsetThumb(const u16* cardReadDmaEndOffset) { dbg_printf("findCardReadDmaStartOffsetThumb:\n"); //if (usesThumb) { - + u16* cardReadDmaStartOffset = findOffsetBackwardsThumb( (u16*)cardReadDmaEndOffset, 0x200, cardReadDmaStartSignatureThumb1, 1 @@ -1720,7 +1723,7 @@ u16* findGbaSlotInitOffsetThumb(const tNDSHeader* ndsHeader) { u32* a9FindCardIrqEnableOffset(const tNDSHeader* ndsHeader, const module_params_t* moduleParams, bool* usesThumb) { dbg_printf("findCardIrqEnableOffset:\n"); - + const u32* irqEnableStartSignature = irqEnableStartSignature1; if (moduleParams->sdk_version > 0x4008000) { irqEnableStartSignature = irqEnableStartSignature4; @@ -1875,7 +1878,7 @@ u32* findMpuDataOffset(const module_params_t* moduleParams, u32 patchMpuRegion, mpuInitRegionData = mpuInitRegion3Data; break; } - + u32* mpuDataOffset = findOffset( mpuStartOffset, 0x100, mpuInitRegionData, 1 @@ -2012,7 +2015,7 @@ u32* findMpuInitTwlEnd(const u32* heapPointer2Offset) { u32* findHeapPointerOffset(const module_params_t* moduleParams, const tNDSHeader* ndsHeader) { dbg_printf("findHeapPointerOffset:\n"); - + const u32* initHeapEndSignature = initHeapEndSignature1; if (moduleParams->sdk_version > 0x5000000) { initHeapEndSignature = initHeapEndSignature5; @@ -2028,7 +2031,7 @@ u32* findHeapPointerOffset(const module_params_t* moduleParams, const tNDSHeader dbg_printf("Init Heap End not found\n\n"); return 0; } - + dbg_hexa((u32)initHeapEnd); dbg_printf("\n"); dbg_printf("heapPointer: "); @@ -2044,7 +2047,7 @@ u32* findHeapPointerOffset(const module_params_t* moduleParams, const tNDSHeader ); } u32* heapPointer = initEndFunc + 1; - + if (!initEndFunc) { u16* initEndFuncThumb = findOffsetBackwardsThumb( (u16*)initHeapEnd, 0x40, @@ -2058,7 +2061,7 @@ u32* findHeapPointerOffset(const module_params_t* moduleParams, const tNDSHeader } heapPointer = (u32*)((u16*)initEndFuncThumb+1); } - + dbg_hexa((u32)heapPointer); dbg_printf("\n"); @@ -2067,7 +2070,7 @@ u32* findHeapPointerOffset(const module_params_t* moduleParams, const tNDSHeader u32* findHeapPointer2Offset(const module_params_t* moduleParams, const tNDSHeader* ndsHeader) { dbg_printf("findHeapPointer2Offset:\n"); - + extern bool dsiModeConfirmed; u32* initEndFunc = NULL; @@ -2098,7 +2101,7 @@ u32* findHeapPointer2Offset(const module_params_t* moduleParams, const tNDSHeade } if (initEndFunc) { u32* heapPointer = dsiEnhanced ? initEndFunc+1 : initEndFunc; - + dbg_hexa((u32)heapPointer); dbg_printf("\n"); @@ -2155,7 +2158,7 @@ u32* findHeapPointer2Offset(const module_params_t* moduleParams, const tNDSHeade } u32* heapPointer = initEndFunc + 1; - + dbg_hexa((u32)heapPointer); dbg_printf("\n"); @@ -2576,18 +2579,18 @@ u32* findSleepOffset(const tNDSHeader* ndsHeader, const module_params_t* moduleP dbg_printf("findSleepOffset\n"); const u32* sleepSignature = sleepSignature2; const u16* sleepSignatureThumb = sleepSignatureThumb2; - - if (moduleParams->sdk_version > 0x3000000 && moduleParams->sdk_version < 0x5000000) { + + if (moduleParams->sdk_version > 0x3000000 && moduleParams->sdk_version < 0x5000000) { sleepSignature = sleepSignature4; - sleepSignatureThumb = sleepSignatureThumb4; + sleepSignatureThumb = sleepSignatureThumb4; } if (moduleParams->sdk_version > 0x5000000) { sleepSignature = sleepSignature5; - sleepSignatureThumb = sleepSignatureThumb5; + sleepSignatureThumb = sleepSignatureThumb5; } - + u32 * sleepOffset = NULL; - + if(usesThumb) { sleepOffset = (u32*)findOffsetThumb( (u16*)ndsHeader->arm9destination, iUncompressedSize,//ndsHeader->arm9binarySize, @@ -2602,7 +2605,7 @@ u32* findSleepOffset(const tNDSHeader* ndsHeader, const module_params_t* moduleP sleepSignature, 4 ); } - + if (!sleepOffset && !usesThumb && moduleParams->sdk_version > 0x3000000) { sleepOffset = findOffset( (u32*)ndsHeader->arm9destination, iUncompressedSize,//ndsHeader->arm9binarySize, @@ -2638,8 +2641,8 @@ u32* findSleepOffset(const tNDSHeader* ndsHeader, const module_params_t* moduleP dbg_hexa((u32)sleepEndOffset); dbg_printf("\n"); break; - } - + } + if(usesThumb) { sleepOffset = (u32*)findOffsetThumb( (u16*)(sleepOffset+1), iUncompressedSize,//ndsHeader->arm9binarySize, @@ -2651,8 +2654,8 @@ u32* findSleepOffset(const tNDSHeader* ndsHeader, const module_params_t* moduleP sleepSignature, 4 ); } - } - + } + if (sleepOffset) { dbg_printf("Sleep found\n"); } else { @@ -2670,7 +2673,7 @@ u32* findCardEndReadDmaSdk5(const tNDSHeader* ndsHeader, const module_params_t* const u32* cardEndReadDmaSignature = cardEndReadDmaSignature5; u32 * offset = NULL; - + if(usesThumb) { offset = (u32*)findOffsetThumb( (u16*)ndsHeader->arm9destination, iUncompressedSize,//ndsHeader->arm9binarySize, @@ -2680,15 +2683,15 @@ u32* findCardEndReadDmaSdk5(const tNDSHeader* ndsHeader, const module_params_t* offset = findOffset( (u32*)ndsHeader->arm9destination, iUncompressedSize,//ndsHeader->arm9binarySize, cardEndReadDmaSignature, 4 - ); - } - + ); + } + if (offset) { dbg_printf("cardEndReadDma found\n"); } else { dbg_printf("cardEndReadDma not found\n"); } - + dbg_printf("\n"); return offset; } @@ -2706,11 +2709,11 @@ u32* findCardEndReadDma(const tNDSHeader* ndsHeader, const module_params_t* modu } if(moduleParams->sdk_version > 0x4000000 || *offsetDmaHandler<0x2000000 || *offsetDmaHandler>0x2400000) { - offsetDmaHandler = cardReadDmaEndOffset+4; + offsetDmaHandler = cardReadDmaEndOffset+4; } if(*offsetDmaHandler<0x2000000 || *offsetDmaHandler>0x2400000) { - offsetDmaHandler = cardReadDmaEndOffset+3; + offsetDmaHandler = cardReadDmaEndOffset+3; } if(*offsetDmaHandler<0x2000000 || *offsetDmaHandler>0x2400000) { @@ -2742,7 +2745,7 @@ u32* findCardEndReadDma(const tNDSHeader* ndsHeader, const module_params_t* modu cardEndReadDmaSignature4Alt, 1 ); } - } + } if (!offset) { if (usesThumb) { @@ -2777,7 +2780,7 @@ u32* findCardEndReadDma(const tNDSHeader* ndsHeader, const module_params_t* modu u32* findCardSetDmaSdk5(const tNDSHeader* ndsHeader, const module_params_t* moduleParams, bool usesThumb) { dbg_printf("findCardSetDmaSdk5\n"); - + u32* currentOffset = (u32*)ndsHeader->arm9destination; u32* startOffset = NULL; while (startOffset==NULL) { @@ -2785,7 +2788,7 @@ u32* findCardSetDmaSdk5(const tNDSHeader* ndsHeader, const module_params_t* modu currentOffset+1, iUncompressedSize, cardSetDmaSignatureValue1, 1 ); - if (cardSetDmaEndOffset==NULL) { + if (cardSetDmaEndOffset==NULL) { dbg_printf("cardSetDmaEnd not found\n"); return NULL; } else { @@ -2794,7 +2797,7 @@ u32* findCardSetDmaSdk5(const tNDSHeader* ndsHeader, const module_params_t* modu dbg_printf(" : "); dbg_hexa(*cardSetDmaEndOffset); dbg_printf("\n"); - + currentOffset = cardSetDmaEndOffset+2; if(usesThumb) { dbg_printf("cardSetDmaSignatureStartThumb used: "); @@ -2808,7 +2811,7 @@ u32* findCardSetDmaSdk5(const tNDSHeader* ndsHeader, const module_params_t* modu cardSetDmaEndOffset, 0x90, cardSetDmaSignatureStart5, 2 ); - } + } if (!startOffset && !usesThumb) { startOffset = findOffsetBackwards( cardSetDmaEndOffset, 0x90, @@ -2819,9 +2822,9 @@ u32* findCardSetDmaSdk5(const tNDSHeader* ndsHeader, const module_params_t* modu dbg_printf("cardSetDmaSignatureStart found\n"); /*dbg_hexa((u32)startOffset); dbg_printf(" : "); - dbg_hexa(*startOffset); + dbg_hexa(*startOffset); dbg_printf("\n");*/ - + return startOffset; } } @@ -2855,7 +2858,7 @@ u32* findCardSetDma(const tNDSHeader* ndsHeader, const module_params_t* modulePa currentOffset+1, iUncompressedSize, cardSetDmaSignatureValue1, 1 ); - if (cardSetDmaEndOffset==NULL) { + if (cardSetDmaEndOffset==NULL) { dbg_printf("cardSetDmaEnd not found\n"); return NULL; } else { @@ -2864,7 +2867,7 @@ u32* findCardSetDma(const tNDSHeader* ndsHeader, const module_params_t* modulePa dbg_printf(" : "); dbg_hexa(*cardSetDmaEndOffset); dbg_printf("\n"); - + currentOffset = cardSetDmaEndOffset+2; cardSetDmaEndOffset = findOffset( currentOffset, 0x18, @@ -2876,11 +2879,11 @@ u32* findCardSetDma(const tNDSHeader* ndsHeader, const module_params_t* modulePa dbg_printf(" : "); dbg_hexa(*cardSetDmaEndOffset); dbg_printf("\n"); - + break; - } - } - } + } + } + } dbg_printf("cardSetDmaEnd found\n"); dbg_hexa((u32)cardSetDmaEndOffset); @@ -2934,11 +2937,29 @@ u32* findCardSetDma(const tNDSHeader* ndsHeader, const module_params_t* modulePa return offset; } -u32* findResetOffset(const tNDSHeader* ndsHeader, const module_params_t* moduleParams, bool* softResetMb) { +u32* findSrlStartOffset9(const tNDSHeader* ndsHeader) { + dbg_printf("findSrlStartOffset9\n"); + + u32* offset = findOffset( + (u32*)ndsHeader->arm9destination, iUncompressedSize, + srlStartSignature3, 4 + ); + + if (offset) { + dbg_printf("SRL start function found\n"); + } else { + dbg_printf("SRL start function not found\n"); + } + + dbg_printf("\n"); + return offset; +} + +u32* findResetOffset(const tNDSHeader* ndsHeader, const module_params_t* moduleParams, const bool softResetMb) { dbg_printf("findResetOffset\n"); const u32* resetSignature = resetSignature2; - if (moduleParams->sdk_version > 0x4008000 && moduleParams->sdk_version < 0x5000000) { + if (moduleParams->sdk_version > 0x4008000 && moduleParams->sdk_version < 0x5000000) { resetSignature = resetSignature4; } if (moduleParams->sdk_version > 0x5000000) { @@ -2947,19 +2968,28 @@ u32* findResetOffset(const tNDSHeader* ndsHeader, const module_params_t* moduleP u32 * resetOffset = NULL; - if ((memcmp(getRomTid(ndsHeader), "NTRJ", 4) == 0) && (moduleParams->sdk_version < 0x5000000)) { - resetOffset = findOffset( - (u32*)ndsHeader->arm9destination, iUncompressedSize,//ndsHeader->arm9binarySize, - resetSignature3Eoo, 4 - ); + if (softResetMb) { + u32* resetEndOffset = findOffset( + (u32*)ndsHeader->arm9destination, iUncompressedSize, + resetConstant, 1 + ); + if (resetEndOffset) { + dbg_printf("Reset constant found: "); + dbg_hexa((u32)resetEndOffset); + dbg_printf("\n"); - if (resetOffset) { - dbg_printf("Reset found\n"); - dbg_printf("\n"); - *softResetMb = true; - return resetOffset; - } else { - dbg_printf("Reset not found\n"); + resetOffset = findOffsetBackwards( + resetEndOffset, 0x80, + resetSignature3Eoo, 2 + ); + + if (resetOffset) { + dbg_printf("Reset found\n"); + dbg_printf("\n"); + return resetOffset; + } else { + dbg_printf("Reset not found\n"); + } } } @@ -2967,7 +2997,7 @@ u32* findResetOffset(const tNDSHeader* ndsHeader, const module_params_t* moduleP (u32*)ndsHeader->arm9destination, iUncompressedSize,//ndsHeader->arm9binarySize, resetSignature, 4 ); - + if (!resetOffset) { if (moduleParams->sdk_version > 0x2000000 && moduleParams->sdk_version < 0x2008000) { resetOffset = findOffset( @@ -3037,13 +3067,13 @@ u32* findResetOffset(const tNDSHeader* ndsHeader, const module_params_t* moduleP } } } - + if (resetOffset) { dbg_printf("Reset found: "); dbg_hexa((u32)resetOffset); dbg_printf("\n"); - } - + } + while(resetOffset!=NULL) { u32* resetEndOffset = findOffset( resetOffset, 0x200, @@ -3054,8 +3084,8 @@ u32* findResetOffset(const tNDSHeader* ndsHeader, const module_params_t* moduleP dbg_hexa((u32)resetEndOffset); dbg_printf("\n"); break; - } - + } + resetOffset = findOffset( resetOffset+1, iUncompressedSize,//ndsHeader->arm9binarySize, resetSignature, 4 @@ -3064,9 +3094,9 @@ u32* findResetOffset(const tNDSHeader* ndsHeader, const module_params_t* moduleP dbg_printf("Reset found: "); dbg_hexa((u32)resetOffset); dbg_printf("\n"); - } - } - + } + } + if (resetOffset) { dbg_printf("Reset found\n"); } else { @@ -3079,7 +3109,7 @@ u32* findResetOffset(const tNDSHeader* ndsHeader, const module_params_t* moduleP u32* findNandTmpJumpFuncOffset(const tNDSHeader* ndsHeader, const module_params_t* moduleParams) { dbg_printf("findNandTmpJumpFuncOffset\n"); - + u32* endOffset = findOffset( (u32*)ndsHeader->arm9destination, iUncompressedSize,//ndsHeader->arm9binarySize, nandTmpJumpFuncConstant, 1 diff --git a/retail/bootloaderi/source/arm7/hook_arm9.c b/retail/bootloaderi/source/arm7/hook_arm9.c index 01db0351e..0989a4916 100644 --- a/retail/bootloaderi/source/arm7/hook_arm9.c +++ b/retail/bootloaderi/source/arm7/hook_arm9.c @@ -24,7 +24,6 @@ #define b_slowSoftReset BIT(10) #define b_dsiBios BIT(11) #define b_asyncCardRead BIT(12) -#define b_softResetMb BIT(13) #define b_cloneboot BIT(14) #define b_isDlp BIT(15) #define b_bypassExceptionHandler BIT(16) @@ -248,9 +247,6 @@ int hookNdsRetailArm9( if (asyncCardRead) { ce9->valueBits |= b_asyncCardRead; } - if (patchOffsetCache.resetMb) { - ce9->valueBits |= b_softResetMb; - } if (usesCloneboot) { ce9->valueBits |= b_cloneboot; } diff --git a/retail/bootloaderi/source/arm7/patch_arm7.c b/retail/bootloaderi/source/arm7/patch_arm7.c index 7a32435d6..aa34ffd33 100644 --- a/retail/bootloaderi/source/arm7/patch_arm7.c +++ b/retail/bootloaderi/source/arm7/patch_arm7.c @@ -565,15 +565,16 @@ static void patchCardCheckPullOut(cardengineArm7* ce7, const tNDSHeader* ndsHead } } -static void patchReset(cardengineArm7* ce7, const tNDSHeader* ndsHeader, const module_params_t* moduleParams) { - u32* offset = findResetOffset7(ndsHeader); +static void patchSrlStart(cardengineArm7* ce7, const tNDSHeader* ndsHeader) { + u32* offset = findSrlStartOffset7(ndsHeader); if (!offset) { return; } - offset[0] = 0xE59F0000; // ldr r0, =reset - offset[1] = 0xE12FFF10; // bx r0 - offset[2] = (u32)ce7->patches->reset; + offset[0] = 0xE3A00001; // mov r0, #1 + offset[1] = 0xE59FC000; // ldr r12, =reset + offset[2] = 0xE12FFF1C; // bx r12 + offset[3] = (u32)ce7->patches->reset; } static void patchSdCardReset(const tNDSHeader* ndsHeader, const module_params_t* moduleParams) { @@ -720,8 +721,8 @@ u32 patchCardNdsArm7( patchCardCheckPullOut(ce7, ndsHeader, moduleParams); } - if (patchOffsetCache.resetMb) { - patchReset(ce7, ndsHeader, moduleParams); + if (patchOffsetCache.srlStartOffset9) { + patchSrlStart(ce7, ndsHeader); } if (a7GetReloc(ndsHeader, moduleParams)) { diff --git a/retail/bootloaderi/source/arm7/patch_arm9.c b/retail/bootloaderi/source/arm7/patch_arm9.c index 1bd99f4d9..3c449229d 100644 --- a/retail/bootloaderi/source/arm7/patch_arm9.c +++ b/retail/bootloaderi/source/arm7/patch_arm9.c @@ -697,23 +697,45 @@ static bool patchCardSetDma(cardengineArm9* ce9, const tNDSHeader* ndsHeader, co } static void patchReset(cardengineArm9* ce9, const tNDSHeader* ndsHeader, const module_params_t* moduleParams) { - u32* reset = patchOffsetCache.resetOffset; + const char* romTid = getRomTid(ndsHeader); + if (strcmp(romTid, "NTRJ") == 0 || strncmp(romTid, "HND", 3) == 0 || strncmp(romTid, "HNE", 3) == 0) { + u32* offset = patchOffsetCache.srlStartOffset9; + + if (!patchOffsetCache.srlStartOffsetChecked) { + offset = findSrlStartOffset9(ndsHeader); + if (offset) patchOffsetCache.srlStartOffset9 = offset; + patchOffsetCache.srlStartOffsetChecked = true; + } + + if (offset) { + // Patch + tonccpy(offset, ce9->patches->reset_arm9, 0x40); + dbg_printf("srlStart location : "); + dbg_hexa((u32)offset); + dbg_printf("\n\n"); + } + } + + u32* offset = patchOffsetCache.resetOffset; if (!patchOffsetCache.resetChecked) { - reset = findResetOffset(ndsHeader, moduleParams, (bool*)&patchOffsetCache.resetMb); - if (reset) patchOffsetCache.resetOffset = reset; + offset = findResetOffset(ndsHeader, moduleParams, (bool)patchOffsetCache.srlStartOffset9); + if (offset) patchOffsetCache.resetOffset = offset; patchOffsetCache.resetChecked = true; } - if (!reset) { + if (!offset) { return; } + /* if (patchOffsetCache.resetMb && offset[-(0x158/4)] == 0xE92D4010 && offset[(-(0x158/4))+1] == 0xE59FE04C && offset[(-(0x158/4))+2] == 0xE59F204C && offset[(-(0x158/4))+16] == 0x18BD8001) { + offset[(-(0x158/4))+16] = 0xE1A00000; // nop + } */ + // Patch - u32* resetPatch = ce9->patches->reset_arm9; - tonccpy(reset, resetPatch, 0x40); + tonccpy(offset, ce9->patches->reset_arm9, 0x40); dbg_printf("reset location : "); - dbg_hexa((u32)reset); + dbg_hexa((u32)offset); dbg_printf("\n\n"); } diff --git a/retail/cardenginei/arm7/include/patcher/decompress.h b/retail/cardenginei/arm7/include/patcher/decompress.h index ad2acdd3b..423d25519 100644 --- a/retail/cardenginei/arm7/include/patcher/decompress.h +++ b/retail/cardenginei/arm7/include/patcher/decompress.h @@ -5,6 +5,6 @@ #include // tNDSHeader #include "module_params.h" -void ensureBinaryDecompressed(const tNDSHeader* ndsHeader, module_params_t* moduleParams, const u32 resetParam); +void ensureBinaryDecompressed(const tNDSHeader* ndsHeader, module_params_t* moduleParams); #endif // DECOMPRESS_H diff --git a/retail/cardenginei/arm7/include/patcher/find.h b/retail/cardenginei/arm7/include/patcher/find.h index 2e9172169..533b2d797 100644 --- a/retail/cardenginei/arm7/include/patcher/find.h +++ b/retail/cardenginei/arm7/include/patcher/find.h @@ -80,7 +80,8 @@ u32* findRandomPatchOffset5Second(const tNDSHeader* ndsHeader); // SDK 5 u32* findSleepOffset(const tNDSHeader* ndsHeader, const module_params_t* moduleParams, bool usesThumb, bool* usesThumbPtr); u32* findCardEndReadDma(const tNDSHeader* ndsHeader, const module_params_t* moduleParams, bool usesThumb, const u32* cardReadDmaEndOffset, u32* offsetDmaHandler); u32* findCardSetDma(const tNDSHeader* ndsHeader, const module_params_t* moduleParams, bool usesThumb); -u32* findResetOffset(const tNDSHeader* ndsHeader, const module_params_t* moduleParams, bool* softResetMb); +u32* findSrlStartOffset9(const tNDSHeader* ndsHeader); +u32* findResetOffset(const tNDSHeader* ndsHeader, const module_params_t* moduleParams, const bool softResetMb); // ARM7 bool a7GetReloc(const tNDSHeader* ndsHeader, const module_params_t* moduleParams); @@ -94,6 +95,6 @@ u16* findSleepPatchOffsetThumb(const tNDSHeader* ndsHeader); u32* findSleepInputWriteOffset(const tNDSHeader* ndsHeader, const module_params_t* moduleParams); u32* findCardCheckPullOutOffset(const tNDSHeader* ndsHeader, const module_params_t* moduleParams); u32* findCardIrqEnableOffset(const tNDSHeader* ndsHeader, const module_params_t* moduleParams); -u32* findResetOffset7(const tNDSHeader* ndsHeader); +u32* findSrlStartOffset7(const tNDSHeader* ndsHeader); #endif // FIND_H diff --git a/retail/cardenginei/arm7/include/patcher/hook.h b/retail/cardenginei/arm7/include/patcher/hook.h index d13fde536..3afdf1494 100644 --- a/retail/cardenginei/arm7/include/patcher/hook.h +++ b/retail/cardenginei/arm7/include/patcher/hook.h @@ -34,6 +34,7 @@ int hookNdsRetailArm7( const tNDSHeader* ndsHeader ); int hookNdsRetailArm9( + cardengineArm9* ce9, const tNDSHeader* ndsHeader ); diff --git a/retail/cardenginei/arm7/source/cardengine.c b/retail/cardenginei/arm7/source/cardengine.c index 5027335de..1078e8d1e 100644 --- a/retail/cardenginei/arm7/source/cardengine.c +++ b/retail/cardenginei/arm7/source/cardengine.c @@ -448,7 +448,7 @@ static void cardReadRAM(u8* dst, u32 src, u32 len/*, int romPartNo*/) { #endif } -void reset(void) { +void reset(const bool downloadedSrl) { register int i, reg; #ifndef TWLSDK @@ -457,7 +457,7 @@ void reset(void) { REG_MASTER_VOLUME = 0; int oldIME = enterCriticalSection(); //driveInitialize(); - if (*(u32*)(resetParam+8) == 0x44414F4C) { // 'LOAD' + if (downloadedSrl) { fileWrite((char*)ndsHeader, &pageFile, 0x2BFE00, 0x160); fileWrite((char*)ndsHeader->arm9destination, &pageFile, 0x14000, ndsHeader->arm9binarySize); fileWrite((char*)0x02380000, &pageFile, 0x2C0000, ndsHeader->arm7binarySize); @@ -534,22 +534,18 @@ void reset(void) { unlockMutex(&saveMutex); #ifndef TWLSDK - if ((valueBits & isDlp) || currentSrlAddr != *(u32*)(resetParam+0xC) || *(u32*)(resetParam+8) == 0x44414F4C) { + if ((valueBits & isDlp) || currentSrlAddr != *(u32*)(resetParam+0xC) || downloadedSrl) { currentSrlAddr = *(u32*)(resetParam+0xC); - if (valueBits & isDlp) { + if ((valueBits & isDlp) || downloadedSrl) { // ndmaCopyWordsAsynch(1, (u32*)0x022C0000, ndsHeader->arm7destination, ndsHeader->arm7binarySize); + } else if (valueBits & ROMinRAM) { + cardReadRAM((u8*)ndsHeader, currentSrlAddr, 0x160); + cardReadRAM((u8*)ndsHeader->arm9destination, currentSrlAddr+ndsHeader->arm9romOffset, ndsHeader->arm9binarySize); + cardReadRAM((u8*)ndsHeader->arm7destination, currentSrlAddr+ndsHeader->arm7romOffset, ndsHeader->arm7binarySize); } else { - if (*(u32*)(resetParam+8) == 0x44414F4C) { - // ndmaCopyWordsAsynch(1, (u32*)0x022C0000, ndsHeader->arm7destination, ndsHeader->arm7binarySize); - } else if (valueBits & ROMinRAM) { - cardReadRAM((u8*)ndsHeader, currentSrlAddr, 0x160); - cardReadRAM((u8*)ndsHeader->arm9destination, currentSrlAddr+ndsHeader->arm9romOffset, ndsHeader->arm9binarySize); - cardReadRAM((u8*)ndsHeader->arm7destination, currentSrlAddr+ndsHeader->arm7romOffset, ndsHeader->arm7binarySize); - } else { - fileRead((char*)ndsHeader, romFile, currentSrlAddr, 0x160); - fileRead((char*)ndsHeader->arm9destination, romFile, currentSrlAddr+ndsHeader->arm9romOffset, ndsHeader->arm9binarySize); - fileRead((char*)ndsHeader->arm7destination, romFile, currentSrlAddr+ndsHeader->arm7romOffset, ndsHeader->arm7binarySize); - } + fileRead((char*)ndsHeader, romFile, currentSrlAddr, 0x160); + fileRead((char*)ndsHeader->arm9destination, romFile, currentSrlAddr+ndsHeader->arm9romOffset, ndsHeader->arm9binarySize); + fileRead((char*)ndsHeader->arm7destination, romFile, currentSrlAddr+ndsHeader->arm7romOffset, ndsHeader->arm7binarySize); } moduleParams = getModuleParams(ndsHeader); @@ -562,7 +558,7 @@ void reset(void) { valueBits &= ~isSdk5; } - ensureBinaryDecompressed(ndsHeader, moduleParams, (valueBits & isDlp) ? 0x44414F4 : resetParam); + ensureBinaryDecompressed(ndsHeader, moduleParams); patchCardNdsArm9( (cardengineArm9*)((valueBits & isDlp) ? CARDENGINEI_ARM9_LOCATION_DLP : CARDENGINEI_ARM9_LOCATION), @@ -570,7 +566,6 @@ void reset(void) { moduleParams, 1 ); - // while (ndmaBusy(1)); patchCardNdsArm7( (cardengineArm7*)ce7, ndsHeader, @@ -581,7 +576,10 @@ void reset(void) { (cardengineArm7*)ce7, ndsHeader ); - hookNdsRetailArm9(ndsHeader); + hookNdsRetailArm9( + (cardengineArm9*)((valueBits & isDlp) ? CARDENGINEI_ARM9_LOCATION_DLP : CARDENGINEI_ARM9_LOCATION), + ndsHeader + ); extern u32 iUncompressedSize; @@ -595,13 +593,8 @@ void reset(void) { ndmaCopyWordsAsynch(1, ndsHeader->arm7destination, (char*)DONOR_ROM_ARM7_LOCATION, ndsHeader->arm7binarySize); while (ndmaBusy(0) || ndmaBusy(1)); } */ - if (valueBits & isDlp) { - toncset((u32*)0x022C0000, 0, ndsHeader->arm7binarySize); - if (!(valueBits & isSdk5)) { - tonccpy((u8*)0x027FF000, (u8*)0x02FFF000, 0x1000); - } - } else { - *(u32*)(resetParam+8) = 0; + if ((valueBits & isDlp) && !(valueBits & isSdk5)) { + tonccpy((u8*)0x027FF000, (u8*)0x02FFF000, 0x1000); } valueBits &= ~isDlp; } else { @@ -1692,7 +1685,7 @@ void myIrqHandlerVBlank(void) { if (valueBits & isDlp) { if (!(REG_EXTKEYINPUT & KEY_A) && *(u32*)(NDS_HEADER_SDK5+0xC) != 0 && !wifiIrq) { IPC_SendSync(0x5); - reset(); + reset(false); } } #endif */ @@ -1764,7 +1757,7 @@ void myIrqHandlerVBlank(void) { } */ if (sharedAddr[3] == (vu32)0x52534554) { - reset(); + reset(false); } if ( 0 == (REG_KEYINPUT & (KEY_L | KEY_R | KEY_START | KEY_SELECT))) { diff --git a/retail/cardenginei/arm7/source/inGameMenu.c b/retail/cardenginei/arm7/source/inGameMenu.c index 87237d155..2bca9c162 100644 --- a/retail/cardenginei/arm7/source/inGameMenu.c +++ b/retail/cardenginei/arm7/source/inGameMenu.c @@ -26,7 +26,7 @@ extern bool ipcEveryFrame; extern struct IgmText *igmText; -extern void reset(void); +extern void reset(const bool downloadedSrl); extern void dumpRam(void); extern void returnToLoader(bool reboot); extern void prepareScreenshot(void); @@ -134,7 +134,7 @@ void inGameMenu(void) { #ifdef TWLSDK i2cWriteRegister(0x4A, 0x12, 0x01); #endif - reset(); + reset(false); break; case 0x54495551: // QUIT unloadInGameMenu(); diff --git a/retail/cardenginei/arm7/source/patcher/decompress.c b/retail/cardenginei/arm7/source/patcher/decompress.c index 231f216c1..ac5166ab2 100644 --- a/retail/cardenginei/arm7/source/patcher/decompress.c +++ b/retail/cardenginei/arm7/source/patcher/decompress.c @@ -27,7 +27,7 @@ u32 iUncompressedSize = 0; static u32 iFixedAddr = 0; static u32 iFixedData = 0; -static u32 decompressBinary(u8 *aMainMemory, u32 aCodeLength, u32 aMemOffset, const u32 resetParam) { +static u32 decompressBinary(u8 *aMainMemory, u32 aCodeLength, u32 aMemOffset) { u8 *ADDR1 = NULL; u8 *ADDR1_END = NULL; u8 *ADDR2 = NULL; @@ -58,9 +58,6 @@ static u32 decompressBinary(u8 *aMainMemory, u32 aCodeLength, u32 aMemOffset, co B &= ~0xff000000; ADDR3 = ADDR1 - B; u32 uncompressEnd = ((u32)ADDR1_END) - ((u32)aMainMemory); - if (uncompressEnd >= ((*(u32*)(resetParam+8) == 0x44414F4) ? 0x2C0000 : 0x380000)) { - while (ndmaBusy(1)); // Wait for ARM7 binary to finish copying - } while (!(ADDR2 <= ADDR3)) { u32 marku8 = *(--ADDR2 + aMemOffset); @@ -95,7 +92,7 @@ static u32 decompressBinary(u8 *aMainMemory, u32 aCodeLength, u32 aMemOffset, co return uncompressEnd; } -void ensureBinaryDecompressed(const tNDSHeader* ndsHeader, module_params_t* moduleParams, const u32 resetParam) { +void ensureBinaryDecompressed(const tNDSHeader* ndsHeader, module_params_t* moduleParams) { unpatchedFunctions* unpatchedFuncs = (unpatchedFunctions*)UNPATCHED_FUNCTION_LOCATION; if (moduleParams->compressed_static_end) { @@ -104,7 +101,7 @@ void ensureBinaryDecompressed(const tNDSHeader* ndsHeader, module_params_t* modu unpatchedFuncs->compressedFlagOffset = (u32*)((u32)moduleParams+0x14); unpatchedFuncs->compressed_static_end = moduleParams->compressed_static_end; //decompressLZ77Backwards((u8*)ndsHeader->arm9destination, ndsHeader->arm9binarySize); - iUncompressedSize = decompressBinary((u8*)ndsHeader->arm9destination, ndsHeader->arm9binarySize, 0, resetParam); + iUncompressedSize = decompressBinary((u8*)ndsHeader->arm9destination, ndsHeader->arm9binarySize, 0); moduleParams->compressed_static_end = 0; } else { // Not compressed diff --git a/retail/cardenginei/arm7/source/patcher/find_arm7.c b/retail/cardenginei/arm7/source/patcher/find_arm7.c index e7d90979b..1ac1ad258 100644 --- a/retail/cardenginei/arm7/source/patcher/find_arm7.c +++ b/retail/cardenginei/arm7/source/patcher/find_arm7.c @@ -90,8 +90,8 @@ static const u16 irqEnableStartSignatureThumb[5] = {0xB530, 0xB081, 0x4D07, 0x8 static const u16 irqEnableStartSignatureThumb3[5] = {0xB510, 0x1C04, 0xF7FF, 0xFFF4, 0x4B05}; // SDK 3 static const u16 irqEnableStartSignatureThumb5[5] = {0xB510, 0x1C04, 0xF7FF, 0xFFE4, 0x4B05}; // SDK 5 -// Reset -static const u32 resetSignature3Eoo[] = {0xE92D4070, 0xE59F0098, 0xE5904004, 0xE3540000}; // eoo.dat (Pokemon) +// SRL start +static const u32 srlStartSignature3[4] = {0xE92D4070, 0xE59F0098, 0xE5904004, 0xE3540000}; // eoo.dat (Pokemon) u32 relocationStart = 0; bool a7GetReloc(const tNDSHeader* ndsHeader, const module_params_t* moduleParams) { @@ -166,13 +166,13 @@ bool a7GetReloc(const tNDSHeader* ndsHeader, const module_params_t* moduleParams forwardedRelocStartAddr += 4; } vAddrOfRelocSrc = *(u32*)(forwardedRelocStartAddr + 8); - + /*dbg_printf("forwardedRelocStartAddr\n"); - dbg_hexa(forwardedRelocStartAddr); + dbg_hexa(forwardedRelocStartAddr); dbg_printf("\nvAddrOfRelocSrc\n"); dbg_hexa(vAddrOfRelocSrc); dbg_printf("\n");*/ - + // Sanity checks u32 relocationCheck1 = *(u32*)(forwardedRelocStartAddr + 0xC); u32 relocationCheck2 = *(u32*)(forwardedRelocStartAddr + 0x10); @@ -184,13 +184,13 @@ bool a7GetReloc(const tNDSHeader* ndsHeader, const module_params_t* moduleParams (u32*)relocationStart, ndsHeader->arm7binarySize, nextFunctiontSignature, 1 ); - + // Validate the relocation signature forwardedRelocStartAddr = nextFunction - 0x14; - + // Validate the relocation signature vAddrOfRelocSrc = *(u32*)(nextFunction - 0xC); - + // Sanity checks relocationCheck1 = *(u32*)(forwardedRelocStartAddr + 0xC); relocationCheck2 = *(u32*)(forwardedRelocStartAddr + 0x10); @@ -819,7 +819,7 @@ u32* findSleepPatchOffset(const tNDSHeader* ndsHeader) { u16* findSleepPatchOffsetThumb(const tNDSHeader* ndsHeader) { //dbg_printf("findSleepPatchOffsetThumb:\n"); - + u16* sleepPatchOffset = findOffsetThumb( (u16*)ndsHeader->arm7destination, ndsHeader->arm7binarySize, sleepPatchThumb, 2 @@ -893,7 +893,7 @@ u32* findSleepInputWriteOffset(const tNDSHeader* ndsHeader, const module_params_ u32* findCardCheckPullOutOffset(const tNDSHeader* ndsHeader, const module_params_t* moduleParams) { //dbg_printf("findCardCheckPullOutOffset:\n"); - + const u32* cardCheckPullOutSignature = cardCheckPullOutSignature1; if (moduleParams->sdk_version > 0x2004FFF && moduleParams->sdk_version < 0x3000000) { cardCheckPullOutSignature = cardCheckPullOutSignature2; @@ -922,7 +922,7 @@ u32* findCardCheckPullOutOffset(const tNDSHeader* ndsHeader, const module_params u32* findCardIrqEnableOffset(const tNDSHeader* ndsHeader, const module_params_t* moduleParams) { // dbg_printf("findCardIrqEnableOffset:\n"); - + const u32* irqEnableStartSignature = irqEnableStartSignature1; if (ndsHeader->arm7binarySize != 0x289C0 && moduleParams->sdk_version > 0x4000000) { irqEnableStartSignature = irqEnableStartSignature4; @@ -1013,21 +1013,20 @@ u32* findCardIrqEnableOffset(const tNDSHeader* ndsHeader, const module_params_t* return cardIrqEnableOffset; } -u32* findResetOffset7(const tNDSHeader* ndsHeader) { - // dbg_printf("findResetOffset\n"); +u32* findSrlStartOffset7(const tNDSHeader* ndsHeader) { + // dbg_printf("findSrlStartOffset7\n"); - u32* resetOffset = findOffset( + u32* offset = findOffset( ndsHeader->arm7destination, ndsHeader->arm7binarySize, - resetSignature3Eoo, 4 + srlStartSignature3, 4 ); - if (resetOffset) { - // dbg_printf("Reset found\n"); - // dbg_printf("\n"); - return resetOffset; + /* if (offset) { + dbg_printf("SRL start function found\n"); } else { - // dbg_printf("Reset not found\n"); + dbg_printf("SRL start function not found\n"); } - return NULL; + dbg_printf("\n"); */ + return offset; } diff --git a/retail/cardenginei/arm7/source/patcher/find_arm9.c b/retail/cardenginei/arm7/source/patcher/find_arm9.c index bac5dede7..63beb3359 100644 --- a/retail/cardenginei/arm7/source/patcher/find_arm9.c +++ b/retail/cardenginei/arm7/source/patcher/find_arm9.c @@ -134,7 +134,7 @@ static const u32 mpuInitRegion3TwlEndSignatureThumb[3] = {0x48010081, 0x47705808 //static const u32 operaRamSignature[2] = {0x097FFFFE, 0x09000000}; -// Threads management +// Threads management static const u32 sleepSignature2[4] = {0xE92D4010, 0xE24DD030, 0xE1A04000, 0xE28D0004}; // sdk2 static const u16 sleepSignatureThumb2[4] = {0x4010, 0xE92D, 0xD030, 0xE24D}; // sdk2 static const u32 sleepSignature4[4] = {0xE92D4030, 0xE24DD034, 0xE1A04000, 0xE28D0008}; // sdk4 @@ -166,7 +166,7 @@ static const u32 resetSignature2Alt1[4] = {0xE92D000F, 0xE92D4010, 0xEB000026, 0 static const u32 resetSignature2Alt2[4] = {0xE92D4010, 0xE59F1078, 0xE1A04000, 0xE1D100B0}; // sdk2 static const u32 resetSignature3[4] = {0xE92D4010, 0xE59F106C, 0xE1A04000, 0xE1D100B0}; // sdk3 static const u32 resetSignature3Alt[4] = {0xE92D4010, 0xE59F1068, 0xE1A04000, 0xE1D100B0}; // sdk3 -static const u32 resetSignature3Eoo[4] = {0xE92D4010, 0xE59F003C, 0xE5904000, 0xE3540000}; // eoo.dat (Pokemon) +static const u32 resetSignature3Eoo[2] = {0xE92D4010, 0xE1A04000}; // eoo.dat (Pokemon) static const u32 resetSignature4[4] = {0xE92D4070, 0xE59F10A0, 0xE1A04000, 0xE1D100B0}; // sdk4 static const u32 resetSignature4Alt[4] = {0xE92D4010, 0xE59F1084, 0xE1A04000, 0xE1D100B0}; // sdk4 static const u32 resetSignature5[4] = {0xE92D4038, 0xE59F1054, 0xE1A05000, 0xE1D100B0}; // sdk5 @@ -178,6 +178,9 @@ static const u32 resetSignature5Alt4[4] = {0xE92D4038, 0xE59F1090, 0xE1A05000, 0 static const u32 resetConstant[1] = {RESET_PARAM}; static const u32 resetConstant5[1] = {RESET_PARAM_SDK5}; +// SRL start +static const u32 srlStartSignature3[4] = {0xE92D4010, 0xE59F003C, 0xE5904000, 0xE3540000}; // eoo.dat (Pokemon) + // Panic // TODO : could be a good idea to catch the call to Panic function and store the message somewhere @@ -362,7 +365,7 @@ u16* findCardReadEndOffsetThumb5Type0(const tNDSHeader* ndsHeader, const module_ if (moduleParams->sdk_version < 0x5000000) { return NULL; } - + // dbg_printf("findCardReadEndOffsetThumb5Type0:\n"); u16* cardReadEndOffset = findOffsetThumb( @@ -443,7 +446,7 @@ u32* findCardReadStartOffset5(const module_params_t* moduleParams, const u32* ca if (moduleParams->sdk_version < 0x5000000) { return NULL; } - + if (!cardReadEndOffset) { return NULL; } @@ -582,7 +585,7 @@ u32* findCardPullOutOffset(const tNDSHeader* ndsHeader, const module_params_t* m //dbg_printf("findCardPullOutOffset:\n"); //if (!usesThumb) { - + u32* cardPullOutOffset = 0; if (moduleParams->sdk_version > 0x5000000) { // SDK 5 @@ -725,7 +728,7 @@ u16* findCardPullOutOffsetThumb5Type0(const tNDSHeader* ndsHeader, const module_ } // dbg_printf("findCardPullOutOffsetThumbType0:\n"); - + u16* cardPullOutOffset = findOffsetThumb( (u16*)ndsHeader->arm9destination, iUncompressedSize,//, ndsHeader->arm9binarySize, cardPullOutSignatureThumb5, 4 @@ -745,9 +748,9 @@ u16* findCardPullOutOffsetThumb5Type1(const tNDSHeader* ndsHeader, const module_ if (moduleParams->sdk_version < 0x5000000) { return NULL; } - + // dbg_printf("findCardPullOutOffsetThumbType1:\n"); - + u16* cardPullOutOffset = findOffsetThumb( (u16*)ndsHeader->arm9destination, iUncompressedSize,//, ndsHeader->arm9binarySize, cardPullOutSignatureThumb5Alt, 4 @@ -1114,7 +1117,7 @@ u16* findCardReadDmaStartOffsetThumb(const u16* cardReadDmaEndOffset) { u32* a9FindCardIrqEnableOffset(const tNDSHeader* ndsHeader, const module_params_t* moduleParams, bool* usesThumb) { // dbg_printf("findCardIrqEnableOffset:\n"); - + const u32* irqEnableStartSignature = irqEnableStartSignature1; if (moduleParams->sdk_version > 0x4008000) { irqEnableStartSignature = irqEnableStartSignature4; @@ -1269,7 +1272,7 @@ u32* findMpuDataOffset(const module_params_t* moduleParams, u32 patchMpuRegion, mpuInitRegionData = mpuInitRegion3Data; break; } - + u32* mpuDataOffset = findOffset( mpuStartOffset, 0x100, mpuInitRegionData, 1 @@ -1406,7 +1409,7 @@ u32* findMpuInitTwlEnd(const u32* heapPointer2Offset) { u32* findHeapPointerOffset(const module_params_t* moduleParams, const tNDSHeader* ndsHeader) { // dbg_printf("findHeapPointerOffset:\n"); - + const u32* initHeapEndSignature = initHeapEndSignature1; if (moduleParams->sdk_version > 0x5000000) { initHeapEndSignature = initHeapEndSignature5; @@ -1422,7 +1425,7 @@ u32* findHeapPointerOffset(const module_params_t* moduleParams, const tNDSHeader // dbg_printf("Init Heap End not found\n\n"); return 0; } - + /* dbg_hexa((u32)initHeapEnd); dbg_printf("\n"); dbg_printf("heapPointer: "); */ @@ -1438,7 +1441,7 @@ u32* findHeapPointerOffset(const module_params_t* moduleParams, const tNDSHeader ); } u32* heapPointer = initEndFunc + 1; - + if (!initEndFunc) { u16* initEndFuncThumb = findOffsetBackwardsThumb( (u16*)initHeapEnd, 0x40, @@ -1452,7 +1455,7 @@ u32* findHeapPointerOffset(const module_params_t* moduleParams, const tNDSHeader } heapPointer = (u32*)((u16*)initEndFuncThumb+1); } - + /* dbg_hexa((u32)heapPointer); dbg_printf("\n"); */ @@ -1461,7 +1464,7 @@ u32* findHeapPointerOffset(const module_params_t* moduleParams, const tNDSHeader u32* findHeapPointer2Offset(const module_params_t* moduleParams, const tNDSHeader* ndsHeader) { //dbg_printf("findHeapPointer2Offset:\n"); - + u32* initEndFunc = NULL; if (!initEndFunc) { initEndFunc = findOffset( @@ -1507,7 +1510,7 @@ u32* findHeapPointer2Offset(const module_params_t* moduleParams, const tNDSHeade } u32* heapPointer = initEndFunc + 1; - + /* dbg_hexa((u32)heapPointer); dbg_printf("\n"); */ @@ -1564,13 +1567,13 @@ u32* findSleepOffset(const tNDSHeader* ndsHeader, const module_params_t* moduleP const u32* sleepSignature = sleepSignature2; const u16* sleepSignatureThumb = sleepSignatureThumb2; - if (moduleParams->sdk_version > 0x3000000 && moduleParams->sdk_version < 0x5000000) { + if (moduleParams->sdk_version > 0x3000000 && moduleParams->sdk_version < 0x5000000) { sleepSignature = sleepSignature4; - sleepSignatureThumb = sleepSignatureThumb4; + sleepSignatureThumb = sleepSignatureThumb4; } if (moduleParams->sdk_version > 0x5000000) { sleepSignature = sleepSignature5; - sleepSignatureThumb = sleepSignatureThumb5; + sleepSignatureThumb = sleepSignatureThumb5; } u32 * sleepOffset = NULL; @@ -1625,8 +1628,8 @@ u32* findSleepOffset(const tNDSHeader* ndsHeader, const module_params_t* moduleP dbg_hexa((u32)sleepEndOffset); dbg_printf("\n"); */ break; - } - + } + if(usesThumb) { sleepOffset = (u32*)findOffsetThumb( (u16*)(sleepOffset+1), iUncompressedSize,//ndsHeader->arm9binarySize, @@ -1638,7 +1641,7 @@ u32* findSleepOffset(const tNDSHeader* ndsHeader, const module_params_t* moduleP sleepSignature, 4 ); } - } + } /* if (sleepOffset) { dbg_printf("Sleep found\n"); @@ -1657,7 +1660,7 @@ u32* findCardEndReadDmaSdk5(const tNDSHeader* ndsHeader, const module_params_t* const u32* cardEndReadDmaSignature = cardEndReadDmaSignature5; u32 * offset = NULL; - + if(usesThumb) { offset = (u32*)findOffsetThumb( (u16*)ndsHeader->arm9destination, iUncompressedSize,//ndsHeader->arm9binarySize, @@ -1667,15 +1670,15 @@ u32* findCardEndReadDmaSdk5(const tNDSHeader* ndsHeader, const module_params_t* offset = findOffset( (u32*)ndsHeader->arm9destination, iUncompressedSize,//ndsHeader->arm9binarySize, cardEndReadDmaSignature, 4 - ); - } - + ); + } + /* if (offset) { dbg_printf("cardEndReadDma found\n"); } else { dbg_printf("cardEndReadDma not found\n"); } - + dbg_printf("\n"); */ return offset; } @@ -1693,11 +1696,11 @@ u32* findCardEndReadDma(const tNDSHeader* ndsHeader, const module_params_t* modu } if(moduleParams->sdk_version > 0x4000000 || *offsetDmaHandler<0x2000000 || *offsetDmaHandler>0x2400000) { - offsetDmaHandler = cardReadDmaEndOffset+4; + offsetDmaHandler = cardReadDmaEndOffset+4; } if(*offsetDmaHandler<0x2000000 || *offsetDmaHandler>0x2400000) { - offsetDmaHandler = cardReadDmaEndOffset+3; + offsetDmaHandler = cardReadDmaEndOffset+3; } if(*offsetDmaHandler<0x2000000 || *offsetDmaHandler>0x2400000) { @@ -1729,7 +1732,7 @@ u32* findCardEndReadDma(const tNDSHeader* ndsHeader, const module_params_t* modu cardEndReadDmaSignature4Alt, 1 ); } - } + } if (!offset) { if (usesThumb) { @@ -1764,7 +1767,7 @@ u32* findCardEndReadDma(const tNDSHeader* ndsHeader, const module_params_t* modu u32* findCardSetDmaSdk5(const tNDSHeader* ndsHeader, const module_params_t* moduleParams, bool usesThumb) { // dbg_printf("findCardSetDmaSdk5\n"); - + u32* currentOffset = (u32*)ndsHeader->arm9destination; u32* startOffset = NULL; while (startOffset==NULL) { @@ -1772,16 +1775,16 @@ u32* findCardSetDmaSdk5(const tNDSHeader* ndsHeader, const module_params_t* modu currentOffset+1, iUncompressedSize, cardSetDmaSignatureValue1, 1 ); - if (cardSetDmaEndOffset==NULL) { + if (cardSetDmaEndOffset==NULL) { // dbg_printf("cardSetDmaEnd not found\n"); return NULL; } else { /* dbg_printf("cardSetDmaSignatureValue1 found\n"); dbg_hexa((u32)cardSetDmaEndOffset); dbg_printf(" : "); - dbg_hexa(*cardSetDmaEndOffset); + dbg_hexa(*cardSetDmaEndOffset); dbg_printf("\n"); */ - + currentOffset = cardSetDmaEndOffset+2; if(usesThumb) { // dbg_printf("cardSetDmaSignatureStartThumb used: "); @@ -1795,7 +1798,7 @@ u32* findCardSetDmaSdk5(const tNDSHeader* ndsHeader, const module_params_t* modu cardSetDmaEndOffset, 0x90, cardSetDmaSignatureStart5, 2 ); - } + } if (!startOffset && !usesThumb) { startOffset = findOffsetBackwards( cardSetDmaEndOffset, 0x90, @@ -1806,9 +1809,9 @@ u32* findCardSetDmaSdk5(const tNDSHeader* ndsHeader, const module_params_t* modu // dbg_printf("cardSetDmaSignatureStart found\n"); /*dbg_hexa((u32)startOffset); dbg_printf(" : "); - dbg_hexa(*startOffset); + dbg_hexa(*startOffset); dbg_printf("\n");*/ - + return startOffset; } } @@ -1842,16 +1845,16 @@ u32* findCardSetDma(const tNDSHeader* ndsHeader, const module_params_t* modulePa currentOffset+1, iUncompressedSize, cardSetDmaSignatureValue1, 1 ); - if (cardSetDmaEndOffset==NULL) { + if (cardSetDmaEndOffset==NULL) { //dbg_printf("cardSetDmaEnd not found\n"); return NULL; } else { /*dbg_printf("cardSetDmaSignatureValue1 found\n"); dbg_hexa((u32)cardSetDmaEndOffset); dbg_printf(" : "); - dbg_hexa(*cardSetDmaEndOffset); + dbg_hexa(*cardSetDmaEndOffset); dbg_printf("\n");*/ - + currentOffset = cardSetDmaEndOffset+2; cardSetDmaEndOffset = findOffset( currentOffset, 0x18, @@ -1861,18 +1864,18 @@ u32* findCardSetDma(const tNDSHeader* ndsHeader, const module_params_t* modulePa /*dbg_printf("cardSetDmaSignatureValue2 found\n"); dbg_hexa((u32)cardSetDmaEndOffset); dbg_printf(" : "); - dbg_hexa(*cardSetDmaEndOffset); + dbg_hexa(*cardSetDmaEndOffset); dbg_printf("\n");*/ - + break; - } - } - } + } + } + } /*bg_printf("cardSetDmaEnd found\n"); dbg_hexa((u32)cardSetDmaEndOffset); dbg_printf(" : "); - dbg_hexa(*cardSetDmaEndOffset); + dbg_hexa(*cardSetDmaEndOffset); dbg_printf("\n");*/ u32 * offset = NULL; @@ -1919,13 +1922,31 @@ u32* findCardSetDma(const tNDSHeader* ndsHeader, const module_params_t* modulePa dbg_printf("\n"); */ return offset; -} +} + +u32* findSrlStartOffset9(const tNDSHeader* ndsHeader) { + // dbg_printf("findSrlStartOffset9\n"); + + u32* offset = findOffset( + (u32*)ndsHeader->arm9destination, iUncompressedSize, + srlStartSignature3, 4 + ); + + /* if (offset) { + dbg_printf("SRL start function found\n"); + } else { + dbg_printf("SRL start function not found\n"); + } -u32* findResetOffset(const tNDSHeader* ndsHeader, const module_params_t* moduleParams, bool* softResetMb) { + dbg_printf("\n"); */ + return offset; +} + +u32* findResetOffset(const tNDSHeader* ndsHeader, const module_params_t* moduleParams, const bool softResetMb) { // dbg_printf("findResetOffset\n"); const u32* resetSignature = resetSignature2; - if (moduleParams->sdk_version > 0x4008000 && moduleParams->sdk_version < 0x5000000) { + if (moduleParams->sdk_version > 0x4008000 && moduleParams->sdk_version < 0x5000000) { resetSignature = resetSignature4; } if (moduleParams->sdk_version > 0x5000000) { @@ -1934,27 +1955,36 @@ u32* findResetOffset(const tNDSHeader* ndsHeader, const module_params_t* moduleP u32 * resetOffset = NULL; - if ((memcmp(getRomTid(ndsHeader), "NTRJ", 4) == 0) && (moduleParams->sdk_version < 0x5000000)) { - resetOffset = findOffset( - (u32*)ndsHeader->arm9destination, iUncompressedSize,//ndsHeader->arm9binarySize, - resetSignature3Eoo, 4 - ); + if (softResetMb) { + u32* resetEndOffset = findOffset( + (u32*)ndsHeader->arm9destination, iUncompressedSize, + resetConstant, 1 + ); + if (resetEndOffset) { + /* dbg_printf("Reset constant found: "); + dbg_hexa((u32)resetEndOffset); + dbg_printf("\n"); */ - if (resetOffset) { - /* dbg_printf("Reset found\n"); - dbg_printf("\n");*/ - *softResetMb = true; - return resetOffset; - } /* else { - dbg_printf("Reset not found\n"); - } */ + resetOffset = findOffsetBackwards( + resetEndOffset, 0x80, + resetSignature3Eoo, 2 + ); + + if (resetOffset) { + // dbg_printf("Reset found\n"); + // dbg_printf("\n"); + return resetOffset; + } /* else { + dbg_printf("Reset not found\n"); + } */ + } } resetOffset = findOffset( (u32*)ndsHeader->arm9destination, iUncompressedSize,//ndsHeader->arm9binarySize, resetSignature, 4 ); - + if (!resetOffset) { if (moduleParams->sdk_version > 0x2000000 && moduleParams->sdk_version < 0x2008000) { resetOffset = findOffset( @@ -2018,13 +2048,13 @@ u32* findResetOffset(const tNDSHeader* ndsHeader, const module_params_t* moduleP } } } - + /* if (resetOffset) { dbg_printf("Reset found: "); dbg_hexa((u32)resetOffset); dbg_printf("\n"); } */ - + while(resetOffset!=NULL) { u32* resetEndOffset = findOffset( resetOffset, 0x200, @@ -2035,8 +2065,8 @@ u32* findResetOffset(const tNDSHeader* ndsHeader, const module_params_t* moduleP dbg_hexa((u32)resetEndOffset); dbg_printf("\n"); */ break; - } - + } + resetOffset = findOffset( resetOffset+1, iUncompressedSize,//ndsHeader->arm9binarySize, resetSignature, 4 @@ -2046,8 +2076,8 @@ u32* findResetOffset(const tNDSHeader* ndsHeader, const module_params_t* moduleP dbg_hexa((u32)resetOffset); dbg_printf("\n"); } */ - } - + } + /* if (resetOffset) { dbg_printf("Reset found\n"); } else { diff --git a/retail/cardenginei/arm7/source/patcher/hook_arm9.c b/retail/cardenginei/arm7/source/patcher/hook_arm9.c index 6d725bb4e..c508107d8 100644 --- a/retail/cardenginei/arm7/source/patcher/hook_arm9.c +++ b/retail/cardenginei/arm7/source/patcher/hook_arm9.c @@ -11,7 +11,6 @@ #define isSdk5_9 BIT(5) #define isSdk5_7 BIT(13) -#define b_softResetMb BIT(13) #define b_isDlp BIT(15) extern u32 valueBits; @@ -119,24 +118,19 @@ static u32* hookInterruptHandler(const u32* start, size_t size) { } int hookNdsRetailArm9( + cardengineArm9* ce9, const tNDSHeader* ndsHeader ) { //nocashMessage("hookNdsRetailArm9"); extern u32 iUncompressedSize; - extern bool softResetMb; if (valueBits & isSdk5_7) { - sharedAddr[1] |= isSdk5_9; + ce9->valueBits |= isSdk5_9; } else { - sharedAddr[1] &= ~isSdk5_9; + ce9->valueBits &= ~isSdk5_9; } - if (softResetMb) { - sharedAddr[1] |= b_softResetMb; - } else { - sharedAddr[1] &= ~b_softResetMb; - } - sharedAddr[1] &= ~b_isDlp; + ce9->valueBits &= ~b_isDlp; u32* tableAddr = hookInterruptHandler((u32*)ndsHeader->arm9destination, iUncompressedSize); @@ -149,7 +143,7 @@ int hookNdsRetailArm9( dbg_hexa((u32)tableAddr); dbg_printf("\n\n");*/ - sharedAddr[2] = (u32)tableAddr; + ce9->irqTable = tableAddr; //nocashMessage("ERR_NONE"); return ERR_NONE; diff --git a/retail/cardenginei/arm7/source/patcher/patch_arm7.c b/retail/cardenginei/arm7/source/patcher/patch_arm7.c index e38f776bb..3762a8971 100644 --- a/retail/cardenginei/arm7/source/patcher/patch_arm7.c +++ b/retail/cardenginei/arm7/source/patcher/patch_arm7.c @@ -229,15 +229,16 @@ static void patchCardCheckPullOut(cardengineArm7* ce7, const tNDSHeader* ndsHead } } -static void patchReset(cardengineArm7* ce7, const tNDSHeader* ndsHeader, const module_params_t* moduleParams) { - u32* offset = findResetOffset7(ndsHeader); +static void patchSrlStart(cardengineArm7* ce7, const tNDSHeader* ndsHeader) { + u32* offset = findSrlStartOffset7(ndsHeader); if (!offset) { return; } - offset[0] = 0xE59F0000; // ldr r0, =reset - offset[1] = 0xE12FFF10; // bx r0 - offset[2] = (u32)ce7->patches->reset; + offset[0] = 0xE3A00001; // mov r0, #1 + offset[1] = 0xE59FC000; // ldr r12, =reset + offset[2] = 0xE12FFF1C; // bx r12 + offset[3] = (u32)ce7->patches->reset; } u32 patchCardNdsArm7( @@ -258,7 +259,7 @@ u32 patchCardNdsArm7( extern bool softResetMb; if (softResetMb) { - patchReset(ce7, ndsHeader, moduleParams); + patchSrlStart(ce7, ndsHeader); } if (a7GetReloc(ndsHeader, moduleParams)) { diff --git a/retail/cardenginei/arm7/source/patcher/patch_arm9.c b/retail/cardenginei/arm7/source/patcher/patch_arm9.c index 006485bd1..2f2a1ae4c 100644 --- a/retail/cardenginei/arm7/source/patcher/patch_arm9.c +++ b/retail/cardenginei/arm7/source/patcher/patch_arm9.c @@ -18,8 +18,6 @@ extern u32 valueBits; extern u16 scfgRomBak; -extern vu32* volatile sharedAddr; - bool isPawsAndClaws(const tNDSHeader* ndsHeader) { const char* romTid = getRomTid(ndsHeader); @@ -393,18 +391,35 @@ static bool patchCardSetDma(cardengineArm9* ce9, const tNDSHeader* ndsHeader, co bool softResetMb = false; static void patchReset(cardengineArm9* ce9, const tNDSHeader* ndsHeader, const module_params_t* moduleParams) { softResetMb = false; - u32* reset = findResetOffset(ndsHeader, moduleParams, &softResetMb); + const char* romTid = getRomTid(ndsHeader); + if (strcmp(romTid, "NTRJ") == 0 || strncmp(romTid, "HND", 3) == 0 || strncmp(romTid, "HNE", 3) == 0) { + u32* offset = findSrlStartOffset9(ndsHeader); + + if (offset) { + // Patch + tonccpy(offset, ce9->patches->reset_arm9, 0x40); + /* dbg_printf("srlStart location : "); + dbg_hexa((u32)offset); + dbg_printf("\n\n"); */ + softResetMb = true; + } + } - if (!reset) { + u32* offset = findResetOffset(ndsHeader, moduleParams, softResetMb); + + if (!offset) { return; } + /* if (softResetMb && offset[-(0x158/4)] == 0xE92D4010 && offset[(-(0x158/4))+1] == 0xE59FE04C && offset[(-(0x158/4))+2] == 0xE59F204C && offset[(-(0x158/4))+16] == 0x18BD8001) { + offset[(-(0x158/4))+16] = 0xE1A00000; // nop + } */ + // Patch - u32* resetPatch = ce9->patches->reset_arm9; - tonccpy(reset, resetPatch, 0x40); - /*dbg_printf("reset location : "); - dbg_hexa((u32)reset); - dbg_printf("\n\n");*/ + tonccpy(offset, ce9->patches->reset_arm9, 0x40); + /* dbg_printf("reset location : "); + dbg_hexa((u32)offset); + dbg_printf("\n\n"); */ } static bool getSleep(cardengineArm9* ce9, const tNDSHeader* ndsHeader, const module_params_t* moduleParams, bool usesThumb) { diff --git a/retail/cardenginei/arm9/source/misc.c b/retail/cardenginei/arm9/source/misc.c index 95ca7c777..c3e52cc53 100644 --- a/retail/cardenginei/arm9/source/misc.c +++ b/retail/cardenginei/arm9/source/misc.c @@ -38,7 +38,6 @@ #define isSdk5 BIT(5) #define overlaysInRam BIT(6) #define slowSoftReset BIT(10) -#define softResetMb BIT(13) #define cloneboot BIT(14) #define isDlp BIT(15) @@ -185,23 +184,12 @@ void reset(u32 param, u32 tid2) { waitFrames(5); // Wait for DSi screens to stabilize } enterCriticalSection(); - if (!igmReset && (ce9->valueBits & softResetMb)) { - *(u32*)resetParams = 0; - *(u32*)(resetParams+8) = 0x44414F4C; // 'LOAD' - } cacheFlush(); sharedAddr[3] = 0x52534554; while (1); } else #endif { - if (*(u32*)(resetParams+0xC) > 0) { - sharedAddr[1] = ce9->valueBits; - } - if (!igmReset && (ce9->valueBits & softResetMb)) { - *(u32*)resetParams = 0; - *(u32*)(resetParams+8) = 0x44414F4C; // 'LOAD' - } sharedAddr[3] = 0x52534554; } #else @@ -341,9 +329,6 @@ void reset(u32 param, u32 tid2) { #ifndef GSDD if ((ce9->valueBits & isDlp) || *(u32*)(resetParams+0xC) > 0) { - u32 newIrqTable = sharedAddr[2]; - ce9->valueBits = sharedAddr[1]; - ce9->irqTable = (u32*)newIrqTable; sharedAddr[4] = 0; initialized = false; } diff --git a/retail/common/include/cardengine_header_arm9.h b/retail/common/include/cardengine_header_arm9.h index 0e1c7db90..971fd649e 100644 --- a/retail/common/include/cardengine_header_arm9.h +++ b/retail/common/include/cardengine_header_arm9.h @@ -98,7 +98,6 @@ typedef struct cardengineArm9 { 10: slowSoftReset 11: dsiBios 12: asyncCardRead - 13: softResetMb 14: cloneboot 15: isDlp 16: bypassExceptionHandler