gdb/
[deliverable/binutils-gdb.git] / opcodes / sparc-dis.c
CommitLineData
252b5132 1/* Print SPARC instructions.
060d22b0 2 Copyright 1989, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
df7b86aa 3 2000, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2010, 2012
aa820537 4 Free Software Foundation, Inc.
252b5132 5
9b201bb5
NC
6 This file is part of the GNU opcodes library.
7
8 This library is free software; you can redistribute it and/or modify
0f6ab988 9 it under the terms of the GNU General Public License as published by
9b201bb5
NC
10 the Free Software Foundation; either version 3, or (at your option)
11 any later version.
252b5132 12
9b201bb5
NC
13 It is distributed in the hope that it will be useful, but WITHOUT
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
16 License for more details.
252b5132 17
0f6ab988
NC
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
47b0e7ad
NC
20 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21 MA 02110-1301, USA. */
252b5132 22
252b5132 23#include "sysdep.h"
df7b86aa 24#include <stdio.h>
252b5132
RH
25#include "opcode/sparc.h"
26#include "dis-asm.h"
27#include "libiberty.h"
28#include "opintl.h"
29
30/* Bitmask of v9 architectures. */
31#define MASK_V9 ((1 << SPARC_OPCODE_ARCH_V9) \
19f7b010
JJ
32 | (1 << SPARC_OPCODE_ARCH_V9A) \
33 | (1 << SPARC_OPCODE_ARCH_V9B))
252b5132
RH
34/* 1 if INSN is for v9 only. */
35#define V9_ONLY_P(insn) (! ((insn)->architecture & ~MASK_V9))
36/* 1 if INSN is for v9. */
37#define V9_P(insn) (((insn)->architecture & MASK_V9) != 0)
38
39/* The sorted opcode table. */
47b0e7ad 40static const sparc_opcode **sorted_opcodes;
252b5132
RH
41
42/* For faster lookup, after insns are sorted they are hashed. */
43/* ??? I think there is room for even more improvement. */
44
45#define HASH_SIZE 256
46/* It is important that we only look at insn code bits as that is how the
47 opcode table is hashed. OPCODE_BITS is a table of valid bits for each
48 of the main types (0,1,2,3). */
49static int opcode_bits[4] = { 0x01c00000, 0x0, 0x01f80000, 0x01f80000 };
50#define HASH_INSN(INSN) \
51 ((((INSN) >> 24) & 0xc0) | (((INSN) & opcode_bits[((INSN) >> 30) & 3]) >> 19))
47b0e7ad 52typedef struct sparc_opcode_hash
0f6ab988 53{
47b0e7ad
NC
54 struct sparc_opcode_hash *next;
55 const sparc_opcode *opcode;
56} sparc_opcode_hash;
252b5132 57
47b0e7ad 58static sparc_opcode_hash *opcode_hash_table[HASH_SIZE];
252b5132
RH
59
60/* Sign-extend a value which is N bits long. */
61#define SEX(value, bits) \
62 ((((int)(value)) << ((8 * sizeof (int)) - bits)) \
63 >> ((8 * sizeof (int)) - bits) )
64
65static char *reg_names[] =
47b0e7ad
NC
66{ "g0", "g1", "g2", "g3", "g4", "g5", "g6", "g7",
67 "o0", "o1", "o2", "o3", "o4", "o5", "sp", "o7",
68 "l0", "l1", "l2", "l3", "l4", "l5", "l6", "l7",
69 "i0", "i1", "i2", "i3", "i4", "i5", "fp", "i7",
70 "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
71 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
252b5132
RH
72 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
73 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31",
47b0e7ad
NC
74 "f32", "f33", "f34", "f35", "f36", "f37", "f38", "f39",
75 "f40", "f41", "f42", "f43", "f44", "f45", "f46", "f47",
252b5132
RH
76 "f48", "f49", "f50", "f51", "f52", "f53", "f54", "f55",
77 "f56", "f57", "f58", "f59", "f60", "f61", "f62", "f63",
78/* psr, wim, tbr, fpsr, cpsr are v8 only. */
79 "y", "psr", "wim", "tbr", "pc", "npc", "fpsr", "cpsr"
80};
81
82#define freg_names (&reg_names[4 * 8])
83
84/* These are ordered according to there register number in
85 rdpr and wrpr insns. */
86static char *v9_priv_reg_names[] =
87{
88 "tpc", "tnpc", "tstate", "tt", "tick", "tba", "pstate", "tl",
89 "pil", "cwp", "cansave", "canrestore", "cleanwin", "otherwin",
ff3f9d5b 90 "wstate", "fq", "gl"
252b5132
RH
91 /* "ver" - special cased */
92};
93
ff3f9d5b
DM
94/* These are ordered according to there register number in
95 rdhpr and wrhpr insns. */
96static char *v9_hpriv_reg_names[] =
97{
98 "hpstate", "htstate", "resv2", "hintp", "resv4", "htba", "hver",
99 "resv7", "resv8", "resv9", "resv10", "resv11", "resv12", "resv13",
100 "resv14", "resv15", "resv16", "resv17", "resv18", "resv19", "resv20",
101 "resv21", "resv22", "resv23", "resv24", "resv25", "resv26", "resv27",
102 "resv28", "resv29", "resv30", "hstick_cmpr"
103};
104
252b5132
RH
105/* These are ordered according to there register number in
106 rd and wr insns (-16). */
107static char *v9a_asr_reg_names[] =
108{
109 "pcr", "pic", "dcr", "gsr", "set_softint", "clear_softint",
2e52845b 110 "softint", "tick_cmpr", "stick", "stick_cmpr", "cfr",
58004e23 111 "pause", "cps"
252b5132
RH
112};
113
114/* Macros used to extract instruction fields. Not all fields have
115 macros defined here, only those which are actually used. */
116
47b0e7ad
NC
117#define X_RD(i) (((i) >> 25) & 0x1f)
118#define X_RS1(i) (((i) >> 14) & 0x1f)
119#define X_LDST_I(i) (((i) >> 13) & 1)
120#define X_ASI(i) (((i) >> 5) & 0xff)
121#define X_RS2(i) (((i) >> 0) & 0x1f)
ea783ef3 122#define X_RS3(i) (((i) >> 9) & 0x1f)
47b0e7ad
NC
123#define X_IMM(i,n) (((i) >> 0) & ((1 << (n)) - 1))
124#define X_SIMM(i,n) SEX (X_IMM ((i), (n)), (n))
125#define X_DISP22(i) (((i) >> 0) & 0x3fffff)
126#define X_IMM22(i) X_DISP22 (i)
127#define X_DISP30(i) (((i) >> 0) & 0x3fffffff)
252b5132
RH
128
129/* These are for v9. */
47b0e7ad 130#define X_DISP16(i) (((((i) >> 20) & 3) << 14) | (((i) >> 0) & 0x3fff))
2615994e 131#define X_DISP10(i) (((((i) >> 19) & 3) << 8) | (((i) >> 5) & 0xff))
47b0e7ad
NC
132#define X_DISP19(i) (((i) >> 0) & 0x7ffff)
133#define X_MEMBAR(i) ((i) & 0x7f)
252b5132
RH
134
135/* Here is the union which was used to extract instruction fields
136 before the shift and mask macros were written.
137
138 union sparc_insn
139 {
140 unsigned long int code;
141 struct
142 {
143 unsigned int anop:2;
144 #define op ldst.anop
145 unsigned int anrd:5;
146 #define rd ldst.anrd
147 unsigned int op3:6;
148 unsigned int anrs1:5;
149 #define rs1 ldst.anrs1
150 unsigned int i:1;
151 unsigned int anasi:8;
152 #define asi ldst.anasi
153 unsigned int anrs2:5;
154 #define rs2 ldst.anrs2
155 #define shcnt rs2
156 } ldst;
157 struct
158 {
159 unsigned int anop:2, anrd:5, op3:6, anrs1:5, i:1;
160 unsigned int IMM13:13;
161 #define imm13 IMM13.IMM13
162 } IMM13;
163 struct
164 {
165 unsigned int anop:2;
166 unsigned int a:1;
167 unsigned int cond:4;
168 unsigned int op2:3;
169 unsigned int DISP22:22;
170 #define disp22 branch.DISP22
171 #define imm22 disp22
172 } branch;
173 struct
174 {
175 unsigned int anop:2;
176 unsigned int a:1;
177 unsigned int z:1;
178 unsigned int rcond:3;
179 unsigned int op2:3;
180 unsigned int DISP16HI:2;
181 unsigned int p:1;
182 unsigned int _rs1:5;
183 unsigned int DISP16LO:14;
184 } branch16;
185 struct
186 {
187 unsigned int anop:2;
188 unsigned int adisp30:30;
189 #define disp30 call.adisp30
190 } call;
47b0e7ad 191 }; */
252b5132
RH
192
193/* Nonzero if INSN is the opcode for a delayed branch. */
47b0e7ad 194
252b5132 195static int
47b0e7ad 196is_delayed_branch (unsigned long insn)
252b5132 197{
47b0e7ad 198 sparc_opcode_hash *op;
252b5132
RH
199
200 for (op = opcode_hash_table[HASH_INSN (insn)]; op; op = op->next)
201 {
47b0e7ad
NC
202 const sparc_opcode *opcode = op->opcode;
203
252b5132
RH
204 if ((opcode->match & insn) == opcode->match
205 && (opcode->lose & insn) == 0)
47b0e7ad 206 return opcode->flags & F_DELAYED;
252b5132
RH
207 }
208 return 0;
209}
210
211/* extern void qsort (); */
212
213/* Records current mask of SPARC_OPCODE_ARCH_FOO values, used to pass value
214 to compare_opcodes. */
215static unsigned int current_arch_mask;
216
47b0e7ad
NC
217/* Given BFD mach number, return a mask of SPARC_OPCODE_ARCH_FOO values. */
218
219static int
220compute_arch_mask (unsigned long mach)
221{
222 switch (mach)
223 {
224 case 0 :
225 case bfd_mach_sparc :
226 return SPARC_OPCODE_ARCH_MASK (SPARC_OPCODE_ARCH_V8);
227 case bfd_mach_sparc_sparclet :
228 return SPARC_OPCODE_ARCH_MASK (SPARC_OPCODE_ARCH_SPARCLET);
229 case bfd_mach_sparc_sparclite :
230 case bfd_mach_sparc_sparclite_le :
231 /* sparclites insns are recognized by default (because that's how
232 they've always been treated, for better or worse). Kludge this by
233 indicating generic v8 is also selected. */
234 return (SPARC_OPCODE_ARCH_MASK (SPARC_OPCODE_ARCH_SPARCLITE)
235 | SPARC_OPCODE_ARCH_MASK (SPARC_OPCODE_ARCH_V8));
236 case bfd_mach_sparc_v8plus :
237 case bfd_mach_sparc_v9 :
238 return SPARC_OPCODE_ARCH_MASK (SPARC_OPCODE_ARCH_V9);
239 case bfd_mach_sparc_v8plusa :
240 case bfd_mach_sparc_v9a :
241 return SPARC_OPCODE_ARCH_MASK (SPARC_OPCODE_ARCH_V9A);
242 case bfd_mach_sparc_v8plusb :
243 case bfd_mach_sparc_v9b :
244 return SPARC_OPCODE_ARCH_MASK (SPARC_OPCODE_ARCH_V9B);
245 }
246 abort ();
247}
248
249/* Compare opcodes A and B. */
250
251static int
252compare_opcodes (const void * a, const void * b)
253{
254 sparc_opcode *op0 = * (sparc_opcode **) a;
255 sparc_opcode *op1 = * (sparc_opcode **) b;
256 unsigned long int match0 = op0->match, match1 = op1->match;
257 unsigned long int lose0 = op0->lose, lose1 = op1->lose;
258 register unsigned int i;
259
260 /* If one (and only one) insn isn't supported by the current architecture,
261 prefer the one that is. If neither are supported, but they're both for
262 the same architecture, continue processing. Otherwise (both unsupported
263 and for different architectures), prefer lower numbered arch's (fudged
264 by comparing the bitmasks). */
265 if (op0->architecture & current_arch_mask)
266 {
267 if (! (op1->architecture & current_arch_mask))
268 return -1;
269 }
270 else
271 {
272 if (op1->architecture & current_arch_mask)
273 return 1;
274 else if (op0->architecture != op1->architecture)
275 return op0->architecture - op1->architecture;
276 }
277
278 /* If a bit is set in both match and lose, there is something
279 wrong with the opcode table. */
280 if (match0 & lose0)
281 {
282 fprintf
283 (stderr,
284 /* xgettext:c-format */
285 _("Internal error: bad sparc-opcode.h: \"%s\", %#.8lx, %#.8lx\n"),
286 op0->name, match0, lose0);
287 op0->lose &= ~op0->match;
288 lose0 = op0->lose;
289 }
290
291 if (match1 & lose1)
292 {
293 fprintf
294 (stderr,
295 /* xgettext:c-format */
296 _("Internal error: bad sparc-opcode.h: \"%s\", %#.8lx, %#.8lx\n"),
297 op1->name, match1, lose1);
298 op1->lose &= ~op1->match;
299 lose1 = op1->lose;
300 }
301
302 /* Because the bits that are variable in one opcode are constant in
303 another, it is important to order the opcodes in the right order. */
304 for (i = 0; i < 32; ++i)
305 {
306 unsigned long int x = 1 << i;
307 int x0 = (match0 & x) != 0;
308 int x1 = (match1 & x) != 0;
309
310 if (x0 != x1)
311 return x1 - x0;
312 }
313
314 for (i = 0; i < 32; ++i)
315 {
316 unsigned long int x = 1 << i;
317 int x0 = (lose0 & x) != 0;
318 int x1 = (lose1 & x) != 0;
319
320 if (x0 != x1)
321 return x1 - x0;
322 }
323
324 /* They are functionally equal. So as long as the opcode table is
325 valid, we can put whichever one first we want, on aesthetic grounds. */
326
327 /* Our first aesthetic ground is that aliases defer to real insns. */
328 {
329 int alias_diff = (op0->flags & F_ALIAS) - (op1->flags & F_ALIAS);
330
331 if (alias_diff != 0)
332 /* Put the one that isn't an alias first. */
333 return alias_diff;
334 }
335
336 /* Except for aliases, two "identical" instructions had
337 better have the same opcode. This is a sanity check on the table. */
338 i = strcmp (op0->name, op1->name);
339 if (i)
340 {
341 if (op0->flags & F_ALIAS) /* If they're both aliases, be arbitrary. */
342 return i;
343 else
344 fprintf (stderr,
345 /* xgettext:c-format */
346 _("Internal error: bad sparc-opcode.h: \"%s\" == \"%s\"\n"),
347 op0->name, op1->name);
348 }
349
350 /* Fewer arguments are preferred. */
351 {
352 int length_diff = strlen (op0->args) - strlen (op1->args);
353
354 if (length_diff != 0)
355 /* Put the one with fewer arguments first. */
356 return length_diff;
357 }
358
359 /* Put 1+i before i+1. */
360 {
361 char *p0 = (char *) strchr (op0->args, '+');
362 char *p1 = (char *) strchr (op1->args, '+');
363
364 if (p0 && p1)
365 {
366 /* There is a plus in both operands. Note that a plus
367 sign cannot be the first character in args,
368 so the following [-1]'s are valid. */
369 if (p0[-1] == 'i' && p1[1] == 'i')
370 /* op0 is i+1 and op1 is 1+i, so op1 goes first. */
371 return 1;
372 if (p0[1] == 'i' && p1[-1] == 'i')
373 /* op0 is 1+i and op1 is i+1, so op0 goes first. */
374 return -1;
375 }
376 }
377
378 /* Put 1,i before i,1. */
379 {
380 int i0 = strncmp (op0->args, "i,1", 3) == 0;
381 int i1 = strncmp (op1->args, "i,1", 3) == 0;
382
383 if (i0 ^ i1)
384 return i0 - i1;
385 }
386
387 /* They are, as far as we can tell, identical.
388 Since qsort may have rearranged the table partially, there is
389 no way to tell which one was first in the opcode table as
390 written, so just say there are equal. */
391 /* ??? This is no longer true now that we sort a vector of pointers,
392 not the table itself. */
393 return 0;
394}
395
396/* Build a hash table from the opcode table.
397 OPCODE_TABLE is a sorted list of pointers into the opcode table. */
398
399static void
400build_hash_table (const sparc_opcode **opcode_table,
401 sparc_opcode_hash **hash_table,
402 int num_opcodes)
403{
404 int i;
405 int hash_count[HASH_SIZE];
406 static sparc_opcode_hash *hash_buf = NULL;
407
408 /* Start at the end of the table and work backwards so that each
409 chain is sorted. */
410
411 memset (hash_table, 0, HASH_SIZE * sizeof (hash_table[0]));
412 memset (hash_count, 0, HASH_SIZE * sizeof (hash_count[0]));
413 if (hash_buf != NULL)
414 free (hash_buf);
415 hash_buf = xmalloc (sizeof (* hash_buf) * num_opcodes);
416 for (i = num_opcodes - 1; i >= 0; --i)
417 {
418 int hash = HASH_INSN (opcode_table[i]->match);
419 sparc_opcode_hash *h = &hash_buf[i];
420
421 h->next = hash_table[hash];
422 h->opcode = opcode_table[i];
423 hash_table[hash] = h;
424 ++hash_count[hash];
425 }
426
427#if 0 /* for debugging */
428 {
429 int min_count = num_opcodes, max_count = 0;
430 int total;
431
432 for (i = 0; i < HASH_SIZE; ++i)
433 {
434 if (hash_count[i] < min_count)
435 min_count = hash_count[i];
436 if (hash_count[i] > max_count)
437 max_count = hash_count[i];
438 total += hash_count[i];
439 }
440
441 printf ("Opcode hash table stats: min %d, max %d, ave %f\n",
442 min_count, max_count, (double) total / HASH_SIZE);
443 }
444#endif
445}
446
252b5132
RH
447/* Print one instruction from MEMADDR on INFO->STREAM.
448
449 We suffix the instruction with a comment that gives the absolute
450 address involved, as well as its symbolic form, if the instruction
451 is preceded by a findable `sethi' and it either adds an immediate
452 displacement to that register, or it is an `add' or `or' instruction
453 on that register. */
454
455int
47b0e7ad 456print_insn_sparc (bfd_vma memaddr, disassemble_info *info)
252b5132
RH
457{
458 FILE *stream = info->stream;
459 bfd_byte buffer[4];
460 unsigned long insn;
47b0e7ad 461 sparc_opcode_hash *op;
252b5132
RH
462 /* Nonzero of opcode table has been initialized. */
463 static int opcodes_initialized = 0;
464 /* bfd mach number of last call. */
465 static unsigned long current_mach = 0;
7bfeee7b 466 bfd_vma (*getword) (const void *);
252b5132
RH
467
468 if (!opcodes_initialized
469 || info->mach != current_mach)
470 {
471 int i;
472
473 current_arch_mask = compute_arch_mask (info->mach);
474
475 if (!opcodes_initialized)
47b0e7ad
NC
476 sorted_opcodes =
477 xmalloc (sparc_num_opcodes * sizeof (sparc_opcode *));
252b5132
RH
478 /* Reset the sorted table so we can resort it. */
479 for (i = 0; i < sparc_num_opcodes; ++i)
480 sorted_opcodes[i] = &sparc_opcodes[i];
481 qsort ((char *) sorted_opcodes, sparc_num_opcodes,
482 sizeof (sorted_opcodes[0]), compare_opcodes);
483
484 build_hash_table (sorted_opcodes, opcode_hash_table, sparc_num_opcodes);
485 current_mach = info->mach;
486 opcodes_initialized = 1;
487 }
488
489 {
490 int status =
491 (*info->read_memory_func) (memaddr, buffer, sizeof (buffer), info);
47b0e7ad 492
252b5132
RH
493 if (status != 0)
494 {
495 (*info->memory_error_func) (status, memaddr, info);
496 return -1;
497 }
498 }
499
500 /* On SPARClite variants such as DANlite (sparc86x), instructions
0f6ab988 501 are always big-endian even when the machine is in little-endian mode. */
252b5132
RH
502 if (info->endian == BFD_ENDIAN_BIG || info->mach == bfd_mach_sparc_sparclite)
503 getword = bfd_getb32;
504 else
505 getword = bfd_getl32;
506
507 insn = getword (buffer);
508
0f6ab988
NC
509 info->insn_info_valid = 1; /* We do return this info. */
510 info->insn_type = dis_nonbranch; /* Assume non branch insn. */
511 info->branch_delay_insns = 0; /* Assume no delay. */
512 info->target = 0; /* Assume no target known. */
252b5132
RH
513
514 for (op = opcode_hash_table[HASH_INSN (insn)]; op; op = op->next)
515 {
47b0e7ad 516 const sparc_opcode *opcode = op->opcode;
252b5132
RH
517
518 /* If the insn isn't supported by the current architecture, skip it. */
519 if (! (opcode->architecture & current_arch_mask))
520 continue;
521
522 if ((opcode->match & insn) == opcode->match
523 && (opcode->lose & insn) == 0)
524 {
525 /* Nonzero means that we have found an instruction which has
526 the effect of adding or or'ing the imm13 field to rs1. */
527 int imm_added_to_rs1 = 0;
9df31319 528 int imm_ored_to_rs1 = 0;
252b5132
RH
529
530 /* Nonzero means that we have found a plus sign in the args
531 field of the opcode table. */
532 int found_plus = 0;
47b0e7ad 533
252b5132
RH
534 /* Nonzero means we have an annulled branch. */
535 int is_annulled = 0;
536
537 /* Do we have an `add' or `or' instruction combining an
538 immediate with rs1? */
9df31319
RH
539 if (opcode->match == 0x80102000) /* or */
540 imm_ored_to_rs1 = 1;
541 if (opcode->match == 0x80002000) /* add */
252b5132
RH
542 imm_added_to_rs1 = 1;
543
544 if (X_RS1 (insn) != X_RD (insn)
545 && strchr (opcode->args, 'r') != 0)
546 /* Can't do simple format if source and dest are different. */
547 continue;
548 if (X_RS2 (insn) != X_RD (insn)
549 && strchr (opcode->args, 'O') != 0)
550 /* Can't do simple format if source and dest are different. */
551 continue;
552
553 (*info->fprintf_func) (stream, opcode->name);
554
555 {
47b0e7ad 556 const char *s;
252b5132
RH
557
558 if (opcode->args[0] != ',')
559 (*info->fprintf_func) (stream, " ");
0f6ab988 560
252b5132
RH
561 for (s = opcode->args; *s != '\0'; ++s)
562 {
563 while (*s == ',')
564 {
565 (*info->fprintf_func) (stream, ",");
566 ++s;
0f6ab988
NC
567 switch (*s)
568 {
569 case 'a':
570 (*info->fprintf_func) (stream, "a");
571 is_annulled = 1;
572 ++s;
573 continue;
574 case 'N':
575 (*info->fprintf_func) (stream, "pn");
576 ++s;
577 continue;
578
579 case 'T':
580 (*info->fprintf_func) (stream, "pt");
581 ++s;
582 continue;
583
584 default:
585 break;
586 }
587 }
252b5132
RH
588
589 (*info->fprintf_func) (stream, " ");
47b0e7ad 590
252b5132
RH
591 switch (*s)
592 {
593 case '+':
594 found_plus = 1;
47b0e7ad 595 /* Fall through. */
252b5132 596
252b5132
RH
597 default:
598 (*info->fprintf_func) (stream, "%c", *s);
599 break;
600
601 case '#':
602 (*info->fprintf_func) (stream, "0");
603 break;
604
605#define reg(n) (*info->fprintf_func) (stream, "%%%s", reg_names[n])
606 case '1':
607 case 'r':
608 reg (X_RS1 (insn));
609 break;
610
611 case '2':
612 case 'O':
613 reg (X_RS2 (insn));
614 break;
615
616 case 'd':
617 reg (X_RD (insn));
618 break;
619#undef reg
620
621#define freg(n) (*info->fprintf_func) (stream, "%%%s", freg_names[n])
622#define fregx(n) (*info->fprintf_func) (stream, "%%%s", freg_names[((n) & ~1) | (((n) & 1) << 5)])
623 case 'e':
624 freg (X_RS1 (insn));
625 break;
47b0e7ad
NC
626 case 'v': /* Double/even. */
627 case 'V': /* Quad/multiple of 4. */
252b5132
RH
628 fregx (X_RS1 (insn));
629 break;
630
631 case 'f':
632 freg (X_RS2 (insn));
633 break;
47b0e7ad
NC
634 case 'B': /* Double/even. */
635 case 'R': /* Quad/multiple of 4. */
252b5132
RH
636 fregx (X_RS2 (insn));
637 break;
638
ea783ef3
DM
639 case '4':
640 freg (X_RS3 (insn));
641 break;
642 case '5': /* Double/even. */
643 fregx (X_RS3 (insn));
644 break;
645
252b5132
RH
646 case 'g':
647 freg (X_RD (insn));
648 break;
47b0e7ad
NC
649 case 'H': /* Double/even. */
650 case 'J': /* Quad/multiple of 4. */
252b5132
RH
651 fregx (X_RD (insn));
652 break;
653#undef freg
654#undef fregx
655
656#define creg(n) (*info->fprintf_func) (stream, "%%c%u", (unsigned int) (n))
657 case 'b':
658 creg (X_RS1 (insn));
659 break;
660
661 case 'c':
662 creg (X_RS2 (insn));
663 break;
664
665 case 'D':
666 creg (X_RD (insn));
667 break;
668#undef creg
669
670 case 'h':
671 (*info->fprintf_func) (stream, "%%hi(%#x)",
56930d37 672 ((unsigned) 0xFFFFFFFF
252b5132
RH
673 & ((int) X_IMM22 (insn) << 10)));
674 break;
675
47b0e7ad
NC
676 case 'i': /* 13 bit immediate. */
677 case 'I': /* 11 bit immediate. */
678 case 'j': /* 10 bit immediate. */
252b5132
RH
679 {
680 int imm;
681
682 if (*s == 'i')
683 imm = X_SIMM (insn, 13);
684 else if (*s == 'I')
685 imm = X_SIMM (insn, 11);
686 else
687 imm = X_SIMM (insn, 10);
688
689 /* Check to see whether we have a 1+i, and take
690 note of that fact.
691
692 Note: because of the way we sort the table,
693 we will be matching 1+i rather than i+1,
694 so it is OK to assume that i is after +,
695 not before it. */
696 if (found_plus)
697 imm_added_to_rs1 = 1;
47b0e7ad 698
252b5132
RH
699 if (imm <= 9)
700 (*info->fprintf_func) (stream, "%d", imm);
701 else
702 (*info->fprintf_func) (stream, "%#x", imm);
703 }
704 break;
705
6cda1326
DM
706 case ')': /* 5 bit unsigned immediate from RS3. */
707 (info->fprintf_func) (stream, "%#x", X_RS3 (insn));
708 break;
709
47b0e7ad
NC
710 case 'X': /* 5 bit unsigned immediate. */
711 case 'Y': /* 6 bit unsigned immediate. */
252b5132
RH
712 {
713 int imm = X_IMM (insn, *s == 'X' ? 5 : 6);
714
715 if (imm <= 9)
716 (info->fprintf_func) (stream, "%d", imm);
717 else
718 (info->fprintf_func) (stream, "%#x", (unsigned) imm);
719 }
720 break;
721
19f7b010 722 case '3':
0fd3a477 723 (info->fprintf_func) (stream, "%ld", X_IMM (insn, 3));
19f7b010
JJ
724 break;
725
252b5132
RH
726 case 'K':
727 {
728 int mask = X_MEMBAR (insn);
729 int bit = 0x40, printed_one = 0;
730 const char *name;
731
732 if (mask == 0)
733 (info->fprintf_func) (stream, "0");
734 else
735 while (bit)
736 {
737 if (mask & bit)
738 {
739 if (printed_one)
740 (info->fprintf_func) (stream, "|");
741 name = sparc_decode_membar (bit);
742 (info->fprintf_func) (stream, "%s", name);
743 printed_one = 1;
744 }
745 bit >>= 1;
746 }
747 break;
748 }
749
2615994e
DM
750 case '=':
751 info->target = memaddr + SEX (X_DISP10 (insn), 10) * 4;
752 (*info->print_address_func) (info->target, info);
753 break;
754
252b5132
RH
755 case 'k':
756 info->target = memaddr + SEX (X_DISP16 (insn), 16) * 4;
757 (*info->print_address_func) (info->target, info);
758 break;
759
760 case 'G':
761 info->target = memaddr + SEX (X_DISP19 (insn), 19) * 4;
762 (*info->print_address_func) (info->target, info);
763 break;
764
765 case '6':
766 case '7':
767 case '8':
768 case '9':
769 (*info->fprintf_func) (stream, "%%fcc%c", *s - '6' + '0');
770 break;
771
772 case 'z':
773 (*info->fprintf_func) (stream, "%%icc");
774 break;
775
776 case 'Z':
777 (*info->fprintf_func) (stream, "%%xcc");
778 break;
779
780 case 'E':
781 (*info->fprintf_func) (stream, "%%ccr");
782 break;
783
784 case 's':
785 (*info->fprintf_func) (stream, "%%fprs");
786 break;
787
788 case 'o':
789 (*info->fprintf_func) (stream, "%%asi");
790 break;
47b0e7ad 791
252b5132
RH
792 case 'W':
793 (*info->fprintf_func) (stream, "%%tick");
794 break;
795
796 case 'P':
797 (*info->fprintf_func) (stream, "%%pc");
798 break;
799
800 case '?':
801 if (X_RS1 (insn) == 31)
802 (*info->fprintf_func) (stream, "%%ver");
ff3f9d5b 803 else if ((unsigned) X_RS1 (insn) < 17)
252b5132
RH
804 (*info->fprintf_func) (stream, "%%%s",
805 v9_priv_reg_names[X_RS1 (insn)]);
806 else
807 (*info->fprintf_func) (stream, "%%reserved");
808 break;
809
810 case '!':
ff3f9d5b 811 if ((unsigned) X_RD (insn) < 17)
252b5132
RH
812 (*info->fprintf_func) (stream, "%%%s",
813 v9_priv_reg_names[X_RD (insn)]);
814 else
815 (*info->fprintf_func) (stream, "%%reserved");
816 break;
817
ff3f9d5b
DM
818 case '$':
819 if ((unsigned) X_RS1 (insn) < 32)
820 (*info->fprintf_func) (stream, "%%%s",
821 v9_hpriv_reg_names[X_RS1 (insn)]);
822 else
823 (*info->fprintf_func) (stream, "%%reserved");
824 break;
825
826 case '%':
827 if ((unsigned) X_RD (insn) < 32)
828 (*info->fprintf_func) (stream, "%%%s",
829 v9_hpriv_reg_names[X_RD (insn)]);
830 else
831 (*info->fprintf_func) (stream, "%%reserved");
832 break;
833
252b5132 834 case '/':
ea783ef3 835 if (X_RS1 (insn) < 16 || X_RS1 (insn) > 28)
252b5132
RH
836 (*info->fprintf_func) (stream, "%%reserved");
837 else
838 (*info->fprintf_func) (stream, "%%%s",
839 v9a_asr_reg_names[X_RS1 (insn)-16]);
840 break;
841
842 case '_':
ea783ef3 843 if (X_RD (insn) < 16 || X_RD (insn) > 28)
252b5132
RH
844 (*info->fprintf_func) (stream, "%%reserved");
845 else
846 (*info->fprintf_func) (stream, "%%%s",
847 v9a_asr_reg_names[X_RD (insn)-16]);
848 break;
849
850 case '*':
851 {
852 const char *name = sparc_decode_prefetch (X_RD (insn));
853
854 if (name)
855 (*info->fprintf_func) (stream, "%s", name);
856 else
0fd3a477 857 (*info->fprintf_func) (stream, "%ld", X_RD (insn));
252b5132
RH
858 break;
859 }
47b0e7ad 860
252b5132 861 case 'M':
0fd3a477 862 (*info->fprintf_func) (stream, "%%asr%ld", X_RS1 (insn));
252b5132 863 break;
47b0e7ad 864
252b5132 865 case 'm':
0fd3a477 866 (*info->fprintf_func) (stream, "%%asr%ld", X_RD (insn));
252b5132 867 break;
47b0e7ad 868
252b5132
RH
869 case 'L':
870 info->target = memaddr + SEX (X_DISP30 (insn), 30) * 4;
871 (*info->print_address_func) (info->target, info);
872 break;
873
874 case 'n':
875 (*info->fprintf_func)
876 (stream, "%#x", SEX (X_DISP22 (insn), 22));
877 break;
878
879 case 'l':
880 info->target = memaddr + SEX (X_DISP22 (insn), 22) * 4;
881 (*info->print_address_func) (info->target, info);
882 break;
883
884 case 'A':
885 {
886 const char *name = sparc_decode_asi (X_ASI (insn));
887
888 if (name)
889 (*info->fprintf_func) (stream, "%s", name);
890 else
0fd3a477 891 (*info->fprintf_func) (stream, "(%ld)", X_ASI (insn));
252b5132
RH
892 break;
893 }
894
895 case 'C':
896 (*info->fprintf_func) (stream, "%%csr");
897 break;
898
899 case 'F':
900 (*info->fprintf_func) (stream, "%%fsr");
901 break;
902
ea783ef3
DM
903 case '(':
904 (*info->fprintf_func) (stream, "%%efsr");
905 break;
906
252b5132
RH
907 case 'p':
908 (*info->fprintf_func) (stream, "%%psr");
909 break;
910
911 case 'q':
912 (*info->fprintf_func) (stream, "%%fq");
913 break;
914
915 case 'Q':
916 (*info->fprintf_func) (stream, "%%cq");
917 break;
918
919 case 't':
920 (*info->fprintf_func) (stream, "%%tbr");
921 break;
922
923 case 'w':
924 (*info->fprintf_func) (stream, "%%wim");
925 break;
926
927 case 'x':
0fd3a477 928 (*info->fprintf_func) (stream, "%ld",
252b5132
RH
929 ((X_LDST_I (insn) << 8)
930 + X_ASI (insn)));
931 break;
932
933 case 'y':
934 (*info->fprintf_func) (stream, "%%y");
935 break;
936
937 case 'u':
938 case 'U':
939 {
940 int val = *s == 'U' ? X_RS1 (insn) : X_RD (insn);
941 const char *name = sparc_decode_sparclet_cpreg (val);
942
943 if (name)
944 (*info->fprintf_func) (stream, "%s", name);
945 else
946 (*info->fprintf_func) (stream, "%%cpreg(%d)", val);
947 break;
948 }
949 }
950 }
951 }
952
953 /* If we are adding or or'ing something to rs1, then
954 check to see whether the previous instruction was
955 a sethi to the same register as in the sethi.
956 If so, attempt to print the result of the add or
957 or (in this context add and or do the same thing)
958 and its symbolic value. */
9df31319 959 if (imm_ored_to_rs1 || imm_added_to_rs1)
252b5132
RH
960 {
961 unsigned long prev_insn;
962 int errcode;
963
0f6ab988
NC
964 if (memaddr >= 4)
965 errcode =
966 (*info->read_memory_func)
252b5132 967 (memaddr - 4, buffer, sizeof (buffer), info);
0f6ab988
NC
968 else
969 errcode = 1;
970
252b5132
RH
971 prev_insn = getword (buffer);
972
973 if (errcode == 0)
974 {
975 /* If it is a delayed branch, we need to look at the
976 instruction before the delayed branch. This handles
0f6ab988 977 sequences such as:
252b5132
RH
978
979 sethi %o1, %hi(_foo), %o1
980 call _printf
0f6ab988 981 or %o1, %lo(_foo), %o1 */
252b5132
RH
982
983 if (is_delayed_branch (prev_insn))
984 {
0f6ab988
NC
985 if (memaddr >= 8)
986 errcode = (*info->read_memory_func)
987 (memaddr - 8, buffer, sizeof (buffer), info);
988 else
989 errcode = 1;
990
252b5132
RH
991 prev_insn = getword (buffer);
992 }
993 }
994
995 /* If there was a problem reading memory, then assume
996 the previous instruction was not sethi. */
997 if (errcode == 0)
998 {
999 /* Is it sethi to the same register? */
1000 if ((prev_insn & 0xc1c00000) == 0x01000000
1001 && X_RD (prev_insn) == X_RS1 (insn))
1002 {
1003 (*info->fprintf_func) (stream, "\t! ");
47b0e7ad 1004 info->target =
56930d37
AO
1005 ((unsigned) 0xFFFFFFFF
1006 & ((int) X_IMM22 (prev_insn) << 10));
9df31319
RH
1007 if (imm_added_to_rs1)
1008 info->target += X_SIMM (insn, 13);
1009 else
1010 info->target |= X_SIMM (insn, 13);
252b5132
RH
1011 (*info->print_address_func) (info->target, info);
1012 info->insn_type = dis_dref;
1013 info->data_size = 4; /* FIXME!!! */
1014 }
1015 }
1016 }
1017
1018 if (opcode->flags & (F_UNBR|F_CONDBR|F_JSR))
1019 {
c7e2358a
AM
1020 /* FIXME -- check is_annulled flag. */
1021 (void) is_annulled;
252b5132
RH
1022 if (opcode->flags & F_UNBR)
1023 info->insn_type = dis_branch;
1024 if (opcode->flags & F_CONDBR)
1025 info->insn_type = dis_condbranch;
1026 if (opcode->flags & F_JSR)
1027 info->insn_type = dis_jsr;
1028 if (opcode->flags & F_DELAYED)
1029 info->branch_delay_insns = 1;
1030 }
1031
1032 return sizeof (buffer);
1033 }
1034 }
1035
0f6ab988 1036 info->insn_type = dis_noninsn; /* Mark as non-valid instruction. */
252b5132
RH
1037 (*info->fprintf_func) (stream, _("unknown"));
1038 return sizeof (buffer);
1039}
This page took 0.609176 seconds and 4 git commands to generate.