OpenCores
URL https://opencores.org/ocsvn/mips32r1/mips32r1/trunk

Subversion Repositories mips32r1

[/] [mips32r1/] [trunk/] [Hardware/] [MIPS32_Standalone/] [Processor.v] - Blame information for rev 12

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 ayersg
`timescale 1ns / 1ps
2
/*
3
 * File         : Processor.v
4
 * Project      : University of Utah, XUM Project MIPS32 core
5
 * Creator(s)   : Grant Ayers (ayers@cs.utah.edu)
6
 *
7
 * Modification History:
8
 *   Rev   Date         Initials  Description of Change
9
 *   1.0   23-Jul-2011  GEA       Initial design.
10
 *   2.0   26-May-2012  GEA       Release version with CP0.
11 7 ayersg
 *   2.01   1-Nov-2012  GEA       Fixed issue with Jal.
12 2 ayersg
 *
13
 * Standards/Formatting:
14
 *   Verilog 2001, 4 soft tab, wide column.
15
 *
16
 * Description:
17
 *   The top-level MIPS32 Processor. This file is mostly the instantiation
18
 *   and wiring of the building blocks of the processor according to the
19
 *   hardware design diagram. It contains very little logic itself.
20
 */
21
module Processor(
22 3 ayersg
    input  clock,
23
    input  reset,
24 2 ayersg
    input  [4:0] Interrupts,            // 5 general-purpose hardware interrupts
25
    input  NMI,                         // Non-maskable interrupt
26 3 ayersg
    // Data Memory Interface
27
    input  [31:0] DataMem_In,
28
    input  DataMem_Ready,
29
    output DataMem_Read,
30 2 ayersg
    output [3:0]  DataMem_Write,        // 4-bit Write, one for each byte in word.
31 3 ayersg
    output [29:0] DataMem_Address,      // Addresses are words, not bytes.
32
    output [31:0] DataMem_Out,
33
    // Instruction Memory Interface
34
    input  [31:0] InstMem_In,
35
    output [29:0] InstMem_Address,      // Addresses are words, not bytes.
36
    input  InstMem_Ready,
37
    output InstMem_Read,
38 2 ayersg
    output [7:0] IP                     // Pending interrupts (diagnostic)
39 3 ayersg
    );
40 2 ayersg
 
41
    `include "MIPS_Parameters.v"
42
 
43
 
44
    /*** MIPS Instruction and Components (ID Stage) ***/
45
    wire [31:0] Instruction;
46
    wire [5:0]  OpCode = Instruction[31:26];
47
    wire [4:0]  Rs = Instruction[25:21];
48
    wire [4:0]  Rt = Instruction[20:16];
49
    wire [4:0]  Rd = Instruction[15:11];
50
    wire [5:0]  Funct = Instruction[5:0];
51
    wire [15:0] Immediate = Instruction[15:0];
52
    wire [25:0] JumpAddress = Instruction[25:0];
53
    wire [2:0]  Cp0_Sel = Instruction[2:0];
54
 
55
    /*** IF (Instruction Fetch) Signals ***/
56
    wire IF_Stall, IF_Flush;
57
    wire IF_EXC_AdIF;
58
    wire IF_Exception_Stall;
59
    wire IF_Exception_Flush;
60
    wire IF_IsBDS;
61
    wire [31:0] IF_PCAdd4, IF_PC_PreExc, IF_PCIn, IF_PCOut, IF_Instruction;
62
 
63
    /*** ID (Instruction Decode) Signals ***/
64
    wire ID_Stall;
65
    wire [1:0] ID_PCSrc;
66
    wire [1:0] ID_RsFwdSel, ID_RtFwdSel;
67
    wire ID_Link, ID_Movn, ID_Movz;
68
    wire ID_SignExtend;
69
    wire ID_LLSC;
70
    wire ID_RegDst, ID_ALUSrcImm, ID_MemWrite, ID_MemRead, ID_MemByte, ID_MemHalf, ID_MemSignExtend, ID_RegWrite, ID_MemtoReg;
71
    wire [4:0] ID_ALUOp;
72
    wire ID_Mfc0, ID_Mtc0, ID_Eret;
73
    wire ID_NextIsDelay;
74
    wire ID_CanErr, ID_ID_CanErr, ID_EX_CanErr, ID_M_CanErr;
75
    wire ID_KernelMode;
76
    wire ID_ReverseEndian;
77
    wire ID_Trap, ID_TrapCond;
78
    wire ID_EXC_Sys, ID_EXC_Bp, ID_EXC_RI;
79
    wire ID_Exception_Stall;
80
    wire ID_Exception_Flush;
81
    wire ID_PCSrc_Exc;
82
    wire [31:0] ID_ExceptionPC;
83
    wire ID_CP1, ID_CP2, ID_CP3;
84
    wire [31:0] ID_PCAdd4;
85
    wire [31:0] ID_ReadData1_RF, ID_ReadData1_End;
86
    wire [31:0] ID_ReadData2_RF, ID_ReadData2_End;
87
    wire [31:0] CP0_RegOut;
88
    wire ID_CmpEQ, ID_CmpGZ, ID_CmpLZ, ID_CmpGEZ, ID_CmpLEZ;
89
    wire [29:0] ID_SignExtImm = (ID_SignExtend & Immediate[15]) ? {14'h3FFF, Immediate} : {14'h0000, Immediate};
90
    wire [31:0] ID_ImmLeftShift2 = {ID_SignExtImm[29:0], 2'b00};
91
    wire [31:0] ID_JumpAddress = {ID_PCAdd4[31:28], JumpAddress[25:0], 2'b00};
92
    wire [31:0] ID_BranchAddress;
93
    wire [31:0] ID_RestartPC;
94
    wire ID_IsBDS;
95
    wire ID_Left, ID_Right;
96
    wire ID_IsFlushed;
97
 
98
    /*** EX (Execute) Signals ***/
99 10 ayersg
    wire EX_ALU_Stall, EX_Stall;
100 2 ayersg
    wire [1:0] EX_RsFwdSel, EX_RtFwdSel;
101
    wire EX_Link;
102
    wire [1:0] EX_LinkRegDst;
103
    wire EX_ALUSrcImm;
104
    wire [4:0] EX_ALUOp;
105
    wire EX_Movn, EX_Movz;
106
    wire EX_LLSC;
107
    wire EX_MemRead, EX_MemWrite, EX_MemByte, EX_MemHalf, EX_MemSignExtend, EX_RegWrite, EX_MemtoReg;
108
    wire [4:0] EX_Rs, EX_Rt;
109
    wire EX_WantRsByEX, EX_NeedRsByEX, EX_WantRtByEX, EX_NeedRtByEX;
110
    wire EX_Trap, EX_TrapCond;
111
    wire EX_CanErr, EX_EX_CanErr, EX_M_CanErr;
112
    wire EX_KernelMode;
113
    wire EX_ReverseEndian;
114
    wire EX_Exception_Stall;
115
    wire EX_Exception_Flush;
116
    wire [31:0] EX_ReadData1_PR, EX_ReadData1_Fwd, EX_ReadData2_PR, EX_ReadData2_Fwd, EX_ReadData2_Imm;
117
    wire [31:0] EX_SignExtImm;
118
    wire [4:0] EX_Rd, EX_RtRd, EX_Shamt;
119
    wire [31:0] EX_ALUResult;
120
    wire EX_BZero;
121
    wire EX_EXC_Ov;
122
    wire [31:0] EX_RestartPC;
123
    wire EX_IsBDS;
124
    wire EX_Left, EX_Right;
125
 
126
    /*** MEM (Memory) Signals ***/
127
    wire M_Stall, M_Stall_Controller;
128
    wire M_LLSC;
129
    wire M_MemRead, M_MemWrite, M_MemByte, M_MemHalf, M_MemSignExtend;
130
    wire M_RegWrite, M_MemtoReg;
131
    wire M_WriteDataFwdSel;
132
    wire M_EXC_AdEL, M_EXC_AdES;
133
    wire M_M_CanErr;
134
    wire M_KernelMode;
135
    wire M_ReverseEndian;
136
    wire M_Trap, M_TrapCond;
137
    wire M_EXC_Tr;
138
    wire M_Exception_Flush;
139
    wire [31:0] M_ALUResult, M_ReadData2_PR;
140
    wire [4:0] M_RtRd;
141
    wire [31:0] M_MemReadData;
142
    wire [31:0] M_RestartPC;
143
    wire M_IsBDS;
144
    wire [31:0] M_WriteData_Pre;
145
    wire M_Left, M_Right;
146
    wire M_Exception_Stall;
147
 
148
    /*** WB (Writeback) Signals ***/
149
    wire WB_Stall, WB_RegWrite;
150
    wire [31:0] WB_ReadData, WB_ALUResult;
151
    wire [4:0]  WB_RtRd;
152
    wire [31:0] WB_WriteData;
153
 
154
    /*** Other Signals ***/
155
    wire [7:0] ID_DP_Hazards, HAZ_DP_Hazards;
156
 
157
    /*** Assignments ***/
158
    assign IF_Instruction = (IF_Stall) ? 32'h00000000 : InstMem_In;
159
    assign IF_IsBDS = ID_NextIsDelay;
160
    assign HAZ_DP_Hazards = {ID_DP_Hazards[7:4], EX_WantRsByEX, EX_NeedRsByEX, EX_WantRtByEX, EX_NeedRtByEX};
161
    assign IF_EXC_AdIF = IF_PCOut[1] | IF_PCOut[0];
162
    assign ID_CanErr = ID_ID_CanErr | ID_EX_CanErr | ID_M_CanErr;
163
    assign EX_CanErr = EX_EX_CanErr | EX_M_CanErr;
164
    assign M_CanErr  = M_M_CanErr;
165
 
166
    // External Memory Interface
167
    reg IRead, IReadMask;
168
    assign InstMem_Address = IF_PCOut[31:2];
169
    assign DataMem_Address = M_ALUResult[31:2];
170
    always @(posedge clock) begin
171
        IRead <= (reset) ? 1 : ~InstMem_Ready;
172
        IReadMask <= (reset) ? 0 : ((IRead & InstMem_Ready) ? 1 : ((~IF_Stall) ? 0 : IReadMask));
173
    end
174
    assign InstMem_Read = IRead & ~IReadMask;
175
 
176
 
177
    /*** Datapath Controller ***/
178
    Control Controller (
179
        .ID_Stall       (ID_Stall),
180
        .OpCode         (OpCode),
181
        .Funct          (Funct),
182
        .Rs             (Rs),
183
        .Rt             (Rt),
184
        .Cmp_EQ         (ID_CmpEQ),
185
        .Cmp_GZ         (ID_CmpGZ),
186
        .Cmp_GEZ        (ID_CmpGEZ),
187
        .Cmp_LZ         (ID_CmpLZ),
188
        .Cmp_LEZ        (ID_CmpLEZ),
189
        .IF_Flush       (IF_Flush),
190
        .DP_Hazards     (ID_DP_Hazards),
191
        .PCSrc          (ID_PCSrc),
192
        .SignExtend     (ID_SignExtend),
193
        .Link           (ID_Link),
194
        .Movn           (ID_Movn),
195
        .Movz           (ID_Movz),
196
        .Mfc0           (ID_Mfc0),
197
        .Mtc0           (ID_Mtc0),
198
        .CP1            (ID_CP1),
199
        .CP2            (ID_CP2),
200
        .CP3            (ID_CP3),
201
        .Eret           (ID_Eret),
202
        .Trap           (ID_Trap),
203
        .TrapCond       (ID_TrapCond),
204
        .EXC_Sys        (ID_EXC_Sys),
205
        .EXC_Bp         (ID_EXC_Bp),
206
        .EXC_RI         (ID_EXC_RI),
207
        .ID_CanErr      (ID_ID_CanErr),
208
        .EX_CanErr      (ID_EX_CanErr),
209
        .M_CanErr       (ID_M_CanErr),
210
        .NextIsDelay    (ID_NextIsDelay),
211
        .RegDst         (ID_RegDst),
212
        .ALUSrcImm      (ID_ALUSrcImm),
213
        .ALUOp          (ID_ALUOp),
214
        .LLSC           (ID_LLSC),
215
        .MemWrite       (ID_MemWrite),
216
        .MemRead        (ID_MemRead),
217
        .MemByte        (ID_MemByte),
218
        .MemHalf        (ID_MemHalf),
219
        .MemSignExtend  (ID_MemSignExtend),
220
        .Left           (ID_Left),
221
        .Right          (ID_Right),
222
        .RegWrite       (ID_RegWrite),
223
        .MemtoReg       (ID_MemtoReg)
224
    );
225
 
226
    /*** Hazard and Forward Control Unit ***/
227
    Hazard_Detection HazardControl (
228
        .DP_Hazards          (HAZ_DP_Hazards),
229
        .ID_Rs               (Rs),
230
        .ID_Rt               (Rt),
231
        .EX_Rs               (EX_Rs),
232
        .EX_Rt               (EX_Rt),
233
        .EX_RtRd             (EX_RtRd),
234
        .MEM_RtRd            (M_RtRd),
235
        .WB_RtRd             (WB_RtRd),
236
        .EX_Link             (EX_Link),
237
        .EX_RegWrite         (EX_RegWrite),
238
        .MEM_RegWrite        (M_RegWrite),
239
        .WB_RegWrite         (WB_RegWrite),
240
        .MEM_MemRead         (M_MemRead),
241
        .MEM_MemWrite        (M_MemWrite),
242
        .InstMem_Read        (InstMem_Read),
243
        .InstMem_Ready       (InstMem_Ready),
244
        .Mfc0                (ID_Mfc0),
245
        .IF_Exception_Stall  (IF_Exception_Stall),
246
        .ID_Exception_Stall  (ID_Exception_Stall),
247
        .EX_Exception_Stall  (EX_Exception_Stall),
248 10 ayersg
        .EX_ALU_Stall        (EX_ALU_Stall),
249 2 ayersg
        .M_Stall_Controller  (M_Stall_Controller),
250
        .IF_Stall            (IF_Stall),
251
        .ID_Stall            (ID_Stall),
252
        .EX_Stall            (EX_Stall),
253
        .M_Stall             (M_Stall),
254
        .WB_Stall            (WB_Stall),
255
        .ID_RsFwdSel         (ID_RsFwdSel),
256
        .ID_RtFwdSel         (ID_RtFwdSel),
257
        .EX_RsFwdSel         (EX_RsFwdSel),
258
        .EX_RtFwdSel         (EX_RtFwdSel),
259
        .M_WriteDataFwdSel   (M_WriteDataFwdSel)
260
    );
261
 
262
    /*** Coprocessor 0: Exceptions and Interrupts ***/
263
    CPZero CP0 (
264
        .clock               (clock),
265
        .Mfc0                (ID_Mfc0),
266
        .Mtc0                (ID_Mtc0),
267
        .IF_Stall            (IF_Stall),
268
        .ID_Stall            (ID_Stall),
269
        .COP1                (ID_CP1),
270
        .COP2                (ID_CP2),
271
        .COP3                (ID_CP3),
272
        .ERET                (ID_Eret),
273
        .Rd                  (Rd),
274
        .Sel                 (Cp0_Sel),
275
        .Reg_In              (ID_ReadData2_End),
276
        .Reg_Out             (CP0_RegOut),
277
        .KernelMode          (ID_KernelMode),
278
        .ReverseEndian       (ID_ReverseEndian),
279
        .Int                 (Interrupts),
280
        .reset               (reset),
281
        .EXC_NMI             (NMI),
282
        .EXC_AdIF            (IF_EXC_AdIF),
283
        .EXC_AdEL            (M_EXC_AdEL),
284
        .EXC_AdES            (M_EXC_AdES),
285
        .EXC_Ov              (EX_EXC_Ov),
286
        .EXC_Tr              (M_EXC_Tr),
287
        .EXC_Sys             (ID_EXC_Sys),
288
        .EXC_Bp              (ID_EXC_Bp),
289
        .EXC_RI              (ID_EXC_RI),
290
        .ID_RestartPC        (ID_RestartPC),
291
        .EX_RestartPC        (EX_RestartPC),
292
        .M_RestartPC         (M_RestartPC),
293
        .ID_IsFlushed        (ID_IsFlushed),
294
        .IF_IsBD             (IF_IsBDS),
295
        .ID_IsBD             (ID_IsBDS),
296
        .EX_IsBD             (EX_IsBDS),
297
        .M_IsBD              (M_IsBDS),
298
        .BadAddr_M           (M_ALUResult),
299
        .BadAddr_IF          (IF_PCOut),
300
        .ID_CanErr           (ID_CanErr),
301
        .EX_CanErr           (EX_CanErr),
302
        .M_CanErr            (M_CanErr),
303
        .IF_Exception_Stall  (IF_Exception_Stall),
304
        .ID_Exception_Stall  (ID_Exception_Stall),
305
        .EX_Exception_Stall  (EX_Exception_Stall),
306
        .M_Exception_Stall   (M_Exception_Stall),
307
        .IF_Exception_Flush  (IF_Exception_Flush),
308
        .ID_Exception_Flush  (ID_Exception_Flush),
309
        .EX_Exception_Flush  (EX_Exception_Flush),
310
        .M_Exception_Flush   (M_Exception_Flush),
311
        .Exc_PC_Sel          (ID_PCSrc_Exc),
312
        .Exc_PC_Out          (ID_ExceptionPC),
313
        .IP                  (IP)
314
    );
315
 
316
    /*** PC Source Non-Exception Mux ***/
317
    Mux4 #(.WIDTH(32)) PCSrcStd_Mux (
318
        .sel  (ID_PCSrc),
319
        .in0  (IF_PCAdd4),
320
        .in1  (ID_JumpAddress),
321
        .in2  (ID_BranchAddress),
322
        .in3  (ID_ReadData1_End),
323
        .out  (IF_PC_PreExc)
324
    );
325
 
326
    /*** PC Source Exception Mux ***/
327
    Mux2 #(.WIDTH(32)) PCSrcExc_Mux (
328
        .sel  (ID_PCSrc_Exc),
329
        .in0  (IF_PC_PreExc),
330
        .in1  (ID_ExceptionPC),
331
        .out  (IF_PCIn)
332
    );
333
 
334
    /*** Program Counter (MIPS spec is 0xBFC00000 starting address) ***/
335
    Register #(.WIDTH(32), .INIT(EXC_Vector_Base_Reset)) PC (
336
        .clock   (clock),
337
        .reset   (reset),
338
        //.enable  (~IF_Stall),   // XXX verify. HERE. Was 1 but on stall latches PC+4, ad nauseum.
339
        .enable (~(IF_Stall | ID_Stall)),
340
        .D       (IF_PCIn),
341
        .Q       (IF_PCOut)
342
    );
343
 
344
    /*** PC +4 Adder ***/
345
    Add PC_Add4 (
346
        .A  (IF_PCOut),
347
        .B  (32'h00000004),
348
        .C  (IF_PCAdd4)
349
    );
350
 
351
    /*** Instruction Fetch -> Instruction Decode Stage Register ***/
352
    IFID_Stage IFID (
353
        .clock           (clock),
354
        .reset           (reset),
355
        .IF_Flush        (IF_Exception_Flush | IF_Flush),
356
        .IF_Stall        (IF_Stall),
357
        .ID_Stall        (ID_Stall),
358
        .IF_Instruction  (IF_Instruction),
359
        .IF_PCAdd4       (IF_PCAdd4),
360
        .IF_PC           (IF_PCOut),
361
        .IF_IsBDS        (IF_IsBDS),
362
        .ID_Instruction  (Instruction),
363
        .ID_PCAdd4       (ID_PCAdd4),
364
        .ID_RestartPC    (ID_RestartPC),
365
        .ID_IsBDS        (ID_IsBDS),
366
        .ID_IsFlushed    (ID_IsFlushed)
367
    );
368
 
369
    /*** Register File ***/
370
    RegisterFile RegisterFile (
371
        .clock      (clock),
372
        .reset      (reset),
373
        .ReadReg1   (Rs),
374
        .ReadReg2   (Rt),
375
        .WriteReg   (WB_RtRd),
376
        .WriteData  (WB_WriteData),
377
        .RegWrite   (WB_RegWrite),
378
        .ReadData1  (ID_ReadData1_RF),
379
        .ReadData2  (ID_ReadData2_RF)
380
    );
381
 
382
    /*** ID Rs Forwarding/Link Mux ***/
383
    Mux4 #(.WIDTH(32)) IDRsFwd_Mux (
384
        .sel  (ID_RsFwdSel),
385
        .in0  (ID_ReadData1_RF),
386
        .in1  (M_ALUResult),
387
        .in2  (WB_WriteData),
388 7 ayersg
        .in3  (32'hxxxxxxxx),
389 2 ayersg
        .out  (ID_ReadData1_End)
390
    );
391
 
392
    /*** ID Rt Forwarding/CP0 Mfc0 Mux ***/
393
    Mux4 #(.WIDTH(32)) IDRtFwd_Mux (
394
        .sel  (ID_RtFwdSel),
395
        .in0  (ID_ReadData2_RF),
396
        .in1  (M_ALUResult),
397
        .in2  (WB_WriteData),
398
        .in3  (CP0_RegOut),
399
        .out  (ID_ReadData2_End)
400
    );
401
 
402
    /*** Condition Compare Unit ***/
403
    Compare Compare (
404
        .A    (ID_ReadData1_End),
405
        .B    (ID_ReadData2_End),
406
        .EQ   (ID_CmpEQ),
407
        .GZ   (ID_CmpGZ),
408
        .LZ   (ID_CmpLZ),
409
        .GEZ  (ID_CmpGEZ),
410
        .LEZ  (ID_CmpLEZ)
411
    );
412
 
413
    /*** Branch Address Adder ***/
414
    Add BranchAddress_Add (
415
        .A  (ID_PCAdd4),
416
        .B  (ID_ImmLeftShift2),
417
        .C  (ID_BranchAddress)
418
    );
419
 
420
    /*** Instruction Decode -> Execute Pipeline Stage ***/
421
    IDEX_Stage IDEX (
422
        .clock             (clock),
423
        .reset             (reset),
424
        .ID_Flush          (ID_Exception_Flush),
425
        .ID_Stall          (ID_Stall),
426
        .EX_Stall          (EX_Stall),
427
        .ID_Link           (ID_Link),
428
        .ID_RegDst         (ID_RegDst),
429
        .ID_ALUSrcImm      (ID_ALUSrcImm),
430
        .ID_ALUOp          (ID_ALUOp),
431
        .ID_Movn           (ID_Movn),
432
        .ID_Movz           (ID_Movz),
433
        .ID_LLSC           (ID_LLSC),
434
        .ID_MemRead        (ID_MemRead),
435
        .ID_MemWrite       (ID_MemWrite),
436
        .ID_MemByte        (ID_MemByte),
437
        .ID_MemHalf        (ID_MemHalf),
438
        .ID_MemSignExtend  (ID_MemSignExtend),
439
        .ID_Left           (ID_Left),
440
        .ID_Right          (ID_Right),
441
        .ID_RegWrite       (ID_RegWrite),
442
        .ID_MemtoReg       (ID_MemtoReg),
443
        .ID_ReverseEndian  (ID_ReverseEndian),
444
        .ID_Rs             (Rs),
445
        .ID_Rt             (Rt),
446
        .ID_WantRsByEX     (ID_DP_Hazards[3]),
447
        .ID_NeedRsByEX     (ID_DP_Hazards[2]),
448
        .ID_WantRtByEX     (ID_DP_Hazards[1]),
449
        .ID_NeedRtByEX     (ID_DP_Hazards[0]),
450
        .ID_KernelMode     (ID_KernelMode),
451
        .ID_RestartPC      (ID_RestartPC),
452
        .ID_IsBDS          (ID_IsBDS),
453
        .ID_Trap           (ID_Trap),
454
        .ID_TrapCond       (ID_TrapCond),
455
        .ID_EX_CanErr      (ID_EX_CanErr),
456
        .ID_M_CanErr       (ID_M_CanErr),
457
        .ID_ReadData1      (ID_ReadData1_End),
458
        .ID_ReadData2      (ID_ReadData2_End),
459
        .ID_SignExtImm     (ID_SignExtImm[16:0]),
460
        .EX_Link           (EX_Link),
461
        .EX_LinkRegDst     (EX_LinkRegDst),
462
        .EX_ALUSrcImm      (EX_ALUSrcImm),
463
        .EX_ALUOp          (EX_ALUOp),
464
        .EX_Movn           (EX_Movn),
465
        .EX_Movz           (EX_Movz),
466
        .EX_LLSC           (EX_LLSC),
467
        .EX_MemRead        (EX_MemRead),
468
        .EX_MemWrite       (EX_MemWrite),
469
        .EX_MemByte        (EX_MemByte),
470
        .EX_MemHalf        (EX_MemHalf),
471
        .EX_MemSignExtend  (EX_MemSignExtend),
472
        .EX_Left           (EX_Left),
473
        .EX_Right          (EX_Right),
474
        .EX_RegWrite       (EX_RegWrite),
475
        .EX_MemtoReg       (EX_MemtoReg),
476
        .EX_ReverseEndian  (EX_ReverseEndian),
477
        .EX_Rs             (EX_Rs),
478
        .EX_Rt             (EX_Rt),
479
        .EX_WantRsByEX     (EX_WantRsByEX),
480
        .EX_NeedRsByEX     (EX_NeedRsByEX),
481
        .EX_WantRtByEX     (EX_WantRtByEX),
482
        .EX_NeedRtByEX     (EX_NeedRtByEX),
483
        .EX_KernelMode     (EX_KernelMode),
484
        .EX_RestartPC      (EX_RestartPC),
485
        .EX_IsBDS          (EX_IsBDS),
486
        .EX_Trap           (EX_Trap),
487
        .EX_TrapCond       (EX_TrapCond),
488
        .EX_EX_CanErr      (EX_EX_CanErr),
489
        .EX_M_CanErr       (EX_M_CanErr),
490
        .EX_ReadData1      (EX_ReadData1_PR),
491
        .EX_ReadData2      (EX_ReadData2_PR),
492
        .EX_SignExtImm     (EX_SignExtImm),
493
        .EX_Rd             (EX_Rd),
494
        .EX_Shamt          (EX_Shamt)
495
    );
496
 
497
    /*** EX Rs Forwarding Mux ***/
498
    Mux4 #(.WIDTH(32)) EXRsFwd_Mux (
499
        .sel  (EX_RsFwdSel),
500
        .in0  (EX_ReadData1_PR),
501
        .in1  (M_ALUResult),
502
        .in2  (WB_WriteData),
503 7 ayersg
        .in3  (EX_RestartPC),
504 2 ayersg
        .out  (EX_ReadData1_Fwd)
505
    );
506
 
507
    /*** EX Rt Forwarding / Link Mux ***/
508
    Mux4 #(.WIDTH(32)) EXRtFwdLnk_Mux (
509
        .sel  (EX_RtFwdSel),
510
        .in0  (EX_ReadData2_PR),
511
        .in1  (M_ALUResult),
512
        .in2  (WB_WriteData),
513 7 ayersg
        .in3  (32'h00000008),
514 2 ayersg
        .out  (EX_ReadData2_Fwd)
515
    );
516
 
517
    /*** EX ALU Immediate Mux ***/
518
    Mux2 #(.WIDTH(32)) EXALUImm_Mux (
519
        .sel  (EX_ALUSrcImm),
520
        .in0  (EX_ReadData2_Fwd),
521
        .in1  (EX_SignExtImm),
522
        .out  (EX_ReadData2_Imm)
523
    );
524
 
525
    /*** EX RtRd / Link Mux ***/
526
    Mux4 #(.WIDTH(5)) EXRtRdLnk_Mux (
527
        .sel  (EX_LinkRegDst),
528
        .in0  (EX_Rt),
529
        .in1  (EX_Rd),
530
        .in2  (5'b11111),
531
        .in3  (5'bxxxxx),
532
        .out  (EX_RtRd)
533
    );
534
 
535
    /*** Arithmetic Logic Unit ***/
536
    ALU ALU (
537 10 ayersg
        .clock      (clock),
538
        .reset      (reset),
539
        .EX_Stall   (EX_Stall),
540
        .EX_Flush   (EX_Exception_Flush),
541
        .A          (EX_ReadData1_Fwd),
542
        .B          (EX_ReadData2_Imm),
543
        .Operation  (EX_ALUOp),
544
        .Shamt      (EX_Shamt),
545
        .Result     (EX_ALUResult),
546
        .BZero      (EX_BZero),
547
        .EXC_Ov     (EX_EXC_Ov),
548
        .ALU_Stall  (EX_ALU_Stall)
549 2 ayersg
    );
550
 
551
    /*** Execute -> Memory Pipeline Stage ***/
552
    EXMEM_Stage EXMEM (
553
        .clock             (clock),
554
        .reset             (reset),
555
        .EX_Flush          (EX_Exception_Flush),
556
        .EX_Stall          (EX_Stall),
557
        .M_Stall           (M_Stall),
558
        .EX_Movn           (EX_Movn),
559
        .EX_Movz           (EX_Movz),
560
        .EX_BZero          (EX_BZero),
561
        .EX_RegWrite       (EX_RegWrite),
562
        .EX_MemtoReg       (EX_MemtoReg),
563
        .EX_ReverseEndian  (EX_ReverseEndian),
564
        .EX_LLSC           (EX_LLSC),
565
        .EX_MemRead        (EX_MemRead),
566
        .EX_MemWrite       (EX_MemWrite),
567
        .EX_MemByte        (EX_MemByte),
568
        .EX_MemHalf        (EX_MemHalf),
569
        .EX_MemSignExtend  (EX_MemSignExtend),
570
        .EX_Left           (EX_Left),
571
        .EX_Right          (EX_Right),
572
        .EX_KernelMode     (EX_KernelMode),
573
        .EX_RestartPC      (EX_RestartPC),
574
        .EX_IsBDS          (EX_IsBDS),
575
        .EX_Trap           (EX_Trap),
576
        .EX_TrapCond       (EX_TrapCond),
577
        .EX_M_CanErr       (EX_M_CanErr),
578
        .EX_ALU_Result     (EX_ALUResult),
579
        .EX_ReadData2      (EX_ReadData2_Fwd),
580
        .EX_RtRd           (EX_RtRd),
581
        .M_RegWrite        (M_RegWrite),
582
        .M_MemtoReg        (M_MemtoReg),
583
        .M_ReverseEndian   (M_ReverseEndian),
584
        .M_LLSC            (M_LLSC),
585
        .M_MemRead         (M_MemRead),
586
        .M_MemWrite        (M_MemWrite),
587
        .M_MemByte         (M_MemByte),
588
        .M_MemHalf         (M_MemHalf),
589
        .M_MemSignExtend   (M_MemSignExtend),
590
        .M_Left            (M_Left),
591
        .M_Right           (M_Right),
592
        .M_KernelMode      (M_KernelMode),
593
        .M_RestartPC       (M_RestartPC),
594
        .M_IsBDS           (M_IsBDS),
595
        .M_Trap            (M_Trap),
596
        .M_TrapCond        (M_TrapCond),
597
        .M_M_CanErr        (M_M_CanErr),
598
        .M_ALU_Result      (M_ALUResult),
599
        .M_ReadData2       (M_ReadData2_PR),
600
        .M_RtRd            (M_RtRd)
601
    );
602
 
603
    /*** Trap Detection Unit ***/
604
    TrapDetect TrapDetect (
605
        .Trap       (M_Trap),
606
        .TrapCond   (M_TrapCond),
607
        .ALUResult  (M_ALUResult),
608
        .EXC_Tr     (M_EXC_Tr)
609
    );
610
 
611
    /*** MEM Write Data Mux ***/
612
    Mux2 #(.WIDTH(32)) MWriteData_Mux (
613
        .sel  (M_WriteDataFwdSel),
614
        .in0  (M_ReadData2_PR),
615
        .in1  (WB_WriteData),
616
        .out  (M_WriteData_Pre)
617
    );
618
 
619
    /*** Data Memory Controller ***/
620
    MemControl DataMem_Controller (
621
        .clock         (clock),
622
        .reset         (reset),
623
        .DataIn        (M_WriteData_Pre),
624
        .Address       (M_ALUResult),
625
        .MReadData     (DataMem_In),
626
        .MemRead       (M_MemRead),
627
        .MemWrite      (M_MemWrite),
628
        .DataMem_Ready (DataMem_Ready),
629
        .Byte          (M_MemByte),
630
        .Half          (M_MemHalf),
631
        .SignExtend    (M_MemSignExtend),
632
        .KernelMode    (M_KernelMode),
633
        .ReverseEndian (M_ReverseEndian),
634
        .LLSC          (M_LLSC),
635
        .ERET          (ID_Eret),
636
        .Left          (M_Left),
637
        .Right         (M_Right),
638
        .M_Exception_Stall (M_Exception_Stall),
639
 
640
        .IF_Stall (IF_Stall),
641
 
642
        .DataOut       (M_MemReadData),
643
        .MWriteData    (DataMem_Out),
644
        .WriteEnable   (DataMem_Write),
645
        .ReadEnable    (DataMem_Read),
646
        .M_Stall       (M_Stall_Controller),
647
        .EXC_AdEL      (M_EXC_AdEL),
648
        .EXC_AdES      (M_EXC_AdES)
649
    );
650
 
651
    /*** Memory -> Writeback Pipeline Stage ***/
652
    MEMWB_Stage MEMWB (
653
        .clock          (clock),
654
        .reset          (reset),
655
        .M_Flush        (M_Exception_Flush),
656
        .M_Stall        (M_Stall),
657
        .WB_Stall       (WB_Stall),
658
        .M_RegWrite     (M_RegWrite),
659
        .M_MemtoReg     (M_MemtoReg),
660
        .M_ReadData     (M_MemReadData),
661
        .M_ALU_Result   (M_ALUResult),
662
        .M_RtRd         (M_RtRd),
663
        .WB_RegWrite    (WB_RegWrite),
664
        .WB_MemtoReg    (WB_MemtoReg),
665
        .WB_ReadData    (WB_ReadData),
666
        .WB_ALU_Result  (WB_ALUResult),
667
        .WB_RtRd        (WB_RtRd)
668
    );
669
 
670
    /*** WB MemtoReg Mux ***/
671
    Mux2 #(.WIDTH(32)) WBMemtoReg_Mux (
672
        .sel  (WB_MemtoReg),
673
        .in0  (WB_ALUResult),
674
        .in1  (WB_ReadData),
675
        .out  (WB_WriteData)
676
    );
677
 
678
endmodule
679 3 ayersg
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.