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