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, Version 1.0 only 6 * (the "License"). You may not use this file except in compliance 7 * with the License. 8 * 9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10 * or http://www.opensolaris.org/os/licensing. 11 * See the License for the specific language governing permissions 12 * and limitations under the License. 13 * 14 * When distributing Covered Code, include this CDDL HEADER in each 15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16 * If applicable, add the following below this CDDL HEADER, with the 17 * fields enclosed by brackets "[]" replaced with your own identifying 18 * information: Portions Copyright [yyyy] [name of copyright owner] 19 * 20 * CDDL HEADER END 21 */ 22 /* 23 * Copyright 2004 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 27 /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */ 28 /* All Rights Reserved */ 29 30 /* 31 * Portions of this source code were derived from Berkeley 4.3 BSD 32 * under license from the Regents of the University of California. 33 */ 34 35 /* 36 * SunOS 4.x a.out format -- 32-bit sparc only 37 */ 38 39 #ifndef _A_OUT_H 40 #define _A_OUT_H 41 42 #pragma ident "%Z%%M% %I% %E% SMI" 43 44 #include <sys/isa_defs.h> 45 46 #ifdef __cplusplus 47 extern "C" { 48 #endif 49 50 #if defined(__sparcv8) 51 52 /* contents of <sys/exec.h> included */ 53 54 /* 55 * format of the exec header 56 * known by kernel and by user programs 57 */ 58 struct exec { 59 unsigned char a_dynamic:1; /* has a __DYNAMIC */ 60 unsigned char a_toolversion:7; 61 /* version of toolset used to create this file */ 62 unsigned char a_machtype; /* machine type */ 63 unsigned short a_magic; /* magic number */ 64 unsigned int a_text; /* size of text segment */ 65 unsigned int a_data; /* size of initialized data */ 66 unsigned int a_bss; /* size of uninitialized data */ 67 unsigned int a_syms; /* size of symbol table */ 68 unsigned int a_entry; /* entry point */ 69 unsigned int a_trsize; /* size of text relocation */ 70 unsigned int a_drsize; /* size of data relocation */ 71 }; 72 73 #define OMAGIC 0407 /* old impure format */ 74 #define NMAGIC 0410 /* read-only text */ 75 #define ZMAGIC 0413 /* demand load format */ 76 77 /* machine types */ 78 79 #define M_OLDSUN2 0 /* old sun-2 executable files */ 80 #define M_SPARC 3 /* runs only on SPARC */ 81 82 #define TV_SUN2_SUN3 0 83 #define TV_SUN4 1 84 /* end <sys/exec.h> */ 85 86 /* 87 * memory management parameters 88 */ 89 90 #define PAGSIZ 0x02000 91 #define SEGSIZ PAGSIZ 92 #define OLD_PAGSIZ 0x00800 /* Page size under Release 2.0 */ 93 #define OLD_SEGSIZ 0x08000 /* Segment size under Release 2.0 */ 94 95 /* 96 * returns 1 if an object file type is invalid, i.e., if the other macros 97 * defined below will not yield the correct offsets. Note that a file may 98 * have N_BADMAG(x) = 0 and may be fully linked, but still may not be 99 * executable. 100 */ 101 102 #define N_BADMAG(x) \ 103 ((x).a_magic != OMAGIC && (x).a_magic != NMAGIC && \ 104 (x).a_magic != ZMAGIC) 105 106 /* 107 * relocation parameters. These are architecture-dependent 108 * and can be deduced from the machine type. They are used 109 * to calculate offsets of segments within the object file; 110 * See N_TXTOFF(x), etc. below. 111 */ 112 113 #define N_PAGSIZ(x) \ 114 ((x).a_machtype == M_OLDSUN2? OLD_PAGSIZ : PAGSIZ) 115 #define N_SEGSIZ(x) \ 116 ((x).a_machtype == M_OLDSUN2? OLD_SEGSIZ : SEGSIZ) 117 118 /* 119 * offsets of various sections of an object file. 120 */ 121 122 #define N_TXTOFF(x) \ 123 /* text segment */ \ 124 ((x).a_machtype == M_OLDSUN2 \ 125 ? ((x).a_magic == ZMAGIC ? N_PAGSIZ(x) : sizeof (struct exec)) \ 126 : ((x).a_magic == ZMAGIC ? 0 : sizeof (struct exec))) 127 128 #define N_DATOFF(x) /* data segment */ \ 129 (N_TXTOFF(x) + (x).a_text) 130 131 #define N_TRELOFF(x) /* text reloc'n */ \ 132 (N_DATOFF(x) + (x).a_data) 133 134 #define N_DRELOFF(x) /* data relocation */ \ 135 (N_TRELOFF(x) + (x).a_trsize) 136 137 #define N_SYMOFF(x) \ 138 /* symbol table */ \ 139 (N_TXTOFF(x)+(x).a_text+(x).a_data+(x).a_trsize+(x).a_drsize) 140 141 #define N_STROFF(x) \ 142 /* string table */ \ 143 (N_SYMOFF(x) + (x).a_syms) 144 145 /* 146 * Macros which take exec structures as arguments and tell where the 147 * various pieces will be loaded. 148 */ 149 150 #define _N_BASEADDR(x) \ 151 (((x).a_magic == ZMAGIC) && ((x).a_entry < N_PAGSIZ(x)) ? \ 152 0 : N_PAGSIZ(x)) 153 154 #define N_TXTADDR(x) \ 155 ((x).a_machtype == M_OLDSUN2 ? N_SEGSIZ(x) : _N_BASEADDR(x)) 156 157 #define N_DATADDR(x) \ 158 (((x).a_magic == OMAGIC)? (N_TXTADDR(x)+(x).a_text) \ 159 : (N_SEGSIZ(x)+((N_TXTADDR(x)+(x).a_text-1) & ~(N_SEGSIZ(x)-1)))) 160 161 #define N_BSSADDR(x) (N_DATADDR(x)+(x).a_data) 162 163 /* 164 * Format of a relocation datum. 165 */ 166 167 /* 168 * Sparc relocation types 169 */ 170 171 enum reloc_type 172 { 173 RELOC_8, RELOC_16, RELOC_32, /* simplest relocs */ 174 RELOC_DISP8, RELOC_DISP16, RELOC_DISP32, /* Disp's (pc-rel) */ 175 RELOC_WDISP30, RELOC_WDISP22, /* SR word disp's */ 176 RELOC_HI22, RELOC_22, /* SR 22-bit relocs */ 177 RELOC_13, RELOC_LO10, /* SR 13&10-bit relocs */ 178 RELOC_SFA_BASE, RELOC_SFA_OFF13, /* SR S.F.A. relocs */ 179 RELOC_BASE10, RELOC_BASE13, RELOC_BASE22, /* base_relative pic */ 180 RELOC_PC10, RELOC_PC22, /* special pc-rel pic */ 181 RELOC_JMP_TBL, /* jmp_tbl_rel in pic */ 182 RELOC_SEGOFF16, /* ShLib offset-in-seg */ 183 RELOC_GLOB_DAT, RELOC_JMP_SLOT, RELOC_RELATIVE /* rtld relocs */ 184 }; 185 186 /* 187 * Format of a relocation datum. 188 */ 189 190 struct reloc_info_sparc /* used when header.a_machtype == M_SPARC */ 191 { 192 unsigned int r_address; 193 /* relocation addr (offset in segment) */ 194 unsigned int r_index :24; /* segment index or symbol index */ 195 unsigned int r_extern : 1; /* if F, r_index==SEG#; if T, SYM idx */ 196 int : 2; /* <unused> */ 197 enum reloc_type r_type : 5; /* type of relocation to perform */ 198 int r_addend; /* addend for relocation value */ 199 }; 200 201 202 203 /* 204 * Format of a symbol table entry 205 */ 206 struct nlist { 207 union { 208 char *n_name; /* for use when in-core */ 209 int n_strx; /* index into file string table */ 210 } n_un; 211 unsigned char n_type; /* type flag (N_TEXT,..) */ 212 char n_other; /* unused */ 213 short n_desc; /* see <stab.h> */ 214 unsigned int n_value; /* value of symbol (or sdb offset) */ 215 }; 216 217 /* 218 * Simple values for n_type. 219 */ 220 #define N_UNDF 0x0 /* undefined */ 221 #define N_ABS 0x2 /* absolute */ 222 #define N_TEXT 0x4 /* text */ 223 #define N_DATA 0x6 /* data */ 224 #define N_BSS 0x8 /* bss */ 225 #define N_COMM 0x12 /* common (internal to ld) */ 226 #define N_FN 0x1e /* file name symbol */ 227 228 #define N_EXT 01 /* external bit, or'ed in */ 229 #define N_TYPE 0x1e /* mask for all the type bits */ 230 231 /* 232 * Dbx entries have some of the N_STAB bits set. 233 * These are given in <stab.h> 234 */ 235 #define N_STAB 0xe0 /* if any of these bits set, a dbx symbol */ 236 237 /* 238 * Format for namelist values. 239 */ 240 #define N_FORMAT "%08x" 241 242 /* 243 * secondary sections. 244 * this stuff follows the string table. 245 * not even its presence or absence is noted in the 246 * exec header (?). the secondary header gives 247 * the number of sections. following it is an 248 * array of "extra_nsects" int's which give the 249 * sizeof of the individual sections. the presence of 250 * even the header is optional. 251 */ 252 253 #define EXTRA_MAGIC 1040 /* taxing concept */ 254 #define EXTRA_IDENT 0 /* ident's in 0th extra section */ 255 256 struct extra_sections { 257 int extra_magic; /* should be EXTRA_MAGIC */ 258 int extra_nsects; /* number of extra sections */ 259 }; 260 261 #endif /* defined(__sparcv8) */ 262 263 #ifdef __cplusplus 264 } 265 #endif 266 267 #endif /* _A_OUT_H */ 268