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