21 #include <sys/types.h>
29 #include "libiberty.h"
32 #define XNEWVEC(T, N) ((T *) malloc (sizeof (T) * (N)))
33 #define XCNEWVEC(T, N) ((T *) calloc ((N), sizeof (T)))
34 #define XNEW(T) ((T *) malloc (sizeof (T)))
35 #define xmalloc malloc
39 #define REGPREFIX "%%"
44 #define NUMOPCS tricore_numopcodes
45 #define NUMSFRS tricore_numsfrs
46 #define NUMPCPOPCS pcp_numopcodes
48 #define MATCHES_ISA(isa) \
49 (((isa) == TRICORE_GENERIC) \
50 || (((isa) & bfd_mach_rider_mask) & current_isa))
193 unsigned long o1,
o2, o3,
o4;
196 o1 = (
val & 0x003f0000) >> 16;
197 o2 = (
val & 0xf0000000) >> 22;
198 o3 = (
val & 0x03c00000) >> 12;
199 o4 = (
val & 0x0000f000) << 2;
247 unsigned long o1,
o2;
294 unsigned long o1,
o2;
319 unsigned long o1,
o2, o3;
1104 idx = pop->opcode & 0x3f;
1163 int i, needs_creg = 0, need_comma;
1167 static bool expect_lea =
false;
1169 static int load_areg[
NO_AREG] = {
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
false};
1170 static unsigned long load_hi_addr[
NO_AREG] = {0};
1171 static unsigned long load_addr = 0;
1172 static bool print_symbolic_address =
false;
1173 #define DPRINT (*info->fprintf_func)
1174 #define DFILE info->stream
1177 if (((*insn->
name ==
'n') && !strcmp (insn->
name,
"nor"))
1178 && ((insn->nr_operands == 1)
1179 || ((insn->nr_operands == 3)
1180 && (insn->args[2] ==
'n')
1204 if (memaddr != next_addr) {
1205 expect_lea = print_symbolic_address =
false;
1207 next_addr = memaddr + (insn->len32 ? 4 : 2);
1209 if (!strcmp (insn->
name,
"movh.a"))
1214 print_symbolic_address =
false;
1217 && (!strcmp (insn->
name,
"lea")
1218 || !strncmp (insn->
name,
"ld.", 3)
1219 || !strncmp (insn->
name,
"st.", 3)
1220 || !strncmp (insn->
name,
"swap", 4)
1221 || !strcmp (insn->
name,
"ldmst")))
1223 if (insn->nr_operands == 3)
1225 if ((!strcmp (insn->
name,
"lea")
1226 || !strncmp (insn->
name,
"ld.", 3)
1227 || !strcmp (insn->
name,
"ldmst"))
1232 print_symbolic_address =
true;
1238 print_symbolic_address =
true;
1242 print_symbolic_address =
false;
1245 if (!strncmp (insn->
name,
"ld.a", 4)) {
1247 }
else if (!strncmp (insn->
name,
"add.a", 5) || !strncmp (insn->
name,
"sub.a", 5) || !strcmp (insn->
name,
"mov.a") || !strncmp (insn->
name,
"addsc.a", 7)) {
1249 }
else if (!strcmp (insn->
name,
"mov.aa")) {
1251 }
else if (!strncmp (insn->
name,
"call", 4)) {
1253 for (
i = 2;
i < 8;
i++) {
1254 load_areg[
i] =
false;
1258 if (!strncmp(insn->
name,
"ret",3)) {
1260 for (
i = 2;
i < 8;
i++) {
1261 load_areg[
i] =
false;
1263 for (
i = 10;
i < 16;
i++) {
1264 load_areg[
i] =
false;
1268 if (!strcmp (insn->
name,
"mfcr") || !strcmp (insn->
name,
"mtcr")) {
1272 for (
i = 0;
i < insn->nr_operands; ++
i)
1274 need_comma = (
i < (insn->nr_operands - 1));
1275 switch (insn->args[
i])
1374 if (print_symbolic_address) {
1376 (*
info->print_address_func) (load_addr,
info);
1386 if (print_symbolic_address) {
1388 (*
info->print_address_func) (load_addr,
info);
1396 (*
info->print_address_func) (abs,
info);
1402 (*
info->print_address_func) (abs,
info);
1410 (*
info->print_address_func) (abs,
info);
1418 (*
info->print_address_func) (abs,
info);
1426 (*
info->print_address_func) (abs,
info);
1435 (*
info->print_address_func) (abs,
info);
1446 #ifdef RESOLVE_SFR_NAMES
1469 if ((insn->args[
i + 1] ==
'a') || (insn->args[
i + 1] ==
'd')) {
1493 if ((insn->args[
i + 1] ==
'a') || (insn->args[
i + 1] ==
'd')) {
1553 int idx = insn & 0x3f;
1561 if ((pinsn->
code->len32 != len32) || (insn & pinsn->
code->lose)) {
1565 fmt = pinsn->
code->format;
1567 if ((insn &
mask) != pinsn->
code->opcode) {
1576 return len32 ? 4 : 2;
1585 (*
info->fprintf_func) (
info->stream,
".hword 0x%04lx", (insn & 0xffff));
1601 unsigned long insn = 0, insn2 = 0,
val;
1605 static const char *pcp_ccodes[] =
1607 "uc",
"z",
"nz",
"v",
"c/ult",
"ugt",
"slt",
"sgt",
1608 "n",
"nn",
"nv",
"nc/uge",
"sge",
"sle",
"cnz",
"cnn"
1610 #define DPRINT (*info->fprintf_func)
1611 #define DFILE info->stream
1615 idx = (insn >> 11) & 0x1f;
1640 DPRINT (
DFILE,
".hword 0x%04lx", (insn & 0xffff));
1655 val = (insn >> 9) & 0x3;
1658 }
else if (
val == 1) {
1660 }
else if (
val == 2) {
1668 val = (insn >> 7) & 0x3;
1671 }
else if (
val == 1) {
1673 }
else if (
val == 2) {
1681 val = (insn >> 5) & 0x3;
1686 if (!strcmp (pop->
name,
"copy")) {
1687 val = ((insn >> 2) & 0x7) + 1;
1689 val = (insn >> 2) & 0x3;
1692 }
else if (
val == 3) {
1700 val = 8 << (insn & 0x3);
1711 val = (insn >> 10) & 0x1;
1716 val = (insn >> 9) & 0x1;
1721 val = (insn >> 8) & 0x1;
1726 val = (insn >> 7) & 0x1;
1741 rb = (insn >> 6) & 0x7;
1742 ra = (insn >> 3) & 0x7;
1743 val = 8 << (insn & 0x3);
1748 ra = (insn >> 6) & 0x7;
1754 rb = (insn >> 6) & 0x7;
1755 ra = (insn >> 3) & 0x7;
1757 if (!strcmp (pop->
name,
"ld.p") || !strcmp (pop->
name,
"st.p")) {
1765 ra = (insn >> 6) & 0x7;
1767 if (!strcmp (pop->
name,
"chkb")) {
1769 (
val & 0x20) ?
"set" :
"clr");
1770 }
else if (!strcmp (pop->
name,
"ldl.il")) {
1772 }
else if (!strcmp (pop->
name,
"ldl.iu")) {
1780 ra = (insn >> 6) & 0x7;
1781 val = 8 << (((insn >> 5) & 0x1) | ((insn >> 8) & 0x2));
1782 if ((!strcmp (pop->
name,
"set.f") || !strcmp (pop->
name,
"clr.f")) && ((insn & 0x1f) >=
val)) {
1783 DPRINT (
DFILE,
"[r%d], %lu ***ILLEGAL VALUE***, size=%lu", ra,
1791 rb = (insn >> 6) & 0x7;
1792 ra = (insn >> 3) & 0x7;
1793 if ((rb == 0) || (ra == 0) || (rb == 7) || (ra == 7) || (rb == ra)) {
1794 DPRINT (
DFILE,
"r%d, r%d ***ILLEGAL REGISTER USE***", rb, ra);
1816 DPRINT (
DFILE,
"cc_%s", pcp_ccodes[(insn >> 6) & 0xf]);
1832 if (!strcmp (pop->
name,
"jl"))
1838 (*
info->print_address_func) (memaddr + 2 + (
val << 1),
info);
1840 else if (!strcmp (pop->
name,
"jc"))
1846 (*
info->print_address_func) (memaddr + 2 + (
val << 1),
info);
1847 }
else if (!strcmp (pop->
name,
"jc.a")) {
1849 (*
info->print_address_func) ((memaddr & 0xffff0000) + (insn2 << 1),
info);
1870 return pop->
len32 ? 4 : 2;
1889 int len32 = 0, failure;
1890 unsigned long insn = 0;
1922 (*
info->memory_error_func) (failure, memaddr,
info);
1927 failure = (*
info->read_memory_func) (memaddr + 1, &
buffer[1], 1,
info);
1943 failure = (*
info->read_memory_func) (memaddr + 2, &
buffer[2], 2,
info);
1946 (*
info->fprintf_func) (
info->stream,
".hword 0x%04lx", insn);
RzBinInfo * info(RzBinFile *bf)
void tricore_init_arch_vars(unsigned long mach)
int(* decode)(const ut8 *, ebc_command_t *cmd)
return memset(p, 0, total)
BFD_HOST_U_64_BIT bfd_vma
static bfd_vma bfd_getl16(const void *p)
static bfd_vma bfd_getl32(const void *p)
unsigned long cexp[MAX_OPS]
const unsigned long opcode
static unsigned long extract_off18()
static struct sfrlist * sfrlink
static const char * find_core_reg(unsigned long addr)
static void decode_rrrw()
static struct insnlist * insnlink
static struct decoded_insn dec_insn
static void decode_rrrr()
static struct pcplist * pcpinsns[32]
static void decode_slro()
static void decode_abs PARAMS((void))
static int decode_tricore_insn(bfd_vma memaddr, unsigned long insn, int len32, struct disassemble_info *info)
static void decode_sbrn()
static tricore_isa current_isa
static void decode_rcrw()
static void decode_rcrr()
static void init_hash_tables()
static int decode_pcp_insn(bfd_vma memaddr, buffer, struct disassemble_info *info)
static void decode_rrr1()
static void decode_rrr2()
static void print_decoded_insn(bfd_vma memaddr, struct disassemble_info *info)
static void decode_absb()
static void decode_ssro()
static void decode_srrs()
static void decode_rcpw()
static struct pcplist * pcplink
static struct sfrlist * sfrs[256]
static void decode_rrpw()
static struct insnlist * insns[64]
int print_insn_tricore(bfd_vma memaddr, struct disassemble_info *info)
const struct tricore_core_register tricore_sfrs[]
struct tricore_opcode tricore_opcodes[]
struct pcp_opcode pcp_opcodes[]
enum _tricore_opcode_arch_val tricore_isa
enum _tricore_fmt tricore_fmt
#define bfd_mach_rider_mask
unsigned long tricore_opmask[]