xref: /illumos-gate/usr/src/cmd/sgs/include/i386/machdep_x86.h (revision 56deab0745753336570f5c63c3b5fa565eaab8f1)
1ba2be530Sab196087 /*
2ba2be530Sab196087  * CDDL HEADER START
3ba2be530Sab196087  *
4ba2be530Sab196087  * The contents of this file are subject to the terms of the
5ba2be530Sab196087  * Common Development and Distribution License (the "License").
6ba2be530Sab196087  * You may not use this file except in compliance with the License.
7ba2be530Sab196087  *
8ba2be530Sab196087  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9ba2be530Sab196087  * or http://www.opensolaris.org/os/licensing.
10ba2be530Sab196087  * See the License for the specific language governing permissions
11ba2be530Sab196087  * and limitations under the License.
12ba2be530Sab196087  *
13ba2be530Sab196087  * When distributing Covered Code, include this CDDL HEADER in each
14ba2be530Sab196087  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15ba2be530Sab196087  * If applicable, add the following below this CDDL HEADER, with the
16ba2be530Sab196087  * fields enclosed by brackets "[]" replaced with your own identifying
17ba2be530Sab196087  * information: Portions Copyright [yyyy] [name of copyright owner]
18ba2be530Sab196087  *
19ba2be530Sab196087  * CDDL HEADER END
20ba2be530Sab196087  */
21ba2be530Sab196087 
22ba2be530Sab196087 /*
23ba2be530Sab196087  *	Copyright (c) 1988 AT&T
24ba2be530Sab196087  *	  All Rights Reserved
25ba2be530Sab196087  *
26bb3b4f6cSRod Evans  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
27ba2be530Sab196087  * Use is subject to license terms.
28ba2be530Sab196087  *
29ba2be530Sab196087  * Global include file for all sgs ia32 based machine dependent macros,
30ba2be530Sab196087  * constants and declarations.
31ba2be530Sab196087  */
32ba2be530Sab196087 
33ba2be530Sab196087 #ifndef	_MACHDEP_X86_H
34ba2be530Sab196087 #define	_MACHDEP_X86_H
35ba2be530Sab196087 
36ba2be530Sab196087 #include <link.h>
37ba2be530Sab196087 #include <sys/machelf.h>
38ba2be530Sab196087 
39ba2be530Sab196087 #ifdef	__cplusplus
40ba2be530Sab196087 extern "C" {
41ba2be530Sab196087 #endif
42ba2be530Sab196087 
43ba2be530Sab196087 /*
44ba2be530Sab196087  * Elf header information.
45ba2be530Sab196087  */
46ba2be530Sab196087 #define	M_MACH_32		EM_386
47ba2be530Sab196087 #define	M_MACH_64		EM_AMD64
48ba2be530Sab196087 
49ba2be530Sab196087 #ifdef _ELF64
50ba2be530Sab196087 #define	M_MACH			EM_AMD64
51ba2be530Sab196087 #define	M_CLASS			ELFCLASS64
52ba2be530Sab196087 #else
53ba2be530Sab196087 #define	M_MACH			EM_386
54ba2be530Sab196087 #define	M_CLASS			ELFCLASS32
55ba2be530Sab196087 #endif
56ba2be530Sab196087 
57ba2be530Sab196087 #define	M_MACHPLUS		M_MACH
58ba2be530Sab196087 #define	M_DATA			ELFDATA2LSB
59ba2be530Sab196087 #define	M_FLAGSPLUS		0
60ba2be530Sab196087 
61ba2be530Sab196087 /*
62ba2be530Sab196087  * Page boundary Macros: truncate to previous page boundary and round to
63ba2be530Sab196087  * next page boundary (refer to generic macros in ../sgs.h also).
64ba2be530Sab196087  */
65ba2be530Sab196087 #define	M_PTRUNC(X)	((X) & ~(syspagsz - 1))
66ba2be530Sab196087 #define	M_PROUND(X)	(((X) + syspagsz - 1) & ~(syspagsz - 1))
67ba2be530Sab196087 
68ba2be530Sab196087 /*
69ba2be530Sab196087  * Segment boundary macros: truncate to previous segment boundary and round
70ba2be530Sab196087  * to next page boundary.
71ba2be530Sab196087  */
72ba2be530Sab196087 #if	defined(_ELF64)
73ba2be530Sab196087 #define	M_SEGSIZE	ELF_AMD64_MAXPGSZ
74ba2be530Sab196087 #else
75ba2be530Sab196087 #define	M_SEGSIZE	ELF_386_MAXPGSZ
76ba2be530Sab196087 #endif
77ba2be530Sab196087 
78ba2be530Sab196087 #define	M_STRUNC(X)	((X) & ~(M_SEGSIZE - 1))
79ba2be530Sab196087 #define	M_SROUND(X)	(((X) + M_SEGSIZE - 1) & ~(M_SEGSIZE - 1))
80ba2be530Sab196087 
81ba2be530Sab196087 /*
82*56deab07SRod Evans  * Relocation type macros.
83*56deab07SRod Evans  */
84*56deab07SRod Evans #if	defined(_ELF64)
85*56deab07SRod Evans #define	M_RELOC		Rela
86*56deab07SRod Evans #else
87*56deab07SRod Evans #define	M_RELOC		Rel
88*56deab07SRod Evans #endif
89*56deab07SRod Evans 
90*56deab07SRod Evans /*
91ba2be530Sab196087  * TLS static segments must be rounded to the following requirements,
92ba2be530Sab196087  * due to libthread stack allocation.
93ba2be530Sab196087  */
94ba2be530Sab196087 #if	defined(_ELF64)
95ba2be530Sab196087 #define	M_TLSSTATALIGN	0x10
96ba2be530Sab196087 #else
97ba2be530Sab196087 #define	M_TLSSTATALIGN	0x08
98ba2be530Sab196087 #endif
99ba2be530Sab196087 
100ba2be530Sab196087 /*
101ba2be530Sab196087  * Other machine dependent entities
102ba2be530Sab196087  */
103ba2be530Sab196087 #if	defined(_ELF64)
104ba2be530Sab196087 #define	M_SEGM_ALIGN	0x00010000
105ba2be530Sab196087 #else
106ba2be530Sab196087 #define	M_SEGM_ALIGN	ELF_386_MAXPGSZ
107ba2be530Sab196087 #endif
108ba2be530Sab196087 
109ba2be530Sab196087 /*
110ba2be530Sab196087  * Values for IA32 objects
111ba2be530Sab196087  */
112ba2be530Sab196087 
113ba2be530Sab196087 /*
114ba2be530Sab196087  * Instruction encodings.
115ba2be530Sab196087  */
116ba2be530Sab196087 #define	M_INST_JMP		0xe9
117ba2be530Sab196087 #define	M_INST_PUSHL		0x68
118ba2be530Sab196087 #define	M_SPECIAL_INST		0xff
119ba2be530Sab196087 #define	M_PUSHL_DISP		0x35
120ba2be530Sab196087 #define	M_PUSHL_REG_DISP	0xb3
121ba2be530Sab196087 #define	M_JMP_DISP_IND		0x25
122ba2be530Sab196087 #define	M_JMP_REG_DISP_IND	0xa3
123ba2be530Sab196087 #define	M_NOP			0x90
124ba2be530Sab196087 
125ba2be530Sab196087 #define	M_BIND_ADJ	1		/* adjustment for end of */
126ba2be530Sab196087 					/*	elf_rtbndr() address */
127ba2be530Sab196087 #ifdef _ELF64
128bb3b4f6cSRod Evans /*
129bb3b4f6cSRod Evans  * Provide default starting addresses.  64-bit programs can also be restricted
130bb3b4f6cSRod Evans  * to a 32-bit address space (SF1_SUNW_ADDR32), and these programs provide an
131bb3b4f6cSRod Evans  * alternative origin.
132bb3b4f6cSRod Evans  */
133bb3b4f6cSRod Evans #define	M_SEGM_ORIGIN	(Addr)0x400000ULL	/* default 1st segment origin */
134bb3b4f6cSRod Evans #define	M_SEGM_AORIGIN	(Addr)0x10000ULL	/* alternative 1st segment */
135bb3b4f6cSRod Evans 						/*    origin */
136ba2be530Sab196087 #define	M_WORD_ALIGN	8
137ba2be530Sab196087 #else
138ba2be530Sab196087 #define	M_STACK_GAP	(0x08000000)
139ba2be530Sab196087 #define	M_STACK_PGS	(0x00048000)
140ba2be530Sab196087 #define	M_SEGM_ORIGIN	(Addr)(M_STACK_GAP + M_STACK_PGS)
141bb3b4f6cSRod Evans #define	M_SEGM_AORIGIN	M_SEGM_ORIGIN
142bb3b4f6cSRod Evans #define	M_WORD_ALIGN	4
143ba2be530Sab196087 #endif
144ba2be530Sab196087 
145ba2be530Sab196087 
146ba2be530Sab196087 /*
147ba2be530Sab196087  * Plt and Got information; the first few .got and .plt entries are reserved
148ba2be530Sab196087  *	PLT[0]	jump to dynamic linker
149ba2be530Sab196087  *	GOT[0]	address of _DYNAMIC
150ba2be530Sab196087  */
151ba2be530Sab196087 #define	M_PLT_ENTSIZE	16		/* plt entry size in bytes */
152ba2be530Sab196087 #define	M_PLT_ALIGN	M_WORD_ALIGN	/* alignment of .plt section */
153ba2be530Sab196087 #define	M_PLT_INSSIZE	6		/* single plt instruction size */
154ba2be530Sab196087 #define	M_PLT_RESERVSZ	M_PLT_ENTSIZE	/* PLT[0] reserved */
155ba2be530Sab196087 
156ba2be530Sab196087 #define	M_GOT_XDYNAMIC	0		/* got index for _DYNAMIC */
157ba2be530Sab196087 #define	M_GOT_XLINKMAP	1		/* got index for link map */
158ba2be530Sab196087 #define	M_GOT_XRTLD	2		/* got index for rtbinder */
159ba2be530Sab196087 #define	M_GOT_XNumber	3		/* reserved no. of got entries */
160ba2be530Sab196087 
161ba2be530Sab196087 #ifdef	_ELF64
162ba2be530Sab196087 #define	M_GOT_ENTSIZE	8		/* got entry size in bytes */
163ba2be530Sab196087 #else /* ELF32 */
164ba2be530Sab196087 #define	M_GOT_ENTSIZE	4		/* got entry size in bytes */
165ba2be530Sab196087 #endif
166ba2be530Sab196087 
167ba2be530Sab196087 /*
168ba2be530Sab196087  * Make common relocation information transparent to the common code
169ba2be530Sab196087  */
170ba2be530Sab196087 #if	defined(_ELF64)
171ba2be530Sab196087 #define	M_REL_DT_TYPE	DT_RELA		/* .dynamic entry */
172ba2be530Sab196087 #define	M_REL_DT_SIZE	DT_RELASZ	/* .dynamic entry */
173ba2be530Sab196087 #define	M_REL_DT_ENT	DT_RELAENT	/* .dynamic entry */
174ba2be530Sab196087 #define	M_REL_DT_COUNT	DT_RELACOUNT	/* .dynamic entry */
175ba2be530Sab196087 #define	M_REL_SHT_TYPE	SHT_RELA	/* section header type */
176ba2be530Sab196087 #define	M_REL_ELF_TYPE	ELF_T_RELA	/* data buffer type */
177ba2be530Sab196087 
178ba2be530Sab196087 #else /* _ELF32 */
179ba2be530Sab196087 #define	M_REL_DT_TYPE	DT_REL		/* .dynamic entry */
180ba2be530Sab196087 #define	M_REL_DT_SIZE	DT_RELSZ	/* .dynamic entry */
181ba2be530Sab196087 #define	M_REL_DT_ENT	DT_RELENT	/* .dynamic entry */
182ba2be530Sab196087 #define	M_REL_DT_COUNT	DT_RELCOUNT	/* .dynamic entry */
183ba2be530Sab196087 #define	M_REL_SHT_TYPE	SHT_REL		/* section header type */
184ba2be530Sab196087 #define	M_REL_ELF_TYPE	ELF_T_REL	/* data buffer type */
185ba2be530Sab196087 
186ba2be530Sab196087 #endif /* ELF32 */
187ba2be530Sab196087 
188ba2be530Sab196087 /*
189ba2be530Sab196087  * Make common relocation types transparent to the common code
190ba2be530Sab196087  */
191ba2be530Sab196087 #if	defined(_ELF64)
192ba2be530Sab196087 #define	M_R_NONE	R_AMD64_NONE
193ba2be530Sab196087 #define	M_R_GLOB_DAT	R_AMD64_GLOB_DAT
194ba2be530Sab196087 #define	M_R_COPY	R_AMD64_COPY
195ba2be530Sab196087 #define	M_R_RELATIVE	R_AMD64_RELATIVE
196ba2be530Sab196087 #define	M_R_JMP_SLOT	R_AMD64_JUMP_SLOT
197ba2be530Sab196087 #define	M_R_FPTR	R_AMD64_NONE
198ba2be530Sab196087 #define	M_R_ARRAYADDR	R_AMD64_GLOB_DAT
199ba2be530Sab196087 #define	M_R_NUM		R_AMD64_NUM
200ba2be530Sab196087 #else
201ba2be530Sab196087 #define	M_R_NONE	R_386_NONE
202ba2be530Sab196087 #define	M_R_GLOB_DAT	R_386_GLOB_DAT
203ba2be530Sab196087 #define	M_R_COPY	R_386_COPY
204ba2be530Sab196087 #define	M_R_RELATIVE	R_386_RELATIVE
205ba2be530Sab196087 #define	M_R_JMP_SLOT	R_386_JMP_SLOT
206ba2be530Sab196087 #define	M_R_FPTR	R_386_NONE
207ba2be530Sab196087 #define	M_R_ARRAYADDR	R_386_GLOB_DAT
208ba2be530Sab196087 #define	M_R_NUM		R_386_NUM
209ba2be530Sab196087 #endif
210ba2be530Sab196087 
211ba2be530Sab196087 /*
212ba2be530Sab196087  * The following are defined as M_R_NONE so that checks
213ba2be530Sab196087  * for these relocations can be performed in common code - although
214ba2be530Sab196087  * the checks are really only relevant to SPARC.
215ba2be530Sab196087  */
216ba2be530Sab196087 #define	M_R_REGISTER	M_R_NONE
217ba2be530Sab196087 
218ba2be530Sab196087 /*
219ba2be530Sab196087  * DT_REGISTER is not valid on i386 or amd64
220ba2be530Sab196087  */
221ba2be530Sab196087 #define	M_DT_REGISTER	0xffffffff
222ba2be530Sab196087 
223ba2be530Sab196087 /*
224ba2be530Sab196087  * Make plt section information transparent to the common code.
225ba2be530Sab196087  */
226ba2be530Sab196087 #define	M_PLT_SHF_FLAGS	(SHF_ALLOC | SHF_EXECINSTR)
227ba2be530Sab196087 
228ba2be530Sab196087 /*
229ba2be530Sab196087  * Make data segment information transparent to the common code.
230ba2be530Sab196087  */
231ba2be530Sab196087 #ifdef _ELF64
232ba2be530Sab196087 #define	M_DATASEG_PERM	(PF_R | PF_W)
233ba2be530Sab196087 #else
234ba2be530Sab196087 #define	M_DATASEG_PERM	(PF_R | PF_W | PF_X)
235ba2be530Sab196087 #endif
236ba2be530Sab196087 
237ba2be530Sab196087 /*
238ba2be530Sab196087  * Define a set of identifies for special sections.  These allow the sections
239ba2be530Sab196087  * to be ordered within the output file image.  These values should be
240ba2be530Sab196087  * maintained consistently, where appropriate, in each platform specific header
241ba2be530Sab196087  * file.
242ba2be530Sab196087  *
243ba2be530Sab196087  *  o	null identifies that this section does not need to be added to the
244ba2be530Sab196087  *	output image (ie. shared object sections or sections we're going to
245ba2be530Sab196087  *	recreate (sym tables, string tables, relocations, etc.)).
246ba2be530Sab196087  *
247ba2be530Sab196087  *  o	any user defined section will be first in the associated segment.
248ba2be530Sab196087  *
249ba2be530Sab196087  *  o	interp and capabilities sections are next, as these are accessed
250ba2be530Sab196087  *	immediately the first page of the image is mapped.
251ba2be530Sab196087  *
252ba2be530Sab196087  *  o	the syminfo, hash, dynsym, dynstr and rel's are grouped together as
253ba2be530Sab196087  *	these will all be accessed first by ld.so.1 to perform relocations.
254ba2be530Sab196087  *
255ba2be530Sab196087  *  o	the got and dynamic are grouped together as these may also be
256ba2be530Sab196087  *	accessed first by ld.so.1 to perform relocations, fill in DT_DEBUG
257ba2be530Sab196087  *	(executables only), and .got[0].
258ba2be530Sab196087  *
259ba2be530Sab196087  *  o	unknown sections (stabs, comments, etc.) go at the end.
260ba2be530Sab196087  *
261ba2be530Sab196087  * Note that .tlsbss/.bss are given the largest identifiers.  This insures that
262ba2be530Sab196087  * if any unknown sections become associated to the same segment as the .bss,
263ba2be530Sab196087  * the .bss sections are always the last section in the segment.
264ba2be530Sab196087  */
265ba2be530Sab196087 #define	M_ID_NULL	0x00
266ba2be530Sab196087 #define	M_ID_USER	0x01
267ba2be530Sab196087 
268ba2be530Sab196087 #define	M_ID_INTERP	0x03			/* SHF_ALLOC */
269ba2be530Sab196087 #define	M_ID_CAP	0x04
270ba2be530Sab196087 #define	M_ID_UNWINDHDR	0x05
271ba2be530Sab196087 #define	M_ID_UNWIND	0x06
272ba2be530Sab196087 #define	M_ID_SYMINFO	0x07
273ba2be530Sab196087 #define	M_ID_HASH	0x08
274ba2be530Sab196087 #define	M_ID_LDYNSYM	0x09			/* always right before DYNSYM */
275ba2be530Sab196087 #define	M_ID_DYNSYM	0x0a
276ba2be530Sab196087 #define	M_ID_DYNSTR	0x0b
277ba2be530Sab196087 #define	M_ID_VERSION	0x0c
278ba2be530Sab196087 #define	M_ID_DYNSORT	0x0d
279ba2be530Sab196087 #define	M_ID_REL	0x0e
280ba2be530Sab196087 #define	M_ID_PLT	0x0f			/* SHF_ALLOC + SHF_EXECISNTR */
281ba2be530Sab196087 #define	M_ID_TEXT	0x10
282ba2be530Sab196087 #define	M_ID_DATA	0x20
283ba2be530Sab196087 
284ba2be530Sab196087 /*	M_ID_USER	0x02			dual entry - listed above */
285ba2be530Sab196087 #define	M_ID_GOT	0x03			/* SHF_ALLOC + SHF_WRITE */
286ba2be530Sab196087 #define	M_ID_DYNAMIC	0x05
287ba2be530Sab196087 #define	M_ID_ARRAY	0x06
288ba2be530Sab196087 
289ba2be530Sab196087 #define	M_ID_UNKNOWN	0xfb			/* just before TLS */
290ba2be530Sab196087 
291ba2be530Sab196087 #define	M_ID_TLS	0xfc			/* just before bss */
292ba2be530Sab196087 #define	M_ID_TLSBSS	0xfd
293ba2be530Sab196087 #define	M_ID_BSS	0xfe
294ba2be530Sab196087 #define	M_ID_LBSS	0xff
295ba2be530Sab196087 
296ba2be530Sab196087 #define	M_ID_SYMTAB_NDX	0x02			/* ! SHF_ALLOC */
297ba2be530Sab196087 #define	M_ID_SYMTAB	0x03
298ba2be530Sab196087 #define	M_ID_STRTAB	0x04
299ba2be530Sab196087 #define	M_ID_DYNSYM_NDX	0x05
300ba2be530Sab196087 #define	M_ID_NOTE	0x06
301ba2be530Sab196087 
302ba2be530Sab196087 
303ba2be530Sab196087 #ifdef	__cplusplus
304ba2be530Sab196087 }
305ba2be530Sab196087 #endif
306ba2be530Sab196087 
307ba2be530Sab196087 #endif /* _MACHDEP_X86_H */
308