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/instructions | |
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/instructions')
-rw-r--r-- | qtmips_machine/instructions/arithmetic.cpp | 174 | ||||
-rw-r--r-- | qtmips_machine/instructions/arithmetic.h | 60 | ||||
-rw-r--r-- | qtmips_machine/instructions/jumpbranch.cpp | 30 | ||||
-rw-r--r-- | qtmips_machine/instructions/jumpbranch.h | 34 | ||||
-rw-r--r-- | qtmips_machine/instructions/loadstore.cpp | 67 | ||||
-rw-r--r-- | qtmips_machine/instructions/loadstore.h | 32 | ||||
-rw-r--r-- | qtmips_machine/instructions/nop.cpp | 7 | ||||
-rw-r--r-- | qtmips_machine/instructions/nop.h | 11 | ||||
-rw-r--r-- | qtmips_machine/instructions/shift.cpp | 51 | ||||
-rw-r--r-- | qtmips_machine/instructions/shift.h | 28 |
10 files changed, 0 insertions, 494 deletions
diff --git a/qtmips_machine/instructions/arithmetic.cpp b/qtmips_machine/instructions/arithmetic.cpp deleted file mode 100644 index f3cad86..0000000 --- a/qtmips_machine/instructions/arithmetic.cpp +++ /dev/null @@ -1,174 +0,0 @@ -#include "instructions/arithmetic.h" - -InstructionArithmetic::InstructionArithmetic(enum InstructionArithmeticT type, std::uint8_t rs, std::uint8_t rd, std::uint8_t rt) - : InstructionR(rs, rd, rt, 0) { - this->type = type; -} - -void InstructionArithmetic::decode(Registers *regs) { - Instruction::decode(regs); - this->rs_d = regs->read_gp(this->rs); - this->rd_d = regs->read_gp(this->rd); -} - -void InstructionArithmetic::execute() { - Instruction::execute(); - switch (this->type) { - case IAT_ADD: - this->rt_d = (std::uint32_t)((std::int32_t)this->rs_d + (std::int32_t)this->rd_d); - break; - case IAT_ADDU: - this->rt_d = this->rs_d + this->rd_d; - break; - case IAT_SUB: - this->rt_d = (std::uint32_t)((std::int32_t)this->rs_d - (std::int32_t)this->rd_d); - break; - case IAT_SUBU: - this->rt_d = this->rs_d - this->rd_d; - break; - case IAT_AND: - this->rt_d = this->rs_d & this->rd_d; - break; - case IAT_OR: - this->rt_d = this->rs_d | this->rd_d; - break; - case IAT_XOR: - this->rt_d = this->rs_d ^ this->rd_d; - break; - case IAT_NOR: - // TODO - break; - case IAT_SLT: - // TODO - break; - case IAT_SLTU: - // TODO - break; - } -} - -void InstructionArithmetic::memory(Memory *mem) { - Instruction::memory(mem); - // pass -} - -void InstructionArithmetic::write_back(Registers *regs) { - Instruction::write_back(regs); - regs->write_gp(this->rt, this->rt_d); -} - -QVector<QString> InstructionArithmetic::to_strs() { - QVector<QString> str = this->InstructionR::to_strs(); - str.erase(str.begin() + 4); // Drop sa field - switch (this->type) { - case IAT_ADD: - str[0] = "add"; - break; - case IAT_ADDU: - str[0] = "addu"; - break; - case IAT_SUB: - str[0] = "sub"; - break; - case IAT_SUBU: - str[0] = "subu"; - break; - case IAT_AND: - str[0] = "and"; - break; - case IAT_OR: - str[0] = "or"; - break; - case IAT_XOR: - str[0] = "xor"; - break; - case IAT_NOR: - str[0] = "nor"; - break; - case IAT_SLT: - str[0] = "slt"; - break; - case IAT_SLTU: - str[0] = "sltu"; - break; - default: - // TODO different exception - throw std::exception(); - } - return str; -} - -InstructionArithmeticImmediate::InstructionArithmeticImmediate(enum InstructionArithmeticImmediateT type, std::uint8_t rs, std::uint8_t rt, std::uint16_t value) - : InstructionI(rs, rt, value) { - this->type = type; -} - -void InstructionArithmeticImmediate::decode(Registers *regs) { - Instruction::decode(regs); - this->rs_d = regs->read_gp(this->rs); -} - -void InstructionArithmeticImmediate::execute() { - Instruction::execute(); - switch (this->type) { - case IAT_ADDI: - this->rt_d = (std::uint32_t)((std::int32_t)this->rs_d + (std::int32_t)this->immediate); - break; - case IAT_ADDIU: - this->rt_d = this->rs_d + this->immediate; - break; - case IAT_ANDI: - this->rt_d = (std::uint32_t)((std::int32_t)this->rs_d - (std::int32_t)this->immediate); - break; - case IAT_ORI: - this->rt_d = this->rs_d - this->immediate; - break; - case IAT_XORI: - this->rt_d = this->rs_d & this->immediate; - break; - } -} - -void InstructionArithmeticImmediate::memory(Memory *mem) { - Instruction::memory(mem); - // pass -} - -void InstructionArithmeticImmediate::write_back(Registers *regs) { - Instruction::write_back(regs); - regs->write_gp(this->rt, this->rt_d); -} - -QVector<QString> InstructionArithmeticImmediate::to_strs() { - QVector<QString> str = this->InstructionI::to_strs(); - switch (this->type) { - case IAT_ADDI: - str[0] = "addi"; - break; - case IAT_ADDIU: - str[0] = "addiu"; - break; - case IAT_ANDI: - str[0] = "andi"; - break; - case IAT_ORI: - str[0] = "ori"; - break; - case IAT_XORI: - str[0] = "xori"; - break; - case IAT_SLTI: - str[0] = "slti"; - break; - case IAT_SLTIU: - str[0] = "sltiu"; - break; - case IAT_LUI: - str[0] = "lui"; - break; - default: - // TODO different exception - throw std::exception(); - } - return str; -} diff --git a/qtmips_machine/instructions/arithmetic.h b/qtmips_machine/instructions/arithmetic.h deleted file mode 100644 index 185ed95..0000000 --- a/qtmips_machine/instructions/arithmetic.h +++ /dev/null @@ -1,60 +0,0 @@ -#ifndef ARITHMETIC_H -#define ARITHMETIC_H - -#include "instruction.h" - -enum InstructionArithmeticT { - IAT_ADD, // Add - IAT_ADDU, // Add unsigned - IAT_SUB, // Subtract - IAT_SUBU, // Subtract unsigned - IAT_AND, - IAT_OR, - IAT_XOR, - IAT_NOR, - IAT_SLT, // set on less than - IAT_SLTU, // set on less than unsigned -}; - -class InstructionArithmetic : public InstructionR { -public: - InstructionArithmetic(enum InstructionArithmeticT type, std::uint8_t rs, std::uint8_t rd, std::uint8_t rt); - - void decode(Registers *regs); - void execute(); - void memory(Memory *mem); - void write_back(Registers *regs); - - QVector<QString> to_strs(); -private: - enum InstructionArithmeticT type; - std::uint32_t rs_d, rd_d, rt_d; -}; - -enum InstructionArithmeticImmediateT { - IAT_ADDI, - IAT_ADDIU, - IAT_ANDI, - IAT_ORI, - IAT_XORI, - IAT_SLTI, - IAT_SLTIU, - IAT_LUI -}; - -class InstructionArithmeticImmediate : public InstructionI { -public: - InstructionArithmeticImmediate(enum InstructionArithmeticImmediateT type, std::uint8_t rs, std::uint8_t rt, std::uint16_t value); - - void decode(Registers *regs); - void execute(); - void memory(Memory *mem); - void write_back(Registers *regs); - - QVector<QString> to_strs(); -private: - enum InstructionArithmeticImmediateT type; - std::uint32_t rs_d, rt_d; -}; - -#endif // ARITHMETIC_H diff --git a/qtmips_machine/instructions/jumpbranch.cpp b/qtmips_machine/instructions/jumpbranch.cpp deleted file mode 100644 index 6579c2b..0000000 --- a/qtmips_machine/instructions/jumpbranch.cpp +++ /dev/null @@ -1,30 +0,0 @@ -#include "jumpbranch.h" - -InstructionJump::InstructionJump(bool link, std::uint32_t address) - : InstructionJ(address) { - this->link = link; -} - -QVector<QString> InstructionJump::to_strs() { - QVector<QString> str = this->InstructionJ::to_strs(); - if (link) - str[0] = "j"; - else - str[0] = "jal"; - return str; -} - -InstructionJumpRegister::InstructionJumpRegister(bool link, std::uint8_t rs) - : InstructionR(rs, 0, 0, 0) { - this->link = link; -} - -QVector<QString> InstructionJumpRegister::to_strs() { - QVector<QString> str = this->InstructionR::to_strs(); - str.erase(str.begin() + 2, str.end()); // Drop every field after rs - if (link) - str[0] = "j"; - else - str[0] = "jal"; - return str; -} diff --git a/qtmips_machine/instructions/jumpbranch.h b/qtmips_machine/instructions/jumpbranch.h deleted file mode 100644 index 762ad95..0000000 --- a/qtmips_machine/instructions/jumpbranch.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef JUMPBRANCH_H -#define JUMPBRANCH_H - -#include "instruction.h" - -class InstructionJump : InstructionJ { -public: - InstructionJump(bool link, std::uint32_t address); - QVector<QString> to_strs(); -private: - bool link; -}; - -class InstructionJumpRegister : InstructionR { -public: - InstructionJumpRegister(bool link, std::uint8_t rs); - QVector<QString> to_strs(); -private: - bool link; -}; - -enum InstructionBranchT { - -}; - -class InstructionBranch : InstructionI { -public: - InstructionBranch(); - QVector<QString> to_strs(); -private: - // TODO -}; - -#endif // JUMPBRANCH_H diff --git a/qtmips_machine/instructions/loadstore.cpp b/qtmips_machine/instructions/loadstore.cpp deleted file mode 100644 index 27c6402..0000000 --- a/qtmips_machine/instructions/loadstore.cpp +++ /dev/null @@ -1,67 +0,0 @@ -#include "loadstore.h" - -InstructionLoad::InstructionLoad(enum InstructionLoadStoreT type, std::uint8_t rs, std::uint8_t rt, std::uint16_t offset) - : InstructionI(rs, rt, offset) { - this->type = type; -} - -QVector<QString> InstructionLoad::to_strs() { - QVector<QString> str = this->InstructionI::to_strs(); - switch (this->type) { - case ILST_B: - str[0] = "lb"; - break; - case ILST_HW: - str[0] = "lh"; - break; - case ILST_WL: - str[0] = "lwl"; - break; - case ILST_W: - str[0] = "lw"; - break; - case ILST_BU: - str[0] = "lbu"; - break; - case ILST_HU: - str[0] = "lhu"; - break; - case ILST_WR: - str[0] = "lwr"; - break; - default: - // TODO different exception - throw std::exception(); - } - return str; -} - -InstructionStore::InstructionStore(enum InstructionLoadStoreT type, std::uint8_t rs, std::uint8_t rt, std::uint16_t offset) - : InstructionI(rs, rt, offset) { - this->type = type; -} - -QVector<QString> InstructionStore::to_strs() { - QVector<QString> str = this->InstructionI::to_strs(); - switch (this->type) { - case ILST_B: - str[0] = "sb"; - break; - case ILST_HW: - str[0] = "sh"; - break; - case ILST_WL: - str[0] = "swl"; - break; - case ILST_W: - str[0] = "sw"; - break; - case ILST_WR: - str[0] = "swr"; - break; - default: - // TODO different exception - throw std::exception(); - } - return str; -} diff --git a/qtmips_machine/instructions/loadstore.h b/qtmips_machine/instructions/loadstore.h deleted file mode 100644 index 6f028fd..0000000 --- a/qtmips_machine/instructions/loadstore.h +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef LOADSTORE_H -#define LOADSTORE_H - -#include "instruction.h" - -enum InstructionLoadStoreT { - ILST_B, // Byte - ILST_HW, // Half word - ILST_WL, // Word left - ILST_W, // Word - ILST_BU, // Byte unsigned - ILST_HU, // Half word unsigned - ILST_WR // Word right -}; - -class InstructionLoad : public InstructionI { -public: - InstructionLoad(enum InstructionLoadStoreT type, std::uint8_t rs, std::uint8_t rt, std::uint16_t offset); - QVector<QString> to_strs(); -private: - enum InstructionLoadStoreT type; -}; - -class InstructionStore : public InstructionI { -public: - InstructionStore(enum InstructionLoadStoreT type, std::uint8_t rs, std::uint8_t rt, std::uint16_t offset); - QVector<QString> to_strs(); -private: - enum InstructionLoadStoreT type; -}; - -#endif // LOADSTORE_H diff --git a/qtmips_machine/instructions/nop.cpp b/qtmips_machine/instructions/nop.cpp deleted file mode 100644 index 7623dff..0000000 --- a/qtmips_machine/instructions/nop.cpp +++ /dev/null @@ -1,7 +0,0 @@ -#include "nop.h" - -QVector<QString> InstructionNop::to_strs() { - QVector<QString> str; - str << QString("nop"); - return str; -} diff --git a/qtmips_machine/instructions/nop.h b/qtmips_machine/instructions/nop.h deleted file mode 100644 index 5c019fd..0000000 --- a/qtmips_machine/instructions/nop.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef NOP_H -#define NOP_H - -#include "instruction.h" - -class InstructionNop : public Instruction { -public: - QVector<QString> to_strs(); -}; - -#endif // NOP_H diff --git a/qtmips_machine/instructions/shift.cpp b/qtmips_machine/instructions/shift.cpp deleted file mode 100644 index 34bc1c9..0000000 --- a/qtmips_machine/instructions/shift.cpp +++ /dev/null @@ -1,51 +0,0 @@ -#include "shift.h" - -InstructionShift::InstructionShift(enum InstructionShiftT type, std::uint8_t rt, std::uint8_t rd, std::uint8_t sa) - : InstructionR(0, rt, rd, sa) { - this->type = type; -} - -QVector<QString> InstructionShift::to_strs() { - QVector<QString> str = this->InstructionR::to_strs(); - str.erase(str.begin() + 1); // Drop rs field - switch (this->type) { - case IST_LL: - str[0] = "sll"; - break; - case IST_RL: - str[0] = "srl"; - break; - case IST_RA: - str[0] = "sra"; - break; - default: - // TODO different exception - throw std::exception(); - } - return str; -} - -InstructionShiftVariable::InstructionShiftVariable(enum InstructionShiftT type, std::uint8_t rs, std::uint8_t rt, std::uint8_t rd) - : InstructionR(rs, rt, rd, 0) { - this->type = type; -} - -QVector<QString> InstructionShiftVariable::to_strs() { - QVector<QString> str = this->InstructionR::to_strs(); - str.erase(str.begin() + 4); // Drop sa field - switch (this->type) { - case IST_LL: - str[0] = "sllv"; - break; - case IST_RL: - str[0] = "srlv"; - break; - case IST_RA: - str[0] = "srav"; - break; - default: - // TODO different exception - throw std::exception(); - } - return str; -} diff --git a/qtmips_machine/instructions/shift.h b/qtmips_machine/instructions/shift.h deleted file mode 100644 index 69e2e1e..0000000 --- a/qtmips_machine/instructions/shift.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef SHIFT_H -#define SHIFT_H - -#include "instruction.h" - -enum InstructionShiftT { - IST_LL, // Left logical - IST_RL, // Right logical - IST_RA // Right arithmetic -}; - -class InstructionShift : public InstructionR { -public: - InstructionShift(enum InstructionShiftT type, std::uint8_t rt, std::uint8_t rd, std::uint8_t sa); - QVector<QString> to_strs(); -private: - enum InstructionShiftT type; -}; - -class InstructionShiftVariable : public InstructionR { -public: - InstructionShiftVariable(enum InstructionShiftT type, std::uint8_t rs, std::uint8_t rt, std::uint8_t rd); - QVector<QString> to_strs(); -private: - enum InstructionShiftT type; -}; - -#endif // SHIFT_H |