xref: /titanic_51/usr/src/cmd/sgs/include/sparc/machdep_sparc.h (revision 25540de2e9a31b620c68d87ce2f3bbe8a196ad93)
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 (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  *	Copyright (c) 1988 AT&T
24  *	  All Rights Reserved
25  *
26  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
27  * Use is subject to license terms.
28  *
29  * Global include file for all sgs SPARC machine dependent macros, constants
30  * and declarations.
31  */
32 
33 #ifndef	_MACHDEP_SPARC_H
34 #define	_MACHDEP_SPARC_H
35 
36 #include <link.h>
37 #include <sys/machelf.h>
38 
39 #ifdef	__cplusplus
40 extern "C" {
41 #endif
42 
43 /*
44  * Elf header information.
45  */
46 #define	M_MACH_32		EM_SPARC
47 #define	M_MACH_64		EM_SPARCV9
48 
49 #ifdef _ELF64
50 #define	M_MACH			EM_SPARCV9
51 #define	M_CLASS			ELFCLASS64
52 #else
53 #define	M_MACH			EM_SPARC
54 #define	M_CLASS			ELFCLASS32
55 #endif
56 #define	M_MACHPLUS		EM_SPARC32PLUS
57 #define	M_DATA			ELFDATA2MSB
58 #define	M_FLAGSPLUS		EF_SPARC_32PLUS
59 
60 /*
61  * Page boundary Macros: truncate to previous page boundary and round to
62  * next page boundary (refer to generic macros in ../sgs.h also).
63  */
64 #define	M_PTRUNC(X)	((X) & ~(syspagsz - 1))
65 #define	M_PROUND(X)	(((X) + syspagsz - 1) & ~(syspagsz - 1))
66 
67 /*
68  * Segment boundary macros: truncate to previous segment boundary and round
69  * to next page boundary.
70  */
71 #ifndef	M_SEGSIZE
72 #define	M_SEGSIZE	ELF_SPARC_MAXPGSZ
73 #endif
74 #define	M_STRUNC(X)	((X) & ~(M_SEGSIZE - 1))
75 #define	M_SROUND(X)	(((X) + M_SEGSIZE - 1) & ~(M_SEGSIZE - 1))
76 
77 
78 /*
79  * TLS static segments must be rounded to the following requirements,
80  * due to libthread stack allocation.
81  */
82 #if	defined(_ELF64)
83 #define	M_TLSSTATALIGN	0x10
84 #else
85 #define	M_TLSSTATALIGN	0x08
86 #endif
87 
88 
89 /*
90  * Instruction encodings.
91  */
92 #define	M_SAVESP64	0x9de3bfc0	/* save %sp, -64, %sp */
93 #define	M_CALL		0x40000000
94 #define	M_JMPL		0x81c06000	/* jmpl %g1 + simm13, %g0 */
95 #define	M_SETHIG0	0x01000000	/* sethi %hi(val), %g0 */
96 #define	M_SETHIG1	0x03000000	/* sethi %hi(val), %g1 */
97 #define	M_STO7G1IM	0xde206000	/* st	 %o7,[%g1 + %lo(val)] */
98 #define	M_SUBFPSPG1	0x8227800e	/* sub	%fp,%sp,%g1 */
99 #define	M_NOP		0x01000000	/* sethi 0, %o0 (nop) */
100 #define	M_BA_A		0x30800000	/* ba,a */
101 #define	M_BA_A_PT	0x30480000	/* ba,a %icc, <dst> */
102 #define	M_MOVO7TOG1	0x8210000f	/* mov %o7, %g1 */
103 #define	M_MOVO7TOG5	0x8a10000f	/* mov %o7, %g5 */
104 #define	M_MOVI7TOG1	0x8210001f	/* mov %i7, %g1 */
105 #define	M_BA_A_XCC	0x30680000	/* ba,a %xcc */
106 #define	M_JMPL_G5G0	0x81c16000	/* jmpl %g5 + 0, %g0 */
107 #define	M_XNOR_G5G1	0x82396000	/* xnor	%g5, 0, %g1 */
108 
109 
110 #define	M_BIND_ADJ	4		/* adjustment for end of */
111 					/*	elf_rtbndr() address */
112 
113 
114 /*
115  * Plt and Got information; the first few .got and .plt entries are reserved
116  *	PLT[0]	jump to dynamic linker
117  *	GOT[0]	address of _DYNAMIC
118  */
119 #define	M_PLT_INSSIZE	4		/* single plt instruction size */
120 #define	M_GOT_XDYNAMIC	0		/* got index for _DYNAMIC */
121 #define	M_GOT_XNumber	1		/* reserved no. of got entries */
122 
123 /*
124  * ELF32 bit PLT constants
125  */
126 #define	M32_PLT_ENTSIZE		12	/* 32bit plt entry size in bytes */
127 
128 /*
129  * ELF64 bit PLT constants
130  */
131 #define	M64_PLT_NEARPLTS	0x8000	/* # of NEAR PLTS we can have */
132 #define	M64_PLT_ENTSIZE		32	/* plt entry size in bytes */
133 #define	M64_PLT_FENTSIZE	24	/* size of far plt is 6 instructions */
134 					/*	x 4bytes */
135 #define	M64_PLT_PSIZE		8		/* size of PLTP pointer */
136 #define	M64_PLT_FBLKCNTS	160	/* # of plts in far PLT blocks */
137 #define	M64_PLT_FBLOCKSZ	(M64_PLT_FBLKCNTS *\
138 				M64_PLT_ENTSIZE) /* size of far PLT block */
139 
140 
141 #ifdef _ELF64
142 #define	M_PLT_ENTSIZE	M64_PLT_ENTSIZE	/* plt entry size in bytes */
143 #define	M_PLT_XNumber	4		/* reserved no. of plt entries */
144 #define	M_PLT_ALIGN	256		/* alignment of .plt section */
145 #define	M_PLT_RESERVSZ	(M_PLT_XNumber * \
146 			M_PLT_ENTSIZE)	/* first 4 plt's reserved */
147 #define	M_GOT_ENTSIZE	8		/* got entry size in bytes */
148 #define	M_GOT_MAXSMALL	1024		/* maximum no. of small gots */
149 #else /* Elf32 */
150 #define	M_PLT_ENTSIZE	M32_PLT_ENTSIZE	/* plt entry size in bytes */
151 #define	M_PLT_XNumber	4		/* reserved no. of plt entries */
152 #define	M_PLT_ALIGN	M_WORD_ALIGN	/* alignment of .plt section */
153 #define	M_PLT_RESERVSZ	(M_PLT_XNumber * \
154 			M_PLT_ENTSIZE)	/* first 4 plt's reserved */
155 #define	M_GOT_ENTSIZE	4		/* got entry size in bytes */
156 #define	M_GOT_MAXSMALL	2048		/* maximum no. of small gots */
157 #endif /* _ELF64 */
158 					/* transition flags for got sizing */
159 #define	M_GOT_LARGE	(Sword)(-M_GOT_MAXSMALL - 1)
160 #define	M_GOT_SMALL	(Sword)(-M_GOT_MAXSMALL - 2)
161 #define	M_GOT_MIXED	(Sword)(-M_GOT_MAXSMALL - 3)
162 
163 
164 /*
165  * Other machine dependent entities
166  */
167 #ifdef _ELF64
168 #define	M_SEGM_ALIGN	ELF_SPARCV9_MAXPGSZ
169 /*
170  * Put default 64-bit programs above 4 gigabytes to help insure correctness, so
171  * that any 64-bit programs that truncate pointers will fault now instead of
172  * corrupting itself and dying mysteriously.  64-bit programs can also be
173  * restricted to a 32-bit address space (SF1_SUNW_ADDR32), and these programs
174  * provide an alternative origin.
175  */
176 #define	M_SEGM_ORIGIN	(Addr)0x100000000ULL	/* default 1st segment origin */
177 #define	M_SEGM_AORIGIN	(Addr)0x100000ULL	/* alternative 1st segment */
178 						/*    origin */
179 #define	M_WORD_ALIGN	8
180 #else
181 #define	M_SEGM_ALIGN	ELF_SPARC_MAXPGSZ
182 #define	M_SEGM_ORIGIN	(Addr)0x10000		/* default 1st segment origin */
183 #define	M_SEGM_AORIGIN	M_SEGM_ORIGIN		/* alternative 1st segment */
184 						/*    origin */
185 #define	M_WORD_ALIGN	4
186 #endif
187 
188 /*
189  * Make common relocation information transparent to the common code
190  */
191 #define	M_REL_DT_TYPE	DT_RELA		/* .dynamic entry */
192 #define	M_REL_DT_SIZE	DT_RELASZ	/* .dynamic entry */
193 #define	M_REL_DT_ENT	DT_RELAENT	/* .dynamic entry */
194 #define	M_REL_DT_COUNT	DT_RELACOUNT	/* .dynamic entry */
195 #define	M_REL_SHT_TYPE	SHT_RELA	/* section header type */
196 #define	M_REL_ELF_TYPE	ELF_T_RELA	/* data buffer type */
197 
198 /*
199  * Make common relocation types transparent to the common code
200  */
201 #define	M_R_NONE	R_SPARC_NONE
202 #define	M_R_GLOB_DAT	R_SPARC_GLOB_DAT
203 #define	M_R_COPY	R_SPARC_COPY
204 #define	M_R_RELATIVE	R_SPARC_RELATIVE
205 #define	M_R_JMP_SLOT	R_SPARC_JMP_SLOT
206 #define	M_R_REGISTER	R_SPARC_REGISTER
207 #define	M_R_FPTR	R_SPARC_NONE
208 #define	M_R_NUM		R_SPARC_NUM
209 
210 #ifdef	_ELF64
211 #define	M_R_ARRAYADDR	R_SPARC_64
212 #define	M_R_DTPMOD	R_SPARC_TLS_DTPMOD64
213 #define	M_R_DTPOFF	R_SPARC_TLS_DTPOFF64
214 #define	M_R_TPOFF	R_SPARC_TLS_TPOFF64
215 #else	/* _ELF32 */
216 #define	M_R_ARRAYADDR	R_SPARC_32
217 #define	M_R_DTPMOD	R_SPARC_TLS_DTPMOD32
218 #define	M_R_DTPOFF	R_SPARC_TLS_DTPOFF32
219 #define	M_R_TPOFF	R_SPARC_TLS_TPOFF32
220 #endif	/* _ELF64 */
221 
222 
223 /*
224  * Make register symbols transparent to common code
225  */
226 #define	M_DT_REGISTER	DT_SPARC_REGISTER
227 
228 /*
229  * Make plt section information transparent to the common code.
230  */
231 #define	M_PLT_SHF_FLAGS	(SHF_ALLOC | SHF_WRITE | SHF_EXECINSTR)
232 
233 /*
234  * Make data segment information transparent to the common code.
235  */
236 #define	M_DATASEG_PERM	(PF_R | PF_W | PF_X)
237 
238 /*
239  * Define a set of identifies for special sections.  These allow the sections
240  * to be ordered within the output file image.  These values should be
241  * maintained consistently, where appropriate, in each platform specific header
242  * file.
243  *
244  *  o	null identifies that this section does not need to be added to the
245  *	output image (ie. shared object sections or sections we're going to
246  *	recreate (sym tables, string tables, relocations, etc.)).
247  *
248  *  o	any user defined section will be first in the associated segment.
249  *
250  *  o	interp and capabilities sections are next, as these are accessed
251  *	immediately the first page of the image is mapped.
252  *
253  *  o	the syminfo, hash, dynsym, dynstr and rel's are grouped together as
254  *	these will all be accessed first by ld.so.1 to perform relocations.
255  *
256  *  o	the got, dynamic, and plt are grouped together as these may also be
257  *	accessed first by ld.so.1 to perform relocations, fill in DT_DEBUG
258  *	(executables only), and .plt[0].
259  *
260  *  o	unknown sections (stabs, comments etc.) go at the end.
261  *
262  * Note that .tlsbss/.bss are given the largest identifiers.  This insures that
263  * if any unknown sections become associated to the same segment as the .bss,
264  * the .bss sections are always the last section in the segment.
265  */
266 #define	M_ID_NULL	0x00
267 #define	M_ID_USER	0x01
268 
269 #define	M_ID_INTERP	0x02			/* SHF_ALLOC */
270 #define	M_ID_CAP	0x03
271 #define	M_ID_SYMINFO	0x04
272 #define	M_ID_HASH	0x05
273 #define	M_ID_LDYNSYM	0x06			/* always right before DYNSYM */
274 #define	M_ID_DYNSYM	0x07
275 #define	M_ID_DYNSTR	0x08
276 #define	M_ID_VERSION	0x09
277 #define	M_ID_DYNSORT	0x0a
278 #define	M_ID_REL	0x0b
279 #define	M_ID_TEXT	0x0c			/* SHF_ALLOC + SHF_EXECINSTR */
280 #define	M_ID_DATA	0x0d
281 
282 /*	M_ID_USER	0x01			dual entry - listed above */
283 #define	M_ID_GOTDATA	0x02			/* SHF_ALLOC + SHF_WRITE */
284 #define	M_ID_GOT	0x03
285 #define	M_ID_PLT	0x04
286 #define	M_ID_DYNAMIC	0x05
287 #define	M_ID_ARRAY	0x06
288 
289 #define	M_ID_UNKNOWN	0xfc			/* just before TLS */
290 
291 #define	M_ID_TLS	0xfd			/* just before bss */
292 #define	M_ID_TLSBSS	0xfe
293 #define	M_ID_BSS	0xff
294 
295 #define	M_ID_SYMTAB_NDX	0x02			/* ! SHF_ALLOC */
296 #define	M_ID_SYMTAB	0x03
297 #define	M_ID_STRTAB	0x04
298 #define	M_ID_DYNSYM_NDX	0x05
299 #define	M_ID_NOTE	0x06
300 
301 
302 #ifdef	__cplusplus
303 }
304 #endif
305 
306 #endif /* _MACHDEP_SPARC_H */
307