xref: /onnv-gate/usr/src/cmd/sgs/include/sparc/machdep_sparc.h (revision 12992:92dfdb3a48cc)
16206Sab196087 /*
26206Sab196087  * CDDL HEADER START
36206Sab196087  *
46206Sab196087  * The contents of this file are subject to the terms of the
56206Sab196087  * Common Development and Distribution License (the "License").
66206Sab196087  * You may not use this file except in compliance with the License.
76206Sab196087  *
86206Sab196087  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
96206Sab196087  * or http://www.opensolaris.org/os/licensing.
106206Sab196087  * See the License for the specific language governing permissions
116206Sab196087  * and limitations under the License.
126206Sab196087  *
136206Sab196087  * When distributing Covered Code, include this CDDL HEADER in each
146206Sab196087  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
156206Sab196087  * If applicable, add the following below this CDDL HEADER, with the
166206Sab196087  * fields enclosed by brackets "[]" replaced with your own identifying
176206Sab196087  * information: Portions Copyright [yyyy] [name of copyright owner]
186206Sab196087  *
196206Sab196087  * CDDL HEADER END
206206Sab196087  */
216206Sab196087 
226206Sab196087 /*
236206Sab196087  *	Copyright (c) 1988 AT&T
246206Sab196087  *	  All Rights Reserved
256206Sab196087  *
26*12992SRod.Evans@Oracle.COM  * Copyright (c) 1990, 2010, Oracle and/or its affiliates. All rights reserved.
276206Sab196087  *
286206Sab196087  * Global include file for all sgs SPARC machine dependent macros, constants
296206Sab196087  * and declarations.
306206Sab196087  */
316206Sab196087 
326206Sab196087 #ifndef	_MACHDEP_SPARC_H
336206Sab196087 #define	_MACHDEP_SPARC_H
346206Sab196087 
356206Sab196087 #include <link.h>
366206Sab196087 #include <sys/machelf.h>
376206Sab196087 
386206Sab196087 #ifdef	__cplusplus
396206Sab196087 extern "C" {
406206Sab196087 #endif
416206Sab196087 
426206Sab196087 /*
436206Sab196087  * Elf header information.
446206Sab196087  */
456206Sab196087 #define	M_MACH_32		EM_SPARC
466206Sab196087 #define	M_MACH_64		EM_SPARCV9
476206Sab196087 
486206Sab196087 #ifdef _ELF64
496206Sab196087 #define	M_MACH			EM_SPARCV9
506206Sab196087 #define	M_CLASS			ELFCLASS64
516206Sab196087 #else
526206Sab196087 #define	M_MACH			EM_SPARC
536206Sab196087 #define	M_CLASS			ELFCLASS32
546206Sab196087 #endif
556206Sab196087 #define	M_MACHPLUS		EM_SPARC32PLUS
566206Sab196087 #define	M_DATA			ELFDATA2MSB
576206Sab196087 #define	M_FLAGSPLUS		EF_SPARC_32PLUS
586206Sab196087 
596206Sab196087 /*
606206Sab196087  * Page boundary Macros: truncate to previous page boundary and round to
616206Sab196087  * next page boundary (refer to generic macros in ../sgs.h also).
626206Sab196087  */
636206Sab196087 #define	M_PTRUNC(X)	((X) & ~(syspagsz - 1))
646206Sab196087 #define	M_PROUND(X)	(((X) + syspagsz - 1) & ~(syspagsz - 1))
656206Sab196087 
666206Sab196087 /*
676206Sab196087  * Segment boundary macros: truncate to previous segment boundary and round
686206Sab196087  * to next page boundary.
696206Sab196087  */
706206Sab196087 #ifndef	M_SEGSIZE
716206Sab196087 #define	M_SEGSIZE	ELF_SPARC_MAXPGSZ
726206Sab196087 #endif
736206Sab196087 #define	M_STRUNC(X)	((X) & ~(M_SEGSIZE - 1))
746206Sab196087 #define	M_SROUND(X)	(((X) + M_SEGSIZE - 1) & ~(M_SEGSIZE - 1))
756206Sab196087 
768598SRod.Evans@Sun.COM /*
778598SRod.Evans@Sun.COM  * Relocation type macro.
788598SRod.Evans@Sun.COM  */
798598SRod.Evans@Sun.COM #define	M_RELOC		Rela
806206Sab196087 
816206Sab196087 /*
826206Sab196087  * TLS static segments must be rounded to the following requirements,
836206Sab196087  * due to libthread stack allocation.
846206Sab196087  */
856206Sab196087 #if	defined(_ELF64)
866206Sab196087 #define	M_TLSSTATALIGN	0x10
876206Sab196087 #else
886206Sab196087 #define	M_TLSSTATALIGN	0x08
896206Sab196087 #endif
906206Sab196087 
916206Sab196087 /*
926206Sab196087  * Instruction encodings.
936206Sab196087  */
946206Sab196087 #define	M_SAVESP64	0x9de3bfc0	/* save %sp, -64, %sp */
956206Sab196087 #define	M_CALL		0x40000000
966206Sab196087 #define	M_JMPL		0x81c06000	/* jmpl %g1 + simm13, %g0 */
976206Sab196087 #define	M_SETHIG0	0x01000000	/* sethi %hi(val), %g0 */
986206Sab196087 #define	M_SETHIG1	0x03000000	/* sethi %hi(val), %g1 */
996206Sab196087 #define	M_STO7G1IM	0xde206000	/* st	 %o7,[%g1 + %lo(val)] */
1006206Sab196087 #define	M_SUBFPSPG1	0x8227800e	/* sub	%fp,%sp,%g1 */
1016206Sab196087 #define	M_NOP		0x01000000	/* sethi 0, %o0 (nop) */
1026206Sab196087 #define	M_BA_A		0x30800000	/* ba,a */
1036206Sab196087 #define	M_BA_A_PT	0x30480000	/* ba,a %icc, <dst> */
1046206Sab196087 #define	M_MOVO7TOG1	0x8210000f	/* mov %o7, %g1 */
1056206Sab196087 #define	M_MOVO7TOG5	0x8a10000f	/* mov %o7, %g5 */
1066206Sab196087 #define	M_MOVI7TOG1	0x8210001f	/* mov %i7, %g1 */
1076206Sab196087 #define	M_BA_A_XCC	0x30680000	/* ba,a %xcc */
1086206Sab196087 #define	M_JMPL_G5G0	0x81c16000	/* jmpl %g5 + 0, %g0 */
1096206Sab196087 #define	M_XNOR_G5G1	0x82396000	/* xnor	%g5, 0, %g1 */
1106206Sab196087 
1116206Sab196087 
1126206Sab196087 #define	M_BIND_ADJ	4		/* adjustment for end of */
1136206Sab196087 					/*	elf_rtbndr() address */
1146206Sab196087 
11510201SEdward.Pilatowicz@Sun.COM /* transition flags for got sizing */
1166206Sab196087 #define	M_GOT_LARGE	(Sword)(-M_GOT_MAXSMALL - 1)
1176206Sab196087 #define	M_GOT_SMALL	(Sword)(-M_GOT_MAXSMALL - 2)
1186206Sab196087 #define	M_GOT_MIXED	(Sword)(-M_GOT_MAXSMALL - 3)
1196206Sab196087 
1206206Sab196087 /*
1216206Sab196087  * Other machine dependent entities
1226206Sab196087  */
1236206Sab196087 #ifdef _ELF64
1246206Sab196087 #define	M_SEGM_ALIGN	ELF_SPARCV9_MAXPGSZ
1256206Sab196087 /*
1268501SRod.Evans@Sun.COM  * Put default 64-bit programs above 4 gigabytes to help insure correctness, so
1278501SRod.Evans@Sun.COM  * that any 64-bit programs that truncate pointers will fault now instead of
1288501SRod.Evans@Sun.COM  * corrupting itself and dying mysteriously.  64-bit programs can also be
1298501SRod.Evans@Sun.COM  * restricted to a 32-bit address space (SF1_SUNW_ADDR32), and these programs
1308501SRod.Evans@Sun.COM  * provide an alternative origin.
1316206Sab196087  */
1328501SRod.Evans@Sun.COM #define	M_SEGM_ORIGIN	(Addr)0x100000000ULL	/* default 1st segment origin */
1338501SRod.Evans@Sun.COM #define	M_SEGM_AORIGIN	(Addr)0x100000ULL	/* alternative 1st segment */
1348501SRod.Evans@Sun.COM 						/*    origin */
1356206Sab196087 #else
1366206Sab196087 #define	M_SEGM_ALIGN	ELF_SPARC_MAXPGSZ
1378501SRod.Evans@Sun.COM #define	M_SEGM_ORIGIN	(Addr)0x10000		/* default 1st segment origin */
1388501SRod.Evans@Sun.COM #define	M_SEGM_AORIGIN	M_SEGM_ORIGIN		/* alternative 1st segment */
1398501SRod.Evans@Sun.COM 						/*    origin */
1406206Sab196087 #endif
1416206Sab196087 
1426206Sab196087 /*
1436206Sab196087  * Make common relocation information transparent to the common code
1446206Sab196087  */
1456206Sab196087 #define	M_REL_DT_TYPE	DT_RELA		/* .dynamic entry */
1466206Sab196087 #define	M_REL_DT_SIZE	DT_RELASZ	/* .dynamic entry */
1476206Sab196087 #define	M_REL_DT_ENT	DT_RELAENT	/* .dynamic entry */
1486206Sab196087 #define	M_REL_DT_COUNT	DT_RELACOUNT	/* .dynamic entry */
1496206Sab196087 #define	M_REL_SHT_TYPE	SHT_RELA	/* section header type */
1506206Sab196087 #define	M_REL_ELF_TYPE	ELF_T_RELA	/* data buffer type */
1516206Sab196087 
1526206Sab196087 /*
1536206Sab196087  * Make common relocation types transparent to the common code
1546206Sab196087  */
1556206Sab196087 #define	M_R_NONE	R_SPARC_NONE
1566206Sab196087 #define	M_R_GLOB_DAT	R_SPARC_GLOB_DAT
1576206Sab196087 #define	M_R_COPY	R_SPARC_COPY
1586206Sab196087 #define	M_R_RELATIVE	R_SPARC_RELATIVE
1596206Sab196087 #define	M_R_JMP_SLOT	R_SPARC_JMP_SLOT
1606206Sab196087 #define	M_R_REGISTER	R_SPARC_REGISTER
1616206Sab196087 #define	M_R_FPTR	R_SPARC_NONE
1626206Sab196087 #define	M_R_NUM		R_SPARC_NUM
1636206Sab196087 
1646206Sab196087 #ifdef	_ELF64
1656206Sab196087 #define	M_R_ARRAYADDR	R_SPARC_64
1666206Sab196087 #define	M_R_DTPMOD	R_SPARC_TLS_DTPMOD64
1676206Sab196087 #define	M_R_DTPOFF	R_SPARC_TLS_DTPOFF64
1686206Sab196087 #define	M_R_TPOFF	R_SPARC_TLS_TPOFF64
1696206Sab196087 #else	/* _ELF32 */
1706206Sab196087 #define	M_R_ARRAYADDR	R_SPARC_32
1716206Sab196087 #define	M_R_DTPMOD	R_SPARC_TLS_DTPMOD32
1726206Sab196087 #define	M_R_DTPOFF	R_SPARC_TLS_DTPOFF32
1736206Sab196087 #define	M_R_TPOFF	R_SPARC_TLS_TPOFF32
1746206Sab196087 #endif	/* _ELF64 */
1756206Sab196087 
1766206Sab196087 
1776206Sab196087 /*
1786206Sab196087  * Make register symbols transparent to common code
1796206Sab196087  */
1806206Sab196087 #define	M_DT_REGISTER	DT_SPARC_REGISTER
1816206Sab196087 
1826206Sab196087 /*
1836206Sab196087  * Make plt section information transparent to the common code.
1846206Sab196087  */
1856206Sab196087 #define	M_PLT_SHF_FLAGS	(SHF_ALLOC | SHF_WRITE | SHF_EXECINSTR)
1866206Sab196087 
1876206Sab196087 /*
18811734SAli.Bahrami@Sun.COM  * Make default data segment and stack flags transparent to the common code.
1896206Sab196087  */
1906206Sab196087 #define	M_DATASEG_PERM	(PF_R | PF_W | PF_X)
19111734SAli.Bahrami@Sun.COM #ifdef _ELF64
19211734SAli.Bahrami@Sun.COM #define	M_STACK_PERM	(PF_R | PF_W)
19311734SAli.Bahrami@Sun.COM #else
19411734SAli.Bahrami@Sun.COM #define	M_STACK_PERM	(PF_R | PF_W | PF_X)
19511734SAli.Bahrami@Sun.COM #endif
19611734SAli.Bahrami@Sun.COM 
1976206Sab196087 /*
1986206Sab196087  * Define a set of identifies for special sections.  These allow the sections
1996206Sab196087  * to be ordered within the output file image.  These values should be
2006206Sab196087  * maintained consistently, where appropriate, in each platform specific header
2016206Sab196087  * file.
2026206Sab196087  *
203*12992SRod.Evans@Oracle.COM  *  -	null identifies that this section does not need to be added to the
2046206Sab196087  *	output image (ie. shared object sections or sections we're going to
2056206Sab196087  *	recreate (sym tables, string tables, relocations, etc.)).
2066206Sab196087  *
207*12992SRod.Evans@Oracle.COM  *  -	any user defined section will be first in the associated segment.
2086206Sab196087  *
209*12992SRod.Evans@Oracle.COM  *  -	interp and capabilities sections are next, as these are accessed
2106206Sab196087  *	immediately the first page of the image is mapped.
2116206Sab196087  *
212*12992SRod.Evans@Oracle.COM  *  -	objects that do not provide an interp normally have a read-only
213*12992SRod.Evans@Oracle.COM  *	.dynamic section that comes next (in this case, there is no need to
214*12992SRod.Evans@Oracle.COM  *	update a DT_DEBUG entry at runtime).
2156206Sab196087  *
216*12992SRod.Evans@Oracle.COM  *  -	the syminfo, hash, dynsym, dynstr and rel's are grouped together as
217*12992SRod.Evans@Oracle.COM  *	these will all be accessed together by ld.so.1 to perform relocations.
218*12992SRod.Evans@Oracle.COM  *
219*12992SRod.Evans@Oracle.COM  *  -	the got, dynamic, and plt are grouped together as these may also be
2206206Sab196087  *	accessed first by ld.so.1 to perform relocations, fill in DT_DEBUG
2216206Sab196087  *	(executables only), and .plt[0].
2226206Sab196087  *
223*12992SRod.Evans@Oracle.COM  *  -	unknown sections (stabs, comments, etc.) go at the end.
2246206Sab196087  *
2256206Sab196087  * Note that .tlsbss/.bss are given the largest identifiers.  This insures that
2266206Sab196087  * if any unknown sections become associated to the same segment as the .bss,
2276206Sab196087  * the .bss sections are always the last section in the segment.
2286206Sab196087  */
2296206Sab196087 #define	M_ID_NULL	0x00
2306206Sab196087 #define	M_ID_USER	0x01
2316206Sab196087 
2326206Sab196087 #define	M_ID_INTERP	0x02			/* SHF_ALLOC */
2336206Sab196087 #define	M_ID_CAP	0x03
234*12992SRod.Evans@Oracle.COM #define	M_ID_CAPINFO	0x04
235*12992SRod.Evans@Oracle.COM #define	M_ID_CAPCHAIN	0x05
23611827SRod.Evans@Sun.COM 
237*12992SRod.Evans@Oracle.COM #define	M_ID_DYNAMIC	0x06			/* if no .interp, then no */
238*12992SRod.Evans@Oracle.COM 						/*    DT_DEBUG is required */
239*12992SRod.Evans@Oracle.COM #define	M_ID_UNWINDHDR	0x07
240*12992SRod.Evans@Oracle.COM #define	M_ID_UNWIND	0x08
241*12992SRod.Evans@Oracle.COM 
242*12992SRod.Evans@Oracle.COM #define	M_ID_SYMINFO	0x09
243*12992SRod.Evans@Oracle.COM #define	M_ID_HASH	0x0a
244*12992SRod.Evans@Oracle.COM #define	M_ID_LDYNSYM	0x0b			/* always right before DYNSYM */
245*12992SRod.Evans@Oracle.COM #define	M_ID_DYNSYM	0x0c
246*12992SRod.Evans@Oracle.COM #define	M_ID_DYNSTR	0x0d
247*12992SRod.Evans@Oracle.COM #define	M_ID_VERSION	0x0e
248*12992SRod.Evans@Oracle.COM #define	M_ID_DYNSORT	0x0f
249*12992SRod.Evans@Oracle.COM #define	M_ID_REL	0x10
250*12992SRod.Evans@Oracle.COM #define	M_ID_ARRAY	0x11
25111827SRod.Evans@Sun.COM #define	M_ID_TEXT	0x12			/* SHF_ALLOC + SHF_EXECINSTR */
2529085SAli.Bahrami@Sun.COM #define	M_ID_DATA	0x20
2536206Sab196087 
2546206Sab196087 /*	M_ID_USER	0x01			dual entry - listed above */
2556206Sab196087 #define	M_ID_GOTDATA	0x02			/* SHF_ALLOC + SHF_WRITE */
2566206Sab196087 #define	M_ID_GOT	0x03
2576206Sab196087 #define	M_ID_PLT	0x04
258*12992SRod.Evans@Oracle.COM /*	M_ID_DYNAMIC	0x06			dual entry - listed above */
259*12992SRod.Evans@Oracle.COM /*	M_ID_UNWIND	0x08			dual entry - listed above */
2606206Sab196087 
2616206Sab196087 #define	M_ID_UNKNOWN	0xfc			/* just before TLS */
2626206Sab196087 
2636206Sab196087 #define	M_ID_TLS	0xfd			/* just before bss */
2646206Sab196087 #define	M_ID_TLSBSS	0xfe
2656206Sab196087 #define	M_ID_BSS	0xff
2666206Sab196087 
2676206Sab196087 #define	M_ID_SYMTAB_NDX	0x02			/* ! SHF_ALLOC */
2686206Sab196087 #define	M_ID_SYMTAB	0x03
2696206Sab196087 #define	M_ID_STRTAB	0x04
2706206Sab196087 #define	M_ID_DYNSYM_NDX	0x05
2716206Sab196087 #define	M_ID_NOTE	0x06
2726206Sab196087 
2736206Sab196087 
2746206Sab196087 #ifdef	__cplusplus
2756206Sab196087 }
2766206Sab196087 #endif
2776206Sab196087 
2786206Sab196087 #endif /* _MACHDEP_SPARC_H */
279