1 /* as.h - global header file
2 Copyright (C) 1987, 90, 91, 92, 93, 94, 95, 96, 1997
3 Free Software Foundation, Inc.
5 This file is part of GAS, the GNU Assembler.
7 GAS is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GAS is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GAS; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
25 * I think this stuff is largely out of date. xoxorich.
27 * CAPITALISED names are #defined.
28 * "lowercaseH" is #defined if "lowercase.h" has been #include-d.
29 * "lowercaseT" is a typedef of "lowercase" objects.
30 * "lowercaseP" is type "pointer to object of type 'lowercase'".
31 * "lowercaseS" is typedef struct ... lowercaseS.
33 * #define DEBUG to enable all the "know" assertion tests.
34 * #define SUSPECT when debugging hash code.
35 * #define COMMON as "extern" for all modules except one, where you #define
37 * If TEST is #defined, then we are testing a module: #define COMMON as "".
42 /* This is the code recommended in the autoconf documentation, almost
43 verbatim. If it doesn't work for you, let me know, and notify
44 djm@gnu.ai.mit.edu as well. */
45 /* Added #undef for DJ Delorie. The right fix is to ensure that as.h
46 is included first, before even any system header files, in all files
47 that use it. KR 1994.11.03 */
48 /* Added void* version for STDC case. This is to be compatible with
49 the declaration in bison.simple, used for m68k operand parsing.
51 /* Force void* decl for hpux. This is what Bison uses. --KR 1995.08.16 */
53 /* AIX requires this to be the first thing in the file. */
56 # define alloca __builtin_alloca
64 # ifndef alloca /* predefined by HP cc +Olibcalls */
65 # if !defined (__STDC__) && !defined (__hpux)
69 # endif /* __STDC__, __hpux */
72 # endif /* HAVE_ALLOCA_H */
75 /* Now, tend to the rest of the configuration. */
77 /* System include files first... */
93 #ifdef HAVE_SYS_TYPES_H
94 /* for size_t, pid_t */
95 #include <sys/types.h>
99 /* The first getopt value for machine-independent long options.
100 150 isn't special; it's just an arbitrary non-ASCII char value. */
101 #define OPTION_STD_BASE 150
102 /* The first getopt value for machine-dependent long options.
103 170 gives the standard options room to grow. */
104 #define OPTION_MD_BASE 170
109 #if !defined (__GNUC__) || __GNUC_MINOR__ <= 5
110 #define __PRETTY_FUNCTION__ ((char*)0)
114 /* Handle lossage with assert.h. */
115 #ifndef BROKEN_ASSERT
117 #else /* BROKEN_ASSERT */
119 #define assert(p) ((p) ? 0 : (as_assert (__FILE__, __LINE__, __PRETTY_FUNCTION__), 0))
121 #define assert(p) ((p), 0)
123 #endif /* BROKEN_ASSERT */
127 #define assert(P) ((P) ? 0 : (as_assert (__FILE__, __LINE__, __PRETTY_FUNCTION__), 0))
129 #define abort() as_abort (__FILE__, __LINE__, __PRETTY_FUNCTION__)
134 /* Now GNU header files... */
135 #include <ansidecl.h>
139 #include <libiberty.h>
141 /* Define the standard progress macros. */
142 #include <progress.h>
144 /* This doesn't get taken care of anywhere. */
145 #ifndef __MWERKS__ /* Metrowerks C chokes on the "defined (inline)" */
146 #if !defined (__GNUC__) && !defined (inline)
149 #endif /* !__MWERKS__ */
151 /* Other stuff from config.h. */
152 #ifdef NEED_DECLARATION_STRSTR
153 extern char *strstr ();
155 #ifdef NEED_DECLARATION_MALLOC
156 extern PTR
malloc ();
157 extern PTR
realloc ();
159 #ifdef NEED_DECLARATION_FREE
162 #ifdef NEED_DECLARATION_ERRNO
166 /* This is needed for VMS with DEC C. */
167 #if ! defined (__GNUC__) && ! defined (HAVE_UNLINK) && defined (HAVE_REMOVE)
168 #define unlink remove
171 /* Hack to make "gcc -Wall" not complain about obstack macros. */
172 #if !defined (memcpy) && !defined (bcopy)
173 #define bcopy(src,dest,size) memcpy(dest,src,size)
176 /* Make Saber happier on obstack.h. */
179 #define __PTR_TO_INT(P) ((int)(P))
181 #define __INT_TO_PTR(P) ((char *)(P))
185 #define __LINE__ "unknown"
186 #endif /* __LINE__ */
189 #define __FILE__ "unknown"
190 #endif /* __FILE__ */
194 #include "fopen-bin.h"
196 #include "fopen-same.h"
201 #define EXIT_SUCCESS 0
202 #define EXIT_FAILURE 1
205 #define obstack_chunk_alloc xmalloc
206 #define obstack_chunk_free xfree
210 #define BAD_CASE(val) \
212 as_fatal("Case value %ld unexpected at line %d of file \"%s\"\n", \
213 (long) val, __LINE__, __FILE__); \
218 /* These are assembler-wide concepts */
221 extern bfd
*stdoutput
;
222 typedef bfd_vma addressT
;
223 typedef bfd_signed_vma offsetT
;
225 typedef unsigned long addressT
;
226 typedef long offsetT
;
229 /* Type of symbol value, etc. For use in prototypes. */
230 typedef addressT valueT
;
234 #define COMMON /* declare our COMMONs storage here. */
236 #define COMMON extern /* our commons live elswhere */
239 /* COMMON now defined */
243 #define know(p) assert(p) /* Verify our assumptions! */
244 #endif /* not yet defined */
246 #define know(p) /* know() checks are no-op.ed */
252 * Supplies sanitised buffers to read.c.
253 * Also understands printing line-number part of error messages.
257 /* subsegs.c Sub-segments. Also, segment(=expression type)s.*/
259 #ifndef BFD_ASSEMBLER
263 #define N_SEGMENTS 40
264 #define SEG_NORMAL(x) ((x) >= SEG_E0 && (x) <= SEG_E39)
265 #define SEG_LIST SEG_E0,SEG_E1,SEG_E2,SEG_E3,SEG_E4,SEG_E5,SEG_E6,SEG_E7,SEG_E8,SEG_E9,\
266 SEG_E10,SEG_E11,SEG_E12,SEG_E13,SEG_E14,SEG_E15,SEG_E16,SEG_E17,SEG_E18,SEG_E19,\
267 SEG_E20,SEG_E21,SEG_E22,SEG_E23,SEG_E24,SEG_E25,SEG_E26,SEG_E27,SEG_E28,SEG_E29,\
268 SEG_E30,SEG_E31,SEG_E32,SEG_E33,SEG_E34,SEG_E35,SEG_E36,SEG_E37,SEG_E38,SEG_E39
269 #define SEG_TEXT SEG_E0
270 #define SEG_DATA SEG_E1
271 #define SEG_BSS SEG_E2
272 #define SEG_LAST SEG_E39
275 #define SEG_NORMAL(x) ((x) == SEG_TEXT || (x) == SEG_DATA || (x) == SEG_BSS)
276 #define SEG_LIST SEG_TEXT,SEG_DATA,SEG_BSS
284 SEG_GOOF
, /* Only happens if AS has a logic error. */
285 /* Invented so we don't crash printing */
286 /* error message involving weird segment. */
287 SEG_EXPR
, /* Intermediate expression values. */
288 SEG_DEBUG
, /* Debug segment */
289 SEG_NTV
, /* Transfert vector preload segment */
290 SEG_PTV
, /* Transfert vector postload segment */
291 SEG_REGISTER
/* Mythical: a register-valued expression */
294 #define SEG_MAXIMUM_ORDINAL (SEG_REGISTER)
296 typedef asection
*segT
;
297 #define SEG_NORMAL(SEG) ((SEG) != absolute_section \
298 && (SEG) != undefined_section \
299 && (SEG) != reg_section \
300 && (SEG) != expr_section)
304 /* What subseg we are accreting now? */
305 COMMON subsegT now_subseg
;
307 /* Segment our instructions emit to. */
311 #define segment_name(SEG) bfd_get_section_name (stdoutput, SEG)
313 extern char const *const seg_name
[];
314 #define segment_name(SEG) seg_name[(int) (SEG)]
317 #ifndef BFD_ASSEMBLER
318 extern int section_alignment
[];
322 extern segT reg_section
, expr_section
;
323 /* Shouldn't these be eliminated someday? */
324 extern segT text_section
, data_section
, bss_section
;
325 #define absolute_section bfd_abs_section_ptr
326 #define undefined_section bfd_und_section_ptr
328 #define reg_section SEG_REGISTER
329 #define expr_section SEG_EXPR
330 #define text_section SEG_TEXT
331 #define data_section SEG_DATA
332 #define bss_section SEG_BSS
333 #define absolute_section SEG_ABSOLUTE
334 #define undefined_section SEG_UNKNOWN
341 /* Variable chars to be repeated fr_offset times.
342 Fr_symbol unused. Used with fr_offset == 0 for a
343 constant length frag. */
346 /* Align. The fr_offset field holds the power of 2 to which to
347 align. The fr_var field holds the number of characters in the
348 fill pattern. The fr_subtype field holds the maximum number of
349 bytes to skip when aligning, or 0 if there is no maximum. */
352 /* Align code. The fr_offset field holds the power of 2 to which
353 to align. This type is only generated by machine specific
354 code, which is normally responsible for handling the fill
355 pattern. The fr_subtype field holds the maximum number of
356 bytes to skip when aligning, or 0 if there is no maximum. */
359 /* Org: Fr_offset, fr_symbol: address. 1 variable char: fill
363 #ifndef WORKING_DOT_WORD
368 /* machine-specific relaxable (or similarly alterable) instruction */
369 rs_machine_dependent
,
371 /* .space directive with expression operand that needs to be computed
372 later. Similar to rs_org, but different.
374 1 variable char: fill character */
378 typedef enum _relax_state relax_stateT
;
380 /* This type is used in prototypes, so it can't be a type that will be
381 widened for argument passing. */
382 typedef unsigned int relax_substateT
;
384 /* Enough bits for address, but still an integer type.
385 Could be a problem, cross-assembling for 64-bit machines. */
386 typedef addressT relax_addressT
;
392 * A code fragment (frag) is some known number of chars, followed by some
393 * unknown number of chars. Typically the unknown number of chars is an
394 * instruction address whose size is yet unknown. We always know the greatest
395 * possible size the unknown number of chars may become, and reserve that
396 * much room at the end of the frag.
397 * Once created, frags do not change address during assembly.
398 * We chain the frags in (a) forward-linked list(s). The object-file address
399 * of the 1st char of a frag is generally not known until after relax().
400 * Many things at assembly time describe an address by {object-file-address
401 * of a particular frag}+offset.
403 BUG: it may be smarter to have a single pointer off to various different
404 notes for different frag kinds. See how code pans
408 /* Object file address. */
410 /* Chain forward; ascending address order. Rooted in frch_root. */
411 struct frag
*fr_next
;
413 /* (Fixed) number of chars we know we have. May be 0. */
415 /* (Variable) number of chars after above. May be 0. */
417 /* For variable-length tail. */
418 struct symbol
*fr_symbol
;
419 /* For variable-length tail. */
421 /* Points to opcode low addr byte, for relaxation. */
425 struct list_info_struct
*line
;
428 /* What state is my tail in? */
429 relax_stateT fr_type
;
430 relax_substateT fr_subtype
;
432 /* These are needed only on the NS32K machines. But since we don't
433 include targ-cpu.h until after this structure has been defined,
434 we can't really conditionalize it. This code should be
435 rearranged a bit to make that possible.
437 In the meantime, if we get stuck like this with any other target,
438 create a union here. */
439 char fr_pcrel_adjust
, fr_bsr
;
441 /* Where the frag was created, or where it became a variant frag. */
443 unsigned int fr_line
;
445 /* Data begins here. */
449 #define SIZEOF_STRUCT_FRAG \
450 ((char *)zero_address_frag.fr_literal-(char *)&zero_address_frag)
451 /* We want to say fr_literal[0] above. */
453 typedef struct frag fragS
;
455 /* Current frag we are building. This frag is incomplete. It is, however,
456 included in frchain_now. The fr_fix field is bogus; instead, use:
457 obstack_next_free(&frags)-frag_now->fr_literal. */
458 COMMON fragS
*frag_now
;
459 extern int frag_now_fix ();
461 /* For foreign-segment symbol fixups. */
462 COMMON fragS zero_address_frag
;
463 /* For local common (N_BSS segment) fixups. */
464 COMMON fragS bss_address_frag
;
466 /* main program "as.c" (command arguments etc) */
468 COMMON
unsigned char flag_no_comments
; /* -f */
469 COMMON
unsigned char flag_debug
; /* -D */
470 COMMON
unsigned char flag_signed_overflow_ok
; /* -J */
471 #ifndef WORKING_DOT_WORD
472 COMMON
unsigned char flag_warn_displacement
; /* -K */
475 /* True if local symbols should be retained. */
476 COMMON
int flag_keep_locals
; /* -L */
478 /* True if we are assembling in MRI mode. */
481 /* True if we are assembling in m68k MRI mode. */
482 COMMON
int flag_m68k_mri
;
484 /* Should the data section be made read-only and appended to the text
486 COMMON
unsigned char flag_readonly_data_in_text
; /* -R */
488 /* True if warnings should be inhibited. */
489 COMMON
int flag_no_warnings
; /* -W */
491 /* True if we should attempt to generate output even if non-fatal errors
493 COMMON
unsigned char flag_always_generate_output
; /* -Z */
495 /* This is true if the assembler should output time and space usage. */
497 COMMON
unsigned char flag_print_statistics
;
499 /* name of emitted object file */
500 COMMON
char *out_file_name
;
502 /* name of file defining extensions to the basic instruction set */
503 COMMON
char *insttbl_file_name
;
505 /* TRUE if we need a second pass. */
506 COMMON
int need_pass_2
;
508 /* TRUE if we should do no relaxing, and
509 leave lots of padding. */
510 COMMON
int linkrelax
;
512 /* TRUE if we should produce a listing. */
515 /* Maximum level of macro nesting. */
516 extern int max_macro_nest
;
518 /* Obstack chunk size. Keep large for efficient space use, make small to
519 increase malloc calls for monitoring memory allocation. */
520 extern int chunksize
;
524 /* assembler mnemonic, lower case, no '.' */
525 const char *poc_name
;
527 void (*poc_handler
) PARAMS ((int));
528 /* Value to pass to handler */
532 typedef struct _pseudo_type pseudo_typeS
;
534 /* Prefer varargs for non-ANSI compiler, since some will barf if the
535 ellipsis definition is used with a no-arguments declaration. */
536 #if defined (HAVE_VARARGS_H) && !defined (__STDC__)
540 #if defined (HAVE_STDARG_H)
543 #if !defined (USE_STDARG) && defined (HAVE_VARARGS_H)
548 #if (__GNUC__ >= 2) && !defined(VMS)
549 /* for use with -Wformat */
550 #define PRINTF_LIKE(FCN) void FCN (const char *format, ...) \
551 __attribute__ ((format (printf, 1, 2)))
552 #define PRINTF_WHERE_LIKE(FCN) void FCN (char *file, unsigned int line, \
553 const char *format, ...) \
554 __attribute__ ((format (printf, 3, 4)))
555 #else /* ANSI C with stdarg, but not GNU C */
556 #define PRINTF_LIKE(FCN) void FCN PARAMS ((const char *format, ...))
557 #define PRINTF_WHERE_LIKE(FCN) void FCN PARAMS ((char *file, \
559 const char *format, ...))
561 #else /* not using stdarg */
562 #define PRINTF_LIKE(FCN) void FCN ()
563 #define PRINTF_WHERE_LIKE(FCN) void FCN ()
566 PRINTF_LIKE (as_bad
);
567 PRINTF_LIKE (as_fatal
);
568 PRINTF_LIKE (as_tsktsk
);
569 PRINTF_LIKE (as_warn
);
570 PRINTF_WHERE_LIKE (as_bad_where
);
571 PRINTF_WHERE_LIKE (as_warn_where
);
572 void as_assert
PARAMS ((const char *, int, const char *));
573 void as_abort
PARAMS ((const char *, int, const char *));
575 void fprint_value
PARAMS ((FILE *file
, addressT value
));
576 void sprint_value
PARAMS ((char *buf
, addressT value
));
578 int had_errors
PARAMS ((void));
579 int had_warnings
PARAMS ((void));
581 void print_version_id
PARAMS ((void));
582 char *app_push
PARAMS ((void));
583 char *atof_ieee
PARAMS ((char *str
, int what_kind
, LITTLENUM_TYPE
* words
));
584 char *input_scrub_include_file
PARAMS ((char *filename
, char *position
));
585 char *input_scrub_new_file
PARAMS ((char *filename
));
586 char *input_scrub_next_buffer
PARAMS ((char **bufp
));
587 int do_scrub_chars
PARAMS ((int (*get
) (char **), char *to
, int tolen
));
588 int gen_to_words
PARAMS ((LITTLENUM_TYPE
* words
, int precision
,
589 long exponent_bits
));
590 int had_err
PARAMS ((void));
591 int ignore_input
PARAMS ((void));
592 int seen_at_least_1_file
PARAMS ((void));
593 void app_pop
PARAMS ((char *arg
));
594 void as_howmuch
PARAMS ((FILE * stream
));
595 void as_perror
PARAMS ((const char *gripe
, const char *filename
));
596 void as_where
PARAMS ((char **namep
, unsigned int *linep
));
597 void bump_line_counters
PARAMS ((void));
598 void do_scrub_begin
PARAMS ((int));
599 void input_scrub_begin
PARAMS ((void));
600 void input_scrub_close
PARAMS ((void));
601 void input_scrub_end
PARAMS ((void));
602 void new_logical_line
PARAMS ((char *fname
, int line_number
));
603 void subsegs_begin
PARAMS ((void));
604 void subseg_change
PARAMS ((segT seg
, int subseg
));
605 segT subseg_new
PARAMS ((const char *name
, subsegT subseg
));
606 segT subseg_force_new
PARAMS ((const char *name
, subsegT subseg
));
607 void subseg_set
PARAMS ((segT seg
, subsegT subseg
));
609 segT subseg_get
PARAMS ((const char *, int));
619 valueT add_to_literal_pool
PARAMS ((struct symbol
*, valueT
, segT
, int));
622 #include "expr.h" /* Before targ-*.h */
624 /* this one starts the chain of target dependant headers */
625 #include "targ-env.h"
627 #include "struc-symbol.h"
637 #ifdef USE_EMULATIONS
642 #ifndef LOCAL_LABELS_DOLLAR
643 #define LOCAL_LABELS_DOLLAR 0
646 #ifndef LOCAL_LABELS_FB
647 #define LOCAL_LABELS_FB 0