All files over ~5 lines get copylefted. All copylefted files get
[deliverable/binutils-gdb.git] / gas / config / obj-bout.h
1 /* b.out object file format
2 Copyright (C) 1989, 1990, 1991, 1992 Free Software Foundation, Inc.
3
4 This file is part of GAS, the GNU Assembler.
5
6 GAS is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as
8 published by the Free Software Foundation; either version 2,
9 or (at your option) any later version.
10
11 GAS is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
14 the GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public
17 License along with GAS; see the file COPYING. If not, write
18 to the Free Software Foundation, 675 Mass Ave, Cambridge, MA
19 02139, USA. */
20
21 /*
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 *
49 * o The downloader ('comm960') takes care to generate a pseudo-header
50 * with correct (i80960) byte-ordering before shipping text and data
51 * off to the NINDY monitor in the target systems. Symbols and
52 * relocation info are never sent to the target.
53 */
54
55
56 #define OBJ_BOUT 1
57
58 #include "targ-cpu.h"
59
60 /* bout uses host byte order for headers */
61 #ifdef CROSS_COMPILE
62 #undef CROSS_COMPILE
63 #endif /* CROSS_COMPILE */
64
65 /* We want \v. */
66 #define BACKSLASH_V 1
67
68 #define OBJ_DEFAULT_OUTPUT_FILE_NAME "b.out"
69
70 extern const short seg_N_TYPE[];
71 extern const segT N_TYPE_seg[];
72
73 #define BMAGIC 0415
74 /* We don't accept the following (see N_BADMAG macro).
75 * They're just here so GNU code will compile.
76 */
77 #define OMAGIC 0407 /* old impure format */
78 #define NMAGIC 0410 /* read-only text */
79 #define ZMAGIC 0413 /* demand load format */
80
81 #ifndef DEFAULT_MAGIC_NUMBER_FOR_OBJECT_FILE
82 #define DEFAULT_MAGIC_NUMBER_FOR_OBJECT_FILE (BMAGIC)
83 #endif /* DEFAULT_MAGIC_NUMBER_FOR_OBJECT_FILE */
84
85 /* FILE HEADER
86 * All 'lengths' are given as a number of bytes.
87 * All 'alignments' are for relinkable files only; an alignment of
88 * 'n' indicates the corresponding segment must begin at an
89 * address that is a multiple of (2**n).
90 */
91 struct exec {
92 /* Standard stuff */
93 unsigned long a_magic; /* Identifies this as a b.out file */
94 unsigned long a_text; /* Length of text */
95 unsigned long a_data; /* Length of data */
96 unsigned long a_bss; /* Length of runtime uninitialized data area */
97 unsigned long a_syms; /* Length of symbol table */
98 unsigned long a_entry; /* Runtime start address */
99 unsigned long a_trsize; /* Length of text relocation info */
100 unsigned long a_drsize; /* Length of data relocation info */
101
102 /* Added for i960 */
103 unsigned long a_tload; /* Text runtime load address */
104 unsigned long a_dload; /* Data runtime load address */
105 unsigned char a_talign; /* Alignment of text segment */
106 unsigned char a_dalign; /* Alignment of data segment */
107 unsigned char a_balign; /* Alignment of bss segment */
108 unsigned char unused; /* (Just to make struct size a multiple of 4) */
109 };
110
111 #define N_BADMAG(x) (((x).a_magic)!=BMAGIC)
112 #define N_TXTOFF(x) ( sizeof(struct exec) )
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 union {
123 char *n_name;
124 struct nlist *n_next;
125 long n_strx; /* Index into string table */
126 } n_un;
127 unsigned char n_type; /* See below */
128 char n_other; /* Used in i80960 support -- see below */
129 short n_desc;
130 unsigned long n_value;
131 };
132
133 typedef struct nlist obj_symbol_type;
134
135 /* Legal values of n_type
136 */
137 #define N_UNDF 0 /* Undefined symbol */
138 #define N_ABS 2 /* Absolute symbol */
139 #define N_TEXT 4 /* Text symbol */
140 #define N_DATA 6 /* Data symbol */
141 #define N_BSS 8 /* BSS symbol */
142 #define N_FN 31 /* Filename symbol */
143
144 #define N_EXT 1 /* External symbol (OR'd in with one of above) */
145 #define N_TYPE 036 /* Mask for all the type bits */
146 #define N_STAB 0340 /* Mask for all bits used for SDB entries */
147
148 #ifndef CUSTOM_RELOC_FORMAT
149 struct relocation_info {
150 int r_address; /* File address of item to be relocated */
151 unsigned
152 r_index:24,/* Index of symbol on which relocation is based*/
153 r_pcrel:1, /* 1 => relocate PC-relative; else absolute
154 * On i960, pc-relative implies 24-bit
155 * address, absolute implies 32-bit.
156 */
157 r_length:2, /* Number of bytes to relocate:
158 * 0 => 1 byte
159 * 1 => 2 bytes
160 * 2 => 4 bytes -- only value used for i960
161 */
162 r_extern:1,
163 r_bsr:1, /* Something for the GNU NS32K assembler */
164 r_disp:1, /* Something for the GNU NS32K assembler */
165 r_callj:1, /* 1 if relocation target is an i960 'callj' */
166 nuthin:1; /* Unused */
167 };
168 #endif /* CUSTOM_RELOC_FORMAT */
169
170 /*
171 * Macros to extract information from a symbol table entry.
172 * This syntaxic indirection allows independence regarding a.out or coff.
173 * The argument (s) of all these macros is a pointer to a symbol table entry.
174 */
175
176 /* Predicates */
177 /* True if the symbol is external */
178 #define S_IS_EXTERNAL(s) ((s)->sy_symbol.n_type & N_EXT)
179
180 /* True if symbol has been defined, ie is in N_{TEXT,DATA,BSS,ABS} or N_EXT */
181 #define S_IS_DEFINED(s) ((S_GET_TYPE(s) != N_UNDF) || (S_GET_DESC(s) != 0))
182 #define S_IS_REGISTER(s) ((s)->sy_symbol.n_type == N_REGISTER)
183
184 /* True if a debug special symbol entry */
185 #define S_IS_DEBUG(s) ((s)->sy_symbol.n_type & N_STAB)
186 /* True if a symbol is local symbol name */
187 /* A symbol name whose name begin with ^A is a gas internal pseudo symbol
188 nameless symbols come from .stab directives. */
189 #define S_IS_LOCAL(s) (S_GET_NAME(s) && \
190 !S_IS_DEBUG(s) && \
191 (S_GET_NAME(s)[0] == '\001' || \
192 (S_LOCAL_NAME(s) && !flagseen['L'])))
193 /* True if a symbol is not defined in this file */
194 #define S_IS_EXTERN(s) ((s)->sy_symbol.n_type & N_EXT)
195 /* True if the symbol has been generated because of a .stabd directive */
196 #define S_IS_STABD(s) (S_GET_NAME(s) == NULL)
197
198 /* Accessors */
199 /* The value of the symbol */
200 #define S_GET_VALUE(s) ((unsigned long) ((s)->sy_symbol.n_value))
201 /* The name of the symbol */
202 #define S_GET_NAME(s) ((s)->sy_symbol.n_un.n_name)
203 /* The pointer to the string table */
204 #define S_GET_OFFSET(s) ((s)->sy_symbol.n_un.n_strx)
205 /* The type of the symbol */
206 #define S_GET_TYPE(s) ((s)->sy_symbol.n_type & N_TYPE)
207 /* The numeric value of the segment */
208 #define S_GET_SEGMENT(s) (N_TYPE_seg[S_GET_TYPE(s)])
209 /* The n_other expression value */
210 #define S_GET_OTHER(s) ((s)->sy_symbol.n_other)
211 /* The n_desc expression value */
212 #define S_GET_DESC(s) ((s)->sy_symbol.n_desc)
213
214 /* Modifiers */
215 /* Set the value of the symbol */
216 #define S_SET_VALUE(s,v) ((s)->sy_symbol.n_value = (unsigned long) (v))
217 /* Assume that a symbol cannot be simultaneously in more than on segment */
218 /* set segment */
219 #define S_SET_SEGMENT(s,seg) ((s)->sy_symbol.n_type &= ~N_TYPE,(s)->sy_symbol.n_type|=SEGMENT_TO_SYMBOL_TYPE(seg))
220 /* The symbol is external */
221 #define S_SET_EXTERNAL(s) ((s)->sy_symbol.n_type |= N_EXT)
222 /* The symbol is not external */
223 #define S_CLEAR_EXTERNAL(s) ((s)->sy_symbol.n_type &= ~N_EXT)
224 /* Set the name of the symbol */
225 #define S_SET_NAME(s,v) ((s)->sy_symbol.n_un.n_name = (v))
226 /* Set the offset in the string table */
227 #define S_SET_OFFSET(s,v) ((s)->sy_symbol.n_un.n_strx = (v))
228 /* Set the n_other expression value */
229 #define S_SET_OTHER(s,v) ((s)->sy_symbol.n_other = (v))
230 /* Set the n_desc expression value */
231 #define S_SET_DESC(s,v) ((s)->sy_symbol.n_desc = (v))
232
233 /* File header macro and type definition */
234
235 #define H_GET_FILE_SIZE(h) (sizeof(struct exec) + \
236 H_GET_TEXT_SIZE(h) + H_GET_DATA_SIZE(h) + \
237 H_GET_SYMBOL_TABLE_SIZE(h) + \
238 H_GET_TEXT_RELOCATION_SIZE(h) + \
239 H_GET_DATA_RELOCATION_SIZE(h) + \
240 (h)->string_table_size)
241
242 #define H_GET_HEADER_SIZE(h) (sizeof(struct exec))
243 #define H_GET_TEXT_SIZE(h) ((h)->header.a_text)
244 #define H_GET_DATA_SIZE(h) ((h)->header.a_data)
245 #define H_GET_BSS_SIZE(h) ((h)->header.a_bss)
246 #define H_GET_TEXT_RELOCATION_SIZE(h) ((h)->header.a_trsize)
247 #define H_GET_DATA_RELOCATION_SIZE(h) ((h)->header.a_drsize)
248 #define H_GET_SYMBOL_TABLE_SIZE(h) ((h)->header.a_syms)
249 #define H_GET_MAGIC_NUMBER(h) ((h)->header.a_info)
250 #define H_GET_ENTRY_POINT(h) ((h)->header.a_entry)
251 #define H_GET_STRING_SIZE(h) ((h)->string_table_size)
252 #define H_GET_LINENO_SIZE(h) (0)
253
254 #ifdef EXEC_MACHINE_TYPE
255 #define H_GET_MACHINE_TYPE(h) ((h)->header.a_machtype)
256 #endif /* EXEC_MACHINE_TYPE */
257 #ifdef EXEC_VERSION
258 #define H_GET_VERSION(h) ((h)->header.a_version)
259 #endif /* EXEC_VERSION */
260
261 #define H_SET_TEXT_SIZE(h,v) ((h)->header.a_text = (v))
262 #define H_SET_DATA_SIZE(h,v) ((h)->header.a_data = (v))
263 #define H_SET_BSS_SIZE(h,v) ((h)->header.a_bss = (v))
264
265 #define H_SET_RELOCATION_SIZE(h,t,d) (H_SET_TEXT_RELOCATION_SIZE((h),(t)),\
266 H_SET_DATA_RELOCATION_SIZE((h),(d)))
267
268 #define H_SET_TEXT_RELOCATION_SIZE(h,v) ((h)->header.a_trsize = (v))
269 #define H_SET_DATA_RELOCATION_SIZE(h,v) ((h)->header.a_drsize = (v))
270 #define H_SET_SYMBOL_TABLE_SIZE(h,v) ((h)->header.a_syms = (v) * \
271 sizeof(struct nlist))
272
273 #define H_SET_MAGIC_NUMBER(h,v) ((h)->header.a_magic = (v))
274
275 #define H_SET_ENTRY_POINT(h,v) ((h)->header.a_entry = (v))
276 #define H_SET_STRING_SIZE(h,v) ((h)->string_table_size = (v))
277 #ifdef EXEC_MACHINE_TYPE
278 #define H_SET_MACHINE_TYPE(h,v) ((h)->header.a_machtype = (v))
279 #endif /* EXEC_MACHINE_TYPE */
280 #ifdef EXEC_VERSION
281 #define H_SET_VERSION(h,v) ((h)->header.a_version = (v))
282 #endif /* EXEC_VERSION */
283
284 /*
285 * Current means for getting the name of a segment.
286 * This will change for infinite-segments support (e.g. COFF).
287 */
288 #define segment_name(seg) ( seg_name[(int)(seg)] )
289 extern char *const seg_name[];
290
291 typedef struct {
292 struct exec header; /* a.out header */
293 long string_table_size; /* names + '\0' + sizeof(int) */
294 } object_headers;
295
296 /* unused hooks. */
297 #define OBJ_EMIT_LINENO(a, b, c) {;}
298 #define obj_pre_write_hook(a) {;}
299
300 #ifdef __STDC__
301 struct fix;
302 void tc_aout_fix_to_chars(char *where, struct fix *fixP, relax_addressT segment_address);
303 #else
304 void tc_aout_fix_to_chars();
305 #endif /* __STDC__ */
306
307 /*
308 * Local Variables:
309 * comment-column: 0
310 * fill-column: 131
311 * End:
312 */
313
314 /* end of obj-bout.h */
This page took 0.038452 seconds and 5 git commands to generate.