Commit | Line | Data |
---|---|---|
3c3bdf30 | 1 | /* tc-mmix.c -- Assembler for Don Knuth's MMIX. |
7e1792e0 | 2 | Copyright (C) 2001, 2002, 2003, 2004 Free Software Foundation. |
3c3bdf30 NC |
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, 59 Temple Place - Suite 330, | |
19 | Boston, MA 02111-1307, USA. */ | |
20 | ||
21 | /* Knuth's assembler mmixal does not provide a relocatable format; mmo is | |
22 | to be considered a final link-format. In the final link, we make mmo, | |
23 | but for relocatable files, we use ELF. | |
24 | ||
25 | One goal is to provide a superset of what mmixal does, including | |
26 | compatible syntax, but the main purpose is to serve GCC. */ | |
27 | ||
28 | ||
29 | #include <stdio.h> | |
88fc725d | 30 | #include <limits.h> |
3c3bdf30 NC |
31 | #include "as.h" |
32 | #include "subsegs.h" | |
33 | #include "bfd.h" | |
34 | #include "elf/mmix.h" | |
35 | #include "opcode/mmix.h" | |
36 | #include "safe-ctype.h" | |
37 | #include "dwarf2dbg.h" | |
38 | #include "obstack.h" | |
39 | ||
40 | /* Something to describe what we need to do with a fixup before output, | |
41 | for example assert something of what it became or make a relocation. */ | |
42 | ||
43 | enum mmix_fixup_action | |
44 | { | |
45 | mmix_fixup_byte, | |
46 | mmix_fixup_register, | |
47 | mmix_fixup_register_or_adjust_for_byte | |
48 | }; | |
49 | ||
50 | static int get_spec_regno PARAMS ((char *)); | |
51 | static int get_operands PARAMS ((int, char *, expressionS[])); | |
52 | static int get_putget_operands | |
53 | PARAMS ((struct mmix_opcode *, char *, expressionS[])); | |
54 | static void s_prefix PARAMS ((int)); | |
55 | static void s_greg PARAMS ((int)); | |
56 | static void s_loc PARAMS ((int)); | |
57 | static void s_bspec PARAMS ((int)); | |
58 | static void s_espec PARAMS ((int)); | |
59 | static void mmix_s_local PARAMS ((int)); | |
60 | static void mmix_greg_internal PARAMS ((char *)); | |
61 | static void mmix_set_geta_branch_offset PARAMS ((char *, offsetT value)); | |
62 | static void mmix_set_jmp_offset PARAMS ((char *, offsetT)); | |
63 | static void mmix_fill_nops PARAMS ((char *, int)); | |
64 | static int cmp_greg_symbol_fixes PARAMS ((const PTR, const PTR)); | |
65 | static int cmp_greg_val_greg_symbol_fixes | |
66 | PARAMS ((const PTR p1, const PTR p2)); | |
67 | static void mmix_handle_rest_of_empty_line PARAMS ((void)); | |
68 | static void mmix_discard_rest_of_line PARAMS ((void)); | |
69 | static void mmix_byte PARAMS ((void)); | |
70 | static void mmix_cons PARAMS ((int)); | |
3c3bdf30 NC |
71 | |
72 | /* Continue the tradition of symbols.c; use control characters to enforce | |
73 | magic. These are used when replacing e.g. 8F and 8B so we can handle | |
74 | such labels correctly with the common parser hooks. */ | |
75 | #define MAGIC_FB_BACKWARD_CHAR '\003' | |
76 | #define MAGIC_FB_FORWARD_CHAR '\004' | |
77 | ||
78 | /* Copy the location of a frag to a fix. */ | |
79 | #define COPY_FR_WHERE_TO_FX(FRAG, FIX) \ | |
80 | do \ | |
81 | { \ | |
82 | (FIX)->fx_file = (FRAG)->fr_file; \ | |
83 | (FIX)->fx_line = (FRAG)->fr_line; \ | |
84 | } \ | |
85 | while (0) | |
86 | ||
87 | const char *md_shortopts = "x"; | |
88 | static int current_fb_label = -1; | |
89 | static char *pending_label = NULL; | |
90 | ||
91 | static bfd_vma lowest_text_loc = (bfd_vma) -1; | |
92 | static int text_has_contents = 0; | |
93 | ||
94 | /* The alignment of the previous instruction, and a boolean for whether we | |
95 | want to avoid aligning the next WYDE, TETRA, OCTA or insn. */ | |
96 | static int last_alignment = 0; | |
97 | static int want_unaligned = 0; | |
98 | ||
99 | static bfd_vma lowest_data_loc = (bfd_vma) -1; | |
100 | static int data_has_contents = 0; | |
101 | ||
102 | /* The fragS of the instruction being assembled. Only valid from within | |
103 | md_assemble. */ | |
104 | fragS *mmix_opcode_frag = NULL; | |
105 | ||
106 | /* Raw GREGs as appearing in input. These may be fewer than the number | |
107 | after relaxing. */ | |
108 | static int n_of_raw_gregs = 0; | |
109 | static struct | |
110 | { | |
111 | char *label; | |
112 | expressionS exp; | |
113 | } mmix_raw_gregs[MAX_GREGS]; | |
114 | ||
115 | /* Fixups for all unique GREG registers. We store the fixups here in | |
116 | md_convert_frag, then we use the array to convert | |
117 | BFD_RELOC_MMIX_BASE_PLUS_OFFSET fixups in tc_gen_reloc. The index is | |
118 | just a running number and is not supposed to be correlated to a | |
119 | register number. */ | |
120 | static fixS *mmix_gregs[MAX_GREGS]; | |
121 | static int n_of_cooked_gregs = 0; | |
122 | ||
123 | /* Pointing to the register section we use for output. */ | |
124 | static asection *real_reg_section; | |
125 | ||
126 | /* For each symbol; unknown or section symbol, we keep a list of GREG | |
127 | definitions sorted on increasing offset. It seems no use keeping count | |
128 | to allocate less room than the maximum number of gregs when we've found | |
129 | one for a section or symbol. */ | |
130 | struct mmix_symbol_gregs | |
131 | { | |
132 | int n_gregs; | |
133 | struct mmix_symbol_greg_fixes | |
134 | { | |
135 | fixS *fix; | |
136 | ||
137 | /* A signed type, since we may have GREGs pointing slightly before the | |
138 | contents of a section. */ | |
139 | offsetT offs; | |
140 | } greg_fixes[MAX_GREGS]; | |
141 | }; | |
142 | ||
143 | /* Should read insert a colon on something that starts in column 0 on | |
144 | this line? */ | |
145 | static int label_without_colon_this_line = 1; | |
146 | ||
88fc725d HPN |
147 | /* Should we automatically expand instructions into multiple insns in |
148 | order to generate working code? */ | |
3c3bdf30 NC |
149 | static int expand_op = 1; |
150 | ||
151 | /* Should we warn when expanding operands? FIXME: test-cases for when -x | |
152 | is absent. */ | |
153 | static int warn_on_expansion = 1; | |
154 | ||
155 | /* Should we merge non-zero GREG register definitions? */ | |
156 | static int merge_gregs = 1; | |
157 | ||
973eb340 HPN |
158 | /* Should we pass on undefined BFD_RELOC_MMIX_BASE_PLUS_OFFSET relocs |
159 | (missing suitable GREG definitions) to the linker? */ | |
160 | static int allocate_undefined_gregs_in_linker = 0; | |
161 | ||
3c3bdf30 NC |
162 | /* Should we emit built-in symbols? */ |
163 | static int predefined_syms = 1; | |
164 | ||
973eb340 HPN |
165 | /* Should we allow anything but the listed special register name |
166 | (e.g. equated symbols)? */ | |
3c3bdf30 NC |
167 | static int equated_spec_regs = 1; |
168 | ||
169 | /* Do we require standard GNU syntax? */ | |
170 | int mmix_gnu_syntax = 0; | |
171 | ||
172 | /* Do we globalize all symbols? */ | |
173 | int mmix_globalize_symbols = 0; | |
174 | ||
88fc725d HPN |
175 | /* When expanding insns, do we want to expand PUSHJ as a call to a stub |
176 | (or else as a series of insns)? */ | |
177 | int pushj_stubs = 1; | |
178 | ||
3c3bdf30 | 179 | /* Do we know that the next semicolon is at the end of the operands field |
88fc725d | 180 | (in mmixal mode; constant 1 in GNU mode)? */ |
3c3bdf30 NC |
181 | int mmix_next_semicolon_is_eoln = 1; |
182 | ||
183 | /* Do we have a BSPEC in progress? */ | |
184 | static int doing_bspec = 0; | |
185 | static char *bspec_file; | |
186 | static unsigned int bspec_line; | |
187 | ||
188 | struct option md_longopts[] = | |
189 | { | |
190 | #define OPTION_RELAX (OPTION_MD_BASE) | |
191 | #define OPTION_NOEXPAND (OPTION_RELAX + 1) | |
192 | #define OPTION_NOMERGEGREG (OPTION_NOEXPAND + 1) | |
193 | #define OPTION_NOSYMS (OPTION_NOMERGEGREG + 1) | |
194 | #define OPTION_GNU_SYNTAX (OPTION_NOSYMS + 1) | |
195 | #define OPTION_GLOBALIZE_SYMBOLS (OPTION_GNU_SYNTAX + 1) | |
196 | #define OPTION_FIXED_SPEC_REGS (OPTION_GLOBALIZE_SYMBOLS + 1) | |
973eb340 | 197 | #define OPTION_LINKER_ALLOCATED_GREGS (OPTION_FIXED_SPEC_REGS + 1) |
88fc725d | 198 | #define OPTION_NOPUSHJSTUBS (OPTION_LINKER_ALLOCATED_GREGS + 1) |
3c3bdf30 NC |
199 | {"linkrelax", no_argument, NULL, OPTION_RELAX}, |
200 | {"no-expand", no_argument, NULL, OPTION_NOEXPAND}, | |
201 | {"no-merge-gregs", no_argument, NULL, OPTION_NOMERGEGREG}, | |
202 | {"no-predefined-syms", no_argument, NULL, OPTION_NOSYMS}, | |
203 | {"gnu-syntax", no_argument, NULL, OPTION_GNU_SYNTAX}, | |
204 | {"globalize-symbols", no_argument, NULL, OPTION_GLOBALIZE_SYMBOLS}, | |
205 | {"fixed-special-register-names", no_argument, NULL, | |
206 | OPTION_FIXED_SPEC_REGS}, | |
973eb340 HPN |
207 | {"linker-allocated-gregs", no_argument, NULL, |
208 | OPTION_LINKER_ALLOCATED_GREGS}, | |
88fc725d HPN |
209 | {"no-pushj-stubs", no_argument, NULL, OPTION_NOPUSHJSTUBS}, |
210 | {"no-stubs", no_argument, NULL, OPTION_NOPUSHJSTUBS}, | |
3c3bdf30 NC |
211 | {NULL, no_argument, NULL, 0} |
212 | }; | |
213 | ||
214 | size_t md_longopts_size = sizeof (md_longopts); | |
215 | ||
216 | static struct hash_control *mmix_opcode_hash; | |
217 | ||
218 | /* We use these when implementing the PREFIX pseudo. */ | |
219 | char *mmix_current_prefix; | |
220 | struct obstack mmix_sym_obstack; | |
221 | ||
222 | ||
223 | /* For MMIX, we encode the relax_substateT:s (in e.g. fr_substate) as one | |
224 | bit length, and the relax-type shifted on top of that. There seems to | |
225 | be no point in making the relaxation more fine-grained; the linker does | |
226 | that better and we might interfere by changing non-optimal relaxations | |
227 | into other insns that cannot be relaxed as easily. | |
228 | ||
229 | Groups for MMIX relaxing: | |
230 | ||
231 | 1. GETA | |
232 | extra length: zero or three insns. | |
233 | ||
234 | 2. Bcc | |
235 | extra length: zero or five insns. | |
236 | ||
237 | 3. PUSHJ | |
238 | extra length: zero or four insns. | |
88fc725d | 239 | Special handling to deal with transition to PUSHJSTUB. |
3c3bdf30 NC |
240 | |
241 | 4. JMP | |
88fc725d HPN |
242 | extra length: zero or four insns. |
243 | ||
244 | 5. GREG | |
245 | special handling, allocates a named global register unless another | |
246 | is within reach for all uses. | |
247 | ||
248 | 6. PUSHJSTUB | |
249 | special handling (mostly) for external references; assumes the | |
250 | linker will generate a stub if target is no longer than 256k from | |
251 | the end of the section plus max size of previous stubs. Zero or | |
252 | four insns. */ | |
3c3bdf30 NC |
253 | |
254 | #define STATE_GETA (1) | |
255 | #define STATE_BCC (2) | |
256 | #define STATE_PUSHJ (3) | |
257 | #define STATE_JMP (4) | |
258 | #define STATE_GREG (5) | |
88fc725d | 259 | #define STATE_PUSHJSTUB (6) |
3c3bdf30 NC |
260 | |
261 | /* No fine-grainedness here. */ | |
262 | #define STATE_LENGTH_MASK (1) | |
263 | ||
264 | #define STATE_ZERO (0) | |
265 | #define STATE_MAX (1) | |
266 | ||
267 | /* More descriptive name for convenience. */ | |
268 | /* FIXME: We should start on something different, not MAX. */ | |
269 | #define STATE_UNDF STATE_MAX | |
270 | ||
271 | /* FIXME: For GREG, we must have other definitions; UNDF == MAX isn't | |
272 | appropriate; we need it the other way round. This value together with | |
273 | fragP->tc_frag_data shows what state the frag is in: tc_frag_data | |
274 | non-NULL means 0, NULL means 8 bytes. */ | |
275 | #define STATE_GREG_UNDF ENCODE_RELAX (STATE_GREG, STATE_ZERO) | |
276 | #define STATE_GREG_DEF ENCODE_RELAX (STATE_GREG, STATE_MAX) | |
277 | ||
67c1ffbe | 278 | /* These displacements are relative to the address following the opcode |
3c3bdf30 NC |
279 | word of the instruction. The catch-all states have zero for "reach" |
280 | and "next" entries. */ | |
281 | ||
282 | #define GETA_0F (65536 * 4 - 8) | |
283 | #define GETA_0B (-65536 * 4 - 4) | |
284 | ||
a1b6236b | 285 | #define GETA_MAX_LEN 4 * 4 |
3c3bdf30 NC |
286 | #define GETA_3F 0 |
287 | #define GETA_3B 0 | |
288 | ||
289 | #define BCC_0F GETA_0F | |
290 | #define BCC_0B GETA_0B | |
291 | ||
a1b6236b | 292 | #define BCC_MAX_LEN 6 * 4 |
3c3bdf30 NC |
293 | #define BCC_5F GETA_3F |
294 | #define BCC_5B GETA_3B | |
295 | ||
296 | #define PUSHJ_0F GETA_0F | |
297 | #define PUSHJ_0B GETA_0B | |
298 | ||
a1b6236b | 299 | #define PUSHJ_MAX_LEN 5 * 4 |
3c3bdf30 NC |
300 | #define PUSHJ_4F GETA_3F |
301 | #define PUSHJ_4B GETA_3B | |
302 | ||
88fc725d HPN |
303 | /* We'll very rarely have sections longer than LONG_MAX, but we'll make a |
304 | feeble attempt at getting 64-bit C99 or gcc-specific values (assuming | |
305 | long long is 64 bits on the host). */ | |
306 | #ifdef LLONG_MIN | |
307 | #define PUSHJSTUB_MIN LLONG_MIN | |
7e1792e0 | 308 | #elif defined (LONG_LONG_MIN) |
88fc725d HPN |
309 | #define PUSHJSTUB_MIN LONG_LONG_MIN |
310 | #else | |
311 | #define PUSHJSTUB_MIN LONG_MIN | |
312 | #endif | |
313 | #ifdef LLONG_MAX | |
314 | #define PUSHJSTUB_MAX LLONG_MAX | |
7e1792e0 | 315 | #elif defined (LONG_LONG_MAX) |
88fc725d HPN |
316 | #define PUSHJSTUB_MAX LONG_LONG_MAX |
317 | #else | |
318 | #define PUSHJSTUB_MAX LONG_MAX | |
319 | #endif | |
320 | ||
3c3bdf30 NC |
321 | #define JMP_0F (65536 * 256 * 4 - 8) |
322 | #define JMP_0B (-65536 * 256 * 4 - 4) | |
323 | ||
a1b6236b | 324 | #define JMP_MAX_LEN 5 * 4 |
3c3bdf30 NC |
325 | #define JMP_4F 0 |
326 | #define JMP_4B 0 | |
327 | ||
328 | #define RELAX_ENCODE_SHIFT 1 | |
329 | #define ENCODE_RELAX(what, length) (((what) << RELAX_ENCODE_SHIFT) + (length)) | |
330 | ||
331 | const relax_typeS mmix_relax_table[] = | |
332 | { | |
333 | /* Error sentinel (0, 0). */ | |
334 | {1, 1, 0, 0}, | |
335 | ||
336 | /* Unused (0, 1). */ | |
337 | {1, 1, 0, 0}, | |
338 | ||
339 | /* GETA (1, 0). */ | |
340 | {GETA_0F, GETA_0B, 0, ENCODE_RELAX (STATE_GETA, STATE_MAX)}, | |
341 | ||
342 | /* GETA (1, 1). */ | |
343 | {GETA_3F, GETA_3B, | |
344 | GETA_MAX_LEN - 4, 0}, | |
345 | ||
346 | /* BCC (2, 0). */ | |
347 | {BCC_0F, BCC_0B, 0, ENCODE_RELAX (STATE_BCC, STATE_MAX)}, | |
348 | ||
349 | /* BCC (2, 1). */ | |
350 | {BCC_5F, BCC_5B, | |
351 | BCC_MAX_LEN - 4, 0}, | |
352 | ||
88fc725d HPN |
353 | /* PUSHJ (3, 0). Next state is actually PUSHJSTUB (6, 0). */ |
354 | {PUSHJ_0F, PUSHJ_0B, 0, ENCODE_RELAX (STATE_PUSHJSTUB, STATE_ZERO)}, | |
3c3bdf30 NC |
355 | |
356 | /* PUSHJ (3, 1). */ | |
357 | {PUSHJ_4F, PUSHJ_4B, | |
358 | PUSHJ_MAX_LEN - 4, 0}, | |
359 | ||
360 | /* JMP (4, 0). */ | |
361 | {JMP_0F, JMP_0B, 0, ENCODE_RELAX (STATE_JMP, STATE_MAX)}, | |
362 | ||
363 | /* JMP (4, 1). */ | |
364 | {JMP_4F, JMP_4B, | |
365 | JMP_MAX_LEN - 4, 0}, | |
366 | ||
367 | /* GREG (5, 0), (5, 1), though the table entry isn't used. */ | |
88fc725d HPN |
368 | {0, 0, 0, 0}, {0, 0, 0, 0}, |
369 | ||
370 | /* PUSHJSTUB (6, 0). PUSHJ (3, 0) uses the range, so we set it to infinite. */ | |
371 | {PUSHJSTUB_MAX, PUSHJSTUB_MIN, | |
372 | 0, ENCODE_RELAX (STATE_PUSHJ, STATE_MAX)}, | |
373 | /* PUSHJSTUB (6, 1) isn't used. */ | |
374 | {0, 0, PUSHJ_MAX_LEN, 0} | |
3c3bdf30 NC |
375 | }; |
376 | ||
377 | const pseudo_typeS md_pseudo_table[] = | |
378 | { | |
379 | /* Support " .greg sym,expr" syntax. */ | |
380 | {"greg", s_greg, 0}, | |
381 | ||
382 | /* Support " .bspec expr" syntax. */ | |
383 | {"bspec", s_bspec, 1}, | |
384 | ||
385 | /* Support " .espec" syntax. */ | |
386 | {"espec", s_espec, 1}, | |
387 | ||
388 | /* Support " .local $45" syntax. */ | |
389 | {"local", mmix_s_local, 1}, | |
390 | ||
3c3bdf30 NC |
391 | {NULL, 0, 0} |
392 | }; | |
393 | ||
394 | const char mmix_comment_chars[] = "%!"; | |
395 | ||
396 | /* A ':' is a valid symbol character in mmixal. It's the prefix | |
397 | delimiter, but other than that, it works like a symbol character, | |
398 | except that we strip one off at the beginning of symbols. An '@' is a | |
399 | symbol by itself (for the current location); space around it must not | |
400 | be stripped. */ | |
401 | const char mmix_symbol_chars[] = ":@"; | |
402 | ||
403 | const char line_comment_chars[] = "*#"; | |
404 | ||
405 | const char line_separator_chars[] = ";"; | |
406 | ||
407 | const char mmix_exp_chars[] = "eE"; | |
408 | ||
409 | const char mmix_flt_chars[] = "rf"; | |
410 | ||
411 | ||
412 | /* Fill in the offset-related part of GETA or Bcc. */ | |
413 | ||
414 | static void | |
415 | mmix_set_geta_branch_offset (opcodep, value) | |
416 | char *opcodep; | |
417 | offsetT value; | |
418 | { | |
419 | if (value < 0) | |
420 | { | |
421 | value += 65536 * 4; | |
422 | opcodep[0] |= 1; | |
423 | } | |
424 | ||
425 | value /= 4; | |
426 | md_number_to_chars (opcodep + 2, value, 2); | |
427 | } | |
428 | ||
429 | /* Fill in the offset-related part of JMP. */ | |
430 | ||
431 | static void | |
432 | mmix_set_jmp_offset (opcodep, value) | |
433 | char *opcodep; | |
434 | offsetT value; | |
435 | { | |
436 | if (value < 0) | |
437 | { | |
438 | value += 65536 * 256 * 4; | |
439 | opcodep[0] |= 1; | |
440 | } | |
441 | ||
442 | value /= 4; | |
443 | md_number_to_chars (opcodep + 1, value, 3); | |
444 | } | |
445 | ||
446 | /* Fill in NOP:s for the expanded part of GETA/JMP/Bcc/PUSHJ. */ | |
447 | ||
448 | static void | |
449 | mmix_fill_nops (opcodep, n) | |
450 | char *opcodep; | |
451 | int n; | |
452 | { | |
453 | int i; | |
454 | ||
455 | for (i = 0; i < n; i++) | |
a1b6236b | 456 | md_number_to_chars (opcodep + i * 4, SWYM_INSN_BYTE << 24, 4); |
3c3bdf30 NC |
457 | } |
458 | ||
459 | /* See macro md_parse_name in tc-mmix.h. */ | |
460 | ||
461 | int | |
462 | mmix_current_location (fn, exp) | |
463 | void (*fn) PARAMS ((expressionS *)); | |
464 | expressionS *exp; | |
465 | { | |
466 | (*fn) (exp); | |
467 | ||
468 | return 1; | |
469 | } | |
470 | ||
471 | /* Get up to three operands, filling them into the exp array. | |
472 | General idea and code stolen from the tic80 port. */ | |
473 | ||
474 | static int | |
475 | get_operands (max_operands, s, exp) | |
476 | int max_operands; | |
477 | char *s; | |
478 | expressionS exp[]; | |
479 | { | |
480 | char *p = s; | |
481 | int numexp = 0; | |
482 | int nextchar = ','; | |
483 | ||
484 | while (nextchar == ',') | |
485 | { | |
486 | /* Skip leading whitespace */ | |
487 | while (*p == ' ' || *p == '\t') | |
488 | p++; | |
489 | ||
490 | /* Check to see if we have any operands left to parse */ | |
491 | if (*p == 0 || *p == '\n' || *p == '\r') | |
492 | { | |
493 | break; | |
494 | } | |
495 | else if (numexp == max_operands) | |
496 | { | |
497 | /* This seems more sane than saying "too many operands". We'll | |
498 | get here only if the trailing trash starts with a comma. */ | |
499 | as_bad (_("invalid operands")); | |
500 | mmix_discard_rest_of_line (); | |
501 | return 0; | |
502 | } | |
503 | ||
a1b6236b | 504 | /* Begin operand parsing at the current scan point. */ |
3c3bdf30 NC |
505 | |
506 | input_line_pointer = p; | |
507 | expression (&exp[numexp]); | |
508 | ||
509 | if (exp[numexp].X_op == O_illegal) | |
510 | { | |
511 | as_bad (_("invalid operands")); | |
512 | } | |
513 | else if (exp[numexp].X_op == O_absent) | |
514 | { | |
515 | as_bad (_("missing operand")); | |
516 | } | |
517 | ||
518 | numexp++; | |
519 | p = input_line_pointer; | |
520 | ||
521 | /* Skip leading whitespace */ | |
522 | while (*p == ' ' || *p == '\t') | |
523 | p++; | |
524 | nextchar = *p++; | |
525 | } | |
526 | ||
527 | /* If we allow "naked" comments, ignore the rest of the line. */ | |
528 | if (nextchar != ',') | |
529 | { | |
530 | mmix_handle_rest_of_empty_line (); | |
531 | input_line_pointer--; | |
532 | } | |
533 | ||
a1b6236b | 534 | /* Mark the end of the valid operands with an illegal expression. */ |
3c3bdf30 NC |
535 | exp[numexp].X_op = O_illegal; |
536 | ||
537 | return (numexp); | |
538 | } | |
539 | ||
540 | /* Get the value of a special register, or -1 if the name does not match | |
541 | one. NAME is a null-terminated string. */ | |
542 | ||
543 | static int | |
544 | get_spec_regno (name) | |
545 | char *name; | |
546 | { | |
547 | int i; | |
548 | ||
549 | if (name == NULL) | |
550 | return -1; | |
551 | ||
552 | if (*name == ':') | |
553 | name++; | |
554 | ||
555 | /* Well, it's a short array and we'll most often just match the first | |
556 | entry, rJ. */ | |
557 | for (i = 0; mmix_spec_regs[i].name != NULL; i++) | |
558 | if (strcmp (name, mmix_spec_regs[i].name) == 0) | |
559 | return mmix_spec_regs[i].number; | |
560 | ||
561 | return -1; | |
562 | } | |
563 | ||
564 | /* For GET and PUT, parse the register names "manually", so we don't use | |
565 | user labels. */ | |
566 | static int | |
567 | get_putget_operands (insn, operands, exp) | |
568 | struct mmix_opcode *insn; | |
569 | char *operands; | |
570 | expressionS exp[]; | |
571 | { | |
572 | expressionS *expp_reg; | |
573 | expressionS *expp_sreg; | |
574 | char *sregp = NULL; | |
575 | char *sregend = operands; | |
576 | char *p = operands; | |
577 | char c = *sregend; | |
578 | int regno; | |
579 | ||
580 | /* Skip leading whitespace */ | |
581 | while (*p == ' ' || *p == '\t') | |
582 | p++; | |
583 | ||
584 | input_line_pointer = p; | |
585 | ||
480c8d94 HPN |
586 | /* Initialize both possible operands to error state, in case we never |
587 | get further. */ | |
588 | exp[0].X_op = O_illegal; | |
589 | exp[1].X_op = O_illegal; | |
590 | ||
3c3bdf30 NC |
591 | if (insn->operands == mmix_operands_get) |
592 | { | |
593 | expp_reg = &exp[0]; | |
594 | expp_sreg = &exp[1]; | |
595 | ||
596 | expression (expp_reg); | |
597 | ||
598 | p = input_line_pointer; | |
599 | ||
600 | /* Skip whitespace */ | |
601 | while (*p == ' ' || *p == '\t') | |
602 | p++; | |
603 | ||
604 | if (*p == ',') | |
605 | { | |
606 | p++; | |
607 | ||
608 | /* Skip whitespace */ | |
609 | while (*p == ' ' || *p == '\t') | |
610 | p++; | |
611 | sregp = p; | |
612 | input_line_pointer = sregp; | |
613 | c = get_symbol_end (); | |
614 | sregend = input_line_pointer; | |
615 | } | |
616 | } | |
617 | else | |
618 | { | |
619 | expp_sreg = &exp[0]; | |
620 | expp_reg = &exp[1]; | |
621 | ||
3c3bdf30 NC |
622 | sregp = p; |
623 | c = get_symbol_end (); | |
624 | sregend = p = input_line_pointer; | |
625 | *p = c; | |
626 | ||
627 | /* Skip whitespace */ | |
628 | while (*p == ' ' || *p == '\t') | |
629 | p++; | |
630 | ||
631 | if (*p == ',') | |
632 | { | |
633 | p++; | |
634 | ||
635 | /* Skip whitespace */ | |
636 | while (*p == ' ' || *p == '\t') | |
637 | p++; | |
638 | ||
639 | input_line_pointer = p; | |
640 | expression (expp_reg); | |
641 | } | |
642 | *sregend = 0; | |
643 | } | |
644 | ||
645 | regno = get_spec_regno (sregp); | |
646 | *sregend = c; | |
647 | ||
648 | /* Let the caller issue errors; we've made sure the operands are | |
649 | invalid. */ | |
650 | if (expp_reg->X_op != O_illegal | |
651 | && expp_reg->X_op != O_absent | |
652 | && regno != -1) | |
653 | { | |
654 | expp_sreg->X_op = O_register; | |
655 | expp_sreg->X_add_number = regno + 256; | |
656 | } | |
657 | ||
658 | return 2; | |
659 | } | |
660 | ||
661 | /* Handle MMIX-specific option. */ | |
662 | ||
663 | int | |
664 | md_parse_option (c, arg) | |
665 | int c; | |
666 | char *arg ATTRIBUTE_UNUSED; | |
667 | { | |
668 | switch (c) | |
669 | { | |
670 | case 'x': | |
671 | warn_on_expansion = 0; | |
973eb340 | 672 | allocate_undefined_gregs_in_linker = 1; |
3c3bdf30 NC |
673 | break; |
674 | ||
675 | case OPTION_RELAX: | |
676 | linkrelax = 1; | |
677 | break; | |
678 | ||
679 | case OPTION_NOEXPAND: | |
680 | expand_op = 0; | |
681 | break; | |
682 | ||
683 | case OPTION_NOMERGEGREG: | |
684 | merge_gregs = 0; | |
685 | break; | |
686 | ||
687 | case OPTION_NOSYMS: | |
688 | predefined_syms = 0; | |
689 | equated_spec_regs = 0; | |
690 | break; | |
691 | ||
692 | case OPTION_GNU_SYNTAX: | |
693 | mmix_gnu_syntax = 1; | |
694 | label_without_colon_this_line = 0; | |
695 | break; | |
696 | ||
697 | case OPTION_GLOBALIZE_SYMBOLS: | |
698 | mmix_globalize_symbols = 1; | |
699 | break; | |
700 | ||
701 | case OPTION_FIXED_SPEC_REGS: | |
702 | equated_spec_regs = 0; | |
703 | break; | |
704 | ||
973eb340 HPN |
705 | case OPTION_LINKER_ALLOCATED_GREGS: |
706 | allocate_undefined_gregs_in_linker = 1; | |
707 | break; | |
708 | ||
88fc725d HPN |
709 | case OPTION_NOPUSHJSTUBS: |
710 | pushj_stubs = 0; | |
711 | break; | |
712 | ||
3c3bdf30 NC |
713 | default: |
714 | return 0; | |
715 | } | |
716 | ||
717 | return 1; | |
718 | } | |
719 | ||
720 | /* Display MMIX-specific help text. */ | |
721 | ||
722 | void | |
723 | md_show_usage (stream) | |
724 | FILE * stream; | |
725 | { | |
726 | fprintf (stream, _(" MMIX-specific command line options:\n")); | |
727 | fprintf (stream, _("\ | |
728 | -fixed-special-register-names\n\ | |
729 | Allow only the original special register names.\n")); | |
730 | fprintf (stream, _("\ | |
731 | -globalize-symbols Make all symbols global.\n")); | |
732 | fprintf (stream, _("\ | |
733 | -gnu-syntax Turn off mmixal syntax compatibility.\n")); | |
734 | fprintf (stream, _("\ | |
735 | -relax Create linker relaxable code.\n")); | |
736 | fprintf (stream, _("\ | |
737 | -no-predefined-syms Do not provide mmixal built-in constants.\n\ | |
738 | Implies -fixed-special-register-names.\n")); | |
739 | fprintf (stream, _("\ | |
740 | -no-expand Do not expand GETA, branches, PUSHJ or JUMP\n\ | |
741 | into multiple instructions.\n")); | |
742 | fprintf (stream, _("\ | |
743 | -no-merge-gregs Do not merge GREG definitions with nearby values.\n")); | |
744 | fprintf (stream, _("\ | |
973eb340 HPN |
745 | -linker-allocated-gregs If there's no suitable GREG definition for the\ |
746 | operands of an instruction, let the linker resolve.\n")); | |
747 | fprintf (stream, _("\ | |
3c3bdf30 NC |
748 | -x Do not warn when an operand to GETA, a branch,\n\ |
749 | PUSHJ or JUMP is not known to be within range.\n\ | |
973eb340 HPN |
750 | The linker will catch any errors. Implies\n\ |
751 | -linker-allocated-gregs.")); | |
3c3bdf30 NC |
752 | } |
753 | ||
754 | /* Step to end of line, but don't step over the end of the line. */ | |
755 | ||
756 | static void | |
757 | mmix_discard_rest_of_line () | |
758 | { | |
759 | while (*input_line_pointer | |
a1b6236b | 760 | && (! is_end_of_line[(unsigned char) *input_line_pointer] |
3c3bdf30 NC |
761 | || TC_EOL_IN_INSN (input_line_pointer))) |
762 | input_line_pointer++; | |
763 | } | |
764 | ||
765 | /* Act as demand_empty_rest_of_line if we're in strict GNU syntax mode, | |
766 | otherwise just ignore the rest of the line (and skip the end-of-line | |
767 | delimiter). */ | |
768 | ||
769 | static void | |
770 | mmix_handle_rest_of_empty_line () | |
771 | { | |
772 | if (mmix_gnu_syntax) | |
773 | demand_empty_rest_of_line (); | |
774 | else | |
775 | { | |
776 | mmix_discard_rest_of_line (); | |
777 | input_line_pointer++; | |
778 | } | |
779 | } | |
780 | ||
781 | /* Initialize GAS MMIX specifics. */ | |
782 | ||
783 | void | |
784 | mmix_md_begin () | |
785 | { | |
786 | int i; | |
787 | const struct mmix_opcode *opcode; | |
788 | ||
789 | /* We assume nobody will use this, so don't allocate any room. */ | |
790 | obstack_begin (&mmix_sym_obstack, 0); | |
791 | ||
792 | /* This will break the day the "lex" thingy changes. For now, it's the | |
793 | only way to make ':' part of a name, and a name beginner. */ | |
a1b6236b | 794 | lex_type[':'] = (LEX_NAME | LEX_BEGIN_NAME); |
3c3bdf30 NC |
795 | |
796 | mmix_opcode_hash = hash_new (); | |
797 | ||
798 | real_reg_section | |
799 | = bfd_make_section_old_way (stdoutput, MMIX_REG_SECTION_NAME); | |
800 | ||
801 | for (opcode = mmix_opcodes; opcode->name; opcode++) | |
802 | hash_insert (mmix_opcode_hash, opcode->name, (char *) opcode); | |
803 | ||
804 | /* We always insert the ordinary registers 0..255 as registers. */ | |
805 | for (i = 0; i < 256; i++) | |
806 | { | |
807 | char buf[5]; | |
808 | ||
809 | /* Alternatively, we could diddle with '$' and the following number, | |
810 | but keeping the registers as symbols helps keep parsing simple. */ | |
811 | sprintf (buf, "$%d", i); | |
812 | symbol_table_insert (symbol_new (buf, reg_section, i, | |
813 | &zero_address_frag)); | |
814 | } | |
815 | ||
816 | /* Insert mmixal built-in names if allowed. */ | |
817 | if (predefined_syms) | |
818 | { | |
819 | for (i = 0; mmix_spec_regs[i].name != NULL; i++) | |
820 | symbol_table_insert (symbol_new (mmix_spec_regs[i].name, | |
821 | reg_section, | |
822 | mmix_spec_regs[i].number + 256, | |
823 | &zero_address_frag)); | |
824 | ||
825 | /* FIXME: Perhaps these should be recognized as specials; as field | |
826 | names for those instructions. */ | |
827 | symbol_table_insert (symbol_new ("ROUND_CURRENT", reg_section, 512, | |
828 | &zero_address_frag)); | |
829 | symbol_table_insert (symbol_new ("ROUND_OFF", reg_section, 512 + 1, | |
830 | &zero_address_frag)); | |
831 | symbol_table_insert (symbol_new ("ROUND_UP", reg_section, 512 + 2, | |
832 | &zero_address_frag)); | |
833 | symbol_table_insert (symbol_new ("ROUND_DOWN", reg_section, 512 + 3, | |
834 | &zero_address_frag)); | |
835 | symbol_table_insert (symbol_new ("ROUND_NEAR", reg_section, 512 + 4, | |
836 | &zero_address_frag)); | |
837 | } | |
838 | } | |
839 | ||
840 | /* Assemble one insn in STR. */ | |
841 | ||
842 | void | |
843 | md_assemble (str) | |
844 | char *str; | |
845 | { | |
846 | char *operands = str; | |
847 | char modified_char = 0; | |
848 | struct mmix_opcode *instruction; | |
849 | fragS *opc_fragP = NULL; | |
850 | int max_operands = 3; | |
851 | ||
852 | /* Note that the struct frag member fr_literal in frags.h is char[], so | |
853 | I have to make this a plain char *. */ | |
854 | /* unsigned */ char *opcodep = NULL; | |
855 | ||
856 | expressionS exp[4]; | |
857 | int n_operands = 0; | |
858 | ||
859 | /* Move to end of opcode. */ | |
860 | for (operands = str; | |
861 | is_part_of_name (*operands); | |
862 | ++operands) | |
863 | ; | |
864 | ||
865 | if (ISSPACE (*operands)) | |
866 | { | |
867 | modified_char = *operands; | |
868 | *operands++ = '\0'; | |
869 | } | |
870 | ||
871 | instruction = (struct mmix_opcode *) hash_find (mmix_opcode_hash, str); | |
872 | if (instruction == NULL) | |
873 | { | |
874 | as_bad (_("unknown opcode: `%s'"), str); | |
875 | ||
876 | /* Avoid "unhandled label" errors. */ | |
877 | pending_label = NULL; | |
878 | return; | |
879 | } | |
880 | ||
881 | /* Put back the character after the opcode. */ | |
882 | if (modified_char != 0) | |
883 | operands[-1] = modified_char; | |
884 | ||
885 | input_line_pointer = operands; | |
886 | ||
887 | /* Is this a mmixal pseudodirective? */ | |
888 | if (instruction->type == mmix_type_pseudo) | |
889 | { | |
890 | /* For mmixal compatibility, a label for an instruction (and | |
891 | emitting pseudo) refers to the _aligned_ address. We emit the | |
892 | label here for the pseudos that don't handle it themselves. When | |
893 | having an fb-label, emit it here, and increment the counter after | |
894 | the pseudo. */ | |
895 | switch (instruction->operands) | |
896 | { | |
897 | case mmix_operands_loc: | |
898 | case mmix_operands_byte: | |
899 | case mmix_operands_prefix: | |
900 | case mmix_operands_local: | |
901 | case mmix_operands_bspec: | |
902 | case mmix_operands_espec: | |
903 | if (current_fb_label >= 0) | |
904 | colon (fb_label_name (current_fb_label, 1)); | |
905 | else if (pending_label != NULL) | |
906 | { | |
907 | colon (pending_label); | |
908 | pending_label = NULL; | |
909 | } | |
910 | break; | |
911 | ||
912 | default: | |
913 | break; | |
914 | } | |
915 | ||
916 | /* Some of the pseudos emit contents, others don't. Set a | |
917 | contents-emitted flag when we emit something into .text */ | |
918 | switch (instruction->operands) | |
919 | { | |
920 | case mmix_operands_loc: | |
921 | /* LOC */ | |
922 | s_loc (0); | |
923 | break; | |
924 | ||
925 | case mmix_operands_byte: | |
926 | /* BYTE */ | |
927 | mmix_byte (); | |
928 | break; | |
929 | ||
930 | case mmix_operands_wyde: | |
931 | /* WYDE */ | |
932 | mmix_cons (2); | |
933 | break; | |
934 | ||
935 | case mmix_operands_tetra: | |
936 | /* TETRA */ | |
937 | mmix_cons (4); | |
938 | break; | |
939 | ||
940 | case mmix_operands_octa: | |
941 | /* OCTA */ | |
942 | mmix_cons (8); | |
943 | break; | |
944 | ||
945 | case mmix_operands_prefix: | |
946 | /* PREFIX */ | |
947 | s_prefix (0); | |
948 | break; | |
949 | ||
950 | case mmix_operands_local: | |
951 | /* LOCAL */ | |
952 | mmix_s_local (0); | |
953 | break; | |
954 | ||
955 | case mmix_operands_bspec: | |
956 | /* BSPEC */ | |
957 | s_bspec (0); | |
958 | break; | |
959 | ||
960 | case mmix_operands_espec: | |
961 | /* ESPEC */ | |
962 | s_espec (0); | |
963 | break; | |
964 | ||
965 | default: | |
966 | BAD_CASE (instruction->operands); | |
967 | } | |
968 | ||
969 | /* These are all working like the pseudo functions in read.c:s_..., | |
970 | in that they step over the end-of-line marker at the end of the | |
971 | line. We don't want that here. */ | |
972 | input_line_pointer--; | |
973 | ||
974 | /* Step up the fb-label counter if there was a definition on this | |
975 | line. */ | |
976 | if (current_fb_label >= 0) | |
977 | { | |
978 | fb_label_instance_inc (current_fb_label); | |
979 | current_fb_label = -1; | |
980 | } | |
981 | ||
982 | /* Reset any don't-align-next-datum request, unless this was a LOC | |
983 | directive. */ | |
984 | if (instruction->operands != mmix_operands_loc) | |
985 | want_unaligned = 0; | |
986 | ||
987 | return; | |
988 | } | |
989 | ||
990 | /* Not a pseudo; we *will* emit contents. */ | |
991 | if (now_seg == data_section) | |
992 | { | |
993 | if (lowest_data_loc != (bfd_vma) -1 && (lowest_data_loc & 3) != 0) | |
994 | { | |
995 | if (data_has_contents) | |
996 | as_bad (_("specified location wasn't TETRA-aligned")); | |
997 | else if (want_unaligned) | |
998 | as_bad (_("unaligned data at an absolute location is not supported")); | |
999 | ||
1000 | lowest_data_loc &= ~(bfd_vma) 3; | |
1001 | lowest_data_loc += 4; | |
1002 | } | |
1003 | ||
1004 | data_has_contents = 1; | |
1005 | } | |
1006 | else if (now_seg == text_section) | |
1007 | { | |
1008 | if (lowest_text_loc != (bfd_vma) -1 && (lowest_text_loc & 3) != 0) | |
1009 | { | |
1010 | if (text_has_contents) | |
1011 | as_bad (_("specified location wasn't TETRA-aligned")); | |
1012 | else if (want_unaligned) | |
1013 | as_bad (_("unaligned data at an absolute location is not supported")); | |
1014 | ||
1015 | lowest_text_loc &= ~(bfd_vma) 3; | |
1016 | lowest_text_loc += 4; | |
1017 | } | |
1018 | ||
1019 | text_has_contents = 1; | |
1020 | } | |
1021 | ||
1022 | /* After a sequence of BYTEs or WYDEs, we need to get to instruction | |
1023 | alignment. For other pseudos, a ".p2align 2" is supposed to be | |
1024 | inserted by the user. */ | |
1025 | if (last_alignment < 2 && ! want_unaligned) | |
1026 | { | |
1027 | frag_align (2, 0, 0); | |
1028 | record_alignment (now_seg, 2); | |
1029 | last_alignment = 2; | |
1030 | } | |
1031 | else | |
1032 | /* Reset any don't-align-next-datum request. */ | |
1033 | want_unaligned = 0; | |
1034 | ||
1035 | /* For mmixal compatibility, a label for an instruction (and emitting | |
1036 | pseudo) refers to the _aligned_ address. So we have to emit the | |
1037 | label here. */ | |
1038 | if (pending_label != NULL) | |
1039 | { | |
1040 | colon (pending_label); | |
1041 | pending_label = NULL; | |
1042 | } | |
1043 | ||
1044 | /* We assume that mmix_opcodes keeps having unique mnemonics for each | |
1045 | opcode, so we don't have to iterate over more than one opcode; if the | |
1046 | syntax does not match, then there's a syntax error. */ | |
1047 | ||
1048 | /* Operands have little or no context and are all comma-separated; it is | |
1049 | easier to parse each expression first. */ | |
1050 | switch (instruction->operands) | |
1051 | { | |
1052 | case mmix_operands_reg_yz: | |
1053 | case mmix_operands_pop: | |
1054 | case mmix_operands_regaddr: | |
1055 | case mmix_operands_pushj: | |
1056 | case mmix_operands_get: | |
1057 | case mmix_operands_put: | |
1058 | case mmix_operands_set: | |
1059 | case mmix_operands_save: | |
1060 | case mmix_operands_unsave: | |
1061 | max_operands = 2; | |
1062 | break; | |
1063 | ||
1064 | case mmix_operands_sync: | |
1065 | case mmix_operands_jmp: | |
1066 | case mmix_operands_resume: | |
1067 | max_operands = 1; | |
1068 | break; | |
1069 | ||
1070 | /* The original 3 is fine for the rest. */ | |
1071 | default: | |
1072 | break; | |
1073 | } | |
1074 | ||
1075 | /* If this is GET or PUT, and we don't do allow those names to be | |
1076 | equated, we need to parse the names ourselves, so we don't pick up a | |
1077 | user label instead of the special register. */ | |
1078 | if (! equated_spec_regs | |
1079 | && (instruction->operands == mmix_operands_get | |
1080 | || instruction->operands == mmix_operands_put)) | |
1081 | n_operands = get_putget_operands (instruction, operands, exp); | |
1082 | else | |
1083 | n_operands = get_operands (max_operands, operands, exp); | |
1084 | ||
1085 | /* If there's a fb-label on the current line, set that label. This must | |
1086 | be done *after* evaluating expressions of operands, since neither a | |
1087 | "1B" nor a "1F" refers to "1H" on the same line. */ | |
1088 | if (current_fb_label >= 0) | |
1089 | { | |
1090 | fb_label_instance_inc (current_fb_label); | |
1091 | colon (fb_label_name (current_fb_label, 0)); | |
1092 | current_fb_label = -1; | |
1093 | } | |
1094 | ||
973eb340 HPN |
1095 | /* We also assume that the length of the instruction is at least 4, the |
1096 | size of an unexpanded instruction. We need a self-contained frag | |
1097 | since we want the relocation to point to the instruction, not the | |
1098 | variant part. */ | |
3c3bdf30 NC |
1099 | |
1100 | opcodep = frag_more (4); | |
1101 | mmix_opcode_frag = opc_fragP = frag_now; | |
1102 | frag_now->fr_opcode = opcodep; | |
1103 | ||
1104 | /* Mark start of insn for DWARF2 debug features. */ | |
1105 | if (OUTPUT_FLAVOR == bfd_target_elf_flavour) | |
1106 | dwarf2_emit_insn (4); | |
1107 | ||
1108 | md_number_to_chars (opcodep, instruction->match, 4); | |
1109 | ||
1110 | switch (instruction->operands) | |
1111 | { | |
1112 | case mmix_operands_jmp: | |
1113 | if (n_operands == 0 && ! mmix_gnu_syntax) | |
1114 | /* Zeros are in place - nothing needs to be done when we have no | |
1115 | operands. */ | |
1116 | break; | |
1117 | ||
1118 | /* Add a frag for a JMP relaxation; we need room for max four | |
1119 | extra instructions. We don't do any work around here to check if | |
1120 | we can determine the offset right away. */ | |
1121 | if (n_operands != 1 || exp[0].X_op == O_register) | |
1122 | { | |
1123 | as_bad (_("invalid operand to opcode %s: `%s'"), | |
1124 | instruction->name, operands); | |
1125 | return; | |
1126 | } | |
1127 | ||
1128 | if (expand_op) | |
a1b6236b | 1129 | frag_var (rs_machine_dependent, 4 * 4, 0, |
3c3bdf30 NC |
1130 | ENCODE_RELAX (STATE_JMP, STATE_UNDF), |
1131 | exp[0].X_add_symbol, | |
1132 | exp[0].X_add_number, | |
1133 | opcodep); | |
1134 | else | |
1135 | fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal, 4, | |
1136 | exp + 0, 1, BFD_RELOC_MMIX_ADDR27); | |
1137 | break; | |
1138 | ||
1139 | case mmix_operands_pushj: | |
1140 | /* We take care of PUSHJ in full here. */ | |
1141 | if (n_operands != 2 | |
1142 | || ((exp[0].X_op == O_constant || exp[0].X_op == O_register) | |
1143 | && (exp[0].X_add_number > 255 || exp[0].X_add_number < 0))) | |
1144 | { | |
1145 | as_bad (_("invalid operands to opcode %s: `%s'"), | |
1146 | instruction->name, operands); | |
1147 | return; | |
1148 | } | |
1149 | ||
1150 | if (exp[0].X_op == O_register || exp[0].X_op == O_constant) | |
1151 | opcodep[1] = exp[0].X_add_number; | |
1152 | else | |
1153 | fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 1, | |
1154 | 1, exp + 0, 0, BFD_RELOC_MMIX_REG_OR_BYTE); | |
1155 | ||
1156 | if (expand_op) | |
1157 | frag_var (rs_machine_dependent, PUSHJ_MAX_LEN - 4, 0, | |
1158 | ENCODE_RELAX (STATE_PUSHJ, STATE_UNDF), | |
1159 | exp[1].X_add_symbol, | |
1160 | exp[1].X_add_number, | |
1161 | opcodep); | |
1162 | else | |
1163 | fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal, 4, | |
1164 | exp + 1, 1, BFD_RELOC_MMIX_ADDR19); | |
1165 | break; | |
1166 | ||
1167 | case mmix_operands_regaddr: | |
1168 | /* GETA/branch: Add a frag for relaxation. We don't do any work | |
1169 | around here to check if we can determine the offset right away. */ | |
1170 | if (n_operands != 2 || exp[1].X_op == O_register) | |
1171 | { | |
1172 | as_bad (_("invalid operands to opcode %s: `%s'"), | |
1173 | instruction->name, operands); | |
1174 | return; | |
1175 | } | |
1176 | ||
1177 | if (! expand_op) | |
1178 | fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal, 4, | |
1179 | exp + 1, 1, BFD_RELOC_MMIX_ADDR19); | |
1180 | else if (instruction->type == mmix_type_condbranch) | |
1181 | frag_var (rs_machine_dependent, BCC_MAX_LEN - 4, 0, | |
1182 | ENCODE_RELAX (STATE_BCC, STATE_UNDF), | |
1183 | exp[1].X_add_symbol, | |
1184 | exp[1].X_add_number, | |
1185 | opcodep); | |
1186 | else | |
1187 | frag_var (rs_machine_dependent, GETA_MAX_LEN - 4, 0, | |
1188 | ENCODE_RELAX (STATE_GETA, STATE_UNDF), | |
1189 | exp[1].X_add_symbol, | |
1190 | exp[1].X_add_number, | |
1191 | opcodep); | |
1192 | break; | |
1193 | ||
1194 | default: | |
1195 | break; | |
1196 | } | |
1197 | ||
1198 | switch (instruction->operands) | |
1199 | { | |
1200 | case mmix_operands_regs: | |
1201 | /* We check the number of operands here, since we're in a | |
1202 | FALLTHROUGH sequence in the next switch. */ | |
1203 | if (n_operands != 3 || exp[2].X_op == O_constant) | |
1204 | { | |
1205 | as_bad (_("invalid operands to opcode %s: `%s'"), | |
1206 | instruction->name, operands); | |
1207 | return; | |
1208 | } | |
1209 | /* FALLTHROUGH. */ | |
1210 | case mmix_operands_regs_z: | |
1211 | if (n_operands != 3) | |
1212 | { | |
1213 | as_bad (_("invalid operands to opcode %s: `%s'"), | |
1214 | instruction->name, operands); | |
1215 | return; | |
1216 | } | |
1217 | /* FALLTHROUGH. */ | |
1218 | case mmix_operands_reg_yz: | |
1219 | case mmix_operands_roundregs_z: | |
1220 | case mmix_operands_roundregs: | |
1221 | case mmix_operands_regs_z_opt: | |
1222 | case mmix_operands_neg: | |
1223 | case mmix_operands_regaddr: | |
1224 | case mmix_operands_get: | |
1225 | case mmix_operands_set: | |
1226 | case mmix_operands_save: | |
1227 | if (n_operands < 1 | |
1228 | || (exp[0].X_op == O_register && exp[0].X_add_number > 255)) | |
1229 | { | |
1230 | as_bad (_("invalid operands to opcode %s: `%s'"), | |
1231 | instruction->name, operands); | |
1232 | return; | |
1233 | } | |
1234 | ||
1235 | if (exp[0].X_op == O_register) | |
1236 | opcodep[1] = exp[0].X_add_number; | |
1237 | else | |
1238 | fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 1, | |
1239 | 1, exp + 0, 0, BFD_RELOC_MMIX_REG); | |
1240 | break; | |
1241 | ||
1242 | default: | |
1243 | ; | |
1244 | } | |
1245 | ||
1246 | /* A corresponding once-over for those who take an 8-bit constant as | |
1247 | their first operand. */ | |
1248 | switch (instruction->operands) | |
1249 | { | |
1250 | case mmix_operands_pushgo: | |
1251 | /* PUSHGO: X is a constant, but can be expressed as a register. | |
1252 | We handle X here and use the common machinery of T,X,3,$ for | |
1253 | the rest of the operands. */ | |
1254 | if (n_operands < 2 | |
1255 | || ((exp[0].X_op == O_constant || exp[0].X_op == O_register) | |
1256 | && (exp[0].X_add_number > 255 || exp[0].X_add_number < 0))) | |
1257 | { | |
1258 | as_bad (_("invalid operands to opcode %s: `%s'"), | |
1259 | instruction->name, operands); | |
1260 | return; | |
1261 | } | |
1262 | else if (exp[0].X_op == O_constant || exp[0].X_op == O_register) | |
1263 | opcodep[1] = exp[0].X_add_number; | |
1264 | else | |
1265 | fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 1, | |
1266 | 1, exp + 0, 0, BFD_RELOC_MMIX_REG_OR_BYTE); | |
1267 | break; | |
1268 | ||
1269 | case mmix_operands_pop: | |
1270 | if ((n_operands == 0 || n_operands == 1) && ! mmix_gnu_syntax) | |
1271 | break; | |
1272 | /* FALLTHROUGH. */ | |
1273 | case mmix_operands_x_regs_z: | |
1274 | if (n_operands < 1 | |
1275 | || (exp[0].X_op == O_constant | |
1276 | && (exp[0].X_add_number > 255 | |
1277 | || exp[0].X_add_number < 0))) | |
1278 | { | |
1279 | as_bad (_("invalid operands to opcode %s: `%s'"), | |
1280 | instruction->name, operands); | |
1281 | return; | |
1282 | } | |
1283 | ||
1284 | if (exp[0].X_op == O_constant) | |
1285 | opcodep[1] = exp[0].X_add_number; | |
1286 | else | |
1287 | /* FIXME: This doesn't bring us unsignedness checking. */ | |
1288 | fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 1, | |
1289 | 1, exp + 0, 0, BFD_RELOC_8); | |
1290 | default: | |
1291 | ; | |
1292 | } | |
1293 | ||
1294 | /* Handle the rest. */ | |
1295 | switch (instruction->operands) | |
1296 | { | |
1297 | case mmix_operands_set: | |
1298 | /* SET: Either two registers, "$X,$Y", with Z field as zero, or | |
1299 | "$X,YZ", meaning change the opcode to SETL. */ | |
1300 | if (n_operands != 2 | |
1301 | || (exp[1].X_op == O_constant | |
1302 | && (exp[1].X_add_number > 0xffff || exp[1].X_add_number < 0))) | |
1303 | { | |
1304 | as_bad (_("invalid operands to opcode %s: `%s'"), | |
1305 | instruction->name, operands); | |
1306 | return; | |
1307 | } | |
1308 | ||
1309 | if (exp[1].X_op == O_constant) | |
1310 | { | |
1311 | /* There's an ambiguity with "SET $0,Y" when Y isn't defined | |
1312 | yet. To keep things simple, we assume that Y is then a | |
1313 | register, and only change the opcode if Y is defined at this | |
1314 | point. | |
1315 | ||
1316 | There's no compatibility problem with mmixal, since it emits | |
1317 | errors if the field is not defined at this point. */ | |
1318 | md_number_to_chars (opcodep, SETL_INSN_BYTE, 1); | |
1319 | ||
1320 | opcodep[2] = (exp[1].X_add_number >> 8) & 255; | |
1321 | opcodep[3] = exp[1].X_add_number & 255; | |
1322 | break; | |
1323 | } | |
1324 | /* FALLTHROUGH. */ | |
1325 | case mmix_operands_x_regs_z: | |
1326 | /* SYNCD: "X,$Y,$Z|Z". */ | |
1327 | /* FALLTHROUGH. */ | |
1328 | case mmix_operands_regs: | |
a1b6236b | 1329 | /* Three registers, $X,$Y,$Z. */ |
3c3bdf30 NC |
1330 | /* FALLTHROUGH. */ |
1331 | case mmix_operands_regs_z: | |
1332 | /* Operands "$X,$Y,$Z|Z", number of arguments checked above. */ | |
1333 | /* FALLTHROUGH. */ | |
1334 | case mmix_operands_pushgo: | |
1335 | /* Operands "$X|X,$Y,$Z|Z", optional Z. */ | |
1336 | /* FALLTHROUGH. */ | |
1337 | case mmix_operands_regs_z_opt: | |
1338 | /* Operands "$X,$Y,$Z|Z", with $Z|Z being optional, default 0. Any | |
1339 | operands not completely decided yet are postponed to later in | |
1340 | assembly (but not until link-time yet). */ | |
1341 | ||
1342 | if ((n_operands != 2 && n_operands != 3) | |
1343 | || (exp[1].X_op == O_register && exp[1].X_add_number > 255) | |
1344 | || (n_operands == 3 | |
1345 | && ((exp[2].X_op == O_register | |
1346 | && exp[2].X_add_number > 255 | |
1347 | && mmix_gnu_syntax) | |
1348 | || (exp[2].X_op == O_constant | |
1349 | && (exp[2].X_add_number > 255 | |
1350 | || exp[2].X_add_number < 0))))) | |
1351 | { | |
1352 | as_bad (_("invalid operands to opcode %s: `%s'"), | |
1353 | instruction->name, operands); | |
1354 | return; | |
1355 | } | |
1356 | ||
1357 | if (n_operands == 2) | |
1358 | { | |
1359 | symbolS *sym; | |
1360 | ||
1361 | /* The last operand is immediate whenever we see just two | |
1362 | operands. */ | |
1363 | opcodep[0] |= IMM_OFFSET_BIT; | |
1364 | ||
1365 | /* Now, we could either have an implied "0" as the Z operand, or | |
1366 | it could be the constant of a "base address plus offset". It | |
1367 | depends on whether it is allowed; only memory operations, as | |
1368 | signified by instruction->type and "T" and "X" operand types, | |
1369 | and it depends on whether we find a register in the second | |
1370 | operand, exp[1]. */ | |
1371 | if (exp[1].X_op == O_register && exp[1].X_add_number <= 255) | |
1372 | { | |
1373 | /* A zero then; all done. */ | |
1374 | opcodep[2] = exp[1].X_add_number; | |
1375 | break; | |
1376 | } | |
1377 | ||
1378 | /* Not known as a register. Is base address plus offset | |
1379 | allowed, or can we assume that it is a register anyway? */ | |
1380 | if ((instruction->operands != mmix_operands_regs_z_opt | |
1381 | && instruction->operands != mmix_operands_x_regs_z | |
1382 | && instruction->operands != mmix_operands_pushgo) | |
1383 | || (instruction->type != mmix_type_memaccess_octa | |
1384 | && instruction->type != mmix_type_memaccess_tetra | |
1385 | && instruction->type != mmix_type_memaccess_wyde | |
1386 | && instruction->type != mmix_type_memaccess_byte | |
1387 | && instruction->type != mmix_type_memaccess_block | |
1388 | && instruction->type != mmix_type_jsr | |
1389 | && instruction->type != mmix_type_branch)) | |
1390 | { | |
1391 | fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 2, | |
1392 | 1, exp + 1, 0, BFD_RELOC_MMIX_REG); | |
1393 | break; | |
1394 | } | |
1395 | ||
1396 | /* To avoid getting a NULL add_symbol for constants and then | |
1397 | catching a SEGV in write_relocs since it doesn't handle | |
1398 | constants well for relocs other than PC-relative, we need to | |
1399 | pass expressions as symbols and use fix_new, not fix_new_exp. */ | |
1400 | sym = make_expr_symbol (exp + 1); | |
1401 | ||
1402 | /* Now we know it can be a "base address plus offset". Add | |
1403 | proper fixup types so we can handle this later, when we've | |
1404 | parsed everything. */ | |
1405 | fix_new (opc_fragP, opcodep - opc_fragP->fr_literal + 2, | |
1406 | 8, sym, 0, 0, BFD_RELOC_MMIX_BASE_PLUS_OFFSET); | |
1407 | break; | |
1408 | } | |
1409 | ||
1410 | if (exp[1].X_op == O_register) | |
1411 | opcodep[2] = exp[1].X_add_number; | |
1412 | else | |
1413 | fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 2, | |
1414 | 1, exp + 1, 0, BFD_RELOC_MMIX_REG); | |
1415 | ||
1416 | /* In mmixal compatibility mode, we allow special registers as | |
1417 | constants for the Z operand. They have 256 added to their | |
1418 | register numbers, so the right thing will happen if we just treat | |
1419 | those as constants. */ | |
1420 | if (exp[2].X_op == O_register && exp[2].X_add_number <= 255) | |
1421 | opcodep[3] = exp[2].X_add_number; | |
1422 | else if (exp[2].X_op == O_constant | |
1423 | || (exp[2].X_op == O_register && exp[2].X_add_number > 255)) | |
1424 | { | |
1425 | opcodep[3] = exp[2].X_add_number; | |
1426 | opcodep[0] |= IMM_OFFSET_BIT; | |
1427 | } | |
1428 | else | |
1429 | fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 3, | |
1430 | 1, exp + 2, 0, | |
1431 | (instruction->operands == mmix_operands_set | |
1432 | || instruction->operands == mmix_operands_regs) | |
1433 | ? BFD_RELOC_MMIX_REG : BFD_RELOC_MMIX_REG_OR_BYTE); | |
1434 | break; | |
1435 | ||
1436 | case mmix_operands_pop: | |
1437 | /* POP, one eight and one 16-bit operand. */ | |
1438 | if (n_operands == 0 && ! mmix_gnu_syntax) | |
1439 | break; | |
1440 | if (n_operands == 1 && ! mmix_gnu_syntax) | |
1441 | goto a_single_24_bit_number_operand; | |
1442 | /* FALLTHROUGH. */ | |
1443 | case mmix_operands_reg_yz: | |
1444 | /* A register and a 16-bit unsigned number. */ | |
1445 | if (n_operands != 2 | |
1446 | || exp[1].X_op == O_register | |
1447 | || (exp[1].X_op == O_constant | |
1448 | && (exp[1].X_add_number > 0xffff || exp[1].X_add_number < 0))) | |
1449 | { | |
1450 | as_bad (_("invalid operands to opcode %s: `%s'"), | |
1451 | instruction->name, operands); | |
1452 | return; | |
1453 | } | |
1454 | ||
1455 | if (exp[1].X_op == O_constant) | |
1456 | { | |
1457 | opcodep[2] = (exp[1].X_add_number >> 8) & 255; | |
1458 | opcodep[3] = exp[1].X_add_number & 255; | |
1459 | } | |
1460 | else | |
1461 | /* FIXME: This doesn't bring us unsignedness checking. */ | |
1462 | fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 2, | |
1463 | 2, exp + 1, 0, BFD_RELOC_16); | |
1464 | break; | |
1465 | ||
1466 | case mmix_operands_jmp: | |
67c1ffbe | 1467 | /* A JMP. Everything is already done. */ |
3c3bdf30 NC |
1468 | break; |
1469 | ||
1470 | case mmix_operands_roundregs: | |
1471 | /* Two registers with optional rounding mode or constant in between. */ | |
1472 | if ((n_operands == 3 && exp[2].X_op == O_constant) | |
1473 | || (n_operands == 2 && exp[1].X_op == O_constant)) | |
1474 | { | |
1475 | as_bad (_("invalid operands to opcode %s: `%s'"), | |
1476 | instruction->name, operands); | |
1477 | return; | |
1478 | } | |
1479 | /* FALLTHROUGH. */ | |
1480 | case mmix_operands_roundregs_z: | |
1481 | /* Like FLOT, "$X,ROUND_MODE,$Z|Z", but the rounding mode is | |
1482 | optional and can be the corresponding constant. */ | |
1483 | { | |
1484 | /* Which exp index holds the second operand (not the rounding | |
1485 | mode). */ | |
1486 | int op2no = n_operands - 1; | |
1487 | ||
1488 | if ((n_operands != 2 && n_operands != 3) | |
1489 | || ((exp[op2no].X_op == O_register | |
1490 | && exp[op2no].X_add_number > 255) | |
1491 | || (exp[op2no].X_op == O_constant | |
1492 | && (exp[op2no].X_add_number > 255 | |
1493 | || exp[op2no].X_add_number < 0))) | |
1494 | || (n_operands == 3 | |
1495 | /* We don't allow for the rounding mode to be deferred; it | |
1496 | must be determined in the "first pass". It cannot be a | |
1497 | symbol equated to a rounding mode, but defined after | |
1498 | the first use. */ | |
1499 | && ((exp[1].X_op == O_register | |
1500 | && exp[1].X_add_number < 512) | |
1501 | || (exp[1].X_op == O_constant | |
1502 | && exp[1].X_add_number < 0 | |
1503 | && exp[1].X_add_number > 4) | |
1504 | || (exp[1].X_op != O_register | |
1505 | && exp[1].X_op != O_constant)))) | |
1506 | { | |
1507 | as_bad (_("invalid operands to opcode %s: `%s'"), | |
1508 | instruction->name, operands); | |
1509 | return; | |
1510 | } | |
1511 | ||
1512 | /* Add rounding mode if present. */ | |
1513 | if (n_operands == 3) | |
1514 | opcodep[2] = exp[1].X_add_number & 255; | |
1515 | ||
1516 | if (exp[op2no].X_op == O_register) | |
1517 | opcodep[3] = exp[op2no].X_add_number; | |
1518 | else if (exp[op2no].X_op == O_constant) | |
1519 | { | |
1520 | opcodep[3] = exp[op2no].X_add_number; | |
1521 | opcodep[0] |= IMM_OFFSET_BIT; | |
1522 | } | |
1523 | else | |
1524 | fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 3, | |
1525 | 1, exp + op2no, 0, | |
1526 | instruction->operands == mmix_operands_roundregs | |
1527 | ? BFD_RELOC_MMIX_REG | |
1528 | : BFD_RELOC_MMIX_REG_OR_BYTE); | |
1529 | break; | |
1530 | } | |
1531 | ||
1532 | case mmix_operands_sync: | |
1533 | a_single_24_bit_number_operand: | |
a1b6236b KH |
1534 | if (n_operands != 1 |
1535 | || exp[0].X_op == O_register | |
1536 | || (exp[0].X_op == O_constant | |
1537 | && (exp[0].X_add_number > 0xffffff || exp[0].X_add_number < 0))) | |
1538 | { | |
1539 | as_bad (_("invalid operands to opcode %s: `%s'"), | |
1540 | instruction->name, operands); | |
1541 | return; | |
1542 | } | |
3c3bdf30 | 1543 | |
a1b6236b KH |
1544 | if (exp[0].X_op == O_constant) |
1545 | { | |
1546 | opcodep[1] = (exp[0].X_add_number >> 16) & 255; | |
1547 | opcodep[2] = (exp[0].X_add_number >> 8) & 255; | |
1548 | opcodep[3] = exp[0].X_add_number & 255; | |
1549 | } | |
1550 | else | |
1551 | /* FIXME: This doesn't bring us unsignedness checking. */ | |
1552 | fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 1, | |
1553 | 3, exp + 0, 0, BFD_RELOC_24); | |
1554 | break; | |
3c3bdf30 NC |
1555 | |
1556 | case mmix_operands_neg: | |
1557 | /* Operands "$X,Y,$Z|Z"; NEG or NEGU. Y is optional, 0 is default. */ | |
1558 | ||
1559 | if ((n_operands != 3 && n_operands != 2) | |
1560 | || (n_operands == 3 && exp[1].X_op == O_register) | |
1561 | || ((exp[1].X_op == O_constant || exp[1].X_op == O_register) | |
1562 | && (exp[1].X_add_number > 255 || exp[1].X_add_number < 0)) | |
1563 | || (n_operands == 3 | |
1564 | && ((exp[2].X_op == O_register && exp[2].X_add_number > 255) | |
1565 | || (exp[2].X_op == O_constant | |
1566 | && (exp[2].X_add_number > 255 | |
1567 | || exp[2].X_add_number < 0))))) | |
1568 | { | |
1569 | as_bad (_("invalid operands to opcode %s: `%s'"), | |
1570 | instruction->name, operands); | |
1571 | return; | |
1572 | } | |
1573 | ||
1574 | if (n_operands == 2) | |
1575 | { | |
1576 | if (exp[1].X_op == O_register) | |
1577 | opcodep[3] = exp[1].X_add_number; | |
1578 | else if (exp[1].X_op == O_constant) | |
1579 | { | |
1580 | opcodep[3] = exp[1].X_add_number; | |
1581 | opcodep[0] |= IMM_OFFSET_BIT; | |
1582 | } | |
1583 | else | |
1584 | fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 3, | |
1585 | 1, exp + 1, 0, BFD_RELOC_MMIX_REG_OR_BYTE); | |
1586 | break; | |
1587 | } | |
1588 | ||
1589 | if (exp[1].X_op == O_constant) | |
1590 | opcodep[2] = exp[1].X_add_number; | |
1591 | else | |
1592 | fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 2, | |
1593 | 1, exp + 1, 0, BFD_RELOC_8); | |
1594 | ||
1595 | if (exp[2].X_op == O_register) | |
1596 | opcodep[3] = exp[2].X_add_number; | |
1597 | else if (exp[2].X_op == O_constant) | |
1598 | { | |
1599 | opcodep[3] = exp[2].X_add_number; | |
1600 | opcodep[0] |= IMM_OFFSET_BIT; | |
1601 | } | |
1602 | else | |
1603 | fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 3, | |
1604 | 1, exp + 2, 0, BFD_RELOC_MMIX_REG_OR_BYTE); | |
1605 | break; | |
1606 | ||
1607 | case mmix_operands_regaddr: | |
a1b6236b | 1608 | /* A GETA/branch-type. */ |
3c3bdf30 NC |
1609 | break; |
1610 | ||
1611 | case mmix_operands_get: | |
1612 | /* "$X,spec_reg"; GET. | |
1613 | Like with rounding modes, we demand that the special register or | |
1614 | symbol is already defined when we get here at the point of use. */ | |
1615 | if (n_operands != 2 | |
1616 | || (exp[1].X_op == O_register | |
1617 | && (exp[1].X_add_number < 256 || exp[1].X_add_number >= 512)) | |
1618 | || (exp[1].X_op == O_constant | |
1619 | && (exp[1].X_add_number < 0 || exp[1].X_add_number > 256)) | |
1620 | || (exp[1].X_op != O_constant && exp[1].X_op != O_register)) | |
1621 | { | |
1622 | as_bad (_("invalid operands to opcode %s: `%s'"), | |
1623 | instruction->name, operands); | |
1624 | return; | |
1625 | } | |
1626 | ||
1627 | opcodep[3] = exp[1].X_add_number - 256; | |
1628 | break; | |
1629 | ||
1630 | case mmix_operands_put: | |
1631 | /* "spec_reg,$Z|Z"; PUT. */ | |
1632 | if (n_operands != 2 | |
1633 | || (exp[0].X_op == O_register | |
1634 | && (exp[0].X_add_number < 256 || exp[0].X_add_number >= 512)) | |
1635 | || (exp[0].X_op == O_constant | |
1636 | && (exp[0].X_add_number < 0 || exp[0].X_add_number > 256)) | |
1637 | || (exp[0].X_op != O_constant && exp[0].X_op != O_register)) | |
1638 | { | |
1639 | as_bad (_("invalid operands to opcode %s: `%s'"), | |
1640 | instruction->name, operands); | |
1641 | return; | |
1642 | } | |
1643 | ||
1644 | opcodep[1] = exp[0].X_add_number - 256; | |
1645 | ||
1646 | /* Note that the Y field is zero. */ | |
1647 | ||
1648 | if (exp[1].X_op == O_register) | |
1649 | opcodep[3] = exp[1].X_add_number; | |
1650 | else if (exp[1].X_op == O_constant) | |
1651 | { | |
1652 | opcodep[3] = exp[1].X_add_number; | |
1653 | opcodep[0] |= IMM_OFFSET_BIT; | |
1654 | } | |
1655 | else | |
1656 | fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 3, | |
1657 | 1, exp + 1, 0, BFD_RELOC_MMIX_REG_OR_BYTE); | |
1658 | break; | |
1659 | ||
1660 | case mmix_operands_save: | |
1661 | /* "$X,0"; SAVE. */ | |
1662 | if (n_operands != 2 | |
1663 | || exp[1].X_op != O_constant | |
1664 | || exp[1].X_add_number != 0) | |
1665 | { | |
1666 | as_bad (_("invalid operands to opcode %s: `%s'"), | |
1667 | instruction->name, operands); | |
1668 | return; | |
1669 | } | |
1670 | break; | |
1671 | ||
1672 | case mmix_operands_unsave: | |
1673 | if (n_operands < 2 && ! mmix_gnu_syntax) | |
1674 | { | |
1675 | if (n_operands == 1) | |
1676 | { | |
1677 | if (exp[0].X_op == O_register) | |
1678 | opcodep[3] = exp[0].X_add_number; | |
1679 | else | |
1680 | fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 3, | |
1681 | 1, exp, 0, BFD_RELOC_MMIX_REG); | |
1682 | } | |
1683 | break; | |
1684 | } | |
1685 | ||
a1b6236b | 1686 | /* "0,$Z"; UNSAVE. */ |
3c3bdf30 NC |
1687 | if (n_operands != 2 |
1688 | || exp[0].X_op != O_constant | |
1689 | || exp[0].X_add_number != 0 | |
1690 | || exp[1].X_op == O_constant | |
1691 | || (exp[1].X_op == O_register | |
1692 | && exp[1].X_add_number > 255)) | |
1693 | { | |
1694 | as_bad (_("invalid operands to opcode %s: `%s'"), | |
1695 | instruction->name, operands); | |
1696 | return; | |
1697 | } | |
1698 | ||
1699 | if (exp[1].X_op == O_register) | |
1700 | opcodep[3] = exp[1].X_add_number; | |
1701 | else | |
1702 | fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 3, | |
1703 | 1, exp + 1, 0, BFD_RELOC_MMIX_REG); | |
1704 | break; | |
1705 | ||
1706 | case mmix_operands_xyz_opt: | |
1707 | /* SWYM, TRIP, TRAP: zero, one, two or three operands. */ | |
1708 | if (n_operands == 0 && ! mmix_gnu_syntax) | |
1709 | /* Zeros are in place - nothing needs to be done for zero | |
1710 | operands. We don't allow this in GNU syntax mode, because it | |
1711 | was believed that the risk of missing to supply an operand is | |
1712 | higher than the benefit of not having to specify a zero. */ | |
1713 | ; | |
1714 | else if (n_operands == 1 && exp[0].X_op != O_register) | |
1715 | { | |
1716 | if (exp[0].X_op == O_constant) | |
1717 | { | |
1718 | if (exp[0].X_add_number > 255*255*255 | |
1719 | || exp[0].X_add_number < 0) | |
1720 | { | |
1721 | as_bad (_("invalid operands to opcode %s: `%s'"), | |
1722 | instruction->name, operands); | |
1723 | return; | |
1724 | } | |
1725 | else | |
1726 | { | |
1727 | opcodep[1] = (exp[0].X_add_number >> 16) & 255; | |
1728 | opcodep[2] = (exp[0].X_add_number >> 8) & 255; | |
1729 | opcodep[3] = exp[0].X_add_number & 255; | |
1730 | } | |
1731 | } | |
1732 | else | |
1733 | fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 1, | |
1734 | 3, exp, 0, BFD_RELOC_24); | |
1735 | } | |
1736 | else if (n_operands == 2 | |
1737 | && exp[0].X_op != O_register | |
1738 | && exp[1].X_op != O_register) | |
1739 | { | |
1740 | /* Two operands. */ | |
1741 | ||
1742 | if (exp[0].X_op == O_constant) | |
1743 | { | |
1744 | if (exp[0].X_add_number > 255 | |
1745 | || exp[0].X_add_number < 0) | |
1746 | { | |
1747 | as_bad (_("invalid operands to opcode %s: `%s'"), | |
1748 | instruction->name, operands); | |
1749 | return; | |
1750 | } | |
1751 | else | |
1752 | opcodep[1] = exp[0].X_add_number & 255; | |
1753 | } | |
1754 | else | |
1755 | fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 1, | |
1756 | 1, exp, 0, BFD_RELOC_8); | |
1757 | ||
1758 | if (exp[1].X_op == O_constant) | |
1759 | { | |
1760 | if (exp[1].X_add_number > 255*255 | |
1761 | || exp[1].X_add_number < 0) | |
1762 | { | |
1763 | as_bad (_("invalid operands to opcode %s: `%s'"), | |
1764 | instruction->name, operands); | |
1765 | return; | |
1766 | } | |
1767 | else | |
1768 | { | |
1769 | opcodep[2] = (exp[1].X_add_number >> 8) & 255; | |
1770 | opcodep[3] = exp[1].X_add_number & 255; | |
1771 | } | |
1772 | } | |
1773 | else | |
1774 | fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 2, | |
1775 | 2, exp + 1, 0, BFD_RELOC_16); | |
1776 | } | |
1777 | else if (n_operands == 3 | |
1778 | && exp[0].X_op != O_register | |
1779 | && exp[1].X_op != O_register | |
1780 | && exp[2].X_op != O_register) | |
1781 | { | |
1782 | /* Three operands. */ | |
1783 | ||
1784 | if (exp[0].X_op == O_constant) | |
1785 | { | |
1786 | if (exp[0].X_add_number > 255 | |
1787 | || exp[0].X_add_number < 0) | |
1788 | { | |
1789 | as_bad (_("invalid operands to opcode %s: `%s'"), | |
1790 | instruction->name, operands); | |
1791 | return; | |
1792 | } | |
1793 | else | |
1794 | opcodep[1] = exp[0].X_add_number & 255; | |
1795 | } | |
1796 | else | |
1797 | fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 1, | |
1798 | 1, exp, 0, BFD_RELOC_8); | |
1799 | ||
1800 | if (exp[1].X_op == O_constant) | |
1801 | { | |
1802 | if (exp[1].X_add_number > 255 | |
1803 | || exp[1].X_add_number < 0) | |
1804 | { | |
1805 | as_bad (_("invalid operands to opcode %s: `%s'"), | |
1806 | instruction->name, operands); | |
1807 | return; | |
1808 | } | |
1809 | else | |
1810 | opcodep[2] = exp[1].X_add_number & 255; | |
1811 | } | |
1812 | else | |
1813 | fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 2, | |
1814 | 1, exp + 1, 0, BFD_RELOC_8); | |
1815 | ||
1816 | if (exp[2].X_op == O_constant) | |
1817 | { | |
1818 | if (exp[2].X_add_number > 255 | |
1819 | || exp[2].X_add_number < 0) | |
1820 | { | |
1821 | as_bad (_("invalid operands to opcode %s: `%s'"), | |
1822 | instruction->name, operands); | |
1823 | return; | |
1824 | } | |
1825 | else | |
1826 | opcodep[3] = exp[2].X_add_number & 255; | |
1827 | } | |
1828 | else | |
1829 | fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 3, | |
1830 | 1, exp + 2, 0, BFD_RELOC_8); | |
1831 | } | |
1832 | else if (n_operands <= 3 | |
1833 | && (strcmp (instruction->name, "trip") == 0 | |
1834 | || strcmp (instruction->name, "trap") == 0)) | |
1835 | { | |
1836 | /* The meaning of operands to TRIP and TRAP are not defined, so | |
1837 | we add combinations not handled above here as we find them. */ | |
1838 | if (n_operands == 3) | |
1839 | { | |
1840 | /* Don't require non-register operands. Always generate | |
1841 | fixups, so we don't have to copy lots of code and create | |
67c1ffbe | 1842 | maintenance problems. TRIP is supposed to be a rare |
3c3bdf30 NC |
1843 | instruction, so the overhead should not matter. We |
1844 | aren't allowed to fix_new_exp for an expression which is | |
1845 | an O_register at this point, however. */ | |
1846 | if (exp[0].X_op == O_register) | |
1847 | opcodep[1] = exp[0].X_add_number; | |
1848 | else | |
1849 | fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 1, | |
1850 | 1, exp, 0, BFD_RELOC_MMIX_REG_OR_BYTE); | |
1851 | if (exp[1].X_op == O_register) | |
1852 | opcodep[2] = exp[1].X_add_number; | |
1853 | else | |
1854 | fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 2, | |
1855 | 1, exp + 1, 0, BFD_RELOC_MMIX_REG_OR_BYTE); | |
1856 | if (exp[2].X_op == O_register) | |
1857 | opcodep[3] = exp[2].X_add_number; | |
1858 | else | |
1859 | fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 3, | |
1860 | 1, exp + 2, 0, BFD_RELOC_MMIX_REG_OR_BYTE); | |
1861 | } | |
1862 | else if (n_operands == 2) | |
1863 | { | |
1864 | if (exp[0].X_op == O_register) | |
1865 | opcodep[2] = exp[0].X_add_number; | |
1866 | else | |
1867 | fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 2, | |
1868 | 1, exp, 0, BFD_RELOC_MMIX_REG_OR_BYTE); | |
1869 | if (exp[1].X_op == O_register) | |
1870 | opcodep[3] = exp[1].X_add_number; | |
1871 | else | |
1872 | fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 3, | |
1873 | 1, exp + 1, 0, BFD_RELOC_MMIX_REG_OR_BYTE); | |
1874 | } | |
1875 | else | |
1876 | { | |
1877 | as_bad (_("unsupported operands to %s: `%s'"), | |
1878 | instruction->name, operands); | |
1879 | return; | |
1880 | } | |
1881 | } | |
1882 | else | |
1883 | { | |
1884 | as_bad (_("invalid operands to opcode %s: `%s'"), | |
1885 | instruction->name, operands); | |
1886 | return; | |
1887 | } | |
1888 | break; | |
1889 | ||
1890 | case mmix_operands_resume: | |
1891 | if (n_operands == 0 && ! mmix_gnu_syntax) | |
1892 | break; | |
1893 | ||
1894 | if (n_operands != 1 | |
1895 | || exp[0].X_op == O_register | |
1896 | || (exp[0].X_op == O_constant | |
1897 | && (exp[0].X_add_number < 0 | |
1898 | || exp[0].X_add_number > 255))) | |
1899 | { | |
1900 | as_bad (_("invalid operands to opcode %s: `%s'"), | |
1901 | instruction->name, operands); | |
1902 | return; | |
1903 | } | |
1904 | ||
1905 | if (exp[0].X_op == O_constant) | |
1906 | opcodep[3] = exp[0].X_add_number; | |
1907 | else | |
1908 | fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 3, | |
1909 | 1, exp + 0, 0, BFD_RELOC_8); | |
1910 | break; | |
1911 | ||
1912 | case mmix_operands_pushj: | |
1913 | /* All is done for PUSHJ already. */ | |
1914 | break; | |
1915 | ||
1916 | default: | |
1917 | BAD_CASE (instruction->operands); | |
1918 | } | |
1919 | } | |
1920 | ||
1921 | /* For the benefit of insns that start with a digit, we assemble by way of | |
1922 | tc_unrecognized_line too, through this function. */ | |
1923 | ||
1924 | int | |
1925 | mmix_assemble_return_nonzero (str) | |
a1b6236b | 1926 | char *str; |
3c3bdf30 NC |
1927 | { |
1928 | int last_error_count = had_errors (); | |
1929 | char *s2 = str; | |
1930 | char c; | |
1931 | ||
1932 | /* Normal instruction handling downcases, so we must too. */ | |
1933 | while (ISALNUM (*s2)) | |
1934 | { | |
1935 | if (ISUPPER ((unsigned char) *s2)) | |
1936 | *s2 = TOLOWER (*s2); | |
1937 | s2++; | |
1938 | } | |
1939 | ||
1940 | /* Cut the line for sake of the assembly. */ | |
1941 | for (s2 = str; *s2 && *s2 != '\n'; s2++) | |
1942 | ; | |
1943 | ||
1944 | c = *s2; | |
1945 | *s2 = 0; | |
1946 | md_assemble (str); | |
1947 | *s2 = c; | |
1948 | ||
1949 | return had_errors () == last_error_count; | |
1950 | } | |
1951 | ||
1952 | /* The PREFIX pseudo. */ | |
1953 | ||
1954 | static void | |
1955 | s_prefix (unused) | |
1956 | int unused ATTRIBUTE_UNUSED; | |
1957 | { | |
1958 | char *p; | |
1959 | int c; | |
1960 | ||
1961 | SKIP_WHITESPACE (); | |
1962 | ||
1963 | p = input_line_pointer; | |
1964 | ||
1965 | c = get_symbol_end (); | |
1966 | ||
1967 | /* Reseting prefix? */ | |
1968 | if (*p == ':' && p[1] == 0) | |
1969 | mmix_current_prefix = NULL; | |
1970 | else | |
1971 | { | |
1972 | /* Put this prefix on the mmix symbols obstack. We could malloc and | |
1973 | free it separately, but then we'd have to worry about that. | |
1974 | People using up memory on prefixes have other problems. */ | |
1975 | obstack_grow (&mmix_sym_obstack, p, strlen (p) + 1); | |
1976 | p = obstack_finish (&mmix_sym_obstack); | |
1977 | ||
1978 | /* Accumulate prefixes, and strip a leading ':'. */ | |
1979 | if (mmix_current_prefix != NULL || *p == ':') | |
1980 | p = mmix_prefix_name (p); | |
1981 | ||
1982 | mmix_current_prefix = p; | |
1983 | } | |
1984 | ||
1985 | *input_line_pointer = c; | |
1986 | ||
1987 | mmix_handle_rest_of_empty_line (); | |
1988 | } | |
1989 | ||
1990 | /* We implement prefixes by using the tc_canonicalize_symbol_name hook, | |
1991 | and store each prefixed name on a (separate) obstack. This means that | |
1992 | the name is on the "notes" obstack in non-prefixed form and on the | |
1993 | mmix_sym_obstack in prefixed form, but currently it is not worth | |
1994 | rewriting the whole GAS symbol handling to improve "hooking" to avoid | |
1995 | that. (It might be worth a rewrite for other reasons, though). */ | |
1996 | ||
1997 | char * | |
1998 | mmix_prefix_name (shortname) | |
1999 | char *shortname; | |
2000 | { | |
2001 | if (*shortname == ':') | |
2002 | return shortname + 1; | |
2003 | ||
2004 | if (mmix_current_prefix == NULL) | |
2005 | as_fatal (_("internal: mmix_prefix_name but empty prefix")); | |
2006 | ||
2007 | if (*shortname == '$') | |
2008 | return shortname; | |
2009 | ||
2010 | obstack_grow (&mmix_sym_obstack, mmix_current_prefix, | |
2011 | strlen (mmix_current_prefix)); | |
2012 | obstack_grow (&mmix_sym_obstack, shortname, strlen (shortname) + 1); | |
2013 | return obstack_finish (&mmix_sym_obstack); | |
2014 | } | |
2015 | ||
2016 | /* The GREG pseudo. At LABEL, we have the name of a symbol that we | |
2017 | want to make a register symbol, and which should be initialized with | |
2018 | the value in the expression at INPUT_LINE_POINTER (defaulting to 0). | |
2019 | Either and (perhaps less meaningful) both may be missing. LABEL must | |
2020 | be persistent, perhaps allocated on an obstack. */ | |
2021 | ||
2022 | static void | |
2023 | mmix_greg_internal (label) | |
2024 | char *label; | |
2025 | { | |
2026 | expressionS *expP = &mmix_raw_gregs[n_of_raw_gregs].exp; | |
2027 | ||
2028 | /* Don't set the section to register contents section before the | |
2029 | expression has been parsed; it may refer to the current position. */ | |
2030 | expression (expP); | |
2031 | ||
2032 | /* FIXME: Check that no expression refers to the register contents | |
2033 | section. May need to be done in elf64-mmix.c. */ | |
2034 | if (expP->X_op == O_absent) | |
2035 | { | |
2036 | /* Default to zero if the expression was absent. */ | |
2037 | expP->X_op = O_constant; | |
2038 | expP->X_add_number = 0; | |
2039 | expP->X_unsigned = 0; | |
2040 | expP->X_add_symbol = NULL; | |
2041 | expP->X_op_symbol = NULL; | |
2042 | } | |
2043 | ||
2044 | /* We must handle prefixes here, as we save the labels and expressions | |
2045 | to be output later. */ | |
2046 | mmix_raw_gregs[n_of_raw_gregs].label | |
2047 | = mmix_current_prefix == NULL ? label : mmix_prefix_name (label); | |
2048 | ||
2049 | if (n_of_raw_gregs == MAX_GREGS - 1) | |
2050 | as_bad (_("too many GREG registers allocated (max %d)"), MAX_GREGS); | |
2051 | else | |
2052 | n_of_raw_gregs++; | |
2053 | ||
2054 | mmix_handle_rest_of_empty_line (); | |
2055 | } | |
2056 | ||
2057 | /* The ".greg label,expr" worker. */ | |
2058 | ||
2059 | static void | |
2060 | s_greg (unused) | |
2061 | int unused ATTRIBUTE_UNUSED; | |
2062 | { | |
2063 | char *p; | |
2064 | char c; | |
2065 | p = input_line_pointer; | |
2066 | ||
2067 | /* This will skip over what can be a symbol and zero out the next | |
2068 | character, which we assume is a ',' or other meaningful delimiter. | |
2069 | What comes after that is the initializer expression for the | |
2070 | register. */ | |
2071 | c = get_symbol_end (); | |
2072 | ||
a1b6236b | 2073 | if (! is_end_of_line[(unsigned char) c]) |
3c3bdf30 NC |
2074 | input_line_pointer++; |
2075 | ||
2076 | if (*p) | |
2077 | { | |
2078 | /* The label must be persistent; it's not used until after all input | |
2079 | has been seen. */ | |
2080 | obstack_grow (&mmix_sym_obstack, p, strlen (p) + 1); | |
2081 | mmix_greg_internal (obstack_finish (&mmix_sym_obstack)); | |
2082 | } | |
2083 | else | |
2084 | mmix_greg_internal (NULL); | |
2085 | } | |
2086 | ||
2087 | /* The "BSPEC expr" worker. */ | |
2088 | ||
2089 | static void | |
2090 | s_bspec (unused) | |
2091 | int unused ATTRIBUTE_UNUSED; | |
2092 | { | |
2093 | asection *expsec; | |
2094 | asection *sec; | |
2095 | char secname[sizeof (MMIX_OTHER_SPEC_SECTION_PREFIX) + 20] | |
2096 | = MMIX_OTHER_SPEC_SECTION_PREFIX; | |
2097 | expressionS exp; | |
2098 | int n; | |
2099 | ||
2100 | /* Get a constant expression which we can evaluate *now*. Supporting | |
2101 | more complex (though assembly-time computable) expressions is | |
2102 | feasible but Too Much Work for something of unknown usefulness like | |
2103 | BSPEC-ESPEC. */ | |
2104 | expsec = expression (&exp); | |
2105 | mmix_handle_rest_of_empty_line (); | |
2106 | ||
2107 | /* Check that we don't have another BSPEC in progress. */ | |
2108 | if (doing_bspec) | |
2109 | { | |
2110 | as_bad (_("BSPEC already active. Nesting is not supported.")); | |
2111 | return; | |
2112 | } | |
2113 | ||
2114 | if (exp.X_op != O_constant | |
2115 | || expsec != absolute_section | |
2116 | || exp.X_add_number < 0 | |
2117 | || exp.X_add_number > 65535) | |
2118 | { | |
2119 | as_bad (_("invalid BSPEC expression")); | |
2120 | exp.X_add_number = 0; | |
2121 | } | |
2122 | ||
2123 | n = (int) exp.X_add_number; | |
2124 | ||
2125 | sprintf (secname + strlen (MMIX_OTHER_SPEC_SECTION_PREFIX), "%d", n); | |
2126 | sec = bfd_get_section_by_name (stdoutput, secname); | |
2127 | if (sec == NULL) | |
2128 | { | |
2129 | /* We need a non-volatile name as it will be stored in the section | |
2130 | struct. */ | |
2131 | char *newsecname = xstrdup (secname); | |
2132 | sec = bfd_make_section (stdoutput, newsecname); | |
2133 | ||
2134 | if (sec == NULL) | |
2135 | as_fatal (_("can't create section %s"), newsecname); | |
2136 | ||
2137 | if (!bfd_set_section_flags (stdoutput, sec, | |
2138 | bfd_get_section_flags (stdoutput, sec) | |
2139 | | SEC_READONLY)) | |
2140 | as_fatal (_("can't set section flags for section %s"), newsecname); | |
2141 | } | |
2142 | ||
2143 | /* Tell ELF about the pending section change. */ | |
2144 | obj_elf_section_change_hook (); | |
2145 | subseg_set (sec, 0); | |
2146 | ||
2147 | /* Save position for missing ESPEC. */ | |
2148 | as_where (&bspec_file, &bspec_line); | |
2149 | ||
2150 | doing_bspec = 1; | |
2151 | } | |
2152 | ||
2153 | /* The "ESPEC" worker. */ | |
2154 | ||
2155 | static void | |
2156 | s_espec (unused) | |
2157 | int unused ATTRIBUTE_UNUSED; | |
2158 | { | |
2159 | /* First, check that we *do* have a BSPEC in progress. */ | |
2160 | if (! doing_bspec) | |
2161 | { | |
2162 | as_bad (_("ESPEC without preceding BSPEC")); | |
2163 | return; | |
2164 | } | |
2165 | ||
2166 | mmix_handle_rest_of_empty_line (); | |
2167 | doing_bspec = 0; | |
2168 | ||
2169 | /* When we told ELF about the section change in s_bspec, it stored the | |
2170 | previous section for us so we can get at it with the equivalent of a | |
2171 | .previous pseudo. */ | |
2172 | obj_elf_previous (0); | |
2173 | } | |
2174 | ||
2175 | /* The " .local expr" and " local expr" worker. We make a BFD_MMIX_LOCAL | |
2176 | relocation against the current position against the expression. | |
2177 | Implementing this by means of contents in a section lost. */ | |
2178 | ||
2179 | static void | |
2180 | mmix_s_local (unused) | |
2181 | int unused ATTRIBUTE_UNUSED; | |
2182 | { | |
2183 | expressionS exp; | |
2184 | ||
2185 | /* Don't set the section to register contents section before the | |
2186 | expression has been parsed; it may refer to the current position in | |
2187 | some contorted way. */ | |
2188 | expression (&exp); | |
2189 | ||
2190 | if (exp.X_op == O_absent) | |
2191 | { | |
2192 | as_bad (_("missing local expression")); | |
2193 | return; | |
2194 | } | |
2195 | else if (exp.X_op == O_register) | |
2196 | { | |
2197 | /* fix_new_exp doesn't like O_register. Should be configurable. | |
2198 | We're fine with a constant here, though. */ | |
2199 | exp.X_op = O_constant; | |
2200 | } | |
2201 | ||
2202 | fix_new_exp (frag_now, 0, 0, &exp, 0, BFD_RELOC_MMIX_LOCAL); | |
2203 | mmix_handle_rest_of_empty_line (); | |
2204 | } | |
2205 | ||
2206 | /* Set fragP->fr_var to the initial guess of the size of a relaxable insn | |
2207 | and return it. Sizes of other instructions are not known. This | |
2208 | function may be called multiple times. */ | |
2209 | ||
2210 | int | |
2211 | md_estimate_size_before_relax (fragP, segment) | |
2212 | fragS *fragP; | |
2213 | segT segment; | |
2214 | { | |
2215 | int length; | |
2216 | ||
2217 | #define HANDLE_RELAXABLE(state) \ | |
2218 | case ENCODE_RELAX (state, STATE_UNDF): \ | |
2219 | if (fragP->fr_symbol != NULL \ | |
2be11e7e HPN |
2220 | && S_GET_SEGMENT (fragP->fr_symbol) == segment \ |
2221 | && !S_IS_WEAK (fragP->fr_symbol)) \ | |
3c3bdf30 NC |
2222 | { \ |
2223 | /* The symbol lies in the same segment - a relaxable case. */ \ | |
2224 | fragP->fr_subtype \ | |
2225 | = ENCODE_RELAX (state, STATE_ZERO); \ | |
2226 | } \ | |
2227 | break; | |
2228 | ||
2229 | switch (fragP->fr_subtype) | |
2230 | { | |
2231 | HANDLE_RELAXABLE (STATE_GETA); | |
2232 | HANDLE_RELAXABLE (STATE_BCC); | |
3c3bdf30 NC |
2233 | HANDLE_RELAXABLE (STATE_JMP); |
2234 | ||
88fc725d HPN |
2235 | case ENCODE_RELAX (STATE_PUSHJ, STATE_UNDF): |
2236 | if (fragP->fr_symbol != NULL | |
2237 | && S_GET_SEGMENT (fragP->fr_symbol) == segment | |
2238 | && !S_IS_WEAK (fragP->fr_symbol)) | |
2239 | /* The symbol lies in the same segment - a relaxable case. */ | |
2240 | fragP->fr_subtype = ENCODE_RELAX (STATE_PUSHJ, STATE_ZERO); | |
2241 | else if (pushj_stubs) | |
2242 | /* If we're to generate stubs, assume we can reach a stub after | |
2243 | the section. */ | |
2244 | fragP->fr_subtype = ENCODE_RELAX (STATE_PUSHJSTUB, STATE_ZERO); | |
2245 | /* FALLTHROUGH. */ | |
2246 | case ENCODE_RELAX (STATE_PUSHJ, STATE_ZERO): | |
2247 | case ENCODE_RELAX (STATE_PUSHJSTUB, STATE_ZERO): | |
2248 | /* We need to distinguish different relaxation rounds. */ | |
2249 | seg_info (segment)->tc_segment_info_data.last_stubfrag = fragP; | |
2250 | break; | |
2251 | ||
3c3bdf30 NC |
2252 | case ENCODE_RELAX (STATE_GETA, STATE_ZERO): |
2253 | case ENCODE_RELAX (STATE_BCC, STATE_ZERO): | |
3c3bdf30 NC |
2254 | case ENCODE_RELAX (STATE_JMP, STATE_ZERO): |
2255 | /* When relaxing a section for the second time, we don't need to do | |
2256 | anything except making sure that fr_var is set right. */ | |
2257 | break; | |
2258 | ||
2259 | case STATE_GREG_DEF: | |
2260 | length = fragP->tc_frag_data != NULL ? 0 : 8; | |
2261 | fragP->fr_var = length; | |
2262 | ||
2263 | /* Don't consult the relax_table; it isn't valid for this | |
2264 | relaxation. */ | |
2265 | return length; | |
2266 | break; | |
2267 | ||
2268 | default: | |
2269 | BAD_CASE (fragP->fr_subtype); | |
2270 | } | |
2271 | ||
2272 | length = mmix_relax_table[fragP->fr_subtype].rlx_length; | |
2273 | fragP->fr_var = length; | |
2274 | ||
2275 | return length; | |
2276 | } | |
2277 | ||
2278 | /* Turn a string in input_line_pointer into a floating point constant of type | |
2279 | type, and store the appropriate bytes in *litP. The number of LITTLENUMS | |
2280 | emitted is stored in *sizeP . An error message is returned, or NULL on | |
2281 | OK. */ | |
2282 | ||
2283 | char * | |
2284 | md_atof (type, litP, sizeP) | |
2285 | int type; | |
2286 | char *litP; | |
2287 | int *sizeP; | |
2288 | { | |
2289 | int prec; | |
2290 | LITTLENUM_TYPE words[4]; | |
2291 | char *t; | |
2292 | int i; | |
2293 | ||
2294 | switch (type) | |
2295 | { | |
2296 | /* FIXME: Having 'f' in mmix_flt_chars (and here) makes it | |
2297 | problematic to also have a forward reference in an expression. | |
2298 | The testsuite wants it, and it's customary. | |
2299 | We'll deal with the real problems when they come; we share the | |
2300 | problem with most other ports. */ | |
2301 | case 'f': | |
2302 | case 'r': | |
2303 | prec = 2; | |
2304 | break; | |
2305 | case 'd': | |
2306 | prec = 4; | |
2307 | break; | |
2308 | default: | |
2309 | *sizeP = 0; | |
2310 | return _("bad call to md_atof"); | |
2311 | } | |
2312 | ||
2313 | t = atof_ieee (input_line_pointer, type, words); | |
2314 | if (t) | |
2315 | input_line_pointer = t; | |
2316 | ||
2317 | *sizeP = prec * 2; | |
2318 | ||
2319 | for (i = 0; i < prec; i++) | |
2320 | { | |
2321 | md_number_to_chars (litP, (valueT) words[i], 2); | |
a1b6236b | 2322 | litP += 2; |
3c3bdf30 NC |
2323 | } |
2324 | return NULL; | |
2325 | } | |
2326 | ||
2327 | /* Convert variable-sized frags into one or more fixups. */ | |
2328 | ||
2329 | void | |
2330 | md_convert_frag (abfd, sec, fragP) | |
2331 | bfd *abfd ATTRIBUTE_UNUSED; | |
2332 | segT sec ATTRIBUTE_UNUSED; | |
2333 | fragS *fragP; | |
2334 | { | |
a1b6236b | 2335 | /* Pointer to first byte in variable-sized part of the frag. */ |
3c3bdf30 NC |
2336 | char *var_partp; |
2337 | ||
2338 | /* Pointer to first opcode byte in frag. */ | |
2339 | char *opcodep; | |
2340 | ||
2341 | /* Size in bytes of variable-sized part of frag. */ | |
2342 | int var_part_size = 0; | |
2343 | ||
2344 | /* This is part of *fragP. It contains all information about addresses | |
2345 | and offsets to varying parts. */ | |
2346 | symbolS *symbolP; | |
2347 | unsigned long var_part_offset; | |
2348 | ||
2349 | /* This is the frag for the opcode. It, rather than fragP, must be used | |
2350 | when emitting a frag for the opcode. */ | |
2351 | fragS *opc_fragP = fragP->tc_frag_data; | |
2352 | fixS *tmpfixP; | |
2353 | ||
2354 | /* Where, in file space, does addr point? */ | |
2355 | bfd_vma target_address; | |
2356 | bfd_vma opcode_address; | |
2357 | ||
2358 | know (fragP->fr_type == rs_machine_dependent); | |
2359 | ||
2360 | var_part_offset = fragP->fr_fix; | |
2361 | var_partp = fragP->fr_literal + var_part_offset; | |
2362 | opcodep = fragP->fr_opcode; | |
2363 | ||
2364 | symbolP = fragP->fr_symbol; | |
2365 | ||
2366 | target_address | |
2367 | = ((symbolP ? S_GET_VALUE (symbolP) : 0) + fragP->fr_offset); | |
2368 | ||
2369 | /* The opcode that would be extended is the last four "fixed" bytes. */ | |
2370 | opcode_address = fragP->fr_address + fragP->fr_fix - 4; | |
2371 | ||
2372 | switch (fragP->fr_subtype) | |
a1b6236b | 2373 | { |
88fc725d HPN |
2374 | case ENCODE_RELAX (STATE_PUSHJSTUB, STATE_ZERO): |
2375 | /* Setting the unknown bits to 0 seems the most appropriate. */ | |
2376 | mmix_set_geta_branch_offset (opcodep, 0); | |
2377 | tmpfixP = fix_new (opc_fragP, opcodep - opc_fragP->fr_literal, 8, | |
2378 | fragP->fr_symbol, fragP->fr_offset, 1, | |
2379 | BFD_RELOC_MMIX_PUSHJ_STUBBABLE); | |
2380 | COPY_FR_WHERE_TO_FX (fragP, tmpfixP); | |
2381 | var_part_size = 0; | |
2382 | break; | |
2383 | ||
a1b6236b KH |
2384 | case ENCODE_RELAX (STATE_GETA, STATE_ZERO): |
2385 | case ENCODE_RELAX (STATE_BCC, STATE_ZERO): | |
2386 | case ENCODE_RELAX (STATE_PUSHJ, STATE_ZERO): | |
2387 | mmix_set_geta_branch_offset (opcodep, target_address - opcode_address); | |
2388 | if (linkrelax) | |
2389 | { | |
2390 | tmpfixP | |
2391 | = fix_new (opc_fragP, opcodep - opc_fragP->fr_literal, 4, | |
2392 | fragP->fr_symbol, fragP->fr_offset, 1, | |
2393 | BFD_RELOC_MMIX_ADDR19); | |
2394 | COPY_FR_WHERE_TO_FX (fragP, tmpfixP); | |
2395 | } | |
2396 | var_part_size = 0; | |
2397 | break; | |
3c3bdf30 | 2398 | |
a1b6236b KH |
2399 | case ENCODE_RELAX (STATE_JMP, STATE_ZERO): |
2400 | mmix_set_jmp_offset (opcodep, target_address - opcode_address); | |
2401 | if (linkrelax) | |
2402 | { | |
2403 | tmpfixP | |
2404 | = fix_new (opc_fragP, opcodep - opc_fragP->fr_literal, 4, | |
2405 | fragP->fr_symbol, fragP->fr_offset, 1, | |
2406 | BFD_RELOC_MMIX_ADDR27); | |
2407 | COPY_FR_WHERE_TO_FX (fragP, tmpfixP); | |
2408 | } | |
3c3bdf30 | 2409 | var_part_size = 0; |
a1b6236b KH |
2410 | break; |
2411 | ||
2412 | case STATE_GREG_DEF: | |
2413 | if (fragP->tc_frag_data == NULL) | |
2414 | { | |
32c27eed HPN |
2415 | /* We must initialize data that's supposed to be "fixed up" to |
2416 | avoid emitting garbage, because md_apply_fix3 won't do | |
2417 | anything for undefined symbols. */ | |
2418 | md_number_to_chars (var_partp, 0, 8); | |
a1b6236b KH |
2419 | tmpfixP |
2420 | = fix_new (fragP, var_partp - fragP->fr_literal, 8, | |
2421 | fragP->fr_symbol, fragP->fr_offset, 0, BFD_RELOC_64); | |
2422 | COPY_FR_WHERE_TO_FX (fragP, tmpfixP); | |
2423 | mmix_gregs[n_of_cooked_gregs++] = tmpfixP; | |
2424 | var_part_size = 8; | |
2425 | } | |
2426 | else | |
2427 | var_part_size = 0; | |
2428 | break; | |
3c3bdf30 NC |
2429 | |
2430 | #define HANDLE_MAX_RELOC(state, reloc) \ | |
2431 | case ENCODE_RELAX (state, STATE_MAX): \ | |
2432 | var_part_size \ | |
2433 | = mmix_relax_table[ENCODE_RELAX (state, STATE_MAX)].rlx_length; \ | |
2434 | mmix_fill_nops (var_partp, var_part_size / 4); \ | |
2435 | if (warn_on_expansion) \ | |
2436 | as_warn_where (fragP->fr_file, fragP->fr_line, \ | |
2437 | _("operand out of range, instruction expanded")); \ | |
2438 | tmpfixP = fix_new (fragP, var_partp - fragP->fr_literal - 4, 8, \ | |
2439 | fragP->fr_symbol, fragP->fr_offset, 1, reloc); \ | |
2440 | COPY_FR_WHERE_TO_FX (fragP, tmpfixP); \ | |
2441 | break | |
2442 | ||
a1b6236b KH |
2443 | HANDLE_MAX_RELOC (STATE_GETA, BFD_RELOC_MMIX_GETA); |
2444 | HANDLE_MAX_RELOC (STATE_BCC, BFD_RELOC_MMIX_CBRANCH); | |
2445 | HANDLE_MAX_RELOC (STATE_PUSHJ, BFD_RELOC_MMIX_PUSHJ); | |
2446 | HANDLE_MAX_RELOC (STATE_JMP, BFD_RELOC_MMIX_JMP); | |
3c3bdf30 | 2447 | |
a1b6236b KH |
2448 | default: |
2449 | BAD_CASE (fragP->fr_subtype); | |
2450 | break; | |
2451 | } | |
3c3bdf30 NC |
2452 | |
2453 | fragP->fr_fix += var_part_size; | |
2454 | fragP->fr_var = 0; | |
2455 | } | |
2456 | ||
2457 | /* Applies the desired value to the specified location. | |
2458 | Also sets up addends for RELA type relocations. | |
2459 | Stolen from tc-mcore.c. | |
2460 | ||
2461 | Note that this function isn't called when linkrelax != 0. */ | |
2462 | ||
94f592af NC |
2463 | void |
2464 | md_apply_fix3 (fixP, valP, segment) | |
3c3bdf30 | 2465 | fixS * fixP; |
94f592af | 2466 | valueT * valP; |
3c3bdf30 NC |
2467 | segT segment; |
2468 | { | |
2469 | char *buf = fixP->fx_where + fixP->fx_frag->fr_literal; | |
2470 | /* Note: use offsetT because it is signed, valueT is unsigned. */ | |
94f592af | 2471 | offsetT val = (offsetT) * valP; |
3c3bdf30 NC |
2472 | segT symsec |
2473 | = (fixP->fx_addsy == NULL | |
2474 | ? absolute_section : S_GET_SEGMENT (fixP->fx_addsy)); | |
2475 | ||
2476 | /* If the fix is relative to a symbol which is not defined, or, (if | |
2477 | pcrel), not in the same segment as the fix, we cannot resolve it | |
2478 | here. */ | |
2479 | if (fixP->fx_addsy != NULL | |
2480 | && (! S_IS_DEFINED (fixP->fx_addsy) | |
2481 | || S_IS_WEAK (fixP->fx_addsy) | |
2482 | || (fixP->fx_pcrel && symsec != segment) | |
2483 | || (! fixP->fx_pcrel | |
2484 | && symsec != absolute_section | |
2485 | && ((fixP->fx_r_type != BFD_RELOC_MMIX_REG | |
2486 | && fixP->fx_r_type != BFD_RELOC_MMIX_REG_OR_BYTE) | |
a161fe53 | 2487 | || symsec != reg_section)))) |
3c3bdf30 NC |
2488 | { |
2489 | fixP->fx_done = 0; | |
94f592af | 2490 | return; |
3c3bdf30 NC |
2491 | } |
2492 | else if (fixP->fx_r_type == BFD_RELOC_MMIX_LOCAL | |
2493 | || fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT | |
2494 | || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY) | |
2495 | { | |
2496 | /* These are never "fixed". */ | |
2497 | fixP->fx_done = 0; | |
94f592af | 2498 | return; |
3c3bdf30 NC |
2499 | } |
2500 | else | |
2501 | /* We assume every other relocation is "fixed". */ | |
2502 | fixP->fx_done = 1; | |
2503 | ||
2504 | switch (fixP->fx_r_type) | |
2505 | { | |
2506 | case BFD_RELOC_64: | |
2507 | case BFD_RELOC_32: | |
2508 | case BFD_RELOC_24: | |
2509 | case BFD_RELOC_16: | |
2510 | case BFD_RELOC_8: | |
2511 | case BFD_RELOC_64_PCREL: | |
2512 | case BFD_RELOC_32_PCREL: | |
2513 | case BFD_RELOC_24_PCREL: | |
2514 | case BFD_RELOC_16_PCREL: | |
2515 | case BFD_RELOC_8_PCREL: | |
2516 | md_number_to_chars (buf, val, fixP->fx_size); | |
2517 | break; | |
2518 | ||
2519 | case BFD_RELOC_MMIX_ADDR19: | |
2520 | if (expand_op) | |
2521 | { | |
2522 | /* This shouldn't happen. */ | |
2523 | BAD_CASE (fixP->fx_r_type); | |
2524 | break; | |
2525 | } | |
2526 | /* FALLTHROUGH. */ | |
2527 | case BFD_RELOC_MMIX_GETA: | |
2528 | case BFD_RELOC_MMIX_CBRANCH: | |
2529 | case BFD_RELOC_MMIX_PUSHJ: | |
88fc725d | 2530 | case BFD_RELOC_MMIX_PUSHJ_STUBBABLE: |
3c3bdf30 NC |
2531 | /* If this fixup is out of range, punt to the linker to emit an |
2532 | error. This should only happen with -no-expand. */ | |
2533 | if (val < -(((offsetT) 1 << 19)/2) | |
2534 | || val >= ((offsetT) 1 << 19)/2 - 1 | |
2535 | || (val & 3) != 0) | |
2536 | { | |
2537 | if (warn_on_expansion) | |
2538 | as_warn_where (fixP->fx_file, fixP->fx_line, | |
2539 | _("operand out of range")); | |
2540 | fixP->fx_done = 0; | |
2541 | val = 0; | |
2542 | } | |
2543 | mmix_set_geta_branch_offset (buf, val); | |
2544 | break; | |
2545 | ||
2546 | case BFD_RELOC_MMIX_ADDR27: | |
2547 | if (expand_op) | |
2548 | { | |
2549 | /* This shouldn't happen. */ | |
2550 | BAD_CASE (fixP->fx_r_type); | |
2551 | break; | |
2552 | } | |
2553 | /* FALLTHROUGH. */ | |
2554 | case BFD_RELOC_MMIX_JMP: | |
2555 | /* If this fixup is out of range, punt to the linker to emit an | |
2556 | error. This should only happen with -no-expand. */ | |
2557 | if (val < -(((offsetT) 1 << 27)/2) | |
2558 | || val >= ((offsetT) 1 << 27)/2 - 1 | |
2559 | || (val & 3) != 0) | |
2560 | { | |
2561 | if (warn_on_expansion) | |
2562 | as_warn_where (fixP->fx_file, fixP->fx_line, | |
2563 | _("operand out of range")); | |
2564 | fixP->fx_done = 0; | |
2565 | val = 0; | |
2566 | } | |
2567 | mmix_set_jmp_offset (buf, val); | |
2568 | break; | |
2569 | ||
2570 | case BFD_RELOC_MMIX_REG_OR_BYTE: | |
2571 | if (fixP->fx_addsy != NULL | |
a161fe53 | 2572 | && (S_GET_SEGMENT (fixP->fx_addsy) != reg_section |
3c3bdf30 NC |
2573 | || S_GET_VALUE (fixP->fx_addsy) > 255) |
2574 | && S_GET_SEGMENT (fixP->fx_addsy) != absolute_section) | |
a161fe53 AM |
2575 | { |
2576 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
2577 | _("invalid operands")); | |
2578 | /* We don't want this "symbol" appearing in output, because | |
2579 | that will fail. */ | |
2580 | fixP->fx_done = 1; | |
2581 | } | |
2582 | ||
3c3bdf30 NC |
2583 | buf[0] = val; |
2584 | ||
2585 | /* If this reloc is for a Z field, we need to adjust | |
2586 | the opcode if we got a constant here. | |
2587 | FIXME: Can we make this more robust? */ | |
2588 | ||
2589 | if ((fixP->fx_where & 3) == 3 | |
2590 | && (fixP->fx_addsy == NULL | |
2591 | || S_GET_SEGMENT (fixP->fx_addsy) == absolute_section)) | |
2592 | buf[-3] |= IMM_OFFSET_BIT; | |
3c3bdf30 NC |
2593 | break; |
2594 | ||
2595 | case BFD_RELOC_MMIX_REG: | |
2596 | if (fixP->fx_addsy == NULL | |
a161fe53 | 2597 | || S_GET_SEGMENT (fixP->fx_addsy) != reg_section |
3c3bdf30 | 2598 | || S_GET_VALUE (fixP->fx_addsy) > 255) |
a161fe53 AM |
2599 | { |
2600 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
2601 | _("invalid operands")); | |
2602 | fixP->fx_done = 1; | |
2603 | } | |
3c3bdf30 | 2604 | |
a161fe53 | 2605 | *buf = val; |
3c3bdf30 NC |
2606 | break; |
2607 | ||
2608 | case BFD_RELOC_MMIX_BASE_PLUS_OFFSET: | |
2609 | /* These are never "fixed". */ | |
2610 | fixP->fx_done = 0; | |
94f592af | 2611 | return; |
3c3bdf30 NC |
2612 | |
2613 | case BFD_RELOC_MMIX_PUSHJ_1: | |
2614 | case BFD_RELOC_MMIX_PUSHJ_2: | |
2615 | case BFD_RELOC_MMIX_PUSHJ_3: | |
2616 | case BFD_RELOC_MMIX_CBRANCH_J: | |
2617 | case BFD_RELOC_MMIX_CBRANCH_1: | |
2618 | case BFD_RELOC_MMIX_CBRANCH_2: | |
2619 | case BFD_RELOC_MMIX_CBRANCH_3: | |
2620 | case BFD_RELOC_MMIX_GETA_1: | |
2621 | case BFD_RELOC_MMIX_GETA_2: | |
2622 | case BFD_RELOC_MMIX_GETA_3: | |
2623 | case BFD_RELOC_MMIX_JMP_1: | |
2624 | case BFD_RELOC_MMIX_JMP_2: | |
2625 | case BFD_RELOC_MMIX_JMP_3: | |
2626 | default: | |
2627 | BAD_CASE (fixP->fx_r_type); | |
2628 | break; | |
2629 | } | |
2630 | ||
2631 | if (fixP->fx_done) | |
2632 | /* Make sure that for completed fixups we have the value around for | |
2633 | use by e.g. mmix_frob_file. */ | |
2634 | fixP->fx_offset = val; | |
3c3bdf30 NC |
2635 | } |
2636 | ||
2637 | /* A bsearch function for looking up a value against offsets for GREG | |
2638 | definitions. */ | |
2639 | ||
2640 | static int | |
2641 | cmp_greg_val_greg_symbol_fixes (p1, p2) | |
2642 | const PTR p1; | |
2643 | const PTR p2; | |
2644 | { | |
2645 | offsetT val1 = *(offsetT *) p1; | |
2646 | offsetT val2 = ((struct mmix_symbol_greg_fixes *) p2)->offs; | |
2647 | ||
2648 | if (val1 >= val2 && val1 < val2 + 255) | |
2649 | return 0; | |
2650 | ||
2651 | if (val1 > val2) | |
2652 | return 1; | |
2653 | ||
2654 | return -1; | |
2655 | } | |
2656 | ||
2657 | /* Generate a machine-dependent relocation. */ | |
2658 | ||
2659 | arelent * | |
2660 | tc_gen_reloc (section, fixP) | |
2661 | asection *section ATTRIBUTE_UNUSED; | |
2662 | fixS *fixP; | |
2663 | { | |
2664 | bfd_signed_vma val | |
5459d7a0 HPN |
2665 | = fixP->fx_offset |
2666 | + (fixP->fx_addsy != NULL | |
2667 | && !S_IS_WEAK (fixP->fx_addsy) | |
2668 | && !S_IS_COMMON (fixP->fx_addsy) | |
2669 | ? S_GET_VALUE (fixP->fx_addsy) : 0); | |
3c3bdf30 NC |
2670 | arelent *relP; |
2671 | bfd_reloc_code_real_type code = BFD_RELOC_NONE; | |
2672 | char *buf = fixP->fx_where + fixP->fx_frag->fr_literal; | |
2673 | symbolS *addsy = fixP->fx_addsy; | |
2674 | asection *addsec = addsy == NULL ? NULL : S_GET_SEGMENT (addsy); | |
3c3bdf30 | 2675 | asymbol *baddsy = addsy != NULL ? symbol_get_bfdsym (addsy) : NULL; |
5459d7a0 HPN |
2676 | bfd_vma addend |
2677 | = val - (baddsy == NULL || S_IS_COMMON (addsy) || S_IS_WEAK (addsy) | |
2678 | ? 0 : bfd_asymbol_value (baddsy)); | |
3c3bdf30 NC |
2679 | |
2680 | /* A single " LOCAL expression" in the wrong section will not work when | |
2681 | linking to MMO; relocations for zero-content sections are then | |
2682 | ignored. Normally, relocations would modify section contents, and | |
2683 | you'd never think or be able to do something like that. The | |
2684 | relocation resulting from a LOCAL directive doesn't have an obvious | |
2685 | and mandatory location. I can't figure out a way to do this better | |
2686 | than just helping the user around this limitation here; hopefully the | |
2687 | code using the local expression is around. Putting the LOCAL | |
2688 | semantics in a relocation still seems right; a section didn't do. */ | |
2689 | if (bfd_section_size (section->owner, section) == 0) | |
2690 | as_bad_where | |
2691 | (fixP->fx_file, fixP->fx_line, | |
2692 | fixP->fx_r_type == BFD_RELOC_MMIX_LOCAL | |
2693 | /* The BFD_RELOC_MMIX_LOCAL-specific message is supposed to be | |
2694 | user-friendly, though a little bit non-substantial. */ | |
2695 | ? _("directive LOCAL must be placed in code or data") | |
2696 | : _("internal confusion: relocation in a section without contents")); | |
2697 | ||
2698 | /* FIXME: Range tests for all these. */ | |
2699 | switch (fixP->fx_r_type) | |
2700 | { | |
2701 | case BFD_RELOC_64: | |
2702 | case BFD_RELOC_32: | |
2703 | case BFD_RELOC_24: | |
2704 | case BFD_RELOC_16: | |
2705 | case BFD_RELOC_8: | |
2706 | code = fixP->fx_r_type; | |
2707 | ||
973eb340 | 2708 | if (addsy == NULL || bfd_is_abs_section (addsec)) |
3c3bdf30 NC |
2709 | { |
2710 | /* Resolve this reloc now, as md_apply_fix3 would have done (not | |
2711 | called if -linkrelax). There is no point in keeping a reloc | |
2712 | to an absolute symbol. No reloc that is subject to | |
2713 | relaxation must be to an absolute symbol; difference | |
2714 | involving symbols in a specific section must be signalled as | |
2715 | an error if the relaxing cannot be expressed; having a reloc | |
2716 | to the resolved (now absolute) value does not help. */ | |
2717 | md_number_to_chars (buf, val, fixP->fx_size); | |
2718 | return NULL; | |
2719 | } | |
2720 | break; | |
2721 | ||
2722 | case BFD_RELOC_64_PCREL: | |
2723 | case BFD_RELOC_32_PCREL: | |
2724 | case BFD_RELOC_24_PCREL: | |
2725 | case BFD_RELOC_16_PCREL: | |
2726 | case BFD_RELOC_8_PCREL: | |
2727 | case BFD_RELOC_MMIX_LOCAL: | |
2728 | case BFD_RELOC_VTABLE_INHERIT: | |
2729 | case BFD_RELOC_VTABLE_ENTRY: | |
2730 | case BFD_RELOC_MMIX_GETA: | |
2731 | case BFD_RELOC_MMIX_GETA_1: | |
2732 | case BFD_RELOC_MMIX_GETA_2: | |
2733 | case BFD_RELOC_MMIX_GETA_3: | |
2734 | case BFD_RELOC_MMIX_CBRANCH: | |
2735 | case BFD_RELOC_MMIX_CBRANCH_J: | |
2736 | case BFD_RELOC_MMIX_CBRANCH_1: | |
2737 | case BFD_RELOC_MMIX_CBRANCH_2: | |
2738 | case BFD_RELOC_MMIX_CBRANCH_3: | |
2739 | case BFD_RELOC_MMIX_PUSHJ: | |
2740 | case BFD_RELOC_MMIX_PUSHJ_1: | |
2741 | case BFD_RELOC_MMIX_PUSHJ_2: | |
2742 | case BFD_RELOC_MMIX_PUSHJ_3: | |
88fc725d | 2743 | case BFD_RELOC_MMIX_PUSHJ_STUBBABLE: |
3c3bdf30 NC |
2744 | case BFD_RELOC_MMIX_JMP: |
2745 | case BFD_RELOC_MMIX_JMP_1: | |
2746 | case BFD_RELOC_MMIX_JMP_2: | |
2747 | case BFD_RELOC_MMIX_JMP_3: | |
2748 | case BFD_RELOC_MMIX_ADDR19: | |
2749 | case BFD_RELOC_MMIX_ADDR27: | |
2750 | code = fixP->fx_r_type; | |
2751 | break; | |
2752 | ||
2753 | case BFD_RELOC_MMIX_REG_OR_BYTE: | |
2754 | /* If we have this kind of relocation to an unknown symbol or to the | |
2755 | register contents section (that is, to a register), then we can't | |
2756 | resolve the relocation here. */ | |
2757 | if (addsy != NULL | |
973eb340 | 2758 | && (bfd_is_und_section (addsec) |
3c3bdf30 NC |
2759 | || strcmp (bfd_get_section_name (addsec->owner, addsec), |
2760 | MMIX_REG_CONTENTS_SECTION_NAME) == 0)) | |
2761 | { | |
2762 | code = fixP->fx_r_type; | |
2763 | break; | |
2764 | } | |
2765 | ||
2766 | /* If the relocation is not to the register section or to the | |
2767 | absolute section (a numeric value), then we have an error. */ | |
2768 | if (addsy != NULL | |
2769 | && (S_GET_SEGMENT (addsy) != real_reg_section | |
2770 | || val > 255 | |
2771 | || val < 0) | |
973eb340 | 2772 | && ! bfd_is_abs_section (addsec)) |
3c3bdf30 NC |
2773 | goto badop; |
2774 | ||
2775 | /* Set the "immediate" bit of the insn if this relocation is to Z | |
2776 | field when the value is a numeric value, i.e. not a register. */ | |
2777 | if ((fixP->fx_where & 3) == 3 | |
973eb340 | 2778 | && (addsy == NULL || bfd_is_abs_section (addsec))) |
3c3bdf30 NC |
2779 | buf[-3] |= IMM_OFFSET_BIT; |
2780 | ||
2781 | buf[0] = val; | |
2782 | return NULL; | |
2783 | ||
2784 | case BFD_RELOC_MMIX_BASE_PLUS_OFFSET: | |
2785 | if (addsy != NULL | |
973eb340 HPN |
2786 | && strcmp (bfd_get_section_name (addsec->owner, addsec), |
2787 | MMIX_REG_CONTENTS_SECTION_NAME) == 0) | |
3c3bdf30 NC |
2788 | { |
2789 | /* This changed into a register; the relocation is for the | |
2790 | register-contents section. The constant part remains zero. */ | |
2791 | code = BFD_RELOC_MMIX_REG; | |
2792 | break; | |
2793 | } | |
2794 | ||
2795 | /* If we've found out that this was indeed a register, then replace | |
2796 | with the register number. The constant part is already zero. | |
2797 | ||
2798 | If we encounter any other defined symbol, then we must find a | |
2799 | suitable register and emit a reloc. */ | |
973eb340 | 2800 | if (addsy == NULL || addsec != real_reg_section) |
3c3bdf30 NC |
2801 | { |
2802 | struct mmix_symbol_gregs *gregs; | |
2803 | struct mmix_symbol_greg_fixes *fix; | |
2804 | ||
a1b6236b | 2805 | if (S_IS_DEFINED (addsy) |
5459d7a0 HPN |
2806 | && !bfd_is_com_section (addsec) |
2807 | && !S_IS_WEAK (addsy)) | |
3c3bdf30 | 2808 | { |
973eb340 | 2809 | if (! symbol_section_p (addsy) && ! bfd_is_abs_section (addsec)) |
3c3bdf30 NC |
2810 | as_fatal (_("internal: BFD_RELOC_MMIX_BASE_PLUS_OFFSET not resolved to section")); |
2811 | ||
2812 | /* If this is an absolute symbol sufficiently near | |
2813 | lowest_data_loc, then we canonicalize on the data | |
2814 | section. Note that val is signed here; we may subtract | |
2815 | lowest_data_loc which is unsigned. Careful with those | |
2816 | comparisons. */ | |
2817 | if (lowest_data_loc != (bfd_vma) -1 | |
2818 | && (bfd_vma) val + 256 > lowest_data_loc | |
973eb340 | 2819 | && bfd_is_abs_section (addsec)) |
3c3bdf30 NC |
2820 | { |
2821 | val -= (offsetT) lowest_data_loc; | |
2822 | addsy = section_symbol (data_section); | |
2823 | } | |
2824 | /* Likewise text section. */ | |
2825 | else if (lowest_text_loc != (bfd_vma) -1 | |
2826 | && (bfd_vma) val + 256 > lowest_text_loc | |
973eb340 | 2827 | && bfd_is_abs_section (addsec)) |
3c3bdf30 NC |
2828 | { |
2829 | val -= (offsetT) lowest_text_loc; | |
2830 | addsy = section_symbol (text_section); | |
2831 | } | |
2832 | } | |
2833 | ||
2834 | gregs = *symbol_get_tc (addsy); | |
2835 | ||
2836 | /* If that symbol does not have any associated GREG definitions, | |
973eb340 | 2837 | we can't do anything. */ |
3c3bdf30 NC |
2838 | if (gregs == NULL |
2839 | || (fix = bsearch (&val, gregs->greg_fixes, gregs->n_gregs, | |
2840 | sizeof (gregs->greg_fixes[0]), | |
2841 | cmp_greg_val_greg_symbol_fixes)) == NULL | |
2842 | /* The register must not point *after* the address we want. */ | |
2843 | || fix->offs > val | |
2844 | /* Neither must the register point more than 255 bytes | |
2845 | before the address we want. */ | |
2846 | || fix->offs + 255 < val) | |
2847 | { | |
973eb340 HPN |
2848 | /* We can either let the linker allocate GREGs |
2849 | automatically, or emit an error. */ | |
2850 | if (allocate_undefined_gregs_in_linker) | |
2851 | { | |
2852 | /* The values in baddsy and addend are right. */ | |
2853 | code = fixP->fx_r_type; | |
2854 | break; | |
2855 | } | |
2856 | else | |
2857 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
2858 | _("no suitable GREG definition for operands")); | |
3c3bdf30 NC |
2859 | return NULL; |
2860 | } | |
2861 | else | |
2862 | { | |
2863 | /* Transform the base-plus-offset reloc for the actual area | |
2864 | to a reloc for the register with the address of the area. | |
2865 | Put addend for register in Z operand. */ | |
2866 | buf[1] = val - fix->offs; | |
2867 | code = BFD_RELOC_MMIX_REG; | |
2868 | baddsy | |
2869 | = (bfd_get_section_by_name (stdoutput, | |
2870 | MMIX_REG_CONTENTS_SECTION_NAME) | |
2871 | ->symbol); | |
2872 | ||
2873 | addend = fix->fix->fx_frag->fr_address + fix->fix->fx_where; | |
2874 | } | |
2875 | } | |
2876 | else if (S_GET_VALUE (addsy) > 255) | |
2877 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
2878 | _("invalid operands")); | |
2879 | else | |
2880 | { | |
2881 | *buf = val; | |
2882 | return NULL; | |
2883 | } | |
2884 | break; | |
2885 | ||
2886 | case BFD_RELOC_MMIX_REG: | |
2887 | if (addsy != NULL | |
973eb340 | 2888 | && (bfd_is_und_section (addsec) |
3c3bdf30 NC |
2889 | || strcmp (bfd_get_section_name (addsec->owner, addsec), |
2890 | MMIX_REG_CONTENTS_SECTION_NAME) == 0)) | |
2891 | { | |
2892 | code = fixP->fx_r_type; | |
2893 | break; | |
2894 | } | |
2895 | ||
2896 | if (addsy != NULL | |
973eb340 | 2897 | && (addsec != real_reg_section |
3c3bdf30 NC |
2898 | || val > 255 |
2899 | || val < 0) | |
973eb340 | 2900 | && ! bfd_is_und_section (addsec)) |
3c3bdf30 NC |
2901 | /* Drop through to error message. */ |
2902 | ; | |
2903 | else | |
2904 | { | |
2905 | buf[0] = val; | |
2906 | return NULL; | |
2907 | } | |
a1b6236b | 2908 | /* FALLTHROUGH. */ |
3c3bdf30 NC |
2909 | |
2910 | /* The others are supposed to be handled by md_apply_fix3. | |
2911 | FIXME: ... which isn't called when -linkrelax. Move over | |
2912 | md_apply_fix3 code here for everything reasonable. */ | |
2913 | badop: | |
2914 | default: | |
2915 | as_bad_where | |
2916 | (fixP->fx_file, fixP->fx_line, | |
2917 | _("operands were not reducible at assembly-time")); | |
2918 | ||
2919 | /* Unmark this symbol as used in a reloc, so we don't bump into a BFD | |
2920 | assert when trying to output reg_section. FIXME: A gas bug. */ | |
a161fe53 | 2921 | fixP->fx_addsy = NULL; |
3c3bdf30 NC |
2922 | return NULL; |
2923 | } | |
2924 | ||
2925 | relP = (arelent *) xmalloc (sizeof (arelent)); | |
2926 | assert (relP != 0); | |
2927 | relP->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *)); | |
2928 | *relP->sym_ptr_ptr = baddsy; | |
2929 | relP->address = fixP->fx_frag->fr_address + fixP->fx_where; | |
2930 | ||
2931 | relP->addend = addend; | |
2932 | ||
2933 | /* If this had been a.out, we would have had a kludge for weak symbols | |
2934 | here. */ | |
2935 | ||
2936 | relP->howto = bfd_reloc_type_lookup (stdoutput, code); | |
2937 | if (! relP->howto) | |
2938 | { | |
2939 | const char *name; | |
2940 | ||
2941 | name = S_GET_NAME (addsy); | |
2942 | if (name == NULL) | |
2943 | name = _("<unknown>"); | |
2944 | as_fatal (_("cannot generate relocation type for symbol %s, code %s"), | |
2945 | name, bfd_get_reloc_code_name (code)); | |
2946 | } | |
2947 | ||
2948 | return relP; | |
2949 | } | |
2950 | ||
2951 | /* Do some reformatting of a line. FIXME: We could transform a mmixal | |
2952 | line into traditional (GNU?) format, unless #NO_APP, and get rid of all | |
2953 | ugly labels_without_colons etc. */ | |
2954 | ||
2955 | void | |
2956 | mmix_handle_mmixal () | |
2957 | { | |
2958 | char *s0 = input_line_pointer; | |
2959 | char *s; | |
2960 | char *label = NULL; | |
2961 | char c; | |
2962 | ||
2963 | if (pending_label != NULL) | |
2964 | as_fatal (_("internal: unhandled label %s"), pending_label); | |
2965 | ||
2966 | if (mmix_gnu_syntax) | |
2967 | return; | |
2968 | ||
2969 | /* If the first character is a '.', then it's a pseudodirective, not a | |
2970 | label. Make GAS not handle label-without-colon on this line. We | |
2971 | also don't do mmixal-specific stuff on this line. */ | |
2972 | if (input_line_pointer[0] == '.') | |
2973 | { | |
2974 | label_without_colon_this_line = 0; | |
2975 | return; | |
2976 | } | |
2977 | ||
2978 | /* Don't handle empty lines here. */ | |
2979 | while (1) | |
2980 | { | |
a1b6236b | 2981 | if (*s0 == 0 || is_end_of_line[(unsigned int) *s0]) |
3c3bdf30 NC |
2982 | return; |
2983 | ||
2984 | if (! ISSPACE (*s0)) | |
2985 | break; | |
2986 | ||
2987 | s0++; | |
2988 | } | |
2989 | ||
2990 | /* If we're on a line with a label, check if it's a mmixal fb-label. | |
2991 | Save an indicator and skip the label; it must be set only after all | |
2992 | fb-labels of expressions are evaluated. */ | |
2993 | if (ISDIGIT (input_line_pointer[0]) | |
2994 | && input_line_pointer[1] == 'H' | |
2995 | && ISSPACE (input_line_pointer[2])) | |
2996 | { | |
2997 | char *s; | |
2998 | current_fb_label = input_line_pointer[0] - '0'; | |
2999 | ||
3000 | /* We have to skip the label, but also preserve the newlineness of | |
3001 | the previous character, since the caller checks that. It's a | |
3002 | mess we blame on the caller. */ | |
3003 | input_line_pointer[1] = input_line_pointer[-1]; | |
3004 | input_line_pointer += 2; | |
3005 | ||
3006 | s = input_line_pointer; | |
3007 | while (*s && ISSPACE (*s) && ! is_end_of_line[(unsigned int) *s]) | |
3008 | s++; | |
3009 | ||
3010 | /* For errors emitted here, the book-keeping is off by one; the | |
3011 | caller is about to bump the counters. Adjust the error messages. */ | |
a1b6236b | 3012 | if (is_end_of_line[(unsigned int) *s]) |
3c3bdf30 NC |
3013 | { |
3014 | char *name; | |
3015 | unsigned int line; | |
3016 | as_where (&name, &line); | |
3017 | as_bad_where (name, line + 1, | |
3018 | _("[0-9]H labels may not appear alone on a line")); | |
3019 | current_fb_label = -1; | |
3020 | } | |
3021 | if (*s == '.') | |
3022 | { | |
3023 | char *name; | |
3024 | unsigned int line; | |
3025 | as_where (&name, &line); | |
3026 | as_bad_where (name, line + 1, | |
3027 | _("[0-9]H labels do not mix with dot-pseudos")); | |
3028 | current_fb_label = -1; | |
3029 | } | |
3030 | } | |
3031 | else | |
3032 | { | |
3033 | current_fb_label = -1; | |
3034 | if (is_name_beginner (input_line_pointer[0])) | |
3035 | label = input_line_pointer; | |
3036 | } | |
3037 | ||
3038 | s0 = input_line_pointer; | |
a1b6236b | 3039 | /* Skip over label. */ |
3c3bdf30 NC |
3040 | while (*s0 && is_part_of_name (*s0)) |
3041 | s0++; | |
3042 | ||
3043 | /* Remove trailing ":" off labels, as they'd otherwise be considered | |
3044 | part of the name. But don't do it for local labels. */ | |
3045 | if (s0 != input_line_pointer && s0[-1] == ':' | |
3046 | && (s0 - 2 != input_line_pointer | |
3047 | || ! ISDIGIT (s0[-2]))) | |
3048 | s0[-1] = ' '; | |
3049 | else if (label != NULL) | |
3050 | { | |
3051 | /* For labels that don't end in ":", we save it so we can later give | |
3052 | it the same alignment and address as the associated instruction. */ | |
3053 | ||
3054 | /* Make room for the label including the ending nul. */ | |
3055 | int len_0 = s0 - label + 1; | |
3056 | ||
3057 | /* Save this label on the MMIX symbol obstack. Saving it on an | |
3058 | obstack is needless for "IS"-pseudos, but it's harmless and we | |
3059 | avoid a little code-cluttering. */ | |
3060 | obstack_grow (&mmix_sym_obstack, label, len_0); | |
3061 | pending_label = obstack_finish (&mmix_sym_obstack); | |
3062 | pending_label[len_0 - 1] = 0; | |
3063 | } | |
3064 | ||
a1b6236b | 3065 | while (*s0 && ISSPACE (*s0) && ! is_end_of_line[(unsigned int) *s0]) |
3c3bdf30 NC |
3066 | s0++; |
3067 | ||
a1b6236b | 3068 | if (pending_label != NULL && is_end_of_line[(unsigned int) *s0]) |
3c3bdf30 NC |
3069 | /* Whoops, this was actually a lone label on a line. Like :-ended |
3070 | labels, we don't attach such labels to the next instruction or | |
3071 | pseudo. */ | |
3072 | pending_label = NULL; | |
3073 | ||
3074 | /* Find local labels of operands. Look for "[0-9][FB]" where the | |
3075 | characters before and after are not part of words. Break if a single | |
3076 | or double quote is seen anywhere. It means we can't have local | |
3077 | labels as part of list with mixed quoted and unquoted members for | |
3078 | mmixal compatibility but we can't have it all. For the moment. | |
3079 | Replace the '<N>B' or '<N>F' with MAGIC_FB_BACKWARD_CHAR<N> and | |
3080 | MAGIC_FB_FORWARD_CHAR<N> respectively. */ | |
3081 | ||
3082 | /* First make sure we don't have any of the magic characters on the line | |
3083 | appearing as input. */ | |
3084 | s = s0; | |
3085 | while (*s) | |
3086 | { | |
3087 | c = *s++; | |
a1b6236b | 3088 | if (is_end_of_line[(unsigned int) c]) |
3c3bdf30 NC |
3089 | break; |
3090 | if (c == MAGIC_FB_BACKWARD_CHAR || c == MAGIC_FB_FORWARD_CHAR) | |
3091 | as_bad (_("invalid characters in input")); | |
3092 | } | |
3093 | ||
3094 | /* Scan again, this time looking for ';' after operands. */ | |
3095 | s = s0; | |
3096 | ||
3097 | /* Skip the insn. */ | |
3098 | while (*s | |
3099 | && ! ISSPACE (*s) | |
3100 | && *s != ';' | |
3101 | && ! is_end_of_line[(unsigned int) *s]) | |
3102 | s++; | |
3103 | ||
3104 | /* Skip the spaces after the insn. */ | |
3105 | while (*s | |
3106 | && ISSPACE (*s) | |
3107 | && *s != ';' | |
3108 | && ! is_end_of_line[(unsigned int) *s]) | |
3109 | s++; | |
3110 | ||
3111 | /* Skip the operands. While doing this, replace [0-9][BF] with | |
3112 | (MAGIC_FB_BACKWARD_CHAR|MAGIC_FB_FORWARD_CHAR)[0-9]. */ | |
3113 | while ((c = *s) != 0 | |
3114 | && ! ISSPACE (c) | |
3115 | && c != ';' | |
3116 | && ! is_end_of_line[(unsigned int) c]) | |
3117 | { | |
3118 | if (c == '"') | |
3119 | { | |
3120 | s++; | |
3121 | ||
3122 | /* FIXME: Test-case for semi-colon in string. */ | |
3123 | while (*s | |
3124 | && *s != '"' | |
a1b6236b | 3125 | && (! is_end_of_line[(unsigned int) *s] || *s == ';')) |
3c3bdf30 NC |
3126 | s++; |
3127 | ||
3128 | if (*s == '"') | |
3129 | s++; | |
3130 | } | |
3131 | else if (ISDIGIT (c)) | |
3132 | { | |
3133 | if ((s[1] != 'B' && s[1] != 'F') | |
3134 | || is_part_of_name (s[-1]) | |
3135 | || is_part_of_name (s[2])) | |
3136 | s++; | |
3137 | else | |
3138 | { | |
3139 | s[0] = (s[1] == 'B' | |
3140 | ? MAGIC_FB_BACKWARD_CHAR : MAGIC_FB_FORWARD_CHAR); | |
3141 | s[1] = c; | |
3142 | } | |
3143 | } | |
3144 | else | |
3145 | s++; | |
3146 | } | |
3147 | ||
3148 | /* Skip any spaces after the operands. */ | |
3149 | while (*s | |
3150 | && ISSPACE (*s) | |
3151 | && *s != ';' | |
3152 | && !is_end_of_line[(unsigned int) *s]) | |
3153 | s++; | |
3154 | ||
3155 | /* If we're now looking at a semi-colon, then it's an end-of-line | |
3156 | delimiter. */ | |
3157 | mmix_next_semicolon_is_eoln = (*s == ';'); | |
3158 | ||
3159 | /* Make IS into an EQU by replacing it with "= ". Only match upper-case | |
3160 | though; let lower-case be a syntax error. */ | |
3161 | s = s0; | |
3162 | if (s[0] == 'I' && s[1] == 'S' && ISSPACE (s[2])) | |
3163 | { | |
3164 | *s = '='; | |
3165 | s[1] = ' '; | |
3166 | ||
3167 | /* Since labels can start without ":", we have to handle "X IS 42" | |
3168 | in full here, or "X" will be parsed as a label to be set at ".". */ | |
3169 | input_line_pointer = s; | |
3170 | ||
3171 | /* Right after this function ends, line numbers will be bumped if | |
3172 | input_line_pointer[-1] = '\n'. We want accurate line numbers for | |
3173 | the equals call, so we bump them before the call, and make sure | |
3174 | they aren't bumped afterwards. */ | |
3175 | bump_line_counters (); | |
3176 | ||
3177 | /* A fb-label is valid as an IS-label. */ | |
3178 | if (current_fb_label >= 0) | |
3179 | { | |
3180 | char *fb_name; | |
3181 | ||
3182 | /* We need to save this name on our symbol obstack, since the | |
3183 | string we got in fb_label_name is volatile and will change | |
3184 | with every call to fb_label_name, like those resulting from | |
3185 | parsing the IS-operand. */ | |
3186 | fb_name = fb_label_name (current_fb_label, 1); | |
3187 | obstack_grow (&mmix_sym_obstack, fb_name, strlen (fb_name) + 1); | |
3188 | equals (obstack_finish (&mmix_sym_obstack), 0); | |
3189 | fb_label_instance_inc (current_fb_label); | |
3190 | current_fb_label = -1; | |
3191 | } | |
3192 | else | |
3193 | { | |
3194 | if (pending_label == NULL) | |
3195 | as_bad (_("empty label field for IS")); | |
3196 | else | |
3197 | equals (pending_label, 0); | |
3198 | pending_label = NULL; | |
3199 | } | |
3200 | ||
3201 | /* For mmixal, we can have comments without a comment-start | |
3202 | character. */ | |
3203 | mmix_handle_rest_of_empty_line (); | |
3204 | input_line_pointer--; | |
3205 | ||
3206 | input_line_pointer[-1] = ' '; | |
3207 | } | |
3208 | else if (s[0] == 'G' | |
3209 | && s[1] == 'R' | |
3210 | && strncmp (s, "GREG", 4) == 0 | |
3211 | && (ISSPACE (s[4]) || is_end_of_line[(unsigned char) s[4]])) | |
3212 | { | |
3213 | input_line_pointer = s + 4; | |
3214 | ||
3215 | /* Right after this function ends, line numbers will be bumped if | |
3216 | input_line_pointer[-1] = '\n'. We want accurate line numbers for | |
3217 | the s_greg call, so we bump them before the call, and make sure | |
3218 | they aren't bumped afterwards. */ | |
3219 | bump_line_counters (); | |
3220 | ||
3221 | /* A fb-label is valid as a GREG-label. */ | |
3222 | if (current_fb_label >= 0) | |
3223 | { | |
3224 | char *fb_name; | |
3225 | ||
3226 | /* We need to save this name on our symbol obstack, since the | |
3227 | string we got in fb_label_name is volatile and will change | |
3228 | with every call to fb_label_name, like those resulting from | |
3229 | parsing the IS-operand. */ | |
3230 | fb_name = fb_label_name (current_fb_label, 1); | |
3231 | ||
3232 | /* Make sure we save the canonical name and don't get bitten by | |
3233 | prefixes. */ | |
3234 | obstack_1grow (&mmix_sym_obstack, ':'); | |
3235 | obstack_grow (&mmix_sym_obstack, fb_name, strlen (fb_name) + 1); | |
3236 | mmix_greg_internal (obstack_finish (&mmix_sym_obstack)); | |
3237 | fb_label_instance_inc (current_fb_label); | |
3238 | current_fb_label = -1; | |
3239 | } | |
3240 | else | |
3241 | mmix_greg_internal (pending_label); | |
3242 | ||
3243 | /* Back up before the end-of-line marker that was skipped in | |
3244 | mmix_greg_internal. */ | |
3245 | input_line_pointer--; | |
3246 | input_line_pointer[-1] = ' '; | |
3247 | ||
3248 | pending_label = NULL; | |
3249 | } | |
3250 | else if (pending_label != NULL) | |
3251 | { | |
3252 | input_line_pointer += strlen (pending_label); | |
3253 | ||
3254 | /* See comment above about getting line numbers bumped. */ | |
3255 | input_line_pointer[-1] = '\n'; | |
3256 | } | |
3257 | } | |
3258 | ||
3259 | /* Give the value of an fb-label rewritten as in mmix_handle_mmixal, when | |
3260 | parsing an expression. | |
3261 | ||
3262 | On valid calls, input_line_pointer points at a MAGIC_FB_BACKWARD_CHAR | |
3263 | or MAGIC_FB_BACKWARD_CHAR, followed by an ascii digit for the label. | |
3264 | We fill in the label as an expression. */ | |
3265 | ||
3266 | void | |
3267 | mmix_fb_label (expP) | |
3268 | expressionS *expP; | |
3269 | { | |
3270 | symbolS *sym; | |
3271 | char *fb_internal_name; | |
3272 | ||
3273 | /* This doesn't happen when not using mmixal syntax. */ | |
3274 | if (mmix_gnu_syntax | |
3275 | || (input_line_pointer[0] != MAGIC_FB_BACKWARD_CHAR | |
3276 | && input_line_pointer[0] != MAGIC_FB_FORWARD_CHAR)) | |
3277 | return; | |
3278 | ||
3279 | /* The current backward reference has augmentation 0. A forward | |
3280 | reference has augmentation 1, unless it's the same as a fb-label on | |
3281 | _this_ line, in which case we add one more so we don't refer to it. | |
3282 | This is the semantics of mmixal; it differs to that of common | |
3283 | fb-labels which refer to a here-label on the current line as a | |
3284 | backward reference. */ | |
3285 | fb_internal_name | |
3286 | = fb_label_name (input_line_pointer[1] - '0', | |
3287 | (input_line_pointer[0] == MAGIC_FB_FORWARD_CHAR ? 1 : 0) | |
3288 | + ((input_line_pointer[1] - '0' == current_fb_label | |
3289 | && input_line_pointer[0] == MAGIC_FB_FORWARD_CHAR) | |
3290 | ? 1 : 0)); | |
3291 | ||
3292 | input_line_pointer += 2; | |
3293 | sym = symbol_find_or_make (fb_internal_name); | |
3294 | ||
3295 | /* We don't have to clean up unrelated fields here; we just do what the | |
3296 | expr machinery does, but *not* just what it does for [0-9][fb], since | |
3297 | we need to treat those as ordinary symbols sometimes; see testcases | |
3298 | err-byte2.s and fb-2.s. */ | |
3299 | if (S_GET_SEGMENT (sym) == absolute_section) | |
3300 | { | |
3301 | expP->X_op = O_constant; | |
3302 | expP->X_add_number = S_GET_VALUE (sym); | |
3303 | } | |
3304 | else | |
3305 | { | |
3306 | expP->X_op = O_symbol; | |
3307 | expP->X_add_symbol = sym; | |
3308 | expP->X_add_number = 0; | |
3309 | } | |
3310 | } | |
3311 | ||
3312 | /* See whether we need to force a relocation into the output file. | |
3313 | This is used to force out switch and PC relative relocations when | |
3314 | relaxing. */ | |
3315 | ||
3316 | int | |
3317 | mmix_force_relocation (fixP) | |
a1b6236b | 3318 | fixS *fixP; |
3c3bdf30 NC |
3319 | { |
3320 | if (fixP->fx_r_type == BFD_RELOC_MMIX_LOCAL | |
3c3bdf30 NC |
3321 | || fixP->fx_r_type == BFD_RELOC_MMIX_BASE_PLUS_OFFSET) |
3322 | return 1; | |
3323 | ||
3c3bdf30 NC |
3324 | if (linkrelax) |
3325 | return 1; | |
3326 | ||
3327 | /* All our pcrel relocations are must-keep. Note that md_apply_fix3 is | |
3328 | called *after* this, and will handle getting rid of the presumed | |
3329 | reloc; a relocation isn't *forced* other than to be handled by | |
3330 | md_apply_fix3 (or tc_gen_reloc if linkrelax). */ | |
3331 | if (fixP->fx_pcrel) | |
3332 | return 1; | |
3333 | ||
ae6063d4 | 3334 | return generic_force_reloc (fixP); |
3c3bdf30 NC |
3335 | } |
3336 | ||
3337 | /* The location from which a PC relative jump should be calculated, | |
3338 | given a PC relative reloc. */ | |
3339 | ||
3340 | long | |
3341 | md_pcrel_from_section (fixP, sec) | |
3342 | fixS * fixP; | |
3343 | segT sec; | |
3344 | { | |
3345 | if (fixP->fx_addsy != (symbolS *) NULL | |
3346 | && (! S_IS_DEFINED (fixP->fx_addsy) | |
3347 | || S_GET_SEGMENT (fixP->fx_addsy) != sec)) | |
3348 | { | |
3349 | /* The symbol is undefined (or is defined but not in this section). | |
3350 | Let the linker figure it out. */ | |
3351 | return 0; | |
3352 | } | |
3353 | ||
3354 | return (fixP->fx_frag->fr_address + fixP->fx_where); | |
3355 | } | |
3356 | ||
3357 | /* Adjust the symbol table. We make reg_section relative to the real | |
a161fe53 | 3358 | register section. */ |
3c3bdf30 NC |
3359 | |
3360 | void | |
3361 | mmix_adjust_symtab () | |
3362 | { | |
3363 | symbolS *sym; | |
3c3bdf30 | 3364 | symbolS *regsec = section_symbol (reg_section); |
3c3bdf30 | 3365 | |
a161fe53 | 3366 | for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym)) |
3c3bdf30 NC |
3367 | if (S_GET_SEGMENT (sym) == reg_section) |
3368 | { | |
a161fe53 | 3369 | if (sym == regsec) |
3c3bdf30 | 3370 | { |
a161fe53 AM |
3371 | if (S_IS_EXTERN (sym) || symbol_used_in_reloc_p (sym)) |
3372 | abort (); | |
3c3bdf30 | 3373 | symbol_remove (sym, &symbol_rootP, &symbol_lastP); |
3c3bdf30 NC |
3374 | } |
3375 | else | |
a161fe53 AM |
3376 | /* Change section to the *real* register section, so it gets |
3377 | proper treatment when writing it out. Only do this for | |
3378 | global symbols. This also means we don't have to check for | |
3379 | $0..$255. */ | |
3380 | S_SET_SEGMENT (sym, real_reg_section); | |
3c3bdf30 NC |
3381 | } |
3382 | } | |
3383 | ||
3384 | /* This is the expansion of LABELS_WITHOUT_COLONS. | |
3385 | We let md_start_line_hook tweak label_without_colon_this_line, and then | |
3386 | this function returns the tweaked value, and sets it to 1 for the next | |
3387 | line. FIXME: Very, very brittle. Not sure it works the way I | |
3388 | thought at the time I first wrote this. */ | |
3389 | ||
3390 | int | |
3391 | mmix_label_without_colon_this_line () | |
3392 | { | |
3393 | int retval = label_without_colon_this_line; | |
3394 | ||
3395 | if (! mmix_gnu_syntax) | |
3396 | label_without_colon_this_line = 1; | |
3397 | ||
3398 | return retval; | |
3399 | } | |
3400 | ||
3401 | /* This is the expansion of md_relax_frag. We go through the ordinary | |
3402 | relax table function except when the frag is for a GREG. Then we have | |
3403 | to check whether there's another GREG by the same value that we can | |
3404 | join with. */ | |
3405 | ||
3406 | long | |
3407 | mmix_md_relax_frag (seg, fragP, stretch) | |
3408 | segT seg; | |
3409 | fragS *fragP; | |
3410 | long stretch; | |
3411 | { | |
88fc725d HPN |
3412 | switch (fragP->fr_subtype) |
3413 | { | |
3414 | /* Growth for this type has been handled by mmix_md_end and | |
3415 | correctly estimated, so there's nothing more to do here. */ | |
3416 | case STATE_GREG_DEF: | |
3417 | return 0; | |
3c3bdf30 | 3418 | |
88fc725d HPN |
3419 | case ENCODE_RELAX (STATE_PUSHJ, STATE_ZERO): |
3420 | { | |
3421 | /* We need to handle relaxation type ourselves, since relax_frag | |
3422 | doesn't update fr_subtype if there's no size increase in the | |
3423 | current section; when going from plain PUSHJ to a stub. This | |
3424 | is otherwise functionally the same as relax_frag in write.c, | |
3425 | simplified for this case. */ | |
3426 | offsetT aim; | |
3427 | addressT target; | |
3428 | addressT address; | |
3429 | symbolS *symbolP; | |
3430 | target = fragP->fr_offset; | |
3431 | address = fragP->fr_address; | |
3432 | symbolP = fragP->fr_symbol; | |
3433 | ||
3434 | if (symbolP) | |
3435 | { | |
3436 | fragS *sym_frag; | |
3437 | ||
3438 | sym_frag = symbol_get_frag (symbolP); | |
3439 | know (S_GET_SEGMENT (symbolP) != absolute_section | |
3440 | || sym_frag == &zero_address_frag); | |
3441 | target += S_GET_VALUE (symbolP); | |
3442 | ||
3443 | /* If frag has yet to be reached on this pass, assume it will | |
3444 | move by STRETCH just as we did. If this is not so, it will | |
3445 | be because some frag between grows, and that will force | |
3446 | another pass. */ | |
3447 | ||
3448 | if (stretch != 0 | |
3449 | && sym_frag->relax_marker != fragP->relax_marker | |
3450 | && S_GET_SEGMENT (symbolP) == seg) | |
3451 | target += stretch; | |
3452 | } | |
3453 | ||
3454 | aim = target - address - fragP->fr_fix; | |
3455 | if (aim >= PUSHJ_0B && aim <= PUSHJ_0F) | |
3456 | { | |
3457 | /* Target is reachable with a PUSHJ. */ | |
3458 | segment_info_type *seginfo = seg_info (seg); | |
3459 | ||
3460 | /* If we're at the end of a relaxation round, clear the stub | |
3461 | counter as initialization for the next round. */ | |
3462 | if (fragP == seginfo->tc_segment_info_data.last_stubfrag) | |
3463 | seginfo->tc_segment_info_data.nstubs = 0; | |
3464 | return 0; | |
3465 | } | |
3466 | ||
3467 | /* Not reachable. Try a stub. */ | |
3468 | fragP->fr_subtype = ENCODE_RELAX (STATE_PUSHJSTUB, STATE_ZERO); | |
3469 | } | |
3470 | /* FALLTHROUGH. */ | |
3471 | ||
3472 | /* See if this PUSHJ is redirectable to a stub. */ | |
3473 | case ENCODE_RELAX (STATE_PUSHJSTUB, STATE_ZERO): | |
3474 | { | |
3475 | segment_info_type *seginfo = seg_info (seg); | |
3476 | fragS *lastfrag = seginfo->frchainP->frch_last; | |
3477 | relax_substateT prev_type = fragP->fr_subtype; | |
3478 | ||
3479 | /* The last frag is always an empty frag, so it suffices to look | |
3480 | at its address to know the ending address of this section. */ | |
3481 | know (lastfrag->fr_type == rs_fill | |
3482 | && lastfrag->fr_fix == 0 | |
3483 | && lastfrag->fr_var == 0); | |
3484 | ||
3485 | /* For this PUSHJ to be relaxable into a call to a stub, the | |
3486 | distance must be no longer than 256k bytes from the PUSHJ to | |
3487 | the end of the section plus the maximum size of stubs so far. */ | |
3488 | if ((lastfrag->fr_address | |
3489 | + stretch | |
3490 | + PUSHJ_MAX_LEN * seginfo->tc_segment_info_data.nstubs) | |
3491 | - (fragP->fr_address + fragP->fr_fix) | |
3492 | > GETA_0F | |
3493 | || !pushj_stubs) | |
3494 | fragP->fr_subtype = mmix_relax_table[prev_type].rlx_more; | |
3495 | else | |
3496 | seginfo->tc_segment_info_data.nstubs++; | |
3497 | ||
3498 | /* If we're at the end of a relaxation round, clear the stub | |
3499 | counter as initialization for the next round. */ | |
3500 | if (fragP == seginfo->tc_segment_info_data.last_stubfrag) | |
3501 | seginfo->tc_segment_info_data.nstubs = 0; | |
3502 | ||
3503 | return | |
3504 | (mmix_relax_table[fragP->fr_subtype].rlx_length | |
3505 | - mmix_relax_table[prev_type].rlx_length); | |
3506 | } | |
3507 | ||
3508 | case ENCODE_RELAX (STATE_PUSHJ, STATE_MAX): | |
3509 | { | |
3510 | segment_info_type *seginfo = seg_info (seg); | |
3511 | ||
3512 | /* Need to cover all STATE_PUSHJ states to act on the last stub | |
3513 | frag (the end of this relax round; initialization for the | |
3514 | next). */ | |
3515 | if (fragP == seginfo->tc_segment_info_data.last_stubfrag) | |
3516 | seginfo->tc_segment_info_data.nstubs = 0; | |
3517 | ||
3518 | return 0; | |
3519 | } | |
3520 | ||
3521 | default: | |
3522 | return relax_frag (seg, fragP, stretch); | |
3523 | ||
3524 | case STATE_GREG_UNDF: | |
3525 | BAD_CASE (fragP->fr_subtype); | |
3526 | } | |
3c3bdf30 NC |
3527 | |
3528 | as_fatal (_("internal: unexpected relax type %d:%d"), | |
3529 | fragP->fr_type, fragP->fr_subtype); | |
3530 | return 0; | |
3531 | } | |
3532 | ||
3533 | /* Various things we punt until all input is seen. */ | |
3534 | ||
3535 | void | |
3536 | mmix_md_end () | |
3537 | { | |
3538 | fragS *fragP; | |
3539 | symbolS *mainsym; | |
3540 | int i; | |
3541 | ||
3542 | /* The first frag of GREG:s going into the register contents section. */ | |
3543 | fragS *mmix_reg_contents_frags = NULL; | |
3544 | ||
3545 | /* Reset prefix. All labels reachable at this point must be | |
3546 | canonicalized. */ | |
3547 | mmix_current_prefix = NULL; | |
3548 | ||
3549 | if (doing_bspec) | |
3550 | as_bad_where (bspec_file, bspec_line, _("BSPEC without ESPEC.")); | |
3551 | ||
3552 | /* Emit the low LOC setting of .text. */ | |
3553 | if (text_has_contents && lowest_text_loc != (bfd_vma) -1) | |
3554 | { | |
3555 | symbolS *symbolP; | |
3556 | char locsymbol[sizeof (":") - 1 | |
3557 | + sizeof (MMIX_LOC_SECTION_START_SYMBOL_PREFIX) - 1 | |
3558 | + sizeof (".text")]; | |
3559 | ||
3560 | /* An exercise in non-ISO-C-ness, this one. */ | |
3561 | sprintf (locsymbol, ":%s%s", MMIX_LOC_SECTION_START_SYMBOL_PREFIX, | |
3562 | ".text"); | |
3563 | symbolP | |
3564 | = symbol_new (locsymbol, absolute_section, lowest_text_loc, | |
3565 | &zero_address_frag); | |
3566 | S_SET_EXTERNAL (symbolP); | |
3567 | } | |
3568 | ||
3569 | /* Ditto .data. */ | |
3570 | if (data_has_contents && lowest_data_loc != (bfd_vma) -1) | |
3571 | { | |
3572 | symbolS *symbolP; | |
3573 | char locsymbol[sizeof (":") - 1 | |
a1b6236b KH |
3574 | + sizeof (MMIX_LOC_SECTION_START_SYMBOL_PREFIX) - 1 |
3575 | + sizeof (".data")]; | |
3c3bdf30 NC |
3576 | |
3577 | sprintf (locsymbol, ":%s%s", MMIX_LOC_SECTION_START_SYMBOL_PREFIX, | |
3578 | ".data"); | |
3579 | symbolP | |
3580 | = symbol_new (locsymbol, absolute_section, lowest_data_loc, | |
3581 | &zero_address_frag); | |
3582 | S_SET_EXTERNAL (symbolP); | |
3583 | } | |
3584 | ||
3585 | /* Unless GNU syntax mode, set "Main" to be a function, so the | |
3586 | disassembler doesn't get confused when we write truly | |
3587 | mmixal-compatible code (and don't use .type). Similarly set it | |
3588 | global (regardless of -globalize-symbols), so the linker sees it as | |
3589 | the start symbol in ELF mode. */ | |
3590 | mainsym = symbol_find (MMIX_START_SYMBOL_NAME); | |
3591 | if (mainsym != NULL && ! mmix_gnu_syntax) | |
3592 | { | |
3593 | symbol_get_bfdsym (mainsym)->flags |= BSF_FUNCTION; | |
3594 | S_SET_EXTERNAL (mainsym); | |
3595 | } | |
3596 | ||
3597 | if (n_of_raw_gregs != 0) | |
3598 | { | |
3599 | /* Emit GREGs. They are collected in order of appearance, but must | |
3600 | be emitted in opposite order to both have section address regno*8 | |
3601 | and the same allocation order (within a file) as mmixal. */ | |
3602 | segT this_segment = now_seg; | |
3603 | subsegT this_subsegment = now_subseg; | |
3604 | asection *regsec | |
3605 | = bfd_make_section_old_way (stdoutput, | |
3606 | MMIX_REG_CONTENTS_SECTION_NAME); | |
3607 | subseg_set (regsec, 0); | |
3608 | ||
3609 | /* Finally emit the initialization-value. Emit a variable frag, which | |
3610 | we'll fix in md_estimate_size_before_relax. We set the initializer | |
3611 | for the tc_frag_data field to NULL, so we can use that field for | |
3612 | relaxation purposes. */ | |
3613 | mmix_opcode_frag = NULL; | |
3614 | ||
3615 | frag_grow (0); | |
3616 | mmix_reg_contents_frags = frag_now; | |
3617 | ||
3618 | for (i = n_of_raw_gregs - 1; i >= 0; i--) | |
3619 | { | |
3620 | if (mmix_raw_gregs[i].label != NULL) | |
3621 | /* There's a symbol. Let it refer to this location in the | |
3622 | register contents section. The symbol must be globalized | |
3623 | separately. */ | |
3624 | colon (mmix_raw_gregs[i].label); | |
3625 | ||
3626 | frag_var (rs_machine_dependent, 8, 0, STATE_GREG_UNDF, | |
3627 | make_expr_symbol (&mmix_raw_gregs[i].exp), 0, NULL); | |
3628 | } | |
3629 | ||
3630 | subseg_set (this_segment, this_subsegment); | |
3631 | } | |
3632 | ||
3633 | /* Iterate over frags resulting from GREGs and move those that evidently | |
3634 | have the same value together and point one to another. | |
3635 | ||
3636 | This works in time O(N^2) but since the upper bound for non-error use | |
3637 | is 223, it's best to keep this simpler algorithm. */ | |
3638 | for (fragP = mmix_reg_contents_frags; fragP != NULL; fragP = fragP->fr_next) | |
3639 | { | |
3640 | fragS **fpp; | |
3641 | fragS *fp = NULL; | |
3642 | fragS *osymfrag; | |
3643 | offsetT osymval; | |
3644 | expressionS *oexpP; | |
3645 | symbolS *symbolP = fragP->fr_symbol; | |
3646 | ||
3647 | if (fragP->fr_type != rs_machine_dependent | |
3648 | || fragP->fr_subtype != STATE_GREG_UNDF) | |
3649 | continue; | |
3650 | ||
3651 | /* Whatever the outcome, we will have this GREG judged merged or | |
3652 | non-merged. Since the tc_frag_data is NULL at this point, we | |
3653 | default to non-merged. */ | |
3654 | fragP->fr_subtype = STATE_GREG_DEF; | |
3655 | ||
3656 | /* If we're not supposed to merge GREG definitions, then just don't | |
3657 | look for equivalents. */ | |
3658 | if (! merge_gregs) | |
3659 | continue; | |
3660 | ||
3661 | osymval = (offsetT) S_GET_VALUE (symbolP); | |
3662 | osymfrag = symbol_get_frag (symbolP); | |
3663 | ||
3664 | /* If the symbol isn't defined, we can't say that another symbol | |
3665 | equals this frag, then. FIXME: We can look at the "deepest" | |
3666 | defined name; if a = c and b = c then obviously a == b. */ | |
3667 | if (! S_IS_DEFINED (symbolP)) | |
3668 | continue; | |
3669 | ||
3670 | oexpP = symbol_get_value_expression (fragP->fr_symbol); | |
3671 | ||
3672 | /* If the initialization value is zero, then we must not merge them. */ | |
3673 | if (oexpP->X_op == O_constant && osymval == 0) | |
3674 | continue; | |
3675 | ||
3676 | /* Iterate through the frags downward this one. If we find one that | |
3677 | has the same non-zero value, move it to after this one and point | |
3678 | to it as the equivalent. */ | |
3679 | for (fpp = &fragP->fr_next; *fpp != NULL; fpp = &fpp[0]->fr_next) | |
3680 | { | |
3681 | fp = *fpp; | |
3682 | ||
3683 | if (fp->fr_type != rs_machine_dependent | |
3684 | || fp->fr_subtype != STATE_GREG_UNDF) | |
3685 | continue; | |
3686 | ||
3687 | /* Calling S_GET_VALUE may simplify the symbol, changing from | |
3688 | expr_section etc. so call it first. */ | |
3689 | if ((offsetT) S_GET_VALUE (fp->fr_symbol) == osymval | |
3690 | && symbol_get_frag (fp->fr_symbol) == osymfrag) | |
3691 | { | |
3692 | /* Move the frag links so the one we found equivalent comes | |
3693 | after the current one, carefully considering that | |
3694 | sometimes fpp == &fragP->fr_next and the moves must be a | |
3695 | NOP then. */ | |
3696 | *fpp = fp->fr_next; | |
3697 | fp->fr_next = fragP->fr_next; | |
3698 | fragP->fr_next = fp; | |
3699 | break; | |
3700 | } | |
3701 | } | |
3702 | ||
3703 | if (*fpp != NULL) | |
3704 | fragP->tc_frag_data = fp; | |
3705 | } | |
3706 | } | |
3707 | ||
3708 | /* qsort function for mmix_symbol_gregs. */ | |
3709 | ||
3710 | static int | |
3711 | cmp_greg_symbol_fixes (parg, qarg) | |
3712 | const PTR parg; | |
3713 | const PTR qarg; | |
3714 | { | |
3715 | const struct mmix_symbol_greg_fixes *p | |
3716 | = (const struct mmix_symbol_greg_fixes *) parg; | |
3717 | const struct mmix_symbol_greg_fixes *q | |
3718 | = (const struct mmix_symbol_greg_fixes *) qarg; | |
3719 | ||
3720 | return p->offs > q->offs ? 1 : p->offs < q->offs ? -1 : 0; | |
3721 | } | |
3722 | ||
3723 | /* Collect GREG definitions from mmix_gregs and hang them as lists sorted | |
3724 | on increasing offsets onto each section symbol or undefined symbol. | |
3725 | ||
3726 | Also, remove the register convenience section so it doesn't get output | |
3727 | as an ELF section. */ | |
3728 | ||
3729 | void | |
3730 | mmix_frob_file () | |
3731 | { | |
3732 | int i; | |
3733 | struct mmix_symbol_gregs *all_greg_symbols[MAX_GREGS]; | |
3734 | int n_greg_symbols = 0; | |
3735 | ||
3736 | /* Collect all greg fixups and decorate each corresponding symbol with | |
3737 | the greg fixups for it. */ | |
3738 | for (i = 0; i < n_of_cooked_gregs; i++) | |
3739 | { | |
3740 | offsetT offs; | |
3741 | symbolS *sym; | |
3742 | struct mmix_symbol_gregs *gregs; | |
3743 | fixS *fixP; | |
3744 | ||
3745 | fixP = mmix_gregs[i]; | |
3746 | know (fixP->fx_r_type == BFD_RELOC_64); | |
3747 | ||
3748 | /* This case isn't doable in general anyway, methinks. */ | |
3749 | if (fixP->fx_subsy != NULL) | |
3750 | { | |
3751 | as_bad_where (fixP->fx_file, fixP->fx_line, | |
3752 | _("GREG expression too complicated")); | |
3753 | continue; | |
3754 | } | |
3755 | ||
3756 | sym = fixP->fx_addsy; | |
3757 | offs = (offsetT) fixP->fx_offset; | |
3758 | ||
3759 | /* If the symbol is defined, then it must be resolved to a section | |
3760 | symbol at this time, or else we don't know how to handle it. */ | |
5459d7a0 HPN |
3761 | if (S_IS_DEFINED (sym) |
3762 | && !bfd_is_com_section (S_GET_SEGMENT (sym)) | |
3763 | && !S_IS_WEAK (sym)) | |
3c3bdf30 NC |
3764 | { |
3765 | if (! symbol_section_p (sym) | |
3766 | && ! bfd_is_abs_section (S_GET_SEGMENT (sym))) | |
3767 | as_fatal (_("internal: GREG expression not resolved to section")); | |
3768 | ||
3769 | offs += S_GET_VALUE (sym); | |
3770 | } | |
3771 | ||
3772 | /* If this is an absolute symbol sufficiently near lowest_data_loc, | |
3773 | then we canonicalize on the data section. Note that offs is | |
3774 | signed here; we may subtract lowest_data_loc which is unsigned. | |
3775 | Careful with those comparisons. */ | |
3776 | if (lowest_data_loc != (bfd_vma) -1 | |
3777 | && (bfd_vma) offs + 256 > lowest_data_loc | |
3778 | && bfd_is_abs_section (S_GET_SEGMENT (sym))) | |
3779 | { | |
3780 | offs -= (offsetT) lowest_data_loc; | |
3781 | sym = section_symbol (data_section); | |
3782 | } | |
3783 | /* Likewise text section. */ | |
3784 | else if (lowest_text_loc != (bfd_vma) -1 | |
3785 | && (bfd_vma) offs + 256 > lowest_text_loc | |
3786 | && bfd_is_abs_section (S_GET_SEGMENT (sym))) | |
3787 | { | |
3788 | offs -= (offsetT) lowest_text_loc; | |
3789 | sym = section_symbol (text_section); | |
3790 | } | |
3791 | ||
3792 | gregs = *symbol_get_tc (sym); | |
3793 | ||
3794 | if (gregs == NULL) | |
3795 | { | |
3796 | gregs = xmalloc (sizeof (*gregs)); | |
3797 | gregs->n_gregs = 0; | |
3798 | symbol_set_tc (sym, &gregs); | |
3799 | all_greg_symbols[n_greg_symbols++] = gregs; | |
3800 | } | |
3801 | ||
3802 | gregs->greg_fixes[gregs->n_gregs].fix = fixP; | |
3803 | gregs->greg_fixes[gregs->n_gregs++].offs = offs; | |
3804 | } | |
3805 | ||
3806 | /* For each symbol having a GREG definition, sort those definitions on | |
3807 | offset. */ | |
3808 | for (i = 0; i < n_greg_symbols; i++) | |
3809 | qsort (all_greg_symbols[i]->greg_fixes, all_greg_symbols[i]->n_gregs, | |
3810 | sizeof (all_greg_symbols[i]->greg_fixes[0]), cmp_greg_symbol_fixes); | |
3811 | ||
3812 | if (real_reg_section != NULL) | |
3813 | { | |
3814 | asection **secpp; | |
3815 | ||
3816 | /* FIXME: Pass error state gracefully. */ | |
3817 | if (bfd_get_section_flags (stdoutput, real_reg_section) & SEC_HAS_CONTENTS) | |
3818 | as_fatal (_("register section has contents\n")); | |
3819 | ||
3c3bdf30 NC |
3820 | /* Really remove the section. */ |
3821 | for (secpp = &stdoutput->sections; | |
3822 | *secpp != real_reg_section; | |
3823 | secpp = &(*secpp)->next) | |
3824 | ; | |
7c6beb69 | 3825 | bfd_section_list_remove (stdoutput, secpp); |
3c3bdf30 NC |
3826 | --stdoutput->section_count; |
3827 | } | |
3828 | ||
3829 | } | |
3830 | ||
3831 | /* Provide an expression for a built-in name provided when-used. | |
3832 | Either a symbol that is a handler; living in 0x10*[1..8] and having | |
3833 | name [DVWIOUZX]_Handler, or a mmixal built-in symbol. | |
3834 | ||
3835 | If the name isn't a built-in name and parsed into *EXPP, return zero. */ | |
3836 | ||
3837 | int | |
3838 | mmix_parse_predefined_name (name, expP) | |
3839 | char *name; | |
3840 | expressionS *expP; | |
3841 | { | |
3842 | char *canon_name; | |
3843 | char *handler_charp; | |
3844 | const char handler_chars[] = "DVWIOUZX"; | |
3845 | symbolS *symp; | |
3846 | ||
3847 | if (! predefined_syms) | |
3848 | return 0; | |
3849 | ||
3850 | canon_name = tc_canonicalize_symbol_name (name); | |
3851 | ||
3852 | if (canon_name[1] == '_' | |
3853 | && strcmp (canon_name + 2, "Handler") == 0 | |
3854 | && (handler_charp = strchr (handler_chars, *canon_name)) != NULL) | |
3855 | { | |
3856 | /* If the symbol doesn't exist, provide one relative to the .text | |
3857 | section. | |
3858 | ||
3859 | FIXME: We should provide separate sections, mapped in the linker | |
3860 | script. */ | |
3861 | symp = symbol_find (name); | |
3862 | if (symp == NULL) | |
3863 | symp = symbol_new (name, text_section, | |
3864 | 0x10 * (handler_charp + 1 - handler_chars), | |
3865 | &zero_address_frag); | |
3866 | } | |
3867 | else | |
3868 | { | |
3869 | /* These symbols appear when referenced; needed for | |
3870 | mmixal-compatible programs. */ | |
3871 | unsigned int i; | |
3872 | ||
3873 | static const struct | |
3874 | { | |
3875 | const char *name; | |
3876 | valueT val; | |
3877 | } predefined_abs_syms[] = | |
3878 | { | |
3879 | {"Data_Segment", (valueT) 0x20 << 56}, | |
3880 | {"Pool_Segment", (valueT) 0x40 << 56}, | |
3881 | {"Stack_Segment", (valueT) 0x60 << 56}, | |
3882 | {"StdIn", 0}, | |
3883 | {"StdOut", 1}, | |
3884 | {"StdErr", 2}, | |
3885 | {"TextRead", 0}, | |
3886 | {"TextWrite", 1}, | |
3887 | {"BinaryRead", 2}, | |
3888 | {"BinaryWrite", 3}, | |
3889 | {"BinaryReadWrite", 4}, | |
3890 | {"Halt", 0}, | |
3891 | {"Fopen", 1}, | |
3892 | {"Fclose", 2}, | |
3893 | {"Fread", 3}, | |
3894 | {"Fgets", 4}, | |
3895 | {"Fgetws", 5}, | |
3896 | {"Fwrite", 6}, | |
3897 | {"Fputs", 7}, | |
3898 | {"Fputws", 8}, | |
3899 | {"Fseek", 9}, | |
3900 | {"Ftell", 10}, | |
3901 | {"D_BIT", 0x80}, | |
3902 | {"V_BIT", 0x40}, | |
3903 | {"W_BIT", 0x20}, | |
3904 | {"I_BIT", 0x10}, | |
3905 | {"O_BIT", 0x08}, | |
3906 | {"U_BIT", 0x04}, | |
3907 | {"Z_BIT", 0x02}, | |
3908 | {"X_BIT", 0x01}, | |
3909 | {"Inf", 0x7ff00000} | |
3910 | }; | |
3911 | ||
3912 | /* If it's already in the symbol table, we shouldn't do anything. */ | |
3913 | symp = symbol_find (name); | |
3914 | if (symp != NULL) | |
3915 | return 0; | |
3916 | ||
3917 | for (i = 0; | |
a1b6236b | 3918 | i < sizeof (predefined_abs_syms) / sizeof (predefined_abs_syms[0]); |
3c3bdf30 NC |
3919 | i++) |
3920 | if (strcmp (canon_name, predefined_abs_syms[i].name) == 0) | |
3921 | { | |
3922 | symbol_table_insert (symbol_new (predefined_abs_syms[i].name, | |
3923 | absolute_section, | |
3924 | predefined_abs_syms[i].val, | |
3925 | &zero_address_frag)); | |
3926 | ||
3927 | /* Let gas find the symbol we just created, through its | |
3928 | ordinary lookup. */ | |
3929 | return 0; | |
3930 | } | |
3931 | ||
3932 | /* Not one of those symbols. Let gas handle it. */ | |
3933 | return 0; | |
3934 | } | |
3935 | ||
3936 | expP->X_op = O_symbol; | |
3937 | expP->X_add_number = 0; | |
3938 | expP->X_add_symbol = symp; | |
3939 | expP->X_op_symbol = NULL; | |
3940 | ||
3941 | return 1; | |
3942 | } | |
3943 | ||
3c3bdf30 NC |
3944 | /* Just check that we don't have a BSPEC/ESPEC pair active when changing |
3945 | sections "normally", and get knowledge about alignment from the new | |
3946 | section. */ | |
3947 | ||
3948 | void | |
3949 | mmix_md_elf_section_change_hook () | |
3950 | { | |
3951 | if (doing_bspec) | |
3952 | as_bad (_("section change from within a BSPEC/ESPEC pair is not supported")); | |
3953 | ||
3954 | last_alignment = bfd_get_section_alignment (now_seg->owner, now_seg); | |
3955 | want_unaligned = 0; | |
3956 | } | |
3957 | ||
3958 | /* The LOC worker. This is like s_org, but we have to support changing | |
3959 | section too. */ | |
3960 | ||
3961 | static void | |
3962 | s_loc (ignore) | |
3963 | int ignore ATTRIBUTE_UNUSED; | |
3964 | { | |
3965 | segT section; | |
3966 | expressionS exp; | |
3967 | char *p; | |
3968 | symbolS *sym; | |
3969 | offsetT off; | |
3970 | ||
a1b6236b | 3971 | /* Must not have a BSPEC in progress. */ |
3c3bdf30 NC |
3972 | if (doing_bspec) |
3973 | { | |
3974 | as_bad (_("directive LOC from within a BSPEC/ESPEC pair is not supported")); | |
3975 | return; | |
3976 | } | |
3977 | ||
3978 | section = expression (&exp); | |
3979 | ||
3980 | if (exp.X_op == O_illegal | |
3981 | || exp.X_op == O_absent | |
3982 | || exp.X_op == O_big | |
3983 | || section == undefined_section) | |
3984 | { | |
3985 | as_bad (_("invalid LOC expression")); | |
3986 | return; | |
3987 | } | |
3988 | ||
3989 | if (section == absolute_section) | |
3990 | { | |
3991 | /* Translate a constant into a suitable section. */ | |
3992 | ||
3993 | if (exp.X_add_number < ((offsetT) 0x20 << 56)) | |
3994 | { | |
3995 | /* Lower than Data_Segment - assume it's .text. */ | |
3996 | section = text_section; | |
3997 | ||
3998 | /* Save the lowest seen location, so we can pass on this | |
3999 | information to the linker. We don't actually org to this | |
4000 | location here, we just pass on information to the linker so | |
4001 | it can put the code there for us. */ | |
4002 | ||
4003 | /* If there was already a loc (that has to be set lower than | |
4004 | this one), we org at (this - lower). There's an implicit | |
4005 | "LOC 0" before any entered code. FIXME: handled by spurious | |
4006 | settings of text_has_contents. */ | |
4007 | if (exp.X_add_number < 0 | |
4008 | || exp.X_add_number < (offsetT) lowest_text_loc) | |
4009 | { | |
4010 | as_bad (_("LOC expression stepping backwards is not supported")); | |
4011 | exp.X_op = O_absent; | |
4012 | } | |
4013 | else | |
4014 | { | |
4015 | if (text_has_contents && lowest_text_loc == (bfd_vma) -1) | |
4016 | lowest_text_loc = 0; | |
4017 | ||
4018 | if (lowest_text_loc == (bfd_vma) -1) | |
4019 | { | |
4020 | lowest_text_loc = exp.X_add_number; | |
4021 | ||
4022 | /* We want only to change the section, not set an offset. */ | |
4023 | exp.X_op = O_absent; | |
4024 | } | |
4025 | else | |
4026 | exp.X_add_number -= lowest_text_loc; | |
4027 | } | |
4028 | } | |
4029 | else | |
4030 | { | |
4031 | /* Do the same for the .data section. */ | |
4032 | section = data_section; | |
4033 | ||
4034 | if (exp.X_add_number < (offsetT) lowest_data_loc) | |
4035 | { | |
4036 | as_bad (_("LOC expression stepping backwards is not supported")); | |
4037 | exp.X_op = O_absent; | |
4038 | } | |
4039 | else | |
4040 | { | |
4041 | if (data_has_contents && lowest_data_loc == (bfd_vma) -1) | |
4042 | lowest_data_loc = (bfd_vma) 0x20 << 56; | |
4043 | ||
4044 | if (lowest_data_loc == (bfd_vma) -1) | |
4045 | { | |
4046 | lowest_data_loc = exp.X_add_number; | |
4047 | ||
4048 | /* We want only to change the section, not set an offset. */ | |
4049 | exp.X_op = O_absent; | |
4050 | } | |
4051 | else | |
4052 | exp.X_add_number -= lowest_data_loc; | |
4053 | } | |
4054 | } | |
4055 | } | |
4056 | ||
4057 | if (section != now_seg) | |
4058 | { | |
4059 | obj_elf_section_change_hook (); | |
4060 | subseg_set (section, 0); | |
4061 | ||
4062 | /* Call our section change hooks using the official hook. */ | |
4063 | md_elf_section_change_hook (); | |
4064 | } | |
4065 | ||
4066 | if (exp.X_op != O_absent) | |
4067 | { | |
4068 | if (exp.X_op != O_constant && exp.X_op != O_symbol) | |
4069 | { | |
4070 | /* Handle complex expressions. */ | |
4071 | sym = make_expr_symbol (&exp); | |
4072 | off = 0; | |
4073 | } | |
4074 | else | |
4075 | { | |
4076 | sym = exp.X_add_symbol; | |
4077 | off = exp.X_add_number; | |
4078 | } | |
4079 | ||
4080 | p = frag_var (rs_org, 1, 1, (relax_substateT) 0, sym, off, (char *) 0); | |
4081 | *p = 0; | |
4082 | } | |
4083 | ||
4084 | mmix_handle_rest_of_empty_line (); | |
4085 | } | |
4086 | ||
4087 | /* The BYTE worker. We have to support sequences of mixed "strings", | |
4088 | numbers and other constant "first-pass" reducible expressions separated | |
4089 | by comma. */ | |
4090 | ||
4091 | static void | |
4092 | mmix_byte () | |
4093 | { | |
4094 | unsigned int c; | |
4095 | char *start; | |
4096 | ||
4097 | if (now_seg == text_section) | |
4098 | text_has_contents = 1; | |
4099 | else if (now_seg == data_section) | |
4100 | data_has_contents = 1; | |
4101 | ||
4102 | do | |
4103 | { | |
4104 | SKIP_WHITESPACE (); | |
4105 | switch (*input_line_pointer) | |
4106 | { | |
4107 | case '\"': | |
4108 | ++input_line_pointer; | |
4109 | start = input_line_pointer; | |
4110 | while (is_a_char (c = next_char_of_string ())) | |
4111 | { | |
4112 | FRAG_APPEND_1_CHAR (c); | |
4113 | } | |
4114 | ||
4115 | if (input_line_pointer[-1] != '\"') | |
4116 | { | |
4117 | /* We will only get here in rare cases involving #NO_APP, | |
4118 | where the unterminated string is not recognized by the | |
4119 | preformatting pass. */ | |
4120 | as_bad (_("unterminated string")); | |
4121 | mmix_discard_rest_of_line (); | |
4122 | return; | |
4123 | } | |
4124 | break; | |
4125 | ||
4126 | default: | |
4127 | { | |
4128 | expressionS exp; | |
4129 | segT expseg = expression (&exp); | |
4130 | ||
4131 | /* We have to allow special register names as constant numbers. */ | |
4132 | if ((expseg != absolute_section && expseg != reg_section) | |
4133 | || (exp.X_op != O_constant | |
4134 | && (exp.X_op != O_register | |
4135 | || exp.X_add_number <= 255))) | |
4136 | { | |
4137 | as_bad (_("BYTE expression not a pure number")); | |
4138 | mmix_discard_rest_of_line (); | |
4139 | return; | |
4140 | } | |
4141 | else if ((exp.X_add_number > 255 && exp.X_op != O_register) | |
4142 | || exp.X_add_number < 0) | |
4143 | { | |
4144 | /* Note that mmixal does not allow negative numbers in | |
4145 | BYTE sequences, so neither should we. */ | |
4146 | as_bad (_("BYTE expression not in the range 0..255")); | |
4147 | mmix_discard_rest_of_line (); | |
4148 | return; | |
4149 | } | |
4150 | ||
4151 | FRAG_APPEND_1_CHAR (exp.X_add_number); | |
4152 | } | |
4153 | break; | |
4154 | } | |
4155 | ||
4156 | SKIP_WHITESPACE (); | |
4157 | c = *input_line_pointer++; | |
4158 | } | |
4159 | while (c == ','); | |
4160 | ||
4161 | input_line_pointer--; | |
4162 | ||
4163 | if (mmix_gnu_syntax) | |
4164 | demand_empty_rest_of_line (); | |
4165 | else | |
4166 | { | |
4167 | mmix_discard_rest_of_line (); | |
4168 | /* Do like demand_empty_rest_of_line and step over the end-of-line | |
4169 | boundary. */ | |
4170 | input_line_pointer++; | |
4171 | } | |
4172 | ||
4173 | /* Make sure we align for the next instruction. */ | |
4174 | last_alignment = 0; | |
4175 | } | |
4176 | ||
4177 | /* Like cons_worker, but we have to ignore "naked comments", not barf on | |
4178 | them. Implements WYDE, TETRA and OCTA. We're a little bit more | |
4179 | lenient than mmix_byte but FIXME: they should eventually merge. */ | |
4180 | ||
4181 | static void | |
4182 | mmix_cons (nbytes) | |
4183 | int nbytes; | |
4184 | { | |
4185 | expressionS exp; | |
4186 | char *start; | |
4187 | ||
4188 | /* If we don't have any contents, then it's ok to have a specified start | |
4189 | address that is not a multiple of the max data size. We will then | |
4190 | align it as necessary when we get here. Otherwise, it's a fatal sin. */ | |
4191 | if (now_seg == text_section) | |
4192 | { | |
4193 | if (lowest_text_loc != (bfd_vma) -1 | |
4194 | && (lowest_text_loc & (nbytes - 1)) != 0) | |
4195 | { | |
4196 | if (text_has_contents) | |
4197 | as_bad (_("data item with alignment larger than location")); | |
4198 | else if (want_unaligned) | |
4199 | as_bad (_("unaligned data at an absolute location is not supported")); | |
4200 | ||
4201 | lowest_text_loc &= ~((bfd_vma) nbytes - 1); | |
4202 | lowest_text_loc += (bfd_vma) nbytes; | |
4203 | } | |
4204 | ||
4205 | text_has_contents = 1; | |
4206 | } | |
4207 | else if (now_seg == data_section) | |
4208 | { | |
4209 | if (lowest_data_loc != (bfd_vma) -1 | |
4210 | && (lowest_data_loc & (nbytes - 1)) != 0) | |
4211 | { | |
4212 | if (data_has_contents) | |
4213 | as_bad (_("data item with alignment larger than location")); | |
4214 | else if (want_unaligned) | |
4215 | as_bad (_("unaligned data at an absolute location is not supported")); | |
4216 | ||
4217 | lowest_data_loc &= ~((bfd_vma) nbytes - 1); | |
4218 | lowest_data_loc += (bfd_vma) nbytes; | |
4219 | } | |
4220 | ||
4221 | data_has_contents = 1; | |
4222 | } | |
4223 | ||
4224 | /* Always align these unless asked not to (valid for the current pseudo). */ | |
4225 | if (! want_unaligned) | |
4226 | { | |
4227 | last_alignment = nbytes == 2 ? 1 : (nbytes == 4 ? 2 : 3); | |
4228 | frag_align (last_alignment, 0, 0); | |
4229 | record_alignment (now_seg, last_alignment); | |
4230 | } | |
4231 | ||
4232 | /* For mmixal compatibility, a label for an instruction (and emitting | |
4233 | pseudo) refers to the _aligned_ address. So we have to emit the | |
4234 | label here. */ | |
4235 | if (current_fb_label >= 0) | |
4236 | colon (fb_label_name (current_fb_label, 1)); | |
4237 | else if (pending_label != NULL) | |
4238 | { | |
4239 | colon (pending_label); | |
4240 | pending_label = NULL; | |
4241 | } | |
4242 | ||
4243 | SKIP_WHITESPACE (); | |
4244 | ||
a1b6236b | 4245 | if (is_end_of_line[(unsigned int) *input_line_pointer]) |
3c3bdf30 NC |
4246 | { |
4247 | /* Default to zero if the expression was absent. */ | |
4248 | ||
4249 | exp.X_op = O_constant; | |
4250 | exp.X_add_number = 0; | |
4251 | exp.X_unsigned = 0; | |
4252 | exp.X_add_symbol = NULL; | |
4253 | exp.X_op_symbol = NULL; | |
4254 | emit_expr (&exp, (unsigned int) nbytes); | |
4255 | } | |
4256 | else | |
4257 | do | |
4258 | { | |
4259 | unsigned int c; | |
4260 | ||
4261 | switch (*input_line_pointer) | |
4262 | { | |
4263 | /* We support strings here too; each character takes up nbytes | |
4264 | bytes. */ | |
4265 | case '\"': | |
4266 | ++input_line_pointer; | |
4267 | start = input_line_pointer; | |
4268 | while (is_a_char (c = next_char_of_string ())) | |
4269 | { | |
4270 | exp.X_op = O_constant; | |
4271 | exp.X_add_number = c; | |
4272 | exp.X_unsigned = 1; | |
4273 | emit_expr (&exp, (unsigned int) nbytes); | |
4274 | } | |
4275 | ||
4276 | if (input_line_pointer[-1] != '\"') | |
4277 | { | |
4278 | /* We will only get here in rare cases involving #NO_APP, | |
4279 | where the unterminated string is not recognized by the | |
4280 | preformatting pass. */ | |
4281 | as_bad (_("unterminated string")); | |
4282 | mmix_discard_rest_of_line (); | |
4283 | return; | |
4284 | } | |
4285 | break; | |
4286 | ||
4287 | default: | |
4288 | { | |
4289 | expression (&exp); | |
4290 | emit_expr (&exp, (unsigned int) nbytes); | |
4291 | SKIP_WHITESPACE (); | |
4292 | } | |
4293 | break; | |
4294 | } | |
4295 | } | |
4296 | while (*input_line_pointer++ == ','); | |
4297 | ||
4298 | input_line_pointer--; /* Put terminator back into stream. */ | |
4299 | ||
4300 | mmix_handle_rest_of_empty_line (); | |
4301 | ||
4302 | /* We don't need to step up the counter for the current_fb_label here; | |
4303 | that's handled by the caller. */ | |
4304 | } | |
4305 | ||
4306 | /* The md_do_align worker. At present, we just record an alignment to | |
4307 | nullify the automatic alignment we do for WYDE, TETRA and OCTA, as gcc | |
4308 | does not use the unaligned macros when attribute packed is used. | |
4309 | Arguably this is a GCC bug. */ | |
4310 | ||
4311 | void | |
4312 | mmix_md_do_align (n, fill, len, max) | |
4313 | int n; | |
4314 | char *fill ATTRIBUTE_UNUSED; | |
4315 | int len ATTRIBUTE_UNUSED; | |
4316 | int max ATTRIBUTE_UNUSED; | |
4317 | { | |
4318 | last_alignment = n; | |
4319 | want_unaligned = n == 0; | |
4320 | } |