xref: /onnv-gate/usr/src/cmd/sgs/include/i386/machdep_x86.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 ia32 based machine dependent macros,
296206Sab196087  * constants and declarations.
306206Sab196087  */
316206Sab196087 
326206Sab196087 #ifndef	_MACHDEP_X86_H
336206Sab196087 #define	_MACHDEP_X86_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_386
466206Sab196087 #define	M_MACH_64		EM_AMD64
476206Sab196087 
486206Sab196087 #ifdef _ELF64
496206Sab196087 #define	M_MACH			EM_AMD64
506206Sab196087 #define	M_CLASS			ELFCLASS64
516206Sab196087 #else
526206Sab196087 #define	M_MACH			EM_386
536206Sab196087 #define	M_CLASS			ELFCLASS32
546206Sab196087 #endif
556206Sab196087 
566206Sab196087 #define	M_MACHPLUS		M_MACH
576206Sab196087 #define	M_DATA			ELFDATA2LSB
586206Sab196087 #define	M_FLAGSPLUS		0
596206Sab196087 
606206Sab196087 /*
616206Sab196087  * Page boundary Macros: truncate to previous page boundary and round to
626206Sab196087  * next page boundary (refer to generic macros in ../sgs.h also).
636206Sab196087  */
646206Sab196087 #define	M_PTRUNC(X)	((X) & ~(syspagsz - 1))
656206Sab196087 #define	M_PROUND(X)	(((X) + syspagsz - 1) & ~(syspagsz - 1))
666206Sab196087 
676206Sab196087 /*
686206Sab196087  * Segment boundary macros: truncate to previous segment boundary and round
696206Sab196087  * to next page boundary.
706206Sab196087  */
716206Sab196087 #if	defined(_ELF64)
726206Sab196087 #define	M_SEGSIZE	ELF_AMD64_MAXPGSZ
736206Sab196087 #else
746206Sab196087 #define	M_SEGSIZE	ELF_386_MAXPGSZ
756206Sab196087 #endif
766206Sab196087 
776206Sab196087 #define	M_STRUNC(X)	((X) & ~(M_SEGSIZE - 1))
786206Sab196087 #define	M_SROUND(X)	(((X) + M_SEGSIZE - 1) & ~(M_SEGSIZE - 1))
796206Sab196087 
806206Sab196087 /*
818598SRod.Evans@Sun.COM  * Relocation type macros.
828598SRod.Evans@Sun.COM  */
838598SRod.Evans@Sun.COM #if	defined(_ELF64)
848598SRod.Evans@Sun.COM #define	M_RELOC		Rela
858598SRod.Evans@Sun.COM #else
868598SRod.Evans@Sun.COM #define	M_RELOC		Rel
878598SRod.Evans@Sun.COM #endif
888598SRod.Evans@Sun.COM 
898598SRod.Evans@Sun.COM /*
906206Sab196087  * TLS static segments must be rounded to the following requirements,
916206Sab196087  * due to libthread stack allocation.
926206Sab196087  */
936206Sab196087 #if	defined(_ELF64)
946206Sab196087 #define	M_TLSSTATALIGN	0x10
956206Sab196087 #else
966206Sab196087 #define	M_TLSSTATALIGN	0x08
976206Sab196087 #endif
986206Sab196087 
996206Sab196087 /*
1006206Sab196087  * Other machine dependent entities
1016206Sab196087  */
1026206Sab196087 #if	defined(_ELF64)
1036206Sab196087 #define	M_SEGM_ALIGN	0x00010000
1046206Sab196087 #else
1056206Sab196087 #define	M_SEGM_ALIGN	ELF_386_MAXPGSZ
1066206Sab196087 #endif
1076206Sab196087 
1086206Sab196087 /*
1096206Sab196087  * Values for IA32 objects
1106206Sab196087  */
1116206Sab196087 
1126206Sab196087 /*
1136206Sab196087  * Instruction encodings.
1146206Sab196087  */
1156206Sab196087 #define	M_INST_JMP		0xe9
1166206Sab196087 #define	M_INST_PUSHL		0x68
1176206Sab196087 #define	M_SPECIAL_INST		0xff
1186206Sab196087 #define	M_PUSHL_DISP		0x35
1196206Sab196087 #define	M_PUSHL_REG_DISP	0xb3
1206206Sab196087 #define	M_JMP_DISP_IND		0x25
1216206Sab196087 #define	M_JMP_REG_DISP_IND	0xa3
1226206Sab196087 #define	M_NOP			0x90
1236206Sab196087 
1246206Sab196087 #define	M_BIND_ADJ	1		/* adjustment for end of */
1256206Sab196087 					/*	elf_rtbndr() address */
1266206Sab196087 #ifdef _ELF64
1278501SRod.Evans@Sun.COM /*
1288501SRod.Evans@Sun.COM  * Provide default starting addresses.  64-bit programs can also be restricted
1298501SRod.Evans@Sun.COM  * to a 32-bit address space (SF1_SUNW_ADDR32), and these programs provide an
1308501SRod.Evans@Sun.COM  * alternative origin.
1318501SRod.Evans@Sun.COM  */
1328501SRod.Evans@Sun.COM #define	M_SEGM_ORIGIN	(Addr)0x400000ULL	/* default 1st segment origin */
1338501SRod.Evans@Sun.COM #define	M_SEGM_AORIGIN	(Addr)0x10000ULL	/* alternative 1st segment */
1348501SRod.Evans@Sun.COM 						/*    origin */
1356206Sab196087 #else
1366206Sab196087 #define	M_STACK_GAP	(0x08000000)
1376206Sab196087 #define	M_STACK_PGS	(0x00048000)
1386206Sab196087 #define	M_SEGM_ORIGIN	(Addr)(M_STACK_GAP + M_STACK_PGS)
1398501SRod.Evans@Sun.COM #define	M_SEGM_AORIGIN	M_SEGM_ORIGIN
1406206Sab196087 #endif
1416206Sab196087 
1426206Sab196087 /*
1436206Sab196087  * Make common relocation information transparent to the common code
1446206Sab196087  */
1456206Sab196087 #if	defined(_ELF64)
1466206Sab196087 #define	M_REL_DT_TYPE	DT_RELA		/* .dynamic entry */
1476206Sab196087 #define	M_REL_DT_SIZE	DT_RELASZ	/* .dynamic entry */
1486206Sab196087 #define	M_REL_DT_ENT	DT_RELAENT	/* .dynamic entry */
1496206Sab196087 #define	M_REL_DT_COUNT	DT_RELACOUNT	/* .dynamic entry */
1506206Sab196087 #define	M_REL_SHT_TYPE	SHT_RELA	/* section header type */
1516206Sab196087 #define	M_REL_ELF_TYPE	ELF_T_RELA	/* data buffer type */
1526206Sab196087 
1536206Sab196087 #else /* _ELF32 */
1546206Sab196087 #define	M_REL_DT_TYPE	DT_REL		/* .dynamic entry */
1556206Sab196087 #define	M_REL_DT_SIZE	DT_RELSZ	/* .dynamic entry */
1566206Sab196087 #define	M_REL_DT_ENT	DT_RELENT	/* .dynamic entry */
1576206Sab196087 #define	M_REL_DT_COUNT	DT_RELCOUNT	/* .dynamic entry */
1586206Sab196087 #define	M_REL_SHT_TYPE	SHT_REL		/* section header type */
1596206Sab196087 #define	M_REL_ELF_TYPE	ELF_T_REL	/* data buffer type */
1606206Sab196087 
1616206Sab196087 #endif /* ELF32 */
1626206Sab196087 
1636206Sab196087 /*
1646206Sab196087  * Make common relocation types transparent to the common code
1656206Sab196087  */
1666206Sab196087 #if	defined(_ELF64)
1676206Sab196087 #define	M_R_NONE	R_AMD64_NONE
1686206Sab196087 #define	M_R_GLOB_DAT	R_AMD64_GLOB_DAT
1696206Sab196087 #define	M_R_COPY	R_AMD64_COPY
1706206Sab196087 #define	M_R_RELATIVE	R_AMD64_RELATIVE
1716206Sab196087 #define	M_R_JMP_SLOT	R_AMD64_JUMP_SLOT
1726206Sab196087 #define	M_R_FPTR	R_AMD64_NONE
1736206Sab196087 #define	M_R_ARRAYADDR	R_AMD64_GLOB_DAT
1746206Sab196087 #define	M_R_NUM		R_AMD64_NUM
1756206Sab196087 #else
1766206Sab196087 #define	M_R_NONE	R_386_NONE
1776206Sab196087 #define	M_R_GLOB_DAT	R_386_GLOB_DAT
1786206Sab196087 #define	M_R_COPY	R_386_COPY
1796206Sab196087 #define	M_R_RELATIVE	R_386_RELATIVE
1806206Sab196087 #define	M_R_JMP_SLOT	R_386_JMP_SLOT
1816206Sab196087 #define	M_R_FPTR	R_386_NONE
1826206Sab196087 #define	M_R_ARRAYADDR	R_386_GLOB_DAT
1836206Sab196087 #define	M_R_NUM		R_386_NUM
1846206Sab196087 #endif
1856206Sab196087 
1866206Sab196087 /*
1876206Sab196087  * The following are defined as M_R_NONE so that checks
1886206Sab196087  * for these relocations can be performed in common code - although
1896206Sab196087  * the checks are really only relevant to SPARC.
1906206Sab196087  */
1916206Sab196087 #define	M_R_REGISTER	M_R_NONE
1926206Sab196087 
1936206Sab196087 /*
1946206Sab196087  * DT_REGISTER is not valid on i386 or amd64
1956206Sab196087  */
1966206Sab196087 #define	M_DT_REGISTER	0xffffffff
1976206Sab196087 
1986206Sab196087 /*
1996206Sab196087  * Make plt section information transparent to the common code.
2006206Sab196087  */
2016206Sab196087 #define	M_PLT_SHF_FLAGS	(SHF_ALLOC | SHF_EXECINSTR)
2026206Sab196087 
2036206Sab196087 /*
20411734SAli.Bahrami@Sun.COM  * Make default data segment and stack flags transparent to the common code.
2056206Sab196087  */
2066206Sab196087 #ifdef _ELF64
2076206Sab196087 #define	M_DATASEG_PERM	(PF_R | PF_W)
20811734SAli.Bahrami@Sun.COM #define	M_STACK_PERM	(PF_R | PF_W)
2096206Sab196087 #else
2106206Sab196087 #define	M_DATASEG_PERM	(PF_R | PF_W | PF_X)
21111734SAli.Bahrami@Sun.COM #define	M_STACK_PERM	(PF_R | PF_W | PF_X)
2126206Sab196087 #endif
2136206Sab196087 
2146206Sab196087 /*
2156206Sab196087  * Define a set of identifies for special sections.  These allow the sections
2166206Sab196087  * to be ordered within the output file image.  These values should be
2176206Sab196087  * maintained consistently, where appropriate, in each platform specific header
2186206Sab196087  * file.
2196206Sab196087  *
220*12992SRod.Evans@Oracle.COM  *  -	null identifies that this section does not need to be added to the
2216206Sab196087  *	output image (ie. shared object sections or sections we're going to
2226206Sab196087  *	recreate (sym tables, string tables, relocations, etc.)).
2236206Sab196087  *
224*12992SRod.Evans@Oracle.COM  *  -	any user defined section will be first in the associated segment.
2256206Sab196087  *
226*12992SRod.Evans@Oracle.COM  *  -	interp and capabilities sections are next, as these are accessed
2276206Sab196087  *	immediately the first page of the image is mapped.
2286206Sab196087  *
229*12992SRod.Evans@Oracle.COM  *  -	objects that do not provide an interp normally have a read-only
230*12992SRod.Evans@Oracle.COM  *	.dynamic section that comes next (in this case, there is no need to
231*12992SRod.Evans@Oracle.COM  *	update a DT_DEBUG entry at runtime).
2326206Sab196087  *
233*12992SRod.Evans@Oracle.COM  *  -	the syminfo, hash, dynsym, dynstr and rel's are grouped together as
234*12992SRod.Evans@Oracle.COM  *	these will all be accessed together by ld.so.1 to perform relocations.
235*12992SRod.Evans@Oracle.COM  *
236*12992SRod.Evans@Oracle.COM  *  -	the got and dynamic are grouped together as these may also be
2376206Sab196087  *	accessed first by ld.so.1 to perform relocations, fill in DT_DEBUG
2386206Sab196087  *	(executables only), and .got[0].
2396206Sab196087  *
240*12992SRod.Evans@Oracle.COM  *  -	unknown sections (stabs, comments, etc.) go at the end.
2416206Sab196087  *
2426206Sab196087  * Note that .tlsbss/.bss are given the largest identifiers.  This insures that
2436206Sab196087  * if any unknown sections become associated to the same segment as the .bss,
2446206Sab196087  * the .bss sections are always the last section in the segment.
2456206Sab196087  */
2466206Sab196087 #define	M_ID_NULL	0x00
2476206Sab196087 #define	M_ID_USER	0x01
2486206Sab196087 
24911827SRod.Evans@Sun.COM #define	M_ID_INTERP	0x02			/* SHF_ALLOC */
25011827SRod.Evans@Sun.COM #define	M_ID_CAP	0x03
251*12992SRod.Evans@Oracle.COM #define	M_ID_CAPINFO	0x04
252*12992SRod.Evans@Oracle.COM #define	M_ID_CAPCHAIN	0x05
25311827SRod.Evans@Sun.COM 
254*12992SRod.Evans@Oracle.COM #define	M_ID_DYNAMIC	0x06			/* if no .interp, then no */
255*12992SRod.Evans@Oracle.COM 						/*    DT_DEBUG is required */
256*12992SRod.Evans@Oracle.COM #define	M_ID_UNWINDHDR	0x07
257*12992SRod.Evans@Oracle.COM #define	M_ID_UNWIND	0x08
258*12992SRod.Evans@Oracle.COM 
259*12992SRod.Evans@Oracle.COM #define	M_ID_SYMINFO	0x09
260*12992SRod.Evans@Oracle.COM #define	M_ID_HASH	0x0a
261*12992SRod.Evans@Oracle.COM #define	M_ID_LDYNSYM	0x0b			/* always right before DYNSYM */
262*12992SRod.Evans@Oracle.COM #define	M_ID_DYNSYM	0x0c
263*12992SRod.Evans@Oracle.COM #define	M_ID_DYNSTR	0x0d
264*12992SRod.Evans@Oracle.COM #define	M_ID_VERSION	0x0e
265*12992SRod.Evans@Oracle.COM #define	M_ID_DYNSORT	0x0f
266*12992SRod.Evans@Oracle.COM #define	M_ID_REL	0x10
267*12992SRod.Evans@Oracle.COM #define	M_ID_PLT	0x11			/* SHF_ALLOC + SHF_EXECINSTR */
268*12992SRod.Evans@Oracle.COM #define	M_ID_ARRAY	0x12
26911827SRod.Evans@Sun.COM #define	M_ID_TEXT	0x13
2706206Sab196087 #define	M_ID_DATA	0x20
2716206Sab196087 
2729085SAli.Bahrami@Sun.COM /*	M_ID_USER	0x01			dual entry - listed above */
2736206Sab196087 #define	M_ID_GOT	0x03			/* SHF_ALLOC + SHF_WRITE */
274*12992SRod.Evans@Oracle.COM /*	M_ID_DYNAMIC	0x06			dual entry - listed above */
275*12992SRod.Evans@Oracle.COM /*	M_ID_UNWIND	0x08			dual entry - listed above */
2766206Sab196087 
2776206Sab196087 #define	M_ID_UNKNOWN	0xfb			/* just before TLS */
2786206Sab196087 
2796206Sab196087 #define	M_ID_TLS	0xfc			/* just before bss */
2806206Sab196087 #define	M_ID_TLSBSS	0xfd
2816206Sab196087 #define	M_ID_BSS	0xfe
2826206Sab196087 #define	M_ID_LBSS	0xff
2836206Sab196087 
2846206Sab196087 #define	M_ID_SYMTAB_NDX	0x02			/* ! SHF_ALLOC */
2856206Sab196087 #define	M_ID_SYMTAB	0x03
2866206Sab196087 #define	M_ID_STRTAB	0x04
2876206Sab196087 #define	M_ID_DYNSYM_NDX	0x05
2886206Sab196087 #define	M_ID_NOTE	0x06
2896206Sab196087 
2906206Sab196087 
2916206Sab196087 #ifdef	__cplusplus
2926206Sab196087 }
2936206Sab196087 #endif
2946206Sab196087 
2956206Sab196087 #endif /* _MACHDEP_X86_H */
296