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