cc8761817a884f2f77eebff00332a5093f7b3fbf
[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 #ifndef GAS
21 #define GAS 1
22 /*
23 * I think this stuff is largely out of date. xoxorich.
24 *
25 * CAPITALISED names are #defined.
26 * "lowercaseH" is #defined if "lowercase.h" has been #include-d.
27 * "lowercaseT" is a typedef of "lowercase" objects.
28 * "lowercaseP" is type "pointer to object of type 'lowercase'".
29 * "lowercaseS" is typedef struct ... lowercaseS.
30 *
31 * #define DEBUG to enable all the "know" assertion tests.
32 * #define SUSPECT when debugging hash code.
33 * #define COMMON as "extern" for all modules except one, where you #define
34 * COMMON as "".
35 * If TEST is #defined, then we are testing a module: #define COMMON as "".
36 */
37
38 #include "config.h"
39
40 /* This is the code recommended in the autoconf documentation, almost
41 verbatim. If it doesn't work for you, let me know, and notify
42 djm@gnu.ai.mit.edu as well. */
43 /* Added #undef for DJ Delorie. The right fix is to ensure that as.h
44 is included first, before even any system header files, in all files
45 that use it. KR 1994.11.03 */
46
47 /* AIX requires this to be the first thing in the file. */
48 #ifdef __GNUC__
49 # undef alloca
50 # define alloca __builtin_alloca
51 #else
52 # if HAVE_ALLOCA_H
53 # include <alloca.h>
54 # else
55 # ifdef _AIX
56 #pragma alloca
57 # else
58 # ifndef alloca /* predefined by HP cc +Olibcalls */
59 char *alloca ();
60 # endif
61 # endif
62 # endif
63 #endif
64
65 /* Now, tend to the rest of the configuration. */
66
67 /* System include files first... */
68 #include <stdio.h>
69 #include <ctype.h>
70 #ifdef HAVE_STRING_H
71 #include <string.h>
72 #else
73 #include <strings.h>
74 #endif
75 #ifdef HAVE_STDLIB_H
76 #include <stdlib.h>
77 #endif
78 #ifdef HAVE_UNISTD_H
79 #include <unistd.h>
80 #endif
81 #ifdef HAVE_SYS_TYPES_H
82 /* for size_t, pid_t */
83 #include <sys/types.h>
84 #endif
85
86 /* Some systems do declare this, but this seems to be the universal
87 declaration, though the parameter type varies. (It ought to use
88 `const' but many systems prototype it without.) Include it here
89 for systems that don't declare it. If conflicts arise, just add
90 another autoconf test... */
91 extern char *strdup (/* const char * */);
92
93 #include <getopt.h>
94 /* The first getopt value for machine-independent long options.
95 150 isn't special; it's just an arbitrary non-ASCII char value. */
96 #define OPTION_STD_BASE 150
97 /* The first getopt value for machine-dependent long options.
98 170 gives the standard options room to grow. */
99 #define OPTION_MD_BASE 170
100
101 #ifdef DEBUG
102 #undef NDEBUG
103 #endif
104 #if !defined (__GNUC__) || __GNUC_MINOR__ <= 5
105 #define __PRETTY_FUNCTION__ ((char*)0)
106 #endif
107 #if 0
108 /* Handle lossage with assert.h. */
109 #ifndef BROKEN_ASSERT
110 #include <assert.h>
111 #else /* BROKEN_ASSERT */
112 #ifndef NDEBUG
113 #define assert(p) ((p) ? 0 : (as_assert (__FILE__, __LINE__, __PRETTY_FUNCTION__), 0))
114 #else
115 #define assert(p) ((p), 0)
116 #endif
117 #endif /* BROKEN_ASSERT */
118 #else
119 #define assert(P) ((P) ? 0 : (as_assert (__FILE__, __LINE__, __PRETTY_FUNCTION__), 0))
120 #endif
121
122
123 /* Now GNU header files... */
124 #include <ansidecl.h>
125 #ifdef BFD_ASSEMBLER
126 #include <bfd.h>
127 #endif
128
129 /* Define the standard progress macros. */
130 #include <progress.h>
131
132 /* This doesn't get taken care of anywhere. */
133 #if !defined (__GNUC__) && !defined (inline)
134 #define inline
135 #endif
136
137 /* Other stuff from config.h. */
138 #ifdef NEED_DECLARATION_MALLOC
139 extern PTR malloc ();
140 extern PTR realloc ();
141 #endif
142 #ifdef NEED_DECLARATION_FREE
143 extern void free ();
144 #endif
145 #ifdef NEED_DECLARATION_ERRNO
146 extern int errno;
147 #endif
148
149 /* This is needed for VMS. */
150 #if ! defined (HAVE_UNLINK) && defined (HAVE_REMOVE)
151 #define unlink remove
152 #endif
153
154 #ifdef BFD_ASSEMBLER
155 /* This one doesn't get declared, but we're using it anyways. This
156 should be fixed -- either it's part of the external interface or
157 it's not. */
158 extern PTR bfd_alloc_by_size_t PARAMS ((bfd *abfd, size_t sz));
159 #endif
160
161 /* Make Saber happier on obstack.h. */
162 #ifdef SABER
163 #undef __PTR_TO_INT
164 #define __PTR_TO_INT(P) ((int)(P))
165 #undef __INT_TO_PTR
166 #define __INT_TO_PTR(P) ((char *)(P))
167 #endif
168
169 #ifndef __LINE__
170 #define __LINE__ "unknown"
171 #endif /* __LINE__ */
172
173 #ifndef __FILE__
174 #define __FILE__ "unknown"
175 #endif /* __FILE__ */
176
177 #ifndef __STDC__
178 #ifndef const
179 #define const
180 #endif
181 #ifndef volatile
182 #define volatile
183 #endif
184 #endif /* ! __STDC__ */
185
186 #if !defined (__GNUC__) && !defined (inline)
187 #define inline
188 #endif
189
190 #ifndef FOPEN_WB
191 #ifdef GO32
192 #include "fopen-bin.h"
193 #else
194 #include "fopen-same.h"
195 #endif
196 #endif
197
198 #ifndef EXIT_SUCCESS
199 #define EXIT_SUCCESS 0
200 #define EXIT_FAILURE 1
201 #endif
202
203 #define obstack_chunk_alloc xmalloc
204 #define obstack_chunk_free xfree
205
206 #define xfree free
207
208 #define BAD_CASE(val) \
209 { \
210 as_fatal("Case value %ld unexpected at line %d of file \"%s\"\n", \
211 (long) val, __LINE__, __FILE__); \
212 }
213
214 /* Version 2.1 of Solaris had problems with this declaration, but I
215 think that bug has since been fixed. If it causes problems on your
216 system, just delete it. */
217 extern char *strstr ();
218 \f
219 #include "flonum.h"
220
221 /* These are assembler-wide concepts */
222
223 #ifdef BFD_ASSEMBLER
224 extern bfd *stdoutput;
225 typedef bfd_vma addressT;
226 typedef bfd_signed_vma offsetT;
227 #else
228 typedef unsigned long addressT;
229 typedef long offsetT;
230 #endif
231
232 /* Type of symbol value, etc. For use in prototypes. */
233 typedef addressT valueT;
234
235 #ifndef COMMON
236 #ifdef TEST
237 #define COMMON /* declare our COMMONs storage here. */
238 #else
239 #define COMMON extern /* our commons live elswhere */
240 #endif
241 #endif
242 /* COMMON now defined */
243
244 #ifdef DEBUG
245 #ifndef know
246 #define know(p) assert(p) /* Verify our assumptions! */
247 #endif /* not yet defined */
248 #else
249 #define know(p) /* know() checks are no-op.ed */
250 #endif
251 \f
252 /* input_scrub.c */
253
254 /*
255 * Supplies sanitised buffers to read.c.
256 * Also understands printing line-number part of error messages.
257 */
258 \f
259
260 /* subsegs.c Sub-segments. Also, segment(=expression type)s.*/
261
262 #ifndef BFD_ASSEMBLER
263
264 #ifdef MANY_SEGMENTS
265 #include "bfd.h"
266 #define N_SEGMENTS 10
267 #define SEG_NORMAL(x) ((x) >= SEG_E0 && (x) <= SEG_E9)
268 #define SEG_LIST SEG_E0,SEG_E1,SEG_E2,SEG_E3,SEG_E4,SEG_E5,SEG_E6,SEG_E7,SEG_E8,SEG_E9
269 #define SEG_TEXT SEG_E0
270 #define SEG_DATA SEG_E1
271 #define SEG_BSS SEG_E2
272 #else
273 #define N_SEGMENTS 3
274 #define SEG_NORMAL(x) ((x) == SEG_TEXT || (x) == SEG_DATA || (x) == SEG_BSS)
275 #define SEG_LIST SEG_TEXT,SEG_DATA,SEG_BSS
276 #endif
277
278 typedef enum _segT
279 {
280 SEG_ABSOLUTE = 0,
281 SEG_LIST,
282 SEG_UNKNOWN,
283 SEG_GOOF, /* Only happens if AS has a logic error. */
284 /* Invented so we don't crash printing */
285 /* error message involving weird segment. */
286 SEG_EXPR, /* Intermediate expression values. */
287 SEG_DEBUG, /* Debug segment */
288 SEG_NTV, /* Transfert vector preload segment */
289 SEG_PTV, /* Transfert vector postload segment */
290 SEG_REGISTER /* Mythical: a register-valued expression */
291 } segT;
292
293 #define SEG_MAXIMUM_ORDINAL (SEG_REGISTER)
294 #else
295 typedef asection *segT;
296 #define SEG_NORMAL(SEG) ((SEG) != absolute_section \
297 && (SEG) != undefined_section \
298 && (SEG) != reg_section \
299 && (SEG) != expr_section)
300 #endif
301 typedef int subsegT;
302
303 /* What subseg we are accreting now? */
304 COMMON subsegT now_subseg;
305
306 /* Segment our instructions emit to. */
307 COMMON segT now_seg;
308
309 #ifdef BFD_ASSEMBLER
310 #define segment_name(SEG) bfd_get_section_name (stdoutput, SEG)
311 #else
312 extern char *const seg_name[];
313 #define segment_name(SEG) seg_name[(int) (SEG)]
314 #endif
315
316 #ifndef BFD_ASSEMBLER
317 extern int section_alignment[];
318 #endif
319
320 #ifdef BFD_ASSEMBLER
321 extern segT reg_section, expr_section;
322 /* Shouldn't these be eliminated someday? */
323 extern segT text_section, data_section, bss_section;
324 #define absolute_section bfd_abs_section_ptr
325 #define undefined_section bfd_und_section_ptr
326 #else
327 #define reg_section SEG_REGISTER
328 #define expr_section SEG_EXPR
329 #define text_section SEG_TEXT
330 #define data_section SEG_DATA
331 #define bss_section SEG_BSS
332 #define absolute_section SEG_ABSOLUTE
333 #define undefined_section SEG_UNKNOWN
334 #endif
335
336 /* relax() */
337
338 enum _relax_state
339 {
340 /* Variable chars to be repeated fr_offset times.
341 Fr_symbol unused. Used with fr_offset == 0 for a
342 constant length frag. */
343 rs_fill = 1,
344
345 /* Align: Fr_offset: power of 2. Variable chars: fill pattern. */
346 rs_align,
347
348 /* Align code: fr_offset: power of 2. Fill pattern is machine
349 specific, defaulting to all zeros. */
350 rs_align_code,
351
352 /* Org: Fr_offset, fr_symbol: address. 1 variable char: fill
353 character. */
354 rs_org,
355
356 #ifndef WORKING_DOT_WORD
357 /* JF: gunpoint */
358 rs_broken_word,
359 #endif
360
361 /* machine-specific relaxable (or similarly alterable) instruction */
362 rs_machine_dependent,
363
364 /* .space directive with expression operand that needs to be computed
365 later. Similar to rs_org, but different.
366 fr_symbol: operand
367 1 variable char: fill character */
368 rs_space
369 };
370
371 typedef enum _relax_state relax_stateT;
372
373 /* This type is used in prototypes, so it can't be a type that will be
374 widened for argument passing. */
375 typedef unsigned int relax_substateT;
376
377 /* Enough bits for address, but still an integer type.
378 Could be a problem, cross-assembling for 64-bit machines. */
379 typedef addressT relax_addressT;
380 \f
381
382 /* frags.c */
383
384 /*
385 * A code fragment (frag) is some known number of chars, followed by some
386 * unknown number of chars. Typically the unknown number of chars is an
387 * instruction address whose size is yet unknown. We always know the greatest
388 * possible size the unknown number of chars may become, and reserve that
389 * much room at the end of the frag.
390 * Once created, frags do not change address during assembly.
391 * We chain the frags in (a) forward-linked list(s). The object-file address
392 * of the 1st char of a frag is generally not known until after relax().
393 * Many things at assembly time describe an address by {object-file-address
394 * of a particular frag}+offset.
395
396 BUG: it may be smarter to have a single pointer off to various different
397 notes for different frag kinds. See how code pans
398 */
399 struct frag
400 {
401 /* Object file address. */
402 addressT fr_address;
403 /* Chain forward; ascending address order. Rooted in frch_root. */
404 struct frag *fr_next;
405
406 /* (Fixed) number of chars we know we have. May be 0. */
407 offsetT fr_fix;
408 /* (Variable) number of chars after above. May be 0. */
409 offsetT fr_var;
410 /* For variable-length tail. */
411 struct symbol *fr_symbol;
412 /* For variable-length tail. */
413 offsetT fr_offset;
414 /* Points to opcode low addr byte, for relaxation. */
415 char *fr_opcode;
416
417 #ifndef NO_LISTING
418 struct list_info_struct *line;
419 #endif
420
421 /* What state is my tail in? */
422 relax_stateT fr_type;
423 relax_substateT fr_subtype;
424
425 /* Track the alignment and offset of the current frag. With this,
426 sometimes we can avoid creating new frags for .align directives. */
427 unsigned short align_mask;
428 unsigned short align_offset;
429
430 /* These are needed only on the NS32K machines. But since we don't
431 include targ-cpu.h until after this structure has been defined,
432 we can't really conditionalize it. This code should be
433 rearranged a bit to make that possible.
434
435 In the meantime, if we get stuck like this with any other target,
436 create a union here. */
437 char fr_pcrel_adjust, fr_bsr;
438
439 /* Data begins here. */
440 char fr_literal[1];
441 };
442
443 #define SIZEOF_STRUCT_FRAG \
444 ((char *)zero_address_frag.fr_literal-(char *)&zero_address_frag)
445 /* We want to say fr_literal[0] above. */
446
447 typedef struct frag fragS;
448
449 /* Current frag we are building. This frag is incomplete. It is, however,
450 included in frchain_now. The fr_fix field is bogus; instead, use:
451 obstack_next_free(&frags)-frag_now->fr_literal. */
452 COMMON fragS *frag_now;
453 extern int frag_now_fix ();
454
455 /* For foreign-segment symbol fixups. */
456 COMMON fragS zero_address_frag;
457 /* For local common (N_BSS segment) fixups. */
458 COMMON fragS bss_address_frag;
459
460 /* main program "as.c" (command arguments etc) */
461
462 COMMON unsigned char flag_no_comments; /* -f */
463 COMMON unsigned char flag_debug; /* -D */
464 COMMON unsigned char flag_signed_overflow_ok; /* -J */
465 COMMON unsigned char flag_warn_displacement; /* -K */
466
467 /* True if local symbols should be retained. */
468 COMMON unsigned char flag_keep_locals; /* -L */
469
470 /* Should the data section be made read-only and appended to the text
471 section? */
472 COMMON unsigned char flag_readonly_data_in_text; /* -R */
473
474 /* True if warnings should be inhibited. */
475 COMMON unsigned char flag_no_warnings; /* -W */
476
477 /* True if we should attempt to generate output even if non-fatal errors
478 are detected. */
479 COMMON unsigned char flag_always_generate_output; /* -Z */
480
481 /* This is true if the assembler should output time and space usage. */
482
483 COMMON unsigned char flag_print_statistics;
484
485 /* name of emitted object file */
486 COMMON char *out_file_name;
487
488 /* TRUE if we need a second pass. */
489 COMMON int need_pass_2;
490
491 /* TRUE if we should do no relaxing, and
492 leave lots of padding. */
493 COMMON int linkrelax;
494
495 /* TRUE if we should produce a listing. */
496 extern int listing;
497
498 struct _pseudo_type
499 {
500 /* assembler mnemonic, lower case, no '.' */
501 char *poc_name;
502 /* Do the work */
503 void (*poc_handler) PARAMS ((int));
504 /* Value to pass to handler */
505 int poc_val;
506 };
507
508 typedef struct _pseudo_type pseudo_typeS;
509
510 /* Prefer varargs for non-ANSI compiler, since some will barf if the
511 ellipsis definition is used with a no-arguments declaration. */
512 #if defined (HAVE_VARARGS_H) && !defined (__STDC__)
513 #undef HAVE_STDARG_H
514 #endif
515
516 #if defined (HAVE_STDARG_H)
517 #define USE_STDARG
518 #endif
519 #if !defined (USE_STDARG) && defined (HAVE_VARARGS_H)
520 #define USE_VARARGS
521 #endif
522
523 #ifdef USE_STDARG
524 #if __GNUC__ >= 2
525 /* for use with -Wformat */
526 #define PRINTF_LIKE(FCN) void FCN (const char *format, ...) \
527 __attribute__ ((format (printf, 1, 2)))
528 #define PRINTF_WHERE_LIKE(FCN) void FCN (char *file, unsigned int line, \
529 const char *format, ...) \
530 __attribute__ ((format (printf, 3, 4)))
531 #else /* ANSI C with stdarg, but not GNU C */
532 #define PRINTF_LIKE(FCN) void FCN PARAMS ((const char *format, ...))
533 #define PRINTF_WHERE_LIKE(FCN) void FCN PARAMS ((char *file, \
534 unsigned int line, \
535 const char *format, ...))
536 #endif
537 #else /* not using stdarg */
538 #define PRINTF_LIKE(FCN) void FCN ()
539 #define PRINTF_WHERE_LIKE(FCN) void FCN ()
540 #endif
541
542 PRINTF_LIKE (as_bad);
543 PRINTF_LIKE (as_fatal);
544 PRINTF_LIKE (as_tsktsk);
545 PRINTF_LIKE (as_warn);
546 PRINTF_WHERE_LIKE (as_bad_where);
547 PRINTF_WHERE_LIKE (as_warn_where);
548 void as_assert PARAMS ((const char *, int, const char *));
549
550 void fprint_value PARAMS ((FILE *file, addressT value));
551 void sprint_value PARAMS ((char *buf, addressT value));
552
553 int had_errors PARAMS ((void));
554 int had_warnings PARAMS ((void));
555
556 void print_version_id PARAMS ((void));
557 char *app_push PARAMS ((void));
558 char *atof_ieee PARAMS ((char *str, int what_kind, LITTLENUM_TYPE * words));
559 char *input_scrub_include_file PARAMS ((char *filename, char *position));
560 char *input_scrub_new_file PARAMS ((char *filename));
561 char *input_scrub_next_buffer PARAMS ((char **bufp));
562 PTR xmalloc PARAMS ((unsigned long size));
563 PTR xrealloc PARAMS ((PTR ptr, unsigned long n));
564 int do_scrub_next_char PARAMS ((int (*get) (void), void (*unget) (int)));
565 int gen_to_words PARAMS ((LITTLENUM_TYPE * words, int precision,
566 long exponent_bits));
567 int had_err PARAMS ((void));
568 int ignore_input PARAMS ((void));
569 int scrub_from_file PARAMS ((void));
570 int scrub_from_string PARAMS ((void));
571 int seen_at_least_1_file PARAMS ((void));
572 void app_pop PARAMS ((char *arg));
573 void as_howmuch PARAMS ((FILE * stream));
574 void as_perror PARAMS ((const char *gripe, const char *filename));
575 void as_where PARAMS ((char **namep, unsigned int *linep));
576 void bump_line_counters PARAMS ((void));
577 void do_scrub_begin PARAMS ((void));
578 void input_scrub_begin PARAMS ((void));
579 void input_scrub_close PARAMS ((void));
580 void input_scrub_end PARAMS ((void));
581 void new_logical_line PARAMS ((char *fname, int line_number));
582 void scrub_to_file PARAMS ((int ch));
583 void scrub_to_string PARAMS ((int ch));
584 void subsegs_begin PARAMS ((void));
585 void subseg_change PARAMS ((segT seg, int subseg));
586 segT subseg_new PARAMS ((const char *name, subsegT subseg));
587 segT subseg_force_new PARAMS ((const char *name, subsegT subseg));
588 void subseg_set PARAMS ((segT seg, subsegT subseg));
589 #ifdef BFD_ASSEMBLER
590 segT subseg_get PARAMS ((const char *, int));
591 #endif
592
593 struct expressionS;
594 struct fix;
595 struct symbol;
596
597 #ifdef BFD_ASSEMBLER
598 /* literal.c */
599 valueT add_to_literal_pool PARAMS ((struct symbol *, valueT, segT, int));
600 #endif
601
602 #include "expr.h" /* Before targ-*.h */
603
604 /* this one starts the chain of target dependant headers */
605 #include "targ-env.h"
606
607 #include "struc-symbol.h"
608 #include "write.h"
609 #include "frags.h"
610 #include "hash.h"
611 #include "read.h"
612 #include "symbols.h"
613
614 #include "tc.h"
615 #include "obj.h"
616
617 #include "listing.h"
618
619 #ifdef BFD_ASSEMBLER
620 /* Someday perhaps this will be selectable at run-time. */
621 #if defined (OBJ_AOUT) || defined (OBJ_BOUT)
622 #define OUTPUT_FLAVOR bfd_target_aout_flavour
623 #endif
624 #ifdef OBJ_COFF
625 #define OUTPUT_FLAVOR bfd_target_coff_flavour
626 #endif
627 #ifdef OBJ_ECOFF
628 #define OUTPUT_FLAVOR bfd_target_ecoff_flavour
629 #endif
630 #ifdef OBJ_ELF
631 #define OUTPUT_FLAVOR bfd_target_elf_flavour
632 #endif
633 #endif /* BFD_ASSEMBLER */
634
635 #endif /* GAS */
636
637 /* end of as.h */