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

Subversion Repositories mips32

[/] [mips32/] [trunk/] [Classic-MIPS/] [source/] [src/] [CPU_Ctr.v] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 jjf
`timescale 1ns / 1ps
2
//////////////////////////////////////////////////////////////////////////////////
3
// Company: 
4
// Engineer: 
5
// 
6
// Create Date:    19:12:22 12/29/2016 
7
// Design Name: 
8
// Module Name:    CPU_Ctr 
9
// Project Name: 
10
// Target Devices: 
11
// Tool versions: 
12
// Description: 
13
//
14
// Dependencies: 
15
//
16
// Revision: 
17
// Revision 0.01 - File Created
18
// Additional Comments: 
19
//
20
//////////////////////////////////////////////////////////////////////////////////
21
`include "macros.v"
22
module CPU_Ctr(
23
input wire [31:0]       instruction,
24
output wire             regdst_flag,
25
output wire [1:0]       jump_flag,
26
output wire [1:0]       branch_flag,
27
output wire             memread_flag,
28
output wire             memtoReg_flag,
29
output wire [1:0]       ALUOp,
30
output wire             memwrite_flag,
31
output wire             ALUSrc_flag,
32
output wire             regwrite_flag
33
    );
34
 
35
        wire [5:0]         opcode;
36
        assign opcode = instruction[31:26];
37
 
38
        /* RegDst */
39
        assign regdst_flag = (opcode == `OPCODE_R) ? 1'b1 : 1'b0;
40
 
41
        /* Jump */
42
        assign jump_flag = JUMP( instruction );
43
        function [1:0] JUMP;
44
        input [31:0]       instruction;
45
        begin
46
           if( instruction[31:26] == `OPCODE_J_JUMP )
47
               JUMP = `JUMP_J;
48
           else if( instruction[31:26] == `OPCODE_JAL_JUMP )
49
               JUMP = `JUMP_JAL;
50
           else if( (instruction[31:26] == `OPCODE_R && instruction[5:0] == `R_FUNC_JR) )
51
               JUMP = `JUMP_JR;
52
           else
53
               JUMP = 2'b00;
54
        end
55
        endfunction
56
 
57
        /* Branch */
58
        assign branch_flag = BRANCH( opcode );
59
        function [1:0]   BRANCH;
60
                input [5:0] opcode;
61
                begin
62
                        case( opcode )
63
                        `OPCODE_I_BEQ: BRANCH = `BRANCH_OP_BEQ;
64
                        `OPCODE_I_BNE: BRANCH = `BRANCH_OP_BNE;
65
                        default:                BRANCH = 2'b00;
66
                        endcase
67
                end
68
        endfunction
69
 
70
        /* MemRead */
71
        assign memread_flag = (opcode == `OPCODE_I_LW) ? 1'b1 : 1'b0;
72
 
73
        /* MemToReg */
74
        assign memtoReg_flag = (opcode == `OPCODE_I_LW) ? 1'b1 : 1'b0;
75
 
76
        /* MemWrite */
77
        assign memwrite_flag = (opcode == `OPCODE_I_SW) ? 1'b1 : 1'b0;
78
 
79
        /* ALUSrc */
80
        assign ALUSrc_flag = ALUSRC( opcode );
81
        function ALUSRC;
82
                input [5:0] opcode;
83
                begin
84
                        if( opcode[5:3] == `OPCODE_I_MASK)
85
                                ALUSRC = 1'b1;
86
                        else
87
                                case( opcode )
88
                                `OPCODE_I_LW:   ALUSRC = 1'b1;
89
                                `OPCODE_I_SW:   ALUSRC = 1'b1;
90
                                default:                ALUSRC = 1'b0;
91
                                endcase
92
                end
93
        endfunction
94
 
95
        /* RegWrite */
96
        assign regwrite_flag = REGWRITE( opcode, instruction );
97
        function REGWRITE;
98
                input [5:0]      opcode;
99
                input [31:0] instruction;
100
                begin
101
                    if( instruction == `NOP )
102
                         REGWRITE = 1'b0;
103
                    else if( opcode == `OPCODE_JAL_JUMP )
104
                         REGWRITE = 1'b1;
105
                        else if( opcode[5:3] == `OPCODE_I_MASK)
106
                                REGWRITE = 1'b1;
107
                        else if( opcode == `OPCODE_I_LW)
108
                             REGWRITE = 1'b1;
109
                        else if( opcode == `OPCODE_R )
110
                        begin
111
                             if( instruction[5:0] == `R_FUNC_JR)
112
                                 REGWRITE = 1'b0;
113
                             else
114
                                 REGWRITE = 1'b1;
115
                        end
116
                        else
117
                             REGWRITE = 1'b0;
118
                end
119
        endfunction
120
 
121
        /* ALUOp */
122
        assign ALUOp = OP( opcode );
123
        function [1:0]   OP;
124
                input [5:0]      opcode;
125
                begin
126
                        if( opcode[5:3] == `OPCODE_I_MASK)
127
                                OP = 2'b11;
128
                        else
129
                                case( opcode )
130
                                `OPCODE_I_SW:  OP = 2'b00;
131
                                `OPCODE_I_LW:  OP = 2'b00;
132
                                `OPCODE_I_BEQ: OP = 2'b01;
133
                                `OPCODE_I_BNE: OP = 2'b01;
134
                                `OPCODE_R:         OP = 2'b10;
135
                                default:           OP = 2'b00;
136
                                endcase
137
                end
138
        endfunction
139
 
140
 
141
endmodule

powered by: WebSVN 2.1.0

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