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

Subversion Repositories klc32

[/] [klc32/] [trunk/] [rtl/] [verilog/] [EXECUTE.v] - Blame information for rev 10

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

Line No. Rev Author Line
1 2 robfinch
// ============================================================================
2
// (C) 2011 Robert Finch
3
// All Rights Reserved.
4
// robfinch<remove>@opencores.org
5
//
6
// KLC32 - 32 bit CPU
7
// EXECUTE.v
8
//
9
// This source file is free software: you can redistribute it and/or modify 
10
// it under the terms of the GNU Lesser General Public License as published 
11
// by the Free Software Foundation, either version 3 of the License, or     
12
// (at your option) any later version.                                      
13
//                                                                          
14
// This source file is distributed in the hope that it will be useful,      
15
// but WITHOUT ANY WARRANTY; without even the implied warranty of           
16
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            
17
// GNU General Public License for more details.                             
18
//                                                                          
19
// You should have received a copy of the GNU General Public License        
20
// along with this program.  If not, see <http://www.gnu.org/licenses/>.    
21
//                                                                          
22
// ============================================================================
23
//
24
EXECUTE:
25
        begin
26
                state <= WRITEBACK;
27
                case(opcode)
28
                `R:
29
                        begin
30
                                case(func)
31
                                `ABS:   res <= a[31] ? -a : a;
32
                                `SGN:   res <= a[31] ? 32'hFFFFFFFF : |a;
33
                                `NEG:   res <= -a;
34
                                `NOT:   res <= ~a;
35
                                `EXTB:  res <= {{24{a[7]}},a[7:0]};
36
                                `EXTH:  res <= {{16{a[15]}},a[15:0]};
37 10 robfinch
                                `MFSPR:
38
                                        casex(ir[25:21])
39
                                        5'b00xxx:       res <= GetCr(ir[23:21]);
40
                                        5'b01000:       res <= cr;
41
                                        5'b01001:       res <= usp;
42
                                        5'b01010:
43
                                                        if (!sf) begin
44
                                                                vector <= `PRIVILEGE_VIOLATION;
45
                                                                state <= TRAP;
46
                                                        end
47
                                                        else begin
48
                                                                res <= im;
49
                                                        end
50
                                        5'b01111:       res <= tick;
51
                                        endcase
52
                                `MTSPR:
53
                                        casex(ir[20:16])
54
                                        5'b00xxx:       // MTSPR CRn,Rn
55
                                                begin
56
                                                        state <= IFETCH;
57
                                                        case(ir[18:16])
58
                                                        3'd0:   cr0 <= a[3:0];
59
                                                        3'd1:   cr1 <= a[3:0];
60
                                                        3'd2:   cr2 <= a[3:0];
61
                                                        3'd3:   cr3 <= a[3:0];
62
                                                        3'd4:   cr4 <= a[3:0];
63
                                                        3'd5:   cr5 <= a[3:0];
64
                                                        3'd6:   cr6 <= a[3:0];
65
                                                        3'd7:   cr7 <= a[3:0];
66
                                                        endcase
67
                                                end
68
                                        5'b01000:       // MTSPR CR,Rn
69
                                                begin
70
                                                        state <= IFETCH;
71
                                                        cr0 <= a[3:0];
72
                                                        cr1 <= a[7:4];
73
                                                        cr2 <= a[11:8];
74
                                                        cr3 <= a[15:12];
75
                                                        cr4 <= a[19:16];
76
                                                        cr5 <= a[23:20];
77
                                                        cr6 <= a[27:24];
78
                                                        cr7 <= a[31:28];
79
                                                end
80
                                        5'b01001:       usp <= a;       // MTSPR USP,Rn
81
                                        5'b01010:
82
                                                        if (!sf) begin
83
                                                                vector <= `PRIVILEGE_VIOLATION;
84
                                                                state <= TRAP;
85
                                                        end
86
                                                        else begin
87
                                                                im <= a[2:0];
88
                                                                state <= IFETCH;
89
                                                        end
90
                                        endcase
91 2 robfinch
                                `EXEC:
92
                                        begin
93
                                        ir <= a;
94
                                        Rn <= a[25:21];
95
                                        state <= REGFETCHA;
96
                                        end
97
                                `MOV_CRn2CRn:
98
                                        begin
99
                                        state <= IFETCH;
100
                                        case(ir[18:16])
101
                                        3'd0:   cr0 <= GetCr(ir[23:21]);
102
                                        3'd1:   cr1 <= GetCr(ir[23:21]);
103
                                        3'd2:   cr2 <= GetCr(ir[23:21]);
104
                                        3'd3:   cr3 <= GetCr(ir[23:21]);
105
                                        3'd4:   cr4 <= GetCr(ir[23:21]);
106
                                        3'd5:   cr5 <= GetCr(ir[23:21]);
107
                                        3'd6:   cr6 <= GetCr(ir[23:21]);
108
                                        3'd7:   cr7 <= GetCr(ir[23:21]);
109
                                        endcase
110
                                        end
111 10 robfinch
                                default:        res <= 32'd0;
112 2 robfinch
                                endcase
113
                        end
114
                `RR:
115
                        begin
116
                                case(func)
117
                                `SUB:   res <= a - b;
118
                                `AND:   res <= a & b;
119 10 robfinch
                                `ANDC:  res <= a & ~b;
120 2 robfinch
                                `OR:    res <= a | b;
121 10 robfinch
                                `ORC:   res <= a | ~b;
122 2 robfinch
                                `EOR:   res <= a ^ b;
123
                                `NAND:  res <= ~(a & b);
124
                                `NOR:   res <= ~(a | b);
125
                                `ENOR:  res <= ~(a ^ b);
126
                                `SHL:   res <= shlo[31: 0];
127
                                `SHR:   res <= shro[63:32];
128
                                `ROL:   res <= shlo[31:0]|shlo[63:32];
129
                                `ROR:   res <= shro[31:0]|shro[63:32];
130
                                `MIN:   res <= as < bs ? as : bs;
131
                                `MAX:   res <= as < bs ? bs : as;
132
                                `BCDADD:        res <= bcdaddo;
133
                                `BCDSUB:        res <= bcdsubo;
134
                                default:        res <= 32'd0;
135
                                endcase
136
                                if (func==`JMP_RR) begin
137
                                        pc <= a + b;
138
                                        pc[1:0] <= 2'b00;
139
                                        state <= IFETCH;
140
                                end
141
                                else if (func==`JSR_RR) begin
142
                                        tgt <= a + b;
143
                                        tgt[1:0] <= 2'b00;
144
                                        state <= JSR1;
145
                                end
146
                                case(func)
147
                                `LWX:   begin ea <= a + b; mopcode <= `LW; state <= MEMORY1; end
148
                                `LHX:   begin ea <= a + b; mopcode <= `LH; state <= MEMORY1; end
149
                                `LHUX:  begin ea <= a + b; mopcode <= `LHU; state <= MEMORY1; end
150
                                `LBX:   begin ea <= a + b; mopcode <= `LB; state <= MEMORY1; end
151
                                `LBUX:  begin ea <= a + b; mopcode <= `LBU; state <= MEMORY1; end
152
                                `SBX:   begin ea <= a + b; mopcode <= `SB; b <= c; state <= MEMORY1; end
153
                                `SHX:   begin ea <= a + b; mopcode <= `SH; b <= c; state <= MEMORY1; end
154
                                `SWX:   begin ea <= a + b; mopcode <= `SW; b <= c; state <= MEMORY1; end
155 10 robfinch
 
156
                                `MULU:  state <= MULTDIV1;
157
                                `MULS:  state <= MULTDIV1;
158
                                `MULUH: state <= MULTDIV1;
159
                                `MULSH: state <= MULTDIV1;
160
                                `DIVU:  state <= MULTDIV1;
161
                                `DIVS:  state <= MULTDIV1;
162
                                `MODU:  state <= MULTDIV1;
163
                                `MODS:  state <= MULTDIV1;
164 2 robfinch
                                endcase
165
                        end
166
                `SETcc:
167
                        begin
168
                                case(cond)
169
                                `SET:   res <= 32'd1;
170
                                `SEQ:   res <=  cr_zf;
171
                                `SNE:   res <= !cr_zf;
172
                                `SMI:   res <= ( cr_nf);
173
                                `SPL:   res <= (!cr_zf);
174
                                `SHI:   res <= (!cr_cf & !cr_zf);
175
                                `SLS:   res <= (cf |zf);
176
                                `SHS:   res <= (!cr_cf);
177
                                `SLO:   res <= ( cr_cf);
178
                                `SGT:   res <= ((cr_nf & cr_vf & !cr_zf)|(!cr_nf & !cr_vf & !cr_zf));
179
                                `SLE:   res <= (cr_zf | (cr_nf & !cr_vf) | (!cr_nf & cr_vf));
180
                                `SGE:   res <= ((cr_nf & cr_vf)|(!cr_nf & !cr_vf));
181
                                `SLT:   res <= ((cr_nf & !cr_vf)|(!cr_nf & cr_vf));
182
                                `SVS:   res <= ( cr_vf);
183
                                `SVC:   res <= (!cr_vf);
184
                                endcase
185
                        end
186
                `ADDI:  res <= a + imm;
187
                `SUBI:  res <= a - imm;
188
                `CMPI:  res <= a - imm;
189
                `ANDI:  res <= a & imm;
190
                `ORI:   res <= a | imm;
191
                `EORI:  res <= a ^ imm;
192 10 robfinch
/*
193 2 robfinch
                        case(ir[20:16])
194
                        `ORI_CCR:
195
                                begin
196
                                        state <= IFETCH;
197
                                        cr0 <= cr0 | imm[3:0];
198
                                        cr1 <= cr1 | imm[7:4];
199
                                        cr2 <= cr2 | imm[11:8];
200
                                        cr3 <= cr3 | imm[15:12];
201
                                        cr4 <= cr4 | imm[19:16];
202
                                        cr5 <= cr5 | imm[23:20];
203
                                        cr6 <= cr6 | imm[27:24];
204
                                        cr7 <= cr7 | imm[31:28];
205
                                end
206
                        `ANDI_CCR:
207
                                begin
208
                                        state <= IFETCH;
209
                                        cr0 <= cr0 & imm[3:0];
210
                                        cr1 <= cr1 & imm[7:4];
211
                                        cr2 <= cr2 & imm[11:8];
212
                                        cr3 <= cr3 & imm[15:12];
213
                                        cr4 <= cr4 & imm[19:16];
214
                                        cr5 <= cr5 & imm[23:20];
215
                                        cr6 <= cr6 & imm[27:24];
216
                                        cr7 <= cr7 & imm[31:28];
217
                                end
218
                        `EORI_CCR:
219
                                begin
220
                                        state <= IFETCH;
221
                                        cr0 <= cr0 ^ imm[3:0];
222
                                        cr1 <= cr1 ^ imm[7:4];
223
                                        cr2 <= cr2 ^ imm[11:8];
224
                                        cr3 <= cr3 ^ imm[15:12];
225
                                        cr4 <= cr4 ^ imm[19:16];
226
                                        cr5 <= cr5 ^ imm[23:20];
227
                                        cr6 <= cr6 ^ imm[27:24];
228
                                        cr7 <= cr7 ^ imm[31:28];
229
                                end
230
                        endcase
231 10 robfinch
*/
232 2 robfinch
                `LINK:  state <= LINK;
233 10 robfinch
                `MULUI: state <= MULTDIV1;
234
                `MULSI: state <= MULTDIV1;
235
                `DIVUI: state <= MULTDIV1;
236
                `DIVSI: state <= MULTDIV1;
237 2 robfinch
                default:        res <= 32'd0;
238
                endcase
239
                case(opcode)
240
                `TAS:   begin ea <= a + imm; mopcode <= opcode; state <= TAS; end
241
                `LW:    begin ea <= a + imm; mopcode <= opcode; state <= MEMORY1; end
242
                `LH:    begin ea <= a + imm; mopcode <= opcode; state <= MEMORY1; end
243
                `LB:    begin ea <= a + imm; mopcode <= opcode; state <= MEMORY1; end
244
                `LHU:   begin ea <= a + imm; mopcode <= opcode; state <= MEMORY1; end
245
                `LBU:   begin ea <= a + imm; mopcode <= opcode; state <= MEMORY1; end
246
                `SW:    begin ea <= a + imm; mopcode <= opcode; state <= MEMORY1; end
247
                `SH:    begin ea <= a + imm; mopcode <= opcode; state <= MEMORY1; end
248
                `SB:    begin ea <= a + imm; mopcode <= opcode; state <= MEMORY1; end
249
                `PEA:   begin ea <= a + imm; mopcode <= opcode; state <= PEA; end
250
                default:        ea <= 32'd0;
251
                endcase
252
        end

powered by: WebSVN 2.1.0

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