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