1 /* tc-mmix.c -- Assembler for Don Knuth's MMIX.
2 Copyright (C) 2001, 2002, 2003 Free Software Foundation.
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 2, 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, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, 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. */
35 #include "opcode/mmix.h"
36 #include "safe-ctype.h"
37 #include "dwarf2dbg.h"
40 /* Something to describe what we need to do with a fixup before output,
41 for example assert something of what it became or make a relocation. */
43 enum mmix_fixup_action
47 mmix_fixup_register_or_adjust_for_byte
50 static int get_spec_regno
PARAMS ((char *));
51 static int get_operands
PARAMS ((int, char *, expressionS
[]));
52 static int get_putget_operands
53 PARAMS ((struct mmix_opcode
*, char *, expressionS
[]));
54 static void s_prefix
PARAMS ((int));
55 static void s_greg
PARAMS ((int));
56 static void s_loc
PARAMS ((int));
57 static void s_bspec
PARAMS ((int));
58 static void s_espec
PARAMS ((int));
59 static void mmix_s_local
PARAMS ((int));
60 static void mmix_greg_internal
PARAMS ((char *));
61 static void mmix_set_geta_branch_offset
PARAMS ((char *, offsetT value
));
62 static void mmix_set_jmp_offset
PARAMS ((char *, offsetT
));
63 static void mmix_fill_nops
PARAMS ((char *, int));
64 static int cmp_greg_symbol_fixes
PARAMS ((const PTR
, const PTR
));
65 static int cmp_greg_val_greg_symbol_fixes
66 PARAMS ((const PTR p1
, const PTR p2
));
67 static void mmix_handle_rest_of_empty_line
PARAMS ((void));
68 static void mmix_discard_rest_of_line
PARAMS ((void));
69 static void mmix_byte
PARAMS ((void));
70 static void mmix_cons
PARAMS ((int));
72 /* Continue the tradition of symbols.c; use control characters to enforce
73 magic. These are used when replacing e.g. 8F and 8B so we can handle
74 such labels correctly with the common parser hooks. */
75 #define MAGIC_FB_BACKWARD_CHAR '\003'
76 #define MAGIC_FB_FORWARD_CHAR '\004'
78 /* Copy the location of a frag to a fix. */
79 #define COPY_FR_WHERE_TO_FX(FRAG, FIX) \
82 (FIX)->fx_file = (FRAG)->fr_file; \
83 (FIX)->fx_line = (FRAG)->fr_line; \
87 const char *md_shortopts
= "x";
88 static int current_fb_label
= -1;
89 static char *pending_label
= NULL
;
91 static bfd_vma lowest_text_loc
= (bfd_vma
) -1;
92 static int text_has_contents
= 0;
94 /* The alignment of the previous instruction, and a boolean for whether we
95 want to avoid aligning the next WYDE, TETRA, OCTA or insn. */
96 static int last_alignment
= 0;
97 static int want_unaligned
= 0;
99 static bfd_vma lowest_data_loc
= (bfd_vma
) -1;
100 static int data_has_contents
= 0;
102 /* The fragS of the instruction being assembled. Only valid from within
104 fragS
*mmix_opcode_frag
= NULL
;
106 /* Raw GREGs as appearing in input. These may be fewer than the number
108 static int n_of_raw_gregs
= 0;
113 } mmix_raw_gregs
[MAX_GREGS
];
115 /* Fixups for all unique GREG registers. We store the fixups here in
116 md_convert_frag, then we use the array to convert
117 BFD_RELOC_MMIX_BASE_PLUS_OFFSET fixups in tc_gen_reloc. The index is
118 just a running number and is not supposed to be correlated to a
120 static fixS
*mmix_gregs
[MAX_GREGS
];
121 static int n_of_cooked_gregs
= 0;
123 /* Pointing to the register section we use for output. */
124 static asection
*real_reg_section
;
126 /* For each symbol; unknown or section symbol, we keep a list of GREG
127 definitions sorted on increasing offset. It seems no use keeping count
128 to allocate less room than the maximum number of gregs when we've found
129 one for a section or symbol. */
130 struct mmix_symbol_gregs
133 struct mmix_symbol_greg_fixes
137 /* A signed type, since we may have GREGs pointing slightly before the
138 contents of a section. */
140 } greg_fixes
[MAX_GREGS
];
143 /* Should read insert a colon on something that starts in column 0 on
145 static int label_without_colon_this_line
= 1;
147 /* Should we automatically expand instructions into multiple insns in
148 order to generate working code? */
149 static int expand_op
= 1;
151 /* Should we warn when expanding operands? FIXME: test-cases for when -x
153 static int warn_on_expansion
= 1;
155 /* Should we merge non-zero GREG register definitions? */
156 static int merge_gregs
= 1;
158 /* Should we pass on undefined BFD_RELOC_MMIX_BASE_PLUS_OFFSET relocs
159 (missing suitable GREG definitions) to the linker? */
160 static int allocate_undefined_gregs_in_linker
= 0;
162 /* Should we emit built-in symbols? */
163 static int predefined_syms
= 1;
165 /* Should we allow anything but the listed special register name
166 (e.g. equated symbols)? */
167 static int equated_spec_regs
= 1;
169 /* Do we require standard GNU syntax? */
170 int mmix_gnu_syntax
= 0;
172 /* Do we globalize all symbols? */
173 int mmix_globalize_symbols
= 0;
175 /* When expanding insns, do we want to expand PUSHJ as a call to a stub
176 (or else as a series of insns)? */
179 /* Do we know that the next semicolon is at the end of the operands field
180 (in mmixal mode; constant 1 in GNU mode)? */
181 int mmix_next_semicolon_is_eoln
= 1;
183 /* Do we have a BSPEC in progress? */
184 static int doing_bspec
= 0;
185 static char *bspec_file
;
186 static unsigned int bspec_line
;
188 struct option md_longopts
[] =
190 #define OPTION_RELAX (OPTION_MD_BASE)
191 #define OPTION_NOEXPAND (OPTION_RELAX + 1)
192 #define OPTION_NOMERGEGREG (OPTION_NOEXPAND + 1)
193 #define OPTION_NOSYMS (OPTION_NOMERGEGREG + 1)
194 #define OPTION_GNU_SYNTAX (OPTION_NOSYMS + 1)
195 #define OPTION_GLOBALIZE_SYMBOLS (OPTION_GNU_SYNTAX + 1)
196 #define OPTION_FIXED_SPEC_REGS (OPTION_GLOBALIZE_SYMBOLS + 1)
197 #define OPTION_LINKER_ALLOCATED_GREGS (OPTION_FIXED_SPEC_REGS + 1)
198 #define OPTION_NOPUSHJSTUBS (OPTION_LINKER_ALLOCATED_GREGS + 1)
199 {"linkrelax", no_argument
, NULL
, OPTION_RELAX
},
200 {"no-expand", no_argument
, NULL
, OPTION_NOEXPAND
},
201 {"no-merge-gregs", no_argument
, NULL
, OPTION_NOMERGEGREG
},
202 {"no-predefined-syms", no_argument
, NULL
, OPTION_NOSYMS
},
203 {"gnu-syntax", no_argument
, NULL
, OPTION_GNU_SYNTAX
},
204 {"globalize-symbols", no_argument
, NULL
, OPTION_GLOBALIZE_SYMBOLS
},
205 {"fixed-special-register-names", no_argument
, NULL
,
206 OPTION_FIXED_SPEC_REGS
},
207 {"linker-allocated-gregs", no_argument
, NULL
,
208 OPTION_LINKER_ALLOCATED_GREGS
},
209 {"no-pushj-stubs", no_argument
, NULL
, OPTION_NOPUSHJSTUBS
},
210 {"no-stubs", no_argument
, NULL
, OPTION_NOPUSHJSTUBS
},
211 {NULL
, no_argument
, NULL
, 0}
214 size_t md_longopts_size
= sizeof (md_longopts
);
216 static struct hash_control
*mmix_opcode_hash
;
218 /* We use these when implementing the PREFIX pseudo. */
219 char *mmix_current_prefix
;
220 struct obstack mmix_sym_obstack
;
223 /* For MMIX, we encode the relax_substateT:s (in e.g. fr_substate) as one
224 bit length, and the relax-type shifted on top of that. There seems to
225 be no point in making the relaxation more fine-grained; the linker does
226 that better and we might interfere by changing non-optimal relaxations
227 into other insns that cannot be relaxed as easily.
229 Groups for MMIX relaxing:
232 extra length: zero or three insns.
235 extra length: zero or five insns.
238 extra length: zero or four insns.
239 Special handling to deal with transition to PUSHJSTUB.
242 extra length: zero or four insns.
245 special handling, allocates a named global register unless another
246 is within reach for all uses.
249 special handling (mostly) for external references; assumes the
250 linker will generate a stub if target is no longer than 256k from
251 the end of the section plus max size of previous stubs. Zero or
254 #define STATE_GETA (1)
255 #define STATE_BCC (2)
256 #define STATE_PUSHJ (3)
257 #define STATE_JMP (4)
258 #define STATE_GREG (5)
259 #define STATE_PUSHJSTUB (6)
261 /* No fine-grainedness here. */
262 #define STATE_LENGTH_MASK (1)
264 #define STATE_ZERO (0)
265 #define STATE_MAX (1)
267 /* More descriptive name for convenience. */
268 /* FIXME: We should start on something different, not MAX. */
269 #define STATE_UNDF STATE_MAX
271 /* FIXME: For GREG, we must have other definitions; UNDF == MAX isn't
272 appropriate; we need it the other way round. This value together with
273 fragP->tc_frag_data shows what state the frag is in: tc_frag_data
274 non-NULL means 0, NULL means 8 bytes. */
275 #define STATE_GREG_UNDF ENCODE_RELAX (STATE_GREG, STATE_ZERO)
276 #define STATE_GREG_DEF ENCODE_RELAX (STATE_GREG, STATE_MAX)
278 /* These displacements are relative to the address following the opcode
279 word of the instruction. The catch-all states have zero for "reach"
280 and "next" entries. */
282 #define GETA_0F (65536 * 4 - 8)
283 #define GETA_0B (-65536 * 4 - 4)
285 #define GETA_MAX_LEN 4 * 4
289 #define BCC_0F GETA_0F
290 #define BCC_0B GETA_0B
292 #define BCC_MAX_LEN 6 * 4
293 #define BCC_5F GETA_3F
294 #define BCC_5B GETA_3B
296 #define PUSHJ_0F GETA_0F
297 #define PUSHJ_0B GETA_0B
299 #define PUSHJ_MAX_LEN 5 * 4
300 #define PUSHJ_4F GETA_3F
301 #define PUSHJ_4B GETA_3B
303 /* We'll very rarely have sections longer than LONG_MAX, but we'll make a
304 feeble attempt at getting 64-bit C99 or gcc-specific values (assuming
305 long long is 64 bits on the host). */
307 #define PUSHJSTUB_MIN LLONG_MIN
308 #elsif defined (LONG_LONG_MIN)
309 #define PUSHJSTUB_MIN LONG_LONG_MIN
311 #define PUSHJSTUB_MIN LONG_MIN
314 #define PUSHJSTUB_MAX LLONG_MAX
315 #elsif defined (LONG_LONG_MAX)
316 #define PUSHJSTUB_MAX LONG_LONG_MAX
318 #define PUSHJSTUB_MAX LONG_MAX
321 #define JMP_0F (65536 * 256 * 4 - 8)
322 #define JMP_0B (-65536 * 256 * 4 - 4)
324 #define JMP_MAX_LEN 5 * 4
328 #define RELAX_ENCODE_SHIFT 1
329 #define ENCODE_RELAX(what, length) (((what) << RELAX_ENCODE_SHIFT) + (length))
331 const relax_typeS mmix_relax_table
[] =
333 /* Error sentinel (0, 0). */
340 {GETA_0F
, GETA_0B
, 0, ENCODE_RELAX (STATE_GETA
, STATE_MAX
)},
344 GETA_MAX_LEN
- 4, 0},
347 {BCC_0F
, BCC_0B
, 0, ENCODE_RELAX (STATE_BCC
, STATE_MAX
)},
353 /* PUSHJ (3, 0). Next state is actually PUSHJSTUB (6, 0). */
354 {PUSHJ_0F
, PUSHJ_0B
, 0, ENCODE_RELAX (STATE_PUSHJSTUB
, STATE_ZERO
)},
358 PUSHJ_MAX_LEN
- 4, 0},
361 {JMP_0F
, JMP_0B
, 0, ENCODE_RELAX (STATE_JMP
, STATE_MAX
)},
367 /* GREG (5, 0), (5, 1), though the table entry isn't used. */
368 {0, 0, 0, 0}, {0, 0, 0, 0},
370 /* PUSHJSTUB (6, 0). PUSHJ (3, 0) uses the range, so we set it to infinite. */
371 {PUSHJSTUB_MAX
, PUSHJSTUB_MIN
,
372 0, ENCODE_RELAX (STATE_PUSHJ
, STATE_MAX
)},
373 /* PUSHJSTUB (6, 1) isn't used. */
374 {0, 0, PUSHJ_MAX_LEN
, 0}
377 const pseudo_typeS md_pseudo_table
[] =
379 /* Support " .greg sym,expr" syntax. */
382 /* Support " .bspec expr" syntax. */
383 {"bspec", s_bspec
, 1},
385 /* Support " .espec" syntax. */
386 {"espec", s_espec
, 1},
388 /* Support " .local $45" syntax. */
389 {"local", mmix_s_local
, 1},
394 const char mmix_comment_chars
[] = "%!";
396 /* A ':' is a valid symbol character in mmixal. It's the prefix
397 delimiter, but other than that, it works like a symbol character,
398 except that we strip one off at the beginning of symbols. An '@' is a
399 symbol by itself (for the current location); space around it must not
401 const char mmix_symbol_chars
[] = ":@";
403 const char line_comment_chars
[] = "*#";
405 const char line_separator_chars
[] = ";";
407 const char mmix_exp_chars
[] = "eE";
409 const char mmix_flt_chars
[] = "rf";
412 /* Fill in the offset-related part of GETA or Bcc. */
415 mmix_set_geta_branch_offset (opcodep
, value
)
426 md_number_to_chars (opcodep
+ 2, value
, 2);
429 /* Fill in the offset-related part of JMP. */
432 mmix_set_jmp_offset (opcodep
, value
)
438 value
+= 65536 * 256 * 4;
443 md_number_to_chars (opcodep
+ 1, value
, 3);
446 /* Fill in NOP:s for the expanded part of GETA/JMP/Bcc/PUSHJ. */
449 mmix_fill_nops (opcodep
, n
)
455 for (i
= 0; i
< n
; i
++)
456 md_number_to_chars (opcodep
+ i
* 4, SWYM_INSN_BYTE
<< 24, 4);
459 /* See macro md_parse_name in tc-mmix.h. */
462 mmix_current_location (fn
, exp
)
463 void (*fn
) PARAMS ((expressionS
*));
471 /* Get up to three operands, filling them into the exp array.
472 General idea and code stolen from the tic80 port. */
475 get_operands (max_operands
, s
, exp
)
484 while (nextchar
== ',')
486 /* Skip leading whitespace */
487 while (*p
== ' ' || *p
== '\t')
490 /* Check to see if we have any operands left to parse */
491 if (*p
== 0 || *p
== '\n' || *p
== '\r')
495 else if (numexp
== max_operands
)
497 /* This seems more sane than saying "too many operands". We'll
498 get here only if the trailing trash starts with a comma. */
499 as_bad (_("invalid operands"));
500 mmix_discard_rest_of_line ();
504 /* Begin operand parsing at the current scan point. */
506 input_line_pointer
= p
;
507 expression (&exp
[numexp
]);
509 if (exp
[numexp
].X_op
== O_illegal
)
511 as_bad (_("invalid operands"));
513 else if (exp
[numexp
].X_op
== O_absent
)
515 as_bad (_("missing operand"));
519 p
= input_line_pointer
;
521 /* Skip leading whitespace */
522 while (*p
== ' ' || *p
== '\t')
527 /* If we allow "naked" comments, ignore the rest of the line. */
530 mmix_handle_rest_of_empty_line ();
531 input_line_pointer
--;
534 /* Mark the end of the valid operands with an illegal expression. */
535 exp
[numexp
].X_op
= O_illegal
;
540 /* Get the value of a special register, or -1 if the name does not match
541 one. NAME is a null-terminated string. */
544 get_spec_regno (name
)
555 /* Well, it's a short array and we'll most often just match the first
557 for (i
= 0; mmix_spec_regs
[i
].name
!= NULL
; i
++)
558 if (strcmp (name
, mmix_spec_regs
[i
].name
) == 0)
559 return mmix_spec_regs
[i
].number
;
564 /* For GET and PUT, parse the register names "manually", so we don't use
567 get_putget_operands (insn
, operands
, exp
)
568 struct mmix_opcode
*insn
;
572 expressionS
*expp_reg
;
573 expressionS
*expp_sreg
;
575 char *sregend
= operands
;
580 /* Skip leading whitespace */
581 while (*p
== ' ' || *p
== '\t')
584 input_line_pointer
= p
;
586 /* Initialize both possible operands to error state, in case we never
588 exp
[0].X_op
= O_illegal
;
589 exp
[1].X_op
= O_illegal
;
591 if (insn
->operands
== mmix_operands_get
)
596 expression (expp_reg
);
598 p
= input_line_pointer
;
600 /* Skip whitespace */
601 while (*p
== ' ' || *p
== '\t')
608 /* Skip whitespace */
609 while (*p
== ' ' || *p
== '\t')
612 input_line_pointer
= sregp
;
613 c
= get_symbol_end ();
614 sregend
= input_line_pointer
;
623 c
= get_symbol_end ();
624 sregend
= p
= input_line_pointer
;
627 /* Skip whitespace */
628 while (*p
== ' ' || *p
== '\t')
635 /* Skip whitespace */
636 while (*p
== ' ' || *p
== '\t')
639 input_line_pointer
= p
;
640 expression (expp_reg
);
645 regno
= get_spec_regno (sregp
);
648 /* Let the caller issue errors; we've made sure the operands are
650 if (expp_reg
->X_op
!= O_illegal
651 && expp_reg
->X_op
!= O_absent
654 expp_sreg
->X_op
= O_register
;
655 expp_sreg
->X_add_number
= regno
+ 256;
661 /* Handle MMIX-specific option. */
664 md_parse_option (c
, arg
)
666 char *arg ATTRIBUTE_UNUSED
;
671 warn_on_expansion
= 0;
672 allocate_undefined_gregs_in_linker
= 1;
679 case OPTION_NOEXPAND
:
683 case OPTION_NOMERGEGREG
:
689 equated_spec_regs
= 0;
692 case OPTION_GNU_SYNTAX
:
694 label_without_colon_this_line
= 0;
697 case OPTION_GLOBALIZE_SYMBOLS
:
698 mmix_globalize_symbols
= 1;
701 case OPTION_FIXED_SPEC_REGS
:
702 equated_spec_regs
= 0;
705 case OPTION_LINKER_ALLOCATED_GREGS
:
706 allocate_undefined_gregs_in_linker
= 1;
709 case OPTION_NOPUSHJSTUBS
:
720 /* Display MMIX-specific help text. */
723 md_show_usage (stream
)
726 fprintf (stream
, _(" MMIX-specific command line options:\n"));
727 fprintf (stream
, _("\
728 -fixed-special-register-names\n\
729 Allow only the original special register names.\n"));
730 fprintf (stream
, _("\
731 -globalize-symbols Make all symbols global.\n"));
732 fprintf (stream
, _("\
733 -gnu-syntax Turn off mmixal syntax compatibility.\n"));
734 fprintf (stream
, _("\
735 -relax Create linker relaxable code.\n"));
736 fprintf (stream
, _("\
737 -no-predefined-syms Do not provide mmixal built-in constants.\n\
738 Implies -fixed-special-register-names.\n"));
739 fprintf (stream
, _("\
740 -no-expand Do not expand GETA, branches, PUSHJ or JUMP\n\
741 into multiple instructions.\n"));
742 fprintf (stream
, _("\
743 -no-merge-gregs Do not merge GREG definitions with nearby values.\n"));
744 fprintf (stream
, _("\
745 -linker-allocated-gregs If there's no suitable GREG definition for the\
746 operands of an instruction, let the linker resolve.\n"));
747 fprintf (stream
, _("\
748 -x Do not warn when an operand to GETA, a branch,\n\
749 PUSHJ or JUMP is not known to be within range.\n\
750 The linker will catch any errors. Implies\n\
751 -linker-allocated-gregs."));
754 /* Step to end of line, but don't step over the end of the line. */
757 mmix_discard_rest_of_line ()
759 while (*input_line_pointer
760 && (! is_end_of_line
[(unsigned char) *input_line_pointer
]
761 || TC_EOL_IN_INSN (input_line_pointer
)))
762 input_line_pointer
++;
765 /* Act as demand_empty_rest_of_line if we're in strict GNU syntax mode,
766 otherwise just ignore the rest of the line (and skip the end-of-line
770 mmix_handle_rest_of_empty_line ()
773 demand_empty_rest_of_line ();
776 mmix_discard_rest_of_line ();
777 input_line_pointer
++;
781 /* Initialize GAS MMIX specifics. */
787 const struct mmix_opcode
*opcode
;
789 /* We assume nobody will use this, so don't allocate any room. */
790 obstack_begin (&mmix_sym_obstack
, 0);
792 /* This will break the day the "lex" thingy changes. For now, it's the
793 only way to make ':' part of a name, and a name beginner. */
794 lex_type
[':'] = (LEX_NAME
| LEX_BEGIN_NAME
);
796 mmix_opcode_hash
= hash_new ();
799 = bfd_make_section_old_way (stdoutput
, MMIX_REG_SECTION_NAME
);
801 for (opcode
= mmix_opcodes
; opcode
->name
; opcode
++)
802 hash_insert (mmix_opcode_hash
, opcode
->name
, (char *) opcode
);
804 /* We always insert the ordinary registers 0..255 as registers. */
805 for (i
= 0; i
< 256; i
++)
809 /* Alternatively, we could diddle with '$' and the following number,
810 but keeping the registers as symbols helps keep parsing simple. */
811 sprintf (buf
, "$%d", i
);
812 symbol_table_insert (symbol_new (buf
, reg_section
, i
,
813 &zero_address_frag
));
816 /* Insert mmixal built-in names if allowed. */
819 for (i
= 0; mmix_spec_regs
[i
].name
!= NULL
; i
++)
820 symbol_table_insert (symbol_new (mmix_spec_regs
[i
].name
,
822 mmix_spec_regs
[i
].number
+ 256,
823 &zero_address_frag
));
825 /* FIXME: Perhaps these should be recognized as specials; as field
826 names for those instructions. */
827 symbol_table_insert (symbol_new ("ROUND_CURRENT", reg_section
, 512,
828 &zero_address_frag
));
829 symbol_table_insert (symbol_new ("ROUND_OFF", reg_section
, 512 + 1,
830 &zero_address_frag
));
831 symbol_table_insert (symbol_new ("ROUND_UP", reg_section
, 512 + 2,
832 &zero_address_frag
));
833 symbol_table_insert (symbol_new ("ROUND_DOWN", reg_section
, 512 + 3,
834 &zero_address_frag
));
835 symbol_table_insert (symbol_new ("ROUND_NEAR", reg_section
, 512 + 4,
836 &zero_address_frag
));
840 /* Assemble one insn in STR. */
846 char *operands
= str
;
847 char modified_char
= 0;
848 struct mmix_opcode
*instruction
;
849 fragS
*opc_fragP
= NULL
;
850 int max_operands
= 3;
852 /* Note that the struct frag member fr_literal in frags.h is char[], so
853 I have to make this a plain char *. */
854 /* unsigned */ char *opcodep
= NULL
;
859 /* Move to end of opcode. */
861 is_part_of_name (*operands
);
865 if (ISSPACE (*operands
))
867 modified_char
= *operands
;
871 instruction
= (struct mmix_opcode
*) hash_find (mmix_opcode_hash
, str
);
872 if (instruction
== NULL
)
874 as_bad (_("unknown opcode: `%s'"), str
);
876 /* Avoid "unhandled label" errors. */
877 pending_label
= NULL
;
881 /* Put back the character after the opcode. */
882 if (modified_char
!= 0)
883 operands
[-1] = modified_char
;
885 input_line_pointer
= operands
;
887 /* Is this a mmixal pseudodirective? */
888 if (instruction
->type
== mmix_type_pseudo
)
890 /* For mmixal compatibility, a label for an instruction (and
891 emitting pseudo) refers to the _aligned_ address. We emit the
892 label here for the pseudos that don't handle it themselves. When
893 having an fb-label, emit it here, and increment the counter after
895 switch (instruction
->operands
)
897 case mmix_operands_loc
:
898 case mmix_operands_byte
:
899 case mmix_operands_prefix
:
900 case mmix_operands_local
:
901 case mmix_operands_bspec
:
902 case mmix_operands_espec
:
903 if (current_fb_label
>= 0)
904 colon (fb_label_name (current_fb_label
, 1));
905 else if (pending_label
!= NULL
)
907 colon (pending_label
);
908 pending_label
= NULL
;
916 /* Some of the pseudos emit contents, others don't. Set a
917 contents-emitted flag when we emit something into .text */
918 switch (instruction
->operands
)
920 case mmix_operands_loc
:
925 case mmix_operands_byte
:
930 case mmix_operands_wyde
:
935 case mmix_operands_tetra
:
940 case mmix_operands_octa
:
945 case mmix_operands_prefix
:
950 case mmix_operands_local
:
955 case mmix_operands_bspec
:
960 case mmix_operands_espec
:
966 BAD_CASE (instruction
->operands
);
969 /* These are all working like the pseudo functions in read.c:s_...,
970 in that they step over the end-of-line marker at the end of the
971 line. We don't want that here. */
972 input_line_pointer
--;
974 /* Step up the fb-label counter if there was a definition on this
976 if (current_fb_label
>= 0)
978 fb_label_instance_inc (current_fb_label
);
979 current_fb_label
= -1;
982 /* Reset any don't-align-next-datum request, unless this was a LOC
984 if (instruction
->operands
!= mmix_operands_loc
)
990 /* Not a pseudo; we *will* emit contents. */
991 if (now_seg
== data_section
)
993 if (lowest_data_loc
!= (bfd_vma
) -1 && (lowest_data_loc
& 3) != 0)
995 if (data_has_contents
)
996 as_bad (_("specified location wasn't TETRA-aligned"));
997 else if (want_unaligned
)
998 as_bad (_("unaligned data at an absolute location is not supported"));
1000 lowest_data_loc
&= ~(bfd_vma
) 3;
1001 lowest_data_loc
+= 4;
1004 data_has_contents
= 1;
1006 else if (now_seg
== text_section
)
1008 if (lowest_text_loc
!= (bfd_vma
) -1 && (lowest_text_loc
& 3) != 0)
1010 if (text_has_contents
)
1011 as_bad (_("specified location wasn't TETRA-aligned"));
1012 else if (want_unaligned
)
1013 as_bad (_("unaligned data at an absolute location is not supported"));
1015 lowest_text_loc
&= ~(bfd_vma
) 3;
1016 lowest_text_loc
+= 4;
1019 text_has_contents
= 1;
1022 /* After a sequence of BYTEs or WYDEs, we need to get to instruction
1023 alignment. For other pseudos, a ".p2align 2" is supposed to be
1024 inserted by the user. */
1025 if (last_alignment
< 2 && ! want_unaligned
)
1027 frag_align (2, 0, 0);
1028 record_alignment (now_seg
, 2);
1032 /* Reset any don't-align-next-datum request. */
1035 /* For mmixal compatibility, a label for an instruction (and emitting
1036 pseudo) refers to the _aligned_ address. So we have to emit the
1038 if (pending_label
!= NULL
)
1040 colon (pending_label
);
1041 pending_label
= NULL
;
1044 /* We assume that mmix_opcodes keeps having unique mnemonics for each
1045 opcode, so we don't have to iterate over more than one opcode; if the
1046 syntax does not match, then there's a syntax error. */
1048 /* Operands have little or no context and are all comma-separated; it is
1049 easier to parse each expression first. */
1050 switch (instruction
->operands
)
1052 case mmix_operands_reg_yz
:
1053 case mmix_operands_pop
:
1054 case mmix_operands_regaddr
:
1055 case mmix_operands_pushj
:
1056 case mmix_operands_get
:
1057 case mmix_operands_put
:
1058 case mmix_operands_set
:
1059 case mmix_operands_save
:
1060 case mmix_operands_unsave
:
1064 case mmix_operands_sync
:
1065 case mmix_operands_jmp
:
1066 case mmix_operands_resume
:
1070 /* The original 3 is fine for the rest. */
1075 /* If this is GET or PUT, and we don't do allow those names to be
1076 equated, we need to parse the names ourselves, so we don't pick up a
1077 user label instead of the special register. */
1078 if (! equated_spec_regs
1079 && (instruction
->operands
== mmix_operands_get
1080 || instruction
->operands
== mmix_operands_put
))
1081 n_operands
= get_putget_operands (instruction
, operands
, exp
);
1083 n_operands
= get_operands (max_operands
, operands
, exp
);
1085 /* If there's a fb-label on the current line, set that label. This must
1086 be done *after* evaluating expressions of operands, since neither a
1087 "1B" nor a "1F" refers to "1H" on the same line. */
1088 if (current_fb_label
>= 0)
1090 fb_label_instance_inc (current_fb_label
);
1091 colon (fb_label_name (current_fb_label
, 0));
1092 current_fb_label
= -1;
1095 /* We also assume that the length of the instruction is at least 4, the
1096 size of an unexpanded instruction. We need a self-contained frag
1097 since we want the relocation to point to the instruction, not the
1100 opcodep
= frag_more (4);
1101 mmix_opcode_frag
= opc_fragP
= frag_now
;
1102 frag_now
->fr_opcode
= opcodep
;
1104 /* Mark start of insn for DWARF2 debug features. */
1105 if (OUTPUT_FLAVOR
== bfd_target_elf_flavour
)
1106 dwarf2_emit_insn (4);
1108 md_number_to_chars (opcodep
, instruction
->match
, 4);
1110 switch (instruction
->operands
)
1112 case mmix_operands_jmp
:
1113 if (n_operands
== 0 && ! mmix_gnu_syntax
)
1114 /* Zeros are in place - nothing needs to be done when we have no
1118 /* Add a frag for a JMP relaxation; we need room for max four
1119 extra instructions. We don't do any work around here to check if
1120 we can determine the offset right away. */
1121 if (n_operands
!= 1 || exp
[0].X_op
== O_register
)
1123 as_bad (_("invalid operand to opcode %s: `%s'"),
1124 instruction
->name
, operands
);
1129 frag_var (rs_machine_dependent
, 4 * 4, 0,
1130 ENCODE_RELAX (STATE_JMP
, STATE_UNDF
),
1131 exp
[0].X_add_symbol
,
1132 exp
[0].X_add_number
,
1135 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
, 4,
1136 exp
+ 0, 1, BFD_RELOC_MMIX_ADDR27
);
1139 case mmix_operands_pushj
:
1140 /* We take care of PUSHJ in full here. */
1142 || ((exp
[0].X_op
== O_constant
|| exp
[0].X_op
== O_register
)
1143 && (exp
[0].X_add_number
> 255 || exp
[0].X_add_number
< 0)))
1145 as_bad (_("invalid operands to opcode %s: `%s'"),
1146 instruction
->name
, operands
);
1150 if (exp
[0].X_op
== O_register
|| exp
[0].X_op
== O_constant
)
1151 opcodep
[1] = exp
[0].X_add_number
;
1153 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 1,
1154 1, exp
+ 0, 0, BFD_RELOC_MMIX_REG_OR_BYTE
);
1157 frag_var (rs_machine_dependent
, PUSHJ_MAX_LEN
- 4, 0,
1158 ENCODE_RELAX (STATE_PUSHJ
, STATE_UNDF
),
1159 exp
[1].X_add_symbol
,
1160 exp
[1].X_add_number
,
1163 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
, 4,
1164 exp
+ 1, 1, BFD_RELOC_MMIX_ADDR19
);
1167 case mmix_operands_regaddr
:
1168 /* GETA/branch: Add a frag for relaxation. We don't do any work
1169 around here to check if we can determine the offset right away. */
1170 if (n_operands
!= 2 || exp
[1].X_op
== O_register
)
1172 as_bad (_("invalid operands to opcode %s: `%s'"),
1173 instruction
->name
, operands
);
1178 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
, 4,
1179 exp
+ 1, 1, BFD_RELOC_MMIX_ADDR19
);
1180 else if (instruction
->type
== mmix_type_condbranch
)
1181 frag_var (rs_machine_dependent
, BCC_MAX_LEN
- 4, 0,
1182 ENCODE_RELAX (STATE_BCC
, STATE_UNDF
),
1183 exp
[1].X_add_symbol
,
1184 exp
[1].X_add_number
,
1187 frag_var (rs_machine_dependent
, GETA_MAX_LEN
- 4, 0,
1188 ENCODE_RELAX (STATE_GETA
, STATE_UNDF
),
1189 exp
[1].X_add_symbol
,
1190 exp
[1].X_add_number
,
1198 switch (instruction
->operands
)
1200 case mmix_operands_regs
:
1201 /* We check the number of operands here, since we're in a
1202 FALLTHROUGH sequence in the next switch. */
1203 if (n_operands
!= 3 || exp
[2].X_op
== O_constant
)
1205 as_bad (_("invalid operands to opcode %s: `%s'"),
1206 instruction
->name
, operands
);
1210 case mmix_operands_regs_z
:
1211 if (n_operands
!= 3)
1213 as_bad (_("invalid operands to opcode %s: `%s'"),
1214 instruction
->name
, operands
);
1218 case mmix_operands_reg_yz
:
1219 case mmix_operands_roundregs_z
:
1220 case mmix_operands_roundregs
:
1221 case mmix_operands_regs_z_opt
:
1222 case mmix_operands_neg
:
1223 case mmix_operands_regaddr
:
1224 case mmix_operands_get
:
1225 case mmix_operands_set
:
1226 case mmix_operands_save
:
1228 || (exp
[0].X_op
== O_register
&& exp
[0].X_add_number
> 255))
1230 as_bad (_("invalid operands to opcode %s: `%s'"),
1231 instruction
->name
, operands
);
1235 if (exp
[0].X_op
== O_register
)
1236 opcodep
[1] = exp
[0].X_add_number
;
1238 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 1,
1239 1, exp
+ 0, 0, BFD_RELOC_MMIX_REG
);
1246 /* A corresponding once-over for those who take an 8-bit constant as
1247 their first operand. */
1248 switch (instruction
->operands
)
1250 case mmix_operands_pushgo
:
1251 /* PUSHGO: X is a constant, but can be expressed as a register.
1252 We handle X here and use the common machinery of T,X,3,$ for
1253 the rest of the operands. */
1255 || ((exp
[0].X_op
== O_constant
|| exp
[0].X_op
== O_register
)
1256 && (exp
[0].X_add_number
> 255 || exp
[0].X_add_number
< 0)))
1258 as_bad (_("invalid operands to opcode %s: `%s'"),
1259 instruction
->name
, operands
);
1262 else if (exp
[0].X_op
== O_constant
|| exp
[0].X_op
== O_register
)
1263 opcodep
[1] = exp
[0].X_add_number
;
1265 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 1,
1266 1, exp
+ 0, 0, BFD_RELOC_MMIX_REG_OR_BYTE
);
1269 case mmix_operands_pop
:
1270 if ((n_operands
== 0 || n_operands
== 1) && ! mmix_gnu_syntax
)
1273 case mmix_operands_x_regs_z
:
1275 || (exp
[0].X_op
== O_constant
1276 && (exp
[0].X_add_number
> 255
1277 || exp
[0].X_add_number
< 0)))
1279 as_bad (_("invalid operands to opcode %s: `%s'"),
1280 instruction
->name
, operands
);
1284 if (exp
[0].X_op
== O_constant
)
1285 opcodep
[1] = exp
[0].X_add_number
;
1287 /* FIXME: This doesn't bring us unsignedness checking. */
1288 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 1,
1289 1, exp
+ 0, 0, BFD_RELOC_8
);
1294 /* Handle the rest. */
1295 switch (instruction
->operands
)
1297 case mmix_operands_set
:
1298 /* SET: Either two registers, "$X,$Y", with Z field as zero, or
1299 "$X,YZ", meaning change the opcode to SETL. */
1301 || (exp
[1].X_op
== O_constant
1302 && (exp
[1].X_add_number
> 0xffff || exp
[1].X_add_number
< 0)))
1304 as_bad (_("invalid operands to opcode %s: `%s'"),
1305 instruction
->name
, operands
);
1309 if (exp
[1].X_op
== O_constant
)
1311 /* There's an ambiguity with "SET $0,Y" when Y isn't defined
1312 yet. To keep things simple, we assume that Y is then a
1313 register, and only change the opcode if Y is defined at this
1316 There's no compatibility problem with mmixal, since it emits
1317 errors if the field is not defined at this point. */
1318 md_number_to_chars (opcodep
, SETL_INSN_BYTE
, 1);
1320 opcodep
[2] = (exp
[1].X_add_number
>> 8) & 255;
1321 opcodep
[3] = exp
[1].X_add_number
& 255;
1325 case mmix_operands_x_regs_z
:
1326 /* SYNCD: "X,$Y,$Z|Z". */
1328 case mmix_operands_regs
:
1329 /* Three registers, $X,$Y,$Z. */
1331 case mmix_operands_regs_z
:
1332 /* Operands "$X,$Y,$Z|Z", number of arguments checked above. */
1334 case mmix_operands_pushgo
:
1335 /* Operands "$X|X,$Y,$Z|Z", optional Z. */
1337 case mmix_operands_regs_z_opt
:
1338 /* Operands "$X,$Y,$Z|Z", with $Z|Z being optional, default 0. Any
1339 operands not completely decided yet are postponed to later in
1340 assembly (but not until link-time yet). */
1342 if ((n_operands
!= 2 && n_operands
!= 3)
1343 || (exp
[1].X_op
== O_register
&& exp
[1].X_add_number
> 255)
1345 && ((exp
[2].X_op
== O_register
1346 && exp
[2].X_add_number
> 255
1348 || (exp
[2].X_op
== O_constant
1349 && (exp
[2].X_add_number
> 255
1350 || exp
[2].X_add_number
< 0)))))
1352 as_bad (_("invalid operands to opcode %s: `%s'"),
1353 instruction
->name
, operands
);
1357 if (n_operands
== 2)
1361 /* The last operand is immediate whenever we see just two
1363 opcodep
[0] |= IMM_OFFSET_BIT
;
1365 /* Now, we could either have an implied "0" as the Z operand, or
1366 it could be the constant of a "base address plus offset". It
1367 depends on whether it is allowed; only memory operations, as
1368 signified by instruction->type and "T" and "X" operand types,
1369 and it depends on whether we find a register in the second
1371 if (exp
[1].X_op
== O_register
&& exp
[1].X_add_number
<= 255)
1373 /* A zero then; all done. */
1374 opcodep
[2] = exp
[1].X_add_number
;
1378 /* Not known as a register. Is base address plus offset
1379 allowed, or can we assume that it is a register anyway? */
1380 if ((instruction
->operands
!= mmix_operands_regs_z_opt
1381 && instruction
->operands
!= mmix_operands_x_regs_z
1382 && instruction
->operands
!= mmix_operands_pushgo
)
1383 || (instruction
->type
!= mmix_type_memaccess_octa
1384 && instruction
->type
!= mmix_type_memaccess_tetra
1385 && instruction
->type
!= mmix_type_memaccess_wyde
1386 && instruction
->type
!= mmix_type_memaccess_byte
1387 && instruction
->type
!= mmix_type_memaccess_block
1388 && instruction
->type
!= mmix_type_jsr
1389 && instruction
->type
!= mmix_type_branch
))
1391 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 2,
1392 1, exp
+ 1, 0, BFD_RELOC_MMIX_REG
);
1396 /* To avoid getting a NULL add_symbol for constants and then
1397 catching a SEGV in write_relocs since it doesn't handle
1398 constants well for relocs other than PC-relative, we need to
1399 pass expressions as symbols and use fix_new, not fix_new_exp. */
1400 sym
= make_expr_symbol (exp
+ 1);
1402 /* Now we know it can be a "base address plus offset". Add
1403 proper fixup types so we can handle this later, when we've
1404 parsed everything. */
1405 fix_new (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 2,
1406 8, sym
, 0, 0, BFD_RELOC_MMIX_BASE_PLUS_OFFSET
);
1410 if (exp
[1].X_op
== O_register
)
1411 opcodep
[2] = exp
[1].X_add_number
;
1413 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 2,
1414 1, exp
+ 1, 0, BFD_RELOC_MMIX_REG
);
1416 /* In mmixal compatibility mode, we allow special registers as
1417 constants for the Z operand. They have 256 added to their
1418 register numbers, so the right thing will happen if we just treat
1419 those as constants. */
1420 if (exp
[2].X_op
== O_register
&& exp
[2].X_add_number
<= 255)
1421 opcodep
[3] = exp
[2].X_add_number
;
1422 else if (exp
[2].X_op
== O_constant
1423 || (exp
[2].X_op
== O_register
&& exp
[2].X_add_number
> 255))
1425 opcodep
[3] = exp
[2].X_add_number
;
1426 opcodep
[0] |= IMM_OFFSET_BIT
;
1429 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 3,
1431 (instruction
->operands
== mmix_operands_set
1432 || instruction
->operands
== mmix_operands_regs
)
1433 ? BFD_RELOC_MMIX_REG
: BFD_RELOC_MMIX_REG_OR_BYTE
);
1436 case mmix_operands_pop
:
1437 /* POP, one eight and one 16-bit operand. */
1438 if (n_operands
== 0 && ! mmix_gnu_syntax
)
1440 if (n_operands
== 1 && ! mmix_gnu_syntax
)
1441 goto a_single_24_bit_number_operand
;
1443 case mmix_operands_reg_yz
:
1444 /* A register and a 16-bit unsigned number. */
1446 || exp
[1].X_op
== O_register
1447 || (exp
[1].X_op
== O_constant
1448 && (exp
[1].X_add_number
> 0xffff || exp
[1].X_add_number
< 0)))
1450 as_bad (_("invalid operands to opcode %s: `%s'"),
1451 instruction
->name
, operands
);
1455 if (exp
[1].X_op
== O_constant
)
1457 opcodep
[2] = (exp
[1].X_add_number
>> 8) & 255;
1458 opcodep
[3] = exp
[1].X_add_number
& 255;
1461 /* FIXME: This doesn't bring us unsignedness checking. */
1462 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 2,
1463 2, exp
+ 1, 0, BFD_RELOC_16
);
1466 case mmix_operands_jmp
:
1467 /* A JMP. Everything is already done. */
1470 case mmix_operands_roundregs
:
1471 /* Two registers with optional rounding mode or constant in between. */
1472 if ((n_operands
== 3 && exp
[2].X_op
== O_constant
)
1473 || (n_operands
== 2 && exp
[1].X_op
== O_constant
))
1475 as_bad (_("invalid operands to opcode %s: `%s'"),
1476 instruction
->name
, operands
);
1480 case mmix_operands_roundregs_z
:
1481 /* Like FLOT, "$X,ROUND_MODE,$Z|Z", but the rounding mode is
1482 optional and can be the corresponding constant. */
1484 /* Which exp index holds the second operand (not the rounding
1486 int op2no
= n_operands
- 1;
1488 if ((n_operands
!= 2 && n_operands
!= 3)
1489 || ((exp
[op2no
].X_op
== O_register
1490 && exp
[op2no
].X_add_number
> 255)
1491 || (exp
[op2no
].X_op
== O_constant
1492 && (exp
[op2no
].X_add_number
> 255
1493 || exp
[op2no
].X_add_number
< 0)))
1495 /* We don't allow for the rounding mode to be deferred; it
1496 must be determined in the "first pass". It cannot be a
1497 symbol equated to a rounding mode, but defined after
1499 && ((exp
[1].X_op
== O_register
1500 && exp
[1].X_add_number
< 512)
1501 || (exp
[1].X_op
== O_constant
1502 && exp
[1].X_add_number
< 0
1503 && exp
[1].X_add_number
> 4)
1504 || (exp
[1].X_op
!= O_register
1505 && exp
[1].X_op
!= O_constant
))))
1507 as_bad (_("invalid operands to opcode %s: `%s'"),
1508 instruction
->name
, operands
);
1512 /* Add rounding mode if present. */
1513 if (n_operands
== 3)
1514 opcodep
[2] = exp
[1].X_add_number
& 255;
1516 if (exp
[op2no
].X_op
== O_register
)
1517 opcodep
[3] = exp
[op2no
].X_add_number
;
1518 else if (exp
[op2no
].X_op
== O_constant
)
1520 opcodep
[3] = exp
[op2no
].X_add_number
;
1521 opcodep
[0] |= IMM_OFFSET_BIT
;
1524 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 3,
1526 instruction
->operands
== mmix_operands_roundregs
1527 ? BFD_RELOC_MMIX_REG
1528 : BFD_RELOC_MMIX_REG_OR_BYTE
);
1532 case mmix_operands_sync
:
1533 a_single_24_bit_number_operand
:
1535 || exp
[0].X_op
== O_register
1536 || (exp
[0].X_op
== O_constant
1537 && (exp
[0].X_add_number
> 0xffffff || exp
[0].X_add_number
< 0)))
1539 as_bad (_("invalid operands to opcode %s: `%s'"),
1540 instruction
->name
, operands
);
1544 if (exp
[0].X_op
== O_constant
)
1546 opcodep
[1] = (exp
[0].X_add_number
>> 16) & 255;
1547 opcodep
[2] = (exp
[0].X_add_number
>> 8) & 255;
1548 opcodep
[3] = exp
[0].X_add_number
& 255;
1551 /* FIXME: This doesn't bring us unsignedness checking. */
1552 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 1,
1553 3, exp
+ 0, 0, BFD_RELOC_24
);
1556 case mmix_operands_neg
:
1557 /* Operands "$X,Y,$Z|Z"; NEG or NEGU. Y is optional, 0 is default. */
1559 if ((n_operands
!= 3 && n_operands
!= 2)
1560 || (n_operands
== 3 && exp
[1].X_op
== O_register
)
1561 || ((exp
[1].X_op
== O_constant
|| exp
[1].X_op
== O_register
)
1562 && (exp
[1].X_add_number
> 255 || exp
[1].X_add_number
< 0))
1564 && ((exp
[2].X_op
== O_register
&& exp
[2].X_add_number
> 255)
1565 || (exp
[2].X_op
== O_constant
1566 && (exp
[2].X_add_number
> 255
1567 || exp
[2].X_add_number
< 0)))))
1569 as_bad (_("invalid operands to opcode %s: `%s'"),
1570 instruction
->name
, operands
);
1574 if (n_operands
== 2)
1576 if (exp
[1].X_op
== O_register
)
1577 opcodep
[3] = exp
[1].X_add_number
;
1578 else if (exp
[1].X_op
== O_constant
)
1580 opcodep
[3] = exp
[1].X_add_number
;
1581 opcodep
[0] |= IMM_OFFSET_BIT
;
1584 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 3,
1585 1, exp
+ 1, 0, BFD_RELOC_MMIX_REG_OR_BYTE
);
1589 if (exp
[1].X_op
== O_constant
)
1590 opcodep
[2] = exp
[1].X_add_number
;
1592 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 2,
1593 1, exp
+ 1, 0, BFD_RELOC_8
);
1595 if (exp
[2].X_op
== O_register
)
1596 opcodep
[3] = exp
[2].X_add_number
;
1597 else if (exp
[2].X_op
== O_constant
)
1599 opcodep
[3] = exp
[2].X_add_number
;
1600 opcodep
[0] |= IMM_OFFSET_BIT
;
1603 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 3,
1604 1, exp
+ 2, 0, BFD_RELOC_MMIX_REG_OR_BYTE
);
1607 case mmix_operands_regaddr
:
1608 /* A GETA/branch-type. */
1611 case mmix_operands_get
:
1612 /* "$X,spec_reg"; GET.
1613 Like with rounding modes, we demand that the special register or
1614 symbol is already defined when we get here at the point of use. */
1616 || (exp
[1].X_op
== O_register
1617 && (exp
[1].X_add_number
< 256 || exp
[1].X_add_number
>= 512))
1618 || (exp
[1].X_op
== O_constant
1619 && (exp
[1].X_add_number
< 0 || exp
[1].X_add_number
> 256))
1620 || (exp
[1].X_op
!= O_constant
&& exp
[1].X_op
!= O_register
))
1622 as_bad (_("invalid operands to opcode %s: `%s'"),
1623 instruction
->name
, operands
);
1627 opcodep
[3] = exp
[1].X_add_number
- 256;
1630 case mmix_operands_put
:
1631 /* "spec_reg,$Z|Z"; PUT. */
1633 || (exp
[0].X_op
== O_register
1634 && (exp
[0].X_add_number
< 256 || exp
[0].X_add_number
>= 512))
1635 || (exp
[0].X_op
== O_constant
1636 && (exp
[0].X_add_number
< 0 || exp
[0].X_add_number
> 256))
1637 || (exp
[0].X_op
!= O_constant
&& exp
[0].X_op
!= O_register
))
1639 as_bad (_("invalid operands to opcode %s: `%s'"),
1640 instruction
->name
, operands
);
1644 opcodep
[1] = exp
[0].X_add_number
- 256;
1646 /* Note that the Y field is zero. */
1648 if (exp
[1].X_op
== O_register
)
1649 opcodep
[3] = exp
[1].X_add_number
;
1650 else if (exp
[1].X_op
== O_constant
)
1652 opcodep
[3] = exp
[1].X_add_number
;
1653 opcodep
[0] |= IMM_OFFSET_BIT
;
1656 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 3,
1657 1, exp
+ 1, 0, BFD_RELOC_MMIX_REG_OR_BYTE
);
1660 case mmix_operands_save
:
1663 || exp
[1].X_op
!= O_constant
1664 || exp
[1].X_add_number
!= 0)
1666 as_bad (_("invalid operands to opcode %s: `%s'"),
1667 instruction
->name
, operands
);
1672 case mmix_operands_unsave
:
1673 if (n_operands
< 2 && ! mmix_gnu_syntax
)
1675 if (n_operands
== 1)
1677 if (exp
[0].X_op
== O_register
)
1678 opcodep
[3] = exp
[0].X_add_number
;
1680 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 3,
1681 1, exp
, 0, BFD_RELOC_MMIX_REG
);
1686 /* "0,$Z"; UNSAVE. */
1688 || exp
[0].X_op
!= O_constant
1689 || exp
[0].X_add_number
!= 0
1690 || exp
[1].X_op
== O_constant
1691 || (exp
[1].X_op
== O_register
1692 && exp
[1].X_add_number
> 255))
1694 as_bad (_("invalid operands to opcode %s: `%s'"),
1695 instruction
->name
, operands
);
1699 if (exp
[1].X_op
== O_register
)
1700 opcodep
[3] = exp
[1].X_add_number
;
1702 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 3,
1703 1, exp
+ 1, 0, BFD_RELOC_MMIX_REG
);
1706 case mmix_operands_xyz_opt
:
1707 /* SWYM, TRIP, TRAP: zero, one, two or three operands. */
1708 if (n_operands
== 0 && ! mmix_gnu_syntax
)
1709 /* Zeros are in place - nothing needs to be done for zero
1710 operands. We don't allow this in GNU syntax mode, because it
1711 was believed that the risk of missing to supply an operand is
1712 higher than the benefit of not having to specify a zero. */
1714 else if (n_operands
== 1 && exp
[0].X_op
!= O_register
)
1716 if (exp
[0].X_op
== O_constant
)
1718 if (exp
[0].X_add_number
> 255*255*255
1719 || exp
[0].X_add_number
< 0)
1721 as_bad (_("invalid operands to opcode %s: `%s'"),
1722 instruction
->name
, operands
);
1727 opcodep
[1] = (exp
[0].X_add_number
>> 16) & 255;
1728 opcodep
[2] = (exp
[0].X_add_number
>> 8) & 255;
1729 opcodep
[3] = exp
[0].X_add_number
& 255;
1733 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 1,
1734 3, exp
, 0, BFD_RELOC_24
);
1736 else if (n_operands
== 2
1737 && exp
[0].X_op
!= O_register
1738 && exp
[1].X_op
!= O_register
)
1742 if (exp
[0].X_op
== O_constant
)
1744 if (exp
[0].X_add_number
> 255
1745 || exp
[0].X_add_number
< 0)
1747 as_bad (_("invalid operands to opcode %s: `%s'"),
1748 instruction
->name
, operands
);
1752 opcodep
[1] = exp
[0].X_add_number
& 255;
1755 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 1,
1756 1, exp
, 0, BFD_RELOC_8
);
1758 if (exp
[1].X_op
== O_constant
)
1760 if (exp
[1].X_add_number
> 255*255
1761 || exp
[1].X_add_number
< 0)
1763 as_bad (_("invalid operands to opcode %s: `%s'"),
1764 instruction
->name
, operands
);
1769 opcodep
[2] = (exp
[1].X_add_number
>> 8) & 255;
1770 opcodep
[3] = exp
[1].X_add_number
& 255;
1774 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 2,
1775 2, exp
+ 1, 0, BFD_RELOC_16
);
1777 else if (n_operands
== 3
1778 && exp
[0].X_op
!= O_register
1779 && exp
[1].X_op
!= O_register
1780 && exp
[2].X_op
!= O_register
)
1782 /* Three operands. */
1784 if (exp
[0].X_op
== O_constant
)
1786 if (exp
[0].X_add_number
> 255
1787 || exp
[0].X_add_number
< 0)
1789 as_bad (_("invalid operands to opcode %s: `%s'"),
1790 instruction
->name
, operands
);
1794 opcodep
[1] = exp
[0].X_add_number
& 255;
1797 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 1,
1798 1, exp
, 0, BFD_RELOC_8
);
1800 if (exp
[1].X_op
== O_constant
)
1802 if (exp
[1].X_add_number
> 255
1803 || exp
[1].X_add_number
< 0)
1805 as_bad (_("invalid operands to opcode %s: `%s'"),
1806 instruction
->name
, operands
);
1810 opcodep
[2] = exp
[1].X_add_number
& 255;
1813 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 2,
1814 1, exp
+ 1, 0, BFD_RELOC_8
);
1816 if (exp
[2].X_op
== O_constant
)
1818 if (exp
[2].X_add_number
> 255
1819 || exp
[2].X_add_number
< 0)
1821 as_bad (_("invalid operands to opcode %s: `%s'"),
1822 instruction
->name
, operands
);
1826 opcodep
[3] = exp
[2].X_add_number
& 255;
1829 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 3,
1830 1, exp
+ 2, 0, BFD_RELOC_8
);
1832 else if (n_operands
<= 3
1833 && (strcmp (instruction
->name
, "trip") == 0
1834 || strcmp (instruction
->name
, "trap") == 0))
1836 /* The meaning of operands to TRIP and TRAP are not defined, so
1837 we add combinations not handled above here as we find them. */
1838 if (n_operands
== 3)
1840 /* Don't require non-register operands. Always generate
1841 fixups, so we don't have to copy lots of code and create
1842 maintenance problems. TRIP is supposed to be a rare
1843 instruction, so the overhead should not matter. We
1844 aren't allowed to fix_new_exp for an expression which is
1845 an O_register at this point, however. */
1846 if (exp
[0].X_op
== O_register
)
1847 opcodep
[1] = exp
[0].X_add_number
;
1849 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 1,
1850 1, exp
, 0, BFD_RELOC_MMIX_REG_OR_BYTE
);
1851 if (exp
[1].X_op
== O_register
)
1852 opcodep
[2] = exp
[1].X_add_number
;
1854 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 2,
1855 1, exp
+ 1, 0, BFD_RELOC_MMIX_REG_OR_BYTE
);
1856 if (exp
[2].X_op
== O_register
)
1857 opcodep
[3] = exp
[2].X_add_number
;
1859 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 3,
1860 1, exp
+ 2, 0, BFD_RELOC_MMIX_REG_OR_BYTE
);
1862 else if (n_operands
== 2)
1864 if (exp
[0].X_op
== O_register
)
1865 opcodep
[2] = exp
[0].X_add_number
;
1867 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 2,
1868 1, exp
, 0, BFD_RELOC_MMIX_REG_OR_BYTE
);
1869 if (exp
[1].X_op
== O_register
)
1870 opcodep
[3] = exp
[1].X_add_number
;
1872 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 3,
1873 1, exp
+ 1, 0, BFD_RELOC_MMIX_REG_OR_BYTE
);
1877 as_bad (_("unsupported operands to %s: `%s'"),
1878 instruction
->name
, operands
);
1884 as_bad (_("invalid operands to opcode %s: `%s'"),
1885 instruction
->name
, operands
);
1890 case mmix_operands_resume
:
1891 if (n_operands
== 0 && ! mmix_gnu_syntax
)
1895 || exp
[0].X_op
== O_register
1896 || (exp
[0].X_op
== O_constant
1897 && (exp
[0].X_add_number
< 0
1898 || exp
[0].X_add_number
> 255)))
1900 as_bad (_("invalid operands to opcode %s: `%s'"),
1901 instruction
->name
, operands
);
1905 if (exp
[0].X_op
== O_constant
)
1906 opcodep
[3] = exp
[0].X_add_number
;
1908 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 3,
1909 1, exp
+ 0, 0, BFD_RELOC_8
);
1912 case mmix_operands_pushj
:
1913 /* All is done for PUSHJ already. */
1917 BAD_CASE (instruction
->operands
);
1921 /* For the benefit of insns that start with a digit, we assemble by way of
1922 tc_unrecognized_line too, through this function. */
1925 mmix_assemble_return_nonzero (str
)
1928 int last_error_count
= had_errors ();
1932 /* Normal instruction handling downcases, so we must too. */
1933 while (ISALNUM (*s2
))
1935 if (ISUPPER ((unsigned char) *s2
))
1936 *s2
= TOLOWER (*s2
);
1940 /* Cut the line for sake of the assembly. */
1941 for (s2
= str
; *s2
&& *s2
!= '\n'; s2
++)
1949 return had_errors () == last_error_count
;
1952 /* The PREFIX pseudo. */
1956 int unused ATTRIBUTE_UNUSED
;
1963 p
= input_line_pointer
;
1965 c
= get_symbol_end ();
1967 /* Reseting prefix? */
1968 if (*p
== ':' && p
[1] == 0)
1969 mmix_current_prefix
= NULL
;
1972 /* Put this prefix on the mmix symbols obstack. We could malloc and
1973 free it separately, but then we'd have to worry about that.
1974 People using up memory on prefixes have other problems. */
1975 obstack_grow (&mmix_sym_obstack
, p
, strlen (p
) + 1);
1976 p
= obstack_finish (&mmix_sym_obstack
);
1978 /* Accumulate prefixes, and strip a leading ':'. */
1979 if (mmix_current_prefix
!= NULL
|| *p
== ':')
1980 p
= mmix_prefix_name (p
);
1982 mmix_current_prefix
= p
;
1985 *input_line_pointer
= c
;
1987 mmix_handle_rest_of_empty_line ();
1990 /* We implement prefixes by using the tc_canonicalize_symbol_name hook,
1991 and store each prefixed name on a (separate) obstack. This means that
1992 the name is on the "notes" obstack in non-prefixed form and on the
1993 mmix_sym_obstack in prefixed form, but currently it is not worth
1994 rewriting the whole GAS symbol handling to improve "hooking" to avoid
1995 that. (It might be worth a rewrite for other reasons, though). */
1998 mmix_prefix_name (shortname
)
2001 if (*shortname
== ':')
2002 return shortname
+ 1;
2004 if (mmix_current_prefix
== NULL
)
2005 as_fatal (_("internal: mmix_prefix_name but empty prefix"));
2007 if (*shortname
== '$')
2010 obstack_grow (&mmix_sym_obstack
, mmix_current_prefix
,
2011 strlen (mmix_current_prefix
));
2012 obstack_grow (&mmix_sym_obstack
, shortname
, strlen (shortname
) + 1);
2013 return obstack_finish (&mmix_sym_obstack
);
2016 /* The GREG pseudo. At LABEL, we have the name of a symbol that we
2017 want to make a register symbol, and which should be initialized with
2018 the value in the expression at INPUT_LINE_POINTER (defaulting to 0).
2019 Either and (perhaps less meaningful) both may be missing. LABEL must
2020 be persistent, perhaps allocated on an obstack. */
2023 mmix_greg_internal (label
)
2026 expressionS
*expP
= &mmix_raw_gregs
[n_of_raw_gregs
].exp
;
2028 /* Don't set the section to register contents section before the
2029 expression has been parsed; it may refer to the current position. */
2032 /* FIXME: Check that no expression refers to the register contents
2033 section. May need to be done in elf64-mmix.c. */
2034 if (expP
->X_op
== O_absent
)
2036 /* Default to zero if the expression was absent. */
2037 expP
->X_op
= O_constant
;
2038 expP
->X_add_number
= 0;
2039 expP
->X_unsigned
= 0;
2040 expP
->X_add_symbol
= NULL
;
2041 expP
->X_op_symbol
= NULL
;
2044 /* We must handle prefixes here, as we save the labels and expressions
2045 to be output later. */
2046 mmix_raw_gregs
[n_of_raw_gregs
].label
2047 = mmix_current_prefix
== NULL
? label
: mmix_prefix_name (label
);
2049 if (n_of_raw_gregs
== MAX_GREGS
- 1)
2050 as_bad (_("too many GREG registers allocated (max %d)"), MAX_GREGS
);
2054 mmix_handle_rest_of_empty_line ();
2057 /* The ".greg label,expr" worker. */
2061 int unused ATTRIBUTE_UNUSED
;
2065 p
= input_line_pointer
;
2067 /* This will skip over what can be a symbol and zero out the next
2068 character, which we assume is a ',' or other meaningful delimiter.
2069 What comes after that is the initializer expression for the
2071 c
= get_symbol_end ();
2073 if (! is_end_of_line
[(unsigned char) c
])
2074 input_line_pointer
++;
2078 /* The label must be persistent; it's not used until after all input
2080 obstack_grow (&mmix_sym_obstack
, p
, strlen (p
) + 1);
2081 mmix_greg_internal (obstack_finish (&mmix_sym_obstack
));
2084 mmix_greg_internal (NULL
);
2087 /* The "BSPEC expr" worker. */
2091 int unused ATTRIBUTE_UNUSED
;
2095 char secname
[sizeof (MMIX_OTHER_SPEC_SECTION_PREFIX
) + 20]
2096 = MMIX_OTHER_SPEC_SECTION_PREFIX
;
2100 /* Get a constant expression which we can evaluate *now*. Supporting
2101 more complex (though assembly-time computable) expressions is
2102 feasible but Too Much Work for something of unknown usefulness like
2104 expsec
= expression (&exp
);
2105 mmix_handle_rest_of_empty_line ();
2107 /* Check that we don't have another BSPEC in progress. */
2110 as_bad (_("BSPEC already active. Nesting is not supported."));
2114 if (exp
.X_op
!= O_constant
2115 || expsec
!= absolute_section
2116 || exp
.X_add_number
< 0
2117 || exp
.X_add_number
> 65535)
2119 as_bad (_("invalid BSPEC expression"));
2120 exp
.X_add_number
= 0;
2123 n
= (int) exp
.X_add_number
;
2125 sprintf (secname
+ strlen (MMIX_OTHER_SPEC_SECTION_PREFIX
), "%d", n
);
2126 sec
= bfd_get_section_by_name (stdoutput
, secname
);
2129 /* We need a non-volatile name as it will be stored in the section
2131 char *newsecname
= xstrdup (secname
);
2132 sec
= bfd_make_section (stdoutput
, newsecname
);
2135 as_fatal (_("can't create section %s"), newsecname
);
2137 if (!bfd_set_section_flags (stdoutput
, sec
,
2138 bfd_get_section_flags (stdoutput
, sec
)
2140 as_fatal (_("can't set section flags for section %s"), newsecname
);
2143 /* Tell ELF about the pending section change. */
2144 obj_elf_section_change_hook ();
2145 subseg_set (sec
, 0);
2147 /* Save position for missing ESPEC. */
2148 as_where (&bspec_file
, &bspec_line
);
2153 /* The "ESPEC" worker. */
2157 int unused ATTRIBUTE_UNUSED
;
2159 /* First, check that we *do* have a BSPEC in progress. */
2162 as_bad (_("ESPEC without preceding BSPEC"));
2166 mmix_handle_rest_of_empty_line ();
2169 /* When we told ELF about the section change in s_bspec, it stored the
2170 previous section for us so we can get at it with the equivalent of a
2171 .previous pseudo. */
2172 obj_elf_previous (0);
2175 /* The " .local expr" and " local expr" worker. We make a BFD_MMIX_LOCAL
2176 relocation against the current position against the expression.
2177 Implementing this by means of contents in a section lost. */
2180 mmix_s_local (unused
)
2181 int unused ATTRIBUTE_UNUSED
;
2185 /* Don't set the section to register contents section before the
2186 expression has been parsed; it may refer to the current position in
2187 some contorted way. */
2190 if (exp
.X_op
== O_absent
)
2192 as_bad (_("missing local expression"));
2195 else if (exp
.X_op
== O_register
)
2197 /* fix_new_exp doesn't like O_register. Should be configurable.
2198 We're fine with a constant here, though. */
2199 exp
.X_op
= O_constant
;
2202 fix_new_exp (frag_now
, 0, 0, &exp
, 0, BFD_RELOC_MMIX_LOCAL
);
2203 mmix_handle_rest_of_empty_line ();
2206 /* Set fragP->fr_var to the initial guess of the size of a relaxable insn
2207 and return it. Sizes of other instructions are not known. This
2208 function may be called multiple times. */
2211 md_estimate_size_before_relax (fragP
, segment
)
2217 #define HANDLE_RELAXABLE(state) \
2218 case ENCODE_RELAX (state, STATE_UNDF): \
2219 if (fragP->fr_symbol != NULL \
2220 && S_GET_SEGMENT (fragP->fr_symbol) == segment \
2221 && !S_IS_WEAK (fragP->fr_symbol)) \
2223 /* The symbol lies in the same segment - a relaxable case. */ \
2225 = ENCODE_RELAX (state, STATE_ZERO); \
2229 switch (fragP
->fr_subtype
)
2231 HANDLE_RELAXABLE (STATE_GETA
);
2232 HANDLE_RELAXABLE (STATE_BCC
);
2233 HANDLE_RELAXABLE (STATE_JMP
);
2235 case ENCODE_RELAX (STATE_PUSHJ
, STATE_UNDF
):
2236 if (fragP
->fr_symbol
!= NULL
2237 && S_GET_SEGMENT (fragP
->fr_symbol
) == segment
2238 && !S_IS_WEAK (fragP
->fr_symbol
))
2239 /* The symbol lies in the same segment - a relaxable case. */
2240 fragP
->fr_subtype
= ENCODE_RELAX (STATE_PUSHJ
, STATE_ZERO
);
2241 else if (pushj_stubs
)
2242 /* If we're to generate stubs, assume we can reach a stub after
2244 fragP
->fr_subtype
= ENCODE_RELAX (STATE_PUSHJSTUB
, STATE_ZERO
);
2246 case ENCODE_RELAX (STATE_PUSHJ
, STATE_ZERO
):
2247 case ENCODE_RELAX (STATE_PUSHJSTUB
, STATE_ZERO
):
2248 /* We need to distinguish different relaxation rounds. */
2249 seg_info (segment
)->tc_segment_info_data
.last_stubfrag
= fragP
;
2252 case ENCODE_RELAX (STATE_GETA
, STATE_ZERO
):
2253 case ENCODE_RELAX (STATE_BCC
, STATE_ZERO
):
2254 case ENCODE_RELAX (STATE_JMP
, STATE_ZERO
):
2255 /* When relaxing a section for the second time, we don't need to do
2256 anything except making sure that fr_var is set right. */
2259 case STATE_GREG_DEF
:
2260 length
= fragP
->tc_frag_data
!= NULL
? 0 : 8;
2261 fragP
->fr_var
= length
;
2263 /* Don't consult the relax_table; it isn't valid for this
2269 BAD_CASE (fragP
->fr_subtype
);
2272 length
= mmix_relax_table
[fragP
->fr_subtype
].rlx_length
;
2273 fragP
->fr_var
= length
;
2278 /* Turn a string in input_line_pointer into a floating point constant of type
2279 type, and store the appropriate bytes in *litP. The number of LITTLENUMS
2280 emitted is stored in *sizeP . An error message is returned, or NULL on
2284 md_atof (type
, litP
, sizeP
)
2290 LITTLENUM_TYPE words
[4];
2296 /* FIXME: Having 'f' in mmix_flt_chars (and here) makes it
2297 problematic to also have a forward reference in an expression.
2298 The testsuite wants it, and it's customary.
2299 We'll deal with the real problems when they come; we share the
2300 problem with most other ports. */
2310 return _("bad call to md_atof");
2313 t
= atof_ieee (input_line_pointer
, type
, words
);
2315 input_line_pointer
= t
;
2319 for (i
= 0; i
< prec
; i
++)
2321 md_number_to_chars (litP
, (valueT
) words
[i
], 2);
2327 /* Convert variable-sized frags into one or more fixups. */
2330 md_convert_frag (abfd
, sec
, fragP
)
2331 bfd
*abfd ATTRIBUTE_UNUSED
;
2332 segT sec ATTRIBUTE_UNUSED
;
2335 /* Pointer to first byte in variable-sized part of the frag. */
2338 /* Pointer to first opcode byte in frag. */
2341 /* Size in bytes of variable-sized part of frag. */
2342 int var_part_size
= 0;
2344 /* This is part of *fragP. It contains all information about addresses
2345 and offsets to varying parts. */
2347 unsigned long var_part_offset
;
2349 /* This is the frag for the opcode. It, rather than fragP, must be used
2350 when emitting a frag for the opcode. */
2351 fragS
*opc_fragP
= fragP
->tc_frag_data
;
2354 /* Where, in file space, does addr point? */
2355 bfd_vma target_address
;
2356 bfd_vma opcode_address
;
2358 know (fragP
->fr_type
== rs_machine_dependent
);
2360 var_part_offset
= fragP
->fr_fix
;
2361 var_partp
= fragP
->fr_literal
+ var_part_offset
;
2362 opcodep
= fragP
->fr_opcode
;
2364 symbolP
= fragP
->fr_symbol
;
2367 = ((symbolP
? S_GET_VALUE (symbolP
) : 0) + fragP
->fr_offset
);
2369 /* The opcode that would be extended is the last four "fixed" bytes. */
2370 opcode_address
= fragP
->fr_address
+ fragP
->fr_fix
- 4;
2372 switch (fragP
->fr_subtype
)
2374 case ENCODE_RELAX (STATE_PUSHJSTUB
, STATE_ZERO
):
2375 /* Setting the unknown bits to 0 seems the most appropriate. */
2376 mmix_set_geta_branch_offset (opcodep
, 0);
2377 tmpfixP
= fix_new (opc_fragP
, opcodep
- opc_fragP
->fr_literal
, 8,
2378 fragP
->fr_symbol
, fragP
->fr_offset
, 1,
2379 BFD_RELOC_MMIX_PUSHJ_STUBBABLE
);
2380 COPY_FR_WHERE_TO_FX (fragP
, tmpfixP
);
2384 case ENCODE_RELAX (STATE_GETA
, STATE_ZERO
):
2385 case ENCODE_RELAX (STATE_BCC
, STATE_ZERO
):
2386 case ENCODE_RELAX (STATE_PUSHJ
, STATE_ZERO
):
2387 mmix_set_geta_branch_offset (opcodep
, target_address
- opcode_address
);
2391 = fix_new (opc_fragP
, opcodep
- opc_fragP
->fr_literal
, 4,
2392 fragP
->fr_symbol
, fragP
->fr_offset
, 1,
2393 BFD_RELOC_MMIX_ADDR19
);
2394 COPY_FR_WHERE_TO_FX (fragP
, tmpfixP
);
2399 case ENCODE_RELAX (STATE_JMP
, STATE_ZERO
):
2400 mmix_set_jmp_offset (opcodep
, target_address
- opcode_address
);
2404 = fix_new (opc_fragP
, opcodep
- opc_fragP
->fr_literal
, 4,
2405 fragP
->fr_symbol
, fragP
->fr_offset
, 1,
2406 BFD_RELOC_MMIX_ADDR27
);
2407 COPY_FR_WHERE_TO_FX (fragP
, tmpfixP
);
2412 case STATE_GREG_DEF
:
2413 if (fragP
->tc_frag_data
== NULL
)
2415 /* We must initialize data that's supposed to be "fixed up" to
2416 avoid emitting garbage, because md_apply_fix3 won't do
2417 anything for undefined symbols. */
2418 md_number_to_chars (var_partp
, 0, 8);
2420 = fix_new (fragP
, var_partp
- fragP
->fr_literal
, 8,
2421 fragP
->fr_symbol
, fragP
->fr_offset
, 0, BFD_RELOC_64
);
2422 COPY_FR_WHERE_TO_FX (fragP
, tmpfixP
);
2423 mmix_gregs
[n_of_cooked_gregs
++] = tmpfixP
;
2430 #define HANDLE_MAX_RELOC(state, reloc) \
2431 case ENCODE_RELAX (state, STATE_MAX): \
2433 = mmix_relax_table[ENCODE_RELAX (state, STATE_MAX)].rlx_length; \
2434 mmix_fill_nops (var_partp, var_part_size / 4); \
2435 if (warn_on_expansion) \
2436 as_warn_where (fragP->fr_file, fragP->fr_line, \
2437 _("operand out of range, instruction expanded")); \
2438 tmpfixP = fix_new (fragP, var_partp - fragP->fr_literal - 4, 8, \
2439 fragP->fr_symbol, fragP->fr_offset, 1, reloc); \
2440 COPY_FR_WHERE_TO_FX (fragP, tmpfixP); \
2443 HANDLE_MAX_RELOC (STATE_GETA
, BFD_RELOC_MMIX_GETA
);
2444 HANDLE_MAX_RELOC (STATE_BCC
, BFD_RELOC_MMIX_CBRANCH
);
2445 HANDLE_MAX_RELOC (STATE_PUSHJ
, BFD_RELOC_MMIX_PUSHJ
);
2446 HANDLE_MAX_RELOC (STATE_JMP
, BFD_RELOC_MMIX_JMP
);
2449 BAD_CASE (fragP
->fr_subtype
);
2453 fragP
->fr_fix
+= var_part_size
;
2457 /* Applies the desired value to the specified location.
2458 Also sets up addends for RELA type relocations.
2459 Stolen from tc-mcore.c.
2461 Note that this function isn't called when linkrelax != 0. */
2464 md_apply_fix3 (fixP
, valP
, segment
)
2469 char *buf
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
2470 /* Note: use offsetT because it is signed, valueT is unsigned. */
2471 offsetT val
= (offsetT
) * valP
;
2473 = (fixP
->fx_addsy
== NULL
2474 ? absolute_section
: S_GET_SEGMENT (fixP
->fx_addsy
));
2476 /* If the fix is relative to a symbol which is not defined, or, (if
2477 pcrel), not in the same segment as the fix, we cannot resolve it
2479 if (fixP
->fx_addsy
!= NULL
2480 && (! S_IS_DEFINED (fixP
->fx_addsy
)
2481 || S_IS_WEAK (fixP
->fx_addsy
)
2482 || (fixP
->fx_pcrel
&& symsec
!= segment
)
2483 || (! fixP
->fx_pcrel
2484 && symsec
!= absolute_section
2485 && ((fixP
->fx_r_type
!= BFD_RELOC_MMIX_REG
2486 && fixP
->fx_r_type
!= BFD_RELOC_MMIX_REG_OR_BYTE
)
2487 || symsec
!= reg_section
))))
2492 else if (fixP
->fx_r_type
== BFD_RELOC_MMIX_LOCAL
2493 || fixP
->fx_r_type
== BFD_RELOC_VTABLE_INHERIT
2494 || fixP
->fx_r_type
== BFD_RELOC_VTABLE_ENTRY
)
2496 /* These are never "fixed". */
2501 /* We assume every other relocation is "fixed". */
2504 switch (fixP
->fx_r_type
)
2511 case BFD_RELOC_64_PCREL
:
2512 case BFD_RELOC_32_PCREL
:
2513 case BFD_RELOC_24_PCREL
:
2514 case BFD_RELOC_16_PCREL
:
2515 case BFD_RELOC_8_PCREL
:
2516 md_number_to_chars (buf
, val
, fixP
->fx_size
);
2519 case BFD_RELOC_MMIX_ADDR19
:
2522 /* This shouldn't happen. */
2523 BAD_CASE (fixP
->fx_r_type
);
2527 case BFD_RELOC_MMIX_GETA
:
2528 case BFD_RELOC_MMIX_CBRANCH
:
2529 case BFD_RELOC_MMIX_PUSHJ
:
2530 case BFD_RELOC_MMIX_PUSHJ_STUBBABLE
:
2531 /* If this fixup is out of range, punt to the linker to emit an
2532 error. This should only happen with -no-expand. */
2533 if (val
< -(((offsetT
) 1 << 19)/2)
2534 || val
>= ((offsetT
) 1 << 19)/2 - 1
2537 if (warn_on_expansion
)
2538 as_warn_where (fixP
->fx_file
, fixP
->fx_line
,
2539 _("operand out of range"));
2543 mmix_set_geta_branch_offset (buf
, val
);
2546 case BFD_RELOC_MMIX_ADDR27
:
2549 /* This shouldn't happen. */
2550 BAD_CASE (fixP
->fx_r_type
);
2554 case BFD_RELOC_MMIX_JMP
:
2555 /* If this fixup is out of range, punt to the linker to emit an
2556 error. This should only happen with -no-expand. */
2557 if (val
< -(((offsetT
) 1 << 27)/2)
2558 || val
>= ((offsetT
) 1 << 27)/2 - 1
2561 if (warn_on_expansion
)
2562 as_warn_where (fixP
->fx_file
, fixP
->fx_line
,
2563 _("operand out of range"));
2567 mmix_set_jmp_offset (buf
, val
);
2570 case BFD_RELOC_MMIX_REG_OR_BYTE
:
2571 if (fixP
->fx_addsy
!= NULL
2572 && (S_GET_SEGMENT (fixP
->fx_addsy
) != reg_section
2573 || S_GET_VALUE (fixP
->fx_addsy
) > 255)
2574 && S_GET_SEGMENT (fixP
->fx_addsy
) != absolute_section
)
2576 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
2577 _("invalid operands"));
2578 /* We don't want this "symbol" appearing in output, because
2585 /* If this reloc is for a Z field, we need to adjust
2586 the opcode if we got a constant here.
2587 FIXME: Can we make this more robust? */
2589 if ((fixP
->fx_where
& 3) == 3
2590 && (fixP
->fx_addsy
== NULL
2591 || S_GET_SEGMENT (fixP
->fx_addsy
) == absolute_section
))
2592 buf
[-3] |= IMM_OFFSET_BIT
;
2595 case BFD_RELOC_MMIX_REG
:
2596 if (fixP
->fx_addsy
== NULL
2597 || S_GET_SEGMENT (fixP
->fx_addsy
) != reg_section
2598 || S_GET_VALUE (fixP
->fx_addsy
) > 255)
2600 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
2601 _("invalid operands"));
2608 case BFD_RELOC_MMIX_BASE_PLUS_OFFSET
:
2609 /* These are never "fixed". */
2613 case BFD_RELOC_MMIX_PUSHJ_1
:
2614 case BFD_RELOC_MMIX_PUSHJ_2
:
2615 case BFD_RELOC_MMIX_PUSHJ_3
:
2616 case BFD_RELOC_MMIX_CBRANCH_J
:
2617 case BFD_RELOC_MMIX_CBRANCH_1
:
2618 case BFD_RELOC_MMIX_CBRANCH_2
:
2619 case BFD_RELOC_MMIX_CBRANCH_3
:
2620 case BFD_RELOC_MMIX_GETA_1
:
2621 case BFD_RELOC_MMIX_GETA_2
:
2622 case BFD_RELOC_MMIX_GETA_3
:
2623 case BFD_RELOC_MMIX_JMP_1
:
2624 case BFD_RELOC_MMIX_JMP_2
:
2625 case BFD_RELOC_MMIX_JMP_3
:
2627 BAD_CASE (fixP
->fx_r_type
);
2632 /* Make sure that for completed fixups we have the value around for
2633 use by e.g. mmix_frob_file. */
2634 fixP
->fx_offset
= val
;
2637 /* A bsearch function for looking up a value against offsets for GREG
2641 cmp_greg_val_greg_symbol_fixes (p1
, p2
)
2645 offsetT val1
= *(offsetT
*) p1
;
2646 offsetT val2
= ((struct mmix_symbol_greg_fixes
*) p2
)->offs
;
2648 if (val1
>= val2
&& val1
< val2
+ 255)
2657 /* Generate a machine-dependent relocation. */
2660 tc_gen_reloc (section
, fixP
)
2661 asection
*section ATTRIBUTE_UNUSED
;
2666 + (fixP
->fx_addsy
!= NULL
2667 && !S_IS_WEAK (fixP
->fx_addsy
)
2668 && !S_IS_COMMON (fixP
->fx_addsy
)
2669 ? S_GET_VALUE (fixP
->fx_addsy
) : 0);
2671 bfd_reloc_code_real_type code
= BFD_RELOC_NONE
;
2672 char *buf
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
2673 symbolS
*addsy
= fixP
->fx_addsy
;
2674 asection
*addsec
= addsy
== NULL
? NULL
: S_GET_SEGMENT (addsy
);
2675 asymbol
*baddsy
= addsy
!= NULL
? symbol_get_bfdsym (addsy
) : NULL
;
2677 = val
- (baddsy
== NULL
|| S_IS_COMMON (addsy
) || S_IS_WEAK (addsy
)
2678 ? 0 : bfd_asymbol_value (baddsy
));
2680 /* A single " LOCAL expression" in the wrong section will not work when
2681 linking to MMO; relocations for zero-content sections are then
2682 ignored. Normally, relocations would modify section contents, and
2683 you'd never think or be able to do something like that. The
2684 relocation resulting from a LOCAL directive doesn't have an obvious
2685 and mandatory location. I can't figure out a way to do this better
2686 than just helping the user around this limitation here; hopefully the
2687 code using the local expression is around. Putting the LOCAL
2688 semantics in a relocation still seems right; a section didn't do. */
2689 if (bfd_section_size (section
->owner
, section
) == 0)
2691 (fixP
->fx_file
, fixP
->fx_line
,
2692 fixP
->fx_r_type
== BFD_RELOC_MMIX_LOCAL
2693 /* The BFD_RELOC_MMIX_LOCAL-specific message is supposed to be
2694 user-friendly, though a little bit non-substantial. */
2695 ? _("directive LOCAL must be placed in code or data")
2696 : _("internal confusion: relocation in a section without contents"));
2698 /* FIXME: Range tests for all these. */
2699 switch (fixP
->fx_r_type
)
2706 code
= fixP
->fx_r_type
;
2708 if (addsy
== NULL
|| bfd_is_abs_section (addsec
))
2710 /* Resolve this reloc now, as md_apply_fix3 would have done (not
2711 called if -linkrelax). There is no point in keeping a reloc
2712 to an absolute symbol. No reloc that is subject to
2713 relaxation must be to an absolute symbol; difference
2714 involving symbols in a specific section must be signalled as
2715 an error if the relaxing cannot be expressed; having a reloc
2716 to the resolved (now absolute) value does not help. */
2717 md_number_to_chars (buf
, val
, fixP
->fx_size
);
2722 case BFD_RELOC_64_PCREL
:
2723 case BFD_RELOC_32_PCREL
:
2724 case BFD_RELOC_24_PCREL
:
2725 case BFD_RELOC_16_PCREL
:
2726 case BFD_RELOC_8_PCREL
:
2727 case BFD_RELOC_MMIX_LOCAL
:
2728 case BFD_RELOC_VTABLE_INHERIT
:
2729 case BFD_RELOC_VTABLE_ENTRY
:
2730 case BFD_RELOC_MMIX_GETA
:
2731 case BFD_RELOC_MMIX_GETA_1
:
2732 case BFD_RELOC_MMIX_GETA_2
:
2733 case BFD_RELOC_MMIX_GETA_3
:
2734 case BFD_RELOC_MMIX_CBRANCH
:
2735 case BFD_RELOC_MMIX_CBRANCH_J
:
2736 case BFD_RELOC_MMIX_CBRANCH_1
:
2737 case BFD_RELOC_MMIX_CBRANCH_2
:
2738 case BFD_RELOC_MMIX_CBRANCH_3
:
2739 case BFD_RELOC_MMIX_PUSHJ
:
2740 case BFD_RELOC_MMIX_PUSHJ_1
:
2741 case BFD_RELOC_MMIX_PUSHJ_2
:
2742 case BFD_RELOC_MMIX_PUSHJ_3
:
2743 case BFD_RELOC_MMIX_PUSHJ_STUBBABLE
:
2744 case BFD_RELOC_MMIX_JMP
:
2745 case BFD_RELOC_MMIX_JMP_1
:
2746 case BFD_RELOC_MMIX_JMP_2
:
2747 case BFD_RELOC_MMIX_JMP_3
:
2748 case BFD_RELOC_MMIX_ADDR19
:
2749 case BFD_RELOC_MMIX_ADDR27
:
2750 code
= fixP
->fx_r_type
;
2753 case BFD_RELOC_MMIX_REG_OR_BYTE
:
2754 /* If we have this kind of relocation to an unknown symbol or to the
2755 register contents section (that is, to a register), then we can't
2756 resolve the relocation here. */
2758 && (bfd_is_und_section (addsec
)
2759 || strcmp (bfd_get_section_name (addsec
->owner
, addsec
),
2760 MMIX_REG_CONTENTS_SECTION_NAME
) == 0))
2762 code
= fixP
->fx_r_type
;
2766 /* If the relocation is not to the register section or to the
2767 absolute section (a numeric value), then we have an error. */
2769 && (S_GET_SEGMENT (addsy
) != real_reg_section
2772 && ! bfd_is_abs_section (addsec
))
2775 /* Set the "immediate" bit of the insn if this relocation is to Z
2776 field when the value is a numeric value, i.e. not a register. */
2777 if ((fixP
->fx_where
& 3) == 3
2778 && (addsy
== NULL
|| bfd_is_abs_section (addsec
)))
2779 buf
[-3] |= IMM_OFFSET_BIT
;
2784 case BFD_RELOC_MMIX_BASE_PLUS_OFFSET
:
2786 && strcmp (bfd_get_section_name (addsec
->owner
, addsec
),
2787 MMIX_REG_CONTENTS_SECTION_NAME
) == 0)
2789 /* This changed into a register; the relocation is for the
2790 register-contents section. The constant part remains zero. */
2791 code
= BFD_RELOC_MMIX_REG
;
2795 /* If we've found out that this was indeed a register, then replace
2796 with the register number. The constant part is already zero.
2798 If we encounter any other defined symbol, then we must find a
2799 suitable register and emit a reloc. */
2800 if (addsy
== NULL
|| addsec
!= real_reg_section
)
2802 struct mmix_symbol_gregs
*gregs
;
2803 struct mmix_symbol_greg_fixes
*fix
;
2805 if (S_IS_DEFINED (addsy
)
2806 && !bfd_is_com_section (addsec
)
2807 && !S_IS_WEAK (addsy
))
2809 if (! symbol_section_p (addsy
) && ! bfd_is_abs_section (addsec
))
2810 as_fatal (_("internal: BFD_RELOC_MMIX_BASE_PLUS_OFFSET not resolved to section"));
2812 /* If this is an absolute symbol sufficiently near
2813 lowest_data_loc, then we canonicalize on the data
2814 section. Note that val is signed here; we may subtract
2815 lowest_data_loc which is unsigned. Careful with those
2817 if (lowest_data_loc
!= (bfd_vma
) -1
2818 && (bfd_vma
) val
+ 256 > lowest_data_loc
2819 && bfd_is_abs_section (addsec
))
2821 val
-= (offsetT
) lowest_data_loc
;
2822 addsy
= section_symbol (data_section
);
2824 /* Likewise text section. */
2825 else if (lowest_text_loc
!= (bfd_vma
) -1
2826 && (bfd_vma
) val
+ 256 > lowest_text_loc
2827 && bfd_is_abs_section (addsec
))
2829 val
-= (offsetT
) lowest_text_loc
;
2830 addsy
= section_symbol (text_section
);
2834 gregs
= *symbol_get_tc (addsy
);
2836 /* If that symbol does not have any associated GREG definitions,
2837 we can't do anything. */
2839 || (fix
= bsearch (&val
, gregs
->greg_fixes
, gregs
->n_gregs
,
2840 sizeof (gregs
->greg_fixes
[0]),
2841 cmp_greg_val_greg_symbol_fixes
)) == NULL
2842 /* The register must not point *after* the address we want. */
2844 /* Neither must the register point more than 255 bytes
2845 before the address we want. */
2846 || fix
->offs
+ 255 < val
)
2848 /* We can either let the linker allocate GREGs
2849 automatically, or emit an error. */
2850 if (allocate_undefined_gregs_in_linker
)
2852 /* The values in baddsy and addend are right. */
2853 code
= fixP
->fx_r_type
;
2857 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
2858 _("no suitable GREG definition for operands"));
2863 /* Transform the base-plus-offset reloc for the actual area
2864 to a reloc for the register with the address of the area.
2865 Put addend for register in Z operand. */
2866 buf
[1] = val
- fix
->offs
;
2867 code
= BFD_RELOC_MMIX_REG
;
2869 = (bfd_get_section_by_name (stdoutput
,
2870 MMIX_REG_CONTENTS_SECTION_NAME
)
2873 addend
= fix
->fix
->fx_frag
->fr_address
+ fix
->fix
->fx_where
;
2876 else if (S_GET_VALUE (addsy
) > 255)
2877 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
2878 _("invalid operands"));
2886 case BFD_RELOC_MMIX_REG
:
2888 && (bfd_is_und_section (addsec
)
2889 || strcmp (bfd_get_section_name (addsec
->owner
, addsec
),
2890 MMIX_REG_CONTENTS_SECTION_NAME
) == 0))
2892 code
= fixP
->fx_r_type
;
2897 && (addsec
!= real_reg_section
2900 && ! bfd_is_und_section (addsec
))
2901 /* Drop through to error message. */
2910 /* The others are supposed to be handled by md_apply_fix3.
2911 FIXME: ... which isn't called when -linkrelax. Move over
2912 md_apply_fix3 code here for everything reasonable. */
2916 (fixP
->fx_file
, fixP
->fx_line
,
2917 _("operands were not reducible at assembly-time"));
2919 /* Unmark this symbol as used in a reloc, so we don't bump into a BFD
2920 assert when trying to output reg_section. FIXME: A gas bug. */
2921 fixP
->fx_addsy
= NULL
;
2925 relP
= (arelent
*) xmalloc (sizeof (arelent
));
2927 relP
->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
2928 *relP
->sym_ptr_ptr
= baddsy
;
2929 relP
->address
= fixP
->fx_frag
->fr_address
+ fixP
->fx_where
;
2931 relP
->addend
= addend
;
2933 /* If this had been a.out, we would have had a kludge for weak symbols
2936 relP
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
2941 name
= S_GET_NAME (addsy
);
2943 name
= _("<unknown>");
2944 as_fatal (_("cannot generate relocation type for symbol %s, code %s"),
2945 name
, bfd_get_reloc_code_name (code
));
2951 /* Do some reformatting of a line. FIXME: We could transform a mmixal
2952 line into traditional (GNU?) format, unless #NO_APP, and get rid of all
2953 ugly labels_without_colons etc. */
2956 mmix_handle_mmixal ()
2958 char *s0
= input_line_pointer
;
2963 if (pending_label
!= NULL
)
2964 as_fatal (_("internal: unhandled label %s"), pending_label
);
2966 if (mmix_gnu_syntax
)
2969 /* If the first character is a '.', then it's a pseudodirective, not a
2970 label. Make GAS not handle label-without-colon on this line. We
2971 also don't do mmixal-specific stuff on this line. */
2972 if (input_line_pointer
[0] == '.')
2974 label_without_colon_this_line
= 0;
2978 /* Don't handle empty lines here. */
2981 if (*s0
== 0 || is_end_of_line
[(unsigned int) *s0
])
2984 if (! ISSPACE (*s0
))
2990 /* If we're on a line with a label, check if it's a mmixal fb-label.
2991 Save an indicator and skip the label; it must be set only after all
2992 fb-labels of expressions are evaluated. */
2993 if (ISDIGIT (input_line_pointer
[0])
2994 && input_line_pointer
[1] == 'H'
2995 && ISSPACE (input_line_pointer
[2]))
2998 current_fb_label
= input_line_pointer
[0] - '0';
3000 /* We have to skip the label, but also preserve the newlineness of
3001 the previous character, since the caller checks that. It's a
3002 mess we blame on the caller. */
3003 input_line_pointer
[1] = input_line_pointer
[-1];
3004 input_line_pointer
+= 2;
3006 s
= input_line_pointer
;
3007 while (*s
&& ISSPACE (*s
) && ! is_end_of_line
[(unsigned int) *s
])
3010 /* For errors emitted here, the book-keeping is off by one; the
3011 caller is about to bump the counters. Adjust the error messages. */
3012 if (is_end_of_line
[(unsigned int) *s
])
3016 as_where (&name
, &line
);
3017 as_bad_where (name
, line
+ 1,
3018 _("[0-9]H labels may not appear alone on a line"));
3019 current_fb_label
= -1;
3025 as_where (&name
, &line
);
3026 as_bad_where (name
, line
+ 1,
3027 _("[0-9]H labels do not mix with dot-pseudos"));
3028 current_fb_label
= -1;
3033 current_fb_label
= -1;
3034 if (is_name_beginner (input_line_pointer
[0]))
3035 label
= input_line_pointer
;
3038 s0
= input_line_pointer
;
3039 /* Skip over label. */
3040 while (*s0
&& is_part_of_name (*s0
))
3043 /* Remove trailing ":" off labels, as they'd otherwise be considered
3044 part of the name. But don't do it for local labels. */
3045 if (s0
!= input_line_pointer
&& s0
[-1] == ':'
3046 && (s0
- 2 != input_line_pointer
3047 || ! ISDIGIT (s0
[-2])))
3049 else if (label
!= NULL
)
3051 /* For labels that don't end in ":", we save it so we can later give
3052 it the same alignment and address as the associated instruction. */
3054 /* Make room for the label including the ending nul. */
3055 int len_0
= s0
- label
+ 1;
3057 /* Save this label on the MMIX symbol obstack. Saving it on an
3058 obstack is needless for "IS"-pseudos, but it's harmless and we
3059 avoid a little code-cluttering. */
3060 obstack_grow (&mmix_sym_obstack
, label
, len_0
);
3061 pending_label
= obstack_finish (&mmix_sym_obstack
);
3062 pending_label
[len_0
- 1] = 0;
3065 while (*s0
&& ISSPACE (*s0
) && ! is_end_of_line
[(unsigned int) *s0
])
3068 if (pending_label
!= NULL
&& is_end_of_line
[(unsigned int) *s0
])
3069 /* Whoops, this was actually a lone label on a line. Like :-ended
3070 labels, we don't attach such labels to the next instruction or
3072 pending_label
= NULL
;
3074 /* Find local labels of operands. Look for "[0-9][FB]" where the
3075 characters before and after are not part of words. Break if a single
3076 or double quote is seen anywhere. It means we can't have local
3077 labels as part of list with mixed quoted and unquoted members for
3078 mmixal compatibility but we can't have it all. For the moment.
3079 Replace the '<N>B' or '<N>F' with MAGIC_FB_BACKWARD_CHAR<N> and
3080 MAGIC_FB_FORWARD_CHAR<N> respectively. */
3082 /* First make sure we don't have any of the magic characters on the line
3083 appearing as input. */
3088 if (is_end_of_line
[(unsigned int) c
])
3090 if (c
== MAGIC_FB_BACKWARD_CHAR
|| c
== MAGIC_FB_FORWARD_CHAR
)
3091 as_bad (_("invalid characters in input"));
3094 /* Scan again, this time looking for ';' after operands. */
3097 /* Skip the insn. */
3101 && ! is_end_of_line
[(unsigned int) *s
])
3104 /* Skip the spaces after the insn. */
3108 && ! is_end_of_line
[(unsigned int) *s
])
3111 /* Skip the operands. While doing this, replace [0-9][BF] with
3112 (MAGIC_FB_BACKWARD_CHAR|MAGIC_FB_FORWARD_CHAR)[0-9]. */
3113 while ((c
= *s
) != 0
3116 && ! is_end_of_line
[(unsigned int) c
])
3122 /* FIXME: Test-case for semi-colon in string. */
3125 && (! is_end_of_line
[(unsigned int) *s
] || *s
== ';'))
3131 else if (ISDIGIT (c
))
3133 if ((s
[1] != 'B' && s
[1] != 'F')
3134 || is_part_of_name (s
[-1])
3135 || is_part_of_name (s
[2]))
3140 ? MAGIC_FB_BACKWARD_CHAR
: MAGIC_FB_FORWARD_CHAR
);
3148 /* Skip any spaces after the operands. */
3152 && !is_end_of_line
[(unsigned int) *s
])
3155 /* If we're now looking at a semi-colon, then it's an end-of-line
3157 mmix_next_semicolon_is_eoln
= (*s
== ';');
3159 /* Make IS into an EQU by replacing it with "= ". Only match upper-case
3160 though; let lower-case be a syntax error. */
3162 if (s
[0] == 'I' && s
[1] == 'S' && ISSPACE (s
[2]))
3167 /* Since labels can start without ":", we have to handle "X IS 42"
3168 in full here, or "X" will be parsed as a label to be set at ".". */
3169 input_line_pointer
= s
;
3171 /* Right after this function ends, line numbers will be bumped if
3172 input_line_pointer[-1] = '\n'. We want accurate line numbers for
3173 the equals call, so we bump them before the call, and make sure
3174 they aren't bumped afterwards. */
3175 bump_line_counters ();
3177 /* A fb-label is valid as an IS-label. */
3178 if (current_fb_label
>= 0)
3182 /* We need to save this name on our symbol obstack, since the
3183 string we got in fb_label_name is volatile and will change
3184 with every call to fb_label_name, like those resulting from
3185 parsing the IS-operand. */
3186 fb_name
= fb_label_name (current_fb_label
, 1);
3187 obstack_grow (&mmix_sym_obstack
, fb_name
, strlen (fb_name
) + 1);
3188 equals (obstack_finish (&mmix_sym_obstack
), 0);
3189 fb_label_instance_inc (current_fb_label
);
3190 current_fb_label
= -1;
3194 if (pending_label
== NULL
)
3195 as_bad (_("empty label field for IS"));
3197 equals (pending_label
, 0);
3198 pending_label
= NULL
;
3201 /* For mmixal, we can have comments without a comment-start
3203 mmix_handle_rest_of_empty_line ();
3204 input_line_pointer
--;
3206 input_line_pointer
[-1] = ' ';
3208 else if (s
[0] == 'G'
3210 && strncmp (s
, "GREG", 4) == 0
3211 && (ISSPACE (s
[4]) || is_end_of_line
[(unsigned char) s
[4]]))
3213 input_line_pointer
= s
+ 4;
3215 /* Right after this function ends, line numbers will be bumped if
3216 input_line_pointer[-1] = '\n'. We want accurate line numbers for
3217 the s_greg call, so we bump them before the call, and make sure
3218 they aren't bumped afterwards. */
3219 bump_line_counters ();
3221 /* A fb-label is valid as a GREG-label. */
3222 if (current_fb_label
>= 0)
3226 /* We need to save this name on our symbol obstack, since the
3227 string we got in fb_label_name is volatile and will change
3228 with every call to fb_label_name, like those resulting from
3229 parsing the IS-operand. */
3230 fb_name
= fb_label_name (current_fb_label
, 1);
3232 /* Make sure we save the canonical name and don't get bitten by
3234 obstack_1grow (&mmix_sym_obstack
, ':');
3235 obstack_grow (&mmix_sym_obstack
, fb_name
, strlen (fb_name
) + 1);
3236 mmix_greg_internal (obstack_finish (&mmix_sym_obstack
));
3237 fb_label_instance_inc (current_fb_label
);
3238 current_fb_label
= -1;
3241 mmix_greg_internal (pending_label
);
3243 /* Back up before the end-of-line marker that was skipped in
3244 mmix_greg_internal. */
3245 input_line_pointer
--;
3246 input_line_pointer
[-1] = ' ';
3248 pending_label
= NULL
;
3250 else if (pending_label
!= NULL
)
3252 input_line_pointer
+= strlen (pending_label
);
3254 /* See comment above about getting line numbers bumped. */
3255 input_line_pointer
[-1] = '\n';
3259 /* Give the value of an fb-label rewritten as in mmix_handle_mmixal, when
3260 parsing an expression.
3262 On valid calls, input_line_pointer points at a MAGIC_FB_BACKWARD_CHAR
3263 or MAGIC_FB_BACKWARD_CHAR, followed by an ascii digit for the label.
3264 We fill in the label as an expression. */
3267 mmix_fb_label (expP
)
3271 char *fb_internal_name
;
3273 /* This doesn't happen when not using mmixal syntax. */
3275 || (input_line_pointer
[0] != MAGIC_FB_BACKWARD_CHAR
3276 && input_line_pointer
[0] != MAGIC_FB_FORWARD_CHAR
))
3279 /* The current backward reference has augmentation 0. A forward
3280 reference has augmentation 1, unless it's the same as a fb-label on
3281 _this_ line, in which case we add one more so we don't refer to it.
3282 This is the semantics of mmixal; it differs to that of common
3283 fb-labels which refer to a here-label on the current line as a
3284 backward reference. */
3286 = fb_label_name (input_line_pointer
[1] - '0',
3287 (input_line_pointer
[0] == MAGIC_FB_FORWARD_CHAR
? 1 : 0)
3288 + ((input_line_pointer
[1] - '0' == current_fb_label
3289 && input_line_pointer
[0] == MAGIC_FB_FORWARD_CHAR
)
3292 input_line_pointer
+= 2;
3293 sym
= symbol_find_or_make (fb_internal_name
);
3295 /* We don't have to clean up unrelated fields here; we just do what the
3296 expr machinery does, but *not* just what it does for [0-9][fb], since
3297 we need to treat those as ordinary symbols sometimes; see testcases
3298 err-byte2.s and fb-2.s. */
3299 if (S_GET_SEGMENT (sym
) == absolute_section
)
3301 expP
->X_op
= O_constant
;
3302 expP
->X_add_number
= S_GET_VALUE (sym
);
3306 expP
->X_op
= O_symbol
;
3307 expP
->X_add_symbol
= sym
;
3308 expP
->X_add_number
= 0;
3312 /* See whether we need to force a relocation into the output file.
3313 This is used to force out switch and PC relative relocations when
3317 mmix_force_relocation (fixP
)
3320 if (fixP
->fx_r_type
== BFD_RELOC_MMIX_LOCAL
3321 || fixP
->fx_r_type
== BFD_RELOC_MMIX_BASE_PLUS_OFFSET
)
3327 /* All our pcrel relocations are must-keep. Note that md_apply_fix3 is
3328 called *after* this, and will handle getting rid of the presumed
3329 reloc; a relocation isn't *forced* other than to be handled by
3330 md_apply_fix3 (or tc_gen_reloc if linkrelax). */
3334 return generic_force_reloc (fixP
);
3337 /* The location from which a PC relative jump should be calculated,
3338 given a PC relative reloc. */
3341 md_pcrel_from_section (fixP
, sec
)
3345 if (fixP
->fx_addsy
!= (symbolS
*) NULL
3346 && (! S_IS_DEFINED (fixP
->fx_addsy
)
3347 || S_GET_SEGMENT (fixP
->fx_addsy
) != sec
))
3349 /* The symbol is undefined (or is defined but not in this section).
3350 Let the linker figure it out. */
3354 return (fixP
->fx_frag
->fr_address
+ fixP
->fx_where
);
3357 /* Adjust the symbol table. We make reg_section relative to the real
3358 register section. */
3361 mmix_adjust_symtab ()
3364 symbolS
*regsec
= section_symbol (reg_section
);
3366 for (sym
= symbol_rootP
; sym
!= NULL
; sym
= symbol_next (sym
))
3367 if (S_GET_SEGMENT (sym
) == reg_section
)
3371 if (S_IS_EXTERN (sym
) || symbol_used_in_reloc_p (sym
))
3373 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
3376 /* Change section to the *real* register section, so it gets
3377 proper treatment when writing it out. Only do this for
3378 global symbols. This also means we don't have to check for
3380 S_SET_SEGMENT (sym
, real_reg_section
);
3384 /* This is the expansion of LABELS_WITHOUT_COLONS.
3385 We let md_start_line_hook tweak label_without_colon_this_line, and then
3386 this function returns the tweaked value, and sets it to 1 for the next
3387 line. FIXME: Very, very brittle. Not sure it works the way I
3388 thought at the time I first wrote this. */
3391 mmix_label_without_colon_this_line ()
3393 int retval
= label_without_colon_this_line
;
3395 if (! mmix_gnu_syntax
)
3396 label_without_colon_this_line
= 1;
3401 /* This is the expansion of md_relax_frag. We go through the ordinary
3402 relax table function except when the frag is for a GREG. Then we have
3403 to check whether there's another GREG by the same value that we can
3407 mmix_md_relax_frag (seg
, fragP
, stretch
)
3412 switch (fragP
->fr_subtype
)
3414 /* Growth for this type has been handled by mmix_md_end and
3415 correctly estimated, so there's nothing more to do here. */
3416 case STATE_GREG_DEF
:
3419 case ENCODE_RELAX (STATE_PUSHJ
, STATE_ZERO
):
3421 /* We need to handle relaxation type ourselves, since relax_frag
3422 doesn't update fr_subtype if there's no size increase in the
3423 current section; when going from plain PUSHJ to a stub. This
3424 is otherwise functionally the same as relax_frag in write.c,
3425 simplified for this case. */
3430 target
= fragP
->fr_offset
;
3431 address
= fragP
->fr_address
;
3432 symbolP
= fragP
->fr_symbol
;
3438 sym_frag
= symbol_get_frag (symbolP
);
3439 know (S_GET_SEGMENT (symbolP
) != absolute_section
3440 || sym_frag
== &zero_address_frag
);
3441 target
+= S_GET_VALUE (symbolP
);
3443 /* If frag has yet to be reached on this pass, assume it will
3444 move by STRETCH just as we did. If this is not so, it will
3445 be because some frag between grows, and that will force
3449 && sym_frag
->relax_marker
!= fragP
->relax_marker
3450 && S_GET_SEGMENT (symbolP
) == seg
)
3454 aim
= target
- address
- fragP
->fr_fix
;
3455 if (aim
>= PUSHJ_0B
&& aim
<= PUSHJ_0F
)
3457 /* Target is reachable with a PUSHJ. */
3458 segment_info_type
*seginfo
= seg_info (seg
);
3460 /* If we're at the end of a relaxation round, clear the stub
3461 counter as initialization for the next round. */
3462 if (fragP
== seginfo
->tc_segment_info_data
.last_stubfrag
)
3463 seginfo
->tc_segment_info_data
.nstubs
= 0;
3467 /* Not reachable. Try a stub. */
3468 fragP
->fr_subtype
= ENCODE_RELAX (STATE_PUSHJSTUB
, STATE_ZERO
);
3472 /* See if this PUSHJ is redirectable to a stub. */
3473 case ENCODE_RELAX (STATE_PUSHJSTUB
, STATE_ZERO
):
3475 segment_info_type
*seginfo
= seg_info (seg
);
3476 fragS
*lastfrag
= seginfo
->frchainP
->frch_last
;
3477 relax_substateT prev_type
= fragP
->fr_subtype
;
3479 /* The last frag is always an empty frag, so it suffices to look
3480 at its address to know the ending address of this section. */
3481 know (lastfrag
->fr_type
== rs_fill
3482 && lastfrag
->fr_fix
== 0
3483 && lastfrag
->fr_var
== 0);
3485 /* For this PUSHJ to be relaxable into a call to a stub, the
3486 distance must be no longer than 256k bytes from the PUSHJ to
3487 the end of the section plus the maximum size of stubs so far. */
3488 if ((lastfrag
->fr_address
3490 + PUSHJ_MAX_LEN
* seginfo
->tc_segment_info_data
.nstubs
)
3491 - (fragP
->fr_address
+ fragP
->fr_fix
)
3494 fragP
->fr_subtype
= mmix_relax_table
[prev_type
].rlx_more
;
3496 seginfo
->tc_segment_info_data
.nstubs
++;
3498 /* If we're at the end of a relaxation round, clear the stub
3499 counter as initialization for the next round. */
3500 if (fragP
== seginfo
->tc_segment_info_data
.last_stubfrag
)
3501 seginfo
->tc_segment_info_data
.nstubs
= 0;
3504 (mmix_relax_table
[fragP
->fr_subtype
].rlx_length
3505 - mmix_relax_table
[prev_type
].rlx_length
);
3508 case ENCODE_RELAX (STATE_PUSHJ
, STATE_MAX
):
3510 segment_info_type
*seginfo
= seg_info (seg
);
3512 /* Need to cover all STATE_PUSHJ states to act on the last stub
3513 frag (the end of this relax round; initialization for the
3515 if (fragP
== seginfo
->tc_segment_info_data
.last_stubfrag
)
3516 seginfo
->tc_segment_info_data
.nstubs
= 0;
3522 return relax_frag (seg
, fragP
, stretch
);
3524 case STATE_GREG_UNDF
:
3525 BAD_CASE (fragP
->fr_subtype
);
3528 as_fatal (_("internal: unexpected relax type %d:%d"),
3529 fragP
->fr_type
, fragP
->fr_subtype
);
3533 /* Various things we punt until all input is seen. */
3542 /* The first frag of GREG:s going into the register contents section. */
3543 fragS
*mmix_reg_contents_frags
= NULL
;
3545 /* Reset prefix. All labels reachable at this point must be
3547 mmix_current_prefix
= NULL
;
3550 as_bad_where (bspec_file
, bspec_line
, _("BSPEC without ESPEC."));
3552 /* Emit the low LOC setting of .text. */
3553 if (text_has_contents
&& lowest_text_loc
!= (bfd_vma
) -1)
3556 char locsymbol
[sizeof (":") - 1
3557 + sizeof (MMIX_LOC_SECTION_START_SYMBOL_PREFIX
) - 1
3558 + sizeof (".text")];
3560 /* An exercise in non-ISO-C-ness, this one. */
3561 sprintf (locsymbol
, ":%s%s", MMIX_LOC_SECTION_START_SYMBOL_PREFIX
,
3564 = symbol_new (locsymbol
, absolute_section
, lowest_text_loc
,
3565 &zero_address_frag
);
3566 S_SET_EXTERNAL (symbolP
);
3570 if (data_has_contents
&& lowest_data_loc
!= (bfd_vma
) -1)
3573 char locsymbol
[sizeof (":") - 1
3574 + sizeof (MMIX_LOC_SECTION_START_SYMBOL_PREFIX
) - 1
3575 + sizeof (".data")];
3577 sprintf (locsymbol
, ":%s%s", MMIX_LOC_SECTION_START_SYMBOL_PREFIX
,
3580 = symbol_new (locsymbol
, absolute_section
, lowest_data_loc
,
3581 &zero_address_frag
);
3582 S_SET_EXTERNAL (symbolP
);
3585 /* Unless GNU syntax mode, set "Main" to be a function, so the
3586 disassembler doesn't get confused when we write truly
3587 mmixal-compatible code (and don't use .type). Similarly set it
3588 global (regardless of -globalize-symbols), so the linker sees it as
3589 the start symbol in ELF mode. */
3590 mainsym
= symbol_find (MMIX_START_SYMBOL_NAME
);
3591 if (mainsym
!= NULL
&& ! mmix_gnu_syntax
)
3593 symbol_get_bfdsym (mainsym
)->flags
|= BSF_FUNCTION
;
3594 S_SET_EXTERNAL (mainsym
);
3597 if (n_of_raw_gregs
!= 0)
3599 /* Emit GREGs. They are collected in order of appearance, but must
3600 be emitted in opposite order to both have section address regno*8
3601 and the same allocation order (within a file) as mmixal. */
3602 segT this_segment
= now_seg
;
3603 subsegT this_subsegment
= now_subseg
;
3605 = bfd_make_section_old_way (stdoutput
,
3606 MMIX_REG_CONTENTS_SECTION_NAME
);
3607 subseg_set (regsec
, 0);
3609 /* Finally emit the initialization-value. Emit a variable frag, which
3610 we'll fix in md_estimate_size_before_relax. We set the initializer
3611 for the tc_frag_data field to NULL, so we can use that field for
3612 relaxation purposes. */
3613 mmix_opcode_frag
= NULL
;
3616 mmix_reg_contents_frags
= frag_now
;
3618 for (i
= n_of_raw_gregs
- 1; i
>= 0; i
--)
3620 if (mmix_raw_gregs
[i
].label
!= NULL
)
3621 /* There's a symbol. Let it refer to this location in the
3622 register contents section. The symbol must be globalized
3624 colon (mmix_raw_gregs
[i
].label
);
3626 frag_var (rs_machine_dependent
, 8, 0, STATE_GREG_UNDF
,
3627 make_expr_symbol (&mmix_raw_gregs
[i
].exp
), 0, NULL
);
3630 subseg_set (this_segment
, this_subsegment
);
3633 /* Iterate over frags resulting from GREGs and move those that evidently
3634 have the same value together and point one to another.
3636 This works in time O(N^2) but since the upper bound for non-error use
3637 is 223, it's best to keep this simpler algorithm. */
3638 for (fragP
= mmix_reg_contents_frags
; fragP
!= NULL
; fragP
= fragP
->fr_next
)
3645 symbolS
*symbolP
= fragP
->fr_symbol
;
3647 if (fragP
->fr_type
!= rs_machine_dependent
3648 || fragP
->fr_subtype
!= STATE_GREG_UNDF
)
3651 /* Whatever the outcome, we will have this GREG judged merged or
3652 non-merged. Since the tc_frag_data is NULL at this point, we
3653 default to non-merged. */
3654 fragP
->fr_subtype
= STATE_GREG_DEF
;
3656 /* If we're not supposed to merge GREG definitions, then just don't
3657 look for equivalents. */
3661 osymval
= (offsetT
) S_GET_VALUE (symbolP
);
3662 osymfrag
= symbol_get_frag (symbolP
);
3664 /* If the symbol isn't defined, we can't say that another symbol
3665 equals this frag, then. FIXME: We can look at the "deepest"
3666 defined name; if a = c and b = c then obviously a == b. */
3667 if (! S_IS_DEFINED (symbolP
))
3670 oexpP
= symbol_get_value_expression (fragP
->fr_symbol
);
3672 /* If the initialization value is zero, then we must not merge them. */
3673 if (oexpP
->X_op
== O_constant
&& osymval
== 0)
3676 /* Iterate through the frags downward this one. If we find one that
3677 has the same non-zero value, move it to after this one and point
3678 to it as the equivalent. */
3679 for (fpp
= &fragP
->fr_next
; *fpp
!= NULL
; fpp
= &fpp
[0]->fr_next
)
3683 if (fp
->fr_type
!= rs_machine_dependent
3684 || fp
->fr_subtype
!= STATE_GREG_UNDF
)
3687 /* Calling S_GET_VALUE may simplify the symbol, changing from
3688 expr_section etc. so call it first. */
3689 if ((offsetT
) S_GET_VALUE (fp
->fr_symbol
) == osymval
3690 && symbol_get_frag (fp
->fr_symbol
) == osymfrag
)
3692 /* Move the frag links so the one we found equivalent comes
3693 after the current one, carefully considering that
3694 sometimes fpp == &fragP->fr_next and the moves must be a
3697 fp
->fr_next
= fragP
->fr_next
;
3698 fragP
->fr_next
= fp
;
3704 fragP
->tc_frag_data
= fp
;
3708 /* qsort function for mmix_symbol_gregs. */
3711 cmp_greg_symbol_fixes (parg
, qarg
)
3715 const struct mmix_symbol_greg_fixes
*p
3716 = (const struct mmix_symbol_greg_fixes
*) parg
;
3717 const struct mmix_symbol_greg_fixes
*q
3718 = (const struct mmix_symbol_greg_fixes
*) qarg
;
3720 return p
->offs
> q
->offs
? 1 : p
->offs
< q
->offs
? -1 : 0;
3723 /* Collect GREG definitions from mmix_gregs and hang them as lists sorted
3724 on increasing offsets onto each section symbol or undefined symbol.
3726 Also, remove the register convenience section so it doesn't get output
3727 as an ELF section. */
3733 struct mmix_symbol_gregs
*all_greg_symbols
[MAX_GREGS
];
3734 int n_greg_symbols
= 0;
3736 /* Collect all greg fixups and decorate each corresponding symbol with
3737 the greg fixups for it. */
3738 for (i
= 0; i
< n_of_cooked_gregs
; i
++)
3742 struct mmix_symbol_gregs
*gregs
;
3745 fixP
= mmix_gregs
[i
];
3746 know (fixP
->fx_r_type
== BFD_RELOC_64
);
3748 /* This case isn't doable in general anyway, methinks. */
3749 if (fixP
->fx_subsy
!= NULL
)
3751 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3752 _("GREG expression too complicated"));
3756 sym
= fixP
->fx_addsy
;
3757 offs
= (offsetT
) fixP
->fx_offset
;
3759 /* If the symbol is defined, then it must be resolved to a section
3760 symbol at this time, or else we don't know how to handle it. */
3761 if (S_IS_DEFINED (sym
)
3762 && !bfd_is_com_section (S_GET_SEGMENT (sym
))
3763 && !S_IS_WEAK (sym
))
3765 if (! symbol_section_p (sym
)
3766 && ! bfd_is_abs_section (S_GET_SEGMENT (sym
)))
3767 as_fatal (_("internal: GREG expression not resolved to section"));
3769 offs
+= S_GET_VALUE (sym
);
3772 /* If this is an absolute symbol sufficiently near lowest_data_loc,
3773 then we canonicalize on the data section. Note that offs is
3774 signed here; we may subtract lowest_data_loc which is unsigned.
3775 Careful with those comparisons. */
3776 if (lowest_data_loc
!= (bfd_vma
) -1
3777 && (bfd_vma
) offs
+ 256 > lowest_data_loc
3778 && bfd_is_abs_section (S_GET_SEGMENT (sym
)))
3780 offs
-= (offsetT
) lowest_data_loc
;
3781 sym
= section_symbol (data_section
);
3783 /* Likewise text section. */
3784 else if (lowest_text_loc
!= (bfd_vma
) -1
3785 && (bfd_vma
) offs
+ 256 > lowest_text_loc
3786 && bfd_is_abs_section (S_GET_SEGMENT (sym
)))
3788 offs
-= (offsetT
) lowest_text_loc
;
3789 sym
= section_symbol (text_section
);
3792 gregs
= *symbol_get_tc (sym
);
3796 gregs
= xmalloc (sizeof (*gregs
));
3798 symbol_set_tc (sym
, &gregs
);
3799 all_greg_symbols
[n_greg_symbols
++] = gregs
;
3802 gregs
->greg_fixes
[gregs
->n_gregs
].fix
= fixP
;
3803 gregs
->greg_fixes
[gregs
->n_gregs
++].offs
= offs
;
3806 /* For each symbol having a GREG definition, sort those definitions on
3808 for (i
= 0; i
< n_greg_symbols
; i
++)
3809 qsort (all_greg_symbols
[i
]->greg_fixes
, all_greg_symbols
[i
]->n_gregs
,
3810 sizeof (all_greg_symbols
[i
]->greg_fixes
[0]), cmp_greg_symbol_fixes
);
3812 if (real_reg_section
!= NULL
)
3816 /* FIXME: Pass error state gracefully. */
3817 if (bfd_get_section_flags (stdoutput
, real_reg_section
) & SEC_HAS_CONTENTS
)
3818 as_fatal (_("register section has contents\n"));
3820 /* Really remove the section. */
3821 for (secpp
= &stdoutput
->sections
;
3822 *secpp
!= real_reg_section
;
3823 secpp
= &(*secpp
)->next
)
3825 bfd_section_list_remove (stdoutput
, secpp
);
3826 --stdoutput
->section_count
;
3831 /* Provide an expression for a built-in name provided when-used.
3832 Either a symbol that is a handler; living in 0x10*[1..8] and having
3833 name [DVWIOUZX]_Handler, or a mmixal built-in symbol.
3835 If the name isn't a built-in name and parsed into *EXPP, return zero. */
3838 mmix_parse_predefined_name (name
, expP
)
3843 char *handler_charp
;
3844 const char handler_chars
[] = "DVWIOUZX";
3847 if (! predefined_syms
)
3850 canon_name
= tc_canonicalize_symbol_name (name
);
3852 if (canon_name
[1] == '_'
3853 && strcmp (canon_name
+ 2, "Handler") == 0
3854 && (handler_charp
= strchr (handler_chars
, *canon_name
)) != NULL
)
3856 /* If the symbol doesn't exist, provide one relative to the .text
3859 FIXME: We should provide separate sections, mapped in the linker
3861 symp
= symbol_find (name
);
3863 symp
= symbol_new (name
, text_section
,
3864 0x10 * (handler_charp
+ 1 - handler_chars
),
3865 &zero_address_frag
);
3869 /* These symbols appear when referenced; needed for
3870 mmixal-compatible programs. */
3877 } predefined_abs_syms
[] =
3879 {"Data_Segment", (valueT
) 0x20 << 56},
3880 {"Pool_Segment", (valueT
) 0x40 << 56},
3881 {"Stack_Segment", (valueT
) 0x60 << 56},
3889 {"BinaryReadWrite", 4},
3912 /* If it's already in the symbol table, we shouldn't do anything. */
3913 symp
= symbol_find (name
);
3918 i
< sizeof (predefined_abs_syms
) / sizeof (predefined_abs_syms
[0]);
3920 if (strcmp (canon_name
, predefined_abs_syms
[i
].name
) == 0)
3922 symbol_table_insert (symbol_new (predefined_abs_syms
[i
].name
,
3924 predefined_abs_syms
[i
].val
,
3925 &zero_address_frag
));
3927 /* Let gas find the symbol we just created, through its
3932 /* Not one of those symbols. Let gas handle it. */
3936 expP
->X_op
= O_symbol
;
3937 expP
->X_add_number
= 0;
3938 expP
->X_add_symbol
= symp
;
3939 expP
->X_op_symbol
= NULL
;
3944 /* Just check that we don't have a BSPEC/ESPEC pair active when changing
3945 sections "normally", and get knowledge about alignment from the new
3949 mmix_md_elf_section_change_hook ()
3952 as_bad (_("section change from within a BSPEC/ESPEC pair is not supported"));
3954 last_alignment
= bfd_get_section_alignment (now_seg
->owner
, now_seg
);
3958 /* The LOC worker. This is like s_org, but we have to support changing
3963 int ignore ATTRIBUTE_UNUSED
;
3971 /* Must not have a BSPEC in progress. */
3974 as_bad (_("directive LOC from within a BSPEC/ESPEC pair is not supported"));
3978 section
= expression (&exp
);
3980 if (exp
.X_op
== O_illegal
3981 || exp
.X_op
== O_absent
3982 || exp
.X_op
== O_big
3983 || section
== undefined_section
)
3985 as_bad (_("invalid LOC expression"));
3989 if (section
== absolute_section
)
3991 /* Translate a constant into a suitable section. */
3993 if (exp
.X_add_number
< ((offsetT
) 0x20 << 56))
3995 /* Lower than Data_Segment - assume it's .text. */
3996 section
= text_section
;
3998 /* Save the lowest seen location, so we can pass on this
3999 information to the linker. We don't actually org to this
4000 location here, we just pass on information to the linker so
4001 it can put the code there for us. */
4003 /* If there was already a loc (that has to be set lower than
4004 this one), we org at (this - lower). There's an implicit
4005 "LOC 0" before any entered code. FIXME: handled by spurious
4006 settings of text_has_contents. */
4007 if (exp
.X_add_number
< 0
4008 || exp
.X_add_number
< (offsetT
) lowest_text_loc
)
4010 as_bad (_("LOC expression stepping backwards is not supported"));
4011 exp
.X_op
= O_absent
;
4015 if (text_has_contents
&& lowest_text_loc
== (bfd_vma
) -1)
4016 lowest_text_loc
= 0;
4018 if (lowest_text_loc
== (bfd_vma
) -1)
4020 lowest_text_loc
= exp
.X_add_number
;
4022 /* We want only to change the section, not set an offset. */
4023 exp
.X_op
= O_absent
;
4026 exp
.X_add_number
-= lowest_text_loc
;
4031 /* Do the same for the .data section. */
4032 section
= data_section
;
4034 if (exp
.X_add_number
< (offsetT
) lowest_data_loc
)
4036 as_bad (_("LOC expression stepping backwards is not supported"));
4037 exp
.X_op
= O_absent
;
4041 if (data_has_contents
&& lowest_data_loc
== (bfd_vma
) -1)
4042 lowest_data_loc
= (bfd_vma
) 0x20 << 56;
4044 if (lowest_data_loc
== (bfd_vma
) -1)
4046 lowest_data_loc
= exp
.X_add_number
;
4048 /* We want only to change the section, not set an offset. */
4049 exp
.X_op
= O_absent
;
4052 exp
.X_add_number
-= lowest_data_loc
;
4057 if (section
!= now_seg
)
4059 obj_elf_section_change_hook ();
4060 subseg_set (section
, 0);
4062 /* Call our section change hooks using the official hook. */
4063 md_elf_section_change_hook ();
4066 if (exp
.X_op
!= O_absent
)
4068 if (exp
.X_op
!= O_constant
&& exp
.X_op
!= O_symbol
)
4070 /* Handle complex expressions. */
4071 sym
= make_expr_symbol (&exp
);
4076 sym
= exp
.X_add_symbol
;
4077 off
= exp
.X_add_number
;
4080 p
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, sym
, off
, (char *) 0);
4084 mmix_handle_rest_of_empty_line ();
4087 /* The BYTE worker. We have to support sequences of mixed "strings",
4088 numbers and other constant "first-pass" reducible expressions separated
4097 if (now_seg
== text_section
)
4098 text_has_contents
= 1;
4099 else if (now_seg
== data_section
)
4100 data_has_contents
= 1;
4105 switch (*input_line_pointer
)
4108 ++input_line_pointer
;
4109 start
= input_line_pointer
;
4110 while (is_a_char (c
= next_char_of_string ()))
4112 FRAG_APPEND_1_CHAR (c
);
4115 if (input_line_pointer
[-1] != '\"')
4117 /* We will only get here in rare cases involving #NO_APP,
4118 where the unterminated string is not recognized by the
4119 preformatting pass. */
4120 as_bad (_("unterminated string"));
4121 mmix_discard_rest_of_line ();
4129 segT expseg
= expression (&exp
);
4131 /* We have to allow special register names as constant numbers. */
4132 if ((expseg
!= absolute_section
&& expseg
!= reg_section
)
4133 || (exp
.X_op
!= O_constant
4134 && (exp
.X_op
!= O_register
4135 || exp
.X_add_number
<= 255)))
4137 as_bad (_("BYTE expression not a pure number"));
4138 mmix_discard_rest_of_line ();
4141 else if ((exp
.X_add_number
> 255 && exp
.X_op
!= O_register
)
4142 || exp
.X_add_number
< 0)
4144 /* Note that mmixal does not allow negative numbers in
4145 BYTE sequences, so neither should we. */
4146 as_bad (_("BYTE expression not in the range 0..255"));
4147 mmix_discard_rest_of_line ();
4151 FRAG_APPEND_1_CHAR (exp
.X_add_number
);
4157 c
= *input_line_pointer
++;
4161 input_line_pointer
--;
4163 if (mmix_gnu_syntax
)
4164 demand_empty_rest_of_line ();
4167 mmix_discard_rest_of_line ();
4168 /* Do like demand_empty_rest_of_line and step over the end-of-line
4170 input_line_pointer
++;
4173 /* Make sure we align for the next instruction. */
4177 /* Like cons_worker, but we have to ignore "naked comments", not barf on
4178 them. Implements WYDE, TETRA and OCTA. We're a little bit more
4179 lenient than mmix_byte but FIXME: they should eventually merge. */
4188 /* If we don't have any contents, then it's ok to have a specified start
4189 address that is not a multiple of the max data size. We will then
4190 align it as necessary when we get here. Otherwise, it's a fatal sin. */
4191 if (now_seg
== text_section
)
4193 if (lowest_text_loc
!= (bfd_vma
) -1
4194 && (lowest_text_loc
& (nbytes
- 1)) != 0)
4196 if (text_has_contents
)
4197 as_bad (_("data item with alignment larger than location"));
4198 else if (want_unaligned
)
4199 as_bad (_("unaligned data at an absolute location is not supported"));
4201 lowest_text_loc
&= ~((bfd_vma
) nbytes
- 1);
4202 lowest_text_loc
+= (bfd_vma
) nbytes
;
4205 text_has_contents
= 1;
4207 else if (now_seg
== data_section
)
4209 if (lowest_data_loc
!= (bfd_vma
) -1
4210 && (lowest_data_loc
& (nbytes
- 1)) != 0)
4212 if (data_has_contents
)
4213 as_bad (_("data item with alignment larger than location"));
4214 else if (want_unaligned
)
4215 as_bad (_("unaligned data at an absolute location is not supported"));
4217 lowest_data_loc
&= ~((bfd_vma
) nbytes
- 1);
4218 lowest_data_loc
+= (bfd_vma
) nbytes
;
4221 data_has_contents
= 1;
4224 /* Always align these unless asked not to (valid for the current pseudo). */
4225 if (! want_unaligned
)
4227 last_alignment
= nbytes
== 2 ? 1 : (nbytes
== 4 ? 2 : 3);
4228 frag_align (last_alignment
, 0, 0);
4229 record_alignment (now_seg
, last_alignment
);
4232 /* For mmixal compatibility, a label for an instruction (and emitting
4233 pseudo) refers to the _aligned_ address. So we have to emit the
4235 if (current_fb_label
>= 0)
4236 colon (fb_label_name (current_fb_label
, 1));
4237 else if (pending_label
!= NULL
)
4239 colon (pending_label
);
4240 pending_label
= NULL
;
4245 if (is_end_of_line
[(unsigned int) *input_line_pointer
])
4247 /* Default to zero if the expression was absent. */
4249 exp
.X_op
= O_constant
;
4250 exp
.X_add_number
= 0;
4252 exp
.X_add_symbol
= NULL
;
4253 exp
.X_op_symbol
= NULL
;
4254 emit_expr (&exp
, (unsigned int) nbytes
);
4261 switch (*input_line_pointer
)
4263 /* We support strings here too; each character takes up nbytes
4266 ++input_line_pointer
;
4267 start
= input_line_pointer
;
4268 while (is_a_char (c
= next_char_of_string ()))
4270 exp
.X_op
= O_constant
;
4271 exp
.X_add_number
= c
;
4273 emit_expr (&exp
, (unsigned int) nbytes
);
4276 if (input_line_pointer
[-1] != '\"')
4278 /* We will only get here in rare cases involving #NO_APP,
4279 where the unterminated string is not recognized by the
4280 preformatting pass. */
4281 as_bad (_("unterminated string"));
4282 mmix_discard_rest_of_line ();
4290 emit_expr (&exp
, (unsigned int) nbytes
);
4296 while (*input_line_pointer
++ == ',');
4298 input_line_pointer
--; /* Put terminator back into stream. */
4300 mmix_handle_rest_of_empty_line ();
4302 /* We don't need to step up the counter for the current_fb_label here;
4303 that's handled by the caller. */
4306 /* The md_do_align worker. At present, we just record an alignment to
4307 nullify the automatic alignment we do for WYDE, TETRA and OCTA, as gcc
4308 does not use the unaligned macros when attribute packed is used.
4309 Arguably this is a GCC bug. */
4312 mmix_md_do_align (n
, fill
, len
, max
)
4314 char *fill ATTRIBUTE_UNUSED
;
4315 int len ATTRIBUTE_UNUSED
;
4316 int max ATTRIBUTE_UNUSED
;
4319 want_unaligned
= n
== 0;