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

Subversion Repositories klc32

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

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 12 robfinch
                                        5'b01011:       res <= be_addr;
51 10 robfinch
                                        5'b01111:       res <= tick;
52
                                        endcase
53
                                `MTSPR:
54
                                        casex(ir[20:16])
55
                                        5'b00xxx:       // MTSPR CRn,Rn
56
                                                begin
57
                                                        state <= IFETCH;
58
                                                        case(ir[18:16])
59
                                                        3'd0:   cr0 <= a[3:0];
60
                                                        3'd1:   cr1 <= a[3:0];
61
                                                        3'd2:   cr2 <= a[3:0];
62
                                                        3'd3:   cr3 <= a[3:0];
63
                                                        3'd4:   cr4 <= a[3:0];
64
                                                        3'd5:   cr5 <= a[3:0];
65
                                                        3'd6:   cr6 <= a[3:0];
66
                                                        3'd7:   cr7 <= a[3:0];
67
                                                        endcase
68
                                                end
69
                                        5'b01000:       // MTSPR CR,Rn
70
                                                begin
71
                                                        state <= IFETCH;
72
                                                        cr0 <= a[3:0];
73
                                                        cr1 <= a[7:4];
74
                                                        cr2 <= a[11:8];
75
                                                        cr3 <= a[15:12];
76
                                                        cr4 <= a[19:16];
77
                                                        cr5 <= a[23:20];
78
                                                        cr6 <= a[27:24];
79
                                                        cr7 <= a[31:28];
80
                                                end
81
                                        5'b01001:       usp <= a;       // MTSPR USP,Rn
82
                                        5'b01010:
83
                                                        if (!sf) begin
84
                                                                vector <= `PRIVILEGE_VIOLATION;
85
                                                                state <= TRAP;
86
                                                        end
87
                                                        else begin
88
                                                                im <= a[2:0];
89
                                                                state <= IFETCH;
90
                                                        end
91
                                        endcase
92 2 robfinch
                                `EXEC:
93
                                        begin
94
                                        ir <= a;
95
                                        Rn <= a[25:21];
96
                                        state <= REGFETCHA;
97
                                        end
98
                                `MOV_CRn2CRn:
99
                                        begin
100
                                        state <= IFETCH;
101
                                        case(ir[18:16])
102
                                        3'd0:   cr0 <= GetCr(ir[23:21]);
103
                                        3'd1:   cr1 <= GetCr(ir[23:21]);
104
                                        3'd2:   cr2 <= GetCr(ir[23:21]);
105
                                        3'd3:   cr3 <= GetCr(ir[23:21]);
106
                                        3'd4:   cr4 <= GetCr(ir[23:21]);
107
                                        3'd5:   cr5 <= GetCr(ir[23:21]);
108
                                        3'd6:   cr6 <= GetCr(ir[23:21]);
109
                                        3'd7:   cr7 <= GetCr(ir[23:21]);
110
                                        endcase
111
                                        end
112 10 robfinch
                                default:        res <= 32'd0;
113 2 robfinch
                                endcase
114
                        end
115
                `RR:
116
                        begin
117
                                case(func)
118 12 robfinch
                                `ADD:   res <= a + b;
119 2 robfinch
                                `SUB:   res <= a - b;
120 12 robfinch
                                `CMP:   res <= a - b;
121 2 robfinch
                                `AND:   res <= a & b;
122 10 robfinch
                                `ANDC:  res <= a & ~b;
123 2 robfinch
                                `OR:    res <= a | b;
124 10 robfinch
                                `ORC:   res <= a | ~b;
125 2 robfinch
                                `EOR:   res <= a ^ b;
126
                                `NAND:  res <= ~(a & b);
127
                                `NOR:   res <= ~(a | b);
128
                                `ENOR:  res <= ~(a ^ b);
129
                                `SHL:   res <= shlo[31: 0];
130
                                `SHR:   res <= shro[63:32];
131
                                `ROL:   res <= shlo[31:0]|shlo[63:32];
132
                                `ROR:   res <= shro[31:0]|shro[63:32];
133
                                `MIN:   res <= as < bs ? as : bs;
134
                                `MAX:   res <= as < bs ? bs : as;
135
                                `BCDADD:        res <= bcdaddo;
136
                                `BCDSUB:        res <= bcdsubo;
137
                                default:        res <= 32'd0;
138
                                endcase
139
                                if (func==`JMP_RR) begin
140
                                        pc <= a + b;
141
                                        pc[1:0] <= 2'b00;
142
                                        state <= IFETCH;
143
                                end
144
                                else if (func==`JSR_RR) begin
145
                                        tgt <= a + b;
146
                                        tgt[1:0] <= 2'b00;
147
                                        state <= JSR1;
148
                                end
149
                                case(func)
150
                                `LWX:   begin ea <= a + b; mopcode <= `LW; state <= MEMORY1; end
151
                                `LHX:   begin ea <= a + b; mopcode <= `LH; state <= MEMORY1; end
152
                                `LHUX:  begin ea <= a + b; mopcode <= `LHU; state <= MEMORY1; end
153
                                `LBX:   begin ea <= a + b; mopcode <= `LB; state <= MEMORY1; end
154
                                `LBUX:  begin ea <= a + b; mopcode <= `LBU; state <= MEMORY1; end
155
                                `SBX:   begin ea <= a + b; mopcode <= `SB; b <= c; state <= MEMORY1; end
156
                                `SHX:   begin ea <= a + b; mopcode <= `SH; b <= c; state <= MEMORY1; end
157
                                `SWX:   begin ea <= a + b; mopcode <= `SW; b <= c; state <= MEMORY1; end
158 10 robfinch
 
159
                                `MULU:  state <= MULTDIV1;
160
                                `MULS:  state <= MULTDIV1;
161
                                `MULUH: state <= MULTDIV1;
162
                                `MULSH: state <= MULTDIV1;
163
                                `DIVU:  state <= MULTDIV1;
164
                                `DIVS:  state <= MULTDIV1;
165
                                `MODU:  state <= MULTDIV1;
166
                                `MODS:  state <= MULTDIV1;
167 2 robfinch
                                endcase
168
                        end
169
                `SETcc:
170
                        begin
171
                                case(cond)
172
                                `SET:   res <= 32'd1;
173
                                `SEQ:   res <=  cr_zf;
174
                                `SNE:   res <= !cr_zf;
175
                                `SMI:   res <= ( cr_nf);
176
                                `SPL:   res <= (!cr_zf);
177
                                `SHI:   res <= (!cr_cf & !cr_zf);
178
                                `SLS:   res <= (cf |zf);
179
                                `SHS:   res <= (!cr_cf);
180
                                `SLO:   res <= ( cr_cf);
181
                                `SGT:   res <= ((cr_nf & cr_vf & !cr_zf)|(!cr_nf & !cr_vf & !cr_zf));
182
                                `SLE:   res <= (cr_zf | (cr_nf & !cr_vf) | (!cr_nf & cr_vf));
183
                                `SGE:   res <= ((cr_nf & cr_vf)|(!cr_nf & !cr_vf));
184
                                `SLT:   res <= ((cr_nf & !cr_vf)|(!cr_nf & cr_vf));
185
                                `SVS:   res <= ( cr_vf);
186
                                `SVC:   res <= (!cr_vf);
187
                                endcase
188
                        end
189
                `ADDI:  res <= a + imm;
190
                `SUBI:  res <= a - imm;
191
                `CMPI:  res <= a - imm;
192
                `ANDI:  res <= a & imm;
193
                `ORI:   res <= a | imm;
194
                `EORI:  res <= a ^ imm;
195 10 robfinch
/*
196 2 robfinch
                        case(ir[20:16])
197
                        `ORI_CCR:
198
                                begin
199
                                        state <= IFETCH;
200
                                        cr0 <= cr0 | imm[3:0];
201
                                        cr1 <= cr1 | imm[7:4];
202
                                        cr2 <= cr2 | imm[11:8];
203
                                        cr3 <= cr3 | imm[15:12];
204
                                        cr4 <= cr4 | imm[19:16];
205
                                        cr5 <= cr5 | imm[23:20];
206
                                        cr6 <= cr6 | imm[27:24];
207
                                        cr7 <= cr7 | imm[31:28];
208
                                end
209
                        `ANDI_CCR:
210
                                begin
211
                                        state <= IFETCH;
212
                                        cr0 <= cr0 & imm[3:0];
213
                                        cr1 <= cr1 & imm[7:4];
214
                                        cr2 <= cr2 & imm[11:8];
215
                                        cr3 <= cr3 & imm[15:12];
216
                                        cr4 <= cr4 & imm[19:16];
217
                                        cr5 <= cr5 & imm[23:20];
218
                                        cr6 <= cr6 & imm[27:24];
219
                                        cr7 <= cr7 & imm[31:28];
220
                                end
221
                        `EORI_CCR:
222
                                begin
223
                                        state <= IFETCH;
224
                                        cr0 <= cr0 ^ imm[3:0];
225
                                        cr1 <= cr1 ^ imm[7:4];
226
                                        cr2 <= cr2 ^ imm[11:8];
227
                                        cr3 <= cr3 ^ imm[15:12];
228
                                        cr4 <= cr4 ^ imm[19:16];
229
                                        cr5 <= cr5 ^ imm[23:20];
230
                                        cr6 <= cr6 ^ imm[27:24];
231
                                        cr7 <= cr7 ^ imm[31:28];
232
                                end
233
                        endcase
234 10 robfinch
*/
235 2 robfinch
                `LINK:  state <= LINK;
236 10 robfinch
                `MULUI: state <= MULTDIV1;
237
                `MULSI: state <= MULTDIV1;
238
                `DIVUI: state <= MULTDIV1;
239
                `DIVSI: state <= MULTDIV1;
240 2 robfinch
                default:        res <= 32'd0;
241
                endcase
242
                case(opcode)
243
                `TAS:   begin ea <= a + imm; mopcode <= opcode; state <= TAS; end
244
                `LW:    begin ea <= a + imm; mopcode <= opcode; state <= MEMORY1; end
245
                `LH:    begin ea <= a + imm; mopcode <= opcode; state <= MEMORY1; end
246
                `LB:    begin ea <= a + imm; mopcode <= opcode; state <= MEMORY1; end
247
                `LHU:   begin ea <= a + imm; mopcode <= opcode; state <= MEMORY1; end
248
                `LBU:   begin ea <= a + imm; mopcode <= opcode; state <= MEMORY1; end
249
                `SW:    begin ea <= a + imm; mopcode <= opcode; state <= MEMORY1; end
250
                `SH:    begin ea <= a + imm; mopcode <= opcode; state <= MEMORY1; end
251
                `SB:    begin ea <= a + imm; mopcode <= opcode; state <= MEMORY1; end
252
                `PEA:   begin ea <= a + imm; mopcode <= opcode; state <= PEA; end
253
                default:        ea <= 32'd0;
254
                endcase
255
        end

powered by: WebSVN 2.1.0

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