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

Subversion Repositories thor

[/] [thor/] [trunk/] [FT64v7/] [rtl/] [common/] [FT64_iexpander.v] - Blame information for rev 61

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 60 robfinch
// ============================================================================
2
//        __
3 61 robfinch
//   \\__/ o\    (C) 2017-2019  Robert Finch, Waterloo
4 60 robfinch
//    \  __ /    All rights reserved.
5
//     \/_//     robfinch<remove>@finitron.ca
6
//       ||
7
//
8
//      FT64_iexpander.v
9
//
10
// This source file is free software: you can redistribute it and/or modify 
11
// it under the terms of the GNU Lesser General Public License as published 
12
// by the Free Software Foundation, either version 3 of the License, or     
13
// (at your option) any later version.                                      
14
//                                                                          
15
// This source file is distributed in the hope that it will be useful,      
16
// but WITHOUT ANY WARRANTY; without even the implied warranty of           
17
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            
18
// GNU General Public License for more details.                             
19
//                                                                          
20
// You should have received a copy of the GNU General Public License        
21
// along with this program.  If not, see <http://www.gnu.org/licenses/>.    
22
//
23
// ============================================================================
24
//
25
`include ".\FT64_defines.vh"
26
 
27
module FT64_iexpander(cinstr,expand);
28
input [15:0] cinstr;
29
output reg [47:0] expand;
30
 
31
// Maps a subset of registers for compressed instructions.
32
function [4:0] fnRp;
33
input [2:0] rg;
34
case(rg)
35
3'd0:   fnRp = 5'd1;            // return value 0
36
3'd1:   fnRp = 5'd3;            // temp
37
3'd2:   fnRp = 5'd4;            // temp
38
3'd3:   fnRp = 5'd11;           // regvar
39
3'd4:   fnRp = 5'd12;           // regvar
40
3'd5:   fnRp = 5'd18;           // arg1
41
3'd6:   fnRp = 5'd19;           // arg2
42
3'd7:   fnRp = 5'd20;           // arg3
43
endcase
44
endfunction
45
 
46
always @*
47
casez({cinstr[15:12],cinstr[6]})
48
5'b00000:       // NOP / ADDI
49
        case(cinstr[4:0])
50
        5'd31:  begin
51
                        expand[47:32] = 16'h0000;
52
                        expand[31:18] = {{6{cinstr[11]}},cinstr[11:8],cinstr[5],3'b0};
53
                        expand[17:13] = cinstr[4:0];
54
                        expand[12:8] = cinstr[4:0];
55
                        expand[7:6] = 2'b10;
56
                        expand[5:0] = `ADDI;
57
                        end
58
        default:
59
                        begin
60
                        expand[47:32] = 16'h0000;
61
                        expand[31:18] = {{9{cinstr[11]}},cinstr[11:8],cinstr[5]};
62
                        expand[17:13] = cinstr[4:0];
63
                        expand[12:8] = cinstr[4:0];
64
                        expand[7:6] = 2'b10;
65
                        expand[5:0] = `ADDI;
66
                        end
67
        endcase
68
5'b00010:       // SYS
69
                        if (cinstr[4:0]==5'd0) begin
70
                                expand[47:32] = 16'h0000;
71
                                expand[5:0] = `BRK;
72
                                expand[7:6] = 2'b10;
73
                                expand[15:8] = {3'd1,cinstr[11:8],cinstr[5]};
74
                                expand[16] = 1'b0;
75
                                expand[20:17] = 4'd0;
76
                                expand[23:21] = 3'd1;
77
                                expand[31:24] = 8'd0;
78
                        end
79
                        // LDI
80
                        else begin
81
                                expand[47:32] = 16'h0000;
82
                                expand[31:18] = {{9{cinstr[11]}},cinstr[11:8],cinstr[5]};
83
                                expand[17:13] = cinstr[4:0];
84
                                expand[12:8] = 5'd0;
85
                                expand[7:6] = 2'b10;
86
                                expand[5:0] = `ADDI;     // ADDI to sign extend
87
                        end
88
5'b00100:       // RET / ANDI
89
                        if (cinstr[4:0]==5'd0) begin
90
                                expand[47:32] = 16'h0000;
91
                                expand[31:23] = {4'd0,cinstr[11:8],cinstr[5]};
92
                                expand[22:18] = 5'd29;
93
                                expand[17:13] = 5'd31;
94
                                expand[12:8] = 5'd31;
95
                                expand[7:6] = 2'b10;
96
                                expand[5:0] = `RET;
97
                        end
98
                        else begin
99
                                expand[47:32] = 16'h0000;
100
                                expand[5:0] = `ANDI;
101
                                expand[7:6] = 2'b10;
102
                                expand[12:8] = cinstr[4:0];
103
                                expand[17:13] = cinstr[4:0];
104
                                expand[31:18] = {{11{cinstr[11]}},cinstr[11:8],cinstr[5]};
105
                        end
106
5'b00110:       // SHLI
107
                        begin
108
                        expand[47:32] = 16'h0000;
109
                        expand[31:26] = 6'h0F;  // immediate mode 0-31
110
                        expand[25:23] = 3'd0;   // SHL
111
                        expand[22:18] = {cinstr[11:8],cinstr[5]};       // amount
112
                        expand[17:13] = cinstr[4:0];
113
                        expand[12:8] = cinstr[4:0];
114
                        expand[7:6] = 2'b10;
115
                        expand[5:0] = 8'h02;             // R2 instruction
116
                        end
117
5'b01000:
118
                        case(cinstr[5:4])
119
                        2'd0:           // SHRI
120
                                begin
121
                                expand[47:32] = 16'h0000;
122
                                expand[31:26] = 6'h0F;          // shift immediate 0-31
123
                                expand[25:23] = 3'd1;           // SHR
124
                                expand[22:18] = {cinstr[11:8],cinstr[3]};       // amount
125
                                expand[17:13] = fnRp(cinstr[2:0]);
126
                                expand[12:8] = fnRp(cinstr[2:0]);
127
                                expand[7:6] = 2'b10;
128
                                expand[5:0] = 8'h02;             // R2 instruction
129
                                end
130
                        2'd1:           // ASRI
131
                                begin
132
                                expand[47:32] = 16'h0000;
133
                                expand[31:26] = 6'h0F;          // shift immediate 0-31
134
                                expand[25:23] = 3'd3;           // ASR
135
                                expand[22:18] = {cinstr[11:8],cinstr[3]};       // amount
136
                                expand[17:13] = fnRp(cinstr[2:0]);
137
                                expand[12:8] = fnRp(cinstr[2:0]);
138
                                expand[7:6] = 2'b10;
139
                                expand[5:0] = 8'h02;             // R2 instruction
140
                                end
141
                        2'd2:           // ORI
142
                                begin
143
                                expand[47:32] = 16'h0000;
144
                                expand[31:18] = {{9{cinstr[11]}},cinstr[11:8],cinstr[3]};
145
                                expand[17:13] = fnRp(cinstr[2:0]);
146
                                expand[12:8] = fnRp(cinstr[2:0]);
147
                                expand[7:6] = 2'b10;
148
                                expand[5:0] = `ORI;
149
                                end
150
                        2'd3:
151
                                case(cinstr[11:10])
152
                                2'd0:   begin
153
                                                expand[47:32] = 16'h0000;
154
                                                expand[31:26] = `SUB;
155
                                                expand[25:23] = 3'b011; // word size
156
                                                expand[22:18] = fnRp({cinstr[9:8],cinstr[3]});
157
                                                expand[17:13] = fnRp(cinstr[2:0]);
158
                                                expand[12:8] = fnRp(cinstr[2:0]);
159
                                                expand[7:6] = 2'b10;
160 61 robfinch
                                                expand[5:0] = 6'h02;             // R2 instruction
161 60 robfinch
                                                end
162
                                2'd1:   begin
163
                                                expand[47:32] = 16'h0000;
164
                                                expand[31:26] = `AND;
165
                                                expand[25:23] = 3'b011; // word size
166
                                                expand[22:18] = fnRp({cinstr[9:8],cinstr[3]});
167
                                                expand[17:13] = fnRp(cinstr[2:0]);
168
                                                expand[12:8] = fnRp(cinstr[2:0]);
169
                                                expand[7:6] = 2'b10;
170 61 robfinch
                                                expand[5:0] = 6'h02;             // R2 instruction
171 60 robfinch
                                                end
172
                                2'd2:   begin
173
                                                expand[47:32] = 16'h0000;
174
                                                expand[31:26] = `OR;
175
                                                expand[25:23] = 3'b011; // word size
176
                                                expand[22:18] = fnRp({cinstr[9:8],cinstr[3]});
177
                                                expand[17:13] = fnRp(cinstr[2:0]);
178
                                                expand[12:8] = fnRp(cinstr[2:0]);
179
                                                expand[7:6] = 2'b10;
180 61 robfinch
                                                expand[5:0] = 6'h02;             // R2 instruction
181 60 robfinch
                                                end
182
                                2'd3:   begin
183
                                                expand[47:32] = 16'h0000;
184
                                                expand[31:26] = `XOR;
185
                                                expand[25:23] = 3'b011; // word size
186
                                                expand[22:18] = fnRp({cinstr[9:8],cinstr[3]});
187
                                                expand[17:13] = fnRp(cinstr[2:0]);
188
                                                expand[12:8] = fnRp(cinstr[2:0]);
189
                                                expand[7:6] = 2'b10;
190 61 robfinch
                                                expand[5:0] = 6'h02;             // R2 instruction
191 60 robfinch
                                                end
192
                                endcase
193
                        endcase
194
5'b01110:
195
                begin
196
                        expand[47:32] = 16'h0000;
197
                        expand[31:23] = {{1{cinstr[11]}},{cinstr[11:8],cinstr[5:2]}};
198
                        expand[22:18] = 5'd0;           // Rb = 0
199
                        expand[17:16] = cinstr[1:0];
200
                        expand[15:13] = 3'd0;           // BEQ
201 61 robfinch
                        expand[12:8] = 5'd0;            // Ra = r0
202 60 robfinch
                        expand[7:6] = 2'b10;
203
                        expand[5:0] = `Bcc;              // 0x38
204
                end
205
5'b10??0:
206
                begin
207
                        expand[47:32] = 16'h0000;
208
                        expand[31:23] = {{4{cinstr[13]}},cinstr[13:9]};
209
                        expand[22:18] = 5'd0;                   // r0
210
                        expand[17:16] = {cinstr[8],cinstr[5]};
211
                        expand[15:13] = 3'd0;                   // BEQ
212
                        expand[12:8] = cinstr[4:0];      // Ra
213
                        expand[7:6] = 2'b10;
214
                        expand[5:0] = `Bcc;
215
                end
216
5'b11??0:
217
                begin
218
                        expand[47:32] = 16'h0000;
219
                        expand[31:23] = {{4{cinstr[13]}},cinstr[13:9]};
220
                        expand[22:18] = 5'd0;                   // r0
221
                        expand[17:16] = {cinstr[8],cinstr[5]};
222
                        expand[15:13] = 3'd1;                   // BNE
223
                        expand[12:8] = cinstr[4:0];      // Ra
224
                        expand[7:6] = 2'b10;
225
                        expand[5:0] = `Bcc;
226
                end
227
5'b00001:
228
                begin
229
                        expand[47:32] = 16'h0000;
230
                        expand[31:26] = `MOV;                   // `MOV is 6'b01001?
231
                        expand[26] = 1'b0;
232
                        expand[25:23] = 3'd7;                   // move current to current
233
                        expand[22:18] = 5'd0;                   // register set (ignored)
234
                        expand[17:13] = {cinstr[11:8],cinstr[5]};
235
                        expand[12:8] = cinstr[4:0];
236
                        expand[7:6] = 2'b10;
237
                        expand[5:0] = 6'h02;
238
                end
239
5'b00011:       // ADD
240
                begin
241
                        expand[47:32] = 16'h0000;
242
                        expand[31:26] = `ADD;
243
                        expand[27:23] = 3'b011; // word size
244
                        expand[22:18] = {cinstr[11:8],cinstr[5]};
245
                        expand[17:13] = cinstr[4:0];
246
                        expand[12:8] = cinstr[4:0];
247
                        expand[7:6] = 2'b10;
248
                        expand[5:0] = 6'h02;             // R2 instruction
249
                end
250
5'b00101:       // JALR
251
                begin
252
                        expand[47:32] = 16'h0000;
253
                        expand[31:18] = 14'd0;
254
                        expand[17:13] = {cinstr[11:8],cinstr[5]};
255
                        expand[12:8] = cinstr[4:0];
256
                        expand[7:6] = 2'b10;
257
                        expand[5:0] = `JAL;
258
                end
259
5'b00111:
260
                if ({cinstr[11:8]==4'h1}) begin
261
                        expand[47:32] = 16'h0000;
262
                        expand[31:26] = 6'h36;          // SEG instructions
263
                        expand[22:18] = {2'b0,cinstr[2:0]};
264
                        expand[17:13] = 5'd0;                   // no target
265
                        expand[12:8] = 5'd0;
266
                        expand[7:6] = 2'b10;
267
                        expand[5:0] = 6'h02;
268
                end
269
                else if ({cinstr[11:8],cinstr[5]}==5'b0) begin  // PUSH
270
                        expand[47:32] = 16'h0000;
271
                        expand[31:28] = 4'hC;
272
                        expand[27:23] = 5'd0;
273
                        expand[22:18] = cinstr[4:0];
274
                        expand[17:13] = 5'd31;
275
                        expand[12:8] = 5'd31;
276
                        expand[7:6] = 2'b10;
277
                        expand[5:0] = `MEMNDX;
278
                end
279
                else begin
280
                        expand[47:8] = 40'd0;
281
                        expand[7:6] = 2'b10;
282
                        expand[5:0] = `NOP;
283
                end
284
5'b01001:       // LH Rt,d[SP]
285
                begin
286
                        expand[47:32] = 16'h0000;
287
                        expand[31:18] = {{7{cinstr[11]}},cinstr[11:8],cinstr[5],2'd2};
288
                        expand[17:13] = {cinstr[4:0]};
289
                        expand[12:8] = 5'd31;
290
                        expand[7:6] = 2'b10;
291
                        expand[5:0] = `Lx;
292
                end
293
5'b01011:       // LW Rt,d[SP]
294
                begin
295
                        expand[47:32] = 16'h0000;
296
                        expand[31:18] = {{6{cinstr[11]}},cinstr[11:8],cinstr[5],3'd4};
297
                        expand[17:13] = cinstr[4:0];
298
                        expand[12:8] = 5'd31;
299
                        expand[7:6] = 2'b10;
300
                        expand[5:0] = `Lx;
301
                end
302
5'b01101:       // LH Rt,d[fP]
303
                begin
304
                        expand[47:32] = 16'h0000;
305
                        expand[31:18] = {{7{cinstr[11]}},cinstr[11:8],cinstr[5],2'd2};
306
                        expand[17:13] = cinstr[4:0];
307
                        expand[12:8] = 5'd30;
308
                        expand[7:6] = 2'b10;
309
                        expand[5:0] = `Lx;
310
                end
311
5'b01111:       // LW Rt,d[FP]
312
                begin
313
                        expand[47:32] = 16'h0000;
314
                        expand[31:18] = {{6{cinstr[11]}},cinstr[11:8],cinstr[5],3'd4};
315
                        expand[17:13] = cinstr[4:0];
316
                        expand[12:8] = 5'd30;
317
                        expand[7:6] = 2'b10;
318
                        expand[5:0] = `Lx;
319
                end
320
5'b10001:       // SH Rt,d[SP]
321
                begin
322
                        expand[47:32] = 16'h0000;
323
                        expand[31:23] = {{7{cinstr[11]}},cinstr[11:10]};
324
                        expand[22:18] = cinstr[4:0];
325
                        expand[17:13] = {cinstr[9:8],cinstr[5],2'd2};
326
                        expand[12:8] = 5'd31;
327
                        expand[7:6] = 2'b10;
328
                        expand[5:0] = `Sx;
329
                end
330
5'b10011:       // SW Rt,d[SP]
331
                begin
332
                        expand[47:32] = 16'h0000;
333
                        expand[31:23] = {{6{cinstr[11]}},cinstr[11:9]};
334
                        expand[22:18] = cinstr[4:0];
335
                        expand[17:13] = {cinstr[8],cinstr[5],3'd4};
336
                        expand[12:8] = 5'd31;
337
                        expand[7:6] = 2'b10;
338
                        expand[5:0] = `Sx;
339
                end
340
5'b10101:       // SH Rt,d[fP]
341
                begin
342
                        expand[47:32] = 16'h0000;
343
                        expand[31:23] = {{7{cinstr[11]}},cinstr[11:10]};
344
                        expand[22:18] = cinstr[4:0];
345
                        expand[17:13] = {cinstr[9:8],cinstr[5],2'd2};
346
                        expand[12:8] = 5'd30;
347
                        expand[7:6] = 2'b10;
348
                        expand[5:0] = `Sx;
349
                end
350
5'b10111:       // SW Rt,d[FP]
351
                begin
352
                        expand[47:32] = 16'h0000;
353
                        expand[31:23] = {{6{cinstr[11]}},cinstr[11:9]};
354
                        expand[22:18] = cinstr[4:0];
355
                        expand[17:13] = {cinstr[8],cinstr[5],3'd4};
356
                        expand[12:8] = 5'd30;
357
                        expand[7:6] = 2'b10;
358
                        expand[5:0] = `Sx;
359
                end
360
5'b11001:
361
                begin   // LH
362
                        expand[47:32] = 16'h0000;
363
                        expand[31:18] = {{8{cinstr[11]}},cinstr[11:10],cinstr[4:3],2'd2};
364
                        expand[17:13] = fnRp({cinstr[9:8],cinstr[5]});
365
                        expand[12:8] = fnRp(cinstr[2:0]);
366
                        expand[7:6] = 2'b10;
367
                        expand[5:0] = `Lx;
368
                end
369
5'b11011:       // LW
370
                begin
371
                        expand[47:32] = 16'h0000;
372
                        expand[31:18] = {{7{cinstr[11]}},cinstr[11:10],cinstr[4:3],3'd4};
373
                        expand[17:13] = fnRp({cinstr[9:8],cinstr[5]});
374
                        expand[12:8] = fnRp(cinstr[2:0]);
375
                        expand[7:6] = 2'b10;
376
                        expand[5:0] = `Lx;
377
                end
378
5'b11101:       // SH
379
                begin
380
                        expand[47:32] = 16'h0000;
381
                        expand[31:23] = {{8{cinstr[11]}},cinstr[11]};
382
                        expand[22:18] = fnRp({cinstr[9:8],cinstr[5]});
383
                        expand[17:13] = {cinstr[10],cinstr[4:3],2'd2};
384
                        expand[12:8] = fnRp(cinstr[2:0]);
385
                        expand[7:6] = 2'b10;
386
                        expand[5:0] = `Sx;
387
                end
388
5'b11111:       // SW
389
                begin
390
                        expand[47:32] = 16'h0000;
391
                        expand[31:23] = {{7{cinstr[11]}},cinstr[11:10]};
392
                        expand[22:18] = fnRp({cinstr[9:8],cinstr[5]});
393
                        expand[17:13] = {cinstr[4:3],3'd4};
394
                        expand[12:8] = fnRp(cinstr[2:0]);
395
                        expand[7:6] = 2'b10;
396
                        expand[5:0] = `Sx;
397
                end
398
default:
399
                begin
400
                        expand[47:8] = 40'd0;
401
                        expand[7:6] = 2'b10;
402
                        expand[5:0] = `NOP;
403
                end
404
endcase
405
 
406
endmodule

powered by: WebSVN 2.1.0

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