RIP gzip, we found a nicer playmate.
[dragonfly.git] / gnu / usr.bin / as / config / obj-aout.h
1 /* obj-aout.h, a.out object file format for gas, the assembler.
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 02139, USA.
19 */
20
21 /*
22  * $FreeBSD: src/gnu/usr.bin/as/config/obj-aout.h,v 1.9 1999/08/27 23:34:29 peter Exp $
23  * $DragonFly: src/gnu/usr.bin/as/config/Attic/obj-aout.h,v 1.2 2003/06/17 04:25:44 dillon Exp $
24  */
25
26
27 /* Tag to validate a.out object file format processing */
28 #define OBJ_AOUT 1
29
30 #include "targ-cpu.h"
31
32 #include "aout.h"               /* Needed to define struct nlist. Sigh. */
33
34 #ifndef AOUT_MACHTYPE
35 #define AOUT_MACHTYPE 0
36 #endif
37
38 #ifndef AOUT_VERSION
39 #define AOUT_VERSION 0
40 #endif
41
42 #ifndef AOUT_FLAGS
43 #define AOUT_FLAGS 0
44 #endif
45
46 extern const short seg_N_TYPE[];
47 extern const segT  N_TYPE_seg[];
48 #define N_REGISTER              0x12    /* Fake register type */
49
50 #ifndef DEFAULT_MAGIC_NUMBER_FOR_OBJECT_FILE
51 #define DEFAULT_MAGIC_NUMBER_FOR_OBJECT_FILE    (OMAGIC)
52 #endif /* DEFAULT_MAGIC_NUMBER_FOR_OBJECT_FILE */
53
54 /* First character of operand in `.type' directives */
55 #define TYPE_OPERAND_FMT        '@'
56
57 /* SYMBOL TABLE */
58 /* Symbol table entry data type */
59
60 typedef struct nlist obj_symbol_type; /* Symbol table entry */
61
62 /* Symbol table macros and constants */
63
64 /*
65  *  Macros to extract information from a symbol table entry.
66  *  This syntaxic indirection allows independence regarding a.out or coff.
67  *  The argument (s) of all these macros is a pointer to a symbol table entry.
68  */
69
70 /* True if the symbol is external */
71 #define S_IS_EXTERNAL(s)        ((s)->sy_symbol.n_type & N_EXT)
72
73 /* True if symbol has been defined, ie is in N_{TEXT,DATA,BSS,ABS} or N_EXT */
74 #define S_IS_DEFINED(s)         ((S_GET_TYPE(s) != N_UNDF) || (S_GET_OTHER(s) != 0) || (S_GET_DESC(s) != 0))
75
76 #define S_IS_REGISTER(s)        ((s)->sy_symbol.n_type == N_REGISTER)
77
78 /* True if a debug special symbol entry */
79 #define S_IS_DEBUG(s)           ((s)->sy_symbol.n_type & N_STAB)
80 /* True if a symbol is local symbol name */
81 /* A symbol name whose name begin with ^A is a gas internal pseudo symbol
82    nameless symbols come from .stab directives. */
83 #define S_IS_LOCAL(s)           (S_GET_NAME(s) && \
84                                  !S_IS_DEBUG(s) && \
85                                  (S_GET_NAME(s)[0] == '\001' || \
86                                   (S_LOCAL_NAME(s) && !flagseen['L'])))
87 /* True if a symbol is not defined in this file */
88 #define S_IS_EXTERN(s)          ((s)->sy_symbol.n_type & N_EXT)
89 /* True if the symbol has been generated because of a .stabd directive */
90 #define S_IS_STABD(s)           (S_GET_NAME(s) == (char *)0)
91
92 /* Accessors */
93 /* The value of the symbol */
94 #define S_GET_VALUE(s)          (((s)->sy_symbol.n_value))
95 /* The name of the symbol */
96 #define S_GET_NAME(s)           ((s)->sy_symbol.n_un.n_name)
97 /* The pointer to the string table */
98 #define S_GET_OFFSET(s)         ((s)->sy_symbol.n_un.n_strx)
99 /* The type of the symbol */
100 #define S_GET_TYPE(s)           ((s)->sy_symbol.n_type & N_TYPE)
101 /* The numeric value of the segment */
102 #define S_GET_SEGMENT(s)        (N_TYPE_seg[S_GET_TYPE(s)])
103 /* The n_other expression value */
104 #define S_GET_OTHER(s)          ((s)->sy_symbol.n_other)
105 /* The n_desc expression value */
106 #define S_GET_DESC(s)           ((s)->sy_symbol.n_desc)
107
108 /* Modifiers */
109 /* Set the value of the symbol */
110 #define S_SET_VALUE(s,v)        ((s)->sy_symbol.n_value = (unsigned long) (v))
111 /* Assume that a symbol cannot be simultaneously in more than on segment */
112 /* set segment */
113 #define S_SET_SEGMENT(s,seg)    ((s)->sy_symbol.n_type &= ~N_TYPE,(s)->sy_symbol.n_type|=SEGMENT_TO_SYMBOL_TYPE(seg))
114 /* The symbol is external */
115 #define S_SET_EXTERNAL(s)       ((s)->sy_symbol.n_type |= N_EXT)
116 /* The symbol is not external */
117 #define S_CLEAR_EXTERNAL(s)     ((s)->sy_symbol.n_type &= ~N_EXT)
118 /* Set the name of the symbol */
119 #define S_SET_NAME(s,v)         ((s)->sy_symbol.n_un.n_name = (v))
120 /* Set the offset in the string table */
121 #define S_SET_OFFSET(s,v)       ((s)->sy_symbol.n_un.n_strx = (v))
122 /* Set the n_other expression value */
123 #define S_SET_OTHER(s,v)        ((s)->sy_symbol.n_other = (v))
124 /* Set the n_desc expression value */
125 #define S_SET_DESC(s,v)         ((s)->sy_symbol.n_desc = (v))
126
127 /* File header macro and type definition */
128
129 #define H_GET_FILE_SIZE(h)      (H_GET_HEADER_SIZE(h) \
130                                  + H_GET_TEXT_SIZE(h) \
131                                  + H_GET_DATA_SIZE(h) \
132                                  + H_GET_SYMBOL_TABLE_SIZE(h) \
133                                  + H_GET_TEXT_RELOCATION_SIZE(h) \
134                                  + H_GET_DATA_RELOCATION_SIZE(h) \
135                                  + H_GET_STRING_SIZE(h))
136
137 #ifndef H_GET_HEADER_SIZE
138 #define H_GET_HEADER_SIZE(h)            (sizeof(struct exec))
139 #endif /* not H_GET_HEADER_SIZE */
140
141 #define H_GET_TEXT_SIZE(h)              ((h)->header.a_text)
142 #define H_GET_DATA_SIZE(h)              ((h)->header.a_data)
143 #define H_GET_BSS_SIZE(h)               ((h)->header.a_bss)
144 #define H_GET_TEXT_RELOCATION_SIZE(h)   ((h)->header.a_trsize)
145 #define H_GET_DATA_RELOCATION_SIZE(h)   ((h)->header.a_drsize)
146 #define H_GET_SYMBOL_TABLE_SIZE(h)      ((h)->header.a_syms)
147 #define H_GET_ENTRY_POINT(h)            ((h)->header.a_entry)
148 #define H_GET_STRING_SIZE(h)            ((h)->string_table_size)
149 #define H_GET_LINENO_SIZE(h)            (0)
150
151 #if defined(FREEBSD_AOUT) || defined(NETBSD_AOUT)
152
153 #if defined(FREEBSD_AOUT)
154 /* duplicate part of <sys/imgact_aout.h> */
155 #define H_GET_FLAGS(h)                                          \
156         ( (((h)->header.a_info)&0xffff)                         \
157                 ? ((h)->header.a_info >> 26) & 0x3f )           \
158                 : 0                                             \
159         )
160 #define H_GET_MACHTYPE(h)                                       \
161         ( (((h)->header.a_info)&0xffff)                         \
162                 ? ((h)->header.a_info >>16 ) & 0x3ff)           \
163                 : 0                                             \
164         )
165
166 #define H_GET_MAGIC_NUMBER(h)                                   \
167         ( (((h)->header.a_info)&0xffff)                         \
168                 ? ((h)->header.a_info & 0xffff)                 \
169                 : (ntohl(((h)->header.a_info))&0xffff)          \
170         )
171
172 #define H_SET_INFO(h,mag,mid,f,v)                               \
173         ( (h)->header.a_info =                                  \
174            (((f)&0x3f)<<26) | (((mid)&0x03ff)<<16) | (((mag)&0xffff)) )
175
176 #endif /* FREEBSD_AOUT */
177
178 #if defined(NETBSD_AOUT)
179 /* SH*T, duplicate part of <a.out.h> */
180 #define H_GET_FLAGS(h)                                          \
181         ( (((h)->header.a_info)&0xffff0000)                     \
182                 ? ((ntohl(((h)->header.a_info))>>26)&0x3f)      \
183                 : 0                                             \
184         )
185
186 #define H_GET_MACHTYPE(h)                                       \
187         ( (((h)->header.a_info)&0xffff0000)                     \
188                 ? ((ntohl(((h)->header.a_info))>>16)&0x3ff)     \
189                 : 0                                             \
190         )
191
192 #define H_GET_MAGIC_NUMBER(h)                                   \
193         ( (((h)->header.a_info)&0xffff0000)                     \
194                 ? (ntohl(((h)->header.a_info))&0xffff)          \
195                 : ((h)->header.a_info & 0xffff)                 \
196         )
197
198 #define H_SET_INFO(h,mag,mid,f,v)                               \
199         ( (h)->header.a_info =                                  \
200            htonl( (((f)&0x3f)<<26) | (((mid)&0x03ff)<<16) | (((mag)&0xffff)) ) )
201
202 #endif /* NETBSD_AOUT */
203
204 #define EX_DYNAMIC                      0x20
205 #define EX_PIC                          0x10
206 #undef AOUT_FLAGS
207 #define AOUT_FLAGS                      (picmode ? EX_PIC : 0)
208
209 #define H_GET_DYNAMIC(h)                (H_GET_FLAGS(h) & EX_DYNAMIC)
210
211 #define H_GET_VERSION(h)                (0)
212
213 #define H_SET_DYNAMIC(h,v)                                      \
214         H_SET_INFO(h, H_GET_MAGIC_NUMBER(h), H_GET_MACHTYPE(h), \
215                    (v)?(H_GET_FLAGS(h)|0x20):(H_GET_FLAGS(h)&(~0x20)), 0)
216
217 #define H_SET_VERSION(h,v)
218
219 #define H_SET_MACHTYPE(h,v)                                     \
220         H_SET_INFO(h, H_GET_MAGIC_NUMBER(h), (v), H_GET_FLAGS(h), 0)
221
222 #define H_SET_MAGIC_NUMBER(h,v)                                 \
223         H_SET_INFO(h, (v), H_GET_MACHTYPE(h), H_GET_FLAGS(h), 0)
224
225 #else /* !(FREEBSD_AOUT || NETBSD_AOUT) */
226
227 #define H_GET_DYNAMIC(h)                ((h)->header.a_info >> 31)
228 #define H_GET_VERSION(h)                (((h)->header.a_info >> 24) & 0x7f)
229 #define H_GET_MACHTYPE(h)               (((h)->header.a_info >> 16) & 0xff)
230 #define H_GET_MAGIC_NUMBER(h)           ((h)->header.a_info & 0xffff)
231
232 #define H_SET_DYNAMIC(h,v)              ((h)->header.a_info = \
233                                                 (((v) << 31) \
234                                                 | (H_GET_VERSION(h) << 24) \
235                                                 | (H_GET_MACHTYPE(h) << 16) \
236                                                 | (H_GET_MAGIC_NUMBER(h))))
237
238 #define H_SET_VERSION(h,v)              ((h)->header.a_info = \
239                                                 ((H_GET_DYNAMIC(h) << 31) \
240                                                 | ((v) << 24) \
241                                                 | (H_GET_MACHTYPE(h) << 16) \
242                                                 | (H_GET_MAGIC_NUMBER(h))))
243
244 #define H_SET_MACHTYPE(h,v)             ((h)->header.a_info = \
245                                                 ((H_GET_DYNAMIC(h) << 31) \
246                                                 | (H_GET_VERSION(h) << 24) \
247                                                 | ((v) << 16) \
248                                                 | (H_GET_MAGIC_NUMBER(h))))
249
250 #define H_SET_MAGIC_NUMBER(h,v)         ((h)->header.a_info = \
251                                                 ((H_GET_DYNAMIC(h) << 31) \
252                                                 | (H_GET_VERSION(h) << 24) \
253                                                 | (H_GET_MACHTYPE(h) << 16) \
254                                                 | ((v))))
255 #define H_SET_INFO(h,mag,mid,f,v)       ((h)->header.a_info = \
256                                                 ((((f)==0x20) << 31) \
257                                                 | ((v) << 24) \
258                                                 | ((mid) << 16) \
259                                                 | ((mag))) )
260 #endif /* FREEBSD_AOUT || NETBSD_AOUT */
261
262 #define H_SET_TEXT_SIZE(h,v)            ((h)->header.a_text = md_section_align(SEG_TEXT, (v)))
263 #define H_SET_DATA_SIZE(h,v)            ((h)->header.a_data = md_section_align(SEG_DATA, (v)))
264 #define H_SET_BSS_SIZE(h,v)             ((h)->header.a_bss = md_section_align(SEG_BSS, (v)))
265
266 #define H_SET_RELOCATION_SIZE(h,t,d)    (H_SET_TEXT_RELOCATION_SIZE((h),(t)),\
267                                          H_SET_DATA_RELOCATION_SIZE((h),(d)))
268
269 #define H_SET_TEXT_RELOCATION_SIZE(h,v) ((h)->header.a_trsize = (v))
270 #define H_SET_DATA_RELOCATION_SIZE(h,v) ((h)->header.a_drsize = (v))
271 #define H_SET_SYMBOL_TABLE_SIZE(h,v)    ((h)->header.a_syms = (v) * \
272                                          sizeof(struct nlist))
273
274 #define H_SET_ENTRY_POINT(h,v)          ((h)->header.a_entry = (v))
275 #define H_SET_STRING_SIZE(h,v)          ((h)->string_table_size = (v))
276
277 /*
278  * Current means for getting the name of a segment.
279  * This will change for infinite-segments support (e.g. COFF).
280  */
281 #define segment_name(seg)  (seg_name[(int)(seg)])
282 extern char *const seg_name[];
283
284 typedef struct {
285         struct exec header;                     /* a.out header */
286         long string_table_size; /* names + '\0' + sizeof(int) */
287 } object_headers;
288
289 /* line numbering stuff. */
290 #define OBJ_EMIT_LINENO(a, b, c)        {;}
291
292 #define obj_symbol_new_hook(s)  {;}
293
294 #if __STDC__ == 1
295 struct fix;
296 void tc_aout_fix_to_chars(char *where, struct fix *fixP, relax_addressT segment_address);
297 #else /* not __STDC__ */
298 void tc_aout_fix_to_chars();
299 #endif /* not __STDC__ */
300
301 /*
302  * Local Variables:
303  * comment-column: 0
304  * fill-column: 131
305  * End:
306  */
307
308 /* end of obj-aout.h */