-
Notifications
You must be signed in to change notification settings - Fork 0
/
AbstractInstruction.h
87 lines (79 loc) · 1.73 KB
/
AbstractInstruction.h
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#ifndef __ABSTRACTINSTRUCTION__
#define __ABSTRACTINSTRUCTION__
#include "../emustd.h"
#include "./sets/AbstractISA.h"
// #include "../bytemanip.h"
// #include "../hw/RegisterFile.h"
// #include "../hw/Memory.h"
// #include "../units/AbstractBranchPredictor.h"
// #include "../units/PipelineHazardController.h"
#define OPCODE_MAX 127
#define R_MAX 31
#define FUNC3_MAX 7
#define FUNC7_MAX 127
#define INSTRUCTION_SIZE 4
enum InstructionType {
R,
I,
S,
B,
U,
J
};
class InstructionException: public exception {
private:
const char* message;
public:
InstructionException() {}
InstructionException(const char* message, ...) {
this->message = message;
}
const char* getMessage() {
return message;
}
};
class AbstractInstruction {
protected:
byte opcode;
byte rs1;
byte rs2;
byte rd;
byte func3;
byte func7;
bytes imm;
InstructionType type;
bytes rs1Val;
bytes rs2Val;
bytes result;
bytes pc;
bool isSigned;
ushort XLEN = 0;
public:
AbstractInstruction() { this->XLEN = 0; }
AbstractInstruction(ushort XLEN) { this->XLEN = XLEN; }
virtual void decode(bytes instruction) {};
byte getOpcode();
byte getRS1();
byte getRS2();
byte getRD();
byte getFunc3();
byte getFunc7();
bytes getImm();
bytes getImm(ushort low, ushort high);
InstructionType getType();
bytes getRs1Val();
void setRs1Val(bytes val);
bytes getRs2Val();
void setRs2Val(bytes val);
bytes getResult();
void setResult(bytes val);
bytes getPC();
void setPC(bytes val);
bool isSignedImmediate();
ushort getXLEN();
virtual string debug() { return string(""); };
ExecuteRoutine execute = nullptr;
WritebackRoutine registerWriteback = nullptr;
MemoryAccessRoutine memoryAccess = nullptr;
};
#endif