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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [or1ksim/] [cpu/] [or32/] [or32.c] - Blame information for rev 673

Go to most recent revision | Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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