* frags.c (frag_init): Call obstack_begin on `frags'.
[deliverable/binutils-gdb.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 #if 0 /* not yet */
407 /* Track the alignment and offset of the current frag. With this,
408 sometimes we can avoid creating new frags for .align directives. */
409 unsigned short align_mask;
410 unsigned short align_offset;
411 #endif
412
413 /* These are needed only on the NS32K machines. But since we don't
414 include targ-cpu.h until after this structure has been defined,
415 we can't really conditionalize it. This code should be
416 rearranged a bit to make that possible.
417
418 In the meantime, if we get stuck like this with any other target,
419 create a union here. */
420 char fr_pcrel_adjust, fr_bsr;
421
422 /* Data begins here. */
423 char fr_literal[1];
424 };
425
426 #define SIZEOF_STRUCT_FRAG \
427 ((char *)zero_address_frag.fr_literal-(char *)&zero_address_frag)
428 /* We want to say fr_literal[0] above. */
429
430 typedef struct frag fragS;
431
432 /* Current frag we are building. This frag is incomplete. It is, however,
433 included in frchain_now. The fr_fix field is bogus; instead, use:
434 obstack_next_free(&frags)-frag_now->fr_literal. */
435 COMMON fragS *frag_now;
436 extern int frag_now_fix ();
437
438 /* For foreign-segment symbol fixups. */
439 COMMON fragS zero_address_frag;
440 /* For local common (N_BSS segment) fixups. */
441 COMMON fragS bss_address_frag;
442
443 /* main program "as.c" (command arguments etc) */
444
445 COMMON unsigned char flag_no_comments; /* -f */
446 COMMON unsigned char flag_debug; /* -D */
447 COMMON unsigned char flag_signed_overflow_ok; /* -J */
448 COMMON unsigned char flag_warn_displacement; /* -K */
449
450 /* True if local symbols should be retained. */
451 COMMON unsigned char flag_keep_locals; /* -L */
452
453 /* Should the data section be made read-only and appended to the text
454 section? */
455 COMMON unsigned char flag_readonly_data_in_text; /* -R */
456
457 /* True if warnings should be inhibited. */
458 COMMON unsigned char flag_no_warnings; /* -W */
459
460 /* True if we should attempt to generate output even if non-fatal errors
461 are detected. */
462 COMMON unsigned char flag_always_generate_output; /* -Z */
463
464 /* This is true if the assembler should output time and space usage. */
465
466 COMMON unsigned char flag_print_statistics;
467
468 /* name of emitted object file */
469 COMMON char *out_file_name;
470
471 /* TRUE if we need a second pass. */
472 COMMON int need_pass_2;
473
474 /* TRUE if we should do no relaxing, and
475 leave lots of padding. */
476 COMMON int linkrelax;
477
478 /* TRUE if we should produce a listing. */
479 extern int listing;
480
481 struct _pseudo_type
482 {
483 /* assembler mnemonic, lower case, no '.' */
484 char *poc_name;
485 /* Do the work */
486 void (*poc_handler) PARAMS ((int));
487 /* Value to pass to handler */
488 int poc_val;
489 };
490
491 typedef struct _pseudo_type pseudo_typeS;
492
493 #ifdef BFD_ASSEMBLER_xxx
494 struct lineno_struct
495 {
496 alent line;
497 fragS *frag;
498 struct lineno_struct *next;
499 };
500 typedef struct lineno_struct lineno;
501 #endif
502
503 /* Prefer varargs for non-ANSI compiler, since some will barf if the
504 ellipsis definition is used with a no-arguments declaration. */
505 #if defined (HAVE_VARARGS_H) && !defined (__STDC__)
506 #undef HAVE_STDARG_H
507 #endif
508
509 #if defined (HAVE_STDARG_H)
510 #define USE_STDARG
511 #endif
512 #if !defined (USE_STDARG) && defined (HAVE_VARARGS_H)
513 #define USE_VARARGS
514 #endif
515
516 #ifdef USE_STDARG
517 #if __GNUC__ >= 2
518 /* for use with -Wformat */
519 #define PRINTF_LIKE(FCN) void FCN (const char *format, ...) \
520 __attribute__ ((format (printf, 1, 2)))
521 #define PRINTF_WHERE_LIKE(FCN) void FCN (char *file, unsigned int line, \
522 const char *format, ...) \
523 __attribute__ ((format (printf, 3, 4)))
524 #else /* ANSI C with stdarg, but not GNU C */
525 #define PRINTF_LIKE(FCN) void FCN PARAMS ((const char *format, ...))
526 #define PRINTF_WHERE_LIKE(FCN) void FCN PARAMS ((char *file, \
527 unsigned int line, \
528 const char *format, ...))
529 #endif
530 #else /* not using stdarg */
531 #define PRINTF_LIKE(FCN) void FCN ()
532 #define PRINTF_WHERE_LIKE(FCN) void FCN ()
533 #endif
534
535 PRINTF_LIKE (as_bad);
536 PRINTF_LIKE (as_fatal);
537 PRINTF_LIKE (as_tsktsk);
538 PRINTF_LIKE (as_warn);
539 PRINTF_WHERE_LIKE (as_bad_where);
540 PRINTF_WHERE_LIKE (as_warn_where);
541
542 void fprint_value PARAMS ((FILE *file, addressT value));
543 void sprint_value PARAMS ((char *buf, addressT value));
544
545 int had_errors PARAMS ((void));
546 int had_warnings PARAMS ((void));
547
548 void print_version_id PARAMS ((void));
549 char *app_push PARAMS ((void));
550 char *atof_ieee PARAMS ((char *str, int what_kind, LITTLENUM_TYPE * words));
551 char *input_scrub_include_file PARAMS ((char *filename, char *position));
552 char *input_scrub_new_file PARAMS ((char *filename));
553 char *input_scrub_next_buffer PARAMS ((char **bufp));
554 PTR xmalloc PARAMS ((unsigned long size));
555 PTR xrealloc PARAMS ((PTR ptr, unsigned long n));
556 int do_scrub_next_char PARAMS ((int (*get) (void), void (*unget) (int)));
557 int gen_to_words PARAMS ((LITTLENUM_TYPE * words, int precision,
558 long exponent_bits));
559 int had_err PARAMS ((void));
560 int ignore_input PARAMS ((void));
561 int scrub_from_file PARAMS ((void));
562 int scrub_from_string PARAMS ((void));
563 int seen_at_least_1_file PARAMS ((void));
564 void app_pop PARAMS ((char *arg));
565 void as_howmuch PARAMS ((FILE * stream));
566 void as_perror PARAMS ((const char *gripe, const char *filename));
567 void as_where PARAMS ((char **namep, unsigned int *linep));
568 void bump_line_counters PARAMS ((void));
569 void do_scrub_begin PARAMS ((void));
570 void input_scrub_begin PARAMS ((void));
571 void input_scrub_close PARAMS ((void));
572 void input_scrub_end PARAMS ((void));
573 void new_logical_line PARAMS ((char *fname, int line_number));
574 void scrub_to_file PARAMS ((int ch));
575 void scrub_to_string PARAMS ((int ch));
576 void subsegs_begin PARAMS ((void));
577 void subseg_change PARAMS ((segT seg, int subseg));
578 segT subseg_new PARAMS ((const char *name, subsegT subseg));
579 segT subseg_force_new PARAMS ((const char *name, subsegT subseg));
580 void subseg_set PARAMS ((segT seg, subsegT subseg));
581 #ifdef BFD_ASSEMBLER
582 segT subseg_get PARAMS ((const char *, int));
583 #endif
584
585 struct expressionS;
586 struct fix;
587 struct symbol;
588
589 #ifdef BFD_ASSEMBLER
590 /* literal.c */
591 valueT add_to_literal_pool PARAMS ((struct symbol *, valueT, segT, int));
592 #endif
593
594 #include "expr.h" /* Before targ-*.h */
595
596 /* this one starts the chain of target dependant headers */
597 #include "targ-env.h"
598
599 #include "struc-symbol.h"
600 #include "write.h"
601 #include "frags.h"
602 #include "hash.h"
603 #include "read.h"
604 #include "symbols.h"
605
606 #include "tc.h"
607 #include "obj.h"
608
609 #include "listing.h"
610
611 #ifdef BFD_ASSEMBLER
612 /* Someday perhaps this will be selectable at run-time. */
613 #if defined (OBJ_AOUT) || defined (OBJ_BOUT)
614 #define OUTPUT_FLAVOR bfd_target_aout_flavour
615 #endif
616 #ifdef OBJ_COFF
617 #define OUTPUT_FLAVOR bfd_target_coff_flavour
618 #endif
619 #ifdef OBJ_ECOFF
620 #define OUTPUT_FLAVOR bfd_target_ecoff_flavour
621 #endif
622 #ifdef OBJ_ELF
623 #define OUTPUT_FLAVOR bfd_target_elf_flavour
624 #endif
625 #endif /* BFD_ASSEMBLER */
626
627 #endif /* GAS */
628
629 /* end of as.h */
This page took 0.050981 seconds and 4 git commands to generate.