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

Subversion Repositories or1k

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

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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