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 #if !defined (__GNUC__) || __GNUC_MINOR__ <= 5
105 #define __PRETTY_FUNCTION__ ((char*)0)
109 /* Handle lossage with assert.h. */
110 #ifndef BROKEN_ASSERT
112 #else /* BROKEN_ASSERT */
114 #define assert(p) ((p) ? 0 : (as_assert (__FILE__, __LINE__, __PRETTY_FUNCTION__), 0))
116 #define assert(p) ((p), 0)
118 #endif /* BROKEN_ASSERT */
122 #define assert(P) ((P) ? 0 : (as_assert (__FILE__, __LINE__, __PRETTY_FUNCTION__), 0))
124 #define abort() as_abort (__FILE__, __LINE__, __PRETTY_FUNCTION__)
129 /* Now GNU header files... */
130 #include <ansidecl.h>
135 /* Define the standard progress macros. */
136 #include <progress.h>
138 /* This doesn't get taken care of anywhere. */
139 #if !defined (__GNUC__) && !defined (inline)
143 /* Other stuff from config.h. */
144 #ifdef NEED_DECLARATION_MALLOC
145 extern PTR malloc ();
146 extern PTR realloc ();
148 #ifdef NEED_DECLARATION_FREE
151 #ifdef NEED_DECLARATION_ERRNO
155 /* This is needed for VMS. */
156 #if ! defined (HAVE_UNLINK) && defined (HAVE_REMOVE)
157 #define unlink remove
160 /* Hack to make "gcc -Wall" not complain about obstack macros. */
161 #if !defined (memcpy) && !defined (bcopy)
162 #define bcopy(src,dest,size) memcpy(dest,src,size)
166 /* This one doesn't get declared, but we're using it anyways. This
167 should be fixed -- either it's part of the external interface or
169 extern PTR bfd_alloc_by_size_t PARAMS ((bfd *abfd, size_t sz));
172 /* Make Saber happier on obstack.h. */
175 #define __PTR_TO_INT(P) ((int)(P))
177 #define __INT_TO_PTR(P) ((char *)(P))
181 #define __LINE__ "unknown"
182 #endif /* __LINE__ */
185 #define __FILE__ "unknown"
186 #endif /* __FILE__ */
195 #endif /* ! __STDC__ */
197 #if !defined (__GNUC__) && !defined (inline)
203 #include "fopen-bin.h"
205 #include "fopen-same.h"
210 #define EXIT_SUCCESS 0
211 #define EXIT_FAILURE 1
214 #define obstack_chunk_alloc xmalloc
215 #define obstack_chunk_free xfree
219 #define BAD_CASE(val) \
221 as_fatal("Case value %ld unexpected at line %d of file \"%s\"\n", \
222 (long) val, __LINE__, __FILE__); \
225 /* Version 2.1 of Solaris had problems with this declaration, but I
226 think that bug has since been fixed. If it causes problems on your
227 system, just delete it. */
228 extern char *strstr ();
232 /* These are assembler-wide concepts */
235 extern bfd *stdoutput;
236 typedef bfd_vma addressT;
237 typedef bfd_signed_vma offsetT;
239 typedef unsigned long addressT;
240 typedef long offsetT;
243 /* Type of symbol value, etc. For use in prototypes. */
244 typedef addressT valueT;
248 #define COMMON /* declare our COMMONs storage here. */
250 #define COMMON extern /* our commons live elswhere */
253 /* COMMON now defined */
257 #define know(p) assert(p) /* Verify our assumptions! */
258 #endif /* not yet defined */
260 #define know(p) /* know() checks are no-op.ed */
266 * Supplies sanitised buffers to read.c.
267 * Also understands printing line-number part of error messages.
271 /* subsegs.c Sub-segments. Also, segment(=expression type)s.*/
273 #ifndef BFD_ASSEMBLER
277 #define N_SEGMENTS 10
278 #define SEG_NORMAL(x) ((x) >= SEG_E0 && (x) <= SEG_E9)
279 #define SEG_LIST SEG_E0,SEG_E1,SEG_E2,SEG_E3,SEG_E4,SEG_E5,SEG_E6,SEG_E7,SEG_E8,SEG_E9
280 #define SEG_TEXT SEG_E0
281 #define SEG_DATA SEG_E1
282 #define SEG_BSS SEG_E2
285 #define SEG_NORMAL(x) ((x) == SEG_TEXT || (x) == SEG_DATA || (x) == SEG_BSS)
286 #define SEG_LIST SEG_TEXT,SEG_DATA,SEG_BSS
294 SEG_GOOF, /* Only happens if AS has a logic error. */
295 /* Invented so we don't crash printing */
296 /* error message involving weird segment. */
297 SEG_EXPR, /* Intermediate expression values. */
298 SEG_DEBUG, /* Debug segment */
299 SEG_NTV, /* Transfert vector preload segment */
300 SEG_PTV, /* Transfert vector postload segment */
301 SEG_REGISTER /* Mythical: a register-valued expression */
304 #define SEG_MAXIMUM_ORDINAL (SEG_REGISTER)
306 typedef asection *segT;
307 #define SEG_NORMAL(SEG) ((SEG) != absolute_section \
308 && (SEG) != undefined_section \
309 && (SEG) != reg_section \
310 && (SEG) != expr_section)
314 /* What subseg we are accreting now? */
315 COMMON subsegT now_subseg;
317 /* Segment our instructions emit to. */
321 #define segment_name(SEG) bfd_get_section_name (stdoutput, SEG)
323 extern char const *const seg_name[];
324 #define segment_name(SEG) seg_name[(int) (SEG)]
327 #ifndef BFD_ASSEMBLER
328 extern int section_alignment[];
332 extern segT reg_section, expr_section;
333 /* Shouldn't these be eliminated someday? */
334 extern segT text_section, data_section, bss_section;
335 #define absolute_section bfd_abs_section_ptr
336 #define undefined_section bfd_und_section_ptr
338 #define reg_section SEG_REGISTER
339 #define expr_section SEG_EXPR
340 #define text_section SEG_TEXT
341 #define data_section SEG_DATA
342 #define bss_section SEG_BSS
343 #define absolute_section SEG_ABSOLUTE
344 #define undefined_section SEG_UNKNOWN
351 /* Variable chars to be repeated fr_offset times.
352 Fr_symbol unused. Used with fr_offset == 0 for a
353 constant length frag. */
356 /* Align: Fr_offset: power of 2. Variable chars: fill pattern. */
359 /* Align code: fr_offset: power of 2. Fill pattern is machine
360 specific, defaulting to all zeros. */
363 /* Org: Fr_offset, fr_symbol: address. 1 variable char: fill
367 #ifndef WORKING_DOT_WORD
372 /* machine-specific relaxable (or similarly alterable) instruction */
373 rs_machine_dependent,
375 /* .space directive with expression operand that needs to be computed
376 later. Similar to rs_org, but different.
378 1 variable char: fill character */
382 typedef enum _relax_state relax_stateT;
384 /* This type is used in prototypes, so it can't be a type that will be
385 widened for argument passing. */
386 typedef unsigned int relax_substateT;
388 /* Enough bits for address, but still an integer type.
389 Could be a problem, cross-assembling for 64-bit machines. */
390 typedef addressT relax_addressT;
396 * A code fragment (frag) is some known number of chars, followed by some
397 * unknown number of chars. Typically the unknown number of chars is an
398 * instruction address whose size is yet unknown. We always know the greatest
399 * possible size the unknown number of chars may become, and reserve that
400 * much room at the end of the frag.
401 * Once created, frags do not change address during assembly.
402 * We chain the frags in (a) forward-linked list(s). The object-file address
403 * of the 1st char of a frag is generally not known until after relax().
404 * Many things at assembly time describe an address by {object-file-address
405 * of a particular frag}+offset.
407 BUG: it may be smarter to have a single pointer off to various different
408 notes for different frag kinds. See how code pans
412 /* Object file address. */
414 /* Chain forward; ascending address order. Rooted in frch_root. */
415 struct frag *fr_next;
417 /* (Fixed) number of chars we know we have. May be 0. */
419 /* (Variable) number of chars after above. May be 0. */
421 /* For variable-length tail. */
422 struct symbol *fr_symbol;
423 /* For variable-length tail. */
425 /* Points to opcode low addr byte, for relaxation. */
429 struct list_info_struct *line;
432 /* What state is my tail in? */
433 relax_stateT fr_type;
434 relax_substateT fr_subtype;
436 /* Track the alignment and offset of the current frag. With this,
437 sometimes we can avoid creating new frags for .align directives. */
438 unsigned short align_mask;
439 unsigned short align_offset;
441 /* These are needed only on the NS32K machines. But since we don't
442 include targ-cpu.h until after this structure has been defined,
443 we can't really conditionalize it. This code should be
444 rearranged a bit to make that possible.
446 In the meantime, if we get stuck like this with any other target,
447 create a union here. */
448 char fr_pcrel_adjust, fr_bsr;
450 /* Data begins here. */
454 #define SIZEOF_STRUCT_FRAG \
455 ((char *)zero_address_frag.fr_literal-(char *)&zero_address_frag)
456 /* We want to say fr_literal[0] above. */
458 typedef struct frag fragS;
460 /* Current frag we are building. This frag is incomplete. It is, however,
461 included in frchain_now. The fr_fix field is bogus; instead, use:
462 obstack_next_free(&frags)-frag_now->fr_literal. */
463 COMMON fragS *frag_now;
464 extern int frag_now_fix ();
466 /* For foreign-segment symbol fixups. */
467 COMMON fragS zero_address_frag;
468 /* For local common (N_BSS segment) fixups. */
469 COMMON fragS bss_address_frag;
471 /* main program "as.c" (command arguments etc) */
473 COMMON unsigned char flag_no_comments; /* -f */
474 COMMON unsigned char flag_debug; /* -D */
475 COMMON unsigned char flag_signed_overflow_ok; /* -J */
476 #ifndef WORKING_DOT_WORD
477 COMMON unsigned char flag_warn_displacement; /* -K */
480 /* True if local symbols should be retained. */
481 COMMON unsigned char flag_keep_locals; /* -L */
483 /* Should the data section be made read-only and appended to the text
485 COMMON unsigned char flag_readonly_data_in_text; /* -R */
487 /* True if warnings should be inhibited. */
488 COMMON unsigned char flag_no_warnings; /* -W */
490 /* True if we should attempt to generate output even if non-fatal errors
492 COMMON unsigned char flag_always_generate_output; /* -Z */
494 /* This is true if the assembler should output time and space usage. */
496 COMMON unsigned char flag_print_statistics;
498 /* name of emitted object file */
499 COMMON char *out_file_name;
501 /* TRUE if we need a second pass. */
502 COMMON int need_pass_2;
504 /* TRUE if we should do no relaxing, and
505 leave lots of padding. */
506 COMMON int linkrelax;
508 /* TRUE if we should produce a listing. */
513 /* assembler mnemonic, lower case, no '.' */
514 const char *poc_name;
516 void (*poc_handler) PARAMS ((int));
517 /* Value to pass to handler */
521 typedef struct _pseudo_type pseudo_typeS;
523 /* Prefer varargs for non-ANSI compiler, since some will barf if the
524 ellipsis definition is used with a no-arguments declaration. */
525 #if defined (HAVE_VARARGS_H) && !defined (__STDC__)
529 #if defined (HAVE_STDARG_H)
532 #if !defined (USE_STDARG) && defined (HAVE_VARARGS_H)
538 /* for use with -Wformat */
539 #define PRINTF_LIKE(FCN) void FCN (const char *format, ...) \
540 __attribute__ ((format (printf, 1, 2)))
541 #define PRINTF_WHERE_LIKE(FCN) void FCN (char *file, unsigned int line, \
542 const char *format, ...) \
543 __attribute__ ((format (printf, 3, 4)))
544 #else /* ANSI C with stdarg, but not GNU C */
545 #define PRINTF_LIKE(FCN) void FCN PARAMS ((const char *format, ...))
546 #define PRINTF_WHERE_LIKE(FCN) void FCN PARAMS ((char *file, \
548 const char *format, ...))
550 #else /* not using stdarg */
551 #define PRINTF_LIKE(FCN) void FCN ()
552 #define PRINTF_WHERE_LIKE(FCN) void FCN ()
555 PRINTF_LIKE (as_bad);
556 PRINTF_LIKE (as_fatal);
557 PRINTF_LIKE (as_tsktsk);
558 PRINTF_LIKE (as_warn);
559 PRINTF_WHERE_LIKE (as_bad_where);
560 PRINTF_WHERE_LIKE (as_warn_where);
561 void as_assert PARAMS ((const char *, int, const char *));
562 void as_abort PARAMS ((const char *, int, const char *));
564 void fprint_value PARAMS ((FILE *file, addressT value));
565 void sprint_value PARAMS ((char *buf, addressT value));
567 int had_errors PARAMS ((void));
568 int had_warnings PARAMS ((void));
570 void print_version_id PARAMS ((void));
571 char *app_push PARAMS ((void));
572 char *atof_ieee PARAMS ((char *str, int what_kind, LITTLENUM_TYPE * words));
573 char *input_scrub_include_file PARAMS ((char *filename, char *position));
574 char *input_scrub_new_file PARAMS ((char *filename));
575 char *input_scrub_next_buffer PARAMS ((char **bufp));
576 PTR xmalloc PARAMS ((unsigned long size));
577 PTR xrealloc PARAMS ((PTR ptr, unsigned long n));
578 int do_scrub_next_char PARAMS ((int (*get) (void), void (*unget) (int)));
579 int gen_to_words PARAMS ((LITTLENUM_TYPE * words, int precision,
580 long exponent_bits));
581 int had_err PARAMS ((void));
582 int ignore_input PARAMS ((void));
583 int scrub_from_file PARAMS ((void));
584 int scrub_from_string PARAMS ((void));
585 int seen_at_least_1_file PARAMS ((void));
586 void app_pop PARAMS ((char *arg));
587 void as_howmuch PARAMS ((FILE * stream));
588 void as_perror PARAMS ((const char *gripe, const char *filename));
589 void as_where PARAMS ((char **namep, unsigned int *linep));
590 void bump_line_counters PARAMS ((void));
591 void do_scrub_begin PARAMS ((void));
592 void input_scrub_begin PARAMS ((void));
593 void input_scrub_close PARAMS ((void));
594 void input_scrub_end PARAMS ((void));
595 void new_logical_line PARAMS ((char *fname, int line_number));
596 void scrub_to_file PARAMS ((int ch));
597 void scrub_to_string PARAMS ((int ch));
598 void subsegs_begin PARAMS ((void));
599 void subseg_change PARAMS ((segT seg, int subseg));
600 segT subseg_new PARAMS ((const char *name, subsegT subseg));
601 segT subseg_force_new PARAMS ((const char *name, subsegT subseg));
602 void subseg_set PARAMS ((segT seg, subsegT subseg));
604 segT subseg_get PARAMS ((const char *, int));
614 valueT add_to_literal_pool PARAMS ((struct symbol *, valueT, segT, int));
617 #include "expr.h" /* Before targ-*.h */
619 /* this one starts the chain of target dependant headers */
620 #include "targ-env.h"
622 #include "struc-symbol.h"
632 #ifdef USE_EMULATIONS
637 #ifndef LOCAL_LABELS_DOLLAR
638 #define LOCAL_LABELS_DOLLAR 0
641 #ifndef LOCAL_LABELS_FB
642 #define LOCAL_LABELS_FB 0