1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate  * CDDL HEADER START
3*0Sstevel@tonic-gate  *
4*0Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
7*0Sstevel@tonic-gate  * with the License.
8*0Sstevel@tonic-gate  *
9*0Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate  * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate  * and limitations under the License.
13*0Sstevel@tonic-gate  *
14*0Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate  *
20*0Sstevel@tonic-gate  * CDDL HEADER END
21*0Sstevel@tonic-gate  */
22*0Sstevel@tonic-gate /*	Copyright (c) 1989 AT&T	*/
23*0Sstevel@tonic-gate /*	  All Rights Reserved  	*/
24*0Sstevel@tonic-gate 
25*0Sstevel@tonic-gate 
26*0Sstevel@tonic-gate /*
27*0Sstevel@tonic-gate  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
28*0Sstevel@tonic-gate  * Use is subject to license terms.
29*0Sstevel@tonic-gate  */
30*0Sstevel@tonic-gate 
31*0Sstevel@tonic-gate #ifndef _DWARF_H
32*0Sstevel@tonic-gate #define	_DWARF_H
33*0Sstevel@tonic-gate 
34*0Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
35*0Sstevel@tonic-gate 
36*0Sstevel@tonic-gate #include <sys/types.h>
37*0Sstevel@tonic-gate 
38*0Sstevel@tonic-gate 
39*0Sstevel@tonic-gate #ifdef	__cplusplus
40*0Sstevel@tonic-gate extern "C" {
41*0Sstevel@tonic-gate #endif
42*0Sstevel@tonic-gate 
43*0Sstevel@tonic-gate 
44*0Sstevel@tonic-gate 
45*0Sstevel@tonic-gate /* dwarf.h - manifest constants used in the .debug section of ELF files */
46*0Sstevel@tonic-gate 
47*0Sstevel@tonic-gate 
48*0Sstevel@tonic-gate /* the "tag" - the first short of any legal record */
49*0Sstevel@tonic-gate 
50*0Sstevel@tonic-gate #define	TAG_padding			0x0000
51*0Sstevel@tonic-gate #define	TAG_array_type			0x0001
52*0Sstevel@tonic-gate #define	TAG_class_type			0x0002
53*0Sstevel@tonic-gate #define	TAG_entry_point			0x0003
54*0Sstevel@tonic-gate #define	TAG_enumeration_type		0x0004
55*0Sstevel@tonic-gate #define	TAG_formal_parameter		0x0005
56*0Sstevel@tonic-gate #define	TAG_global_subroutine		0x0006
57*0Sstevel@tonic-gate #define	TAG_global_variable		0x0007
58*0Sstevel@tonic-gate #define	TAG_imported_declaration	0x0008
59*0Sstevel@tonic-gate #define	TAG_inline_subroutine		0x0009
60*0Sstevel@tonic-gate #define	TAG_label			0x000a
61*0Sstevel@tonic-gate #define	TAG_lexical_block		0x000b
62*0Sstevel@tonic-gate #define	TAG_local_variable		0x000c
63*0Sstevel@tonic-gate #define	TAG_member			0x000d
64*0Sstevel@tonic-gate #define	TAG_member_function		0x000e
65*0Sstevel@tonic-gate #define	TAG_pointer_type		0x000f
66*0Sstevel@tonic-gate #define	TAG_reference_type		0x0010
67*0Sstevel@tonic-gate #define	TAG_source_file			0x0011
68*0Sstevel@tonic-gate #define	TAG_string_type			0x0012
69*0Sstevel@tonic-gate #define	TAG_structure_type		0x0013
70*0Sstevel@tonic-gate #define	TAG_subroutine			0x0014
71*0Sstevel@tonic-gate #define	TAG_subroutine_type		0x0015
72*0Sstevel@tonic-gate #define	TAG_typedef			0x0016
73*0Sstevel@tonic-gate #define	TAG_union_type			0x0017
74*0Sstevel@tonic-gate #define	TAG_unspecified_parameters	0x0018
75*0Sstevel@tonic-gate #define	TAG_variant			0x0019
76*0Sstevel@tonic-gate 
77*0Sstevel@tonic-gate 
78*0Sstevel@tonic-gate /* attribute forms are encoded as part */
79*0Sstevel@tonic-gate /* of the attribute name and must fit */
80*0Sstevel@tonic-gate /* into 4 bits */
81*0Sstevel@tonic-gate 
82*0Sstevel@tonic-gate #define	FORM_MASK	0xf
83*0Sstevel@tonic-gate 
84*0Sstevel@tonic-gate #define	FORM_NONE	0x0	/* error */
85*0Sstevel@tonic-gate #define	FORM_ADDR	0x1	/* relocated address */
86*0Sstevel@tonic-gate #define	FORM_REF	0x2	/* reference to another .debug entry */
87*0Sstevel@tonic-gate #define	FORM_BLOCK2	0x3	/* block with 2-byte length */
88*0Sstevel@tonic-gate #define	FORM_BLOCK4	0x4	/* block with 4-byte length (unused) */
89*0Sstevel@tonic-gate #define	FORM_DATA2	0x5	/* 2 bytes */
90*0Sstevel@tonic-gate #define	FORM_DATA4	0x6	/* 4 bytes */
91*0Sstevel@tonic-gate #define	FORM_DATA8	0x7	/* 8 bytes (two 4-byte values) */
92*0Sstevel@tonic-gate #define	FORM_STRING	0x8	/* NUL-terminated string */
93*0Sstevel@tonic-gate 
94*0Sstevel@tonic-gate 
95*0Sstevel@tonic-gate /* attribute names, halfwords with low 4 bits indicating the form */
96*0Sstevel@tonic-gate 
97*0Sstevel@tonic-gate #define	AT_padding	 (0x0000|FORM_NONE)	/* just padding */
98*0Sstevel@tonic-gate #define	AT_sibling	 (0x0010|FORM_REF)	/* next owned declaration */
99*0Sstevel@tonic-gate #define	AT_location	 (0x0020|FORM_BLOCK2)	/* location description */
100*0Sstevel@tonic-gate #define	AT_name		 (0x0030|FORM_STRING)	/* symbol name */
101*0Sstevel@tonic-gate #define	AT_dimensions	 (0x0040|FORM_DATA2)	/* array dimensions */
102*0Sstevel@tonic-gate #define	AT_fund_type	 (0x0050|FORM_DATA2)	/* fund type enum */
103*0Sstevel@tonic-gate #define	AT_mod_fund_type (0x0060|FORM_BLOCK2)	/* modifiers & fund type enum */
104*0Sstevel@tonic-gate #define	AT_user_def_type (0x0070|FORM_REF)	/* type entry */
105*0Sstevel@tonic-gate #define	AT_mod_u_d_type  (0x0080|FORM_BLOCK2)	/* modifiers & type entry ref */
106*0Sstevel@tonic-gate #define	AT_ordering	 (0x0090|FORM_DATA2)	/* array row/column major */
107*0Sstevel@tonic-gate #define	AT_subscr_data	 (0x00a0|FORM_BLOCK2)	/* list of array dim info */
108*0Sstevel@tonic-gate #define	AT_byte_size	 (0x00b0|FORM_DATA4)	/* number bytes per instance */
109*0Sstevel@tonic-gate #define	AT_bit_offset	 (0x00c0|FORM_DATA2)	/* number bits padding */
110*0Sstevel@tonic-gate #define	AT_bit_size	 (0x00d0|FORM_DATA4)	/* number bits per instance */
111*0Sstevel@tonic-gate #define	AT_deriv_list	 (0x00e0|FORM_BLOCK2)	/* list of base class refs */
112*0Sstevel@tonic-gate #define	AT_element_list	 (0x00f0|FORM_BLOCK4)	/* list of enum data elements */
113*0Sstevel@tonic-gate #define	AT_stmt_list	 (0x0100|FORM_DATA4)	/* offset in .line sect */
114*0Sstevel@tonic-gate #define	AT_low_pc	 (0x0110|FORM_ADDR)	/* first machine instr */
115*0Sstevel@tonic-gate #define	AT_high_pc	 (0x0120|FORM_ADDR)	/* beyond last machine instr */
116*0Sstevel@tonic-gate #define	AT_language	 (0x0130|FORM_DATA4)	/* compiler enumeration */
117*0Sstevel@tonic-gate #define	AT_member	 (0x0140|FORM_REF)	/* class description */
118*0Sstevel@tonic-gate #define	AT_discr	 (0x0150|FORM_REF)	/* discriminant entry */
119*0Sstevel@tonic-gate #define	AT_discr_value	 (0x0160|FORM_BLOCK2)	/* value of discr */
120*0Sstevel@tonic-gate #define	AT_visibility	 (0x0170|FORM_DATA2)	/* visibility enumeration */
121*0Sstevel@tonic-gate #define	AT_import	 (0x0180|FORM_REF)	/* imported declaration */
122*0Sstevel@tonic-gate #define	AT_string_length (0x0190|FORM_BLOCK2)	/* runtime string size */
123*0Sstevel@tonic-gate 
124*0Sstevel@tonic-gate 
125*0Sstevel@tonic-gate /* atoms which compose a location description; must fit in a byte */
126*0Sstevel@tonic-gate 
127*0Sstevel@tonic-gate #define	OP_UNK		0x00	/* error */
128*0Sstevel@tonic-gate #define	OP_REG		0x01	/* push register (number) */
129*0Sstevel@tonic-gate #define	OP_BASEREG	0x02	/* push value of register (number) */
130*0Sstevel@tonic-gate #define	OP_ADDR		0x03	/* push address (relocated address) */
131*0Sstevel@tonic-gate #define	OP_CONST	0x04	/* push constant (number) */
132*0Sstevel@tonic-gate #define	OP_DEREF2	0x05	/* pop, deref and push 2 bytes (as a long) */
133*0Sstevel@tonic-gate #define	OP_DEREF4	0x06	/* pop, deref and push 4 bytes (as a long) */
134*0Sstevel@tonic-gate #define	OP_ADD		0x07	/* pop top 2 items, add, push result */
135*0Sstevel@tonic-gate 
136*0Sstevel@tonic-gate /* fundamental types; must fit in two bytes */
137*0Sstevel@tonic-gate 
138*0Sstevel@tonic-gate #define	FT_none			0x0000	/* error */
139*0Sstevel@tonic-gate #define	FT_char			0x0001	/* "plain" char */
140*0Sstevel@tonic-gate #define	FT_signed_char		0x0002
141*0Sstevel@tonic-gate #define	FT_unsigned_char	0x0003
142*0Sstevel@tonic-gate #define	FT_short		0x0004	/* "plain" short */
143*0Sstevel@tonic-gate #define	FT_signed_short		0x0005
144*0Sstevel@tonic-gate #define	FT_unsigned_short	0x0006
145*0Sstevel@tonic-gate #define	FT_integer		0x0007	/* "plain" integer */
146*0Sstevel@tonic-gate #define	FT_signed_integer	0x0008
147*0Sstevel@tonic-gate #define	FT_unsigned_integer	0x0009
148*0Sstevel@tonic-gate #define	FT_long			0x000a	/* "plain" long */
149*0Sstevel@tonic-gate #define	FT_signed_long		0x000b
150*0Sstevel@tonic-gate #define	FT_unsigned_long	0x000c
151*0Sstevel@tonic-gate #define	FT_pointer		0x000d	/* (void *) */
152*0Sstevel@tonic-gate #define	FT_float		0x000e
153*0Sstevel@tonic-gate #define	FT_dbl_prec_float	0x000f
154*0Sstevel@tonic-gate #define	FT_ext_prec_float	0x0010
155*0Sstevel@tonic-gate #define	FT_complex		0x0011
156*0Sstevel@tonic-gate #define	FT_dbl_prec_complex	0x0012
157*0Sstevel@tonic-gate #define	FT_set			0x0013
158*0Sstevel@tonic-gate #define	FT_void			0x0014
159*0Sstevel@tonic-gate 
160*0Sstevel@tonic-gate 
161*0Sstevel@tonic-gate /* type modifiers; must fit in a byte */
162*0Sstevel@tonic-gate 
163*0Sstevel@tonic-gate #define	MOD_none		0x00	/* error */
164*0Sstevel@tonic-gate #define	MOD_pointer_to		0x01
165*0Sstevel@tonic-gate #define	MOD_reference_to	0x02
166*0Sstevel@tonic-gate 
167*0Sstevel@tonic-gate 
168*0Sstevel@tonic-gate /* the "format" byte for array descriptions; formed from three */
169*0Sstevel@tonic-gate /* one-bit fields */
170*0Sstevel@tonic-gate 
171*0Sstevel@tonic-gate #define	FMT_FT	0		/* fundamental type */
172*0Sstevel@tonic-gate #define	FMT_UDT	1		/* user-defined type */
173*0Sstevel@tonic-gate 
174*0Sstevel@tonic-gate #define	FMT_CONST	0	/* 4-byte constant */
175*0Sstevel@tonic-gate #define	FMT_EXPR	1	/* block with 2-byte length (loc descr) */
176*0Sstevel@tonic-gate 
177*0Sstevel@tonic-gate #define	FMT_FT_C_C	((FMT_FT <<2) | (FMT_CONST<<1) | (FMT_CONST))
178*0Sstevel@tonic-gate #define	FMT_FT_C_X	((FMT_FT <<2) | (FMT_CONST<<1) | (FMT_EXPR))
179*0Sstevel@tonic-gate #define	FMT_FT_X_C	((FMT_FT <<2) | (FMT_EXPR <<1) | (FMT_CONST))
180*0Sstevel@tonic-gate #define	FMT_FT_X_X	((FMT_FT <<2) | (FMT_EXPR <<1) | (FMT_EXPR))
181*0Sstevel@tonic-gate #define	FMT_UT_C_C	((FMT_UDT<<2) | (FMT_CONST<<1) | (FMT_CONST))
182*0Sstevel@tonic-gate #define	FMT_UT_C_X	((FMT_UDT<<2) | (FMT_CONST<<1) | (FMT_EXPR))
183*0Sstevel@tonic-gate #define	FMT_UT_X_C	((FMT_UDT<<2) | (FMT_EXPR <<1) | (FMT_CONST))
184*0Sstevel@tonic-gate #define	FMT_UT_X_X	((FMT_UDT<<2) | (FMT_EXPR <<1) | (FMT_EXPR))
185*0Sstevel@tonic-gate 
186*0Sstevel@tonic-gate #define	FMT_ET		8	/* element type */
187*0Sstevel@tonic-gate 
188*0Sstevel@tonic-gate 
189*0Sstevel@tonic-gate /* ordering of arrays */
190*0Sstevel@tonic-gate 
191*0Sstevel@tonic-gate #define	ORD_row_major	0
192*0Sstevel@tonic-gate #define	ORD_col_major	1
193*0Sstevel@tonic-gate 
194*0Sstevel@tonic-gate 
195*0Sstevel@tonic-gate /* visibility values */
196*0Sstevel@tonic-gate 
197*0Sstevel@tonic-gate #define	VIS_local	0	/* for static functions in C */
198*0Sstevel@tonic-gate #define	VIS_exported	1	/* for Modula */
199*0Sstevel@tonic-gate 
200*0Sstevel@tonic-gate /*
201*0Sstevel@tonic-gate  * DWARF Exception Header Encoding
202*0Sstevel@tonic-gate  *
203*0Sstevel@tonic-gate  * The DWARF Exception Header Encoding is used to describe the type of data
204*0Sstevel@tonic-gate  * used in the .eh_frame_hdr section. The upper 4 bits indicate how the value
205*0Sstevel@tonic-gate  * is to be applied. The lower 4 bits indicate the format of the data.
206*0Sstevel@tonic-gate  */
207*0Sstevel@tonic-gate 
208*0Sstevel@tonic-gate /*
209*0Sstevel@tonic-gate  * Dwarf Exception Header Value format
210*0Sstevel@tonic-gate  */
211*0Sstevel@tonic-gate #define	DW_EH_PE_omit		0xff    /* No value is present. */
212*0Sstevel@tonic-gate #define	DW_EH_PE_absptr		0x00    /* Value is a void* */
213*0Sstevel@tonic-gate #define	DW_EH_PE_uleb128	0x01    /* Unsigned value is encoded using */
214*0Sstevel@tonic-gate 					/*   the Little Endian */
215*0Sstevel@tonic-gate 					/*   Base 128 (LEB128) */
216*0Sstevel@tonic-gate #define	DW_EH_PE_udata2		0x02    /* A 2 bytes unsigned value. */
217*0Sstevel@tonic-gate #define	DW_EH_PE_udata4		0x03    /* A 4 bytes unsigned value. */
218*0Sstevel@tonic-gate #define	DW_EH_PE_udata8		0x04    /* An 8 bytes unsigned value. */
219*0Sstevel@tonic-gate #define	DW_EH_PE_signed		0x08	/* bit on for all signed encodings */
220*0Sstevel@tonic-gate #define	DW_EH_PE_sleb128	0x09	/* Signed value is encoded using */
221*0Sstevel@tonic-gate 					/*   the Little Endian */
222*0Sstevel@tonic-gate 					/*   Base 128 (LEB128) */
223*0Sstevel@tonic-gate #define	DW_EH_PE_sdata2		0x0a	/* A 2 bytes signed value. */
224*0Sstevel@tonic-gate #define	DW_EH_PE_sdata4		0x0b	/* A 4 bytes signed value. */
225*0Sstevel@tonic-gate #define	DW_EH_PE_sdata8		0x0c	/* An 8 bytes signed value. */
226*0Sstevel@tonic-gate 
227*0Sstevel@tonic-gate /*
228*0Sstevel@tonic-gate  * Dwarf Exception Header application
229*0Sstevel@tonic-gate  */
230*0Sstevel@tonic-gate #define	DW_EH_PE_absptr		0x00	/* Value is used with no */
231*0Sstevel@tonic-gate 					/*  modification. */
232*0Sstevel@tonic-gate #define	DW_EH_PE_pcrel		0x10	/* Value is reletive to the location */
233*0Sstevel@tonic-gate 					/*  of itself */
234*0Sstevel@tonic-gate #define	DW_EH_PE_textrel	0x20
235*0Sstevel@tonic-gate #define	DW_EH_PE_datarel	0x30	/* Value is reletive to the beginning */
236*0Sstevel@tonic-gate 					/*  of the eh_frame_hdr segment */
237*0Sstevel@tonic-gate 					/*  ( segment type PT_AMD64_UNWIND ) */
238*0Sstevel@tonic-gate #define	DW_EH_PE_funcrel	0x40
239*0Sstevel@tonic-gate #define	DW_EH_PE_aligned	0x50	/* value is an aligned void* */
240*0Sstevel@tonic-gate #define	DW_EH_PE_indirect	0x80	/* bit to signal indirection after */
241*0Sstevel@tonic-gate 					/*  relocation */
242*0Sstevel@tonic-gate 
243*0Sstevel@tonic-gate 
244*0Sstevel@tonic-gate /* language/compiler enumeration */
245*0Sstevel@tonic-gate 
246*0Sstevel@tonic-gate typedef enum _LANG {
247*0Sstevel@tonic-gate 	LANG_UNK = 0,
248*0Sstevel@tonic-gate 	LANG_ANSI_C_V1 = 1
249*0Sstevel@tonic-gate } LANG;
250*0Sstevel@tonic-gate 
251*0Sstevel@tonic-gate /*
252*0Sstevel@tonic-gate  * Little Endian Base 128 (leb128) encoding/decoding routines
253*0Sstevel@tonic-gate  */
254*0Sstevel@tonic-gate extern	uint64_t	uleb_extract(unsigned char *, uint64_t *);
255*0Sstevel@tonic-gate extern	int64_t		sleb_extract(unsigned char *, uint64_t *);
256*0Sstevel@tonic-gate extern	uint64_t	dwarf_ehe_extract(unsigned char *, uint64_t *,
257*0Sstevel@tonic-gate 				uint_t, unsigned char *, uint64_t);
258*0Sstevel@tonic-gate 
259*0Sstevel@tonic-gate /*
260*0Sstevel@tonic-gate  * LSB32EXTRACT()
261*0Sstevel@tonic-gate  *
262*0Sstevel@tonic-gate  * Extract a LSB encoded int which may or may not be
263*0Sstevel@tonic-gate  * aligned on a 4 byte boundary.  This macro will work
264*0Sstevel@tonic-gate  * on either a MSB or LSB based system.
265*0Sstevel@tonic-gate  */
266*0Sstevel@tonic-gate #define	LSB32EXTRACT(lsbptr)	((unsigned int)(\
267*0Sstevel@tonic-gate 				((unsigned const char *)(lsbptr))[0] + \
268*0Sstevel@tonic-gate 				(((unsigned const char *)(lsbptr))[1] << 8) + \
269*0Sstevel@tonic-gate 				(((unsigned const char *)(lsbptr))[2] << 16) + \
270*0Sstevel@tonic-gate 				(((unsigned const char *)(lsbptr))[3] << 24)))
271*0Sstevel@tonic-gate 
272*0Sstevel@tonic-gate #ifdef	__cplusplus
273*0Sstevel@tonic-gate }
274*0Sstevel@tonic-gate #endif
275*0Sstevel@tonic-gate 
276*0Sstevel@tonic-gate 
277*0Sstevel@tonic-gate #endif /* _DWARF_H */
278