| 1 | //cxx . . $ `<file>/cstool/cstool_sh.c`/ |
| 2 | // cstool_sh.c |
| 3 | // |
| 4 | // Yoshinori Sato 2022/09/07 |
| 5 | // |
| 6 | |
| 7 | #include <stdio.h> |
| 8 | #include <capstone/capstone.h>cxx . . $ `<file>/include/capstone/capstone.h`/ |
| 9 | #include "cstool.h"cxx . . $ `<file>/cstool/cstool.h`/ |
| 10 | |
| 11 | static const char* s_addressing_modescxx . . $ s_addressing_modes.[] = { |
| 12 | "<invalid mode>", |
| 13 | |
| 14 | "Register Direct", /// Rn |
| 15 | |
| 16 | "Register Indirect", /// @Rn |
| 17 | "Register Indirect with Postincrement", /// @Rn+ |
| 18 | "Register Indirect with Predecrement", /// @-Rn |
| 19 | "Register Indirect with Displacement", /// @(disp,Rn) |
| 20 | |
| 21 | "Indexed register indirect", /// @(R0, Rn) |
| 22 | "GBR indirect with displacement", /// @(disp,GBR) |
| 23 | "Indexed GBR indirect", /// @(R0, GBR) |
| 24 | |
| 25 | "PC-relative with Displacement", /// @(disp, PC) |
| 26 | |
| 27 | "Immediate value", |
| 28 | }; |
| 29 | |
| 30 | static void print_read_write_regscxx . . $ print_read_write_regs(a2e4a576d0da8a69).(cs_detailcxx . . $ cs_detail#* detail, cshcxx . . $ csh# handle) |
| 31 | { |
| 32 | int i; |
| 33 | |
| 34 | for (i = 0; i < detail->regs_read_countcxx . . $ cs_detail#regs_read_count.; ++i) { |
| 35 | uint16_tcxx . . $ uint16_t# reg_id = detail->regs_readcxx . . $ cs_detail#regs_read.[i]; |
| 36 | const char* reg_name = cs_reg_namecxx . . $ cs_reg_name(efd1348d9ae5172e).(handle, reg_id); |
| 37 | printfcxx . . $ printf(581fddd72a8db8fc).("\treading from reg: %s\n", reg_name); |
| 38 | } |
| 39 | |
| 40 | for (i = 0; i < detail->regs_write_countcxx . . $ cs_detail#regs_write_count.; ++i) { |
| 41 | uint16_tcxx . . $ uint16_t# reg_id = detail->regs_writecxx . . $ cs_detail#regs_write.[i]; |
| 42 | const char* reg_name = cs_reg_namecxx . . $ cs_reg_name(efd1348d9ae5172e).(handle, reg_id); |
| 43 | printfcxx . . $ printf(581fddd72a8db8fc).("\twriting to reg: %s\n", reg_name); |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | void print_insn_detail_shcxx . . $ print_insn_detail_sh(2888c3e5b0984e8d).(cshcxx . . $ csh# handle, cs_insncxx . . $ cs_insn# *ins) |
| 48 | { |
| 49 | cs_detailcxx . . $ cs_detail#* detail; |
| 50 | int i; |
| 51 | |
| 52 | // detail can be NULL on "data" instruction if SKIPDATA option is turned ON |
| 53 | if (ins->detailcxx . . $ cs_insn#detail. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) |
| 54 | return; |
| 55 | |
| 56 | detail = ins->detailcxx . . $ cs_insn#detail.; |
| 57 | |
| 58 | print_read_write_regscxx . . $ print_read_write_regs(a2e4a576d0da8a69).(detail, handle); |
| 59 | |
| 60 | printfcxx . . $ printf(581fddd72a8db8fc).("\tgroups_count: %u\n", detail->groups_countcxx . . $ cs_detail#groups_count.); |
| 61 | |
| 62 | for (i = 0; i < detail->shcxx . . $ cs_detail#$anonymous_type_0#sh..op_countcxx . . $ cs_sh#op_count.; i++) { |
| 63 | cs_sh_opcxx . . $ cs_sh_op#* op = &(detail->shcxx . . $ cs_detail#$anonymous_type_0#sh..operandscxx . . $ cs_sh#operands.[i]); |
| 64 | |
| 65 | switch((int)op->typecxx . . $ cs_sh_op#type.) { |
| 66 | default: |
| 67 | break; |
| 68 | case SH_OP_REGcxx . . $ SH_OP_REG.: |
| 69 | printfcxx . . $ printf(581fddd72a8db8fc).("\t\toperands[%u].type: REG = %s\n", i, cs_reg_namecxx . . $ cs_reg_name(efd1348d9ae5172e).(handle, op->regcxx . . $ cs_sh_op#$anonymous_type_3#reg.)); |
| 70 | break; |
| 71 | case SH_OP_IMMcxx . . $ SH_OP_IMM.: |
| 72 | printfcxx . . $ printf(581fddd72a8db8fc).("\t\toperands[%u].type: IMM = 0x%x\n", i, (int)op->immcxx . . $ cs_sh_op#$anonymous_type_3#imm.); |
| 73 | break; |
| 74 | case SH_OP_MEMcxx . . $ SH_OP_MEM.: |
| 75 | printfcxx . . $ printf(581fddd72a8db8fc).("\t\toperands[%u].type: MEM\n", i); |
| 76 | if (op->memcxx . . $ cs_sh_op#$anonymous_type_3#mem..regcxx . . $ sh_op_mem#reg. != SH_REG_INVALIDcxx . . $ SH_REG_INVALID.) |
| 77 | printfcxx . . $ printf(581fddd72a8db8fc).("\t\t\toperands[%u].mem.reg: REG = %s\n", |
| 78 | i, cs_reg_namecxx . . $ cs_reg_name(efd1348d9ae5172e).(handle, op->memcxx . . $ cs_sh_op#$anonymous_type_3#mem..regcxx . . $ sh_op_mem#reg.)); |
| 79 | if (op->memcxx . . $ cs_sh_op#$anonymous_type_3#mem..dispcxx . . $ sh_op_mem#disp. != 0) |
| 80 | printfcxx . . $ printf(581fddd72a8db8fc).("\t\t\toperands[%u].mem.disp: 0x%x\n", |
| 81 | i, op->memcxx . . $ cs_sh_op#$anonymous_type_3#mem..dispcxx . . $ sh_op_mem#disp.); |
| 82 | printfcxx . . $ printf(581fddd72a8db8fc).("\t\taddress mode: %s\n", s_addressing_modescxx . . $ s_addressing_modes.[op->memcxx . . $ cs_sh_op#$anonymous_type_3#mem..addresscxx . . $ sh_op_mem#address.]); |
| 83 | break; |
| 84 | } |
| 85 | } |
| 86 | } |
| 87 |