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

Subversion Repositories mips789

[/] [mips789/] [branches/] [avendor/] [rtl/] [verilog/] [RF_components.v] - Blame information for rev 53

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

Line No. Rev Author Line
1 35 mcupro
/******************************************************************
2
 *                                                                *
3
 *    Author: Liwei                                               *
4
 *                                                                *
5
 *    This file is part of the "mips789" project.                 *
6
 *    Downloaded from:                                            *
7
 *    http://www.opencores.org/pdownloads.cgi/list/mips789        *
8
 *                                                                *
9
 *    If you encountered any problem, please contact me via       *
10
 *    Email:mcupro@opencores.org  or mcupro@163.com               *
11
 *                                                                *
12
 ******************************************************************/
13
 
14
`include "mips789_defs.v"
15 10 mcupro
module ext(
16
        input [31:0] ins_i ,
17
        output reg [31:0] res ,
18
        input [2:0]ctl
19
    );
20
 
21
    wire [25:0] instr25_0;
22
    assign instr25_0 = ins_i[25:0] ;
23
 
24
    wire[15:0] sign = {
25
            instr25_0[15],instr25_0[15],instr25_0[15],instr25_0[15],
26
            instr25_0[15],instr25_0[15],instr25_0[15],instr25_0[15],
27
            instr25_0[15],instr25_0[15],instr25_0[15],instr25_0[15],
28
            instr25_0[15],instr25_0[15],instr25_0[15],instr25_0[15]};
29
 
30
    always @ (*)
31
    case (ctl)
32
        `EXT_SIGN    :res ={sign,instr25_0[15:0]};//sign
33
        `EXT_UNSIGN  :res ={16'b0,instr25_0[15:0]};//zeroext
34
        `EXT_J       :res ={4'b0,instr25_0[25:0],2'b0};//jmp
35
        `EXT_B       :res ={sign[13:0],instr25_0[15:0],2'B0};//brach
36
        `EXT_SA      :res ={27'b0,instr25_0[10:6]} ;//sll,srl
37
        `EXT_S2H     :res ={instr25_0[15:0],16'B0};//shift to high
38
        default: res=0;
39
    endcase
40
endmodule
41
 
42
 
43
module compare (
44
        input [31:0] s,
45
        input [31:0] t,
46
        input [2:0]ctl,
47
        output reg res
48 35 mcupro
    );
49 10 mcupro
    always @ (*)
50
    case  (ctl)
51
        `CMP_BEQ:   res = (s==t);
52
        `CMP_BNE:   res = (s!=t);
53
        `CMP_BLTZ:  res = s[31];
54
        `CMP_BGTZ:  res = ~s[31] && (|s[30:0]);
55
        `CMP_BLEZ:  res = s[31] |(~|s);
56
        `CMP_BGEZ:  res = ~s[31];
57
        default res=1'B0;
58
    endcase
59
endmodule
60
 
61
 
62
module pc_gen(
63
        input [2:0]ctl,
64
        output reg   [31:0]pc_next,
65
        input [3:0] pc_prectl,
66
        input check,
67
        input [31:0]s,
68
        input [31:0]pc,
69
        input [31:0]zz_spc,
70
        input [31:0]imm,
71
        input [31:0]irq
72
    );
73
 
74
    wire [32:0] br_addr = pc + imm ;
75
 
76
    always @ (*)
77
        if(pc_prectl == `PC_IGN )
78
        begin
79
            case (ctl)
80
                `PC_RET         :       pc_next = zz_spc ;
81
                `PC_J           :       pc_next ={pc[31:28],imm[27:0]};
82
                `PC_JR          :       pc_next = s;
83
                `PC_BC          :       pc_next = (check)?({br_addr[31:0]}):(pc+4);
84
                `PC_NEXT        :       pc_next = pc+ 4 ;
85
                default                 pc_next = pc + 4;
86
            endcase
87
        end
88
        else
89
        begin
90
            case (pc_prectl)
91
                `PC_KEP         : pc_next=pc;
92
                `PC_IRQ         : pc_next=irq;
93
                `PC_RST         : pc_next='d0;
94
                default           pc_next =0;
95
            endcase
96
        end
97
 
98
endmodule
99
 
100
 
101
 
102
module reg_array(
103
        data,
104
        wraddress,
105
        rdaddress_a,
106
        rdaddress_b,
107
        wren,
108
        clock,
109
        qa,
110
        qb,
111
        rd_clk_cls
112
    );
113
 
114
    input       [31:0]  data;
115
    input       [4:0]  wraddress;
116
    input       [4:0]  rdaddress_a;
117
    input       [4:0]  rdaddress_b;
118
 
119
    reg [31:0]  r_data;
120
    reg [4:0]  r_wraddress;
121
    reg [4:0]  r_rdaddress_a;
122
    reg [4:0]  r_rdaddress_b;
123
    input rd_clk_cls;
124
    input       wren;
125
    reg r_wren;
126
    input       clock;
127
    output      [31:0]  qa;
128
    output      [31:0]  qb;
129
    reg [31:0]reg_bank[0:31];
130 35 mcupro
    integer i;
131
    initial
132
    begin
133
        for(i=0;i<32;i=i+1)
134
            reg_bank[i]=0;
135
    end
136 10 mcupro
 
137
    assign qa=(r_rdaddress_a==0)?0:
138
           ((r_wraddress==r_rdaddress_a)&&(1==r_wren))?r_data:
139
           reg_bank[r_rdaddress_a];
140
 
141
    assign qb=(r_rdaddress_b==0)?0:
142
           ((r_wraddress==r_rdaddress_b)&&(1==r_wren))?r_data:
143
           reg_bank[r_rdaddress_b];
144
 
145
    always@(posedge clock)
146
        if (~rd_clk_cls)
147
        begin
148
            r_rdaddress_a <=rdaddress_a;
149
            r_rdaddress_b<=rdaddress_b;
150
        end
151
 
152
    always@(posedge clock)
153
    begin
154
        r_data <=data;
155
        r_wraddress<=wraddress;
156
        r_wren<=wren;
157
    end
158
    always@(posedge clock)
159
        if (r_wren)
160
            reg_bank[r_wraddress] <= r_data ;
161
endmodule

powered by: WebSVN 2.1.0

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