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)
108 /* Handle lossage with assert.h. */
109 #ifndef BROKEN_ASSERT
111 #else /* BROKEN_ASSERT */
113 #define assert(p) ((p) ? 0 : (as_assert (__FILE__, __LINE__, __PRETTY_FUNCTION__), 0))
115 #define assert(p) ((p), 0)
117 #endif /* BROKEN_ASSERT */
119 #define assert(P) ((P) ? 0 : (as_assert (__FILE__, __LINE__, __PRETTY_FUNCTION__), 0))
123 /* Now GNU header files... */
124 #include <ansidecl.h>
129 /* Define the standard progress macros. */
130 #include <progress.h>
132 /* This doesn't get taken care of anywhere. */
133 #if !defined (__GNUC__) && !defined (inline)
137 /* Other stuff from config.h. */
138 #ifdef NEED_DECLARATION_MALLOC
139 extern PTR
malloc ();
140 extern PTR
realloc ();
142 #ifdef NEED_DECLARATION_FREE
145 #ifdef NEED_DECLARATION_ERRNO
149 /* This is needed for VMS. */
150 #if ! defined (HAVE_UNLINK) && defined (HAVE_REMOVE)
151 #define unlink remove
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
158 extern PTR bfd_alloc_by_size_t
PARAMS ((bfd
*abfd
, size_t sz
));
161 /* Make Saber happier on obstack.h. */
164 #define __PTR_TO_INT(P) ((int)(P))
166 #define __INT_TO_PTR(P) ((char *)(P))
170 #define __LINE__ "unknown"
171 #endif /* __LINE__ */
174 #define __FILE__ "unknown"
175 #endif /* __FILE__ */
184 #endif /* ! __STDC__ */
186 #if !defined (__GNUC__) && !defined (inline)
192 #include "fopen-bin.h"
194 #include "fopen-same.h"
199 #define EXIT_SUCCESS 0
200 #define EXIT_FAILURE 1
203 #define obstack_chunk_alloc xmalloc
204 #define obstack_chunk_free xfree
208 #define BAD_CASE(val) \
210 as_fatal("Case value %ld unexpected at line %d of file \"%s\"\n", \
211 (long) val, __LINE__, __FILE__); \
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 ();
221 /* These are assembler-wide concepts */
224 extern bfd
*stdoutput
;
225 typedef bfd_vma addressT
;
226 typedef bfd_signed_vma offsetT
;
228 typedef unsigned long addressT
;
229 typedef long offsetT
;
232 /* Type of symbol value, etc. For use in prototypes. */
233 typedef addressT valueT
;
237 #define COMMON /* declare our COMMONs storage here. */
239 #define COMMON extern /* our commons live elswhere */
242 /* COMMON now defined */
246 #define know(p) assert(p) /* Verify our assumptions! */
247 #endif /* not yet defined */
249 #define know(p) /* know() checks are no-op.ed */
255 * Supplies sanitised buffers to read.c.
256 * Also understands printing line-number part of error messages.
260 /* subsegs.c Sub-segments. Also, segment(=expression type)s.*/
262 #ifndef BFD_ASSEMBLER
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
274 #define SEG_NORMAL(x) ((x) == SEG_TEXT || (x) == SEG_DATA || (x) == SEG_BSS)
275 #define SEG_LIST SEG_TEXT,SEG_DATA,SEG_BSS
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 */
293 #define SEG_MAXIMUM_ORDINAL (SEG_REGISTER)
295 typedef asection
*segT
;
296 #define SEG_NORMAL(SEG) ((SEG) != absolute_section \
297 && (SEG) != undefined_section \
298 && (SEG) != reg_section \
299 && (SEG) != expr_section)
303 /* What subseg we are accreting now? */
304 COMMON subsegT now_subseg
;
306 /* Segment our instructions emit to. */
310 #define segment_name(SEG) bfd_get_section_name (stdoutput, SEG)
312 extern char *const seg_name
[];
313 #define segment_name(SEG) seg_name[(int) (SEG)]
316 #ifndef BFD_ASSEMBLER
317 extern int section_alignment
[];
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
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
340 /* Variable chars to be repeated fr_offset times.
341 Fr_symbol unused. Used with fr_offset == 0 for a
342 constant length frag. */
345 /* Align: Fr_offset: power of 2. Variable chars: fill pattern. */
348 /* Align code: fr_offset: power of 2. Fill pattern is machine
349 specific, defaulting to all zeros. */
352 /* Org: Fr_offset, fr_symbol: address. 1 variable char: fill
356 #ifndef WORKING_DOT_WORD
361 /* machine-specific relaxable (or similarly alterable) instruction */
362 rs_machine_dependent
,
364 /* .space directive with expression operand that needs to be computed
365 later. Similar to rs_org, but different.
367 1 variable char: fill character */
371 typedef enum _relax_state relax_stateT
;
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
;
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
;
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.
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
401 /* Object file address. */
403 /* Chain forward; ascending address order. Rooted in frch_root. */
404 struct frag
*fr_next
;
406 /* (Fixed) number of chars we know we have. May be 0. */
408 /* (Variable) number of chars after above. May be 0. */
410 /* For variable-length tail. */
411 struct symbol
*fr_symbol
;
412 /* For variable-length tail. */
414 /* Points to opcode low addr byte, for relaxation. */
418 struct list_info_struct
*line
;
421 /* What state is my tail in? */
422 relax_stateT fr_type
;
423 relax_substateT fr_subtype
;
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
;
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.
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
;
439 /* Data begins here. */
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. */
447 typedef struct frag fragS
;
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 ();
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
;
460 /* main program "as.c" (command arguments etc) */
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 */
467 /* True if local symbols should be retained. */
468 COMMON
unsigned char flag_keep_locals
; /* -L */
470 /* Should the data section be made read-only and appended to the text
472 COMMON
unsigned char flag_readonly_data_in_text
; /* -R */
474 /* True if warnings should be inhibited. */
475 COMMON
unsigned char flag_no_warnings
; /* -W */
477 /* True if we should attempt to generate output even if non-fatal errors
479 COMMON
unsigned char flag_always_generate_output
; /* -Z */
481 /* This is true if the assembler should output time and space usage. */
483 COMMON
unsigned char flag_print_statistics
;
485 /* name of emitted object file */
486 COMMON
char *out_file_name
;
488 /* TRUE if we need a second pass. */
489 COMMON
int need_pass_2
;
491 /* TRUE if we should do no relaxing, and
492 leave lots of padding. */
493 COMMON
int linkrelax
;
495 /* TRUE if we should produce a listing. */
500 /* assembler mnemonic, lower case, no '.' */
503 void (*poc_handler
) PARAMS ((int));
504 /* Value to pass to handler */
508 typedef struct _pseudo_type pseudo_typeS
;
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__)
516 #if defined (HAVE_STDARG_H)
519 #if !defined (USE_STDARG) && defined (HAVE_VARARGS_H)
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, \
535 const char *format, ...))
537 #else /* not using stdarg */
538 #define PRINTF_LIKE(FCN) void FCN ()
539 #define PRINTF_WHERE_LIKE(FCN) void FCN ()
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 *));
550 void fprint_value
PARAMS ((FILE *file
, addressT value
));
551 void sprint_value
PARAMS ((char *buf
, addressT value
));
553 int had_errors
PARAMS ((void));
554 int had_warnings
PARAMS ((void));
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
));
590 segT subseg_get
PARAMS ((const char *, int));
599 valueT add_to_literal_pool
PARAMS ((struct symbol
*, valueT
, segT
, int));
602 #include "expr.h" /* Before targ-*.h */
604 /* this one starts the chain of target dependant headers */
605 #include "targ-env.h"
607 #include "struc-symbol.h"
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
625 #define OUTPUT_FLAVOR bfd_target_coff_flavour
628 #define OUTPUT_FLAVOR bfd_target_ecoff_flavour
631 #define OUTPUT_FLAVOR bfd_target_elf_flavour
633 #endif /* BFD_ASSEMBLER */