1 /* Capstone Disassembly Engine */ 2 /* By Dang Hoang Vu <danghvu@gmail.com> 2013 */ 3 4 #ifdef CAPSTONE_HAS_MIPS 5 6 #include "../../utils.h" 7 #include "../../MCRegisterInfo.h" 8 #include "MipsDisassembler.h" 9 #include "MipsInstPrinter.h" 10 #include "MipsMapping.h" 11 init(cs_struct * ud)12static cs_err init(cs_struct *ud) 13 { 14 MCRegisterInfo *mri; 15 16 // verify if requested mode is valid 17 if (ud->mode & ~(CS_MODE_LITTLE_ENDIAN | CS_MODE_32 | CS_MODE_64 | 18 CS_MODE_MICRO | CS_MODE_MIPS32R6 | 19 CS_MODE_MIPSGP64 | CS_MODE_BIG_ENDIAN)) 20 return CS_ERR_MODE; 21 22 mri = cs_mem_malloc(sizeof(*mri)); 23 24 Mips_init(mri); 25 ud->printer = Mips_printInst; 26 ud->printer_info = mri; 27 ud->getinsn_info = mri; 28 ud->reg_name = Mips_reg_name; 29 ud->insn_id = Mips_get_insn_id; 30 ud->insn_name = Mips_insn_name; 31 ud->group_name = Mips_group_name; 32 33 if (ud->mode & CS_MODE_32 || ud->mode & CS_MODE_MIPS32R6) 34 ud->disasm = Mips_getInstruction; 35 else 36 ud->disasm = Mips64_getInstruction; 37 38 return CS_ERR_OK; 39 } 40 option(cs_struct * handle,cs_opt_type type,size_t value)41static cs_err option(cs_struct *handle, cs_opt_type type, size_t value) 42 { 43 if (type == CS_OPT_MODE) { 44 if (value & CS_MODE_32) 45 handle->disasm = Mips_getInstruction; 46 else 47 handle->disasm = Mips64_getInstruction; 48 49 handle->mode = (cs_mode)value; 50 handle->big_endian = ((handle->mode & CS_MODE_BIG_ENDIAN) != 0); 51 } 52 return CS_ERR_OK; 53 } 54 destroy(cs_struct * handle)55static void destroy(cs_struct *handle) 56 { 57 } 58 Mips_enable(void)59void Mips_enable(void) 60 { 61 arch_init[CS_ARCH_MIPS] = init; 62 arch_option[CS_ARCH_MIPS] = option; 63 arch_destroy[CS_ARCH_MIPS] = destroy; 64 65 // support this arch 66 all_arch |= (1 << CS_ARCH_MIPS); 67 } 68 69 #endif 70