1 /* as.h - global header file
2 Copyright (C) 1987, 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 published by
8 the Free Software Foundation; either version 2, or (at your option)
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.
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. */
23 * I think this stuff is largely out of date. xoxorich.
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.
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
35 * If TEST is #defined, then we are testing a module: #define COMMON as "".
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 */
47 /* AIX requires this to be the first thing in the file. */
50 # define alloca __builtin_alloca
58 # ifndef alloca /* predefined by HP cc +Olibcalls */
65 /* Now, tend to the rest of the configuration. */
67 /* System include files first... */
81 #ifdef HAVE_SYS_TYPES_H
82 /* for size_t, pid_t */
83 #include <sys/types.h>
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 * */);
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
104 /* Handle lossage with assert.h. */
105 #ifndef BROKEN_ASSERT
107 #else /* BROKEN_ASSERT */
109 #define assert(p) ((p) ? 0 : (abort(), 0))
111 #define assert(p) ((p), 0)
113 #endif /* BROKEN_ASSERT */
116 /* Now GNU header files... */
117 #include <ansidecl.h>
122 /* Define the standard progress macros. */
123 #include <progress.h>
125 /* This doesn't get taken care of anywhere. */
126 #if !defined (__GNUC__) && !defined (inline)
130 /* Other stuff from config.h. */
131 #ifdef NEED_DECLARATION_MALLOC
132 extern PTR malloc ();
133 extern PTR realloc ();
135 #ifdef NEED_DECLARATION_FREE
138 #ifdef NEED_DECLARATION_ERRNO
142 /* This is needed for VMS. */
143 #if ! defined (HAVE_UNLINK) && defined (HAVE_REMOVE)
144 #define unlink remove
148 /* This one doesn't get declared, but we're using it anyways. This
149 should be fixed -- either it's part of the external interface or
151 extern PTR bfd_alloc_by_size_t PARAMS ((bfd *abfd, size_t sz));
154 /* Make Saber happier on obstack.h. */
157 #define __PTR_TO_INT(P) ((int)(P))
159 #define __INT_TO_PTR(P) ((char *)(P))
163 #define __LINE__ "unknown"
164 #endif /* __LINE__ */
167 #define __FILE__ "unknown"
168 #endif /* __FILE__ */
177 #endif /* ! __STDC__ */
179 #if !defined (__GNUC__) && !defined (inline)
185 #include "fopen-bin.h"
187 #include "fopen-same.h"
192 #define EXIT_SUCCESS 0
193 #define EXIT_FAILURE 1
196 #define obstack_chunk_alloc xmalloc
197 #define obstack_chunk_free xfree
201 #define BAD_CASE(val) \
203 as_fatal("Case value %ld unexpected at line %d of file \"%s\"\n", \
204 (long) val, __LINE__, __FILE__); \
207 /* Version 2.1 of Solaris had problems with this declaration, but I
208 think that bug has since been fixed. If it causes problems on your
209 system, just delete it. */
210 extern char *strstr ();
214 /* These are assembler-wide concepts */
217 extern bfd *stdoutput;
218 typedef bfd_vma addressT;
219 typedef bfd_signed_vma offsetT;
221 typedef unsigned long addressT;
222 typedef long offsetT;
225 /* Type of symbol value, etc. For use in prototypes. */
226 typedef addressT valueT;
230 #define COMMON /* declare our COMMONs storage here. */
232 #define COMMON extern /* our commons live elswhere */
235 /* COMMON now defined */
239 #define know(p) assert(p) /* Verify our assumptions! */
240 #endif /* not yet defined */
242 #define know(p) /* know() checks are no-op.ed */
248 * Supplies sanitised buffers to read.c.
249 * Also understands printing line-number part of error messages.
253 /* subsegs.c Sub-segments. Also, segment(=expression type)s.*/
255 #ifndef BFD_ASSEMBLER
259 #define N_SEGMENTS 10
260 #define SEG_NORMAL(x) ((x) >= SEG_E0 && (x) <= SEG_E9)
261 #define SEG_LIST SEG_E0,SEG_E1,SEG_E2,SEG_E3,SEG_E4,SEG_E5,SEG_E6,SEG_E7,SEG_E8,SEG_E9
262 #define SEG_TEXT SEG_E0
263 #define SEG_DATA SEG_E1
264 #define SEG_BSS SEG_E2
267 #define SEG_NORMAL(x) ((x) == SEG_TEXT || (x) == SEG_DATA || (x) == SEG_BSS)
268 #define SEG_LIST SEG_TEXT,SEG_DATA,SEG_BSS
276 SEG_GOOF, /* Only happens if AS has a logic error. */
277 /* Invented so we don't crash printing */
278 /* error message involving weird segment. */
279 SEG_EXPR, /* Intermediate expression values. */
280 SEG_DEBUG, /* Debug segment */
281 SEG_NTV, /* Transfert vector preload segment */
282 SEG_PTV, /* Transfert vector postload segment */
283 SEG_REGISTER /* Mythical: a register-valued expression */
286 #define SEG_MAXIMUM_ORDINAL (SEG_REGISTER)
288 typedef asection *segT;
289 #define SEG_NORMAL(SEG) ((SEG) != absolute_section \
290 && (SEG) != undefined_section \
291 && (SEG) != reg_section \
292 && (SEG) != expr_section)
296 /* What subseg we are accreting now? */
297 COMMON subsegT now_subseg;
299 /* Segment our instructions emit to. */
303 #define segment_name(SEG) bfd_get_section_name (stdoutput, SEG)
305 extern char *const seg_name[];
306 #define segment_name(SEG) seg_name[(int) (SEG)]
309 #ifndef BFD_ASSEMBLER
310 extern int section_alignment[];
314 extern segT reg_section, expr_section;
315 /* Shouldn't these be eliminated someday? */
316 extern segT text_section, data_section, bss_section;
317 #define absolute_section bfd_abs_section_ptr
318 #define undefined_section bfd_und_section_ptr
320 #define reg_section SEG_REGISTER
321 #define expr_section SEG_EXPR
322 #define text_section SEG_TEXT
323 #define data_section SEG_DATA
324 #define bss_section SEG_BSS
325 #define absolute_section SEG_ABSOLUTE
326 #define undefined_section SEG_UNKNOWN
331 typedef enum _relax_state
333 /* Variable chars to be repeated fr_offset times.
334 Fr_symbol unused. Used with fr_offset == 0 for a
335 constant length frag. */
338 /* Align: Fr_offset: power of 2. Variable chars: fill pattern. */
341 /* Org: Fr_offset, fr_symbol: address. 1 variable char: fill
347 #ifndef WORKING_DOT_WORD
353 /* typedef unsigned char relax_substateT; */
354 /* JF this is more likely to leave the end of a struct frag on an align
355 boundry. Be very careful with this. */
356 typedef unsigned long relax_substateT;
358 /* Enough bits for address, but still an integer type.
359 Could be a problem, cross-assembling for 64-bit machines. */
360 typedef addressT relax_addressT;
366 * A code fragment (frag) is some known number of chars, followed by some
367 * unknown number of chars. Typically the unknown number of chars is an
368 * instruction address whose size is yet unknown. We always know the greatest
369 * possible size the unknown number of chars may become, and reserve that
370 * much room at the end of the frag.
371 * Once created, frags do not change address during assembly.
372 * We chain the frags in (a) forward-linked list(s). The object-file address
373 * of the 1st char of a frag is generally not known until after relax().
374 * Many things at assembly time describe an address by {object-file-address
375 * of a particular frag}+offset.
377 BUG: it may be smarter to have a single pointer off to various different
378 notes for different frag kinds. See how code pans
382 /* Object file address. */
384 /* Chain forward; ascending address order. Rooted in frch_root. */
385 struct frag *fr_next;
387 /* (Fixed) number of chars we know we have. May be 0. */
389 /* (Variable) number of chars after above. May be 0. */
391 /* For variable-length tail. */
392 struct symbol *fr_symbol;
393 /* For variable-length tail. */
395 /* Points to opcode low addr byte, for relaxation. */
399 struct list_info_struct *line;
402 /* What state is my tail in? */
403 relax_stateT fr_type;
404 relax_substateT fr_subtype;
406 /* Track the alignment and offset of the current frag. With this,
407 sometimes we can avoid creating new frags for .align directives. */
408 unsigned short align_mask;
409 unsigned short align_offset;
411 /* These are needed only on the NS32K machines. But since we don't
412 include targ-cpu.h until after this structure has been defined,
413 we can't really conditionalize it. This code should be
414 rearranged a bit to make that possible.
416 In the meantime, if we get stuck like this with any other target,
417 create a union here. */
418 char fr_pcrel_adjust, fr_bsr;
420 /* Data begins here. */
424 #define SIZEOF_STRUCT_FRAG \
425 ((char *)zero_address_frag.fr_literal-(char *)&zero_address_frag)
426 /* We want to say fr_literal[0] above. */
428 typedef struct frag fragS;
430 /* Current frag we are building. This frag is incomplete. It is, however,
431 included in frchain_now. The fr_fix field is bogus; instead, use:
432 obstack_next_free(&frags)-frag_now->fr_literal. */
433 COMMON fragS *frag_now;
434 extern int frag_now_fix ();
436 /* For foreign-segment symbol fixups. */
437 COMMON fragS zero_address_frag;
438 /* For local common (N_BSS segment) fixups. */
439 COMMON fragS bss_address_frag;
441 /* main program "as.c" (command arguments etc) */
443 COMMON unsigned char flag_no_comments; /* -f */
444 COMMON unsigned char flag_debug; /* -D */
445 COMMON unsigned char flag_signed_overflow_ok; /* -J */
446 COMMON unsigned char flag_warn_displacement; /* -K */
448 /* True if local symbols should be retained. */
449 COMMON unsigned char flag_keep_locals; /* -L */
451 /* Should the data section be made read-only and appended to the text
453 COMMON unsigned char flag_readonly_data_in_text; /* -R */
455 /* True if warnings should be inhibited. */
456 COMMON unsigned char flag_no_warnings; /* -W */
458 /* True if we should attempt to generate output even if non-fatal errors
460 COMMON unsigned char flag_always_generate_output; /* -Z */
462 /* This is true if the assembler should output time and space usage. */
464 COMMON unsigned char flag_print_statistics;
466 /* name of emitted object file */
467 COMMON char *out_file_name;
469 /* TRUE if we need a second pass. */
470 COMMON int need_pass_2;
472 /* TRUE if we should do no relaxing, and
473 leave lots of padding. */
474 COMMON int linkrelax;
476 /* TRUE if we should produce a listing. */
481 /* assembler mnemonic, lower case, no '.' */
484 void (*poc_handler) PARAMS ((int));
485 /* Value to pass to handler */
489 typedef struct _pseudo_type pseudo_typeS;
491 #ifdef BFD_ASSEMBLER_xxx
496 struct lineno_struct *next;
498 typedef struct lineno_struct lineno;
501 /* Prefer varargs for non-ANSI compiler, since some will barf if the
502 ellipsis definition is used with a no-arguments declaration. */
503 #if defined (HAVE_VARARGS_H) && !defined (__STDC__)
507 #if defined (HAVE_STDARG_H)
510 #if !defined (USE_STDARG) && defined (HAVE_VARARGS_H)
516 /* for use with -Wformat */
517 #define PRINTF_LIKE(FCN) void FCN (const char *format, ...) \
518 __attribute__ ((format (printf, 1, 2)))
519 #define PRINTF_WHERE_LIKE(FCN) void FCN (char *file, unsigned int line, \
520 const char *format, ...) \
521 __attribute__ ((format (printf, 3, 4)))
522 #else /* ANSI C with stdarg, but not GNU C */
523 #define PRINTF_LIKE(FCN) void FCN PARAMS ((const char *format, ...))
524 #define PRINTF_WHERE_LIKE(FCN) void FCN PARAMS ((char *file, \
526 const char *format, ...))
528 #else /* not using stdarg */
529 #define PRINTF_LIKE(FCN) void FCN ()
530 #define PRINTF_WHERE_LIKE(FCN) void FCN ()
533 PRINTF_LIKE (as_bad);
534 PRINTF_LIKE (as_fatal);
535 PRINTF_LIKE (as_tsktsk);
536 PRINTF_LIKE (as_warn);
537 PRINTF_WHERE_LIKE (as_bad_where);
538 PRINTF_WHERE_LIKE (as_warn_where);
540 void fprint_value PARAMS ((FILE *file, addressT value));
541 void sprint_value PARAMS ((char *buf, addressT value));
543 int had_errors PARAMS ((void));
544 int had_warnings PARAMS ((void));
546 void print_version_id PARAMS ((void));
547 char *app_push PARAMS ((void));
548 char *atof_ieee PARAMS ((char *str, int what_kind, LITTLENUM_TYPE * words));
549 char *input_scrub_include_file PARAMS ((char *filename, char *position));
550 char *input_scrub_new_file PARAMS ((char *filename));
551 char *input_scrub_next_buffer PARAMS ((char **bufp));
552 PTR xmalloc PARAMS ((unsigned long size));
553 PTR xrealloc PARAMS ((PTR ptr, unsigned long n));
554 int do_scrub_next_char PARAMS ((int (*get) (void), void (*unget) (int)));
555 int gen_to_words PARAMS ((LITTLENUM_TYPE * words, int precision,
556 long exponent_bits));
557 int had_err PARAMS ((void));
558 int ignore_input PARAMS ((void));
559 int scrub_from_file PARAMS ((void));
560 int scrub_from_string PARAMS ((void));
561 int seen_at_least_1_file PARAMS ((void));
562 void app_pop PARAMS ((char *arg));
563 void as_howmuch PARAMS ((FILE * stream));
564 void as_perror PARAMS ((const char *gripe, const char *filename));
565 void as_where PARAMS ((char **namep, unsigned int *linep));
566 void bump_line_counters PARAMS ((void));
567 void do_scrub_begin PARAMS ((void));
568 void input_scrub_begin PARAMS ((void));
569 void input_scrub_close PARAMS ((void));
570 void input_scrub_end PARAMS ((void));
571 void new_logical_line PARAMS ((char *fname, int line_number));
572 void scrub_to_file PARAMS ((int ch));
573 void scrub_to_string PARAMS ((int ch));
574 void subsegs_begin PARAMS ((void));
575 void subseg_change PARAMS ((segT seg, int subseg));
576 segT subseg_new PARAMS ((const char *name, subsegT subseg));
577 segT subseg_force_new PARAMS ((const char *name, subsegT subseg));
578 void subseg_set PARAMS ((segT seg, subsegT subseg));
580 segT subseg_get PARAMS ((const char *, int));
589 valueT add_to_literal_pool PARAMS ((struct symbol *, valueT, segT, int));
592 #include "expr.h" /* Before targ-*.h */
594 /* this one starts the chain of target dependant headers */
595 #include "targ-env.h"
597 #include "struc-symbol.h"
610 /* Someday perhaps this will be selectable at run-time. */
611 #if defined (OBJ_AOUT) || defined (OBJ_BOUT)
612 #define OUTPUT_FLAVOR bfd_target_aout_flavour
615 #define OUTPUT_FLAVOR bfd_target_coff_flavour
618 #define OUTPUT_FLAVOR bfd_target_ecoff_flavour
621 #define OUTPUT_FLAVOR bfd_target_elf_flavour
623 #endif /* BFD_ASSEMBLER */