forked from vxd555/CPUpipelining
-
Notifications
You must be signed in to change notification settings - Fork 1
/
potok.hpp
187 lines (153 loc) · 4.37 KB
/
potok.hpp
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#ifndef __POTOK__
#define __POTOK__
#include <iostream>
#include <vector>
//#define WORD_SIZE 64 //bit | zamiast tego struct instruction{};
#define IF_PC_SIZE 8
//#define IF_REGISTER_SIZE 16 <- będzie z pliku wiadomo
#define MEM_REGISTER_SIZE 16
enum instructionType //Dzięki Maćku :)
{
Rtype = 0, //instrukcje operacji może być uzywany jako zapełniacz
ADD = 1, //dodanie
MUL = 2, //mnożenie
SUB = 3, //odejmowanie
SW = 4, //zapisanie z reg -> mem
LW = 5, //wczytanie z mem -> reg
BEQ = 6, //skok warunkwy
NOP = 7 //nic
};
struct IF_ID;
struct ID_EX;
struct EX_MEM;
struct MEM_WB;
struct instruction;
struct mux221;
class IF;
struct ID_REGISTER;
class ID;
class EX;
struct MEM_REGISTER;
class MEM;
struct WB;
struct IF_ID
{
int nextInstruction;
instruction actualInstruction;
};
struct ID_EX
{
int nextInstruction,
DataA, //ReadData1
DataB, //ReadData2
offset; //signed extand
};
struct EX_MEM
{
int nextInstruction, //ADD result
isJump, //Zero
//ALU result
//DataB
};
struct MEM_WB
{
int readedData; //dane z pamięci
//Address
};
struct instruction
{
instructionType insType;
int R1,
R2,
R3;
};
struct mux221
{
int A, // returned if FALSE
B; // returned if TRUE
int control(int val)
{
return val ? B : A;
}
};
/***************************************** IF: Instruction fetch section *****************************************/
class IF
{
int pc;
vector<instruction> IF_REGISTER; // register in IF section
mux221 instructionSelect; //multiplexer który wybiera czy wykonujemy skok czy nie
IF_ID *registerIFID;
//funkcja PC += 1;
};
/******************************* ID: Instruction decode / register file read section *******************************/
struct ID_REGISTER
{
ID_REGISTER();
friend class ID;
};
class ID
{
ID_REGISTER* t pc;ID_REG;
//ten odczyt i zapis zrobimy na maskach np. ReadRegister1 odczytamy tak:
// 0xF000 && instrukcja;
ID_SIGN_EXTEND(/* tu przekażemy tylko te bity które są potrzebne a rozszerzenie zrobimy na przesunięciach bitowych */);
friend class EX;
};
/************************************ EX: Execute / address calculation section ************************************/
class EX
{
//shift 2
// ↓
//add → wynik do multipleksera w IF_ADD;
// ↑
//wynik z IF_ADD
//shift 2
// ↓
//multiplekser → X
// ↑
//readData2 z ID_REGISTER
//ReadData1 z ID_REGISTER
// ↓
//ALU
// ↑
// X
friend struct IF_ADD;
friend struct ID_REGISTER;
};
/******************************************** MEM: Memory access section ********************************************/
struct MEM_REGISTER
{
MEM_REGISTER(); //konstruowanie pamięci, jej rozmiaru itd;
};
class MEM
{
MEM_REGISTER* MEM_REG;
//ALU result z EX → this->Address
//ReadData2 z ID_REGISTER → this->WriteData
friend class EX;
friend struct ID_REGISTER;
};
/********************************************** WB: Write back section **********************************************/
struct WB
{
//ReadData z MEM_REGISTER
// ↓
//multiplekser → WriteData z ID_REGISTER
// ↑
//ALU Result z EX
friend struct MEM_REGISTER;
friend class EX;
};
class RISC //: OPTIONAL → multibase incheritance
{
IF instructionFetch;
IF_ID registerIFID;
ID instructionDecode;
ID_EX registerIDEX;
EX instructionExecute;
EX_MEM registerEXMEM;
MEM instructionMemory;
MEM_WB registerMEMWB;
WB instructionWriteBack;
};
#endif /* __POTOK__ */