dingusppc/devices/memctrl/memctrlbase.h
Mihai Parparita 35c86ad6bf Clean up #includes
Result of running IWYU (https://include-what-you-use.org/) and
applying most of the suggestions about unncessary includes and
forward declarations.

Was motivated by observing that <thread> was being included in
ppcopcodes.cpp even though it was unused (found while researching
the use of threads), but seems generally good to help with build
times and correctness.
2023-11-03 00:33:47 -07:00

93 lines
3.2 KiB
C++

/*
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 {
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 {
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:
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);
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);
virtual bool set_data(uint32_t reg_addr, const uint8_t* data, uint32_t size);
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:
bool add_mem_region(
uint32_t start_addr, uint32_t size, uint32_t dest_addr, uint32_t type, uint8_t init_val);
private:
std::vector<uint8_t*> mem_regions;
std::vector<AddressMapEntry*> address_map;
};
#endif /* MEMORY_CONTROLLER_BASE_H */