Allow early init of the Module System, check EnvrionmentLoader version

This commit is contained in:
Maschell 2024-04-19 13:11:28 +02:00
parent 40bec5454c
commit 40420432e2
6 changed files with 31 additions and 10 deletions

View File

@ -1,4 +1,5 @@
#include "kernel.h"
#include "../wumsloader/src/globals.h"
#include "ElfUtils.h"
#include "wumsloader_elf.h"
#include <coreinit/cache.h>
@ -20,6 +21,9 @@ void SetupWUMSLoader() {
KernelWriteU32(repl_addr, 0x48000003 | entryPoint);
DCFlushRange((void *) repl_addr, 4);
ICInvalidateRange((void *) (repl_addr), 4);
// We call the mainhook (wumloader) once with a MAGIC number to set up the WUMS Modules but not actually call the original main function
((int (*)(int, char **))(entryPoint))(WUMS_LOADER_SETUP_MAGIC_WORD, nullptr);
}
void KernelWriteU32(uint32_t addr, uint32_t value) {

View File

@ -12,6 +12,11 @@ int main(int argc, char **argv) {
if (argc >= 1) {
basePath = argv[0];
}
if (argc < 4 || std::string_view("EnvironmentLoader") != argv[1] || (uint32_t) argv[2] < 2 || (uint32_t) argv[3] == 0) {
OSFatal("WUMSLoader: Failed to parse arguments, make sure to use the latest environment loader.\n See https://wiiu.hacks.guide/ for more information.");
}
memcpy(MEMORY_REGION_USABLE_MEM_REGION_END_VALUE_PTR, &argv[3], sizeof(uint32_t));
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Warray-bounds"

View File

@ -70,7 +70,7 @@ MAKEFLAGS += --no-print-directory
#---------------------------------------------------------------------------------
# any extra libraries we wish to link with the project
#---------------------------------------------------------------------------------
LIBS := -lwums -lwut -lz
LIBS := -lwut -lz
#---------------------------------------------------------------------------------
# list of directories containing libraries, this must be the top level containing

View File

@ -53,6 +53,10 @@ extern "C" int _start(int argc, char **argv) {
:);
OSCheckActiveThreads();
if (argc == WUMS_LOADER_SETUP_MAGIC_WORD) {
DEBUG_FUNCTION_LINE("Skip calling the real main function because we just want to setup WUMS");
return 0;
}
return ((int (*)(int, char **))(*(unsigned int *) 0x1005E040))(argc, argv);
}

View File

@ -14,15 +14,21 @@ extern std::unique_ptr<module_information_single_t[]> gModuleDataInfo;
extern std::map<std::string, OSDynLoad_Module> gUsedRPLs;
extern std::vector<void *> gAllocatedAddresses;
#define MEMORY_REGION_START 0x00800000
#define MEMORY_REGION_SIZE 0x00800000
#define MEMORY_REGION_START 0x00800000
#define MEMORY_REGION_SIZE 0x00800000
#define CUSTOM_RPX_LOADER_RETURN_CODE 0x00009000 // We have to skip the first 0x00009000 bytes because it's still used
#define RELOCATOR_SIZE 0x52000 // Maximum size of the wumsloader, needs to match the one defined in link.ld
#define ENVIRONMENT_PATH_LENGTH 0x100 // Length of the EnvironmentPath.
#define CUSTOM_RPX_LOADER_RETURN_CODE 0x00009000 // We have to skip the first 0x00009000 bytes because it's still used
#define RELOCATOR_SIZE 0x52000 // Maximum size of the wumsloader, needs to match the one defined in link.ld
#define ENVIRONMENT_PATH_LENGTH 0x100 // Length of the EnvironmentPath.
#define MEMORY_REGION_USABLE_MEM_REGION_END_LENGTH 0x04 // sizeof(uint32_t)
#define MEMORY_REGION_ENVIRONMENT_STRING_ADRR (MEMORY_REGION_START + CUSTOM_RPX_LOADER_RETURN_CODE + RELOCATOR_SIZE)
#define MEMORY_REGION_USABLE_HEAP_START (MEMORY_REGION_ENVIRONMENT_STRING_ADRR + ENVIRONMENT_PATH_LENGTH)
#define MEMORY_REGION_USABLE_HEAP_END (0x00FFF000) // We need to leave space for the BAT hook
#define MEMORY_REGION_ENVIRONMENT_STRING_ADRR (MEMORY_REGION_START + CUSTOM_RPX_LOADER_RETURN_CODE + RELOCATOR_SIZE)
#define MEMORY_REGION_USABLE_MEM_REGION_END_VALUE_PTR ((uint32_t *) (MEMORY_REGION_ENVIRONMENT_STRING_ADRR + ENVIRONMENT_PATH_LENGTH))
#define MEMORY_REGION_USABLE_MEM_REGION_END_VALUE (*MEMORY_REGION_USABLE_MEM_REGION_END_VALUE_PTR)
#define ENVRIONMENT_STRING ((char *) MEMORY_REGION_ENVIRONMENT_STRING_ADRR)
#define MEMORY_REGION_USABLE_HEAP_START ((uint32_t) MEMORY_REGION_USABLE_MEM_REGION_END_VALUE_PTR + MEMORY_REGION_USABLE_MEM_REGION_END_LENGTH)
#define MEMORY_REGION_USABLE_HEAP_END MEMORY_REGION_USABLE_MEM_REGION_END_VALUE
#define ENVRIONMENT_STRING ((char *) MEMORY_REGION_ENVIRONMENT_STRING_ADRR)
#define WUMS_LOADER_SETUP_MAGIC_WORD 0x13371337

View File

@ -38,6 +38,8 @@ IMPORT(__KernelGetInfo);
IMPORT(OSCheckActiveThreads);
IMPORT(OSGetCurrentThread);
IMPORT(OSSetThreadCleanupCallback);
IMPORT(OSIsDebuggerPresent);
IMPORT(__os_snprintf);
IMPORT(FSTimeToCalendarTime);
IMPORT(FSInit);