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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [opcodes/] [or32.c] - Blame information for rev 1554

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

powered by: WebSVN 2.1.0

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