23 #define xmalloc malloc
33 #include "libiberty.h"
36 #define XNEWVEC(T, N) ((T *) malloc (sizeof (T) * (N)))
37 #define XCNEWVEC(T, N) ((T *) calloc ((N), sizeof (T)))
38 #define XNEW(T) ((T *) malloc (sizeof (T)))
39 #define xmalloc malloc
44 #define MASK_V9 ((1 << SPARC_OPCODE_ARCH_V9) \
45 | (1 << SPARC_OPCODE_ARCH_V9A) \
46 | (1 << SPARC_OPCODE_ARCH_V9B))
48 #define V9_ONLY_P(insn) (! ((insn)->architecture & ~MASK_V9))
50 #define V9_P(insn) (((insn)->architecture & MASK_V9) != 0)
62 static int opcode_bits[4] = { 0x01c00000, 0x0, 0x01f80000, 0x01f80000 };
63 #define HASH_INSN(INSN) \
64 ((((INSN) >> 24) & 0xc0) | (((INSN) & opcode_bits[((INSN) >> 30) & 3]) >> 19))
74 #define SIGN_EXT(value, bits) \
75 ((((int)(value)) << ((8 * sizeof (int)) - (bits))) \
76 >> ((8 * sizeof (int)) - (bits)) )
79 {
"g0",
"g1",
"g2",
"g3",
"g4",
"g5",
"g6",
"g7",
80 "o0",
"o1",
"o2",
"o3",
"o4",
"o5",
"sp",
"o7",
81 "l0",
"l1",
"l2",
"l3",
"l4",
"l5",
"l6",
"l7",
82 "i0",
"i1",
"i2",
"i3",
"i4",
"i5",
"fp",
"i7",
83 "f0",
"f1",
"f2",
"f3",
"f4",
"f5",
"f6",
"f7",
84 "f8",
"f9",
"f10",
"f11",
"f12",
"f13",
"f14",
"f15",
85 "f16",
"f17",
"f18",
"f19",
"f20",
"f21",
"f22",
"f23",
86 "f24",
"f25",
"f26",
"f27",
"f28",
"f29",
"f30",
"f31",
87 "f32",
"f33",
"f34",
"f35",
"f36",
"f37",
"f38",
"f39",
88 "f40",
"f41",
"f42",
"f43",
"f44",
"f45",
"f46",
"f47",
89 "f48",
"f49",
"f50",
"f51",
"f52",
"f53",
"f54",
"f55",
90 "f56",
"f57",
"f58",
"f59",
"f60",
"f61",
"f62",
"f63",
92 "y",
"psr",
"wim",
"tbr",
"pc",
"npc",
"fpsr",
"cpsr"
95 #define freg_names (®_names[4 * 8])
101 "tpc",
"tnpc",
"tstate",
"tt",
"tick",
"tba",
"pstate",
"tl",
102 "pil",
"cwp",
"cansave",
"canrestore",
"cleanwin",
"otherwin",
111 "hpstate",
"htstate",
"resv2",
"hintp",
"resv4",
"htba",
"hver",
112 "resv7",
"resv8",
"resv9",
"resv10",
"resv11",
"resv12",
"resv13",
113 "resv14",
"resv15",
"resv16",
"resv17",
"resv18",
"resv19",
"resv20",
114 "resv21",
"resv22",
"resv23",
"resv24",
"resv25",
"resv26",
"resv27",
115 "resv28",
"resv29",
"resv30",
"hstick_cmpr"
122 "pcr",
"pic",
"dcr",
"gsr",
"set_softint",
"clear_softint",
123 "softint",
"tick_cmpr",
"stick",
"stick_cmpr"
129 #define X_RD(i) (((i) >> 25) & 0x1f)
130 #define X_RS1(i) (((i) >> 14) & 0x1f)
131 #define X_LDST_I(i) (((i) >> 13) & 1)
132 #define X_ASI(i) (((i) >> 5) & 0xff)
133 #define X_RS2(i) (((i) >> 0) & 0x1f)
134 #define X_IMM(i,n) (((i) >> 0) & ((1 << (n)) - 1))
135 #define X_SIMM(i,n) SIGN_EXT (X_IMM ((i), (n)), (n))
136 #define X_DISP22(i) (((i) >> 0) & 0x3fffff)
137 #define X_IMM22(i) X_DISP22 (i)
138 #define X_DISP30(i) (((i) >> 0) & 0x3fffffff)
141 #define X_DISP16(i) (((((i) >> 20) & 3) << 14) | (((i) >> 0) & 0x3fff))
142 #define X_DISP19(i) (((i) >> 0) & 0x7ffff)
143 #define X_MEMBAR(i) ((i) & 0x7f)
266 unsigned long int match0 = op0->
match, match1 = op1->
match;
267 unsigned long int lose0 = op0->
lose, lose1 = op1->
lose;
268 register unsigned int i;
297 _(
"Internal error: bad sparc-opcode.h: \"%s\", %#.8lx, %#.8lx\n"),
298 op0->
name, match0, lose0);
308 _(
"Internal error: bad sparc-opcode.h: \"%s\", %#.8lx, %#.8lx\n"),
309 op1->
name, match1, lose1);
316 for (
i = 0;
i < 32;
i++)
318 unsigned long int x = 1 <<
i;
319 int x0 = (match0 &
x) != 0;
320 int x1 = (match1 &
x) != 0;
327 for (
i = 0;
i < 32;
i++)
329 unsigned long int x = 1 <<
i;
330 int x0 = (lose0 &
x) != 0;
331 int x1 = (lose1 &
x) != 0;
345 if (alias_diff != 0) {
361 _ (
"Internal error: bad sparc-opcode.h: \"%s\" == \"%s\"\n"),
368 int length_diff = strlen (op0->
args) - strlen (op1->
args);
370 if (length_diff != 0) {
378 char *p0 = (
char *) strchr (op0->
args,
'+');
379 char *p1 = (
char *) strchr (op1->
args,
'+');
386 if (p0[-1] ==
'i' && p1[1] ==
'i') {
390 if (p0[1] ==
'i' && p1[-1] ==
'i') {
399 int i0 = strncmp (op0->
args,
"i,1", 3) == 0;
400 int i1 = strncmp (op1->
args,
"i,1", 3) == 0;
433 if (hash_buf !=
NULL) {
436 hash_buf =
calloc (
sizeof (* hash_buf), num_opcodes);
440 for (
i = num_opcodes - 1;
i >= 0; --
i)
446 h->opcode = opcode_table[
i];
453 int min_count = num_opcodes,
max_count = 0;
458 if (hash_count[
i] < min_count)
459 min_count = hash_count[
i];
462 total += hash_count[
i];
465 printf (
"Opcode hash table stats: min %d, max %d, ave %f\n",
487 static int opcodes_initialized = 0;
489 static unsigned long current_mach = 0;
490 bfd_vma (*getword) (
const void *);
492 if (!opcodes_initialized
493 ||
info->mach != current_mach)
499 if (!opcodes_initialized) {
511 current_mach =
info->mach;
512 opcodes_initialized = 1;
536 info->insn_info_valid = 1;
538 info->branch_delay_insns = 0;
555 int imm_added_to_rs1 = 0;
556 int imm_ored_to_rs1 = 0;
571 imm_added_to_rs1 = 1;
617 if (*
s !=
'[' && !brackets) {
619 }
else if (*
s ==
']') {
623 }
else if (*
s ==
'[') {
643 #define reg(n) (*info->fprintf_func) (stream, "%%%s", reg_names[n])
659 #define freg(n) (*info->fprintf_func) (stream, "%%%s", freg_names[n])
660 #define fregx(n) (*info->fprintf_func) (stream, "%%%s", freg_names[((n) & ~1) | (((n) & 1) << 5)])
687 #define creg(n) (*info->fprintf_func) (stream, "%%c%u", (unsigned int) (n))
703 ((
unsigned) 0xFFFFFFFF
704 & ((
int)
X_IMM22 (insn) << 10)));
715 }
else if (*
s ==
'I') {
729 imm_added_to_rs1 = 1;
743 int imm =
X_IMM (insn, *
s ==
'X' ? 5 : 6);
760 int bit = 0x40, printed_one = 0;
795 (*
info->fprintf_func) (
stream,
"%%fcc%c", *
s -
'6' +
'0');
827 if (
X_RS1 (insn) == 31) {
829 }
else if ((
unsigned)
X_RS1 (insn) < 17) {
838 if ((
unsigned)
X_RD (insn) < 17) {
847 if ((
unsigned)
X_RS1 (insn) < 32) {
856 if ((
unsigned)
X_RD (insn) < 32) {
874 if (
X_RD (insn) < 16 ||
X_RD (insn) > 25) {
908 (*
info->fprintf_func)
990 if (imm_ored_to_rs1 || imm_added_to_rs1)
992 unsigned long prev_insn;
1002 prev_insn = getword (
buffer);
1022 prev_insn = getword (
buffer);
1031 if ((prev_insn & 0xc1c00000) == 0x01000000
1037 & ((
int)
X_IMM22 (prev_insn) << 10));
1038 if (imm_added_to_rs1) {
1045 info->data_size = 4;
1064 info->branch_delay_insns = 1;
RzBinInfo * info(RzBinFile *bf)
_Use_decl_annotations_ int __cdecl printf(const char *const _Format,...)
RZ_API void Ht_() free(HtName_(Ht) *ht)
return memset(p, 0, total)
@ SPARC_OPCODE_ARCH_SPARCLITE
@ SPARC_OPCODE_ARCH_SPARCLET
#define SPARC_OPCODE_ARCH_MASK(arch)
const int sparc_num_opcodes
const char * sparc_decode_asi(int)
const struct sparc_opcode sparc_opcodes[]
const char * sparc_decode_membar(int)
const char * sparc_decode_prefetch(int)
const char * sparc_decode_sparclet_cpreg(int)
void * calloc(size_t number, size_t size)
static const char struct stat static buf struct stat static buf static vhangup int status
static void struct sockaddr socklen_t static fromlen static backlog static fork char char char static envp int struct rusage static rusage struct utsname static buf struct sembuf unsigned
#define bfd_mach_sparc_sparclet
#define bfd_mach_sparc_v8plusa
#define bfd_mach_sparc_v8plusb
#define bfd_mach_sparc_v9b
#define bfd_mach_sparc_sparclite_le
#define bfd_mach_sparc_v8plus
BFD_HOST_U_64_BIT bfd_vma
static bfd_vma bfd_getb32(const void *p)
#define bfd_mach_sparc_sparclite
#define bfd_mach_sparc_v9
static bfd_vma bfd_getl32(const void *p)
#define bfd_mach_sparc_v9a
void qsort(void *a, size_t n, size_t es, int(*cmp)(const void *, const void *))
static int opcode_bits[4]
static int compare_opcodes(const void *a, const void *b)
int print_insn_sparc(bfd_vma memaddr, disassemble_info *info)
static sparc_opcode_hash * opcode_hash_table[HASH_SIZE]
static int is_delayed_branch(unsigned long insn)
struct sparc_opcode_hash sparc_opcode_hash
static void build_hash_table(const sparc_opcode **opcode_table, sparc_opcode_hash **hash_table, int num_opcodes)
static unsigned int current_arch_mask
static int compute_arch_mask(unsigned long mach)
#define SIGN_EXT(value, bits)
static char * v9_priv_reg_names[]
static char * v9a_asr_reg_names[]
static char * v9_hpriv_reg_names[]
static char * reg_names[]
static const sparc_opcode ** sorted_opcodes
const sparc_opcode * opcode
struct sparc_opcode_hash * next