1 /* tc-mmix.c -- Assembler for Don Knuth's MMIX.
2 Copyright (C) 2001-2014 Free Software Foundation, Inc.
4 This file is part of GAS, the GNU Assembler.
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 3, or (at your option)
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.
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, 51 Franklin Street - Fifth Floor,
19 Boston, MA 02110-1301, USA. */
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.
25 One goal is to provide a superset of what mmixal does, including
26 compatible syntax, but the main purpose is to serve GCC. */
33 #include "opcode/mmix.h"
34 #include "safe-ctype.h"
35 #include "dwarf2dbg.h"
38 /* Something to describe what we need to do with a fixup before output,
39 for example assert something of what it became or make a relocation. */
41 enum mmix_fixup_action
45 mmix_fixup_register_or_adjust_for_byte
48 static int get_spec_regno (char *);
49 static int get_operands (int, char *, expressionS *);
50 static int get_putget_operands (struct mmix_opcode *, char *, expressionS *);
51 static void s_prefix (int);
52 static void s_greg (int);
53 static void s_loc (int);
54 static void s_bspec (int);
55 static void s_espec (int);
56 static void mmix_s_local (int);
57 static void mmix_greg_internal (char *);
58 static void mmix_set_geta_branch_offset (char *, offsetT);
59 static void mmix_set_jmp_offset (char *, offsetT);
60 static void mmix_fill_nops (char *, int);
61 static int cmp_greg_symbol_fixes (const void *, const void *);
62 static int cmp_greg_val_greg_symbol_fixes (const void *, const void *);
63 static void mmix_handle_rest_of_empty_line (void);
64 static void mmix_discard_rest_of_line (void);
65 static void mmix_byte (void);
66 static void mmix_cons (int);
68 /* Continue the tradition of symbols.c; use control characters to enforce
69 magic. These are used when replacing e.g. 8F and 8B so we can handle
70 such labels correctly with the common parser hooks. */
71 #define MAGIC_FB_BACKWARD_CHAR '\003'
72 #define MAGIC_FB_FORWARD_CHAR '\004'
74 /* Copy the location of a frag to a fix. */
75 #define COPY_FR_WHERE_TO_FX(FRAG, FIX) \
78 (FIX)->fx_file = (FRAG)->fr_file; \
79 (FIX)->fx_line = (FRAG)->fr_line; \
83 const char *md_shortopts = "x";
84 static int current_fb_label = -1;
85 static char *pending_label = NULL;
87 static bfd_vma lowest_text_loc = (bfd_vma) -1;
88 static int text_has_contents = 0;
90 /* The alignment of the previous instruction, and a boolean for whether we
91 want to avoid aligning the next WYDE, TETRA, OCTA or insn. */
92 static int last_alignment = 0;
93 static int want_unaligned = 0;
95 static bfd_vma lowest_data_loc = (bfd_vma) -1;
96 static int data_has_contents = 0;
98 /* The fragS of the instruction being assembled. Only valid from within
100 fragS *mmix_opcode_frag = NULL;
102 /* Raw GREGs as appearing in input. These may be fewer than the number
104 static int n_of_raw_gregs = 0;
109 } mmix_raw_gregs[MAX_GREGS];
111 static struct loc_assert_s
115 struct loc_assert_s *next;
116 } *loc_asserts = NULL;
118 /* Fixups for all unique GREG registers. We store the fixups here in
119 md_convert_frag, then we use the array to convert
120 BFD_RELOC_MMIX_BASE_PLUS_OFFSET fixups in tc_gen_reloc. The index is
121 just a running number and is not supposed to be correlated to a
123 static fixS *mmix_gregs[MAX_GREGS];
124 static int n_of_cooked_gregs = 0;
126 /* Pointing to the register section we use for output. */
127 static asection *real_reg_section;
129 /* For each symbol; unknown or section symbol, we keep a list of GREG
130 definitions sorted on increasing offset. It seems no use keeping count
131 to allocate less room than the maximum number of gregs when we've found
132 one for a section or symbol. */
133 struct mmix_symbol_gregs
136 struct mmix_symbol_greg_fixes
140 /* A signed type, since we may have GREGs pointing slightly before the
141 contents of a section. */
143 } greg_fixes[MAX_GREGS];
146 /* Should read insert a colon on something that starts in column 0 on
148 static int label_without_colon_this_line = 1;
150 /* Should we automatically expand instructions into multiple insns in
151 order to generate working code? */
152 static int expand_op = 1;
154 /* Should we warn when expanding operands? FIXME: test-cases for when -x
156 static int warn_on_expansion = 1;
158 /* Should we merge non-zero GREG register definitions? */
159 static int merge_gregs = 1;
161 /* Should we pass on undefined BFD_RELOC_MMIX_BASE_PLUS_OFFSET relocs
162 (missing suitable GREG definitions) to the linker? */
163 static int allocate_undefined_gregs_in_linker = 0;
165 /* Should we emit built-in symbols? */
166 static int predefined_syms = 1;
168 /* Should we allow anything but the listed special register name
169 (e.g. equated symbols)? */
170 static int equated_spec_regs = 1;
172 /* Do we require standard GNU syntax? */
173 int mmix_gnu_syntax = 0;
175 /* Do we globalize all symbols? */
176 int mmix_globalize_symbols = 0;
178 /* When expanding insns, do we want to expand PUSHJ as a call to a stub
179 (or else as a series of insns)? */
182 /* Do we know that the next semicolon is at the end of the operands field
183 (in mmixal mode; constant 1 in GNU mode)? */
184 int mmix_next_semicolon_is_eoln = 1;
186 /* Do we have a BSPEC in progress? */
187 static int doing_bspec = 0;
188 static char *bspec_file;
189 static unsigned int bspec_line;
191 struct option md_longopts[] =
193 #define OPTION_RELAX (OPTION_MD_BASE)
194 #define OPTION_NOEXPAND (OPTION_RELAX + 1)
195 #define OPTION_NOMERGEGREG (OPTION_NOEXPAND + 1)
196 #define OPTION_NOSYMS (OPTION_NOMERGEGREG + 1)
197 #define OPTION_GNU_SYNTAX (OPTION_NOSYMS + 1)
198 #define OPTION_GLOBALIZE_SYMBOLS (OPTION_GNU_SYNTAX + 1)
199 #define OPTION_FIXED_SPEC_REGS (OPTION_GLOBALIZE_SYMBOLS + 1)
200 #define OPTION_LINKER_ALLOCATED_GREGS (OPTION_FIXED_SPEC_REGS + 1)
201 #define OPTION_NOPUSHJSTUBS (OPTION_LINKER_ALLOCATED_GREGS + 1)
202 {"linkrelax", no_argument, NULL, OPTION_RELAX},
203 {"no-expand", no_argument, NULL, OPTION_NOEXPAND},
204 {"no-merge-gregs", no_argument, NULL, OPTION_NOMERGEGREG},
205 {"no-predefined-syms", no_argument, NULL, OPTION_NOSYMS},
206 {"gnu-syntax", no_argument, NULL, OPTION_GNU_SYNTAX},
207 {"globalize-symbols", no_argument, NULL, OPTION_GLOBALIZE_SYMBOLS},
208 {"fixed-special-register-names", no_argument, NULL,
209 OPTION_FIXED_SPEC_REGS},
210 {"linker-allocated-gregs", no_argument, NULL,
211 OPTION_LINKER_ALLOCATED_GREGS},
212 {"no-pushj-stubs", no_argument, NULL, OPTION_NOPUSHJSTUBS},
213 {"no-stubs", no_argument, NULL, OPTION_NOPUSHJSTUBS},
214 {NULL, no_argument, NULL, 0}
217 size_t md_longopts_size = sizeof (md_longopts);
219 static struct hash_control *mmix_opcode_hash;
221 /* We use these when implementing the PREFIX pseudo. */
222 char *mmix_current_prefix;
223 struct obstack mmix_sym_obstack;
226 /* For MMIX, we encode the relax_substateT:s (in e.g. fr_substate) as one
227 bit length, and the relax-type shifted on top of that. There seems to
228 be no point in making the relaxation more fine-grained; the linker does
229 that better and we might interfere by changing non-optimal relaxations
230 into other insns that cannot be relaxed as easily.
232 Groups for MMIX relaxing:
235 extra length: zero or three insns.
238 extra length: zero or five insns.
241 extra length: zero or four insns.
242 Special handling to deal with transition to PUSHJSTUB.
245 extra length: zero or four insns.
248 special handling, allocates a named global register unless another
249 is within reach for all uses.
252 special handling (mostly) for external references; assumes the
253 linker will generate a stub if target is no longer than 256k from
254 the end of the section plus max size of previous stubs. Zero or
257 #define STATE_GETA (1)
258 #define STATE_BCC (2)
259 #define STATE_PUSHJ (3)
260 #define STATE_JMP (4)
261 #define STATE_GREG (5)
262 #define STATE_PUSHJSTUB (6)
264 /* No fine-grainedness here. */
265 #define STATE_LENGTH_MASK (1)
267 #define STATE_ZERO (0)
268 #define STATE_MAX (1)
270 /* More descriptive name for convenience. */
271 /* FIXME: We should start on something different, not MAX. */
272 #define STATE_UNDF STATE_MAX
274 /* FIXME: For GREG, we must have other definitions; UNDF == MAX isn't
275 appropriate; we need it the other way round. This value together with
276 fragP->tc_frag_data shows what state the frag is in: tc_frag_data
277 non-NULL means 0, NULL means 8 bytes. */
278 #define STATE_GREG_UNDF ENCODE_RELAX (STATE_GREG, STATE_ZERO)
279 #define STATE_GREG_DEF ENCODE_RELAX (STATE_GREG, STATE_MAX)
281 /* These displacements are relative to the address following the opcode
282 word of the instruction. The catch-all states have zero for "reach"
283 and "next" entries. */
285 #define GETA_0F (65536 * 4 - 8)
286 #define GETA_0B (-65536 * 4 - 4)
288 #define GETA_MAX_LEN 4 * 4
292 #define BCC_0F GETA_0F
293 #define BCC_0B GETA_0B
295 #define BCC_MAX_LEN 6 * 4
296 #define BCC_5F GETA_3F
297 #define BCC_5B GETA_3B
299 #define PUSHJ_0F GETA_0F
300 #define PUSHJ_0B GETA_0B
302 #define PUSHJ_MAX_LEN 5 * 4
303 #define PUSHJ_4F GETA_3F
304 #define PUSHJ_4B GETA_3B
306 /* We'll very rarely have sections longer than LONG_MAX, but we'll make a
307 feeble attempt at getting 64-bit values. */
308 #define PUSHJSTUB_MAX ((offsetT) (((addressT) -1) >> 1))
309 #define PUSHJSTUB_MIN (-PUSHJSTUB_MAX - 1)
311 #define JMP_0F (65536 * 256 * 4 - 8)
312 #define JMP_0B (-65536 * 256 * 4 - 4)
314 #define JMP_MAX_LEN 5 * 4
318 #define RELAX_ENCODE_SHIFT 1
319 #define ENCODE_RELAX(what, length) (((what) << RELAX_ENCODE_SHIFT) + (length))
321 const relax_typeS mmix_relax_table[] =
323 /* Error sentinel (0, 0). */
330 {GETA_0F, GETA_0B, 0, ENCODE_RELAX (STATE_GETA, STATE_MAX)},
334 GETA_MAX_LEN - 4, 0},
337 {BCC_0F, BCC_0B, 0, ENCODE_RELAX (STATE_BCC, STATE_MAX)},
343 /* PUSHJ (3, 0). Next state is actually PUSHJSTUB (6, 0). */
344 {PUSHJ_0F, PUSHJ_0B, 0, ENCODE_RELAX (STATE_PUSHJSTUB, STATE_ZERO)},
348 PUSHJ_MAX_LEN - 4, 0},
351 {JMP_0F, JMP_0B, 0, ENCODE_RELAX (STATE_JMP, STATE_MAX)},
357 /* GREG (5, 0), (5, 1), though the table entry isn't used. */
358 {0, 0, 0, 0}, {0, 0, 0, 0},
360 /* PUSHJSTUB (6, 0). PUSHJ (3, 0) uses the range, so we set it to infinite. */
361 {PUSHJSTUB_MAX, PUSHJSTUB_MIN,
362 0, ENCODE_RELAX (STATE_PUSHJ, STATE_MAX)},
363 /* PUSHJSTUB (6, 1) isn't used. */
364 {0, 0, PUSHJ_MAX_LEN, 0}
367 const pseudo_typeS md_pseudo_table[] =
369 /* Support " .greg sym,expr" syntax. */
372 /* Support " .bspec expr" syntax. */
373 {"bspec", s_bspec, 1},
375 /* Support " .espec" syntax. */
376 {"espec", s_espec, 1},
378 /* Support " .local $45" syntax. */
379 {"local", mmix_s_local, 1},
384 const char mmix_comment_chars[] = "%!";
386 /* A ':' is a valid symbol character in mmixal. It's the prefix
387 delimiter, but other than that, it works like a symbol character,
388 except that we strip one off at the beginning of symbols. An '@' is a
389 symbol by itself (for the current location); space around it must not
391 const char mmix_symbol_chars[] = ":@";
393 const char line_comment_chars[] = "*#";
395 const char line_separator_chars[] = ";";
397 const char mmix_exp_chars[] = "eE";
399 const char mmix_flt_chars[] = "rf";
402 /* Fill in the offset-related part of GETA or Bcc. */
405 mmix_set_geta_branch_offset (char *opcodep, offsetT value)
414 md_number_to_chars (opcodep + 2, value, 2);
417 /* Fill in the offset-related part of JMP. */
420 mmix_set_jmp_offset (char *opcodep, offsetT value)
424 value += 65536 * 256 * 4;
429 md_number_to_chars (opcodep + 1, value, 3);
432 /* Fill in NOP:s for the expanded part of GETA/JMP/Bcc/PUSHJ. */
435 mmix_fill_nops (char *opcodep, int n)
439 for (i = 0; i < n; i++)
440 md_number_to_chars (opcodep + i * 4, SWYM_INSN_BYTE << 24, 4);
443 /* See macro md_parse_name in tc-mmix.h. */
446 mmix_current_location (void (*fn) (expressionS *), expressionS *exp)
453 /* Get up to three operands, filling them into the exp array.
454 General idea and code stolen from the tic80 port. */
457 get_operands (int max_operands, char *s, expressionS *exp)
463 while (nextchar == ',')
465 /* Skip leading whitespace */
466 while (*p == ' ' || *p == '\t')
469 /* Check to see if we have any operands left to parse */
470 if (*p == 0 || *p == '\n' || *p == '\r')
474 else if (numexp == max_operands)
476 /* This seems more sane than saying "too many operands". We'll
477 get here only if the trailing trash starts with a comma. */
478 as_bad (_("invalid operands"));
479 mmix_discard_rest_of_line ();
483 /* Begin operand parsing at the current scan point. */
485 input_line_pointer = p;
486 expression (&exp[numexp]);
488 if (exp[numexp].X_op == O_illegal)
490 as_bad (_("invalid operands"));
492 else if (exp[numexp].X_op == O_absent)
494 as_bad (_("missing operand"));
498 p = input_line_pointer;
500 /* Skip leading whitespace */
501 while (*p == ' ' || *p == '\t')
506 /* If we allow "naked" comments, ignore the rest of the line. */
509 mmix_handle_rest_of_empty_line ();
510 input_line_pointer--;
513 /* Mark the end of the valid operands with an illegal expression. */
514 exp[numexp].X_op = O_illegal;
519 /* Get the value of a special register, or -1 if the name does not match
520 one. NAME is a null-terminated string. */
523 get_spec_regno (char *name)
533 /* Well, it's a short array and we'll most often just match the first
535 for (i = 0; mmix_spec_regs[i].name != NULL; i++)
536 if (strcmp (name, mmix_spec_regs[i].name) == 0)
537 return mmix_spec_regs[i].number;
542 /* For GET and PUT, parse the register names "manually", so we don't use
545 get_putget_operands (struct mmix_opcode *insn, char *operands,
548 expressionS *expp_reg;
549 expressionS *expp_sreg;
551 char *sregend = operands;
556 /* Skip leading whitespace */
557 while (*p == ' ' || *p == '\t')
560 input_line_pointer = p;
562 /* Initialize both possible operands to error state, in case we never
564 exp[0].X_op = O_illegal;
565 exp[1].X_op = O_illegal;
567 if (insn->operands == mmix_operands_get)
572 expression (expp_reg);
574 p = input_line_pointer;
576 /* Skip whitespace */
577 while (*p == ' ' || *p == '\t')
584 /* Skip whitespace */
585 while (*p == ' ' || *p == '\t')
588 input_line_pointer = sregp;
589 c = get_symbol_end ();
590 sregend = input_line_pointer;
599 c = get_symbol_end ();
600 sregend = p = input_line_pointer;
603 /* Skip whitespace */
604 while (*p == ' ' || *p == '\t')
611 /* Skip whitespace */
612 while (*p == ' ' || *p == '\t')
615 input_line_pointer = p;
616 expression (expp_reg);
621 regno = get_spec_regno (sregp);
624 /* Let the caller issue errors; we've made sure the operands are
626 if (expp_reg->X_op != O_illegal
627 && expp_reg->X_op != O_absent
630 expp_sreg->X_op = O_register;
631 expp_sreg->X_add_number = regno + 256;
637 /* Handle MMIX-specific option. */
640 md_parse_option (int c, char *arg ATTRIBUTE_UNUSED)
645 warn_on_expansion = 0;
646 allocate_undefined_gregs_in_linker = 1;
653 case OPTION_NOEXPAND:
657 case OPTION_NOMERGEGREG:
663 equated_spec_regs = 0;
666 case OPTION_GNU_SYNTAX:
668 label_without_colon_this_line = 0;
671 case OPTION_GLOBALIZE_SYMBOLS:
672 mmix_globalize_symbols = 1;
675 case OPTION_FIXED_SPEC_REGS:
676 equated_spec_regs = 0;
679 case OPTION_LINKER_ALLOCATED_GREGS:
680 allocate_undefined_gregs_in_linker = 1;
683 case OPTION_NOPUSHJSTUBS:
694 /* Display MMIX-specific help text. */
697 md_show_usage (FILE * stream)
699 fprintf (stream, _(" MMIX-specific command line options:\n"));
700 fprintf (stream, _("\
701 -fixed-special-register-names\n\
702 Allow only the original special register names.\n"));
703 fprintf (stream, _("\
704 -globalize-symbols Make all symbols global.\n"));
705 fprintf (stream, _("\
706 -gnu-syntax Turn off mmixal syntax compatibility.\n"));
707 fprintf (stream, _("\
708 -relax Create linker relaxable code.\n"));
709 fprintf (stream, _("\
710 -no-predefined-syms Do not provide mmixal built-in constants.\n\
711 Implies -fixed-special-register-names.\n"));
712 fprintf (stream, _("\
713 -no-expand Do not expand GETA, branches, PUSHJ or JUMP\n\
714 into multiple instructions.\n"));
715 fprintf (stream, _("\
716 -no-merge-gregs Do not merge GREG definitions with nearby values.\n"));
717 fprintf (stream, _("\
718 -linker-allocated-gregs If there's no suitable GREG definition for the\
719 operands of an instruction, let the linker resolve.\n"));
720 fprintf (stream, _("\
721 -x Do not warn when an operand to GETA, a branch,\n\
722 PUSHJ or JUMP is not known to be within range.\n\
723 The linker will catch any errors. Implies\n\
724 -linker-allocated-gregs."));
727 /* Step to end of line, but don't step over the end of the line. */
730 mmix_discard_rest_of_line (void)
732 while (*input_line_pointer
733 && (! is_end_of_line[(unsigned char) *input_line_pointer]
734 || TC_EOL_IN_INSN (input_line_pointer)))
735 input_line_pointer++;
738 /* Act as demand_empty_rest_of_line if we're in strict GNU syntax mode,
739 otherwise just ignore the rest of the line (and skip the end-of-line
743 mmix_handle_rest_of_empty_line (void)
746 demand_empty_rest_of_line ();
749 mmix_discard_rest_of_line ();
750 input_line_pointer++;
754 /* Initialize GAS MMIX specifics. */
760 const struct mmix_opcode *opcode;
762 /* We assume nobody will use this, so don't allocate any room. */
763 obstack_begin (&mmix_sym_obstack, 0);
765 /* This will break the day the "lex" thingy changes. For now, it's the
766 only way to make ':' part of a name, and a name beginner. */
767 lex_type[':'] = (LEX_NAME | LEX_BEGIN_NAME);
769 mmix_opcode_hash = hash_new ();
772 = bfd_make_section_old_way (stdoutput, MMIX_REG_SECTION_NAME);
774 for (opcode = mmix_opcodes; opcode->name; opcode++)
775 hash_insert (mmix_opcode_hash, opcode->name, (char *) opcode);
777 /* We always insert the ordinary registers 0..255 as registers. */
778 for (i = 0; i < 256; i++)
782 /* Alternatively, we could diddle with '$' and the following number,
783 but keeping the registers as symbols helps keep parsing simple. */
784 sprintf (buf, "$%d", i);
785 symbol_table_insert (symbol_new (buf, reg_section, i,
786 &zero_address_frag));
789 /* Insert mmixal built-in names if allowed. */
792 for (i = 0; mmix_spec_regs[i].name != NULL; i++)
793 symbol_table_insert (symbol_new (mmix_spec_regs[i].name,
795 mmix_spec_regs[i].number + 256,
796 &zero_address_frag));
798 /* FIXME: Perhaps these should be recognized as specials; as field
799 names for those instructions. */
800 symbol_table_insert (symbol_new ("ROUND_CURRENT", reg_section, 512,
801 &zero_address_frag));
802 symbol_table_insert (symbol_new ("ROUND_OFF", reg_section, 512 + 1,
803 &zero_address_frag));
804 symbol_table_insert (symbol_new ("ROUND_UP", reg_section, 512 + 2,
805 &zero_address_frag));
806 symbol_table_insert (symbol_new ("ROUND_DOWN", reg_section, 512 + 3,
807 &zero_address_frag));
808 symbol_table_insert (symbol_new ("ROUND_NEAR", reg_section, 512 + 4,
809 &zero_address_frag));
813 /* Assemble one insn in STR. */
816 md_assemble (char *str)
818 char *operands = str;
819 char modified_char = 0;
820 struct mmix_opcode *instruction;
821 fragS *opc_fragP = NULL;
822 int max_operands = 3;
824 /* Note that the struct frag member fr_literal in frags.h is char[], so
825 I have to make this a plain char *. */
826 /* unsigned */ char *opcodep = NULL;
831 /* Move to end of opcode. */
833 is_part_of_name (*operands);
837 if (ISSPACE (*operands))
839 modified_char = *operands;
843 instruction = (struct mmix_opcode *) hash_find (mmix_opcode_hash, str);
844 if (instruction == NULL)
846 as_bad (_("unknown opcode: `%s'"), str);
848 /* Avoid "unhandled label" errors. */
849 pending_label = NULL;
853 /* Put back the character after the opcode. */
854 if (modified_char != 0)
855 operands[-1] = modified_char;
857 input_line_pointer = operands;
859 /* Is this a mmixal pseudodirective? */
860 if (instruction->type == mmix_type_pseudo)
862 /* For mmixal compatibility, a label for an instruction (and
863 emitting pseudo) refers to the _aligned_ address. We emit the
864 label here for the pseudos that don't handle it themselves. When
865 having an fb-label, emit it here, and increment the counter after
867 switch (instruction->operands)
869 case mmix_operands_loc:
870 case mmix_operands_byte:
871 case mmix_operands_prefix:
872 case mmix_operands_local:
873 case mmix_operands_bspec:
874 case mmix_operands_espec:
875 if (current_fb_label >= 0)
876 colon (fb_label_name (current_fb_label, 1));
877 else if (pending_label != NULL)
879 colon (pending_label);
880 pending_label = NULL;
888 /* Some of the pseudos emit contents, others don't. Set a
889 contents-emitted flag when we emit something into .text */
890 switch (instruction->operands)
892 case mmix_operands_loc:
897 case mmix_operands_byte:
902 case mmix_operands_wyde:
907 case mmix_operands_tetra:
912 case mmix_operands_octa:
917 case mmix_operands_prefix:
922 case mmix_operands_local:
927 case mmix_operands_bspec:
932 case mmix_operands_espec:
938 BAD_CASE (instruction->operands);
941 /* These are all working like the pseudo functions in read.c:s_...,
942 in that they step over the end-of-line marker at the end of the
943 line. We don't want that here. */
944 input_line_pointer--;
946 /* Step up the fb-label counter if there was a definition on this
948 if (current_fb_label >= 0)
950 fb_label_instance_inc (current_fb_label);
951 current_fb_label = -1;
954 /* Reset any don't-align-next-datum request, unless this was a LOC
956 if (instruction->operands != mmix_operands_loc)
962 /* Not a pseudo; we *will* emit contents. */
963 if (now_seg == data_section)
965 if (lowest_data_loc != (bfd_vma) -1 && (lowest_data_loc & 3) != 0)
967 if (data_has_contents)
968 as_bad (_("specified location wasn't TETRA-aligned"));
969 else if (want_unaligned)
970 as_bad (_("unaligned data at an absolute location is not supported"));
972 lowest_data_loc &= ~(bfd_vma) 3;
973 lowest_data_loc += 4;
976 data_has_contents = 1;
978 else if (now_seg == text_section)
980 if (lowest_text_loc != (bfd_vma) -1 && (lowest_text_loc & 3) != 0)
982 if (text_has_contents)
983 as_bad (_("specified location wasn't TETRA-aligned"));
984 else if (want_unaligned)
985 as_bad (_("unaligned data at an absolute location is not supported"));
987 lowest_text_loc &= ~(bfd_vma) 3;
988 lowest_text_loc += 4;
991 text_has_contents = 1;
994 /* After a sequence of BYTEs or WYDEs, we need to get to instruction
995 alignment. For other pseudos, a ".p2align 2" is supposed to be
996 inserted by the user. */
997 if (last_alignment < 2 && ! want_unaligned)
999 frag_align (2, 0, 0);
1000 record_alignment (now_seg, 2);
1004 /* Reset any don't-align-next-datum request. */
1007 /* For mmixal compatibility, a label for an instruction (and emitting
1008 pseudo) refers to the _aligned_ address. So we have to emit the
1010 if (pending_label != NULL)
1012 colon (pending_label);
1013 pending_label = NULL;
1016 /* We assume that mmix_opcodes keeps having unique mnemonics for each
1017 opcode, so we don't have to iterate over more than one opcode; if the
1018 syntax does not match, then there's a syntax error. */
1020 /* Operands have little or no context and are all comma-separated; it is
1021 easier to parse each expression first. */
1022 switch (instruction->operands)
1024 case mmix_operands_reg_yz:
1025 case mmix_operands_pop:
1026 case mmix_operands_regaddr:
1027 case mmix_operands_pushj:
1028 case mmix_operands_get:
1029 case mmix_operands_put:
1030 case mmix_operands_set:
1031 case mmix_operands_save:
1032 case mmix_operands_unsave:
1036 case mmix_operands_sync:
1037 case mmix_operands_jmp:
1038 case mmix_operands_resume:
1042 /* The original 3 is fine for the rest. */
1047 /* If this is GET or PUT, and we don't do allow those names to be
1048 equated, we need to parse the names ourselves, so we don't pick up a
1049 user label instead of the special register. */
1050 if (! equated_spec_regs
1051 && (instruction->operands == mmix_operands_get
1052 || instruction->operands == mmix_operands_put))
1053 n_operands = get_putget_operands (instruction, operands, exp);
1055 n_operands = get_operands (max_operands, operands, exp);
1057 /* If there's a fb-label on the current line, set that label. This must
1058 be done *after* evaluating expressions of operands, since neither a
1059 "1B" nor a "1F" refers to "1H" on the same line. */
1060 if (current_fb_label >= 0)
1062 fb_label_instance_inc (current_fb_label);
1063 colon (fb_label_name (current_fb_label, 0));
1064 current_fb_label = -1;
1067 /* We also assume that the length of the instruction is at least 4, the
1068 size of an unexpanded instruction. We need a self-contained frag
1069 since we want the relocation to point to the instruction, not the
1072 opcodep = frag_more (4);
1073 mmix_opcode_frag = opc_fragP = frag_now;
1074 frag_now->fr_opcode = opcodep;
1076 /* Mark start of insn for DWARF2 debug features. */
1077 if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
1078 dwarf2_emit_insn (4);
1080 md_number_to_chars (opcodep, instruction->match, 4);
1082 switch (instruction->operands)
1084 case mmix_operands_jmp:
1085 if (n_operands == 0 && ! mmix_gnu_syntax)
1086 /* Zeros are in place - nothing needs to be done when we have no
1090 /* Add a frag for a JMP relaxation; we need room for max four
1091 extra instructions. We don't do any work around here to check if
1092 we can determine the offset right away. */
1093 if (n_operands != 1 || exp[0].X_op == O_register)
1095 as_bad (_("invalid operand to opcode %s: `%s'"),
1096 instruction->name, operands);
1101 frag_var (rs_machine_dependent, 4 * 4, 0,
1102 ENCODE_RELAX (STATE_JMP, STATE_UNDF),
1103 exp[0].X_add_symbol,
1104 exp[0].X_add_number,
1107 fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal, 4,
1108 exp + 0, 1, BFD_RELOC_MMIX_ADDR27);
1111 case mmix_operands_pushj:
1112 /* We take care of PUSHJ in full here. */
1114 || ((exp[0].X_op == O_constant || exp[0].X_op == O_register)
1115 && (exp[0].X_add_number > 255 || exp[0].X_add_number < 0)))
1117 as_bad (_("invalid operands to opcode %s: `%s'"),
1118 instruction->name, operands);
1122 if (exp[0].X_op == O_register || exp[0].X_op == O_constant)
1123 opcodep[1] = exp[0].X_add_number;
1125 fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 1,
1126 1, exp + 0, 0, BFD_RELOC_MMIX_REG_OR_BYTE);
1129 frag_var (rs_machine_dependent, PUSHJ_MAX_LEN - 4, 0,
1130 ENCODE_RELAX (STATE_PUSHJ, STATE_UNDF),
1131 exp[1].X_add_symbol,
1132 exp[1].X_add_number,
1135 fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal, 4,
1136 exp + 1, 1, BFD_RELOC_MMIX_ADDR19);
1139 case mmix_operands_regaddr:
1140 /* GETA/branch: Add a frag for relaxation. We don't do any work
1141 around here to check if we can determine the offset right away. */
1142 if (n_operands != 2 || exp[1].X_op == O_register)
1144 as_bad (_("invalid operands to opcode %s: `%s'"),
1145 instruction->name, operands);
1150 fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal, 4,
1151 exp + 1, 1, BFD_RELOC_MMIX_ADDR19);
1152 else if (instruction->type == mmix_type_condbranch)
1153 frag_var (rs_machine_dependent, BCC_MAX_LEN - 4, 0,
1154 ENCODE_RELAX (STATE_BCC, STATE_UNDF),
1155 exp[1].X_add_symbol,
1156 exp[1].X_add_number,
1159 frag_var (rs_machine_dependent, GETA_MAX_LEN - 4, 0,
1160 ENCODE_RELAX (STATE_GETA, STATE_UNDF),
1161 exp[1].X_add_symbol,
1162 exp[1].X_add_number,
1170 switch (instruction->operands)
1172 case mmix_operands_regs:
1173 /* We check the number of operands here, since we're in a
1174 FALLTHROUGH sequence in the next switch. */
1175 if (n_operands != 3 || exp[2].X_op == O_constant)
1177 as_bad (_("invalid operands to opcode %s: `%s'"),
1178 instruction->name, operands);
1182 case mmix_operands_regs_z:
1183 if (n_operands != 3)
1185 as_bad (_("invalid operands to opcode %s: `%s'"),
1186 instruction->name, operands);
1190 case mmix_operands_reg_yz:
1191 case mmix_operands_roundregs_z:
1192 case mmix_operands_roundregs:
1193 case mmix_operands_regs_z_opt:
1194 case mmix_operands_neg:
1195 case mmix_operands_regaddr:
1196 case mmix_operands_get:
1197 case mmix_operands_set:
1198 case mmix_operands_save:
1200 || (exp[0].X_op == O_register && exp[0].X_add_number > 255))
1202 as_bad (_("invalid operands to opcode %s: `%s'"),
1203 instruction->name, operands);
1207 if (exp[0].X_op == O_register)
1208 opcodep[1] = exp[0].X_add_number;
1210 fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 1,
1211 1, exp + 0, 0, BFD_RELOC_MMIX_REG);
1218 /* A corresponding once-over for those who take an 8-bit constant as
1219 their first operand. */
1220 switch (instruction->operands)
1222 case mmix_operands_pushgo:
1223 /* PUSHGO: X is a constant, but can be expressed as a register.
1224 We handle X here and use the common machinery of T,X,3,$ for
1225 the rest of the operands. */
1227 || ((exp[0].X_op == O_constant || exp[0].X_op == O_register)
1228 && (exp[0].X_add_number > 255 || exp[0].X_add_number < 0)))
1230 as_bad (_("invalid operands to opcode %s: `%s'"),
1231 instruction->name, operands);
1234 else if (exp[0].X_op == O_constant || exp[0].X_op == O_register)
1235 opcodep[1] = exp[0].X_add_number;
1237 fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 1,
1238 1, exp + 0, 0, BFD_RELOC_MMIX_REG_OR_BYTE);
1241 case mmix_operands_pop:
1242 if ((n_operands == 0 || n_operands == 1) && ! mmix_gnu_syntax)
1245 case mmix_operands_x_regs_z:
1247 || (exp[0].X_op == O_constant
1248 && (exp[0].X_add_number > 255
1249 || exp[0].X_add_number < 0)))
1251 as_bad (_("invalid operands to opcode %s: `%s'"),
1252 instruction->name, operands);
1256 if (exp[0].X_op == O_constant)
1257 opcodep[1] = exp[0].X_add_number;
1259 /* FIXME: This doesn't bring us unsignedness checking. */
1260 fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 1,
1261 1, exp + 0, 0, BFD_RELOC_8);
1266 /* Handle the rest. */
1267 switch (instruction->operands)
1269 case mmix_operands_set:
1270 /* SET: Either two registers, "$X,$Y", with Z field as zero, or
1271 "$X,YZ", meaning change the opcode to SETL. */
1273 || (exp[1].X_op == O_constant
1274 && (exp[1].X_add_number > 0xffff || exp[1].X_add_number < 0)))
1276 as_bad (_("invalid operands to opcode %s: `%s'"),
1277 instruction->name, operands);
1281 if (exp[1].X_op == O_constant)
1283 /* There's an ambiguity with "SET $0,Y" when Y isn't defined
1284 yet. To keep things simple, we assume that Y is then a
1285 register, and only change the opcode if Y is defined at this
1288 There's no compatibility problem with mmixal, since it emits
1289 errors if the field is not defined at this point. */
1290 md_number_to_chars (opcodep, SETL_INSN_BYTE, 1);
1292 opcodep[2] = (exp[1].X_add_number >> 8) & 255;
1293 opcodep[3] = exp[1].X_add_number & 255;
1297 case mmix_operands_x_regs_z:
1298 /* SYNCD: "X,$Y,$Z|Z". */
1300 case mmix_operands_regs:
1301 /* Three registers, $X,$Y,$Z. */
1303 case mmix_operands_regs_z:
1304 /* Operands "$X,$Y,$Z|Z", number of arguments checked above. */
1306 case mmix_operands_pushgo:
1307 /* Operands "$X|X,$Y,$Z|Z", optional Z. */
1309 case mmix_operands_regs_z_opt:
1310 /* Operands "$X,$Y,$Z|Z", with $Z|Z being optional, default 0. Any
1311 operands not completely decided yet are postponed to later in
1312 assembly (but not until link-time yet). */
1314 if ((n_operands != 2 && n_operands != 3)
1315 || (exp[1].X_op == O_register && exp[1].X_add_number > 255)
1317 && ((exp[2].X_op == O_register
1318 && exp[2].X_add_number > 255
1320 || (exp[2].X_op == O_constant
1321 && (exp[2].X_add_number > 255
1322 || exp[2].X_add_number < 0)))))
1324 as_bad (_("invalid operands to opcode %s: `%s'"),
1325 instruction->name, operands);
1329 if (n_operands == 2)
1333 /* The last operand is immediate whenever we see just two
1335 opcodep[0] |= IMM_OFFSET_BIT;
1337 /* Now, we could either have an implied "0" as the Z operand, or
1338 it could be the constant of a "base address plus offset". It
1339 depends on whether it is allowed; only memory operations, as
1340 signified by instruction->type and "T" and "X" operand types,
1341 and it depends on whether we find a register in the second
1343 if (exp[1].X_op == O_register && exp[1].X_add_number <= 255)
1345 /* A zero then; all done. */
1346 opcodep[2] = exp[1].X_add_number;
1350 /* Not known as a register. Is base address plus offset
1351 allowed, or can we assume that it is a register anyway? */
1352 if ((instruction->operands != mmix_operands_regs_z_opt
1353 && instruction->operands != mmix_operands_x_regs_z
1354 && instruction->operands != mmix_operands_pushgo)
1355 || (instruction->type != mmix_type_memaccess_octa
1356 && instruction->type != mmix_type_memaccess_tetra
1357 && instruction->type != mmix_type_memaccess_wyde
1358 && instruction->type != mmix_type_memaccess_byte
1359 && instruction->type != mmix_type_memaccess_block
1360 && instruction->type != mmix_type_jsr
1361 && instruction->type != mmix_type_branch))
1363 fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 2,
1364 1, exp + 1, 0, BFD_RELOC_MMIX_REG);
1368 /* To avoid getting a NULL add_symbol for constants and then
1369 catching a SEGV in write_relocs since it doesn't handle
1370 constants well for relocs other than PC-relative, we need to
1371 pass expressions as symbols and use fix_new, not fix_new_exp. */
1372 sym = make_expr_symbol (exp + 1);
1374 /* Mark the symbol as being OK for a reloc. */
1375 symbol_get_bfdsym (sym)->flags |= BSF_KEEP;
1377 /* Now we know it can be a "base address plus offset". Add
1378 proper fixup types so we can handle this later, when we've
1379 parsed everything. */
1380 fix_new (opc_fragP, opcodep - opc_fragP->fr_literal + 2,
1381 8, sym, 0, 0, BFD_RELOC_MMIX_BASE_PLUS_OFFSET);
1385 if (exp[1].X_op == O_register)
1386 opcodep[2] = exp[1].X_add_number;
1388 fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 2,
1389 1, exp + 1, 0, BFD_RELOC_MMIX_REG);
1391 /* In mmixal compatibility mode, we allow special registers as
1392 constants for the Z operand. They have 256 added to their
1393 register numbers, so the right thing will happen if we just treat
1394 those as constants. */
1395 if (exp[2].X_op == O_register && exp[2].X_add_number <= 255)
1396 opcodep[3] = exp[2].X_add_number;
1397 else if (exp[2].X_op == O_constant
1398 || (exp[2].X_op == O_register && exp[2].X_add_number > 255))
1400 opcodep[3] = exp[2].X_add_number;
1401 opcodep[0] |= IMM_OFFSET_BIT;
1404 fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 3,
1406 (instruction->operands == mmix_operands_set
1407 || instruction->operands == mmix_operands_regs)
1408 ? BFD_RELOC_MMIX_REG : BFD_RELOC_MMIX_REG_OR_BYTE);
1411 case mmix_operands_pop:
1412 /* POP, one eight and one 16-bit operand. */
1413 if (n_operands == 0 && ! mmix_gnu_syntax)
1415 if (n_operands == 1 && ! mmix_gnu_syntax)
1416 goto a_single_24_bit_number_operand;
1418 case mmix_operands_reg_yz:
1419 /* A register and a 16-bit unsigned number. */
1421 || exp[1].X_op == O_register
1422 || (exp[1].X_op == O_constant
1423 && (exp[1].X_add_number > 0xffff || exp[1].X_add_number < 0)))
1425 as_bad (_("invalid operands to opcode %s: `%s'"),
1426 instruction->name, operands);
1430 if (exp[1].X_op == O_constant)
1432 opcodep[2] = (exp[1].X_add_number >> 8) & 255;
1433 opcodep[3] = exp[1].X_add_number & 255;
1436 /* FIXME: This doesn't bring us unsignedness checking. */
1437 fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 2,
1438 2, exp + 1, 0, BFD_RELOC_16);
1441 case mmix_operands_jmp:
1442 /* A JMP. Everything is already done. */
1445 case mmix_operands_roundregs:
1446 /* Two registers with optional rounding mode or constant in between. */
1447 if ((n_operands == 3 && exp[2].X_op == O_constant)
1448 || (n_operands == 2 && exp[1].X_op == O_constant))
1450 as_bad (_("invalid operands to opcode %s: `%s'"),
1451 instruction->name, operands);
1455 case mmix_operands_roundregs_z:
1456 /* Like FLOT, "$X,ROUND_MODE,$Z|Z", but the rounding mode is
1457 optional and can be the corresponding constant. */
1459 /* Which exp index holds the second operand (not the rounding
1461 int op2no = n_operands - 1;
1463 if ((n_operands != 2 && n_operands != 3)
1464 || ((exp[op2no].X_op == O_register
1465 && exp[op2no].X_add_number > 255)
1466 || (exp[op2no].X_op == O_constant
1467 && (exp[op2no].X_add_number > 255
1468 || exp[op2no].X_add_number < 0)))
1470 /* We don't allow for the rounding mode to be deferred; it
1471 must be determined in the "first pass". It cannot be a
1472 symbol equated to a rounding mode, but defined after
1474 && ((exp[1].X_op == O_register
1475 && exp[1].X_add_number < 512)
1476 || (exp[1].X_op == O_constant
1477 && exp[1].X_add_number < 0
1478 && exp[1].X_add_number > 4)
1479 || (exp[1].X_op != O_register
1480 && exp[1].X_op != O_constant))))
1482 as_bad (_("invalid operands to opcode %s: `%s'"),
1483 instruction->name, operands);
1487 /* Add rounding mode if present. */
1488 if (n_operands == 3)
1489 opcodep[2] = exp[1].X_add_number & 255;
1491 if (exp[op2no].X_op == O_register)
1492 opcodep[3] = exp[op2no].X_add_number;
1493 else if (exp[op2no].X_op == O_constant)
1495 opcodep[3] = exp[op2no].X_add_number;
1496 opcodep[0] |= IMM_OFFSET_BIT;
1499 fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 3,
1501 instruction->operands == mmix_operands_roundregs
1502 ? BFD_RELOC_MMIX_REG
1503 : BFD_RELOC_MMIX_REG_OR_BYTE);
1507 case mmix_operands_sync:
1508 a_single_24_bit_number_operand:
1510 || exp[0].X_op == O_register
1511 || (exp[0].X_op == O_constant
1512 && (exp[0].X_add_number > 0xffffff || exp[0].X_add_number < 0)))
1514 as_bad (_("invalid operands to opcode %s: `%s'"),
1515 instruction->name, operands);
1519 if (exp[0].X_op == O_constant)
1521 opcodep[1] = (exp[0].X_add_number >> 16) & 255;
1522 opcodep[2] = (exp[0].X_add_number >> 8) & 255;
1523 opcodep[3] = exp[0].X_add_number & 255;
1526 /* FIXME: This doesn't bring us unsignedness checking. */
1527 fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 1,
1528 3, exp + 0, 0, BFD_RELOC_24);
1531 case mmix_operands_neg:
1532 /* Operands "$X,Y,$Z|Z"; NEG or NEGU. Y is optional, 0 is default. */
1534 if ((n_operands != 3 && n_operands != 2)
1535 || (n_operands == 3 && exp[1].X_op == O_register)
1536 || ((exp[1].X_op == O_constant || exp[1].X_op == O_register)
1537 && (exp[1].X_add_number > 255 || exp[1].X_add_number < 0))
1539 && ((exp[2].X_op == O_register && exp[2].X_add_number > 255)
1540 || (exp[2].X_op == O_constant
1541 && (exp[2].X_add_number > 255
1542 || exp[2].X_add_number < 0)))))
1544 as_bad (_("invalid operands to opcode %s: `%s'"),
1545 instruction->name, operands);
1549 if (n_operands == 2)
1551 if (exp[1].X_op == O_register)
1552 opcodep[3] = exp[1].X_add_number;
1553 else if (exp[1].X_op == O_constant)
1555 opcodep[3] = exp[1].X_add_number;
1556 opcodep[0] |= IMM_OFFSET_BIT;
1559 fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 3,
1560 1, exp + 1, 0, BFD_RELOC_MMIX_REG_OR_BYTE);
1564 if (exp[1].X_op == O_constant)
1565 opcodep[2] = exp[1].X_add_number;
1567 fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 2,
1568 1, exp + 1, 0, BFD_RELOC_8);
1570 if (exp[2].X_op == O_register)
1571 opcodep[3] = exp[2].X_add_number;
1572 else if (exp[2].X_op == O_constant)
1574 opcodep[3] = exp[2].X_add_number;
1575 opcodep[0] |= IMM_OFFSET_BIT;
1578 fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 3,
1579 1, exp + 2, 0, BFD_RELOC_MMIX_REG_OR_BYTE);
1582 case mmix_operands_regaddr:
1583 /* A GETA/branch-type. */
1586 case mmix_operands_get:
1587 /* "$X,spec_reg"; GET.
1588 Like with rounding modes, we demand that the special register or
1589 symbol is already defined when we get here at the point of use. */
1591 || (exp[1].X_op == O_register
1592 && (exp[1].X_add_number < 256 || exp[1].X_add_number >= 512))
1593 || (exp[1].X_op == O_constant
1594 && (exp[1].X_add_number < 0 || exp[1].X_add_number > 256))
1595 || (exp[1].X_op != O_constant && exp[1].X_op != O_register))
1597 as_bad (_("invalid operands to opcode %s: `%s'"),
1598 instruction->name, operands);
1602 opcodep[3] = exp[1].X_add_number - 256;
1605 case mmix_operands_put:
1606 /* "spec_reg,$Z|Z"; PUT. */
1608 || (exp[0].X_op == O_register
1609 && (exp[0].X_add_number < 256 || exp[0].X_add_number >= 512))
1610 || (exp[0].X_op == O_constant
1611 && (exp[0].X_add_number < 0 || exp[0].X_add_number > 256))
1612 || (exp[0].X_op != O_constant && exp[0].X_op != O_register))
1614 as_bad (_("invalid operands to opcode %s: `%s'"),
1615 instruction->name, operands);
1619 opcodep[1] = exp[0].X_add_number - 256;
1621 /* Note that the Y field is zero. */
1623 if (exp[1].X_op == O_register)
1624 opcodep[3] = exp[1].X_add_number;
1625 else if (exp[1].X_op == O_constant)
1627 opcodep[3] = exp[1].X_add_number;
1628 opcodep[0] |= IMM_OFFSET_BIT;
1631 fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 3,
1632 1, exp + 1, 0, BFD_RELOC_MMIX_REG_OR_BYTE);
1635 case mmix_operands_save:
1638 || exp[1].X_op != O_constant
1639 || exp[1].X_add_number != 0)
1641 as_bad (_("invalid operands to opcode %s: `%s'"),
1642 instruction->name, operands);
1647 case mmix_operands_unsave:
1648 if (n_operands < 2 && ! mmix_gnu_syntax)
1650 if (n_operands == 1)
1652 if (exp[0].X_op == O_register)
1653 opcodep[3] = exp[0].X_add_number;
1655 fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 3,
1656 1, exp, 0, BFD_RELOC_MMIX_REG);
1661 /* "0,$Z"; UNSAVE. */
1663 || exp[0].X_op != O_constant
1664 || exp[0].X_add_number != 0
1665 || exp[1].X_op == O_constant
1666 || (exp[1].X_op == O_register
1667 && exp[1].X_add_number > 255))
1669 as_bad (_("invalid operands to opcode %s: `%s'"),
1670 instruction->name, operands);
1674 if (exp[1].X_op == O_register)
1675 opcodep[3] = exp[1].X_add_number;
1677 fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 3,
1678 1, exp + 1, 0, BFD_RELOC_MMIX_REG);
1681 case mmix_operands_xyz_opt:
1682 /* SWYM, TRIP, TRAP: zero, one, two or three operands. It's
1683 unspecified whether operands are registers or constants, but
1684 when we find register syntax, we require operands to be literal and
1686 if (n_operands == 0 && ! mmix_gnu_syntax)
1687 /* Zeros are in place - nothing needs to be done for zero
1688 operands. We don't allow this in GNU syntax mode, because it
1689 was believed that the risk of missing to supply an operand is
1690 higher than the benefit of not having to specify a zero. */
1692 else if (n_operands == 1 && exp[0].X_op != O_register)
1694 if (exp[0].X_op == O_constant)
1696 if (exp[0].X_add_number > 255*256*256
1697 || exp[0].X_add_number < 0)
1699 as_bad (_("invalid operands to opcode %s: `%s'"),
1700 instruction->name, operands);
1705 opcodep[1] = (exp[0].X_add_number >> 16) & 255;
1706 opcodep[2] = (exp[0].X_add_number >> 8) & 255;
1707 opcodep[3] = exp[0].X_add_number & 255;
1711 fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 1,
1712 3, exp, 0, BFD_RELOC_24);
1714 else if (n_operands == 2
1715 && exp[0].X_op != O_register
1716 && exp[1].X_op != O_register)
1720 if (exp[0].X_op == O_constant)
1722 if (exp[0].X_add_number > 255
1723 || exp[0].X_add_number < 0)
1725 as_bad (_("invalid operands to opcode %s: `%s'"),
1726 instruction->name, operands);
1730 opcodep[1] = exp[0].X_add_number & 255;
1733 fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 1,
1734 1, exp, 0, BFD_RELOC_8);
1736 if (exp[1].X_op == O_constant)
1738 if (exp[1].X_add_number > 255*256
1739 || exp[1].X_add_number < 0)
1741 as_bad (_("invalid operands to opcode %s: `%s'"),
1742 instruction->name, operands);
1747 opcodep[2] = (exp[1].X_add_number >> 8) & 255;
1748 opcodep[3] = exp[1].X_add_number & 255;
1752 fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 2,
1753 2, exp + 1, 0, BFD_RELOC_16);
1755 else if (n_operands == 3
1756 && exp[0].X_op != O_register
1757 && exp[1].X_op != O_register
1758 && exp[2].X_op != O_register)
1760 /* Three operands. */
1762 if (exp[0].X_op == O_constant)
1764 if (exp[0].X_add_number > 255
1765 || exp[0].X_add_number < 0)
1767 as_bad (_("invalid operands to opcode %s: `%s'"),
1768 instruction->name, operands);
1772 opcodep[1] = exp[0].X_add_number & 255;
1775 fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 1,
1776 1, exp, 0, BFD_RELOC_8);
1778 if (exp[1].X_op == O_constant)
1780 if (exp[1].X_add_number > 255
1781 || exp[1].X_add_number < 0)
1783 as_bad (_("invalid operands to opcode %s: `%s'"),
1784 instruction->name, operands);
1788 opcodep[2] = exp[1].X_add_number & 255;
1791 fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 2,
1792 1, exp + 1, 0, BFD_RELOC_8);
1794 if (exp[2].X_op == O_constant)
1796 if (exp[2].X_add_number > 255
1797 || exp[2].X_add_number < 0)
1799 as_bad (_("invalid operands to opcode %s: `%s'"),
1800 instruction->name, operands);
1804 opcodep[3] = exp[2].X_add_number & 255;
1807 fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 3,
1808 1, exp + 2, 0, BFD_RELOC_8);
1812 /* We can't get here for other cases. */
1813 gas_assert (n_operands <= 3);
1815 /* The meaning of operands to TRIP and TRAP is not defined (and
1816 SWYM operands aren't enforced in mmixal, so let's avoid
1817 that). We add combinations not handled above here as we find
1818 them and as they're reported. */
1819 if (n_operands == 3)
1821 /* Don't require non-register operands. Always generate
1822 fixups, so we don't have to copy lots of code and create
1823 maintenance problems. TRIP is supposed to be a rare
1824 instruction, so the overhead should not matter. We
1825 aren't allowed to fix_new_exp for an expression which is
1826 an O_register at this point, however.
1828 Don't use BFD_RELOC_MMIX_REG_OR_BYTE as that modifies
1829 the insn for a register in the Z field and we want
1831 if (exp[0].X_op == O_register)
1832 opcodep[1] = exp[0].X_add_number;
1834 fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 1,
1835 1, exp, 0, BFD_RELOC_8);
1836 if (exp[1].X_op == O_register)
1837 opcodep[2] = exp[1].X_add_number;
1839 fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 2,
1840 1, exp + 1, 0, BFD_RELOC_8);
1841 if (exp[2].X_op == O_register)
1842 opcodep[3] = exp[2].X_add_number;
1844 fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 3,
1845 1, exp + 2, 0, BFD_RELOC_8);
1847 else if (n_operands == 2)
1849 if (exp[0].X_op == O_register)
1850 opcodep[1] = exp[0].X_add_number;
1852 fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 1,
1853 1, exp, 0, BFD_RELOC_8);
1854 if (exp[1].X_op == O_register)
1855 opcodep[3] = exp[1].X_add_number;
1857 fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 2,
1858 2, exp + 1, 0, BFD_RELOC_16);
1862 /* We can't get here for other cases. */
1863 gas_assert (n_operands == 1 && exp[0].X_op == O_register);
1865 opcodep[3] = exp[0].X_add_number;
1870 case mmix_operands_resume:
1871 if (n_operands == 0 && ! mmix_gnu_syntax)
1875 || exp[0].X_op == O_register
1876 || (exp[0].X_op == O_constant
1877 && (exp[0].X_add_number < 0
1878 || exp[0].X_add_number > 255)))
1880 as_bad (_("invalid operands to opcode %s: `%s'"),
1881 instruction->name, operands);
1885 if (exp[0].X_op == O_constant)
1886 opcodep[3] = exp[0].X_add_number;
1888 fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 3,
1889 1, exp + 0, 0, BFD_RELOC_8);
1892 case mmix_operands_pushj:
1893 /* All is done for PUSHJ already. */
1897 BAD_CASE (instruction->operands);
1901 /* For the benefit of insns that start with a digit, we assemble by way of
1902 tc_unrecognized_line too, through this function. */
1905 mmix_assemble_return_nonzero (char *str)
1907 int last_error_count = had_errors ();
1911 /* Normal instruction handling downcases, so we must too. */
1912 while (ISALNUM (*s2))
1914 if (ISUPPER ((unsigned char) *s2))
1915 *s2 = TOLOWER (*s2);
1919 /* Cut the line for sake of the assembly. */
1920 for (s2 = str; *s2 && *s2 != '\n'; s2++)
1928 return had_errors () == last_error_count;
1931 /* The PREFIX pseudo. */
1934 s_prefix (int unused ATTRIBUTE_UNUSED)
1941 p = input_line_pointer;
1943 c = get_symbol_end ();
1945 /* Reseting prefix? */
1946 if (*p == ':' && p[1] == 0)
1947 mmix_current_prefix = NULL;
1950 /* Put this prefix on the mmix symbols obstack. We could malloc and
1951 free it separately, but then we'd have to worry about that.
1952 People using up memory on prefixes have other problems. */
1953 obstack_grow (&mmix_sym_obstack, p, strlen (p) + 1);
1954 p = obstack_finish (&mmix_sym_obstack);
1956 /* Accumulate prefixes, and strip a leading ':'. */
1957 if (mmix_current_prefix != NULL || *p == ':')
1958 p = mmix_prefix_name (p);
1960 mmix_current_prefix = p;
1963 *input_line_pointer = c;
1965 mmix_handle_rest_of_empty_line ();
1968 /* We implement prefixes by using the tc_canonicalize_symbol_name hook,
1969 and store each prefixed name on a (separate) obstack. This means that
1970 the name is on the "notes" obstack in non-prefixed form and on the
1971 mmix_sym_obstack in prefixed form, but currently it is not worth
1972 rewriting the whole GAS symbol handling to improve "hooking" to avoid
1973 that. (It might be worth a rewrite for other reasons, though). */
1976 mmix_prefix_name (char *shortname)
1978 if (*shortname == ':')
1979 return shortname + 1;
1981 if (mmix_current_prefix == NULL)
1982 as_fatal (_("internal: mmix_prefix_name but empty prefix"));
1984 if (*shortname == '$')
1987 obstack_grow (&mmix_sym_obstack, mmix_current_prefix,
1988 strlen (mmix_current_prefix));
1989 obstack_grow (&mmix_sym_obstack, shortname, strlen (shortname) + 1);
1990 return obstack_finish (&mmix_sym_obstack);
1993 /* The GREG pseudo. At LABEL, we have the name of a symbol that we
1994 want to make a register symbol, and which should be initialized with
1995 the value in the expression at INPUT_LINE_POINTER (defaulting to 0).
1996 Either and (perhaps less meaningful) both may be missing. LABEL must
1997 be persistent, perhaps allocated on an obstack. */
2000 mmix_greg_internal (char *label)
2002 expressionS *expP = &mmix_raw_gregs[n_of_raw_gregs].exp;
2005 /* Don't set the section to register contents section before the
2006 expression has been parsed; it may refer to the current position. */
2007 section = expression (expP);
2009 /* FIXME: Check that no expression refers to the register contents
2010 section. May need to be done in elf64-mmix.c. */
2011 if (expP->X_op == O_absent)
2013 /* Default to zero if the expression was absent. */
2014 expP->X_op = O_constant;
2015 expP->X_add_number = 0;
2016 expP->X_unsigned = 0;
2017 expP->X_add_symbol = NULL;
2018 expP->X_op_symbol = NULL;
2021 if (section == undefined_section)
2023 /* This is an error or a LOC with an expression involving
2024 forward references. For the expression to be correctly
2025 evaluated, we need to force a proper symbol; gas loses track
2026 of the segment for "local symbols". */
2027 if (expP->X_op == O_add)
2029 symbol_get_value_expression (expP->X_op_symbol);
2030 symbol_get_value_expression (expP->X_add_symbol);
2034 gas_assert (expP->X_op == O_symbol);
2035 symbol_get_value_expression (expP->X_add_symbol);
2039 /* We must handle prefixes here, as we save the labels and expressions
2040 to be output later. */
2041 mmix_raw_gregs[n_of_raw_gregs].label
2042 = mmix_current_prefix == NULL ? label : mmix_prefix_name (label);
2044 if (n_of_raw_gregs == MAX_GREGS - 1)
2045 as_bad (_("too many GREG registers allocated (max %d)"), MAX_GREGS);
2049 mmix_handle_rest_of_empty_line ();
2052 /* The ".greg label,expr" worker. */
2055 s_greg (int unused ATTRIBUTE_UNUSED)
2059 p = input_line_pointer;
2061 /* This will skip over what can be a symbol and zero out the next
2062 character, which we assume is a ',' or other meaningful delimiter.
2063 What comes after that is the initializer expression for the
2065 c = get_symbol_end ();
2067 if (! is_end_of_line[(unsigned char) c])
2068 input_line_pointer++;
2072 /* The label must be persistent; it's not used until after all input
2074 obstack_grow (&mmix_sym_obstack, p, strlen (p) + 1);
2075 mmix_greg_internal (obstack_finish (&mmix_sym_obstack));
2078 mmix_greg_internal (NULL);
2081 /* The "BSPEC expr" worker. */
2084 s_bspec (int unused ATTRIBUTE_UNUSED)
2088 char secname[sizeof (MMIX_OTHER_SPEC_SECTION_PREFIX) + 20]
2089 = MMIX_OTHER_SPEC_SECTION_PREFIX;
2093 /* Get a constant expression which we can evaluate *now*. Supporting
2094 more complex (though assembly-time computable) expressions is
2095 feasible but Too Much Work for something of unknown usefulness like
2097 expsec = expression (&exp);
2098 mmix_handle_rest_of_empty_line ();
2100 /* Check that we don't have another BSPEC in progress. */
2103 as_bad (_("BSPEC already active. Nesting is not supported."));
2107 if (exp.X_op != O_constant
2108 || expsec != absolute_section
2109 || exp.X_add_number < 0
2110 || exp.X_add_number > 65535)
2112 as_bad (_("invalid BSPEC expression"));
2113 exp.X_add_number = 0;
2116 n = (int) exp.X_add_number;
2118 sprintf (secname + strlen (MMIX_OTHER_SPEC_SECTION_PREFIX), "%d", n);
2119 sec = bfd_get_section_by_name (stdoutput, secname);
2122 /* We need a non-volatile name as it will be stored in the section
2124 char *newsecname = xstrdup (secname);
2125 sec = bfd_make_section (stdoutput, newsecname);
2128 as_fatal (_("can't create section %s"), newsecname);
2130 if (!bfd_set_section_flags (stdoutput, sec,
2131 bfd_get_section_flags (stdoutput, sec)
2133 as_fatal (_("can't set section flags for section %s"), newsecname);
2136 /* Tell ELF about the pending section change. */
2137 obj_elf_section_change_hook ();
2138 subseg_set (sec, 0);
2140 /* Save position for missing ESPEC. */
2141 as_where (&bspec_file, &bspec_line);
2146 /* The "ESPEC" worker. */
2149 s_espec (int unused ATTRIBUTE_UNUSED)
2151 /* First, check that we *do* have a BSPEC in progress. */
2154 as_bad (_("ESPEC without preceding BSPEC"));
2158 mmix_handle_rest_of_empty_line ();
2161 /* When we told ELF about the section change in s_bspec, it stored the
2162 previous section for us so we can get at it with the equivalent of a
2163 .previous pseudo. */
2164 obj_elf_previous (0);
2167 /* The " .local expr" and " local expr" worker. We make a BFD_MMIX_LOCAL
2168 relocation against the current position against the expression.
2169 Implementing this by means of contents in a section lost. */
2172 mmix_s_local (int unused ATTRIBUTE_UNUSED)
2176 /* Don't set the section to register contents section before the
2177 expression has been parsed; it may refer to the current position in
2178 some contorted way. */
2181 if (exp.X_op == O_absent)
2183 as_bad (_("missing local expression"));
2186 else if (exp.X_op == O_register)
2188 /* fix_new_exp doesn't like O_register. Should be configurable.
2189 We're fine with a constant here, though. */
2190 exp.X_op = O_constant;
2193 fix_new_exp (frag_now, 0, 0, &exp, 0, BFD_RELOC_MMIX_LOCAL);
2194 mmix_handle_rest_of_empty_line ();
2197 /* Set fragP->fr_var to the initial guess of the size of a relaxable insn
2198 and return it. Sizes of other instructions are not known. This
2199 function may be called multiple times. */
2202 md_estimate_size_before_relax (fragS *fragP, segT segment)
2206 #define HANDLE_RELAXABLE(state) \
2207 case ENCODE_RELAX (state, STATE_UNDF): \
2208 if (fragP->fr_symbol != NULL \
2209 && S_GET_SEGMENT (fragP->fr_symbol) == segment \
2210 && !S_IS_WEAK (fragP->fr_symbol)) \
2212 /* The symbol lies in the same segment - a relaxable case. */ \
2214 = ENCODE_RELAX (state, STATE_ZERO); \
2218 switch (fragP->fr_subtype)
2220 HANDLE_RELAXABLE (STATE_GETA);
2221 HANDLE_RELAXABLE (STATE_BCC);
2222 HANDLE_RELAXABLE (STATE_JMP);
2224 case ENCODE_RELAX (STATE_PUSHJ, STATE_UNDF):
2225 if (fragP->fr_symbol != NULL
2226 && S_GET_SEGMENT (fragP->fr_symbol) == segment
2227 && !S_IS_WEAK (fragP->fr_symbol))
2228 /* The symbol lies in the same segment - a relaxable case. */
2229 fragP->fr_subtype = ENCODE_RELAX (STATE_PUSHJ, STATE_ZERO);
2230 else if (pushj_stubs)
2231 /* If we're to generate stubs, assume we can reach a stub after
2233 fragP->fr_subtype = ENCODE_RELAX (STATE_PUSHJSTUB, STATE_ZERO);
2235 case ENCODE_RELAX (STATE_PUSHJ, STATE_ZERO):
2236 case ENCODE_RELAX (STATE_PUSHJSTUB, STATE_ZERO):
2237 /* We need to distinguish different relaxation rounds. */
2238 seg_info (segment)->tc_segment_info_data.last_stubfrag = fragP;
2241 case ENCODE_RELAX (STATE_GETA, STATE_ZERO):
2242 case ENCODE_RELAX (STATE_BCC, STATE_ZERO):
2243 case ENCODE_RELAX (STATE_JMP, STATE_ZERO):
2244 /* When relaxing a section for the second time, we don't need to do
2245 anything except making sure that fr_var is set right. */
2248 case STATE_GREG_DEF:
2249 length = fragP->tc_frag_data != NULL ? 0 : 8;
2250 fragP->fr_var = length;
2252 /* Don't consult the relax_table; it isn't valid for this
2258 BAD_CASE (fragP->fr_subtype);
2261 length = mmix_relax_table[fragP->fr_subtype].rlx_length;
2262 fragP->fr_var = length;
2267 /* Turn a string in input_line_pointer into a floating point constant of type
2268 type, and store the appropriate bytes in *litP. The number of LITTLENUMS
2269 emitted is stored in *sizeP . An error message is returned, or NULL on
2273 md_atof (int type, char *litP, int *sizeP)
2277 /* FIXME: Having 'f' in mmix_flt_chars (and here) makes it
2278 problematic to also have a forward reference in an expression.
2279 The testsuite wants it, and it's customary.
2280 We'll deal with the real problems when they come; we share the
2281 problem with most other ports. */
2282 return ieee_md_atof (type, litP, sizeP, TRUE);
2285 /* Convert variable-sized frags into one or more fixups. */
2288 md_convert_frag (bfd *abfd ATTRIBUTE_UNUSED, segT sec ATTRIBUTE_UNUSED,
2291 /* Pointer to first byte in variable-sized part of the frag. */
2294 /* Pointer to first opcode byte in frag. */
2297 /* Size in bytes of variable-sized part of frag. */
2298 int var_part_size = 0;
2300 /* This is part of *fragP. It contains all information about addresses
2301 and offsets to varying parts. */
2303 unsigned long var_part_offset;
2305 /* This is the frag for the opcode. It, rather than fragP, must be used
2306 when emitting a frag for the opcode. */
2307 fragS *opc_fragP = fragP->tc_frag_data;
2310 /* Where, in file space, does addr point? */
2311 bfd_vma target_address;
2312 bfd_vma opcode_address;
2314 know (fragP->fr_type == rs_machine_dependent);
2316 var_part_offset = fragP->fr_fix;
2317 var_partp = fragP->fr_literal + var_part_offset;
2318 opcodep = fragP->fr_opcode;
2320 symbolP = fragP->fr_symbol;
2323 = ((symbolP ? S_GET_VALUE (symbolP) : 0) + fragP->fr_offset);
2325 /* The opcode that would be extended is the last four "fixed" bytes. */
2326 opcode_address = fragP->fr_address + fragP->fr_fix - 4;
2328 switch (fragP->fr_subtype)
2330 case ENCODE_RELAX (STATE_PUSHJSTUB, STATE_ZERO):
2331 /* Setting the unknown bits to 0 seems the most appropriate. */
2332 mmix_set_geta_branch_offset (opcodep, 0);
2333 tmpfixP = fix_new (opc_fragP, opcodep - opc_fragP->fr_literal, 8,
2334 fragP->fr_symbol, fragP->fr_offset, 1,
2335 BFD_RELOC_MMIX_PUSHJ_STUBBABLE);
2336 COPY_FR_WHERE_TO_FX (fragP, tmpfixP);
2340 case ENCODE_RELAX (STATE_GETA, STATE_ZERO):
2341 case ENCODE_RELAX (STATE_BCC, STATE_ZERO):
2342 case ENCODE_RELAX (STATE_PUSHJ, STATE_ZERO):
2343 mmix_set_geta_branch_offset (opcodep, target_address - opcode_address);
2347 = fix_new (opc_fragP, opcodep - opc_fragP->fr_literal, 4,
2348 fragP->fr_symbol, fragP->fr_offset, 1,
2349 BFD_RELOC_MMIX_ADDR19);
2350 COPY_FR_WHERE_TO_FX (fragP, tmpfixP);
2355 case ENCODE_RELAX (STATE_JMP, STATE_ZERO):
2356 mmix_set_jmp_offset (opcodep, target_address - opcode_address);
2360 = fix_new (opc_fragP, opcodep - opc_fragP->fr_literal, 4,
2361 fragP->fr_symbol, fragP->fr_offset, 1,
2362 BFD_RELOC_MMIX_ADDR27);
2363 COPY_FR_WHERE_TO_FX (fragP, tmpfixP);
2368 case STATE_GREG_DEF:
2369 if (fragP->tc_frag_data == NULL)
2371 /* We must initialize data that's supposed to be "fixed up" to
2372 avoid emitting garbage, because md_apply_fix won't do
2373 anything for undefined symbols. */
2374 md_number_to_chars (var_partp, 0, 8);
2376 = fix_new (fragP, var_partp - fragP->fr_literal, 8,
2377 fragP->fr_symbol, fragP->fr_offset, 0, BFD_RELOC_64);
2378 COPY_FR_WHERE_TO_FX (fragP, tmpfixP);
2379 mmix_gregs[n_of_cooked_gregs++] = tmpfixP;
2386 #define HANDLE_MAX_RELOC(state, reloc) \
2387 case ENCODE_RELAX (state, STATE_MAX): \
2389 = mmix_relax_table[ENCODE_RELAX (state, STATE_MAX)].rlx_length; \
2390 mmix_fill_nops (var_partp, var_part_size / 4); \
2391 if (warn_on_expansion) \
2392 as_warn_where (fragP->fr_file, fragP->fr_line, \
2393 _("operand out of range, instruction expanded")); \
2394 tmpfixP = fix_new (fragP, var_partp - fragP->fr_literal - 4, 8, \
2395 fragP->fr_symbol, fragP->fr_offset, 1, reloc); \
2396 COPY_FR_WHERE_TO_FX (fragP, tmpfixP); \
2399 HANDLE_MAX_RELOC (STATE_GETA, BFD_RELOC_MMIX_GETA);
2400 HANDLE_MAX_RELOC (STATE_BCC, BFD_RELOC_MMIX_CBRANCH);
2401 HANDLE_MAX_RELOC (STATE_PUSHJ, BFD_RELOC_MMIX_PUSHJ);
2402 HANDLE_MAX_RELOC (STATE_JMP, BFD_RELOC_MMIX_JMP);
2405 BAD_CASE (fragP->fr_subtype);
2409 fragP->fr_fix += var_part_size;
2413 /* Applies the desired value to the specified location.
2414 Also sets up addends for RELA type relocations.
2415 Stolen from tc-mcore.c.
2417 Note that this function isn't called when linkrelax != 0. */
2420 md_apply_fix (fixS *fixP, valueT *valP, segT segment)
2422 char *buf = fixP->fx_where + fixP->fx_frag->fr_literal;
2423 /* Note: use offsetT because it is signed, valueT is unsigned. */
2424 offsetT val = (offsetT) * valP;
2426 = (fixP->fx_addsy == NULL
2427 ? absolute_section : S_GET_SEGMENT (fixP->fx_addsy));
2429 /* If the fix is relative to a symbol which is not defined, or, (if
2430 pcrel), not in the same segment as the fix, we cannot resolve it
2432 if (fixP->fx_addsy != NULL
2433 && (! S_IS_DEFINED (fixP->fx_addsy)
2434 || S_IS_WEAK (fixP->fx_addsy)
2435 || (fixP->fx_pcrel && symsec != segment)
2436 || (! fixP->fx_pcrel
2437 && symsec != absolute_section
2438 && ((fixP->fx_r_type != BFD_RELOC_MMIX_REG
2439 && fixP->fx_r_type != BFD_RELOC_MMIX_REG_OR_BYTE)
2440 || symsec != reg_section))))
2445 else if (fixP->fx_r_type == BFD_RELOC_MMIX_LOCAL
2446 || fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
2447 || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
2449 /* These are never "fixed". */
2454 /* We assume every other relocation is "fixed". */
2457 switch (fixP->fx_r_type)
2464 case BFD_RELOC_64_PCREL:
2465 case BFD_RELOC_32_PCREL:
2466 case BFD_RELOC_24_PCREL:
2467 case BFD_RELOC_16_PCREL:
2468 case BFD_RELOC_8_PCREL:
2469 md_number_to_chars (buf, val, fixP->fx_size);
2472 case BFD_RELOC_MMIX_ADDR19:
2475 /* This shouldn't happen. */
2476 BAD_CASE (fixP->fx_r_type);
2480 case BFD_RELOC_MMIX_GETA:
2481 case BFD_RELOC_MMIX_CBRANCH:
2482 case BFD_RELOC_MMIX_PUSHJ:
2483 case BFD_RELOC_MMIX_PUSHJ_STUBBABLE:
2484 /* If this fixup is out of range, punt to the linker to emit an
2485 error. This should only happen with -no-expand. */
2486 if (val < -(((offsetT) 1 << 19)/2)
2487 || val >= ((offsetT) 1 << 19)/2 - 1
2490 if (warn_on_expansion)
2491 as_warn_where (fixP->fx_file, fixP->fx_line,
2492 _("operand out of range"));
2496 mmix_set_geta_branch_offset (buf, val);
2499 case BFD_RELOC_MMIX_ADDR27:
2502 /* This shouldn't happen. */
2503 BAD_CASE (fixP->fx_r_type);
2507 case BFD_RELOC_MMIX_JMP:
2508 /* If this fixup is out of range, punt to the linker to emit an
2509 error. This should only happen with -no-expand. */
2510 if (val < -(((offsetT) 1 << 27)/2)
2511 || val >= ((offsetT) 1 << 27)/2 - 1
2514 if (warn_on_expansion)
2515 as_warn_where (fixP->fx_file, fixP->fx_line,
2516 _("operand out of range"));
2520 mmix_set_jmp_offset (buf, val);
2523 case BFD_RELOC_MMIX_REG_OR_BYTE:
2524 if (fixP->fx_addsy != NULL
2525 && (S_GET_SEGMENT (fixP->fx_addsy) != reg_section
2526 || S_GET_VALUE (fixP->fx_addsy) > 255)
2527 && S_GET_SEGMENT (fixP->fx_addsy) != absolute_section)
2529 as_bad_where (fixP->fx_file, fixP->fx_line,
2530 _("invalid operands"));
2531 /* We don't want this "symbol" appearing in output, because
2538 /* If this reloc is for a Z field, we need to adjust
2539 the opcode if we got a constant here.
2540 FIXME: Can we make this more robust? */
2542 if ((fixP->fx_where & 3) == 3
2543 && (fixP->fx_addsy == NULL
2544 || S_GET_SEGMENT (fixP->fx_addsy) == absolute_section))
2545 buf[-3] |= IMM_OFFSET_BIT;
2548 case BFD_RELOC_MMIX_REG:
2549 if (fixP->fx_addsy == NULL
2550 || S_GET_SEGMENT (fixP->fx_addsy) != reg_section
2551 || S_GET_VALUE (fixP->fx_addsy) > 255)
2553 as_bad_where (fixP->fx_file, fixP->fx_line,
2554 _("invalid operands"));
2561 case BFD_RELOC_MMIX_BASE_PLUS_OFFSET:
2562 /* These are never "fixed". */
2566 case BFD_RELOC_MMIX_PUSHJ_1:
2567 case BFD_RELOC_MMIX_PUSHJ_2:
2568 case BFD_RELOC_MMIX_PUSHJ_3:
2569 case BFD_RELOC_MMIX_CBRANCH_J:
2570 case BFD_RELOC_MMIX_CBRANCH_1:
2571 case BFD_RELOC_MMIX_CBRANCH_2:
2572 case BFD_RELOC_MMIX_CBRANCH_3:
2573 case BFD_RELOC_MMIX_GETA_1:
2574 case BFD_RELOC_MMIX_GETA_2:
2575 case BFD_RELOC_MMIX_GETA_3:
2576 case BFD_RELOC_MMIX_JMP_1:
2577 case BFD_RELOC_MMIX_JMP_2:
2578 case BFD_RELOC_MMIX_JMP_3:
2580 BAD_CASE (fixP->fx_r_type);
2585 /* Make sure that for completed fixups we have the value around for
2586 use by e.g. mmix_frob_file. */
2587 fixP->fx_offset = val;
2590 /* A bsearch function for looking up a value against offsets for GREG
2594 cmp_greg_val_greg_symbol_fixes (const void *p1, const void *p2)
2596 offsetT val1 = *(offsetT *) p1;
2597 offsetT val2 = ((struct mmix_symbol_greg_fixes *) p2)->offs;
2599 if (val1 >= val2 && val1 < val2 + 255)
2608 /* Generate a machine-dependent relocation. */
2611 tc_gen_reloc (asection *section ATTRIBUTE_UNUSED, fixS *fixP)
2615 + (fixP->fx_addsy != NULL
2616 && !S_IS_WEAK (fixP->fx_addsy)
2617 && !S_IS_COMMON (fixP->fx_addsy)
2618 ? S_GET_VALUE (fixP->fx_addsy) : 0);
2620 bfd_reloc_code_real_type code = BFD_RELOC_NONE;
2621 char *buf = fixP->fx_where + fixP->fx_frag->fr_literal;
2622 symbolS *addsy = fixP->fx_addsy;
2623 asection *addsec = addsy == NULL ? NULL : S_GET_SEGMENT (addsy);
2624 asymbol *baddsy = addsy != NULL ? symbol_get_bfdsym (addsy) : NULL;
2626 = val - (baddsy == NULL || S_IS_COMMON (addsy) || S_IS_WEAK (addsy)
2627 ? 0 : bfd_asymbol_value (baddsy));
2629 /* A single " LOCAL expression" in the wrong section will not work when
2630 linking to MMO; relocations for zero-content sections are then
2631 ignored. Normally, relocations would modify section contents, and
2632 you'd never think or be able to do something like that. The
2633 relocation resulting from a LOCAL directive doesn't have an obvious
2634 and mandatory location. I can't figure out a way to do this better
2635 than just helping the user around this limitation here; hopefully the
2636 code using the local expression is around. Putting the LOCAL
2637 semantics in a relocation still seems right; a section didn't do. */
2638 if (bfd_section_size (section->owner, section) == 0)
2640 (fixP->fx_file, fixP->fx_line,
2641 fixP->fx_r_type == BFD_RELOC_MMIX_LOCAL
2642 /* The BFD_RELOC_MMIX_LOCAL-specific message is supposed to be
2643 user-friendly, though a little bit non-substantial. */
2644 ? _("directive LOCAL must be placed in code or data")
2645 : _("internal confusion: relocation in a section without contents"));
2647 /* FIXME: Range tests for all these. */
2648 switch (fixP->fx_r_type)
2655 code = fixP->fx_r_type;
2657 if (addsy == NULL || bfd_is_abs_section (addsec))
2659 /* Resolve this reloc now, as md_apply_fix would have done (not
2660 called if -linkrelax). There is no point in keeping a reloc
2661 to an absolute symbol. No reloc that is subject to
2662 relaxation must be to an absolute symbol; difference
2663 involving symbols in a specific section must be signalled as
2664 an error if the relaxing cannot be expressed; having a reloc
2665 to the resolved (now absolute) value does not help. */
2666 md_number_to_chars (buf, val, fixP->fx_size);
2671 case BFD_RELOC_64_PCREL:
2672 case BFD_RELOC_32_PCREL:
2673 case BFD_RELOC_24_PCREL:
2674 case BFD_RELOC_16_PCREL:
2675 case BFD_RELOC_8_PCREL:
2676 case BFD_RELOC_MMIX_LOCAL:
2677 case BFD_RELOC_VTABLE_INHERIT:
2678 case BFD_RELOC_VTABLE_ENTRY:
2679 case BFD_RELOC_MMIX_GETA:
2680 case BFD_RELOC_MMIX_GETA_1:
2681 case BFD_RELOC_MMIX_GETA_2:
2682 case BFD_RELOC_MMIX_GETA_3:
2683 case BFD_RELOC_MMIX_CBRANCH:
2684 case BFD_RELOC_MMIX_CBRANCH_J:
2685 case BFD_RELOC_MMIX_CBRANCH_1:
2686 case BFD_RELOC_MMIX_CBRANCH_2:
2687 case BFD_RELOC_MMIX_CBRANCH_3:
2688 case BFD_RELOC_MMIX_PUSHJ:
2689 case BFD_RELOC_MMIX_PUSHJ_1:
2690 case BFD_RELOC_MMIX_PUSHJ_2:
2691 case BFD_RELOC_MMIX_PUSHJ_3:
2692 case BFD_RELOC_MMIX_PUSHJ_STUBBABLE:
2693 case BFD_RELOC_MMIX_JMP:
2694 case BFD_RELOC_MMIX_JMP_1:
2695 case BFD_RELOC_MMIX_JMP_2:
2696 case BFD_RELOC_MMIX_JMP_3:
2697 case BFD_RELOC_MMIX_ADDR19:
2698 case BFD_RELOC_MMIX_ADDR27:
2699 code = fixP->fx_r_type;
2702 case BFD_RELOC_MMIX_REG_OR_BYTE:
2703 /* If we have this kind of relocation to an unknown symbol or to the
2704 register contents section (that is, to a register), then we can't
2705 resolve the relocation here. */
2707 && (bfd_is_und_section (addsec)
2708 || strcmp (bfd_get_section_name (addsec->owner, addsec),
2709 MMIX_REG_CONTENTS_SECTION_NAME) == 0))
2711 code = fixP->fx_r_type;
2715 /* If the relocation is not to the register section or to the
2716 absolute section (a numeric value), then we have an error. */
2718 && (S_GET_SEGMENT (addsy) != real_reg_section
2721 && ! bfd_is_abs_section (addsec))
2724 /* Set the "immediate" bit of the insn if this relocation is to Z
2725 field when the value is a numeric value, i.e. not a register. */
2726 if ((fixP->fx_where & 3) == 3
2727 && (addsy == NULL || bfd_is_abs_section (addsec)))
2728 buf[-3] |= IMM_OFFSET_BIT;
2733 case BFD_RELOC_MMIX_BASE_PLUS_OFFSET:
2735 && strcmp (bfd_get_section_name (addsec->owner, addsec),
2736 MMIX_REG_CONTENTS_SECTION_NAME) == 0)
2738 /* This changed into a register; the relocation is for the
2739 register-contents section. The constant part remains zero. */
2740 code = BFD_RELOC_MMIX_REG;
2744 /* If we've found out that this was indeed a register, then replace
2745 with the register number. The constant part is already zero.
2747 If we encounter any other defined symbol, then we must find a
2748 suitable register and emit a reloc. */
2749 if (addsy == NULL || addsec != real_reg_section)
2751 struct mmix_symbol_gregs *gregs;
2752 struct mmix_symbol_greg_fixes *fix;
2754 if (S_IS_DEFINED (addsy)
2755 && !bfd_is_com_section (addsec)
2756 && !S_IS_WEAK (addsy))
2758 if (! symbol_section_p (addsy) && ! bfd_is_abs_section (addsec))
2759 as_fatal (_("internal: BFD_RELOC_MMIX_BASE_PLUS_OFFSET not resolved to section"));
2761 /* If this is an absolute symbol sufficiently near
2762 lowest_data_loc, then we canonicalize on the data
2763 section. Note that val is signed here; we may subtract
2764 lowest_data_loc which is unsigned. Careful with those
2766 if (lowest_data_loc != (bfd_vma) -1
2767 && (bfd_vma) val + 256 > lowest_data_loc
2768 && bfd_is_abs_section (addsec))
2770 val -= (offsetT) lowest_data_loc;
2771 addsy = section_symbol (data_section);
2773 /* Likewise text section. */
2774 else if (lowest_text_loc != (bfd_vma) -1
2775 && (bfd_vma) val + 256 > lowest_text_loc
2776 && bfd_is_abs_section (addsec))
2778 val -= (offsetT) lowest_text_loc;
2779 addsy = section_symbol (text_section);
2783 gregs = *symbol_get_tc (addsy);
2785 /* If that symbol does not have any associated GREG definitions,
2786 we can't do anything. */
2788 || (fix = bsearch (&val, gregs->greg_fixes, gregs->n_gregs,
2789 sizeof (gregs->greg_fixes[0]),
2790 cmp_greg_val_greg_symbol_fixes)) == NULL
2791 /* The register must not point *after* the address we want. */
2793 /* Neither must the register point more than 255 bytes
2794 before the address we want. */
2795 || fix->offs + 255 < val)
2797 /* We can either let the linker allocate GREGs
2798 automatically, or emit an error. */
2799 if (allocate_undefined_gregs_in_linker)
2801 /* The values in baddsy and addend are right. */
2802 code = fixP->fx_r_type;
2806 as_bad_where (fixP->fx_file, fixP->fx_line,
2807 _("no suitable GREG definition for operands"));
2812 /* Transform the base-plus-offset reloc for the actual area
2813 to a reloc for the register with the address of the area.
2814 Put addend for register in Z operand. */
2815 buf[1] = val - fix->offs;
2816 code = BFD_RELOC_MMIX_REG;
2818 = (bfd_get_section_by_name (stdoutput,
2819 MMIX_REG_CONTENTS_SECTION_NAME)
2822 addend = fix->fix->fx_frag->fr_address + fix->fix->fx_where;
2825 else if (S_GET_VALUE (addsy) > 255)
2826 as_bad_where (fixP->fx_file, fixP->fx_line,
2827 _("invalid operands"));
2835 case BFD_RELOC_MMIX_REG:
2837 && (bfd_is_und_section (addsec)
2838 || strcmp (bfd_get_section_name (addsec->owner, addsec),
2839 MMIX_REG_CONTENTS_SECTION_NAME) == 0))
2841 code = fixP->fx_r_type;
2846 && (addsec != real_reg_section
2849 && ! bfd_is_und_section (addsec))
2850 /* Drop through to error message. */
2859 /* The others are supposed to be handled by md_apply_fix.
2860 FIXME: ... which isn't called when -linkrelax. Move over
2861 md_apply_fix code here for everything reasonable. */
2865 (fixP->fx_file, fixP->fx_line,
2866 _("operands were not reducible at assembly-time"));
2868 /* Unmark this symbol as used in a reloc, so we don't bump into a BFD
2869 assert when trying to output reg_section. FIXME: A gas bug. */
2870 fixP->fx_addsy = NULL;
2874 relP = (arelent *) xmalloc (sizeof (arelent));
2875 gas_assert (relP != 0);
2876 relP->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
2877 *relP->sym_ptr_ptr = baddsy;
2878 relP->address = fixP->fx_frag->fr_address + fixP->fx_where;
2880 relP->addend = addend;
2882 /* If this had been a.out, we would have had a kludge for weak symbols
2885 relP->howto = bfd_reloc_type_lookup (stdoutput, code);
2890 name = S_GET_NAME (addsy);
2892 name = _("<unknown>");
2893 as_fatal (_("cannot generate relocation type for symbol %s, code %s"),
2894 name, bfd_get_reloc_code_name (code));
2900 /* Do some reformatting of a line. FIXME: We could transform a mmixal
2901 line into traditional (GNU?) format, unless #NO_APP, and get rid of all
2902 ugly labels_without_colons etc. */
2905 mmix_handle_mmixal (void)
2908 char *s = input_line_pointer;
2912 if (pending_label != NULL)
2913 as_fatal (_("internal: unhandled label %s"), pending_label);
2915 if (mmix_gnu_syntax)
2918 /* If we're on a line with a label, check if it's a mmixal fb-label.
2919 Save an indicator and skip the label; it must be set only after all
2920 fb-labels of expressions are evaluated. */
2921 if (ISDIGIT (s[0]) && s[1] == 'H' && ISSPACE (s[2]))
2923 current_fb_label = s[0] - '0';
2925 /* We have to skip the label, but also preserve the newlineness of
2926 the previous character, since the caller checks that. It's a
2927 mess we blame on the caller. */
2930 input_line_pointer = s;
2932 while (*s && ISSPACE (*s) && ! is_end_of_line[(unsigned int) *s])
2935 /* For errors emitted here, the book-keeping is off by one; the
2936 caller is about to bump the counters. Adjust the error messages. */
2937 if (is_end_of_line[(unsigned int) *s])
2941 as_where (&name, &line);
2942 as_bad_where (name, line + 1,
2943 _("[0-9]H labels may not appear alone on a line"));
2944 current_fb_label = -1;
2950 as_where (&name, &line);
2951 as_bad_where (name, line + 1,
2952 _("[0-9]H labels do not mix with dot-pseudos"));
2953 current_fb_label = -1;
2956 /* Back off to the last space before the opcode so we don't handle
2957 the opcode as a label. */
2961 current_fb_label = -1;
2965 /* If the first character is a '.', then it's a pseudodirective, not a
2966 label. Make GAS not handle label-without-colon on this line. We
2967 also don't do mmixal-specific stuff on this line. */
2968 label_without_colon_this_line = 0;
2972 if (*s == 0 || is_end_of_line[(unsigned int) *s])
2973 /* We avoid handling empty lines here. */
2976 if (is_name_beginner (*s))
2979 /* If there is a label, skip over it. */
2980 while (*s && is_part_of_name (*s))
2983 /* Find the start of the instruction or pseudo following the label,
2986 *insn && ISSPACE (*insn) && ! is_end_of_line[(unsigned int) *insn];
2991 /* Remove a trailing ":" off labels, as they'd otherwise be considered
2992 part of the name. But don't do this for local labels. */
2993 if (s != input_line_pointer && s[-1] == ':'
2994 && (s - 2 != input_line_pointer
2995 || ! ISDIGIT (s[-2])))
2997 else if (label != NULL
2998 /* For a lone label on a line, we don't attach it to the next
2999 instruction or MMIXAL-pseudo (getting its alignment). Thus
3000 is acts like a "normal" :-ended label. Ditto if it's
3001 followed by a non-MMIXAL pseudo. */
3002 && !is_end_of_line[(unsigned int) *insn]
3005 /* For labels that don't end in ":", we save it so we can later give
3006 it the same alignment and address as the associated instruction. */
3008 /* Make room for the label including the ending nul. */
3009 int len_0 = s - label + 1;
3011 /* Save this label on the MMIX symbol obstack. Saving it on an
3012 obstack is needless for "IS"-pseudos, but it's harmless and we
3013 avoid a little code-cluttering. */
3014 obstack_grow (&mmix_sym_obstack, label, len_0);
3015 pending_label = obstack_finish (&mmix_sym_obstack);
3016 pending_label[len_0 - 1] = 0;
3019 /* If we have a non-MMIXAL pseudo, we have not business with the rest of
3024 /* Find local labels of operands. Look for "[0-9][FB]" where the
3025 characters before and after are not part of words. Break if a single
3026 or double quote is seen anywhere. It means we can't have local
3027 labels as part of list with mixed quoted and unquoted members for
3028 mmixal compatibility but we can't have it all. For the moment.
3029 Replace the '<N>B' or '<N>F' with MAGIC_FB_BACKWARD_CHAR<N> and
3030 MAGIC_FB_FORWARD_CHAR<N> respectively. */
3032 /* First make sure we don't have any of the magic characters on the line
3033 appearing as input. */
3037 if (is_end_of_line[(unsigned int) c])
3039 if (c == MAGIC_FB_BACKWARD_CHAR || c == MAGIC_FB_FORWARD_CHAR)
3040 as_bad (_("invalid characters in input"));
3043 /* Scan again, this time looking for ';' after operands. */
3046 /* Skip the insn. */
3050 && ! is_end_of_line[(unsigned int) *s])
3053 /* Skip the spaces after the insn. */
3057 && ! is_end_of_line[(unsigned int) *s])
3060 /* Skip the operands. While doing this, replace [0-9][BF] with
3061 (MAGIC_FB_BACKWARD_CHAR|MAGIC_FB_FORWARD_CHAR)[0-9]. */
3062 while ((c = *s) != 0
3065 && ! is_end_of_line[(unsigned int) c])
3071 /* FIXME: Test-case for semi-colon in string. */
3074 && (! is_end_of_line[(unsigned int) *s] || *s == ';'))
3080 else if (ISDIGIT (c))
3082 if ((s[1] != 'B' && s[1] != 'F')
3083 || is_part_of_name (s[-1])
3084 || is_part_of_name (s[2])
3085 /* Don't treat e.g. #1F as a local-label reference. */
3086 || (s != input_line_pointer && s[-1] == '#'))
3091 ? MAGIC_FB_BACKWARD_CHAR : MAGIC_FB_FORWARD_CHAR);
3099 /* Skip any spaces after the operands. */
3103 && !is_end_of_line[(unsigned int) *s])
3106 /* If we're now looking at a semi-colon, then it's an end-of-line
3108 mmix_next_semicolon_is_eoln = (*s == ';');
3110 /* Make IS into an EQU by replacing it with "= ". Only match upper-case
3111 though; let lower-case be a syntax error. */
3113 if (s[0] == 'I' && s[1] == 'S' && ISSPACE (s[2]))
3118 /* Since labels can start without ":", we have to handle "X IS 42"
3119 in full here, or "X" will be parsed as a label to be set at ".". */
3120 input_line_pointer = s;
3122 /* Right after this function ends, line numbers will be bumped if
3123 input_line_pointer[-1] = '\n'. We want accurate line numbers for
3124 the equals call, so we bump them before the call, and make sure
3125 they aren't bumped afterwards. */
3126 bump_line_counters ();
3128 /* A fb-label is valid as an IS-label. */
3129 if (current_fb_label >= 0)
3133 /* We need to save this name on our symbol obstack, since the
3134 string we got in fb_label_name is volatile and will change
3135 with every call to fb_label_name, like those resulting from
3136 parsing the IS-operand. */
3137 fb_name = fb_label_name (current_fb_label, 1);
3138 obstack_grow (&mmix_sym_obstack, fb_name, strlen (fb_name) + 1);
3139 equals (obstack_finish (&mmix_sym_obstack), 0);
3140 fb_label_instance_inc (current_fb_label);
3141 current_fb_label = -1;
3145 if (pending_label == NULL)
3146 as_bad (_("empty label field for IS"));
3148 equals (pending_label, 0);
3149 pending_label = NULL;
3152 /* For mmixal, we can have comments without a comment-start
3154 mmix_handle_rest_of_empty_line ();
3155 input_line_pointer--;
3157 input_line_pointer[-1] = ' ';
3159 else if (s[0] == 'G'
3161 && strncmp (s, "GREG", 4) == 0
3162 && (ISSPACE (s[4]) || is_end_of_line[(unsigned char) s[4]]))
3164 input_line_pointer = s + 4;
3166 /* Right after this function ends, line numbers will be bumped if
3167 input_line_pointer[-1] = '\n'. We want accurate line numbers for
3168 the s_greg call, so we bump them before the call, and make sure
3169 they aren't bumped afterwards. */
3170 bump_line_counters ();
3172 /* A fb-label is valid as a GREG-label. */
3173 if (current_fb_label >= 0)
3177 /* We need to save this name on our symbol obstack, since the
3178 string we got in fb_label_name is volatile and will change
3179 with every call to fb_label_name, like those resulting from
3180 parsing the IS-operand. */
3181 fb_name = fb_label_name (current_fb_label, 1);
3183 /* Make sure we save the canonical name and don't get bitten by
3185 obstack_1grow (&mmix_sym_obstack, ':');
3186 obstack_grow (&mmix_sym_obstack, fb_name, strlen (fb_name) + 1);
3187 mmix_greg_internal (obstack_finish (&mmix_sym_obstack));
3188 fb_label_instance_inc (current_fb_label);
3189 current_fb_label = -1;
3192 mmix_greg_internal (pending_label);
3194 /* Back up before the end-of-line marker that was skipped in
3195 mmix_greg_internal. */
3196 input_line_pointer--;
3197 input_line_pointer[-1] = ' ';
3199 pending_label = NULL;
3201 else if (pending_label != NULL)
3203 input_line_pointer += strlen (pending_label);
3205 /* See comment above about getting line numbers bumped. */
3206 input_line_pointer[-1] = '\n';
3210 /* Give the value of an fb-label rewritten as in mmix_handle_mmixal, when
3211 parsing an expression.
3213 On valid calls, input_line_pointer points at a MAGIC_FB_BACKWARD_CHAR
3214 or MAGIC_FB_BACKWARD_CHAR, followed by an ascii digit for the label.
3215 We fill in the label as an expression. */
3218 mmix_fb_label (expressionS *expP)
3221 char *fb_internal_name;
3223 /* This doesn't happen when not using mmixal syntax. */
3225 || (input_line_pointer[0] != MAGIC_FB_BACKWARD_CHAR
3226 && input_line_pointer[0] != MAGIC_FB_FORWARD_CHAR))
3229 /* The current backward reference has augmentation 0. A forward
3230 reference has augmentation 1, unless it's the same as a fb-label on
3231 _this_ line, in which case we add one more so we don't refer to it.
3232 This is the semantics of mmixal; it differs to that of common
3233 fb-labels which refer to a here-label on the current line as a
3234 backward reference. */
3236 = fb_label_name (input_line_pointer[1] - '0',
3237 (input_line_pointer[0] == MAGIC_FB_FORWARD_CHAR ? 1 : 0)
3238 + ((input_line_pointer[1] - '0' == current_fb_label
3239 && input_line_pointer[0] == MAGIC_FB_FORWARD_CHAR)
3242 input_line_pointer += 2;
3243 sym = symbol_find_or_make (fb_internal_name);
3245 /* We don't have to clean up unrelated fields here; we just do what the
3246 expr machinery does, but *not* just what it does for [0-9][fb], since
3247 we need to treat those as ordinary symbols sometimes; see testcases
3248 err-byte2.s and fb-2.s. */
3249 if (S_GET_SEGMENT (sym) == absolute_section)
3251 expP->X_op = O_constant;
3252 expP->X_add_number = S_GET_VALUE (sym);
3256 expP->X_op = O_symbol;
3257 expP->X_add_symbol = sym;
3258 expP->X_add_number = 0;
3262 /* See whether we need to force a relocation into the output file.
3263 This is used to force out switch and PC relative relocations when
3267 mmix_force_relocation (fixS *fixP)
3269 if (fixP->fx_r_type == BFD_RELOC_MMIX_LOCAL
3270 || fixP->fx_r_type == BFD_RELOC_MMIX_BASE_PLUS_OFFSET)
3276 /* All our pcrel relocations are must-keep. Note that md_apply_fix is
3277 called *after* this, and will handle getting rid of the presumed
3278 reloc; a relocation isn't *forced* other than to be handled by
3279 md_apply_fix (or tc_gen_reloc if linkrelax). */
3283 return generic_force_reloc (fixP);
3286 /* The location from which a PC relative jump should be calculated,
3287 given a PC relative reloc. */
3290 md_pcrel_from_section (fixS *fixP, segT sec)
3292 if (fixP->fx_addsy != (symbolS *) NULL
3293 && (! S_IS_DEFINED (fixP->fx_addsy)
3294 || S_GET_SEGMENT (fixP->fx_addsy) != sec))
3296 /* The symbol is undefined (or is defined but not in this section).
3297 Let the linker figure it out. */
3301 return (fixP->fx_frag->fr_address + fixP->fx_where);
3304 /* Adjust the symbol table. We make reg_section relative to the real
3305 register section. */
3308 mmix_adjust_symtab (void)
3311 symbolS *regsec = section_symbol (reg_section);
3313 for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
3314 if (S_GET_SEGMENT (sym) == reg_section)
3318 if (S_IS_EXTERNAL (sym) || symbol_used_in_reloc_p (sym))
3320 symbol_remove (sym, &symbol_rootP, &symbol_lastP);
3323 /* Change section to the *real* register section, so it gets
3324 proper treatment when writing it out. Only do this for
3325 global symbols. This also means we don't have to check for
3327 S_SET_SEGMENT (sym, real_reg_section);
3331 /* This is the expansion of LABELS_WITHOUT_COLONS.
3332 We let md_start_line_hook tweak label_without_colon_this_line, and then
3333 this function returns the tweaked value, and sets it to 1 for the next
3334 line. FIXME: Very, very brittle. Not sure it works the way I
3335 thought at the time I first wrote this. */
3338 mmix_label_without_colon_this_line (void)
3340 int retval = label_without_colon_this_line;
3342 if (! mmix_gnu_syntax)
3343 label_without_colon_this_line = 1;
3348 /* This is the expansion of md_relax_frag. We go through the ordinary
3349 relax table function except when the frag is for a GREG. Then we have
3350 to check whether there's another GREG by the same value that we can
3354 mmix_md_relax_frag (segT seg, fragS *fragP, long stretch)
3356 switch (fragP->fr_subtype)
3358 /* Growth for this type has been handled by mmix_md_end and
3359 correctly estimated, so there's nothing more to do here. */
3360 case STATE_GREG_DEF:
3363 case ENCODE_RELAX (STATE_PUSHJ, STATE_ZERO):
3365 /* We need to handle relaxation type ourselves, since relax_frag
3366 doesn't update fr_subtype if there's no size increase in the
3367 current section; when going from plain PUSHJ to a stub. This
3368 is otherwise functionally the same as relax_frag in write.c,
3369 simplified for this case. */
3374 target = fragP->fr_offset;
3375 address = fragP->fr_address;
3376 symbolP = fragP->fr_symbol;
3382 sym_frag = symbol_get_frag (symbolP);
3383 know (S_GET_SEGMENT (symbolP) != absolute_section
3384 || sym_frag == &zero_address_frag);
3385 target += S_GET_VALUE (symbolP);
3387 /* If frag has yet to be reached on this pass, assume it will
3388 move by STRETCH just as we did. If this is not so, it will
3389 be because some frag between grows, and that will force
3393 && sym_frag->relax_marker != fragP->relax_marker
3394 && S_GET_SEGMENT (symbolP) == seg)
3398 aim = target - address - fragP->fr_fix;
3399 if (aim >= PUSHJ_0B && aim <= PUSHJ_0F)
3401 /* Target is reachable with a PUSHJ. */
3402 segment_info_type *seginfo = seg_info (seg);
3404 /* If we're at the end of a relaxation round, clear the stub
3405 counter as initialization for the next round. */
3406 if (fragP == seginfo->tc_segment_info_data.last_stubfrag)
3407 seginfo->tc_segment_info_data.nstubs = 0;
3411 /* Not reachable. Try a stub. */
3412 fragP->fr_subtype = ENCODE_RELAX (STATE_PUSHJSTUB, STATE_ZERO);
3416 /* See if this PUSHJ is redirectable to a stub. */
3417 case ENCODE_RELAX (STATE_PUSHJSTUB, STATE_ZERO):
3419 segment_info_type *seginfo = seg_info (seg);
3420 fragS *lastfrag = seginfo->frchainP->frch_last;
3421 relax_substateT prev_type = fragP->fr_subtype;
3423 /* The last frag is always an empty frag, so it suffices to look
3424 at its address to know the ending address of this section. */
3425 know (lastfrag->fr_type == rs_fill
3426 && lastfrag->fr_fix == 0
3427 && lastfrag->fr_var == 0);
3429 /* For this PUSHJ to be relaxable into a call to a stub, the
3430 distance must be no longer than 256k bytes from the PUSHJ to
3431 the end of the section plus the maximum size of stubs so far. */
3432 if ((lastfrag->fr_address
3434 + PUSHJ_MAX_LEN * seginfo->tc_segment_info_data.nstubs)
3435 - (fragP->fr_address + fragP->fr_fix)
3438 fragP->fr_subtype = mmix_relax_table[prev_type].rlx_more;
3440 seginfo->tc_segment_info_data.nstubs++;
3442 /* If we're at the end of a relaxation round, clear the stub
3443 counter as initialization for the next round. */
3444 if (fragP == seginfo->tc_segment_info_data.last_stubfrag)
3445 seginfo->tc_segment_info_data.nstubs = 0;
3448 (mmix_relax_table[fragP->fr_subtype].rlx_length
3449 - mmix_relax_table[prev_type].rlx_length);
3452 case ENCODE_RELAX (STATE_PUSHJ, STATE_MAX):
3454 segment_info_type *seginfo = seg_info (seg);
3456 /* Need to cover all STATE_PUSHJ states to act on the last stub
3457 frag (the end of this relax round; initialization for the
3459 if (fragP == seginfo->tc_segment_info_data.last_stubfrag)
3460 seginfo->tc_segment_info_data.nstubs = 0;
3466 return relax_frag (seg, fragP, stretch);
3468 case STATE_GREG_UNDF:
3469 BAD_CASE (fragP->fr_subtype);
3472 as_fatal (_("internal: unexpected relax type %d:%d"),
3473 fragP->fr_type, fragP->fr_subtype);
3477 /* Various things we punt until all input is seen. */
3485 struct loc_assert_s *loc_assert;
3488 /* The first frag of GREG:s going into the register contents section. */
3489 fragS *mmix_reg_contents_frags = NULL;
3491 /* Reset prefix. All labels reachable at this point must be
3493 mmix_current_prefix = NULL;
3496 as_bad_where (bspec_file, bspec_line, _("BSPEC without ESPEC."));
3498 /* Emit the low LOC setting of .text. */
3499 if (text_has_contents && lowest_text_loc != (bfd_vma) -1)
3502 char locsymbol[sizeof (":") - 1
3503 + sizeof (MMIX_LOC_SECTION_START_SYMBOL_PREFIX) - 1
3504 + sizeof (".text")];
3506 /* An exercise in non-ISO-C-ness, this one. */
3507 sprintf (locsymbol, ":%s%s", MMIX_LOC_SECTION_START_SYMBOL_PREFIX,
3510 = symbol_new (locsymbol, absolute_section, lowest_text_loc,
3511 &zero_address_frag);
3512 S_SET_EXTERNAL (symbolP);
3516 if (data_has_contents && lowest_data_loc != (bfd_vma) -1)
3519 char locsymbol[sizeof (":") - 1
3520 + sizeof (MMIX_LOC_SECTION_START_SYMBOL_PREFIX) - 1
3521 + sizeof (".data")];
3523 sprintf (locsymbol, ":%s%s", MMIX_LOC_SECTION_START_SYMBOL_PREFIX,
3526 = symbol_new (locsymbol, absolute_section, lowest_data_loc,
3527 &zero_address_frag);
3528 S_SET_EXTERNAL (symbolP);
3531 /* Unless GNU syntax mode, set "Main" to be a function, so the
3532 disassembler doesn't get confused when we write truly
3533 mmixal-compatible code (and don't use .type). Similarly set it
3534 global (regardless of -globalize-symbols), so the linker sees it as
3535 the start symbol in ELF mode. */
3536 mainsym = symbol_find (MMIX_START_SYMBOL_NAME);
3537 if (mainsym != NULL && ! mmix_gnu_syntax)
3539 symbol_get_bfdsym (mainsym)->flags |= BSF_FUNCTION;
3540 S_SET_EXTERNAL (mainsym);
3543 /* Check that we didn't LOC into the unknown, or rather that when it
3544 was unknown, we actually change sections. */
3545 for (loc_assert = loc_asserts;
3547 loc_assert = loc_assert->next)
3551 resolve_symbol_value (loc_assert->loc_sym);
3552 actual_seg = S_GET_SEGMENT (loc_assert->loc_sym);
3553 if (actual_seg != loc_assert->old_seg)
3557 int e_valid = expr_symbol_where (loc_assert->loc_sym, &fnam, &line);
3559 gas_assert (e_valid == 1);
3560 as_bad_where (fnam, line,
3561 _("LOC to section unknown or indeterminable "
3566 if (n_of_raw_gregs != 0)
3568 /* Emit GREGs. They are collected in order of appearance, but must
3569 be emitted in opposite order to both have section address regno*8
3570 and the same allocation order (within a file) as mmixal. */
3571 segT this_segment = now_seg;
3572 subsegT this_subsegment = now_subseg;
3574 regsec = bfd_make_section_old_way (stdoutput,
3575 MMIX_REG_CONTENTS_SECTION_NAME);
3576 subseg_set (regsec, 0);
3578 /* Finally emit the initialization-value. Emit a variable frag, which
3579 we'll fix in md_estimate_size_before_relax. We set the initializer
3580 for the tc_frag_data field to NULL, so we can use that field for
3581 relaxation purposes. */
3582 mmix_opcode_frag = NULL;
3585 mmix_reg_contents_frags = frag_now;
3587 for (i = n_of_raw_gregs - 1; i >= 0; i--)
3589 if (mmix_raw_gregs[i].label != NULL)
3590 /* There's a symbol. Let it refer to this location in the
3591 register contents section. The symbol must be globalized
3593 colon (mmix_raw_gregs[i].label);
3595 frag_var (rs_machine_dependent, 8, 0, STATE_GREG_UNDF,
3596 make_expr_symbol (&mmix_raw_gregs[i].exp), 0, NULL);
3599 subseg_set (this_segment, this_subsegment);
3602 regsec = bfd_get_section_by_name (stdoutput, MMIX_REG_CONTENTS_SECTION_NAME);
3603 /* Mark the section symbol as being OK for a reloc. */
3605 regsec->symbol->flags |= BSF_KEEP;
3607 /* Iterate over frags resulting from GREGs and move those that evidently
3608 have the same value together and point one to another.
3610 This works in time O(N^2) but since the upper bound for non-error use
3611 is 223, it's best to keep this simpler algorithm. */
3612 for (fragP = mmix_reg_contents_frags; fragP != NULL; fragP = fragP->fr_next)
3619 symbolS *symbolP = fragP->fr_symbol;
3621 if (fragP->fr_type != rs_machine_dependent
3622 || fragP->fr_subtype != STATE_GREG_UNDF)
3625 /* Whatever the outcome, we will have this GREG judged merged or
3626 non-merged. Since the tc_frag_data is NULL at this point, we
3627 default to non-merged. */
3628 fragP->fr_subtype = STATE_GREG_DEF;
3630 /* If we're not supposed to merge GREG definitions, then just don't
3631 look for equivalents. */
3635 osymval = (offsetT) S_GET_VALUE (symbolP);
3636 osymfrag = symbol_get_frag (symbolP);
3638 /* If the symbol isn't defined, we can't say that another symbol
3639 equals this frag, then. FIXME: We can look at the "deepest"
3640 defined name; if a = c and b = c then obviously a == b. */
3641 if (! S_IS_DEFINED (symbolP))
3644 oexpP = symbol_get_value_expression (fragP->fr_symbol);
3646 /* If the initialization value is zero, then we must not merge them. */
3647 if (oexpP->X_op == O_constant && osymval == 0)
3650 /* Iterate through the frags downward this one. If we find one that
3651 has the same non-zero value, move it to after this one and point
3652 to it as the equivalent. */
3653 for (fpp = &fragP->fr_next; *fpp != NULL; fpp = &fpp[0]->fr_next)
3657 if (fp->fr_type != rs_machine_dependent
3658 || fp->fr_subtype != STATE_GREG_UNDF)
3661 /* Calling S_GET_VALUE may simplify the symbol, changing from
3662 expr_section etc. so call it first. */
3663 if ((offsetT) S_GET_VALUE (fp->fr_symbol) == osymval
3664 && symbol_get_frag (fp->fr_symbol) == osymfrag)
3666 /* Move the frag links so the one we found equivalent comes
3667 after the current one, carefully considering that
3668 sometimes fpp == &fragP->fr_next and the moves must be a
3671 fp->fr_next = fragP->fr_next;
3672 fragP->fr_next = fp;
3678 fragP->tc_frag_data = fp;
3682 /* qsort function for mmix_symbol_gregs. */
3685 cmp_greg_symbol_fixes (const void *parg, const void *qarg)
3687 const struct mmix_symbol_greg_fixes *p
3688 = (const struct mmix_symbol_greg_fixes *) parg;
3689 const struct mmix_symbol_greg_fixes *q
3690 = (const struct mmix_symbol_greg_fixes *) qarg;
3692 return p->offs > q->offs ? 1 : p->offs < q->offs ? -1 : 0;
3695 /* Collect GREG definitions from mmix_gregs and hang them as lists sorted
3696 on increasing offsets onto each section symbol or undefined symbol.
3698 Also, remove the register convenience section so it doesn't get output
3699 as an ELF section. */
3702 mmix_frob_file (void)
3705 struct mmix_symbol_gregs *all_greg_symbols[MAX_GREGS];
3706 int n_greg_symbols = 0;
3708 /* Collect all greg fixups and decorate each corresponding symbol with
3709 the greg fixups for it. */
3710 for (i = 0; i < n_of_cooked_gregs; i++)
3714 struct mmix_symbol_gregs *gregs;
3717 fixP = mmix_gregs[i];
3718 know (fixP->fx_r_type == BFD_RELOC_64);
3720 /* This case isn't doable in general anyway, methinks. */
3721 if (fixP->fx_subsy != NULL)
3723 as_bad_where (fixP->fx_file, fixP->fx_line,
3724 _("GREG expression too complicated"));
3728 sym = fixP->fx_addsy;
3729 offs = (offsetT) fixP->fx_offset;
3731 /* If the symbol is defined, then it must be resolved to a section
3732 symbol at this time, or else we don't know how to handle it. */
3733 if (S_IS_DEFINED (sym)
3734 && !bfd_is_com_section (S_GET_SEGMENT (sym))
3735 && !S_IS_WEAK (sym))
3737 if (! symbol_section_p (sym)
3738 && ! bfd_is_abs_section (S_GET_SEGMENT (sym)))
3739 as_fatal (_("internal: GREG expression not resolved to section"));
3741 offs += S_GET_VALUE (sym);
3744 /* If this is an absolute symbol sufficiently near lowest_data_loc,
3745 then we canonicalize on the data section. Note that offs is
3746 signed here; we may subtract lowest_data_loc which is unsigned.
3747 Careful with those comparisons. */
3748 if (lowest_data_loc != (bfd_vma) -1
3749 && (bfd_vma) offs + 256 > lowest_data_loc
3750 && bfd_is_abs_section (S_GET_SEGMENT (sym)))
3752 offs -= (offsetT) lowest_data_loc;
3753 sym = section_symbol (data_section);
3755 /* Likewise text section. */
3756 else if (lowest_text_loc != (bfd_vma) -1
3757 && (bfd_vma) offs + 256 > lowest_text_loc
3758 && bfd_is_abs_section (S_GET_SEGMENT (sym)))
3760 offs -= (offsetT) lowest_text_loc;
3761 sym = section_symbol (text_section);
3764 gregs = *symbol_get_tc (sym);
3768 gregs = xmalloc (sizeof (*gregs));
3770 symbol_set_tc (sym, &gregs);
3771 all_greg_symbols[n_greg_symbols++] = gregs;
3774 gregs->greg_fixes[gregs->n_gregs].fix = fixP;
3775 gregs->greg_fixes[gregs->n_gregs++].offs = offs;
3778 /* For each symbol having a GREG definition, sort those definitions on
3780 for (i = 0; i < n_greg_symbols; i++)
3781 qsort (all_greg_symbols[i]->greg_fixes, all_greg_symbols[i]->n_gregs,
3782 sizeof (all_greg_symbols[i]->greg_fixes[0]), cmp_greg_symbol_fixes);
3784 if (real_reg_section != NULL)
3786 /* FIXME: Pass error state gracefully. */
3787 if (bfd_get_section_flags (stdoutput, real_reg_section) & SEC_HAS_CONTENTS)
3788 as_fatal (_("register section has contents\n"));
3790 bfd_section_list_remove (stdoutput, real_reg_section);
3791 --stdoutput->section_count;
3796 /* Provide an expression for a built-in name provided when-used.
3797 Either a symbol that is a handler; living in 0x10*[1..8] and having
3798 name [DVWIOUZX]_Handler, or a mmixal built-in symbol.
3800 If the name isn't a built-in name and parsed into *EXPP, return zero. */
3803 mmix_parse_predefined_name (char *name, expressionS *expP)
3806 char *handler_charp;
3807 const char handler_chars[] = "DVWIOUZX";
3810 if (! predefined_syms)
3813 canon_name = tc_canonicalize_symbol_name (name);
3815 if (canon_name[1] == '_'
3816 && strcmp (canon_name + 2, "Handler") == 0
3817 && (handler_charp = strchr (handler_chars, *canon_name)) != NULL)
3819 /* If the symbol doesn't exist, provide one relative to the .text
3822 FIXME: We should provide separate sections, mapped in the linker
3824 symp = symbol_find (name);
3826 symp = symbol_new (name, text_section,
3827 0x10 * (handler_charp + 1 - handler_chars),
3828 &zero_address_frag);
3832 /* These symbols appear when referenced; needed for
3833 mmixal-compatible programs. */
3840 } predefined_abs_syms[] =
3842 {"Data_Segment", (valueT) 0x20 << 56},
3843 {"Pool_Segment", (valueT) 0x40 << 56},
3844 {"Stack_Segment", (valueT) 0x60 << 56},
3852 {"BinaryReadWrite", 4},
3875 /* If it's already in the symbol table, we shouldn't do anything. */
3876 symp = symbol_find (name);
3881 i < sizeof (predefined_abs_syms) / sizeof (predefined_abs_syms[0]);
3883 if (strcmp (canon_name, predefined_abs_syms[i].name) == 0)
3885 symbol_table_insert (symbol_new (predefined_abs_syms[i].name,
3887 predefined_abs_syms[i].val,
3888 &zero_address_frag));
3890 /* Let gas find the symbol we just created, through its
3895 /* Not one of those symbols. Let gas handle it. */
3899 expP->X_op = O_symbol;
3900 expP->X_add_number = 0;
3901 expP->X_add_symbol = symp;
3902 expP->X_op_symbol = NULL;
3907 /* Just check that we don't have a BSPEC/ESPEC pair active when changing
3908 sections "normally", and get knowledge about alignment from the new
3912 mmix_md_elf_section_change_hook (void)
3915 as_bad (_("section change from within a BSPEC/ESPEC pair is not supported"));
3917 last_alignment = bfd_get_section_alignment (now_seg->owner, now_seg);
3921 /* The LOC worker. This is like s_org, but we have to support changing
3925 s_loc (int ignore ATTRIBUTE_UNUSED)
3933 /* Must not have a BSPEC in progress. */
3936 as_bad (_("directive LOC from within a BSPEC/ESPEC pair is not supported"));
3940 section = expression (&exp);
3942 if (exp.X_op == O_illegal
3943 || exp.X_op == O_absent
3944 || exp.X_op == O_big)
3946 as_bad (_("invalid LOC expression"));
3950 if (section == undefined_section)
3952 /* This is an error or a LOC with an expression involving
3953 forward references. For the expression to be correctly
3954 evaluated, we need to force a proper symbol; gas loses track
3955 of the segment for "local symbols". */
3956 if (exp.X_op == O_add)
3958 symbol_get_value_expression (exp.X_op_symbol);
3959 symbol_get_value_expression (exp.X_add_symbol);
3963 gas_assert (exp.X_op == O_symbol);
3964 symbol_get_value_expression (exp.X_add_symbol);
3968 if (section == absolute_section)
3970 /* Translate a constant into a suitable section. */
3972 if (exp.X_add_number < ((offsetT) 0x20 << 56))
3974 /* Lower than Data_Segment or in the reserved area (the
3975 segment number is >= 0x80, appearing negative) - assume
3977 section = text_section;
3979 /* Save the lowest seen location, so we can pass on this
3980 information to the linker. We don't actually org to this
3981 location here, we just pass on information to the linker so
3982 it can put the code there for us. */
3984 /* If there was already a loc (that has to be set lower than
3985 this one), we org at (this - lower). There's an implicit
3986 "LOC 0" before any entered code. FIXME: handled by spurious
3987 settings of text_has_contents. */
3988 if (lowest_text_loc != (bfd_vma) -1
3989 && (bfd_vma) exp.X_add_number < lowest_text_loc)
3991 as_bad (_("LOC expression stepping backwards is not supported"));
3992 exp.X_op = O_absent;
3996 if (text_has_contents && lowest_text_loc == (bfd_vma) -1)
3997 lowest_text_loc = 0;
3999 if (lowest_text_loc == (bfd_vma) -1)
4001 lowest_text_loc = exp.X_add_number;
4003 /* We want only to change the section, not set an offset. */
4004 exp.X_op = O_absent;
4007 exp.X_add_number -= lowest_text_loc;
4012 /* Do the same for the .data section, except we don't have
4013 to worry about exp.X_add_number carrying a sign. */
4014 section = data_section;
4016 if (exp.X_add_number < (offsetT) lowest_data_loc)
4018 as_bad (_("LOC expression stepping backwards is not supported"));
4019 exp.X_op = O_absent;
4023 if (data_has_contents && lowest_data_loc == (bfd_vma) -1)
4024 lowest_data_loc = (bfd_vma) 0x20 << 56;
4026 if (lowest_data_loc == (bfd_vma) -1)
4028 lowest_data_loc = exp.X_add_number;
4030 /* We want only to change the section, not set an offset. */
4031 exp.X_op = O_absent;
4034 exp.X_add_number -= lowest_data_loc;
4039 /* If we can't deduce the section, it must be the current one.
4040 Below, we arrange to assert this. */
4041 if (section != now_seg && section != undefined_section)
4043 obj_elf_section_change_hook ();
4044 subseg_set (section, 0);
4046 /* Call our section change hooks using the official hook. */
4047 md_elf_section_change_hook ();
4050 if (exp.X_op != O_absent)
4052 symbolS *esym = NULL;
4054 if (exp.X_op != O_constant && exp.X_op != O_symbol)
4056 /* Handle complex expressions. */
4057 esym = sym = make_expr_symbol (&exp);
4062 sym = exp.X_add_symbol;
4063 off = exp.X_add_number;
4065 if (section == undefined_section)
4067 /* We need an expr_symbol when tracking sections. In
4068 order to make this an expr_symbol with file and line
4069 tracked, we have to make the exp non-trivial; not an
4070 O_symbol with .X_add_number == 0. The constant part
4072 exp.X_add_number = 1;
4073 esym = make_expr_symbol (&exp);
4077 /* Track the LOC's where we couldn't deduce the section: assert
4078 that we weren't supposed to change section. */
4079 if (section == undefined_section)
4081 struct loc_assert_s *next = loc_asserts;
4083 = (struct loc_assert_s *) xmalloc (sizeof (*loc_asserts));
4084 loc_asserts->next = next;
4085 loc_asserts->old_seg = now_seg;
4086 loc_asserts->loc_sym = esym;
4089 p = frag_var (rs_org, 1, 1, (relax_substateT) 0, sym, off, (char *) 0);
4093 mmix_handle_rest_of_empty_line ();
4096 /* The BYTE worker. We have to support sequences of mixed "strings",
4097 numbers and other constant "first-pass" reducible expressions separated
4105 if (now_seg == text_section)
4106 text_has_contents = 1;
4107 else if (now_seg == data_section)
4108 data_has_contents = 1;
4113 switch (*input_line_pointer)
4116 ++input_line_pointer;
4117 while (is_a_char (c = next_char_of_string ()))
4119 FRAG_APPEND_1_CHAR (c);
4122 if (input_line_pointer[-1] != '\"')
4124 /* We will only get here in rare cases involving #NO_APP,
4125 where the unterminated string is not recognized by the
4126 preformatting pass. */
4127 as_bad (_("unterminated string"));
4128 mmix_discard_rest_of_line ();
4136 segT expseg = expression (&exp);
4138 /* We have to allow special register names as constant numbers. */
4139 if ((expseg != absolute_section && expseg != reg_section)
4140 || (exp.X_op != O_constant
4141 && (exp.X_op != O_register
4142 || exp.X_add_number <= 255)))
4144 as_bad (_("BYTE expression not a pure number"));
4145 mmix_discard_rest_of_line ();
4148 else if ((exp.X_add_number > 255 && exp.X_op != O_register)
4149 || exp.X_add_number < 0)
4151 /* Note that mmixal does not allow negative numbers in
4152 BYTE sequences, so neither should we. */
4153 as_bad (_("BYTE expression not in the range 0..255"));
4154 mmix_discard_rest_of_line ();
4158 FRAG_APPEND_1_CHAR (exp.X_add_number);
4164 c = *input_line_pointer++;
4168 input_line_pointer--;
4170 if (mmix_gnu_syntax)
4171 demand_empty_rest_of_line ();
4174 mmix_discard_rest_of_line ();
4175 /* Do like demand_empty_rest_of_line and step over the end-of-line
4177 input_line_pointer++;
4180 /* Make sure we align for the next instruction. */
4184 /* Like cons_worker, but we have to ignore "naked comments", not barf on
4185 them. Implements WYDE, TETRA and OCTA. We're a little bit more
4186 lenient than mmix_byte but FIXME: they should eventually merge. */
4189 mmix_cons (int nbytes)
4193 /* If we don't have any contents, then it's ok to have a specified start
4194 address that is not a multiple of the max data size. We will then
4195 align it as necessary when we get here. Otherwise, it's a fatal sin. */
4196 if (now_seg == text_section)
4198 if (lowest_text_loc != (bfd_vma) -1
4199 && (lowest_text_loc & (nbytes - 1)) != 0)
4201 if (text_has_contents)
4202 as_bad (_("data item with alignment larger than location"));
4203 else if (want_unaligned)
4204 as_bad (_("unaligned data at an absolute location is not supported"));
4206 lowest_text_loc &= ~((bfd_vma) nbytes - 1);
4207 lowest_text_loc += (bfd_vma) nbytes;
4210 text_has_contents = 1;
4212 else if (now_seg == data_section)
4214 if (lowest_data_loc != (bfd_vma) -1
4215 && (lowest_data_loc & (nbytes - 1)) != 0)
4217 if (data_has_contents)
4218 as_bad (_("data item with alignment larger than location"));
4219 else if (want_unaligned)
4220 as_bad (_("unaligned data at an absolute location is not supported"));
4222 lowest_data_loc &= ~((bfd_vma) nbytes - 1);
4223 lowest_data_loc += (bfd_vma) nbytes;
4226 data_has_contents = 1;
4229 /* Always align these unless asked not to (valid for the current pseudo). */
4230 if (! want_unaligned)
4232 last_alignment = nbytes == 2 ? 1 : (nbytes == 4 ? 2 : 3);
4233 frag_align (last_alignment, 0, 0);
4234 record_alignment (now_seg, last_alignment);
4237 /* For mmixal compatibility, a label for an instruction (and emitting
4238 pseudo) refers to the _aligned_ address. So we have to emit the
4240 if (current_fb_label >= 0)
4241 colon (fb_label_name (current_fb_label, 1));
4242 else if (pending_label != NULL)
4244 colon (pending_label);
4245 pending_label = NULL;
4250 if (is_end_of_line[(unsigned int) *input_line_pointer])
4252 /* Default to zero if the expression was absent. */
4254 exp.X_op = O_constant;
4255 exp.X_add_number = 0;
4257 exp.X_add_symbol = NULL;
4258 exp.X_op_symbol = NULL;
4259 emit_expr (&exp, (unsigned int) nbytes);
4266 switch (*input_line_pointer)
4268 /* We support strings here too; each character takes up nbytes
4271 ++input_line_pointer;
4272 while (is_a_char (c = next_char_of_string ()))
4274 exp.X_op = O_constant;
4275 exp.X_add_number = c;
4277 emit_expr (&exp, (unsigned int) nbytes);
4280 if (input_line_pointer[-1] != '\"')
4282 /* We will only get here in rare cases involving #NO_APP,
4283 where the unterminated string is not recognized by the
4284 preformatting pass. */
4285 as_bad (_("unterminated string"));
4286 mmix_discard_rest_of_line ();
4294 emit_expr (&exp, (unsigned int) nbytes);
4300 while (*input_line_pointer++ == ',');
4302 input_line_pointer--; /* Put terminator back into stream. */
4304 mmix_handle_rest_of_empty_line ();
4306 /* We don't need to step up the counter for the current_fb_label here;
4307 that's handled by the caller. */
4310 /* The md_do_align worker. At present, we just record an alignment to
4311 nullify the automatic alignment we do for WYDE, TETRA and OCTA, as gcc
4312 does not use the unaligned macros when attribute packed is used.
4313 Arguably this is a GCC bug. */
4316 mmix_md_do_align (int n, char *fill ATTRIBUTE_UNUSED,
4317 int len ATTRIBUTE_UNUSED, int max ATTRIBUTE_UNUSED)
4320 want_unaligned = n == 0;