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