Permalink
Browse files

*Adjust memory ranges and protect areas used for appldr and wdvd unen…

…crypted read from libogc or mem2alloc.cpp use.

*Raise amount of memory set aside for mem2alloc.cpp to a max of 52, still limited by arena2 size.

*NOTE: seems SYS_GetArena1Lo always returns the SAME address? SYS_GetArena1Size is always the same at least. I might be wrong but if this is so we are going to need to manage mem1 on our own also.

git-svn-id: https://wiiflow-advanced.googlecode.com/svn/trunk@394 43c7226f-5572-e80b-0314-b0280708705f
  • Loading branch information...
1 parent dffd871 commit 0bf1f849b1358ce642c012e13ec1c729cc191fa4 miigotu@hotmail.com committed Jul 27, 2011
Showing with 17 additions and 26 deletions.
  1. +6 −19 source/loader/apploader.c
  2. +1 −1 source/loader/disc.c
  3. +3 −0 source/loader/disc.h
  4. +3 −2 source/main.cpp
  5. +4 −4 source/memory/mem2alloc.cpp
View
25 source/loader/apploader.c
@@ -19,9 +19,6 @@ typedef void (*app_init)(void (*report)(const char *fmt, ...));
typedef void *(*app_final)();
typedef void (*app_entry)(void (**init)(void (*report)(const char *fmt, ...)), int (**main)(), void *(**final)());
-/* Apploader pointers */
-static u8 *appldr = (u8 *)0x81200000;
-
/* Constants */
#define APPLDR_OFFSET 0x2440
@@ -41,40 +38,33 @@ s32 Apploader_Run(entry_point *entry, u8 vidMode, GXRModeObj *vmode, bool vipatc
void *dst = NULL;
int len = 0;
int offset = 0;
- app_entry appldr_entry;
app_init appldr_init;
app_main appldr_main;
app_final appldr_final;
-
- u32 appldr_len;
- s32 ret;
- SYS_SetArena1Hi((void *)0x816FFFF0);
+ SYS_SetArena1Hi(APPLOADER_END);
/* Read apploader header */
- ret = WDVD_Read(buffer, 0x20, APPLDR_OFFSET);
+ s32 ret = WDVD_Read(buffer, 0x20, APPLDR_OFFSET);
if (ret < 0) return ret;
/* Calculate apploader length */
- appldr_len = buffer[5] + buffer[6];
+ u32 appldr_len = buffer[5] + buffer[6];
/* Read apploader code */
// Either you limit memory usage or you don't touch the heap after that, because this is writing at 0x1200000
- ret = WDVD_Read(appldr, appldr_len, APPLDR_OFFSET + 0x20);
+ ret = WDVD_Read(APPLOADER_START, appldr_len, APPLDR_OFFSET + 0x20);
if (ret < 0) return ret;
- DCFlushRange(appldr, appldr_len);
+ DCFlushRange(APPLOADER_START, appldr_len);
/* Set apploader entry function */
- appldr_entry = (app_entry)buffer[4];
+ app_entry appldr_entry = (app_entry)buffer[4];
/* Call apploader entry */
appldr_entry(&appldr_init, &appldr_main, &appldr_final);
/* Initialize apploader */
appldr_init(__noprint);
-
- u32 dolStart = 0x90000000;
- u32 dolEnd = 0;
bool hookpatched = false;
@@ -84,9 +74,6 @@ s32 Apploader_Run(entry_point *entry, u8 vidMode, GXRModeObj *vmode, bool vipatc
WDVD_Read(dst, len, (u64)(offset << 2));
if(maindolpatches(dst, len, vidMode, vmode, vipatch, countryString, patchVidModes))
hookpatched = true;
-
- if ((u32) dst < dolStart) dolStart = (u32) dst;
- if ((u32) dst + len > dolEnd) dolEnd = (u32) dst + len;
}
if (hooktype != 0 && !hookpatched)
View
2 source/loader/disc.c
@@ -33,7 +33,7 @@
u32 appentrypoint;
/* Disc pointers */
-static u32 *buffer = (u32 *)0x93000000;
+static u32 *buffer = (u32 *)0x93200000;
static u8 *diskid = (u8 *)0x80000000;
GXRModeObj *disc_vmode = NULL;
View
3 source/loader/disc.h
@@ -5,6 +5,9 @@
#define ALT_DOL_DISC 2
#define ALT_DOL_PLUS 3
+#define APPLOADER_START (void *)0x81200000
+#define APPLOADER_END (void *)0x816FFFF0
+
/* Disc header structure */
struct discHdr
{
View
5 source/main.cpp
@@ -35,7 +35,7 @@ int old_main(int argc, char **argv)
geckoinit = InitGecko();
__exception_setreload(5);
- SYS_SetArena1Hi((void *)0x81200000); // See loader/apploader.c
+ SYS_SetArena1Hi(APPLOADER_START); // Make sure libogc doesnt use appldr area
CVideo vid;
char *gameid = NULL;
@@ -70,7 +70,8 @@ int old_main(int argc, char **argv)
mainIOSRev = IOS_GetRevision();
iosOK = iosOK && mainIOSRev >= mainIOSminRev;
- MEM2_init(48);
+ SYS_SetArena1Hi(APPLOADER_START); // Make sure libogc doesnt use appldr area after ios reload.
+ MEM2_init(52);
// Init video
vid.init();
View
8 source/memory/mem2alloc.cpp
@@ -10,10 +10,10 @@
void CMEM2Alloc::init(unsigned int size)
{
m_baseAddress = (SBlock *)(((u32)SYS_GetArena2Lo() + 31) & ~31);
- m_endAddress = (SBlock *)((char *)m_baseAddress + std::min(size * 0x100000, SYS_GetArena2Size() & ~31));
- if (m_endAddress > (SBlock *)0x93000000) //rest is reserved for usb/usb2/network and other stuff... (0xE0000 bytes)
- m_endAddress = (SBlock *)0x93000000; // was 0x93300000 in code from GX // Loader/disc.c:36 and 215 etc
- SYS_SetArena2Lo(m_endAddress);
+ m_endAddress = (SBlock *)((char *)m_baseAddress + std::min(size * 0x100000, (SYS_GetArena2Size() - 63) & ~31)); // Round down - an extra 32 for wdvd_unencrypted read
+ if (m_endAddress > (SBlock *)0x93200000) //rest is reserved for usb/usb2/network and other stuff... (0xE0000 bytes)
+ m_endAddress = (SBlock *)0x93200000; // was 0x93300000 in code from GX // Loader/disc.c:36 and 215 etc
+ SYS_SetArena2Lo(m_endAddress + 32); // Protect an extra 32 for wdvd unencrpted read
LWP_MutexInit(&m_mutex, 0);
}

0 comments on commit 0bf1f84

Please sign in to comment.