-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPipe.py
125 lines (105 loc) · 2.98 KB
/
Pipe.py
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
import Format
import Address
class IFID:
def __init__(self):
self.pc = '0' * 32
self.instruction = 0
self.IFFlush = 0
self.IFWrite = 0
def update(self, pc, instruction, IFFlush, IFWrtie):
self.pc = pc
self.instruction = instruction
self.IFFlush = IFFlush
self.IFWrite = IFWrtie
if IFFlush == 1 and IFWrtie == 1:
self.flush()
def flush(self):
self.pc = Address.Address32(0)
self.instruction = Format.RFormat('0' * 6, '0' * 5, '0' * 5, '0' * 5, '0' * 5, '0' * 6)
self.IFFlush = 0
class IDEX:
def __init__(self):
self.pc = 0
self.r1 = 0
self.r2 = 0
self.rs = 0
self.rt = 0
self.rd = 0
self.signextended = '0' * 32
# EX control signals
self.aluop = 'x0x'
self.RegDst = 0
# Mem control signals
self.MemWrite = 0
self.MemRead = 0
# WB control signals
self.MemtoReg = 0
self.RegWrite = 0
def update(self, pc, ifidrs, ifidrt, ifidrd, r1, r2, signextended, aluop, RegDst, MemWrite, MemRead, MemtoReg,
RegWrite):
self.pc = pc
self.rs = ifidrs
self.rt = ifidrt
self.rd = ifidrd
self.r1 = r1
self.r2 = r2
self.signextended = signextended
self.aluop = aluop
self.RegDst = RegDst
self.MemWrite = MemWrite
self.MemRead = MemRead
self.MemtoReg = MemtoReg
self.RegWrite = RegWrite
def zerocontrol(self):
# EX control signals
self.aluop = 'x0x'
self.RegDst = 0
# Mem control signals
self.MemWrite = 0
self.MemRead = 0
# WB control signals
self.MemtoReg = 0
self.RegWrite = 0
class EXMEM:
def __init__(self):
self.result = 0
self.wdata = 0
self.rd = 0
# WB control signals
self.MemtoReg = 0
self.RegWrite = 0
# Mem control signals
self.MemWrite = 0
self.MemRead = 0
def update(self, result, wdata, exmemrd, MemtoReg, RegWrite, MemWrite):
self.result = result
self.wdata = wdata
self.rd = exmemrd
self.MemtoReg = MemtoReg
self.RegWrite = RegWrite
self.MemWrite = MemWrite
def zerocontrol(self):
# WB control signals
self.MemtoReg = 0
self.RegWrite = 0
# Mem control signals
self.MemWrite = 0
self.MemRead = 0
class MEMWB:
def __init__(self):
self.rdata = 0
self.result = 0
self.rd = 0
# WB control signals
self.MemtoReg = 0
self.RegWrite = 0
def update(self, rdata, result, memwbrd, MemtoReg, RegWrite):
self.rdata = rdata
self.result = result
self.rd = memwbrd
self.MemtoReg = MemtoReg
self.RegWrite = RegWrite
def zerocontrol(self):
# WB control signals
self.MemtoReg = 0
self.RegWrite = 0