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