From f0ad502e4651243d6a96194b3393bd460c0f7fc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karel=20Ko=C4=8D=C3=AD?= Date: Sun, 19 Nov 2017 21:23:04 +0100 Subject: 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. --- qtmips_machine/instruction.h | 66 +++++++++++--------------------------------- 1 file changed, 16 insertions(+), 50 deletions(-) (limited to 'qtmips_machine/instruction.h') diff --git a/qtmips_machine/instruction.h b/qtmips_machine/instruction.h index 8c5ede9..3b76fba 100644 --- a/qtmips_machine/instruction.h +++ b/qtmips_machine/instruction.h @@ -2,64 +2,30 @@ #define INSTRUCTION_H #include -#include -#include "registers.h" -#include "memory.h" - -enum InstructionState { - IS_FETCH, - IS_DECODE, - IS_EXECUTE, - IS_MEMORY, - IS_WRITE_BACK, -}; class Instruction { public: - Instruction(); + Instruction(std::uint32_t inst); + Instruction(std::uint8_t opcode, std::uint8_t rs, std::uint8_t rt, std::uint8_t rd, std::uint8_t shamt, std::uint8_t funct); // Type R + Instruction(std::uint8_t opcode, std::uint8_t rs, std::uint8_t rt, std::uint16_t immediate); // Type I + Instruction(std::uint8_t opcode, std::uint32_t address); // Type J - // TODO return some info for forwarding, stall, flush - virtual void decode(Registers *regs); // Read and prepare instructions - virtual void execute(); // ALU operations - virtual void memory(Memory *mem); // Read or write to memory - virtual void write_back(Registers *regs); // Write results to registers + QString to_str(); - enum InstructionState state(); - bool running(); - bool done(); + std::uint8_t opcode() const; + std::uint8_t rs() const; + std::uint8_t rt() const; + std::uint8_t rd() const; + std::uint8_t shamt() const; + std::uint8_t funct() const; + std::uint16_t immediate() const; + std::uint32_t address() const; + std::uint32_t data() const; - virtual QVector to_strs() = 0; // Returns all fields of instructions in string + bool operator ==(const Instruction &c) const; private: - enum InstructionState st; -}; - -class InstructionR : public Instruction { -public: - InstructionR(std::uint8_t rs, std::uint8_t rd, std::uint8_t rt, std::uint8_t sa); - - QVector to_strs(); -protected: - std::uint8_t rs, rd, rt, sa; -}; - -class InstructionI : public Instruction { -public: - InstructionI(std::uint8_t rs, std::uint8_t rt, std::uint16_t immediate); - - QVector to_strs(); -protected: - std::uint8_t rs, rt; - std::uint16_t immediate; -}; - -class InstructionJ : public Instruction { -public: - InstructionJ(std::uint32_t address); - - QVector to_strs(); -protected: - std::uint32_t address; + std::uint32_t dt; }; #endif // INSTRUCTION_H -- cgit v1.2.3