dingusppc/devices/memctrl/memctrlbase.h

93 lines
3.2 KiB
C
Raw Normal View History

/*
DingusPPC - The Experimental PowerPC Macintosh emulator
Copyright (C) 2018-22 divingkatae and maximum
(theweirdo) spatium
(Contact divingkatae#1017 or powermax#2286 on Discord for more info)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef MEMORY_CONTROLLER_BASE_H
#define MEMORY_CONTROLLER_BASE_H
#include <cinttypes>
#include <string>
#include <vector>
class MMIODevice;
// Common DRAM capacities.
enum {
DRAM_CAP_2MB = (1 << 21),
DRAM_CAP_4MB = (1 << 22),
DRAM_CAP_8MB = (1 << 23),
DRAM_CAP_16MB = (1 << 24),
DRAM_CAP_32MB = (1 << 25),
DRAM_CAP_64MB = (1 << 26),
DRAM_CAP_128MB = (1 << 27),
};
enum RangeType {
2020-05-12 18:55:45 +00:00
RT_ROM = 1, /* read-only memory */
RT_RAM = 2, /* random access memory */
RT_MMIO = 4, /* memory mapped I/O */
RT_MIRROR = 8 /* region mirror (content of another region is acessible
at some other address) */
};
/** Defines the format for the address map entry. */
typedef struct AddressMapEntry {
2020-05-12 18:55:45 +00:00
uint32_t start; /* first address of the corresponding range */
uint32_t end; /* last address of the corresponding range */
uint32_t mirror; /* mirror address for RT_MIRROR */
uint32_t type; /* range type */
MMIODevice* devobj; /* pointer to device object */
unsigned char* mem_ptr; /* direct pointer to data for memory objects */
} AddressMapEntry;
/** Base class for memory controllers. */
class MemCtrlBase {
public:
2020-03-14 13:23:46 +00:00
MemCtrlBase() = default;
virtual ~MemCtrlBase();
virtual bool add_rom_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);
2020-05-12 18:55:45 +00:00
virtual bool add_mmio_region(uint32_t start_addr, uint32_t size, MMIODevice* dev_instance);
virtual bool remove_mmio_region(uint32_t start_addr, uint32_t size, MMIODevice* dev_instance);
2020-05-12 18:55:45 +00:00
virtual bool set_data(uint32_t reg_addr, const uint8_t* data, uint32_t size);
2020-05-12 18:55:45 +00:00
AddressMapEntry* find_range(uint32_t addr);
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_overlaps(uint32_t addr, uint32_t size);
bool is_range_free(uint32_t addr, uint32_t size);
AddressMapEntry* find_rom_region();
protected:
2020-05-12 18:55:45 +00:00
bool add_mem_region(
uint32_t start_addr, uint32_t size, uint32_t dest_addr, uint32_t type, uint8_t init_val);
private:
2020-05-12 18:55:45 +00:00
std::vector<uint8_t*> mem_regions;
std::vector<AddressMapEntry*> address_map;
};
#endif /* MEMORY_CONTROLLER_BASE_H */