From 3ab509192ab23b665c1702b9968f7a4efd5b8811 Mon Sep 17 00:00:00 2001 From: Nguyen Anh Quynh Date: Fri, 31 Oct 2014 14:40:45 +0800 Subject: [PATCH] use common instruction groups across all architectures. this adds cs_group_type to capstone.h. suggestion by @zneak --- include/arm.h | 12 ++++++++---- include/arm64.h | 11 +++++++---- include/capstone.h | 14 ++++++++++++-- include/mips.h | 11 +++++++---- include/ppc.h | 11 +++++++---- include/sparc.h | 11 +++++++---- include/systemz.h | 12 ++++++++---- include/x86.h | 23 +++++++++++++++-------- include/xcore.h | 6 ++++-- 9 files changed, 75 insertions(+), 36 deletions(-) diff --git a/include/arm.h b/include/arm.h index 5d38bea1a6..e6aed29051 100644 --- a/include/arm.h +++ b/include/arm.h @@ -808,8 +808,14 @@ typedef enum arm_insn { //> Group of ARM instructions typedef enum arm_insn_group { - ARM_GRP_INVALID = 0, - ARM_GRP_CRYPTO, + ARM_GRP_INVALID = 0, // = CS_GRP_INVALID + + //> Generic groups + // all jump instructions (conditional+direct+indirect jumps) + ARM_GRP_JUMP, // = CS_GRP_JUMP + + //> Architecture-specific groups + ARM_GRP_CRYPTO = 128, ARM_GRP_DATABARRIER, ARM_GRP_DIVIDE, ARM_GRP_FPARMV8, @@ -841,8 +847,6 @@ typedef enum arm_insn_group { ARM_GRP_DPVFP, ARM_GRP_V6M, - ARM_GRP_JUMP, // all jump instructions (conditional+direct+indirect jumps) - ARM_GRP_ENDING, } arm_insn_group; diff --git a/include/arm64.h b/include/arm64.h index 06e146f69b..9f6d558810 100644 --- a/include/arm64.h +++ b/include/arm64.h @@ -1129,15 +1129,18 @@ typedef enum arm64_insn { //> Group of ARM64 instructions typedef enum arm64_insn_group { - ARM64_GRP_INVALID = 0, + ARM64_GRP_INVALID = 0, // = CS_GRP_INVALID - ARM64_GRP_CRYPTO, + //> Generic groups + // all jump instructions (conditional+direct+indirect jumps) + ARM64_GRP_JUMP, // = CS_GRP_JUMP + + //> Architecture-specific groups + ARM64_GRP_CRYPTO = 128, ARM64_GRP_FPARMV8, ARM64_GRP_NEON, ARM64_GRP_CRC, - ARM64_GRP_JUMP, // all jump instructions (conditional+direct+indirect jumps) - ARM64_GRP_ENDING, // <-- mark the end of the list of groups } arm64_insn_group; diff --git a/include/capstone.h b/include/capstone.h index a13ec30376..9f2d0df27c 100644 --- a/include/capstone.h +++ b/include/capstone.h @@ -125,15 +125,25 @@ typedef enum cs_opt_value { CS_OPT_SYNTAX_NOREGNAME, // Prints register name with only number (CS_OPT_SYNTAX) } cs_opt_value; -//> Common operand types - to be used consistently across all architectures. +//> Common instruction operand types - to be consistent across all architectures. typedef enum cs_op_type { CS_OP_INVALID = 0, // uninitialized/invalid operand. CS_OP_REG, // Register operand. CS_OP_IMM, // Immediate operand. CS_OP_MEM, // Memory operand. - CS_OP_FP, // Floating-point operand. + CS_OP_FP, // Floating-Point operand. } cs_op_type; +//> Common instruction groups - to be consistent across all architectures. +typedef enum cs_group_type { + CS_GRP_INVALID = 0, // uninitialized/invalid group. + CS_GRP_JUMP, // all jump instructions (conditional+direct+indirect jumps) + CS_GRP_CALL, // all call instructions + CS_GRP_RET, // all return instructions + CS_GRP_INT, // all interrupt instructions (int+syscall) + CS_GRP_IRET, // all interrupt return instructions +} cs_group_type; + /* User-defined callback function for SKIPDATA option. See tests/test_skipdata.c for sample code demonstrating this API. diff --git a/include/mips.h b/include/mips.h index 957bd73724..d467f0d741 100644 --- a/include/mips.h +++ b/include/mips.h @@ -852,9 +852,14 @@ typedef enum mips_insn { //> Group of MIPS instructions typedef enum mips_insn_group { - MIPS_GRP_INVALID = 0, + MIPS_GRP_INVALID = 0, // = CS_GRP_INVALID - MIPS_GRP_BITCOUNT, + //> Generic groups + // all jump instructions (conditional+direct+indirect jumps) + MIPS_GRP_JUMP, // = CS_GRP_JUMP + + //> Architecture-specific groups + MIPS_GRP_BITCOUNT = 128, MIPS_GRP_DSP, MIPS_GRP_DSPR2, MIPS_GRP_FPIDX, @@ -888,8 +893,6 @@ typedef enum mips_insn_group { MIPS_GRP_GP32BIT, MIPS_GRP_GP64BIT, - MIPS_GRP_JUMP, // all jump instructions (conditional+direct+indirect jumps) - MIPS_GRP_ENDING, } mips_insn_group; diff --git a/include/ppc.h b/include/ppc.h index cf5a50be20..d2bff9f7fd 100644 --- a/include/ppc.h +++ b/include/ppc.h @@ -1222,9 +1222,14 @@ typedef enum ppc_insn { //> Group of PPC instructions typedef enum ppc_insn_group { - PPC_GRP_INVALID = 0, + PPC_GRP_INVALID = 0, // = CS_GRP_INVALID - PPC_GRP_ALTIVEC, + //> Generic groups + // all jump instructions (conditional+direct+indirect jumps) + PPC_GRP_JUMP, // = CS_GRP_JUMP + + //> Architecture-specific groups + PPC_GRP_ALTIVEC = 128, PPC_GRP_MODE32, PPC_GRP_MODE64, PPC_GRP_BOOKE, @@ -1235,8 +1240,6 @@ typedef enum ppc_insn_group { PPC_GRP_PPC4XX, PPC_GRP_PPC6XX, - PPC_GRP_JUMP, // all jump instructions (conditional+direct+indirect jumps) - PPC_GRP_ENDING, // <-- mark the end of the list of groups } ppc_insn_group; diff --git a/include/sparc.h b/include/sparc.h index 5799b2bee1..60a1e53e4c 100644 --- a/include/sparc.h +++ b/include/sparc.h @@ -494,9 +494,14 @@ typedef enum sparc_insn { //> Group of SPARC instructions typedef enum sparc_insn_group { - SPARC_GRP_INVALID = 0, + SPARC_GRP_INVALID = 0, // = CS_GRP_INVALID - SPARC_GRP_HARDQUAD, + //> Generic groups + // all jump instructions (conditional+direct+indirect jumps) + SPARC_GRP_JUMP, // = CS_GRP_JUMP + + //> Architecture-specific groups + SPARC_GRP_HARDQUAD = 128, SPARC_GRP_V9, SPARC_GRP_VIS, SPARC_GRP_VIS2, @@ -504,8 +509,6 @@ typedef enum sparc_insn_group { SPARC_GRP_32BIT, SPARC_GRP_64BIT, - SPARC_GRP_JUMP, // all jump instructions (conditional+direct+indirect jumps) - SPARC_GRP_ENDING, // <-- mark the end of the list of groups } sparc_insn_group; diff --git a/include/systemz.h b/include/systemz.h index 951db52956..96c3993d7e 100644 --- a/include/systemz.h +++ b/include/systemz.h @@ -806,15 +806,19 @@ typedef enum sysz_insn { //> Group of SystemZ instructions typedef enum sysz_insn_group { - SYSZ_GRP_INVALID = 0, - SYSZ_GRP_DISTINCTOPS, + SYSZ_GRP_INVALID = 0, // = CS_GRP_INVALID + + //> Generic groups + // all jump instructions (conditional+direct+indirect jumps) + SYSZ_GRP_JUMP, // = CS_GRP_JUMP + + //> Architecture-specific groups + SYSZ_GRP_DISTINCTOPS = 128, SYSZ_GRP_FPEXTENSION, SYSZ_GRP_HIGHWORD, SYSZ_GRP_INTERLOCKEDACCESS1, SYSZ_GRP_LOADSTOREONCOND, - SYSZ_GRP_JUMP, // all jump instructions (conditional+direct+indirect jumps) - SYSZ_GRP_ENDING, // <-- mark the end of the list of groups } sysz_insn_group; diff --git a/include/x86.h b/include/x86.h index 96d6c41309..90dabdcda3 100644 --- a/include/x86.h +++ b/include/x86.h @@ -1561,8 +1561,22 @@ typedef enum x86_insn { //> Group of X86 instructions typedef enum x86_insn_group { - X86_GRP_INVALID = 0, + X86_GRP_INVALID = 0, // = CS_GRP_INVALID + //> Generic groups + // all jump instructions (conditional+direct+indirect jumps) + X86_GRP_JUMP, // = CS_GRP_JUMP + // all call instructions + X86_GRP_CALL, // = CS_GRP_CALL + // all return instructions + X86_GRP_RET, // = CS_GRP_RET + // all interrupt instructions (int+syscall) + X86_GRP_INT, // = CS_GRP_INT + // all interrupt return instructions + X86_GRP_IRET, // = CS_GRP_IRET + + //> Architecture-specific groups + X86_GRP_VM = 128, // all virtualization instructions (VT-x + AMD-V) X86_GRP_3DNOW, X86_GRP_AES, X86_GRP_ADX, @@ -1604,13 +1618,6 @@ typedef enum x86_insn_group { X86_GRP_SMAP, X86_GRP_NOVLX, - X86_GRP_JUMP, // all jump instructions (conditional+direct+indirect jumps) - X86_GRP_VM, // all virtualization instructions (VT-x + AMD-V) - X86_GRP_INT, // all interrupt instructions (int+syscall) - X86_GRP_IRET, // all interrupt return instructions - X86_GRP_CALL, // all call instructions - X86_GRP_RET, // all call return instructions - X86_GRP_ENDING } x86_insn_group; diff --git a/include/xcore.h b/include/xcore.h index e8545a6ba3..ff6a5d25f6 100644 --- a/include/xcore.h +++ b/include/xcore.h @@ -218,9 +218,11 @@ typedef enum xcore_insn { //> Group of XCore instructions typedef enum xcore_insn_group { - XCORE_GRP_INVALID = 0, + XCORE_GRP_INVALID = 0, // = CS_GRP_INVALID - XCORE_GRP_JUMP, // all jump instructions (conditional+direct+indirect jumps) + //> Generic groups + // all jump instructions (conditional+direct+indirect jumps) + XCORE_GRP_JUMP, // = CS_GRP_JUMP XCORE_GRP_ENDING, // <-- mark the end of the list of groups } xcore_insn_group;