Merge from vendor branch GCC:
[dragonfly.git] / gnu / usr.bin / as / 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 /*
21  * $FreeBSD: src/gnu/usr.bin/as/as.h,v 1.8 1999/08/27 23:34:12 peter Exp $
22  * $DragonFly: src/gnu/usr.bin/as/Attic/as.h,v 1.3 2004/01/23 20:53:09 joerg Exp $
23  */
24
25 #define GAS 1
26 /* #include <ansidecl.h> */
27 #include "host.h"
28 #include "flonum.h"
29
30 #ifdef __GNUC__
31 #define alloca __builtin_alloca
32 #define register
33 #endif /* __GNUC__ */
34
35 #ifndef __LINE__
36 #define __LINE__ "unknown"
37 #endif /* __LINE__ */
38
39 #ifndef __FILE__
40 #define __FILE__ "unknown"
41 #endif /* __FILE__ */
42
43 #ifndef PARAMS
44 #if __STDC__ != 1
45 #define PARAMS(x)       ()
46 #else
47 #define PARAMS(x)       x
48 #endif
49 #endif /*PARAMS */
50
51 /*
52  * I think this stuff is largely out of date.  xoxorich.
53  *
54  * CAPITALISED names are #defined.
55  * "lowercaseH" is #defined if "lowercase.h" has been #include-d.
56  * "lowercaseT" is a typedef of "lowercase" objects.
57  * "lowercaseP" is type "pointer to object of type 'lowercase'".
58  * "lowercaseS" is typedef struct ... lowercaseS.
59  *
60  * #define DEBUG to enable all the "know" assertion tests.
61  * #define SUSPECT when debugging.
62  * #define COMMON as "extern" for all modules except one, where you #define
63  *      COMMON as "".
64  * If TEST is #defined, then we are testing a module: #define COMMON as "".
65  */
66
67 /* These #defines are for parameters of entire assembler. */
68
69 /* #define SUSPECT JF remove for speed testing */
70 /* These #includes are for type definitions etc. */
71
72 #include <stdio.h>
73 #include <assert.h>
74 #include <string.h>
75
76 #define obstack_chunk_alloc xmalloc
77 #define obstack_chunk_free xfree
78
79 #define xfree free
80
81 #define BAD_CASE(value) \
82 { \
83       as_fatal("Case value %d unexpected at line %d of file \"%s\"\n", \
84                value, __LINE__, __FILE__); \
85            }
86
87 \f
88 /* These are assembler-wide concepts */
89
90
91 #ifndef COMMON
92 #ifdef TEST
93 #define COMMON                  /* declare our COMMONs storage here. */
94 #else
95 #define COMMON extern           /* our commons live elswhere */
96 #endif
97 #endif
98 /* COMMON now defined */
99 #define DEBUG /* temporary */
100
101 #ifdef DEBUG
102 #undef NDEBUG
103 #ifndef know
104 #define know(p) assert(p)       /* Verify our assumptions! */
105 #endif /* not yet defined */
106 #else
107 #define know(p)                 /* know() checks are no-op.ed */
108 #endif
109 \f
110 /* input_scrub.c */
111
112 /*
113  * Supplies sanitised buffers to read.c.
114  * Also understands printing line-number part of error messages.
115  */
116
117 \f
118 /* subsegs.c     Sub-segments. Also, segment(=expression type)s.*/
119
120 /*
121  * This table describes the use of segments as EXPRESSION types.
122  *
123  *      X_seg   X_add_symbol  X_subtract_symbol X_add_number
124  * SEG_ABSENT                                           no (legal) expression
125  * SEG_PASS1                                            no (defined) "
126  * SEG_BIG                                      *       > 32 bits const.
127  * SEG_ABSOLUTE                                 0
128  * SEG_DATA             *                       0
129  * SEG_TEXT             *                       0
130  * SEG_BSS              *                       0
131  * SEG_UNKNOWN          *                       0
132  * SEG_DIFFERENCE       0               *       0
133  * SEG_REGISTER                                 *
134  *
135  * The blank fields MUST be 0, and are nugatory.
136  * The '0' fields MAY be 0. The '*' fields MAY NOT be 0.
137  *
138  * SEG_BIG: X_add_number is < 0 if the result is in
139  *      generic_floating_point_number.  The value is -'c' where c is the
140  *      character that introduced the constant.  e.g. "0f6.9" will have  -'f'
141  *      as a X_add_number value.
142  *      X_add_number > 0 is a count of how many littlenums it took to
143  *      represent a bignum.
144  * SEG_DIFFERENCE:
145  * If segments of both symbols are known, they are the same segment.
146  * X_add_symbol != X_sub_symbol (then we just cancel them, => SEG_ABSOLUTE).
147  */
148
149
150 #ifdef MANY_SEGMENTS
151 #define N_SEGMENTS 10
152 #define SEG_NORMAL(x) ((x) >= SEG_E0 && (x) <= SEG_E9)
153 #define SEG_LIST SEG_E0,SEG_E1,SEG_E2,SEG_E3,SEG_E4,SEG_E5,SEG_E6,SEG_E7,SEG_E8,SEG_E9
154 #define SEG_DATA SEG_E1
155 #define SEG_TEXT SEG_E0
156 #define SEG_BSS SEG_E2
157 #else
158 #define N_SEGMENTS 3
159 #define SEG_NORMAL(x) ((x) == SEG_TEXT || (x) == SEG_DATA || (x) == SEG_BSS)
160 #define SEG_LIST SEG_TEXT,SEG_DATA,SEG_BSS
161 #endif
162
163 typedef enum _segT {
164         SEG_ABSOLUTE = 0,
165         SEG_LIST,
166         SEG_UNKNOWN,
167         SEG_ABSENT,             /* Mythical Segment (absent): NO expression seen. */
168         SEG_PASS1,              /* Mythical Segment: Need another pass. */
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_BIG,                /* Bigger than 32 bits constant. */
173         SEG_DIFFERENCE,         /* Mythical Segment: absolute difference. */
174         SEG_DEBUG,              /* Debug segment */
175         SEG_NTV,                /* Transfert vector preload segment */
176         SEG_PTV,                /* Transfert vector postload segment */
177         SEG_REGISTER,           /* Mythical: a register-valued expression */
178 } segT;
179
180 #define SEG_MAXIMUM_ORDINAL (SEG_REGISTER)
181
182 typedef int subsegT;
183
184 COMMON subsegT                  now_subseg;
185 /* What subseg we are accreting now? */
186
187
188 COMMON segT                     now_seg;
189 /* Segment our instructions emit to. */
190 /* Only OK values are SEG_TEXT or SEG_DATA. */
191
192
193 extern char *const seg_name[];
194 extern int section_alignment[];
195
196
197 /* relax() */
198
199 typedef enum _relax_state {
200         rs_fill, /* Variable chars to be repeated fr_offset times. Fr_symbol
201                     unused. Used with fr_offset == 0 for a constant length
202                     frag. */
203
204         rs_align, /* Align: Fr_offset: power of 2. 1 variable char: fill
205                      character. */
206
207         rs_org, /* Org: Fr_offset, fr_symbol: address. 1 variable char: fill
208                    character. */
209
210         rs_machine_dependent,
211
212 #ifndef WORKING_DOT_WORD
213         rs_broken_word,         /* JF: gunpoint */
214 #endif
215 } relax_stateT;
216
217 /* typedef unsigned char relax_substateT; */
218 /* JF this is more likely to leave the end of a struct frag on an align
219    boundry.  Be very careful with this.  */
220 typedef unsigned long relax_substateT;
221
222 typedef unsigned long relax_addressT;/* Enough bits for address. */
223 /* Still an integer type. */
224
225 \f
226 /* frags.c */
227
228 /*
229  * A code fragment (frag) is some known number of chars, followed by some
230  * unknown number of chars. Typically the unknown number of chars is an
231  * instruction address whose size is yet unknown. We always know the greatest
232  * possible size the unknown number of chars may become, and reserve that
233  * much room at the end of the frag.
234  * Once created, frags do not change address during assembly.
235  * We chain the frags in (a) forward-linked list(s). The object-file address
236  * of the 1st char of a frag is generally not known until after relax().
237  * Many things at assembly time describe an address by {object-file-address
238  * of a particular frag}+offset.
239
240  BUG: it may be smarter to have a single pointer off to various different
241  notes for different frag kinds. See how code pans
242  */
243 struct frag                     /* a code fragment */
244 {
245         unsigned long fr_address; /* Object file address. */
246         struct frag *fr_next;   /* Chain forward; ascending address order. */
247         /* Rooted in frch_root. */
248
249         long fr_fix;    /* (Fixed) number of chars we know we have. */
250         /* May be 0. */
251         long fr_var;    /* (Variable) number of chars after above. */
252         /* May be 0. */
253         struct symbol *fr_symbol; /* For variable-length tail. */
254         long fr_offset; /* For variable-length tail. */
255         char    *fr_opcode;     /*->opcode low addr byte,for relax()ation*/
256         relax_stateT fr_type;   /* What state is my tail in? */
257         relax_substateT fr_subtype;
258         /* These are needed only on the NS32K machines */
259         char    fr_pcrel_adjust;
260         char    fr_bsr;
261 #ifndef NO_LISTING
262         struct list_info_struct *line;
263 #endif
264         char    fr_literal[1];  /* Chars begin here. */
265         /* One day we will compile fr_literal[0]. */
266 };
267 #define SIZEOF_STRUCT_FRAG \
268 ((int)zero_address_frag.fr_literal-(int)&zero_address_frag)
269 /* We want to say fr_literal[0] above. */
270
271 typedef struct frag fragS;
272
273 COMMON fragS *frag_now; /* -> current frag we are building. */
274 /* This frag is incomplete. */
275 /* It is, however, included in frchain_now. */
276 /* Frag_now->fr_fix is bogus. Use: */
277 /* Virtual frag_now->fr_fix == obstack_next_free(&frags)-frag_now->fr_literal.*/
278
279 COMMON fragS zero_address_frag; /* For foreign-segment symbol fixups. */
280 COMMON fragS  bss_address_frag; /* For local common (N_BSS segment) fixups. */
281
282 /* main program "as.c" (command arguments etc) */
283
284 COMMON char
285     flagseen[128];                      /* ['x'] TRUE if "-x" seen. */
286
287 COMMON char *
288     out_file_name;                      /* name of emitted object file */
289
290 COMMON int      need_pass_2;    /* TRUE if we need a second pass. */
291
292 COMMON int      picmode;        /* TRUE if "-k" or "-K" seen. */
293
294 typedef struct {
295         char *  poc_name;       /* assembler mnemonic, lower case, no '.' */
296         void            (*poc_handler)();       /* Do the work */
297         int             poc_val;        /* Value to pass to handler */
298 } pseudo_typeS;
299
300 int had_errors(void);
301 int had_warnings(void);
302 void as_bad(const char *Format, ...);
303 void as_fatal(const char *Format, ...);
304 void as_tsktsk(const char *Format, ...);
305 void as_warn(const char *Format, ...);
306
307 char *app_push(void);
308 char *atof_ieee(char *str, int what_kind, LITTLENUM_TYPE *words);
309 char *input_scrub_include_file(char *filename, char *position);
310 char *input_scrub_new_file(char *filename);
311 char *input_scrub_next_buffer(char **bufp);
312 char *strstr(const char *s, const char *wanted);
313 char *xmalloc(int size);
314 char *xrealloc(char *ptr, long n);
315 int do_scrub_next_char(int (*get)(), void (*unget)());
316 int gen_to_words(LITTLENUM_TYPE *words, int precision, long exponent_bits);
317 int had_err(void);
318 int had_errors(void);
319 int had_warnings(void);
320 int ignore_input(void);
321 int scrub_from_file(void);
322 int scrub_from_file(void);
323 int scrub_from_string(void);
324 int seen_at_least_1_file(void);
325 void app_pop(char *arg);
326 void as_howmuch(FILE *stream);
327 void as_perror(const char *gripe, const char *filename);
328 void as_where(char **, unsigned int *);
329 void bump_line_counters(void);
330 void do_scrub_begin(void);
331 void input_scrub_begin(void);
332 void input_scrub_close(void);
333 void input_scrub_end(void);
334 void int_to_gen(long x);
335 void new_logical_line(char *fname, int line_number);
336 void scrub_to_file(int ch);
337 void scrub_to_string(int ch);
338 void subseg_change(segT seg, int subseg);
339 void subseg_new(segT seg, subsegT subseg);
340 void subsegs_begin(void);
341
342 /* this one starts the chain of target dependant headers */
343 #include "targ-env.h"
344
345 /* these define types needed by the interfaces */
346 #include "struc-symbol.h"
347 #include "write.h"
348 #include "expr.h"
349 #include "frags.h"
350 #include "hash.h"
351 #include "read.h"
352 #include "symbols.h"
353
354 #include "tc.h"
355 #include "obj.h"
356
357 #include "listing.h"
358
359 /*
360  * Local Variables:
361  * comment-column: 0
362  * fill-column: 131
363  * End:
364  */
365
366 /* end of as.h */