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

Subversion Repositories klc32

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

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
                `MISC:
29
                        case(func)
30
                        `STOP:
31
                                if (!sf) begin
32
                                        vector <= `PRIVILEGE_VIOLATION;
33
                                        state <= TRAP;
34
                                end
35
                                else begin
36
                                        im <= imm[18:16];
37
                                        tf <= imm[23];
38
                                        sf <= imm[21];
39
                                        clk_en <= 1'b0;
40
                                        state <= IFETCH;
41
                                end
42
                        endcase
43
                `R:
44
                        begin
45
                                case(func)
46
                                `ABS:   res <= a[31] ? -a : a;
47
                                `SGN:   res <= a[31] ? 32'hFFFFFFFF : |a;
48
                                `NEG:   res <= -a;
49
                                `NOT:   res <= ~a;
50
                                `EXTB:  res <= {{24{a[7]}},a[7:0]};
51
                                `EXTH:  res <= {{16{a[15]}},a[15:0]};
52
                                default:        res <= 32'd0;
53
                                endcase
54
                                case(func)
55
                                `EXEC:
56
                                        begin
57
                                        ir <= a;
58
                                        Rn <= a[25:21];
59
                                        state <= REGFETCHA;
60
                                        end
61
                                `MOV_CRn2CRn:
62
                                        begin
63
                                        state <= IFETCH;
64
                                        case(ir[18:16])
65
                                        3'd0:   cr0 <= GetCr(ir[23:21]);
66
                                        3'd1:   cr1 <= GetCr(ir[23:21]);
67
                                        3'd2:   cr2 <= GetCr(ir[23:21]);
68
                                        3'd3:   cr3 <= GetCr(ir[23:21]);
69
                                        3'd4:   cr4 <= GetCr(ir[23:21]);
70
                                        3'd5:   cr5 <= GetCr(ir[23:21]);
71
                                        3'd6:   cr6 <= GetCr(ir[23:21]);
72
                                        3'd7:   cr7 <= GetCr(ir[23:21]);
73
                                        endcase
74
                                        end
75
                                `MOV_REG2CRn:
76
                                        begin
77
                                        case(ir[18:16])
78
                                        3'd0:   cr0 <= a[3:0];
79
                                        3'd1:   cr1 <= a[3:0];
80
                                        3'd2:   cr2 <= a[3:0];
81
                                        3'd3:   cr3 <= a[3:0];
82
                                        3'd4:   cr4 <= a[3:0];
83
                                        3'd5:   cr5 <= a[3:0];
84
                                        3'd6:   cr6 <= a[3:0];
85
                                        3'd7:   cr7 <= a[3:0];
86
                                        endcase
87
                                        end
88
                                `MOV_CRn2REG:
89
                                        res <= GetCr(ir[23:21]);
90
                                `MOV_CR2REG:
91
                                        res <= cr;
92
                                `MOV_REG2CR:
93
                                        begin
94
                                                state <= IFETCH;
95
                                                cr0 <= a[3:0];
96
                                                cr1 <= a[7:4];
97
                                                cr2 <= a[11:8];
98
                                                cr3 <= a[15:12];
99
                                                cr4 <= a[19:16];
100
                                                cr5 <= a[23:20];
101
                                                cr6 <= a[27:24];
102
                                                cr7 <= a[31:28];
103
                                        end
104
                                `MOV_REG2IM:    if (!sf) begin
105
                                                                        vector <= `PRIVILEGE_VIOLATION;
106
                                                                        state <= TRAP;
107
                                                                end
108
                                                                else begin
109
                                                                        im <= a[2:0];
110
                                                                        state <= IFETCH;
111
                                                                end
112
                                `MOV_IM2REG:    if (!sf) begin
113
                                                                        vector <= `PRIVILEGE_VIOLATION;
114
                                                                        state <= TRAP;
115
                                                                end
116
                                                                else begin
117
                                                                        res <= im;
118
                                                                end
119
                                `MOV_USP2REG:
120
                                                res <= usp;
121
                                `MOV_REG2USP:
122
                                                usp <= a;
123
                                `MFTICK:
124
                                                res <= tick;
125
                                endcase
126
                        end
127
                `RR:
128
                        begin
129
                                case(func)
130
                                `ADD:   res <= a + b;
131
                                `SUB:   res <= a - b;
132
                                `CMP:   res <= a - b;
133
                                `AND:   res <= a & b;
134
                                `OR:    res <= a | b;
135
                                `EOR:   res <= a ^ b;
136
                                `NAND:  res <= ~(a & b);
137
                                `NOR:   res <= ~(a | b);
138
                                `ENOR:  res <= ~(a ^ b);
139
                                `SHL:   res <= shlo[31: 0];
140
                                `SHR:   res <= shro[63:32];
141
                                `ROL:   res <= shlo[31:0]|shlo[63:32];
142
                                `ROR:   res <= shro[31:0]|shro[63:32];
143
                                `MIN:   res <= as < bs ? as : bs;
144
                                `MAX:   res <= as < bs ? bs : as;
145
                                `BCDADD:        res <= bcdaddo;
146
                                `BCDSUB:        res <= bcdsubo;
147
                                default:        res <= 32'd0;
148
                                endcase
149
                                if (func==`JMP_RR) begin
150
                                        pc <= a + b;
151
                                        pc[1:0] <= 2'b00;
152
                                        state <= IFETCH;
153
                                end
154
                                else if (func==`JSR_RR) begin
155
                                        tgt <= a + b;
156
                                        tgt[1:0] <= 2'b00;
157
                                        state <= JSR1;
158
                                end
159
                                else if (func==`CROR) begin
160
                                        state <= IFETCH;
161
                                        case(ir[15:13])
162
                                        3'd0:   cr0[ir[12:11]] <= GetCrBit(ir[25:21])| GetCrBit(ir[20:16]);
163
                                        3'd1:   cr1[ir[12:11]] <= GetCrBit(ir[25:21])| GetCrBit(ir[20:16]);
164
                                        3'd2:   cr2[ir[12:11]] <= GetCrBit(ir[25:21])| GetCrBit(ir[20:16]);
165
                                        3'd3:   cr3[ir[12:11]] <= GetCrBit(ir[25:21])| GetCrBit(ir[20:16]);
166
                                        3'd4:   cr4[ir[12:11]] <= GetCrBit(ir[25:21])| GetCrBit(ir[20:16]);
167
                                        3'd5:   cr5[ir[12:11]] <= GetCrBit(ir[25:21])| GetCrBit(ir[20:16]);
168
                                        3'd6:   cr6[ir[12:11]] <= GetCrBit(ir[25:21])| GetCrBit(ir[20:16]);
169
                                        3'd7:   cr7[ir[12:11]] <= GetCrBit(ir[25:21])| GetCrBit(ir[20:16]);
170
                                        endcase
171
                                end
172
                                else if (func==`CRAND) begin
173
                                        state <= IFETCH;
174
                                        case(ir[15:13])
175
                                        3'd0:   cr0[ir[12:11]] <= GetCrBit(ir[25:21])& GetCrBit(ir[20:16]);
176
                                        3'd1:   cr1[ir[12:11]] <= GetCrBit(ir[25:21])& GetCrBit(ir[20:16]);
177
                                        3'd2:   cr2[ir[12:11]] <= GetCrBit(ir[25:21])& GetCrBit(ir[20:16]);
178
                                        3'd3:   cr3[ir[12:11]] <= GetCrBit(ir[25:21])& GetCrBit(ir[20:16]);
179
                                        3'd4:   cr4[ir[12:11]] <= GetCrBit(ir[25:21])& GetCrBit(ir[20:16]);
180
                                        3'd5:   cr5[ir[12:11]] <= GetCrBit(ir[25:21])& GetCrBit(ir[20:16]);
181
                                        3'd6:   cr6[ir[12:11]] <= GetCrBit(ir[25:21])& GetCrBit(ir[20:16]);
182
                                        3'd7:   cr7[ir[12:11]] <= GetCrBit(ir[25:21])& GetCrBit(ir[20:16]);
183
                                        endcase
184
                                end
185
                                else if (func==`CRXOR) begin
186
                                        state <= IFETCH;
187
                                        case(ir[15:13])
188
                                        3'd0:   cr0[ir[12:11]] <= GetCrBit(ir[25:21])^ GetCrBit(ir[20:16]);
189
                                        3'd1:   cr1[ir[12:11]] <= GetCrBit(ir[25:21])^ GetCrBit(ir[20:16]);
190
                                        3'd2:   cr2[ir[12:11]] <= GetCrBit(ir[25:21])^ GetCrBit(ir[20:16]);
191
                                        3'd3:   cr3[ir[12:11]] <= GetCrBit(ir[25:21])^ GetCrBit(ir[20:16]);
192
                                        3'd4:   cr4[ir[12:11]] <= GetCrBit(ir[25:21])^ GetCrBit(ir[20:16]);
193
                                        3'd5:   cr5[ir[12:11]] <= GetCrBit(ir[25:21])^ GetCrBit(ir[20:16]);
194
                                        3'd6:   cr6[ir[12:11]] <= GetCrBit(ir[25:21])^ GetCrBit(ir[20:16]);
195
                                        3'd7:   cr7[ir[12:11]] <= GetCrBit(ir[25:21])^ GetCrBit(ir[20:16]);
196
                                        endcase
197
                                end
198
                                else if (func==`CRNOR) begin
199
                                        state <= IFETCH;
200
                                        case(ir[15:13])
201
                                        3'd0:   cr0[ir[12:11]] <= ~(GetCrBit(ir[25:21])| GetCrBit(ir[20:16]));
202
                                        3'd1:   cr1[ir[12:11]] <= ~(GetCrBit(ir[25:21])| GetCrBit(ir[20:16]));
203
                                        3'd2:   cr2[ir[12:11]] <= ~(GetCrBit(ir[25:21])| GetCrBit(ir[20:16]));
204
                                        3'd3:   cr3[ir[12:11]] <= ~(GetCrBit(ir[25:21])| GetCrBit(ir[20:16]));
205
                                        3'd4:   cr4[ir[12:11]] <= ~(GetCrBit(ir[25:21])| GetCrBit(ir[20:16]));
206
                                        3'd5:   cr5[ir[12:11]] <= ~(GetCrBit(ir[25:21])| GetCrBit(ir[20:16]));
207
                                        3'd6:   cr6[ir[12:11]] <= ~(GetCrBit(ir[25:21])| GetCrBit(ir[20:16]));
208
                                        3'd7:   cr7[ir[12:11]] <= ~(GetCrBit(ir[25:21])| GetCrBit(ir[20:16]));
209
                                        endcase
210
                                end
211
                                else if (func==`CRNAND) begin
212
                                        state <= IFETCH;
213
                                        case(ir[15:13])
214
                                        3'd0:   cr0[ir[12:11]] <= ~(GetCrBit(ir[25:21])& GetCrBit(ir[20:16]));
215
                                        3'd1:   cr1[ir[12:11]] <= ~(GetCrBit(ir[25:21])& GetCrBit(ir[20:16]));
216
                                        3'd2:   cr2[ir[12:11]] <= ~(GetCrBit(ir[25:21])& GetCrBit(ir[20:16]));
217
                                        3'd3:   cr3[ir[12:11]] <= ~(GetCrBit(ir[25:21])& GetCrBit(ir[20:16]));
218
                                        3'd4:   cr4[ir[12:11]] <= ~(GetCrBit(ir[25:21])& GetCrBit(ir[20:16]));
219
                                        3'd5:   cr5[ir[12:11]] <= ~(GetCrBit(ir[25:21])& GetCrBit(ir[20:16]));
220
                                        3'd6:   cr6[ir[12:11]] <= ~(GetCrBit(ir[25:21])& GetCrBit(ir[20:16]));
221
                                        3'd7:   cr7[ir[12:11]] <= ~(GetCrBit(ir[25:21])& GetCrBit(ir[20:16]));
222
                                        endcase
223
                                end
224
                                else if (func==`CRXNOR) begin
225
                                        state <= IFETCH;
226
                                        case(ir[15:13])
227
                                        3'd0:   cr0[ir[12:11]] <= ~(GetCrBit(ir[25:21])^ GetCrBit(ir[20:16]));
228
                                        3'd1:   cr1[ir[12:11]] <= ~(GetCrBit(ir[25:21])^ GetCrBit(ir[20:16]));
229
                                        3'd2:   cr2[ir[12:11]] <= ~(GetCrBit(ir[25:21])^ GetCrBit(ir[20:16]));
230
                                        3'd3:   cr3[ir[12:11]] <= ~(GetCrBit(ir[25:21])^ GetCrBit(ir[20:16]));
231
                                        3'd4:   cr4[ir[12:11]] <= ~(GetCrBit(ir[25:21])^ GetCrBit(ir[20:16]));
232
                                        3'd5:   cr5[ir[12:11]] <= ~(GetCrBit(ir[25:21])^ GetCrBit(ir[20:16]));
233
                                        3'd6:   cr6[ir[12:11]] <= ~(GetCrBit(ir[25:21])^ GetCrBit(ir[20:16]));
234
                                        3'd7:   cr7[ir[12:11]] <= ~(GetCrBit(ir[25:21])^ GetCrBit(ir[20:16]));
235
                                        endcase
236
                                end
237
                                case(func)
238
                                `LWX:   begin ea <= a + b; mopcode <= `LW; state <= MEMORY1; end
239
                                `LHX:   begin ea <= a + b; mopcode <= `LH; state <= MEMORY1; end
240
                                `LHUX:  begin ea <= a + b; mopcode <= `LHU; state <= MEMORY1; end
241
                                `LBX:   begin ea <= a + b; mopcode <= `LB; state <= MEMORY1; end
242
                                `LBUX:  begin ea <= a + b; mopcode <= `LBU; state <= MEMORY1; end
243
                                `SBX:   begin ea <= a + b; mopcode <= `SB; b <= c; state <= MEMORY1; end
244
                                `SHX:   begin ea <= a + b; mopcode <= `SH; b <= c; state <= MEMORY1; end
245
                                `SWX:   begin ea <= a + b; mopcode <= `SW; b <= c; state <= MEMORY1; end
246
                                endcase
247
                        end
248
                `SETcc:
249
                        begin
250
                                case(cond)
251
                                `SET:   res <= 32'd1;
252
                                `SEQ:   res <=  cr_zf;
253
                                `SNE:   res <= !cr_zf;
254
                                `SMI:   res <= ( cr_nf);
255
                                `SPL:   res <= (!cr_zf);
256
                                `SHI:   res <= (!cr_cf & !cr_zf);
257
                                `SLS:   res <= (cf |zf);
258
                                `SHS:   res <= (!cr_cf);
259
                                `SLO:   res <= ( cr_cf);
260
                                `SGT:   res <= ((cr_nf & cr_vf & !cr_zf)|(!cr_nf & !cr_vf & !cr_zf));
261
                                `SLE:   res <= (cr_zf | (cr_nf & !cr_vf) | (!cr_nf & cr_vf));
262
                                `SGE:   res <= ((cr_nf & cr_vf)|(!cr_nf & !cr_vf));
263
                                `SLT:   res <= ((cr_nf & !cr_vf)|(!cr_nf & cr_vf));
264
                                `SVS:   res <= ( cr_vf);
265
                                `SVC:   res <= (!cr_vf);
266
                                endcase
267
                        end
268
                `ADDI:  res <= a + imm;
269
                `SUBI:  res <= a - imm;
270
                `CMPI:  res <= a - imm;
271
                `ANDI:  res <= a & imm;
272
                `ORI:   res <= a | imm;
273
                `EORI:  res <= a ^ imm;
274
                `CRxx:
275
                        case(ir[20:16])
276
                        `ORI_CCR:
277
                                begin
278
                                        state <= IFETCH;
279
                                        cr0 <= cr0 | imm[3:0];
280
                                        cr1 <= cr1 | imm[7:4];
281
                                        cr2 <= cr2 | imm[11:8];
282
                                        cr3 <= cr3 | imm[15:12];
283
                                        cr4 <= cr4 | imm[19:16];
284
                                        cr5 <= cr5 | imm[23:20];
285
                                        cr6 <= cr6 | imm[27:24];
286
                                        cr7 <= cr7 | imm[31:28];
287
                                end
288
                        `ANDI_CCR:
289
                                begin
290
                                        state <= IFETCH;
291
                                        cr0 <= cr0 & imm[3:0];
292
                                        cr1 <= cr1 & imm[7:4];
293
                                        cr2 <= cr2 & imm[11:8];
294
                                        cr3 <= cr3 & imm[15:12];
295
                                        cr4 <= cr4 & imm[19:16];
296
                                        cr5 <= cr5 & imm[23:20];
297
                                        cr6 <= cr6 & imm[27:24];
298
                                        cr7 <= cr7 & imm[31:28];
299
                                end
300
                        `EORI_CCR:
301
                                begin
302
                                        state <= IFETCH;
303
                                        cr0 <= cr0 ^ imm[3:0];
304
                                        cr1 <= cr1 ^ imm[7:4];
305
                                        cr2 <= cr2 ^ imm[11:8];
306
                                        cr3 <= cr3 ^ imm[15:12];
307
                                        cr4 <= cr4 ^ imm[19:16];
308
                                        cr5 <= cr5 ^ imm[23:20];
309
                                        cr6 <= cr6 ^ imm[27:24];
310
                                        cr7 <= cr7 ^ imm[31:28];
311
                                end
312
                        endcase
313
                `LINK:  state <= LINK;
314
                default:        res <= 32'd0;
315
                endcase
316
                case(opcode)
317
                `TAS:   begin ea <= a + imm; mopcode <= opcode; state <= TAS; end
318
                `LW:    begin ea <= a + imm; mopcode <= opcode; state <= MEMORY1; end
319
                `LH:    begin ea <= a + imm; mopcode <= opcode; state <= MEMORY1; end
320
                `LB:    begin ea <= a + imm; mopcode <= opcode; state <= MEMORY1; end
321
                `LHU:   begin ea <= a + imm; mopcode <= opcode; state <= MEMORY1; end
322
                `LBU:   begin ea <= a + imm; mopcode <= opcode; state <= MEMORY1; end
323
                `SW:    begin ea <= a + imm; mopcode <= opcode; state <= MEMORY1; end
324
                `SH:    begin ea <= a + imm; mopcode <= opcode; state <= MEMORY1; end
325
                `SB:    begin ea <= a + imm; mopcode <= opcode; state <= MEMORY1; end
326
                `PEA:   begin ea <= a + imm; mopcode <= opcode; state <= PEA; end
327
                default:        ea <= 32'd0;
328
                endcase
329
        end

powered by: WebSVN 2.1.0

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