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

Subversion Repositories or1k

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

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

powered by: WebSVN 2.1.0

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