1/* Capstone Disassembly Engine */
2/* By Nguyen Anh Quynh <aquynh@gmail.com>, 2013-2014 */
3
4#ifdef CAPSTONE_HAS_SPARC
5
6#include "../../utils.h"
7#include "../../MCRegisterInfo.h"
8#include "SparcDisassembler.h"
9#include "SparcInstPrinter.h"
10#include "SparcMapping.h"
11
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_BIG_ENDIAN | CS_MODE_V9))
18		return CS_ERR_MODE;
19
20	mri = cs_mem_malloc(sizeof(*mri));
21
22	Sparc_init(mri);
23	ud->printer = Sparc_printInst;
24	ud->printer_info = mri;
25	ud->getinsn_info = mri;
26	ud->disasm = Sparc_getInstruction;
27	ud->post_printer = Sparc_post_printer;
28
29	ud->reg_name = Sparc_reg_name;
30	ud->insn_id = Sparc_get_insn_id;
31	ud->insn_name = Sparc_insn_name;
32	ud->group_name = Sparc_group_name;
33
34	return CS_ERR_OK;
35}
36
37static cs_err option(cs_struct *handle, cs_opt_type type, size_t value)
38{
39	if (type == CS_OPT_SYNTAX)
40		handle->syntax = (int) value;
41
42	if (type == CS_OPT_MODE) {
43		handle->big_endian = (((cs_mode)value & CS_MODE_BIG_ENDIAN) != 0);
44	}
45
46	return CS_ERR_OK;
47}
48
49static void destroy(cs_struct *handle)
50{
51}
52
53void Sparc_enable(void)
54{
55	arch_init[CS_ARCH_SPARC] = init;
56	arch_option[CS_ARCH_SPARC] = option;
57	arch_destroy[CS_ARCH_SPARC] = destroy;
58
59	// support this arch
60	all_arch |= (1 << CS_ARCH_SPARC);
61}
62
63#endif
64