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