xref: /illumos-gate/usr/src/head/syms.h (revision 581cede61ac9c14d8d4ea452562a567189eead78)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*	Copyright (c) 1988 AT&T	*/
23 /*	  All Rights Reserved  	*/
24 
25 
26 #ifndef	_SYMS_H
27 #define	_SYMS_H
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"	/* SVr4.0 2.8	*/
30 
31 /*		Storage Classes are defined in storclass.h  */
32 #include <storclass.h>
33 
34 #ifdef	__cplusplus
35 extern "C" {
36 #endif
37 
38 /*		Number of characters in a symbol name */
39 #define	SYMNMLEN	8
40 /*		Number of characters in a file name */
41 #define	FILNMLEN	14
42 /*		Number of array dimensions in auxiliary entry */
43 #define	DIMNUM		4
44 
45 struct syment
46 {
47 	union
48 	{
49 		char		_n_name[SYMNMLEN];	/* old COFF version */
50 		struct
51 		{
52 			long	_n_zeroes;	/* new == 0 */
53 			long	_n_offset;	/* offset into string table */
54 		} _n_n;
55 		char		*_n_nptr[2];	/* allows for overlaying */
56 	} _n;
57 	unsigned long		n_value;	/* value of symbol */
58 	short			n_scnum;	/* section number */
59 	unsigned short		n_type;		/* type and derived type */
60 	char			n_sclass;	/* storage class */
61 	char			n_numaux;	/* number of aux. entries */
62 };
63 
64 #define	n_name		_n._n_name
65 #define	n_nptr		_n._n_nptr[1]
66 #define	n_zeroes	_n._n_n._n_zeroes
67 #define	n_offset	_n._n_n._n_offset
68 
69 /*
70  * Relocatable symbols have a section number of the
71  * section in which they are defined.  Otherwise, section
72  * numbers have the following meanings:
73  */
74 	/* undefined symbol */
75 #define	N_UNDEF	0
76 	/* value of symbol is absolute */
77 #define	N_ABS	-1
78 	/* special debugging symbol -- value of symbol is meaningless */
79 #define	N_DEBUG	-2
80 	/* indicates symbol needs transfer vector (preload) */
81 #define	N_TV	(unsigned short)-3
82 
83 	/* indicates symbol needs transfer vector (postload) */
84 
85 #define	P_TV	(unsigned short)-4
86 
87 /*
88  * The fundamental type of a symbol packed into the low
89  * 4 bits of the word.
90  */
91 
92 #define	_EF	".ef"
93 
94 #define	T_NULL		0
95 #define	T_ARG		1	/* function argument (only used by compiler) */
96 #define	T_CHAR		2	/* character */
97 #define	T_SHORT		3	/* short integer */
98 #define	T_INT		4	/* integer */
99 #define	T_LONG		5	/* long integer */
100 #define	T_FLOAT		6	/* floating point */
101 #define	T_DOUBLE	7	/* double word */
102 #define	T_STRUCT	8	/* structure	*/
103 #define	T_UNION		9	/* union	*/
104 #define	T_ENUM		10	/* enumeration	*/
105 #define	T_MOE		11	/* member of enumeration */
106 #define	T_UCHAR		12	/* unsigned character */
107 #define	T_USHORT	13	/* unsigned short */
108 #define	T_UINT		14	/* unsigned integer */
109 #define	T_ULONG		15	/* unsigned long */
110 
111 /*
112  * derived types are:
113  */
114 
115 #define	DT_NON		0	/* no derived type */
116 #define	DT_PTR		1	/* pointer */
117 #define	DT_FCN		2	/* function */
118 #define	DT_ARY		3	/* array */
119 
120 /*
121  *   type packing constants
122  */
123 
124 #define	N_BTMASK	017
125 #define	N_TMASK		060
126 #define	N_TMASK1	0300
127 #define	N_TMASK2	0360
128 #define	N_BTSHFT	4
129 #define	N_TSHIFT	2
130 
131 /*
132  *   MACROS
133  */
134 
135 	/*   Basic Type of  x   */
136 
137 #define	BTYPE(x)  ((x) & N_BTMASK)
138 
139 	/*   Is  x  a  pointer ?   */
140 
141 #define	ISPTR(x)  (((x) & N_TMASK) == (DT_PTR << N_BTSHFT))
142 
143 	/*   Is  x  a  function ?  */
144 
145 #define	ISFCN(x)  (((x) & N_TMASK) == (DT_FCN << N_BTSHFT))
146 
147 	/*   Is  x  an  array ?   */
148 
149 #define	ISARY(x)  (((x) & N_TMASK) == (DT_ARY << N_BTSHFT))
150 
151 	/* Is x a structure, union, or enumeration TAG? */
152 
153 #define	ISTAG(x)  ((x) == C_STRTAG || (x) == C_UNTAG || (x) == C_ENTAG)
154 
155 #define	INCREF(x) ((((x)&~N_BTMASK)<<N_TSHIFT)|(DT_PTR<<N_BTSHFT)|(x&N_BTMASK))
156 
157 #define	DECREF(x) ((((x)>>N_TSHIFT)&~N_BTMASK)|((x)&N_BTMASK))
158 
159 /*
160  *	AUXILIARY ENTRY FORMAT
161  */
162 
163 union auxent
164 {
165 	struct
166 	{
167 		long		x_tagndx;	/* str, un, or enum tag indx */
168 		union
169 		{
170 			struct
171 			{
172 				unsigned short	x_lnno;	/* declaration line */
173 							/* number */
174 				unsigned short	x_size;	/* str, union, array */
175 							/* size */
176 			} x_lnsz;
177 			long	x_fsize;	/* size of function */
178 		} x_misc;
179 		union
180 		{
181 			struct			/* if ISFCN, tag, or .bb */
182 			{
183 				long	x_lnnoptr;	/* ptr to fcn line # */
184 				long	x_endndx;	/* entry ndx past */
185 							/* block end */
186 			} 	x_fcn;
187 			struct			/* if ISARY, up to 4 dimen. */
188 			{
189 				unsigned short	x_dimen[DIMNUM];
190 			} 	x_ary;
191 		}		x_fcnary;
192 		unsigned short  x_tvndx;		/* tv index */
193 	} 	x_sym;
194 	struct
195 	{
196 		char	x_fname[FILNMLEN];
197 	} 	x_file;
198 	struct
199 	{
200 		long		x_scnlen;	/* section length */
201 		unsigned short	x_nreloc;	/* number of reloc entries */
202 		unsigned short	x_nlinno;	/* number of line numbers */
203 	}	x_scn;
204 
205 	struct
206 	{
207 		long		x_tvfill;	/* tv fill value */
208 		unsigned short	x_tvlen;	/* length of .tv */
209 		unsigned short	x_tvran[2];	/* tv range */
210 	}	x_tv;	/* info about .tv section (in auxent of symbol .tv)) */
211 };
212 
213 #define	SYMENT	struct syment
214 #define	SYMESZ	18	/* sizeof(SYMENT) */
215 
216 #define	AUXENT	union auxent
217 #define	AUXESZ	18	/* sizeof(AUXENT) */
218 
219 /*	Defines for "special" symbols   */
220 
221 #define	_ETEXT	"etext"
222 #define	_EDATA	"edata"
223 #define	_END	"end"
224 #define	_START	"_start"
225 
226 #ifdef	__cplusplus
227 }
228 #endif
229 
230 #endif	/* _SYMS_H */
231