1 /* b.out object file format 2 Copyright 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1998, 2000, 3 2002, 2003, 2005 Free Software Foundation, Inc. 4 5 This file is part of GAS, the GNU Assembler. 6 7 GAS is free software; you can redistribute it and/or modify 8 it under the terms of the GNU General Public License as 9 published by the Free Software Foundation; either version 2, 10 or (at your option) any later version. 11 12 GAS is distributed in the hope that it will be useful, but 13 WITHOUT ANY WARRANTY; without even the implied warranty of 14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 15 the GNU General Public License for more details. 16 17 You should have received a copy of the GNU General Public 18 License along with GAS; see the file COPYING. If not, write 19 to the Free Software Foundation, 59 Temple Place - Suite 330, Cambridge, MA 20 02139, USA. */ 21 22 /* 23 * This file is a modified version of 'a.out.h'. It is to be used in all GNU 24 * tools modified to support the i80960 b.out format (or tools that operate on 25 * object files created by such tools). 26 * 27 * All i80960 development is done in a CROSS-DEVELOPMENT environment. I.e., 28 * object code is generated on, and executed under the direction of a symbolic 29 * debugger running on, a host system. We do not want to be subject to the 30 * vagaries of which host it is or whether it supports COFF or a.out format, or 31 * anything else. We DO want to: 32 * 33 * o always generate the same format object files, regardless of host. 34 * 35 * o have an 'a.out' header that we can modify for our own purposes 36 * (the 80960 is typically an embedded processor and may require 37 * enhanced linker support that the normal a.out.h header can't 38 * accommodate). 39 * 40 * As for byte-ordering, the following rules apply: 41 * 42 * o Text and data that is actually downloaded to the target is always 43 * in i80960 (little-endian) order. 44 * 45 * o All other numbers (in the header, symbols, relocation directives) 46 * are in host byte-order: object files CANNOT be lifted from a 47 * little-end host and used on a big-endian (or vice versa) without 48 * modification. 49 * ==> THIS IS NO LONGER TRUE USING BFD. WE CAN GENERATE ANY BYTE ORDER 50 * FOR THE HEADER, AND READ ANY BYTE ORDER. PREFERENCE WOULD BE TO 51 * USE LITTLE-ENDIAN BYTE ORDER THROUGHOUT, REGARDLESS OF HOST. <== 52 * 53 * o The downloader ('comm960') takes care to generate a pseudo-header 54 * with correct (i80960) byte-ordering before shipping text and data 55 * off to the NINDY monitor in the target systems. Symbols and 56 * relocation info are never sent to the target. 57 */ 58 59 #define OBJ_BOUT 1 60 61 #define OUTPUT_FLAVOR bfd_target_aout_flavour 62 63 #include "targ-cpu.h" 64 65 #define OBJ_DEFAULT_OUTPUT_FILE_NAME "b.out" 66 67 extern const short seg_N_TYPE[]; 68 extern const segT N_TYPE_seg[]; 69 70 #define BMAGIC 0415 71 /* We don't accept the following (see N_BADMAG macro). 72 * They're just here so GNU code will compile. 73 */ 74 #define OMAGIC 0407 /* old impure format */ 75 #define NMAGIC 0410 /* read-only text */ 76 #define ZMAGIC 0413 /* demand load format */ 77 78 #ifndef DEFAULT_MAGIC_NUMBER_FOR_OBJECT_FILE 79 #define DEFAULT_MAGIC_NUMBER_FOR_OBJECT_FILE (BMAGIC) 80 #endif /* DEFAULT_MAGIC_NUMBER_FOR_OBJECT_FILE */ 81 82 /* FILE HEADER 83 * All 'lengths' are given as a number of bytes. 84 * All 'alignments' are for relinkable files only; an alignment of 85 * 'n' indicates the corresponding segment must begin at an 86 * address that is a multiple of (2**n). 87 */ 88 struct exec 89 { 90 /* Standard stuff */ 91 unsigned long a_magic; /* Identifies this as a b.out file */ 92 unsigned long a_text; /* Length of text */ 93 unsigned long a_data; /* Length of data */ 94 unsigned long a_bss; /* Length of runtime uninitialized data area */ 95 unsigned long a_syms; /* Length of symbol table */ 96 unsigned long a_entry; /* Runtime start address */ 97 unsigned long a_trsize; /* Length of text relocation info */ 98 unsigned long a_drsize; /* Length of data relocation info */ 99 100 /* Added for i960 */ 101 unsigned long a_tload; /* Text runtime load address */ 102 unsigned long a_dload; /* Data runtime load address */ 103 unsigned char a_talign; /* Alignment of text segment */ 104 unsigned char a_dalign; /* Alignment of data segment */ 105 unsigned char a_balign; /* Alignment of bss segment */ 106 unsigned char a_relaxable; /* Contains enough info to relax */ 107 }; 108 109 #define EXEC_BYTES_SIZE (10 * 4 + 4 * 1) 110 111 #define N_BADMAG(x) (((x).a_magic)!=BMAGIC) 112 #define N_TXTOFF(x) EXEC_BYTES_SIZE 113 #define N_DATOFF(x) ( N_TXTOFF(x) + (x).a_text ) 114 #define N_TROFF(x) ( N_DATOFF(x) + (x).a_data ) 115 #define N_DROFF(x) ( N_TROFF(x) + (x).a_trsize ) 116 #define N_SYMOFF(x) ( N_DROFF(x) + (x).a_drsize ) 117 #define N_STROFF(x) ( N_SYMOFF(x) + (x).a_syms ) 118 119 /* A single entry in the symbol table 120 */ 121 struct nlist 122 { 123 union 124 { 125 char *n_name; 126 struct nlist *n_next; 127 long n_strx; /* Index into string table */ 128 } 129 n_un; 130 unsigned char n_type; /* See below */ 131 char n_other; /* Used in i80960 support -- see below */ 132 short n_desc; 133 unsigned long n_value; 134 }; 135 136 typedef struct nlist obj_symbol_type; 137 138 /* Legal values of n_type 139 */ 140 #define N_UNDF 0 /* Undefined symbol */ 141 #define N_ABS 2 /* Absolute symbol */ 142 #define N_TEXT 4 /* Text symbol */ 143 #define N_DATA 6 /* Data symbol */ 144 #define N_BSS 8 /* BSS symbol */ 145 #define N_FN 31 /* Filename symbol */ 146 147 #define N_EXT 1 /* External symbol (OR'd in with one of above) */ 148 #define N_TYPE 036 /* Mask for all the type bits */ 149 #define N_STAB 0340 /* Mask for all bits used for SDB entries */ 150 151 #ifndef CUSTOM_RELOC_FORMAT 152 struct relocation_info 153 { 154 int r_address; /* File address of item to be relocated */ 155 unsigned 156 r_index:24, /* Index of symbol on which relocation is based*/ 157 r_pcrel:1, /* 1 => relocate PC-relative; else absolute 158 * On i960, pc-relative implies 24-bit 159 * address, absolute implies 32-bit. 160 */ 161 r_length:2, /* Number of bytes to relocate: 162 * 0 => 1 byte 163 * 1 => 2 bytes 164 * 2 => 4 bytes -- only value used for i960 165 */ 166 r_extern:1, r_bsr:1, /* Something for the GNU NS32K assembler */ 167 r_disp:1, /* Something for the GNU NS32K assembler */ 168 r_callj:1, /* 1 if relocation target is an i960 'callj' */ 169 nuthin:1; /* Unused */ 170 }; 171 172 #endif /* CUSTOM_RELOC_FORMAT */ 173 174 /* 175 * Macros to extract information from a symbol table entry. 176 * This syntactic indirection allows independence regarding a.out or coff. 177 * The argument (s) of all these macros is a pointer to a symbol table entry. 178 */ 179 180 /* Predicates */ 181 /* True if the symbol is external */ 182 #define S_IS_EXTERNAL(s) ((s)->sy_symbol.n_type & N_EXT) 183 184 /* True if symbol has been defined, ie is in N_{TEXT,DATA,BSS,ABS} or N_EXT */ 185 #define S_IS_DEFINED(s) ((S_GET_TYPE(s) != N_UNDF) || (S_GET_DESC(s) != 0)) 186 187 /* Return true for symbols that should not be reduced to section 188 symbols or eliminated from expressions, because they may be 189 overridden by the linker. */ 190 #define S_FORCE_RELOC(s, strict) \ 191 (!SEG_NORMAL (S_GET_SEGMENT (s))) 192 193 #define S_IS_COMMON(s) \ 194 (S_GET_TYPE (s) == N_UNDF && S_GET_VALUE (s) != 0) 195 196 #define S_IS_REGISTER(s) ((s)->sy_symbol.n_type == N_REGISTER) 197 198 /* True if a debug special symbol entry */ 199 #define S_IS_DEBUG(s) ((s)->sy_symbol.n_type & N_STAB) 200 /* True if a symbol is local symbol name */ 201 #define S_IS_LOCAL(s) \ 202 ((S_GET_NAME (s) \ 203 && !S_IS_DEBUG (s) \ 204 && (strchr (S_GET_NAME (s), '\001') != NULL \ 205 || strchr (S_GET_NAME (s), '\002') != NULL \ 206 || (S_LOCAL_NAME(s) && !flag_keep_locals))) \ 207 || (flag_strip_local_absolute \ 208 && !S_IS_EXTERNAL(s) \ 209 && S_GET_SEGMENT(s) == absolute_section)) 210 /* True if a symbol is not defined in this file */ 211 #define S_IS_EXTERN(s) ((s)->sy_symbol.n_type & N_EXT) 212 /* True if the symbol has been generated because of a .stabd directive */ 213 #define S_IS_STABD(s) (S_GET_NAME(s) == NULL) 214 215 /* Accessors */ 216 /* The name of the symbol */ 217 #define S_GET_NAME(s) ((s)->sy_symbol.n_un.n_name) 218 /* The pointer to the string table */ 219 #define S_GET_OFFSET(s) ((s)->sy_symbol.n_un.n_strx) 220 /* The type of the symbol */ 221 #define S_GET_TYPE(s) ((s)->sy_symbol.n_type & N_TYPE) 222 /* The numeric value of the segment */ 223 #define S_GET_SEGMENT(s) (N_TYPE_seg[S_GET_TYPE(s)]) 224 /* The n_other expression value */ 225 #define S_GET_OTHER(s) ((s)->sy_symbol.n_other) 226 /* The n_desc expression value */ 227 #define S_GET_DESC(s) ((s)->sy_symbol.n_desc) 228 229 /* Modifiers */ 230 /* Assume that a symbol cannot be simultaneously in more than on segment */ 231 /* set segment */ 232 #define S_SET_SEGMENT(s,seg) ((s)->sy_symbol.n_type &= ~N_TYPE,(s)->sy_symbol.n_type|=SEGMENT_TO_SYMBOL_TYPE(seg)) 233 /* The symbol is external */ 234 #define S_SET_EXTERNAL(s) ((s)->sy_symbol.n_type |= N_EXT) 235 /* The symbol is not external */ 236 #define S_CLEAR_EXTERNAL(s) ((s)->sy_symbol.n_type &= ~N_EXT) 237 /* Set the name of the symbol */ 238 #define S_SET_NAME(s,v) ((s)->sy_symbol.n_un.n_name = (v)) 239 /* Set the offset in the string table */ 240 #define S_SET_OFFSET(s,v) ((s)->sy_symbol.n_un.n_strx = (v)) 241 /* Set the n_other expression value */ 242 #define S_SET_OTHER(s,v) ((s)->sy_symbol.n_other = (v)) 243 /* Set the n_desc expression value */ 244 #define S_SET_DESC(s,v) ((s)->sy_symbol.n_desc = (v)) 245 /* Set the n_type value */ 246 #define S_SET_TYPE(s,v) ((s)->sy_symbol.n_type = (v)) 247 248 /* File header macro and type definition */ 249 250 #define H_GET_FILE_SIZE(h) (EXEC_BYTES_SIZE + \ 251 H_GET_TEXT_SIZE(h) + H_GET_DATA_SIZE(h) + \ 252 H_GET_SYMBOL_TABLE_SIZE(h) + \ 253 H_GET_TEXT_RELOCATION_SIZE(h) + \ 254 H_GET_DATA_RELOCATION_SIZE(h) + \ 255 (h)->string_table_size) 256 257 #define H_GET_HEADER_SIZE(h) EXEC_BYTES_SIZE 258 #define H_GET_TEXT_SIZE(h) ((h)->header.a_text) 259 #define H_GET_DATA_SIZE(h) ((h)->header.a_data) 260 #define H_GET_BSS_SIZE(h) ((h)->header.a_bss) 261 #define H_GET_TEXT_RELOCATION_SIZE(h) ((h)->header.a_trsize) 262 #define H_GET_DATA_RELOCATION_SIZE(h) ((h)->header.a_drsize) 263 #define H_GET_SYMBOL_TABLE_SIZE(h) ((h)->header.a_syms) 264 #define H_GET_MAGIC_NUMBER(h) ((h)->header.a_info) 265 #define H_GET_ENTRY_POINT(h) ((h)->header.a_entry) 266 #define H_GET_STRING_SIZE(h) ((h)->string_table_size) 267 #define H_GET_LINENO_SIZE(h) (0) 268 269 #ifdef EXEC_MACHINE_TYPE 270 #define H_GET_MACHINE_TYPE(h) ((h)->header.a_machtype) 271 #endif /* EXEC_MACHINE_TYPE */ 272 #ifdef EXEC_VERSION 273 #define H_GET_VERSION(h) ((h)->header.a_version) 274 #endif /* EXEC_VERSION */ 275 276 #define H_SET_TEXT_SIZE(h,v) ((h)->header.a_text = (v)) 277 #define H_SET_DATA_SIZE(h,v) ((h)->header.a_data = (v)) 278 #define H_SET_BSS_SIZE(h,v) ((h)->header.a_bss = (v)) 279 280 #define H_SET_RELOCATION_SIZE(h,t,d) (H_SET_TEXT_RELOCATION_SIZE((h),(t)),\ 281 H_SET_DATA_RELOCATION_SIZE((h),(d))) 282 283 #define H_SET_TEXT_RELOCATION_SIZE(h,v) ((h)->header.a_trsize = (v)) 284 #define H_SET_DATA_RELOCATION_SIZE(h,v) ((h)->header.a_drsize = (v)) 285 #define H_SET_SYMBOL_TABLE_SIZE(h,v) ((h)->header.a_syms = (v) * 12) 286 287 #define H_SET_MAGIC_NUMBER(h,v) ((h)->header.a_magic = (v)) 288 289 #define H_SET_ENTRY_POINT(h,v) ((h)->header.a_entry = (v)) 290 #define H_SET_STRING_SIZE(h,v) ((h)->string_table_size = (v)) 291 #ifdef EXEC_MACHINE_TYPE 292 #define H_SET_MACHINE_TYPE(h,v) ((h)->header.a_machtype = (v)) 293 #endif /* EXEC_MACHINE_TYPE */ 294 #ifdef EXEC_VERSION 295 #define H_SET_VERSION(h,v) ((h)->header.a_version = (v)) 296 #endif /* EXEC_VERSION */ 297 298 typedef struct 299 { 300 struct exec header; /* a.out header */ 301 long string_table_size; /* names + '\0' + sizeof (int) */ 302 } 303 304 object_headers; 305 306 /* unused hooks. */ 307 #define OBJ_EMIT_LINENO(a, b, c) {;} 308 #define obj_pre_write_hook(a) {;} 309 310 #if WORDS_BIGENDIAN 311 #define host_number_to_chars number_to_chars_bigendian 312 #else 313 #define host_number_to_chars number_to_chars_littleendian 314 #endif 315 316 #if __STDC__ 317 struct fix; 318 #endif 319 extern void tc_aout_fix_to_chars PARAMS ((char *where, 320 struct fix *fixP, 321 relax_addressT segment_address)); 322 extern void tc_bout_fix_to_chars PARAMS ((char *where, 323 struct fix *fixP, 324 relax_addressT segment_address)); 325 326 #define AOUT_STABS 327