diff options
author | Karel Kočí <cynerd@email.cz> | 2017-11-19 21:23:04 +0100 |
---|---|---|
committer | Karel Kočí <cynerd@email.cz> | 2017-11-19 21:23:04 +0100 |
commit | f0ad502e4651243d6a96194b3393bd460c0f7fc9 (patch) | |
tree | 4f912c24b5943bd93b5a3378df75f9611de6779b /qtmips_machine/registers.cpp | |
parent | 2c6562fa78e884d66b8c2a306f020101e8803f2e (diff) | |
download | qtmips-f0ad502e4651243d6a96194b3393bd460c0f7fc9.tar.gz qtmips-f0ad502e4651243d6a96194b3393bd460c0f7fc9.tar.bz2 qtmips-f0ad502e4651243d6a96194b3393bd460c0f7fc9.zip |
Another huge pile of work for about two months
Well I should commit every change instead of this madness. I am not
documenting changes as all this is just improvements and implementation
progression.
Diffstat (limited to 'qtmips_machine/registers.cpp')
-rw-r--r-- | qtmips_machine/registers.cpp | 29 |
1 files changed, 26 insertions, 3 deletions
diff --git a/qtmips_machine/registers.cpp b/qtmips_machine/registers.cpp index 837f403..fa984fb 100644 --- a/qtmips_machine/registers.cpp +++ b/qtmips_machine/registers.cpp @@ -14,12 +14,21 @@ Registers::Registers() { this->hi = this->lo = 0; } -std::uint32_t Registers::read_pc() { +Registers::Registers(const Registers *orig) : Registers() { + this->pc = orig->read_pc(); + for (int i = 0; i < 31; i++) + this->gp[i] = orig->read_gp(i); + this->lo = orig->read_hi_lo(false); + this->hi = orig->read_hi_lo(true); +} + +std::uint32_t Registers::read_pc() const { return this->pc; } std::uint32_t Registers::pc_inc() { this->pc += 4; + emit pc_update(this->pc); return this->pc; } @@ -27,6 +36,7 @@ std::uint32_t Registers::pc_jmp(std::int32_t offset) { if (offset % 4) throw QTMIPS_EXCEPTION(UnalignedJump, "Trying to jump by unaligned offset", QString::number(offset, 16)); this->pc += offset; + emit pc_update(this->pc); return this->pc; } @@ -36,7 +46,7 @@ void Registers::pc_abs_jmp(std::uint32_t address) { this->pc = address; } -std::uint32_t Registers::read_gp(std::uint8_t i) { +std::uint32_t Registers::read_gp(std::uint8_t i) const { SANITY_ASSERT(i < 32, QString("Trying to read from register ") + QString(i)); if (!i) // $0 always reads as 0 return 0; @@ -50,7 +60,7 @@ void Registers::write_gp(std::uint8_t i, std::uint32_t value) { this->gp[i - 1] = value; } -std::uint32_t Registers::read_hi_lo(bool hi) { +std::uint32_t Registers::read_hi_lo(bool hi) const { if (hi) return this->hi; else @@ -63,3 +73,16 @@ void Registers::write_hi_lo(bool hi, std::uint32_t value) { else this->lo = value; } + +bool Registers::operator ==(const Registers &c) const { + if (read_pc() != c.read_pc()) + return false; + for (int i = 0; i < 31; i++) + if (read_gp(i) != c.read_gp(i)) + return false; + if (read_hi_lo(false) != c.read_hi_lo(false)) + return false; + if (read_hi_lo(true) != c.read_hi_lo(true)) + return false; + return true; +} |