as.h revision 33965
1/* as.h - global header file 2 Copyright (C) 1987, 90, 91, 92, 93, 94, 95, 96, 1997 3 Free Software Foundation, Inc. 4 5 This file is part of GAS, the GNU Assembler. 6 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) 10 any later version. 11 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. 16 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 20 02111-1307, USA. */ 21 22#ifndef GAS 23#define GAS 1 24/* 25 * I think this stuff is largely out of date. xoxorich. 26 * 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. 32 * 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 36 * COMMON as "". 37 * If TEST is #defined, then we are testing a module: #define COMMON as "". 38 */ 39 40#include "config.h" 41 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. 50 --KR 1995.08.08 */ 51/* Force void* decl for hpux. This is what Bison uses. --KR 1995.08.16 */ 52 53/* AIX requires this to be the first thing in the file. */ 54#ifdef __GNUC__ 55# undef alloca 56# define alloca __builtin_alloca 57#else 58# if HAVE_ALLOCA_H 59# include <alloca.h> 60# else 61# ifdef _AIX 62 #pragma alloca 63# else 64# ifndef alloca /* predefined by HP cc +Olibcalls */ 65# if !defined (__STDC__) && !defined (__hpux) 66char *alloca (); 67# else 68void *alloca (); 69# endif /* __STDC__, __hpux */ 70# endif /* alloca */ 71# endif /* _AIX */ 72# endif /* HAVE_ALLOCA_H */ 73#endif 74 75/* Now, tend to the rest of the configuration. */ 76 77/* System include files first... */ 78#include <stdio.h> 79#include <ctype.h> 80#ifdef HAVE_STRING_H 81#include <string.h> 82#else 83#ifdef HAVE_STRINGS_H 84#include <strings.h> 85#endif 86#endif 87#ifdef HAVE_STDLIB_H 88#include <stdlib.h> 89#endif 90#ifdef HAVE_UNISTD_H 91#include <unistd.h> 92#endif 93#ifdef HAVE_SYS_TYPES_H 94/* for size_t, pid_t */ 95#include <sys/types.h> 96#endif 97 98#include <getopt.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 105 106#ifdef DEBUG 107#undef NDEBUG 108#endif 109#if !defined (__GNUC__) || __GNUC_MINOR__ <= 5 110#define __PRETTY_FUNCTION__ ((char*)0) 111#endif 112#if 0 113 114/* Handle lossage with assert.h. */ 115#ifndef BROKEN_ASSERT 116#include <assert.h> 117#else /* BROKEN_ASSERT */ 118#ifndef NDEBUG 119#define assert(p) ((p) ? 0 : (as_assert (__FILE__, __LINE__, __PRETTY_FUNCTION__), 0)) 120#else 121#define assert(p) ((p), 0) 122#endif 123#endif /* BROKEN_ASSERT */ 124 125#else 126 127#define assert(P) ((P) ? 0 : (as_assert (__FILE__, __LINE__, __PRETTY_FUNCTION__), 0)) 128#undef abort 129#define abort() as_abort (__FILE__, __LINE__, __PRETTY_FUNCTION__) 130 131#endif 132 133 134/* Now GNU header files... */ 135#include <ansidecl.h> 136#ifdef BFD_ASSEMBLER 137#include <bfd.h> 138#endif 139#include <libiberty.h> 140 141/* Define the standard progress macros. */ 142#include <progress.h> 143 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) 147#define inline 148#endif 149#endif /* !__MWERKS__ */ 150 151/* Other stuff from config.h. */ 152#ifdef NEED_DECLARATION_STRSTR 153extern char *strstr (); 154#endif 155#ifdef NEED_DECLARATION_MALLOC 156extern PTR malloc (); 157extern PTR realloc (); 158#endif 159#ifdef NEED_DECLARATION_FREE 160extern void free (); 161#endif 162#ifdef NEED_DECLARATION_ERRNO 163extern int errno; 164#endif 165 166/* This is needed for VMS with DEC C. */ 167#if ! defined (__GNUC__) && ! defined (HAVE_UNLINK) && defined (HAVE_REMOVE) 168#define unlink remove 169#endif 170 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) 174#endif 175 176/* Make Saber happier on obstack.h. */ 177#ifdef SABER 178#undef __PTR_TO_INT 179#define __PTR_TO_INT(P) ((int)(P)) 180#undef __INT_TO_PTR 181#define __INT_TO_PTR(P) ((char *)(P)) 182#endif 183 184#ifndef __LINE__ 185#define __LINE__ "unknown" 186#endif /* __LINE__ */ 187 188#ifndef __FILE__ 189#define __FILE__ "unknown" 190#endif /* __FILE__ */ 191 192#ifndef FOPEN_WB 193#ifdef GO32 194#include "fopen-bin.h" 195#else 196#include "fopen-same.h" 197#endif 198#endif 199 200#ifndef EXIT_SUCCESS 201#define EXIT_SUCCESS 0 202#define EXIT_FAILURE 1 203#endif 204 205#define obstack_chunk_alloc xmalloc 206#define obstack_chunk_free xfree 207 208#define xfree free 209 210#define BAD_CASE(val) \ 211{ \ 212 as_fatal("Case value %ld unexpected at line %d of file \"%s\"\n", \ 213 (long) val, __LINE__, __FILE__); \ 214 } 215 216#include "flonum.h" 217 218/* These are assembler-wide concepts */ 219 220#ifdef BFD_ASSEMBLER 221extern bfd *stdoutput; 222typedef bfd_vma addressT; 223typedef bfd_signed_vma offsetT; 224#else 225typedef unsigned long addressT; 226typedef long offsetT; 227#endif 228 229/* Type of symbol value, etc. For use in prototypes. */ 230typedef addressT valueT; 231 232#ifndef COMMON 233#ifdef TEST 234#define COMMON /* declare our COMMONs storage here. */ 235#else 236#define COMMON extern /* our commons live elswhere */ 237#endif 238#endif 239/* COMMON now defined */ 240 241#ifdef DEBUG 242#ifndef know 243#define know(p) assert(p) /* Verify our assumptions! */ 244#endif /* not yet defined */ 245#else 246#define know(p) /* know() checks are no-op.ed */ 247#endif 248 249/* input_scrub.c */ 250 251/* 252 * Supplies sanitised buffers to read.c. 253 * Also understands printing line-number part of error messages. 254 */ 255 256 257/* subsegs.c Sub-segments. Also, segment(=expression type)s.*/ 258 259#ifndef BFD_ASSEMBLER 260 261#ifdef MANY_SEGMENTS 262#include "bfd.h" 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 273#else 274#define N_SEGMENTS 3 275#define SEG_NORMAL(x) ((x) == SEG_TEXT || (x) == SEG_DATA || (x) == SEG_BSS) 276#define SEG_LIST SEG_TEXT,SEG_DATA,SEG_BSS 277#endif 278 279typedef enum _segT 280 { 281 SEG_ABSOLUTE = 0, 282 SEG_LIST, 283 SEG_UNKNOWN, 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 */ 292 } segT; 293 294#define SEG_MAXIMUM_ORDINAL (SEG_REGISTER) 295#else 296typedef asection *segT; 297#define SEG_NORMAL(SEG) ((SEG) != absolute_section \ 298 && (SEG) != undefined_section \ 299 && (SEG) != reg_section \ 300 && (SEG) != expr_section) 301#endif 302typedef int subsegT; 303 304/* What subseg we are accreting now? */ 305COMMON subsegT now_subseg; 306 307/* Segment our instructions emit to. */ 308COMMON segT now_seg; 309 310#ifdef BFD_ASSEMBLER 311#define segment_name(SEG) bfd_get_section_name (stdoutput, SEG) 312#else 313extern char const *const seg_name[]; 314#define segment_name(SEG) seg_name[(int) (SEG)] 315#endif 316 317#ifndef BFD_ASSEMBLER 318extern int section_alignment[]; 319#endif 320 321#ifdef BFD_ASSEMBLER 322extern segT reg_section, expr_section; 323/* Shouldn't these be eliminated someday? */ 324extern segT text_section, data_section, bss_section; 325#define absolute_section bfd_abs_section_ptr 326#define undefined_section bfd_und_section_ptr 327#else 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 335#endif 336 337/* relax() */ 338 339enum _relax_state 340 { 341 /* Variable chars to be repeated fr_offset times. 342 Fr_symbol unused. Used with fr_offset == 0 for a 343 constant length frag. */ 344 rs_fill = 1, 345 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. */ 350 rs_align, 351 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. */ 357 rs_align_code, 358 359 /* Org: Fr_offset, fr_symbol: address. 1 variable char: fill 360 character. */ 361 rs_org, 362 363#ifndef WORKING_DOT_WORD 364 /* JF: gunpoint */ 365 rs_broken_word, 366#endif 367 368 /* machine-specific relaxable (or similarly alterable) instruction */ 369 rs_machine_dependent, 370 371 /* .space directive with expression operand that needs to be computed 372 later. Similar to rs_org, but different. 373 fr_symbol: operand 374 1 variable char: fill character */ 375 rs_space 376 }; 377 378typedef enum _relax_state relax_stateT; 379 380/* This type is used in prototypes, so it can't be a type that will be 381 widened for argument passing. */ 382typedef unsigned int relax_substateT; 383 384/* Enough bits for address, but still an integer type. 385 Could be a problem, cross-assembling for 64-bit machines. */ 386typedef addressT relax_addressT; 387 388 389/* frags.c */ 390 391/* 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. 402 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 405 */ 406struct frag 407{ 408 /* Object file address. */ 409 addressT fr_address; 410 /* Chain forward; ascending address order. Rooted in frch_root. */ 411 struct frag *fr_next; 412 413 /* (Fixed) number of chars we know we have. May be 0. */ 414 offsetT fr_fix; 415 /* (Variable) number of chars after above. May be 0. */ 416 offsetT fr_var; 417 /* For variable-length tail. */ 418 struct symbol *fr_symbol; 419 /* For variable-length tail. */ 420 offsetT fr_offset; 421 /* Points to opcode low addr byte, for relaxation. */ 422 char *fr_opcode; 423 424#ifndef NO_LISTING 425 struct list_info_struct *line; 426#endif 427 428 /* What state is my tail in? */ 429 relax_stateT fr_type; 430 relax_substateT fr_subtype; 431 432 union { 433 /* These are needed only on the NS32K machines. But since we don't 434 include targ-cpu.h until after this structure has been defined, 435 we can't really conditionalize it. This code should be 436 rearranged a bit to make that possible. */ 437 struct { 438 char pcrel_adjust, bsr; 439 } ns32k; 440#ifdef USING_CGEN 441 /* Don't include this unless using CGEN to keep frag size down. */ 442 struct { 443 const struct cgen_insn *insn; 444 unsigned char opindex, opinfo; 445 } cgen; 446#endif 447 } fr_targ; 448 449 /* Where the frag was created, or where it became a variant frag. */ 450 char *fr_file; 451 unsigned int fr_line; 452 453 /* Data begins here. */ 454 char fr_literal[1]; 455}; 456 457#define SIZEOF_STRUCT_FRAG \ 458((char *)zero_address_frag.fr_literal-(char *)&zero_address_frag) 459/* We want to say fr_literal[0] above. */ 460 461typedef struct frag fragS; 462 463/* Current frag we are building. This frag is incomplete. It is, however, 464 included in frchain_now. The fr_fix field is bogus; instead, use: 465 obstack_next_free(&frags)-frag_now->fr_literal. */ 466COMMON fragS *frag_now; 467extern int frag_now_fix PARAMS ((void)); 468 469/* For foreign-segment symbol fixups. */ 470COMMON fragS zero_address_frag; 471/* For local common (N_BSS segment) fixups. */ 472COMMON fragS bss_address_frag; 473 474/* main program "as.c" (command arguments etc) */ 475 476COMMON unsigned char flag_no_comments; /* -f */ 477COMMON unsigned char flag_debug; /* -D */ 478COMMON unsigned char flag_signed_overflow_ok; /* -J */ 479#ifndef WORKING_DOT_WORD 480COMMON unsigned char flag_warn_displacement; /* -K */ 481#endif 482 483/* True if local symbols should be retained. */ 484COMMON int flag_keep_locals; /* -L */ 485 486/* True if we are assembling in MRI mode. */ 487COMMON int flag_mri; 488 489/* True if we are assembling in m68k MRI mode. */ 490COMMON int flag_m68k_mri; 491 492/* Should the data section be made read-only and appended to the text 493 section? */ 494COMMON unsigned char flag_readonly_data_in_text; /* -R */ 495 496/* True if warnings should be inhibited. */ 497COMMON int flag_no_warnings; /* -W */ 498 499/* True if we should attempt to generate output even if non-fatal errors 500 are detected. */ 501COMMON unsigned char flag_always_generate_output; /* -Z */ 502 503/* This is true if the assembler should output time and space usage. */ 504 505COMMON unsigned char flag_print_statistics; 506 507/* name of emitted object file */ 508COMMON char *out_file_name; 509 510/* name of file defining extensions to the basic instruction set */ 511COMMON char *insttbl_file_name; 512 513/* TRUE if we need a second pass. */ 514COMMON int need_pass_2; 515 516/* TRUE if we should do no relaxing, and 517 leave lots of padding. */ 518COMMON int linkrelax; 519 520/* TRUE if we should produce a listing. */ 521extern int listing; 522 523/* Maximum level of macro nesting. */ 524extern int max_macro_nest; 525 526/* Obstack chunk size. Keep large for efficient space use, make small to 527 increase malloc calls for monitoring memory allocation. */ 528extern int chunksize; 529 530struct _pseudo_type 531 { 532 /* assembler mnemonic, lower case, no '.' */ 533 const char *poc_name; 534 /* Do the work */ 535 void (*poc_handler) PARAMS ((int)); 536 /* Value to pass to handler */ 537 int poc_val; 538 }; 539 540typedef struct _pseudo_type pseudo_typeS; 541 542/* Prefer varargs for non-ANSI compiler, since some will barf if the 543 ellipsis definition is used with a no-arguments declaration. */ 544#if defined (HAVE_VARARGS_H) && !defined (__STDC__) 545#undef HAVE_STDARG_H 546#endif 547 548#if defined (HAVE_STDARG_H) 549#define USE_STDARG 550#endif 551#if !defined (USE_STDARG) && defined (HAVE_VARARGS_H) 552#define USE_VARARGS 553#endif 554 555#ifdef USE_STDARG 556#if (__GNUC__ >= 2) && !defined(VMS) 557/* for use with -Wformat */ 558#define PRINTF_LIKE(FCN) void FCN (const char *format, ...) \ 559 __attribute__ ((format (printf, 1, 2))) 560#define PRINTF_WHERE_LIKE(FCN) void FCN (char *file, unsigned int line, \ 561 const char *format, ...) \ 562 __attribute__ ((format (printf, 3, 4))) 563#else /* ANSI C with stdarg, but not GNU C */ 564#define PRINTF_LIKE(FCN) void FCN PARAMS ((const char *format, ...)) 565#define PRINTF_WHERE_LIKE(FCN) void FCN PARAMS ((char *file, \ 566 unsigned int line, \ 567 const char *format, ...)) 568#endif 569#else /* not using stdarg */ 570#define PRINTF_LIKE(FCN) void FCN () 571#define PRINTF_WHERE_LIKE(FCN) void FCN () 572#endif 573 574PRINTF_LIKE (as_bad); 575PRINTF_LIKE (as_fatal); 576PRINTF_LIKE (as_tsktsk); 577PRINTF_LIKE (as_warn); 578PRINTF_WHERE_LIKE (as_bad_where); 579PRINTF_WHERE_LIKE (as_warn_where); 580void as_assert PARAMS ((const char *, int, const char *)); 581void as_abort PARAMS ((const char *, int, const char *)); 582 583void fprint_value PARAMS ((FILE *file, addressT value)); 584void sprint_value PARAMS ((char *buf, addressT value)); 585 586int had_errors PARAMS ((void)); 587int had_warnings PARAMS ((void)); 588 589void print_version_id PARAMS ((void)); 590char *app_push PARAMS ((void)); 591char *atof_ieee PARAMS ((char *str, int what_kind, LITTLENUM_TYPE * words)); 592char *input_scrub_include_file PARAMS ((char *filename, char *position)); 593char *input_scrub_new_file PARAMS ((char *filename)); 594char *input_scrub_next_buffer PARAMS ((char **bufp)); 595int do_scrub_chars PARAMS ((int (*get) (char **), char *to, int tolen)); 596int gen_to_words PARAMS ((LITTLENUM_TYPE * words, int precision, 597 long exponent_bits)); 598int had_err PARAMS ((void)); 599int ignore_input PARAMS ((void)); 600void cond_finish_check PARAMS ((int)); 601void cond_exit_macro PARAMS ((int)); 602int seen_at_least_1_file PARAMS ((void)); 603void app_pop PARAMS ((char *arg)); 604void as_howmuch PARAMS ((FILE * stream)); 605void as_perror PARAMS ((const char *gripe, const char *filename)); 606void as_where PARAMS ((char **namep, unsigned int *linep)); 607void bump_line_counters PARAMS ((void)); 608void do_scrub_begin PARAMS ((int)); 609void input_scrub_begin PARAMS ((void)); 610void input_scrub_close PARAMS ((void)); 611void input_scrub_end PARAMS ((void)); 612void new_logical_line PARAMS ((char *fname, int line_number)); 613void subsegs_begin PARAMS ((void)); 614void subseg_change PARAMS ((segT seg, int subseg)); 615segT subseg_new PARAMS ((const char *name, subsegT subseg)); 616segT subseg_force_new PARAMS ((const char *name, subsegT subseg)); 617void subseg_set PARAMS ((segT seg, subsegT subseg)); 618#ifdef BFD_ASSEMBLER 619segT subseg_get PARAMS ((const char *, int)); 620#endif 621 622struct expressionS; 623struct fix; 624struct symbol; 625struct relax_type; 626 627#ifdef BFD_ASSEMBLER 628/* literal.c */ 629valueT add_to_literal_pool PARAMS ((struct symbol *, valueT, segT, int)); 630#endif 631 632#include "expr.h" /* Before targ-*.h */ 633 634/* this one starts the chain of target dependant headers */ 635#include "targ-env.h" 636 637#include "struc-symbol.h" 638#include "write.h" 639#include "frags.h" 640#include "hash.h" 641#include "read.h" 642#include "symbols.h" 643 644#include "tc.h" 645#include "obj.h" 646 647#ifdef USE_EMULATIONS 648#include "emul.h" 649#endif 650#include "listing.h" 651 652#ifndef LOCAL_LABELS_DOLLAR 653#define LOCAL_LABELS_DOLLAR 0 654#endif 655 656#ifndef LOCAL_LABELS_FB 657#define LOCAL_LABELS_FB 0 658#endif 659 660#endif /* GAS */ 661 662/* end of as.h */ 663