-
Notifications
You must be signed in to change notification settings - Fork 21
/
mriscvcore.v
executable file
·250 lines (217 loc) · 4.6 KB
/
mriscvcore.v
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
`timescale 1ns / 1ps
/*
mriscvcore
by CKDUR
This is the definitive core.
*/
module mriscvcore(
input clk,
input rstn,
// AXI-4 LITE INTERFACE
input [31:0] Rdata,
input ARready,
input Rvalid,
input AWready,
input Wready,
input Bvalid,
output [31:0] AWdata,
output [31:0] ARdata,
output [31:0] Wdata,
output ARvalid,
output RReady,
output AWvalid,
output Wvalid,
output [2:0] ARprot,AWprot,
output Bready,
output [3:0] Wstrb,
// IRQ interface
input [31:0] inirr,
output [31:0] outirr,
output trap
);
// SIGNAL DECLARATION *********************************************************
// Data Buses
wire [31:0] rd, rs1, rs2, imm, pc, inst;
wire [11:0] code;
wire [11:0] codif;
// Auxiliars
wire [4:0] rs1i, rs2i, rdi;
//IRQ SIGNALS
wire [31:0] pc_c, addrm, pc_irq;
wire flag;
//MEMORY INTERFACE SIGNALS
wire is_rd_mem;
wire [1:0] W_R_mem, wordsize_mem;
wire sign_mem, en_mem, busy_mem, done_mem, align_mem;
//SIGNALS DECO INST
wire enableDec;
//SIGNALS MULT
wire enable_mul, done_mul, is_inst_mul;
//SIGNALS ALU
wire cmp, carry, enable_alu, is_inst_alu, is_rd_alu;
//SIGNALS UTILITY
wire is_inst_util, is_rd_util;
//SIGNALS FSM
wire is_exec;
// DATAPATH PHASE *************************************************************
MEMORY_INTERFACE MEMORY_INTERFACE_inst(
.clock(clk),
.resetn(rstn),
// Data buses
.rs1(rs1),
.rs2(rs2),
.rd(rd),
.imm(imm),
.pc(pc),
.rd_en(is_rd_mem),
// AXI4-Interface
.Rdata_mem(Rdata),
.ARready(ARready),
.Rvalid(Rvalid),
.AWready(AWready),
.Wready(Wready),
.Bvalid(Bvalid),
.AWdata(AWdata),
.ARdata(ARdata),
.Wdata(Wdata),
.ARvalid(ARvalid),
.RReady(RReady),
.AWvalid(AWvalid),
.Wvalid(Wvalid),
.arprot(ARprot),
.awprot(AWprot),
.Bready(Bready),
.Wstrb(Wstrb),
// To DECO_INSTR
.inst(inst),
// To FSM
.W_R(W_R_mem),
.wordsize(wordsize_mem),
.signo(sign_mem),
.enable(en_mem),
.busy(busy_mem),
.done(done_mem),
.align(align_mem)
);
DECO_INSTR DECO_INSTR_inst(
.clk(clk),
// From MEMORY_INTERFACE
.inst(inst),
// Auxiliars to BUS
.rs1i(rs1i),
.rs2i(rs2i),
.rdi(rdi),
.imm(imm),
.code(code),
.codif(codif)
);
REG_FILE REG_FILE_inst(
.clk(clk),
.rst(rstn),
.rd(rd),
.rdi(rdi),
.rdw_rsrn(rdw_rsrn),
.rs1(rs1),
.rs1i(rs1i),
.rs2(rs2),
.rs2i(rs2i)
);
ALU ALU_inst(
.clk(clk),
.reset(rstn),
// Data Buses
.rs1(rs1),
.rs2(rs2),
.rd(rd),
.decinst(code),
.imm(imm),
// To UTILITY
.cmp(cmp),
// To FSM
.en(enable_alu),
.carry(carry),
.is_rd(is_rd_alu),
.is_inst(is_inst_alu)
);
IRQ IRQ_inst(
.rst(rstn),
.clk(clk),
.savepc(1'b0),
.en(1'b0),
.instr(code),
.rs1(rs1),
.rs2(rs2),
.inirr(inirr),
.pc(pc),
.imm(imm),
.rd(rd),
.addrm(addrm),
.outirr(outirr),
.pc_irq(pc_irq),
.pc_c(pc_c),
.flag(flag)
);
MULT MULT_inst(
.clk(clk),
.reset(rstn),
.rs1(rs1),
.rs2(rs2),
.rd(rd),
.Enable(enable_mul),
.is_oper(is_inst_mul),
.Done(done_mul),
.codif(code)
);
UTILITY UTILITY_inst(
.clk(clk),
.rst(rstn),
// FROM DATA BUS
.rs1(rs1),
.rd(rd),
.opcode(code),
.imm(imm),
.pc(pc),
// FROM IRQ
.irr_ret(pc_c),
.irr_dest(pc_irq),
// FROM ALU
.branch(cmp),
// FSM
.irr(1'b0),
.enable_pc(enable_pc),
.is_inst(is_inst_util),
.is_rd(is_rd_util)
);
// FINITE-STATE MACHINE PHASE *************************************************
FSM FSM_inst
(
.clk(clk),
.reset(rstn),
// Auxiliars from DATAPATH
.codif(codif),
// Inputs from DATAPATH
.busy_mem(busy_mem),
.done_mem(done_mem),
.aligned_mem(align_mem),
.done_exec(done_exec),
.is_exec(is_exec),
// Outputs to DATAPATH
.W_R_mem(W_R_mem),
.wordsize_mem(wordsize_mem),
.sign_mem(sign_mem),
.en_mem(en_mem),
.enable_exec(enable_exec),
.enable_exec_mem(enable_exec_mem),
.trap(trap),
.enable_pc(enable_pc)
);
// Enable Assign
assign enable_mul = enable_exec;
assign enable_alu = enable_exec;
// Done Assign
assign done_exec = is_inst_util | is_inst_alu | (done_mul & is_inst_mul);
// Is exec assign
assign is_exec = ~(&(code));
// Write to rd flag
assign rdw_rsrn = (is_rd_util | is_rd_alu | done_mul | (is_rd_mem & done_mem)) & (enable_exec | enable_exec_mem);
endmodule