diff --git a/native/projects/riscv/include/riscv/Bus.hpp b/native/projects/riscv/include/riscv/Bus.hpp index 5f0080b..9275f94 100644 --- a/native/projects/riscv/include/riscv/Bus.hpp +++ b/native/projects/riscv/include/riscv/Bus.hpp @@ -92,11 +92,10 @@ namespace riscv { virtual void Poke(AddressT address, u32 value) = 0; }; - Bus(CPU* cpu); + /// Bus destructor. + /// This frees the memory for all devices. ~Bus(); - CPU* GetCPU() { return attachedCpu; } - /// Attach a device to the bus. /// /// Note that once this function is called (and the device is successfully added), @@ -106,8 +105,8 @@ namespace riscv { /// This function returns true if the device was able to be put on the bus. /// This function returns false in the following error cases: /// - [device] is a null pointer - /// - if [device] is a memory device (and thus reserves address space), adding it would - /// end up shadowing another previously-added device. + /// - If [device] is a memory device (and thus reserves some address space), adding it + /// to the address space would end up shadowing another previously-added device. bool AttachDevice(Device* device); /// Clock all clocked devices mapped onto the bus.. @@ -124,11 +123,6 @@ namespace riscv { private: Bus::Device* FindDeviceForAddress(AddressT address) const; - // TODO: The CPU needs not be a separate member or be treated specially, it too can be a Bus::Device now - // In fact that would probably be really clean and elegant for calling Step() properly - - CPU* attachedCpu {}; - /// All devices attached to the bus std::vector devices; diff --git a/native/projects/riscv/include/riscv/System.hpp b/native/projects/riscv/include/riscv/System.hpp index e20eca9..0d67cb2 100644 --- a/native/projects/riscv/include/riscv/System.hpp +++ b/native/projects/riscv/include/riscv/System.hpp @@ -12,7 +12,9 @@ namespace riscv { /// Create static System* WithMemory(AddressT ramSize); - void AddDevice(Bus::MmioDevice* device); + ~System(); + + void AddDeviceToBus(Bus::Device* device); /// returns false if the cpu broke execution bool Step(); @@ -29,6 +31,7 @@ namespace riscv { /// How many instructions will the CPU execute each step u32 ipsRate; + // Most of our basic required devices. CPU* cpu; Bus* bus; devices::RamDevice* ram; diff --git a/native/projects/riscv/src/Bus.cpp b/native/projects/riscv/src/Bus.cpp index 454878f..34d5e97 100644 --- a/native/projects/riscv/src/Bus.cpp +++ b/native/projects/riscv/src/Bus.cpp @@ -1,13 +1,8 @@ #include #include -#include "riscv/Types.hpp" - namespace riscv { - Bus::Bus(CPU* cpu) : attachedCpu(cpu) { - } - Bus::~Bus() { // Free all devices for(auto device: devices)