xref: /titanic_51/usr/src/lib/libdisasm/common/libdisasm.h (revision e007031558dddc1a7f3593d9457d99bde738653e)
1dc0093f4Seschrock /*
2dc0093f4Seschrock  * CDDL HEADER START
3dc0093f4Seschrock  *
4dc0093f4Seschrock  * The contents of this file are subject to the terms of the
5dc0093f4Seschrock  * Common Development and Distribution License (the "License").
6dc0093f4Seschrock  * You may not use this file except in compliance with the License.
7dc0093f4Seschrock  *
8dc0093f4Seschrock  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9dc0093f4Seschrock  * or http://www.opensolaris.org/os/licensing.
10dc0093f4Seschrock  * See the License for the specific language governing permissions
11dc0093f4Seschrock  * and limitations under the License.
12dc0093f4Seschrock  *
13dc0093f4Seschrock  * When distributing Covered Code, include this CDDL HEADER in each
14dc0093f4Seschrock  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15dc0093f4Seschrock  * If applicable, add the following below this CDDL HEADER, with the
16dc0093f4Seschrock  * fields enclosed by brackets "[]" replaced with your own identifying
17dc0093f4Seschrock  * information: Portions Copyright [yyyy] [name of copyright owner]
18dc0093f4Seschrock  *
19dc0093f4Seschrock  * CDDL HEADER END
20dc0093f4Seschrock  */
21dc0093f4Seschrock 
22dc0093f4Seschrock /*
23*e0070315Sdmick  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
24dc0093f4Seschrock  * Use is subject to license terms.
25dc0093f4Seschrock  */
26dc0093f4Seschrock 
27dc0093f4Seschrock #ifndef	_LIBDISASM_H
28dc0093f4Seschrock #define	_LIBDISASM_H
29dc0093f4Seschrock 
30dc0093f4Seschrock #pragma ident	"%Z%%M%	%I%	%E% SMI"
31dc0093f4Seschrock 
32dc0093f4Seschrock #include <sys/types.h>
33dc0093f4Seschrock 
34dc0093f4Seschrock #ifdef	__cplusplus
35dc0093f4Seschrock extern "C" {
36dc0093f4Seschrock #endif
37dc0093f4Seschrock 
38dc0093f4Seschrock typedef struct dis_handle dis_handle_t;
39dc0093f4Seschrock 
40dc0093f4Seschrock #define	DIS_DEFAULT		0x0
41dc0093f4Seschrock 
42dc0093f4Seschrock /* SPARC disassembler flags */
43dc0093f4Seschrock #define	DIS_SPARC_V8		0x01
44dc0093f4Seschrock #define	DIS_SPARC_V9		0x02
45dc0093f4Seschrock #define	DIS_SPARC_V9_SGI	0x04
46dc0093f4Seschrock 
47dc0093f4Seschrock /* x86 diassembler flags (mutually exclusive) */
48dc0093f4Seschrock #define	DIS_X86_SIZE16		0x08
49dc0093f4Seschrock #define	DIS_X86_SIZE32		0x10
50dc0093f4Seschrock #define	DIS_X86_SIZE64		0x20
51dc0093f4Seschrock 
52dc0093f4Seschrock /* generic disassembler flags */
53dc0093f4Seschrock #define	DIS_OCTAL		0x40
54*e0070315Sdmick #define	DIS_NOIMMSYM		0x80
55dc0093f4Seschrock 
56dc0093f4Seschrock typedef int (*dis_lookup_f)(void *, uint64_t, char *, size_t, uint64_t *,
57dc0093f4Seschrock     size_t *);
58dc0093f4Seschrock typedef int (*dis_read_f)(void *, uint64_t, void *, size_t);
59dc0093f4Seschrock 
60dc0093f4Seschrock extern dis_handle_t *dis_handle_create(int, void *, dis_lookup_f, dis_read_f);
61dc0093f4Seschrock extern void dis_handle_destroy(dis_handle_t *);
62dc0093f4Seschrock 
63dc0093f4Seschrock extern int dis_disassemble(dis_handle_t *, uint64_t, char *, size_t);
64dc0093f4Seschrock extern uint64_t dis_previnstr(dis_handle_t *, uint64_t, int n);
65dc0093f4Seschrock extern void dis_set_data(dis_handle_t *, void *);
66*e0070315Sdmick extern void dis_flags_set(dis_handle_t *, int f);
67*e0070315Sdmick extern void dis_flags_clear(dis_handle_t *, int f);
68dc0093f4Seschrock extern int dis_max_instrlen(dis_handle_t *);
69dc0093f4Seschrock 
70dc0093f4Seschrock /* libdisasm errors */
71dc0093f4Seschrock #define	E_DIS_NOMEM		1	/* Out of memory */
72dc0093f4Seschrock #define	E_DIS_INVALFLAG		2	/* Invalid flag for this architecture */
73dc0093f4Seschrock 
74dc0093f4Seschrock extern int dis_errno(void);
75dc0093f4Seschrock extern const char *dis_strerror(int);
76dc0093f4Seschrock 
77dc0093f4Seschrock #ifdef	__cplusplus
78dc0093f4Seschrock }
79dc0093f4Seschrock #endif
80dc0093f4Seschrock 
81dc0093f4Seschrock #endif	/* _LIBDISASM_H */
82