From a2190e4497a1d9c4b719859f112a76fea1480479 Mon Sep 17 00:00:00 2001 From: "crediar@rypp.net" Date: Sun, 21 Oct 2012 21:36:35 +0000 Subject: [PATCH] -updated to version 2.4- *Fixed NMM for Mario Kart Double Dash. Saving ghost data works now as well *Fixed a bug that would sometimes break cheating/debugging unless both were enabled *Moved the VIConfigure patch to the ARM side which should fix a number of broken titles *Changed the HDD time out to read a random sector *Optimised the EHCI reset code *Optimised the CARD code git-svn-id: svn://localhost/Users/andi/Downloads/code/DML@31 be6c1b03-d731-4111-a574-e37d80d43941 --- Card.c | 163 ++++++++++++++++++----------------------------- Patches.c | 42 +++++++++--- Patches.h | 2 - asm/CARDCreate.S | 14 ++-- asm/CARDRead.S | 18 +++--- asm/CARDWrite.S | 16 +++-- diosmioslite.ld | 81 +++++++++++++++++++++++ global.h | 2 +- vsprintf.c | 27 -------- 9 files changed, 201 insertions(+), 164 deletions(-) create mode 100644 diosmioslite.ld diff --git a/Card.c b/Card.c index 89f9721..0614d72 100644 --- a/Card.c +++ b/Card.c @@ -71,7 +71,31 @@ void CardInit( void ) write32( 0x2FA0, 0 ); } +void LFNfy( char *str ) +{ + u32 len = strlen(str); + u32 i; + for( i=0; i < len; ++i ) + { + switch( str[i] ) + { + case '\\': + case '/': + case '*': + case '|': + case '?': + case '<': + case '>': + case '\"': + case ':': + str[i] = ' '; + break; + default: + break; + } + } +} s32 CardFindFreeEntry( void ) { CARDStat CStat; @@ -127,6 +151,7 @@ s32 CardOpenFile( char *Filename, CARDFileInfo *CFInfo ) return -4; } + LFNfy( Filename ); fres = f_open( &savefile, Filename, FA_READ|FA_WRITE|FA_OPEN_EXISTING ) ; switch( fres ) { @@ -177,6 +202,7 @@ s32 CardFastOpenFile( u32 FileNo, CARDFileInfo *CFInfo ) return 0; } + LFNfy( CStat.fileName ); fres = f_open( &savefile, CStat.fileName, FA_READ|FA_WRITE|FA_OPEN_EXISTING ) ; switch( fres ) { @@ -332,7 +358,11 @@ void CardCreateFile( char *Filename, u32 Size, CARDFileInfo *CFInfo ) if( Slot < 0 ) return; - fres = f_open( &savefile, Filename, FA_READ|FA_WRITE|FA_CREATE_NEW ); + char FName[32]; + memcpy( FName, Filename, 32 ); + + LFNfy( FName ); + fres = f_open( &savefile, FName, FA_READ|FA_WRITE|FA_CREATE_NEW ); switch( fres ) { case FR_EXIST: @@ -406,7 +436,8 @@ void CardReadFile( u32 FileNo, u8 *Buffer, u32 Length, u32 Offset ) f_lseek( &CardStat, sizeof(CARDStat) * FileNo ); f_read( &CardStat, &CStat, sizeof(CARDStat), &read ); - + + LFNfy( CStat.fileName ); if( f_open( &savefile, CStat.fileName, FA_OPEN_EXISTING | FA_READ ) == FR_OK ) { f_lseek( &savefile, Offset ); @@ -423,7 +454,8 @@ void CardWriteFile( u32 FileNo, u8 *Buffer, u32 Length, u32 Offset ) f_lseek( &CardStat, sizeof(CARDStat) * FileNo ); f_read( &CardStat, &CStat, sizeof(CARDStat), &read ); - + + LFNfy( CStat.fileName ); switch( f_open( &savefile, CStat.fileName, FA_OPEN_EXISTING | FA_WRITE ) ) { case FR_OK: @@ -523,6 +555,7 @@ void CardUpdateStats( CARDStat *CStat ) void CARDUpdateRegisters( void ) { u32 read,i; + u32 CARDOK=0; if( read32(CARD_CONTROL) != 0xdeadbeef ) { @@ -590,19 +623,10 @@ void CARDUpdateRegisters( void ) #ifdef CARDDEBUG dbgprintf("MC:CARDOpen( \"%s\", 0x%08x )", FileName, FInfo ); -#endif - +#endif CardOpenFile( (char*)FileName, (CARDFileInfo*)FInfo ); - while( read32(CARD_CONTROL) & 1 ) - clear32( CARD_CONTROL, 1 ); - - while( (read32(CARD_SSTATUS) & 0x10) != 0x10 ) - set32( CARD_SSTATUS, 0x10 ); - -#ifdef CARDDEBUG - dbgprintf(":%d\n", read32( CARD_SRETURN ) ); -#endif + CARDOK = 1; } break; case 0xC1: { @@ -616,13 +640,7 @@ void CARDUpdateRegisters( void ) else write32( CARD_SRETURN, 0 ); - while( read32(CARD_SCONTROL) & 1 ) - clear32( CARD_SCONTROL, 1 ); - - set32( CARD_SSTATUS, 0x10 ); -#ifdef CARDDEBUG - dbgprintf(":%d\n", read32(CARD_SRETURN) ); -#endif + CARDOK = 1; } break; case 0xC2: { @@ -635,25 +653,18 @@ void CARDUpdateRegisters( void ) #ifdef CARDDEBUG dbgprintf("MC:CARDCreate( \"%s\", 0x%04x, 0x%08x )", FileName, Size, FInfo ); #endif - CardCreateFile( (char*)FileName, Size, (CARDFileInfo*)FInfo ); write32( 0x2FA0, read32(0x2FA0) + CARD_XFER_CREATE ); - - while( read32(CARD_SCONTROL) & 1 ) - clear32( CARD_SCONTROL, 1 ); - set32( CARD_SSTATUS, 0x10 ); -#ifdef CARDDEBUG - dbgprintf(":%d\n", read32( CARD_SRETURN ) ); -#endif + CARDOK = 1; } break; case 0xC3: { CARDStat CS; #ifdef CARDDEBUG - // dbgprintf("MC:CARDGetState( %d, 0x%08x, ", read32(CARD_SCMD_1), P2C(read32(CARD_SCMD_2)) ); + dbgprintf("MC:CARDGetState( %d, 0x%08x, ", read32(CARD_SCMD_1), P2C(read32(CARD_SCMD_2)) ); #endif if( read32(CARD_SCMD_1) >= CARD_MAX_FILES ) @@ -673,11 +684,6 @@ void CARDUpdateRegisters( void ) #endif write32( CARD_SRETURN, CARD_NO_FILE ); } else { - -#ifdef CARDDEBUG - // dbgprintf("\"%s\")", CS.fileName ); - dbgprintf("MC:CARDGetState( %d, 0x%08x, \"%s\"):0", read32(CARD_SCMD_1), P2C(read32(CARD_SCMD_2)), CS.fileName ); -#endif CardUpdateStats( &CS ); @@ -711,14 +717,7 @@ void CARDUpdateRegisters( void ) write32( CARD_SRETURN, CARD_SUCCESS ); } - - while( read32(CARD_SCONTROL) & 1 ) - clear32( CARD_SCONTROL, 1 ); - - set32( CARD_SSTATUS, 0x10 ); -#ifdef CARDDEBUG - // dbgprintf("MC:CARDGetState( %d, 0x%08x, ):%d\n", read32(CARD_SCMD_1), P2C(read32(CARD_SCMD_2)), read32( CARD_SRETURN) ); -#endif + CARDOK = 1; } break; case 0xC4: { @@ -727,7 +726,6 @@ void CARDUpdateRegisters( void ) #ifdef CARDDEBUG dbgprintf("MC:CARDSetState( %d, 0x%08x )", read32(CARD_SCMD_1), P2C(read32(CARD_SCMD_2)) ); #endif - if( read32(CARD_SCMD_1) >= CARD_MAX_FILES ) { EXIControl(1); @@ -792,13 +790,7 @@ void CARDUpdateRegisters( void ) write32( CARD_SRETURN, CARD_SUCCESS ); } - while( read32(CARD_SCONTROL) & 1 ) - clear32( CARD_SCONTROL, 1 ); - - set32( CARD_SSTATUS, 0x10 ); -#ifdef CARDDEBUG - dbgprintf(":1\n"); -#endif + CARDOK = 1; } break; /* CARDFastOpen( u32 FileNO, CARDFileInfo *CFInfo ) */ case 0xC5: @@ -808,20 +800,10 @@ void CARDUpdateRegisters( void ) #ifdef CARDDEBUG dbgprintf("MC:CARDFastOpen( %d, 0x%08X )", FileNo, FInfo ); -#endif - +#endif CardFastOpenFile( FileNo, (CARDFileInfo*)FInfo ); - - while( read32(CARD_CONTROL) & 1 ) - clear32( CARD_CONTROL, 1 ); - while( (read32(CARD_SSTATUS) & 0x10) != 0x10 ) - set32( CARD_SSTATUS, 0x10 ); - -#ifdef CARDDEBUG - dbgprintf(":%d\n", read32( CARD_SRETURN ) ); -#endif - + CARDOK = 1; } break; case 0xC6: { @@ -835,14 +817,8 @@ void CARDUpdateRegisters( void ) CardDeleteFile( (char*)FileName ); write32( 0x2FA0, read32(0x2FA0) + CARD_XFER_DELETE ); - - while( read32(CARD_SCONTROL) & 1 ) - clear32( CARD_SCONTROL, 1 ); - set32( CARD_SSTATUS, 0x10 ); -#ifdef CARDDEBUG - dbgprintf(":%d\n", read32( CARD_SRETURN ) ); -#endif + CARDOK = 1; } break; case 0xC8: { @@ -854,7 +830,6 @@ void CARDUpdateRegisters( void ) #ifdef CARDDEBUG dbgprintf("MC:CARDWrite( %d, 0x%08x, 0x%04x, 0x%04x )", FileNo, Buffer, Offset, Length ); #endif - if( FileNo >= CARD_MAX_FILES ) { EXIControl(1); @@ -868,14 +843,7 @@ void CARDUpdateRegisters( void ) write32( CARD_SRETURN, 0 ); - while( read32(CARD_SCONTROL) & 1 ) - clear32( CARD_SCONTROL, 1 ); - - set32( CARD_SSTATUS, 0x10 ); - -#ifdef CARDDEBUG - dbgprintf(":%u\n", read32(CARD_SRETURN) ); -#endif + CARDOK = 1; } break; case 0xC9: { @@ -887,7 +855,6 @@ void CARDUpdateRegisters( void ) #ifdef CARDDEBUG dbgprintf("MC:CARDRead( %d, 0x%08x, 0x%04x, 0x%04x )", FileNo, Buffer, Offset, Length ); #endif - if( FileNo >= CARD_MAX_FILES ) { EXIControl(1); @@ -900,15 +867,8 @@ void CARDUpdateRegisters( void ) write32( 0x2FA0, read32(0x2FA0) + Length ); write32( CARD_SRETURN, 0 ); - - while( read32(CARD_SCONTROL) & 1 ) - clear32( CARD_SCONTROL, 1 ); - - set32( CARD_SSTATUS, 0x10 ); -#ifdef CARDDEBUG - dbgprintf(":%u\n", read32(CARD_SRETURN) ); -#endif + CARDOK = 1; } break; case 0xCA: { @@ -919,14 +879,8 @@ void CARDUpdateRegisters( void ) CardFastDelete( FileNo ); write32( 0x2FA0, read32(0x2FA0) + CARD_XFER_DELETE ); - - while( read32(CARD_SCONTROL) & 1 ) - clear32( CARD_SCONTROL, 1 ); - set32( CARD_SSTATUS, 0x10 ); -#ifdef CARDDEBUG - dbgprintf(":%d\n", read32( CARD_SRETURN ) ); -#endif + CARDOK = 1; } break; case 0xCB: { @@ -941,16 +895,21 @@ void CARDUpdateRegisters( void ) #endif CardRename( NameSrc, NameDst ); - while( read32(CARD_SCONTROL) & 1 ) - clear32( CARD_SCONTROL, 1 ); - - set32( CARD_SSTATUS, 0x10 ); -#ifdef CARDDEBUG - dbgprintf(":%d\n", read32( CARD_SRETURN ) ); -#endif + CARDOK = 1; } break; } + if(CARDOK) + { +#ifdef CARDDEBUG + dbgprintf(":%d\n", read32( CARD_SRETURN ) ); +#endif + while( read32(CARD_SCONTROL) & 1 ) + clear32( CARD_SCONTROL, 1 ); + + set32( CARD_SSTATUS, 0x10 ); + } + if( ConfigGetConfig(DML_CFG_ACTIVITY_LED) ) clear32( HW_GPIO_OUT, 1<<5 ); } diff --git a/Patches.c b/Patches.c index d323f0d..7c824ab 100644 --- a/Patches.c +++ b/Patches.c @@ -452,11 +452,16 @@ void DoCardPatches( char *ptr, u32 size, u32 SectionOffset ) if( (read32( offset + 0x04 ) & 0x0000F000 ) == 0x00008000 ) // lis { write32( offset, read32( offset + 0x0C ) & 0xFBE00000 ); + offset += 4; + + if( CPatterns[j].Patch == CARDCheckEX ) + { + write32( offset, 0x38800000 ); // lis r4,0 + offset += 4; + } //Forge a branch to the async function - offset += 4; - u32 newval = ((u32)ptr + i) - offset; newval&= 0x03FFFFFC; newval|= 0x48000000; @@ -478,11 +483,15 @@ void DoCardPatches( char *ptr, u32 size, u32 SectionOffset ) } } - for( j=0; j < sizeof(CPatterns)/sizeof(FuncPattern); ++j ) - { - if( CPatterns[j].Found == 0 ) - dbgprintf("Pattern %s not found!\n", CPatterns[j].Name ); - } + + //if( CardLowestOff ) + //{ + // for( j=0; j < sizeof(CPatterns)/sizeof(FuncPattern); ++j ) + // { + // if( CPatterns[j].Found == 0 ) + // dbgprintf("Pattern %s not found!\n", CPatterns[j].Name ); + // } + //} return; @@ -739,12 +748,25 @@ void DoPatches( char *ptr, u32 size, u32 SectionOffset ) } } - if( ConfigGetConfig(DML_CFG_CHEATS) ) + if( (PatchCount & 64) == 0 ) { - if( PatchCount == 63 ) + if( read32( (u32)ptr + i + 0 ) == 0x3C608000 ) + { + if( ((read32( (u32)ptr + i + 4 ) & 0xFC1FFFFF ) == 0x800300CC) && ((read32( (u32)ptr + i + 8 ) >> 24) == 0x54 ) ) + { + dbgprintf( "Patch:[VIConfgiure] 0x%08X\n", (u32)(ptr+i) ); + write32( *(vu32*)(ptr+i+4), 0x5400F0BE | ((read32( (u32)ptr + i + 4 ) & 0x3E00000) >> 5 ) ); + PatchCount |= 64; + } + } + } + + if( ConfigGetConfig(DML_CFG_CHEATS) || ConfigGetConfig( DML_CFG_DEBUGGER ) ) + { + if( PatchCount == 127 ) break; } else { - if( PatchCount == 47 ) + if( PatchCount == 111 ) break; } } diff --git a/Patches.h b/Patches.h index d6cafa5..0795bac 100644 --- a/Patches.h +++ b/Patches.h @@ -66,8 +66,6 @@ typedef struct _gx_rmodeobj { #define GXNtsc480IntDf 3 #define GXNtsc480Int 4 - -void PatchGCIPL( void ); void DoPatches( char *ptr, u32 size, u32 SectionOffset ); void DoCardPatches( char *ptr, u32 size, u32 SectionOffset ); void DoPatchesLoader( char *ptr, u32 size ); diff --git a/asm/CARDCreate.S b/asm/CARDCreate.S index e0dedab..8ab2004 100644 --- a/asm/CARDCreate.S +++ b/asm/CARDCreate.S @@ -18,8 +18,9 @@ CARDCreate: DoCode: mflr %r0 - stw %r0, 4(%sp) - stwu %sp, -0x10(%sp) + stw %r0, 4(%sp) + stwu %sp, -0x28(%sp) + stmw %r27, 0x14(%sp) #send cmd to DM @@ -80,9 +81,10 @@ skip_cb: lis %r7, 0xC000 lwz %r3, 0x2F94(%r7) mr %r4, %r3 - - lwz %r0, 0x14(%sp) - addi %sp, %sp, 0x10 - mtlr %r0 + + lmw %r27, 0x14(%sp) + lwz %r0, 0x2C(%sp) + addi %sp, %sp, 0x28 + mtlr %r0 blr diff --git a/asm/CARDRead.S b/asm/CARDRead.S index 7c50e61..bd29e42 100644 --- a/asm/CARDRead.S +++ b/asm/CARDRead.S @@ -7,12 +7,12 @@ # r6 offset # r7 cb -CardWrite: +CardRead: mflr %r0 stw %r0, 4(%sp) - stwu %sp, -0x20(%sp) - stw %r31, 0x1C(%sp) + stwu %sp, -0x28(%sp) + stmw %r27, 0x14(%sp) #Update fileinfo stw %r5, 0x0C(%r3) @@ -66,17 +66,17 @@ wait_loop: cmpwi %r12, 0 beq skip_cb - mtctr %r12 + mtlr %r12 li %r3, 0 li %r4, 0 - bctrl + blrl skip_cb: li %r3, 0 mr %r4, %r3 - lwz %r0, 0x24(%sp) - lwz %r31, 0x1C(%sp) - addi %sp, %sp, 0x20 - mtlr %r0 + lmw %r27, 0x14(%sp) + lwz %r0, 0x2C(%sp) + addi %sp, %sp, 0x28 + mtlr %r0 blr diff --git a/asm/CARDWrite.S b/asm/CARDWrite.S index e4f2529..7baf1be 100644 --- a/asm/CARDWrite.S +++ b/asm/CARDWrite.S @@ -11,7 +11,8 @@ CardWrite: mflr %r0 stw %r0, 4(%sp) - stwu %sp, -0x10(%sp) + stwu %sp, -0x28(%sp) + stmw %r27, 0x14(%sp) #Update fileinfo stw %r5, 0x0C(%r3) @@ -65,16 +66,17 @@ wait_loop: cmpwi %r12, 0 beq skip_cb - mtctr %r12 + mtlr %r12 li %r3, 0 li %r4, 0 - bctrl + blrl skip_cb: li %r3, 0 mr %r4, %r3 - - lwz %r0, 0x14(%sp) - addi %sp, %sp, 0x10 - mtlr %r0 + + lmw %r27, 0x14(%sp) + lwz %r0, 0x2C(%sp) + addi %sp, %sp, 0x28 + mtlr %r0 blr diff --git a/diosmioslite.ld b/diosmioslite.ld new file mode 100644 index 0000000..32026a6 --- /dev/null +++ b/diosmioslite.ld @@ -0,0 +1,81 @@ +OUTPUT_FORMAT("elf32-bigarm") +OUTPUT_ARCH(arm) +ENTRY(_start) + +__stack_size = 0x4000; + +MEMORY +{ + sram : ORIGIN = 0xFFFF0000, LENGTH = 0x10000 + stack : ORIGIN = 0xFFFE0000, LENGTH = 0x4000 +} + +PHDRS +{ + sram PT_LOAD AT ( 0xFFFF0000 ) ; + stack PT_LOAD AT ( 0xFFFE0000 ) ; +} + +SECTIONS +{ + .init : + { + *(.init) + . = ALIGN(4); + } >sram :sram + + .text : + { + *(.text*) + *(.text.*) + *(.gnu.warning) + *(.gnu.linkonce.t*) + *(.glue_7) + *(.glue_7t) + . = ALIGN(4); + } >sram :sram + + .rodata : + { + *(.rodata) + *all.rodata*(*) + *(.roda) + *(.rodata.*) + *(.gnu.linkonce.r*) + . = ALIGN(4); + } >sram :sram + + .data : + { + *(.data) + *(.data.*) + *(.gnu.linkonce.d*) + . = ALIGN(4); + } >sram :sram + + .bss : + { + __bss_start = . ; + *(.dynbss) + *(.gnu.linkonce.b*) + *(.bss*) + *(COMMON) + . = ALIGN(4); + __bss_end = . ; + } >sram :sram + + + .stack : + { + __stack_end = .; + . = . +__stack_size; + . = ALIGN(4); + __stack_addr = .; + } >stack :stack + + /DISCARD/ : + { + *(.ARM.exidx*) + *(.ARM.extab*) + } +} diff --git a/global.h b/global.h index ae7a110..a6c8237 100644 --- a/global.h +++ b/global.h @@ -15,7 +15,7 @@ #define PADHOOK 1 #define CONFIG_VERSION 0x00000002 -#define DML_VERSION 0x00020003 +#define DML_VERSION 0x00020004 #define DI_SUCCESS 1 #define DI_ERROR 2 diff --git a/vsprintf.c b/vsprintf.c index 91830d4..117aaa0 100644 --- a/vsprintf.c +++ b/vsprintf.c @@ -362,35 +362,8 @@ void GeckoSendBuffer( char *buffer ) return; } -extern FIL Log; - -//static char buffer[128] ALIGNED(32); int dbgprintf( const char *fmt, ...) { - //va_list args; - // - //va_start(args, fmt); - //vsprintf(buffer, fmt, args); - //va_end(args); - - //// Only write debug output to usb gecko when possible - //if( read32( 0x0D800070 ) & 1 ) - //{ - // GeckoSendBuffer( buffer ); - //} else { - // u32 read; - // u32 fres = f_open( &Log, "/dm.log", FA_READ|FA_WRITE|FA_OPEN_ALWAYS ); - // if( fres != FR_OK ) - // { - // write32( 0x0D800070, 1 ); - // dbgprintf("f_open():%d\n", fres ); - // } - - // f_lseek( &Log, Log.fsize ); - // f_write( &Log, buffer, strlen(buffer), &read ); - // f_close( &Log ); - //} - return 1; }