xref: /titanic_50/usr/src/uts/common/sys/machelf.h (revision bfed486ad8de8b8ebc6345a8e10accae08bf2f45)
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 2008 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_SYS_MACHELF_H
28 #define	_SYS_MACHELF_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #ifdef	__cplusplus
33 extern "C" {
34 #endif
35 
36 #if defined(__amd64)
37 #include <sys/elf_amd64.h>
38 #elif defined(__i386)
39 #include <sys/elf_386.h>
40 #elif defined(__sparc)
41 #include <sys/elf_SPARC.h>
42 #endif
43 #ifndef	_ASM
44 #include <sys/types.h>
45 #include <sys/elf.h>
46 #include <sys/link.h>	/* for Elf*_Dyn */
47 #endif	/* _ASM */
48 
49 /*
50  * Make machine class dependent data types transparent to the common code
51  */
52 #if defined(_ELF64) && !defined(_ELF32_COMPAT)
53 
54 #ifndef	_ASM
55 typedef	Elf64_Xword	Xword;
56 typedef	Elf64_Lword	Lword;
57 typedef	Elf64_Sxword	Sxword;
58 typedef	Elf64_Word	Word;
59 typedef	Elf64_Sword	Sword;
60 typedef	Elf64_Half	Half;
61 typedef	Elf64_Addr	Addr;
62 typedef	Elf64_Off	Off;
63 typedef	uchar_t		Byte;
64 #endif	/* _ASM */
65 
66 #if defined(_KERNEL)
67 #define	ELF_R_TYPE	ELF64_R_TYPE
68 #define	ELF_R_SYM	ELF64_R_SYM
69 #define	ELF_R_TYPE_DATA ELF64_R_TYPE_DATA
70 #define	ELF_R_INFO	ELF64_R_INFO
71 #define	ELF_ST_BIND	ELF64_ST_BIND
72 #define	ELF_ST_TYPE	ELF64_ST_TYPE
73 #define	ELF_M_SYM	ELF64_M_SYM
74 #define	ELF_M_SIZE	ELF64_M_SIZE
75 #endif
76 
77 #ifndef	_ASM
78 typedef	Elf64_Ehdr	Ehdr;
79 typedef	Elf64_Shdr	Shdr;
80 typedef	Elf64_Sym	Sym;
81 typedef	Elf64_Syminfo	Syminfo;
82 typedef	Elf64_Rela	Rela;
83 typedef	Elf64_Rel	Rel;
84 typedef	Elf64_Nhdr	Nhdr;
85 typedef	Elf64_Phdr	Phdr;
86 typedef	Elf64_Dyn	Dyn;
87 typedef	Elf64_Boot	Boot;
88 typedef	Elf64_Verdef	Verdef;
89 typedef	Elf64_Verdaux	Verdaux;
90 typedef	Elf64_Verneed	Verneed;
91 typedef	Elf64_Vernaux	Vernaux;
92 typedef	Elf64_Versym	Versym;
93 typedef	Elf64_Move	Move;
94 typedef	Elf64_Cap	Cap;
95 #endif	/* _ASM */
96 
97 #else	/* _ILP32 */
98 
99 #ifndef	_ASM
100 typedef	Elf32_Word	Xword;	/* Xword/Sxword are 32-bits in Elf32 */
101 typedef	Elf32_Lword	Lword;
102 typedef	Elf32_Sword	Sxword;
103 typedef	Elf32_Word	Word;
104 typedef	Elf32_Sword	Sword;
105 typedef	Elf32_Half	Half;
106 typedef	Elf32_Addr	Addr;
107 typedef	Elf32_Off	Off;
108 typedef	uchar_t		Byte;
109 #endif	/* _ASM */
110 
111 #if defined(_KERNEL)
112 #define	ELF_R_TYPE	ELF32_R_TYPE
113 #define	ELF_R_SYM	ELF32_R_SYM
114 #define	ELF_R_TYPE_DATA(x)	(0)
115 #define	ELF_R_INFO	ELF32_R_INFO
116 #define	ELF_ST_BIND	ELF32_ST_BIND
117 #define	ELF_ST_TYPE	ELF32_ST_TYPE
118 #define	ELF_M_SYM	ELF32_M_SYM
119 #define	ELF_M_SIZE	ELF32_M_SIZE
120 #endif
121 
122 #ifndef	_ASM
123 typedef	Elf32_Ehdr	Ehdr;
124 typedef	Elf32_Shdr	Shdr;
125 typedef	Elf32_Sym	Sym;
126 typedef	Elf32_Syminfo	Syminfo;
127 typedef	Elf32_Rela	Rela;
128 typedef	Elf32_Rel	Rel;
129 typedef	Elf32_Nhdr	Nhdr;
130 typedef	Elf32_Phdr	Phdr;
131 typedef	Elf32_Dyn	Dyn;
132 typedef	Elf32_Boot	Boot;
133 typedef	Elf32_Verdef	Verdef;
134 typedef	Elf32_Verdaux	Verdaux;
135 typedef	Elf32_Verneed	Verneed;
136 typedef	Elf32_Vernaux	Vernaux;
137 typedef	Elf32_Versym	Versym;
138 typedef	Elf32_Move	Move;
139 typedef	Elf32_Cap	Cap;
140 #endif	/* _ASM */
141 
142 #endif	/* _ILP32 */
143 
144 /*
145  * Elf `printf' type-cast macros.  These force arguments to be a fixed size
146  * so that Elf32 and Elf64 can share common format strings.
147  */
148 #ifndef	__lint
149 #define	EC_ADDR(a)	((Elf64_Addr)(a))		/* "ull" */
150 #define	EC_OFF(a)	((Elf64_Off)(a))		/* "ull"  */
151 #define	EC_HALF(a)	((Elf64_Half)(a))		/* "d"   */
152 #define	EC_WORD(a)	((Elf64_Word)(a))		/* "u"   */
153 #define	EC_SWORD(a)	((Elf64_Sword)(a))		/* "d"   */
154 #define	EC_XWORD(a)	((Elf64_Xword)(a))		/* "ull" */
155 #define	EC_SXWORD(a)	((Elf64_Sxword)(a))		/* "ll"  */
156 #define	EC_LWORD(a)	((Elf64_Lword)(a))		/* "ull" */
157 
158 /*
159  * A native pointer is special.  Although it can be convenient to display
160  * these from a common format (ull), compilers may flag the cast of a pointer
161  * to an integer as illegal.  Casting these pointers to the native pointer
162  * size, suppresses any compiler errors.
163  */
164 #define	EC_NATPTR(a)	((Elf64_Xword)(uintptr_t)(a))	/* "ull" */
165 #else
166 #define	EC_ADDR(a)	((u_longlong_t)(a))
167 #define	EC_OFF(a)	((u_longlong_t)(a))
168 #define	EC_HALF(a)	((ushort_t)(a))
169 #define	EC_WORD(a)	((uint_t)(a))
170 #define	EC_SWORD(a)	((int)(a))
171 #define	EC_XWORD(a)	((u_longlong_t)(a))
172 #define	EC_SXWORD(a)	((longlong_t)(a))
173 #define	EC_LWORD(a)	((u_longlong_t)(a))
174 
175 #define	EC_NATPTR(a)	((u_longlong_t)(a))
176 #endif
177 
178 #ifdef	__cplusplus
179 }
180 #endif
181 
182 #endif	/* _SYS_MACHELF_H */
183