diff --git a/bootloader/source/card_patcher.c b/bootloader/source/card_patcher.c index 4a38663cb..59da91125 100644 --- a/bootloader/source/card_patcher.c +++ b/bootloader/source/card_patcher.c @@ -57,6 +57,13 @@ u32 cardReadCachedEndSignature3[4] = {0xE5950024,0xE3500000,0x13A00001,0x03A00 u32 cardReadCachedStartSignature4[2] = {0xE92D4038,0xE59F407C}; u32 cardReadCachedEndSignature4[4] = {0xE5940024,0xE3500000,0x13A00001,0x03A00000}; +u32 cardReadDmaStartSignature[1] = {0xE92D4FF8}; +u32 cardReadDmaStartSignatureAlt[1] = {0xE92D47F0}; +u32 cardReadDmaEndSignature[3] = {0x01FF8000,0x000001FF,0x027FFE60}; + + + + // irqEnable u32 irqEnableStartSignature1[4] = {0xE59FC028,0xE1DC30B0,0xE3A01000,0xE1CC10B0}; u32 irqEnableStartSignature4[4] = {0xE92D4010, 0xE1A04000, 0xEBFFFFF6, 0xE59FC020}; @@ -278,7 +285,6 @@ u32 patchCardNdsArm9 (const tNDSHeader* ndsHeader, u32* cardEngineLocation, modu dbg_printf("Card read cached end not found\n"); return 0; } - debug[1] = cardReadCachedEndOffset; u32 cardReadCachedOffset = getOffset((u32*)cardReadCachedEndOffset, -0xFF, (u32*)cardReadCachedStartSignature, 2, -1); @@ -289,6 +295,30 @@ u32 patchCardNdsArm9 (const tNDSHeader* ndsHeader, u32* cardEngineLocation, modu dbg_printf("Card read cached :\t"); dbg_hexa(cardReadCachedOffset); dbg_printf("\n"); + + u32 cardReadDmaOffset = 0; + u32 cardReadDmaEndOffset = + getOffset((u32*)ndsHeader->arm9destination, 0x00300000,//ndsHeader->arm9binarySize, + (u32*)cardReadDmaEndSignature, 3, 1); + if (!cardReadDmaEndOffset) { + dbg_printf("Card read dma end not found\n"); + } else { + dbg_printf("Card read dma end :\t"); + dbg_hexa(cardReadDmaEndOffset); + dbg_printf("\n"); + cardReadDmaOffset = + getOffset((u32*)cardReadDmaEndOffset, -0x200, + (u32*)cardReadDmaStartSignature, 1, -1); + if (!cardReadDmaOffset) { + dbg_printf("Card read dma start not found\n"); + cardReadDmaOffset = + getOffset((u32*)cardReadDmaEndOffset, -0x200, + (u32*)cardReadDmaStartSignatureAlt, 1, -1); + if (!cardReadDmaOffset) { + dbg_printf("Card read dma start alt not found\n"); + } + } + } // Find the card id u32 cardIdStartOffset = 0; @@ -311,7 +341,6 @@ u32 patchCardNdsArm9 (const tNDSHeader* ndsHeader, u32* cardEngineLocation, modu } } - // Find the mpu init u32* mpuDataOffset = 0; u32 mpuStartOffset = @@ -349,7 +378,7 @@ u32 patchCardNdsArm9 (const tNDSHeader* ndsHeader, u32* cardEngineLocation, modu mpuDataOffset[mpuAccessOffset] = mpuNewInstrAccess; } if(mpuNewDataAccess) { - mpuDataOffset[mpuAccessOffset] = mpuNewDataAccess; + mpuDataOffset[mpuAccessOffset+1] = mpuNewDataAccess; } } } @@ -364,6 +393,9 @@ u32 patchCardNdsArm9 (const tNDSHeader* ndsHeader, u32* cardEngineLocation, modu *mpuCacheOffset = 0xE3A00046; } */ + dbg_printf("patchMpuSize :\t"); + dbg_hexa(patchMpuSize); + dbg_printf("\n"); // patch out all further mpu reconfiguration while(mpuStartOffset && patchMpuSize) { @@ -372,7 +404,7 @@ u32 patchCardNdsArm9 (const tNDSHeader* ndsHeader, u32* cardEngineLocation, modu patchSize = patchMpuSize; } mpuStartOffset = getOffset(mpuStartOffset+4, patchSize, - (u32*)mpuInitRegion1Signature, 1, 1); + (u32*)mpuInitRegionSignature, 1, 1); if(mpuStartOffset) { dbg_printf("Mpu init :\t"); dbg_hexa(mpuStartOffset); @@ -432,6 +464,10 @@ u32 patchCardNdsArm9 (const tNDSHeader* ndsHeader, u32* cardEngineLocation, modu u32* cardPullOutPatch = patches[6]; + u32* cardIdPatch = patches[3]; + + u32* cardDmaPatch = patches[4]; + debug[5] = patches; u32* card_struct = ((u32*)cardReadEndOffset) - 1; @@ -463,8 +499,16 @@ u32 patchCardNdsArm9 (const tNDSHeader* ndsHeader, u32* cardEngineLocation, modu copyLoop ((u32*)(cardPullOutOffset), cardPullOutPatch, 0x5C); if (cardIdStartOffset) { - copyLoop ((u32*)cardIdStartOffset, cardPullOutPatch, 0x4); + copyLoop ((u32*)cardIdStartOffset, cardIdPatch, 0x8); } + + if (cardReadDmaOffset) { + dbg_printf("Card read dma :\t"); + dbg_hexa(cardReadDmaOffset); + dbg_printf("\n"); + + copyLoop ((u32*)cardReadDmaOffset, cardDmaPatch, 0x8); + } dbg_printf("ERR_NONE"); return 0; diff --git a/cardengine_arm9/source/cardEngine.c b/cardengine_arm9/source/cardEngine.c index 1426e2094..5f0bb9faa 100644 --- a/cardengine_arm9/source/cardEngine.c +++ b/cardengine_arm9/source/cardEngine.c @@ -34,13 +34,6 @@ vu32* volatile sharedAddr = (vu32*)0x027FFB08; extern volatile int (*readCachedRef)(u32*); // this pointer is not at the end of the table but at the handler pointer corresponding to the current irq static u32 currentSector = 0; - -u32 cardId (void) { - //nocashMessage("\narm9 cardId\n"); - - return 1; -} - void cardRead (u32* cacheStruct) { //nocashMessage("\narm9 cardRead\n"); diff --git a/cardengine_arm9/source/cardEngine.h b/cardengine_arm9/source/cardEngine.h index 23515bb2d..87cf22044 100644 --- a/cardengine_arm9/source/cardEngine.h +++ b/cardengine_arm9/source/cardEngine.h @@ -26,7 +26,6 @@ extern "C" { #define is_aligned(POINTER, BYTE_COUNT) \ (((uintptr_t)(const void *)(POINTER)) % (BYTE_COUNT) == 0) -u32 cardId (void); void cardRead (u32* cacheStruct); #ifdef __cplusplus diff --git a/cardengine_arm9/source/card_engine_header.s b/cardengine_arm9/source/card_engine_header.s index cedc4519d..773d640d7 100644 --- a/cardengine_arm9/source/card_engine_header.s +++ b/cardengine_arm9/source/card_engine_header.s @@ -39,51 +39,6 @@ cacheStruct: card_engine_start: -vblankHandler: -@ Hook the return address, then go back to the original function - stmdb sp!, {lr} - adr lr, code_handler_start_vblank - ldr r0, intr_vblank_orig_return - bx r0 - -fifoHandler: -@ Hook the return address, then go back to the original function - stmdb sp!, {lr} - adr lr, code_handler_start_fifo - ldr r0, intr_fifo_orig_return - bx r0 - -code_handler_start_vblank: - push {r0-r12} - bl _blx_r3_stub @ jump to myIrqHandler - - @ exit after return - b exit - -code_handler_start_fifo: - push {r0-r12} - bl _blx_r3_stub @ jump to myIrqHandler - - - @ exit after return - b exit - -@--------------------------------------------------------------------------------- -_blx_r3_stub: -@--------------------------------------------------------------------------------- - bx r3 - -@--------------------------------------------------------------------------------- - -@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ - -exit: - pop {r0-r12} - pop {lr} - bx lr - -.pool - .global fastCopy32 .type fastCopy32 STT_FUNC @ r0 : src, r1 : dst, r2 : len @@ -108,8 +63,8 @@ patches: .word card_read_arm9 .word card_pull_out_arm9 .word 0x0 -.word vblankHandler -.word fifoHandler +.word card_id_arm9 +.word card_dma_arm9 .word cardStructArm9 .word card_pull .word cacheFlushRef @@ -157,18 +112,15 @@ cacheRef: @--------------------------------------------------------------------------------- card_id_arm9: @--------------------------------------------------------------------------------- - stmfd sp!, {r4-r11,lr} + mov r0, #1 + bx lr +@--------------------------------------------------------------------------------- - ldr r3, =cardId - push {lr} - bl _blx_r3_stub_card_id - pop {lr} - - ldmfd sp!, {r4-r11,lr} - bx lr -_blx_r3_stub_card_id: - bx r3 -.pool +@--------------------------------------------------------------------------------- +card_dma_arm9: +@--------------------------------------------------------------------------------- + mov r0, #0 + bx lr @--------------------------------------------------------------------------------- @---------------------------------------------------------------------------------