Debian Codegraph @

cstool/cstool_arm64.c

raw symbols SCIP
1 /* Capstone Disassembler Engine */
2 /* By Nguyen Anh Quynh <[email protected]>, 2013> */
3
4 #include <stdio.h>
5 #include <stdlib.h>
6
7 #include <capstone/capstone.h>
8 #include "cstool.h"
9
10 void print_insn_detail_arm64(csh handle, cs_insn *ins)
11 {
12 cs_arm64 *arm64;
13 int i;
14 cs_regs regs_read, regs_write;
15 uint8_t regs_read_count, regs_write_count;
16 uint8_t access;
17
18 // detail can be NULL if SKIPDATA option is turned ON
19 if (ins->detail == NULL)
20 return;
21
22 arm64 = &(ins->detail->arm64);
23 if (arm64->op_count)
24 printf("\top_count: %u\n", arm64->op_count);
25
26 for (i = 0; i < arm64->op_count; i++) {
27 cs_arm64_op *op = &(arm64->operands[i]);
28 switch(op->type) {
29 default:
30 break;
31 case ARM64_OP_REG:
32 printf("\t\toperands[%u].type: REG = %s\n", i, cs_reg_name(handle, op->reg));
33 break;
34 case ARM64_OP_IMM:
35 printf("\t\toperands[%u].type: IMM = 0x%" PRIx64 "\n", i, op->imm);
36 break;
37 case ARM64_OP_FP:
38 #if defined(_KERNEL_MODE)
39 // Issue #681: Windows kernel does not support formatting float point
40 printf("\t\toperands[%u].type: FP = <float_point_unsupported>\n", i);
41 #else
42 printf("\t\toperands[%u].type: FP = %f\n", i, op->fp);
43 #endif
44 break;
45 case ARM64_OP_MEM:
46 printf("\t\toperands[%u].type: MEM\n", i);
47 if (op->mem.base != ARM64_REG_INVALID)
48 printf("\t\t\toperands[%u].mem.base: REG = %s\n", i, cs_reg_name(handle, op->mem.base));
49 if (op->mem.index != ARM64_REG_INVALID)
50 printf("\t\t\toperands[%u].mem.index: REG = %s\n", i, cs_reg_name(handle, op->mem.index));
51 if (op->mem.disp != 0)
52 printf("\t\t\toperands[%u].mem.disp: 0x%x\n", i, op->mem.disp);
53
54 break;
55 case ARM64_OP_CIMM:
56 printf("\t\toperands[%u].type: C-IMM = %u\n", i, (int)op->imm);
57 break;
58 case ARM64_OP_REG_MRS:
59 printf("\t\toperands[%u].type: REG_MRS = 0x%x\n", i, op->reg);
60 break;
61 case ARM64_OP_REG_MSR:
62 printf("\t\toperands[%u].type: REG_MSR = 0x%x\n", i, op->reg);
63 break;
64 case ARM64_OP_PSTATE:
65 printf("\t\toperands[%u].type: PSTATE = 0x%x\n", i, op->pstate);
66 break;
67 case ARM64_OP_SYS:
68 printf("\t\toperands[%u].type: SYS = 0x%x\n", i, op->sys);
69 break;
70 case ARM64_OP_PREFETCH:
71 printf("\t\toperands[%u].type: PREFETCH = 0x%x\n", i, op->prefetch);
72 break;
73 case ARM64_OP_BARRIER:
74 printf("\t\toperands[%u].type: BARRIER = 0x%x\n", i, op->barrier);
75 break;
76 case ARM64_OP_SVCR:
77 printf("\t\toperands[%u].type: SYS = 0x%x\n", i, op->sys);
78 if(op->svcr == ARM64_SVCR_SVCRSM)
79 printf("\t\t\toperands[%u].svcr: BIT = SM\n", i);
80 if(op->svcr == ARM64_SVCR_SVCRZA)
81 printf("\t\t\toperands[%u].svcr: BIT = ZA\n", i);
82 if(op->svcr == ARM64_SVCR_SVCRSMZA)
83 printf("\t\t\toperands[%u].svcr: BIT = SM & ZA\n", i);
84 break;
85 case ARM64_OP_SME_INDEX:
86 printf("\t\toperands[%u].type: REG = %s\n", i, cs_reg_name(handle, op->sme_index.reg));
87 if (op->sme_index.base != ARM64_REG_INVALID)
88 printf("\t\t\toperands[%u].index.base: REG = %s\n", i, cs_reg_name(handle, op->sme_index.base));
89 if (op->sme_index.disp != 0)
90 printf("\t\t\toperands[%u].index.disp: 0x%x\n", i, op->sme_index.disp);
91 break;
92 }
93
94 access = op->access;
95 switch(access) {
96 default:
97 break;
98 case CS_AC_READ:
99 printf("\t\toperands[%u].access: READ\n", i);
100 break;
101 case CS_AC_WRITE:
102 printf("\t\toperands[%u].access: WRITE\n", i);
103 break;
104 case CS_AC_READ | CS_AC_WRITE:
105 printf("\t\toperands[%u].access: READ | WRITE\n", i);
106 break;
107 }
108
109 if (op->shift.type != ARM64_SFT_INVALID &&
110 op->shift.value)
111 printf("\t\t\tShift: type = %u, value = %u\n",
112 op->shift.type, op->shift.value);
113
114 if (op->ext != ARM64_EXT_INVALID)
115 printf("\t\t\tExt: %u\n", op->ext);
116
117 if (op->vas != ARM64_VAS_INVALID)
118 printf("\t\t\tVector Arrangement Specifier: 0x%x\n", op->vas);
119
120 if (op->vector_index != -1)
121 printf("\t\t\tVector Index: %u\n", op->vector_index);
122 }
123
124 if (arm64->update_flags)
125 printf("\tUpdate-flags: True\n");
126
127 if (arm64->writeback)
128 printf("\tWrite-back: True\n");
129
130 if (arm64->cc)
131 printf("\tCode-condition: %u\n", arm64->cc);
132
133 // Print out all registers accessed by this instruction (either implicit or explicit)
134 if (!cs_regs_access(handle, ins,
135 regs_read, &regs_read_count,
136 regs_write, &regs_write_count)) {
137 if (regs_read_count) {
138 printf("\tRegisters read:");
139 for(i = 0; i < regs_read_count; i++) {
140 printf(" %s", cs_reg_name(handle, regs_read[i]));
141 }
142 printf("\n");
143 }
144
145 if (regs_write_count) {
146 printf("\tRegisters modified:");
147 for(i = 0; i < regs_write_count; i++) {
148 printf(" %s", cs_reg_name(handle, regs_write[i]));
149 }
150 printf("\n");
151 }
152 }
153 }