mirror of
https://github.com/wiiu-env/WUMSLoader.git
synced 2024-12-26 08:01:52 +01:00
[relocator] Re-use the header from the SetupPayload and move some files into /utils
This commit is contained in:
parent
7fe051d2cf
commit
ebf09003d3
@ -31,7 +31,7 @@ export OBJCOPY := $(PREFIX)objcopy
|
|||||||
TARGET := relocator
|
TARGET := relocator
|
||||||
BUILD := build
|
BUILD := build
|
||||||
BUILD_DBG := $(TARGET)_dbg
|
BUILD_DBG := $(TARGET)_dbg
|
||||||
SOURCES := src
|
SOURCES := src src/utils
|
||||||
|
|
||||||
DATA := data
|
DATA := data
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "logger.h"
|
#include "utils/logger.h"
|
||||||
#include "../../source/common/module_defines.h"
|
#include "../../source/common/module_defines.h"
|
||||||
|
|
||||||
dyn_linking_function_t * DynamicLinkingHelper::getOrAddFunctionEntryByName(dyn_linking_relocation_data_t * data, const char* functionName) {
|
dyn_linking_function_t * DynamicLinkingHelper::getOrAddFunctionEntryByName(dyn_linking_relocation_data_t * data, const char* functionName) {
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "../../source/common/dynamic_linking_defines.h"
|
#include "../../source/common/dynamic_linking_defines.h"
|
||||||
#include "logger.h"
|
#include "utils/logger.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "RelocationData.h"
|
#include "../../source/module/RelocationData.h"
|
||||||
|
|
||||||
class DynamicLinkingHelper {
|
class DynamicLinkingHelper {
|
||||||
public:
|
public:
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <coreinit/cache.h>
|
#include <coreinit/cache.h>
|
||||||
|
|
||||||
#include "logger.h"
|
#include "utils/logger.h"
|
||||||
#include "ElfUtils.h"
|
#include "ElfUtils.h"
|
||||||
|
|
||||||
// See https://github.com/decaf-emu/decaf-emu/blob/43366a34e7b55ab9d19b2444aeb0ccd46ac77dea/src/libdecaf/src/cafe/loader/cafe_loader_reloc.cpp#L144
|
// See https://github.com/decaf-emu/decaf-emu/blob/43366a34e7b55ab9d19b2444aeb0ccd46ac77dea/src/libdecaf/src/cafe/loader/cafe_loader_reloc.cpp#L144
|
||||||
|
@ -1,69 +0,0 @@
|
|||||||
/****************************************************************************
|
|
||||||
* Copyright (C) 2018 Maschell
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include "logger.h"
|
|
||||||
|
|
||||||
class ImportRPLInformation {
|
|
||||||
|
|
||||||
public:
|
|
||||||
ImportRPLInformation(std::string name, bool isData = false) {
|
|
||||||
this->name = name;
|
|
||||||
this->_isData = isData;
|
|
||||||
}
|
|
||||||
|
|
||||||
~ImportRPLInformation() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
static ImportRPLInformation * createImportRPLInformation(std::string rawSectionName) {
|
|
||||||
std::string fimport = ".fimport_";
|
|
||||||
std::string dimport = ".dimport_";
|
|
||||||
|
|
||||||
bool data = false;
|
|
||||||
|
|
||||||
std::string rplName = "";
|
|
||||||
|
|
||||||
if(rawSectionName.size() < fimport.size()) {
|
|
||||||
return NULL;
|
|
||||||
} else if (std::equal(fimport.begin(), fimport.end(), rawSectionName.begin())) {
|
|
||||||
rplName = rawSectionName.substr(fimport.size());
|
|
||||||
} else if (std::equal(dimport.begin(), dimport.end(), rawSectionName.begin())) {
|
|
||||||
rplName = rawSectionName.substr(dimport.size());
|
|
||||||
data = true;
|
|
||||||
} else {
|
|
||||||
DEBUG_FUNCTION_LINE("invalid section name\n");
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
DEBUG_FUNCTION_LINE("Adding %s of section index %02X. isData: %d\n",rplName.c_str(),data);
|
|
||||||
return new ImportRPLInformation(rplName, data);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool isData() {
|
|
||||||
return _isData;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
std::string name;
|
|
||||||
bool _isData = false;
|
|
||||||
};
|
|
@ -1,86 +0,0 @@
|
|||||||
/****************************************************************************
|
|
||||||
* Copyright (C) 2018 Maschell
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
#include "RelocationData.h"
|
|
||||||
|
|
||||||
class ModuleData {
|
|
||||||
public:
|
|
||||||
ModuleData() {
|
|
||||||
}
|
|
||||||
|
|
||||||
~ModuleData() {
|
|
||||||
for (auto const& reloc : relocation_data_list) {
|
|
||||||
if(reloc != NULL) {
|
|
||||||
delete reloc;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void setBSSLocation(uint32_t addr, uint32_t size) {
|
|
||||||
this->bssAddr = addr;
|
|
||||||
this->bssSize = size;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setSBSSLocation(uint32_t addr, uint32_t size) {
|
|
||||||
this->sbssAddr = addr;
|
|
||||||
this->sbssSize = size;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setEntrypoint(uint32_t addr) {
|
|
||||||
this->entrypoint = addr;
|
|
||||||
}
|
|
||||||
|
|
||||||
void addRelocationData(RelocationData * relocation_data) {
|
|
||||||
relocation_data_list.push_back(relocation_data);
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<RelocationData *> getRelocationDataList() {
|
|
||||||
return relocation_data_list;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t getBSSAddr() {
|
|
||||||
return bssAddr;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t getBSSSize() {
|
|
||||||
return bssSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t getSBSSAddr() {
|
|
||||||
return sbssAddr;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t getSBSSSize() {
|
|
||||||
return sbssSize;
|
|
||||||
}
|
|
||||||
|
|
||||||
uint32_t getEntrypoint() {
|
|
||||||
return entrypoint;
|
|
||||||
}
|
|
||||||
private:
|
|
||||||
std::vector<RelocationData *> relocation_data_list;
|
|
||||||
|
|
||||||
uint32_t bssAddr = 0;
|
|
||||||
uint32_t bssSize = 0;
|
|
||||||
uint32_t sbssAddr = 0;
|
|
||||||
uint32_t sbssSize = 0;
|
|
||||||
uint32_t entrypoint = 0;
|
|
||||||
};
|
|
@ -1,8 +1,8 @@
|
|||||||
#include "ModuleDataPersistence.h"
|
#include "ModuleDataPersistence.h"
|
||||||
#include "DynamicLinkingHelper.h"
|
#include "DynamicLinkingHelper.h"
|
||||||
#include "../../source/common/module_defines.h"
|
#include "../../source/common/module_defines.h"
|
||||||
#include "ModuleData.h"
|
#include "../../source/module/ModuleData.h"
|
||||||
#include "RelocationData.h"
|
#include "../../source/module/RelocationData.h"
|
||||||
#include <coreinit/cache.h>
|
#include <coreinit/cache.h>
|
||||||
|
|
||||||
bool ModuleDataPersistence::saveModuleData(module_information_t * moduleInformation, ModuleData * module) {
|
bool ModuleDataPersistence::saveModuleData(module_information_t * moduleInformation, ModuleData * module) {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "../../source/common/module_defines.h"
|
#include "../../source/common/module_defines.h"
|
||||||
#include "ModuleData.h"
|
#include "../../source/module/ModuleData.h"
|
||||||
|
|
||||||
class ModuleDataPersistence {
|
class ModuleDataPersistence {
|
||||||
public:
|
public:
|
||||||
|
@ -1,71 +0,0 @@
|
|||||||
/****************************************************************************
|
|
||||||
* Copyright (C) 2018 Maschell
|
|
||||||
*
|
|
||||||
* This program is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
#include "ImportRPLInformation.h"
|
|
||||||
|
|
||||||
class RelocationData {
|
|
||||||
|
|
||||||
public:
|
|
||||||
RelocationData(char type, size_t offset, int32_t addend, void *destination, std::string name, ImportRPLInformation * rplInfo) {
|
|
||||||
this->type = type;
|
|
||||||
this->offset = offset;
|
|
||||||
this->addend = addend;
|
|
||||||
this->destination = destination;
|
|
||||||
this->name = name;
|
|
||||||
this->rplInfo = rplInfo;
|
|
||||||
}
|
|
||||||
|
|
||||||
~RelocationData() {
|
|
||||||
if(rplInfo != NULL) {
|
|
||||||
delete rplInfo;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
char getType() {
|
|
||||||
return type;
|
|
||||||
}
|
|
||||||
|
|
||||||
size_t getOffset() {
|
|
||||||
return offset;
|
|
||||||
}
|
|
||||||
|
|
||||||
int32_t getAddend() {
|
|
||||||
return addend;
|
|
||||||
}
|
|
||||||
|
|
||||||
void * getDestination() {
|
|
||||||
return destination;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
ImportRPLInformation * getImportRPLInformation() {
|
|
||||||
return rplInfo;
|
|
||||||
}
|
|
||||||
private:
|
|
||||||
char type;
|
|
||||||
size_t offset;
|
|
||||||
int32_t addend;
|
|
||||||
void *destination;
|
|
||||||
std::string name;
|
|
||||||
ImportRPLInformation * rplInfo;
|
|
||||||
};
|
|
@ -7,18 +7,17 @@
|
|||||||
#include <nsysnet/socket.h>
|
#include <nsysnet/socket.h>
|
||||||
#include "../../source/common/dynamic_linking_defines.h"
|
#include "../../source/common/dynamic_linking_defines.h"
|
||||||
#include "../../source/common/module_defines.h"
|
#include "../../source/common/module_defines.h"
|
||||||
#include "RelocationData.h"
|
#include "../../source/module/RelocationData.h"
|
||||||
#include "ModuleData.h"
|
#include "../../source/module/ModuleData.h"
|
||||||
#include "ModuleDataPersistence.h"
|
#include "ModuleDataPersistence.h"
|
||||||
#include "ElfUtils.h"
|
#include "ElfUtils.h"
|
||||||
#include "../../source/common/relocation_defines.h"
|
#include "../../source/common/relocation_defines.h"
|
||||||
|
|
||||||
#include "logger.h"
|
#include "utils/logger.h"
|
||||||
#include "dynamic.h"
|
#include "utils/dynamic.h"
|
||||||
|
|
||||||
#define gModuleData ((module_information_t *) (0x00880000))
|
#define gModuleData ((module_information_t *) (0x00880000))
|
||||||
|
|
||||||
|
|
||||||
extern "C" void doStart(int argc, char **argv);
|
extern "C" void doStart(int argc, char **argv);
|
||||||
// We need to wrap it to make sure the main function is called AFTER our code.
|
// We need to wrap it to make sure the main function is called AFTER our code.
|
||||||
// The compiler tries to optimize this otherwise and calling the main function earlier
|
// The compiler tries to optimize this otherwise and calling the main function earlier
|
||||||
@ -51,7 +50,6 @@ bool doRelocation(std::vector<RelocationData *> &relocData, relocation_trampolin
|
|||||||
DEBUG_FUNCTION_LINE("Relocation failed\n");
|
DEBUG_FUNCTION_LINE("Relocation failed\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DCFlushRange(tramp_data, tramp_length * sizeof(relocation_trampolin_entry_t));
|
DCFlushRange(tramp_data, tramp_length * sizeof(relocation_trampolin_entry_t));
|
||||||
|
Loading…
Reference in New Issue
Block a user