-
Notifications
You must be signed in to change notification settings - Fork 1
/
instruction_encdec.h
88 lines (65 loc) · 1.68 KB
/
instruction_encdec.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
88
#ifndef INSTRUCTION_ENCDEC_H
#define INSTRUCTION_ENCDEC_H
#include <cstdint>
namespace RISCV_EMULATOR {
// TODO: In the current Emulator code, these classes are not being used. Shall they be removed from the test code too?
class BitField {
public:
virtual uint32_t GetValue() = 0;
virtual void SetValue(uint32_t value) = 0;
uint8_t opcode: 7;
uint8_t rd: 5;
uint8_t rs2: 5;
uint8_t rs1: 5;
uint8_t funct3: 3;
};
class RType : public BitField {
public:
uint8_t funct7: 7;
uint32_t GetValue() override;
void SetValue(uint32_t value) override;
};
class IType : public BitField {
public:
int16_t imm12: 12;
uint32_t GetValue() override ;
void SetValue(uint32_t value) override;
};
class SType : public BitField {
public:
int16_t imm12: 12;
uint32_t GetValue() override ;
void SetValue(uint32_t value) override;
};
class BType : public BitField {
public:
int16_t imm13: 13;
uint32_t GetValue() override ;
void SetValue(uint32_t value) override;
};
class JType : public BitField {
public:
int32_t imm21: 21;
uint32_t GetValue() override ;
void SetValue(uint32_t value) override;
};
class UType : public BitField {
public:
uint32_t imm20: 24;
uint32_t GetValue() override ;
void SetValue(uint32_t value) override;
};
int32_t GetImm(uint32_t ir);
uint32_t GetOpcode(uint32_t ir);
uint32_t GetRd(uint32_t ir);
uint32_t GetRs1(uint32_t ir);
uint32_t GetRs2(uint32_t ir);
int32_t GetImm12(uint32_t ir);
int32_t GetCsr(uint32_t ir);
int32_t GetImm13(uint32_t ir);
int32_t GetImm21(uint32_t ir);
uint32_t GetImm20(uint32_t ir);
int32_t GetStypeImm12(uint32_t ir);
uint32_t GetShamt(uint32_t ir);
} // namespace // RISCV_EMULATOR
#endif // INSTRUCTION_ENCDEC_H