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

Subversion Repositories rtf8088

[/] [rtf8088/] [trunk/] [rtl/] [verilog/] [EXECUTE.v] - Blame information for rev 4

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

Line No. Rev Author Line
1 2 robfinch
// ============================================================================
2
//  (C) 2009,2010,2012  Robert Finch
3
//  robfinch<remove>@opencores.org
4
//
5
//  EXECUTE
6
//  - execute instruction
7
//
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
//  Verilog 
24
//
25
// ============================================================================
26
//
27
EXECUTE:
28
        begin
29
                casex(ir)
30
 
31
                `EXTOP:
32
                        casex(ir2)
33
                        `LxDT: state <= FETCH_DESC;
34
                        endcase
35
 
36
                `DAA:
37
                        begin
38
                                state <= IFETCH;
39
                        end
40
 
41
                `ALU_I2R8,`ALU_I2R16,`ADD,`ADD_ALI8,`ADD_AXI16,`ADC,`ADC_ALI8,`ADC_AXI16:
42
                        begin
43
                                state <= IFETCH;
44
                                wrregs <= 1'b1;
45
                                res <= alu_o;
46
                                pf <= pres;
47
                                af <= carry   (1'b0,a[3],b[3],alu_o[3]);
48
                                cf <= carry   (1'b0,amsb,bmsb,resn);
49
                                vf <= overflow(1'b0,amsb,bmsb,resn);
50
                                sf <= resn;
51
                                zf <= resz;
52
                        end
53
 
54
                `AND,`OR,`XOR,`AND_ALI8,`OR_ALI8,`XOR_ALI8,`AND_AXI16,`OR_AXI16,`XOR_AXI16:
55
                        begin
56
                                state <= IFETCH;
57
                                wrregs <= 1'b1;
58
                                res <= alu_o;
59
                                pf <= pres;
60
                                cf <= 1'b0;
61
                                vf <= 1'b0;
62
                                sf <= resn;
63
                                zf <= resz;
64
                        end
65
 
66
                `TEST:
67
                        begin
68
                                state <= IFETCH;
69
                                res <= alu_o;
70
                                pf <= pres;
71
                                cf <= 1'b0;
72
                                vf <= 1'b0;
73
                                sf <= resn;
74
                                zf <= resz;
75
                        end
76
 
77
                `CMP,`CMP_ALI8,`CMP_AXI16:
78
                        begin
79
                                state <= IFETCH;
80
                                pf <= pres;
81
                                af <= carry   (1'b1,a[3],b[3],alu_o[3]);
82
                                cf <= carry   (1'b1,amsb,bmsb,resn);
83
                                vf <= overflow(1'b1,amsb,bmsb,resn);
84
                                sf <= resn;
85
                                zf <= resz;
86
                        end
87
 
88
                `SBB,`SUB,`SBB_ALI8,`SUB_ALI8,`SBB_AXI16,`SUB_AXI16:
89
                        begin
90
                                wrregs <= 1'b1;
91
                                state <= IFETCH;
92
                                res <= alu_o;
93
                                pf <= pres;
94
                                af <= carry   (1'b1,a[3],b[3],alu_o[3]);
95
                                cf <= carry   (1'b1,amsb,bmsb,resn);
96
                                vf <= overflow(1'b1,amsb,bmsb,resn);
97
                                sf <= resn;
98
                                zf <= resz;
99
                        end
100
 
101
                8'hF6,8'hF7:
102
                        begin
103
                                wrregs <= 1'b1;
104
                                state <= IFETCH;
105
                                case(rrr)
106
                                3'd2: res <= ~b;        // NOT
107
                                3'd3: res <= -b;        // NEG
108
                                endcase
109
                        end
110
                `INC_REG:
111
                        begin
112
                                state <= IFETCH;
113
                                wrregs <= 1'b1;
114
                                w <= 1'b1;
115
                                res <= alu_o;
116
                                pf <= pres;
117
                                af <= carry   (1'b0,a[3],b[3],alu_o[3]);
118
                                vf <= overflow(1'b0,a[15],b[15],resnw);
119
                                sf <= resnw;
120
                                zf <= reszw;
121
                        end
122
                `DEC_REG:
123
                        begin
124
                                state <= IFETCH;
125
                                wrregs <= 1'b1;
126
                                w <= 1'b1;
127
                                res <= alu_o;
128
                                pf <= pres;
129
                                af <= carry   (1'b1,a[3],b[3],alu_o[3]);
130
                                vf <= overflow(1'b1,a[15],b[15],resnw);
131
                                sf <= resnw;
132
                                zf <= reszw;
133
                        end
134
                `IMUL:
135
                        begin
136
                                state <= IFETCH;
137
                                wrregs <= 1'b1;
138
                                w <= 1'b1;
139
                                rrr <= 3'd0;
140
                                res <= alu_o;
141
                                if (w) begin
142
                                        cf <= wp[31:16]!={16{resnw}};
143
                                        vf <= wp[31:16]!={16{resnw}};
144
                                        dx <= wp[31:16];
145
                                end
146
                                else begin
147
                                        cf <= ah!={8{resnb}};
148
                                        vf <= ah!={8{resnb}};
149
                                end
150
                        end
151
 
152
 
153
                //-----------------------------------------------------------------
154
                // Memory Operations
155
                //-----------------------------------------------------------------
156
 
157
                // registers not allowed on LEA
158
                // invalid opcode
159
                //
160
                `LEA:
161
                        begin
162
                                w <= 1'b1;
163
                                res <= ea;
164
                                if (mod==2'b11) begin
165
                                        int_num <= 8'h06;
166
                                        state <= INT;
167
                                end
168
                                else begin
169
                                        state <= IFETCH;
170
                                        wrregs <= 1'b1;
171
                                end
172
                        end
173
                `LDS:
174
                        begin
175
                                wrsregs <= 1'b1;
176
                                res <= alu_o;
177
                                rrr <= 3'd3;
178
                                state <= IFETCH;
179
                        end
180
                `LES:
181
                        begin
182
                                wrsregs <= 1'b1;
183
                                res <= alu_o;
184
                                rrr <= 3'd0;
185
                                state <= IFETCH;
186
                        end
187
 
188
                `MOV_RR8,`MOV_RR16,
189
                `MOV_MR,
190
                `MOV_M2AL,`MOV_M2AX,
191
                `MOV_I2AL,`MOV_I2DL,`MOV_I2CL,`MOV_I2BL,`MOV_I2AH,`MOV_I2DH,`MOV_I2CH,`MOV_I2BH,
192
                `MOV_I2AX,`MOV_I2DX,`MOV_I2CX,`MOV_I2BX,`MOV_I2SP,`MOV_I2BP,`MOV_I2SI,`MOV_I2DI:
193
                        begin
194
                                state <= IFETCH;
195
                                wrregs <= 1'b1;
196
                                res <= alu_o;
197
                        end
198
                `XCHG_MEM:
199
                        begin
200
                                wrregs <= 1'b1;
201
                                if (mod==2'b11) rrr <= rm;
202
                                res <= alu_o;
203
                                b <= rrro;
204
                                state <= mod==2'b11 ? IFETCH : XCHG_MEM;
205
                        end
206
                `MOV_I8M,`MOV_I16M:
207
                        begin
208
                                res <= alu_o;
209
                                state <= rrr==3'd0 ? STORE_DATA : INVALID_OPCODE;
210
                        end
211
 
212
                `MOV_S2R:
213
                        begin
214
                                w <= 1'b1;
215
                                rrr <= rm;
216
                                res <= b;
217
                                if (mod==2'b11) begin
218
                                        state <= IFETCH;
219
                                        wrregs <= 1'b1;
220
                                end
221
                                else
222
                                        state <= STORE_DATA;
223
                        end
224
                `MOV_R2S:
225
                        begin
226
                                wrsregs <= 1'b1;
227
                                res <= alu_o;
228
                                state <= IFETCH;
229
                        end
230
 
231
                `LODSB:
232
                        begin
233
                                state <= IFETCH;
234
                                wrregs <= 1'b1;
235
                                w <= 1'b0;
236
                                rrr <= 3'd0;
237
                                res <= a[7:0];
238
                                if ( df) si <= si_dec;
239
                                if (!df) si <= si_inc;
240
                        end
241
                `LODSW:
242
                        begin
243
                                state <= IFETCH;
244
                                wrregs <= 1'b1;
245
                                w <= 1'b1;
246
                                rrr <= 3'd0;
247
                                res <= a;
248
                                if ( df) si <= si - 16'd2;
249
                                if (!df) si <= si + 16'd2;
250
                        end
251
 
252
                8'hD0,8'hD1,8'hD2,8'hD3,8'hC0,8'hC1:
253
                        begin
254
                                state <= IFETCH;
255
                                wrregs <= 1'b1;
256
                                if (w)
257
                                        case(rrr)
258
                                        3'b000: // ROL
259
                                                begin
260 4 robfinch
                                                        res <= shlo[15:0]|shlo[31:16];
261 2 robfinch
                                                        cf <= bmsb;
262
                                                        vf <= bmsb^b[14];
263
                                                end
264
                                        3'b001: // ROR
265
                                                begin
266 4 robfinch
                                                        res <= shruo[15:0]|shruo[31:16];
267 2 robfinch
                                                        cf <= b[0];
268
                                                        vf <= cf^b[15];
269
                                                end
270
                                        3'b010: // RCL
271
                                                begin
272 4 robfinch
                                                        res <= shlco[16:1]|shlco[32:17];
273 2 robfinch
                                                        cf <= b[15];
274
                                                        vf <= b[15]^b[14];
275
                                                end
276
                                        3'b011: // RCR
277
                                                begin
278 4 robfinch
                                                        res <= shrcuo[15:0]|shrcuo[31:16];
279 2 robfinch
                                                        cf <= b[0];
280
                                                        vf <= cf^b[15];
281
                                                end
282
                                        3'b100: // SHL
283
                                                begin
284 4 robfinch
                                                        res <= shlo[15:0];
285
                                                        cf <= shlo[16];
286 2 robfinch
                                                        vf <= b[15]^b[14];
287
                                                end
288
                                        3'b101: // SHR
289
                                                begin
290 4 robfinch
                                                        res <= shruo[31:16];
291
                                                        cf <= shruo[15];
292 2 robfinch
                                                        vf <= b[15];
293
                                                end
294
                                        3'b111: // SAR
295
                                                begin
296 4 robfinch
                                                        res <= shro;
297 2 robfinch
                                                        cf <= b[0];
298
                                                        vf <= 1'b0;
299
                                                end
300
                                        endcase
301
                                else
302
                                        case(rrr)
303
                                        3'b000: // ROL
304
                                                begin
305 4 robfinch
                                                        res <= shlo8[7:0]|shlo8[15:8];
306 2 robfinch
                                                        cf <= b[7];
307
                                                        vf <= b[7]^b[6];
308
                                                end
309
                                        3'b001: // ROR
310
                                                begin
311 4 robfinch
                                                        res <= shruo8[15:8]|shruo8[7:0];
312 2 robfinch
                                                        cf <= b[0];
313
                                                        vf <= cf^b[7];
314
                                                end
315
                                        3'b010: // RCL
316
                                                begin
317 4 robfinch
                                                        res <= shlco8[8:1]|shlco8[16:9];
318 2 robfinch
                                                        cf <= b[7];
319
                                                        vf <= b[7]^b[6];
320
                                                end
321
                                        3'b011: // RCR
322
                                                begin
323 4 robfinch
                                                        res <= shrcuo8[15:8]|shrcuo8[7:0];
324 2 robfinch
                                                        cf <= b[0];
325
                                                        vf <= cf^b[7];
326
                                                end
327
                                        3'b100: // SHL
328
                                                begin
329 4 robfinch
                                                        res <= shlo8[7:0];
330
                                                        cf <= shlo8[8];
331 2 robfinch
                                                        vf <= b[7]^b[6];
332
                                                end
333
                                        3'b101: // SHR
334
                                                begin
335 4 robfinch
                                                        res <= shruo8[15:8];
336
                                                        cf <= shruo8[7];
337 2 robfinch
                                                        vf <= b[7];
338
                                                end
339
                                        3'b111: // SAR
340
                                                begin
341 4 robfinch
                                                        res <= shro8;
342 2 robfinch
                                                        cf <= b[0];
343
                                                        vf <= 1'b0;
344
                                                end
345
                                        endcase
346
                        end
347
 
348
                //-----------------------------------------------------------------
349
                //-----------------------------------------------------------------
350
                `GRPFF:
351
                        begin
352
                                case(rrr)
353
                                3'b000:         // INC
354
                                        begin
355
                                                state <= IFETCH;
356
                                                wrregs <= 1'b1;
357
                                                af <= carry   (1'b0,a[3],b[3],alu_o[3]);
358
                                                vf <= overflow(1'b0,a[15],b[15],alu_o[15]);
359
                                                w <= 1'b1;
360
                                                res <= alu_o;
361
                                                rrr <= rm;
362
                                                pf <= pres;
363
                                                sf <= resnw;
364
                                                zf <= reszw;
365
                                        end
366
                                3'b001:         // DEC
367
                                        begin
368
                                                state <= IFETCH;
369
                                                wrregs <= 1'b1;
370
                                                af <= carry   (1'b1,a[3],b[3],alu_o[3]);
371
                                                vf <= overflow(1'b1,a[15],b[15],alu_o[15]);
372
                                                w <= 1'b1;
373
                                                res <= alu_o;
374
                                                rrr <= rm;
375
                                                pf <= pres;
376
                                                sf <= resnw;
377
                                                zf <= reszw;
378
                                        end
379
                                3'b010: begin sp <= sp_dec; state <= CALL_IN; end
380
                                // These two should not be reachable here, as they would
381
                                // be trapped by the EACALC.
382
                                3'b011: state <= CALL_FIN;      // CALL FAR indirect
383
                                3'b101: // JMP FAR indirect
384
                                        begin
385
                                                ip <= offset;
386
                                                cs <= selector;
387
                                                state <= IFETCH;
388
                                        end
389
                                3'b110: begin sp <= sp_dec; state <= PUSH; end
390
                                default:
391
                                        begin
392
                                                af <= carry   (1'b0,a[3],b[3],alu_o[3]);
393
                                                vf <= overflow(1'b0,a[15],b[15],alu_o[15]);
394
                                        end
395
                                endcase
396
                        end
397
 
398
                //-----------------------------------------------------------------
399
                //-----------------------------------------------------------------
400
                default:
401
                        state <= IFETCH;
402
                endcase
403
        end
404
 

powered by: WebSVN 2.1.0

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