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