Add PhysicaltoEffective and EffectiveToPhysical for own mapped memory.

This commit is contained in:
Maschell 2019-02-08 16:34:52 +01:00
parent 64e4ed5f71
commit 2fc11412f3
2 changed files with 81 additions and 5 deletions

View File

@ -675,3 +675,66 @@ bool MemoryMapping::mapMemory(uint32_t pa_start_address,uint32_t pa_end_address,
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;
}

View File

@ -25,6 +25,7 @@ typedef struct _memory_values_t {
typedef struct _memory_mapping_t {
uint32_t effective_start_address;
uint32_t effective_end_address;
const memory_values_t* physical_addresses;
} memory_mapping_t;
@ -140,11 +141,11 @@ const memory_values_t mem_vals_heap[] = {
};
const memory_mapping_t mem_mapping[] = {
{MEMORY_START_PLUGIN_LOADER, mem_vals_loader},
{MEMORY_START_PLUGIN_SPACE, mem_vals_plugins},
{MEMORY_START_PLUGIN_HEAP, mem_vals_heap},
{MEMORY_START_VIDEO_SPACE, mem_vals_video},
{0,NULL}
{MEMORY_START_VIDEO_SPACE, MEMORY_START_VIDEO_SPACE_END, mem_vals_video},
{MEMORY_START_PLUGIN_LOADER, MEMORY_START_PLUGIN_LOADER_END, mem_vals_loader},
{MEMORY_START_PLUGIN_SPACE, MEMORY_START_PLUGIN_SPACE_END, mem_vals_plugins},
{MEMORY_START_PLUGIN_HEAP, MEMORY_START_PLUGIN_HEAP_END, mem_vals_heap},
{0,0,NULL}
};
class MemoryMapping {
@ -166,8 +167,20 @@ public:
static uint32_t getHeapSize();
static uint32_t getVideoMemoryAddress();
static uint32_t getVideoMemorySize();
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:
static void memoryMappingForRegions(const memory_mapping_t * memory_mapping, sr_table_t SRTable, uint32_t * translation_table);