* subsegs.h: Include obstack.h.
[external/binutils.git] / gas / as.h
1 /* as.h - global header file
2    Copyright (C) 1987, 1990, 1991, 1992 Free Software Foundation, Inc.
3
4    This file is part of GAS, the GNU Assembler.
5
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)
9    any later version.
10
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.
15
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.  */
19
20 #ifndef GAS
21 #define GAS 1
22 /*
23  * I think this stuff is largely out of date.  xoxorich.
24  *
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.
30  *
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
34  *      COMMON as "".
35  * If TEST is #defined, then we are testing a module: #define COMMON as "".
36  */
37
38 #include "config.h"
39
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 */
46
47 /* AIX requires this to be the first thing in the file.  */
48 #ifdef __GNUC__
49 # undef alloca
50 # define alloca __builtin_alloca
51 #else
52 # if HAVE_ALLOCA_H
53 #  include <alloca.h>
54 # else
55 #  ifdef _AIX
56  #pragma alloca
57 #  else
58 #   ifndef alloca /* predefined by HP cc +Olibcalls */
59 char *alloca ();
60 #   endif
61 #  endif
62 # endif
63 #endif
64
65 /* Now, tend to the rest of the configuration.  */
66
67 /* System include files first... */
68 #include <stdio.h>
69 #include <ctype.h>
70 #ifdef HAVE_STRING_H
71 #include <string.h>
72 #else
73 #include <strings.h>
74 #endif
75 #ifdef HAVE_STDLIB_H
76 #include <stdlib.h>
77 #endif
78 #ifdef HAVE_UNISTD_H
79 #include <unistd.h>
80 #endif
81 #ifdef HAVE_SYS_TYPES_H
82 /* for size_t, pid_t */
83 #include <sys/types.h>
84 #endif
85
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 * */);
92
93 #include <getopt.h>
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
100
101 #ifdef DEBUG
102 #undef NDEBUG
103 #endif
104 /* Handle lossage with assert.h.  */
105 #ifndef BROKEN_ASSERT
106 #include <assert.h>
107 #else /* BROKEN_ASSERT */
108 #ifndef NDEBUG
109 #define assert(p) ((p) ? 0 : (abort(), 0))
110 #else
111 #define assert(p) ((p), 0)
112 #endif
113 #endif /* BROKEN_ASSERT */
114
115
116 /* Now GNU header files... */
117 #include <ansidecl.h>
118 #ifdef BFD_ASSEMBLER
119 #include <bfd.h>
120 #endif
121
122 /* Define the standard progress macros.  */
123 #include <progress.h>
124
125 /* This doesn't get taken care of anywhere.  */
126 #if !defined (__GNUC__) && !defined (inline)
127 #define inline
128 #endif
129
130 /* Other stuff from config.h.  */
131 #ifdef NEED_DECLARATION_MALLOC
132 extern PTR malloc ();
133 extern PTR realloc ();
134 #endif
135 #ifdef NEED_DECLARATION_FREE
136 extern void free ();
137 #endif
138 #ifdef NEED_DECLARATION_ERRNO
139 extern int errno;
140 #endif
141
142 /* This is needed for VMS.  */
143 #if ! defined (HAVE_UNLINK) && defined (HAVE_REMOVE)
144 #define unlink remove
145 #endif
146
147 #ifdef BFD_ASSEMBLER
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
150    it's not.  */
151 extern PTR bfd_alloc_by_size_t PARAMS ((bfd *abfd, size_t sz));
152 #endif
153
154 /* Make Saber happier on obstack.h.  */
155 #ifdef SABER
156 #undef  __PTR_TO_INT
157 #define __PTR_TO_INT(P) ((int)(P))
158 #undef  __INT_TO_PTR
159 #define __INT_TO_PTR(P) ((char *)(P))
160 #endif
161
162 #ifndef __LINE__
163 #define __LINE__ "unknown"
164 #endif /* __LINE__ */
165
166 #ifndef __FILE__
167 #define __FILE__ "unknown"
168 #endif /* __FILE__ */
169
170 #ifndef __STDC__
171 #ifndef const
172 #define const
173 #endif
174 #ifndef volatile
175 #define volatile
176 #endif
177 #endif /* ! __STDC__ */
178
179 #if !defined (__GNUC__) && !defined (inline)
180 #define inline
181 #endif
182
183 #ifndef FOPEN_WB
184 #ifdef GO32
185 #include "fopen-bin.h"
186 #else
187 #include "fopen-same.h"
188 #endif
189 #endif
190
191 #ifndef EXIT_SUCCESS
192 #define EXIT_SUCCESS 0
193 #define EXIT_FAILURE 1
194 #endif
195
196 #define obstack_chunk_alloc xmalloc
197 #define obstack_chunk_free xfree
198
199 #define xfree free
200
201 #define BAD_CASE(val) \
202 { \
203       as_fatal("Case value %ld unexpected at line %d of file \"%s\"\n", \
204                (long) val, __LINE__, __FILE__); \
205            }
206
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 ();
211 \f
212 #include "flonum.h"
213
214 /* These are assembler-wide concepts */
215
216 #ifdef BFD_ASSEMBLER
217 extern bfd *stdoutput;
218 typedef bfd_vma addressT;
219 typedef bfd_signed_vma offsetT;
220 #else
221 typedef unsigned long addressT;
222 typedef long offsetT;
223 #endif
224
225 /* Type of symbol value, etc.  For use in prototypes.  */
226 typedef addressT valueT;
227
228 #ifndef COMMON
229 #ifdef TEST
230 #define COMMON                  /* declare our COMMONs storage here. */
231 #else
232 #define COMMON extern           /* our commons live elswhere */
233 #endif
234 #endif
235 /* COMMON now defined */
236
237 #ifdef DEBUG
238 #ifndef know
239 #define know(p) assert(p)       /* Verify our assumptions! */
240 #endif /* not yet defined */
241 #else
242 #define know(p)                 /* know() checks are no-op.ed */
243 #endif
244 \f
245 /* input_scrub.c */
246
247 /*
248  * Supplies sanitised buffers to read.c.
249  * Also understands printing line-number part of error messages.
250  */
251 \f
252
253 /* subsegs.c     Sub-segments. Also, segment(=expression type)s.*/
254
255 #ifndef BFD_ASSEMBLER
256
257 #ifdef MANY_SEGMENTS
258 #include "bfd.h"
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
265 #else
266 #define N_SEGMENTS 3
267 #define SEG_NORMAL(x) ((x) == SEG_TEXT || (x) == SEG_DATA || (x) == SEG_BSS)
268 #define SEG_LIST SEG_TEXT,SEG_DATA,SEG_BSS
269 #endif
270
271 typedef enum _segT
272   {
273     SEG_ABSOLUTE = 0,
274     SEG_LIST,
275     SEG_UNKNOWN,
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 */
284   } segT;
285
286 #define SEG_MAXIMUM_ORDINAL (SEG_REGISTER)
287 #else
288 typedef asection *segT;
289 #define SEG_NORMAL(SEG)         ((SEG) != absolute_section      \
290                                  && (SEG) != undefined_section  \
291                                  && (SEG) != reg_section        \
292                                  && (SEG) != expr_section)
293 #endif
294 typedef int subsegT;
295
296 /* What subseg we are accreting now? */
297 COMMON subsegT now_subseg;
298
299 /* Segment our instructions emit to. */
300 COMMON segT now_seg;
301
302 #ifdef BFD_ASSEMBLER
303 #define segment_name(SEG)       bfd_get_section_name (stdoutput, SEG)
304 #else
305 extern char *const seg_name[];
306 #define segment_name(SEG)       seg_name[(int) (SEG)]
307 #endif
308
309 #ifndef BFD_ASSEMBLER
310 extern int section_alignment[];
311 #endif
312
313 #ifdef BFD_ASSEMBLER
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
319 #else
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
327 #endif
328
329 /* relax() */
330
331 typedef enum _relax_state
332   {
333     /* Variable chars to be repeated fr_offset times.
334        Fr_symbol unused. Used with fr_offset == 0 for a
335        constant length frag. */
336     rs_fill = 1,
337
338     /* Align: Fr_offset: power of 2.  Variable chars: fill pattern. */
339     rs_align,
340
341     /* Org: Fr_offset, fr_symbol: address. 1 variable char: fill
342        character. */
343     rs_org,
344
345     rs_machine_dependent
346
347 #ifndef WORKING_DOT_WORD
348     /* JF: gunpoint */
349       , rs_broken_word
350 #endif
351   } relax_stateT;
352
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;
357
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;
361 \f
362
363 /* frags.c */
364
365 /*
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.
376
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
379  */
380 struct frag
381 {
382   /* Object file address. */
383   addressT fr_address;
384   /* Chain forward; ascending address order.  Rooted in frch_root. */
385   struct frag *fr_next;
386
387   /* (Fixed) number of chars we know we have.  May be 0. */
388   offsetT fr_fix;
389   /* (Variable) number of chars after above.  May be 0. */
390   offsetT fr_var;
391   /* For variable-length tail. */
392   struct symbol *fr_symbol;
393   /* For variable-length tail. */
394   offsetT fr_offset;
395   /* Points to opcode low addr byte, for relaxation.  */
396   char *fr_opcode;
397
398 #ifndef NO_LISTING
399   struct list_info_struct *line;
400 #endif
401
402   /* What state is my tail in? */
403   relax_stateT fr_type;
404   relax_substateT fr_subtype;
405
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;
410
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.
415
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;
419
420   /* Data begins here.  */
421   char fr_literal[1];
422 };
423
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. */
427
428 typedef struct frag fragS;
429
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 ();
435
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;
440
441 /* main program "as.c" (command arguments etc) */
442
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 */
447
448 /* True if local symbols should be retained.  */
449 COMMON unsigned char flag_keep_locals; /* -L */
450
451 /* Should the data section be made read-only and appended to the text
452    section?  */
453 COMMON unsigned char flag_readonly_data_in_text; /* -R */
454
455 /* True if warnings should be inhibited.  */
456 COMMON unsigned char flag_no_warnings; /* -W */
457
458 /* True if we should attempt to generate output even if non-fatal errors
459    are detected.  */
460 COMMON unsigned char flag_always_generate_output; /* -Z */
461
462 /* This is true if the assembler should output time and space usage. */
463
464 COMMON unsigned char flag_print_statistics;
465
466 /* name of emitted object file */
467 COMMON char *out_file_name;
468
469 /* TRUE if we need a second pass. */
470 COMMON int need_pass_2;
471
472 /* TRUE if we should do no relaxing, and
473    leave lots of padding.  */
474 COMMON int linkrelax;
475
476 /* TRUE if we should produce a listing.  */
477 extern int listing;
478
479 struct _pseudo_type
480   {
481     /* assembler mnemonic, lower case, no '.' */
482     char *poc_name;
483     /* Do the work */
484     void (*poc_handler) PARAMS ((int));
485     /* Value to pass to handler */
486     int poc_val;
487   };
488
489 typedef struct _pseudo_type pseudo_typeS;
490
491 #ifdef BFD_ASSEMBLER_xxx
492 struct lineno_struct
493   {
494     alent line;
495     fragS *frag;
496     struct lineno_struct *next;
497   };
498 typedef struct lineno_struct lineno;
499 #endif
500
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__)
504 #undef HAVE_STDARG_H
505 #endif
506
507 #if defined (HAVE_STDARG_H)
508 #define USE_STDARG
509 #endif
510 #if !defined (USE_STDARG) && defined (HAVE_VARARGS_H)
511 #define USE_VARARGS
512 #endif
513
514 #ifdef USE_STDARG
515 #if __GNUC__ >= 2
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, \
525                                                   unsigned int line, \
526                                                   const char *format, ...))
527 #endif
528 #else /* not using stdarg */
529 #define PRINTF_LIKE(FCN)        void FCN ()
530 #define PRINTF_WHERE_LIKE(FCN)  void FCN ()
531 #endif
532
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);
539
540 void fprint_value PARAMS ((FILE *file, addressT value));
541 void sprint_value PARAMS ((char *buf, addressT value));
542
543 int had_errors PARAMS ((void));
544 int had_warnings PARAMS ((void));
545
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));
579 #ifdef BFD_ASSEMBLER
580 segT subseg_get PARAMS ((const char *, int));
581 #endif
582
583 struct expressionS;
584 struct fix;
585 struct symbol;
586
587 #ifdef BFD_ASSEMBLER
588 /* literal.c */
589 valueT add_to_literal_pool PARAMS ((struct symbol *, valueT, segT, int));
590 #endif
591
592 #include "expr.h"               /* Before targ-*.h */
593
594 /* this one starts the chain of target dependant headers */
595 #include "targ-env.h"
596
597 #include "struc-symbol.h"
598 #include "write.h"
599 #include "frags.h"
600 #include "hash.h"
601 #include "read.h"
602 #include "symbols.h"
603
604 #include "tc.h"
605 #include "obj.h"
606
607 #include "listing.h"
608
609 #ifdef BFD_ASSEMBLER
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
613 #endif
614 #ifdef OBJ_COFF
615 #define OUTPUT_FLAVOR bfd_target_coff_flavour
616 #endif
617 #ifdef OBJ_ECOFF
618 #define OUTPUT_FLAVOR bfd_target_ecoff_flavour
619 #endif
620 #ifdef OBJ_ELF
621 #define OUTPUT_FLAVOR bfd_target_elf_flavour
622 #endif
623 #endif /* BFD_ASSEMBLER */
624
625 #endif /* GAS */
626
627 /* end of as.h */