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