xref: /illumos-gate/usr/src/cmd/sgs/include/i386/machdep_x86.h (revision 5422785d352a2bb398daceab3d1898a8aa64d006)
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 (c) 1990, 2010, Oracle and/or its affiliates. All rights reserved.
27  *
28  * Global include file for all sgs ia32 based machine dependent macros,
29  * constants and declarations.
30  */
31 
32 #ifndef	_MACHDEP_X86_H
33 #define	_MACHDEP_X86_H
34 
35 #include <link.h>
36 #include <sys/machelf.h>
37 
38 #ifdef	__cplusplus
39 extern "C" {
40 #endif
41 
42 /*
43  * Elf header information.
44  */
45 #define	M_MACH_32		EM_386
46 #define	M_MACH_64		EM_AMD64
47 
48 #ifdef _ELF64
49 #define	M_MACH			EM_AMD64
50 #define	M_CLASS			ELFCLASS64
51 #else
52 #define	M_MACH			EM_386
53 #define	M_CLASS			ELFCLASS32
54 #endif
55 
56 #define	M_MACHPLUS		M_MACH
57 #define	M_DATA			ELFDATA2LSB
58 #define	M_FLAGSPLUS		0
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 #if	defined(_ELF64)
72 #define	M_SEGSIZE	ELF_AMD64_MAXPGSZ
73 #else
74 #define	M_SEGSIZE	ELF_386_MAXPGSZ
75 #endif
76 
77 #define	M_STRUNC(X)	((X) & ~(M_SEGSIZE - 1))
78 #define	M_SROUND(X)	(((X) + M_SEGSIZE - 1) & ~(M_SEGSIZE - 1))
79 
80 /*
81  * Relocation type macros.
82  */
83 #if	defined(_ELF64)
84 #define	M_RELOC		Rela
85 #else
86 #define	M_RELOC		Rel
87 #endif
88 
89 /*
90  * TLS static segments must be rounded to the following requirements,
91  * due to libthread stack allocation.
92  */
93 #if	defined(_ELF64)
94 #define	M_TLSSTATALIGN	0x10
95 #else
96 #define	M_TLSSTATALIGN	0x08
97 #endif
98 
99 /*
100  * Other machine dependent entities
101  */
102 #if	defined(_ELF64)
103 #define	M_SEGM_ALIGN	0x00010000
104 #else
105 #define	M_SEGM_ALIGN	ELF_386_MAXPGSZ
106 #endif
107 
108 /*
109  * Values for IA32 objects
110  */
111 
112 /*
113  * Instruction encodings.
114  */
115 #define	M_INST_JMP		0xe9
116 #define	M_INST_PUSHL		0x68
117 #define	M_SPECIAL_INST		0xff
118 #define	M_PUSHL_DISP		0x35
119 #define	M_PUSHL_REG_DISP	0xb3
120 #define	M_JMP_DISP_IND		0x25
121 #define	M_JMP_REG_DISP_IND	0xa3
122 #define	M_NOP			0x90
123 
124 #define	M_BIND_ADJ	1		/* adjustment for end of */
125 					/*	elf_rtbndr() address */
126 #ifdef _ELF64
127 /*
128  * Provide default starting addresses.  64-bit programs can also be restricted
129  * to a 32-bit address space (SF1_SUNW_ADDR32), and these programs provide an
130  * alternative origin.
131  */
132 #define	M_SEGM_ORIGIN	(Addr)0x400000ULL	/* default 1st segment origin */
133 #define	M_SEGM_AORIGIN	(Addr)0x10000ULL	/* alternative 1st segment */
134 						/*    origin */
135 #else
136 #define	M_STACK_GAP	(0x08000000)
137 #define	M_STACK_PGS	(0x00048000)
138 #define	M_SEGM_ORIGIN	(Addr)(M_STACK_GAP + M_STACK_PGS)
139 #define	M_SEGM_AORIGIN	M_SEGM_ORIGIN
140 #endif
141 
142 /*
143  * Make common relocation information transparent to the common code
144  */
145 #if	defined(_ELF64)
146 #define	M_REL_DT_TYPE	DT_RELA		/* .dynamic entry */
147 #define	M_REL_DT_SIZE	DT_RELASZ	/* .dynamic entry */
148 #define	M_REL_DT_ENT	DT_RELAENT	/* .dynamic entry */
149 #define	M_REL_DT_COUNT	DT_RELACOUNT	/* .dynamic entry */
150 #define	M_REL_SHT_TYPE	SHT_RELA	/* section header type */
151 #define	M_REL_ELF_TYPE	ELF_T_RELA	/* data buffer type */
152 
153 #else /* _ELF32 */
154 #define	M_REL_DT_TYPE	DT_REL		/* .dynamic entry */
155 #define	M_REL_DT_SIZE	DT_RELSZ	/* .dynamic entry */
156 #define	M_REL_DT_ENT	DT_RELENT	/* .dynamic entry */
157 #define	M_REL_DT_COUNT	DT_RELCOUNT	/* .dynamic entry */
158 #define	M_REL_SHT_TYPE	SHT_REL		/* section header type */
159 #define	M_REL_ELF_TYPE	ELF_T_REL	/* data buffer type */
160 
161 #endif /* ELF32 */
162 
163 /*
164  * Make common relocation types transparent to the common code
165  */
166 #if	defined(_ELF64)
167 #define	M_R_NONE	R_AMD64_NONE
168 #define	M_R_GLOB_DAT	R_AMD64_GLOB_DAT
169 #define	M_R_COPY	R_AMD64_COPY
170 #define	M_R_RELATIVE	R_AMD64_RELATIVE
171 #define	M_R_JMP_SLOT	R_AMD64_JUMP_SLOT
172 #define	M_R_FPTR	R_AMD64_NONE
173 #define	M_R_ARRAYADDR	R_AMD64_GLOB_DAT
174 #define	M_R_NUM		R_AMD64_NUM
175 #else
176 #define	M_R_NONE	R_386_NONE
177 #define	M_R_GLOB_DAT	R_386_GLOB_DAT
178 #define	M_R_COPY	R_386_COPY
179 #define	M_R_RELATIVE	R_386_RELATIVE
180 #define	M_R_JMP_SLOT	R_386_JMP_SLOT
181 #define	M_R_FPTR	R_386_NONE
182 #define	M_R_ARRAYADDR	R_386_GLOB_DAT
183 #define	M_R_NUM		R_386_NUM
184 #endif
185 
186 /*
187  * The following are defined as M_R_NONE so that checks
188  * for these relocations can be performed in common code - although
189  * the checks are really only relevant to SPARC.
190  */
191 #define	M_R_REGISTER	M_R_NONE
192 
193 /*
194  * DT_REGISTER is not valid on i386 or amd64
195  */
196 #define	M_DT_REGISTER	0xffffffff
197 
198 /*
199  * Make plt section information transparent to the common code.
200  */
201 #define	M_PLT_SHF_FLAGS	(SHF_ALLOC | SHF_EXECINSTR)
202 
203 /*
204  * Make default data segment and stack flags transparent to the common code.
205  */
206 #ifdef _ELF64
207 #define	M_DATASEG_PERM	(PF_R | PF_W)
208 #define	M_STACK_PERM	(PF_R | PF_W)
209 #else
210 #define	M_DATASEG_PERM	(PF_R | PF_W | PF_X)
211 #define	M_STACK_PERM	(PF_R | PF_W | PF_X)
212 #endif
213 
214 /*
215  * Define a set of identifies for special sections.  These allow the sections
216  * to be ordered within the output file image.  These values should be
217  * maintained consistently, where appropriate, in each platform specific header
218  * file.
219  *
220  *  -	null identifies that this section does not need to be added to the
221  *	output image (ie. shared object sections or sections we're going to
222  *	recreate (sym tables, string tables, relocations, etc.)).
223  *
224  *  -	any user defined section will be first in the associated segment.
225  *
226  *  -	interp and capabilities sections are next, as these are accessed
227  *	immediately the first page of the image is mapped.
228  *
229  *  -	objects that do not provide an interp normally have a read-only
230  *	.dynamic section that comes next (in this case, there is no need to
231  *	update a DT_DEBUG entry at runtime).
232  *
233  *  -	the syminfo, hash, dynsym, dynstr and rel's are grouped together as
234  *	these will all be accessed together by ld.so.1 to perform relocations.
235  *
236  *  -	the got and dynamic are grouped together as these may also be
237  *	accessed first by ld.so.1 to perform relocations, fill in DT_DEBUG
238  *	(executables only), and .got[0].
239  *
240  *  -	unknown sections (stabs, comments, etc.) go at the end.
241  *
242  * Note that .tlsbss/.bss are given the largest identifiers.  This insures that
243  * if any unknown sections become associated to the same segment as the .bss,
244  * the .bss sections are always the last section in the segment.
245  */
246 #define	M_ID_NULL	0x00
247 #define	M_ID_USER	0x01
248 
249 #define	M_ID_INTERP	0x02			/* SHF_ALLOC */
250 #define	M_ID_CAP	0x03
251 #define	M_ID_CAPINFO	0x04
252 #define	M_ID_CAPCHAIN	0x05
253 
254 #define	M_ID_DYNAMIC	0x06			/* if no .interp, then no */
255 						/*    DT_DEBUG is required */
256 #define	M_ID_UNWINDHDR	0x07
257 #define	M_ID_UNWIND	0x08
258 
259 #define	M_ID_SYMINFO	0x09
260 #define	M_ID_HASH	0x0a
261 #define	M_ID_LDYNSYM	0x0b			/* always right before DYNSYM */
262 #define	M_ID_DYNSYM	0x0c
263 #define	M_ID_DYNSTR	0x0d
264 #define	M_ID_VERSION	0x0e
265 #define	M_ID_DYNSORT	0x0f
266 #define	M_ID_REL	0x10
267 #define	M_ID_PLT	0x11			/* SHF_ALLOC + SHF_EXECINSTR */
268 #define	M_ID_ARRAY	0x12
269 #define	M_ID_TEXT	0x13
270 #define	M_ID_DATA	0x20
271 
272 /*	M_ID_USER	0x01			dual entry - listed above */
273 #define	M_ID_GOT	0x03			/* SHF_ALLOC + SHF_WRITE */
274 /*	M_ID_DYNAMIC	0x06			dual entry - listed above */
275 /*	M_ID_UNWIND	0x08			dual entry - listed above */
276 
277 #define	M_ID_UNKNOWN	0xfb			/* just before TLS */
278 
279 #define	M_ID_TLS	0xfc			/* just before bss */
280 #define	M_ID_TLSBSS	0xfd
281 #define	M_ID_BSS	0xfe
282 #define	M_ID_LBSS	0xff
283 
284 #define	M_ID_SYMTAB_NDX	0x02			/* ! SHF_ALLOC */
285 #define	M_ID_SYMTAB	0x03
286 #define	M_ID_STRTAB	0x04
287 #define	M_ID_DYNSYM_NDX	0x05
288 #define	M_ID_NOTE	0x06
289 
290 
291 #ifdef	__cplusplus
292 }
293 #endif
294 
295 #endif /* _MACHDEP_X86_H */
296