26 #include "libiberty.h"
62 #define BIT(word, n) ((word) & (1 << (n)))
64 #define BITS(word, s, e) (((word) << (sizeof(word) * 8 - 1 - (e))) >> ((s) + (sizeof(word) * 8 - 1 - (e))))
66 #define OPCODE(word) (BITS((word), 27, 31))
67 #define FIELDA(word) (BITS((word), 21, 26))
68 #define FIELDB(word) (BITS((word), 15, 20))
69 #define FIELDC(word) (BITS((word), 9, 14))
73 #define FIELDD(word) (BITS(((signed int)(word)), 0, 8))
75 #define PUT_NEXT_WORD_IN(a) \
77 if (is_limm == 1 && !NEXT_WORD(1)) { \
78 mwerror(state, _("Illegal limm reference in last instruction!\n")); \
80 (a) = state->words[1]; \
83 #define CHECK_FLAG_COND_NULLIFY() \
85 if (is_shimm == 0) { \
86 flag = BIT(state->words[0], 8); \
87 state->nullifyMode = BITS(state->words[0], 5, 6); \
88 cond = BITS(state->words[0], 0, 4); \
92 #define CHECK_COND() \
95 cond = BITS(state->words[0], 0, 4); \
98 #define CHECK_FIELD(field) \
100 if ((field) == 62) { \
103 PUT_NEXT_WORD_IN(field); \
104 } else if ((field) > 60) { \
107 flag = ((field) == 61); \
108 (field) = FIELDD(state->words[0]); \
112 #define CHECK_FIELD_A() \
114 fieldA = FIELDA(state->words[0]); \
121 #define CHECK_FIELD_B() \
123 fieldB = FIELDB(state->words[0]); \
124 CHECK_FIELD(fieldB); \
127 #define CHECK_FIELD_C() \
129 fieldC = FIELDC(state->words[0]); \
130 CHECK_FIELD(fieldC); \
133 #define IS_SMALL(x) (((field##x) < 10) && ((field##x) >= 0))
134 #define IS_REG(x) (field##x##isReg)
135 #define WRITE_FORMAT_LB_Rx_RB(x) WRITE_FORMAT(x, "[", "]", "", "")
136 #define WRITE_FORMAT_x_COMMA_LB(x) WRITE_FORMAT(x, "", ", [", "", ", [")
137 #define WRITE_FORMAT_COMMA_x_RB(x) WRITE_FORMAT(x, ", ", "]", ", ", "]")
138 #define WRITE_FORMAT_x_RB(x) WRITE_FORMAT(x, "", "]", "", "]")
139 #define WRITE_FORMAT_COMMA_x(x) WRITE_FORMAT(x, ", ", "", ", ", "")
140 #define WRITE_FORMAT_x_COMMA(x) WRITE_FORMAT(x, "", ", ", "", ", ")
141 #define WRITE_FORMAT_x(x) WRITE_FORMAT(x, "", "", "", "")
142 #define WRITE_FORMAT(x, cb1, ca1, cb, ca) strcat(formatString, \
143 (IS_REG(x) ? cb1 "%r" ca1 : usesAuxReg ? cb "%a" ca \
144 : IS_SMALL(x) ? cb "%d" ca \
146 #define WRITE_FORMAT_RB() strcat(formatString, "]")
147 #define WRITE_COMMENT(str) (state->comm[state->commNum++] = (str))
148 #define WRITE_NOP_COMMENT() \
149 if (!fieldAisReg && !flag) \
150 WRITE_COMMENT("nop");
152 #define NEXT_WORD(x) (offset += 4, state->words[x])
154 #define add_target(x) (state->targets[state->tcnt++] = (x))
158 if (
state->coreRegName) {
166 if (
state->auxRegName) {
174 if (
state->condCodeName) {
185 if (
state->instName) {
193 if (
state->err != 0) {
201 unsigned int j,
i =
state->acnt;
220 int size, leading_zero, regMap[2];
223 va_start(ap, format);
225 if (!
buf || !format) {
263 while (*
p >=
'0' && *
p <=
'9') {
269 #define inc_bp() bp = bp + strlen(bp)
272 unsigned u = va_arg(ap,
int);
278 int val = va_arg(ap,
int);
292 int val = va_arg(ap,
int);
303 int val = va_arg(ap,
int);
305 #define REG2NAME(num, name) \
307 sprintf(bp, "" name); \
308 regMap[((num) < 32) ? 0 : 1] |= 1 << ((num) - (((num) < 32) ? 0 : 32)); \
334 int val = va_arg(ap,
int);
335 #define AUXREG2NAME(num, name) \
336 case num: sprintf(bp, "" name); break;
359 sprintf(bp,
"%s", va_arg(ap,
char *));
363 fprintf(stderr,
"?? format %c\n",
p[-1]);
376 "",
"z",
"nz",
"p",
"n",
"c",
"nc",
"v",
377 "nv",
"gt",
"ge",
"lt",
"le",
"hi",
"ls",
"pnz"
382 const char *instrName,
384 int condCodeIsPartOfName,
389 strncpy(
state->instrBuffer, instrName,
sizeof(
state->instrBuffer) - 1);
393 if (!condCodeIsPartOfName) {
394 strcat(
state->instrBuffer,
".");
404 strcat(
state->instrBuffer, cc);
407 strcat(
state->instrBuffer,
".f");
409 switch (
state->nullifyMode) {
411 strcat(
state->instrBuffer,
".d");
414 strcat(
state->instrBuffer,
".jd");
420 strcat(
state->instrBuffer,
".x");
423 strcat(
state->instrBuffer,
".a");
426 strcat(
state->instrBuffer,
".di");
430 #define write_instr_name() \
432 write_instr_name_(state, instrName, cond, condCodeIsPartOfName, \
433 flag, signExtend, addrWriteBack, directMem); \
434 formatString[0] = '\0'; \
460 int condCodeIsPartOfName = 0;
462 const char *instrName;
464 int fieldAisReg = 1, fieldBisReg = 1, fieldCisReg = 1;
465 int fieldA, fieldB, fieldC = 0;
466 int flag = 0,
cond = 0, is_shimm = 0, is_limm = 0;
467 int signExtend = 0, addrWriteBack = 0, directMem = 0;
472 char formatString[60];
475 state->instructionLen = 4;
480 state->_mem_load = 0;
481 state->_ea_present = 0;
482 state->_load_len = 0;
495 condCodeIsPartOfName = 0;
502 switch (
state->_opcode) {
507 state->_load_len = 4;
511 state->_load_len = 1;
515 state->_load_len = 2;
518 instrName =
"??? (0[3])";
533 state->_load_len = 4;
537 state->_load_len = 1;
541 state->_load_len = 2;
544 instrName =
"??? (1[3])";
558 case 0: instrName =
"st";
break;
559 case 1: instrName =
"stb";
break;
560 case 2: instrName =
"stw";
break;
562 instrName =
"??? (2[3])";
638 case op_BC: instrName =
"b";
659 condCodeIsPartOfName = 1;
668 switch (
state->_opcode) {
669 case op_ADD: instrName = (repeatsOp ?
"asl" :
"add");
break;
670 case op_ADC: instrName = (repeatsOp ?
"rlc" :
"adc");
break;
671 case op_AND: instrName = (repeatsOp ?
"mov" :
"and");
break;
675 case op_SUB: instrName =
"sub";
break;
676 case op_SBC: instrName =
"sbc";
break;
677 case op_OR: instrName =
"or";
break;
678 case op_BIC: instrName =
"bic";
break;
681 if (
state->words[0] == 0x7fffffff) {
705 fieldAisReg = fieldBisReg = fieldCisReg = 1;
706 flag =
cond = is_shimm = is_limm = 0;
708 signExtend = addrWriteBack = directMem = 0;
711 switch (decodingClass) {
721 if (!ignoreFirstOpd) {
729 fieldA, fieldB, fieldC);
746 if (!ignoreFirstOpd) {
769 fieldA =
BITS(
state->words[0], 7, 26) << 2;
770 fieldA = (fieldA << 10) >> 10;
784 strcat(formatString,
"%s");
798 fieldA = (fieldB >> 25) & 0x7F;
799 fieldB = (fieldB & 0xFFFFFF) << 2;
813 state->register_for_indirect_jump = fieldB;
836 state->_ea_present = 1;
838 state->ea_reg1 = fieldB;
840 state->_offset += fieldB;
843 state->ea_reg2 = fieldC;
845 state->_offset += fieldC;
847 state->_mem_load = 1;
849 directMem =
BIT(
state->words[0], 5);
850 addrWriteBack =
BIT(
state->words[0], 3);
851 signExtend =
BIT(
state->words[0], 0);
855 if (fieldBisReg || fieldB != 0) {
863 fieldA, fieldB, fieldC);
872 state->_ea_present = 1;
873 state->_offset = fieldC;
874 state->_mem_load = 1;
876 state->ea_reg1 = fieldB;
880 state->_offset += fieldB,
state->_ea_present = 0;
883 directMem =
BIT(
state->words[0], 14);
884 addrWriteBack =
BIT(
state->words[0], 12);
885 signExtend =
BIT(
state->words[0], 9);
890 fieldB =
state->_offset;
894 if (fieldC != 0 && !
BIT(
state->words[0], 13)) {
902 fieldA, fieldB, fieldC);
912 state->_ea_present = 1;
913 state->_offset = fieldA;
915 state->ea_reg1 = fieldB;
920 state->_offset += fieldB,
state->_ea_present = 0;
923 directMem =
BIT(
state->words[0], 26);
924 addrWriteBack =
BIT(
state->words[0], 24);
930 fieldB =
state->_offset;
934 if (fieldBisReg && fieldA != 0) {
942 fieldC, fieldB, fieldA);
961 state->operandBuffer[0] =
'\0';
979 mwerror(
state,
"Bad decoding class in ARC disassembler");
1068 (*func)(
stream,
"%s ",
s.instrBuffer);
1076 (*func)(
stream,
"%s",
s.operandBuffer);
1079 return s.instructionLen;
disassemble_info tm_print_insn_info
#define WRITE_FORMAT_COMMA_x(x)
static const char * cond_code_name(struct arcDisState *state, int val)
#define write_instr_name()
#define REG2NAME(num, name)
static const char * _condCodeName(void *cpp_this ATTRIBUTE_UNUSED, int num)
static void arc_sprintf(struct arcDisState *state, char *buf, const char *format,...)
static const char * condName[]
#define CHECK_FLAG_COND_NULLIFY()
#define WRITE_FORMAT_x(x)
static const char * _auxRegName(void *cpp_this ATTRIBUTE_UNUSED, int regnum)
#define WRITE_FORMAT_COMMA_x_RB(x)
#define WRITE_FORMAT_RB()
static const char * _instName(void *_this ATTRIBUTE_UNUSED, int majop, int minop, int *flags)
static int dsmOneArcInst(bfd_vma addr, struct arcDisState *state)
#define AUXREG2NAME(num, name)
static void mwerror(struct arcDisState *state, const char *msg)
#define WRITE_FORMAT_x_COMMA_LB(x)
int ARCTangent_decodeInstr(bfd_vma address, disassemble_info *info)
#define WRITE_NOP_COMMENT()
static const char * post_address(struct arcDisState *state, int addr)
static const char * instruction_name(struct arcDisState *state, int op1, int op2, int *flags)
static const char * _coreRegName(void *cpp_this ATTRIBUTE_UNUSED, int regnum)
#define WRITE_FORMAT_x_COMMA(x)
static const char * core_reg_name(struct arcDisState *state, int val)
static const char * aux_reg_name(struct arcDisState *state, int val)
#define WRITE_FORMAT_x_RB(x)
static void write_instr_name_(struct arcDisState *state, const char *instrName, int cond, int condCodeIsPartOfName, int flag, int signExtend, int addrWriteBack, int directMem)
#define __TRANSLATION_REQUIRED(state)
const char * arcExtMap_auxRegName(long address)
const char * arcExtMap_instName(int opcode, int insn, int *flags)
const char * arcExtMap_condCodeName(int code)
const char * arcExtMap_coreRegName(int regnum)
RzBinInfo * info(RzBinFile *bf)
int(* fprintf_ftype)(void *, const char *,...) ATTRIBUTE_FPTR_PRINTF_2
return memset(p, 0, total)
static static fork const void static count static fd const char const char static newpath char char char static envp time_t static t const char static mode static whence const char static dir time_t static t unsigned static seconds const char struct utimbuf static buf static inc static sig const char static mode static oldfd struct tms static buf static getgid static geteuid const char static filename static arg static mask struct ustat static ubuf static getppid static setsid static egid sigset_t static set struct timeval struct timezone static tz fd_set fd_set fd_set struct timeval static timeout const char char static bufsiz const char static swapflags void static offset const char static length static mode static who const char struct statfs static buf unsigned unsigned num
static const char struct stat static buf struct stat static buf static vhangup int status
BFD_HOST_U_64_BIT bfd_vma
static bfd_vma bfd_getb32(const void *p)
static bfd_vma bfd_getl32(const void *p)
static struct sockaddr static addrlen static backlog const void static flags void flags
static struct sockaddr static addrlen static backlog const void msg
#define cond(bop, top, mask, flags)