• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Capstone Disassembly Engine */
2 /* M680X Backend by Wolfgang Schwotzer <wolfgang.schwotzer@gmx.net> 2017 */
3 
4 #ifdef CAPSTONE_HAS_M680X
5 
6 #include "../../utils.h"
7 #include "../../MCRegisterInfo.h"
8 #include "M680XDisassembler.h"
9 #include "M680XDisassemblerInternals.h"
10 #include "M680XInstPrinter.h"
11 #include "M680XModule.h"
12 
M680X_global_init(cs_struct * ud)13 cs_err M680X_global_init(cs_struct *ud)
14 {
15 	m680x_info *info;
16 	cs_err errcode;
17 
18 	/* Do some validation checks */
19 	errcode = M680X_disassembler_init(ud);
20 
21 	if (errcode != CS_ERR_OK)
22 		return errcode;
23 
24 	errcode =  M680X_instprinter_init(ud);
25 
26 	if (errcode != CS_ERR_OK)
27 		return errcode;
28 
29 	// verify if requested mode is valid
30 	if (ud->mode & ~(CS_MODE_M680X_6800 | CS_MODE_M680X_6801 |
31 			CS_MODE_M680X_6805 | CS_MODE_M680X_6808 |
32 			CS_MODE_M680X_6809 | CS_MODE_M680X_6811 |
33 			CS_MODE_M680X_6301 | CS_MODE_M680X_6309 |
34 			CS_MODE_M680X_CPU12 | CS_MODE_M680X_HCS08)) {
35 		// At least one mode is not supported by M680X
36 		return CS_ERR_MODE;
37 	}
38 
39 	if (!(ud->mode & (CS_MODE_M680X_6800 | CS_MODE_M680X_6801 |
40 				CS_MODE_M680X_6805 | CS_MODE_M680X_6808 |
41 				CS_MODE_M680X_6809 | CS_MODE_M680X_6811 |
42 				CS_MODE_M680X_6301 | CS_MODE_M680X_6309 |
43 				CS_MODE_M680X_CPU12 | CS_MODE_M680X_HCS08))) {
44 		// At least the cpu type has to be selected. No default.
45 		return CS_ERR_MODE;
46 	}
47 
48 	info = cs_mem_malloc(sizeof(m680x_info));
49 
50 	if (!info)
51 		return CS_ERR_MEM;
52 
53 	ud->printer = M680X_printInst;
54 	ud->printer_info = info;
55 	ud->getinsn_info = NULL;
56 	ud->disasm = M680X_getInstruction;
57 	ud->reg_name = M680X_reg_name;
58 	ud->insn_id = M680X_get_insn_id;
59 	ud->insn_name = M680X_insn_name;
60 	ud->group_name = M680X_group_name;
61 	ud->skipdata_size = 1;
62 	ud->post_printer = NULL;
63 #ifndef CAPSTONE_DIET
64 	ud->reg_access = M680X_reg_access;
65 #endif
66 
67 	return CS_ERR_OK;
68 }
69 
M680X_option(cs_struct * handle,cs_opt_type type,size_t value)70 cs_err M680X_option(cs_struct *handle, cs_opt_type type, size_t value)
71 {
72 	//TODO
73 	return CS_ERR_OK;
74 }
75 
76 #endif
77 
78