aboutsummaryrefslogtreecommitdiff
path: root/qtmips_machine/instruction.h
blob: 8c5ede9965a556a1a21dc056f8c46286cacc7a99 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#ifndef INSTRUCTION_H
#define INSTRUCTION_H

#include <qstring.h>
#include <qvector.h>
#include "registers.h"
#include "memory.h"

enum InstructionState {
    IS_FETCH,
    IS_DECODE,
    IS_EXECUTE,
    IS_MEMORY,
    IS_WRITE_BACK,
};

class Instruction {
public:
    Instruction();

    // 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

    enum InstructionState state();
    bool running();
    bool done();

    virtual QVector<QString> to_strs() = 0; // Returns all fields of instructions in string

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<QString> 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<QString> to_strs();
protected:
    std::uint8_t rs, rt;
    std::uint16_t immediate;
};

class InstructionJ : public Instruction {
public:
    InstructionJ(std::uint32_t address);

    QVector<QString> to_strs();
protected:
    std::uint32_t address;
};

#endif // INSTRUCTION_H