mirror of
https://github.com/wiiu-env/WiiUPluginLoaderBackend.git
synced 2024-11-05 12:35:06 +01:00
Add PhysicaltoEffective and EffectiveToPhysical for own mapped memory.
This commit is contained in:
parent
64e4ed5f71
commit
2fc11412f3
@ -675,3 +675,66 @@ bool MemoryMapping::mapMemory(uint32_t pa_start_address,uint32_t pa_end_address,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint32_t MemoryMapping::PhysicalToEffective(uint32_t phyiscalAddress){
|
||||||
|
uint32_t result = 0;
|
||||||
|
const memory_values_t * curMemValues = NULL;
|
||||||
|
int32_t curOffset = 0;
|
||||||
|
//iterate through all own mapped memory regions
|
||||||
|
for(int32_t i = 0;true;i++){
|
||||||
|
if(mem_mapping[i].physical_addresses == NULL){
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
curMemValues = mem_mapping[i].physical_addresses;
|
||||||
|
uint32_t curOffsetInEA = 0;
|
||||||
|
// iterate through all memory values of this region
|
||||||
|
for(int32_t j= 0;true;j++){
|
||||||
|
if(curMemValues[j].end_address == 0){
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if(phyiscalAddress >= curMemValues[j].start_address && phyiscalAddress < curMemValues[j].end_address){
|
||||||
|
// calculate the EA
|
||||||
|
result = (phyiscalAddress - curMemValues[j].start_address) + (mem_mapping[i].effective_start_address + curOffsetInEA);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
curOffsetInEA += curMemValues[j].end_address - curMemValues[j].start_address;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t MemoryMapping::EffectiveToPhysical(uint32_t effectiveAddress){
|
||||||
|
uint32_t result = 0;
|
||||||
|
// CAUTION: The data may be fragmented between multiple areas in PA.
|
||||||
|
const memory_values_t * curMemValues = NULL;
|
||||||
|
int32_t curOffset = 0;
|
||||||
|
|
||||||
|
for(int32_t i = 0;true;i++){
|
||||||
|
if(mem_mapping[i].physical_addresses == NULL){
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if(effectiveAddress >= mem_mapping[i].effective_start_address && effectiveAddress < mem_mapping[i].effective_end_address){
|
||||||
|
curMemValues = mem_mapping[i].physical_addresses;
|
||||||
|
curOffset = mem_mapping[i].effective_start_address;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(curMemValues == NULL){
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
for(int32_t i= 0;true;i++){
|
||||||
|
if(curMemValues[i].end_address == 0){
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
int32_t curChunkSize = curMemValues[i].end_address - curMemValues[i].start_address;
|
||||||
|
if(effectiveAddress < (curOffset + curChunkSize)){
|
||||||
|
result = (effectiveAddress - curOffset) + curMemValues[i].start_address;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
curOffset += curChunkSize;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
@ -25,6 +25,7 @@ typedef struct _memory_values_t {
|
|||||||
|
|
||||||
typedef struct _memory_mapping_t {
|
typedef struct _memory_mapping_t {
|
||||||
uint32_t effective_start_address;
|
uint32_t effective_start_address;
|
||||||
|
uint32_t effective_end_address;
|
||||||
const memory_values_t* physical_addresses;
|
const memory_values_t* physical_addresses;
|
||||||
} memory_mapping_t;
|
} memory_mapping_t;
|
||||||
|
|
||||||
@ -140,11 +141,11 @@ const memory_values_t mem_vals_heap[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const memory_mapping_t mem_mapping[] = {
|
const memory_mapping_t mem_mapping[] = {
|
||||||
{MEMORY_START_PLUGIN_LOADER, mem_vals_loader},
|
{MEMORY_START_VIDEO_SPACE, MEMORY_START_VIDEO_SPACE_END, mem_vals_video},
|
||||||
{MEMORY_START_PLUGIN_SPACE, mem_vals_plugins},
|
{MEMORY_START_PLUGIN_LOADER, MEMORY_START_PLUGIN_LOADER_END, mem_vals_loader},
|
||||||
{MEMORY_START_PLUGIN_HEAP, mem_vals_heap},
|
{MEMORY_START_PLUGIN_SPACE, MEMORY_START_PLUGIN_SPACE_END, mem_vals_plugins},
|
||||||
{MEMORY_START_VIDEO_SPACE, mem_vals_video},
|
{MEMORY_START_PLUGIN_HEAP, MEMORY_START_PLUGIN_HEAP_END, mem_vals_heap},
|
||||||
{0,NULL}
|
{0,0,NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
class MemoryMapping {
|
class MemoryMapping {
|
||||||
@ -166,8 +167,20 @@ public:
|
|||||||
|
|
||||||
static uint32_t getHeapSize();
|
static uint32_t getHeapSize();
|
||||||
|
|
||||||
|
static uint32_t getVideoMemoryAddress();
|
||||||
|
|
||||||
|
static uint32_t getVideoMemorySize();
|
||||||
|
|
||||||
static uint32_t getAreaSizeFromPageTable(uint32_t start, uint32_t maxSize);
|
static uint32_t getAreaSizeFromPageTable(uint32_t start, uint32_t maxSize);
|
||||||
|
|
||||||
|
// Caution when using the result. A chunk of memory in effective address may be split up
|
||||||
|
// into several small chunks inside physical space.
|
||||||
|
static uint32_t PhysicalToEffective(uint32_t phyiscalAddress);
|
||||||
|
|
||||||
|
// Caution when using the result. A chunk of memory in effective address may be split up
|
||||||
|
// into several small chunks inside physical space.
|
||||||
|
static uint32_t EffectiveToPhysical(uint32_t effectiveAddress);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
static void memoryMappingForRegions(const memory_mapping_t * memory_mapping, sr_table_t SRTable, uint32_t * translation_table);
|
static void memoryMappingForRegions(const memory_mapping_t * memory_mapping, sr_table_t SRTable, uint32_t * translation_table);
|
||||||
|
Loading…
Reference in New Issue
Block a user