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

Subversion Repositories or1k

[/] [or1k/] [tags/] [stable_0_2_0_rc1/] [gen_or1k_isa/] [sources/] [or32.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 133 markom
/* Table of opcodes for the OpenRISC 1000 ISA.
2
   Copyright 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
3
   Contributed by Damjan Lampret (lampret@opencores.org).
4
 
5 717 markom
This file is part of gen_or1k_isa, or1ksim, GDB and GAS.
6 133 markom
 
7
This program is free software; you can redistribute it and/or modify
8
it under the terms of the GNU General Public License as published by
9
the Free Software Foundation; either version 2 of the License, or
10
(at your option) any later version.
11
 
12
This program is distributed in the hope that it will be useful,
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
GNU General Public License for more details.
16
 
17
You should have received a copy of the GNU General Public License
18
along with this program; if not, write to the Free Software
19
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
20
 
21 1114 lampret
/*
22
 * $Log: not supported by cvs2svn $
23 1557 nogj
 * Revision 1.46  2005/08/18 22:13:27  phoenix
24
 * fixed l.maci encoding
25
 *
26 1554 phoenix
 * Revision 1.45  2005/04/27 19:13:13  nogj
27
 * l.rfe does not have a delay slot.  Don't mark it as such.
28
 *
29 1475 nogj
 * Revision 1.44  2005/03/31 16:09:57  nogj
30
 * Implement a dynamic recompiler to speed up the execution
31
 *
32 1452 nogj
 * Revision 1.43  2005/03/31 16:01:59  nogj
33
 * Reclasify l.trap and l.sys to be an exception instruction
34
 *
35 1440 nogj
 * Revision 1.42  2005/03/16 12:25:56  nogj
36
 * Fix the parameters to the l.ff1/l.maci instructions
37
 *
38 1384 nogj
 * Revision 1.41  2005/02/09 17:41:03  nogj
39
 * Mark a simulated cpu address as such, by introducing the new oraddr_t type
40
 *
41 1350 nogj
 * Revision 1.40  2005/01/27 14:14:13  nogj
42
 * Remove the global op structure
43
 *
44 1346 nogj
 * Revision 1.39  2005/01/27 13:35:40  nogj
45
 *  * Fix generate.c to produce a execgen.c with less warnings.
46
 *  * Fix the --enable-simple configure option.
47
 *
48 1342 nogj
 * Revision 1.38  2005/01/27 13:15:50  nogj
49
 * Mark wich operand is the destination operand in the architechture definition
50
 *
51 1341 nogj
 * Revision 1.37  2005/01/11 15:41:58  andreje
52
 * l.ff1 instruction added
53
 *
54 1338 andreje
 * Revision 1.36  2004/07/22 20:17:23  phoenix
55
 * removed includes
56
 *
57 1309 phoenix
 * Revision 1.35  2004/07/19 23:07:37  phoenix
58
 * Gyorgy Jeney: extensive cleanup
59
 *
60 1308 phoenix
 * Revision 1.34  2004/06/27 22:56:48  lampret
61
 * Updated instruction set descriptions. Changed FP instructions encoding.
62
 *
63 1295 lampret
 * Revision 1.33  2004/05/09 19:52:31  lampret
64
 * Changed desciption of the l.cust5 insns
65
 *
66 1285 lampret
 * Revision 1.31  2003/07/01 19:34:49  csanchez
67
 * Added support for l.addc instruction.
68
 *
69 1169 csanchez
 * Revision 1.30  2003/01/28 03:49:24  lampret
70
 * Added cvs log keywords
71
 *
72 1114 lampret
 */
73
 
74 133 markom
#include <string.h>
75
#include <stdio.h>
76
#include <stdlib.h>
77 371 markom
#include <ctype.h>
78 133 markom
 
79 371 markom
 
80 138 markom
#ifdef HAVE_CONFIG_H
81
# include "config.h"
82
#endif
83 1342 nogj
#ifdef HAS_EXECUTION
84 1350 nogj
# ifdef HAVE_INTTYPES_H
85
#  include <inttypes.h> /* ...but to get arch.h we need uint{8,16,32}_t... */
86
# endif
87
# include "port.h"
88
# include "arch.h" /* ...but to get abstract.h, we need oraddr_t... */
89
# include "abstract.h" /* To get struct iqueue_entry... */
90 1557 nogj
# include "debug.h" /* To get debug() */
91 1342 nogj
#endif
92 133 markom
#include "opcode/or32.h"
93
 
94
/* **INDENT-OFF** */
95
 
96 1342 nogj
/* We treat all letters the same in encode/decode routines so
97
   we need to assign some characteristics to them like signess etc.*/
98 133 markom
CONST struct or32_letter or32_letters[] =
99
{
100
{ 'A', NUM_UNSIGNED },
101
{ 'B', NUM_UNSIGNED },
102
{ 'D', NUM_UNSIGNED },
103
{ 'I', NUM_SIGNED },
104
{ 'K', NUM_UNSIGNED },
105
{ 'L', NUM_UNSIGNED },
106
{ 'N', NUM_SIGNED },
107
{ '0', NUM_UNSIGNED },
108
{ '\0', 0 }     /* dummy entry */
109
};
110
 
111
/* Opcode encoding:
112
   machine[31:30]: first two bits of opcode
113
                   00 - neither of source operands is GPR
114
                   01 - second source operand is GPR (rB)
115
                   10 - first source operand is GPR (rA)
116
                   11 - both source operands are GPRs (rA and rB)
117
   machine[29:26]: next four bits of opcode
118
   machine[25:00]: instruction operands (specific to individual instruction)
119
 
120
  Recommendation: irrelevant instruction bits should be set with a value of
121
  bits in same positions of instruction preceding current instruction in the
122
  code (when assembling).
123
*/
124
 
125 1341 nogj
#ifdef HAS_EXECUTION
126
# if SIMPLE_EXECUTION
127
#  define EFN &l_none
128
#  define EF(func) &(func)
129
#  define EFI &l_invalid
130 1452 nogj
# elif COMPLEX_EXECUTION
131 1341 nogj
#  define EFN "l_none"
132
#  define EFI "l_invalid"
133
#  ifdef __GNUC__
134
#   define EF(func) #func
135
#  else
136
#   define EF(func) "func"
137
#  endif
138 1452 nogj
# else /* DYNAMIC_EXECUTION */
139
#  define EFN &l_none
140
#  define EF(func) &(gen_ ##func)
141
#  define EFI &gen_l_invalid
142
# endif
143 1341 nogj
#else /* HAS_EXECUTION */
144
# define EFN &l_none
145
# define EF(func) EFN
146
# define EFI EFN
147 133 markom
#endif /* HAS_EXECUTION */
148
 
149
CONST struct or32_opcode or32_opcodes[] =
150
{
151
 
152 1346 nogj
{ "l.j",       "N",            "00 0x0  NNNNN NNNNN NNNN NNNN NNNN NNNN",
153
  EF(l_j), OR32_IF_DELAY, it_jump },
154
{ "l.jal",     "N",            "00 0x1  NNNNN NNNNN NNNN NNNN NNNN NNNN",
155
  EF(l_jal), OR32_IF_DELAY, it_jump },
156
{ "l.bnf",     "N",            "00 0x3  NNNNN NNNNN NNNN NNNN NNNN NNNN",
157
  EF(l_bnf), OR32_IF_DELAY | OR32_R_FLAG, it_branch },
158
{ "l.bf",      "N",            "00 0x4  NNNNN NNNNN NNNN NNNN NNNN NNNN",
159
  EF(l_bf), OR32_IF_DELAY | OR32_R_FLAG, it_branch },
160
{ "l.nop",     "K",            "00 0x5  01--- ----- KKKK KKKK KKKK KKKK",
161
  EF(l_nop), 0, it_nop },
162
{ "l.movhi",   "rD,K",         "00 0x6  DDDDD ----0 KKKK KKKK KKKK KKKK",
163
  EF(l_movhi), 0, it_movimm },
164
{ "l.macrc",   "rD",           "00 0x6  DDDDD ----1 0000 0000 0000 0000",
165
  EF(l_macrc), 0, it_mac },
166
{ "l.sys",     "K",            "00 0x8  00000 00000 KKKK KKKK KKKK KKKK",
167 1440 nogj
  EF(l_sys), 0, it_exception },
168 1346 nogj
{ "l.trap",    "K",            "00 0x8  01000 00000 KKKK KKKK KKKK KKKK",
169 1440 nogj
  EF(l_trap), 0, it_exception },
170 1346 nogj
{ "l.msync",   "",             "00 0x8  10000 00000 0000 0000 0000 0000", EFN,
171
  0, it_unknown },
172
{ "l.psync",   "",             "00 0x8  10100 00000 0000 0000 0000 0000", EFN,
173
  0, it_unknown },
174
{ "l.csync",   "",             "00 0x8  11000 00000 0000 0000 0000 0000", EFN,
175
  0, it_unknown },
176
{ "l.rfe",     "",             "00 0x9  ----- ----- ---- ---- ---- ----",
177 1475 nogj
  EF(l_rfe), 0, it_exception },
178 1346 nogj
{ "lv.all_eq.b","rD,rA,rB",    "00 0xA  DDDDD AAAAA BBBB B--- 0x1 0x0", EFI, 0,
179
  it_unknown },
180
{ "lv.all_eq.h","rD,rA,rB",    "00 0xA  DDDDD AAAAA BBBB B--- 0x1 0x1", EFI, 0,
181
  it_unknown },
182
{ "lv.all_ge.b","rD,rA,rB",    "00 0xA  DDDDD AAAAA BBBB B--- 0x1 0x2", EFI, 0,
183
  it_unknown },
184
{ "lv.all_ge.h","rD,rA,rB",    "00 0xA  DDDDD AAAAA BBBB B--- 0x1 0x3", EFI, 0,
185
  it_unknown },
186
{ "lv.all_gt.b","rD,rA,rB",    "00 0xA  DDDDD AAAAA BBBB B--- 0x1 0x4", EFI, 0,
187
  it_unknown },
188
{ "lv.all_gt.h","rD,rA,rB",    "00 0xA  DDDDD AAAAA BBBB B--- 0x1 0x5", EFI, 0,
189
  it_unknown },
190
{ "lv.all_le.b","rD,rA,rB",    "00 0xA  DDDDD AAAAA BBBB B--- 0x1 0x6", EFI, 0,
191
  it_unknown },
192
{ "lv.all_le.h","rD,rA,rB",    "00 0xA  DDDDD AAAAA BBBB B--- 0x1 0x7", EFI, 0,
193
  it_unknown },
194
{ "lv.all_lt.b","rD,rA,rB",    "00 0xA  DDDDD AAAAA BBBB B--- 0x1 0x8", EFI, 0,
195
  it_unknown },
196
{ "lv.all_lt.h","rD,rA,rB",    "00 0xA  DDDDD AAAAA BBBB B--- 0x1 0x9", EFI, 0,
197
  it_unknown },
198
{ "lv.all_ne.b","rD,rA,rB",    "00 0xA  DDDDD AAAAA BBBB B--- 0x1 0xA", EFI, 0,
199
  it_unknown },
200
{ "lv.all_ne.h","rD,rA,rB",    "00 0xA  DDDDD AAAAA BBBB B--- 0x1 0xB", EFI, 0,
201
  it_unknown },
202
{ "lv.any_eq.b","rD,rA,rB",    "00 0xA  DDDDD AAAAA BBBB B--- 0x2 0x0", EFI, 0,
203
  it_unknown },
204
{ "lv.any_eq.h","rD,rA,rB",    "00 0xA  DDDDD AAAAA BBBB B--- 0x2 0x1", EFI, 0,
205
  it_unknown },
206
{ "lv.any_ge.b","rD,rA,rB",    "00 0xA  DDDDD AAAAA BBBB B--- 0x2 0x2", EFI, 0,
207
  it_unknown },
208
{ "lv.any_ge.h","rD,rA,rB",    "00 0xA  DDDDD AAAAA BBBB B--- 0x2 0x3", EFI, 0,
209
  it_unknown },
210
{ "lv.any_gt.b","rD,rA,rB",    "00 0xA  DDDDD AAAAA BBBB B--- 0x2 0x4", EFI, 0,
211
  it_unknown },
212
{ "lv.any_gt.h","rD,rA,rB",    "00 0xA  DDDDD AAAAA BBBB B--- 0x2 0x5", EFI, 0,
213
  it_unknown },
214
{ "lv.any_le.b","rD,rA,rB",    "00 0xA  DDDDD AAAAA BBBB B--- 0x2 0x6", EFI, 0,
215
  it_unknown },
216
{ "lv.any_le.h","rD,rA,rB",    "00 0xA  DDDDD AAAAA BBBB B--- 0x2 0x7", EFI, 0,
217
  it_unknown },
218
{ "lv.any_lt.b","rD,rA,rB",    "00 0xA  DDDDD AAAAA BBBB B--- 0x2 0x8", EFI, 0,
219
  it_unknown },
220
{ "lv.any_lt.h","rD,rA,rB",    "00 0xA  DDDDD AAAAA BBBB B--- 0x2 0x9", EFI, 0,
221
  it_unknown },
222
{ "lv.any_ne.b","rD,rA,rB",    "00 0xA  DDDDD AAAAA BBBB B--- 0x2 0xA", EFI, 0,
223
  it_unknown },
224
{ "lv.any_ne.h","rD,rA,rB",    "00 0xA  DDDDD AAAAA BBBB B--- 0x2 0xB", EFI, 0,
225
  it_unknown },
226
{ "lv.add.b",  "rD,rA,rB",     "00 0xA  DDDDD AAAAA BBBB B--- 0x3 0x0", EFI, 0,
227
  it_unknown },
228
{ "lv.add.h",  "rD,rA,rB",     "00 0xA  DDDDD AAAAA BBBB B--- 0x3 0x1", EFI, 0,
229
  it_unknown },
230
{ "lv.adds.b", "rD,rA,rB",     "00 0xA  DDDDD AAAAA BBBB B--- 0x3 0x2", EFI, 0,
231
  it_unknown },
232
{ "lv.adds.h", "rD,rA,rB",     "00 0xA  DDDDD AAAAA BBBB B--- 0x3 0x3", EFI, 0,
233
  it_unknown },
234
{ "lv.addu.b", "rD,rA,rB",     "00 0xA  DDDDD AAAAA BBBB B--- 0x3 0x4", EFI, 0,
235
  it_unknown },
236
{ "lv.addu.h", "rD,rA,rB",     "00 0xA  DDDDD AAAAA BBBB B--- 0x3 0x5", EFI, 0,
237
  it_unknown },
238
{ "lv.addus.b","rD,rA,rB",     "00 0xA  DDDDD AAAAA BBBB B--- 0x3 0x6", EFI, 0,
239
  it_unknown },
240
{ "lv.addus.h","rD,rA,rB",     "00 0xA  DDDDD AAAAA BBBB B--- 0x3 0x7", EFI, 0,
241
  it_unknown },
242
{ "lv.and",    "rD,rA,rB",     "00 0xA  DDDDD AAAAA BBBB B--- 0x3 0x8", EFI, 0,
243
  it_unknown },
244
{ "lv.avg.b",  "rD,rA,rB",     "00 0xA  DDDDD AAAAA BBBB B--- 0x3 0x9", EFI, 0,
245
  it_unknown },
246
{ "lv.avg.h",  "rD,rA,rB",     "00 0xA  DDDDD AAAAA BBBB B--- 0x3 0xA", EFI, 0,
247
  it_unknown },
248
{ "lv.cmp_eq.b","rD,rA,rB",    "00 0xA  DDDDD AAAAA BBBB B--- 0x4 0x0", EFI, 0,
249
  it_unknown },
250
{ "lv.cmp_eq.h","rD,rA,rB",    "00 0xA  DDDDD AAAAA BBBB B--- 0x4 0x1", EFI, 0,
251
  it_unknown },
252
{ "lv.cmp_ge.b","rD,rA,rB",    "00 0xA  DDDDD AAAAA BBBB B--- 0x4 0x2", EFI, 0,
253
  it_unknown },
254
{ "lv.cmp_ge.h","rD,rA,rB",    "00 0xA  DDDDD AAAAA BBBB B--- 0x4 0x3", EFI, 0,
255
  it_unknown },
256
{ "lv.cmp_gt.b","rD,rA,rB",    "00 0xA  DDDDD AAAAA BBBB B--- 0x4 0x4", EFI, 0,
257
  it_unknown },
258
{ "lv.cmp_gt.h","rD,rA,rB",    "00 0xA  DDDDD AAAAA BBBB B--- 0x4 0x5", EFI, 0,
259
  it_unknown },
260
{ "lv.cmp_le.b","rD,rA,rB",    "00 0xA  DDDDD AAAAA BBBB B--- 0x4 0x6", EFI, 0,
261
  it_unknown },
262
{ "lv.cmp_le.h","rD,rA,rB",    "00 0xA  DDDDD AAAAA BBBB B--- 0x4 0x7", EFI, 0,
263
  it_unknown },
264
{ "lv.cmp_lt.b","rD,rA,rB",    "00 0xA  DDDDD AAAAA BBBB B--- 0x4 0x8", EFI, 0,
265
  it_unknown },
266
{ "lv.cmp_lt.h","rD,rA,rB",    "00 0xA  DDDDD AAAAA BBBB B--- 0x4 0x9", EFI, 0,
267
  it_unknown },
268
{ "lv.cmp_ne.b","rD,rA,rB",    "00 0xA  DDDDD AAAAA BBBB B--- 0x4 0xA", EFI, 0,
269
  it_unknown },
270
{ "lv.cmp_ne.h","rD,rA,rB",    "00 0xA  DDDDD AAAAA BBBB B--- 0x4 0xB", EFI, 0,
271
  it_unknown },
272
{ "lv.madds.h","rD,rA,rB",     "00 0xA  DDDDD AAAAA BBBB B--- 0x5 0x4", EFI, 0,
273
  it_unknown },
274
{ "lv.max.b",  "rD,rA,rB",     "00 0xA  DDDDD AAAAA BBBB B--- 0x5 0x5", EFI, 0,
275
  it_unknown },
276
{ "lv.max.h",  "rD,rA,rB",     "00 0xA  DDDDD AAAAA BBBB B--- 0x5 0x6", EFI, 0,
277
  it_unknown },
278
{ "lv.merge.b","rD,rA,rB",     "00 0xA  DDDDD AAAAA BBBB B--- 0x5 0x7", EFI, 0,
279
  it_unknown },
280
{ "lv.merge.h","rD,rA,rB",     "00 0xA  DDDDD AAAAA BBBB B--- 0x5 0x8", EFI, 0,
281
  it_unknown },
282
{ "lv.min.b",  "rD,rA,rB",     "00 0xA  DDDDD AAAAA BBBB B--- 0x5 0x9", EFI, 0,
283
  it_unknown },
284
{ "lv.min.h",  "rD,rA,rB",     "00 0xA  DDDDD AAAAA BBBB B--- 0x5 0xA", EFI, 0,
285
  it_unknown },
286
{ "lv.msubs.h","rD,rA,rB",     "00 0xA  DDDDD AAAAA BBBB B--- 0x5 0xB", EFI, 0,
287
  it_unknown },
288
{ "lv.muls.h", "rD,rA,rB",     "00 0xA  DDDDD AAAAA BBBB B--- 0x5 0xC", EFI, 0,
289
  it_unknown },
290
{ "lv.nand",   "rD,rA,rB",     "00 0xA  DDDDD AAAAA BBBB B--- 0x5 0xD", EFI, 0,
291
  it_unknown },
292
{ "lv.nor",    "rD,rA,rB",     "00 0xA  DDDDD AAAAA BBBB B--- 0x5 0xE", EFI, 0,
293
  it_unknown },
294
{ "lv.or",     "rD,rA,rB",     "00 0xA  DDDDD AAAAA BBBB B--- 0x5 0xF", EFI, 0,
295
  it_unknown },
296
{ "lv.pack.b", "rD,rA,rB",     "00 0xA  DDDDD AAAAA BBBB B--- 0x6 0x0", EFI, 0,
297
  it_unknown },
298
{ "lv.pack.h", "rD,rA,rB",     "00 0xA  DDDDD AAAAA BBBB B--- 0x6 0x1", EFI, 0,
299
  it_unknown },
300
{ "lv.packs.b","rD,rA,rB",     "00 0xA  DDDDD AAAAA BBBB B--- 0x6 0x2", EFI, 0,
301
  it_unknown },
302
{ "lv.packs.h","rD,rA,rB",     "00 0xA  DDDDD AAAAA BBBB B--- 0x6 0x3", EFI, 0,
303
  it_unknown },
304
{ "lv.packus.b","rD,rA,rB",    "00 0xA  DDDDD AAAAA BBBB B--- 0x6 0x4", EFI, 0,
305
  it_unknown },
306
{ "lv.packus.h","rD,rA,rB",    "00 0xA  DDDDD AAAAA BBBB B--- 0x6 0x5", EFI, 0,
307
  it_unknown },
308
{ "lv.perm.n", "rD,rA,rB",     "00 0xA  DDDDD AAAAA BBBB B--- 0x6 0x6", EFI, 0,
309
  it_unknown },
310
{ "lv.rl.b",   "rD,rA,rB",     "00 0xA  DDDDD AAAAA BBBB B--- 0x6 0x7", EFI, 0,
311
  it_unknown },
312
{ "lv.rl.h",   "rD,rA,rB",     "00 0xA  DDDDD AAAAA BBBB B--- 0x6 0x8", EFI, 0,
313
  it_unknown },
314
{ "lv.sll.b",  "rD,rA,rB",     "00 0xA  DDDDD AAAAA BBBB B--- 0x6 0x9", EFI, 0,
315
  it_unknown },
316
{ "lv.sll.h",  "rD,rA,rB",     "00 0xA  DDDDD AAAAA BBBB B--- 0x6 0xA", EFI, 0,
317
  it_unknown },
318
{ "lv.sll",    "rD,rA,rB",     "00 0xA  DDDDD AAAAA BBBB B--- 0x6 0xB", EFI, 0,
319
  it_unknown },
320
{ "lv.srl.b",  "rD,rA,rB",     "00 0xA  DDDDD AAAAA BBBB B--- 0x6 0xC", EFI, 0,
321
  it_unknown },
322
{ "lv.srl.h",  "rD,rA,rB",     "00 0xA  DDDDD AAAAA BBBB B--- 0x6 0xD", EFI, 0,
323
  it_unknown },
324
{ "lv.sra.b",  "rD,rA,rB",     "00 0xA  DDDDD AAAAA BBBB B--- 0x6 0xE", EFI, 0,
325
  it_unknown },
326
{ "lv.sra.h",  "rD,rA,rB",     "00 0xA  DDDDD AAAAA BBBB B--- 0x6 0xF", EFI, 0,
327
  it_unknown },
328
{ "lv.srl",    "rD,rA,rB",     "00 0xA  DDDDD AAAAA BBBB B--- 0x7 0x0", EFI, 0,
329
  it_unknown },
330
{ "lv.sub.b",  "rD,rA,rB",     "00 0xA  DDDDD AAAAA BBBB B--- 0x7 0x1", EFI, 0,
331
  it_unknown },
332
{ "lv.sub.h",  "rD,rA,rB",     "00 0xA  DDDDD AAAAA BBBB B--- 0x7 0x2", EFI, 0,
333
  it_unknown },
334
{ "lv.subs.b", "rD,rA,rB",     "00 0xA  DDDDD AAAAA BBBB B--- 0x7 0x3", EFI, 0,
335
  it_unknown },
336
{ "lv.subs.h", "rD,rA,rB",     "00 0xA  DDDDD AAAAA BBBB B--- 0x7 0x4", EFI, 0,
337
  it_unknown },
338
{ "lv.subu.b", "rD,rA,rB",     "00 0xA  DDDDD AAAAA BBBB B--- 0x7 0x5", EFI, 0,
339
  it_unknown },
340
{ "lv.subu.h", "rD,rA,rB",     "00 0xA  DDDDD AAAAA BBBB B--- 0x7 0x6", EFI, 0,
341
  it_unknown },
342
{ "lv.subus.b","rD,rA,rB",     "00 0xA  DDDDD AAAAA BBBB B--- 0x7 0x7", EFI, 0,
343
  it_unknown },
344
{ "lv.subus.h","rD,rA,rB",     "00 0xA  DDDDD AAAAA BBBB B--- 0x7 0x8", EFI, 0,
345
  it_unknown },
346
{ "lv.unpack.b","rD,rA,rB",    "00 0xA  DDDDD AAAAA BBBB B--- 0x7 0x9", EFI, 0,
347
  it_unknown },
348
{ "lv.unpack.h","rD,rA,rB",    "00 0xA  DDDDD AAAAA BBBB B--- 0x7 0xA", EFI, 0,
349
  it_unknown },
350
{ "lv.xor",    "rD,rA,rB",     "00 0xA  DDDDD AAAAA BBBB B--- 0x7 0xB", EFI, 0,
351
  it_unknown },
352
{ "lv.cust1",  "",             "00 0xA  ----- ----- ---- ---- 0xC ----", EFI, 0,
353
  it_unknown },
354
{ "lv.cust2",  "",             "00 0xA  ----- ----- ---- ---- 0xD ----", EFI, 0,
355
  it_unknown },
356
{ "lv.cust3",  "",             "00 0xA  ----- ----- ---- ---- 0xE ----", EFI, 0,
357
  it_unknown },
358
{ "lv.cust4",  "",             "00 0xA  ----- ----- ---- ---- 0xF ----", EFI, 0,
359
  it_unknown },
360 676 markom
 
361 1346 nogj
{ "l.jr",      "rB",           "01 0x1  ----- ----- BBBB B--- ---- ----",
362
  EF(l_jr), OR32_IF_DELAY, it_jump },
363
{ "l.jalr",    "rB",           "01 0x2  ----- ----- BBBB B--- ---- ----",
364
  EF(l_jalr), OR32_IF_DELAY, it_jump },
365 1554 phoenix
{ "l.maci",    "rA,I",         "01 0x3  IIIII AAAAA ---- -III IIII IIII",
366 1346 nogj
  EF(l_mac), 0, it_mac },
367
{ "l.cust1",   "",             "01 0xC  ----- ----- ---- ---- ---- ----",
368
  EF(l_cust1), 0, it_unknown },
369
{ "l.cust2",   "",             "01 0xD  ----- ----- ---- ---- ---- ----",
370
  EF(l_cust2), 0, it_unknown },
371
{ "l.cust3",   "",             "01 0xE  ----- ----- ---- ---- ---- ----",
372
  EF(l_cust3), 0, it_unknown },
373
{ "l.cust4",   "",             "01 0xF  ----- ----- ---- ---- ---- ----",
374
  EF(l_cust4), 0, it_unknown },
375 133 markom
 
376 1346 nogj
{ "l.ld",      "rD,I(rA)",     "10 0x0  DDDDD AAAAA IIII IIII IIII IIII", EFI,
377
  0, it_load },
378
{ "l.lwz",     "rD,I(rA)",     "10 0x1  DDDDD AAAAA IIII IIII IIII IIII",
379
  EF(l_lwz), 0, it_load },
380
{ "l.lws",     "rD,I(rA)",     "10 0x2  DDDDD AAAAA IIII IIII IIII IIII", EFI,
381
  0, it_load },
382
{ "l.lbz",     "rD,I(rA)",     "10 0x3  DDDDD AAAAA IIII IIII IIII IIII",
383
  EF(l_lbz), 0, it_load },
384
{ "l.lbs",     "rD,I(rA)",     "10 0x4  DDDDD AAAAA IIII IIII IIII IIII",
385
  EF(l_lbs), 0, it_load },
386
{ "l.lhz",     "rD,I(rA)",     "10 0x5  DDDDD AAAAA IIII IIII IIII IIII",
387
  EF(l_lhz), 0, it_load },
388
{ "l.lhs",     "rD,I(rA)",     "10 0x6  DDDDD AAAAA IIII IIII IIII IIII",
389
  EF(l_lhs), 0, it_load },
390 133 markom
 
391 1346 nogj
{ "l.addi",    "rD,rA,I",      "10 0x7  DDDDD AAAAA IIII IIII IIII IIII",
392
  EF(l_add), OR32_W_FLAG, it_arith },
393
{ "l.addic",   "rD,rA,I",      "10 0x8  DDDDD AAAAA IIII IIII IIII IIII", EFI,
394
  0, it_arith },
395
{ "l.andi",    "rD,rA,K",      "10 0x9  DDDDD AAAAA KKKK KKKK KKKK KKKK",
396
  EF(l_and), OR32_W_FLAG, it_arith },
397
{ "l.ori",     "rD,rA,K",      "10 0xA  DDDDD AAAAA KKKK KKKK KKKK KKKK",
398
  EF(l_or), 0, it_arith },
399
{ "l.xori",    "rD,rA,I",      "10 0xB  DDDDD AAAAA IIII IIII IIII IIII",
400
  EF(l_xor), 0, it_arith },
401
{ "l.muli",    "rD,rA,I",      "10 0xC  DDDDD AAAAA IIII IIII IIII IIII",
402
  EF(l_mul), 0, it_arith },
403
{ "l.mfspr",   "rD,rA,K",      "10 0xD  DDDDD AAAAA KKKK KKKK KKKK KKKK",
404
  EF(l_mfspr), 0, it_move },
405
{ "l.slli",    "rD,rA,L",      "10 0xE  DDDDD AAAAA ---- ---- 00LL LLLL",
406
  EF(l_sll), 0, it_shift },
407
{ "l.srli",    "rD,rA,L",      "10 0xE  DDDDD AAAAA ---- ---- 01LL LLLL",
408
  EF(l_srl), 0, it_shift },
409
{ "l.srai",    "rD,rA,L",      "10 0xE  DDDDD AAAAA ---- ---- 10LL LLLL",
410
  EF(l_sra), 0, it_shift },
411
{ "l.rori",    "rD,rA,L",      "10 0xE  DDDDD AAAAA ---- ---- 11LL LLLL", EFI,
412
  0, it_shift },
413 133 markom
 
414 1346 nogj
{ "l.sfeqi",   "rA,I",         "10 0xF  00000 AAAAA IIII IIII IIII IIII",
415
  EF(l_sfeq), OR32_W_FLAG, it_compare },
416
{ "l.sfnei",   "rA,I",         "10 0xF  00001 AAAAA IIII IIII IIII IIII",
417
  EF(l_sfne), OR32_W_FLAG, it_compare },
418
{ "l.sfgtui",  "rA,I",         "10 0xF  00010 AAAAA IIII IIII IIII IIII",
419
  EF(l_sfgtu), OR32_W_FLAG, it_compare },
420
{ "l.sfgeui",  "rA,I",         "10 0xF  00011 AAAAA IIII IIII IIII IIII",
421
  EF(l_sfgeu), OR32_W_FLAG, it_compare },
422
{ "l.sfltui",  "rA,I",         "10 0xF  00100 AAAAA IIII IIII IIII IIII",
423
  EF(l_sfltu), OR32_W_FLAG, it_compare },
424
{ "l.sfleui",  "rA,I",         "10 0xF  00101 AAAAA IIII IIII IIII IIII",
425
  EF(l_sfleu), OR32_W_FLAG, it_compare },
426
{ "l.sfgtsi",  "rA,I",         "10 0xF  01010 AAAAA IIII IIII IIII IIII",
427
  EF(l_sfgts), OR32_W_FLAG, it_compare },
428
{ "l.sfgesi",  "rA,I",         "10 0xF  01011 AAAAA IIII IIII IIII IIII",
429
  EF(l_sfges), OR32_W_FLAG, it_compare },
430
{ "l.sfltsi",  "rA,I",         "10 0xF  01100 AAAAA IIII IIII IIII IIII",
431
  EF(l_sflts), OR32_W_FLAG, it_compare },
432
{ "l.sflesi",  "rA,I",         "10 0xF  01101 AAAAA IIII IIII IIII IIII",
433
  EF(l_sfles), OR32_W_FLAG, it_compare },
434 133 markom
 
435 1346 nogj
{ "l.mtspr",   "rA,rB,K",      "11 0x0  KKKKK AAAAA BBBB BKKK KKKK KKKK",
436
  EF(l_mtspr), 0, it_move },
437
{ "l.mac",     "rA,rB",        "11 0x1  ----- AAAAA BBBB B--- ---- 0x1",
438
  EF(l_mac), 0, it_mac },
439
{ "l.msb",     "rA,rB",        "11 0x1  ----- AAAAA BBBB B--- ---- 0x2",
440
  EF(l_msb), 0, it_mac },
441 133 markom
 
442 1346 nogj
{ "lf.add.s",   "rD,rA,rB",    "11 0x2  DDDDD AAAAA BBBB B--- 0x0 0x0",
443
  EF(lf_add_s), 0, it_float },
444
{ "lf.sub.s",   "rD,rA,rB",    "11 0x2  DDDDD AAAAA BBBB B--- 0x0 0x1",
445
  EF(lf_sub_s), 0, it_float },
446
{ "lf.mul.s",   "rD,rA,rB",    "11 0x2  DDDDD AAAAA BBBB B--- 0x0 0x2",
447
  EF(lf_mul_s), 0, it_float },
448
{ "lf.div.s",   "rD,rA,rB",    "11 0x2  DDDDD AAAAA BBBB B--- 0x0 0x3",
449
  EF(lf_div_s), 0, it_float },
450
{ "lf.itof.s",  "rD,rA",       "11 0x2  DDDDD AAAAA 0000 0--- 0x0 0x4",
451
  EF(lf_itof_s), 0, it_float },
452
{ "lf.ftoi.s",  "rD,rA",       "11 0x2  DDDDD AAAAA 0000 0--- 0x0 0x5",
453
  EF(lf_ftoi_s), 0, it_float },
454
{ "lf.rem.s",   "rD,rA,rB",    "11 0x2  DDDDD AAAAA BBBB B--- 0x0 0x6",
455
  EF(lf_rem_s), 0, it_float },
456
{ "lf.madd.s",  "rD,rA,rB",    "11 0x2  DDDDD AAAAA BBBB B--- 0x0 0x7",
457
  EF(lf_madd_s), 0, it_float },
458
{ "lf.sfeq.s",  "rA,rB",       "11 0x2  ----- AAAAA BBBB B--- 0x0 0x8",
459
  EF(lf_sfeq_s), 0, it_float },
460
{ "lf.sfne.s",  "rA,rB",       "11 0x2  ----- AAAAA BBBB B--- 0x0 0x9",
461
  EF(lf_sfne_s), 0, it_float },
462
{ "lf.sfgt.s",  "rA,rB",       "11 0x2  ----- AAAAA BBBB B--- 0x0 0xA",
463
  EF(lf_sfgt_s), 0, it_float },
464
{ "lf.sfge.s",  "rA,rB",       "11 0x2  ----- AAAAA BBBB B--- 0x0 0xB",
465
  EF(lf_sfge_s), 0, it_float },
466
{ "lf.sflt.s",  "rA,rB",       "11 0x2  ----- AAAAA BBBB B--- 0x0 0xC",
467
  EF(lf_sflt_s), 0, it_float },
468
{ "lf.sfle.s",  "rA,rB",       "11 0x2  ----- AAAAA BBBB B--- 0x0 0xD",
469
  EF(lf_sfle_s), 0, it_float },
470
{ "lf.cust1.s", "rA,rB",       "11 0x2  ----- AAAAA BBBB B--- 0xD ----", EFI,
471
  0, it_float },
472 133 markom
 
473 1346 nogj
{ "lf.add.d",   "rD,rA,rB",    "11 0x2  DDDDD AAAAA BBBB B--- 0x1 0x0", EFI, 0,
474
  it_float },
475
{ "lf.sub.d",   "rD,rA,rB",    "11 0x2  DDDDD AAAAA BBBB B--- 0x1 0x1", EFI, 0,
476
  it_float },
477
{ "lf.mul.d",   "rD,rA,rB",    "11 0x2  DDDDD AAAAA BBBB B--- 0x1 0x2", EFI, 0,
478
  it_float },
479
{ "lf.div.d",   "rD,rA,rB",    "11 0x2  DDDDD AAAAA BBBB B--- 0x1 0x3", EFI, 0,
480
  it_float },
481
{ "lf.itof.d",  "rD,rA",       "11 0x2  DDDDD AAAAA 0000 0--- 0x1 0x4", EFI, 0,
482
  it_float },
483
{ "lf.ftoi.d",  "rD,rA",       "11 0x2  DDDDD AAAAA 0000 0--- 0x1 0x5", EFI, 0,
484
  it_float },
485
{ "lf.rem.d",   "rD,rA,rB",    "11 0x2  DDDDD AAAAA BBBB B--- 0x1 0x6", EFI, 0,
486
  it_float },
487
{ "lf.madd.d",  "rD,rA,rB",    "11 0x2  DDDDD AAAAA BBBB B--- 0x1 0x7", EFI, 0,
488
  it_float },
489
{ "lf.sfeq.d",  "rA,rB",       "11 0x2  ----- AAAAA BBBB B--- 0x1 0x8", EFI, 0,
490
  it_float },
491
{ "lf.sfne.d",  "rA,rB",       "11 0x2  ----- AAAAA BBBB B--- 0x1 0x9", EFI, 0,
492
  it_float },
493
{ "lf.sfgt.d",  "rA,rB",       "11 0x2  ----- AAAAA BBBB B--- 0x1 0xA", EFI, 0,
494
  it_float },
495
{ "lf.sfge.d",  "rA,rB",       "11 0x2  ----- AAAAA BBBB B--- 0x1 0xB", EFI, 0,
496
  it_float },
497
{ "lf.sflt.d",  "rA,rB",       "11 0x2  ----- AAAAA BBBB B--- 0x1 0xC", EFI, 0,
498
  it_float },
499
{ "lf.sfle.d",  "rA,rB",       "11 0x2  ----- AAAAA BBBB B--- 0x1 0xD", EFI, 0,
500
  it_float },
501
{ "lf.cust1.d", "rA,rB",       "11 0x2  ----- AAAAA BBBB B--- 0xE ----", EFI, 0,
502
  it_float },
503 676 markom
 
504 1346 nogj
{ "l.sd",      "I(rD),rB",     "11 0x4  IIIII DDDDD BBBB BIII IIII IIII", EFI,
505
  0, it_store },
506
{ "l.sw",      "I(rD),rB",     "11 0x5  IIIII DDDDD BBBB BIII IIII IIII",
507
  EF(l_sw), 0, it_store },
508
{ "l.sb",      "I(rD),rB",     "11 0x6  IIIII DDDDD BBBB BIII IIII IIII",
509
  EF(l_sb), 0, it_store },
510
{ "l.sh",      "I(rD),rB",     "11 0x7  IIIII DDDDD BBBB BIII IIII IIII",
511
  EF(l_sh), 0, it_store },
512 1295 lampret
 
513 1346 nogj
{ "l.add",     "rD,rA,rB",     "11 0x8  DDDDD AAAAA BBBB B-00 ---- 0x0",
514
  EF(l_add), OR32_W_FLAG, it_arith },
515
{ "l.addc",    "rD,rA,rB",     "11 0x8  DDDDD AAAAA BBBB B-00 ---- 0x1",
516
  EF(l_addc), OR32_W_FLAG, it_arith },
517
{ "l.sub",     "rD,rA,rB",     "11 0x8  DDDDD AAAAA BBBB B-00 ---- 0x2",
518
  EF(l_sub), 0, it_arith },
519
{ "l.and",     "rD,rA,rB",     "11 0x8  DDDDD AAAAA BBBB B-00 ---- 0x3",
520
  EF(l_and), OR32_W_FLAG, it_arith },
521
{ "l.or",      "rD,rA,rB",     "11 0x8  DDDDD AAAAA BBBB B-00 ---- 0x4",
522
  EF(l_or), 0, it_arith },
523
{ "l.xor",     "rD,rA,rB",     "11 0x8  DDDDD AAAAA BBBB B-00 ---- 0x5",
524
  EF(l_xor), 0, it_arith },
525
{ "l.mul",     "rD,rA,rB",     "11 0x8  DDDDD AAAAA BBBB B-11 ---- 0x6",
526
  EF(l_mul), 0, it_arith },
527 1295 lampret
 
528 1346 nogj
{ "l.sll",     "rD,rA,rB",     "11 0x8  DDDDD AAAAA BBBB B-00 00-- 0x8",
529
  EF(l_sll), 0, it_shift },
530
{ "l.srl",     "rD,rA,rB",     "11 0x8  DDDDD AAAAA BBBB B-00 01-- 0x8",
531
  EF(l_srl), 0, it_shift },
532
{ "l.sra",     "rD,rA,rB",     "11 0x8  DDDDD AAAAA BBBB B-00 10-- 0x8",
533
  EF(l_sra), 0, it_shift },
534
{ "l.ror",     "rD,rA,rB",     "11 0x8  DDDDD AAAAA BBBB B-00 11-- 0x8", EFI,
535
  0, it_shift },
536
{ "l.div",     "rD,rA,rB",     "11 0x8  DDDDD AAAAA BBBB B-11 ---- 0x9",
537
  EF(l_div), 0, it_arith },
538
{ "l.divu",    "rD,rA,rB",     "11 0x8  DDDDD AAAAA BBBB B-11 ---- 0xA",
539
  EF(l_divu), 0, it_arith },
540
{ "l.mulu",    "rD,rA,rB",     "11 0x8  DDDDD AAAAA BBBB B-11 ---- 0xB", EFI,
541
  0, it_arith },
542
{ "l.extbs",   "rD,rA",     "11 0x8  DDDDD AAAAA ---- --00 01-- 0xC",
543
  EF(l_extbs), 0, it_move },
544
{ "l.exths",   "rD,rA",     "11 0x8  DDDDD AAAAA ---- --00 00-- 0xC",
545
  EF(l_exths), 0, it_move },
546
{ "l.extws",   "rD,rA",     "11 0x8  DDDDD AAAAA ---- --00 00-- 0xD",
547
  EF(l_extws), 0, it_move },
548
{ "l.extbz",   "rD,rA",     "11 0x8  DDDDD AAAAA ---- --00 11-- 0xC",
549
  EF(l_extbz), 0, it_move },
550
{ "l.exthz",   "rD,rA",     "11 0x8  DDDDD AAAAA ---- --00 10-- 0xC",
551
  EF(l_exthz), 0, it_move },
552
{ "l.extwz",   "rD,rA",     "11 0x8  DDDDD AAAAA ---- --00 01-- 0xD",
553
  EF(l_extwz), 0, it_move },
554
{ "l.cmov",    "rD,rA,rB",     "11 0x8  DDDDD AAAAA BBBB B-00 ---- 0xE",
555
  EF(l_cmov), OR32_R_FLAG, it_move },
556 1384 nogj
{ "l.ff1",     "rD,rA",     "11 0x8  DDDDD AAAAA ---- --00 ---- 0xF", EFI, 0,
557
  it_arith },
558 133 markom
 
559 1346 nogj
{ "l.sfeq",    "rA,rB",        "11 0x9  00000 AAAAA BBBB B--- ---- ----",
560
  EF(l_sfeq), OR32_W_FLAG, it_compare },
561
{ "l.sfne",    "rA,rB",        "11 0x9  00001 AAAAA BBBB B--- ---- ----",
562
  EF(l_sfne), OR32_W_FLAG, it_compare },
563
{ "l.sfgtu",   "rA,rB",        "11 0x9  00010 AAAAA BBBB B--- ---- ----",
564
  EF(l_sfgtu), OR32_W_FLAG, it_compare },
565
{ "l.sfgeu",   "rA,rB",        "11 0x9  00011 AAAAA BBBB B--- ---- ----",
566
  EF(l_sfgeu), OR32_W_FLAG, it_compare },
567
{ "l.sfltu",   "rA,rB",        "11 0x9  00100 AAAAA BBBB B--- ---- ----",
568
  EF(l_sfltu), OR32_W_FLAG, it_compare },
569
{ "l.sfleu",   "rA,rB",        "11 0x9  00101 AAAAA BBBB B--- ---- ----",
570
  EF(l_sfleu), OR32_W_FLAG, it_compare },
571
{ "l.sfgts",   "rA,rB",        "11 0x9  01010 AAAAA BBBB B--- ---- ----",
572
  EF(l_sfgts), OR32_W_FLAG, it_compare },
573
{ "l.sfges",   "rA,rB",        "11 0x9  01011 AAAAA BBBB B--- ---- ----",
574
  EF(l_sfges), OR32_W_FLAG, it_compare },
575
{ "l.sflts",   "rA,rB",        "11 0x9  01100 AAAAA BBBB B--- ---- ----",
576
  EF(l_sflts), OR32_W_FLAG, it_compare },
577
{ "l.sfles",   "rA,rB",        "11 0x9  01101 AAAAA BBBB B--- ---- ----",
578
  EF(l_sfles), OR32_W_FLAG, it_compare },
579 676 markom
 
580 1346 nogj
{ "l.cust5",   "rD,rA,rB,L,K", "11 0xC  DDDDD AAAAA BBBB BLLL LLLK KKKK", EFI,
581
  0, it_unknown },
582
{ "l.cust6",   "",             "11 0xD  ----- ----- ---- ---- ---- ----", EFI,
583
  0, it_unknown },
584
{ "l.cust7",   "",             "11 0xE  ----- ----- ---- ---- ---- ----", EFI,
585
  0, it_unknown },
586
{ "l.cust8",   "",             "11 0xF  ----- ----- ---- ---- ---- ----", EFI,
587
  0, it_unknown },
588 133 markom
 
589 221 markom
/* This section should not be defined in or1ksim, since it contains duplicates,
590
   which would cause machine builder to complain.  */
591 374 simons
#ifdef HAS_CUST
592 1346 nogj
{ "l.cust5_1",   "rD",         "11 0xC  DDDDD ----- ---- ---- ---- ----", EFI,
593
  0, it_unknown },
594
{ "l.cust5_2",   "rD,rA"   ,   "11 0xC  DDDDD AAAAA ---- ---- ---- ----", EFI,
595
  0, it_unknown },
596
{ "l.cust5_3",   "rD,rA,rB",   "11 0xC  DDDDD AAAAA BBBB B--- ---- ----", EFI,
597
  0, it_unknown },
598 221 markom
 
599 1346 nogj
{ "l.cust6_1",   "rD",         "11 0xD  DDDDD ----- ---- ---- ---- ----", EFI,
600
  0, it_unknown },
601
{ "l.cust6_2",   "rD,rA"   ,   "11 0xD  DDDDD AAAAA ---- ---- ---- ----", EFI,
602
  0, it_unknown },
603
{ "l.cust6_3",   "rD,rA,rB",   "11 0xD  DDDDD AAAAA BBBB B--- ---- ----", EFI,
604
  0, it_unknown },
605 221 markom
 
606 1346 nogj
{ "l.cust7_1",   "rD",         "11 0xE  DDDDD ----- ---- ---- ---- ----", EFI,
607
  0, it_unknown },
608
{ "l.cust7_2",   "rD,rA"   ,   "11 0xE  DDDDD AAAAA ---- ---- ---- ----", EFI,
609
  0, it_unknown },
610
{ "l.cust7_3",   "rD,rA,rB",   "11 0xE  DDDDD AAAAA BBBB B--- ---- ----", EFI,
611
  0, it_unknown },
612 221 markom
 
613 1346 nogj
{ "l.cust8_1",   "rD",         "11 0xF  DDDDD ----- ---- ---- ---- ----", EFI,
614
  0, it_unknown },
615
{ "l.cust8_2",   "rD,rA"   ,   "11 0xF  DDDDD AAAAA ---- ---- ---- ----", EFI,
616
  0, it_unknown },
617
{ "l.cust8_3",   "rD,rA,rB",   "11 0xF  DDDDD AAAAA BBBB B--- ---- ----", EFI,
618
  0, it_unknown },
619 221 markom
#endif
620
 
621 1346 nogj
{ "", "", "", EFI, 0, 0 }  /* Dummy entry, not included in num_opcodes.  This
622
                            * lets code examine entry i+1 without checking
623
                            * if we've run off the end of the table.  */
624 133 markom
};
625
 
626
#undef EFI
627
#undef EFN
628
#undef EF 
629
 
630
/* **INDENT-ON** */
631
 
632 371 markom
/* Define dummy, if debug is not defined.  */
633 1341 nogj
#ifndef HAS_DEBUG
634
#define debug(l, fmt...) ;
635 371 markom
#endif
636 133 markom
 
637 371 markom
CONST int num_opcodes = ((sizeof(or32_opcodes)) / (sizeof(struct or32_opcode))) - 1;
638
 
639 138 markom
/* Calculates instruction length in bytes. Always 4 for OR32. */
640
int
641
insn_len(int insn_index)
642 133 markom
{
643
  insn_index = 0; /* Just to get rid that warning.  */
644
  return 4;
645
}
646
 
647
/* Is individual insn's operand signed or unsigned? */
648 138 markom
int
649
letter_signed(char l)
650 133 markom
{
651
  CONST struct or32_letter *pletter;
652
 
653
  for(pletter = or32_letters; pletter->letter != '\0'; pletter++)
654
    if (pletter->letter == l)
655
      return pletter->sign;
656
 
657
  printf("letter_signed(%c): Unknown letter.\n", l);
658
  return 0;
659
}
660
 
661 703 markom
/* Simple cache for letter ranges */
662
static int range_cache[256] = {0};
663
 
664 133 markom
/* Number of letters in the individual lettered operand. */
665 138 markom
int
666
letter_range(char l)
667 133 markom
{
668
  CONST struct or32_opcode *pinsn;
669
  char *enc;
670
  int range = 0;
671 703 markom
 
672
  /* Is value cached? */
673 1308 phoenix
  if ((range = range_cache[(unsigned char)l])) return range;
674 133 markom
 
675 138 markom
  for(pinsn = or32_opcodes; strlen(pinsn->name); pinsn++)
676
    {
677
      if (strchr(pinsn->encoding,l))
678
        {
679
          for (enc = pinsn->encoding; *enc != '\0'; enc++)
680
            if ((*enc == '0') && (*(enc+1) == 'x'))
681
              enc += 2;
682
            else if (*enc == l)
683
              range++;
684 703 markom
          return range_cache[(unsigned char)l] = range;
685 133 markom
        }
686
    }
687 703 markom
 
688 133 markom
  printf("\nABORT: letter_range(%c): Never used letter.\n", l);
689
  exit(1);
690
}
691
 
692
/* MM: Returns index of given instruction name.  */
693 138 markom
int
694
insn_index (char *insn)
695
{
696 133 markom
  int i, found = -1;
697 371 markom
  for (i = 0; i < num_opcodes; i++)
698 138 markom
    if (!strcmp (or32_opcodes[i].name, insn))
699
      {
700
        found = i;
701
        break;
702
      }
703 133 markom
  return found;
704
}
705
 
706 717 markom
/* Returns name of the specified instruction index */
707
CONST char *
708
insn_name(int index)
709 138 markom
{
710 371 markom
  if (index >= 0 && index < num_opcodes)
711 133 markom
    return or32_opcodes[index].name;
712
  else
713
    return "???";
714
}
715
 
716 1342 nogj
#if defined(HAS_EXECUTION) && SIMPLE_EXECUTION
717 717 markom
void
718 1342 nogj
l_none(struct iqueue_entry *current)
719
{
720
}
721 1452 nogj
#elif defined(HAS_EXECUTION) && DYNAMIC_EXECUTION
722
void
723
l_none(struct op_queue *opq, int *param_t, orreg_t *param, int delay_slot)
724
{
725
}
726 1342 nogj
#else
727
void
728 717 markom
l_none()
729 138 markom
{
730 133 markom
}
731 1342 nogj
#endif
732 133 markom
 
733
/*** Finite automata for instruction decoding building code ***/
734
 
735 1341 nogj
/* Find symbols in encoding.  */
736 706 markom
unsigned long
737 133 markom
insn_extract(param_ch, enc_initial)
738
     char param_ch;
739
     char *enc_initial;
740
{
741
  char *enc;
742
  unsigned long ret = 0;
743
  unsigned opc_pos = 32;
744
  for (enc = enc_initial; *enc != '\0'; )
745
    if ((*enc == '0') && (*(enc+1) == 'x'))
746
      {
747
        unsigned long tmp = strtol(enc+2, NULL, 16);
748
        opc_pos -= 4;
749 138 markom
        if (param_ch == '0' || param_ch == '1')
750
          {
751
            if (param_ch == '0')
752
              tmp = 15 - tmp;
753
            ret |= tmp << opc_pos;
754
          }
755 133 markom
        enc += 3;
756
      }
757 138 markom
    else
758
      {
759
        if (*enc == '0' || *enc == '1' || *enc == '-' || isalpha(*enc) )
760
          {
761
            opc_pos--;
762
            if (param_ch == *enc)
763
              ret |= 1 << opc_pos;
764
          }
765
        enc++;
766 133 markom
      }
767
  return ret;
768
}
769
 
770 138 markom
#define MAX_AUTOMATA_SIZE (1200)
771
#define MAX_OP_TABLE_SIZE (1200)
772 133 markom
#define MAX_LEN           (8)
773
 
774
#ifndef MIN
775
# define MIN(x,y)          ((x) < (y) ? (x) : (y))
776
#endif
777
 
778
unsigned long *automata;
779
int nuncovered;
780
int curpass = 0;
781
 
782 1341 nogj
/* MM: Struct that holds runtime build information about instructions.  */
783 1342 nogj
struct temp_insn_struct *ti;
784 138 markom
 
785
struct insn_op_struct *op_data, **op_start;
786
 
787
/* Recursive utility function used to find best match and to build automata.  */
788
 
789
static unsigned long *
790
cover_insn (unsigned long *cur, int pass, unsigned int mask)
791
{
792 133 markom
  int best_first = 0, best_len = 0, i, last_match = -1, ninstr = 0;
793
  unsigned long cur_mask = mask;
794
  unsigned long *next;
795
 
796
  for (i = 0; i < num_opcodes; i++)
797 138 markom
    if (ti[i].in_pass == pass)
798
      {
799
        cur_mask &= ti[i].insn_mask;
800
        ninstr++;
801
        last_match = i;
802
      }
803
 
804 344 markom
  debug(8, "%08X %08X\n", mask, cur_mask);
805 138 markom
  if (ninstr == 0)
806
    return 0;
807
  if (ninstr == 1)
808
    {
809
      /* Leaf holds instruction index. */
810 344 markom
      debug(8, "%i>I%i %s\n", cur - automata, last_match, or32_opcodes[last_match].name);
811 138 markom
      *cur = LEAF_FLAG | last_match;
812
      cur++;
813
      nuncovered--;
814
    } else {
815
      /* Find longest match.  */
816
      for (i = 0; i < 32; i++)
817
        {
818
          int len;
819
          for (len = best_len + 1; len < MIN(MAX_LEN, 33 - i); len++)
820
            {
821
              unsigned long m = (1UL << ((unsigned long)len)) - 1;
822 344 markom
              debug(9, " (%i(%08X & %08X>>%i = %08X, %08X)",len,m, cur_mask, i, (cur_mask >> (unsigned)i), (cur_mask >> (unsigned)i) & m);
823 138 markom
              if ((m & (cur_mask >> (unsigned)i)) == m)
824
                {
825
                  best_len = len;
826
                  best_first = i;
827 344 markom
                  debug(9, "!");
828 138 markom
                }
829
              else
830
                break;
831
            }
832
        }
833 344 markom
      debug(9, "\n");
834 138 markom
      if (!best_len)
835
        {
836
          fprintf (stderr, "%i instructions match mask 0x%08X:\n", ninstr, mask);
837
          for (i = 0; i < num_opcodes; i++)
838
            if (ti[i].in_pass == pass)
839
              fprintf (stderr, "%s ", or32_opcodes[i].name);
840
 
841
          fprintf (stderr, "\n");
842
          exit (1);
843
        }
844 344 markom
      debug(8, "%i> #### %i << %i (%i) ####\n", cur - automata, best_len, best_first, ninstr);
845 138 markom
      *cur = best_first;
846
      cur++;
847
      *cur = (1 << best_len) - 1;
848
      cur++;
849
      next = cur;
850
      /* Allocate space for pointers.  */
851
      cur += 1 << best_len;
852
      cur_mask = (1 << (unsigned long)best_len) - 1;
853
 
854
      for (i = 0; i < (1 << (unsigned long)best_len); i++)
855
        {
856
          int j;
857
          unsigned long *c;
858
          curpass++;
859
          for (j = 0; j < num_opcodes; j++)
860
            if (ti[j].in_pass == pass
861 371 markom
                && ((ti[j].insn >> best_first) & cur_mask) == (unsigned long) i
862 138 markom
                && ((ti[j].insn_mask >> best_first) & cur_mask) == cur_mask)
863
              ti[j].in_pass = curpass;
864
 
865 344 markom
          debug(9, "%08X %08X %i\n", mask, cur_mask, best_first);
866 138 markom
          c = cover_insn (cur, curpass, mask & (~(cur_mask << best_first)));
867
          if (c)
868
            {
869 344 markom
              debug(8, "%i> #%X -> %u\n", next - automata, i, cur - automata);
870 138 markom
              *next = cur - automata;
871
              cur = c;
872
            }
873
          else
874
            {
875 344 markom
              debug(8, "%i> N/A\n", next - automata);
876 138 markom
              *next = 0;
877
            }
878
          next++;
879
        }
880 133 markom
    }
881 138 markom
  return cur;
882
}
883 133 markom
 
884 138 markom
/* Returns number of nonzero bits. */
885
static int
886
num_ones (unsigned long value)
887
{
888
  int c = 0;
889
  while (value)
890
    {
891
      if (value & 1)
892
        c++;
893
      value >>= 1;
894 133 markom
    }
895 138 markom
  return c;
896
}
897 133 markom
 
898 138 markom
/* Utility function, which converts parameters from or32_opcode format to more binary form.
899
   Parameters are stored in ti struct.  */
900
 
901
static struct insn_op_struct *
902
parse_params (CONST struct or32_opcode *opcode, struct insn_op_struct *cur)
903
{
904
  char *args = opcode->args;
905
  int i, type;
906 1346 nogj
  int num_cur_op = 0;;
907 138 markom
 
908
  i = 0;
909
  type = 0;
910 262 markom
  /* In case we don't have any parameters, we add dummy read from r0.  */
911
  if (!(*args)) {
912 263 markom
    cur->type = OPTYPE_REG | OPTYPE_OP | OPTYPE_LAST;
913 262 markom
    cur->data = 0;
914 355 markom
    debug(9, "#%08X %08X\n", cur->type, cur->data);
915 262 markom
    cur++;
916
    return cur;
917
  }
918
 
919 138 markom
  while (*args != '\0')
920
    {
921
      if (*args == 'r')
922
        {
923
          args++;
924
          type |= OPTYPE_REG;
925 1341 nogj
          if(args[1] == 'D')
926
            type |= OPTYPE_DST;
927 133 markom
        }
928 138 markom
      else if (isalpha (*args))
929
        {
930
          unsigned long arg;
931
          arg = insn_extract(*args, opcode->encoding);
932 355 markom
          debug(9, "%s : %08X ------\n", opcode->name, arg);
933 138 markom
          if (letter_signed (*args))
934
            {
935
              type |= OPTYPE_SIG;
936
              type |= ((num_ones (arg) - 1) << OPTYPE_SBIT_SHR) & OPTYPE_SBIT;
937
            }
938
 
939 1346 nogj
          num_cur_op = 0;
940 138 markom
          /* Split argument to sequences of consecutive ones.  */
941
          while (arg)
942
            {
943
              int shr = 0;
944
              unsigned long tmp = arg, mask = 0;
945
              while ((tmp & 1) == 0)
946
                {
947
                  shr++;
948
                  tmp >>= 1;
949
                }
950
              while (tmp & 1)
951
                {
952
                  mask++;
953
                  tmp >>= 1;
954
                }
955
              cur->type = type | shr;
956
              cur->data = mask;
957
              arg &= ~(((1 << mask) - 1) << shr);
958 355 markom
              debug(6, "|%08X %08X\n", cur->type, cur->data);
959 138 markom
              cur++;
960 1346 nogj
              num_cur_op++;
961 138 markom
            }
962
          args++;
963
        }
964
      else if (*args == '(')
965
        {
966
          /* Next param is displacement.  Later we will treat them as one operand.  */
967 1346 nogj
          /* Set the OPTYPE_DIS flag on all insn_op_structs that belong to this
968
           * operand */
969
          while(num_cur_op > 0) {
970
            cur[-num_cur_op].type |= type | OPTYPE_DIS;
971
            num_cur_op--;
972
          }
973
          cur[-1].type |= OPTYPE_OP;
974 355 markom
          debug(9, ">%08X %08X\n", cur->type, cur->data);
975 138 markom
          type = 0;
976
          i++;
977
          args++;
978
        }
979
      else if (*args == OPERAND_DELIM)
980
        {
981
          cur--;
982
          cur->type = type | cur->type | OPTYPE_OP;
983 355 markom
          debug(9, ">%08X %08X\n", cur->type, cur->data);
984 138 markom
          cur++;
985
          type = 0;
986
          i++;
987
          args++;
988
        }
989
      else if (*args == '0')
990
        {
991
          cur->type = type;
992
          cur->data = 0;
993 355 markom
          debug(9, ">%08X %08X\n", cur->type, cur->data);
994 138 markom
          cur++;
995
          type = 0;
996
          i++;
997
          args++;
998
        }
999
      else if (*args == ')')
1000
        args++;
1001
      else
1002
        {
1003
          fprintf (stderr, "%s : parse error in args.\n", opcode->name);
1004
          exit (1);
1005
        }
1006 133 markom
    }
1007 138 markom
  cur--;
1008
  cur->type = type | cur->type | OPTYPE_OP | OPTYPE_LAST;
1009 355 markom
  debug(9, "#%08X %08X\n", cur->type, cur->data);
1010 138 markom
  cur++;
1011 133 markom
  return cur;
1012
}
1013
 
1014 138 markom
/* Constructs new automata based on or32_opcodes array.  */
1015
 
1016
void
1017
build_automata()
1018
{
1019 371 markom
  int i;
1020 133 markom
  unsigned long *end;
1021 138 markom
  struct insn_op_struct *cur;
1022
 
1023 133 markom
  automata = (unsigned long *) malloc (MAX_AUTOMATA_SIZE * sizeof (unsigned long));
1024 138 markom
  ti = (struct temp_insn_struct *) malloc (sizeof (struct temp_insn_struct) * num_opcodes);
1025 133 markom
 
1026
  nuncovered = num_opcodes;
1027 709 markom
 
1028
#ifdef HAS_EXECUTION
1029 138 markom
  printf("Building automata... ");
1030 709 markom
#endif
1031
 
1032 133 markom
  /* Build temporary information about instructions.  */
1033 138 markom
  for (i = 0; i < num_opcodes; i++)
1034
    {
1035
      unsigned long ones, zeros;
1036
      char *encoding = or32_opcodes[i].encoding;
1037
      ones  = insn_extract('1', encoding);
1038
      zeros = insn_extract('0', encoding);
1039
      ti[i].insn_mask = ones | zeros;
1040
      ti[i].insn = ones;
1041
      ti[i].in_pass = curpass = 0;
1042 344 markom
      /*debug(9, "%s: %s %08X %08X\n", or32_opcodes[i].name,
1043 138 markom
        or32_opcodes[i].encoding, ti[i].insn_mask, ti[i].insn);*/
1044
    }
1045 133 markom
 
1046
  /* Until all are covered search for best criteria to separate them.  */
1047 138 markom
  end = cover_insn (automata, curpass, 0xFFFFFFFF);
1048
  if (end - automata > MAX_AUTOMATA_SIZE)
1049
    {
1050
      fprintf (stderr, "Automata too large. Increase MAX_AUTOMATA_SIZE.");
1051
      exit (1);
1052
    }
1053 709 markom
#ifdef HAS_EXECUTION
1054 138 markom
  printf("done, num uncovered: %i/%i.\n", nuncovered, num_opcodes);
1055 709 markom
#endif
1056 371 markom
 
1057 709 markom
#ifdef HAS_EXECUTION
1058 138 markom
  printf("Parsing operands data... ");
1059 709 markom
#endif
1060 138 markom
  op_data = (struct insn_op_struct *) malloc (MAX_OP_TABLE_SIZE * sizeof (struct insn_op_struct));
1061
  op_start = (struct insn_op_struct **) malloc (num_opcodes * sizeof (struct insn_op_struct *));
1062
  cur = op_data;
1063
  for (i = 0; i < num_opcodes; i++)
1064
    {
1065
      op_start[i] = cur;
1066
      cur = parse_params (&or32_opcodes[i], cur);
1067
      if (cur - op_data > MAX_OP_TABLE_SIZE)
1068
        {
1069
          fprintf (stderr, "Operands table too small, increase MAX_OP_TABLE_SIZE.\n");
1070
          exit (1);
1071
        }
1072
    }
1073 709 markom
#ifdef HAS_EXECUTION
1074 138 markom
  printf("done.\n");
1075 709 markom
#endif
1076 133 markom
}
1077
 
1078 138 markom
void destruct_automata ()
1079
{
1080
  free (ti);
1081 133 markom
  free (automata);
1082 138 markom
  free (op_data);
1083
  free (op_start);
1084 133 markom
}
1085
 
1086
/* Decodes instruction and returns instruction index.  */
1087 138 markom
int insn_decode (unsigned int insn)
1088
{
1089 133 markom
  unsigned long *a = automata;
1090 138 markom
  int i;
1091
  while (!(*a & LEAF_FLAG))
1092
    {
1093
      unsigned int first = *a;
1094 703 markom
      //debug(9, "%i ", a - automata);
1095 138 markom
      a++;
1096
      i = (insn >> first) & *a;
1097
      a++;
1098
      if (!*(a + i))
1099
        { /* Invalid instruction found?  */
1100 703 markom
          //debug(9, "XXX\n", i);
1101 138 markom
          return -1;
1102
        }
1103
      a = automata + *(a + i);
1104
    }
1105
  i = *a & ~LEAF_FLAG;
1106 703 markom
  //debug(9, "%i\n", i);
1107 138 markom
  /* Final check - do we have direct match?
1108
     (based on or32_opcodes this should be the only possibility,
1109
     but in case of invalid/missing instruction we must perform a check)  */
1110
  if ((ti[i].insn_mask & insn) == ti[i].insn)
1111
    return i;
1112
  else
1113
    return -1;
1114 133 markom
}
1115 371 markom
 
1116
static char disassembled_str[50];
1117
char *disassembled = &disassembled_str[0];
1118
 
1119
/* Automagically does zero- or sign- extension and also finds correct
1120
   sign bit position if sign extension is correct extension. Which extension
1121
   is proper is figured out from letter description. */
1122
 
1123 879 markom
unsigned long
1124 371 markom
extend_imm(unsigned long imm, char l)
1125
{
1126
  unsigned long mask;
1127
  int letter_bits;
1128
 
1129
  /* First truncate all bits above valid range for this letter
1130
     in case it is zero extend. */
1131
  letter_bits = letter_range(l);
1132
  mask = (1 << letter_bits) - 1;
1133
  imm &= mask;
1134
 
1135
  /* Do sign extend if this is the right one. */
1136
  if (letter_signed(l) && (imm >> (letter_bits - 1)))
1137
    imm |= (~mask);
1138
 
1139
  return imm;
1140
}
1141
 
1142 879 markom
unsigned long
1143 371 markom
or32_extract(param_ch, enc_initial, insn)
1144
     char param_ch;
1145
     char *enc_initial;
1146
     unsigned long insn;
1147
{
1148
  char *enc;
1149
  unsigned long ret = 0;
1150
  int opc_pos = 0;
1151
  int param_pos = 0;
1152
 
1153
  for (enc = enc_initial; *enc != '\0'; enc++)
1154
    if (*enc == param_ch)
1155
      {
1156
        if (enc - 2 >= enc_initial && (*(enc - 2) == '0') && (*(enc - 1) == 'x'))
1157
          continue;
1158
        else
1159
          param_pos++;
1160
      }
1161
 
1162
#if DEBUG
1163
  printf("or32_extract: %x ", param_pos);
1164
#endif
1165
  opc_pos = 32;
1166
  for (enc = enc_initial; *enc != '\0'; )
1167
    if ((*enc == '0') && (*(enc+1) == 'x'))
1168
      {
1169
        opc_pos -= 4;
1170
        if ((param_ch == '0') || (param_ch == '1'))
1171
          {
1172
            unsigned long tmp = strtol(enc, NULL, 16);
1173
#if DEBUG
1174
            printf(" enc=%s, tmp=%x ", enc, tmp);
1175
#endif
1176
            if (param_ch == '0')
1177
              tmp = 15 - tmp;
1178
            ret |= tmp << opc_pos;
1179
          }
1180
        enc += 3;
1181
      }
1182
    else if ((*enc == '0') || (*enc == '1'))
1183
      {
1184
        opc_pos--;
1185
        if (param_ch == *enc)
1186
          ret |= 1 << opc_pos;
1187
        enc++;
1188
      }
1189
    else if (*enc == param_ch)
1190
      {
1191
        opc_pos--;
1192
        param_pos--;
1193
#if DEBUG
1194
        printf("\n  ret=%x opc_pos=%x, param_pos=%x\n", ret, opc_pos, param_pos);
1195
#endif  
1196
        if (islower(param_ch))
1197
          ret -= ((insn >> opc_pos) & 0x1) << param_pos;
1198
        else
1199
          ret += ((insn >> opc_pos) & 0x1) << param_pos;
1200
        enc++;
1201
      }
1202
    else if (isalpha(*enc))
1203
      {
1204
        opc_pos--;
1205
        enc++;
1206
      }
1207
    else if (*enc == '-')
1208
      {
1209
        opc_pos--;
1210
        enc++;
1211
      }
1212
    else
1213
      enc++;
1214
 
1215
#if DEBUG
1216
  printf ("ret=%x\n", ret);
1217
#endif
1218
  return ret;
1219
}
1220
 
1221
/* Print register. Used only by print_insn. */
1222
 
1223 703 markom
static char *
1224
or32_print_register (dest, param_ch, encoding, insn)
1225
     char *dest;
1226 371 markom
     char param_ch;
1227
     char *encoding;
1228
     unsigned long insn;
1229
{
1230
  int regnum = or32_extract(param_ch, encoding, insn);
1231
 
1232 703 markom
  sprintf (dest, "r%d", regnum);
1233
  while (*dest) dest++;
1234
  return dest;
1235 371 markom
}
1236
 
1237
/* Print immediate. Used only by print_insn. */
1238
 
1239 703 markom
static char *
1240
or32_print_immediate (dest, param_ch, encoding, insn)
1241
     char *dest;
1242 371 markom
     char param_ch;
1243
     char *encoding;
1244
     unsigned long insn;
1245
{
1246
  int imm = or32_extract (param_ch, encoding, insn);
1247
 
1248
  imm = extend_imm(imm, param_ch);
1249
 
1250
  if (letter_signed(param_ch))
1251
    {
1252
      if (imm < 0)
1253 703 markom
        sprintf (dest, "%d", imm);
1254 371 markom
      else
1255 703 markom
        sprintf (dest, "0x%x", imm);
1256 371 markom
    }
1257
  else
1258 703 markom
    sprintf (dest, "%#x", imm);
1259
  while (*dest) dest++;
1260
  return dest;
1261 371 markom
}
1262
 
1263
/* Disassemble one instruction from insn to disassemble.
1264
   Return the size of the instruction.  */
1265
 
1266
int
1267
disassemble_insn (insn)
1268
     unsigned long insn;
1269
{
1270 703 markom
  return disassemble_index (insn, insn_decode (insn));
1271
}
1272 371 markom
 
1273 703 markom
/* Disassemble one instruction from insn index.
1274
   Return the size of the instruction.  */
1275
 
1276
int
1277
disassemble_index (insn, index)
1278
     unsigned long insn;
1279
     int index;
1280
{
1281
  char *dest = disassembled;
1282 371 markom
  if (index >= 0)
1283
    {
1284
      struct or32_opcode const *opcode = &or32_opcodes[index];
1285
      char *s;
1286
 
1287 703 markom
      strcpy (dest, opcode->name);
1288
      while (*dest) dest++;
1289
      *dest++ = ' ';
1290
      *dest = 0;
1291
 
1292 371 markom
      for (s = opcode->args; *s != '\0'; ++s)
1293
        {
1294
          switch (*s)
1295
            {
1296
            case '\0':
1297 703 markom
              return insn_len (insn);
1298 714 markom
 
1299 371 markom
            case 'r':
1300 703 markom
              dest = or32_print_register(dest, *++s, opcode->encoding, insn);
1301 371 markom
              break;
1302 714 markom
 
1303 371 markom
            default:
1304
              if (strchr (opcode->encoding, *s))
1305 703 markom
                dest = or32_print_immediate (dest, *s, opcode->encoding, insn);
1306
              else {
1307
                *dest++ = *s;
1308
                *dest = 0;
1309
              }
1310 371 markom
            }
1311
        }
1312
    }
1313
  else
1314
    {
1315
      /* This used to be %8x for binutils.  */
1316 1308 phoenix
      sprintf(dest, ".word 0x%08lx", insn);
1317 703 markom
      while (*dest) dest++;
1318 371 markom
    }
1319
  return insn_len (insn);
1320
}

powered by: WebSVN 2.1.0

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