mirror of
https://github.com/dingusdev/dingusppc.git
synced 2025-01-11 05:29:43 +00:00
memctrlbase: allocate address map entries with new().
This commit is contained in:
parent
6f9ee10de5
commit
05330bc942
@ -28,6 +28,11 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|||||||
|
|
||||||
|
|
||||||
MemCtrlBase::~MemCtrlBase() {
|
MemCtrlBase::~MemCtrlBase() {
|
||||||
|
for (auto& entry : address_map) {
|
||||||
|
if (entry)
|
||||||
|
delete(entry);
|
||||||
|
}
|
||||||
|
|
||||||
for (auto& reg : mem_regions) {
|
for (auto& reg : mem_regions) {
|
||||||
if (reg)
|
if (reg)
|
||||||
delete (reg);
|
delete (reg);
|
||||||
@ -39,8 +44,8 @@ MemCtrlBase::~MemCtrlBase() {
|
|||||||
|
|
||||||
AddressMapEntry* MemCtrlBase::find_range(uint32_t addr) {
|
AddressMapEntry* MemCtrlBase::find_range(uint32_t addr) {
|
||||||
for (auto& entry : address_map) {
|
for (auto& entry : address_map) {
|
||||||
if (addr >= entry.start && addr <= entry.end)
|
if (addr >= entry->start && addr <= entry->end)
|
||||||
return &entry;
|
return entry;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@ -49,7 +54,7 @@ AddressMapEntry* MemCtrlBase::find_range(uint32_t addr) {
|
|||||||
|
|
||||||
bool MemCtrlBase::add_mem_region(
|
bool MemCtrlBase::add_mem_region(
|
||||||
uint32_t start_addr, uint32_t size, uint32_t dest_addr, uint32_t type, uint8_t init_val = 0) {
|
uint32_t start_addr, uint32_t size, uint32_t dest_addr, uint32_t type, uint8_t init_val = 0) {
|
||||||
AddressMapEntry entry;
|
AddressMapEntry *entry;
|
||||||
|
|
||||||
/* error if a memory region for the given range already exists */
|
/* error if a memory region for the given range already exists */
|
||||||
if (find_range(start_addr) || find_range(start_addr + size))
|
if (find_range(start_addr) || find_range(start_addr + size))
|
||||||
@ -59,12 +64,14 @@ bool MemCtrlBase::add_mem_region(
|
|||||||
|
|
||||||
this->mem_regions.push_back(reg_content);
|
this->mem_regions.push_back(reg_content);
|
||||||
|
|
||||||
entry.start = start_addr;
|
entry = new AddressMapEntry;
|
||||||
entry.end = start_addr + size - 1;
|
|
||||||
entry.mirror = dest_addr;
|
entry->start = start_addr;
|
||||||
entry.type = type;
|
entry->end = start_addr + size - 1;
|
||||||
entry.devobj = 0;
|
entry->mirror = dest_addr;
|
||||||
entry.mem_ptr = reg_content;
|
entry->type = type;
|
||||||
|
entry->devobj = 0;
|
||||||
|
entry->mem_ptr = reg_content;
|
||||||
|
|
||||||
this->address_map.push_back(entry);
|
this->address_map.push_back(entry);
|
||||||
|
|
||||||
@ -83,18 +90,20 @@ bool MemCtrlBase::add_ram_region(uint32_t start_addr, uint32_t size) {
|
|||||||
|
|
||||||
|
|
||||||
bool MemCtrlBase::add_mem_mirror(uint32_t start_addr, uint32_t dest_addr) {
|
bool MemCtrlBase::add_mem_mirror(uint32_t start_addr, uint32_t dest_addr) {
|
||||||
AddressMapEntry entry, *ref_entry;
|
AddressMapEntry *entry, *ref_entry;
|
||||||
|
|
||||||
ref_entry = find_range(dest_addr);
|
ref_entry = find_range(dest_addr);
|
||||||
if (!ref_entry)
|
if (!ref_entry)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
entry.start = start_addr;
|
entry = new AddressMapEntry;
|
||||||
entry.end = start_addr + (ref_entry->end - ref_entry->start) + 1;
|
|
||||||
entry.mirror = dest_addr;
|
entry->start = start_addr;
|
||||||
entry.type = ref_entry->type | RT_MIRROR;
|
entry->end = start_addr + (ref_entry->end - ref_entry->start) + 1;
|
||||||
entry.devobj = 0;
|
entry->mirror = dest_addr;
|
||||||
entry.mem_ptr = ref_entry->mem_ptr;
|
entry->type = ref_entry->type | RT_MIRROR;
|
||||||
|
entry->devobj = 0;
|
||||||
|
entry->mem_ptr = ref_entry->mem_ptr;
|
||||||
|
|
||||||
this->address_map.push_back(entry);
|
this->address_map.push_back(entry);
|
||||||
|
|
||||||
@ -118,18 +127,20 @@ bool MemCtrlBase::set_data(uint32_t reg_addr, const uint8_t* data, uint32_t size
|
|||||||
|
|
||||||
|
|
||||||
bool MemCtrlBase::add_mmio_region(uint32_t start_addr, uint32_t size, MMIODevice* dev_instance) {
|
bool MemCtrlBase::add_mmio_region(uint32_t start_addr, uint32_t size, MMIODevice* dev_instance) {
|
||||||
AddressMapEntry entry;
|
AddressMapEntry *entry;
|
||||||
|
|
||||||
/* error if another region for the given range already exists */
|
/* error if another region for the given range already exists */
|
||||||
if (find_range(start_addr) || find_range(start_addr + size))
|
if (find_range(start_addr) || find_range(start_addr + size))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
entry.start = start_addr;
|
entry = new AddressMapEntry;
|
||||||
entry.end = start_addr + size - 1;
|
|
||||||
entry.mirror = 0;
|
entry->start = start_addr;
|
||||||
entry.type = RT_MMIO;
|
entry->end = start_addr + size - 1;
|
||||||
entry.devobj = dev_instance;
|
entry->mirror = 0;
|
||||||
entry.mem_ptr = 0;
|
entry->type = RT_MMIO;
|
||||||
|
entry->devobj = dev_instance;
|
||||||
|
entry->mem_ptr = 0;
|
||||||
|
|
||||||
this->address_map.push_back(entry);
|
this->address_map.push_back(entry);
|
||||||
|
|
||||||
|
@ -67,7 +67,7 @@ protected:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<uint8_t*> mem_regions;
|
std::vector<uint8_t*> mem_regions;
|
||||||
std::vector<AddressMapEntry> address_map;
|
std::vector<AddressMapEntry*> address_map;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* MEMORY_CONTROLLER_BASE_H */
|
#endif /* MEMORY_CONTROLLER_BASE_H */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user