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