1 /* as.h - global header file
2 Copyright (C) 1987, 1990, 1991, 1992 Free Software Foundation, Inc.
4 This file is part of GAS, the GNU Assembler.
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)
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.
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. */
23 * I think this stuff is largely out of date. xoxorich.
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.
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
35 * If TEST is #defined, then we are testing a module: #define COMMON as "".
38 /* These #defines are for parameters of entire assembler. */
40 /* These #includes are for type definitions etc. */
57 /* Make Saber happier on obstack.h. */
60 #define __PTR_TO_INT(P) ((int)(P))
62 #define __INT_TO_PTR(P) ((char *)(P))
66 #define __LINE__ "unknown"
70 #define __FILE__ "unknown"
80 #endif /* ! __STDC__ */
83 #include "fopen-same.h"
86 #define obstack_chunk_alloc xmalloc
87 #define obstack_chunk_free xfree
91 #define BAD_CASE(val) \
93 as_fatal("Case value %ld unexpected at line %d of file \"%s\"\n", \
94 (long) val, __LINE__, __FILE__); \
98 /* These are assembler-wide concepts */
101 extern bfd *stdoutput;
102 typedef bfd_vma addressT;
103 typedef bfd_signed_vma offsetT;
105 typedef unsigned long addressT;
106 typedef long offsetT;
109 /* Type of symbol value, etc. For use in prototypes. */
110 typedef addressT valueT;
114 #define COMMON /* declare our COMMONs storage here. */
116 #define COMMON extern /* our commons live elswhere */
119 /* COMMON now defined */
123 #define know(p) assert(p) /* Verify our assumptions! */
124 #endif /* not yet defined */
126 #define know(p) /* know() checks are no-op.ed */
129 #if defined (BROKEN_ASSERT) && !defined (NDEBUG)
130 /* Used on machines where the "assert" macro is buggy. (For example, on the
131 RS/6000, Reiser-cpp substitution is done to put the condition into a
132 string, so if the condition contains a string, parse errors result.) If
133 the condition fails, just drop core file. */
135 #define assert(p) ((p) ? 0 : (abort (), 0))
141 * Supplies sanitised buffers to read.c.
142 * Also understands printing line-number part of error messages.
146 /* subsegs.c Sub-segments. Also, segment(=expression type)s.*/
148 #ifndef BFD_ASSEMBLER
152 #define N_SEGMENTS 10
153 #define SEG_NORMAL(x) ((x) >= SEG_E0 && (x) <= SEG_E9)
154 #define SEG_LIST SEG_E0,SEG_E1,SEG_E2,SEG_E3,SEG_E4,SEG_E5,SEG_E6,SEG_E7,SEG_E8,SEG_E9
155 #define SEG_TEXT SEG_E0
156 #define SEG_DATA SEG_E1
157 #define SEG_BSS SEG_E2
160 #define SEG_NORMAL(x) ((x) == SEG_TEXT || (x) == SEG_DATA || (x) == SEG_BSS)
161 #define SEG_LIST SEG_TEXT,SEG_DATA,SEG_BSS
169 SEG_GOOF, /* Only happens if AS has a logic error. */
170 /* Invented so we don't crash printing */
171 /* error message involving weird segment. */
172 SEG_EXPR, /* Intermediate expression values. */
173 SEG_DEBUG, /* Debug segment */
174 SEG_NTV, /* Transfert vector preload segment */
175 SEG_PTV, /* Transfert vector postload segment */
176 SEG_REGISTER /* Mythical: a register-valued expression */
179 #define SEG_MAXIMUM_ORDINAL (SEG_REGISTER)
181 typedef asection *segT;
182 #define SEG_NORMAL(SEG) ((SEG) != absolute_section \
183 && (SEG) != undefined_section \
184 && (SEG) != reg_section \
185 && (SEG) != expr_section)
189 /* What subseg we are accreting now? */
190 COMMON subsegT now_subseg;
192 /* Segment our instructions emit to. */
196 #define segment_name(SEG) bfd_get_section_name (stdoutput, SEG)
198 extern char *const seg_name[];
199 #define segment_name(SEG) seg_name[(int) (SEG)]
202 #ifndef BFD_ASSEMBLER
203 extern int section_alignment[];
207 extern segT reg_section, expr_section;
208 /* Shouldn't these be eliminated someday? */
209 extern segT text_section, data_section, bss_section;
210 #define absolute_section (&bfd_abs_section)
211 #define undefined_section (&bfd_und_section)
213 #define reg_section SEG_REGISTER
214 #define expr_section SEG_EXPR
215 #define text_section SEG_TEXT
216 #define data_section SEG_DATA
217 #define bss_section SEG_BSS
218 #define absolute_section SEG_ABSOLUTE
219 #define undefined_section SEG_UNKNOWN
224 typedef enum _relax_state
226 /* Variable chars to be repeated fr_offset times.
227 Fr_symbol unused. Used with fr_offset == 0 for a
228 constant length frag. */
231 /* Align: Fr_offset: power of 2. 1 variable char: fill character. */
234 /* Org: Fr_offset, fr_symbol: address. 1 variable char: fill
240 #ifndef WORKING_DOT_WORD
246 /* typedef unsigned char relax_substateT; */
247 /* JF this is more likely to leave the end of a struct frag on an align
248 boundry. Be very careful with this. */
249 typedef unsigned long relax_substateT;
251 /* Enough bits for address, but still an integer type.
252 Could be a problem, cross-assembling for 64-bit machines. */
253 typedef addressT relax_addressT;
259 * A code fragment (frag) is some known number of chars, followed by some
260 * unknown number of chars. Typically the unknown number of chars is an
261 * instruction address whose size is yet unknown. We always know the greatest
262 * possible size the unknown number of chars may become, and reserve that
263 * much room at the end of the frag.
264 * Once created, frags do not change address during assembly.
265 * We chain the frags in (a) forward-linked list(s). The object-file address
266 * of the 1st char of a frag is generally not known until after relax().
267 * Many things at assembly time describe an address by {object-file-address
268 * of a particular frag}+offset.
270 BUG: it may be smarter to have a single pointer off to various different
271 notes for different frag kinds. See how code pans
275 /* Object file address. */
277 /* Chain forward; ascending address order. Rooted in frch_root. */
278 struct frag *fr_next;
280 /* (Fixed) number of chars we know we have. May be 0. */
282 /* (Variable) number of chars after above. May be 0. */
284 /* For variable-length tail. */
285 struct symbol *fr_symbol;
286 /* For variable-length tail. */
288 /* Points to opcode low addr byte, for relaxation. */
292 struct list_info_struct *line;
295 /* What state is my tail in? */
296 relax_stateT fr_type;
297 relax_substateT fr_subtype;
299 /* These are needed only on the NS32K machines */
300 char fr_pcrel_adjust;
304 One day we will compile fr_literal[0]. */
308 #define SIZEOF_STRUCT_FRAG \
309 ((int)zero_address_frag.fr_literal-(int)&zero_address_frag)
310 /* We want to say fr_literal[0] above. */
312 typedef struct frag fragS;
314 /* Current frag we are building. This frag is incomplete. It is, however,
315 included in frchain_now. The fr_fix field is bogus; instead, use:
316 obstack_next_free(&frags)-frag_now->fr_literal. */
317 COMMON fragS *frag_now;
318 #define frag_now_fix() ((char*)obstack_next_free (&frags) - frag_now->fr_literal)
320 /* For foreign-segment symbol fixups. */
321 COMMON fragS zero_address_frag;
322 /* For local common (N_BSS segment) fixups. */
323 COMMON fragS bss_address_frag;
325 /* main program "as.c" (command arguments etc) */
327 /* ['x'] TRUE if "-x" seen. */
328 COMMON char flagseen[128];
329 COMMON unsigned char flag_readonly_data_in_text;
330 COMMON unsigned char flag_suppress_warnings;
331 COMMON unsigned char flag_always_generate_output;
333 /* name of emitted object file */
334 COMMON char *out_file_name;
336 /* TRUE if we need a second pass. */
337 COMMON int need_pass_2;
339 /* TRUE if we should do no relaxing, and
340 leave lots of padding. */
341 COMMON int linkrelax;
343 /* TRUE if we should produce a listing. */
348 /* assembler mnemonic, lower case, no '.' */
351 void (*poc_handler) PARAMS ((int));
352 /* Value to pass to handler */
356 typedef struct _pseudo_type pseudo_typeS;
358 #ifdef BFD_ASSEMBLER_xxx
363 struct lineno_struct *next;
365 typedef struct lineno_struct lineno;
368 #if defined (__STDC__) && !defined(NO_STDARG)
371 /* for use with -Wformat */
372 #define PRINTF_LIKE(FCN) void FCN (const char *format, ...) \
373 __attribute__ ((format (printf, 1, 2)))
374 #define PRINTF_WHERE_LIKE(FCN) void FCN (char *file, unsigned int line, \
375 const char *format, ...) \
376 __attribute__ ((format (printf, 3, 4)))
377 #else /* ANSI C with stdarg, but not GNU C */
378 #define PRINTF_LIKE(FCN) void FCN (const char *format, ...)
379 #define PRINTF_WHERE_LIKE(FCN) void FCN (char *file, unsigned int line, \
380 const char *format, ...)
382 #else /* not ANSI C, or not stdarg */
383 #define PRINTF_LIKE(FCN) void FCN ()
384 #define PRINTF_WHERE_LIKE(FCN) void FCN ()
387 PRINTF_LIKE (as_bad);
388 PRINTF_LIKE (as_fatal);
389 PRINTF_LIKE (as_tsktsk);
390 PRINTF_LIKE (as_warn);
391 PRINTF_WHERE_LIKE (as_bad_where);
392 PRINTF_WHERE_LIKE (as_warn_where);
394 void fprint_value PARAMS ((FILE *file, addressT value));
395 void sprint_value PARAMS ((char *buf, addressT value));
397 int had_errors PARAMS ((void));
398 int had_warnings PARAMS ((void));
400 void print_version_id PARAMS ((void));
401 char *app_push PARAMS ((void));
402 char *atof_ieee PARAMS ((char *str, int what_kind, LITTLENUM_TYPE * words));
403 char *input_scrub_include_file PARAMS ((char *filename, char *position));
404 char *input_scrub_new_file PARAMS ((char *filename));
405 char *input_scrub_next_buffer PARAMS ((char **bufp));
406 #if 0 /* incompatible with solaris 2 native cc */
407 char *strstr PARAMS ((const char *s, const char *wanted));
409 char *xmalloc PARAMS ((unsigned long size));
410 char *xrealloc PARAMS ((char *ptr, unsigned long n));
411 int do_scrub_next_char PARAMS ((int (*get) (void), void (*unget) (int)));
412 int gen_to_words PARAMS ((LITTLENUM_TYPE * words, int precision,
413 long exponent_bits));
414 int had_err PARAMS ((void));
415 int ignore_input PARAMS ((void));
416 int scrub_from_file PARAMS ((void));
417 int scrub_from_string PARAMS ((void));
418 int seen_at_least_1_file PARAMS ((void));
419 void app_pop PARAMS ((char *arg));
420 void as_howmuch PARAMS ((FILE * stream));
421 void as_perror PARAMS ((char *gripe, char *filename));
422 void as_where PARAMS ((char **namep, unsigned int *linep));
423 void bump_line_counters PARAMS ((void));
424 void do_scrub_begin PARAMS ((void));
425 void input_scrub_begin PARAMS ((void));
426 void input_scrub_close PARAMS ((void));
427 void input_scrub_end PARAMS ((void));
428 void new_logical_line PARAMS ((char *fname, int line_number));
429 void scrub_to_file PARAMS ((int ch));
430 void scrub_to_string PARAMS ((int ch));
431 void subsegs_begin PARAMS ((void));
432 void subseg_change PARAMS ((segT seg, int subseg));
433 segT subseg_new PARAMS ((const char *name, subsegT subseg));
434 segT subseg_force_new PARAMS ((const char *name, subsegT subseg));
435 void subseg_set PARAMS ((segT seg, subsegT subseg));
443 valueT add_to_literal_pool PARAMS ((struct symbol *, valueT, segT, int));
446 /* this one starts the chain of target dependant headers */
447 #include "targ-env.h"
450 #include "struc-symbol.h"
463 /* Someday perhaps this will be selectable at run-time. */
464 #if defined (OBJ_AOUT) || defined (OBJ_BOUT)
465 #define OUTPUT_FLAVOR bfd_target_aout_flavour
468 #define OUTPUT_FLAVOR bfd_target_coff_flavour
471 #define OUTPUT_FLAVOR bfd_target_ecoff_flavour
474 #define OUTPUT_FLAVOR bfd_target_elf_flavour
476 #endif /* BFD_ASSEMBLER */