mirror of
https://github.com/dingusdev/dingusppc.git
synced 2024-09-29 17:56:59 +00:00
memctrlbase: cosmetic improvements.
This commit is contained in:
parent
c7ca4d9b97
commit
ab60bb8d0b
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||||
Copyright (C) 2018-21 divingkatae and maximum
|
Copyright (C) 2018-24 divingkatae and maximum
|
||||||
(theweirdo) spatium
|
(theweirdo) spatium
|
||||||
|
|
||||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||||
@ -22,20 +22,12 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|||||||
#include <devices/memctrl/memctrlbase.h>
|
#include <devices/memctrl/memctrlbase.h>
|
||||||
#include <devices/common/mmiodevice.h>
|
#include <devices/common/mmiodevice.h>
|
||||||
|
|
||||||
#include <algorithm> // to shut up MSVC errors (:
|
#include <algorithm>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <loguru.hpp>
|
#include <loguru.hpp>
|
||||||
|
|
||||||
static inline bool match_mem_entry(const AddressMapEntry* entry,
|
|
||||||
const uint32_t start, const uint32_t end,
|
|
||||||
MMIODevice* dev_instance)
|
|
||||||
{
|
|
||||||
return start == entry->start && end == entry->end &&
|
|
||||||
(!dev_instance || dev_instance == entry->devobj);
|
|
||||||
}
|
|
||||||
|
|
||||||
MemCtrlBase::~MemCtrlBase() {
|
MemCtrlBase::~MemCtrlBase() {
|
||||||
for (auto& entry : address_map) {
|
for (auto& entry : address_map) {
|
||||||
if (entry)
|
if (entry)
|
||||||
@ -51,6 +43,15 @@ MemCtrlBase::~MemCtrlBase() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static inline bool match_mem_entry(const AddressMapEntry* entry,
|
||||||
|
const uint32_t start, const uint32_t end,
|
||||||
|
MMIODevice* dev_instance)
|
||||||
|
{
|
||||||
|
return start == entry->start && end == entry->end &&
|
||||||
|
(!dev_instance || dev_instance == entry->devobj);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
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)
|
||||||
@ -149,11 +150,11 @@ bool MemCtrlBase::add_mem_region(uint32_t start_addr, uint32_t size,
|
|||||||
{
|
{
|
||||||
AddressMapEntry *entry;
|
AddressMapEntry *entry;
|
||||||
|
|
||||||
/* error if a memory region for the given range already exists */
|
// bail out if a memory region for the given range already exists
|
||||||
if (!is_range_free(start_addr, size))
|
if (!is_range_free(start_addr, size))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
uint8_t* reg_content = new uint8_t[size](); /* () intializer clears the memory to zero */
|
uint8_t* reg_content = new uint8_t[size](); // allocate and clear to zero
|
||||||
|
|
||||||
this->mem_regions.push_back(reg_content);
|
this->mem_regions.push_back(reg_content);
|
||||||
|
|
||||||
@ -249,7 +250,7 @@ bool MemCtrlBase::add_mmio_region(uint32_t start_addr, uint32_t size, MMIODevice
|
|||||||
{
|
{
|
||||||
AddressMapEntry *entry;
|
AddressMapEntry *entry;
|
||||||
|
|
||||||
/* error if a memory region for the given range already exists */
|
// bail out if a memory region for the given range already exists
|
||||||
if (!is_range_free(start_addr, size))
|
if (!is_range_free(start_addr, size))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
DingusPPC - The Experimental PowerPC Macintosh emulator
|
DingusPPC - The Experimental PowerPC Macintosh emulator
|
||||||
Copyright (C) 2018-22 divingkatae and maximum
|
Copyright (C) 2018-24 divingkatae and maximum
|
||||||
(theweirdo) spatium
|
(theweirdo) spatium
|
||||||
|
|
||||||
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
|
||||||
@ -28,7 +28,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|||||||
|
|
||||||
class MMIODevice;
|
class MMIODevice;
|
||||||
|
|
||||||
// Common DRAM capacities.
|
/* Common DRAM capacities. */
|
||||||
enum {
|
enum {
|
||||||
DRAM_CAP_2MB = (1 << 21),
|
DRAM_CAP_2MB = (1 << 21),
|
||||||
DRAM_CAP_4MB = (1 << 22),
|
DRAM_CAP_4MB = (1 << 22),
|
||||||
@ -40,21 +40,21 @@ enum {
|
|||||||
};
|
};
|
||||||
|
|
||||||
enum RangeType {
|
enum RangeType {
|
||||||
RT_ROM = 1, /* read-only memory */
|
RT_ROM = 1, // read-only memory
|
||||||
RT_RAM = 2, /* random access memory */
|
RT_RAM = 2, // random access memory
|
||||||
RT_MMIO = 4, /* memory mapped I/O */
|
RT_MMIO = 4, // memory mapped I/O
|
||||||
RT_MIRROR = 8 /* region mirror (content of another region is acessible
|
RT_MIRROR = 8 // region mirror (content of another region acessible at some
|
||||||
at some other address) */
|
// other address)
|
||||||
};
|
};
|
||||||
|
|
||||||
/** Defines the format for the address map entry. */
|
/** Defines the format for the address map entry. */
|
||||||
typedef struct AddressMapEntry {
|
typedef struct AddressMapEntry {
|
||||||
uint32_t start; /* first address of the corresponding range */
|
uint32_t start; // first address of the corresponding range
|
||||||
uint32_t end; /* last address of the corresponding range */
|
uint32_t end; // last address of the corresponding range
|
||||||
uint32_t mirror; /* mirror address for RT_MIRROR */
|
uint32_t mirror; // starting address of the origin for RT_MIRROR
|
||||||
uint32_t type; /* range type */
|
uint32_t type; // range type
|
||||||
MMIODevice* devobj; /* pointer to device object */
|
MMIODevice* devobj; // pointer to device object
|
||||||
unsigned char* mem_ptr; /* direct pointer to data for memory objects */
|
unsigned char* mem_ptr; // direct pointer to data for memory objects
|
||||||
} AddressMapEntry;
|
} AddressMapEntry;
|
||||||
|
|
||||||
|
|
||||||
@ -67,13 +67,16 @@ public:
|
|||||||
virtual bool add_ram_region(uint32_t start_addr, uint32_t size);
|
virtual bool add_ram_region(uint32_t start_addr, uint32_t size);
|
||||||
virtual bool add_mem_mirror(uint32_t start_addr, uint32_t dest_addr);
|
virtual bool add_mem_mirror(uint32_t start_addr, uint32_t dest_addr);
|
||||||
|
|
||||||
virtual bool add_mmio_region(uint32_t start_addr, uint32_t size, MMIODevice* dev_instance);
|
virtual bool add_mmio_region(uint32_t start_addr, uint32_t size,
|
||||||
virtual bool remove_mmio_region(uint32_t start_addr, uint32_t size, MMIODevice* dev_instance);
|
MMIODevice* dev_instance);
|
||||||
|
virtual bool remove_mmio_region(uint32_t start_addr, uint32_t size,
|
||||||
|
MMIODevice* dev_instance);
|
||||||
|
|
||||||
virtual bool set_data(uint32_t reg_addr, const uint8_t* data, uint32_t size);
|
virtual bool set_data(uint32_t reg_addr, const uint8_t* data, uint32_t size);
|
||||||
|
|
||||||
AddressMapEntry* find_range(uint32_t addr);
|
AddressMapEntry* find_range(uint32_t addr);
|
||||||
AddressMapEntry* find_range_exact(uint32_t addr, uint32_t size, MMIODevice* dev_instance);
|
AddressMapEntry* find_range_exact(uint32_t addr, uint32_t size,
|
||||||
|
MMIODevice* dev_instance);
|
||||||
AddressMapEntry* find_range_contains(uint32_t addr, uint32_t size);
|
AddressMapEntry* find_range_contains(uint32_t addr, uint32_t size);
|
||||||
AddressMapEntry* find_range_overlaps(uint32_t addr, uint32_t size);
|
AddressMapEntry* find_range_overlaps(uint32_t addr, uint32_t size);
|
||||||
bool is_range_free(uint32_t addr, uint32_t size);
|
bool is_range_free(uint32_t addr, uint32_t size);
|
||||||
@ -82,11 +85,13 @@ public:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool add_mem_region(
|
bool add_mem_region(
|
||||||
uint32_t start_addr, uint32_t size, uint32_t dest_addr, uint32_t type, uint8_t init_val);
|
uint32_t start_addr, uint32_t size, uint32_t dest_addr, uint32_t type,
|
||||||
|
uint8_t init_val
|
||||||
|
);
|
||||||
|
|
||||||
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…
Reference in New Issue
Block a user