1 /* Print SPARC instructions.
2 Copyright 1989, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
3 2000, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
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.
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.
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., 51 Franklin Street - Fifth Floor, Boston,
18 MA 02110-1301, USA. */
23 #include "opcode/sparc.h"
25 #include "libiberty.h"
28 /* Bitmask of v9 architectures. */
29 #define MASK_V9 ((1 << SPARC_OPCODE_ARCH_V9) \
30 | (1 << SPARC_OPCODE_ARCH_V9A) \
31 | (1 << SPARC_OPCODE_ARCH_V9B))
32 /* 1 if INSN is for v9 only. */
33 #define V9_ONLY_P(insn) (! ((insn)->architecture & ~MASK_V9))
34 /* 1 if INSN is for v9. */
35 #define V9_P(insn) (((insn)->architecture & MASK_V9) != 0)
37 /* The sorted opcode table. */
38 static const sparc_opcode
**sorted_opcodes
;
40 /* For faster lookup, after insns are sorted they are hashed. */
41 /* ??? I think there is room for even more improvement. */
44 /* It is important that we only look at insn code bits as that is how the
45 opcode table is hashed. OPCODE_BITS is a table of valid bits for each
46 of the main types (0,1,2,3). */
47 static int opcode_bits
[4] = { 0x01c00000, 0x0, 0x01f80000, 0x01f80000 };
48 #define HASH_INSN(INSN) \
49 ((((INSN) >> 24) & 0xc0) | (((INSN) & opcode_bits[((INSN) >> 30) & 3]) >> 19))
50 typedef struct sparc_opcode_hash
52 struct sparc_opcode_hash
*next
;
53 const sparc_opcode
*opcode
;
56 static sparc_opcode_hash
*opcode_hash_table
[HASH_SIZE
];
58 /* Sign-extend a value which is N bits long. */
59 #define SEX(value, bits) \
60 ((((int)(value)) << ((8 * sizeof (int)) - bits)) \
61 >> ((8 * sizeof (int)) - bits) )
63 static char *reg_names
[] =
64 { "g0", "g1", "g2", "g3", "g4", "g5", "g6", "g7",
65 "o0", "o1", "o2", "o3", "o4", "o5", "sp", "o7",
66 "l0", "l1", "l2", "l3", "l4", "l5", "l6", "l7",
67 "i0", "i1", "i2", "i3", "i4", "i5", "fp", "i7",
68 "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
69 "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
70 "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
71 "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31",
72 "f32", "f33", "f34", "f35", "f36", "f37", "f38", "f39",
73 "f40", "f41", "f42", "f43", "f44", "f45", "f46", "f47",
74 "f48", "f49", "f50", "f51", "f52", "f53", "f54", "f55",
75 "f56", "f57", "f58", "f59", "f60", "f61", "f62", "f63",
76 /* psr, wim, tbr, fpsr, cpsr are v8 only. */
77 "y", "psr", "wim", "tbr", "pc", "npc", "fpsr", "cpsr"
80 #define freg_names (®_names[4 * 8])
82 /* These are ordered according to there register number in
83 rdpr and wrpr insns. */
84 static char *v9_priv_reg_names
[] =
86 "tpc", "tnpc", "tstate", "tt", "tick", "tba", "pstate", "tl",
87 "pil", "cwp", "cansave", "canrestore", "cleanwin", "otherwin",
89 /* "ver" - special cased */
92 /* These are ordered according to there register number in
93 rd and wr insns (-16). */
94 static char *v9a_asr_reg_names
[] =
96 "pcr", "pic", "dcr", "gsr", "set_softint", "clear_softint",
97 "softint", "tick_cmpr", "sys_tick", "sys_tick_cmpr"
100 /* Macros used to extract instruction fields. Not all fields have
101 macros defined here, only those which are actually used. */
103 #define X_RD(i) (((i) >> 25) & 0x1f)
104 #define X_RS1(i) (((i) >> 14) & 0x1f)
105 #define X_LDST_I(i) (((i) >> 13) & 1)
106 #define X_ASI(i) (((i) >> 5) & 0xff)
107 #define X_RS2(i) (((i) >> 0) & 0x1f)
108 #define X_IMM(i,n) (((i) >> 0) & ((1 << (n)) - 1))
109 #define X_SIMM(i,n) SEX (X_IMM ((i), (n)), (n))
110 #define X_DISP22(i) (((i) >> 0) & 0x3fffff)
111 #define X_IMM22(i) X_DISP22 (i)
112 #define X_DISP30(i) (((i) >> 0) & 0x3fffffff)
114 /* These are for v9. */
115 #define X_DISP16(i) (((((i) >> 20) & 3) << 14) | (((i) >> 0) & 0x3fff))
116 #define X_DISP19(i) (((i) >> 0) & 0x7ffff)
117 #define X_MEMBAR(i) ((i) & 0x7f)
119 /* Here is the union which was used to extract instruction fields
120 before the shift and mask macros were written.
124 unsigned long int code;
132 unsigned int anrs1:5;
133 #define rs1 ldst.anrs1
135 unsigned int anasi:8;
136 #define asi ldst.anasi
137 unsigned int anrs2:5;
138 #define rs2 ldst.anrs2
143 unsigned int anop:2, anrd:5, op3:6, anrs1:5, i:1;
144 unsigned int IMM13:13;
145 #define imm13 IMM13.IMM13
153 unsigned int DISP22:22;
154 #define disp22 branch.DISP22
162 unsigned int rcond:3;
164 unsigned int DISP16HI:2;
167 unsigned int DISP16LO:14;
172 unsigned int adisp30:30;
173 #define disp30 call.adisp30
177 /* Nonzero if INSN is the opcode for a delayed branch. */
180 is_delayed_branch (unsigned long insn
)
182 sparc_opcode_hash
*op
;
184 for (op
= opcode_hash_table
[HASH_INSN (insn
)]; op
; op
= op
->next
)
186 const sparc_opcode
*opcode
= op
->opcode
;
188 if ((opcode
->match
& insn
) == opcode
->match
189 && (opcode
->lose
& insn
) == 0)
190 return opcode
->flags
& F_DELAYED
;
195 /* extern void qsort (); */
197 /* Records current mask of SPARC_OPCODE_ARCH_FOO values, used to pass value
198 to compare_opcodes. */
199 static unsigned int current_arch_mask
;
201 /* Given BFD mach number, return a mask of SPARC_OPCODE_ARCH_FOO values. */
204 compute_arch_mask (unsigned long mach
)
209 case bfd_mach_sparc
:
210 return SPARC_OPCODE_ARCH_MASK (SPARC_OPCODE_ARCH_V8
);
211 case bfd_mach_sparc_sparclet
:
212 return SPARC_OPCODE_ARCH_MASK (SPARC_OPCODE_ARCH_SPARCLET
);
213 case bfd_mach_sparc_sparclite
:
214 case bfd_mach_sparc_sparclite_le
:
215 /* sparclites insns are recognized by default (because that's how
216 they've always been treated, for better or worse). Kludge this by
217 indicating generic v8 is also selected. */
218 return (SPARC_OPCODE_ARCH_MASK (SPARC_OPCODE_ARCH_SPARCLITE
)
219 | SPARC_OPCODE_ARCH_MASK (SPARC_OPCODE_ARCH_V8
));
220 case bfd_mach_sparc_v8plus
:
221 case bfd_mach_sparc_v9
:
222 return SPARC_OPCODE_ARCH_MASK (SPARC_OPCODE_ARCH_V9
);
223 case bfd_mach_sparc_v8plusa
:
224 case bfd_mach_sparc_v9a
:
225 return SPARC_OPCODE_ARCH_MASK (SPARC_OPCODE_ARCH_V9A
);
226 case bfd_mach_sparc_v8plusb
:
227 case bfd_mach_sparc_v9b
:
228 return SPARC_OPCODE_ARCH_MASK (SPARC_OPCODE_ARCH_V9B
);
233 /* Compare opcodes A and B. */
236 compare_opcodes (const void * a
, const void * b
)
238 sparc_opcode
*op0
= * (sparc_opcode
**) a
;
239 sparc_opcode
*op1
= * (sparc_opcode
**) b
;
240 unsigned long int match0
= op0
->match
, match1
= op1
->match
;
241 unsigned long int lose0
= op0
->lose
, lose1
= op1
->lose
;
242 register unsigned int i
;
244 /* If one (and only one) insn isn't supported by the current architecture,
245 prefer the one that is. If neither are supported, but they're both for
246 the same architecture, continue processing. Otherwise (both unsupported
247 and for different architectures), prefer lower numbered arch's (fudged
248 by comparing the bitmasks). */
249 if (op0
->architecture
& current_arch_mask
)
251 if (! (op1
->architecture
& current_arch_mask
))
256 if (op1
->architecture
& current_arch_mask
)
258 else if (op0
->architecture
!= op1
->architecture
)
259 return op0
->architecture
- op1
->architecture
;
262 /* If a bit is set in both match and lose, there is something
263 wrong with the opcode table. */
268 /* xgettext:c-format */
269 _("Internal error: bad sparc-opcode.h: \"%s\", %#.8lx, %#.8lx\n"),
270 op0
->name
, match0
, lose0
);
271 op0
->lose
&= ~op0
->match
;
279 /* xgettext:c-format */
280 _("Internal error: bad sparc-opcode.h: \"%s\", %#.8lx, %#.8lx\n"),
281 op1
->name
, match1
, lose1
);
282 op1
->lose
&= ~op1
->match
;
286 /* Because the bits that are variable in one opcode are constant in
287 another, it is important to order the opcodes in the right order. */
288 for (i
= 0; i
< 32; ++i
)
290 unsigned long int x
= 1 << i
;
291 int x0
= (match0
& x
) != 0;
292 int x1
= (match1
& x
) != 0;
298 for (i
= 0; i
< 32; ++i
)
300 unsigned long int x
= 1 << i
;
301 int x0
= (lose0
& x
) != 0;
302 int x1
= (lose1
& x
) != 0;
308 /* They are functionally equal. So as long as the opcode table is
309 valid, we can put whichever one first we want, on aesthetic grounds. */
311 /* Our first aesthetic ground is that aliases defer to real insns. */
313 int alias_diff
= (op0
->flags
& F_ALIAS
) - (op1
->flags
& F_ALIAS
);
316 /* Put the one that isn't an alias first. */
320 /* Except for aliases, two "identical" instructions had
321 better have the same opcode. This is a sanity check on the table. */
322 i
= strcmp (op0
->name
, op1
->name
);
325 if (op0
->flags
& F_ALIAS
) /* If they're both aliases, be arbitrary. */
329 /* xgettext:c-format */
330 _("Internal error: bad sparc-opcode.h: \"%s\" == \"%s\"\n"),
331 op0
->name
, op1
->name
);
334 /* Fewer arguments are preferred. */
336 int length_diff
= strlen (op0
->args
) - strlen (op1
->args
);
338 if (length_diff
!= 0)
339 /* Put the one with fewer arguments first. */
343 /* Put 1+i before i+1. */
345 char *p0
= (char *) strchr (op0
->args
, '+');
346 char *p1
= (char *) strchr (op1
->args
, '+');
350 /* There is a plus in both operands. Note that a plus
351 sign cannot be the first character in args,
352 so the following [-1]'s are valid. */
353 if (p0
[-1] == 'i' && p1
[1] == 'i')
354 /* op0 is i+1 and op1 is 1+i, so op1 goes first. */
356 if (p0
[1] == 'i' && p1
[-1] == 'i')
357 /* op0 is 1+i and op1 is i+1, so op0 goes first. */
362 /* Put 1,i before i,1. */
364 int i0
= strncmp (op0
->args
, "i,1", 3) == 0;
365 int i1
= strncmp (op1
->args
, "i,1", 3) == 0;
371 /* They are, as far as we can tell, identical.
372 Since qsort may have rearranged the table partially, there is
373 no way to tell which one was first in the opcode table as
374 written, so just say there are equal. */
375 /* ??? This is no longer true now that we sort a vector of pointers,
376 not the table itself. */
380 /* Build a hash table from the opcode table.
381 OPCODE_TABLE is a sorted list of pointers into the opcode table. */
384 build_hash_table (const sparc_opcode
**opcode_table
,
385 sparc_opcode_hash
**hash_table
,
389 int hash_count
[HASH_SIZE
];
390 static sparc_opcode_hash
*hash_buf
= NULL
;
392 /* Start at the end of the table and work backwards so that each
395 memset (hash_table
, 0, HASH_SIZE
* sizeof (hash_table
[0]));
396 memset (hash_count
, 0, HASH_SIZE
* sizeof (hash_count
[0]));
397 if (hash_buf
!= NULL
)
399 hash_buf
= xmalloc (sizeof (* hash_buf
) * num_opcodes
);
400 for (i
= num_opcodes
- 1; i
>= 0; --i
)
402 int hash
= HASH_INSN (opcode_table
[i
]->match
);
403 sparc_opcode_hash
*h
= &hash_buf
[i
];
405 h
->next
= hash_table
[hash
];
406 h
->opcode
= opcode_table
[i
];
407 hash_table
[hash
] = h
;
411 #if 0 /* for debugging */
413 int min_count
= num_opcodes
, max_count
= 0;
416 for (i
= 0; i
< HASH_SIZE
; ++i
)
418 if (hash_count
[i
] < min_count
)
419 min_count
= hash_count
[i
];
420 if (hash_count
[i
] > max_count
)
421 max_count
= hash_count
[i
];
422 total
+= hash_count
[i
];
425 printf ("Opcode hash table stats: min %d, max %d, ave %f\n",
426 min_count
, max_count
, (double) total
/ HASH_SIZE
);
431 /* Print one instruction from MEMADDR on INFO->STREAM.
433 We suffix the instruction with a comment that gives the absolute
434 address involved, as well as its symbolic form, if the instruction
435 is preceded by a findable `sethi' and it either adds an immediate
436 displacement to that register, or it is an `add' or `or' instruction
440 print_insn_sparc (bfd_vma memaddr
, disassemble_info
*info
)
442 FILE *stream
= info
->stream
;
445 sparc_opcode_hash
*op
;
446 /* Nonzero of opcode table has been initialized. */
447 static int opcodes_initialized
= 0;
448 /* bfd mach number of last call. */
449 static unsigned long current_mach
= 0;
450 bfd_vma (*getword
) (const void *);
452 if (!opcodes_initialized
453 || info
->mach
!= current_mach
)
457 current_arch_mask
= compute_arch_mask (info
->mach
);
459 if (!opcodes_initialized
)
461 xmalloc (sparc_num_opcodes
* sizeof (sparc_opcode
*));
462 /* Reset the sorted table so we can resort it. */
463 for (i
= 0; i
< sparc_num_opcodes
; ++i
)
464 sorted_opcodes
[i
] = &sparc_opcodes
[i
];
465 qsort ((char *) sorted_opcodes
, sparc_num_opcodes
,
466 sizeof (sorted_opcodes
[0]), compare_opcodes
);
468 build_hash_table (sorted_opcodes
, opcode_hash_table
, sparc_num_opcodes
);
469 current_mach
= info
->mach
;
470 opcodes_initialized
= 1;
475 (*info
->read_memory_func
) (memaddr
, buffer
, sizeof (buffer
), info
);
479 (*info
->memory_error_func
) (status
, memaddr
, info
);
484 /* On SPARClite variants such as DANlite (sparc86x), instructions
485 are always big-endian even when the machine is in little-endian mode. */
486 if (info
->endian
== BFD_ENDIAN_BIG
|| info
->mach
== bfd_mach_sparc_sparclite
)
487 getword
= bfd_getb32
;
489 getword
= bfd_getl32
;
491 insn
= getword (buffer
);
493 info
->insn_info_valid
= 1; /* We do return this info. */
494 info
->insn_type
= dis_nonbranch
; /* Assume non branch insn. */
495 info
->branch_delay_insns
= 0; /* Assume no delay. */
496 info
->target
= 0; /* Assume no target known. */
498 for (op
= opcode_hash_table
[HASH_INSN (insn
)]; op
; op
= op
->next
)
500 const sparc_opcode
*opcode
= op
->opcode
;
502 /* If the insn isn't supported by the current architecture, skip it. */
503 if (! (opcode
->architecture
& current_arch_mask
))
506 if ((opcode
->match
& insn
) == opcode
->match
507 && (opcode
->lose
& insn
) == 0)
509 /* Nonzero means that we have found an instruction which has
510 the effect of adding or or'ing the imm13 field to rs1. */
511 int imm_added_to_rs1
= 0;
512 int imm_ored_to_rs1
= 0;
514 /* Nonzero means that we have found a plus sign in the args
515 field of the opcode table. */
518 /* Nonzero means we have an annulled branch. */
521 /* Do we have an `add' or `or' instruction combining an
522 immediate with rs1? */
523 if (opcode
->match
== 0x80102000) /* or */
525 if (opcode
->match
== 0x80002000) /* add */
526 imm_added_to_rs1
= 1;
528 if (X_RS1 (insn
) != X_RD (insn
)
529 && strchr (opcode
->args
, 'r') != 0)
530 /* Can't do simple format if source and dest are different. */
532 if (X_RS2 (insn
) != X_RD (insn
)
533 && strchr (opcode
->args
, 'O') != 0)
534 /* Can't do simple format if source and dest are different. */
537 (*info
->fprintf_func
) (stream
, opcode
->name
);
542 if (opcode
->args
[0] != ',')
543 (*info
->fprintf_func
) (stream
, " ");
545 for (s
= opcode
->args
; *s
!= '\0'; ++s
)
549 (*info
->fprintf_func
) (stream
, ",");
554 (*info
->fprintf_func
) (stream
, "a");
559 (*info
->fprintf_func
) (stream
, "pn");
564 (*info
->fprintf_func
) (stream
, "pt");
573 (*info
->fprintf_func
) (stream
, " ");
582 (*info
->fprintf_func
) (stream
, "%c", *s
);
586 (*info
->fprintf_func
) (stream
, "0");
589 #define reg(n) (*info->fprintf_func) (stream, "%%%s", reg_names[n])
605 #define freg(n) (*info->fprintf_func) (stream, "%%%s", freg_names[n])
606 #define fregx(n) (*info->fprintf_func) (stream, "%%%s", freg_names[((n) & ~1) | (((n) & 1) << 5)])
610 case 'v': /* Double/even. */
611 case 'V': /* Quad/multiple of 4. */
612 fregx (X_RS1 (insn
));
618 case 'B': /* Double/even. */
619 case 'R': /* Quad/multiple of 4. */
620 fregx (X_RS2 (insn
));
626 case 'H': /* Double/even. */
627 case 'J': /* Quad/multiple of 4. */
633 #define creg(n) (*info->fprintf_func) (stream, "%%c%u", (unsigned int) (n))
648 (*info
->fprintf_func
) (stream
, "%%hi(%#x)",
649 ((unsigned) 0xFFFFFFFF
650 & ((int) X_IMM22 (insn
) << 10)));
653 case 'i': /* 13 bit immediate. */
654 case 'I': /* 11 bit immediate. */
655 case 'j': /* 10 bit immediate. */
660 imm
= X_SIMM (insn
, 13);
662 imm
= X_SIMM (insn
, 11);
664 imm
= X_SIMM (insn
, 10);
666 /* Check to see whether we have a 1+i, and take
669 Note: because of the way we sort the table,
670 we will be matching 1+i rather than i+1,
671 so it is OK to assume that i is after +,
674 imm_added_to_rs1
= 1;
677 (*info
->fprintf_func
) (stream
, "%d", imm
);
679 (*info
->fprintf_func
) (stream
, "%#x", imm
);
683 case 'X': /* 5 bit unsigned immediate. */
684 case 'Y': /* 6 bit unsigned immediate. */
686 int imm
= X_IMM (insn
, *s
== 'X' ? 5 : 6);
689 (info
->fprintf_func
) (stream
, "%d", imm
);
691 (info
->fprintf_func
) (stream
, "%#x", (unsigned) imm
);
696 (info
->fprintf_func
) (stream
, "%ld", X_IMM (insn
, 3));
701 int mask
= X_MEMBAR (insn
);
702 int bit
= 0x40, printed_one
= 0;
706 (info
->fprintf_func
) (stream
, "0");
713 (info
->fprintf_func
) (stream
, "|");
714 name
= sparc_decode_membar (bit
);
715 (info
->fprintf_func
) (stream
, "%s", name
);
724 info
->target
= memaddr
+ SEX (X_DISP16 (insn
), 16) * 4;
725 (*info
->print_address_func
) (info
->target
, info
);
729 info
->target
= memaddr
+ SEX (X_DISP19 (insn
), 19) * 4;
730 (*info
->print_address_func
) (info
->target
, info
);
737 (*info
->fprintf_func
) (stream
, "%%fcc%c", *s
- '6' + '0');
741 (*info
->fprintf_func
) (stream
, "%%icc");
745 (*info
->fprintf_func
) (stream
, "%%xcc");
749 (*info
->fprintf_func
) (stream
, "%%ccr");
753 (*info
->fprintf_func
) (stream
, "%%fprs");
757 (*info
->fprintf_func
) (stream
, "%%asi");
761 (*info
->fprintf_func
) (stream
, "%%tick");
765 (*info
->fprintf_func
) (stream
, "%%pc");
769 if (X_RS1 (insn
) == 31)
770 (*info
->fprintf_func
) (stream
, "%%ver");
771 else if ((unsigned) X_RS1 (insn
) < 16)
772 (*info
->fprintf_func
) (stream
, "%%%s",
773 v9_priv_reg_names
[X_RS1 (insn
)]);
775 (*info
->fprintf_func
) (stream
, "%%reserved");
779 if ((unsigned) X_RD (insn
) < 15)
780 (*info
->fprintf_func
) (stream
, "%%%s",
781 v9_priv_reg_names
[X_RD (insn
)]);
783 (*info
->fprintf_func
) (stream
, "%%reserved");
787 if (X_RS1 (insn
) < 16 || X_RS1 (insn
) > 25)
788 (*info
->fprintf_func
) (stream
, "%%reserved");
790 (*info
->fprintf_func
) (stream
, "%%%s",
791 v9a_asr_reg_names
[X_RS1 (insn
)-16]);
795 if (X_RD (insn
) < 16 || X_RD (insn
) > 25)
796 (*info
->fprintf_func
) (stream
, "%%reserved");
798 (*info
->fprintf_func
) (stream
, "%%%s",
799 v9a_asr_reg_names
[X_RD (insn
)-16]);
804 const char *name
= sparc_decode_prefetch (X_RD (insn
));
807 (*info
->fprintf_func
) (stream
, "%s", name
);
809 (*info
->fprintf_func
) (stream
, "%ld", X_RD (insn
));
814 (*info
->fprintf_func
) (stream
, "%%asr%ld", X_RS1 (insn
));
818 (*info
->fprintf_func
) (stream
, "%%asr%ld", X_RD (insn
));
822 info
->target
= memaddr
+ SEX (X_DISP30 (insn
), 30) * 4;
823 (*info
->print_address_func
) (info
->target
, info
);
827 (*info
->fprintf_func
)
828 (stream
, "%#x", SEX (X_DISP22 (insn
), 22));
832 info
->target
= memaddr
+ SEX (X_DISP22 (insn
), 22) * 4;
833 (*info
->print_address_func
) (info
->target
, info
);
838 const char *name
= sparc_decode_asi (X_ASI (insn
));
841 (*info
->fprintf_func
) (stream
, "%s", name
);
843 (*info
->fprintf_func
) (stream
, "(%ld)", X_ASI (insn
));
848 (*info
->fprintf_func
) (stream
, "%%csr");
852 (*info
->fprintf_func
) (stream
, "%%fsr");
856 (*info
->fprintf_func
) (stream
, "%%psr");
860 (*info
->fprintf_func
) (stream
, "%%fq");
864 (*info
->fprintf_func
) (stream
, "%%cq");
868 (*info
->fprintf_func
) (stream
, "%%tbr");
872 (*info
->fprintf_func
) (stream
, "%%wim");
876 (*info
->fprintf_func
) (stream
, "%ld",
877 ((X_LDST_I (insn
) << 8)
882 (*info
->fprintf_func
) (stream
, "%%y");
888 int val
= *s
== 'U' ? X_RS1 (insn
) : X_RD (insn
);
889 const char *name
= sparc_decode_sparclet_cpreg (val
);
892 (*info
->fprintf_func
) (stream
, "%s", name
);
894 (*info
->fprintf_func
) (stream
, "%%cpreg(%d)", val
);
901 /* If we are adding or or'ing something to rs1, then
902 check to see whether the previous instruction was
903 a sethi to the same register as in the sethi.
904 If so, attempt to print the result of the add or
905 or (in this context add and or do the same thing)
906 and its symbolic value. */
907 if (imm_ored_to_rs1
|| imm_added_to_rs1
)
909 unsigned long prev_insn
;
914 (*info
->read_memory_func
)
915 (memaddr
- 4, buffer
, sizeof (buffer
), info
);
919 prev_insn
= getword (buffer
);
923 /* If it is a delayed branch, we need to look at the
924 instruction before the delayed branch. This handles
927 sethi %o1, %hi(_foo), %o1
929 or %o1, %lo(_foo), %o1 */
931 if (is_delayed_branch (prev_insn
))
934 errcode
= (*info
->read_memory_func
)
935 (memaddr
- 8, buffer
, sizeof (buffer
), info
);
939 prev_insn
= getword (buffer
);
943 /* If there was a problem reading memory, then assume
944 the previous instruction was not sethi. */
947 /* Is it sethi to the same register? */
948 if ((prev_insn
& 0xc1c00000) == 0x01000000
949 && X_RD (prev_insn
) == X_RS1 (insn
))
951 (*info
->fprintf_func
) (stream
, "\t! ");
953 ((unsigned) 0xFFFFFFFF
954 & ((int) X_IMM22 (prev_insn
) << 10));
955 if (imm_added_to_rs1
)
956 info
->target
+= X_SIMM (insn
, 13);
958 info
->target
|= X_SIMM (insn
, 13);
959 (*info
->print_address_func
) (info
->target
, info
);
960 info
->insn_type
= dis_dref
;
961 info
->data_size
= 4; /* FIXME!!! */
966 if (opcode
->flags
& (F_UNBR
|F_CONDBR
|F_JSR
))
968 /* FIXME -- check is_annulled flag. */
969 if (opcode
->flags
& F_UNBR
)
970 info
->insn_type
= dis_branch
;
971 if (opcode
->flags
& F_CONDBR
)
972 info
->insn_type
= dis_condbranch
;
973 if (opcode
->flags
& F_JSR
)
974 info
->insn_type
= dis_jsr
;
975 if (opcode
->flags
& F_DELAYED
)
976 info
->branch_delay_insns
= 1;
979 return sizeof (buffer
);
983 info
->insn_type
= dis_noninsn
; /* Mark as non-valid instruction. */
984 (*info
->fprintf_func
) (stream
, _("unknown"));
985 return sizeof (buffer
);