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

Subversion Repositories forwardcom

[/] [forwardcom/] [bintools/] [format_tables.cpp] - Blame information for rev 99

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

Line No. Rev Author Line
1 59 Agner
/****************************  format_tables.cpp  ***************************
2
* Author:        Agner Fog
3
* date created:  2018-02-18
4
* Last modified: 2021-06-30
5
* Version:       1.11
6
* Project:       Binary tools for ForwardCom instruction set
7
* Description:
8
* Format tables used by emulator, assembler, and disassembler
9
*
10
* Copyright 2018-2021 GN1 General Public License http://www.gnu.org/licenses
11
*****************************************************************************/
12
 
13
#include "stdafx.h"
14
 
15
// formatList is a list of instruction formats. All format-dependent code should preferably rely on this list.
16
// The list contains all details about each instruction format.
17
// This is used by both the assembler, disassembler, and emulator. 
18
// See definition of structure SFormat in disassem.h.
19
 
20
// A lookup in formatList uses a nested table lookup as follows:
21
// il.mode.M is used as index into formatI. The indexes have constants FX000, etc.
22
// formatI contains an index into formatJ and a criterion for division into subgroups.
23
// formatJ contains an index into formatList or an index into formatJ if further subdivision is needed.
24
 
25
// Indexes into formatList:
26
const int FX000 = 0;
27
const int FX010 = FX000 + 1;
28
const int FX020 = FX010 + 1;
29
const int FX030 = FX020 + 1;
30
const int FX040 = FX030 + 1;
31
const int FX050 = FX040 + 1;
32
const int FX060 = FX050 + 1;
33
const int FX070 = FX060 + 1;
34
const int FX080 = FX070 + 1;
35
const int FX090 = FX080 + 1;
36
const int FX100 = FX090 + 1;
37
const int FX110 = FX100 + 1;
38
const int FX120 = FX110 + 1;
39
const int FX130 = FX120 + 1;
40
const int FX141 = FX130 + 1;
41
const int FX142 = FX141 + 1;
42
const int FX143 = FX142 + 1;
43
const int FX144 = FX143 + 1;
44
const int FX150 = FX144 + 1;
45
const int FX160 = FX150 + 1;
46
const int FX161 = FX160 + 1;
47
const int FX162 = FX161 + 1;
48
const int FX163 = FX162 + 1;
49
const int FX170 = FX163 + 1;
50
const int FX171 = FX170 + 1;
51
const int FX172 = FX171 + 1;
52
const int FX173 = FX172 + 1;
53
const int FX174 = FX173 + 1;
54
const int FX175 = FX174 + 1;
55
const int FX17A = FX175 + 1;
56
const int FX180 = FX17A + 1;
57
const int FX200 = FX180 + 1;
58
const int FX201 = FX200 + 1;
59
const int FX202 = FX201 + 1;
60
const int FX203 = FX202 + 1;
61
const int FX205 = FX203 + 1;
62
const int FX206 = FX205 + 1;
63
const int FX207 = FX206 + 1;
64
const int FX210 = FX207 + 1;
65
const int FX220 = FX210 + 1;
66
const int FX221 = FX220 + 1;
67
const int FX222 = FX221 + 1;
68
const int FX223 = FX222 + 1;
69
const int FX224 = FX223 + 1;
70
const int FX225 = FX224 + 1;
71
const int FX226 = FX225 + 1;
72
const int FX227 = FX226 + 1;
73
const int FX230 = FX227 + 1;
74
const int FX240 = FX230 + 1;
75
const int FX250 = FX240 + 1;
76
const int FX251 = FX250 + 1;
77
const int FX251X= FX251 + 1;
78
const int FX252 = FX251X+ 1;
79
const int FX252X= FX252 + 1;
80
const int FX253 = FX252X+ 1;
81
const int FX254 = FX253 + 1;
82
const int FX254X= FX254 + 1;
83
const int FX255 = FX254X+ 1;
84
const int FX255X= FX255 + 1;
85
const int FX256 = FX255X+ 1;   // unused
86
const int FX257 = FX256 + 1;
87
const int FX258 = FX257 + 1;
88
const int FX259 = FX258 + 1;
89
const int FX25A = FX259 + 1;
90
const int FX260 = FX25A + 1;
91
const int FX270 = FX260 + 1;
92
const int FX280 = FX270 + 1;
93
const int FX290 = FX280 + 1;
94
const int FX291 = FX290 + 1;
95
const int FX300 = FX291 + 1;
96
const int FX301 = FX300 + 1;
97
const int FX302 = FX301 + 1;
98
const int FX303 = FX302 + 1;
99
const int FX305 = FX303 + 1;
100
const int FX307 = FX305 + 1;
101
const int FX310 = FX307 + 1;
102
const int FX311 = FX310 + 1;
103
const int FX311X= FX311 + 1;
104
const int FX312 = FX311X+ 1;
105
const int FX313 = FX312 + 1;
106
const int FX318 = FX313 + 1;
107
const int FX320 = FX318 + 1;
108
const int FX321 = FX320 + 1;
109
const int FX322 = FX321 + 1;
110
const int FX323 = FX322 + 1;
111
const int FX325 = FX323 + 1;
112
const int FX327 = FX325 + 1;
113
const int FX330 = FX327 + 1;
114
const int FX380 = FX330 + 1;
115
const int FXEND = FX380 + 1;
116
 
117
// Indexes into formatJ:
118
const int FJ140 = 0;
119
const int FJ160 = FJ140 + 8;
120
const int FJ167 = FJ160 + 8;
121
const int FJ170 = FJ167 + 8;
122
const int FJ171 = FJ170 + 8;
123
const int FJ172 = FJ171 + 8;
124
const int FJ174 = FJ172 + 8;
125
const int FJ200 = FJ174 + 2;
126
const int FJ220 = FJ200 + 8;
127
const int FJ25_ = FJ220 + 8;
128
const int FJ25J = FJ25_ + 8;
129
const int FJ250 = FJ25J + 8;
130
const int FJ251 = FJ250 + 8;
131
const int FJ252 = FJ251 + 8;
132
const int FJ254 = FJ252 + 8;
133
const int FJ254B= FJ254 + 8;
134
const int FJ255 = FJ254B+ 8;
135
const int FJ290 = FJ255 + 8;
136
const int FJ300 = FJ290 + 8;
137
const int FJ31_ = FJ300 + 8;
138
const int FJ31J = FJ31_ + 8;
139
const int FJ311 = FJ31J + 8;
140
const int FJ320 = FJ311 + 8;
141
const int FJEND = FJ320 + 8;
142
 
143
 
144
// First list in nested lookup lists. Index is il.mode.M
145
// Each record contains: criterion and index for next table
146
// Criterion for lookup into next table: 0 = format table. 
147
// 1: mode2, 2: op1 / 8, 3: op1 % 8, 4: IM1 % 64 / 8, 5: IM1 % 8, 
148
// 6: IM12 == 0xFFFF
149
 
150
SFormatIndex formatI[] = {
151
    {0, FX000}, {0, FX080}, // 0.0, 0.8
152
    {0, FX010}, {0, FX090}, // 0.1, 0.9
153
    {0, FX020}, {0, FX020}, // 0.2
154
    {0, FX030}, {0, FX030}, // 0.3
155
    {0, FX040}, {0, FX040}, // 0.4
156
    {0, FX050}, {0, FX050}, // 0.5
157
    {0, FX060}, {0, FX060}, // 0.6
158
    {0, FX070}, {0, FX070}, // 0.7
159
    {0, FX100}, {0, FX180}, // 1.0, 1.8
160
    {0, FX110}, {0, FX110}, // 1.1 // no 1.9
161
    {0, FX120}, {0, FX120}, // 1.2
162
 
163
    {0, FX130}, {0, FX130}, // 1.3 
164
    {2, FJ140}, {2, FJ140}, // 1.4 subdivided by op1 / 8
165
    {0, FX150}, {0, FX150}, // 1.5
166
    {2, FJ160}, {2, FJ160}, // 1.6 subdivided by op1 / 8
167
    {2, FJ170}, {2, FJ170}, // 1.7 subdivided by op1 / 8    
168
 
169
    {1, FJ200}, {0, FX280}, // 2.0 subdivided by mode2, 2.8 
170
    {0, FX210}, {2, FJ290}, // 2.1, 2.9 subdivided by op1 / 8
171
    {1, FJ220}, {1, FJ220}, // 2.2 
172
    {0, FX230}, {0, FX230}, // 2.3
173
    {0, FX240}, {0, FX240}, // 2.4
174
    {2, FJ25_}, {2, FJ25_}, // 2.5, subdivided by op1 / 8
175
    {0, FX260}, {0, FX260}, // 2.6
176
    {2, FX270}, {2, FX270}, // 2.7
177
    {1, FJ300}, {0, FX380}, // 3.0, subdivided by mode2, 3.8
178
    {2, FJ31_}, {2, FJ31_}, // 3.1, subdivided by op1 / 8, there is no format 3.9
179
    {1, FJ320}, {1, FJ320}, // 3.2, subdivided by mode2
180
    {0, FX330}, {0, FX330}, // 3.3
181
    {0, FX380}, {0, FX380}, // reserved for longer instructions
182
    {0, FX380}, {0, FX380}, // 
183
    {0, FX380}, {0, FX380}, // 
184
    {0, FX380}, {0, FX380}  // 
185
};
186
 
187
 
188
// Next level of nested tables.
189
// Do not add or delete lines here without updating the index constants FJ140 etc. above
190
 
191
SFormatIndex formatJ[FJEND] = {
192
    //  FJ140: subdivision of format 1.4 by by op1 / 8
193
    {0, FX141},                                     // 141: 0  - 7
194
    {0, FX142}, {0, FX142}, {0, FX142},             // 142: 8  - 31
195
    {0, FX143},                                     // 143: 32 - 39
196
    {0, FX144}, {0, FX144},                         // 144: 40 - 55
197
    {0, FX144},                                     // 144: 56 - 63
198
 
199
    //  FJ160: subdivision of format 1.6 by by op1 / 8
200
    {0, FX160}, {0, FX160}, {0, FX160}, {0, FX160}, {0, FX160}, {0, FX160}, {0, FX160},  // 160: 0 - 55
201
    {3, FJ167},                                                                          // 161-163: 56-63
202
 
203
    //  FJ167: subdivision of format 1.6:7 by by op1 % 8
204
    {0, FX161}, {0, FX161}, {0, FX161}, {0, FX161},   // 161: 56 - 59
205
    {0, FX162}, {0, FX162},                           // 162: 60 - 61
206
    {0, FX163}, {0, FX163},                           // 163: 62 - 63
207
 
208
    //  FJ170: subdivision of format 1.7 by by op1 / 8
209
    {0, FX170}, {0, FX170},                           // 150:  0 - 15  1.7D
210
    {0, FX171}, {0, FX171}, {0, FX171}, {0, FX171},   // 151: 16 - 47  1.7C
211
    {3, FJ171}, {3, FJ172},                           // FJ171, FJ172: subdivision by op1 % 8
212
 
213
    //  FJ171: subdivision of format 1.7:6 by by op1 % 8
214
    {0, FX171}, {0, FX171}, {0, FX171}, {0, FX171},        // 172: 48 - 51
215
    {0, FX17A}, {0, FX17A},                                // 17A: 52 - 53
216
    {0, FX171}, {0, FX171},                                // 172: 54 - 55
217
 
218
    //  FJ172: subdivision of format 1.7:7 by by op1 % 8
219
    {0, FX172}, {0, FX172}, {0, FX172}, {0, FX172},        // 152: 56 - 59
220
    {0, FX173}, {0, FX173}, {0, FX173},                    // 153: 60 - 62
221
    {8, FJ174},                                            // 154: 63
222
 
223
    //  FJ174: subdivision of format 1.7:63 by by IM12 == 0xFFFF
224
    {0, FX174}, {0, FX175},                               // 154: 63, trap / filler
225
 
226
    //  FJ200: 2.0 subdivided by mode2
227
    {0, FX200}, {0, FX201}, {0, FX202}, {0, FX203},        // 2.0.0 - 2.0.3
228
    {0, FX200}, {0, FX205}, {0, FX206}, {0, FX207},        // 2.0.6 - 2.0.7
229
 
230
    //  FJ220: 2.2 subdivided by mode2
231
    {0, FX220}, {0, FX221}, {0, FX222}, {0, FX223},        // 2.2.0 - 2.2.3
232
    {0, FX224}, {0, FX225}, {0, FX226}, {0, FX227},        // 2.2.4 - 2.2.7
233
 
234
    //  FJ25_: subdivision of format 2.5 by op1 / 8
235
    {3, FJ25J}, {0, FX258}, {0, FX259}, {0, FX25A},        // jump, 2.5.8 - ...
236
    {0, FX25A}, {0, FX25A}, {0, FX25A}, {0, FX25A},
237
    //  FJ25J: subdivision of format 2.5 jump instructions by op1 % 8
238
    {4, FJ250}, {4, FJ251}, {4, FJ252}, {0, FX253},
239
    {4, FJ254}, {4, FJ255}, {0, FX256}, {0, FX257},
240
    //  FJ250: subdivision of format 2.5.0 jump instructions by opj / 8
241
    {0, FX250}, {0, FX250}, {0, FX250}, {0, FX250},
242
    {0, FX250}, {0, FX250}, {0, FX250}, {0, FX250},
243
    //  FJ251: subdivision of format 2.5.1 jump instructions by opj / 8
244
    {0, FX251}, {0, FX251}, {0, FX251}, {0, FX251},
245
    {0, FX251}, {0, FX251}, {0, FX251}, {0, FX251X},
246
    //  FJ252: subdivision of format 2.5.2 jump instructions by opj / 8
247
    {0, FX252}, {0, FX252}, {0, FX252}, {0, FX252},
248
    {0, FX252}, {0, FX252}, {0, FX252}, {0, FX252X},
249
    //  FJ254: subdivision of format 2.5.4 jump instructions by opj / 8
250
    {0, FX254}, {0, FX254}, {0, FX254}, {0, FX254},       // opj 0 - 31
251
    {0, FX254}, {0, FX254}, {5, FJ254B},{0, FX254},       // opj 32 - 63
252
    //  FJ254B: subdivision of format 2.5.4:6 by by opj % 8
253
    {0, FX254}, {0, FX254}, {0, FX254}, {0, FX254},        // 254: 48 - 51
254
    {0, FX254X},{0, FX254X},                               // 254: 52 - 53
255
    {0, FX254}, {0, FX254},                                // 254: 54 - 55
256
    //  FJ255: subdivision of format 2.5.5 jump instructions by opj / 8
257
    {0, FX255}, {0, FX255}, {0, FX255}, {0, FX255},
258
    {0, FX255}, {0, FX255}, {0, FX255}, {0, FX255X},
259
    //  FJ290: subdivision of format 2.9 by by op1 / 8
260
    {0, FX290}, {0, FX290}, {0, FX290}, {0, FX290},         // 2.9.0
261
    {0, FX291}, {0, FX291}, {0, FX291}, {0, FX291},         // 2.9.1
262
 
263
    //  FJ300: 3.0 subdivided by mode2
264
    {0, FX300}, {0, FX301}, {0, FX302}, {0, FX303},        // 3.0.0 - 3.0.3
265
    {0, FX300}, {0, FX305}, {0, FX300}, {0, FX307},        // 3.0.4 - 3.0.7
266
 
267
    //  FJ31_: subdivision of format 3.1 instructions by op1 / 8
268
    {3, FJ31J}, {0, FX318}, {0, FX318}, {0, FX318},
269
    {0, FX318}, {0, FX318}, {0, FX318}, {0, FX318},
270
 
271
    //  FJ31J: subdivision of format 3.1.0-8 jump instructions by op1 % 8
272
    {0, FX310}, {4, FJ311}, {0, FX312}, {0, FX313},
273
    {0, FX310}, {0, FX310}, {0, FX310}, {0, FX310},
274
 
275
    //  FJ311 subdivision of format 3.1.1 instructions by opj / 8
276
    {0, FX311}, {0, FX311}, {0, FX311}, {0, FX311},
277
    {0, FX311}, {0, FX311}, {0, FX311}, {0, FX311X},
278
 
279
    //  FJ320: 3.2 subdivided by mode2
280
    {0, FX320}, {0, FX321}, {0, FX322}, {0, FX323},        // 3.2.0 - 3.2.3
281
    {0, FX320}, {0, FX325}, {0, FX320}, {0, FX327}         // 3.2.4 - 3.2.7
282
};
283
 
284
 
285
// Definition of bit fields in all formats. The members of SFormat are defined in disassem.h.
286
// Do not add or delete lines in formatList without updating the index constants FX000 etc. above.
287
 
288
const SFormat formatList[FXEND] = {
289
//  form   cat tmpl  opav  ot     jump   addr  imm         v     mem   scl fi  xt
290
    {0x000, 3, 0xA,  0xB0, 0x00,  0, 0,  0, 0, 0, 0, 0,    0,    0x00, 0,  0,  1},
291
    {0x010, 3, 0xB,  0xA1, 0x00,  0, 0,  0, 0, 1, 0, 0,    0,    0x00, 0,  1,  1},
292
    {0x020, 3, 0xA,  0xB0, 0x00,  0, 0,  0, 0, 0, 0, 0,    1,    0x00, 0,  2,  1},
293
    {0x030, 3, 0xB,  0xA1, 0x00,  0, 0,  0, 0, 1, 0, 0,    1,    0x00, 0,  3,  1},
294
    {0x040, 3, 0xA,  0x82, 0x00,  0, 0,  0, 0, 0, 0, 0,    3,    0x02, 0,  4,  1},
295
    {0x050, 3, 0xA,  0x82, 0x00,  0, 0,  0, 0, 0, 0, 0,    3,    0x06, 4,  5,  1},
296
    {0x060, 3, 0xA,  0x82, 0x00,  0, 0,  0, 0, 0, 0, 0,    1,    0x06, 2,  6,  1},
297
    {0x070, 3, 0xB,  0x82, 0x00,  0, 0,  1, 0, 0, 0, 0,    1,    0x12, 1,  7,  1},
298
    {0x080, 3, 0xA,  0x82, 0x00,  0, 0,  0, 0, 0, 0, 0,    0,    0x06, 2,  8,  1},
299
    {0x090, 3, 0xB,  0x82, 0x00,  0, 0,  1, 0, 0, 0, 0,    0,    0x12, 1,  9,  1},
300
 
301
    // FX100
302
    {0x100, 1, 0xA,  0xB0, 0x00,  0, 0,  0, 0, 0, 0, 0,    0,    0x00, 0,   0,  4},  // Format 1.0 A
303
    {0x110, 1, 0xC,  0x81, 0x32,  0, 0,  0, 0, 2, 0, 0,    0,    0x00, 0,   0,  5},  // Format 1.1 C
304
    {0x120, 1, 0xA,  0xB0, 0x00,  0, 0,  0, 0, 0, 0, 0,    1,    0x00, 0,   0,  6},  // Format 1.2 A
305
    {0x130, 1, 0xB,  0xA1, 0x00,  0, 0,  0, 0, 1, 0, 0,    1,    0x00, 0,   0,  7},  // Format 1.3 B
306
    {0x141, 1, 0xC,  0x81, 0x11,  0, 0,  0, 0, 2, 0, 0,    1,    0x00, 0,   0,  8},  // Format 1.4 C, in16. op1 = 0-7
307
    {0x142, 1, 0xC,  0x81, 0x32,  0, 0,  0, 0, 2, 0, 0,    1,    0x00, 0,   0,  8},  // Format 1.4 C, int32/int64. op1 = 8-31
308
    {0x143, 1, 0xC,  0x81, 0x35,  0, 0,  0, 0, 2, 0, 0,    1,    0x00, 0,   0,  8},  // Format 1.4 C, float/double. op1 = 32-39
309
    {0x144, 1, 0xC,  0x81, 0x11,  0, 0,  0, 0, 2, 0, 0,    1,    0x00, 0,   0,  8},  // Format 1.4 C, half. op1 = 40-63
310
    {0x150, 1, 0xB,  0xA1, 0x00,  0, 0,  0, 0, 1, 0, 0,    1,    0x00, 0,   0,  8},  // Format 1.5 B. op1 = 0-63
311
 
312
    {0x160, 4, 0xB,  0xA0, 0x00,  1, 0,  0, 0, 0, 0, 0,    0x10, 0x00, 0,   0,  2},  // Format 1.6 jump. op1 = 0-55
313
    {0x161, 4, 0xB,  0x02, 0x13,  0, 0,  1, 0, 0, 0, 0,    0,    0x12, 1,  16,  2},  // Format 1.6.1 jump [mem] like format 0.9. op1 = 56-59
314
    {0x162, 4, 0xA,  0x82, 0x00,  0, 0,  0, 0, 0, 0, 0,    0,    0x06, 2,  17,  2},  // Format 1.6.2 jump (refpoint, [mem]). op1 = 60-61
315
    {0x163, 4, 0xA,  0xB0, 0x00,  0, 0,  0, 0, 0, 0, 0,    0,    0x00, 0,  18,  2},  // Format 1.6.3 return, sys_call. op1 = 62-63
316
    {0x170, 4, 0xD,  0x00, 0x13,  3, 0,  0, 0, 0, 0, 1,    0,    0x00, 0,  20,  3},  // Format 1.7 D. op1 = 0-15
317
    {0x171, 4, 0xC,  0x81, 0x12,  1, 0,  0, 0, 1, 1, 0,    0x10, 0x00, 0,   1,  2},  // Format 1.7 C. op1 = 16-55, except 52-53
318
    {0x172, 0, 0xC,  0x81, 0x13,  2, 0,  0, 0, 0, 0, 0,    0,    0x00, 0,  21,  2},  // Format 1.7.2 C, unconditional 16 bit jump. op1 = 56-59. Unused
319
    {0x173, 4, 0xC,  0x80, 0x13,  0, 0,  0, 0, 0, 0, 0,    0,    0x00, 0,  22,  2},  // Format 1.7.3 C, jump to register, sys_return. op1 = 60-62
320
    {0x174, 4, 0xC,  0x01, 0x13,  0, 0,  0, 0, 2, 0, 0,    0,    0x00, 0,  23,  2},  // Format 1.7.4 C, trap. op1 = 63
321
    {0x175, 4, 0xC,  0x00, 0x13,  0, 0,  0, 0, 2, 0, 0x40, 0,    0x00, 0,  24,  2},  // Format 1.7.5 C, filler. op1 = 63. IM12 = 0xFFFF
322
    {0x17A, 4, 0xC,  0x81, 0x13,  1, 0,  0, 0, 1, 1, 0,    0,    0x00, 0,  25,  2},  // Format 1.7.A C, sub_maxlen. op1 = 52-53
323
    {0x180, 1, 0xB,  0xA1, 0x00,  0, 0,  0, 0, 1, 0, 0,    0,    0x00, 0,   0,  9},
324
 
325
// FX200
326
    {0x200, 3, 0xE,  0xD2, 0x00,  0, 0,  2, 4, 0, 0, 2,    0,    0x12, 0, 16,  1},
327
    {0x201, 3, 0xE,  0xC2, 0x00,  0, 0,  2, 4, 0, 0, 2,    0,    0x16, 0, 17,  1},
328
    {0x202, 3, 0xE,  0xC2, 0x00,  0, 0,  2, 4, 0, 0, 2,    0,    0x16, 2, 18,  1},
329
    {0x203, 3, 0xE,  0xC2, 0x00,  0, 0,  2, 4, 0, 0, 2,    0,    0x26, 2, 19,  1},
330
    {0x205, 3, 0xE,  0xC3, 0x00,  0, 0,  2, 4, 1, 6, 0x100,0,    0x16, 2, 21,  1},
331
    {0x206, 3, 0xE,  0xF0, 0x00,  0, 0,  0, 0, 0, 0, 2,    0,    0x00, 0, 22,  1},
332
    {0x207, 3, 0xE,  0xF1, 0x00,  0, 0,  0, 0, 2, 4, 6,    0,    0x00, 0, 23,  1},
333
    {0x210, 3, 0xA,  0x92, 0x00,  0, 0,  4, 4, 0, 0, 0,    0,    0x12, 0, 13,  1},
334
    {0x220, 3, 0xE,  0xC2, 0x00,  0, 0,  2, 4, 0, 0, 2,    5,    0x12, 0, 24,  1},
335
    {0x221, 3, 0xE,  0xC2, 0x00,  0, 0,  2, 4, 0, 0, 2,    3,    0x12, 0, 25,  1},
336
    {0x222, 3, 0xE,  0xC2, 0x00,  0, 0,  2, 4, 0, 0, 2,    1,    0x16, 2, 26,  1},
337
    {0x223, 3, 0xE,  0xC2, 0x00,  0, 0,  2, 4, 0, 0, 2,    1,    0x26, 2, 27,  1},
338
    {0x224, 3, 0xE,  0xC2, 0x00,  0, 0,  2, 4, 0, 0, 2,    3,    0x16, 4, 28,  1},
339
    {0x225, 3, 0xE,  0xC3, 0x00,  0, 0,  2, 4, 1, 6, 0x100,3,    0x16, 0, 29,  1},
340
    {0x226, 3, 0xE,  0xF0, 0x00,  0, 0,  0, 0, 0, 0, 2,    1,    0x00, 0, 30,  1},
341
    {0x227, 3, 0xE,  0xF1, 0x00,  0, 0,  0, 0, 2, 4, 6,    1,    0x00, 0, 31,  1},
342
    {0x230, 3, 0xA,  0xB1, 0x00,  0, 0,  0, 0, 4, 4, 0,    1,    0x00, 0, 14,  1},
343
    {0x240, 3, 0xA,  0x82, 0x00,  0, 0,  4, 4, 0, 0, 0,    3,    0x12, 0, 15,  1},
344
 
345
    // FX250
346
//  form   cat tmpl  opav  ot     jump   addr  imm         v     mem  scl fi   xt
347
    {0x250, 4, 0xA,  0xB0, 0x00,  3, 4,  0, 0, 0, 0, 0x90, 0x10, 0x00, 0,  4,  2},  // Format 2.5.0. jump w three registers, 24-bit offset
348
    {0x251, 4, 0xB,  0xA1, 0x00,  2, 6,  0, 0, 2, 4, 0x80, 0x10, 0x00, 0,  5,  2},  // Format 2.5.1. jump w 16-bit imm + 16 bit offset. op1 = 0-55
349
    {0x251, 4, 0xB,  0xA1, 0x00,  0, 0,  0, 0, 4, 4, 0x80, 0,    0x00, 0, 28,  2},  // Format 2.5.1x system call. op1 = 56-63
350
    {0x252, 4, 0xB,  0x82, 0x00,  2, 6,  2, 4, 0, 0, 0x80, 0,    0x12, 0,  6,  2},  // Format 2.5.2. jump w memory operand and 16 bit jump offset
351
    {0x252, 4, 0xB,  0x82, 0x00,  0, 0,  4, 4, 0, 0, 0x80, 0,    0x12, 0, 29,  2},  // Format 2.5.2x jump [mem+i]. op1 = 56-63
352
    {0x253, 0, 0xA,  0xB0, 0x00,  3, 4,  0, 0, 0, 0, 0x90, 0x10, 0x00, 0,  7,  2},  // Format 2.5.3. unused
353
    {0x254, 4, 0xC,  0x81, 0x12,  4, 4,  0, 0, 1, 1, 0x80, 0x10, 0x00, 0,  8,  2},  // Format 2.5.4. jump w 8-bit imm + 32 bit offset. op1 = 0-55
354
    {0x254, 4, 0xC,  0x81, 0x13,  4, 4,  0, 0, 1, 1, 0x80, 0,    0x00, 0, 30,  2},  // Format 2.5.4x Same as 2.5.4, 64 bit operand size
355
    {0x255, 4, 0xC,  0x81, 0x12,  1, 1,  0, 0, 4, 4, 0x80, 0x10, 0x00, 0,  9,  2},  // Format 2.5.5. jump w 32-bit imm + 8 bit offset. op1 = 0-55
356
    {0x255, 4, 0xC,  0x81, 0x13,  0, 0,  0, 0, 4, 4, 0x80, 0,    0x00, 0, 31,  2},  // Format 2.5.5x conditional trap. op1 = 56-63
357
    {0x256, 0, 0xB,  0xA0, 0x00,  4, 4,  0, 0, 0, 0, 0x80, 0x10, 0x00, 0, 10,  2},  // Format 2.5.6. unused
358
    {0x257, 4, 0xC,  0x01, 0x13,  0, 0,  0, 0, 2, 0, 0xC0, 0,    0x00, 0, 32,  2},  // Format 2.5.7. system call w 16+32 bit imm 
359
    {0x258, 1, 0xB,  0x83, 0x00,  0, 0,  1, 0, 4, 4, 0,    0x10, 0x12, 1,  0, 10},  // single format instructions, format 2.5 B with both memory and immediate: store. op1 = 0-15
360
    {0x259, 1, 0xB,  0x82, 0x00,  0, 0,  4, 4, 0, 0, 0,    0,    0x12, 0,  0, 10},  // single format instructions, format 2.5 B with memory: compare_swap. op1 = 16-23
361
    {0x25A, 1, 0xA,  0x92, 0x00,  0, 0,  4, 4, 0, 0, 0,    1,    0x12, 0,  0, 10},  // Miscellaneous single format instructions, format 2.5 A with memory operand. op1 = 24-63
362
    {0x260, 1, 0xA,  0xB1, 0x00,  0, 0,  0, 0, 4, 4, 0,    1,    0x00, 0,  0, 11},
363
    {0x270, 0, 0xA,  0x00, 0x00,  0, 0,  0, 0, 0, 0, 0,    0,    0x00, 0,  0,  0},  // currently unused
364
    {0x280, 3, 0xA,  0xB1, 0x00,  0, 0,  0, 0, 4, 4, 0,    0,    0x00, 0, 12,  1},
365
    {0x290, 1, 0xA,  0xB1, 0x00,  0, 0,  0, 0, 4, 4, 0,    0,    0x00, 0,  0, 12},
366
    {0x291, 1, 0xA,  0xA2, 0x00,  0, 0,  4, 4, 0, 0, 0,    0,    0x12, 0,  0, 12},
367
 
368
    // FX300
369
    {0x300, 3, 0xE,  0xD2, 0x00,  0, 0,  4, 8, 0, 0, 2,    0,    0x12, 0, 36,  1},
370
    {0x301, 0, 0xE,  0xD2, 0x00,  0, 0,  4, 8, 0, 0, 2,    0,    0x12, 0, 36,  1},  // Format 3.0.1. unused
371
    {0x302, 3, 0xE,  0xC2, 0x00,  0, 0,  4, 8, 0, 0, 2,    0,    0x16, 2, 38,  1},
372
    {0x303, 3, 0xE,  0xC2, 0x00,  0, 0,  4, 8, 0, 0, 2,    0,    0x26, 2, 39,  1},
373
    {0x305, 3, 0xE,  0xC3, 0x00,  0, 0,  2, 4, 4, 8, 2,    0,    0x16, 2, 41,  1},
374
    {0x307, 3, 0xE,  0xF1, 0x00,  0, 0,  0, 0, 4, 8, 0xA,  0,    0x00, 0, 43,  1},
375
 
376
    {0x310, 4, 0xA,  0x92, 0x00,  3, 4,  4, 8, 0, 0, 0x90, 0x10, 0x12, 0, 12,  2},  // Jump w memory operand and 32 bit jump offset
377
    {0x311, 4, 0xB,  0xA1, 0x00,  4, 4,  0, 0, 4, 8, 0x80, 0x10, 0x00, 0, 13,  2},  // Jump w 32 bit offset + 32-bit imm. op1 = 0-55
378
    {0x311, 4, 0xB,  0xA1, 0x13,  0, 0,  0, 0, 8, 4, 0x80, 0,    0x00, 0, 40,  2},  // 3.1.1X. Syscall. op1 = 56-63
379
    {0x312, 0, 0xB,  0xA0, 0x00,  4, 4,  0, 0, 0, 0, 0x80, 0x10, 0x00, 0, 14,  2},  // Format 3.1.2. unused
380
    {0x313, 0, 0xB,  0xD2, 0x00,  0, 0,  4, 8, 0, 0, 2,    0,    0x12, 0, 15,  2},  // Format 3.1.3. unused
381
 
382
    {0x318, 1, 0xA,  0xB1, 0x00,  0, 0,  0, 0, 8, 4, 0,    1,    0x00, 0,  0, 13},  // Triple size single format instructions. op1 = 8-15
383
    {0x320, 3, 0xE,  0xC2, 0x00,  0, 0,  4, 8, 0, 0, 2,    5,    0x12, 0, 44,  1},
384
    {0x321, 3, 0xE,  0xC2, 0x00,  0, 0,  4, 8, 0, 0, 2,    3,    0x12, 0, 45,  1},
385
    {0x322, 3, 0xE,  0xC2, 0x00,  0, 0,  4, 8, 0, 0, 2,    1,    0x16, 2, 46,  1},
386
    {0x323, 3, 0xE,  0xC2, 0x00,  0, 0,  4, 8, 0, 0, 2,    1,    0x26, 2, 47,  1},
387
    {0x325, 3, 0xE,  0xC3, 0x00,  0, 0,  2, 4, 4, 8, 2,    3,    0x12, 0, 49,  1},
388
    {0x327, 3, 0xE,  0xF1, 0x00,  0, 0,  0, 0, 4, 8, 0xA,  1,    0x00, 0, 51,  1},
389
    {0x330, 3, 0xA,  0xB1, 0x00,  0, 0,  0, 0, 8, 4, 0x10, 1,    0x00, 0, 34,  1},  // 340 - 370 do not exist. reserved for larger instruction sizes
390
    {0x380, 3, 0xA,  0xB1, 0x00,  0, 0,  0, 0, 8, 4, 0x10, 0,    0x00, 0, 32,  1}
391
};
392
 
393
uint32_t formatListSize = TableSize(formatList);  // export size to other modules
394
 
395
// Data size for each operant type, max = 8
396
const uint32_t dataSizeTable[8] = {1, 2, 4, 8, 16, 4, 8, 16};   // data size in bytes
397
const uint32_t dataSizeTableMax8[8] = {1, 2, 4, 8, 8, 4, 8, 8}; // same, max 8
398
const uint32_t dataSizeTableLog[8] = {0, 1, 2, 3, 4, 2, 3, 4};  // log2(dataSizeTable)
399
const uint32_t dataSizeTableBits[8] = {8, 16, 32, 64, 128, 32, 64, 128};   // data size in bits
400
const uint64_t dataSizeMask[8] = {0xFF, 0xFFFF, 0xFFFFFFFFU, 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFU, 0xFFFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF};
401
 
402
 
403
 
404
// Check integrity of format lists
405
void checkFormatListIntegrity() {
406
    if (FXEND != TableSize(formatList)) {
407
        printf("\nInternal error in formatList");
408
        exit(1);
409
    }
410
    if (FJEND != TableSize(formatJ)) {
411
        printf("\nInternal error in formatJ");
412
        exit(1);
413
    }
414
    if (sizeof(formatI) != 128) {
415
        printf("\nInternal error in formatI");
416
        exit(1);
417
    }
418
}
419
 
420
 
421
// Look up format in nested format lists.
422
// The parameter is the first 64 bits of the instruction
423
// The return value is a structure containing all information about the instruction format.
424
// (This method is optimized for speed for the sake of the emulator. The tables use
425
//  a minimum of cache size).
426
uint32_t lookupFormat(uint64_t instruct) {
427
    // Index into formatI is il.mode.M
428
    uint8_t il_mode_m = (instruct >> 26 & 0x3E) | (instruct >> 15 & 1);
429
    uint8_t crit = formatI[il_mode_m].crit;
430
    uint8_t t    = formatI[il_mode_m].index;
431
    uint8_t i;
432
    STemplate F;
433
    F.q = instruct;
434
 
435
    // Nested table lookup
436
    while (crit) {
437
        // Index into next table determined by criterion
438
        switch (crit) {
439
        case 1:  // mode2
440
            i = F.a.mode2; // instruct >> 59 & 7;
441
            break;
442
        case 2:  // op1 / 8 
443
            i = instruct >> 24 & 7;
444
            break;
445
        case 3:  // op1 % 8
446
            i = instruct >> 21 & 7;
447
            break;
448
        case 4:  // IM1 / 8 % 8
449
            i = instruct >> 3 & 7;
450
            break;
451
        case 5:  // IM1 % 8, 
452
            i = instruct & 7;
453
            break;
454
        case 6:  // op1 / 4. unused
455
            i = instruct >> 23 & 7;
456
            break;
457
        case 7:  // op1 / 2 % 16
458
            i = instruct >> 22 & 0xF;
459
            break;
460
        case 8:  // IM12 == 0xFFFF
461
            i = (instruct & 0xFFFF) == 0xFFFF;
462
            break;
463
        default:  // Error. Should never occur
464
            printf("\nInternal error in formatList");
465
            return FX380;
466
        }
467
        t += i;
468
        if (t >= FJEND) return FX380;  // Error. Should never occur        
469
        crit = formatJ[t].crit;
470
        t    = formatJ[t].index;
471
    }
472
    if (t >= FXEND) return FX380;  // Error. Should never occur
473
 
474
    return t;
475
}
476
 
477
// Table of tables, indexed by fInstr->exeTable
478
PFunc * metaFunctionTable[14] = {
479
    0, funcTab1, funcTab2, funcTab3, funcTab4, funcTab5, funcTab6, funcTab7,
480
    funcTab8, funcTab9, funcTab10, funcTab11, funcTab12, funcTab13
481
};
482
 
483
// constants used in numOperands table below 
484
const uint8_t D = 0x22;  // double size operation. take two vector elements at a time
485
const uint8_t M = 0x0A;  // ignore mask. call instruction function even if mask = 0
486
const uint8_t L = 0x1A;  // ignore mask. RT is not a vector, or destination is not a vector. vector length is determined by the instruction function
487
const uint8_t l = 0x19;  // same as L, single operand
488
const uint8_t N = 0x1B;  // same as L, three operands
489
const uint8_t A = 0x41;  // one operand, don't read memory operand
490
const uint8_t S = 0xC9;  // store: one operand, don't read memory operand, ignore mask, don't modify RD
491
 
492
// Table of number of operands for each instruction
493
// bit 0-2: number of source operands
494
// bit 3: call execution function even if mask = 0
495
// bit 4: RT is not a vector register. vector length is determined by the instruction function
496
// bit 5: take two vector elements at a time
497
// bit 6: don't read memory operand before calling execution function
498
// bit 7: RD is unchanged (not destination)
499
uint8_t numOperands[15][64] = {
500
    {0},  //          8                16               24               32               40               48               56
501
    {8,S,1,1,1,1,2,M, 2,2,2,2,2,2,2,2, 2,2,2,2,2,2,2,2, 2,2,2,2,2,2,2,2, 2,2,2,2,2,2,2,M, M,M,2,2,2,2,2,2, 3,3,3,3,3,3,3,3, 2,2,2,2,2,2,2,2},  // 1:  multi-format instructions
502
    {2,2,2,2,2,2,2,2, 2,2,2,2,2,2,2,2, 2,2,2,2,2,2,2,2, 2,2,2,2,2,2,2,2, 2,2,2,2,2,2,2,2, 2,2,2,2,2,2,2,2, 2,2,2,2,2,2,2,2, 2,2,2,2,2,2,2,2},  // 2:  conditional and indirect jump instructions
503
    {1,1,1,1,1,1,1,1, 1,1,1,1,1,1,1,1, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0},  // 3:  simple jump and call instructions
504
    {0,1,1,1,1,2,2,2, 2,2,2,2,2,2,2,2, 2,2,2,2,2,2,2,2, 2,2,2,2,2,2,2,2, 2,2,2,2,2,2,2,2, 2,2,2,2,2,2,2,2, 2,2,2,2,2,2,2,2, 2,2,2,2,2,2,2,2},  // 4:  format 1.0
505
    {1,1,1,1,1,1,2,2, 2,2,2,2,2,2,2,2, 2,2,2,2,2,2,2,2, 2,2,2,2,2,2,2,2, 2,2,2,2,2,2,2,2, 2,2,2,2,2,2,2,2, 2,2,2,2,2,2,2,2, 2,2,2,2,2,2,2,2},  // 5:  format 1.1
506
    {9,9,L,L,3,L,N,L, L,L,L,L,L,L,L,L, L,L,L,L,1,1,2,2, D,D,D,D,1,2,2,2, 2,2,2,2,2,2,D,D, D,D,D,D,2,2,2,2, 2,2,2,2,2,2,2,2, 2,2,L,L,L,L,L,L},  // 6:  format 1.2
507
    {l,l,L,L,N,2,L,L, 2,2,2,2,2,2,2,2, 2,2,2,1,2,2,2,2, 2,2,2,2,2,2,2,2, 2,2,2,2,2,2,2,2, 2,2,2,2,2,2,2,2, 2,2,2,2,2,2,2,2, L,L,L,2,2,2,2,2},  // 7:  format 1.3
508
    {1,2,2,2,2,2,2,2, 1,1,2,2,2,2,2,2, 2,2,2,2,2,2,2,2, 2,2,2,2,2,2,2,2, 1,1,2,2,2,2,2,2, 2,2,2,2,2,2,2,2, 2,2,2,2,2,2,2,2, 2,2,2,2,2,2,2,2},  // 8:  format 1.4
509
    {2,3,2,2,2,2,2,2, 2,2,2,2,2,2,2,2, 2,2,2,2,2,2,2,2, 2,2,2,2,2,2,2,2, M,M,M,M,M,M,M,M, 2,2,2,2,2,2,2,2, 2,2,2,2,2,2,2,2, 2,2,2,2,2,2,2,3},  // 9:  format 1.8
510
 
511
    {2,2,2,2,2,2,2,2, A,2,2,2,2,2,2,2, 2,2,3,2,2,2,2,2, 2,2,2,2,2,2,2,2, N,2,2,2,2,2,2,2,0x5A,2,2,2,2,2,2,2, 2,2,2,2,2,2,2,2, 2,2,2,2,2,2,2,2},//10:  format 2.5
512
    {l,L,2,2,2,2,L,2, L,2,2,2,2,2,2,2, 2,2,2,2,2,2,2,2, 2,2,2,2,2,2,2,2, 2,2,2,2,2,2,2,2, 2,2,2,2,2,2,2,2, 2,2,2,2,2,2,2,2, 2,2,2,2,2,2,2,2},  //11:  format 2.6
513
    {1,2,2,2,2,2,2,2, 2,2,2,2,2,2,2,2, 2,2,2,2,2,2,2,2, 2,2,2,2,2,2,2,2, A,2,2,2,2,2,2,2, 2,2,2,2,2,2,2,2, 2,2,2,2,2,2,2,2, 2,2,2,2,2,2,2,2},  //12:  format 2.9
514
    {2,2,2,l,2,2,2,2, 2,2,2,2,2,2,2,2, 2,2,2,2,2,2,2,2, 2,2,2,2,2,2,2,2, 2,L,2,2,2,2,2,2, 2,2,2,2,2,2,2,2, 2,2,2,2,2,2,2,2, 2,2,2,2,2,2,2,2},  //13:  format 3.1
515
    {0}
516
};
517
 
518
// Table of number of operands for each instruction, Format 2.0.7, op2 = 1
519
uint8_t numOperands2071[64] = {
520
  // 0                8                16               24               32               40               48               56
521
     3,3,3,3,3,3,3,3, 3,3,3,3,3,3,3,3, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0};
522
 
523
// Table of number of operands for each instruction, Format 2.2.6, op2 = 1
524
uint8_t numOperands2261[64] = {
525
  // 0                8                16               24               32               40               48               56
526
     N,N,N,0,0,0,0,0, 0xB,3,3,3,3,3,3,3, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0};
527
 
528
// Table of number of operands for each instruction, Format 2.2.7, op2 = 1
529
uint8_t numOperands2271[64] = {
530
  // 0                8                16               24               32               40               48               56
531
     3,3,3,3,3,3,3,3, N,N,3,3,3,3,3,3, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0};

powered by: WebSVN 2.1.0

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