diff --git a/src/common/module_defines.h b/src/common/module_defines.h index f14e5df..4a301b9 100644 --- a/src/common/module_defines.h +++ b/src/common/module_defines.h @@ -26,29 +26,8 @@ extern "C" { #endif -#define MAXIMUM_MODULE_PATH_NAME_LENGTH 256 -#define MAXIMUM_MODULE_NAME_LENGTH 51 - -#define DYN_LINK_RELOCATION_LIST_LENGTH 500 - -struct module_information_single_t { - char path[MAXIMUM_MODULE_PATH_NAME_LENGTH] = ""; // Path where the module is stored - dyn_linking_relocation_entry_t linking_entries[DYN_LINK_RELOCATION_LIST_LENGTH]; - int32_t priority; // Priority of this module - uint32_t bssAddr; - uint32_t bssSize; - uint32_t sbssAddr; - uint32_t sbssSize; - uint32_t entrypoint; -}; - -#define MAXIMUM_MODULES 8 - struct module_information_t { - int32_t number_used_modules = 0; // Number of used function. Maximum is MAXIMUM_MODULES - dyn_linking_relocation_data_t linking_data; relocation_trampolin_entry_t trampolines[DYN_LINK_TRAMPOLIN_LIST_LENGTH]; - module_information_single_t module_data[MAXIMUM_MODULES]; }; #ifdef __cplusplus diff --git a/src/main.cpp b/src/main.cpp index 27b222d..0da1781 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -18,12 +18,9 @@ #include "utils/utils.h" #include "utils/sd_fat_devoptab.h" -#define gModuleData ((module_information_t *) (0x00880000)) -static_assert(sizeof(module_information_t) <= 0x80000); bool doRelocation(std::vector &relocData, relocation_trampolin_entry_t * tramp_data, uint32_t tramp_length); - bool CheckRunning() { switch(ProcUIProcessMessages(true)) { @@ -58,8 +55,15 @@ extern "C" int _start(int argc, char **argv) { uint32_t ApplicationMemoryEnd; asm volatile("lis %0, __CODE_END@h; ori %0, %0, __CODE_END@l" : "=r" (ApplicationMemoryEnd)); - ApplicationMemoryEnd = (ApplicationMemoryEnd + 0x10000) & 0xFFFF0000; ModuleData * moduleData = ModuleDataFactory::load("sd:/wiiu/payload.rpx", ApplicationMemoryEnd, 0x01000000 - ApplicationMemoryEnd, gModuleData->trampolines, DYN_LINK_TRAMPOLIN_LIST_LENGTH); + + ApplicationMemoryEnd = (ApplicationMemoryEnd + 0x100) & 0xFFFFFF00; + + module_information_t * gModuleData = (module_information_t *) ApplicationMemoryEnd; + + uint32_t moduleDataStartAddress = ((uint32_t) gModuleData + sizeof(module_information_t)); + moduleDataStartAddress = (moduleDataStartAddress + 0x10000) & 0xFFFF0000; + if(moduleData != NULL) { DEBUG_FUNCTION_LINE("Loaded module data\n"); std::vector relocData = moduleData->getRelocationDataList(); diff --git a/src/module/ModuleDataPersistence.cpp b/src/module/ModuleDataPersistence.cpp deleted file mode 100644 index 4048a49..0000000 --- a/src/module/ModuleDataPersistence.cpp +++ /dev/null @@ -1,106 +0,0 @@ -#include - -#include "ModuleDataPersistence.h" -#include "DynamicLinkingHelper.h" -#include "common/module_defines.h" -#include "ModuleData.h" -#include "RelocationData.h" - -bool ModuleDataPersistence::saveModuleData(module_information_t * moduleInformation, ModuleData * module) { - int32_t module_count = moduleInformation->number_used_modules; - - if(module_count >= MAXIMUM_MODULES) { - return false; - } - // Copy data to global struct. - module_information_single_t * module_data = &(moduleInformation->module_data[module_count]); - - // Relocation - std::vector relocationData = module->getRelocationDataList(); - for (auto const& reloc : relocationData) { - if(!DynamicLinkingHelper::addReloationEntry(&(moduleInformation->linking_data), module_data->linking_entries, DYN_LINK_RELOCATION_LIST_LENGTH, reloc)) { - return false; - } - } - - module_data->bssAddr = module->getBSSAddr(); - module_data->bssSize = module->getBSSSize(); - module_data->sbssAddr = module->getSBSSAddr(); - module_data->sbssSize = module->getSBSSSize(); - - module_data->entrypoint = module->getEntrypoint(); - - moduleInformation->number_used_modules++; - - DCFlushRange((void*)moduleInformation,sizeof(module_information_t)); - ICInvalidateRange((void*)moduleInformation,sizeof(module_information_t)); - - return true; -} - -std::vector ModuleDataPersistence::loadModuleData(module_information_t * moduleInformation) { - std::vector result; - if(moduleInformation == NULL) { - DEBUG_FUNCTION_LINE("moduleInformation == NULL\n"); - return result; - } - DCFlushRange((void*)moduleInformation,sizeof(module_information_t)); - ICInvalidateRange((void*)moduleInformation,sizeof(module_information_t)); - - int32_t module_count = moduleInformation->number_used_modules; - if(module_count > MAXIMUM_MODULES) { - DEBUG_FUNCTION_LINE("moduleInformation->module_count was bigger then allowed. %d > %d. Limiting to %d\n",module_count, MAXIMUM_MODULES, MAXIMUM_MODULES); - module_count = MAXIMUM_MODULES; - } - for(int32_t i = 0; i < module_count; i++) { - // Copy data from struct. - module_information_single_t * module_data = &(moduleInformation->module_data[i]); - ModuleData * moduleData = new ModuleData(); - if(moduleData == NULL){ - DEBUG_FUNCTION_LINE("Failed to allocate data for ModuleData object\n"); - continue; - } - moduleData->setBSSLocation(module_data->bssAddr, module_data->bssSize); - moduleData->setSBSSLocation(module_data->sbssAddr, module_data->sbssSize); - moduleData->setEntrypoint(module_data->entrypoint); - - for(uint32_t j = 0; j < DYN_LINK_RELOCATION_LIST_LENGTH; j++) { - dyn_linking_relocation_entry_t * linking_entry = &(module_data->linking_entries[j]); - if(linking_entry->destination == NULL){ - break; - } - dyn_linking_import_t* importEntry = linking_entry->importEntry; - if(importEntry == NULL){ - DEBUG_FUNCTION_LINE("importEntry was NULL, skipping relocation entry\n"); - continue; - } - if(importEntry->importName == NULL){ - DEBUG_FUNCTION_LINE("importEntry->importName was NULL, skipping relocation entry\n"); - continue; - } - dyn_linking_function_t* functionEntry = linking_entry->functionEntry; - - if(functionEntry == NULL){ - DEBUG_FUNCTION_LINE("functionEntry was NULL, skipping relocation entry\n"); - continue; - } - if(functionEntry->functionName == NULL){ - DEBUG_FUNCTION_LINE("functionEntry->functionName was NULL, skipping relocation entry\n"); - continue; - } - ImportRPLInformation * rplInfo = new ImportRPLInformation(importEntry->importName, importEntry->isData); - if(rplInfo == NULL){ - DEBUG_FUNCTION_LINE("Failed to allocate ImportRPLInformation object. Skipping relocation entry.\n"); - continue; - } - RelocationData * reloc = new RelocationData(linking_entry->type, linking_entry->offset, linking_entry->addend, linking_entry->destination, functionEntry->functionName, rplInfo); - if(reloc == NULL){ - DEBUG_FUNCTION_LINE("Failed to allocate RelocationData object. Skipping relocation entry.\n"); - continue; - } - moduleData->addRelocationData(reloc); - } - result.push_back(moduleData); - } - return result; -} diff --git a/src/module/ModuleDataPersistence.h b/src/module/ModuleDataPersistence.h deleted file mode 100644 index 2c35ff6..0000000 --- a/src/module/ModuleDataPersistence.h +++ /dev/null @@ -1,10 +0,0 @@ -#pragma once - -#include "common/module_defines.h" -#include "ModuleData.h" - -class ModuleDataPersistence { -public: - static bool saveModuleData(module_information_t * moduleInformation, ModuleData * module); - static std::vector loadModuleData(module_information_t * moduleInformation); -};