Debian Codegraph @

cstool/cstool_m680x.c

raw symbols SCIP
1 /* Capstone Disassembly Engine */cxx . . $ `<file>/cstool/cstool_m680x.c`/
2 /* M680X Backend by Wolfgang Schwotzer <[email protected]> 2017 */
3
4 #include <stdio.h>
5 #include <capstone/capstone.h>cxx . . $ `<file>/include/capstone/capstone.h`/
6 #include "cstool.h"cxx . . $ `<file>/cstool/cstool.h`/
7
8 static const char *s_accesscxx . . $ s_access.[] = {
9 "UNCHANGED", "READ", "WRITE", "READ | WRITE",
10 };
11
12 static void print_read_write_regscxx . . $ print_read_write_regs(429ed0f42458107e).(cshcxx . . $ csh# handle, cs_detailcxx . . $ cs_detail# *detail)
13 {
14 int i;
15
16 if (detail->regs_read_countcxx . . $ cs_detail#regs_read_count. > 0) {
17 printfcxx . . $ printf(581fddd72a8db8fc).("\treading from regs: ");
18
19 for (i = 0; i < detail->regs_read_countcxx . . $ cs_detail#regs_read_count.; ++i) {
20 if (i > 0)
21 printfcxx . . $ printf(581fddd72a8db8fc).(", ");
22
23 printfcxx . . $ printf(581fddd72a8db8fc).("%s", cs_reg_namecxx . . $ cs_reg_name(efd1348d9ae5172e).(handle, detail->regs_readcxx . . $ cs_detail#regs_read.[i]));
24 }
25
26 printfcxx . . $ printf(581fddd72a8db8fc).("\n");
27 }
28
29 if (detail->regs_write_countcxx . . $ cs_detail#regs_write_count. > 0) {
30 printfcxx . . $ printf(581fddd72a8db8fc).("\twriting to regs: ");
31
32 for (i = 0; i < detail->regs_write_countcxx . . $ cs_detail#regs_write_count.; ++i) {
33 if (i > 0)
34 printfcxx . . $ printf(581fddd72a8db8fc).(", ");
35
36 printfcxx . . $ printf(581fddd72a8db8fc).("%s", cs_reg_namecxx . . $ cs_reg_name(efd1348d9ae5172e).(handle,
37 detail->regs_writecxx . . $ cs_detail#regs_write.[i]));
38 }
39
40 printfcxx . . $ printf(581fddd72a8db8fc).("\n");
41 }
42 }
43
44 void print_insn_detail_m680xcxx . . $ print_insn_detail_m680x(2888c3e5b0984e8d).(cshcxx . . $ csh# handle, cs_insncxx . . $ cs_insn# *insn)
45 {
46 cs_detailcxx . . $ cs_detail# *detail = insn->detailcxx . . $ cs_insn#detail.;
47 cs_m680xcxx . . $ cs_m680x# *m680x = NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!;
48 int i;
49
50 // detail can be NULL on "data" instruction if SKIPDATA option is
51 // turned ON
52 if (detail == NULLcxx . . $ `<external>/16391990256953433862/stddef.h:419:9`!)
53 return;
54
55 m680x = &detail->m680xcxx . . $ cs_detail#$anonymous_type_0#m680x.;
56
57 if (m680x->op_countcxx . . $ cs_m680x#op_count.)
58 printfcxx . . $ printf(581fddd72a8db8fc).("\top_count: %u\n", m680x->op_countcxx . . $ cs_m680x#op_count.);
59
60 for (i = 0; i < m680x->op_countcxx . . $ cs_m680x#op_count.; i++) {
61 cs_m680x_opcxx . . $ cs_m680x_op# *op = &(m680x->operandscxx . . $ cs_m680x#operands.[i]);
62 const char *comment;
63
64 switch ((int)op->typecxx . . $ cs_m680x_op#type.) {
65 default:
66 break;
67
68 case M680X_OP_REGISTERcxx . . $ M680X_OP_REGISTER.:
69 comment = "";
70
71 if ((i == 0 && m680x->flagscxx . . $ cs_m680x#flags. & M680X_FIRST_OP_IN_MNEMcxx . . $ `include/capstone/m680x.h:159:9`!) ||
72 (i == 1 && m680x->flagscxx . . $ cs_m680x#flags. &
73 M680X_SECOND_OP_IN_MNEMcxx . . $ `include/capstone/m680x.h:162:9`!))
74 comment = " (in mnemonic)";
75
76 printfcxx . . $ printf(581fddd72a8db8fc).("\t\toperands[%u].type: REGISTER = %s%s\n", i,
77 cs_reg_namecxx . . $ cs_reg_name(efd1348d9ae5172e).(handle, op->regcxx . . $ cs_m680x_op#$anonymous_type_0#reg.), comment);
78 break;
79
80 case M680X_OP_CONSTANTcxx . . $ M680X_OP_CONSTANT.:
81 printfcxx . . $ printf(581fddd72a8db8fc).("\t\toperands[%u].type: CONSTANT = %u\n", i,
82 op->const_valcxx . . $ cs_m680x_op#$anonymous_type_0#const_val.);
83 break;
84
85 case M680X_OP_IMMEDIATEcxx . . $ M680X_OP_IMMEDIATE.:
86 printfcxx . . $ printf(581fddd72a8db8fc).("\t\toperands[%u].type: IMMEDIATE = #%d\n", i,
87 op->immcxx . . $ cs_m680x_op#$anonymous_type_0#imm.);
88 break;
89
90 case M680X_OP_DIRECTcxx . . $ M680X_OP_DIRECT.:
91 printfcxx . . $ printf(581fddd72a8db8fc).("\t\toperands[%u].type: DIRECT = 0x%02x\n", i,
92 op->direct_addrcxx . . $ cs_m680x_op#$anonymous_type_0#direct_addr.);
93 break;
94
95 case M680X_OP_EXTENDEDcxx . . $ M680X_OP_EXTENDED.:
96 printfcxx . . $ printf(581fddd72a8db8fc).("\t\toperands[%u].type: EXTENDED %s = 0x%04x\n",
97 i, op->extcxx . . $ cs_m680x_op#$anonymous_type_0#ext..indirectcxx . . $ m680x_op_ext#indirect. ? "INDIRECT" : "",
98 op->extcxx . . $ cs_m680x_op#$anonymous_type_0#ext..addresscxx . . $ m680x_op_ext#address.);
99 break;
100
101 case M680X_OP_RELATIVEcxx . . $ M680X_OP_RELATIVE.:
102 printfcxx . . $ printf(581fddd72a8db8fc).("\t\toperands[%u].type: RELATIVE = 0x%04x\n", i,
103 op->relcxx . . $ cs_m680x_op#$anonymous_type_0#rel..addresscxx . . $ m680x_op_rel#address.);
104 break;
105
106 case M680X_OP_INDEXEDcxx . . $ M680X_OP_INDEXED.:
107 printfcxx . . $ printf(581fddd72a8db8fc).("\t\toperands[%u].type: INDEXED%s\n", i,
108 (op->idxcxx . . $ cs_m680x_op#$anonymous_type_0#idx..flagscxx . . $ m680x_op_idx#flags. & M680X_IDX_INDIRECTcxx . . $ `include/capstone/m680x.h:76:9`!) ?
109 " INDIRECT" : "");
110
111 if (op->idxcxx . . $ cs_m680x_op#$anonymous_type_0#idx..base_regcxx . . $ m680x_op_idx#base_reg. != M680X_REG_INVALIDcxx . . $ M680X_REG_INVALID.)
112 printfcxx . . $ printf(581fddd72a8db8fc).("\t\t\tbase register: %s\n",
113 cs_reg_namecxx . . $ cs_reg_name(efd1348d9ae5172e).(handle, op->idxcxx . . $ cs_m680x_op#$anonymous_type_0#idx..base_regcxx . . $ m680x_op_idx#base_reg.));
114
115 if (op->idxcxx . . $ cs_m680x_op#$anonymous_type_0#idx..offset_regcxx . . $ m680x_op_idx#offset_reg. != M680X_REG_INVALIDcxx . . $ M680X_REG_INVALID.)
116 printfcxx . . $ printf(581fddd72a8db8fc).("\t\t\toffset register: %s\n",
117 cs_reg_namecxx . . $ cs_reg_name(efd1348d9ae5172e).(handle, op->idxcxx . . $ cs_m680x_op#$anonymous_type_0#idx..offset_regcxx . . $ m680x_op_idx#offset_reg.));
118
119 if ((op->idxcxx . . $ cs_m680x_op#$anonymous_type_0#idx..offset_bitscxx . . $ m680x_op_idx#offset_bits. != 0) &&
120 (op->idxcxx . . $ cs_m680x_op#$anonymous_type_0#idx..offset_regcxx . . $ m680x_op_idx#offset_reg. == M680X_REG_INVALIDcxx . . $ M680X_REG_INVALID.) &&
121 !op->idxcxx . . $ cs_m680x_op#$anonymous_type_0#idx..inc_deccxx . . $ m680x_op_idx#inc_dec.) {
122 printfcxx . . $ printf(581fddd72a8db8fc).("\t\t\toffset: %d\n", op->idxcxx . . $ cs_m680x_op#$anonymous_type_0#idx..offsetcxx . . $ m680x_op_idx#offset.);
123
124 if (op->idxcxx . . $ cs_m680x_op#$anonymous_type_0#idx..base_regcxx . . $ m680x_op_idx#base_reg. == M680X_REG_PCcxx . . $ M680X_REG_PC.)
125 printfcxx . . $ printf(581fddd72a8db8fc).("\t\t\toffset address: 0x%x\n",
126 op->idxcxx . . $ cs_m680x_op#$anonymous_type_0#idx..offset_addrcxx . . $ m680x_op_idx#offset_addr.);
127
128 printfcxx . . $ printf(581fddd72a8db8fc).("\t\t\toffset bits: %u\n",
129 op->idxcxx . . $ cs_m680x_op#$anonymous_type_0#idx..offset_bitscxx . . $ m680x_op_idx#offset_bits.);
130 }
131
132 if (op->idxcxx . . $ cs_m680x_op#$anonymous_type_0#idx..inc_deccxx . . $ m680x_op_idx#inc_dec.) {
133 const char *post_pre = op->idxcxx . . $ cs_m680x_op#$anonymous_type_0#idx..flagscxx . . $ m680x_op_idx#flags. &
134 M680X_IDX_POST_INC_DECcxx . . $ `include/capstone/m680x.h:78:9`! ? "post" : "pre";
135 const char *inc_dec = (op->idxcxx . . $ cs_m680x_op#$anonymous_type_0#idx..inc_deccxx . . $ m680x_op_idx#inc_dec. > 0) ?
136 "increment" : "decrement";
137
138 printfcxx . . $ printf(581fddd72a8db8fc).("\t\t\t%s %s: %d\n", post_pre, inc_dec,
139 abscxx . . $ abs(7864480464b09eea).(op->idxcxx . . $ cs_m680x_op#$anonymous_type_0#idx..inc_deccxx . . $ m680x_op_idx#inc_dec.));
140 }
141
142 break;
143 }
144
145 if (op->sizecxx . . $ cs_m680x_op#size. != 0)
146 printfcxx . . $ printf(581fddd72a8db8fc).("\t\t\tsize: %u\n", op->sizecxx . . $ cs_m680x_op#size.);
147
148 if (op->accesscxx . . $ cs_m680x_op#access. != CS_AC_INVALIDcxx . . $ CS_AC_INVALID.)
149 printfcxx . . $ printf(581fddd72a8db8fc).("\t\t\taccess: %s\n", s_accesscxx . . $ s_access.[op->accesscxx . . $ cs_m680x_op#access.]);
150 }
151
152 print_read_write_regscxx . . $ print_read_write_regs(429ed0f42458107e).(handle, detail);
153 }
154