2020-02-28 16:04:28 +00:00
|
|
|
/*
|
|
|
|
DingusPPC - The Experimental PowerPC Macintosh emulator
|
2022-08-06 17:33:25 +00:00
|
|
|
Copyright (C) 2018-22 divingkatae and maximum
|
2020-02-28 16:04:28 +00:00
|
|
|
(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/>.
|
|
|
|
*/
|
|
|
|
|
2019-08-18 23:34:24 +00:00
|
|
|
#ifndef MEMORY_CONTROLLER_BASE_H
|
|
|
|
#define MEMORY_CONTROLLER_BASE_H
|
|
|
|
|
|
|
|
#include <cinttypes>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
|
2023-11-03 07:21:33 +00:00
|
|
|
class MMIODevice;
|
|
|
|
|
2022-08-06 17:33:25 +00:00
|
|
|
// 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),
|
|
|
|
};
|
|
|
|
|
2019-08-18 23:34:24 +00:00
|
|
|
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) */
|
2019-08-18 23:34:24 +00:00
|
|
|
};
|
|
|
|
|
2020-03-31 16:23:18 +00:00
|
|
|
/** Defines the format for the address map entry. */
|
2019-08-18 23:34:24 +00:00
|
|
|
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 */
|
2019-08-18 23:34:24 +00:00
|
|
|
} AddressMapEntry;
|
|
|
|
|
|
|
|
|
|
|
|
/** Base class for memory controllers. */
|
|
|
|
class MemCtrlBase {
|
|
|
|
public:
|
2020-03-14 13:23:46 +00:00
|
|
|
MemCtrlBase() = default;
|
2019-08-18 23:34:24 +00:00
|
|
|
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);
|
2022-12-12 08:16:59 +00:00
|
|
|
virtual bool remove_mmio_region(uint32_t start_addr, uint32_t size, MMIODevice* dev_instance);
|
2019-08-18 23:34:24 +00:00
|
|
|
|
2020-05-12 18:55:45 +00:00
|
|
|
virtual bool set_data(uint32_t reg_addr, const uint8_t* data, uint32_t size);
|
2019-08-18 23:34:24 +00:00
|
|
|
|
2020-05-12 18:55:45 +00:00
|
|
|
AddressMapEntry* find_range(uint32_t addr);
|
2022-12-12 08:13:49 +00:00
|
|
|
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);
|
|
|
|
|
2021-10-06 20:46:39 +00:00
|
|
|
AddressMapEntry* find_rom_region();
|
2019-08-18 23:34:24 +00:00
|
|
|
|
|
|
|
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);
|
2019-08-18 23:34:24 +00:00
|
|
|
|
|
|
|
private:
|
2020-05-12 18:55:45 +00:00
|
|
|
std::vector<uint8_t*> mem_regions;
|
2021-05-15 22:50:44 +00:00
|
|
|
std::vector<AddressMapEntry*> address_map;
|
2019-08-18 23:34:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* MEMORY_CONTROLLER_BASE_H */
|