Add AddressMap class for defining physical maps.

This commit is contained in:
Maxim Poliakovski 2019-08-07 20:13:55 +02:00
parent a469bcf900
commit aec95254a8
3 changed files with 97 additions and 14 deletions

36
addressmap.cpp Normal file
View File

@ -0,0 +1,36 @@
#include <iostream>
#include "addressmap.h"
AddressMap::AddressMap()
{
this->address_map.clear();
}
AddressMap::~AddressMap()
{
for (auto &entry : address_map) {
if (entry.devobj)
delete(entry.devobj);
}
this->address_map.clear();
}
void AddressMap::add(AddressMapEntry &entry)
{
if (entry.type & RT_ROM) {
printf("ROM entry added.\n");
printf("entry.mem_ptr = %llx\n", (uint64_t)entry.mem_ptr);
}
address_map.push_back(entry);
}
AddressMapEntry *AddressMap::get_range(uint32_t addr)
{
for (auto &entry : address_map) {
if (addr >= entry.start && addr <= entry.end)
return &entry;
}
return 0;
}

39
addressmap.h Normal file
View File

@ -0,0 +1,39 @@
#ifndef ADDRESS_MAP_H
#define ADDRESS_MAP_H
#include <cinttypes>
#include <vector>
#include "mmiodevice.h"
typedef uint32_t (*DevRead) (uint32_t offset, int size);
typedef void (*DevWrite)(uint32_t offset, uint32_t value, int size);
enum RangeType {
RT_ROM = 1,
RT_RAM = 2,
RT_MMIO = 4, /* memory mapped I/O */
RT_MIRROR = 8
};
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;
class AddressMap {
public:
AddressMap();
~AddressMap();
void add(AddressMapEntry &entry);
AddressMapEntry *get_range(uint32_t addr);
private:
std::vector<AddressMapEntry> address_map;
};
#endif /* ADDRESS_MAP_H_ */

View File

@ -1,6 +1,11 @@
OBJS = main.o macioserial.o macscsi.o macswim3.o mpc106.o openpic.o poweropcodes.o ppcfpopcodes.o ppcgekkoopcodes.o ppcmemory.o ppcopcodes.o viacuda.o davbus.o debugger.o
SOURCE = main.cpp macioserial.cpp macscsi.cpp macswim3.cpp mpc106.cpp openpic.cpp poweropcodes.cpp ppcfpopcodes.cpp ppcgekkoopcodes.cpp ppcmemory.cpp ppcopcodes.cpp viacuda.cpp davbus.cpp debugger.cpp
HEADER = macioserial.h macscsi.h macswim3.h mpc106.h openpic.h ppcemumain.h ppcmemory.h viacuda.h debugger.h
OBJS = main.o macioserial.o macscsi.o macswim3.o mpc106.o openpic.o poweropcodes.o \
ppcfpopcodes.o ppcgekkoopcodes.o ppcmemory.o ppcopcodes.o viacuda.o davbus.o \
debugger.o addressmap.o
SOURCE = main.cpp macioserial.cpp macscsi.cpp macswim3.cpp mpc106.cpp openpic.cpp \
poweropcodes.cpp ppcfpopcodes.cpp ppcgekkoopcodes.cpp ppcmemory.cpp \
ppcopcodes.cpp viacuda.cpp davbus.cpp debugger.cpp addressmap.cpp
HEADER = macioserial.h macscsi.h macswim3.h mpc106.h openpic.h ppcemumain.h ppcmemory.h \
viacuda.h debugger.h addressmap.h
OUT = dingusppc
CC = g++
FLAGS = -g -c -Wall -std=c++11
@ -51,5 +56,8 @@ davbus.o: davbus.cpp
debugger.o: debugger.cpp
$(CC) $(FLAGS) debugger.cpp
addressmap.o: addressmap.cpp
$(CC) $(FLAGS) addressmap.cpp
clean:
rm -f $(OBJS) $(OUT)