~jderose/ubuntu/raring/qemu/vde-again

« back to all changes in this revision

Viewing changes to sparc-dis.c

  • Committer: Bazaar Package Importer
  • Author(s): Aurelien Jarno, Aurelien Jarno
  • Date: 2009-03-22 10:13:17 UTC
  • mfrom: (1.2.1 upstream) (6.1.1 sid)
  • Revision ID: james.westby@ubuntu.com-20090322101317-iigjtnu5qil35dtb
Tags: 0.10.1-1
[ Aurelien Jarno ]
* New upstream stable release:
  - patches/80_stable-branch.patch: remove.
* debian/control: 
  - Remove depends on proll.
  - Move depends on device-tree-compiler to build-depends.
  - Bump Standards-Version to 3.8.1 (no changes).
* patches/82_qemu-img_decimal.patch: new patch from upstream to make
  qemu-img accept sizes with decimal values (closes: bug#501400).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Print SPARC instructions.
2
 
   Copyright 1989, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
3
 
   2000, 2002 Free Software Foundation, Inc.
4
 
 
5
 
This program is free software; you can redistribute it and/or modify
6
 
it under the terms of the GNU General Public License as published by
7
 
the Free Software Foundation; either version 2 of the License, or
8
 
(at your option) any later version.
9
 
 
10
 
This program is distributed in the hope that it will be useful,
11
 
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 
GNU General Public License for more details.
14
 
 
15
 
You should have received a copy of the GNU General Public License
16
 
along with this program; if not, write to the Free Software
17
 
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 
1
/*
 
2
 * These files from binutils are concatenated:
 
3
 * include/opcode/sparc.h, opcodes/sparc-opc.c, opcodes/sparc-dis.c
 
4
 */
 
5
 
 
6
/* include/opcode/sparc.h */
 
7
 
 
8
/* Definitions for opcode table for the sparc.
 
9
   Copyright 1989, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 2000, 2002,
 
10
   2003, 2005 Free Software Foundation, Inc.
 
11
 
 
12
   This file is part of GAS, the GNU Assembler, GDB, the GNU debugger, and
 
13
   the GNU Binutils.
 
14
 
 
15
   GAS/GDB is free software; you can redistribute it and/or modify
 
16
   it under the terms of the GNU General Public License as published by
 
17
   the Free Software Foundation; either version 2, or (at your option)
 
18
   any later version.
 
19
 
 
20
   GAS/GDB is distributed in the hope that it will be useful,
 
21
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
22
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 
23
   GNU General Public License for more details.
 
24
 
 
25
   You should have received a copy of the GNU General Public License
 
26
   along with GAS or GDB; see the file COPYING. If not, write to
 
27
   the Free Software Foundation, 51 Franklin Street - Fifth Floor,
 
28
   Boston, MA 02110-1301, USA.  */
 
29
 
18
30
#include <stdlib.h>
19
31
#include "dis-asm.h"
20
32
 
33
45
   The values are indices into `sparc_opcode_archs' defined in sparc-opc.c.
34
46
   Don't change this without updating sparc-opc.c.  */
35
47
 
36
 
enum sparc_opcode_arch_val {
 
48
enum sparc_opcode_arch_val
 
49
{
37
50
  SPARC_OPCODE_ARCH_V6 = 0,
38
51
  SPARC_OPCODE_ARCH_V7,
39
52
  SPARC_OPCODE_ARCH_V8,
40
53
  SPARC_OPCODE_ARCH_SPARCLET,
41
54
  SPARC_OPCODE_ARCH_SPARCLITE,
42
 
  /* v9 variants must appear last */
 
55
  /* V9 variants must appear last.  */
43
56
  SPARC_OPCODE_ARCH_V9,
44
 
  SPARC_OPCODE_ARCH_V9A, /* v9 with ultrasparc additions */
45
 
  SPARC_OPCODE_ARCH_V9B, /* v9 with ultrasparc and cheetah additions */
46
 
  SPARC_OPCODE_ARCH_BAD /* error return from sparc_opcode_lookup_arch */
 
57
  SPARC_OPCODE_ARCH_V9A, /* V9 with ultrasparc additions.  */
 
58
  SPARC_OPCODE_ARCH_V9B, /* V9 with ultrasparc and cheetah additions.  */
 
59
  SPARC_OPCODE_ARCH_BAD  /* Error return from sparc_opcode_lookup_arch.  */
47
60
};
48
61
 
49
62
/* The highest architecture in the table.  */
58
71
 
59
72
/* Table of cpu variants.  */
60
73
 
61
 
struct sparc_opcode_arch {
 
74
typedef struct sparc_opcode_arch
 
75
{
62
76
  const char *name;
63
77
  /* Mask of sparc_opcode_arch_val's supported.
64
78
     EG: For v7 this would be
65
79
     (SPARC_OPCODE_ARCH_MASK (..._V6) | SPARC_OPCODE_ARCH_MASK (..._V7)).
66
80
     These are short's because sparc_opcode.architecture is.  */
67
81
  short supported;
68
 
};
69
 
 
70
 
extern const struct sparc_opcode_arch sparc_opcode_archs[];
71
 
 
72
 
/* Given architecture name, look up it's sparc_opcode_arch_val value.  */
73
 
extern enum sparc_opcode_arch_val sparc_opcode_lookup_arch
74
 
  PARAMS ((const char *));
 
82
} sparc_opcode_arch;
 
83
 
 
84
static const struct sparc_opcode_arch sparc_opcode_archs[];
75
85
 
76
86
/* Return the bitmask of supported architectures for ARCH.  */
77
87
#define SPARC_OPCODE_SUPPORTED(ARCH) (sparc_opcode_archs[ARCH].supported)
79
89
/* Non-zero if ARCH1 conflicts with ARCH2.
80
90
   IE: ARCH1 as a supported bit set that ARCH2 doesn't, and vice versa.  */
81
91
#define SPARC_OPCODE_CONFLICT_P(ARCH1, ARCH2) \
82
 
(((SPARC_OPCODE_SUPPORTED (ARCH1) & SPARC_OPCODE_SUPPORTED (ARCH2)) \
83
 
  != SPARC_OPCODE_SUPPORTED (ARCH1)) \
84
 
 && ((SPARC_OPCODE_SUPPORTED (ARCH1) & SPARC_OPCODE_SUPPORTED (ARCH2)) \
 
92
 (((SPARC_OPCODE_SUPPORTED (ARCH1) & SPARC_OPCODE_SUPPORTED (ARCH2)) \
 
93
   != SPARC_OPCODE_SUPPORTED (ARCH1)) \
 
94
  && ((SPARC_OPCODE_SUPPORTED (ARCH1) & SPARC_OPCODE_SUPPORTED (ARCH2)) \
85
95
     != SPARC_OPCODE_SUPPORTED (ARCH2)))
86
96
 
87
97
/* Structure of an opcode table entry.  */
88
98
 
89
 
struct sparc_opcode {
 
99
typedef struct sparc_opcode
 
100
{
90
101
  const char *name;
91
 
  unsigned long match;  /* Bits that must be set. */
92
 
  unsigned long lose;   /* Bits that must not be set. */
 
102
  unsigned long match;  /* Bits that must be set.  */
 
103
  unsigned long lose;   /* Bits that must not be set.  */
93
104
  const char *args;
94
 
  /* This was called "delayed" in versions before the flags. */
 
105
  /* This was called "delayed" in versions before the flags.  */
95
106
  char flags;
96
107
  short architecture;   /* Bitmask of sparc_opcode_arch_val's.  */
97
 
};
 
108
} sparc_opcode;
98
109
 
99
 
#define F_DELAYED       1       /* Delayed branch */
100
 
#define F_ALIAS         2       /* Alias for a "real" instruction */
101
 
#define F_UNBR          4       /* Unconditional branch */
102
 
#define F_CONDBR        8       /* Conditional branch */
103
 
#define F_JSR           16      /* Subroutine call */
104
 
#define F_FLOAT         32      /* Floating point instruction (not a branch) */
105
 
#define F_FBR           64      /* Floating point branch */
 
110
#define F_DELAYED       1       /* Delayed branch.  */
 
111
#define F_ALIAS         2       /* Alias for a "real" instruction.  */
 
112
#define F_UNBR          4       /* Unconditional branch.  */
 
113
#define F_CONDBR        8       /* Conditional branch.  */
 
114
#define F_JSR           16      /* Subroutine call.  */
 
115
#define F_FLOAT         32      /* Floating point instruction (not a branch).  */
 
116
#define F_FBR           64      /* Floating point branch.  */
106
117
/* FIXME: Add F_ANACHRONISTIC flag for v9.  */
107
118
 
108
 
/*
109
 
 
110
 
All sparc opcodes are 32 bits, except for the `set' instruction (really a
111
 
macro), which is 64 bits. It is handled as a special case.
112
 
 
113
 
The match component is a mask saying which bits must match a particular
114
 
opcode in order for an instruction to be an instance of that opcode.
115
 
 
116
 
The args component is a string containing one character for each operand of the
117
 
instruction.
118
 
 
119
 
Kinds of operands:
 
119
/* All sparc opcodes are 32 bits, except for the `set' instruction (really a
 
120
   macro), which is 64 bits. It is handled as a special case.
 
121
 
 
122
   The match component is a mask saying which bits must match a particular
 
123
   opcode in order for an instruction to be an instance of that opcode.
 
124
 
 
125
   The args component is a string containing one character for each operand of the
 
126
   instruction.
 
127
 
 
128
   Kinds of operands:
120
129
        #       Number used by optimizer.       It is ignored.
121
130
        1       rs1 register.
122
131
        2       rs2 register.
184
193
        _       Ancillary state register in rd (v9a)
185
194
        /       Ancillary state register in rs1 (v9a)
186
195
 
187
 
The following chars are unused: (note: ,[] are used as punctuation)
188
 
[45]
189
 
 
190
 
*/
191
 
 
192
 
#define OP2(x)          (((x)&0x7) << 22) /* op2 field of format2 insns */
193
 
#define OP3(x)          (((x)&0x3f) << 19) /* op3 field of format3 insns */
194
 
#define OP(x)           ((unsigned)((x)&0x3) << 30) /* op field of all insns */
195
 
#define OPF(x)          (((x)&0x1ff) << 5) /* opf field of float insns */
196
 
#define OPF_LOW5(x)     OPF((x)&0x1f) /* v9 */
197
 
#define F3F(x, y, z)    (OP(x) | OP3(y) | OPF(z)) /* format3 float insns */
198
 
#define F3I(x)          (((x)&0x1) << 13) /* immediate field of format 3 insns */
199
 
#define F2(x, y)        (OP(x) | OP2(y)) /* format 2 insns */
200
 
#define F3(x, y, z)     (OP(x) | OP3(y) | F3I(z)) /* format3 insns */
201
 
#define F1(x)           (OP(x))
202
 
#define DISP30(x)       ((x)&0x3fffffff)
203
 
#define ASI(x)          (((x)&0xff) << 5) /* asi field of format3 insns */
204
 
#define RS2(x)          ((x)&0x1f) /* rs2 field */
205
 
#define SIMM13(x)       ((x)&0x1fff) /* simm13 field */
206
 
#define RD(x)           (((x)&0x1f) << 25) /* destination register field */
207
 
#define RS1(x)          (((x)&0x1f) << 14) /* rs1 field */
208
 
#define ASI_RS2(x)      (SIMM13(x))
209
 
#define MEMBAR(x)       ((x)&0x7f)
210
 
#define SLCPOP(x)       (((x)&0x7f) << 6) /* sparclet cpop */
211
 
 
212
 
#define ANNUL   (1<<29)
213
 
#define BPRED   (1<<19) /* v9 */
214
 
#define IMMED   F3I(1)
215
 
#define RD_G0   RD(~0)
216
 
#define RS1_G0  RS1(~0)
217
 
#define RS2_G0  RS2(~0)
218
 
 
219
 
extern const struct sparc_opcode sparc_opcodes[];
220
 
extern const int sparc_num_opcodes;
221
 
 
222
 
extern int sparc_encode_asi PARAMS ((const char *));
223
 
extern const char *sparc_decode_asi PARAMS ((int));
224
 
extern int sparc_encode_membar PARAMS ((const char *));
225
 
extern const char *sparc_decode_membar PARAMS ((int));
226
 
extern int sparc_encode_prefetch PARAMS ((const char *));
227
 
extern const char *sparc_decode_prefetch PARAMS ((int));
228
 
extern int sparc_encode_sparclet_cpreg PARAMS ((const char *));
229
 
extern const char *sparc_decode_sparclet_cpreg PARAMS ((int));
 
196
  The following chars are unused: (note: ,[] are used as punctuation)
 
197
  [45].  */
 
198
 
 
199
#define OP2(x)          (((x) & 0x7) << 22)  /* Op2 field of format2 insns.  */
 
200
#define OP3(x)          (((x) & 0x3f) << 19) /* Op3 field of format3 insns.  */
 
201
#define OP(x)           ((unsigned) ((x) & 0x3) << 30) /* Op field of all insns.  */
 
202
#define OPF(x)          (((x) & 0x1ff) << 5) /* Opf field of float insns.  */
 
203
#define OPF_LOW5(x)     OPF ((x) & 0x1f)     /* V9.  */
 
204
#define F3F(x, y, z)    (OP (x) | OP3 (y) | OPF (z)) /* Format3 float insns.  */
 
205
#define F3I(x)          (((x) & 0x1) << 13)  /* Immediate field of format 3 insns.  */
 
206
#define F2(x, y)        (OP (x) | OP2(y))    /* Format 2 insns.  */
 
207
#define F3(x, y, z)     (OP (x) | OP3(y) | F3I(z)) /* Format3 insns.  */
 
208
#define F1(x)           (OP (x))
 
209
#define DISP30(x)       ((x) & 0x3fffffff)
 
210
#define ASI(x)          (((x) & 0xff) << 5)  /* Asi field of format3 insns.  */
 
211
#define RS2(x)          ((x) & 0x1f)         /* Rs2 field.  */
 
212
#define SIMM13(x)       ((x) & 0x1fff)       /* Simm13 field.  */
 
213
#define RD(x)           (((x) & 0x1f) << 25) /* Destination register field.  */
 
214
#define RS1(x)          (((x) & 0x1f) << 14) /* Rs1 field.  */
 
215
#define ASI_RS2(x)      (SIMM13 (x))
 
216
#define MEMBAR(x)       ((x) & 0x7f)
 
217
#define SLCPOP(x)       (((x) & 0x7f) << 6)  /* Sparclet cpop.  */
 
218
 
 
219
#define ANNUL   (1 << 29)
 
220
#define BPRED   (1 << 19)       /* V9.  */
 
221
#define IMMED   F3I (1)
 
222
#define RD_G0   RD (~0)
 
223
#define RS1_G0  RS1 (~0)
 
224
#define RS2_G0  RS2 (~0)
 
225
 
 
226
static const struct sparc_opcode sparc_opcodes[];
 
227
 
 
228
static const char *sparc_decode_asi_v8 (int);
 
229
static const char *sparc_decode_asi_v9 (int);
 
230
static const char *sparc_decode_membar (int);
 
231
static const char *sparc_decode_prefetch (int);
 
232
static const char *sparc_decode_sparclet_cpreg (int);
 
233
 
 
234
/* Local Variables:
 
235
   fill-column: 131
 
236
   comment-column: 0
 
237
   End: */
 
238
 
 
239
/* opcodes/sparc-opc.c */
 
240
 
 
241
/* Table of opcodes for the sparc.
 
242
   Copyright 1989, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
 
243
   2000, 2002, 2004, 2005
 
244
   Free Software Foundation, Inc.
 
245
 
 
246
   This file is part of the BFD library.
 
247
 
 
248
   BFD is free software; you can redistribute it and/or modify it under
 
249
   the terms of the GNU General Public License as published by the Free
 
250
   Software Foundation; either version 2, or (at your option) any later
 
251
   version.
 
252
 
 
253
   BFD is distributed in the hope that it will be useful, but WITHOUT ANY
 
254
   WARRANTY; without even the implied warranty of MERCHANTABILITY or
 
255
   FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
 
256
   for more details.
 
257
 
 
258
   You should have received a copy of the GNU General Public License
 
259
   along with this software; see the file COPYING.  If not, write to
 
260
   the Free Software Foundation, 51 Franklin Street - Fifth Floor,
 
261
   Boston, MA 02110-1301, USA.  */
 
262
 
 
263
/* FIXME-someday: perhaps the ,a's and such should be embedded in the
 
264
   instruction's name rather than the args.  This would make gas faster, pinsn
 
265
   slower, but would mess up some macros a bit.  xoxorich. */
230
266
 
231
267
/* Some defines to make life easy.  */
232
268
#define MASK_V6         SPARC_OPCODE_ARCH_MASK (SPARC_OPCODE_ARCH_V6)
242
278
 
243
279
#define v6              (MASK_V6 | MASK_V7 | MASK_V8 | MASK_SPARCLET \
244
280
                         | MASK_SPARCLITE | MASK_V9 | MASK_V9A | MASK_V9B)
245
 
/* v6 insns not supported on the sparclet */
 
281
/* v6 insns not supported on the sparclet.  */
246
282
#define v6notlet        (MASK_V6 | MASK_V7 | MASK_V8 \
247
283
                         | MASK_SPARCLITE | MASK_V9 | MASK_V9A | MASK_V9B)
248
284
#define v7              (MASK_V7 | MASK_V8 | MASK_SPARCLET \
260
296
#define v9              (MASK_V9 | MASK_V9A | MASK_V9B)
261
297
#define v9a             (MASK_V9A | MASK_V9B)
262
298
#define v9b             (MASK_V9B)
263
 
/* v6 insns not supported by v9 */
 
299
/* v6 insns not supported by v9.  */
264
300
#define v6notv9         (MASK_V6 | MASK_V7 | MASK_V8 \
265
301
                         | MASK_SPARCLET | MASK_SPARCLITE)
266
302
/* v9a instructions which would appear to be aliases to v9's impdep's
267
 
   otherwise */
 
303
   otherwise.  */
268
304
#define v9notv9a        (MASK_V9)
269
305
 
270
306
/* Table of opcode architectures.
271
307
   The order is defined in opcode/sparc.h.  */
272
308
 
273
 
const struct sparc_opcode_arch sparc_opcode_archs[] = {
 
309
static const struct sparc_opcode_arch sparc_opcode_archs[] =
 
310
{
274
311
  { "v6", MASK_V6 },
275
312
  { "v7", MASK_V6 | MASK_V7 },
276
313
  { "v8", MASK_V6 | MASK_V7 | MASK_V8 },
285
322
  { NULL, 0 }
286
323
};
287
324
 
288
 
/* Given NAME, return it's architecture entry.  */
289
 
 
290
 
enum sparc_opcode_arch_val
291
 
sparc_opcode_lookup_arch (name)
292
 
     const char *name;
293
 
{
294
 
  const struct sparc_opcode_arch *p;
295
 
 
296
 
  for (p = &sparc_opcode_archs[0]; p->name; ++p)
297
 
    {
298
 
      if (strcmp (name, p->name) == 0)
299
 
        return (enum sparc_opcode_arch_val) (p - &sparc_opcode_archs[0]);
300
 
    }
301
 
 
302
 
  return SPARC_OPCODE_ARCH_BAD;
303
 
}
304
 
 
305
325
/* Branch condition field.  */
306
 
#define COND(x)         (((x)&0xf)<<25)
 
326
#define COND(x)         (((x) & 0xf) << 25)
307
327
 
308
328
/* v9: Move (MOVcc and FMOVcc) condition field.  */
309
 
#define MCOND(x,i_or_f) ((((i_or_f)&1)<<18)|(((x)>>11)&(0xf<<14))) /* v9 */
 
329
#define MCOND(x,i_or_f) ((((i_or_f) & 1) << 18) | (((x) >> 11) & (0xf << 14))) /* v9 */
310
330
 
311
331
/* v9: Move register (MOVRcc and FMOVRcc) condition field.  */
312
 
#define RCOND(x)        (((x)&0x7)<<10) /* v9 */
 
332
#define RCOND(x)        (((x) & 0x7) << 10)     /* v9 */
313
333
 
314
 
#define CONDA   (COND(0x8))
315
 
#define CONDCC  (COND(0xd))
316
 
#define CONDCS  (COND(0x5))
317
 
#define CONDE   (COND(0x1))
318
 
#define CONDG   (COND(0xa))
319
 
#define CONDGE  (COND(0xb))
320
 
#define CONDGU  (COND(0xc))
321
 
#define CONDL   (COND(0x3))
322
 
#define CONDLE  (COND(0x2))
323
 
#define CONDLEU (COND(0x4))
324
 
#define CONDN   (COND(0x0))
325
 
#define CONDNE  (COND(0x9))
326
 
#define CONDNEG (COND(0x6))
327
 
#define CONDPOS (COND(0xe))
328
 
#define CONDVC  (COND(0xf))
329
 
#define CONDVS  (COND(0x7))
 
334
#define CONDA   (COND (0x8))
 
335
#define CONDCC  (COND (0xd))
 
336
#define CONDCS  (COND (0x5))
 
337
#define CONDE   (COND (0x1))
 
338
#define CONDG   (COND (0xa))
 
339
#define CONDGE  (COND (0xb))
 
340
#define CONDGU  (COND (0xc))
 
341
#define CONDL   (COND (0x3))
 
342
#define CONDLE  (COND (0x2))
 
343
#define CONDLEU (COND (0x4))
 
344
#define CONDN   (COND (0x0))
 
345
#define CONDNE  (COND (0x9))
 
346
#define CONDNEG (COND (0x6))
 
347
#define CONDPOS (COND (0xe))
 
348
#define CONDVC  (COND (0xf))
 
349
#define CONDVS  (COND (0x7))
330
350
 
331
351
#define CONDNZ  CONDNE
332
352
#define CONDZ   CONDE
333
353
#define CONDGEU CONDCC
334
354
#define CONDLU  CONDCS
335
355
 
336
 
#define FCONDA          (COND(0x8))
337
 
#define FCONDE          (COND(0x9))
338
 
#define FCONDG          (COND(0x6))
339
 
#define FCONDGE         (COND(0xb))
340
 
#define FCONDL          (COND(0x4))
341
 
#define FCONDLE         (COND(0xd))
342
 
#define FCONDLG         (COND(0x2))
343
 
#define FCONDN          (COND(0x0))
344
 
#define FCONDNE         (COND(0x1))
345
 
#define FCONDO          (COND(0xf))
346
 
#define FCONDU          (COND(0x7))
347
 
#define FCONDUE         (COND(0xa))
348
 
#define FCONDUG         (COND(0x5))
349
 
#define FCONDUGE        (COND(0xc))
350
 
#define FCONDUL         (COND(0x3))
351
 
#define FCONDULE        (COND(0xe))
 
356
#define FCONDA          (COND (0x8))
 
357
#define FCONDE          (COND (0x9))
 
358
#define FCONDG          (COND (0x6))
 
359
#define FCONDGE         (COND (0xb))
 
360
#define FCONDL          (COND (0x4))
 
361
#define FCONDLE         (COND (0xd))
 
362
#define FCONDLG         (COND (0x2))
 
363
#define FCONDN          (COND (0x0))
 
364
#define FCONDNE         (COND (0x1))
 
365
#define FCONDO          (COND (0xf))
 
366
#define FCONDU          (COND (0x7))
 
367
#define FCONDUE         (COND (0xa))
 
368
#define FCONDUG         (COND (0x5))
 
369
#define FCONDUGE        (COND (0xc))
 
370
#define FCONDUL         (COND (0x3))
 
371
#define FCONDULE        (COND (0xe))
352
372
 
353
373
#define FCONDNZ FCONDNE
354
374
#define FCONDZ  FCONDE
355
375
 
356
 
#define ICC (0) /* v9 */
357
 
#define XCC (1<<12) /* v9 */
358
 
#define FCC(x)  (((x)&0x3)<<11) /* v9 */
359
 
#define FBFCC(x)        (((x)&0x3)<<20) /* v9 */
 
376
#define ICC             (0)     /* v9 */
 
377
#define XCC             (1 << 12) /* v9 */
 
378
#define FCC(x)          (((x) & 0x3) << 11) /* v9 */
 
379
#define FBFCC(x)        (((x) & 0x3) << 20)     /* v9 */
360
380
 
361
381
/* The order of the opcodes in the table is significant:
362
382
 
363
383
        * The assembler requires that all instances of the same mnemonic must
364
384
        be consecutive. If they aren't, the assembler will bomb at runtime.
365
385
 
366
 
        * The disassembler should not care about the order of the opcodes.
367
 
 
368
 
*/
 
386
        * The disassembler should not care about the order of the opcodes.  */
369
387
 
370
388
/* Entries for commutative arithmetic operations.  */
371
389
/* ??? More entries can make use of this.  */
374
392
{ opcode,       F3(2, op3, 1), F3(~2, ~op3, ~1),                "1,i,d", 0, arch_mask }, \
375
393
{ opcode,       F3(2, op3, 1), F3(~2, ~op3, ~1),                "i,1,d", 0, arch_mask }
376
394
 
377
 
const struct sparc_opcode sparc_opcodes[] = {
 
395
static const struct sparc_opcode sparc_opcodes[] = {
378
396
 
379
397
{ "ld", F3(3, 0x00, 0), F3(~3, ~0x00, ~0),              "[1+2],d", 0, v6 },
380
398
{ "ld", F3(3, 0x00, 0), F3(~3, ~0x00, ~0)|RS2_G0,       "[1],d", 0, v6 }, /* ld [rs1+%g0],d */
896
914
{ "retry",      F3(2, 0x3e, 0)|RD(1), F3(~2, ~0x3e, ~0)|RD(~1)|RS1_G0|SIMM13(~0),       "", 0, v9 },
897
915
{ "saved",      F3(2, 0x31, 0)|RD(0), F3(~2, ~0x31, ~0)|RD(~0)|RS1_G0|SIMM13(~0),       "", 0, v9 },
898
916
{ "restored",   F3(2, 0x31, 0)|RD(1), F3(~2, ~0x31, ~0)|RD(~1)|RS1_G0|SIMM13(~0),       "", 0, v9 },
 
917
{ "allclean",   F3(2, 0x31, 0)|RD(2), F3(~2, ~0x31, ~0)|RD(~2)|RS1_G0|SIMM13(~0),       "", 0, v9 },
 
918
{ "otherw",     F3(2, 0x31, 0)|RD(3), F3(~2, ~0x31, ~0)|RD(~3)|RS1_G0|SIMM13(~0),       "", 0, v9 },
 
919
{ "normalw",    F3(2, 0x31, 0)|RD(4), F3(~2, ~0x31, ~0)|RD(~4)|RS1_G0|SIMM13(~0),       "", 0, v9 },
 
920
{ "invalw",     F3(2, 0x31, 0)|RD(5), F3(~2, ~0x31, ~0)|RD(~5)|RS1_G0|SIMM13(~0),       "", 0, v9 },
899
921
{ "sir",        F3(2, 0x30, 1)|RD(0xf), F3(~2, ~0x30, ~1)|RD(~0xf)|RS1_G0,              "i", 0, v9 },
900
922
 
901
923
{ "flush",      F3(2, 0x3b, 0), F3(~2, ~0x3b, ~0)|ASI(~0),      "1+2", 0, v8 },
1082
1104
{ "wrpr",       F3(2, 0x32, 1),         F3(~2, ~0x32, ~1),              "i,1,!", F_ALIAS, v9 }, /* wrpr i,r1,%priv */
1083
1105
{ "wrpr",       F3(2, 0x32, 1),         F3(~2, ~0x32, ~1)|RS1(~0),      "i,!", 0, v9 },   /* wrpr i,%priv */
1084
1106
 
 
1107
{ "rdhpr",      F3(2, 0x29, 0),         F3(~2, ~0x29, ~0)|SIMM13(~0),   "$,d", 0, v9 },   /* rdhpr %hpriv,r */
 
1108
{ "wrhpr",      F3(2, 0x33, 0),         F3(~2, ~0x33, ~0),              "1,2,%", 0, v9 }, /* wrhpr r1,r2,%hpriv */
 
1109
{ "wrhpr",      F3(2, 0x33, 0),         F3(~2, ~0x33, ~0)|SIMM13(~0),   "1,%", 0, v9 },   /* wrhpr r1,%hpriv */
 
1110
{ "wrhpr",      F3(2, 0x33, 1),         F3(~2, ~0x33, ~1),              "1,i,%", 0, v9 }, /* wrhpr r1,i,%hpriv */
 
1111
{ "wrhpr",      F3(2, 0x33, 1),         F3(~2, ~0x33, ~1),              "i,1,%", F_ALIAS, v9 }, /* wrhpr i,r1,%hpriv */
 
1112
{ "wrhpr",      F3(2, 0x33, 1),         F3(~2, ~0x33, ~1)|RS1(~0),      "i,%", 0, v9 },   /* wrhpr i,%hpriv */
 
1113
 
1085
1114
/* ??? This group seems wrong.  A three operand move?  */
1086
1115
{ "mov",        F3(2, 0x30, 0), F3(~2, ~0x30, ~0)|ASI(~0),              "1,2,m", F_ALIAS, v8 }, /* wr r,r,%asrX */
1087
1116
{ "mov",        F3(2, 0x30, 1), F3(~2, ~0x30, ~1),                      "1,i,m", F_ALIAS, v8 }, /* wr r,i,%asrX */
1473
1502
#define FM_DF 2         /* v9 */
1474
1503
#define FM_QF 3         /* v9 */
1475
1504
 
1476
 
#define fmovicc(opcode, fpsize, cond, flags) /* v9 */ \
1477
 
{ opcode, F3F(2, 0x35, 0x100+fpsize)|MCOND(cond,0),  F3F(~2, ~0x35, ~(0x100+fpsize))|MCOND(~cond,~0),  "z,f,g", flags, v9 }, \
1478
 
{ opcode, F3F(2, 0x35, 0x180+fpsize)|MCOND(cond,0),  F3F(~2, ~0x35, ~(0x180+fpsize))|MCOND(~cond,~0),  "Z,f,g", flags, v9 }
 
1505
#define fmoviccx(opcode, fpsize, args, cond, flags) /* v9 */ \
 
1506
{ opcode, F3F(2, 0x35, 0x100+fpsize)|MCOND(cond,0),  F3F(~2, ~0x35, ~(0x100+fpsize))|MCOND(~cond,~0),  "z," args, flags, v9 }, \
 
1507
{ opcode, F3F(2, 0x35, 0x180+fpsize)|MCOND(cond,0),  F3F(~2, ~0x35, ~(0x180+fpsize))|MCOND(~cond,~0),  "Z," args, flags, v9 }
1479
1508
 
1480
 
#define fmovfcc(opcode, fpsize, fcond, flags) /* v9 */ \
1481
 
{ opcode, F3F(2, 0x35, 0x000+fpsize)|MCOND(fcond,0), F3F(~2, ~0x35, ~(0x000+fpsize))|MCOND(~fcond,~0), "6,f,g", flags, v9 }, \
1482
 
{ opcode, F3F(2, 0x35, 0x040+fpsize)|MCOND(fcond,0), F3F(~2, ~0x35, ~(0x040+fpsize))|MCOND(~fcond,~0), "7,f,g", flags, v9 }, \
1483
 
{ opcode, F3F(2, 0x35, 0x080+fpsize)|MCOND(fcond,0), F3F(~2, ~0x35, ~(0x080+fpsize))|MCOND(~fcond,~0), "8,f,g", flags, v9 }, \
1484
 
{ opcode, F3F(2, 0x35, 0x0c0+fpsize)|MCOND(fcond,0), F3F(~2, ~0x35, ~(0x0c0+fpsize))|MCOND(~fcond,~0), "9,f,g", flags, v9 }
 
1509
#define fmovfccx(opcode, fpsize, args, fcond, flags) /* v9 */ \
 
1510
{ opcode, F3F(2, 0x35, 0x000+fpsize)|MCOND(fcond,0), F3F(~2, ~0x35, ~(0x000+fpsize))|MCOND(~fcond,~0), "6," args, flags, v9 }, \
 
1511
{ opcode, F3F(2, 0x35, 0x040+fpsize)|MCOND(fcond,0), F3F(~2, ~0x35, ~(0x040+fpsize))|MCOND(~fcond,~0), "7," args, flags, v9 }, \
 
1512
{ opcode, F3F(2, 0x35, 0x080+fpsize)|MCOND(fcond,0), F3F(~2, ~0x35, ~(0x080+fpsize))|MCOND(~fcond,~0), "8," args, flags, v9 }, \
 
1513
{ opcode, F3F(2, 0x35, 0x0c0+fpsize)|MCOND(fcond,0), F3F(~2, ~0x35, ~(0x0c0+fpsize))|MCOND(~fcond,~0), "9," args, flags, v9 }
1485
1514
 
1486
1515
/* FIXME: use fmovicc/fmovfcc? */ /* v9 */
1487
 
#define fmovcc(opcode, fpsize, cond, fcond, flags) /* v9 */ \
1488
 
{ opcode, F3F(2, 0x35, 0x100+fpsize)|MCOND(cond,0),  F3F(~2, ~0x35, ~(0x100+fpsize))|MCOND(~cond,~0),  "z,f,g", flags | F_FLOAT, v9 }, \
1489
 
{ opcode, F3F(2, 0x35, 0x000+fpsize)|MCOND(fcond,0), F3F(~2, ~0x35, ~(0x000+fpsize))|MCOND(~fcond,~0), "6,f,g", flags | F_FLOAT, v9 }, \
1490
 
{ opcode, F3F(2, 0x35, 0x180+fpsize)|MCOND(cond,0),  F3F(~2, ~0x35, ~(0x180+fpsize))|MCOND(~cond,~0),  "Z,f,g", flags | F_FLOAT, v9 }, \
1491
 
{ opcode, F3F(2, 0x35, 0x040+fpsize)|MCOND(fcond,0), F3F(~2, ~0x35, ~(0x040+fpsize))|MCOND(~fcond,~0), "7,f,g", flags | F_FLOAT, v9 }, \
1492
 
{ opcode, F3F(2, 0x35, 0x080+fpsize)|MCOND(fcond,0), F3F(~2, ~0x35, ~(0x080+fpsize))|MCOND(~fcond,~0), "8,f,g", flags | F_FLOAT, v9 }, \
1493
 
{ opcode, F3F(2, 0x35, 0x0c0+fpsize)|MCOND(fcond,0), F3F(~2, ~0x35, ~(0x0c0+fpsize))|MCOND(~fcond,~0), "9,f,g", flags | F_FLOAT, v9 }
1494
 
 
1495
 
/* v9 */ fmovcc  ("fmovda",     FM_DF, CONDA, FCONDA, 0),
1496
 
/* v9 */ fmovcc  ("fmovqa",     FM_QF, CONDA, FCONDA, 0),
1497
 
/* v9 */ fmovcc  ("fmovsa",     FM_SF, CONDA, FCONDA, 0),
1498
 
/* v9 */ fmovicc ("fmovdcc",    FM_DF, CONDCC, 0),
1499
 
/* v9 */ fmovicc ("fmovqcc",    FM_QF, CONDCC, 0),
1500
 
/* v9 */ fmovicc ("fmovscc",    FM_SF, CONDCC, 0),
1501
 
/* v9 */ fmovicc ("fmovdcs",    FM_DF, CONDCS, 0),
1502
 
/* v9 */ fmovicc ("fmovqcs",    FM_QF, CONDCS, 0),
1503
 
/* v9 */ fmovicc ("fmovscs",    FM_SF, CONDCS, 0),
1504
 
/* v9 */ fmovcc  ("fmovde",     FM_DF, CONDE, FCONDE, 0),
1505
 
/* v9 */ fmovcc  ("fmovqe",     FM_QF, CONDE, FCONDE, 0),
1506
 
/* v9 */ fmovcc  ("fmovse",     FM_SF, CONDE, FCONDE, 0),
1507
 
/* v9 */ fmovcc  ("fmovdg",     FM_DF, CONDG, FCONDG, 0),
1508
 
/* v9 */ fmovcc  ("fmovqg",     FM_QF, CONDG, FCONDG, 0),
1509
 
/* v9 */ fmovcc  ("fmovsg",     FM_SF, CONDG, FCONDG, 0),
1510
 
/* v9 */ fmovcc  ("fmovdge",    FM_DF, CONDGE, FCONDGE, 0),
1511
 
/* v9 */ fmovcc  ("fmovqge",    FM_QF, CONDGE, FCONDGE, 0),
1512
 
/* v9 */ fmovcc  ("fmovsge",    FM_SF, CONDGE, FCONDGE, 0),
1513
 
/* v9 */ fmovicc ("fmovdgeu",   FM_DF, CONDGEU, F_ALIAS),
1514
 
/* v9 */ fmovicc ("fmovqgeu",   FM_QF, CONDGEU, F_ALIAS),
1515
 
/* v9 */ fmovicc ("fmovsgeu",   FM_SF, CONDGEU, F_ALIAS),
1516
 
/* v9 */ fmovicc ("fmovdgu",    FM_DF, CONDGU, 0),
1517
 
/* v9 */ fmovicc ("fmovqgu",    FM_QF, CONDGU, 0),
1518
 
/* v9 */ fmovicc ("fmovsgu",    FM_SF, CONDGU, 0),
1519
 
/* v9 */ fmovcc  ("fmovdl",     FM_DF, CONDL, FCONDL, 0),
1520
 
/* v9 */ fmovcc  ("fmovql",     FM_QF, CONDL, FCONDL, 0),
1521
 
/* v9 */ fmovcc  ("fmovsl",     FM_SF, CONDL, FCONDL, 0),
1522
 
/* v9 */ fmovcc  ("fmovdle",    FM_DF, CONDLE, FCONDLE, 0),
1523
 
/* v9 */ fmovcc  ("fmovqle",    FM_QF, CONDLE, FCONDLE, 0),
1524
 
/* v9 */ fmovcc  ("fmovsle",    FM_SF, CONDLE, FCONDLE, 0),
1525
 
/* v9 */ fmovicc ("fmovdleu",   FM_DF, CONDLEU, 0),
1526
 
/* v9 */ fmovicc ("fmovqleu",   FM_QF, CONDLEU, 0),
1527
 
/* v9 */ fmovicc ("fmovsleu",   FM_SF, CONDLEU, 0),
1528
 
/* v9 */ fmovfcc ("fmovdlg",    FM_DF, FCONDLG, 0),
1529
 
/* v9 */ fmovfcc ("fmovqlg",    FM_QF, FCONDLG, 0),
1530
 
/* v9 */ fmovfcc ("fmovslg",    FM_SF, FCONDLG, 0),
1531
 
/* v9 */ fmovicc ("fmovdlu",    FM_DF, CONDLU, F_ALIAS),
1532
 
/* v9 */ fmovicc ("fmovqlu",    FM_QF, CONDLU, F_ALIAS),
1533
 
/* v9 */ fmovicc ("fmovslu",    FM_SF, CONDLU, F_ALIAS),
1534
 
/* v9 */ fmovcc  ("fmovdn",     FM_DF, CONDN, FCONDN, 0),
1535
 
/* v9 */ fmovcc  ("fmovqn",     FM_QF, CONDN, FCONDN, 0),
1536
 
/* v9 */ fmovcc  ("fmovsn",     FM_SF, CONDN, FCONDN, 0),
1537
 
/* v9 */ fmovcc  ("fmovdne",    FM_DF, CONDNE, FCONDNE, 0),
1538
 
/* v9 */ fmovcc  ("fmovqne",    FM_QF, CONDNE, FCONDNE, 0),
1539
 
/* v9 */ fmovcc  ("fmovsne",    FM_SF, CONDNE, FCONDNE, 0),
1540
 
/* v9 */ fmovicc ("fmovdneg",   FM_DF, CONDNEG, 0),
1541
 
/* v9 */ fmovicc ("fmovqneg",   FM_QF, CONDNEG, 0),
1542
 
/* v9 */ fmovicc ("fmovsneg",   FM_SF, CONDNEG, 0),
1543
 
/* v9 */ fmovcc  ("fmovdnz",    FM_DF, CONDNZ, FCONDNZ, F_ALIAS),
1544
 
/* v9 */ fmovcc  ("fmovqnz",    FM_QF, CONDNZ, FCONDNZ, F_ALIAS),
1545
 
/* v9 */ fmovcc  ("fmovsnz",    FM_SF, CONDNZ, FCONDNZ, F_ALIAS),
1546
 
/* v9 */ fmovfcc ("fmovdo",     FM_DF, FCONDO, 0),
1547
 
/* v9 */ fmovfcc ("fmovqo",     FM_QF, FCONDO, 0),
1548
 
/* v9 */ fmovfcc ("fmovso",     FM_SF, FCONDO, 0),
1549
 
/* v9 */ fmovicc ("fmovdpos",   FM_DF, CONDPOS, 0),
1550
 
/* v9 */ fmovicc ("fmovqpos",   FM_QF, CONDPOS, 0),
1551
 
/* v9 */ fmovicc ("fmovspos",   FM_SF, CONDPOS, 0),
1552
 
/* v9 */ fmovfcc ("fmovdu",     FM_DF, FCONDU, 0),
1553
 
/* v9 */ fmovfcc ("fmovqu",     FM_QF, FCONDU, 0),
1554
 
/* v9 */ fmovfcc ("fmovsu",     FM_SF, FCONDU, 0),
1555
 
/* v9 */ fmovfcc ("fmovdue",    FM_DF, FCONDUE, 0),
1556
 
/* v9 */ fmovfcc ("fmovque",    FM_QF, FCONDUE, 0),
1557
 
/* v9 */ fmovfcc ("fmovsue",    FM_SF, FCONDUE, 0),
1558
 
/* v9 */ fmovfcc ("fmovdug",    FM_DF, FCONDUG, 0),
1559
 
/* v9 */ fmovfcc ("fmovqug",    FM_QF, FCONDUG, 0),
1560
 
/* v9 */ fmovfcc ("fmovsug",    FM_SF, FCONDUG, 0),
1561
 
/* v9 */ fmovfcc ("fmovduge",   FM_DF, FCONDUGE, 0),
1562
 
/* v9 */ fmovfcc ("fmovquge",   FM_QF, FCONDUGE, 0),
1563
 
/* v9 */ fmovfcc ("fmovsuge",   FM_SF, FCONDUGE, 0),
1564
 
/* v9 */ fmovfcc ("fmovdul",    FM_DF, FCONDUL, 0),
1565
 
/* v9 */ fmovfcc ("fmovqul",    FM_QF, FCONDUL, 0),
1566
 
/* v9 */ fmovfcc ("fmovsul",    FM_SF, FCONDUL, 0),
1567
 
/* v9 */ fmovfcc ("fmovdule",   FM_DF, FCONDULE, 0),
1568
 
/* v9 */ fmovfcc ("fmovqule",   FM_QF, FCONDULE, 0),
1569
 
/* v9 */ fmovfcc ("fmovsule",   FM_SF, FCONDULE, 0),
1570
 
/* v9 */ fmovicc ("fmovdvc",    FM_DF, CONDVC, 0),
1571
 
/* v9 */ fmovicc ("fmovqvc",    FM_QF, CONDVC, 0),
1572
 
/* v9 */ fmovicc ("fmovsvc",    FM_SF, CONDVC, 0),
1573
 
/* v9 */ fmovicc ("fmovdvs",    FM_DF, CONDVS, 0),
1574
 
/* v9 */ fmovicc ("fmovqvs",    FM_QF, CONDVS, 0),
1575
 
/* v9 */ fmovicc ("fmovsvs",    FM_SF, CONDVS, 0),
1576
 
/* v9 */ fmovcc  ("fmovdz",     FM_DF, CONDZ, FCONDZ, F_ALIAS),
1577
 
/* v9 */ fmovcc  ("fmovqz",     FM_QF, CONDZ, FCONDZ, F_ALIAS),
1578
 
/* v9 */ fmovcc  ("fmovsz",     FM_SF, CONDZ, FCONDZ, F_ALIAS),
1579
 
 
 
1516
#define fmovccx(opcode, fpsize, args, cond, fcond, flags) /* v9 */ \
 
1517
{ opcode, F3F(2, 0x35, 0x100+fpsize)|MCOND(cond,0),  F3F(~2, ~0x35, ~(0x100+fpsize))|MCOND(~cond,~0),  "z," args, flags | F_FLOAT, v9 }, \
 
1518
{ opcode, F3F(2, 0x35, 0x000+fpsize)|MCOND(fcond,0), F3F(~2, ~0x35, ~(0x000+fpsize))|MCOND(~fcond,~0), "6," args, flags | F_FLOAT, v9 }, \
 
1519
{ opcode, F3F(2, 0x35, 0x180+fpsize)|MCOND(cond,0),  F3F(~2, ~0x35, ~(0x180+fpsize))|MCOND(~cond,~0),  "Z," args, flags | F_FLOAT, v9 }, \
 
1520
{ opcode, F3F(2, 0x35, 0x040+fpsize)|MCOND(fcond,0), F3F(~2, ~0x35, ~(0x040+fpsize))|MCOND(~fcond,~0), "7," args, flags | F_FLOAT, v9 }, \
 
1521
{ opcode, F3F(2, 0x35, 0x080+fpsize)|MCOND(fcond,0), F3F(~2, ~0x35, ~(0x080+fpsize))|MCOND(~fcond,~0), "8," args, flags | F_FLOAT, v9 }, \
 
1522
{ opcode, F3F(2, 0x35, 0x0c0+fpsize)|MCOND(fcond,0), F3F(~2, ~0x35, ~(0x0c0+fpsize))|MCOND(~fcond,~0), "9," args, flags | F_FLOAT, v9 }
 
1523
 
 
1524
#define fmovicc(suffix, cond, flags) /* v9 */ \
 
1525
fmoviccx("fmovd" suffix, FM_DF, "B,H", cond, flags),            \
 
1526
fmoviccx("fmovq" suffix, FM_QF, "R,J", cond, flags),            \
 
1527
fmoviccx("fmovs" suffix, FM_SF, "f,g", cond, flags)
 
1528
 
 
1529
#define fmovfcc(suffix, fcond, flags) /* v9 */ \
 
1530
fmovfccx("fmovd" suffix, FM_DF, "B,H", fcond, flags),           \
 
1531
fmovfccx("fmovq" suffix, FM_QF, "R,J", fcond, flags),           \
 
1532
fmovfccx("fmovs" suffix, FM_SF, "f,g", fcond, flags)
 
1533
 
 
1534
#define fmovcc(suffix, cond, fcond, flags) /* v9 */ \
 
1535
fmovccx("fmovd" suffix, FM_DF, "B,H", cond, fcond, flags),      \
 
1536
fmovccx("fmovq" suffix, FM_QF, "R,J", cond, fcond, flags),      \
 
1537
fmovccx("fmovs" suffix, FM_SF, "f,g", cond, fcond, flags)
 
1538
 
 
1539
/* v9 */ fmovcc  ("a", CONDA, FCONDA, 0),
 
1540
/* v9 */ fmovicc ("cc", CONDCC, 0),
 
1541
/* v9 */ fmovicc ("cs", CONDCS, 0),
 
1542
/* v9 */ fmovcc  ("e", CONDE, FCONDE, 0),
 
1543
/* v9 */ fmovcc  ("g", CONDG, FCONDG, 0),
 
1544
/* v9 */ fmovcc  ("ge", CONDGE, FCONDGE, 0),
 
1545
/* v9 */ fmovicc ("geu", CONDGEU, F_ALIAS),
 
1546
/* v9 */ fmovicc ("gu", CONDGU, 0),
 
1547
/* v9 */ fmovcc  ("l", CONDL, FCONDL, 0),
 
1548
/* v9 */ fmovcc  ("le", CONDLE, FCONDLE, 0),
 
1549
/* v9 */ fmovicc ("leu", CONDLEU, 0),
 
1550
/* v9 */ fmovfcc ("lg", FCONDLG, 0),
 
1551
/* v9 */ fmovicc ("lu", CONDLU, F_ALIAS),
 
1552
/* v9 */ fmovcc  ("n", CONDN, FCONDN, 0),
 
1553
/* v9 */ fmovcc  ("ne", CONDNE, FCONDNE, 0),
 
1554
/* v9 */ fmovicc ("neg", CONDNEG, 0),
 
1555
/* v9 */ fmovcc  ("nz", CONDNZ, FCONDNZ, F_ALIAS),
 
1556
/* v9 */ fmovfcc ("o", FCONDO, 0),
 
1557
/* v9 */ fmovicc ("pos", CONDPOS, 0),
 
1558
/* v9 */ fmovfcc ("u", FCONDU, 0),
 
1559
/* v9 */ fmovfcc ("ue", FCONDUE, 0),
 
1560
/* v9 */ fmovfcc ("ug", FCONDUG, 0),
 
1561
/* v9 */ fmovfcc ("uge", FCONDUGE, 0),
 
1562
/* v9 */ fmovfcc ("ul", FCONDUL, 0),
 
1563
/* v9 */ fmovfcc ("ule", FCONDULE, 0),
 
1564
/* v9 */ fmovicc ("vc", CONDVC, 0),
 
1565
/* v9 */ fmovicc ("vs", CONDVS, 0),
 
1566
/* v9 */ fmovcc  ("z", CONDZ, FCONDZ, F_ALIAS),
 
1567
 
 
1568
#undef fmoviccx /* v9 */
 
1569
#undef fmovfccx /* v9 */
 
1570
#undef fmovccx /* v9 */
1580
1571
#undef fmovicc /* v9 */
1581
1572
#undef fmovfcc /* v9 */
1582
1573
#undef fmovcc /* v9 */
1586
1577
 
1587
1578
/* Coprocessor branches.  */
1588
1579
#define CBR(opcode, mask, lose, flags, arch) \
1589
 
 { opcode, (mask), ANNUL|(lose), "l",    flags|F_DELAYED, arch }, \
1590
 
 { opcode, (mask)|ANNUL, (lose), ",a l", flags|F_DELAYED, arch }
 
1580
 { opcode, (mask), ANNUL | (lose), "l",    flags | F_DELAYED, arch }, \
 
1581
 { opcode, (mask) | ANNUL, (lose), ",a l", flags | F_DELAYED, arch }
1591
1582
 
1592
1583
/* Floating point branches.  */
1593
1584
#define FBR(opcode, mask, lose, flags) \
1594
 
 { opcode, (mask), ANNUL|(lose), "l",    flags|F_DELAYED|F_FBR, v6 }, \
1595
 
 { opcode, (mask)|ANNUL, (lose), ",a l", flags|F_DELAYED|F_FBR, v6 }
 
1585
 { opcode, (mask), ANNUL | (lose), "l",    flags | F_DELAYED | F_FBR, v6 }, \
 
1586
 { opcode, (mask) | ANNUL, (lose), ",a l", flags | F_DELAYED | F_FBR, v6 }
1596
1587
 
1597
1588
/* V9 extended floating point branches.  */
1598
1589
#define FBRX(opcode, mask, lose, flags) /* v9 */ \
1725
1716
{ "fstoi",      F3F(2, 0x34, 0x0d1), F3F(~2, ~0x34, ~0x0d1)|RS1_G0, "f,g", F_FLOAT, v6 },
1726
1717
{ "fqtoi",      F3F(2, 0x34, 0x0d3), F3F(~2, ~0x34, ~0x0d3)|RS1_G0, "R,g", F_FLOAT, v8 },
1727
1718
 
1728
 
{ "fdtox",      F3F(2, 0x34, 0x082), F3F(~2, ~0x34, ~0x082)|RS1_G0, "B,g", F_FLOAT, v9 },
1729
 
{ "fstox",      F3F(2, 0x34, 0x081), F3F(~2, ~0x34, ~0x081)|RS1_G0, "f,g", F_FLOAT, v9 },
1730
 
{ "fqtox",      F3F(2, 0x34, 0x083), F3F(~2, ~0x34, ~0x083)|RS1_G0, "R,g", F_FLOAT, v9 },
 
1719
{ "fdtox",      F3F(2, 0x34, 0x082), F3F(~2, ~0x34, ~0x082)|RS1_G0, "B,H", F_FLOAT, v9 },
 
1720
{ "fstox",      F3F(2, 0x34, 0x081), F3F(~2, ~0x34, ~0x081)|RS1_G0, "f,H", F_FLOAT, v9 },
 
1721
{ "fqtox",      F3F(2, 0x34, 0x083), F3F(~2, ~0x34, ~0x083)|RS1_G0, "R,H", F_FLOAT, v9 },
1731
1722
 
1732
1723
{ "fitod",      F3F(2, 0x34, 0x0c8), F3F(~2, ~0x34, ~0x0c8)|RS1_G0, "f,H", F_FLOAT, v6 },
1733
1724
{ "fitos",      F3F(2, 0x34, 0x0c4), F3F(~2, ~0x34, ~0x0c4)|RS1_G0, "f,g", F_FLOAT, v6 },
1734
1725
{ "fitoq",      F3F(2, 0x34, 0x0cc), F3F(~2, ~0x34, ~0x0cc)|RS1_G0, "f,J", F_FLOAT, v8 },
1735
1726
 
1736
 
{ "fxtod",      F3F(2, 0x34, 0x088), F3F(~2, ~0x34, ~0x088)|RS1_G0, "f,H", F_FLOAT, v9 },
1737
 
{ "fxtos",      F3F(2, 0x34, 0x084), F3F(~2, ~0x34, ~0x084)|RS1_G0, "f,g", F_FLOAT, v9 },
1738
 
{ "fxtoq",      F3F(2, 0x34, 0x08c), F3F(~2, ~0x34, ~0x08c)|RS1_G0, "f,J", F_FLOAT, v9 },
 
1727
{ "fxtod",      F3F(2, 0x34, 0x088), F3F(~2, ~0x34, ~0x088)|RS1_G0, "B,H", F_FLOAT, v9 },
 
1728
{ "fxtos",      F3F(2, 0x34, 0x084), F3F(~2, ~0x34, ~0x084)|RS1_G0, "B,g", F_FLOAT, v9 },
 
1729
{ "fxtoq",      F3F(2, 0x34, 0x08c), F3F(~2, ~0x34, ~0x08c)|RS1_G0, "B,J", F_FLOAT, v9 },
1739
1730
 
1740
1731
{ "fdtoq",      F3F(2, 0x34, 0x0ce), F3F(~2, ~0x34, ~0x0ce)|RS1_G0, "B,J", F_FLOAT, v8 },
1741
1732
{ "fdtos",      F3F(2, 0x34, 0x0c6), F3F(~2, ~0x34, ~0x0c6)|RS1_G0, "B,g", F_FLOAT, v6 },
2055
2046
 
2056
2047
};
2057
2048
 
2058
 
const int sparc_num_opcodes = ((sizeof sparc_opcodes)/(sizeof sparc_opcodes[0]));
 
2049
static const int sparc_num_opcodes = ((sizeof sparc_opcodes)/(sizeof sparc_opcodes[0]));
2059
2050
 
2060
2051
/* Utilities for argument parsing.  */
2061
2052
 
2065
2056
  const char *name;
2066
2057
} arg;
2067
2058
 
2068
 
/* Look up NAME in TABLE.  */
2069
 
 
2070
 
static int lookup_name PARAMS ((const arg *, const char *));
2071
 
static const char *lookup_value PARAMS ((const arg *, int));
2072
 
 
2073
 
static int
2074
 
lookup_name (table, name)
2075
 
     const arg *table;
2076
 
     const char *name;
2077
 
{
2078
 
  const arg *p;
2079
 
 
2080
 
  for (p = table; p->name; ++p)
2081
 
    if (strcmp (name, p->name) == 0)
2082
 
      return p->value;
2083
 
 
2084
 
  return -1;
2085
 
}
2086
 
 
2087
2059
/* Look up VALUE in TABLE.  */
2088
2060
 
2089
2061
static const char *
2090
 
lookup_value (table, value)
2091
 
     const arg *table;
2092
 
     int value;
 
2062
lookup_value (const arg *table, int value)
2093
2063
{
2094
2064
  const arg *p;
2095
2065
 
2097
2067
    if (value == p->value)
2098
2068
      return p->name;
2099
2069
 
2100
 
  return (char *) 0;
 
2070
  return NULL;
2101
2071
}
2102
2072
 
2103
2073
/* Handle ASI's.  */
2218
2188
  { 0, 0 }
2219
2189
};
2220
2190
 
2221
 
/* Return the value for membar arg NAME, or -1 if not found.  */
2222
 
 
2223
 
int
2224
 
sparc_encode_membar (name)
2225
 
     const char *name;
2226
 
{
2227
 
  return lookup_name (membar_table, name);
2228
 
}
2229
 
 
2230
2191
/* Return the name for membar value VALUE or NULL if not found.  */
2231
2192
 
2232
 
const char *
2233
 
sparc_decode_membar (value)
2234
 
     int value;
 
2193
static const char *
 
2194
sparc_decode_membar (int value)
2235
2195
{
2236
2196
  return lookup_value (membar_table, value);
2237
2197
}
2249
2209
  { 0, 0 }
2250
2210
};
2251
2211
 
2252
 
/* Return the value for prefetch arg NAME, or -1 if not found.  */
2253
 
 
2254
 
int
2255
 
sparc_encode_prefetch (name)
2256
 
     const char *name;
2257
 
{
2258
 
  return lookup_name (prefetch_table, name);
2259
 
}
2260
 
 
2261
2212
/* Return the name for prefetch value VALUE or NULL if not found.  */
2262
2213
 
2263
 
const char *
2264
 
sparc_decode_prefetch (value)
2265
 
     int value;
 
2214
static const char *
 
2215
sparc_decode_prefetch (int value)
2266
2216
{
2267
2217
  return lookup_value (prefetch_table, value);
2268
2218
}
2281
2231
  { 0, 0 }
2282
2232
};
2283
2233
 
2284
 
/* Return the value for sparclet cpreg arg NAME, or -1 if not found.  */
2285
 
 
2286
 
int
2287
 
sparc_encode_sparclet_cpreg (name)
2288
 
     const char *name;
2289
 
{
2290
 
  return lookup_name (sparclet_cpreg_table, name);
2291
 
}
2292
 
 
2293
2234
/* Return the name for sparclet cpreg value VALUE or NULL if not found.  */
2294
2235
 
2295
 
const char *
2296
 
sparc_decode_sparclet_cpreg (value)
2297
 
     int value;
 
2236
static const char *
 
2237
sparc_decode_sparclet_cpreg (int value)
2298
2238
{
2299
2239
  return lookup_value (sparclet_cpreg_table, value);
2300
2240
}
2301
2241
 
2302
2242
#undef MASK_V9
2303
2243
 
 
2244
/* opcodes/sparc-dis.c */
 
2245
 
 
2246
/* Print SPARC instructions.
 
2247
   Copyright 1989, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
 
2248
   2000, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
 
2249
 
 
2250
   This program is free software; you can redistribute it and/or modify
 
2251
   it under the terms of the GNU General Public License as published by
 
2252
   the Free Software Foundation; either version 2 of the License, or
 
2253
   (at your option) any later version.
 
2254
 
 
2255
   This program is distributed in the hope that it will be useful,
 
2256
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
2257
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
2258
   GNU General Public License for more details.
 
2259
 
 
2260
   You should have received a copy of the GNU General Public License
 
2261
   along with this program; if not, write to the Free Software
 
2262
   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
 
2263
   MA 02110-1301, USA.  */
 
2264
 
2304
2265
/* Bitmask of v9 architectures.  */
2305
2266
#define MASK_V9 ((1 << SPARC_OPCODE_ARCH_V9) \
2306
2267
                 | (1 << SPARC_OPCODE_ARCH_V9A) \
2311
2272
#define V9_P(insn) (((insn)->architecture & MASK_V9) != 0)
2312
2273
 
2313
2274
/* The sorted opcode table.  */
2314
 
static const struct sparc_opcode **sorted_opcodes;
 
2275
static const sparc_opcode **sorted_opcodes;
2315
2276
 
2316
2277
/* For faster lookup, after insns are sorted they are hashed.  */
2317
2278
/* ??? I think there is room for even more improvement.  */
2323
2284
static const int opcode_bits[4] = { 0x01c00000, 0x0, 0x01f80000, 0x01f80000 };
2324
2285
#define HASH_INSN(INSN) \
2325
2286
  ((((INSN) >> 24) & 0xc0) | (((INSN) & opcode_bits[((INSN) >> 30) & 3]) >> 19))
2326
 
struct opcode_hash {
2327
 
  struct opcode_hash *next;
2328
 
  const struct sparc_opcode *opcode;
2329
 
};
2330
 
static struct opcode_hash *opcode_hash_table[HASH_SIZE];
 
2287
typedef struct sparc_opcode_hash
 
2288
{
 
2289
  struct sparc_opcode_hash *next;
 
2290
  const sparc_opcode *opcode;
 
2291
} sparc_opcode_hash;
2331
2292
 
2332
 
static void build_hash_table
2333
 
  PARAMS ((const struct sparc_opcode **, struct opcode_hash **, int));
2334
 
static int is_delayed_branch PARAMS ((unsigned long));
2335
 
static int compare_opcodes PARAMS ((const void *, const void *));
2336
 
static int compute_arch_mask PARAMS ((unsigned long));
 
2293
static sparc_opcode_hash *opcode_hash_table[HASH_SIZE];
2337
2294
 
2338
2295
/* Sign-extend a value which is N bits long.  */
2339
2296
#define SEX(value, bits) \
2365
2322
{
2366
2323
  "tpc", "tnpc", "tstate", "tt", "tick", "tba", "pstate", "tl",
2367
2324
  "pil", "cwp", "cansave", "canrestore", "cleanwin", "otherwin",
2368
 
  "wstate", "fq"
 
2325
  "wstate", "fq", "gl"
2369
2326
  /* "ver" - special cased */
2370
2327
};
2371
2328
 
2372
2329
/* These are ordered according to there register number in
 
2330
   rdhpr and wrhpr insns.  */
 
2331
static const char * const v9_hpriv_reg_names[] =
 
2332
{
 
2333
  "hpstate", "htstate", "resv2", "hintp", "resv4", "htba", "hver",
 
2334
  "resv7", "resv8", "resv9", "resv10", "resv11", "resv12", "resv13",
 
2335
  "resv14", "resv15", "resv16", "resv17", "resv18", "resv19", "resv20",
 
2336
  "resv21", "resv22", "resv23", "resv24", "resv25", "resv26", "resv27",
 
2337
  "resv28", "resv29", "resv30", "hstick_cmpr"
 
2338
};
 
2339
 
 
2340
/* These are ordered according to there register number in
2373
2341
   rd and wr insns (-16).  */
2374
2342
static const char * const v9a_asr_reg_names[] =
2375
2343
{
2380
2348
/* Macros used to extract instruction fields.  Not all fields have
2381
2349
   macros defined here, only those which are actually used.  */
2382
2350
 
2383
 
#define X_RD(i) (((i) >> 25) & 0x1f)
2384
 
#define X_RS1(i) (((i) >> 14) & 0x1f)
2385
 
#define X_LDST_I(i) (((i) >> 13) & 1)
2386
 
#define X_ASI(i) (((i) >> 5) & 0xff)
2387
 
#define X_RS2(i) (((i) >> 0) & 0x1f)
2388
 
#define X_IMM(i,n) (((i) >> 0) & ((1 << (n)) - 1))
2389
 
#define X_SIMM(i,n) SEX (X_IMM ((i), (n)), (n))
2390
 
#define X_DISP22(i) (((i) >> 0) & 0x3fffff)
2391
 
#define X_IMM22(i) X_DISP22 (i)
2392
 
#define X_DISP30(i) (((i) >> 0) & 0x3fffffff)
 
2351
#define X_RD(i)      (((i) >> 25) & 0x1f)
 
2352
#define X_RS1(i)     (((i) >> 14) & 0x1f)
 
2353
#define X_LDST_I(i)  (((i) >> 13) & 1)
 
2354
#define X_ASI(i)     (((i) >> 5) & 0xff)
 
2355
#define X_RS2(i)     (((i) >> 0) & 0x1f)
 
2356
#define X_IMM(i,n)   (((i) >> 0) & ((1 << (n)) - 1))
 
2357
#define X_SIMM(i,n)  SEX (X_IMM ((i), (n)), (n))
 
2358
#define X_DISP22(i)  (((i) >> 0) & 0x3fffff)
 
2359
#define X_IMM22(i)   X_DISP22 (i)
 
2360
#define X_DISP30(i)  (((i) >> 0) & 0x3fffffff)
2393
2361
 
2394
2362
/* These are for v9.  */
2395
 
#define X_DISP16(i) (((((i) >> 20) & 3) << 14) | (((i) >> 0) & 0x3fff))
2396
 
#define X_DISP19(i) (((i) >> 0) & 0x7ffff)
2397
 
#define X_MEMBAR(i) ((i) & 0x7f)
 
2363
#define X_DISP16(i)  (((((i) >> 20) & 3) << 14) | (((i) >> 0) & 0x3fff))
 
2364
#define X_DISP19(i)  (((i) >> 0) & 0x7ffff)
 
2365
#define X_MEMBAR(i)  ((i) & 0x7f)
2398
2366
 
2399
2367
/* Here is the union which was used to extract instruction fields
2400
2368
   before the shift and mask macros were written.
2452
2420
           unsigned int adisp30:30;
2453
2421
           #define      disp30  call.adisp30
2454
2422
         } call;
2455
 
     };
2456
 
 
2457
 
   */
 
2423
     };  */
2458
2424
 
2459
2425
/* Nonzero if INSN is the opcode for a delayed branch.  */
 
2426
 
2460
2427
static int
2461
 
is_delayed_branch (insn)
2462
 
     unsigned long insn;
 
2428
is_delayed_branch (unsigned long insn)
2463
2429
{
2464
 
  struct opcode_hash *op;
 
2430
  sparc_opcode_hash *op;
2465
2431
 
2466
2432
  for (op = opcode_hash_table[HASH_INSN (insn)]; op; op = op->next)
2467
2433
    {
2468
 
      const struct sparc_opcode *opcode = op->opcode;
 
2434
      const sparc_opcode *opcode = op->opcode;
 
2435
 
2469
2436
      if ((opcode->match & insn) == opcode->match
2470
2437
          && (opcode->lose & insn) == 0)
2471
 
        return (opcode->flags & F_DELAYED);
 
2438
        return opcode->flags & F_DELAYED;
2472
2439
    }
2473
2440
  return 0;
2474
2441
}
2479
2446
   to compare_opcodes.  */
2480
2447
static unsigned int current_arch_mask;
2481
2448
 
 
2449
/* Given BFD mach number, return a mask of SPARC_OPCODE_ARCH_FOO values.  */
 
2450
 
 
2451
static int
 
2452
compute_arch_mask (unsigned long mach)
 
2453
{
 
2454
  switch (mach)
 
2455
    {
 
2456
    case 0 :
 
2457
    case bfd_mach_sparc :
 
2458
      return SPARC_OPCODE_ARCH_MASK (SPARC_OPCODE_ARCH_V8);
 
2459
    case bfd_mach_sparc_sparclet :
 
2460
      return SPARC_OPCODE_ARCH_MASK (SPARC_OPCODE_ARCH_SPARCLET);
 
2461
    case bfd_mach_sparc_sparclite :
 
2462
    case bfd_mach_sparc_sparclite_le :
 
2463
      /* sparclites insns are recognized by default (because that's how
 
2464
         they've always been treated, for better or worse).  Kludge this by
 
2465
         indicating generic v8 is also selected.  */
 
2466
      return (SPARC_OPCODE_ARCH_MASK (SPARC_OPCODE_ARCH_SPARCLITE)
 
2467
              | SPARC_OPCODE_ARCH_MASK (SPARC_OPCODE_ARCH_V8));
 
2468
    case bfd_mach_sparc_v8plus :
 
2469
    case bfd_mach_sparc_v9 :
 
2470
      return SPARC_OPCODE_ARCH_MASK (SPARC_OPCODE_ARCH_V9);
 
2471
    case bfd_mach_sparc_v8plusa :
 
2472
    case bfd_mach_sparc_v9a :
 
2473
      return SPARC_OPCODE_ARCH_MASK (SPARC_OPCODE_ARCH_V9A);
 
2474
    case bfd_mach_sparc_v8plusb :
 
2475
    case bfd_mach_sparc_v9b :
 
2476
      return SPARC_OPCODE_ARCH_MASK (SPARC_OPCODE_ARCH_V9B);
 
2477
    }
 
2478
  abort ();
 
2479
}
 
2480
 
 
2481
/* Compare opcodes A and B.  */
 
2482
 
 
2483
static int
 
2484
compare_opcodes (const void * a, const void * b)
 
2485
{
 
2486
  sparc_opcode *op0 = * (sparc_opcode **) a;
 
2487
  sparc_opcode *op1 = * (sparc_opcode **) b;
 
2488
  unsigned long int match0 = op0->match, match1 = op1->match;
 
2489
  unsigned long int lose0 = op0->lose, lose1 = op1->lose;
 
2490
  register unsigned int i;
 
2491
 
 
2492
  /* If one (and only one) insn isn't supported by the current architecture,
 
2493
     prefer the one that is.  If neither are supported, but they're both for
 
2494
     the same architecture, continue processing.  Otherwise (both unsupported
 
2495
     and for different architectures), prefer lower numbered arch's (fudged
 
2496
     by comparing the bitmasks).  */
 
2497
  if (op0->architecture & current_arch_mask)
 
2498
    {
 
2499
      if (! (op1->architecture & current_arch_mask))
 
2500
        return -1;
 
2501
    }
 
2502
  else
 
2503
    {
 
2504
      if (op1->architecture & current_arch_mask)
 
2505
        return 1;
 
2506
      else if (op0->architecture != op1->architecture)
 
2507
        return op0->architecture - op1->architecture;
 
2508
    }
 
2509
 
 
2510
  /* If a bit is set in both match and lose, there is something
 
2511
     wrong with the opcode table.  */
 
2512
  if (match0 & lose0)
 
2513
    {
 
2514
      fprintf
 
2515
        (stderr,
 
2516
         /* xgettext:c-format */
 
2517
         _("Internal error:  bad sparc-opcode.h: \"%s\", %#.8lx, %#.8lx\n"),
 
2518
         op0->name, match0, lose0);
 
2519
      op0->lose &= ~op0->match;
 
2520
      lose0 = op0->lose;
 
2521
    }
 
2522
 
 
2523
  if (match1 & lose1)
 
2524
    {
 
2525
      fprintf
 
2526
        (stderr,
 
2527
         /* xgettext:c-format */
 
2528
         _("Internal error: bad sparc-opcode.h: \"%s\", %#.8lx, %#.8lx\n"),
 
2529
         op1->name, match1, lose1);
 
2530
      op1->lose &= ~op1->match;
 
2531
      lose1 = op1->lose;
 
2532
    }
 
2533
 
 
2534
  /* Because the bits that are variable in one opcode are constant in
 
2535
     another, it is important to order the opcodes in the right order.  */
 
2536
  for (i = 0; i < 32; ++i)
 
2537
    {
 
2538
      unsigned long int x = 1 << i;
 
2539
      int x0 = (match0 & x) != 0;
 
2540
      int x1 = (match1 & x) != 0;
 
2541
 
 
2542
      if (x0 != x1)
 
2543
        return x1 - x0;
 
2544
    }
 
2545
 
 
2546
  for (i = 0; i < 32; ++i)
 
2547
    {
 
2548
      unsigned long int x = 1 << i;
 
2549
      int x0 = (lose0 & x) != 0;
 
2550
      int x1 = (lose1 & x) != 0;
 
2551
 
 
2552
      if (x0 != x1)
 
2553
        return x1 - x0;
 
2554
    }
 
2555
 
 
2556
  /* They are functionally equal.  So as long as the opcode table is
 
2557
     valid, we can put whichever one first we want, on aesthetic grounds.  */
 
2558
 
 
2559
  /* Our first aesthetic ground is that aliases defer to real insns.  */
 
2560
  {
 
2561
    int alias_diff = (op0->flags & F_ALIAS) - (op1->flags & F_ALIAS);
 
2562
 
 
2563
    if (alias_diff != 0)
 
2564
      /* Put the one that isn't an alias first.  */
 
2565
      return alias_diff;
 
2566
  }
 
2567
 
 
2568
  /* Except for aliases, two "identical" instructions had
 
2569
     better have the same opcode.  This is a sanity check on the table.  */
 
2570
  i = strcmp (op0->name, op1->name);
 
2571
  if (i)
 
2572
    {
 
2573
      if (op0->flags & F_ALIAS) /* If they're both aliases, be arbitrary.  */
 
2574
        return i;
 
2575
      else
 
2576
        fprintf (stderr,
 
2577
                 /* xgettext:c-format */
 
2578
                 _("Internal error: bad sparc-opcode.h: \"%s\" == \"%s\"\n"),
 
2579
                 op0->name, op1->name);
 
2580
    }
 
2581
 
 
2582
  /* Fewer arguments are preferred.  */
 
2583
  {
 
2584
    int length_diff = strlen (op0->args) - strlen (op1->args);
 
2585
 
 
2586
    if (length_diff != 0)
 
2587
      /* Put the one with fewer arguments first.  */
 
2588
      return length_diff;
 
2589
  }
 
2590
 
 
2591
  /* Put 1+i before i+1.  */
 
2592
  {
 
2593
    char *p0 = (char *) strchr (op0->args, '+');
 
2594
    char *p1 = (char *) strchr (op1->args, '+');
 
2595
 
 
2596
    if (p0 && p1)
 
2597
      {
 
2598
        /* There is a plus in both operands.  Note that a plus
 
2599
           sign cannot be the first character in args,
 
2600
           so the following [-1]'s are valid.  */
 
2601
        if (p0[-1] == 'i' && p1[1] == 'i')
 
2602
          /* op0 is i+1 and op1 is 1+i, so op1 goes first.  */
 
2603
          return 1;
 
2604
        if (p0[1] == 'i' && p1[-1] == 'i')
 
2605
          /* op0 is 1+i and op1 is i+1, so op0 goes first.  */
 
2606
          return -1;
 
2607
      }
 
2608
  }
 
2609
 
 
2610
  /* Put 1,i before i,1.  */
 
2611
  {
 
2612
    int i0 = strncmp (op0->args, "i,1", 3) == 0;
 
2613
    int i1 = strncmp (op1->args, "i,1", 3) == 0;
 
2614
 
 
2615
    if (i0 ^ i1)
 
2616
      return i0 - i1;
 
2617
  }
 
2618
 
 
2619
  /* They are, as far as we can tell, identical.
 
2620
     Since qsort may have rearranged the table partially, there is
 
2621
     no way to tell which one was first in the opcode table as
 
2622
     written, so just say there are equal.  */
 
2623
  /* ??? This is no longer true now that we sort a vector of pointers,
 
2624
     not the table itself.  */
 
2625
  return 0;
 
2626
}
 
2627
 
 
2628
/* Build a hash table from the opcode table.
 
2629
   OPCODE_TABLE is a sorted list of pointers into the opcode table.  */
 
2630
 
 
2631
static void
 
2632
build_hash_table (const sparc_opcode **opcode_table,
 
2633
                  sparc_opcode_hash **hash_table,
 
2634
                  int num_opcodes)
 
2635
{
 
2636
  int i;
 
2637
  int hash_count[HASH_SIZE];
 
2638
  static sparc_opcode_hash *hash_buf = NULL;
 
2639
 
 
2640
  /* Start at the end of the table and work backwards so that each
 
2641
     chain is sorted.  */
 
2642
 
 
2643
  memset (hash_table, 0, HASH_SIZE * sizeof (hash_table[0]));
 
2644
  memset (hash_count, 0, HASH_SIZE * sizeof (hash_count[0]));
 
2645
  if (hash_buf != NULL)
 
2646
    free (hash_buf);
 
2647
  hash_buf = malloc (sizeof (* hash_buf) * num_opcodes);
 
2648
  for (i = num_opcodes - 1; i >= 0; --i)
 
2649
    {
 
2650
      int hash = HASH_INSN (opcode_table[i]->match);
 
2651
      sparc_opcode_hash *h = &hash_buf[i];
 
2652
 
 
2653
      h->next = hash_table[hash];
 
2654
      h->opcode = opcode_table[i];
 
2655
      hash_table[hash] = h;
 
2656
      ++hash_count[hash];
 
2657
    }
 
2658
 
 
2659
#if 0 /* for debugging */
 
2660
  {
 
2661
    int min_count = num_opcodes, max_count = 0;
 
2662
    int total;
 
2663
 
 
2664
    for (i = 0; i < HASH_SIZE; ++i)
 
2665
      {
 
2666
        if (hash_count[i] < min_count)
 
2667
          min_count = hash_count[i];
 
2668
        if (hash_count[i] > max_count)
 
2669
          max_count = hash_count[i];
 
2670
        total += hash_count[i];
 
2671
      }
 
2672
 
 
2673
    printf ("Opcode hash table stats: min %d, max %d, ave %f\n",
 
2674
            min_count, max_count, (double) total / HASH_SIZE);
 
2675
  }
 
2676
#endif
 
2677
}
 
2678
 
2482
2679
/* Print one instruction from MEMADDR on INFO->STREAM.
2483
2680
 
2484
2681
   We suffix the instruction with a comment that gives the absolute
2488
2685
   on that register.  */
2489
2686
 
2490
2687
int
2491
 
print_insn_sparc (memaddr, info)
2492
 
     bfd_vma memaddr;
2493
 
     disassemble_info *info;
 
2688
print_insn_sparc (bfd_vma memaddr, disassemble_info *info)
2494
2689
{
2495
2690
  FILE *stream = info->stream;
2496
2691
  bfd_byte buffer[4];
2497
2692
  unsigned long insn;
2498
 
  register struct opcode_hash *op;
 
2693
  sparc_opcode_hash *op;
2499
2694
  /* Nonzero of opcode table has been initialized.  */
2500
2695
  static int opcodes_initialized = 0;
2501
2696
  /* bfd mach number of last call.  */
2502
2697
  static unsigned long current_mach = 0;
2503
 
  bfd_vma (*getword) PARAMS ((const unsigned char *));
 
2698
  bfd_vma (*getword) (const unsigned char *);
2504
2699
 
2505
2700
  if (!opcodes_initialized
2506
2701
      || info->mach != current_mach)
2510
2705
      current_arch_mask = compute_arch_mask (info->mach);
2511
2706
 
2512
2707
      if (!opcodes_initialized)
2513
 
        sorted_opcodes = (const struct sparc_opcode **)
2514
 
            malloc (sparc_num_opcodes * sizeof (struct sparc_opcode *));
 
2708
        sorted_opcodes =
 
2709
          malloc (sparc_num_opcodes * sizeof (sparc_opcode *));
2515
2710
      /* Reset the sorted table so we can resort it.  */
2516
2711
      for (i = 0; i < sparc_num_opcodes; ++i)
2517
2712
        sorted_opcodes[i] = &sparc_opcodes[i];
2526
2721
  {
2527
2722
    int status =
2528
2723
      (*info->read_memory_func) (memaddr, buffer, sizeof (buffer), info);
 
2724
 
2529
2725
    if (status != 0)
2530
2726
      {
2531
2727
        (*info->memory_error_func) (status, memaddr, info);
2534
2730
  }
2535
2731
 
2536
2732
  /* On SPARClite variants such as DANlite (sparc86x), instructions
2537
 
     are always big-endian even when the machine is in little-endian mode. */
 
2733
     are always big-endian even when the machine is in little-endian mode.  */
2538
2734
  if (info->endian == BFD_ENDIAN_BIG || info->mach == bfd_mach_sparc_sparclite)
2539
2735
    getword = bfd_getb32;
2540
2736
  else
2542
2738
 
2543
2739
  insn = getword (buffer);
2544
2740
 
2545
 
  info->insn_info_valid = 1;                    /* We do return this info */
2546
 
  info->insn_type = dis_nonbranch;              /* Assume non branch insn */
2547
 
  info->branch_delay_insns = 0;                 /* Assume no delay */
2548
 
  info->target = 0;                             /* Assume no target known */
 
2741
  info->insn_info_valid = 1;                    /* We do return this info.  */
 
2742
  info->insn_type = dis_nonbranch;              /* Assume non branch insn.  */
 
2743
  info->branch_delay_insns = 0;                 /* Assume no delay.  */
 
2744
  info->target = 0;                             /* Assume no target known.  */
2549
2745
 
2550
2746
  for (op = opcode_hash_table[HASH_INSN (insn)]; op; op = op->next)
2551
2747
    {
2552
 
      const struct sparc_opcode *opcode = op->opcode;
 
2748
      const sparc_opcode *opcode = op->opcode;
2553
2749
 
2554
2750
      /* If the insn isn't supported by the current architecture, skip it.  */
2555
2751
      if (! (opcode->architecture & current_arch_mask))
2589
2785
          (*info->fprintf_func) (stream, opcode->name);
2590
2786
 
2591
2787
          {
2592
 
            register const char *s;
 
2788
            const char *s;
2593
2789
 
2594
2790
            if (opcode->args[0] != ',')
2595
2791
              (*info->fprintf_func) (stream, " ");
 
2792
 
2596
2793
            for (s = opcode->args; *s != '\0'; ++s)
2597
2794
              {
2598
2795
                while (*s == ',')
2599
2796
                  {
2600
2797
                    (*info->fprintf_func) (stream, ",");
2601
2798
                    ++s;
2602
 
                    switch (*s) {
2603
 
                    case 'a':
2604
 
                      (*info->fprintf_func) (stream, "a");
2605
 
                      is_annulled = 1;
2606
 
                      ++s;
2607
 
                      continue;
2608
 
                    case 'N':
2609
 
                      (*info->fprintf_func) (stream, "pn");
2610
 
                      ++s;
2611
 
                      continue;
2612
 
 
2613
 
                    case 'T':
2614
 
                      (*info->fprintf_func) (stream, "pt");
2615
 
                      ++s;
2616
 
                      continue;
2617
 
 
2618
 
                    default:
2619
 
                      break;
2620
 
                    }           /* switch on arg */
2621
 
                  }             /* while there are comma started args */
 
2799
                    switch (*s)
 
2800
                      {
 
2801
                      case 'a':
 
2802
                        (*info->fprintf_func) (stream, "a");
 
2803
                        is_annulled = 1;
 
2804
                        ++s;
 
2805
                        continue;
 
2806
                      case 'N':
 
2807
                        (*info->fprintf_func) (stream, "pn");
 
2808
                        ++s;
 
2809
                        continue;
 
2810
 
 
2811
                      case 'T':
 
2812
                        (*info->fprintf_func) (stream, "pt");
 
2813
                        ++s;
 
2814
                        continue;
 
2815
 
 
2816
                      default:
 
2817
                        break;
 
2818
                      }
 
2819
                  }
2622
2820
 
2623
2821
                (*info->fprintf_func) (stream, " ");
2624
2822
 
2626
2824
                  {
2627
2825
                  case '+':
2628
2826
                    found_plus = 1;
 
2827
                    /* Fall through.  */
2629
2828
 
2630
 
                    /* note fall-through */
2631
2829
                  default:
2632
2830
                    (*info->fprintf_func) (stream, "%c", *s);
2633
2831
                    break;
2657
2855
                  case 'e':
2658
2856
                    freg (X_RS1 (insn));
2659
2857
                    break;
2660
 
                  case 'v':     /* double/even */
2661
 
                  case 'V':     /* quad/multiple of 4 */
 
2858
                  case 'v':     /* Double/even.  */
 
2859
                  case 'V':     /* Quad/multiple of 4.  */
2662
2860
                    fregx (X_RS1 (insn));
2663
2861
                    break;
2664
2862
 
2665
2863
                  case 'f':
2666
2864
                    freg (X_RS2 (insn));
2667
2865
                    break;
2668
 
                  case 'B':     /* double/even */
2669
 
                  case 'R':     /* quad/multiple of 4 */
 
2866
                  case 'B':     /* Double/even.  */
 
2867
                  case 'R':     /* Quad/multiple of 4.  */
2670
2868
                    fregx (X_RS2 (insn));
2671
2869
                    break;
2672
2870
 
2673
2871
                  case 'g':
2674
2872
                    freg (X_RD (insn));
2675
2873
                    break;
2676
 
                  case 'H':     /* double/even */
2677
 
                  case 'J':     /* quad/multiple of 4 */
 
2874
                  case 'H':     /* Double/even.  */
 
2875
                  case 'J':     /* Quad/multiple of 4.  */
2678
2876
                    fregx (X_RD (insn));
2679
2877
                    break;
2680
2878
#undef  freg
2700
2898
                                            & ((int) X_IMM22 (insn) << 10)));
2701
2899
                    break;
2702
2900
 
2703
 
                  case 'i':     /* 13 bit immediate */
2704
 
                  case 'I':     /* 11 bit immediate */
2705
 
                  case 'j':     /* 10 bit immediate */
 
2901
                  case 'i':     /* 13 bit immediate.  */
 
2902
                  case 'I':     /* 11 bit immediate.  */
 
2903
                  case 'j':     /* 10 bit immediate.  */
2706
2904
                    {
2707
2905
                      int imm;
2708
2906
 
2730
2928
                    }
2731
2929
                    break;
2732
2930
 
2733
 
                  case 'X':     /* 5 bit unsigned immediate */
2734
 
                  case 'Y':     /* 6 bit unsigned immediate */
 
2931
                  case 'X':     /* 5 bit unsigned immediate.  */
 
2932
                  case 'Y':     /* 6 bit unsigned immediate.  */
2735
2933
                    {
2736
2934
                      int imm = X_IMM (insn, *s == 'X' ? 5 : 6);
2737
2935
 
2743
2941
                    break;
2744
2942
 
2745
2943
                  case '3':
2746
 
                    (info->fprintf_func) (stream, "%d", X_IMM (insn, 3));
 
2944
                    (info->fprintf_func) (stream, "%ld", X_IMM (insn, 3));
2747
2945
                    break;
2748
2946
 
2749
2947
                  case 'K':
2818
3016
                  case '?':
2819
3017
                    if (X_RS1 (insn) == 31)
2820
3018
                      (*info->fprintf_func) (stream, "%%ver");
2821
 
                    else if ((unsigned) X_RS1 (insn) < 16)
 
3019
                    else if ((unsigned) X_RS1 (insn) < 17)
2822
3020
                      (*info->fprintf_func) (stream, "%%%s",
2823
3021
                                             v9_priv_reg_names[X_RS1 (insn)]);
2824
3022
                    else
2826
3024
                    break;
2827
3025
 
2828
3026
                  case '!':
2829
 
                    if ((unsigned) X_RD (insn) < 15)
 
3027
                    if ((unsigned) X_RD (insn) < 17)
2830
3028
                      (*info->fprintf_func) (stream, "%%%s",
2831
3029
                                             v9_priv_reg_names[X_RD (insn)]);
2832
3030
                    else
2833
3031
                      (*info->fprintf_func) (stream, "%%reserved");
2834
3032
                    break;
2835
3033
 
 
3034
                  case '$':
 
3035
                    if ((unsigned) X_RS1 (insn) < 32)
 
3036
                      (*info->fprintf_func) (stream, "%%%s",
 
3037
                                             v9_hpriv_reg_names[X_RS1 (insn)]);
 
3038
                    else
 
3039
                      (*info->fprintf_func) (stream, "%%reserved");
 
3040
                    break;
 
3041
 
 
3042
                  case '%':
 
3043
                    if ((unsigned) X_RD (insn) < 32)
 
3044
                      (*info->fprintf_func) (stream, "%%%s",
 
3045
                                             v9_hpriv_reg_names[X_RD (insn)]);
 
3046
                    else
 
3047
                      (*info->fprintf_func) (stream, "%%reserved");
 
3048
                    break;
 
3049
 
2836
3050
                  case '/':
2837
3051
                    if (X_RS1 (insn) < 16 || X_RS1 (insn) > 25)
2838
3052
                      (*info->fprintf_func) (stream, "%%reserved");
2856
3070
                      if (name)
2857
3071
                        (*info->fprintf_func) (stream, "%s", name);
2858
3072
                      else
2859
 
                        (*info->fprintf_func) (stream, "%d", X_RD (insn));
 
3073
                        (*info->fprintf_func) (stream, "%ld", X_RD (insn));
2860
3074
                      break;
2861
3075
                    }
2862
3076
 
2863
3077
                  case 'M':
2864
 
                    (*info->fprintf_func) (stream, "%%asr%d", X_RS1 (insn));
 
3078
                    (*info->fprintf_func) (stream, "%%asr%ld", X_RS1 (insn));
2865
3079
                    break;
2866
3080
 
2867
3081
                  case 'm':
2868
 
                    (*info->fprintf_func) (stream, "%%asr%d", X_RD (insn));
 
3082
                    (*info->fprintf_func) (stream, "%%asr%ld", X_RD (insn));
2869
3083
                    break;
2870
3084
 
2871
3085
                  case 'L':
2897
3111
                      if (name)
2898
3112
                        (*info->fprintf_func) (stream, "%s", name);
2899
3113
                      else
2900
 
                        (*info->fprintf_func) (stream, "(%d)", X_ASI (insn));
 
3114
                        (*info->fprintf_func) (stream, "(%ld)", X_ASI (insn));
2901
3115
                      break;
2902
3116
                    }
2903
3117
 
2930
3144
                    break;
2931
3145
 
2932
3146
                  case 'x':
2933
 
                    (*info->fprintf_func) (stream, "%d",
 
3147
                    (*info->fprintf_func) (stream, "%ld",
2934
3148
                                           ((X_LDST_I (insn) << 8)
2935
3149
                                            + X_ASI (insn)));
2936
3150
                    break;
2966
3180
              unsigned long prev_insn;
2967
3181
              int errcode;
2968
3182
 
2969
 
              errcode =
2970
 
                (*info->read_memory_func)
 
3183
              if (memaddr >= 4)
 
3184
                errcode =
 
3185
                  (*info->read_memory_func)
2971
3186
                  (memaddr - 4, buffer, sizeof (buffer), info);
 
3187
              else
 
3188
                errcode = 1;
 
3189
 
2972
3190
              prev_insn = getword (buffer);
2973
3191
 
2974
3192
              if (errcode == 0)
2975
3193
                {
2976
3194
                  /* If it is a delayed branch, we need to look at the
2977
3195
                     instruction before the delayed branch.  This handles
2978
 
                     sequences such as
 
3196
                     sequences such as:
2979
3197
 
2980
3198
                     sethi %o1, %hi(_foo), %o1
2981
3199
                     call _printf
2982
 
                     or %o1, %lo(_foo), %o1
2983
 
                     */
 
3200
                     or %o1, %lo(_foo), %o1  */
2984
3201
 
2985
3202
                  if (is_delayed_branch (prev_insn))
2986
3203
                    {
2987
 
                      errcode = (*info->read_memory_func)
2988
 
                        (memaddr - 8, buffer, sizeof (buffer), info);
 
3204
                      if (memaddr >= 8)
 
3205
                        errcode = (*info->read_memory_func)
 
3206
                          (memaddr - 8, buffer, sizeof (buffer), info);
 
3207
                      else
 
3208
                        errcode = 1;
 
3209
 
2989
3210
                      prev_insn = getword (buffer);
2990
3211
                    }
2991
3212
                }
3015
3236
 
3016
3237
          if (opcode->flags & (F_UNBR|F_CONDBR|F_JSR))
3017
3238
            {
3018
 
                /* FIXME -- check is_annulled flag */
 
3239
                /* FIXME -- check is_annulled flag.  */
3019
3240
              if (opcode->flags & F_UNBR)
3020
3241
                info->insn_type = dis_branch;
3021
3242
              if (opcode->flags & F_CONDBR)
3030
3251
        }
3031
3252
    }
3032
3253
 
3033
 
  info->insn_type = dis_noninsn;        /* Mark as non-valid instruction */
 
3254
  info->insn_type = dis_noninsn;        /* Mark as non-valid instruction.  */
3034
3255
  (*info->fprintf_func) (stream, _("unknown"));
3035
3256
  return sizeof (buffer);
3036
3257
}
3037
 
 
3038
 
/* Given BFD mach number, return a mask of SPARC_OPCODE_ARCH_FOO values.  */
3039
 
 
3040
 
static int
3041
 
compute_arch_mask (mach)
3042
 
     unsigned long mach;
3043
 
{
3044
 
  switch (mach)
3045
 
    {
3046
 
    case 0 :
3047
 
    case bfd_mach_sparc :
3048
 
      return SPARC_OPCODE_ARCH_MASK (SPARC_OPCODE_ARCH_V8);
3049
 
    case bfd_mach_sparc_sparclet :
3050
 
      return SPARC_OPCODE_ARCH_MASK (SPARC_OPCODE_ARCH_SPARCLET);
3051
 
    case bfd_mach_sparc_sparclite :
3052
 
    case bfd_mach_sparc_sparclite_le :
3053
 
      /* sparclites insns are recognized by default (because that's how
3054
 
         they've always been treated, for better or worse).  Kludge this by
3055
 
         indicating generic v8 is also selected.  */
3056
 
      return (SPARC_OPCODE_ARCH_MASK (SPARC_OPCODE_ARCH_SPARCLITE)
3057
 
              | SPARC_OPCODE_ARCH_MASK (SPARC_OPCODE_ARCH_V8));
3058
 
    case bfd_mach_sparc_v8plus :
3059
 
    case bfd_mach_sparc_v9 :
3060
 
      return SPARC_OPCODE_ARCH_MASK (SPARC_OPCODE_ARCH_V9);
3061
 
    case bfd_mach_sparc_v8plusa :
3062
 
    case bfd_mach_sparc_v9a :
3063
 
      return SPARC_OPCODE_ARCH_MASK (SPARC_OPCODE_ARCH_V9A);
3064
 
    case bfd_mach_sparc_v8plusb :
3065
 
    case bfd_mach_sparc_v9b :
3066
 
      return SPARC_OPCODE_ARCH_MASK (SPARC_OPCODE_ARCH_V9B);
3067
 
    }
3068
 
  abort ();
3069
 
}
3070
 
 
3071
 
/* Compare opcodes A and B.  */
3072
 
 
3073
 
static int
3074
 
compare_opcodes (const void *a, const void *b)
3075
 
{
3076
 
  struct sparc_opcode *op0 = * (struct sparc_opcode **) a;
3077
 
  struct sparc_opcode *op1 = * (struct sparc_opcode **) b;
3078
 
  unsigned long int match0 = op0->match, match1 = op1->match;
3079
 
  unsigned long int lose0 = op0->lose, lose1 = op1->lose;
3080
 
  register unsigned int i;
3081
 
 
3082
 
  /* If one (and only one) insn isn't supported by the current architecture,
3083
 
     prefer the one that is.  If neither are supported, but they're both for
3084
 
     the same architecture, continue processing.  Otherwise (both unsupported
3085
 
     and for different architectures), prefer lower numbered arch's (fudged
3086
 
     by comparing the bitmasks).  */
3087
 
  if (op0->architecture & current_arch_mask)
3088
 
    {
3089
 
      if (! (op1->architecture & current_arch_mask))
3090
 
        return -1;
3091
 
    }
3092
 
  else
3093
 
    {
3094
 
      if (op1->architecture & current_arch_mask)
3095
 
        return 1;
3096
 
      else if (op0->architecture != op1->architecture)
3097
 
        return op0->architecture - op1->architecture;
3098
 
    }
3099
 
 
3100
 
  /* If a bit is set in both match and lose, there is something
3101
 
     wrong with the opcode table.  */
3102
 
  if (match0 & lose0)
3103
 
    {
3104
 
      fprintf
3105
 
        (stderr,
3106
 
         /* xgettext:c-format */
3107
 
         _("Internal error:  bad sparc-opcode.h: \"%s\", %#.8lx, %#.8lx\n"),
3108
 
         op0->name, match0, lose0);
3109
 
      op0->lose &= ~op0->match;
3110
 
      lose0 = op0->lose;
3111
 
    }
3112
 
 
3113
 
  if (match1 & lose1)
3114
 
    {
3115
 
      fprintf
3116
 
        (stderr,
3117
 
         /* xgettext:c-format */
3118
 
         _("Internal error: bad sparc-opcode.h: \"%s\", %#.8lx, %#.8lx\n"),
3119
 
         op1->name, match1, lose1);
3120
 
      op1->lose &= ~op1->match;
3121
 
      lose1 = op1->lose;
3122
 
    }
3123
 
 
3124
 
  /* Because the bits that are variable in one opcode are constant in
3125
 
     another, it is important to order the opcodes in the right order.  */
3126
 
  for (i = 0; i < 32; ++i)
3127
 
    {
3128
 
      unsigned long int x = 1 << i;
3129
 
      int x0 = (match0 & x) != 0;
3130
 
      int x1 = (match1 & x) != 0;
3131
 
 
3132
 
      if (x0 != x1)
3133
 
        return x1 - x0;
3134
 
    }
3135
 
 
3136
 
  for (i = 0; i < 32; ++i)
3137
 
    {
3138
 
      unsigned long int x = 1 << i;
3139
 
      int x0 = (lose0 & x) != 0;
3140
 
      int x1 = (lose1 & x) != 0;
3141
 
 
3142
 
      if (x0 != x1)
3143
 
        return x1 - x0;
3144
 
    }
3145
 
 
3146
 
  /* They are functionally equal.  So as long as the opcode table is
3147
 
     valid, we can put whichever one first we want, on aesthetic grounds.  */
3148
 
 
3149
 
  /* Our first aesthetic ground is that aliases defer to real insns.  */
3150
 
  {
3151
 
    int alias_diff = (op0->flags & F_ALIAS) - (op1->flags & F_ALIAS);
3152
 
    if (alias_diff != 0)
3153
 
      /* Put the one that isn't an alias first.  */
3154
 
      return alias_diff;
3155
 
  }
3156
 
 
3157
 
  /* Except for aliases, two "identical" instructions had
3158
 
     better have the same opcode.  This is a sanity check on the table.  */
3159
 
  i = strcmp (op0->name, op1->name);
3160
 
  if (i)
3161
 
    {
3162
 
      if (op0->flags & F_ALIAS) /* If they're both aliases, be arbitrary. */
3163
 
        return i;
3164
 
      else
3165
 
        fprintf (stderr,
3166
 
                 /* xgettext:c-format */
3167
 
                 _("Internal error: bad sparc-opcode.h: \"%s\" == \"%s\"\n"),
3168
 
                 op0->name, op1->name);
3169
 
    }
3170
 
 
3171
 
  /* Fewer arguments are preferred.  */
3172
 
  {
3173
 
    int length_diff = strlen (op0->args) - strlen (op1->args);
3174
 
    if (length_diff != 0)
3175
 
      /* Put the one with fewer arguments first.  */
3176
 
      return length_diff;
3177
 
  }
3178
 
 
3179
 
  /* Put 1+i before i+1.  */
3180
 
  {
3181
 
    char *p0 = (char *) strchr (op0->args, '+');
3182
 
    char *p1 = (char *) strchr (op1->args, '+');
3183
 
 
3184
 
    if (p0 && p1)
3185
 
      {
3186
 
        /* There is a plus in both operands.  Note that a plus
3187
 
           sign cannot be the first character in args,
3188
 
           so the following [-1]'s are valid.  */
3189
 
        if (p0[-1] == 'i' && p1[1] == 'i')
3190
 
          /* op0 is i+1 and op1 is 1+i, so op1 goes first.  */
3191
 
          return 1;
3192
 
        if (p0[1] == 'i' && p1[-1] == 'i')
3193
 
          /* op0 is 1+i and op1 is i+1, so op0 goes first.  */
3194
 
          return -1;
3195
 
      }
3196
 
  }
3197
 
 
3198
 
  /* Put 1,i before i,1.  */
3199
 
  {
3200
 
    int i0 = strncmp (op0->args, "i,1", 3) == 0;
3201
 
    int i1 = strncmp (op1->args, "i,1", 3) == 0;
3202
 
 
3203
 
    if (i0 ^ i1)
3204
 
      return i0 - i1;
3205
 
  }
3206
 
 
3207
 
  /* They are, as far as we can tell, identical.
3208
 
     Since qsort may have rearranged the table partially, there is
3209
 
     no way to tell which one was first in the opcode table as
3210
 
     written, so just say there are equal.  */
3211
 
  /* ??? This is no longer true now that we sort a vector of pointers,
3212
 
     not the table itself.  */
3213
 
  return 0;
3214
 
}
3215
 
 
3216
 
/* Build a hash table from the opcode table.
3217
 
   OPCODE_TABLE is a sorted list of pointers into the opcode table.  */
3218
 
 
3219
 
static void
3220
 
build_hash_table (opcode_table, hash_table, num_opcodes)
3221
 
     const struct sparc_opcode **opcode_table;
3222
 
     struct opcode_hash **hash_table;
3223
 
     int num_opcodes;
3224
 
{
3225
 
  register int i;
3226
 
  int hash_count[HASH_SIZE];
3227
 
  static struct opcode_hash *hash_buf = NULL;
3228
 
 
3229
 
  /* Start at the end of the table and work backwards so that each
3230
 
     chain is sorted.  */
3231
 
 
3232
 
  memset (hash_table, 0, HASH_SIZE * sizeof (hash_table[0]));
3233
 
  memset (hash_count, 0, HASH_SIZE * sizeof (hash_count[0]));
3234
 
  if (hash_buf != NULL)
3235
 
    free (hash_buf);
3236
 
  hash_buf = (struct opcode_hash *) malloc (sizeof (struct opcode_hash) * num_opcodes);
3237
 
  for (i = num_opcodes - 1; i >= 0; --i)
3238
 
    {
3239
 
      register int hash = HASH_INSN (opcode_table[i]->match);
3240
 
      register struct opcode_hash *h = &hash_buf[i];
3241
 
      h->next = hash_table[hash];
3242
 
      h->opcode = opcode_table[i];
3243
 
      hash_table[hash] = h;
3244
 
      ++hash_count[hash];
3245
 
    }
3246
 
 
3247
 
#if 0 /* for debugging */
3248
 
  {
3249
 
    int min_count = num_opcodes, max_count = 0;
3250
 
    int total;
3251
 
 
3252
 
    for (i = 0; i < HASH_SIZE; ++i)
3253
 
      {
3254
 
        if (hash_count[i] < min_count)
3255
 
          min_count = hash_count[i];
3256
 
        if (hash_count[i] > max_count)
3257
 
          max_count = hash_count[i];
3258
 
        total += hash_count[i];
3259
 
      }
3260
 
 
3261
 
    printf ("Opcode hash table stats: min %d, max %d, ave %f\n",
3262
 
            min_count, max_count, (double) total / HASH_SIZE);
3263
 
  }
3264
 
#endif
3265
 
}