]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gas/as.h
* config/tc-sparc.c (md_shortopts): Add "K:" if OBJ_ELF.
[thirdparty/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 #if !defined (__GNUC__) || __GNUC_MINOR__ <= 5
105 #define __PRETTY_FUNCTION__ ((char*)0)
106 #endif
107 #if 0
108
109 /* Handle lossage with assert.h. */
110 #ifndef BROKEN_ASSERT
111 #include <assert.h>
112 #else /* BROKEN_ASSERT */
113 #ifndef NDEBUG
114 #define assert(p) ((p) ? 0 : (as_assert (__FILE__, __LINE__, __PRETTY_FUNCTION__), 0))
115 #else
116 #define assert(p) ((p), 0)
117 #endif
118 #endif /* BROKEN_ASSERT */
119
120 #else
121
122 #define assert(P) ((P) ? 0 : (as_assert (__FILE__, __LINE__, __PRETTY_FUNCTION__), 0))
123 #undef abort
124 #define abort() as_abort (__FILE__, __LINE__, __PRETTY_FUNCTION__)
125
126 #endif
127
128
129 /* Now GNU header files... */
130 #include <ansidecl.h>
131 #ifdef BFD_ASSEMBLER
132 #include <bfd.h>
133 #endif
134
135 /* Define the standard progress macros. */
136 #include <progress.h>
137
138 /* This doesn't get taken care of anywhere. */
139 #if !defined (__GNUC__) && !defined (inline)
140 #define inline
141 #endif
142
143 /* Other stuff from config.h. */
144 #ifdef NEED_DECLARATION_MALLOC
145 extern PTR malloc ();
146 extern PTR realloc ();
147 #endif
148 #ifdef NEED_DECLARATION_FREE
149 extern void free ();
150 #endif
151 #ifdef NEED_DECLARATION_ERRNO
152 extern int errno;
153 #endif
154
155 /* This is needed for VMS. */
156 #if ! defined (HAVE_UNLINK) && defined (HAVE_REMOVE)
157 #define unlink remove
158 #endif
159
160 /* Hack to make "gcc -Wall" not complain about obstack macros. */
161 #if !defined (memcpy) && !defined (bcopy)
162 #define bcopy(src,dest,size) memcpy(dest,src,size)
163 #endif
164
165 #ifdef BFD_ASSEMBLER
166 /* This one doesn't get declared, but we're using it anyways. This
167 should be fixed -- either it's part of the external interface or
168 it's not. */
169 extern PTR bfd_alloc_by_size_t PARAMS ((bfd *abfd, size_t sz));
170 #endif
171
172 /* Make Saber happier on obstack.h. */
173 #ifdef SABER
174 #undef __PTR_TO_INT
175 #define __PTR_TO_INT(P) ((int)(P))
176 #undef __INT_TO_PTR
177 #define __INT_TO_PTR(P) ((char *)(P))
178 #endif
179
180 #ifndef __LINE__
181 #define __LINE__ "unknown"
182 #endif /* __LINE__ */
183
184 #ifndef __FILE__
185 #define __FILE__ "unknown"
186 #endif /* __FILE__ */
187
188 #ifndef __STDC__
189 #ifndef const
190 #define const
191 #endif
192 #ifndef volatile
193 #define volatile
194 #endif
195 #endif /* ! __STDC__ */
196
197 #if !defined (__GNUC__) && !defined (inline)
198 #define inline
199 #endif
200
201 #ifndef FOPEN_WB
202 #ifdef GO32
203 #include "fopen-bin.h"
204 #else
205 #include "fopen-same.h"
206 #endif
207 #endif
208
209 #ifndef EXIT_SUCCESS
210 #define EXIT_SUCCESS 0
211 #define EXIT_FAILURE 1
212 #endif
213
214 #define obstack_chunk_alloc xmalloc
215 #define obstack_chunk_free xfree
216
217 #define xfree free
218
219 #define BAD_CASE(val) \
220 { \
221 as_fatal("Case value %ld unexpected at line %d of file \"%s\"\n", \
222 (long) val, __LINE__, __FILE__); \
223 }
224
225 /* Version 2.1 of Solaris had problems with this declaration, but I
226 think that bug has since been fixed. If it causes problems on your
227 system, just delete it. */
228 extern char *strstr ();
229 \f
230 #include "flonum.h"
231
232 /* These are assembler-wide concepts */
233
234 #ifdef BFD_ASSEMBLER
235 extern bfd *stdoutput;
236 typedef bfd_vma addressT;
237 typedef bfd_signed_vma offsetT;
238 #else
239 typedef unsigned long addressT;
240 typedef long offsetT;
241 #endif
242
243 /* Type of symbol value, etc. For use in prototypes. */
244 typedef addressT valueT;
245
246 #ifndef COMMON
247 #ifdef TEST
248 #define COMMON /* declare our COMMONs storage here. */
249 #else
250 #define COMMON extern /* our commons live elswhere */
251 #endif
252 #endif
253 /* COMMON now defined */
254
255 #ifdef DEBUG
256 #ifndef know
257 #define know(p) assert(p) /* Verify our assumptions! */
258 #endif /* not yet defined */
259 #else
260 #define know(p) /* know() checks are no-op.ed */
261 #endif
262 \f
263 /* input_scrub.c */
264
265 /*
266 * Supplies sanitised buffers to read.c.
267 * Also understands printing line-number part of error messages.
268 */
269 \f
270
271 /* subsegs.c Sub-segments. Also, segment(=expression type)s.*/
272
273 #ifndef BFD_ASSEMBLER
274
275 #ifdef MANY_SEGMENTS
276 #include "bfd.h"
277 #define N_SEGMENTS 10
278 #define SEG_NORMAL(x) ((x) >= SEG_E0 && (x) <= SEG_E9)
279 #define SEG_LIST SEG_E0,SEG_E1,SEG_E2,SEG_E3,SEG_E4,SEG_E5,SEG_E6,SEG_E7,SEG_E8,SEG_E9
280 #define SEG_TEXT SEG_E0
281 #define SEG_DATA SEG_E1
282 #define SEG_BSS SEG_E2
283 #else
284 #define N_SEGMENTS 3
285 #define SEG_NORMAL(x) ((x) == SEG_TEXT || (x) == SEG_DATA || (x) == SEG_BSS)
286 #define SEG_LIST SEG_TEXT,SEG_DATA,SEG_BSS
287 #endif
288
289 typedef enum _segT
290 {
291 SEG_ABSOLUTE = 0,
292 SEG_LIST,
293 SEG_UNKNOWN,
294 SEG_GOOF, /* Only happens if AS has a logic error. */
295 /* Invented so we don't crash printing */
296 /* error message involving weird segment. */
297 SEG_EXPR, /* Intermediate expression values. */
298 SEG_DEBUG, /* Debug segment */
299 SEG_NTV, /* Transfert vector preload segment */
300 SEG_PTV, /* Transfert vector postload segment */
301 SEG_REGISTER /* Mythical: a register-valued expression */
302 } segT;
303
304 #define SEG_MAXIMUM_ORDINAL (SEG_REGISTER)
305 #else
306 typedef asection *segT;
307 #define SEG_NORMAL(SEG) ((SEG) != absolute_section \
308 && (SEG) != undefined_section \
309 && (SEG) != reg_section \
310 && (SEG) != expr_section)
311 #endif
312 typedef int subsegT;
313
314 /* What subseg we are accreting now? */
315 COMMON subsegT now_subseg;
316
317 /* Segment our instructions emit to. */
318 COMMON segT now_seg;
319
320 #ifdef BFD_ASSEMBLER
321 #define segment_name(SEG) bfd_get_section_name (stdoutput, SEG)
322 #else
323 extern char const *const seg_name[];
324 #define segment_name(SEG) seg_name[(int) (SEG)]
325 #endif
326
327 #ifndef BFD_ASSEMBLER
328 extern int section_alignment[];
329 #endif
330
331 #ifdef BFD_ASSEMBLER
332 extern segT reg_section, expr_section;
333 /* Shouldn't these be eliminated someday? */
334 extern segT text_section, data_section, bss_section;
335 #define absolute_section bfd_abs_section_ptr
336 #define undefined_section bfd_und_section_ptr
337 #else
338 #define reg_section SEG_REGISTER
339 #define expr_section SEG_EXPR
340 #define text_section SEG_TEXT
341 #define data_section SEG_DATA
342 #define bss_section SEG_BSS
343 #define absolute_section SEG_ABSOLUTE
344 #define undefined_section SEG_UNKNOWN
345 #endif
346
347 /* relax() */
348
349 enum _relax_state
350 {
351 /* Variable chars to be repeated fr_offset times.
352 Fr_symbol unused. Used with fr_offset == 0 for a
353 constant length frag. */
354 rs_fill = 1,
355
356 /* Align: Fr_offset: power of 2. Variable chars: fill pattern. */
357 rs_align,
358
359 /* Align code: fr_offset: power of 2. Fill pattern is machine
360 specific, defaulting to all zeros. */
361 rs_align_code,
362
363 /* Org: Fr_offset, fr_symbol: address. 1 variable char: fill
364 character. */
365 rs_org,
366
367 #ifndef WORKING_DOT_WORD
368 /* JF: gunpoint */
369 rs_broken_word,
370 #endif
371
372 /* machine-specific relaxable (or similarly alterable) instruction */
373 rs_machine_dependent,
374
375 /* .space directive with expression operand that needs to be computed
376 later. Similar to rs_org, but different.
377 fr_symbol: operand
378 1 variable char: fill character */
379 rs_space
380 };
381
382 typedef enum _relax_state relax_stateT;
383
384 /* This type is used in prototypes, so it can't be a type that will be
385 widened for argument passing. */
386 typedef unsigned int relax_substateT;
387
388 /* Enough bits for address, but still an integer type.
389 Could be a problem, cross-assembling for 64-bit machines. */
390 typedef addressT relax_addressT;
391 \f
392
393 /* frags.c */
394
395 /*
396 * A code fragment (frag) is some known number of chars, followed by some
397 * unknown number of chars. Typically the unknown number of chars is an
398 * instruction address whose size is yet unknown. We always know the greatest
399 * possible size the unknown number of chars may become, and reserve that
400 * much room at the end of the frag.
401 * Once created, frags do not change address during assembly.
402 * We chain the frags in (a) forward-linked list(s). The object-file address
403 * of the 1st char of a frag is generally not known until after relax().
404 * Many things at assembly time describe an address by {object-file-address
405 * of a particular frag}+offset.
406
407 BUG: it may be smarter to have a single pointer off to various different
408 notes for different frag kinds. See how code pans
409 */
410 struct frag
411 {
412 /* Object file address. */
413 addressT fr_address;
414 /* Chain forward; ascending address order. Rooted in frch_root. */
415 struct frag *fr_next;
416
417 /* (Fixed) number of chars we know we have. May be 0. */
418 offsetT fr_fix;
419 /* (Variable) number of chars after above. May be 0. */
420 offsetT fr_var;
421 /* For variable-length tail. */
422 struct symbol *fr_symbol;
423 /* For variable-length tail. */
424 offsetT fr_offset;
425 /* Points to opcode low addr byte, for relaxation. */
426 char *fr_opcode;
427
428 #ifndef NO_LISTING
429 struct list_info_struct *line;
430 #endif
431
432 /* What state is my tail in? */
433 relax_stateT fr_type;
434 relax_substateT fr_subtype;
435
436 /* Track the alignment and offset of the current frag. With this,
437 sometimes we can avoid creating new frags for .align directives. */
438 unsigned short align_mask;
439 unsigned short align_offset;
440
441 /* These are needed only on the NS32K machines. But since we don't
442 include targ-cpu.h until after this structure has been defined,
443 we can't really conditionalize it. This code should be
444 rearranged a bit to make that possible.
445
446 In the meantime, if we get stuck like this with any other target,
447 create a union here. */
448 char fr_pcrel_adjust, fr_bsr;
449
450 /* Data begins here. */
451 char fr_literal[1];
452 };
453
454 #define SIZEOF_STRUCT_FRAG \
455 ((char *)zero_address_frag.fr_literal-(char *)&zero_address_frag)
456 /* We want to say fr_literal[0] above. */
457
458 typedef struct frag fragS;
459
460 /* Current frag we are building. This frag is incomplete. It is, however,
461 included in frchain_now. The fr_fix field is bogus; instead, use:
462 obstack_next_free(&frags)-frag_now->fr_literal. */
463 COMMON fragS *frag_now;
464 extern int frag_now_fix ();
465
466 /* For foreign-segment symbol fixups. */
467 COMMON fragS zero_address_frag;
468 /* For local common (N_BSS segment) fixups. */
469 COMMON fragS bss_address_frag;
470
471 /* main program "as.c" (command arguments etc) */
472
473 COMMON unsigned char flag_no_comments; /* -f */
474 COMMON unsigned char flag_debug; /* -D */
475 COMMON unsigned char flag_signed_overflow_ok; /* -J */
476 #ifndef WORKING_DOT_WORD
477 COMMON unsigned char flag_warn_displacement; /* -K */
478 #endif
479
480 /* True if local symbols should be retained. */
481 COMMON unsigned char flag_keep_locals; /* -L */
482
483 /* Should the data section be made read-only and appended to the text
484 section? */
485 COMMON unsigned char flag_readonly_data_in_text; /* -R */
486
487 /* True if warnings should be inhibited. */
488 COMMON unsigned char flag_no_warnings; /* -W */
489
490 /* True if we should attempt to generate output even if non-fatal errors
491 are detected. */
492 COMMON unsigned char flag_always_generate_output; /* -Z */
493
494 /* This is true if the assembler should output time and space usage. */
495
496 COMMON unsigned char flag_print_statistics;
497
498 /* name of emitted object file */
499 COMMON char *out_file_name;
500
501 /* TRUE if we need a second pass. */
502 COMMON int need_pass_2;
503
504 /* TRUE if we should do no relaxing, and
505 leave lots of padding. */
506 COMMON int linkrelax;
507
508 /* TRUE if we should produce a listing. */
509 extern int listing;
510
511 struct _pseudo_type
512 {
513 /* assembler mnemonic, lower case, no '.' */
514 const char *poc_name;
515 /* Do the work */
516 void (*poc_handler) PARAMS ((int));
517 /* Value to pass to handler */
518 int poc_val;
519 };
520
521 typedef struct _pseudo_type pseudo_typeS;
522
523 /* Prefer varargs for non-ANSI compiler, since some will barf if the
524 ellipsis definition is used with a no-arguments declaration. */
525 #if defined (HAVE_VARARGS_H) && !defined (__STDC__)
526 #undef HAVE_STDARG_H
527 #endif
528
529 #if defined (HAVE_STDARG_H)
530 #define USE_STDARG
531 #endif
532 #if !defined (USE_STDARG) && defined (HAVE_VARARGS_H)
533 #define USE_VARARGS
534 #endif
535
536 #ifdef USE_STDARG
537 #if __GNUC__ >= 2
538 /* for use with -Wformat */
539 #define PRINTF_LIKE(FCN) void FCN (const char *format, ...) \
540 __attribute__ ((format (printf, 1, 2)))
541 #define PRINTF_WHERE_LIKE(FCN) void FCN (char *file, unsigned int line, \
542 const char *format, ...) \
543 __attribute__ ((format (printf, 3, 4)))
544 #else /* ANSI C with stdarg, but not GNU C */
545 #define PRINTF_LIKE(FCN) void FCN PARAMS ((const char *format, ...))
546 #define PRINTF_WHERE_LIKE(FCN) void FCN PARAMS ((char *file, \
547 unsigned int line, \
548 const char *format, ...))
549 #endif
550 #else /* not using stdarg */
551 #define PRINTF_LIKE(FCN) void FCN ()
552 #define PRINTF_WHERE_LIKE(FCN) void FCN ()
553 #endif
554
555 PRINTF_LIKE (as_bad);
556 PRINTF_LIKE (as_fatal);
557 PRINTF_LIKE (as_tsktsk);
558 PRINTF_LIKE (as_warn);
559 PRINTF_WHERE_LIKE (as_bad_where);
560 PRINTF_WHERE_LIKE (as_warn_where);
561 void as_assert PARAMS ((const char *, int, const char *));
562 void as_abort PARAMS ((const char *, int, const char *));
563
564 void fprint_value PARAMS ((FILE *file, addressT value));
565 void sprint_value PARAMS ((char *buf, addressT value));
566
567 int had_errors PARAMS ((void));
568 int had_warnings PARAMS ((void));
569
570 void print_version_id PARAMS ((void));
571 char *app_push PARAMS ((void));
572 char *atof_ieee PARAMS ((char *str, int what_kind, LITTLENUM_TYPE * words));
573 char *input_scrub_include_file PARAMS ((char *filename, char *position));
574 char *input_scrub_new_file PARAMS ((char *filename));
575 char *input_scrub_next_buffer PARAMS ((char **bufp));
576 PTR xmalloc PARAMS ((unsigned long size));
577 PTR xrealloc PARAMS ((PTR ptr, unsigned long n));
578 int do_scrub_next_char PARAMS ((int (*get) (void), void (*unget) (int)));
579 int gen_to_words PARAMS ((LITTLENUM_TYPE * words, int precision,
580 long exponent_bits));
581 int had_err PARAMS ((void));
582 int ignore_input PARAMS ((void));
583 int scrub_from_file PARAMS ((void));
584 int scrub_from_string PARAMS ((void));
585 int seen_at_least_1_file PARAMS ((void));
586 void app_pop PARAMS ((char *arg));
587 void as_howmuch PARAMS ((FILE * stream));
588 void as_perror PARAMS ((const char *gripe, const char *filename));
589 void as_where PARAMS ((char **namep, unsigned int *linep));
590 void bump_line_counters PARAMS ((void));
591 void do_scrub_begin PARAMS ((void));
592 void input_scrub_begin PARAMS ((void));
593 void input_scrub_close PARAMS ((void));
594 void input_scrub_end PARAMS ((void));
595 void new_logical_line PARAMS ((char *fname, int line_number));
596 void scrub_to_file PARAMS ((int ch));
597 void scrub_to_string PARAMS ((int ch));
598 void subsegs_begin PARAMS ((void));
599 void subseg_change PARAMS ((segT seg, int subseg));
600 segT subseg_new PARAMS ((const char *name, subsegT subseg));
601 segT subseg_force_new PARAMS ((const char *name, subsegT subseg));
602 void subseg_set PARAMS ((segT seg, subsegT subseg));
603 #ifdef BFD_ASSEMBLER
604 segT subseg_get PARAMS ((const char *, int));
605 #endif
606
607 struct expressionS;
608 struct fix;
609 struct symbol;
610 struct relax_type;
611
612 #ifdef BFD_ASSEMBLER
613 /* literal.c */
614 valueT add_to_literal_pool PARAMS ((struct symbol *, valueT, segT, int));
615 #endif
616
617 #include "expr.h" /* Before targ-*.h */
618
619 /* this one starts the chain of target dependant headers */
620 #include "targ-env.h"
621
622 #include "struc-symbol.h"
623 #include "write.h"
624 #include "frags.h"
625 #include "hash.h"
626 #include "read.h"
627 #include "symbols.h"
628
629 #include "tc.h"
630 #include "obj.h"
631
632 #ifdef USE_EMULATIONS
633 #include "emul.h"
634 #endif
635 #include "listing.h"
636
637 #ifndef LOCAL_LABELS_DOLLAR
638 #define LOCAL_LABELS_DOLLAR 0
639 #endif
640
641 #ifndef LOCAL_LABELS_FB
642 #define LOCAL_LABELS_FB 0
643 #endif
644
645 #endif /* GAS */
646
647 /* end of as.h */