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