mirror of
https://github.com/wiiu-env/CustomRPXLoader.git
synced 2024-11-12 21:45:06 +01:00
- Use the(de)-init functions from libwut to handle logging, sd access and memory.
- Adapt logging to WHBLogPrintf
This commit is contained in:
parent
8c1c3e91e3
commit
a941429f88
3
.gitignore
vendored
3
.gitignore
vendored
@ -5,3 +5,6 @@
|
||||
*.bin
|
||||
*.cscope_file_list
|
||||
*.layout
|
||||
cmake-build-debug/
|
||||
.idea/
|
||||
CMakeLists.txt
|
||||
|
7
Makefile
7
Makefile
@ -47,7 +47,7 @@ CFLAGS := -std=gnu11 -mcpu=750 -meabi -mhard-float -ffast-math \
|
||||
CXXFLAGS := -std=gnu++11 -mcpu=750 -meabi -mhard-float -ffast-math \
|
||||
-O2 -Wall -Wextra -Wno-unused-parameter -Wno-strict-aliasing $(INCLUDE)
|
||||
ASFLAGS := -mregnames
|
||||
LDFLAGS := -nostartfiles -Wl,--gc-sections
|
||||
LDFLAGS := -nostartfiles -Wl,--gc-sections,--allow-multiple-definition
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
Q := @
|
||||
@ -55,7 +55,7 @@ MAKEFLAGS += --no-print-directory
|
||||
#---------------------------------------------------------------------------------
|
||||
# any extra libraries we wish to link with the project
|
||||
#---------------------------------------------------------------------------------
|
||||
LIBS :=
|
||||
LIBS := -lwut
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# list of directories containing libraries, this must be the top level containing
|
||||
@ -106,8 +106,7 @@ export OFILES := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) \
|
||||
#---------------------------------------------------------------------------------
|
||||
export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
|
||||
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
|
||||
-I$(CURDIR)/$(BUILD) -I$(LIBOGC_INC) \
|
||||
-I$(PORTLIBS)/include -I$(PORTLIBS)/include/freetype2
|
||||
-I$(CURDIR)/$(BUILD) -I$(PORTLIBS)/include
|
||||
|
||||
#---------------------------------------------------------------------------------
|
||||
# build a list of library paths
|
||||
|
@ -39,7 +39,7 @@ bool ElfUtils::elfLinkOne(char type, size_t offset, int32_t addend, uint32_t des
|
||||
*((uint16_t *)(target)) = static_cast<uint16_t>((value + 0x8000) >> 16);
|
||||
break;
|
||||
case R_PPC_DTPMOD32:
|
||||
DEBUG_FUNCTION_LINE("################IMPLEMENT ME\n");
|
||||
DEBUG_FUNCTION_LINE("################IMPLEMENT ME");
|
||||
//*((int32_t *)(target)) = tlsModuleIndex;
|
||||
break;
|
||||
case R_PPC_DTPREL32:
|
||||
@ -57,18 +57,18 @@ bool ElfUtils::elfLinkOne(char type, size_t offset, int32_t addend, uint32_t des
|
||||
case R_PPC_REL14: {
|
||||
auto distance = static_cast<int32_t>(value) - static_cast<int32_t>(target);
|
||||
if (distance > 0x7FFC || distance < -0x7FFC) {
|
||||
DEBUG_FUNCTION_LINE("***14-bit relative branch cannot hit target.\n");
|
||||
DEBUG_FUNCTION_LINE("***14-bit relative branch cannot hit target.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (distance & 3) {
|
||||
DEBUG_FUNCTION_LINE("***RELOC ERROR %d: lower 2 bits must be zero before shifting.\n", -470040);
|
||||
DEBUG_FUNCTION_LINE("***RELOC ERROR %d: lower 2 bits must be zero before shifting.", -470040);
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((distance >= 0 && (distance & 0xFFFF8000)) ||
|
||||
(distance < 0 && ((distance & 0xFFFF8000) != 0xFFFF8000))) {
|
||||
DEBUG_FUNCTION_LINE("***RELOC ERROR %d: upper 17 bits before shift must all be the same.\n", -470040);
|
||||
DEBUG_FUNCTION_LINE("***RELOC ERROR %d: upper 17 bits before shift must all be the same.", -470040);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -83,8 +83,8 @@ bool ElfUtils::elfLinkOne(char type, size_t offset, int32_t addend, uint32_t des
|
||||
auto distance = static_cast<int32_t>(value) - static_cast<int32_t>(target);
|
||||
if (distance > 0x1FFFFFC || distance < -0x1FFFFFC) {
|
||||
if(trampolin_data == NULL) {
|
||||
DEBUG_FUNCTION_LINE("***24-bit relative branch cannot hit target. Trampolin isn't provided\n");
|
||||
DEBUG_FUNCTION_LINE("***value %08X - target %08X = distance %08X\n", value, target, distance);
|
||||
DEBUG_FUNCTION_LINE("***24-bit relative branch cannot hit target. Trampolin isn't provided");
|
||||
DEBUG_FUNCTION_LINE("***value %08X - target %08X = distance %08X", value, target, distance);
|
||||
return false;
|
||||
} else {
|
||||
relocation_trampolin_entry_t * freeSlot = NULL;
|
||||
@ -102,13 +102,13 @@ bool ElfUtils::elfLinkOne(char type, size_t offset, int32_t addend, uint32_t des
|
||||
}
|
||||
}
|
||||
if(freeSlot != NULL) {
|
||||
DEBUG_FUNCTION_LINE("***24-bit relative branch cannot hit target. Trampolin data list is full\n");
|
||||
DEBUG_FUNCTION_LINE("***value %08X - target %08X = distance %08X\n", value, target, distance);
|
||||
DEBUG_FUNCTION_LINE("***24-bit relative branch cannot hit target. Trampolin data list is full");
|
||||
DEBUG_FUNCTION_LINE("***value %08X - target %08X = distance %08X", value, target, distance);
|
||||
return false;
|
||||
}
|
||||
if(target - (uint32_t)&(freeSlot->trampolin[0]) > 0x1FFFFFC) {
|
||||
DEBUG_FUNCTION_LINE("**Cannot link 24-bit jump (too far to tramp buffer).\n");
|
||||
DEBUG_FUNCTION_LINE("***value %08X - target %08X = distance %08X\n", value, target, distance);
|
||||
DEBUG_FUNCTION_LINE("**Cannot link 24-bit jump (too far to tramp buffer).");
|
||||
DEBUG_FUNCTION_LINE("***value %08X - target %08X = distance %08X", value, target, distance);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -128,22 +128,22 @@ bool ElfUtils::elfLinkOne(char type, size_t offset, int32_t addend, uint32_t des
|
||||
uint32_t symbolValue = (uint32_t)&(freeSlot->trampolin[0]);
|
||||
value = symbolValue + addend;
|
||||
distance = static_cast<int32_t>(value) - static_cast<int32_t>(target);
|
||||
DEBUG_FUNCTION_LINE("Created tramp\n");
|
||||
DEBUG_FUNCTION_LINE("Created tramp");
|
||||
}
|
||||
}
|
||||
|
||||
if (distance & 3) {
|
||||
DEBUG_FUNCTION_LINE("***RELOC ERROR %d: lower 2 bits must be zero before shifting.\n", -470022);
|
||||
DEBUG_FUNCTION_LINE("***RELOC ERROR %d: lower 2 bits must be zero before shifting.", -470022);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (distance < 0 && (distance & 0xFE000000) != 0xFE000000) {
|
||||
DEBUG_FUNCTION_LINE("***RELOC ERROR %d: upper 7 bits before shift must all be the same (1).\n", -470040);
|
||||
DEBUG_FUNCTION_LINE("***RELOC ERROR %d: upper 7 bits before shift must all be the same (1).", -470040);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (distance >= 0 && (distance & 0xFE000000)) {
|
||||
DEBUG_FUNCTION_LINE("***RELOC ERROR %d: upper 7 bits before shift must all be the same (0).\n", -470040);
|
||||
DEBUG_FUNCTION_LINE("***RELOC ERROR %d: upper 7 bits before shift must all be the same (0).", -470040);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -151,7 +151,7 @@ bool ElfUtils::elfLinkOne(char type, size_t offset, int32_t addend, uint32_t des
|
||||
break;
|
||||
}
|
||||
default:
|
||||
DEBUG_FUNCTION_LINE("***ERROR: Unsupported Relocation_Add Type (%08X):\n", type);
|
||||
DEBUG_FUNCTION_LINE("***ERROR: Unsupported Relocation_Add Type (%08X):", type);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
@ -17,10 +17,9 @@
|
||||
|
||||
#define EXPORT_VAR(type, var) type var __attribute__((section(".data")));
|
||||
|
||||
EXPORT_VAR(uint32_t *, pMEMAllocFromDefaultHeapEx);
|
||||
EXPORT_VAR(uint32_t *, pMEMAllocFromDefaultHeap);
|
||||
EXPORT_VAR(uint32_t *, pMEMFreeToDefaultHeap);
|
||||
|
||||
EXPORT_VAR(uint32_t *, MEMAllocFromDefaultHeap);
|
||||
EXPORT_VAR(uint32_t *, MEMAllocFromDefaultHeapEx);
|
||||
EXPORT_VAR(uint32_t *, MEMFreeToDefaultHeap);
|
||||
|
||||
void InitFunctionPointers(void) {
|
||||
OSDynLoad_Module handle;
|
||||
@ -28,10 +27,17 @@ void InitFunctionPointers(void) {
|
||||
addr_OSDynLoad_FindExport = (void*) 0x0102B828;
|
||||
|
||||
OSDynLoad_Acquire("coreinit.rpl", &handle);
|
||||
OSDynLoad_FindExport(handle, 1, "MEMAllocFromDefaultHeapEx", (void**) &pMEMAllocFromDefaultHeapEx);
|
||||
OSDynLoad_FindExport(handle, 1, "MEMAllocFromDefaultHeap", (void**) &pMEMAllocFromDefaultHeap);
|
||||
OSDynLoad_FindExport(handle, 1, "MEMFreeToDefaultHeap", (void**) &pMEMFreeToDefaultHeap);
|
||||
|
||||
uint32_t** value = 0;
|
||||
OSDynLoad_FindExport(handle, 1, "MEMAllocFromDefaultHeap", (void**) &value);
|
||||
MEMAllocFromDefaultHeap = *value;
|
||||
OSDynLoad_FindExport(handle, 1, "MEMAllocFromDefaultHeapEx", (void**) &value);
|
||||
MEMAllocFromDefaultHeapEx = *value;
|
||||
OSDynLoad_FindExport(handle, 1, "MEMFreeToDefaultHeap", (void**) &value);
|
||||
MEMFreeToDefaultHeap = *value;
|
||||
|
||||
#include "imports.h"
|
||||
|
||||
// override failed __rplwrap_exit find export
|
||||
OSDynLoad_FindExport(handle, 0, "exit", (void**) &addr___rplwrap_exit);
|
||||
}
|
||||
|
@ -283,7 +283,7 @@ class section_impl : public section
|
||||
|
||||
ret = inflate(&s, Z_FINISH);
|
||||
if (ret != Z_OK && ret != Z_STREAM_END){
|
||||
DEBUG_FUNCTION_LINE("NOOOO\n");
|
||||
DEBUG_FUNCTION_LINE("NOOOO");
|
||||
}
|
||||
|
||||
inflateEnd(&s);
|
||||
@ -301,7 +301,7 @@ class section_impl : public section
|
||||
}
|
||||
}else{
|
||||
set_size(0);
|
||||
DEBUG_FUNCTION_LINE("Failed to allocate memory.\n");
|
||||
DEBUG_FUNCTION_LINE("Failed to allocate memory.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -104,6 +104,10 @@ IMPORT(FSRename);
|
||||
IMPORT(FSGetMountSource);
|
||||
IMPORT(FSMount);
|
||||
IMPORT(FSUnmount);
|
||||
IMPORT(FSChangeMode);
|
||||
IMPORT(FSGetPosFile);
|
||||
IMPORT(OSTicksToCalendarTime);
|
||||
IMPORT(__rplwrap_exit);
|
||||
|
||||
IMPORT(IOS_Open);
|
||||
IMPORT(IOS_Close);
|
||||
|
75
src/main.cpp
75
src/main.cpp
@ -11,13 +11,14 @@
|
||||
#include "module/ModuleDataFactory.h"
|
||||
#include "common/module_defines.h"
|
||||
|
||||
#include <whb/log.h>
|
||||
#include <whb/log_udp.h>
|
||||
|
||||
#include "main.h"
|
||||
#include "kernel.h"
|
||||
#include "dynamic.h"
|
||||
#include "utils/logger.h"
|
||||
#include "utils/utils.h"
|
||||
#include "utils/sd_fat_devoptab.h"
|
||||
|
||||
|
||||
bool doRelocation(std::vector<RelocationData *> &relocData, relocation_trampolin_entry_t * tramp_data, uint32_t tramp_length);
|
||||
|
||||
@ -41,66 +42,66 @@ bool CheckRunning() {
|
||||
return true;
|
||||
}
|
||||
|
||||
extern "C" void __init_wut();
|
||||
extern "C" void __fini_wut();
|
||||
|
||||
extern "C" int _start(int argc, char **argv) {
|
||||
doKernelSetup();
|
||||
InitFunctionPointers();
|
||||
doKernelSetup2();
|
||||
|
||||
socket_lib_init();
|
||||
log_init();
|
||||
__init_wut();
|
||||
|
||||
WHBLogUdpInit();
|
||||
|
||||
int res = 0;
|
||||
if((res = mount_sd_fat("sd")) >= 0) {
|
||||
DEBUG_FUNCTION_LINE("Mounted sd card\n");
|
||||
|
||||
uint32_t ApplicationMemoryEnd;
|
||||
uint32_t ApplicationMemoryEnd;
|
||||
|
||||
asm volatile("lis %0, __CODE_END@h; ori %0, %0, __CODE_END@l" : "=r" (ApplicationMemoryEnd));
|
||||
asm volatile("lis %0, __CODE_END@h; ori %0, %0, __CODE_END@l" : "=r" (ApplicationMemoryEnd));
|
||||
|
||||
ApplicationMemoryEnd = (ApplicationMemoryEnd + 0x100) & 0xFFFFFF00;
|
||||
ApplicationMemoryEnd = (ApplicationMemoryEnd + 0x100) & 0xFFFFFF00;
|
||||
|
||||
module_information_t * gModuleData = (module_information_t *) ApplicationMemoryEnd;
|
||||
module_information_t * gModuleData = (module_information_t *) ApplicationMemoryEnd;
|
||||
|
||||
uint32_t moduleDataStartAddress = ((uint32_t) gModuleData + sizeof(module_information_t));
|
||||
moduleDataStartAddress = (moduleDataStartAddress + 0x10000) & 0xFFFF0000;
|
||||
uint32_t moduleDataStartAddress = ((uint32_t) gModuleData + sizeof(module_information_t));
|
||||
moduleDataStartAddress = (moduleDataStartAddress + 0x10000) & 0xFFFF0000;
|
||||
|
||||
ModuleData * moduleData = ModuleDataFactory::load("sd:/wiiu/payload.rpx", 0x00FFF000, 0x00FFF000 - ApplicationMemoryEnd, gModuleData->trampolines, DYN_LINK_TRAMPOLIN_LIST_LENGTH);
|
||||
if(moduleData != NULL) {
|
||||
DEBUG_FUNCTION_LINE("Loaded module data\n");
|
||||
std::vector<RelocationData *> relocData = moduleData->getRelocationDataList();
|
||||
if(!doRelocation(relocData, gModuleData->trampolines,DYN_LINK_TRAMPOLIN_LIST_LENGTH)) {
|
||||
DEBUG_FUNCTION_LINE("relocations failed\n");
|
||||
}
|
||||
if(moduleData->getBSSAddr() != 0) {
|
||||
DEBUG_FUNCTION_LINE("memset .bss %08X (%d)\n", moduleData->getBSSAddr(), moduleData->getBSSSize());
|
||||
memset((void*)moduleData->getBSSAddr(), 0, moduleData->getBSSSize());
|
||||
}
|
||||
if(moduleData->getSBSSAddr() != 0) {
|
||||
DEBUG_FUNCTION_LINE("memset .sbss %08X (%d)\n", moduleData->getSBSSAddr(), moduleData->getSBSSSize());
|
||||
memset((void*)moduleData->getSBSSAddr(), 0, moduleData->getSBSSSize());
|
||||
}
|
||||
DCFlushRange((void*)0x00800000, 0x00800000);
|
||||
ICInvalidateRange((void*)0x00800000, 0x00800000);
|
||||
DEBUG_FUNCTION_LINE("New entrypoint: %08X\n", moduleData->getEntrypoint());
|
||||
((int (*)(int, char **))moduleData->getEntrypoint())(argc, argv);
|
||||
delete moduleData;
|
||||
} else {
|
||||
DEBUG_FUNCTION_LINE("Failed to load module\n");
|
||||
ModuleData * moduleData = ModuleDataFactory::load("fs:/vol/external01/wiiu/payload.rpx", 0x00FFF000, 0x00FFF000 - ApplicationMemoryEnd, gModuleData->trampolines, DYN_LINK_TRAMPOLIN_LIST_LENGTH);
|
||||
if(moduleData != NULL) {
|
||||
DEBUG_FUNCTION_LINE("Loaded module data");
|
||||
std::vector<RelocationData *> relocData = moduleData->getRelocationDataList();
|
||||
if(!doRelocation(relocData, gModuleData->trampolines,DYN_LINK_TRAMPOLIN_LIST_LENGTH)) {
|
||||
DEBUG_FUNCTION_LINE("relocations failed");
|
||||
}
|
||||
if(moduleData->getBSSAddr() != 0) {
|
||||
DEBUG_FUNCTION_LINE("memset .bss %08X (%d)", moduleData->getBSSAddr(), moduleData->getBSSSize());
|
||||
memset((void*)moduleData->getBSSAddr(), 0, moduleData->getBSSSize());
|
||||
}
|
||||
if(moduleData->getSBSSAddr() != 0) {
|
||||
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);
|
||||
DEBUG_FUNCTION_LINE("New entrypoint: %08X", moduleData->getEntrypoint());
|
||||
((int (*)(int, char **))moduleData->getEntrypoint())(argc, argv);
|
||||
delete moduleData;
|
||||
} else {
|
||||
DEBUG_FUNCTION_LINE("Mounted sd card failed %d.\n", res);
|
||||
DEBUG_FUNCTION_LINE("Failed to load module");
|
||||
}
|
||||
|
||||
SYSLaunchMenu();
|
||||
|
||||
ProcUIInit(OSSavesDone_ReadyToRelease);
|
||||
DEBUG_FUNCTION_LINE("In ProcUI loop\n");
|
||||
DEBUG_FUNCTION_LINE("In ProcUI loop");
|
||||
while(CheckRunning()) {
|
||||
// wait.
|
||||
OSSleepTicks(OSMillisecondsToTicks(100));
|
||||
}
|
||||
ProcUIShutdown();
|
||||
|
||||
__fini_wut();
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -119,7 +120,7 @@ bool doRelocation(std::vector<RelocationData *> &relocData, relocation_trampolin
|
||||
return false;
|
||||
}
|
||||
if(!ElfUtils::elfLinkOne(cur->getType(), cur->getOffset(), cur->getAddend(), (uint32_t) cur->getDestination(), functionAddress, tramp_data, tramp_length, RELOC_TYPE_IMPORT)) {
|
||||
DEBUG_FUNCTION_LINE("Relocation failed\n");
|
||||
DEBUG_FUNCTION_LINE("Relocation failed");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ dyn_linking_function_t * DynamicLinkingHelper::getOrAddFunctionEntryByName(dyn_l
|
||||
dyn_linking_function_t * curEntry = &(data->functions[i]);
|
||||
if(strlen(curEntry->functionName) == 0) {
|
||||
if(strlen(functionName) > DYN_LINK_FUNCTION_NAME_LENGTH) {
|
||||
DEBUG_FUNCTION_LINE("Failed to add function name, it's too long.\n");
|
||||
DEBUG_FUNCTION_LINE("Failed to add function name, it's too long.");
|
||||
return NULL;
|
||||
}
|
||||
strncpy(curEntry->functionName,functionName,DYN_LINK_FUNCTION_NAME_LENGTH);
|
||||
@ -50,7 +50,7 @@ dyn_linking_import_t * DynamicLinkingHelper::getOrAddImport(dyn_linking_relocati
|
||||
dyn_linking_import_t * curEntry = &(data->imports[i]);
|
||||
if(strlen(curEntry->importName) == 0) {
|
||||
if(strlen(importName) > DYN_LINK_IMPORT_NAME_LENGTH) {
|
||||
DEBUG_FUNCTION_LINE("Failed to add Import, it's too long.\n");
|
||||
DEBUG_FUNCTION_LINE("Failed to add Import, it's too long.");
|
||||
return NULL;
|
||||
}
|
||||
strncpy(curEntry->importName,importName,DYN_LINK_IMPORT_NAME_LENGTH);
|
||||
@ -72,13 +72,13 @@ bool DynamicLinkingHelper::addReloationEntry(dyn_linking_relocation_data_t * lin
|
||||
bool DynamicLinkingHelper::addReloationEntry(dyn_linking_relocation_data_t * linking_data, dyn_linking_relocation_entry_t * linking_entries, uint32_t linking_entry_length, char type, size_t offset, int32_t addend, void *destination, std::string name, ImportRPLInformation * rplInfo) {
|
||||
dyn_linking_import_t * importInfoGbl = DynamicLinkingHelper::getOrAddImport(linking_data, rplInfo->getName().c_str(),rplInfo->isData());
|
||||
if(importInfoGbl == NULL) {
|
||||
DEBUG_FUNCTION_LINE("Getting import info failed. Probably maximum of %d rpl files to import reached.\n",DYN_LINK_IMPORT_LIST_LENGTH);
|
||||
DEBUG_FUNCTION_LINE("Getting import info failed. Probably maximum of %d rpl files to import reached.",DYN_LINK_IMPORT_LIST_LENGTH);
|
||||
return false;
|
||||
}
|
||||
|
||||
dyn_linking_function_t * functionInfo = DynamicLinkingHelper::getOrAddFunctionEntryByName(linking_data, name.c_str());
|
||||
if(functionInfo == NULL) {
|
||||
DEBUG_FUNCTION_LINE("Getting import info failed. Probably maximum of %d function to be relocated reached.\n",DYN_LINK_FUNCTION_LIST_LENGTH);
|
||||
DEBUG_FUNCTION_LINE("Getting import info failed. Probably maximum of %d function to be relocated reached.",DYN_LINK_FUNCTION_LIST_LENGTH);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -47,7 +47,7 @@ public:
|
||||
rplName = rawSectionName.substr(dimport.size());
|
||||
data = true;
|
||||
} else {
|
||||
DEBUG_FUNCTION_LINE("invalid section name\n");
|
||||
DEBUG_FUNCTION_LINE("invalid section name");
|
||||
return NULL;
|
||||
}
|
||||
return new ImportRPLInformation(rplName, data);
|
||||
|
@ -35,7 +35,7 @@ ModuleData * ModuleDataFactory::load(std::string path, uint32_t destination_addr
|
||||
|
||||
// Load ELF data
|
||||
if (!reader.load(path)) {
|
||||
DEBUG_FUNCTION_LINE("Can't find or process ELF file\n");
|
||||
DEBUG_FUNCTION_LINE("Can't find or process ELF file");
|
||||
delete moduleData;
|
||||
return NULL;
|
||||
}
|
||||
@ -96,7 +96,7 @@ ModuleData * ModuleDataFactory::load(std::string path, uint32_t destination_addr
|
||||
destination -= 0xC0000000;
|
||||
destinations[psec->get_index()] -= 0xC0000000;
|
||||
} else {
|
||||
DEBUG_FUNCTION_LINE("Unhandled case\n");
|
||||
DEBUG_FUNCTION_LINE("Unhandled case");
|
||||
free(destinations);
|
||||
delete moduleData;
|
||||
return NULL;
|
||||
@ -105,20 +105,20 @@ ModuleData * ModuleDataFactory::load(std::string path, uint32_t destination_addr
|
||||
const char* p = reader.sections[i]->get_data();
|
||||
|
||||
if(psec->get_type() == SHT_NOBITS) {
|
||||
DEBUG_FUNCTION_LINE("memset section %s %08X [%08X] to 0 (%d bytes)\n", psec->get_name().c_str(), destination, destination + sectionSize, sectionSize);
|
||||
DEBUG_FUNCTION_LINE("memset section %s %08X [%08X] to 0 (%d bytes)", psec->get_name().c_str(), destination, destination + sectionSize, sectionSize);
|
||||
memset((void*) destination, 0, sectionSize);
|
||||
} else if(psec->get_type() == SHT_PROGBITS) {
|
||||
DEBUG_FUNCTION_LINE("Copy section %s %08X -> %08X [%08X] (%d bytes)\n", psec->get_name().c_str(), p, destination, destination + sectionSize, sectionSize);
|
||||
DEBUG_FUNCTION_LINE("Copy section %s %08X -> %08X [%08X] (%d bytes)", psec->get_name().c_str(), p, destination, destination + sectionSize, sectionSize);
|
||||
memcpy((void*) destination, p, sectionSize);
|
||||
}
|
||||
|
||||
//nextAddress = ROUNDUP(destination + sectionSize,0x100);
|
||||
if(psec->get_name().compare(".bss") == 0) {
|
||||
moduleData->setBSSLocation(destination, sectionSize);
|
||||
DEBUG_FUNCTION_LINE("Saved %s section info. Location: %08X size: %08X\n", psec->get_name().c_str(), destination, sectionSize);
|
||||
DEBUG_FUNCTION_LINE("Saved %s section info. Location: %08X size: %08X", psec->get_name().c_str(), destination, sectionSize);
|
||||
} else if(psec->get_name().compare(".sbss") == 0) {
|
||||
moduleData->setSBSSLocation(destination, sectionSize);
|
||||
DEBUG_FUNCTION_LINE("Saved %s section info. Location: %08X size: %08X\n", psec->get_name().c_str(), destination, sectionSize);
|
||||
DEBUG_FUNCTION_LINE("Saved %s section info. Location: %08X size: %08X", psec->get_name().c_str(), destination, sectionSize);
|
||||
}
|
||||
totalSize += sectionSize;
|
||||
|
||||
@ -130,9 +130,9 @@ ModuleData * ModuleDataFactory::load(std::string path, uint32_t destination_addr
|
||||
for(uint32_t i = 0; i < sec_num; ++i ) {
|
||||
section* psec = reader.sections[i];
|
||||
if ((psec->get_type() == SHT_PROGBITS || psec->get_type() == SHT_NOBITS) && (psec->get_flags() & SHF_ALLOC)) {
|
||||
DEBUG_FUNCTION_LINE("Linking (%d)... %s\n",i,psec->get_name().c_str());
|
||||
DEBUG_FUNCTION_LINE("Linking (%d)... %s",i,psec->get_name().c_str());
|
||||
if (!linkSection(reader, psec->get_index(), (uint32_t) destinations[psec->get_index()], offset_text, offset_data, trampolin_data, trampolin_data_length)) {
|
||||
DEBUG_FUNCTION_LINE("elfLink failed\n");
|
||||
DEBUG_FUNCTION_LINE("elfLink failed");
|
||||
free(destinations);
|
||||
delete moduleData;
|
||||
return NULL;
|
||||
@ -151,7 +151,7 @@ ModuleData * ModuleDataFactory::load(std::string path, uint32_t destination_addr
|
||||
free(destinations);
|
||||
|
||||
moduleData->setEntrypoint(entrypoint);
|
||||
DEBUG_FUNCTION_LINE("Saved entrypoint as %08X\n", entrypoint);
|
||||
DEBUG_FUNCTION_LINE("Saved entrypoint as %08X", entrypoint);
|
||||
|
||||
return moduleData;
|
||||
}
|
||||
@ -173,7 +173,7 @@ std::vector<RelocationData*> ModuleDataFactory::getImportRelocationData(elfio& r
|
||||
for (uint32_t i = 0; i < sec_num; ++i ) {
|
||||
section* psec = reader.sections[i];
|
||||
if(psec->get_type() == SHT_RELA || psec->get_type() == SHT_REL) {
|
||||
DEBUG_FUNCTION_LINE("Found relocation section %s\n",psec->get_name().c_str());
|
||||
DEBUG_FUNCTION_LINE("Found relocation section %s",psec->get_name().c_str());
|
||||
relocation_section_accessor rel(reader, psec);
|
||||
for ( uint32_t j = 0; j < (uint32_t) rel.get_entries_num(); ++j ) {
|
||||
Elf64_Addr offset;
|
||||
@ -184,7 +184,7 @@ std::vector<RelocationData*> ModuleDataFactory::getImportRelocationData(elfio& r
|
||||
Elf_Half sym_section_index;
|
||||
|
||||
if(!rel.get_entry(j, offset, sym_value, sym_name, type, addend, sym_section_index)) {
|
||||
DEBUG_FUNCTION_LINE("Failed to get relocation\n");
|
||||
DEBUG_FUNCTION_LINE("Failed to get relocation");
|
||||
break;
|
||||
}
|
||||
|
||||
@ -194,7 +194,7 @@ std::vector<RelocationData*> ModuleDataFactory::getImportRelocationData(elfio& r
|
||||
}
|
||||
ImportRPLInformation * rplInfo = ImportRPLInformation::createImportRPLInformation(infoMap[sym_section_index]);
|
||||
if(rplInfo == NULL) {
|
||||
DEBUG_FUNCTION_LINE("Failed to create import information\n");
|
||||
DEBUG_FUNCTION_LINE("Failed to create import information");
|
||||
break;
|
||||
}
|
||||
|
||||
@ -215,7 +215,7 @@ bool ModuleDataFactory::linkSection(elfio& reader, uint32_t section_index, uint3
|
||||
for (uint32_t i = 0; i < sec_num; ++i ) {
|
||||
section* psec = reader.sections[i];
|
||||
if(psec->get_info() == section_index) {
|
||||
DEBUG_FUNCTION_LINE("Found relocation section %s\n",psec->get_name().c_str());
|
||||
DEBUG_FUNCTION_LINE("Found relocation section %s",psec->get_name().c_str());
|
||||
relocation_section_accessor rel(reader, psec);
|
||||
for ( uint32_t j = 0; j < (uint32_t) rel.get_entries_num(); ++j ) {
|
||||
Elf64_Addr offset;
|
||||
@ -226,7 +226,7 @@ bool ModuleDataFactory::linkSection(elfio& reader, uint32_t section_index, uint3
|
||||
Elf_Half sym_section_index;
|
||||
|
||||
if(!rel.get_entry(j, offset, sym_value, sym_name, type, addend, sym_section_index)) {
|
||||
DEBUG_FUNCTION_LINE("Failed to get relocation\n");
|
||||
DEBUG_FUNCTION_LINE("Failed to get relocation");
|
||||
break;
|
||||
}
|
||||
|
||||
@ -243,23 +243,23 @@ bool ModuleDataFactory::linkSection(elfio& reader, uint32_t section_index, uint3
|
||||
} else if(adjusted_sym_value == 0x0) {
|
||||
//
|
||||
} else {
|
||||
DEBUG_FUNCTION_LINE("Unhandled case %08X\n",adjusted_sym_value);
|
||||
DEBUG_FUNCTION_LINE("Unhandled case %08X",adjusted_sym_value);
|
||||
return false;
|
||||
}
|
||||
|
||||
if(sym_section_index == SHN_ABS) {
|
||||
//
|
||||
} else if(sym_section_index > SHN_LORESERVE) {
|
||||
DEBUG_FUNCTION_LINE("NOT IMPLEMENTED: %04X\n", sym_section_index);
|
||||
DEBUG_FUNCTION_LINE("NOT IMPLEMENTED: %04X", sym_section_index);
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!ElfUtils::elfLinkOne(type, offset, addend, destination, adjusted_sym_value, trampolin_data, trampolin_data_length, RELOC_TYPE_FIXED)) {
|
||||
DEBUG_FUNCTION_LINE("Link failed\n");
|
||||
DEBUG_FUNCTION_LINE("Link failed");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
DEBUG_FUNCTION_LINE("done\n");
|
||||
DEBUG_FUNCTION_LINE("done");
|
||||
}
|
||||
}
|
||||
return true;
|
||||
|
@ -2,5 +2,5 @@
|
||||
#include "utils/StringTools.h"
|
||||
|
||||
std::string RelocationData::toString(){
|
||||
return StringTools::strfmt("%s destination: %08X offset: %08X type: %02X addend: %d rplName: %s isData: %d \n",name.c_str(), destination, offset, type, addend, rplInfo->getName().c_str(), rplInfo->isData() );
|
||||
return StringTools::strfmt("%s destination: %08X offset: %08X type: %02X addend: %d rplName: %s isData: %d" ,name.c_str(), destination, offset, type, addend, rplInfo->getName().c_str(), rplInfo->isData() );
|
||||
}
|
||||
|
@ -1,60 +0,0 @@
|
||||
#include <malloc.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
#include <coreinit/filesystem.h>
|
||||
#include "utils/logger.h"
|
||||
#include "FSOSUtils.h"
|
||||
|
||||
#define FS_MOUNT_SOURCE_SIZE 0x300
|
||||
#define FS_MAX_MOUNTPATH_SIZE 128
|
||||
#define FS_SOURCETYPE_EXTERNAL 0
|
||||
|
||||
int32_t FSOSUtils::MountFS(FSClient *pClient, FSCmdBlock *pCmd, char **mount_path) {
|
||||
int32_t result = -1;
|
||||
DEBUG_FUNCTION_LINE("\n");
|
||||
FSMountSource *mountSrc = (FSMountSource*) malloc(sizeof(FSMountSource));
|
||||
if(!mountSrc) {
|
||||
return -3;
|
||||
}
|
||||
|
||||
DEBUG_FUNCTION_LINE("\n");
|
||||
char* mountPath = (char*) malloc(FS_MAX_MOUNTPATH_SIZE);
|
||||
if(!mountPath) {
|
||||
free(mountSrc);
|
||||
mountSrc = NULL;
|
||||
return -4;
|
||||
}
|
||||
DEBUG_FUNCTION_LINE("\n");
|
||||
memset(mountSrc, 0, FS_MOUNT_SOURCE_SIZE);
|
||||
memset(mountPath, 0, FS_MAX_MOUNTPATH_SIZE);
|
||||
|
||||
|
||||
// Mount sdcard
|
||||
if (FSGetMountSource(pClient, pCmd, FS_MOUNT_SOURCE_SD, mountSrc, -1) == 0) {
|
||||
DEBUG_FUNCTION_LINE("\n");
|
||||
result = FSMount(pClient, pCmd, mountSrc, mountPath, FS_MAX_MOUNTPATH_SIZE, -1);
|
||||
if((result == 0) && mount_path) {
|
||||
*mount_path = (char*)malloc(strlen(mountPath) + 1);
|
||||
if(*mount_path)
|
||||
strcpy(*mount_path, mountPath);
|
||||
}
|
||||
}
|
||||
|
||||
DEBUG_FUNCTION_LINE("\n");
|
||||
free(mountPath);
|
||||
free(mountSrc);
|
||||
|
||||
mountPath = NULL;
|
||||
mountSrc = NULL;
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
int32_t FSOSUtils::UmountFS(FSClient *pClient, FSCmdBlock *pCmd, const char *mountPath) {
|
||||
int32_t result = -1;
|
||||
result = FSUnmount(pClient, pCmd, mountPath, -1);
|
||||
|
||||
return result;
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
#ifndef __FS_OS_UTILS_H_
|
||||
#define __FS_OS_UTILS_H_
|
||||
|
||||
#include <stdint.h>
|
||||
#include <coreinit/filesystem.h>
|
||||
|
||||
class FSOSUtils {
|
||||
public:
|
||||
static int32_t MountFS(FSClient *pClient, FSCmdBlock *pCmd, char **mount_path);
|
||||
static int32_t UmountFS(FSClient *pClient, FSCmdBlock *pCmd, const char *mountPath);
|
||||
};
|
||||
|
||||
#endif // __FS_OS_UTILS_H_
|
@ -1,11 +1,11 @@
|
||||
#ifndef __LOGGER_H_
|
||||
#define __LOGGER_H_
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
#include <whb/log.h>
|
||||
|
||||
void log_init_();
|
||||
//void log_deinit_(void);
|
||||
@ -28,11 +28,9 @@ void OSFatal_printf(const char *format, ...);
|
||||
#define log_printf(FMT, ARGS...) log_printf_(FMT, ## ARGS);
|
||||
|
||||
#define DEBUG_FUNCTION_LINE(FMT, ARGS...)do { \
|
||||
log_printf("[%23s]%30s@L%04d: " FMT "",__FILENAME__,__FUNCTION__, __LINE__, ## ARGS); \
|
||||
WHBLogPrintf("[%23s]%30s@L%04d: " FMT "",__FILENAME__,__FUNCTION__, __LINE__, ## ARGS); \
|
||||
} while (0)
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
@ -1,107 +0,0 @@
|
||||
/****************************************************************************
|
||||
* Copyright (C) 2015 Dimok
|
||||
*
|
||||
* 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/>.
|
||||
****************************************************************************/
|
||||
#include <coreinit/memexpheap.h>
|
||||
#include <coreinit/memdefaultheap.h>
|
||||
#include <coreinit/memorymap.h>
|
||||
#include <malloc.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
extern uint32_t * pMEMAllocFromDefaultHeapEx;
|
||||
extern uint32_t * pMEMAllocFromDefaultHeap;
|
||||
extern uint32_t * pMEMFreeToDefaultHeap;
|
||||
|
||||
//!-------------------------------------------------------------------------------------------
|
||||
//! reent versions
|
||||
//!-------------------------------------------------------------------------------------------
|
||||
void *_malloc_r(struct _reent *r, size_t size) {
|
||||
void *ptr = ((void * (*)(size_t))(*pMEMAllocFromDefaultHeap))(size);
|
||||
if (!ptr) {
|
||||
r->_errno = ENOMEM;
|
||||
}
|
||||
return ptr;
|
||||
}
|
||||
|
||||
void *_calloc_r(struct _reent *r, size_t num, size_t size) {
|
||||
void *ptr = ((void * (*)(size_t))(*pMEMAllocFromDefaultHeap))(size);
|
||||
if (ptr) {
|
||||
memset(ptr, 0, num * size);
|
||||
} else {
|
||||
r->_errno = ENOMEM;
|
||||
}
|
||||
|
||||
return ptr;
|
||||
}
|
||||
|
||||
void *_memalign_r(struct _reent *r, size_t align, size_t size) {
|
||||
return ((void * (*)(size_t, size_t))(*pMEMAllocFromDefaultHeapEx))(size, align);
|
||||
}
|
||||
|
||||
void _free_r(struct _reent *r, void *ptr) {
|
||||
if (ptr) {
|
||||
((void (*)(void *))(*pMEMFreeToDefaultHeap))(ptr);
|
||||
}
|
||||
}
|
||||
|
||||
void *_realloc_r(struct _reent *r, void *p, size_t size) {
|
||||
void *new_ptr = ((void * (*)(size_t))(*pMEMAllocFromDefaultHeap))(size);
|
||||
if (!new_ptr) {
|
||||
r->_errno = ENOMEM;
|
||||
return new_ptr;
|
||||
}
|
||||
|
||||
if (p) {
|
||||
size_t old_size = MEMGetSizeForMBlockExpHeap(p);
|
||||
memcpy(new_ptr, p, old_size <= size ? old_size : size);
|
||||
((void (*)(void *))(*pMEMFreeToDefaultHeap))(p);
|
||||
}
|
||||
return new_ptr;
|
||||
}
|
||||
|
||||
struct mallinfo _mallinfo_r(struct _reent *r) {
|
||||
struct mallinfo info = { 0 };
|
||||
return info;
|
||||
}
|
||||
|
||||
void
|
||||
_malloc_stats_r(struct _reent *r) {
|
||||
}
|
||||
|
||||
int
|
||||
_mallopt_r(struct _reent *r, int param, int value) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
size_t
|
||||
_malloc_usable_size_r(struct _reent *r, void *ptr) {
|
||||
return MEMGetSizeForMBlockExpHeap(ptr);
|
||||
}
|
||||
|
||||
void *
|
||||
_valloc_r(struct _reent *r, size_t size) {
|
||||
return ((void * (*)(size_t, size_t))(*pMEMAllocFromDefaultHeapEx))(size, OS_PAGE_SIZE);
|
||||
}
|
||||
|
||||
void *
|
||||
_pvalloc_r(struct _reent *r, size_t size) {
|
||||
return ((void * (*)(size_t, size_t))(*pMEMAllocFromDefaultHeapEx))((size + (OS_PAGE_SIZE - 1)) & ~(OS_PAGE_SIZE - 1), OS_PAGE_SIZE);
|
||||
}
|
||||
|
||||
int
|
||||
_malloc_trim_r(struct _reent *r, size_t pad) {
|
||||
return 0;
|
||||
}
|
@ -1,42 +0,0 @@
|
||||
/****************************************************************************
|
||||
* Copyright (C) 2015 Dimok
|
||||
*
|
||||
* 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/>.
|
||||
****************************************************************************/
|
||||
#ifndef __MEMORY_H_
|
||||
#define __MEMORY_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <malloc.h>
|
||||
|
||||
void memoryInitialize(void);
|
||||
void memoryRelease(void);
|
||||
|
||||
void * MEM2_alloc(u32 size, u32 align);
|
||||
void MEM2_free(void *ptr);
|
||||
|
||||
void * MEM1_alloc(u32 size, u32 align);
|
||||
void MEM1_free(void *ptr);
|
||||
|
||||
void * MEMBucket_alloc(u32 size, u32 align);
|
||||
void MEMBucket_free(void *ptr);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // __MEMORY_H_
|
File diff suppressed because it is too large
Load Diff
@ -1,40 +0,0 @@
|
||||
/***************************************************************************
|
||||
* Copyright (C) 2015
|
||||
* by Dimok
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any
|
||||
* damages arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any
|
||||
* purpose, including commercial applications, and to alter it and
|
||||
* redistribute it freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you
|
||||
* must not claim that you wrote the original software. If you use
|
||||
* this software in a product, an acknowledgment in the product
|
||||
* documentation would be appreciated but is not required.
|
||||
*
|
||||
* 2. Altered source versions must be plainly marked as such, and
|
||||
* must not be misrepresented as being the original software.
|
||||
*
|
||||
* 3. This notice may not be removed or altered from any source
|
||||
* distribution.
|
||||
***************************************************************************/
|
||||
#ifndef __SD_FAT_DEVOPTAB_H_
|
||||
#define __SD_FAT_DEVOPTAB_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
int32_t mount_sd_fat(const char *path);
|
||||
int32_t unmount_sd_fat(const char *path);
|
||||
int32_t mount_fake();
|
||||
int32_t unmount_fake();
|
||||
void deleteDevTabsNames();
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // __SD_FAT_DEVOPTAB_H_
|
Loading…
Reference in New Issue
Block a user