2020-05-29 19:25:05 +02:00
|
|
|
#include <wums.h>
|
|
|
|
#include "memory_mapping.h"
|
2020-06-06 22:39:25 +02:00
|
|
|
#include <function_patcher/function_patching.h>
|
|
|
|
#include "function_replacements.h"
|
2022-01-26 13:24:56 +01:00
|
|
|
#include "logger.h"
|
2020-05-29 19:25:05 +02:00
|
|
|
|
|
|
|
WUMS_MODULE_EXPORT_NAME("homebrew_memorymapping");
|
2022-01-26 13:21:07 +01:00
|
|
|
WUMS_MODULE_SKIP_INIT_FINI();
|
2020-12-26 15:51:21 +01:00
|
|
|
WUMS_MODULE_INIT_BEFORE_RELOCATION_DONE_HOOK();
|
2020-05-29 19:25:05 +02:00
|
|
|
|
2021-09-24 16:51:11 +02:00
|
|
|
WUMS_INITIALIZE(args) {
|
2020-05-29 19:25:05 +02:00
|
|
|
static uint8_t ucSetupRequired = 1;
|
2020-06-03 18:36:02 +02:00
|
|
|
if (!ucSetupRequired) {
|
2020-05-29 19:25:05 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
ucSetupRequired = 0;
|
2020-06-03 18:51:24 +02:00
|
|
|
MemoryMapping_setupMemoryMapping();
|
|
|
|
MemoryMapping_CreateHeaps();
|
2020-06-06 22:39:25 +02:00
|
|
|
|
|
|
|
FunctionPatcherPatchFunction(function_replacements, function_replacements_size);
|
2020-05-29 19:25:05 +02:00
|
|
|
}
|
|
|
|
|
2022-01-26 13:24:56 +01:00
|
|
|
#ifdef DEBUG
|
|
|
|
WUMS_APPLICATION_STARTS() {
|
|
|
|
initLogging();
|
|
|
|
}
|
|
|
|
|
|
|
|
WUMS_APPLICATION_REQUESTS_EXIT() {
|
|
|
|
deinitLogging();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2020-06-03 18:36:02 +02:00
|
|
|
void MemoryMappingFree(void *ptr) {
|
2020-06-03 18:51:24 +02:00
|
|
|
//DEBUG_FUNCTION_LINE("[%08X] free", ptr);
|
|
|
|
MemoryMapping_free(ptr);
|
2020-05-29 19:25:05 +02:00
|
|
|
}
|
|
|
|
|
2020-06-03 18:36:02 +02:00
|
|
|
uint32_t MemoryMappingEffectiveToPhysical(uint32_t address) {
|
2020-06-03 18:51:24 +02:00
|
|
|
return MemoryMapping_EffectiveToPhysical(address);
|
2020-05-29 19:25:05 +02:00
|
|
|
}
|
2020-06-03 18:36:02 +02:00
|
|
|
|
|
|
|
uint32_t MemoryMappingPhysicalToEffective(uint32_t address) {
|
2020-06-03 18:51:24 +02:00
|
|
|
return MemoryMapping_PhysicalToEffective(address);
|
2020-05-29 19:25:05 +02:00
|
|
|
}
|
|
|
|
|
2020-06-03 18:36:02 +02:00
|
|
|
void *MemoryMappingAlloc(uint32_t size) {
|
2020-06-03 18:51:24 +02:00
|
|
|
void *res = MemoryMapping_alloc(size, 0x04);
|
2020-05-30 21:47:44 +02:00
|
|
|
//DEBUG_FUNCTION_LINE("[res: %08X] alloc %d ", res, size);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2021-09-28 17:58:20 +02:00
|
|
|
void *MemoryMappingAllocEx(uint32_t size, int32_t align) {
|
2020-06-03 18:51:24 +02:00
|
|
|
void *res = MemoryMapping_alloc(size, align);
|
2020-05-30 21:47:44 +02:00
|
|
|
//DEBUG_FUNCTION_LINE("[res %08X] allocEX %d %d ", res, size, align);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2021-09-28 17:58:20 +02:00
|
|
|
void *MemoryMappingAllocForGX2Ex(uint32_t size, int32_t align) {
|
2020-06-27 11:17:38 +02:00
|
|
|
void *res = MemoryMapping_allocVideoMemory(size, align);
|
|
|
|
//DEBUG_FUNCTION_LINE("[res %08X] allocEX %d %d ", res, size, align);
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2020-05-30 21:47:44 +02:00
|
|
|
uint32_t MEMAllocFromMappedMemory __attribute__((__section__ (".data"))) = (uint32_t) MemoryMappingAlloc;
|
|
|
|
uint32_t MEMAllocFromMappedMemoryEx __attribute__((__section__ (".data"))) = (uint32_t) MemoryMappingAllocEx;
|
2020-06-27 11:17:38 +02:00
|
|
|
uint32_t MEMAllocFromMappedMemoryForGX2Ex __attribute__((__section__ (".data"))) = (uint32_t) MemoryMappingAllocForGX2Ex;
|
2020-05-30 21:47:44 +02:00
|
|
|
uint32_t MEMFreeToMappedMemory __attribute__((__section__ (".data"))) = (uint32_t) MemoryMappingFree;
|
|
|
|
|
2020-05-29 19:25:05 +02:00
|
|
|
WUMS_EXPORT_FUNCTION(MemoryMappingEffectiveToPhysical);
|
2020-05-30 21:47:44 +02:00
|
|
|
WUMS_EXPORT_FUNCTION(MemoryMappingPhysicalToEffective);
|
|
|
|
|
|
|
|
WUMS_EXPORT_DATA(MEMAllocFromMappedMemory);
|
|
|
|
WUMS_EXPORT_DATA(MEMAllocFromMappedMemoryEx);
|
2020-06-27 11:17:38 +02:00
|
|
|
WUMS_EXPORT_DATA(MEMAllocFromMappedMemoryForGX2Ex);
|
2020-05-30 21:47:44 +02:00
|
|
|
WUMS_EXPORT_DATA(MEMFreeToMappedMemory);
|