#ifndef CAPSTONE_M680X_H #define CAPSTONE_M680X_H /* Capstone Disassembly Engine */ /* M680X Backend by Wolfgang Schwotzer 2017 */ #ifdef __cplusplus extern "C" { #endif #include "platform.h" #ifdef _MSC_VER #pragma warning(disable:4201) #endif #define M680X_OPERAND_COUNT 9 /// M680X registers and special registers typedef enum m680x_reg { M680X_REG_INVALID = 0, M680X_REG_A, ///< M6800/1/2/3/9, HD6301/9 M680X_REG_B, ///< M6800/1/2/3/9, HD6301/9 M680X_REG_E, ///< HD6309 M680X_REG_F, ///< HD6309 M680X_REG_0, ///< HD6309 M680X_REG_D, ///< M6801/3/9, HD6301/9 M680X_REG_W, ///< HD6309 M680X_REG_CC, ///< M6800/1/2/3/9, M6301/9 M680X_REG_DP, ///< M6809/M6309 M680X_REG_MD, ///< M6309 M680X_REG_HX, ///< M6808 M680X_REG_H, ///< M6808 M680X_REG_X, ///< M6800/1/2/3/9, M6301/9 M680X_REG_Y, ///< M6809/M6309 M680X_REG_S, ///< M6809/M6309 M680X_REG_U, ///< M6809/M6309 M680X_REG_V, ///< M6309 M680X_REG_Q, ///< M6309 M680X_REG_PC, ///< M6800/1/2/3/9, M6301/9 M680X_REG_TMP2, ///< CPU12 M680X_REG_TMP3, ///< CPU12 M680X_REG_ENDING, ///< <-- mark the end of the list of registers } m680x_reg; /// Operand type for instruction's operands typedef enum m680x_op_type { M680X_OP_INVALID = 0, ///< = CS_OP_INVALID (Uninitialized). M680X_OP_REGISTER, ///< = Register operand. M680X_OP_IMMEDIATE, ///< = Immediate operand. M680X_OP_INDEXED, ///< = Indexed addressing operand. M680X_OP_EXTENDED, ///< = Extended addressing operand. M680X_OP_DIRECT, ///< = Direct addressing operand. M680X_OP_RELATIVE, ///< = Relative addressing operand. M680X_OP_CONSTANT, ///< = constant operand (Displayed as number only). ///< Used e.g. for a bit index or page number. } m680x_op_type; // Supported bit values for mem.idx.offset_bits #define M680X_OFFSET_NONE 0 #define M680X_OFFSET_BITS_5 5 #define M680X_OFFSET_BITS_8 8 #define M680X_OFFSET_BITS_9 9 #define M680X_OFFSET_BITS_16 16 // Supported bit flags for mem.idx.flags // These flags can be combined #define M680X_IDX_INDIRECT 1 #define M680X_IDX_NO_COMMA 2 #define M680X_IDX_POST_INC_DEC 4 /// Instruction's operand referring to indexed addressing typedef struct m680x_op_idx { m680x_reg base_reg; ///< base register (or M680X_REG_INVALID if ///< irrelevant) m680x_reg offset_reg; ///< offset register (or M680X_REG_INVALID if ///< irrelevant) int16_t offset; ///< 5-,8- or 16-bit offset. See also offset_bits. uint16_t offset_addr; ///< = offset addr. if base_reg == M680X_REG_PC. ///< calculated as offset + PC uint8_t offset_bits; ///< offset width in bits for indexed addressing int8_t inc_dec; ///< inc. or dec. value: ///< 0: no inc-/decrement ///< 1 .. 8: increment by 1 .. 8 ///< -1 .. -8: decrement by 1 .. 8 ///< if flag M680X_IDX_POST_INC_DEC set it is post ///< inc-/decrement otherwise pre inc-/decrement uint8_t flags; ///< 8-bit flags (see above) } m680x_op_idx; /// Instruction's memory operand referring to relative addressing (Bcc/LBcc) typedef struct m680x_op_rel { uint16_t address; ///< The absolute address. ///< calculated as PC + offset. PC is the first ///< address after the instruction. int16_t offset; ///< the offset/displacement value } m680x_op_rel; /// Instruction's operand referring to extended addressing typedef struct m680x_op_ext { uint16_t address; ///< The absolute address bool indirect; ///< true if extended indirect addressing } m680x_op_ext; /// Instruction operand typedef struct cs_m680x_op { m680x_op_type type; union { int32_t imm; ///< immediate value for IMM operand m680x_reg reg; ///< register value for REG operand m680x_op_idx idx; ///< Indexed addressing operand m680x_op_rel rel; ///< Relative address. operand (Bcc/LBcc) m680x_op_ext ext; ///< Extended address uint8_t direct_addr; ///<