f51a210cac73e879205cba09749b42f2a413679b
[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 --
41 verbatim. If it doesn't work for you, let me know, and notify
42 djm@gnu.ai.mit.edu as well. */
43 /* AIX requires this to be the first thing in the file. */
44 #ifdef __GNUC__
45 # define alloca __builtin_alloca
46 #else
47 # if HAVE_ALLOCA_H
48 # include <alloca.h>
49 # else
50 # ifdef _AIX
51 #pragma alloca
52 # else
53 # ifndef alloca /* predefined by HP cc +Olibcalls */
54 char *alloca ();
55 # endif
56 # endif
57 # endif
58 #endif
59
60 /* Now, tend to the rest of the configuration. */
61
62 /* System include files first... */
63 #include <stdio.h>
64 #include <ctype.h>
65 #ifdef HAVE_STRING_H
66 #include <string.h>
67 #else
68 #include <strings.h>
69 #endif
70 #ifdef HAVE_STDLIB_H
71 #include <stdlib.h>
72 #endif
73 #ifdef HAVE_UNISTD_H
74 #include <unistd.h>
75 #endif
76 #ifdef HAVE_SYS_TYPES_H
77 /* for size_t, pid_t */
78 #include <sys/types.h>
79 #endif
80
81 /* Some systems do declare this, but this seems to be the universal
82 declaration, though the parameter type varies. (It ought to use
83 `const' but many systems prototype it without.) Include it here
84 for systems that don't declare it. If conflicts arise, just add
85 another autoconf test... */
86 extern char *strdup (/* const char * */);
87
88 #include <getopt.h>
89 /* The first getopt value for machine-independent long options.
90 150 isn't special; it's just an arbitrary non-ASCII char value. */
91 #define OPTION_STD_BASE 150
92 /* The first getopt value for machine-dependent long options.
93 170 gives the standard options room to grow. */
94 #define OPTION_MD_BASE 170
95
96 #ifdef DEBUG
97 #undef NDEBUG
98 #endif
99 /* Handle lossage with assert.h. */
100 #ifndef BROKEN_ASSERT
101 #include <assert.h>
102 #else /* BROKEN_ASSERT */
103 #ifndef NDEBUG
104 #define assert(p) ((p) ? 0 : (abort(), 0))
105 #else
106 #define assert(p) ((p), 0)
107 #endif
108 #endif /* BROKEN_ASSERT */
109
110
111 /* Now GNU header files... */
112 #include <ansidecl.h>
113 #ifdef BFD_ASSEMBLER
114 #include <bfd.h>
115 #endif
116
117 #ifdef WANT_FOPEN_BIN
118 #include "fopen-bin.h"
119 #else
120 #include "fopen-same.h"
121 #endif
122
123 /* This doesn't get taken care of anywhere. */
124 #if !defined (__GNUC__) && !defined (inline)
125 #define inline
126 #endif
127
128 /* Other stuff from config.h. */
129 #ifdef NEED_MALLOC_DECLARATION
130 extern PTR malloc ();
131 extern PTR realloc ();
132 #endif
133 #ifdef NEED_FREE_DECLARATION
134 extern void free ();
135 #endif
136
137 #ifdef USE_DELETE_FOR_UNLINK
138 #define unlink delete
139 #endif
140
141 #ifdef BFD_ASSEMBLER
142 /* This one doesn't get declared, but we're using it anyways. This
143 should be fixed -- either it's part of the external interface or
144 it's not. */
145 extern PTR bfd_alloc_by_size_t PARAMS ((bfd *abfd, size_t sz));
146 #endif
147
148 /* Make Saber happier on obstack.h. */
149 #ifdef SABER
150 #undef __PTR_TO_INT
151 #define __PTR_TO_INT(P) ((int)(P))
152 #undef __INT_TO_PTR
153 #define __INT_TO_PTR(P) ((char *)(P))
154 #endif
155
156 #ifndef __LINE__
157 #define __LINE__ "unknown"
158 #endif /* __LINE__ */
159
160 #ifndef __FILE__
161 #define __FILE__ "unknown"
162 #endif /* __FILE__ */
163
164 #ifndef __STDC__
165 #ifndef const
166 #define const
167 #endif
168 #ifndef volatile
169 #define volatile
170 #endif
171 #endif /* ! __STDC__ */
172
173 #if !defined (__GNUC__) && !defined (inline)
174 #define inline
175 #endif
176
177 #ifndef FOPEN_WB
178 #ifdef GO32
179 #include "fopen-bin.h"
180 #else
181 #include "fopen-same.h"
182 #endif
183 #endif
184
185 #ifndef EXIT_SUCCESS
186 #define EXIT_SUCCESS 0
187 #define EXIT_FAILURE 1
188 #endif
189
190 #define obstack_chunk_alloc xmalloc
191 #define obstack_chunk_free xfree
192
193 #define xfree free
194
195 #define BAD_CASE(val) \
196 { \
197 as_fatal("Case value %ld unexpected at line %d of file \"%s\"\n", \
198 (long) val, __LINE__, __FILE__); \
199 }
200
201 /* Version 2.1 of Solaris had problems with this declaration, but I
202 think that bug has since been fixed. If it causes problems on your
203 system, just delete it. */
204 extern char *strstr ();
205 \f
206 #include "flonum.h"
207
208 /* These are assembler-wide concepts */
209
210 #ifdef BFD_ASSEMBLER
211 extern bfd *stdoutput;
212 typedef bfd_vma addressT;
213 typedef bfd_signed_vma offsetT;
214 #else
215 typedef unsigned long addressT;
216 typedef long offsetT;
217 #endif
218
219 /* Type of symbol value, etc. For use in prototypes. */
220 typedef addressT valueT;
221
222 #ifndef COMMON
223 #ifdef TEST
224 #define COMMON /* declare our COMMONs storage here. */
225 #else
226 #define COMMON extern /* our commons live elswhere */
227 #endif
228 #endif
229 /* COMMON now defined */
230
231 #ifdef DEBUG
232 #ifndef know
233 #define know(p) assert(p) /* Verify our assumptions! */
234 #endif /* not yet defined */
235 #else
236 #define know(p) /* know() checks are no-op.ed */
237 #endif
238 \f
239 /* input_scrub.c */
240
241 /*
242 * Supplies sanitised buffers to read.c.
243 * Also understands printing line-number part of error messages.
244 */
245 \f
246
247 /* subsegs.c Sub-segments. Also, segment(=expression type)s.*/
248
249 #ifndef BFD_ASSEMBLER
250
251 #ifdef MANY_SEGMENTS
252 #include "bfd.h"
253 #define N_SEGMENTS 10
254 #define SEG_NORMAL(x) ((x) >= SEG_E0 && (x) <= SEG_E9)
255 #define SEG_LIST SEG_E0,SEG_E1,SEG_E2,SEG_E3,SEG_E4,SEG_E5,SEG_E6,SEG_E7,SEG_E8,SEG_E9
256 #define SEG_TEXT SEG_E0
257 #define SEG_DATA SEG_E1
258 #define SEG_BSS SEG_E2
259 #else
260 #define N_SEGMENTS 3
261 #define SEG_NORMAL(x) ((x) == SEG_TEXT || (x) == SEG_DATA || (x) == SEG_BSS)
262 #define SEG_LIST SEG_TEXT,SEG_DATA,SEG_BSS
263 #endif
264
265 typedef enum _segT
266 {
267 SEG_ABSOLUTE = 0,
268 SEG_LIST,
269 SEG_UNKNOWN,
270 SEG_GOOF, /* Only happens if AS has a logic error. */
271 /* Invented so we don't crash printing */
272 /* error message involving weird segment. */
273 SEG_EXPR, /* Intermediate expression values. */
274 SEG_DEBUG, /* Debug segment */
275 SEG_NTV, /* Transfert vector preload segment */
276 SEG_PTV, /* Transfert vector postload segment */
277 SEG_REGISTER /* Mythical: a register-valued expression */
278 } segT;
279
280 #define SEG_MAXIMUM_ORDINAL (SEG_REGISTER)
281 #else
282 typedef asection *segT;
283 #define SEG_NORMAL(SEG) ((SEG) != absolute_section \
284 && (SEG) != undefined_section \
285 && (SEG) != reg_section \
286 && (SEG) != expr_section)
287 #endif
288 typedef int subsegT;
289
290 /* What subseg we are accreting now? */
291 COMMON subsegT now_subseg;
292
293 /* Segment our instructions emit to. */
294 COMMON segT now_seg;
295
296 #ifdef BFD_ASSEMBLER
297 #define segment_name(SEG) bfd_get_section_name (stdoutput, SEG)
298 #else
299 extern char *const seg_name[];
300 #define segment_name(SEG) seg_name[(int) (SEG)]
301 #endif
302
303 #ifndef BFD_ASSEMBLER
304 extern int section_alignment[];
305 #endif
306
307 #ifdef BFD_ASSEMBLER
308 extern segT reg_section, expr_section;
309 /* Shouldn't these be eliminated someday? */
310 extern segT text_section, data_section, bss_section;
311 #define absolute_section bfd_abs_section_ptr
312 #define undefined_section bfd_und_section_ptr
313 #else
314 #define reg_section SEG_REGISTER
315 #define expr_section SEG_EXPR
316 #define text_section SEG_TEXT
317 #define data_section SEG_DATA
318 #define bss_section SEG_BSS
319 #define absolute_section SEG_ABSOLUTE
320 #define undefined_section SEG_UNKNOWN
321 #endif
322
323 /* relax() */
324
325 typedef enum _relax_state
326 {
327 /* Variable chars to be repeated fr_offset times.
328 Fr_symbol unused. Used with fr_offset == 0 for a
329 constant length frag. */
330 rs_fill = 1,
331
332 /* Align: Fr_offset: power of 2. Variable chars: fill pattern. */
333 rs_align,
334
335 /* Org: Fr_offset, fr_symbol: address. 1 variable char: fill
336 character. */
337 rs_org,
338
339 rs_machine_dependent
340
341 #ifndef WORKING_DOT_WORD
342 /* JF: gunpoint */
343 , rs_broken_word
344 #endif
345 } relax_stateT;
346
347 /* typedef unsigned char relax_substateT; */
348 /* JF this is more likely to leave the end of a struct frag on an align
349 boundry. Be very careful with this. */
350 typedef unsigned long relax_substateT;
351
352 /* Enough bits for address, but still an integer type.
353 Could be a problem, cross-assembling for 64-bit machines. */
354 typedef addressT relax_addressT;
355 \f
356
357 /* frags.c */
358
359 /*
360 * A code fragment (frag) is some known number of chars, followed by some
361 * unknown number of chars. Typically the unknown number of chars is an
362 * instruction address whose size is yet unknown. We always know the greatest
363 * possible size the unknown number of chars may become, and reserve that
364 * much room at the end of the frag.
365 * Once created, frags do not change address during assembly.
366 * We chain the frags in (a) forward-linked list(s). The object-file address
367 * of the 1st char of a frag is generally not known until after relax().
368 * Many things at assembly time describe an address by {object-file-address
369 * of a particular frag}+offset.
370
371 BUG: it may be smarter to have a single pointer off to various different
372 notes for different frag kinds. See how code pans
373 */
374 struct frag
375 {
376 /* Object file address. */
377 addressT fr_address;
378 /* Chain forward; ascending address order. Rooted in frch_root. */
379 struct frag *fr_next;
380
381 /* (Fixed) number of chars we know we have. May be 0. */
382 offsetT fr_fix;
383 /* (Variable) number of chars after above. May be 0. */
384 offsetT fr_var;
385 /* For variable-length tail. */
386 struct symbol *fr_symbol;
387 /* For variable-length tail. */
388 offsetT fr_offset;
389 /* Points to opcode low addr byte, for relaxation. */
390 char *fr_opcode;
391
392 #ifndef NO_LISTING
393 struct list_info_struct *line;
394 #endif
395
396 /* What state is my tail in? */
397 relax_stateT fr_type;
398 relax_substateT fr_subtype;
399
400 /* These are needed only on the NS32K machines. But since we don't
401 include targ-cpu.h until after this structure has been defined,
402 we can't really conditionalize it. This code should be
403 rearranged a bit to make that possible.
404
405 In the meantime, if we get stuck like this with any other target,
406 create a union here. */
407 char fr_pcrel_adjust, fr_bsr;
408
409 /* Data begins here. */
410 char fr_literal[1];
411 };
412
413 #define SIZEOF_STRUCT_FRAG \
414 ((char *)zero_address_frag.fr_literal-(char *)&zero_address_frag)
415 /* We want to say fr_literal[0] above. */
416
417 typedef struct frag fragS;
418
419 /* Current frag we are building. This frag is incomplete. It is, however,
420 included in frchain_now. The fr_fix field is bogus; instead, use:
421 obstack_next_free(&frags)-frag_now->fr_literal. */
422 COMMON fragS *frag_now;
423 #define frag_now_fix() ((char*)obstack_next_free (&frags) - frag_now->fr_literal)
424
425 /* For foreign-segment symbol fixups. */
426 COMMON fragS zero_address_frag;
427 /* For local common (N_BSS segment) fixups. */
428 COMMON fragS bss_address_frag;
429
430 /* main program "as.c" (command arguments etc) */
431
432 COMMON unsigned char flag_no_comments; /* -f */
433 COMMON unsigned char flag_debug; /* -D */
434 COMMON unsigned char flag_signed_overflow_ok; /* -J */
435 COMMON unsigned char flag_warn_displacement; /* -K */
436
437 /* True if local symbols should be retained. */
438 COMMON unsigned char flag_keep_locals; /* -L */
439
440 /* Should the data section be made read-only and appended to the text
441 section? */
442 COMMON unsigned char flag_readonly_data_in_text; /* -R */
443
444 /* True if warnings should be inhibited. */
445 COMMON unsigned char flag_no_warnings; /* -W */
446
447 /* True if we should attempt to generate output even if non-fatal errors
448 are detected. */
449 COMMON unsigned char flag_always_generate_output; /* -Z */
450
451 /* This is true if the assembler should output time and space usage. */
452
453 COMMON unsigned char flag_print_statistics;
454
455 /* name of emitted object file */
456 COMMON char *out_file_name;
457
458 /* TRUE if we need a second pass. */
459 COMMON int need_pass_2;
460
461 /* TRUE if we should do no relaxing, and
462 leave lots of padding. */
463 COMMON int linkrelax;
464
465 /* TRUE if we should produce a listing. */
466 extern int listing;
467
468 struct _pseudo_type
469 {
470 /* assembler mnemonic, lower case, no '.' */
471 char *poc_name;
472 /* Do the work */
473 void (*poc_handler) PARAMS ((int));
474 /* Value to pass to handler */
475 int poc_val;
476 };
477
478 typedef struct _pseudo_type pseudo_typeS;
479
480 #ifdef BFD_ASSEMBLER_xxx
481 struct lineno_struct
482 {
483 alent line;
484 fragS *frag;
485 struct lineno_struct *next;
486 };
487 typedef struct lineno_struct lineno;
488 #endif
489
490 #if defined (__STDC__) && !defined(NO_STDARG)
491
492 #if __GNUC__ >= 2
493 /* for use with -Wformat */
494 #define PRINTF_LIKE(FCN) void FCN (const char *format, ...) \
495 __attribute__ ((format (printf, 1, 2)))
496 #define PRINTF_WHERE_LIKE(FCN) void FCN (char *file, unsigned int line, \
497 const char *format, ...) \
498 __attribute__ ((format (printf, 3, 4)))
499 #else /* ANSI C with stdarg, but not GNU C */
500 #define PRINTF_LIKE(FCN) void FCN (const char *format, ...)
501 #define PRINTF_WHERE_LIKE(FCN) void FCN (char *file, unsigned int line, \
502 const char *format, ...)
503 #endif
504 #else /* not ANSI C, or not stdarg */
505 #define PRINTF_LIKE(FCN) void FCN ()
506 #define PRINTF_WHERE_LIKE(FCN) void FCN ()
507 #endif
508
509 PRINTF_LIKE (as_bad);
510 PRINTF_LIKE (as_fatal);
511 PRINTF_LIKE (as_tsktsk);
512 PRINTF_LIKE (as_warn);
513 PRINTF_WHERE_LIKE (as_bad_where);
514 PRINTF_WHERE_LIKE (as_warn_where);
515
516 void fprint_value PARAMS ((FILE *file, addressT value));
517 void sprint_value PARAMS ((char *buf, addressT value));
518
519 int had_errors PARAMS ((void));
520 int had_warnings PARAMS ((void));
521
522 void print_version_id PARAMS ((void));
523 char *app_push PARAMS ((void));
524 char *atof_ieee PARAMS ((char *str, int what_kind, LITTLENUM_TYPE * words));
525 char *input_scrub_include_file PARAMS ((char *filename, char *position));
526 char *input_scrub_new_file PARAMS ((char *filename));
527 char *input_scrub_next_buffer PARAMS ((char **bufp));
528 PTR xmalloc PARAMS ((unsigned long size));
529 PTR xrealloc PARAMS ((PTR ptr, unsigned long n));
530 int do_scrub_next_char PARAMS ((int (*get) (void), void (*unget) (int)));
531 int gen_to_words PARAMS ((LITTLENUM_TYPE * words, int precision,
532 long exponent_bits));
533 int had_err PARAMS ((void));
534 int ignore_input PARAMS ((void));
535 int scrub_from_file PARAMS ((void));
536 int scrub_from_string PARAMS ((void));
537 int seen_at_least_1_file PARAMS ((void));
538 void app_pop PARAMS ((char *arg));
539 void as_howmuch PARAMS ((FILE * stream));
540 void as_perror PARAMS ((const char *gripe, const char *filename));
541 void as_where PARAMS ((char **namep, unsigned int *linep));
542 void bump_line_counters PARAMS ((void));
543 void do_scrub_begin PARAMS ((void));
544 void input_scrub_begin PARAMS ((void));
545 void input_scrub_close PARAMS ((void));
546 void input_scrub_end PARAMS ((void));
547 void new_logical_line PARAMS ((char *fname, int line_number));
548 void scrub_to_file PARAMS ((int ch));
549 void scrub_to_string PARAMS ((int ch));
550 void subsegs_begin PARAMS ((void));
551 void subseg_change PARAMS ((segT seg, int subseg));
552 segT subseg_new PARAMS ((const char *name, subsegT subseg));
553 segT subseg_force_new PARAMS ((const char *name, subsegT subseg));
554 void subseg_set PARAMS ((segT seg, subsegT subseg));
555 #ifdef BFD_ASSEMBLER
556 segT subseg_get PARAMS ((const char *, int));
557 #endif
558
559 struct expressionS;
560 struct fix;
561 struct symbol;
562
563 #ifdef BFD_ASSEMBLER
564 /* literal.c */
565 valueT add_to_literal_pool PARAMS ((struct symbol *, valueT, segT, int));
566 #endif
567
568 #include "expr.h" /* Before targ-*.h */
569
570 /* this one starts the chain of target dependant headers */
571 #include "targ-env.h"
572
573 #include "struc-symbol.h"
574 #include "write.h"
575 #include "frags.h"
576 #include "hash.h"
577 #include "read.h"
578 #include "symbols.h"
579
580 #include "tc.h"
581 #include "obj.h"
582
583 #include "listing.h"
584
585 #ifdef BFD_ASSEMBLER
586 /* Someday perhaps this will be selectable at run-time. */
587 #if defined (OBJ_AOUT) || defined (OBJ_BOUT)
588 #define OUTPUT_FLAVOR bfd_target_aout_flavour
589 #endif
590 #ifdef OBJ_COFF
591 #define OUTPUT_FLAVOR bfd_target_coff_flavour
592 #endif
593 #ifdef OBJ_ECOFF
594 #define OUTPUT_FLAVOR bfd_target_ecoff_flavour
595 #endif
596 #ifdef OBJ_ELF
597 #define OUTPUT_FLAVOR bfd_target_elf_flavour
598 #endif
599 #endif /* BFD_ASSEMBLER */
600
601 #endif /* GAS */
602
603 /* end of as.h */
This page took 0.040631 seconds and 4 git commands to generate.