diff options
-rw-r--r-- | qtmips_gui/coreview/memory.cpp | 4 | ||||
-rw-r--r-- | qtmips_machine/machineconfig.cpp | 71 | ||||
-rw-r--r-- | qtmips_machine/machineconfig.h | 42 | ||||
-rw-r--r-- | qtmips_machine/qtmipsmachine.cpp | 19 |
4 files changed, 95 insertions, 41 deletions
diff --git a/qtmips_gui/coreview/memory.cpp b/qtmips_gui/coreview/memory.cpp index 13355db..cde1c72 100644 --- a/qtmips_gui/coreview/memory.cpp +++ b/qtmips_gui/coreview/memory.cpp @@ -18,9 +18,7 @@ Memory::Memory(machine::QtMipsMachine *machine) : QGraphicsObject(nullptr) { con_req_write = new Connector(M_PI_2); con_req_read = new Connector(M_PI_2); - if (machine->config().cache()) { - // TODO cache? - } + // TODO cache? name = new QGraphicsSimpleTextItem("Memory", this); QRectF name_box = name->boundingRect(); diff --git a/qtmips_machine/machineconfig.cpp b/qtmips_machine/machineconfig.cpp index cf8629c..e479d66 100644 --- a/qtmips_machine/machineconfig.cpp +++ b/qtmips_machine/machineconfig.cpp @@ -2,18 +2,36 @@ using namespace machine; +MachineConfigCache::MachineConfigCache() { + // TODO +} + +MachineConfigCache::MachineConfigCache(const MachineConfigCache *cc) { + // TODO +} + +bool MachineConfigCache::operator==(const MachineConfigCache &c) const { + // TODO + return true; +} + +bool MachineConfigCache::operator!=(const MachineConfigCache &c) const { + return !operator==(c); +} + MachineConfig::MachineConfig() { pipeline = false; delayslot = true; - cache_type = CCT_NONE; - elf_path = QString(""); + hunit = HU_STALL_FORWARD; } MachineConfig::MachineConfig(const MachineConfig *cc) { pipeline = cc->pipelined(); delayslot = cc->delay_slot(); - cache_type = cc->cache(); elf_path = cc->elf(); + cch_program = cc->cache_program(); + cch_data = cc->cache_data(); + hunit = cc->hazard_unit(); } void MachineConfig::set_pipelined(bool v) { @@ -26,14 +44,22 @@ void MachineConfig::set_delay_slot(bool v) { pipeline = false; } -void MachineConfig::set_cache(enum CacheType cc) { - cache_type = cc; -} - void MachineConfig::set_elf(QString path) { elf_path = path; } +void MachineConfig::set_cache_program(const MachineConfigCache &c) { + cch_program = c; +} + +void MachineConfig::set_cache_data(const MachineConfigCache &c) { + cch_data = c; +} + +void MachineConfig::set_hazard_unit(enum MachineConfig::HazardUnit hu) { + hunit = hu; +} + bool MachineConfig::pipelined() const { return pipeline; } @@ -42,10 +68,33 @@ bool MachineConfig::delay_slot() const { return delayslot; } -enum MachineConfig::CacheType MachineConfig::cache() const { - return cache_type; -} - QString MachineConfig::elf() const { return elf_path; } + +MachineConfigCache MachineConfig::cache_program() const { + return cch_program; +} + +MachineConfigCache MachineConfig::cache_data() const { + return cch_data; +} + +enum MachineConfig::HazardUnit MachineConfig::hazard_unit() const { + return hunit; +} + +bool MachineConfig::operator==(const MachineConfig &c) const { +#define CMP(GETTER) (GETTER)() == (c.GETTER)() + return CMP(pipelined) && \ + CMP(delay_slot) && \ + CMP(elf) && \ + CMP(cache_program) && \ + CMP(cache_data) && \ + CMP(hazard_unit); +#undef CMP +} + +bool MachineConfig::operator!=(const MachineConfig &c) const { + return !operator==(c); +} diff --git a/qtmips_machine/machineconfig.h b/qtmips_machine/machineconfig.h index c55228a..10b8458 100644 --- a/qtmips_machine/machineconfig.h +++ b/qtmips_machine/machineconfig.h @@ -5,38 +5,60 @@ namespace machine { +class MachineConfigCache { +public: + MachineConfigCache(); + MachineConfigCache(const MachineConfigCache *cc); + + // TODO + + bool operator ==(const MachineConfigCache &c) const; + bool operator !=(const MachineConfigCache &c) const; + +private: + // TODO +}; + class MachineConfig { public: MachineConfig(); MachineConfig(const MachineConfig *cc); - enum CacheType { - CCT_NONE, - CCT_ASSOCIATIVE, - // TODO + enum HazardUnit { + HU_NONE, + HU_STALL, + HU_STALL_FORWARD }; // Configure if CPU is pipelined // In default disabled. void set_pipelined(bool); - // Configure if we want to do jump prediction + // Configure if cpu should simulate delay slot in non-pipelined core // In default enabled. When disabled it also automatically disables pipelining. void set_delay_slot(bool); - // Configure cache type - // In default CCT_NONE is used. - void set_cache(enum CacheType); // Set path to source elf file. This has to be set before core is initialized. void set_elf(QString path); + // Configure cache + void set_cache_program(const MachineConfigCache&); + void set_cache_data(const MachineConfigCache&); + // Hazard unit + void set_hazard_unit(enum HazardUnit); bool pipelined() const; bool delay_slot() const; - enum CacheType cache() const; QString elf() const; + MachineConfigCache cache_program() const; + MachineConfigCache cache_data() const; + enum HazardUnit hazard_unit() const; + + bool operator ==(const MachineConfig &c) const; + bool operator !=(const MachineConfig &c) const; private: bool pipeline, delayslot; - enum CacheType cache_type; QString elf_path; + MachineConfigCache cch_program, cch_data; + enum HazardUnit hunit; }; } diff --git a/qtmips_machine/qtmipsmachine.cpp b/qtmips_machine/qtmipsmachine.cpp index f2683fb..c60cdce 100644 --- a/qtmips_machine/qtmipsmachine.cpp +++ b/qtmips_machine/qtmipsmachine.cpp @@ -14,25 +14,10 @@ QtMipsMachine::QtMipsMachine(const MachineConfig &cc) : QObject(), mcnf(&cc) { regs = new Registers(); mem = new Memory(*mem_program_only); - MemoryAccess *coremem; - switch (cc.cache()) { - case MachineConfig::CCT_NONE: - cch = nullptr; - coremem = mem; - break; - case MachineConfig::CCT_ASSOCIATIVE: - // TODO - coremem = mem; - //coremem = cch = new CacheAssociative(); - break; - default: - throw QTMIPS_EXCEPTION(Sanity, "Trying to configure unknown cache type", ""); - } - if (cc.pipelined()) - cr = new CorePipelined(regs, coremem); + cr = new CorePipelined(regs, mem); else - cr = new CoreSingle(regs, coremem, cc.delay_slot()); + cr = new CoreSingle(regs, mem, cc.delay_slot()); run_t = new QTimer(this); set_speed(0); // In default run as fast as possible |