mirror of
https://github.com/dingusdev/dingusppc.git
synced 2024-06-06 16:29:33 +00:00
Introduce subdevices interface.
This commit is contained in:
parent
d53400ebae
commit
14156dd32b
|
@ -29,6 +29,7 @@ add_executable(dingusppc ${SOURCES} $<TARGET_OBJECTS:cpu_ppc>
|
||||||
|
|
||||||
add_executable(testppc ${TEST_SOURCES} $<TARGET_OBJECTS:cpu_ppc>
|
add_executable(testppc ${TEST_SOURCES} $<TARGET_OBJECTS:cpu_ppc>
|
||||||
$<TARGET_OBJECTS:devices>
|
$<TARGET_OBJECTS:devices>
|
||||||
|
$<TARGET_OBJECTS:machines>
|
||||||
$<TARGET_OBJECTS:loguru>)
|
$<TARGET_OBJECTS:loguru>)
|
||||||
|
|
||||||
add_custom_command(
|
add_custom_command(
|
||||||
|
|
|
@ -24,6 +24,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include "macio.h"
|
#include "macio.h"
|
||||||
#include "viacuda.h"
|
#include "viacuda.h"
|
||||||
|
#include "machines/machinebase.h"
|
||||||
|
|
||||||
/** Heathrow Mac I/O device emulation.
|
/** Heathrow Mac I/O device emulation.
|
||||||
|
|
||||||
|
@ -36,6 +37,8 @@ HeathrowIC::HeathrowIC() : PCIDevice("mac-io/heathrow")
|
||||||
{
|
{
|
||||||
this->viacuda = new ViaCuda();
|
this->viacuda = new ViaCuda();
|
||||||
this->nvram = new NVram();
|
this->nvram = new NVram();
|
||||||
|
|
||||||
|
gMachineObj->add_subdevice("ViaCuda", this->viacuda);
|
||||||
}
|
}
|
||||||
|
|
||||||
HeathrowIC::~HeathrowIC()
|
HeathrowIC::~HeathrowIC()
|
||||||
|
|
|
@ -13,6 +13,7 @@ MachineBase::MachineBase(std::string name)
|
||||||
|
|
||||||
/* initialize internal maps */
|
/* initialize internal maps */
|
||||||
this->comp_map.clear();
|
this->comp_map.clear();
|
||||||
|
this->subdev_map.clear();
|
||||||
this->aliases.clear();
|
this->aliases.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,9 +23,11 @@ MachineBase::~MachineBase()
|
||||||
delete it->second;
|
delete it->second;
|
||||||
}
|
}
|
||||||
this->comp_map.clear();
|
this->comp_map.clear();
|
||||||
|
this->aliases.clear();
|
||||||
|
this->subdev_map.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MachineBase::add_component(std::string name, HWCompType type, HWComponent *dev_obj)
|
bool MachineBase::add_component(std::string name, HWComponent *dev_obj)
|
||||||
{
|
{
|
||||||
if (this->comp_map.count(name)) {
|
if (this->comp_map.count(name)) {
|
||||||
LOG_F(ERROR, "Component %s already exists!", name.c_str());
|
LOG_F(ERROR, "Component %s already exists!", name.c_str());
|
||||||
|
@ -36,9 +39,21 @@ bool MachineBase::add_component(std::string name, HWCompType type, HWComponent *
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MachineBase::add_alias(std::string name, std::string alias, HWCompType type)
|
bool MachineBase::add_subdevice(std::string name, HWComponent *dev_obj)
|
||||||
{
|
{
|
||||||
this->aliases[alias] = name;
|
if (this->subdev_map.count(name)) {
|
||||||
|
LOG_F(ERROR, "Subdevice %s already exists!", name.c_str());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
this->subdev_map[name] = dev_obj;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MachineBase::add_alias(std::string name, std::string alias)
|
||||||
|
{
|
||||||
|
this->aliases[alias] = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
HWComponent *MachineBase::get_comp_by_name(std::string name)
|
HWComponent *MachineBase::get_comp_by_name(std::string name)
|
||||||
|
@ -49,6 +64,10 @@ HWComponent *MachineBase::get_comp_by_name(std::string name)
|
||||||
|
|
||||||
if (this->comp_map.count(name)) {
|
if (this->comp_map.count(name)) {
|
||||||
return this->comp_map[name];
|
return this->comp_map[name];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this->subdev_map.count(name)) {
|
||||||
|
return this->subdev_map[name];
|
||||||
} else {
|
} else {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -67,8 +86,21 @@ HWComponent *MachineBase::get_comp_by_type(HWCompType type)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!found)
|
if (found) {
|
||||||
return NULL;
|
return this->get_comp_by_name(comp_name);
|
||||||
|
}
|
||||||
|
|
||||||
return this->get_comp_by_name(comp_name);
|
for(auto it = this->subdev_map.begin(); it != this->subdev_map.end(); it++) {
|
||||||
|
if (it->second->supports_type(type)) {
|
||||||
|
comp_name = it->first;
|
||||||
|
found = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (found) {
|
||||||
|
return this->get_comp_by_name(comp_name);
|
||||||
|
} else {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,14 +38,16 @@ public:
|
||||||
MachineBase(std::string name);
|
MachineBase(std::string name);
|
||||||
~MachineBase();
|
~MachineBase();
|
||||||
|
|
||||||
bool add_component(std::string name, HWCompType type, HWComponent *dev_obj);
|
bool add_component(std::string name, HWComponent *dev_obj);
|
||||||
void add_alias(std::string name, std::string alias, HWCompType type);
|
bool add_subdevice(std::string name, HWComponent *dev_obj);
|
||||||
|
void add_alias(std::string name, std::string alias);
|
||||||
HWComponent *get_comp_by_name(std::string name);
|
HWComponent *get_comp_by_name(std::string name);
|
||||||
HWComponent *get_comp_by_type(HWCompType type);
|
HWComponent *get_comp_by_type(HWCompType type);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string name;
|
std::string name;
|
||||||
std::map<std::string, HWComponent *>comp_map;
|
std::map<std::string, HWComponent *>comp_map;
|
||||||
|
std::map<std::string, HWComponent *>subdev_map;
|
||||||
std::map<std::string, std::string> aliases;
|
std::map<std::string, std::string> aliases;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -45,20 +45,19 @@ int create_gossamer()
|
||||||
gMachineObj.reset(new MachineBase("Gossamer"));
|
gMachineObj.reset(new MachineBase("Gossamer"));
|
||||||
|
|
||||||
/* register MPC106 aka Grackle as memory controller and PCI host */
|
/* register MPC106 aka Grackle as memory controller and PCI host */
|
||||||
gMachineObj->add_component("Grackle", HWCompType::MEM_CTRL, new MPC106);
|
gMachineObj->add_component("Grackle", new MPC106);
|
||||||
gMachineObj->add_alias("Grackle", "PCI_Host", HWCompType::PCI_HOST);
|
gMachineObj->add_alias("Grackle", "PCI_Host");
|
||||||
|
|
||||||
/* get raw pointer to MPC106 object */
|
/* get raw pointer to MPC106 object */
|
||||||
MPC106 *grackle_obj = dynamic_cast<MPC106 *>(gMachineObj->get_comp_by_name("Grackle"));
|
MPC106 *grackle_obj = dynamic_cast<MPC106 *>(gMachineObj->get_comp_by_name("Grackle"));
|
||||||
|
|
||||||
/* add the machine ID register */
|
/* add the machine ID register */
|
||||||
gMachineObj->add_component("MachineID", HWCompType::MMIO_DEV,
|
gMachineObj->add_component("MachineID", new GossamerID(0x3d8c));
|
||||||
new GossamerID(0x3d8c));
|
|
||||||
grackle_obj->add_mmio_region(0xFF000004, 4096,
|
grackle_obj->add_mmio_region(0xFF000004, 4096,
|
||||||
dynamic_cast<MMIODevice *>(gMachineObj->get_comp_by_name("MachineID")));
|
dynamic_cast<MMIODevice *>(gMachineObj->get_comp_by_name("MachineID")));
|
||||||
|
|
||||||
/* add the Heathrow I/O controller */
|
/* add the Heathrow I/O controller */
|
||||||
gMachineObj->add_component("Heathrow", HWCompType::MMIO_DEV, new HeathrowIC);
|
gMachineObj->add_component("Heathrow", new HeathrowIC);
|
||||||
grackle_obj->pci_register_device(16,
|
grackle_obj->pci_register_device(16,
|
||||||
dynamic_cast<PCIDevice *>(gMachineObj->get_comp_by_name("Heathrow")));
|
dynamic_cast<PCIDevice *>(gMachineObj->get_comp_by_name("Heathrow")));
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user