6b797ab029ba78893844f00b16af9ba09047cc2a
[binutils-gdb.git] / gas / as.h
1 /* as.h - global header file
2 Copyright (C) 1987, 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 published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
10
11 GAS is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with GAS; see the file COPYING. If not, write to
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
19
20 #define GAS 1
21 /*
22 * I think this stuff is largely out of date. xoxorich.
23 *
24 * CAPITALISED names are #defined.
25 * "lowercaseH" is #defined if "lowercase.h" has been #include-d.
26 * "lowercaseT" is a typedef of "lowercase" objects.
27 * "lowercaseP" is type "pointer to object of type 'lowercase'".
28 * "lowercaseS" is typedef struct ... lowercaseS.
29 *
30 * #define DEBUG to enable all the "know" assertion tests.
31 * #define SUSPECT when debugging hash code.
32 * #define COMMON as "extern" for all modules except one, where you #define
33 * COMMON as "".
34 * If TEST is #defined, then we are testing a module: #define COMMON as "".
35 */
36
37 /* These #defines are for parameters of entire assembler. */
38
39 #define DEBUG /* temporary */
40 /* These #includes are for type definitions etc. */
41
42 #include <stdio.h>
43 #ifdef DEBUG
44 #undef NDEBUG
45 #endif
46 #include <assert.h>
47
48 #include <ansidecl.h>
49 #ifdef BFD_ASSEMBLER
50 #include <bfd.h>
51 #endif
52 #include "host.h"
53 #include "flonum.h"
54
55 #ifndef __LINE__
56 #define __LINE__ "unknown"
57 #endif /* __LINE__ */
58
59 #ifndef __FILE__
60 #define __FILE__ "unknown"
61 #endif /* __FILE__ */
62
63 #define obstack_chunk_alloc xmalloc
64 #define obstack_chunk_free xfree
65
66 #define xfree free
67
68 #define BAD_CASE(value) \
69 { \
70 as_fatal("Case value %d unexpected at line %d of file \"%s\"\n", \
71 value, __LINE__, __FILE__); \
72 }
73 \f
74
75 /* These are assembler-wide concepts */
76
77 #ifdef BFD_ASSEMBLER
78 extern bfd *stdoutput;
79 #endif
80
81 #ifndef COMMON
82 #ifdef TEST
83 #define COMMON /* declare our COMMONs storage here. */
84 #else
85 #define COMMON extern /* our commons live elswhere */
86 #endif
87 #endif
88 /* COMMON now defined */
89
90 #ifdef DEBUG
91 #ifndef know
92 #define know(p) assert(p) /* Verify our assumptions! */
93 #endif /* not yet defined */
94 #else
95 #define know(p) /* know() checks are no-op.ed */
96 #endif
97
98 #if defined (BROKEN_ASSERT) && !defined (NDEBUG)
99 /* Used on machines where the "assert" macro is buggy. (For example, on the
100 RS/6000, Reiser-cpp substitution is done to put the condition into a
101 string, so if the condition contains a string, parse errors result.) If
102 the condition fails, just drop core file. */
103 #undef assert
104 #define assert(p) ((p) ? 0 : (abort (), 0))
105 #endif
106 \f
107 /* input_scrub.c */
108
109 /*
110 * Supplies sanitised buffers to read.c.
111 * Also understands printing line-number part of error messages.
112 */
113 \f
114
115 /* subsegs.c Sub-segments. Also, segment(=expression type)s.*/
116
117 #ifndef BFD_ASSEMBLER
118 /*
119 * This table describes the use of segments as EXPRESSION types.
120 *
121 * X_seg X_add_symbol X_subtract_symbol X_add_number
122 * SEG_ABSENT no (legal) expression
123 * SEG_PASS1 no (defined) "
124 * SEG_BIG * > 32 bits const.
125 * SEG_ABSOLUTE 0
126 * SEG_DATA * 0
127 * SEG_TEXT * 0
128 * SEG_BSS * 0
129 * SEG_UNKNOWN * 0
130 * SEG_DIFFERENCE 0 * 0
131 * SEG_REGISTER *
132 *
133 * The blank fields MUST be 0, and are nugatory.
134 * The '0' fields MAY be 0. The '*' fields MAY NOT be 0.
135 *
136 * SEG_BIG: X_add_number is < 0 if the result is in
137 * generic_floating_point_number. The value is -'c' where c is the
138 * character that introduced the constant. e.g. "0f6.9" will have -'f'
139 * as a X_add_number value.
140 * X_add_number > 0 is a count of how many littlenums it took to
141 * represent a bignum.
142 * SEG_DIFFERENCE:
143 * If segments of both symbols are known, they are the same segment.
144 * X_add_symbol != X_sub_symbol (then we just cancel them, => SEG_ABSOLUTE).
145 */
146
147
148 #ifdef MANY_SEGMENTS
149 #include "bfd.h"
150 #define N_SEGMENTS 10
151 #define SEG_NORMAL(x) ((x) >= SEG_E0 && (x) <= SEG_E9)
152 #define SEG_LIST SEG_E0,SEG_E1,SEG_E2,SEG_E3,SEG_E4,SEG_E5,SEG_E6,SEG_E7,SEG_E8,SEG_E9
153 #define SEG_TEXT SEG_E0
154 #define SEG_DATA SEG_E1
155 #define SEG_BSS SEG_E2
156 #else
157 #define N_SEGMENTS 3
158 #define SEG_NORMAL(x) ((x) == SEG_TEXT || (x) == SEG_DATA || (x) == SEG_BSS)
159 #define SEG_LIST SEG_TEXT,SEG_DATA,SEG_BSS
160 #endif
161
162 typedef enum _segT
163 {
164 SEG_ABSOLUTE = 0,
165 SEG_LIST,
166 SEG_UNKNOWN,
167 SEG_ABSENT, /* Mythical Segment (absent): NO expression seen. */
168 SEG_PASS1, /* Mythical Segment: Need another pass. */
169 SEG_GOOF, /* Only happens if AS has a logic error. */
170 /* Invented so we don't crash printing */
171 /* error message involving weird segment. */
172 SEG_BIG, /* Bigger than 32 bits constant. */
173 SEG_DIFFERENCE, /* Mythical Segment: absolute difference. */
174 SEG_DEBUG, /* Debug segment */
175 SEG_NTV, /* Transfert vector preload segment */
176 SEG_PTV, /* Transfert vector postload segment */
177 SEG_REGISTER, /* Mythical: a register-valued expression */
178 } segT;
179
180 #define SEG_MAXIMUM_ORDINAL (SEG_REGISTER)
181 #else
182 typedef asection *segT;
183 #define SEG_NORMAL(SEG) ((SEG) != absolute_section \
184 && (SEG) != undefined_section \
185 && (SEG) != big_section \
186 && (SEG) != reg_section \
187 && (SEG) != pass1_section \
188 && (SEG) != diff_section \
189 && (SEG) != absent_section)
190 #endif
191 typedef int subsegT;
192
193 /* What subseg we are accreting now? */
194 COMMON subsegT now_subseg;
195
196 /* Segment our instructions emit to. */
197 COMMON segT now_seg;
198
199 #ifdef BFD_ASSEMBLER
200 #define segment_name(SEG) bfd_get_section_name (stdoutput, SEG)
201 #else
202 extern char *CONST seg_name[];
203 #define segment_name(SEG) seg_name[(int) (SEG)]
204 #endif
205
206 #ifndef BFD_ASSEMBLER
207 extern int section_alignment[];
208 #endif
209
210 #ifdef BFD_ASSEMBLER
211 extern segT big_section, reg_section, pass1_section;
212 extern segT diff_section, absent_section;
213 /* Shouldn't these be eliminated someday? */
214 extern segT text_section, data_section, bss_section;
215 #define absolute_section (&bfd_abs_section)
216 #define undefined_section (&bfd_und_section)
217 #else
218 #define big_section SEG_BIG
219 #define reg_section SEG_REGISTER
220 #define pass1_section SEG_PASS1
221 #define diff_section SEG_DIFFERENCE
222 #define absent_section SEG_ABSENT
223 #define text_section SEG_TEXT
224 #define data_section SEG_DATA
225 #define bss_section SEG_BSS
226 #define absolute_section SEG_ABSOLUTE
227 #define undefined_section SEG_UNKNOWN
228 #endif
229
230 /* relax() */
231
232 typedef enum _relax_state
233 {
234 /* Variable chars to be repeated fr_offset times.
235 Fr_symbol unused. Used with fr_offset == 0 for a
236 constant length frag. */
237 rs_fill = 1,
238
239 /* Align: Fr_offset: power of 2. 1 variable char: fill character. */
240 rs_align,
241
242 /* Org: Fr_offset, fr_symbol: address. 1 variable char: fill
243 character. */
244 rs_org,
245
246 rs_machine_dependent,
247
248 #ifndef WORKING_DOT_WORD
249 /* JF: gunpoint */
250 rs_broken_word,
251 #endif
252 } relax_stateT;
253
254 /* typedef unsigned char relax_substateT; */
255 /* JF this is more likely to leave the end of a struct frag on an align
256 boundry. Be very careful with this. */
257 typedef unsigned long relax_substateT;
258
259 /* Enough bits for address, but still an integer type.
260 Could be a problem, cross-assembling for 64-bit machines. */
261 typedef unsigned long relax_addressT;
262 \f
263
264 /* frags.c */
265
266 /*
267 * A code fragment (frag) is some known number of chars, followed by some
268 * unknown number of chars. Typically the unknown number of chars is an
269 * instruction address whose size is yet unknown. We always know the greatest
270 * possible size the unknown number of chars may become, and reserve that
271 * much room at the end of the frag.
272 * Once created, frags do not change address during assembly.
273 * We chain the frags in (a) forward-linked list(s). The object-file address
274 * of the 1st char of a frag is generally not known until after relax().
275 * Many things at assembly time describe an address by {object-file-address
276 * of a particular frag}+offset.
277
278 BUG: it may be smarter to have a single pointer off to various different
279 notes for different frag kinds. See how code pans
280 */
281 struct frag
282 {
283 /* Object file address. */
284 unsigned long fr_address;
285 /* Chain forward; ascending address order. Rooted in frch_root. */
286 struct frag *fr_next;
287
288 /* (Fixed) number of chars we know we have. May be 0. */
289 long fr_fix;
290 /* (Variable) number of chars after above. May be 0. */
291 long fr_var;
292 /* For variable-length tail. */
293 struct symbol *fr_symbol;
294 /* For variable-length tail. */
295 long fr_offset;
296 /* Points to opcode low addr byte, for relaxation. */
297 char *fr_opcode;
298
299 #ifndef NO_LISTING
300 struct list_info_struct *line;
301 #endif
302
303 /* What state is my tail in? */
304 relax_stateT fr_type;
305 relax_substateT fr_subtype;
306
307 /* These are needed only on the NS32K machines */
308 char fr_pcrel_adjust;
309 char fr_bsr;
310
311 /* Chars begin here.
312 One day we will compile fr_literal[0]. */
313 char fr_literal[1];
314 };
315
316 #define SIZEOF_STRUCT_FRAG \
317 ((int)zero_address_frag.fr_literal-(int)&zero_address_frag)
318 /* We want to say fr_literal[0] above. */
319
320 typedef struct frag fragS;
321
322 /* Current frag we are building. This frag is incomplete. It is, however,
323 included in frchain_now. The fr_fix field is bogus; instead, use:
324 obstack_next_free(&frags)-frag_now->fr_literal. */
325 COMMON fragS *frag_now;
326 #define frag_now_fix() (obstack_next_free (&frags) - frag_now->fr_literal)
327
328 /* For foreign-segment symbol fixups. */
329 COMMON fragS zero_address_frag;
330 /* For local common (N_BSS segment) fixups. */
331 COMMON fragS bss_address_frag;
332
333 /* main program "as.c" (command arguments etc) */
334
335 /* ['x'] TRUE if "-x" seen. */
336 COMMON char flagseen[128];
337 COMMON unsigned char flag_readonly_data_in_text;
338 COMMON unsigned char flag_suppress_warnings;
339 COMMON unsigned char flag_always_generate_output;
340
341 /* name of emitted object file */
342 COMMON char *out_file_name;
343
344 /* TRUE if we need a second pass. */
345 COMMON int need_pass_2;
346
347 /* TRUE if we should do no relaxing, and
348 leave lots of padding. */
349 COMMON int linkrelax;
350
351 struct _pseudo_type
352 {
353 /* assembler mnemonic, lower case, no '.' */
354 char *poc_name;
355 /* Do the work */
356 void (*poc_handler) ();
357 /* Value to pass to handler */
358 int poc_val;
359 };
360
361 typedef struct _pseudo_type pseudo_typeS;
362
363 #ifdef BFD_ASSEMBLER_xxx
364 struct lineno_struct
365 {
366 alent line;
367 fragS *frag;
368 struct lineno_struct *next;
369 };
370 typedef struct lineno_struct lineno;
371 #endif
372
373 #if defined (__STDC__) && !defined(NO_STDARG)
374
375 #if __GNUC__ >= 2
376 /* for use with -Wformat */
377 #define PRINTF_LIKE(FCN) void FCN (const char *Format, ...) \
378 __attribute__ ((format (printf, 1, 2)))
379 #else /* ANSI C with stdarg, but not GNU C */
380 #define PRINTF_LIKE(FCN) void FCN (const char *Format, ...)
381 #endif
382 #else /* not ANSI C, or not stdarg */
383 #define PRINTF_LIKE(FCN) void FCN ()
384 #endif
385
386 PRINTF_LIKE (as_bad);
387 PRINTF_LIKE (as_fatal);
388 PRINTF_LIKE (as_tsktsk);
389 PRINTF_LIKE (as_warn);
390
391 int had_errors PARAMS ((void));
392 int had_warnings PARAMS ((void));
393
394 char *app_push PARAMS ((void));
395 char *atof_ieee PARAMS ((char *str, int what_kind, LITTLENUM_TYPE * words));
396 char *input_scrub_include_file PARAMS ((char *filename, char *position));
397 char *input_scrub_new_file PARAMS ((char *filename));
398 char *input_scrub_next_buffer PARAMS ((char **bufp));
399 char *strstr PARAMS ((const char *s, const char *wanted));
400 char *xmalloc PARAMS ((long size));
401 char *xrealloc PARAMS ((char *ptr, long n));
402 int do_scrub_next_char PARAMS ((int (*get) (), void (*unget) ()));
403 int gen_to_words PARAMS ((LITTLENUM_TYPE * words, int precision,
404 long exponent_bits));
405 int had_err PARAMS ((void));
406 int had_errors PARAMS ((void));
407 int had_warnings PARAMS ((void));
408 int ignore_input PARAMS ((void));
409 int scrub_from_file PARAMS ((void));
410 int scrub_from_file PARAMS ((void));
411 int scrub_from_string PARAMS ((void));
412 int seen_at_least_1_file PARAMS ((void));
413 void app_pop PARAMS ((char *arg));
414 void as_howmuch PARAMS ((FILE * stream));
415 void as_perror PARAMS ((char *gripe, char *filename));
416 void as_where PARAMS ((void));
417 void bump_line_counters PARAMS ((void));
418 void do_scrub_begin PARAMS ((void));
419 void input_scrub_begin PARAMS ((void));
420 void input_scrub_close PARAMS ((void));
421 void input_scrub_end PARAMS ((void));
422 void int_to_gen PARAMS ((long x));
423 void new_logical_line PARAMS ((char *fname, int line_number));
424 void scrub_to_file PARAMS ((int ch));
425 void scrub_to_string PARAMS ((int ch));
426 void subsegs_begin PARAMS ((void));
427 void subseg_change PARAMS ((segT seg, int subseg));
428 #ifdef BFD_ASSEMBLER
429 segT subseg_new PARAMS ((char *name, subsegT subseg));
430 void subseg_set PARAMS ((segT seg, subsegT subseg));
431 #else
432 void subseg_new PARAMS ((segT seg, subsegT subseg));
433 #endif
434
435 /* this one starts the chain of target dependant headers */
436 #include "targ-env.h"
437
438 /* these define types needed by the interfaces */
439 #include "struc-symbol.h"
440
441 #include "write.h"
442 #include "expr.h"
443 #include "frags.h"
444 #include "hash.h"
445 #include "read.h"
446 #include "symbols.h"
447
448 #include "tc.h"
449 #include "obj.h"
450
451 #include "listing.h"
452
453 /* end of as.h */