Debian Codegraph @

tests/test_tricore.c

raw symbols SCIP
1 /* Capstone Disassembler Engine */cxx . . $ `<file>/tests/test_tricore.c`/
2 /* By Nguyen Anh Quynh <[email protected]>, 2013-2014 */
3
4 #include <stdio.h>
5
6 #include <capstone/platform.h>cxx . . $ `<file>/include/capstone/platform.h`/
7 #include <capstone/capstone.h>cxx . . $ `<file>/include/capstone/capstone.h`/
8
9 struct platformcxx . . $ platform# {
10 cs_archcxx . . $ cs_arch# archcxx . . $ platform#arch.;
11 cs_modecxx . . $ cs_mode# modecxx . . $ platform#mode.;
12 unsigned char *codecxx . . $ platform#code.;
13 size_t sizecxx . . $ platform#size.;
14 char *commentcxx . . $ platform#comment.;
15 };
16
17 static cshcxx . . $ csh# handlecxx . . $ handle.;
18
19 static void print_string_hexcxx . . $ print_string_hex(a4251af8cd875309).(char *comment, unsigned char *str, size_t len)
20 {
21 unsigned char *c;
22
23 printfcxx . . $ printf(581fddd72a8db8fc).("%s", comment);
24 for (c = str; c < str + len; c++) {
25 printfcxx . . $ printf(581fddd72a8db8fc).("0x%02x ", *c & 0xff);
26 }
27
28 printfcxx . . $ printf(581fddd72a8db8fc).("\n");
29 }
30
31 static void print_insn_detailcxx . . $ print_insn_detail(ecef60df25d96a55).(cs_insncxx . . $ cs_insn# *ins)
32 {
33 cs_tricorecxx . . $ cs_tricore# *tricore;
34 int i;
35
36 // detail can be NULL on "data" instruction if SKIPDATA option is turned ON
37 if (ins->detailcxx . . $ cs_insn#detail. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!)
38 return;
39
40 tricore = &(ins->detailcxx . . $ cs_insn#detail.->tricorecxx . . $ cs_detail#$anonymous_type_0#tricore.);
41 if (tricore->op_countcxx . . $ cs_tricore#op_count.)
42 printfcxx . . $ printf(581fddd72a8db8fc).("\top_count: %u\n", tricore->op_countcxx . . $ cs_tricore#op_count.);
43
44 for (i = 0; i < tricore->op_countcxx . . $ cs_tricore#op_count.; i++) {
45 cs_tricore_opcxx . . $ cs_tricore_op# *op = &(tricore->operandscxx . . $ cs_tricore#operands.[i]);
46 switch ((int)op->typecxx . . $ cs_tricore_op#type.) {
47 default:
48 break;
49 case TRICORE_OP_REGcxx . . $ TRICORE_OP_REG.:
50 printfcxx . . $ printf(581fddd72a8db8fc).("\t\toperands[%u].type: REG = %s\n", i,
51 cs_reg_namecxx . . $ cs_reg_name(efd1348d9ae5172e).(handlecxx . . $ handle., op->regcxx . . $ cs_tricore_op#$anonymous_type_0#reg.));
52 break;
53 case TRICORE_OP_IMMcxx . . $ TRICORE_OP_IMM.:
54 printfcxx . . $ printf(581fddd72a8db8fc).("\t\toperands[%u].type: IMM = 0x%x\n", i,
55 op->immcxx . . $ cs_tricore_op#$anonymous_type_0#imm.);
56 break;
57 case TRICORE_OP_MEMcxx . . $ TRICORE_OP_MEM.:
58 printfcxx . . $ printf(581fddd72a8db8fc).("\t\toperands[%u].type: MEM\n", i);
59 if (op->memcxx . . $ cs_tricore_op#$anonymous_type_0#mem..basecxx . . $ tricore_op_mem#base. != TRICORE_REG_INVALIDcxx . . $ TRICORE_REG_INVALID.)
60 printfcxx . . $ printf(581fddd72a8db8fc).("\t\t\toperands[%u].mem.base: REG = %s\n",
61 i, cs_reg_namecxx . . $ cs_reg_name(efd1348d9ae5172e).(handlecxx . . $ handle., op->memcxx . . $ cs_tricore_op#$anonymous_type_0#mem..basecxx . . $ tricore_op_mem#base.));
62 if (op->memcxx . . $ cs_tricore_op#$anonymous_type_0#mem..dispcxx . . $ tricore_op_mem#disp. != 0)
63 printfcxx . . $ printf(581fddd72a8db8fc).("\t\t\toperands[%u].mem.disp: 0x%x\n", i,
64 op->memcxx . . $ cs_tricore_op#$anonymous_type_0#mem..dispcxx . . $ tricore_op_mem#disp.);
65
66 break;
67 }
68 }
69
70 printfcxx . . $ printf(581fddd72a8db8fc).("\n");
71 }
72
73 static void testcxx . . $ test(d878ad36e69247c7).()
74 {
75 //#define TRICORE_CODE "\x16\x01\x20\x01\x1d\x00\x02\x00\x8f\x70\x00\x11\x40\xae\x89\xee\x04\x09\x42\xf2\xe2\xf2\xc2\x11\x19\xff\xc0\x70\x19\xff\x20\x10"
76 #define TRICORE_CODEcxx . . $ `tests/test_tricore.c:76:9`! \
77 "\x09\xcf\xbc\xf5\x09\xf4\x01\x00\x89\xfb\x8f\x74\x89\xfe\x48\x01\x29\x00\x19\x25\x29\x03\x09\xf4\x85\xf9\x68\x0f\x16\x01"
78
79 struct platformcxx . . $ platform# platforms[] = {
80 {
81 CS_ARCH_TRICOREcxx . . $ CS_ARCH_TRICORE.,
82 CS_MODE_TRICORE_162cxx . . $ CS_MODE_TRICORE_162.,
83 (unsigned char *)TRICORE_CODEcxx . . $ `tests/test_tricore.c:76:9`!,
84 sizeof(TRICORE_CODEcxx . . $ `tests/test_tricore.c:76:9`!) - 1,
85 "TriCore",
86 },
87 };
88
89 uint64_tcxx . . $ uint64_t# address = 0x1000;
90 cs_insncxx . . $ cs_insn# *insn;
91 int i;
92 size_t count;
93
94 for (i = 0; i < sizeof(platforms) / sizeof(platforms[0]); i++) {
95 cs_errcxx . . $ cs_err# err =
96 cs_opencxx . . $ cs_open(b2cb849d8ee082cd).(platforms[i].archcxx . . $ platform#arch., platforms[i].modecxx . . $ platform#mode., &handlecxx . . $ handle.);
97 if (err) {
98 printfcxx . . $ printf(581fddd72a8db8fc).("Failed on cs_open() with error returned: %u\n",
99 err);
100 continue;
101 }
102
103 cs_optioncxx . . $ cs_option(a321a010700ba3d2).(handlecxx . . $ handle., CS_OPT_DETAILcxx . . $ CS_OPT_DETAIL., CS_OPT_ONcxx . . $ CS_OPT_ON.);
104
105 count = cs_disasmcxx . . $ cs_disasm(d552efbd9b22be5).(handlecxx . . $ handle., platforms[i].codecxx . . $ platform#code., platforms[i].sizecxx . . $ platform#size.,
106 address, 0, &insn);
107 if (count) {
108 size_t j;
109
110 printfcxx . . $ printf(581fddd72a8db8fc).("****************\n");
111 printfcxx . . $ printf(581fddd72a8db8fc).("Platform: %s\n", platforms[i].commentcxx . . $ platform#comment.);
112 print_string_hexcxx . . $ print_string_hex(a4251af8cd875309).("Code:", platforms[i].codecxx . . $ platform#code.,
113 platforms[i].sizecxx . . $ platform#size.);
114 printfcxx . . $ printf(581fddd72a8db8fc).("Disasm:\n");
115
116 for (j = 0; j < count; j++) {
117 printfcxx . . $ printf(581fddd72a8db8fc).("0x%" PRIx64cxx . . $ `<external>/15933738808807975373/inttypes.h:126:10`! ":\t%s\t%s\n",
118 insn[j].addresscxx . . $ cs_insn#address., insn[j].mnemoniccxx . . $ cs_insn#mnemonic.,
119 insn[j].op_strcxx . . $ cs_insn#op_str.);
120 print_insn_detailcxx . . $ print_insn_detail(ecef60df25d96a55).(&insn[j]);
121 }
122 printfcxx . . $ printf(581fddd72a8db8fc).("0x%" PRIx64cxx . . $ `<external>/15933738808807975373/inttypes.h:126:10`! ":\n",
123 insn[j - 1].addresscxx . . $ cs_insn#address. + insn[j - 1].sizecxx . . $ cs_insn#size.);
124
125 // free memory allocated by cs_disasm()
126 cs_freecxx . . $ cs_free(d0ae7023b33cf0c8).(insn, count);
127 } else {
128 printfcxx . . $ printf(581fddd72a8db8fc).("****************\n");
129 printfcxx . . $ printf(581fddd72a8db8fc).("Platform: %s\n", platforms[i].commentcxx . . $ platform#comment.);
130 print_string_hexcxx . . $ print_string_hex(a4251af8cd875309).("Code:", platforms[i].codecxx . . $ platform#code.,
131 platforms[i].sizecxx . . $ platform#size.);
132 printfcxx . . $ printf(581fddd72a8db8fc).("ERROR: Failed to disasm given code!\n");
133 }
134
135 printfcxx . . $ printf(581fddd72a8db8fc).("\n");
136
137 cs_closecxx . . $ cs_close(b9ab39fbab147149).(&handlecxx . . $ handle.);
138 }
139 }
140
141 int maincxx . . $ main(d1b40a211a1a4e4c).()
142 {
143 testcxx . . $ test(d878ad36e69247c7).();
144
145 return 0;
146 }