Remove all special treatment of the CPU class
This commit is contained in:
parent
8eaf05a8ac
commit
6a3170dc5c
|
@ -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<Device*> devices;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -1,13 +1,8 @@
|
|||
#include <algorithm>
|
||||
#include <riscv/Bus.hpp>
|
||||
|
||||
#include "riscv/Types.hpp"
|
||||
|
||||
namespace riscv {
|
||||
|
||||
Bus::Bus(CPU* cpu) : attachedCpu(cpu) {
|
||||
}
|
||||
|
||||
Bus::~Bus() {
|
||||
// Free all devices
|
||||
for(auto device: devices)
|
||||
|
|
Loading…
Reference in New Issue