1 /* obj-aout.h, a.out object file format for gas, the assembler.
2 Copyright (C) 1989, 1990, 1991, 1992 Free Software Foundation, Inc.
4 This file is part of GAS, the GNU Assembler.
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.
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.
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.
24 /* Tag to validate a.out object file format processing */
29 #include "aout.h" /* Needed to define struct nlist. Sigh. */
32 #define AOUT_MACHTYPE 0
36 #define AOUT_VERSION 0
43 extern const short seg_N_TYPE[];
44 extern const segT N_TYPE_seg[];
45 #define N_REGISTER 0x12 /* Fake register type */
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 */
51 /* First character of operand in `.type' directives */
52 #define TYPE_OPERAND_FMT '@'
55 /* Symbol table entry data type */
57 typedef struct nlist obj_symbol_type; /* Symbol table entry */
59 /* Symbol table macros and constants */
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.
67 /* True if the symbol is external */
68 #define S_IS_EXTERNAL(s) ((s)->sy_symbol.n_type & N_EXT)
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))
73 #define S_IS_REGISTER(s) ((s)->sy_symbol.n_type == N_REGISTER)
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) && \
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)
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)
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 */
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))
124 /* File header macro and type definition */
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))
134 #ifndef H_GET_HEADER_SIZE
135 #define H_GET_HEADER_SIZE(h) (sizeof(struct exec))
136 #endif /* not H_GET_HEADER_SIZE */
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)
148 #if defined(FREEBSD_AOUT) || defined(NETBSD_AOUT)
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 ) \
157 #define H_GET_MACHTYPE(h) \
158 ( (((h)->header.a_info)&0xffff) \
159 ? ((h)->header.a_info >>16 ) & 0x3ff) \
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) \
169 #define H_SET_INFO(h,mag,mid,f,v) \
170 ( (h)->header.a_info = \
171 (((f)&0x3f)<<26) | (((mid)&0x03ff)<<16) | (((mag)&0xffff)) )
173 #endif /* FREEBSD_AOUT */
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) \
183 #define H_GET_MACHTYPE(h) \
184 ( (((h)->header.a_info)&0xffff0000) \
185 ? ((ntohl(((h)->header.a_info))>>16)&0x3ff) \
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) \
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)) ) )
199 #endif /* NETBSD_AOUT */
201 #define EX_DYNAMIC 0x20
204 #define AOUT_FLAGS (picmode ? EX_PIC : 0)
206 #define H_GET_DYNAMIC(h) (H_GET_FLAGS(h) & EX_DYNAMIC)
208 #define H_GET_VERSION(h) (0)
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)
214 #define H_SET_VERSION(h,v)
216 #define H_SET_MACHTYPE(h,v) \
217 H_SET_INFO(h, H_GET_MAGIC_NUMBER(h), (v), H_GET_FLAGS(h), 0)
219 #define H_SET_MAGIC_NUMBER(h,v) \
220 H_SET_INFO(h, (v), H_GET_MACHTYPE(h), H_GET_FLAGS(h), 0)
222 #else /* !(FREEBSD_AOUT || NETBSD_AOUT) */
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)
229 #define H_SET_DYNAMIC(h,v) ((h)->header.a_info = \
231 | (H_GET_VERSION(h) << 24) \
232 | (H_GET_MACHTYPE(h) << 16) \
233 | (H_GET_MAGIC_NUMBER(h))))
235 #define H_SET_VERSION(h,v) ((h)->header.a_info = \
236 ((H_GET_DYNAMIC(h) << 31) \
238 | (H_GET_MACHTYPE(h) << 16) \
239 | (H_GET_MAGIC_NUMBER(h))))
241 #define H_SET_MACHTYPE(h,v) ((h)->header.a_info = \
242 ((H_GET_DYNAMIC(h) << 31) \
243 | (H_GET_VERSION(h) << 24) \
245 | (H_GET_MAGIC_NUMBER(h))))
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) \
252 #define H_SET_INFO(h,mag,mid,f,v) ((h)->header.a_info = \
253 ((((f)==0x20) << 31) \
257 #endif /* FREEBSD_AOUT || NETBSD_AOUT */
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)))
263 #define H_SET_RELOCATION_SIZE(h,t,d) (H_SET_TEXT_RELOCATION_SIZE((h),(t)),\
264 H_SET_DATA_RELOCATION_SIZE((h),(d)))
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))
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))
275 * Current means for getting the name of a segment.
276 * This will change for infinite-segments support (e.g. COFF).
278 #define segment_name(seg) (seg_name[(int)(seg)])
279 extern char *const seg_name[];
282 struct exec header; /* a.out header */
283 long string_table_size; /* names + '\0' + sizeof(int) */
286 /* line numbering stuff. */
287 #define OBJ_EMIT_LINENO(a, b, c) {;}
289 #define obj_symbol_new_hook(s) {;}
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__ */
305 /* end of obj-aout.h */