From c1208b398e41cbde077e914a94de16ee63761a3c Mon Sep 17 00:00:00 2001 From: Maxim Poliakovski Date: Fri, 21 Jan 2022 11:16:34 +0100 Subject: [PATCH] Add posti-initialization to HW components. --- devices/common/hwcomponent.h | 4 ++++ machines/machinebase.cpp | 17 +++++++++++++++++ machines/machinebase.h | 1 + machines/machinegossamer.cpp | 6 ++++++ machines/machinepdm.cpp | 8 +++++++- 5 files changed, 35 insertions(+), 1 deletion(-) diff --git a/devices/common/hwcomponent.h b/devices/common/hwcomponent.h index fd805ba..8688a57 100644 --- a/devices/common/hwcomponent.h +++ b/devices/common/hwcomponent.h @@ -57,6 +57,10 @@ public: virtual bool supports_type(HWCompType type) = 0; + virtual int device_postinit() { + return 0; + }; + protected: std::string name; }; diff --git a/machines/machinebase.cpp b/machines/machinebase.cpp index 87829e1..6f234dd 100644 --- a/machines/machinebase.cpp +++ b/machines/machinebase.cpp @@ -119,3 +119,20 @@ HWComponent* MachineBase::get_comp_by_type(HWCompType type) { return NULL; } } + +int MachineBase::postinit_devices() +{ + for (auto it = this->comp_map.begin(); it != this->comp_map.end(); it++) { + if (it->second->device_postinit()) { + return -1; + } + } + + for (auto it = this->subdev_map.begin(); it != this->subdev_map.end(); it++) { + if (it->second->device_postinit()) { + return -1; + } + } + + return 0; +} diff --git a/machines/machinebase.h b/machines/machinebase.h index e45de44..1154fd2 100644 --- a/machines/machinebase.h +++ b/machines/machinebase.h @@ -43,6 +43,7 @@ public: void add_alias(std::string name, std::string alias); HWComponent* get_comp_by_name(std::string name); HWComponent* get_comp_by_type(HWCompType type); + int postinit_devices(); private: std::string name; diff --git a/machines/machinegossamer.cpp b/machines/machinegossamer.cpp index d3aab33..ced226e 100644 --- a/machines/machinegossamer.cpp +++ b/machines/machinegossamer.cpp @@ -103,6 +103,12 @@ int create_gossamer(std::string& id) { /* Init virtual CPU and request MPC750 CPU aka G3 */ ppc_cpu_init(grackle_obj, PPC_VER::MPC750); + // post-initialize all devices + if (gMachineObj->postinit_devices()) { + LOG_F(ERROR, "Could not post-initialize devices!\n"); + return -1; + } + /* check for a floppy image to be inserted into the virtual superdrive */ std::string fdd_path = GET_STR_PROP("fdd_img"); if (!fdd_path.empty()) { diff --git a/machines/machinepdm.cpp b/machines/machinepdm.cpp index c1d1fdb..4ff5e75 100644 --- a/machines/machinepdm.cpp +++ b/machines/machinepdm.cpp @@ -59,7 +59,7 @@ int create_pdm(std::string& id) { /* get raw pointer to HMC object */ HMC* hmc_obj = dynamic_cast(gMachineObj->get_comp_by_name("HMC")); - /* allocate machine ID register and tell we're running PowerMac 6100 */ + // allocate machine ID register and tell we're running PowerMac 6100 // TODO: add a possibility to select another machine // to be used with the same ROM gMachineObj->add_component("MachineID", new NubusMacID(0x3010)); @@ -87,6 +87,12 @@ int create_pdm(std::string& id) { /* Init virtual CPU and request MPC601 */ ppc_cpu_init(hmc_obj, PPC_VER::MPC601); + // post-initialize all devices + if (gMachineObj->postinit_devices()) { + LOG_F(ERROR, "Could not post-initialize devices!\n"); + return -1; + } + /* check for a floppy image to be inserted into the virtual superdrive */ std::string fdd_path = GET_STR_PROP("fdd_img"); if (!fdd_path.empty()) {