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 SPARC machine dependent macros, constants 29 * and declarations. 30 */ 31 32 #ifndef _MACHDEP_SPARC_H 33 #define _MACHDEP_SPARC_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_SPARC 46 #define M_MACH_64 EM_SPARCV9 47 48 #ifdef _ELF64 49 #define M_MACH EM_SPARCV9 50 #define M_CLASS ELFCLASS64 51 #else 52 #define M_MACH EM_SPARC 53 #define M_CLASS ELFCLASS32 54 #endif 55 #define M_MACHPLUS EM_SPARC32PLUS 56 #define M_DATA ELFDATA2MSB 57 #define M_FLAGSPLUS EF_SPARC_32PLUS 58 59 /* 60 * Page boundary Macros: truncate to previous page boundary and round to 61 * next page boundary (refer to generic macros in ../sgs.h also). 62 */ 63 #define M_PTRUNC(X) ((X) & ~(syspagsz - 1)) 64 #define M_PROUND(X) (((X) + syspagsz - 1) & ~(syspagsz - 1)) 65 66 /* 67 * Segment boundary macros: truncate to previous segment boundary and round 68 * to next page boundary. 69 */ 70 #ifndef M_SEGSIZE 71 #define M_SEGSIZE ELF_SPARC_MAXPGSZ 72 #endif 73 #define M_STRUNC(X) ((X) & ~(M_SEGSIZE - 1)) 74 #define M_SROUND(X) (((X) + M_SEGSIZE - 1) & ~(M_SEGSIZE - 1)) 75 76 /* 77 * Relocation type macro. 78 */ 79 #define M_RELOC Rela 80 81 /* 82 * TLS static segments must be rounded to the following requirements, 83 * due to libthread stack allocation. 84 */ 85 #if defined(_ELF64) 86 #define M_TLSSTATALIGN 0x10 87 #else 88 #define M_TLSSTATALIGN 0x08 89 #endif 90 91 /* 92 * Instruction encodings. 93 */ 94 #define M_SAVESP64 0x9de3bfc0 /* save %sp, -64, %sp */ 95 #define M_CALL 0x40000000 96 #define M_JMPL 0x81c06000 /* jmpl %g1 + simm13, %g0 */ 97 #define M_SETHIG0 0x01000000 /* sethi %hi(val), %g0 */ 98 #define M_SETHIG1 0x03000000 /* sethi %hi(val), %g1 */ 99 #define M_STO7G1IM 0xde206000 /* st %o7,[%g1 + %lo(val)] */ 100 #define M_SUBFPSPG1 0x8227800e /* sub %fp,%sp,%g1 */ 101 #define M_NOP 0x01000000 /* sethi 0, %o0 (nop) */ 102 #define M_BA_A 0x30800000 /* ba,a */ 103 #define M_BA_A_PT 0x30480000 /* ba,a %icc, <dst> */ 104 #define M_MOVO7TOG1 0x8210000f /* mov %o7, %g1 */ 105 #define M_MOVO7TOG5 0x8a10000f /* mov %o7, %g5 */ 106 #define M_MOVI7TOG1 0x8210001f /* mov %i7, %g1 */ 107 #define M_BA_A_XCC 0x30680000 /* ba,a %xcc */ 108 #define M_JMPL_G5G0 0x81c16000 /* jmpl %g5 + 0, %g0 */ 109 #define M_XNOR_G5G1 0x82396000 /* xnor %g5, 0, %g1 */ 110 111 112 #define M_BIND_ADJ 4 /* adjustment for end of */ 113 /* elf_rtbndr() address */ 114 115 /* transition flags for got sizing */ 116 #define M_GOT_LARGE (Sword)(-M_GOT_MAXSMALL - 1) 117 #define M_GOT_SMALL (Sword)(-M_GOT_MAXSMALL - 2) 118 #define M_GOT_MIXED (Sword)(-M_GOT_MAXSMALL - 3) 119 120 /* 121 * Other machine dependent entities 122 */ 123 #ifdef _ELF64 124 #define M_SEGM_ALIGN ELF_SPARCV9_MAXPGSZ 125 /* 126 * Put default 64-bit programs above 4 gigabytes to help insure correctness, so 127 * that any 64-bit programs that truncate pointers will fault now instead of 128 * corrupting itself and dying mysteriously. 64-bit programs can also be 129 * restricted to a 32-bit address space (SF1_SUNW_ADDR32), and these programs 130 * provide an alternative origin. 131 */ 132 #define M_SEGM_ORIGIN (Addr)0x100000000ULL /* default 1st segment origin */ 133 #define M_SEGM_AORIGIN (Addr)0x100000ULL /* alternative 1st segment */ 134 /* origin */ 135 #else 136 #define M_SEGM_ALIGN ELF_SPARC_MAXPGSZ 137 #define M_SEGM_ORIGIN (Addr)0x10000 /* default 1st segment origin */ 138 #define M_SEGM_AORIGIN M_SEGM_ORIGIN /* alternative 1st segment */ 139 /* origin */ 140 #endif 141 142 /* 143 * Make common relocation information transparent to the common code 144 */ 145 #define M_REL_DT_TYPE DT_RELA /* .dynamic entry */ 146 #define M_REL_DT_SIZE DT_RELASZ /* .dynamic entry */ 147 #define M_REL_DT_ENT DT_RELAENT /* .dynamic entry */ 148 #define M_REL_DT_COUNT DT_RELACOUNT /* .dynamic entry */ 149 #define M_REL_SHT_TYPE SHT_RELA /* section header type */ 150 #define M_REL_ELF_TYPE ELF_T_RELA /* data buffer type */ 151 152 /* 153 * Make common relocation types transparent to the common code 154 */ 155 #define M_R_NONE R_SPARC_NONE 156 #define M_R_GLOB_DAT R_SPARC_GLOB_DAT 157 #define M_R_COPY R_SPARC_COPY 158 #define M_R_RELATIVE R_SPARC_RELATIVE 159 #define M_R_JMP_SLOT R_SPARC_JMP_SLOT 160 #define M_R_REGISTER R_SPARC_REGISTER 161 #define M_R_FPTR R_SPARC_NONE 162 #define M_R_NUM R_SPARC_NUM 163 164 #ifdef _ELF64 165 #define M_R_ARRAYADDR R_SPARC_64 166 #define M_R_DTPMOD R_SPARC_TLS_DTPMOD64 167 #define M_R_DTPOFF R_SPARC_TLS_DTPOFF64 168 #define M_R_TPOFF R_SPARC_TLS_TPOFF64 169 #else /* _ELF32 */ 170 #define M_R_ARRAYADDR R_SPARC_32 171 #define M_R_DTPMOD R_SPARC_TLS_DTPMOD32 172 #define M_R_DTPOFF R_SPARC_TLS_DTPOFF32 173 #define M_R_TPOFF R_SPARC_TLS_TPOFF32 174 #endif /* _ELF64 */ 175 176 177 /* 178 * Make register symbols transparent to common code 179 */ 180 #define M_DT_REGISTER DT_SPARC_REGISTER 181 182 /* 183 * Make plt section information transparent to the common code. 184 */ 185 #define M_PLT_SHF_FLAGS (SHF_ALLOC | SHF_WRITE | SHF_EXECINSTR) 186 187 /* 188 * Make default data segment and stack flags transparent to the common code. 189 */ 190 #define M_DATASEG_PERM (PF_R | PF_W | PF_X) 191 #ifdef _ELF64 192 #define M_STACK_PERM (PF_R | PF_W) 193 #else 194 #define M_STACK_PERM (PF_R | PF_W | PF_X) 195 #endif 196 197 /* 198 * Define a set of identifies for special sections. These allow the sections 199 * to be ordered within the output file image. These values should be 200 * maintained consistently, where appropriate, in each platform specific header 201 * file. 202 * 203 * - null identifies that this section does not need to be added to the 204 * output image (ie. shared object sections or sections we're going to 205 * recreate (sym tables, string tables, relocations, etc.)). 206 * 207 * - any user defined section will be first in the associated segment. 208 * 209 * - interp and capabilities sections are next, as these are accessed 210 * immediately the first page of the image is mapped. 211 * 212 * - objects that do not provide an interp normally have a read-only 213 * .dynamic section that comes next (in this case, there is no need to 214 * update a DT_DEBUG entry at runtime). 215 * 216 * - the syminfo, hash, dynsym, dynstr and rel's are grouped together as 217 * these will all be accessed together by ld.so.1 to perform relocations. 218 * 219 * - the got, dynamic, and plt are grouped together as these may also be 220 * accessed first by ld.so.1 to perform relocations, fill in DT_DEBUG 221 * (executables only), and .plt[0]. 222 * 223 * - unknown sections (stabs, comments, etc.) go at the end. 224 * 225 * Note that .tlsbss/.bss are given the largest identifiers. This insures that 226 * if any unknown sections become associated to the same segment as the .bss, 227 * the .bss sections are always the last section in the segment. 228 */ 229 #define M_ID_NULL 0x00 230 #define M_ID_USER 0x01 231 232 #define M_ID_INTERP 0x02 /* SHF_ALLOC */ 233 #define M_ID_CAP 0x03 234 #define M_ID_CAPINFO 0x04 235 #define M_ID_CAPCHAIN 0x05 236 237 #define M_ID_DYNAMIC 0x06 /* if no .interp, then no */ 238 /* DT_DEBUG is required */ 239 #define M_ID_UNWINDHDR 0x07 240 #define M_ID_UNWIND 0x08 241 242 #define M_ID_SYMINFO 0x09 243 #define M_ID_HASH 0x0a 244 #define M_ID_LDYNSYM 0x0b /* always right before DYNSYM */ 245 #define M_ID_DYNSYM 0x0c 246 #define M_ID_DYNSTR 0x0d 247 #define M_ID_VERSION 0x0e 248 #define M_ID_DYNSORT 0x0f 249 #define M_ID_REL 0x10 250 #define M_ID_ARRAY 0x11 251 #define M_ID_TEXT 0x12 /* SHF_ALLOC + SHF_EXECINSTR */ 252 #define M_ID_DATA 0x20 253 254 /* M_ID_USER 0x01 dual entry - listed above */ 255 #define M_ID_GOTDATA 0x02 /* SHF_ALLOC + SHF_WRITE */ 256 #define M_ID_GOT 0x03 257 #define M_ID_PLT 0x04 258 /* M_ID_DYNAMIC 0x06 dual entry - listed above */ 259 /* M_ID_UNWIND 0x08 dual entry - listed above */ 260 261 #define M_ID_UNKNOWN 0xfc /* just before TLS */ 262 263 #define M_ID_TLS 0xfd /* just before bss */ 264 #define M_ID_TLSBSS 0xfe 265 #define M_ID_BSS 0xff 266 267 #define M_ID_SYMTAB_NDX 0x02 /* ! SHF_ALLOC */ 268 #define M_ID_SYMTAB 0x03 269 #define M_ID_STRTAB 0x04 270 #define M_ID_DYNSYM_NDX 0x05 271 #define M_ID_NOTE 0x06 272 273 274 #ifdef __cplusplus 275 } 276 #endif 277 278 #endif /* _MACHDEP_SPARC_H */ 279