Move the gModuleData struct into a different location in memory, move defines into a new globals.h which both projects are using

This commit is contained in:
Maschell 2020-06-25 19:01:25 +02:00
parent 3853f3876e
commit 1ed1b96bdb
4 changed files with 22 additions and 16 deletions

View File

@ -102,8 +102,8 @@ bool ResolveRelocations(const std::vector<ModuleData> &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;
}

View File

@ -1,8 +1,7 @@
#pragma once
#include <cstdint>
#include "../../source/globals.h"
extern uint32_t MemoryMappingEffectiveToPhysicalPTR;
extern uint32_t MemoryMappingPhysicalToEffectivePTR;
#define gModuleData ((module_information_t *) (0x00880000))
extern uint32_t MemoryMappingPhysicalToEffectivePTR;

11
source/globals.h Normal file
View File

@ -0,0 +1,11 @@
#pragma once
#include <cstdint>
#include <wums/defines/module_defines.h>
#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))

View File

@ -1,7 +1,6 @@
#include <stdio.h>
#include <string.h>
#include <elfio/elfio.hpp>
#include <proc_ui/procui.h>
#include <sysapp/launch.h>
@ -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<RelocationData> &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> 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> 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> moduleData = ModuleDataFactory::load(modules.GetFilepath(i), &destination_address, 0x01000000 - textSectionStart, gModuleData->trampolines, DYN_LINK_TRAMPOLIN_LIST_LENGTH);
std::optional<ModuleData> 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));