2023-07-24 00:01:39 -04:00
|
|
|
#include <riscv/System.hpp>
|
|
|
|
|
|
|
|
namespace riscv {
|
|
|
|
|
|
|
|
System* System::Create(Address ramSize) {
|
|
|
|
auto* system = new System;
|
|
|
|
|
2023-07-24 00:20:40 -04:00
|
|
|
// create all the devices we require.
|
2023-07-24 00:01:39 -04:00
|
|
|
system->bus = new Bus();
|
|
|
|
system->cpu = new CPU();
|
|
|
|
system->ram = new devices::RamDevice(0x80000000, ramSize);
|
|
|
|
system->clnt = new devices::ClntDevice();
|
|
|
|
system->syscon = new devices::SysconDevice(system);
|
|
|
|
|
2023-07-24 00:20:40 -04:00
|
|
|
// techinically this is done on construction but lets be hard about it
|
2023-07-24 00:01:39 -04:00
|
|
|
system->cpu->Reset();
|
|
|
|
|
2023-07-24 00:20:40 -04:00
|
|
|
// attach everything into the bus
|
|
|
|
if(!system->bus->AttachDevice(system->cpu)) return nullptr;
|
|
|
|
if(!system->bus->AttachDevice(system->clnt)) return nullptr;
|
|
|
|
if(!system->bus->AttachDevice(system->syscon)) return nullptr;
|
|
|
|
if(!system->bus->AttachDevice(system->ram)) return nullptr;
|
2023-07-24 00:01:39 -04:00
|
|
|
|
|
|
|
return system;
|
|
|
|
}
|
|
|
|
|
|
|
|
System::~System() {
|
|
|
|
delete cpu;
|
|
|
|
delete bus; // the rest of the device pointers will be deleted by the bus.
|
|
|
|
}
|
|
|
|
|
|
|
|
void System::Step() {
|
|
|
|
// Clock the bus, it'll do everything else.
|
|
|
|
bus->Clock();
|
|
|
|
|
|
|
|
// Later: handling for invalid cases!
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace riscv
|