| 1 | //cxx . . $ `<file>/cstool/cstool_m68k.c`/ |
| 2 | // cstool_m68k.c |
| 3 | // |
| 4 | // |
| 5 | // Created by YUHANG TANG on 26/10/16. |
| 6 | // |
| 7 | // |
| 8 | |
| 9 | #include <stdio.h> |
| 10 | #include <capstone/capstone.h>cxx . . $ `<file>/include/capstone/capstone.h`/ |
| 11 | #include "cstool.h"cxx . . $ `<file>/cstool/cstool.h`/ |
| 12 | |
| 13 | static const char* s_addressing_modescxx . . $ s_addressing_modes.[] = { |
| 14 | "<invalid mode>", |
| 15 | |
| 16 | "Register Direct - Data", |
| 17 | "Register Direct - Address", |
| 18 | |
| 19 | "Register Indirect - Address", |
| 20 | "Register Indirect - Address with Postincrement", |
| 21 | "Register Indirect - Address with Predecrement", |
| 22 | "Register Indirect - Address with Displacement", |
| 23 | |
| 24 | "Address Register Indirect With Index - 8-bit displacement", |
| 25 | "Address Register Indirect With Index - Base displacement", |
| 26 | |
| 27 | "Memory indirect - Postindex", |
| 28 | "Memory indirect - Preindex", |
| 29 | |
| 30 | "Program Counter Indirect - with Displacement", |
| 31 | |
| 32 | "Program Counter Indirect with Index - with 8-Bit Displacement", |
| 33 | "Program Counter Indirect with Index - with Base Displacement", |
| 34 | |
| 35 | "Program Counter Memory Indirect - Postindexed", |
| 36 | "Program Counter Memory Indirect - Preindexed", |
| 37 | |
| 38 | "Absolute Data Addressing - Short", |
| 39 | "Absolute Data Addressing - Long", |
| 40 | "Immediate value", |
| 41 | }; |
| 42 | |
| 43 | static void print_read_write_regscxx . . $ print_read_write_regs(a2e4a576d0da8a69).(cs_detailcxx . . $ cs_detail#* detail, cshcxx . . $ csh# handle) |
| 44 | { |
| 45 | int i; |
| 46 | |
| 47 | for (i = 0; i < detail->regs_read_countcxx . . $ cs_detail#regs_read_count.; ++i) { |
| 48 | uint16_tcxx . . $ uint16_t# reg_id = detail->regs_readcxx . . $ cs_detail#regs_read.[i]; |
| 49 | const char* reg_name = cs_reg_namecxx . . $ cs_reg_name(efd1348d9ae5172e).(handle, reg_id); |
| 50 | printfcxx . . $ printf(581fddd72a8db8fc).("\treading from reg: %s\n", reg_name); |
| 51 | } |
| 52 | |
| 53 | for (i = 0; i < detail->regs_write_countcxx . . $ cs_detail#regs_write_count.; ++i) { |
| 54 | uint16_tcxx . . $ uint16_t# reg_id = detail->regs_writecxx . . $ cs_detail#regs_write.[i]; |
| 55 | const char* reg_name = cs_reg_namecxx . . $ cs_reg_name(efd1348d9ae5172e).(handle, reg_id); |
| 56 | printfcxx . . $ printf(581fddd72a8db8fc).("\twriting to reg: %s\n", reg_name); |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | void print_insn_detail_m68kcxx . . $ print_insn_detail_m68k(2888c3e5b0984e8d).(cshcxx . . $ csh# handle, cs_insncxx . . $ cs_insn# *ins) |
| 61 | { |
| 62 | cs_m68kcxx . . $ cs_m68k#* m68k; |
| 63 | cs_detailcxx . . $ cs_detail#* detail; |
| 64 | int i; |
| 65 | |
| 66 | // detail can be NULL on "data" instruction if SKIPDATA option is turned ON |
| 67 | if (ins->detailcxx . . $ cs_insn#detail. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) |
| 68 | return; |
| 69 | |
| 70 | detail = ins->detailcxx . . $ cs_insn#detail.; |
| 71 | m68k = &detail->m68kcxx . . $ cs_detail#$anonymous_type_0#m68k.; |
| 72 | if (m68k->op_countcxx . . $ cs_m68k#op_count.) |
| 73 | printfcxx . . $ printf(581fddd72a8db8fc).("\top_count: %u\n", m68k->op_countcxx . . $ cs_m68k#op_count.); |
| 74 | |
| 75 | print_read_write_regscxx . . $ print_read_write_regs(a2e4a576d0da8a69).(detail, handle); |
| 76 | |
| 77 | printfcxx . . $ printf(581fddd72a8db8fc).("\tgroups_count: %u\n", detail->groups_countcxx . . $ cs_detail#groups_count.); |
| 78 | |
| 79 | for (i = 0; i < m68k->op_countcxx . . $ cs_m68k#op_count.; i++) { |
| 80 | cs_m68k_opcxx . . $ cs_m68k_op#* op = &(m68k->operandscxx . . $ cs_m68k#operands.[i]); |
| 81 | |
| 82 | switch((int)op->typecxx . . $ cs_m68k_op#type.) { |
| 83 | default: |
| 84 | break; |
| 85 | case M68K_OP_REGcxx . . $ M68K_OP_REG.: |
| 86 | printfcxx . . $ printf(581fddd72a8db8fc).("\t\toperands[%u].type: REG = %s\n", i, cs_reg_namecxx . . $ cs_reg_name(efd1348d9ae5172e).(handle, op->regcxx . . $ cs_m68k_op#$anonymous_type_0#reg.)); |
| 87 | break; |
| 88 | case M68K_OP_IMMcxx . . $ M68K_OP_IMM.: |
| 89 | printfcxx . . $ printf(581fddd72a8db8fc).("\t\toperands[%u].type: IMM = 0x%x\n", i, (int)op->immcxx . . $ cs_m68k_op#$anonymous_type_0#imm.); |
| 90 | break; |
| 91 | case M68K_OP_MEMcxx . . $ M68K_OP_MEM.: |
| 92 | printfcxx . . $ printf(581fddd72a8db8fc).("\t\toperands[%u].type: MEM\n", i); |
| 93 | if (op->memcxx . . $ cs_m68k_op#mem..base_regcxx . . $ m68k_op_mem#base_reg. != M68K_REG_INVALIDcxx . . $ M68K_REG_INVALID.) |
| 94 | printfcxx . . $ printf(581fddd72a8db8fc).("\t\t\toperands[%u].mem.base: REG = %s\n", |
| 95 | i, cs_reg_namecxx . . $ cs_reg_name(efd1348d9ae5172e).(handle, op->memcxx . . $ cs_m68k_op#mem..base_regcxx . . $ m68k_op_mem#base_reg.)); |
| 96 | if (op->memcxx . . $ cs_m68k_op#mem..index_regcxx . . $ m68k_op_mem#index_reg. != M68K_REG_INVALIDcxx . . $ M68K_REG_INVALID.) { |
| 97 | printfcxx . . $ printf(581fddd72a8db8fc).("\t\t\toperands[%u].mem.index: REG = %s\n", |
| 98 | i, cs_reg_namecxx . . $ cs_reg_name(efd1348d9ae5172e).(handle, op->memcxx . . $ cs_m68k_op#mem..index_regcxx . . $ m68k_op_mem#index_reg.)); |
| 99 | printfcxx . . $ printf(581fddd72a8db8fc).("\t\t\toperands[%u].mem.index: size = %c\n", |
| 100 | i, op->memcxx . . $ cs_m68k_op#mem..index_sizecxx . . $ m68k_op_mem#index_size. ? 'l' : 'w'); |
| 101 | } |
| 102 | if (op->memcxx . . $ cs_m68k_op#mem..dispcxx . . $ m68k_op_mem#disp. != 0) |
| 103 | printfcxx . . $ printf(581fddd72a8db8fc).("\t\t\toperands[%u].mem.disp: 0x%x\n", i, op->memcxx . . $ cs_m68k_op#mem..dispcxx . . $ m68k_op_mem#disp.); |
| 104 | if (op->memcxx . . $ cs_m68k_op#mem..scalecxx . . $ m68k_op_mem#scale. != 0) |
| 105 | printfcxx . . $ printf(581fddd72a8db8fc).("\t\t\toperands[%u].mem.scale: %d\n", i, op->memcxx . . $ cs_m68k_op#mem..scalecxx . . $ m68k_op_mem#scale.); |
| 106 | |
| 107 | printfcxx . . $ printf(581fddd72a8db8fc).("\t\taddress mode: %s\n", s_addressing_modescxx . . $ s_addressing_modes.[op->address_modecxx . . $ cs_m68k_op#address_mode.]); |
| 108 | break; |
| 109 | case M68K_OP_FP_SINGLEcxx . . $ M68K_OP_FP_SINGLE.: |
| 110 | printfcxx . . $ printf(581fddd72a8db8fc).("\t\toperands[%u].type: FP_SINGLE\n", i); |
| 111 | printfcxx . . $ printf(581fddd72a8db8fc).("\t\t\toperands[%u].simm: %f\n", i, op->simmcxx . . $ cs_m68k_op#$anonymous_type_0#simm.); |
| 112 | break; |
| 113 | case M68K_OP_FP_DOUBLEcxx . . $ M68K_OP_FP_DOUBLE.: |
| 114 | printfcxx . . $ printf(581fddd72a8db8fc).("\t\toperands[%u].type: FP_DOUBLE\n", i); |
| 115 | printfcxx . . $ printf(581fddd72a8db8fc).("\t\t\toperands[%u].dimm: %lf\n", i, op->dimmcxx . . $ cs_m68k_op#$anonymous_type_0#dimm.); |
| 116 | break; |
| 117 | } |
| 118 | } |
| 119 | } |
| 120 |