-
Notifications
You must be signed in to change notification settings - Fork 1
/
StageID.cpp
113 lines (85 loc) · 3.1 KB
/
StageID.cpp
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#ifndef VM_Stage_ID
#define VM_Stage_ID
#include <stdint.h>
#include "HwError.hpp"
#include "Component.hpp"
#include "InstructionType.hpp"
#include "Pipeline.hpp"
#include "RegisterFile.cpp"
#include "ConstantGenerator.hpp"
namespace Stage
{
class ID : public Component::Component_t
{
private:
Component::IntegerRegisterFile RegF;
Component::ConstantGenerator Gen;
public:
Component::Component_ID GetID() override
{
return Component::Component_ID_StageID;
}
HwError Setup() override
{
HwError result = RegF.Setup();
if( result != HwError_NoError )
return result;
result = Gen.Setup();
return result;
}
Pipeline_IDtoEX Perform( Pipeline_IFtoID pipe, Instruction::ParsedInstruction instr )
{
SetLastHwError( HwError_NoError );
Pipeline_IDtoEX result;
// Copy over the unused stuff;
result.CopyFromLast( pipe );
uint64_t leConst = 0;
uint64_t RegVal1 = 0;
uint64_t RegVal2 = 0;
uint64_t PCVal = pipe.PCCalc.PCVal;
// Generate constant
if( pipe.IDParams.DoGenConst )
leConst = Gen.GenerateConst( instr, pipe.IDParams.SignExtend );
SetLastHwError( Gen.LastHwError() );
if( LastHwError() != HwError_NoError )
{
result.SetALUInputs( RegVal1, RegVal2, leConst, PCVal );
result.SetMemParam( RegVal2 );
return result;
}
// Read Registers
if( pipe.IDParams.ReadRegisters & 0b01 )
{
RegVal1 = RegF.GetVal( pipe.IDParams.ReadReg1 );
SetLastHwError( RegF.LastHwError() );
if( LastHwError() != HwError_NoError )
{
result.SetALUInputs( RegVal1, RegVal2, leConst, PCVal );
result.SetMemParam( RegVal2 );
return result;
}
}
else
RegVal1 = 0;
if( pipe.IDParams.ReadRegisters & 0b10 )
{
RegVal2 = RegF.GetVal( pipe.IDParams.ReadReg2 );
SetLastHwError( RegF.LastHwError() );
if( LastHwError() != HwError_NoError )
{
result.SetALUInputs( RegVal1, RegVal2, leConst, PCVal );
result.SetMemParam( RegVal2 );
return result;
}
}
result.SetALUInputs( RegVal1, RegVal2, leConst, PCVal );
result.SetMemParam( RegVal2 );
return result;
}
Component::IntegerRegisterFile * GetRegFForWB()
{
return &RegF;
}
};
};
#endif