From 1ed1b96bdb6b56fc444785b1a504ea55dcf7a0c0 Mon Sep 17 00:00:00 2001 From: Maschell Date: Thu, 25 Jun 2020 19:01:25 +0200 Subject: [PATCH] Move the gModuleData struct into a different location in memory, move defines into a new globals.h which both projects are using --- relocator/src/entry.cpp | 4 ++-- relocator/src/globals.h | 5 ++--- source/globals.h | 11 +++++++++++ source/main.cpp | 18 +++++++----------- 4 files changed, 22 insertions(+), 16 deletions(-) create mode 100644 source/globals.h diff --git a/relocator/src/entry.cpp b/relocator/src/entry.cpp index d3f9a72..2f109d1 100644 --- a/relocator/src/entry.cpp +++ b/relocator/src/entry.cpp @@ -102,8 +102,8 @@ bool ResolveRelocations(const std::vector &loadedModules) { // memset((void *) curModule.getSBSSAddr(), 0, curModule.getSBSSSize()); } } - DCFlushRange((void *) 0x00800000, 0x00800000); - ICInvalidateRange((void *) 0x00800000, 0x00800000); + DCFlushRange((void *) MEMORY_REGION_START, MEMORY_REGION_SIZE); + ICInvalidateRange((void *) MEMORY_REGION_START, MEMORY_REGION_SIZE); return wasSuccessful; } diff --git a/relocator/src/globals.h b/relocator/src/globals.h index 2d95f62..5e97379 100644 --- a/relocator/src/globals.h +++ b/relocator/src/globals.h @@ -1,8 +1,7 @@ #pragma once #include +#include "../../source/globals.h" extern uint32_t MemoryMappingEffectiveToPhysicalPTR; -extern uint32_t MemoryMappingPhysicalToEffectivePTR; - -#define gModuleData ((module_information_t *) (0x00880000)) \ No newline at end of file +extern uint32_t MemoryMappingPhysicalToEffectivePTR; \ No newline at end of file diff --git a/source/globals.h b/source/globals.h new file mode 100644 index 0000000..ff30368 --- /dev/null +++ b/source/globals.h @@ -0,0 +1,11 @@ +#pragma once +#include +#include + +#define MEMORY_REGION_START 0x00800000 +#define MEMORY_REGION_SIZE 0x00800000 + +#define MEMORY_REGION_USABLE_START MEMORY_REGION_START +#define MEMORY_REGION_USABLE_END 0x00FFF000 + +#define gModuleData ((module_information_t *) (MEMORY_REGION_USABLE_START)) \ No newline at end of file diff --git a/source/main.cpp b/source/main.cpp index 8fd1b2d..e5272fd 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -1,7 +1,6 @@ #include #include - #include #include #include @@ -21,6 +20,7 @@ #include "module/ModuleDataFactory.h" #include "ElfUtils.h" #include "kernel.h" +#include "globals.h" bool CheckRunning() { @@ -42,10 +42,6 @@ bool CheckRunning() { return true; } - -#define gModuleData ((module_information_t *) (0x00880000)) -static_assert(sizeof(module_information_t) <= 0x80000); - extern "C" uint32_t textStart(); bool doRelocation(std::vector &relocData, relocation_trampolin_entry_t *tramp_data, uint32_t tramp_length) { @@ -85,8 +81,8 @@ int main(int argc, char **argv) { for (int i = 0; i < setupModules.GetFilecount(); i++) { memset((void *) gModuleData, 0, sizeof(module_information_t)); DEBUG_FUNCTION_LINE("Trying to run %s", setupModules.GetFilepath(i)); - uint32_t destination_address = 0x00900000; - std::optional moduleData = ModuleDataFactory::load(setupModules.GetFilepath(i), &destination_address, 0x01000000 - textSectionStart, gModuleData->trampolines, DYN_LINK_TRAMPOLIN_LIST_LENGTH); + uint32_t destination_address = ((uint32_t) gModuleData + (sizeof(module_information_t) + 0x0000FFFF)) & 0xFFFF0000; + std::optional moduleData = ModuleDataFactory::load(setupModules.GetFilepath(i), &destination_address, MEMORY_REGION_USABLE_END - textSectionStart, gModuleData->trampolines, DYN_LINK_TRAMPOLIN_LIST_LENGTH); if (!moduleData) { DEBUG_FUNCTION_LINE("Failed to load %s", setupModules.GetFilepath(i)); continue; @@ -104,8 +100,8 @@ int main(int argc, char **argv) { DEBUG_FUNCTION_LINE("memset .sbss %08X (%d)", moduleData->getSBSSAddr(), moduleData->getSBSSSize()); memset((void *) moduleData->getSBSSAddr(), 0, moduleData->getSBSSSize()); } - DCFlushRange((void *) 0x00800000, 0x00800000); - ICInvalidateRange((void *) 0x00800000, 0x00800000); + DCFlushRange((void *) MEMORY_REGION_START, MEMORY_REGION_SIZE); + ICInvalidateRange((void *) MEMORY_REGION_START, MEMORY_REGION_SIZE); DEBUG_FUNCTION_LINE("Calling %08X", moduleData->getEntrypoint()); ((int (*)(int, char **)) moduleData->getEntrypoint())(argc, argv); DEBUG_FUNCTION_LINE("Back from module"); @@ -116,12 +112,12 @@ int main(int argc, char **argv) { DirList modules("fs:/vol/external01/wiiu/modules", ".wms", DirList::Files, 1); modules.SortList(); - uint32_t destination_address = 0x00900000; + uint32_t destination_address = ((uint32_t) gModuleData + (sizeof(module_information_t) + 0x0000FFFF)) & 0xFFFF0000; for (int i = 0; i < modules.GetFilecount(); i++) { DEBUG_FUNCTION_LINE("Loading module %s", modules.GetFilepath(i)); - std::optional moduleData = ModuleDataFactory::load(modules.GetFilepath(i), &destination_address, 0x01000000 - textSectionStart, gModuleData->trampolines, DYN_LINK_TRAMPOLIN_LIST_LENGTH); + std::optional moduleData = ModuleDataFactory::load(modules.GetFilepath(i), &destination_address, MEMORY_REGION_USABLE_END - textSectionStart, gModuleData->trampolines, DYN_LINK_TRAMPOLIN_LIST_LENGTH); if (moduleData) { DEBUG_FUNCTION_LINE("Successfully loaded %s", modules.GetFilepath(i));