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

Subversion Repositories or1k

[/] [or1k/] [tags/] [nog_patch_36/] [insight/] [opcodes/] [or32.c] - Blame information for rev 1350

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

powered by: WebSVN 2.1.0

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