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

Subversion Repositories mips32

[/] [mips32/] [trunk/] [Classic-MIPS/] [source/] [src/] [execute.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: 2017/01/11 15:53:54
7
// Design Name: 
8
// Module Name: execute
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
 
23
module execute(
24
input wire                  clk,
25
input wire                  rst,
26
input wire [3:0]            ctr_ex,
27
input wire [5:0]            ctr_m,
28
input wire [1:0]            ctr_wb,
29
input wire [31:0]           pc,
30
input wire [31:0]           instruction,
31
input wire [31:0]           reg1_data,
32
input wire [31:0]           reg2_data,
33
input wire signed [31:0]    immediate,
34
input wire [4:0]            rt,
35
input wire [4:0]            rd,
36
input wire                  isFlush,
37
input wire                  isCacheStall,
38
input [3:0]                 ALUcmd,
39
output reg [31:0]           reg_ALU_out,
40
output reg [31:0]           reg_reg2_data,
41
output reg [4:0]            reg_write_reg,
42
output reg [5:0]            reg_ctr_m,
43
output reg [1:0]            reg_ctr_wb,
44
/* bypass interface */
45
input wire [31:0]           ex_mem_data,
46
input wire [31:0]           mem_wb_data,
47
input wire [1:0]            forward_a,
48
input wire [1:0]            forward_b,
49
output wire [4:0]           ex_write_reg,
50
output wire                 ex_regwrite_flag,
51
input wire [1:0]            bht_token,
52
output reg [1:0]            reg_bht_token,
53
output reg signed [31:0]    reg_pc,
54
output reg signed [31:0]    reg_pc_branch,
55
output reg signed [31:0]    reg_pc_jump,
56
output reg signed [31:0]    reg_pc_next
57
    );
58
 
59
       /* ALU related signals */
60
      wire                  ALUSrc_flag;
61
      wire [31:0]           ALU_out;
62
      wire                  regdst_flag;
63
 
64
      wire [31:0]           ALU_opa;
65
      wire [31:0]           ALU_opb;
66
      wire [31:0]           ALU_opb2;
67
      wire signed [31:0]    pc_next;
68
 
69
      assign pc_next = reg_pc + 3'd4;
70
 
71
      /* the write reg */
72
      assign regdst_flag = ctr_ex[3];
73
      /* pass on the bypass related signal to the ID stage */
74
      assign ex_write_reg = (regdst_flag) ? rd : rt;
75
      assign ex_regwrite_flag = ctr_wb[1];
76
      assign ALUSrc_flag = ctr_ex[0];
77
 
78
      /* the bypath for the OPA */
79
      bypath bypath_inst_opa(
80
        .reg_data(      reg1_data       ),
81
        .ex_mem_data(   ex_mem_data     ),
82
        .mem_wb_data(   mem_wb_data     ),
83
        .sel(           forward_a       ),
84
        .out(           ALU_opa         )
85
      );
86
 
87
      /* the bypath for the OPB */
88
      bypath bypath_inst_opb(
89
        .reg_data(      reg2_data       ),
90
        .ex_mem_data(   ex_mem_data     ),
91
        .mem_wb_data(   mem_wb_data     ),
92
        .sel(           forward_b       ),
93
        .out(           ALU_opb         )
94
      );
95
 
96
      /* the bypath for the OPB */
97
      bypath2 bypath2_inst(
98
        .reg_data(      reg2_data       ),
99
        .ex_mem_data(   ex_mem_data     ),
100
        .mem_wb_data(   mem_wb_data     ),
101
        .immediate(     immediate       ),
102
        .ALUSrc_flag(   ALUSrc_flag     ),
103
        .sel(           forward_b       ),
104
        .out(           ALU_opb2         )
105
      );
106
 
107
      /* pass on the cpntrol signals to next stage */
108
      always @(posedge clk)
109
      begin
110
        if( rst )
111
        begin
112
            reg_ctr_m <= 0;
113
            reg_ctr_wb <= 0;
114
            reg_bht_token <= 0;
115
            reg_pc <= 0;
116
            reg_ALU_out <= 0;
117
            reg_reg2_data <= 0;
118
            reg_write_reg <= 0;
119
            reg_pc_branch <= 0;
120
            reg_pc_next <= 0;
121
            reg_pc_jump <= 0;
122
        end
123
        else
124
        begin
125
            /* clear the control signals when found FLUSH signal */
126
            if( isCacheStall )
127
            begin
128
                reg_ctr_m <= reg_ctr_m;
129
                reg_ctr_wb <= reg_ctr_wb;
130
                reg_bht_token <= reg_bht_token;
131
                reg_pc <= reg_pc;
132
                reg_ALU_out <= reg_ALU_out;
133
                reg_reg2_data <= reg_reg2_data;
134
                reg_write_reg <= reg_write_reg;
135
                reg_pc_branch <= reg_pc_branch;
136
                reg_pc_next <= reg_pc_next;
137
                reg_pc_jump <= reg_pc_jump;
138
            end
139
            else if( isFlush )
140
            begin
141
                reg_ctr_m <= 0;
142
                reg_ctr_wb <= 0;
143
                reg_bht_token <= 0;
144
                reg_pc <= 0;
145
                reg_ALU_out <= 0;
146
                reg_reg2_data <= 0;
147
                reg_write_reg <= 0;
148
                reg_pc_branch <= 0;
149
                reg_pc_next <= 0;
150
                reg_pc_jump <= 0;
151
            end
152
            else
153
            begin
154
                reg_ctr_m <= ctr_m;
155
                reg_ctr_wb <= ctr_wb;
156
                reg_bht_token <= bht_token;
157
                reg_pc <= pc;
158
                reg_ALU_out <= ALU_out;
159
                reg_reg2_data <= ALU_opb;
160
                reg_write_reg <= ex_write_reg;
161
                reg_pc_branch <= pc_next + (immediate << 2);
162
                reg_pc_next <= pc_next;
163
                if( ctr_m[5:4] == `JUMP_J || ctr_m[5:4] == `JUMP_JAL )
164
                    reg_pc_jump <= {pc_next[31:28], instruction[25:0], 2'b00};
165
                else if( ctr_m[5:4] == `JUMP_JR  )
166
                      reg_pc_jump <= ALU_opa;
167
                else
168
                    reg_pc_jump <= 0;
169
            end
170
        end
171
      end
172
 
173
 
174
//Instantiate of the ALU         
175
    ALU ALU_inst (
176
        .opa(                   ALU_opa                     ),
177
        .opb(                   ALU_opb2                        ),
178
        .cmd(                   ALUcmd                          ),
179
        .res(                   ALU_out                         )
180
    );
181
 
182
endmodule

powered by: WebSVN 2.1.0

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