capstone/arch/ARM/ARMMapping.c

552 lines
12 KiB
C
Raw Normal View History

/* Capstone Disassembly Engine */
2019-03-16 15:22:15 +08:00
/* By Nguyen Anh Quynh <aquynh@gmail.com>, 2013-2019 */
#ifdef CAPSTONE_HAS_ARM
2013-11-27 12:11:31 +08:00
#include <stdio.h> // debug
#include <string.h>
#include "../../cs_priv.h"
2013-11-27 12:11:31 +08:00
#include "ARMMapping.h"
2013-11-27 12:11:31 +08:00
#define GET_INSTRINFO_ENUM
#include "ARMGenInstrInfo.inc"
#ifndef CAPSTONE_DIET
Constify backend data (#1040) * Constify string literals Use -Wwrite-strings to force string literals to be of type "const char[]", then fix up all warning fallout. * Constify common infrastructure Step one in allowing backend data to be readonly. Minimal changes to backends for now; just set all pointers in common structs that aren't modified to const. * Constify AArch64 backend Section size changes within libcapstone.so are -.rodata 602587 -.data.rel.ro 228416 -.data 1003746 +.rodata 769051 +.data.rel.ro 241120 +.data 824578 * Constify ARM backend Section size changes within libcapstone.so are -.rodata 769051 -.data.rel.ro 241120 -.data 824578 +.rodata 959835 +.data.rel.ro 245120 +.data 629506 * Constify Mips backend Section size changes within libcapstone.so are -.rodata 959835 -.data.rel.ro 245120 -.data 629506 +.rodata 1069851 +.data.rel.ro 256416 +.data 508194 * Constify PowerPC backend Section size changes within libcapstone.so are -.rodata 1069851 -.data.rel.ro 256416 -.data 508194 +.rodata 1142715 +.data.rel.ro 272224 +.data 419490 * Constify Sparc backend Section size changes within libcapstone.so are -.rodata 1142715 -.data.rel.ro 272224 -.data 419490 +.rodata 1175227 +.data.rel.ro 277536 +.data 381666 * Constify SystemZ backend Section size changes within libcapstone.so are -.rodata 1175227 -.data.rel.ro 277536 -.data 381666 +.rodata 1221883 +.data.rel.ro 278016 +.data 334498 * Constify X86 backend Section size changes within libcapstone.so are -.rodata 1221883 -.data.rel.ro 278016 -.data 334498 +.rodata 1533531 +.data.rel.ro 281184 +.data 19714 * Constify XCore backend Section size changes within libcapstone.so are -.rodata 1533531 -.data.rel.ro 281184 -.data 19714 +.rodata 1553026 +.data.rel.ro 281280 +.data 40
2017-10-22 08:45:40 +08:00
static const name_map reg_name_maps[] = {
2013-11-27 12:11:31 +08:00
{ ARM_REG_INVALID, NULL },
{ ARM_REG_APSR, "apsr"},
{ ARM_REG_APSR_NZCV, "apsr_nzcv"},
{ ARM_REG_CPSR, "cpsr"},
{ ARM_REG_FPEXC, "fpexc"},
{ ARM_REG_FPINST, "fpinst"},
{ ARM_REG_FPSCR, "fpscr"},
{ ARM_REG_FPSCR_NZCV, "fpscr_nzcv"},
{ ARM_REG_FPSID, "fpsid"},
{ ARM_REG_ITSTATE, "itstate"},
{ ARM_REG_LR, "lr"},
{ ARM_REG_PC, "pc"},
{ ARM_REG_SP, "sp"},
{ ARM_REG_SPSR, "spsr"},
{ ARM_REG_D0, "d0"},
{ ARM_REG_D1, "d1"},
{ ARM_REG_D2, "d2"},
{ ARM_REG_D3, "d3"},
{ ARM_REG_D4, "d4"},
{ ARM_REG_D5, "d5"},
{ ARM_REG_D6, "d6"},
{ ARM_REG_D7, "d7"},
{ ARM_REG_D8, "d8"},
{ ARM_REG_D9, "d9"},
{ ARM_REG_D10, "d10"},
{ ARM_REG_D11, "d11"},
{ ARM_REG_D12, "d12"},
{ ARM_REG_D13, "d13"},
{ ARM_REG_D14, "d14"},
{ ARM_REG_D15, "d15"},
{ ARM_REG_D16, "d16"},
{ ARM_REG_D17, "d17"},
{ ARM_REG_D18, "d18"},
{ ARM_REG_D19, "d19"},
{ ARM_REG_D20, "d20"},
{ ARM_REG_D21, "d21"},
{ ARM_REG_D22, "d22"},
{ ARM_REG_D23, "d23"},
{ ARM_REG_D24, "d24"},
{ ARM_REG_D25, "d25"},
{ ARM_REG_D26, "d26"},
{ ARM_REG_D27, "d27"},
{ ARM_REG_D28, "d28"},
{ ARM_REG_D29, "d29"},
{ ARM_REG_D30, "d30"},
{ ARM_REG_D31, "d31"},
{ ARM_REG_FPINST2, "fpinst2"},
{ ARM_REG_MVFR0, "mvfr0"},
{ ARM_REG_MVFR1, "mvfr1"},
{ ARM_REG_MVFR2, "mvfr2"},
2013-11-27 12:11:31 +08:00
{ ARM_REG_Q0, "q0"},
{ ARM_REG_Q1, "q1"},
{ ARM_REG_Q2, "q2"},
{ ARM_REG_Q3, "q3"},
{ ARM_REG_Q4, "q4"},
{ ARM_REG_Q5, "q5"},
{ ARM_REG_Q6, "q6"},
{ ARM_REG_Q7, "q7"},
{ ARM_REG_Q8, "q8"},
{ ARM_REG_Q9, "q9"},
{ ARM_REG_Q10, "q10"},
{ ARM_REG_Q11, "q11"},
{ ARM_REG_Q12, "q12"},
{ ARM_REG_Q13, "q13"},
{ ARM_REG_Q14, "q14"},
{ ARM_REG_Q15, "q15"},
{ ARM_REG_R0, "r0"},
{ ARM_REG_R1, "r1"},
{ ARM_REG_R2, "r2"},
{ ARM_REG_R3, "r3"},
{ ARM_REG_R4, "r4"},
{ ARM_REG_R5, "r5"},
{ ARM_REG_R6, "r6"},
{ ARM_REG_R7, "r7"},
{ ARM_REG_R8, "r8"},
{ ARM_REG_R9, "sb"},
{ ARM_REG_R10, "sl"},
{ ARM_REG_R11, "fp"},
{ ARM_REG_R12, "ip"},
2013-11-27 12:11:31 +08:00
{ ARM_REG_S0, "s0"},
{ ARM_REG_S1, "s1"},
{ ARM_REG_S2, "s2"},
{ ARM_REG_S3, "s3"},
{ ARM_REG_S4, "s4"},
{ ARM_REG_S5, "s5"},
{ ARM_REG_S6, "s6"},
{ ARM_REG_S7, "s7"},
{ ARM_REG_S8, "s8"},
{ ARM_REG_S9, "s9"},
{ ARM_REG_S10, "s10"},
{ ARM_REG_S11, "s11"},
{ ARM_REG_S12, "s12"},
{ ARM_REG_S13, "s13"},
{ ARM_REG_S14, "s14"},
{ ARM_REG_S15, "s15"},
{ ARM_REG_S16, "s16"},
{ ARM_REG_S17, "s17"},
{ ARM_REG_S18, "s18"},
{ ARM_REG_S19, "s19"},
{ ARM_REG_S20, "s20"},
{ ARM_REG_S21, "s21"},
{ ARM_REG_S22, "s22"},
{ ARM_REG_S23, "s23"},
{ ARM_REG_S24, "s24"},
{ ARM_REG_S25, "s25"},
{ ARM_REG_S26, "s26"},
{ ARM_REG_S27, "s27"},
{ ARM_REG_S28, "s28"},
{ ARM_REG_S29, "s29"},
{ ARM_REG_S30, "s30"},
{ ARM_REG_S31, "s31"},
};
Constify backend data (#1040) * Constify string literals Use -Wwrite-strings to force string literals to be of type "const char[]", then fix up all warning fallout. * Constify common infrastructure Step one in allowing backend data to be readonly. Minimal changes to backends for now; just set all pointers in common structs that aren't modified to const. * Constify AArch64 backend Section size changes within libcapstone.so are -.rodata 602587 -.data.rel.ro 228416 -.data 1003746 +.rodata 769051 +.data.rel.ro 241120 +.data 824578 * Constify ARM backend Section size changes within libcapstone.so are -.rodata 769051 -.data.rel.ro 241120 -.data 824578 +.rodata 959835 +.data.rel.ro 245120 +.data 629506 * Constify Mips backend Section size changes within libcapstone.so are -.rodata 959835 -.data.rel.ro 245120 -.data 629506 +.rodata 1069851 +.data.rel.ro 256416 +.data 508194 * Constify PowerPC backend Section size changes within libcapstone.so are -.rodata 1069851 -.data.rel.ro 256416 -.data 508194 +.rodata 1142715 +.data.rel.ro 272224 +.data 419490 * Constify Sparc backend Section size changes within libcapstone.so are -.rodata 1142715 -.data.rel.ro 272224 -.data 419490 +.rodata 1175227 +.data.rel.ro 277536 +.data 381666 * Constify SystemZ backend Section size changes within libcapstone.so are -.rodata 1175227 -.data.rel.ro 277536 -.data 381666 +.rodata 1221883 +.data.rel.ro 278016 +.data 334498 * Constify X86 backend Section size changes within libcapstone.so are -.rodata 1221883 -.data.rel.ro 278016 -.data 334498 +.rodata 1533531 +.data.rel.ro 281184 +.data 19714 * Constify XCore backend Section size changes within libcapstone.so are -.rodata 1533531 -.data.rel.ro 281184 -.data 19714 +.rodata 1553026 +.data.rel.ro 281280 +.data 40
2017-10-22 08:45:40 +08:00
static const name_map reg_name_maps2[] = {
{ ARM_REG_INVALID, NULL },
{ ARM_REG_APSR, "apsr"},
{ ARM_REG_APSR_NZCV, "apsr_nzcv"},
{ ARM_REG_CPSR, "cpsr"},
{ ARM_REG_FPEXC, "fpexc"},
{ ARM_REG_FPINST, "fpinst"},
{ ARM_REG_FPSCR, "fpscr"},
{ ARM_REG_FPSCR_NZCV, "fpscr_nzcv"},
{ ARM_REG_FPSID, "fpsid"},
{ ARM_REG_ITSTATE, "itstate"},
{ ARM_REG_LR, "lr"},
{ ARM_REG_PC, "pc"},
{ ARM_REG_SP, "sp"},
{ ARM_REG_SPSR, "spsr"},
{ ARM_REG_D0, "d0"},
{ ARM_REG_D1, "d1"},
{ ARM_REG_D2, "d2"},
{ ARM_REG_D3, "d3"},
{ ARM_REG_D4, "d4"},
{ ARM_REG_D5, "d5"},
{ ARM_REG_D6, "d6"},
{ ARM_REG_D7, "d7"},
{ ARM_REG_D8, "d8"},
{ ARM_REG_D9, "d9"},
{ ARM_REG_D10, "d10"},
{ ARM_REG_D11, "d11"},
{ ARM_REG_D12, "d12"},
{ ARM_REG_D13, "d13"},
{ ARM_REG_D14, "d14"},
{ ARM_REG_D15, "d15"},
{ ARM_REG_D16, "d16"},
{ ARM_REG_D17, "d17"},
{ ARM_REG_D18, "d18"},
{ ARM_REG_D19, "d19"},
{ ARM_REG_D20, "d20"},
{ ARM_REG_D21, "d21"},
{ ARM_REG_D22, "d22"},
{ ARM_REG_D23, "d23"},
{ ARM_REG_D24, "d24"},
{ ARM_REG_D25, "d25"},
{ ARM_REG_D26, "d26"},
{ ARM_REG_D27, "d27"},
{ ARM_REG_D28, "d28"},
{ ARM_REG_D29, "d29"},
{ ARM_REG_D30, "d30"},
{ ARM_REG_D31, "d31"},
{ ARM_REG_FPINST2, "fpinst2"},
{ ARM_REG_MVFR0, "mvfr0"},
{ ARM_REG_MVFR1, "mvfr1"},
{ ARM_REG_MVFR2, "mvfr2"},
{ ARM_REG_Q0, "q0"},
{ ARM_REG_Q1, "q1"},
{ ARM_REG_Q2, "q2"},
{ ARM_REG_Q3, "q3"},
{ ARM_REG_Q4, "q4"},
{ ARM_REG_Q5, "q5"},
{ ARM_REG_Q6, "q6"},
{ ARM_REG_Q7, "q7"},
{ ARM_REG_Q8, "q8"},
{ ARM_REG_Q9, "q9"},
{ ARM_REG_Q10, "q10"},
{ ARM_REG_Q11, "q11"},
{ ARM_REG_Q12, "q12"},
{ ARM_REG_Q13, "q13"},
{ ARM_REG_Q14, "q14"},
{ ARM_REG_Q15, "q15"},
{ ARM_REG_R0, "r0"},
{ ARM_REG_R1, "r1"},
{ ARM_REG_R2, "r2"},
{ ARM_REG_R3, "r3"},
{ ARM_REG_R4, "r4"},
{ ARM_REG_R5, "r5"},
{ ARM_REG_R6, "r6"},
{ ARM_REG_R7, "r7"},
{ ARM_REG_R8, "r8"},
{ ARM_REG_R9, "r9"},
{ ARM_REG_R10, "r10"},
{ ARM_REG_R11, "r11"},
{ ARM_REG_R12, "r12"},
{ ARM_REG_S0, "s0"},
{ ARM_REG_S1, "s1"},
{ ARM_REG_S2, "s2"},
{ ARM_REG_S3, "s3"},
{ ARM_REG_S4, "s4"},
{ ARM_REG_S5, "s5"},
{ ARM_REG_S6, "s6"},
{ ARM_REG_S7, "s7"},
{ ARM_REG_S8, "s8"},
{ ARM_REG_S9, "s9"},
{ ARM_REG_S10, "s10"},
{ ARM_REG_S11, "s11"},
{ ARM_REG_S12, "s12"},
{ ARM_REG_S13, "s13"},
{ ARM_REG_S14, "s14"},
{ ARM_REG_S15, "s15"},
{ ARM_REG_S16, "s16"},
{ ARM_REG_S17, "s17"},
{ ARM_REG_S18, "s18"},
{ ARM_REG_S19, "s19"},
{ ARM_REG_S20, "s20"},
{ ARM_REG_S21, "s21"},
{ ARM_REG_S22, "s22"},
{ ARM_REG_S23, "s23"},
{ ARM_REG_S24, "s24"},
{ ARM_REG_S25, "s25"},
{ ARM_REG_S26, "s26"},
{ ARM_REG_S27, "s27"},
{ ARM_REG_S28, "s28"},
{ ARM_REG_S29, "s29"},
{ ARM_REG_S30, "s30"},
{ ARM_REG_S31, "s31"},
};
#endif
2013-11-27 12:11:31 +08:00
2013-12-12 05:14:42 +08:00
const char *ARM_reg_name(csh handle, unsigned int reg)
2013-11-27 12:11:31 +08:00
{
#ifndef CAPSTONE_DIET
if (reg >= ARR_SIZE(reg_name_maps))
2013-11-27 12:11:31 +08:00
return NULL;
return reg_name_maps[reg].name;
#else
return NULL;
#endif
2013-11-27 12:11:31 +08:00
}
const char *ARM_reg_name2(csh handle, unsigned int reg)
{
#ifndef CAPSTONE_DIET
if (reg >= ARR_SIZE(reg_name_maps2))
return NULL;
return reg_name_maps2[reg].name;
#else
return NULL;
#endif
}
Constify backend data (#1040) * Constify string literals Use -Wwrite-strings to force string literals to be of type "const char[]", then fix up all warning fallout. * Constify common infrastructure Step one in allowing backend data to be readonly. Minimal changes to backends for now; just set all pointers in common structs that aren't modified to const. * Constify AArch64 backend Section size changes within libcapstone.so are -.rodata 602587 -.data.rel.ro 228416 -.data 1003746 +.rodata 769051 +.data.rel.ro 241120 +.data 824578 * Constify ARM backend Section size changes within libcapstone.so are -.rodata 769051 -.data.rel.ro 241120 -.data 824578 +.rodata 959835 +.data.rel.ro 245120 +.data 629506 * Constify Mips backend Section size changes within libcapstone.so are -.rodata 959835 -.data.rel.ro 245120 -.data 629506 +.rodata 1069851 +.data.rel.ro 256416 +.data 508194 * Constify PowerPC backend Section size changes within libcapstone.so are -.rodata 1069851 -.data.rel.ro 256416 -.data 508194 +.rodata 1142715 +.data.rel.ro 272224 +.data 419490 * Constify Sparc backend Section size changes within libcapstone.so are -.rodata 1142715 -.data.rel.ro 272224 -.data 419490 +.rodata 1175227 +.data.rel.ro 277536 +.data 381666 * Constify SystemZ backend Section size changes within libcapstone.so are -.rodata 1175227 -.data.rel.ro 277536 -.data 381666 +.rodata 1221883 +.data.rel.ro 278016 +.data 334498 * Constify X86 backend Section size changes within libcapstone.so are -.rodata 1221883 -.data.rel.ro 278016 -.data 334498 +.rodata 1533531 +.data.rel.ro 281184 +.data 19714 * Constify XCore backend Section size changes within libcapstone.so are -.rodata 1533531 -.data.rel.ro 281184 -.data 19714 +.rodata 1553026 +.data.rel.ro 281280 +.data 40
2017-10-22 08:45:40 +08:00
static const insn_map insns[] = {
2019-04-11 00:46:12 +08:00
// dummy item
{
0, 0,
#ifndef CAPSTONE_DIET
{ 0 }, { 0 }, { 0 }, 0, 0
#endif
},
#include "ARMMappingInsn.inc"
2013-11-27 12:11:31 +08:00
};
// look for @id in @insns
// return -1 if not found
static unsigned int find_insn(unsigned int id)
{
// binary searching since the IDs are sorted in order
unsigned int left, right, m;
unsigned int max = ARR_SIZE(insns);
right = max - 1;
if (id < insns[0].id || id > insns[right].id)
// not found
return -1;
left = 0;
while(left <= right) {
m = (left + right) / 2;
if (id == insns[m].id) {
return m;
}
if (id < insns[m].id)
right = m - 1;
else
left = m + 1;
}
// not found
// printf("NOT FOUNDDDDDDDDDDDDDDD id = %u\n", id);
return -1;
}
void ARM_get_insn_id(cs_struct *h, cs_insn *insn, unsigned int id)
2013-11-27 12:11:31 +08:00
{
unsigned int i = find_insn(id);
2019-04-11 00:46:12 +08:00
if (i != -1) {
2013-11-27 12:11:31 +08:00
insn->id = insns[i].mapid;
// printf("id = %u, mapid = %u\n", id, insn->id);
if (h->detail) {
#ifndef CAPSTONE_DIET
cs_struct handle;
handle.detail = h->detail;
2013-12-30 00:15:25 +08:00
memcpy(insn->detail->regs_read, insns[i].regs_use, sizeof(insns[i].regs_use));
insn->detail->regs_read_count = (uint8_t)count_positive(insns[i].regs_use);
memcpy(insn->detail->regs_write, insns[i].regs_mod, sizeof(insns[i].regs_mod));
insn->detail->regs_write_count = (uint8_t)count_positive(insns[i].regs_mod);
memcpy(insn->detail->groups, insns[i].groups, sizeof(insns[i].groups));
insn->detail->groups_count = (uint8_t)count_positive8(insns[i].groups);
insn->detail->arm.update_flags = cs_reg_write((csh)&handle, insn, ARM_REG_CPSR);
if (insns[i].branch || insns[i].indirect_branch) {
// this insn also belongs to JUMP group. add JUMP group
insn->detail->groups[insn->detail->groups_count] = ARM_GRP_JUMP;
insn->detail->groups_count++;
}
#endif
}
2013-11-27 12:11:31 +08:00
}
}
#ifndef CAPSTONE_DIET
Constify backends (#1549) * Constify registerinfo.py output Remove two conditionals separating identical bits of code. Add "const" markup to MCRegisterDesc and MCRegisterClass. Signed-off-by: Richard Henderson <rth@twiddle.net> * Constify instrinfo-arch.py output In this case, do not actively strip const. Signed-off-by: Richard Henderson <rth@twiddle.net> * Constify the AArch64 backend Signed-off-by: Richard Henderson <rth@twiddle.net> * Constify the EVM backend Signed-off-by: Richard Henderson <rth@twiddle.net> * Constify M680X backend Signed-off-by: Richard Henderson <rth@twiddle.net> * Constify M68K backend Signed-off-by: Richard Henderson <rth@twiddle.net> * Constify the Mips backend The Mips backend has not been regenerated from LLVM recently, and there are more fixups required than I'd like. Just apply the fixes to the tables by hand for now. Signed-off-by: Richard Henderson <rth@twiddle.net> * Constify the Sparc backend Signed-off-by: Richard Henderson <rth@twiddle.net> * Constify the TMS320C64x backend Signed-off-by: Richard Henderson <rth@twiddle.net> * Constify the X86 backend Signed-off-by: Richard Henderson <rth@twiddle.net> * Constify the XCore backend Signed-off-by: Richard Henderson <rth@twiddle.net> * Constify systemregister.py output Signed-off-by: Richard Henderson <rth@twiddle.net> * Constify the ARM backend Signed-off-by: Richard Henderson <rth@twiddle.net> * Constify the PowerPC backend Signed-off-by: Richard Henderson <rth@twiddle.net> * Constify the MOS65XX backend Signed-off-by: Richard Henderson <rth@twiddle.net> * Constify the SystemZ backend The mapping of system register to indexes is easy to generate read-only. Since we know the indexes are between 0 and 31, use uint8_t instead of unsigned. Signed-off-by: Richard Henderson <rth@twiddle.net> * Constify the WASM backend Signed-off-by: Richard Henderson <rth@twiddle.net> * Constify cs.c Signed-off-by: Richard Henderson <rth@twiddle.net> * Constify the BPF backend Signed-off-by: Richard Henderson <rth@twiddle.net>
2019-12-23 20:30:58 +08:00
static const char * const insn_name_maps[] = {
NULL, // ARM_INS_INVALID
#include "ARMMappingInsnName.inc"
2013-11-27 12:11:31 +08:00
};
#endif
2013-11-27 12:11:31 +08:00
2013-12-12 05:14:42 +08:00
const char *ARM_insn_name(csh handle, unsigned int id)
2013-11-27 12:11:31 +08:00
{
#ifndef CAPSTONE_DIET
if (id >= ARM_INS_ENDING)
2013-11-27 12:11:31 +08:00
return NULL;
return insn_name_maps[id];
#else
return NULL;
#endif
2013-11-27 12:11:31 +08:00
}
#ifndef CAPSTONE_DIET
Constify backend data (#1040) * Constify string literals Use -Wwrite-strings to force string literals to be of type "const char[]", then fix up all warning fallout. * Constify common infrastructure Step one in allowing backend data to be readonly. Minimal changes to backends for now; just set all pointers in common structs that aren't modified to const. * Constify AArch64 backend Section size changes within libcapstone.so are -.rodata 602587 -.data.rel.ro 228416 -.data 1003746 +.rodata 769051 +.data.rel.ro 241120 +.data 824578 * Constify ARM backend Section size changes within libcapstone.so are -.rodata 769051 -.data.rel.ro 241120 -.data 824578 +.rodata 959835 +.data.rel.ro 245120 +.data 629506 * Constify Mips backend Section size changes within libcapstone.so are -.rodata 959835 -.data.rel.ro 245120 -.data 629506 +.rodata 1069851 +.data.rel.ro 256416 +.data 508194 * Constify PowerPC backend Section size changes within libcapstone.so are -.rodata 1069851 -.data.rel.ro 256416 -.data 508194 +.rodata 1142715 +.data.rel.ro 272224 +.data 419490 * Constify Sparc backend Section size changes within libcapstone.so are -.rodata 1142715 -.data.rel.ro 272224 -.data 419490 +.rodata 1175227 +.data.rel.ro 277536 +.data 381666 * Constify SystemZ backend Section size changes within libcapstone.so are -.rodata 1175227 -.data.rel.ro 277536 -.data 381666 +.rodata 1221883 +.data.rel.ro 278016 +.data 334498 * Constify X86 backend Section size changes within libcapstone.so are -.rodata 1221883 -.data.rel.ro 278016 -.data 334498 +.rodata 1533531 +.data.rel.ro 281184 +.data 19714 * Constify XCore backend Section size changes within libcapstone.so are -.rodata 1533531 -.data.rel.ro 281184 -.data 19714 +.rodata 1553026 +.data.rel.ro 281280 +.data 40
2017-10-22 08:45:40 +08:00
static const name_map group_name_maps[] = {
// generic groups
{ ARM_GRP_INVALID, NULL },
{ ARM_GRP_JUMP, "jump" },
{ ARM_GRP_CALL, "call" },
{ ARM_GRP_INT, "int" },
{ ARM_GRP_PRIVILEGE, "privilege" },
{ ARM_GRP_BRANCH_RELATIVE, "branch_relative" },
// architecture-specific groups
{ ARM_GRP_CRYPTO, "crypto" },
{ ARM_GRP_DATABARRIER, "databarrier" },
{ ARM_GRP_DIVIDE, "divide" },
{ ARM_GRP_FPARMV8, "fparmv8" },
{ ARM_GRP_MULTPRO, "multpro" },
{ ARM_GRP_NEON, "neon" },
{ ARM_GRP_T2EXTRACTPACK, "T2EXTRACTPACK" },
{ ARM_GRP_THUMB2DSP, "THUMB2DSP" },
{ ARM_GRP_TRUSTZONE, "TRUSTZONE" },
{ ARM_GRP_V4T, "v4t" },
{ ARM_GRP_V5T, "v5t" },
{ ARM_GRP_V5TE, "v5te" },
{ ARM_GRP_V6, "v6" },
{ ARM_GRP_V6T2, "v6t2" },
{ ARM_GRP_V7, "v7" },
{ ARM_GRP_V8, "v8" },
{ ARM_GRP_VFP2, "vfp2" },
{ ARM_GRP_VFP3, "vfp3" },
{ ARM_GRP_VFP4, "vfp4" },
{ ARM_GRP_ARM, "arm" },
{ ARM_GRP_MCLASS, "mclass" },
{ ARM_GRP_NOTMCLASS, "notmclass" },
{ ARM_GRP_THUMB, "thumb" },
{ ARM_GRP_THUMB1ONLY, "thumb1only" },
{ ARM_GRP_THUMB2, "thumb2" },
{ ARM_GRP_PREV8, "prev8" },
{ ARM_GRP_FPVMLX, "fpvmlx" },
{ ARM_GRP_MULOPS, "mulops" },
{ ARM_GRP_CRC, "crc" },
{ ARM_GRP_DPVFP, "dpvfp" },
{ ARM_GRP_V6M, "v6m" },
{ ARM_GRP_VIRTUALIZATION, "virtualization" },
};
#endif
const char *ARM_group_name(csh handle, unsigned int id)
{
#ifndef CAPSTONE_DIET
return id2name(group_name_maps, ARR_SIZE(group_name_maps), id);
#else
return NULL;
#endif
}
// list all relative branch instructions
// ie: insns[i].branch && !insns[i].indirect_branch
Constify backend data (#1040) * Constify string literals Use -Wwrite-strings to force string literals to be of type "const char[]", then fix up all warning fallout. * Constify common infrastructure Step one in allowing backend data to be readonly. Minimal changes to backends for now; just set all pointers in common structs that aren't modified to const. * Constify AArch64 backend Section size changes within libcapstone.so are -.rodata 602587 -.data.rel.ro 228416 -.data 1003746 +.rodata 769051 +.data.rel.ro 241120 +.data 824578 * Constify ARM backend Section size changes within libcapstone.so are -.rodata 769051 -.data.rel.ro 241120 -.data 824578 +.rodata 959835 +.data.rel.ro 245120 +.data 629506 * Constify Mips backend Section size changes within libcapstone.so are -.rodata 959835 -.data.rel.ro 245120 -.data 629506 +.rodata 1069851 +.data.rel.ro 256416 +.data 508194 * Constify PowerPC backend Section size changes within libcapstone.so are -.rodata 1069851 -.data.rel.ro 256416 -.data 508194 +.rodata 1142715 +.data.rel.ro 272224 +.data 419490 * Constify Sparc backend Section size changes within libcapstone.so are -.rodata 1142715 -.data.rel.ro 272224 -.data 419490 +.rodata 1175227 +.data.rel.ro 277536 +.data 381666 * Constify SystemZ backend Section size changes within libcapstone.so are -.rodata 1175227 -.data.rel.ro 277536 -.data 381666 +.rodata 1221883 +.data.rel.ro 278016 +.data 334498 * Constify X86 backend Section size changes within libcapstone.so are -.rodata 1221883 -.data.rel.ro 278016 -.data 334498 +.rodata 1533531 +.data.rel.ro 281184 +.data 19714 * Constify XCore backend Section size changes within libcapstone.so are -.rodata 1533531 -.data.rel.ro 281184 -.data 19714 +.rodata 1553026 +.data.rel.ro 281280 +.data 40
2017-10-22 08:45:40 +08:00
static const unsigned int insn_rel[] = {
ARM_BL,
ARM_BLX_pred,
ARM_Bcc,
ARM_t2B,
ARM_t2Bcc,
ARM_tB,
ARM_tBcc,
ARM_tCBNZ,
ARM_tCBZ,
ARM_BL_pred,
ARM_BLXi,
ARM_tBL,
ARM_tBLXi,
0
};
Constify backend data (#1040) * Constify string literals Use -Wwrite-strings to force string literals to be of type "const char[]", then fix up all warning fallout. * Constify common infrastructure Step one in allowing backend data to be readonly. Minimal changes to backends for now; just set all pointers in common structs that aren't modified to const. * Constify AArch64 backend Section size changes within libcapstone.so are -.rodata 602587 -.data.rel.ro 228416 -.data 1003746 +.rodata 769051 +.data.rel.ro 241120 +.data 824578 * Constify ARM backend Section size changes within libcapstone.so are -.rodata 769051 -.data.rel.ro 241120 -.data 824578 +.rodata 959835 +.data.rel.ro 245120 +.data 629506 * Constify Mips backend Section size changes within libcapstone.so are -.rodata 959835 -.data.rel.ro 245120 -.data 629506 +.rodata 1069851 +.data.rel.ro 256416 +.data 508194 * Constify PowerPC backend Section size changes within libcapstone.so are -.rodata 1069851 -.data.rel.ro 256416 -.data 508194 +.rodata 1142715 +.data.rel.ro 272224 +.data 419490 * Constify Sparc backend Section size changes within libcapstone.so are -.rodata 1142715 -.data.rel.ro 272224 -.data 419490 +.rodata 1175227 +.data.rel.ro 277536 +.data 381666 * Constify SystemZ backend Section size changes within libcapstone.so are -.rodata 1175227 -.data.rel.ro 277536 -.data 381666 +.rodata 1221883 +.data.rel.ro 278016 +.data 334498 * Constify X86 backend Section size changes within libcapstone.so are -.rodata 1221883 -.data.rel.ro 278016 -.data 334498 +.rodata 1533531 +.data.rel.ro 281184 +.data 19714 * Constify XCore backend Section size changes within libcapstone.so are -.rodata 1533531 -.data.rel.ro 281184 -.data 19714 +.rodata 1553026 +.data.rel.ro 281280 +.data 40
2017-10-22 08:45:40 +08:00
static const unsigned int insn_blx_rel_to_arm[] = {
ARM_tBLXi,
0
};
// check if this insn is relative branch
bool ARM_rel_branch(cs_struct *h, unsigned int id)
{
int i;
for (i = 0; insn_rel[i]; i++) {
if (id == insn_rel[i]) {
return true;
}
}
// not found
return false;
}
bool ARM_blx_to_arm_mode(cs_struct *h, unsigned int id) {
int i;
for (i = 0; insn_blx_rel_to_arm[i]; i++)
if (id == insn_blx_rel_to_arm[i])
return true;
// not found
return false;
}
2015-04-07 11:59:26 +08:00
#ifndef CAPSTONE_DIET
// map instruction to its characteristics
typedef struct insn_op {
2015-04-07 11:59:26 +08:00
uint8_t access[7];
} insn_op;
Constify backends (#1549) * Constify registerinfo.py output Remove two conditionals separating identical bits of code. Add "const" markup to MCRegisterDesc and MCRegisterClass. Signed-off-by: Richard Henderson <rth@twiddle.net> * Constify instrinfo-arch.py output In this case, do not actively strip const. Signed-off-by: Richard Henderson <rth@twiddle.net> * Constify the AArch64 backend Signed-off-by: Richard Henderson <rth@twiddle.net> * Constify the EVM backend Signed-off-by: Richard Henderson <rth@twiddle.net> * Constify M680X backend Signed-off-by: Richard Henderson <rth@twiddle.net> * Constify M68K backend Signed-off-by: Richard Henderson <rth@twiddle.net> * Constify the Mips backend The Mips backend has not been regenerated from LLVM recently, and there are more fixups required than I'd like. Just apply the fixes to the tables by hand for now. Signed-off-by: Richard Henderson <rth@twiddle.net> * Constify the Sparc backend Signed-off-by: Richard Henderson <rth@twiddle.net> * Constify the TMS320C64x backend Signed-off-by: Richard Henderson <rth@twiddle.net> * Constify the X86 backend Signed-off-by: Richard Henderson <rth@twiddle.net> * Constify the XCore backend Signed-off-by: Richard Henderson <rth@twiddle.net> * Constify systemregister.py output Signed-off-by: Richard Henderson <rth@twiddle.net> * Constify the ARM backend Signed-off-by: Richard Henderson <rth@twiddle.net> * Constify the PowerPC backend Signed-off-by: Richard Henderson <rth@twiddle.net> * Constify the MOS65XX backend Signed-off-by: Richard Henderson <rth@twiddle.net> * Constify the SystemZ backend The mapping of system register to indexes is easy to generate read-only. Since we know the indexes are between 0 and 31, use uint8_t instead of unsigned. Signed-off-by: Richard Henderson <rth@twiddle.net> * Constify the WASM backend Signed-off-by: Richard Henderson <rth@twiddle.net> * Constify cs.c Signed-off-by: Richard Henderson <rth@twiddle.net> * Constify the BPF backend Signed-off-by: Richard Henderson <rth@twiddle.net>
2019-12-23 20:30:58 +08:00
static const insn_op insn_ops[] = {
2015-03-07 16:38:35 +08:00
{
// NULL item
{ 0 }
},
#include "ARMMappingInsnOp.inc"
};
2015-04-07 11:59:26 +08:00
// given internal insn id, return operand access info
Constify backends (#1549) * Constify registerinfo.py output Remove two conditionals separating identical bits of code. Add "const" markup to MCRegisterDesc and MCRegisterClass. Signed-off-by: Richard Henderson <rth@twiddle.net> * Constify instrinfo-arch.py output In this case, do not actively strip const. Signed-off-by: Richard Henderson <rth@twiddle.net> * Constify the AArch64 backend Signed-off-by: Richard Henderson <rth@twiddle.net> * Constify the EVM backend Signed-off-by: Richard Henderson <rth@twiddle.net> * Constify M680X backend Signed-off-by: Richard Henderson <rth@twiddle.net> * Constify M68K backend Signed-off-by: Richard Henderson <rth@twiddle.net> * Constify the Mips backend The Mips backend has not been regenerated from LLVM recently, and there are more fixups required than I'd like. Just apply the fixes to the tables by hand for now. Signed-off-by: Richard Henderson <rth@twiddle.net> * Constify the Sparc backend Signed-off-by: Richard Henderson <rth@twiddle.net> * Constify the TMS320C64x backend Signed-off-by: Richard Henderson <rth@twiddle.net> * Constify the X86 backend Signed-off-by: Richard Henderson <rth@twiddle.net> * Constify the XCore backend Signed-off-by: Richard Henderson <rth@twiddle.net> * Constify systemregister.py output Signed-off-by: Richard Henderson <rth@twiddle.net> * Constify the ARM backend Signed-off-by: Richard Henderson <rth@twiddle.net> * Constify the PowerPC backend Signed-off-by: Richard Henderson <rth@twiddle.net> * Constify the MOS65XX backend Signed-off-by: Richard Henderson <rth@twiddle.net> * Constify the SystemZ backend The mapping of system register to indexes is easy to generate read-only. Since we know the indexes are between 0 and 31, use uint8_t instead of unsigned. Signed-off-by: Richard Henderson <rth@twiddle.net> * Constify the WASM backend Signed-off-by: Richard Henderson <rth@twiddle.net> * Constify cs.c Signed-off-by: Richard Henderson <rth@twiddle.net> * Constify the BPF backend Signed-off-by: Richard Henderson <rth@twiddle.net>
2019-12-23 20:30:58 +08:00
const uint8_t *ARM_get_op_access(cs_struct *h, unsigned int id)
2015-04-07 11:59:26 +08:00
{
int i = insn_find(insns, ARR_SIZE(insns), id, &h->insn_cache);
if (i != 0) {
return insn_ops[i].access;
}
return NULL;
}
void ARM_reg_access(const cs_insn *insn,
cs_regs regs_read, uint8_t *regs_read_count,
cs_regs regs_write, uint8_t *regs_write_count)
{
uint8_t i;
uint8_t read_count, write_count;
cs_arm *arm = &(insn->detail->arm);
read_count = insn->detail->regs_read_count;
write_count = insn->detail->regs_write_count;
// implicit registers
memcpy(regs_read, insn->detail->regs_read, read_count * sizeof(insn->detail->regs_read[0]));
memcpy(regs_write, insn->detail->regs_write, write_count * sizeof(insn->detail->regs_write[0]));
// explicit registers
for (i = 0; i < arm->op_count; i++) {
cs_arm_op *op = &(arm->operands[i]);
switch((int)op->type) {
case ARM_OP_REG:
if ((op->access & CS_AC_READ) && !arr_exist(regs_read, read_count, op->reg)) {
2016-05-12 12:48:32 +08:00
regs_read[read_count] = (uint16_t)op->reg;
2015-04-07 11:59:26 +08:00
read_count++;
}
if ((op->access & CS_AC_WRITE) && !arr_exist(regs_write, write_count, op->reg)) {
2016-05-12 12:48:32 +08:00
regs_write[write_count] = (uint16_t)op->reg;
2015-04-07 11:59:26 +08:00
write_count++;
}
break;
case ARM_OP_MEM:
// registers appeared in memory references always being read
if ((op->mem.base != ARM_REG_INVALID) && !arr_exist(regs_read, read_count, op->mem.base)) {
2016-05-12 12:48:32 +08:00
regs_read[read_count] = (uint16_t)op->mem.base;
2015-04-07 11:59:26 +08:00
read_count++;
}
if ((op->mem.index != ARM_REG_INVALID) && !arr_exist(regs_read, read_count, op->mem.index)) {
2016-05-12 12:48:32 +08:00
regs_read[read_count] = (uint16_t)op->mem.index;
2015-04-07 11:59:26 +08:00
read_count++;
}
if ((arm->writeback) && (op->mem.base != ARM_REG_INVALID) && !arr_exist(regs_write, write_count, op->mem.base)) {
2016-05-12 12:48:32 +08:00
regs_write[write_count] = (uint16_t)op->mem.base;
2015-04-07 11:59:26 +08:00
write_count++;
}
default:
break;
}
}
*regs_read_count = read_count;
*regs_write_count = write_count;
}
#endif
#endif