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