1 /* tc-mmix.c -- Assembler for Don Knuth's MMIX.
2 Copyright (C) 2001, 2002, 2003, 2004, 2005 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 values. */
305 #define PUSHJSTUB_MAX ((offsetT) (((addressT) -1) >> 1))
306 #define PUSHJSTUB_MIN (-PUSHJSTUB_MAX - 1)
308 #define JMP_0F (65536 * 256 * 4 - 8)
309 #define JMP_0B (-65536 * 256 * 4 - 4)
311 #define JMP_MAX_LEN 5 * 4
315 #define RELAX_ENCODE_SHIFT 1
316 #define ENCODE_RELAX(what, length) (((what) << RELAX_ENCODE_SHIFT) + (length))
318 const relax_typeS mmix_relax_table
[] =
320 /* Error sentinel (0, 0). */
327 {GETA_0F
, GETA_0B
, 0, ENCODE_RELAX (STATE_GETA
, STATE_MAX
)},
331 GETA_MAX_LEN
- 4, 0},
334 {BCC_0F
, BCC_0B
, 0, ENCODE_RELAX (STATE_BCC
, STATE_MAX
)},
340 /* PUSHJ (3, 0). Next state is actually PUSHJSTUB (6, 0). */
341 {PUSHJ_0F
, PUSHJ_0B
, 0, ENCODE_RELAX (STATE_PUSHJSTUB
, STATE_ZERO
)},
345 PUSHJ_MAX_LEN
- 4, 0},
348 {JMP_0F
, JMP_0B
, 0, ENCODE_RELAX (STATE_JMP
, STATE_MAX
)},
354 /* GREG (5, 0), (5, 1), though the table entry isn't used. */
355 {0, 0, 0, 0}, {0, 0, 0, 0},
357 /* PUSHJSTUB (6, 0). PUSHJ (3, 0) uses the range, so we set it to infinite. */
358 {PUSHJSTUB_MAX
, PUSHJSTUB_MIN
,
359 0, ENCODE_RELAX (STATE_PUSHJ
, STATE_MAX
)},
360 /* PUSHJSTUB (6, 1) isn't used. */
361 {0, 0, PUSHJ_MAX_LEN
, 0}
364 const pseudo_typeS md_pseudo_table
[] =
366 /* Support " .greg sym,expr" syntax. */
369 /* Support " .bspec expr" syntax. */
370 {"bspec", s_bspec
, 1},
372 /* Support " .espec" syntax. */
373 {"espec", s_espec
, 1},
375 /* Support " .local $45" syntax. */
376 {"local", mmix_s_local
, 1},
381 const char mmix_comment_chars
[] = "%!";
383 /* A ':' is a valid symbol character in mmixal. It's the prefix
384 delimiter, but other than that, it works like a symbol character,
385 except that we strip one off at the beginning of symbols. An '@' is a
386 symbol by itself (for the current location); space around it must not
388 const char mmix_symbol_chars
[] = ":@";
390 const char line_comment_chars
[] = "*#";
392 const char line_separator_chars
[] = ";";
394 const char mmix_exp_chars
[] = "eE";
396 const char mmix_flt_chars
[] = "rf";
399 /* Fill in the offset-related part of GETA or Bcc. */
402 mmix_set_geta_branch_offset (opcodep
, value
)
413 md_number_to_chars (opcodep
+ 2, value
, 2);
416 /* Fill in the offset-related part of JMP. */
419 mmix_set_jmp_offset (opcodep
, value
)
425 value
+= 65536 * 256 * 4;
430 md_number_to_chars (opcodep
+ 1, value
, 3);
433 /* Fill in NOP:s for the expanded part of GETA/JMP/Bcc/PUSHJ. */
436 mmix_fill_nops (opcodep
, n
)
442 for (i
= 0; i
< n
; i
++)
443 md_number_to_chars (opcodep
+ i
* 4, SWYM_INSN_BYTE
<< 24, 4);
446 /* See macro md_parse_name in tc-mmix.h. */
449 mmix_current_location (fn
, exp
)
450 void (*fn
) PARAMS ((expressionS
*));
458 /* Get up to three operands, filling them into the exp array.
459 General idea and code stolen from the tic80 port. */
462 get_operands (max_operands
, s
, exp
)
471 while (nextchar
== ',')
473 /* Skip leading whitespace */
474 while (*p
== ' ' || *p
== '\t')
477 /* Check to see if we have any operands left to parse */
478 if (*p
== 0 || *p
== '\n' || *p
== '\r')
482 else if (numexp
== max_operands
)
484 /* This seems more sane than saying "too many operands". We'll
485 get here only if the trailing trash starts with a comma. */
486 as_bad (_("invalid operands"));
487 mmix_discard_rest_of_line ();
491 /* Begin operand parsing at the current scan point. */
493 input_line_pointer
= p
;
494 expression (&exp
[numexp
]);
496 if (exp
[numexp
].X_op
== O_illegal
)
498 as_bad (_("invalid operands"));
500 else if (exp
[numexp
].X_op
== O_absent
)
502 as_bad (_("missing operand"));
506 p
= input_line_pointer
;
508 /* Skip leading whitespace */
509 while (*p
== ' ' || *p
== '\t')
514 /* If we allow "naked" comments, ignore the rest of the line. */
517 mmix_handle_rest_of_empty_line ();
518 input_line_pointer
--;
521 /* Mark the end of the valid operands with an illegal expression. */
522 exp
[numexp
].X_op
= O_illegal
;
527 /* Get the value of a special register, or -1 if the name does not match
528 one. NAME is a null-terminated string. */
531 get_spec_regno (name
)
542 /* Well, it's a short array and we'll most often just match the first
544 for (i
= 0; mmix_spec_regs
[i
].name
!= NULL
; i
++)
545 if (strcmp (name
, mmix_spec_regs
[i
].name
) == 0)
546 return mmix_spec_regs
[i
].number
;
551 /* For GET and PUT, parse the register names "manually", so we don't use
554 get_putget_operands (insn
, operands
, exp
)
555 struct mmix_opcode
*insn
;
559 expressionS
*expp_reg
;
560 expressionS
*expp_sreg
;
562 char *sregend
= operands
;
567 /* Skip leading whitespace */
568 while (*p
== ' ' || *p
== '\t')
571 input_line_pointer
= p
;
573 /* Initialize both possible operands to error state, in case we never
575 exp
[0].X_op
= O_illegal
;
576 exp
[1].X_op
= O_illegal
;
578 if (insn
->operands
== mmix_operands_get
)
583 expression (expp_reg
);
585 p
= input_line_pointer
;
587 /* Skip whitespace */
588 while (*p
== ' ' || *p
== '\t')
595 /* Skip whitespace */
596 while (*p
== ' ' || *p
== '\t')
599 input_line_pointer
= sregp
;
600 c
= get_symbol_end ();
601 sregend
= input_line_pointer
;
610 c
= get_symbol_end ();
611 sregend
= p
= input_line_pointer
;
614 /* Skip whitespace */
615 while (*p
== ' ' || *p
== '\t')
622 /* Skip whitespace */
623 while (*p
== ' ' || *p
== '\t')
626 input_line_pointer
= p
;
627 expression (expp_reg
);
632 regno
= get_spec_regno (sregp
);
635 /* Let the caller issue errors; we've made sure the operands are
637 if (expp_reg
->X_op
!= O_illegal
638 && expp_reg
->X_op
!= O_absent
641 expp_sreg
->X_op
= O_register
;
642 expp_sreg
->X_add_number
= regno
+ 256;
648 /* Handle MMIX-specific option. */
651 md_parse_option (c
, arg
)
653 char *arg ATTRIBUTE_UNUSED
;
658 warn_on_expansion
= 0;
659 allocate_undefined_gregs_in_linker
= 1;
666 case OPTION_NOEXPAND
:
670 case OPTION_NOMERGEGREG
:
676 equated_spec_regs
= 0;
679 case OPTION_GNU_SYNTAX
:
681 label_without_colon_this_line
= 0;
684 case OPTION_GLOBALIZE_SYMBOLS
:
685 mmix_globalize_symbols
= 1;
688 case OPTION_FIXED_SPEC_REGS
:
689 equated_spec_regs
= 0;
692 case OPTION_LINKER_ALLOCATED_GREGS
:
693 allocate_undefined_gregs_in_linker
= 1;
696 case OPTION_NOPUSHJSTUBS
:
707 /* Display MMIX-specific help text. */
710 md_show_usage (stream
)
713 fprintf (stream
, _(" MMIX-specific command line options:\n"));
714 fprintf (stream
, _("\
715 -fixed-special-register-names\n\
716 Allow only the original special register names.\n"));
717 fprintf (stream
, _("\
718 -globalize-symbols Make all symbols global.\n"));
719 fprintf (stream
, _("\
720 -gnu-syntax Turn off mmixal syntax compatibility.\n"));
721 fprintf (stream
, _("\
722 -relax Create linker relaxable code.\n"));
723 fprintf (stream
, _("\
724 -no-predefined-syms Do not provide mmixal built-in constants.\n\
725 Implies -fixed-special-register-names.\n"));
726 fprintf (stream
, _("\
727 -no-expand Do not expand GETA, branches, PUSHJ or JUMP\n\
728 into multiple instructions.\n"));
729 fprintf (stream
, _("\
730 -no-merge-gregs Do not merge GREG definitions with nearby values.\n"));
731 fprintf (stream
, _("\
732 -linker-allocated-gregs If there's no suitable GREG definition for the\
733 operands of an instruction, let the linker resolve.\n"));
734 fprintf (stream
, _("\
735 -x Do not warn when an operand to GETA, a branch,\n\
736 PUSHJ or JUMP is not known to be within range.\n\
737 The linker will catch any errors. Implies\n\
738 -linker-allocated-gregs."));
741 /* Step to end of line, but don't step over the end of the line. */
744 mmix_discard_rest_of_line ()
746 while (*input_line_pointer
747 && (! is_end_of_line
[(unsigned char) *input_line_pointer
]
748 || TC_EOL_IN_INSN (input_line_pointer
)))
749 input_line_pointer
++;
752 /* Act as demand_empty_rest_of_line if we're in strict GNU syntax mode,
753 otherwise just ignore the rest of the line (and skip the end-of-line
757 mmix_handle_rest_of_empty_line ()
760 demand_empty_rest_of_line ();
763 mmix_discard_rest_of_line ();
764 input_line_pointer
++;
768 /* Initialize GAS MMIX specifics. */
774 const struct mmix_opcode
*opcode
;
776 /* We assume nobody will use this, so don't allocate any room. */
777 obstack_begin (&mmix_sym_obstack
, 0);
779 /* This will break the day the "lex" thingy changes. For now, it's the
780 only way to make ':' part of a name, and a name beginner. */
781 lex_type
[':'] = (LEX_NAME
| LEX_BEGIN_NAME
);
783 mmix_opcode_hash
= hash_new ();
786 = bfd_make_section_old_way (stdoutput
, MMIX_REG_SECTION_NAME
);
788 for (opcode
= mmix_opcodes
; opcode
->name
; opcode
++)
789 hash_insert (mmix_opcode_hash
, opcode
->name
, (char *) opcode
);
791 /* We always insert the ordinary registers 0..255 as registers. */
792 for (i
= 0; i
< 256; i
++)
796 /* Alternatively, we could diddle with '$' and the following number,
797 but keeping the registers as symbols helps keep parsing simple. */
798 sprintf (buf
, "$%d", i
);
799 symbol_table_insert (symbol_new (buf
, reg_section
, i
,
800 &zero_address_frag
));
803 /* Insert mmixal built-in names if allowed. */
806 for (i
= 0; mmix_spec_regs
[i
].name
!= NULL
; i
++)
807 symbol_table_insert (symbol_new (mmix_spec_regs
[i
].name
,
809 mmix_spec_regs
[i
].number
+ 256,
810 &zero_address_frag
));
812 /* FIXME: Perhaps these should be recognized as specials; as field
813 names for those instructions. */
814 symbol_table_insert (symbol_new ("ROUND_CURRENT", reg_section
, 512,
815 &zero_address_frag
));
816 symbol_table_insert (symbol_new ("ROUND_OFF", reg_section
, 512 + 1,
817 &zero_address_frag
));
818 symbol_table_insert (symbol_new ("ROUND_UP", reg_section
, 512 + 2,
819 &zero_address_frag
));
820 symbol_table_insert (symbol_new ("ROUND_DOWN", reg_section
, 512 + 3,
821 &zero_address_frag
));
822 symbol_table_insert (symbol_new ("ROUND_NEAR", reg_section
, 512 + 4,
823 &zero_address_frag
));
827 /* Assemble one insn in STR. */
833 char *operands
= str
;
834 char modified_char
= 0;
835 struct mmix_opcode
*instruction
;
836 fragS
*opc_fragP
= NULL
;
837 int max_operands
= 3;
839 /* Note that the struct frag member fr_literal in frags.h is char[], so
840 I have to make this a plain char *. */
841 /* unsigned */ char *opcodep
= NULL
;
846 /* Move to end of opcode. */
848 is_part_of_name (*operands
);
852 if (ISSPACE (*operands
))
854 modified_char
= *operands
;
858 instruction
= (struct mmix_opcode
*) hash_find (mmix_opcode_hash
, str
);
859 if (instruction
== NULL
)
861 as_bad (_("unknown opcode: `%s'"), str
);
863 /* Avoid "unhandled label" errors. */
864 pending_label
= NULL
;
868 /* Put back the character after the opcode. */
869 if (modified_char
!= 0)
870 operands
[-1] = modified_char
;
872 input_line_pointer
= operands
;
874 /* Is this a mmixal pseudodirective? */
875 if (instruction
->type
== mmix_type_pseudo
)
877 /* For mmixal compatibility, a label for an instruction (and
878 emitting pseudo) refers to the _aligned_ address. We emit the
879 label here for the pseudos that don't handle it themselves. When
880 having an fb-label, emit it here, and increment the counter after
882 switch (instruction
->operands
)
884 case mmix_operands_loc
:
885 case mmix_operands_byte
:
886 case mmix_operands_prefix
:
887 case mmix_operands_local
:
888 case mmix_operands_bspec
:
889 case mmix_operands_espec
:
890 if (current_fb_label
>= 0)
891 colon (fb_label_name (current_fb_label
, 1));
892 else if (pending_label
!= NULL
)
894 colon (pending_label
);
895 pending_label
= NULL
;
903 /* Some of the pseudos emit contents, others don't. Set a
904 contents-emitted flag when we emit something into .text */
905 switch (instruction
->operands
)
907 case mmix_operands_loc
:
912 case mmix_operands_byte
:
917 case mmix_operands_wyde
:
922 case mmix_operands_tetra
:
927 case mmix_operands_octa
:
932 case mmix_operands_prefix
:
937 case mmix_operands_local
:
942 case mmix_operands_bspec
:
947 case mmix_operands_espec
:
953 BAD_CASE (instruction
->operands
);
956 /* These are all working like the pseudo functions in read.c:s_...,
957 in that they step over the end-of-line marker at the end of the
958 line. We don't want that here. */
959 input_line_pointer
--;
961 /* Step up the fb-label counter if there was a definition on this
963 if (current_fb_label
>= 0)
965 fb_label_instance_inc (current_fb_label
);
966 current_fb_label
= -1;
969 /* Reset any don't-align-next-datum request, unless this was a LOC
971 if (instruction
->operands
!= mmix_operands_loc
)
977 /* Not a pseudo; we *will* emit contents. */
978 if (now_seg
== data_section
)
980 if (lowest_data_loc
!= (bfd_vma
) -1 && (lowest_data_loc
& 3) != 0)
982 if (data_has_contents
)
983 as_bad (_("specified location wasn't TETRA-aligned"));
984 else if (want_unaligned
)
985 as_bad (_("unaligned data at an absolute location is not supported"));
987 lowest_data_loc
&= ~(bfd_vma
) 3;
988 lowest_data_loc
+= 4;
991 data_has_contents
= 1;
993 else if (now_seg
== text_section
)
995 if (lowest_text_loc
!= (bfd_vma
) -1 && (lowest_text_loc
& 3) != 0)
997 if (text_has_contents
)
998 as_bad (_("specified location wasn't TETRA-aligned"));
999 else if (want_unaligned
)
1000 as_bad (_("unaligned data at an absolute location is not supported"));
1002 lowest_text_loc
&= ~(bfd_vma
) 3;
1003 lowest_text_loc
+= 4;
1006 text_has_contents
= 1;
1009 /* After a sequence of BYTEs or WYDEs, we need to get to instruction
1010 alignment. For other pseudos, a ".p2align 2" is supposed to be
1011 inserted by the user. */
1012 if (last_alignment
< 2 && ! want_unaligned
)
1014 frag_align (2, 0, 0);
1015 record_alignment (now_seg
, 2);
1019 /* Reset any don't-align-next-datum request. */
1022 /* For mmixal compatibility, a label for an instruction (and emitting
1023 pseudo) refers to the _aligned_ address. So we have to emit the
1025 if (pending_label
!= NULL
)
1027 colon (pending_label
);
1028 pending_label
= NULL
;
1031 /* We assume that mmix_opcodes keeps having unique mnemonics for each
1032 opcode, so we don't have to iterate over more than one opcode; if the
1033 syntax does not match, then there's a syntax error. */
1035 /* Operands have little or no context and are all comma-separated; it is
1036 easier to parse each expression first. */
1037 switch (instruction
->operands
)
1039 case mmix_operands_reg_yz
:
1040 case mmix_operands_pop
:
1041 case mmix_operands_regaddr
:
1042 case mmix_operands_pushj
:
1043 case mmix_operands_get
:
1044 case mmix_operands_put
:
1045 case mmix_operands_set
:
1046 case mmix_operands_save
:
1047 case mmix_operands_unsave
:
1051 case mmix_operands_sync
:
1052 case mmix_operands_jmp
:
1053 case mmix_operands_resume
:
1057 /* The original 3 is fine for the rest. */
1062 /* If this is GET or PUT, and we don't do allow those names to be
1063 equated, we need to parse the names ourselves, so we don't pick up a
1064 user label instead of the special register. */
1065 if (! equated_spec_regs
1066 && (instruction
->operands
== mmix_operands_get
1067 || instruction
->operands
== mmix_operands_put
))
1068 n_operands
= get_putget_operands (instruction
, operands
, exp
);
1070 n_operands
= get_operands (max_operands
, operands
, exp
);
1072 /* If there's a fb-label on the current line, set that label. This must
1073 be done *after* evaluating expressions of operands, since neither a
1074 "1B" nor a "1F" refers to "1H" on the same line. */
1075 if (current_fb_label
>= 0)
1077 fb_label_instance_inc (current_fb_label
);
1078 colon (fb_label_name (current_fb_label
, 0));
1079 current_fb_label
= -1;
1082 /* We also assume that the length of the instruction is at least 4, the
1083 size of an unexpanded instruction. We need a self-contained frag
1084 since we want the relocation to point to the instruction, not the
1087 opcodep
= frag_more (4);
1088 mmix_opcode_frag
= opc_fragP
= frag_now
;
1089 frag_now
->fr_opcode
= opcodep
;
1091 /* Mark start of insn for DWARF2 debug features. */
1092 if (OUTPUT_FLAVOR
== bfd_target_elf_flavour
)
1093 dwarf2_emit_insn (4);
1095 md_number_to_chars (opcodep
, instruction
->match
, 4);
1097 switch (instruction
->operands
)
1099 case mmix_operands_jmp
:
1100 if (n_operands
== 0 && ! mmix_gnu_syntax
)
1101 /* Zeros are in place - nothing needs to be done when we have no
1105 /* Add a frag for a JMP relaxation; we need room for max four
1106 extra instructions. We don't do any work around here to check if
1107 we can determine the offset right away. */
1108 if (n_operands
!= 1 || exp
[0].X_op
== O_register
)
1110 as_bad (_("invalid operand to opcode %s: `%s'"),
1111 instruction
->name
, operands
);
1116 frag_var (rs_machine_dependent
, 4 * 4, 0,
1117 ENCODE_RELAX (STATE_JMP
, STATE_UNDF
),
1118 exp
[0].X_add_symbol
,
1119 exp
[0].X_add_number
,
1122 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
, 4,
1123 exp
+ 0, 1, BFD_RELOC_MMIX_ADDR27
);
1126 case mmix_operands_pushj
:
1127 /* We take care of PUSHJ in full here. */
1129 || ((exp
[0].X_op
== O_constant
|| exp
[0].X_op
== O_register
)
1130 && (exp
[0].X_add_number
> 255 || exp
[0].X_add_number
< 0)))
1132 as_bad (_("invalid operands to opcode %s: `%s'"),
1133 instruction
->name
, operands
);
1137 if (exp
[0].X_op
== O_register
|| exp
[0].X_op
== O_constant
)
1138 opcodep
[1] = exp
[0].X_add_number
;
1140 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 1,
1141 1, exp
+ 0, 0, BFD_RELOC_MMIX_REG_OR_BYTE
);
1144 frag_var (rs_machine_dependent
, PUSHJ_MAX_LEN
- 4, 0,
1145 ENCODE_RELAX (STATE_PUSHJ
, STATE_UNDF
),
1146 exp
[1].X_add_symbol
,
1147 exp
[1].X_add_number
,
1150 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
, 4,
1151 exp
+ 1, 1, BFD_RELOC_MMIX_ADDR19
);
1154 case mmix_operands_regaddr
:
1155 /* GETA/branch: Add a frag for relaxation. We don't do any work
1156 around here to check if we can determine the offset right away. */
1157 if (n_operands
!= 2 || exp
[1].X_op
== O_register
)
1159 as_bad (_("invalid operands to opcode %s: `%s'"),
1160 instruction
->name
, operands
);
1165 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
, 4,
1166 exp
+ 1, 1, BFD_RELOC_MMIX_ADDR19
);
1167 else if (instruction
->type
== mmix_type_condbranch
)
1168 frag_var (rs_machine_dependent
, BCC_MAX_LEN
- 4, 0,
1169 ENCODE_RELAX (STATE_BCC
, STATE_UNDF
),
1170 exp
[1].X_add_symbol
,
1171 exp
[1].X_add_number
,
1174 frag_var (rs_machine_dependent
, GETA_MAX_LEN
- 4, 0,
1175 ENCODE_RELAX (STATE_GETA
, STATE_UNDF
),
1176 exp
[1].X_add_symbol
,
1177 exp
[1].X_add_number
,
1185 switch (instruction
->operands
)
1187 case mmix_operands_regs
:
1188 /* We check the number of operands here, since we're in a
1189 FALLTHROUGH sequence in the next switch. */
1190 if (n_operands
!= 3 || exp
[2].X_op
== O_constant
)
1192 as_bad (_("invalid operands to opcode %s: `%s'"),
1193 instruction
->name
, operands
);
1197 case mmix_operands_regs_z
:
1198 if (n_operands
!= 3)
1200 as_bad (_("invalid operands to opcode %s: `%s'"),
1201 instruction
->name
, operands
);
1205 case mmix_operands_reg_yz
:
1206 case mmix_operands_roundregs_z
:
1207 case mmix_operands_roundregs
:
1208 case mmix_operands_regs_z_opt
:
1209 case mmix_operands_neg
:
1210 case mmix_operands_regaddr
:
1211 case mmix_operands_get
:
1212 case mmix_operands_set
:
1213 case mmix_operands_save
:
1215 || (exp
[0].X_op
== O_register
&& exp
[0].X_add_number
> 255))
1217 as_bad (_("invalid operands to opcode %s: `%s'"),
1218 instruction
->name
, operands
);
1222 if (exp
[0].X_op
== O_register
)
1223 opcodep
[1] = exp
[0].X_add_number
;
1225 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 1,
1226 1, exp
+ 0, 0, BFD_RELOC_MMIX_REG
);
1233 /* A corresponding once-over for those who take an 8-bit constant as
1234 their first operand. */
1235 switch (instruction
->operands
)
1237 case mmix_operands_pushgo
:
1238 /* PUSHGO: X is a constant, but can be expressed as a register.
1239 We handle X here and use the common machinery of T,X,3,$ for
1240 the rest of the operands. */
1242 || ((exp
[0].X_op
== O_constant
|| exp
[0].X_op
== O_register
)
1243 && (exp
[0].X_add_number
> 255 || exp
[0].X_add_number
< 0)))
1245 as_bad (_("invalid operands to opcode %s: `%s'"),
1246 instruction
->name
, operands
);
1249 else if (exp
[0].X_op
== O_constant
|| exp
[0].X_op
== O_register
)
1250 opcodep
[1] = exp
[0].X_add_number
;
1252 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 1,
1253 1, exp
+ 0, 0, BFD_RELOC_MMIX_REG_OR_BYTE
);
1256 case mmix_operands_pop
:
1257 if ((n_operands
== 0 || n_operands
== 1) && ! mmix_gnu_syntax
)
1260 case mmix_operands_x_regs_z
:
1262 || (exp
[0].X_op
== O_constant
1263 && (exp
[0].X_add_number
> 255
1264 || exp
[0].X_add_number
< 0)))
1266 as_bad (_("invalid operands to opcode %s: `%s'"),
1267 instruction
->name
, operands
);
1271 if (exp
[0].X_op
== O_constant
)
1272 opcodep
[1] = exp
[0].X_add_number
;
1274 /* FIXME: This doesn't bring us unsignedness checking. */
1275 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 1,
1276 1, exp
+ 0, 0, BFD_RELOC_8
);
1281 /* Handle the rest. */
1282 switch (instruction
->operands
)
1284 case mmix_operands_set
:
1285 /* SET: Either two registers, "$X,$Y", with Z field as zero, or
1286 "$X,YZ", meaning change the opcode to SETL. */
1288 || (exp
[1].X_op
== O_constant
1289 && (exp
[1].X_add_number
> 0xffff || exp
[1].X_add_number
< 0)))
1291 as_bad (_("invalid operands to opcode %s: `%s'"),
1292 instruction
->name
, operands
);
1296 if (exp
[1].X_op
== O_constant
)
1298 /* There's an ambiguity with "SET $0,Y" when Y isn't defined
1299 yet. To keep things simple, we assume that Y is then a
1300 register, and only change the opcode if Y is defined at this
1303 There's no compatibility problem with mmixal, since it emits
1304 errors if the field is not defined at this point. */
1305 md_number_to_chars (opcodep
, SETL_INSN_BYTE
, 1);
1307 opcodep
[2] = (exp
[1].X_add_number
>> 8) & 255;
1308 opcodep
[3] = exp
[1].X_add_number
& 255;
1312 case mmix_operands_x_regs_z
:
1313 /* SYNCD: "X,$Y,$Z|Z". */
1315 case mmix_operands_regs
:
1316 /* Three registers, $X,$Y,$Z. */
1318 case mmix_operands_regs_z
:
1319 /* Operands "$X,$Y,$Z|Z", number of arguments checked above. */
1321 case mmix_operands_pushgo
:
1322 /* Operands "$X|X,$Y,$Z|Z", optional Z. */
1324 case mmix_operands_regs_z_opt
:
1325 /* Operands "$X,$Y,$Z|Z", with $Z|Z being optional, default 0. Any
1326 operands not completely decided yet are postponed to later in
1327 assembly (but not until link-time yet). */
1329 if ((n_operands
!= 2 && n_operands
!= 3)
1330 || (exp
[1].X_op
== O_register
&& exp
[1].X_add_number
> 255)
1332 && ((exp
[2].X_op
== O_register
1333 && exp
[2].X_add_number
> 255
1335 || (exp
[2].X_op
== O_constant
1336 && (exp
[2].X_add_number
> 255
1337 || exp
[2].X_add_number
< 0)))))
1339 as_bad (_("invalid operands to opcode %s: `%s'"),
1340 instruction
->name
, operands
);
1344 if (n_operands
== 2)
1348 /* The last operand is immediate whenever we see just two
1350 opcodep
[0] |= IMM_OFFSET_BIT
;
1352 /* Now, we could either have an implied "0" as the Z operand, or
1353 it could be the constant of a "base address plus offset". It
1354 depends on whether it is allowed; only memory operations, as
1355 signified by instruction->type and "T" and "X" operand types,
1356 and it depends on whether we find a register in the second
1358 if (exp
[1].X_op
== O_register
&& exp
[1].X_add_number
<= 255)
1360 /* A zero then; all done. */
1361 opcodep
[2] = exp
[1].X_add_number
;
1365 /* Not known as a register. Is base address plus offset
1366 allowed, or can we assume that it is a register anyway? */
1367 if ((instruction
->operands
!= mmix_operands_regs_z_opt
1368 && instruction
->operands
!= mmix_operands_x_regs_z
1369 && instruction
->operands
!= mmix_operands_pushgo
)
1370 || (instruction
->type
!= mmix_type_memaccess_octa
1371 && instruction
->type
!= mmix_type_memaccess_tetra
1372 && instruction
->type
!= mmix_type_memaccess_wyde
1373 && instruction
->type
!= mmix_type_memaccess_byte
1374 && instruction
->type
!= mmix_type_memaccess_block
1375 && instruction
->type
!= mmix_type_jsr
1376 && instruction
->type
!= mmix_type_branch
))
1378 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 2,
1379 1, exp
+ 1, 0, BFD_RELOC_MMIX_REG
);
1383 /* To avoid getting a NULL add_symbol for constants and then
1384 catching a SEGV in write_relocs since it doesn't handle
1385 constants well for relocs other than PC-relative, we need to
1386 pass expressions as symbols and use fix_new, not fix_new_exp. */
1387 sym
= make_expr_symbol (exp
+ 1);
1389 /* Now we know it can be a "base address plus offset". Add
1390 proper fixup types so we can handle this later, when we've
1391 parsed everything. */
1392 fix_new (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 2,
1393 8, sym
, 0, 0, BFD_RELOC_MMIX_BASE_PLUS_OFFSET
);
1397 if (exp
[1].X_op
== O_register
)
1398 opcodep
[2] = exp
[1].X_add_number
;
1400 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 2,
1401 1, exp
+ 1, 0, BFD_RELOC_MMIX_REG
);
1403 /* In mmixal compatibility mode, we allow special registers as
1404 constants for the Z operand. They have 256 added to their
1405 register numbers, so the right thing will happen if we just treat
1406 those as constants. */
1407 if (exp
[2].X_op
== O_register
&& exp
[2].X_add_number
<= 255)
1408 opcodep
[3] = exp
[2].X_add_number
;
1409 else if (exp
[2].X_op
== O_constant
1410 || (exp
[2].X_op
== O_register
&& exp
[2].X_add_number
> 255))
1412 opcodep
[3] = exp
[2].X_add_number
;
1413 opcodep
[0] |= IMM_OFFSET_BIT
;
1416 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 3,
1418 (instruction
->operands
== mmix_operands_set
1419 || instruction
->operands
== mmix_operands_regs
)
1420 ? BFD_RELOC_MMIX_REG
: BFD_RELOC_MMIX_REG_OR_BYTE
);
1423 case mmix_operands_pop
:
1424 /* POP, one eight and one 16-bit operand. */
1425 if (n_operands
== 0 && ! mmix_gnu_syntax
)
1427 if (n_operands
== 1 && ! mmix_gnu_syntax
)
1428 goto a_single_24_bit_number_operand
;
1430 case mmix_operands_reg_yz
:
1431 /* A register and a 16-bit unsigned number. */
1433 || exp
[1].X_op
== O_register
1434 || (exp
[1].X_op
== O_constant
1435 && (exp
[1].X_add_number
> 0xffff || exp
[1].X_add_number
< 0)))
1437 as_bad (_("invalid operands to opcode %s: `%s'"),
1438 instruction
->name
, operands
);
1442 if (exp
[1].X_op
== O_constant
)
1444 opcodep
[2] = (exp
[1].X_add_number
>> 8) & 255;
1445 opcodep
[3] = exp
[1].X_add_number
& 255;
1448 /* FIXME: This doesn't bring us unsignedness checking. */
1449 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 2,
1450 2, exp
+ 1, 0, BFD_RELOC_16
);
1453 case mmix_operands_jmp
:
1454 /* A JMP. Everything is already done. */
1457 case mmix_operands_roundregs
:
1458 /* Two registers with optional rounding mode or constant in between. */
1459 if ((n_operands
== 3 && exp
[2].X_op
== O_constant
)
1460 || (n_operands
== 2 && exp
[1].X_op
== O_constant
))
1462 as_bad (_("invalid operands to opcode %s: `%s'"),
1463 instruction
->name
, operands
);
1467 case mmix_operands_roundregs_z
:
1468 /* Like FLOT, "$X,ROUND_MODE,$Z|Z", but the rounding mode is
1469 optional and can be the corresponding constant. */
1471 /* Which exp index holds the second operand (not the rounding
1473 int op2no
= n_operands
- 1;
1475 if ((n_operands
!= 2 && n_operands
!= 3)
1476 || ((exp
[op2no
].X_op
== O_register
1477 && exp
[op2no
].X_add_number
> 255)
1478 || (exp
[op2no
].X_op
== O_constant
1479 && (exp
[op2no
].X_add_number
> 255
1480 || exp
[op2no
].X_add_number
< 0)))
1482 /* We don't allow for the rounding mode to be deferred; it
1483 must be determined in the "first pass". It cannot be a
1484 symbol equated to a rounding mode, but defined after
1486 && ((exp
[1].X_op
== O_register
1487 && exp
[1].X_add_number
< 512)
1488 || (exp
[1].X_op
== O_constant
1489 && exp
[1].X_add_number
< 0
1490 && exp
[1].X_add_number
> 4)
1491 || (exp
[1].X_op
!= O_register
1492 && exp
[1].X_op
!= O_constant
))))
1494 as_bad (_("invalid operands to opcode %s: `%s'"),
1495 instruction
->name
, operands
);
1499 /* Add rounding mode if present. */
1500 if (n_operands
== 3)
1501 opcodep
[2] = exp
[1].X_add_number
& 255;
1503 if (exp
[op2no
].X_op
== O_register
)
1504 opcodep
[3] = exp
[op2no
].X_add_number
;
1505 else if (exp
[op2no
].X_op
== O_constant
)
1507 opcodep
[3] = exp
[op2no
].X_add_number
;
1508 opcodep
[0] |= IMM_OFFSET_BIT
;
1511 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 3,
1513 instruction
->operands
== mmix_operands_roundregs
1514 ? BFD_RELOC_MMIX_REG
1515 : BFD_RELOC_MMIX_REG_OR_BYTE
);
1519 case mmix_operands_sync
:
1520 a_single_24_bit_number_operand
:
1522 || exp
[0].X_op
== O_register
1523 || (exp
[0].X_op
== O_constant
1524 && (exp
[0].X_add_number
> 0xffffff || exp
[0].X_add_number
< 0)))
1526 as_bad (_("invalid operands to opcode %s: `%s'"),
1527 instruction
->name
, operands
);
1531 if (exp
[0].X_op
== O_constant
)
1533 opcodep
[1] = (exp
[0].X_add_number
>> 16) & 255;
1534 opcodep
[2] = (exp
[0].X_add_number
>> 8) & 255;
1535 opcodep
[3] = exp
[0].X_add_number
& 255;
1538 /* FIXME: This doesn't bring us unsignedness checking. */
1539 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 1,
1540 3, exp
+ 0, 0, BFD_RELOC_24
);
1543 case mmix_operands_neg
:
1544 /* Operands "$X,Y,$Z|Z"; NEG or NEGU. Y is optional, 0 is default. */
1546 if ((n_operands
!= 3 && n_operands
!= 2)
1547 || (n_operands
== 3 && exp
[1].X_op
== O_register
)
1548 || ((exp
[1].X_op
== O_constant
|| exp
[1].X_op
== O_register
)
1549 && (exp
[1].X_add_number
> 255 || exp
[1].X_add_number
< 0))
1551 && ((exp
[2].X_op
== O_register
&& exp
[2].X_add_number
> 255)
1552 || (exp
[2].X_op
== O_constant
1553 && (exp
[2].X_add_number
> 255
1554 || exp
[2].X_add_number
< 0)))))
1556 as_bad (_("invalid operands to opcode %s: `%s'"),
1557 instruction
->name
, operands
);
1561 if (n_operands
== 2)
1563 if (exp
[1].X_op
== O_register
)
1564 opcodep
[3] = exp
[1].X_add_number
;
1565 else if (exp
[1].X_op
== O_constant
)
1567 opcodep
[3] = exp
[1].X_add_number
;
1568 opcodep
[0] |= IMM_OFFSET_BIT
;
1571 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 3,
1572 1, exp
+ 1, 0, BFD_RELOC_MMIX_REG_OR_BYTE
);
1576 if (exp
[1].X_op
== O_constant
)
1577 opcodep
[2] = exp
[1].X_add_number
;
1579 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 2,
1580 1, exp
+ 1, 0, BFD_RELOC_8
);
1582 if (exp
[2].X_op
== O_register
)
1583 opcodep
[3] = exp
[2].X_add_number
;
1584 else if (exp
[2].X_op
== O_constant
)
1586 opcodep
[3] = exp
[2].X_add_number
;
1587 opcodep
[0] |= IMM_OFFSET_BIT
;
1590 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 3,
1591 1, exp
+ 2, 0, BFD_RELOC_MMIX_REG_OR_BYTE
);
1594 case mmix_operands_regaddr
:
1595 /* A GETA/branch-type. */
1598 case mmix_operands_get
:
1599 /* "$X,spec_reg"; GET.
1600 Like with rounding modes, we demand that the special register or
1601 symbol is already defined when we get here at the point of use. */
1603 || (exp
[1].X_op
== O_register
1604 && (exp
[1].X_add_number
< 256 || exp
[1].X_add_number
>= 512))
1605 || (exp
[1].X_op
== O_constant
1606 && (exp
[1].X_add_number
< 0 || exp
[1].X_add_number
> 256))
1607 || (exp
[1].X_op
!= O_constant
&& exp
[1].X_op
!= O_register
))
1609 as_bad (_("invalid operands to opcode %s: `%s'"),
1610 instruction
->name
, operands
);
1614 opcodep
[3] = exp
[1].X_add_number
- 256;
1617 case mmix_operands_put
:
1618 /* "spec_reg,$Z|Z"; PUT. */
1620 || (exp
[0].X_op
== O_register
1621 && (exp
[0].X_add_number
< 256 || exp
[0].X_add_number
>= 512))
1622 || (exp
[0].X_op
== O_constant
1623 && (exp
[0].X_add_number
< 0 || exp
[0].X_add_number
> 256))
1624 || (exp
[0].X_op
!= O_constant
&& exp
[0].X_op
!= O_register
))
1626 as_bad (_("invalid operands to opcode %s: `%s'"),
1627 instruction
->name
, operands
);
1631 opcodep
[1] = exp
[0].X_add_number
- 256;
1633 /* Note that the Y field is zero. */
1635 if (exp
[1].X_op
== O_register
)
1636 opcodep
[3] = exp
[1].X_add_number
;
1637 else if (exp
[1].X_op
== O_constant
)
1639 opcodep
[3] = exp
[1].X_add_number
;
1640 opcodep
[0] |= IMM_OFFSET_BIT
;
1643 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 3,
1644 1, exp
+ 1, 0, BFD_RELOC_MMIX_REG_OR_BYTE
);
1647 case mmix_operands_save
:
1650 || exp
[1].X_op
!= O_constant
1651 || exp
[1].X_add_number
!= 0)
1653 as_bad (_("invalid operands to opcode %s: `%s'"),
1654 instruction
->name
, operands
);
1659 case mmix_operands_unsave
:
1660 if (n_operands
< 2 && ! mmix_gnu_syntax
)
1662 if (n_operands
== 1)
1664 if (exp
[0].X_op
== O_register
)
1665 opcodep
[3] = exp
[0].X_add_number
;
1667 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 3,
1668 1, exp
, 0, BFD_RELOC_MMIX_REG
);
1673 /* "0,$Z"; UNSAVE. */
1675 || exp
[0].X_op
!= O_constant
1676 || exp
[0].X_add_number
!= 0
1677 || exp
[1].X_op
== O_constant
1678 || (exp
[1].X_op
== O_register
1679 && exp
[1].X_add_number
> 255))
1681 as_bad (_("invalid operands to opcode %s: `%s'"),
1682 instruction
->name
, operands
);
1686 if (exp
[1].X_op
== O_register
)
1687 opcodep
[3] = exp
[1].X_add_number
;
1689 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 3,
1690 1, exp
+ 1, 0, BFD_RELOC_MMIX_REG
);
1693 case mmix_operands_xyz_opt
:
1694 /* SWYM, TRIP, TRAP: zero, one, two or three operands. */
1695 if (n_operands
== 0 && ! mmix_gnu_syntax
)
1696 /* Zeros are in place - nothing needs to be done for zero
1697 operands. We don't allow this in GNU syntax mode, because it
1698 was believed that the risk of missing to supply an operand is
1699 higher than the benefit of not having to specify a zero. */
1701 else if (n_operands
== 1 && exp
[0].X_op
!= O_register
)
1703 if (exp
[0].X_op
== O_constant
)
1705 if (exp
[0].X_add_number
> 255*255*255
1706 || exp
[0].X_add_number
< 0)
1708 as_bad (_("invalid operands to opcode %s: `%s'"),
1709 instruction
->name
, operands
);
1714 opcodep
[1] = (exp
[0].X_add_number
>> 16) & 255;
1715 opcodep
[2] = (exp
[0].X_add_number
>> 8) & 255;
1716 opcodep
[3] = exp
[0].X_add_number
& 255;
1720 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 1,
1721 3, exp
, 0, BFD_RELOC_24
);
1723 else if (n_operands
== 2
1724 && exp
[0].X_op
!= O_register
1725 && exp
[1].X_op
!= O_register
)
1729 if (exp
[0].X_op
== O_constant
)
1731 if (exp
[0].X_add_number
> 255
1732 || exp
[0].X_add_number
< 0)
1734 as_bad (_("invalid operands to opcode %s: `%s'"),
1735 instruction
->name
, operands
);
1739 opcodep
[1] = exp
[0].X_add_number
& 255;
1742 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 1,
1743 1, exp
, 0, BFD_RELOC_8
);
1745 if (exp
[1].X_op
== O_constant
)
1747 if (exp
[1].X_add_number
> 255*255
1748 || exp
[1].X_add_number
< 0)
1750 as_bad (_("invalid operands to opcode %s: `%s'"),
1751 instruction
->name
, operands
);
1756 opcodep
[2] = (exp
[1].X_add_number
>> 8) & 255;
1757 opcodep
[3] = exp
[1].X_add_number
& 255;
1761 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 2,
1762 2, exp
+ 1, 0, BFD_RELOC_16
);
1764 else if (n_operands
== 3
1765 && exp
[0].X_op
!= O_register
1766 && exp
[1].X_op
!= O_register
1767 && exp
[2].X_op
!= O_register
)
1769 /* Three operands. */
1771 if (exp
[0].X_op
== O_constant
)
1773 if (exp
[0].X_add_number
> 255
1774 || exp
[0].X_add_number
< 0)
1776 as_bad (_("invalid operands to opcode %s: `%s'"),
1777 instruction
->name
, operands
);
1781 opcodep
[1] = exp
[0].X_add_number
& 255;
1784 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 1,
1785 1, exp
, 0, BFD_RELOC_8
);
1787 if (exp
[1].X_op
== O_constant
)
1789 if (exp
[1].X_add_number
> 255
1790 || exp
[1].X_add_number
< 0)
1792 as_bad (_("invalid operands to opcode %s: `%s'"),
1793 instruction
->name
, operands
);
1797 opcodep
[2] = exp
[1].X_add_number
& 255;
1800 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 2,
1801 1, exp
+ 1, 0, BFD_RELOC_8
);
1803 if (exp
[2].X_op
== O_constant
)
1805 if (exp
[2].X_add_number
> 255
1806 || exp
[2].X_add_number
< 0)
1808 as_bad (_("invalid operands to opcode %s: `%s'"),
1809 instruction
->name
, operands
);
1813 opcodep
[3] = exp
[2].X_add_number
& 255;
1816 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 3,
1817 1, exp
+ 2, 0, BFD_RELOC_8
);
1819 else if (n_operands
<= 3
1820 && (strcmp (instruction
->name
, "trip") == 0
1821 || strcmp (instruction
->name
, "trap") == 0))
1823 /* The meaning of operands to TRIP and TRAP are not defined, so
1824 we add combinations not handled above here as we find them. */
1825 if (n_operands
== 3)
1827 /* Don't require non-register operands. Always generate
1828 fixups, so we don't have to copy lots of code and create
1829 maintenance problems. TRIP is supposed to be a rare
1830 instruction, so the overhead should not matter. We
1831 aren't allowed to fix_new_exp for an expression which is
1832 an O_register at this point, however. */
1833 if (exp
[0].X_op
== O_register
)
1834 opcodep
[1] = exp
[0].X_add_number
;
1836 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 1,
1837 1, exp
, 0, BFD_RELOC_MMIX_REG_OR_BYTE
);
1838 if (exp
[1].X_op
== O_register
)
1839 opcodep
[2] = exp
[1].X_add_number
;
1841 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 2,
1842 1, exp
+ 1, 0, BFD_RELOC_MMIX_REG_OR_BYTE
);
1843 if (exp
[2].X_op
== O_register
)
1844 opcodep
[3] = exp
[2].X_add_number
;
1846 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 3,
1847 1, exp
+ 2, 0, BFD_RELOC_MMIX_REG_OR_BYTE
);
1849 else if (n_operands
== 2)
1851 if (exp
[0].X_op
== O_register
)
1852 opcodep
[2] = exp
[0].X_add_number
;
1854 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 2,
1855 1, exp
, 0, BFD_RELOC_MMIX_REG_OR_BYTE
);
1856 if (exp
[1].X_op
== O_register
)
1857 opcodep
[3] = exp
[1].X_add_number
;
1859 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 3,
1860 1, exp
+ 1, 0, BFD_RELOC_MMIX_REG_OR_BYTE
);
1864 as_bad (_("unsupported operands to %s: `%s'"),
1865 instruction
->name
, operands
);
1871 as_bad (_("invalid operands to opcode %s: `%s'"),
1872 instruction
->name
, operands
);
1877 case mmix_operands_resume
:
1878 if (n_operands
== 0 && ! mmix_gnu_syntax
)
1882 || exp
[0].X_op
== O_register
1883 || (exp
[0].X_op
== O_constant
1884 && (exp
[0].X_add_number
< 0
1885 || exp
[0].X_add_number
> 255)))
1887 as_bad (_("invalid operands to opcode %s: `%s'"),
1888 instruction
->name
, operands
);
1892 if (exp
[0].X_op
== O_constant
)
1893 opcodep
[3] = exp
[0].X_add_number
;
1895 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 3,
1896 1, exp
+ 0, 0, BFD_RELOC_8
);
1899 case mmix_operands_pushj
:
1900 /* All is done for PUSHJ already. */
1904 BAD_CASE (instruction
->operands
);
1908 /* For the benefit of insns that start with a digit, we assemble by way of
1909 tc_unrecognized_line too, through this function. */
1912 mmix_assemble_return_nonzero (str
)
1915 int last_error_count
= had_errors ();
1919 /* Normal instruction handling downcases, so we must too. */
1920 while (ISALNUM (*s2
))
1922 if (ISUPPER ((unsigned char) *s2
))
1923 *s2
= TOLOWER (*s2
);
1927 /* Cut the line for sake of the assembly. */
1928 for (s2
= str
; *s2
&& *s2
!= '\n'; s2
++)
1936 return had_errors () == last_error_count
;
1939 /* The PREFIX pseudo. */
1943 int unused ATTRIBUTE_UNUSED
;
1950 p
= input_line_pointer
;
1952 c
= get_symbol_end ();
1954 /* Reseting prefix? */
1955 if (*p
== ':' && p
[1] == 0)
1956 mmix_current_prefix
= NULL
;
1959 /* Put this prefix on the mmix symbols obstack. We could malloc and
1960 free it separately, but then we'd have to worry about that.
1961 People using up memory on prefixes have other problems. */
1962 obstack_grow (&mmix_sym_obstack
, p
, strlen (p
) + 1);
1963 p
= obstack_finish (&mmix_sym_obstack
);
1965 /* Accumulate prefixes, and strip a leading ':'. */
1966 if (mmix_current_prefix
!= NULL
|| *p
== ':')
1967 p
= mmix_prefix_name (p
);
1969 mmix_current_prefix
= p
;
1972 *input_line_pointer
= c
;
1974 mmix_handle_rest_of_empty_line ();
1977 /* We implement prefixes by using the tc_canonicalize_symbol_name hook,
1978 and store each prefixed name on a (separate) obstack. This means that
1979 the name is on the "notes" obstack in non-prefixed form and on the
1980 mmix_sym_obstack in prefixed form, but currently it is not worth
1981 rewriting the whole GAS symbol handling to improve "hooking" to avoid
1982 that. (It might be worth a rewrite for other reasons, though). */
1985 mmix_prefix_name (shortname
)
1988 if (*shortname
== ':')
1989 return shortname
+ 1;
1991 if (mmix_current_prefix
== NULL
)
1992 as_fatal (_("internal: mmix_prefix_name but empty prefix"));
1994 if (*shortname
== '$')
1997 obstack_grow (&mmix_sym_obstack
, mmix_current_prefix
,
1998 strlen (mmix_current_prefix
));
1999 obstack_grow (&mmix_sym_obstack
, shortname
, strlen (shortname
) + 1);
2000 return obstack_finish (&mmix_sym_obstack
);
2003 /* The GREG pseudo. At LABEL, we have the name of a symbol that we
2004 want to make a register symbol, and which should be initialized with
2005 the value in the expression at INPUT_LINE_POINTER (defaulting to 0).
2006 Either and (perhaps less meaningful) both may be missing. LABEL must
2007 be persistent, perhaps allocated on an obstack. */
2010 mmix_greg_internal (label
)
2013 expressionS
*expP
= &mmix_raw_gregs
[n_of_raw_gregs
].exp
;
2015 /* Don't set the section to register contents section before the
2016 expression has been parsed; it may refer to the current position. */
2019 /* FIXME: Check that no expression refers to the register contents
2020 section. May need to be done in elf64-mmix.c. */
2021 if (expP
->X_op
== O_absent
)
2023 /* Default to zero if the expression was absent. */
2024 expP
->X_op
= O_constant
;
2025 expP
->X_add_number
= 0;
2026 expP
->X_unsigned
= 0;
2027 expP
->X_add_symbol
= NULL
;
2028 expP
->X_op_symbol
= NULL
;
2031 /* We must handle prefixes here, as we save the labels and expressions
2032 to be output later. */
2033 mmix_raw_gregs
[n_of_raw_gregs
].label
2034 = mmix_current_prefix
== NULL
? label
: mmix_prefix_name (label
);
2036 if (n_of_raw_gregs
== MAX_GREGS
- 1)
2037 as_bad (_("too many GREG registers allocated (max %d)"), MAX_GREGS
);
2041 mmix_handle_rest_of_empty_line ();
2044 /* The ".greg label,expr" worker. */
2048 int unused ATTRIBUTE_UNUSED
;
2052 p
= input_line_pointer
;
2054 /* This will skip over what can be a symbol and zero out the next
2055 character, which we assume is a ',' or other meaningful delimiter.
2056 What comes after that is the initializer expression for the
2058 c
= get_symbol_end ();
2060 if (! is_end_of_line
[(unsigned char) c
])
2061 input_line_pointer
++;
2065 /* The label must be persistent; it's not used until after all input
2067 obstack_grow (&mmix_sym_obstack
, p
, strlen (p
) + 1);
2068 mmix_greg_internal (obstack_finish (&mmix_sym_obstack
));
2071 mmix_greg_internal (NULL
);
2074 /* The "BSPEC expr" worker. */
2078 int unused ATTRIBUTE_UNUSED
;
2082 char secname
[sizeof (MMIX_OTHER_SPEC_SECTION_PREFIX
) + 20]
2083 = MMIX_OTHER_SPEC_SECTION_PREFIX
;
2087 /* Get a constant expression which we can evaluate *now*. Supporting
2088 more complex (though assembly-time computable) expressions is
2089 feasible but Too Much Work for something of unknown usefulness like
2091 expsec
= expression (&exp
);
2092 mmix_handle_rest_of_empty_line ();
2094 /* Check that we don't have another BSPEC in progress. */
2097 as_bad (_("BSPEC already active. Nesting is not supported."));
2101 if (exp
.X_op
!= O_constant
2102 || expsec
!= absolute_section
2103 || exp
.X_add_number
< 0
2104 || exp
.X_add_number
> 65535)
2106 as_bad (_("invalid BSPEC expression"));
2107 exp
.X_add_number
= 0;
2110 n
= (int) exp
.X_add_number
;
2112 sprintf (secname
+ strlen (MMIX_OTHER_SPEC_SECTION_PREFIX
), "%d", n
);
2113 sec
= bfd_get_section_by_name (stdoutput
, secname
);
2116 /* We need a non-volatile name as it will be stored in the section
2118 char *newsecname
= xstrdup (secname
);
2119 sec
= bfd_make_section (stdoutput
, newsecname
);
2122 as_fatal (_("can't create section %s"), newsecname
);
2124 if (!bfd_set_section_flags (stdoutput
, sec
,
2125 bfd_get_section_flags (stdoutput
, sec
)
2127 as_fatal (_("can't set section flags for section %s"), newsecname
);
2130 /* Tell ELF about the pending section change. */
2131 obj_elf_section_change_hook ();
2132 subseg_set (sec
, 0);
2134 /* Save position for missing ESPEC. */
2135 as_where (&bspec_file
, &bspec_line
);
2140 /* The "ESPEC" worker. */
2144 int unused ATTRIBUTE_UNUSED
;
2146 /* First, check that we *do* have a BSPEC in progress. */
2149 as_bad (_("ESPEC without preceding BSPEC"));
2153 mmix_handle_rest_of_empty_line ();
2156 /* When we told ELF about the section change in s_bspec, it stored the
2157 previous section for us so we can get at it with the equivalent of a
2158 .previous pseudo. */
2159 obj_elf_previous (0);
2162 /* The " .local expr" and " local expr" worker. We make a BFD_MMIX_LOCAL
2163 relocation against the current position against the expression.
2164 Implementing this by means of contents in a section lost. */
2167 mmix_s_local (unused
)
2168 int unused ATTRIBUTE_UNUSED
;
2172 /* Don't set the section to register contents section before the
2173 expression has been parsed; it may refer to the current position in
2174 some contorted way. */
2177 if (exp
.X_op
== O_absent
)
2179 as_bad (_("missing local expression"));
2182 else if (exp
.X_op
== O_register
)
2184 /* fix_new_exp doesn't like O_register. Should be configurable.
2185 We're fine with a constant here, though. */
2186 exp
.X_op
= O_constant
;
2189 fix_new_exp (frag_now
, 0, 0, &exp
, 0, BFD_RELOC_MMIX_LOCAL
);
2190 mmix_handle_rest_of_empty_line ();
2193 /* Set fragP->fr_var to the initial guess of the size of a relaxable insn
2194 and return it. Sizes of other instructions are not known. This
2195 function may be called multiple times. */
2198 md_estimate_size_before_relax (fragP
, segment
)
2204 #define HANDLE_RELAXABLE(state) \
2205 case ENCODE_RELAX (state, STATE_UNDF): \
2206 if (fragP->fr_symbol != NULL \
2207 && S_GET_SEGMENT (fragP->fr_symbol) == segment \
2208 && !S_IS_WEAK (fragP->fr_symbol)) \
2210 /* The symbol lies in the same segment - a relaxable case. */ \
2212 = ENCODE_RELAX (state, STATE_ZERO); \
2216 switch (fragP
->fr_subtype
)
2218 HANDLE_RELAXABLE (STATE_GETA
);
2219 HANDLE_RELAXABLE (STATE_BCC
);
2220 HANDLE_RELAXABLE (STATE_JMP
);
2222 case ENCODE_RELAX (STATE_PUSHJ
, STATE_UNDF
):
2223 if (fragP
->fr_symbol
!= NULL
2224 && S_GET_SEGMENT (fragP
->fr_symbol
) == segment
2225 && !S_IS_WEAK (fragP
->fr_symbol
))
2226 /* The symbol lies in the same segment - a relaxable case. */
2227 fragP
->fr_subtype
= ENCODE_RELAX (STATE_PUSHJ
, STATE_ZERO
);
2228 else if (pushj_stubs
)
2229 /* If we're to generate stubs, assume we can reach a stub after
2231 fragP
->fr_subtype
= ENCODE_RELAX (STATE_PUSHJSTUB
, STATE_ZERO
);
2233 case ENCODE_RELAX (STATE_PUSHJ
, STATE_ZERO
):
2234 case ENCODE_RELAX (STATE_PUSHJSTUB
, STATE_ZERO
):
2235 /* We need to distinguish different relaxation rounds. */
2236 seg_info (segment
)->tc_segment_info_data
.last_stubfrag
= fragP
;
2239 case ENCODE_RELAX (STATE_GETA
, STATE_ZERO
):
2240 case ENCODE_RELAX (STATE_BCC
, STATE_ZERO
):
2241 case ENCODE_RELAX (STATE_JMP
, STATE_ZERO
):
2242 /* When relaxing a section for the second time, we don't need to do
2243 anything except making sure that fr_var is set right. */
2246 case STATE_GREG_DEF
:
2247 length
= fragP
->tc_frag_data
!= NULL
? 0 : 8;
2248 fragP
->fr_var
= length
;
2250 /* Don't consult the relax_table; it isn't valid for this
2256 BAD_CASE (fragP
->fr_subtype
);
2259 length
= mmix_relax_table
[fragP
->fr_subtype
].rlx_length
;
2260 fragP
->fr_var
= length
;
2265 /* Turn a string in input_line_pointer into a floating point constant of type
2266 type, and store the appropriate bytes in *litP. The number of LITTLENUMS
2267 emitted is stored in *sizeP . An error message is returned, or NULL on
2271 md_atof (type
, litP
, sizeP
)
2277 LITTLENUM_TYPE words
[4];
2283 /* FIXME: Having 'f' in mmix_flt_chars (and here) makes it
2284 problematic to also have a forward reference in an expression.
2285 The testsuite wants it, and it's customary.
2286 We'll deal with the real problems when they come; we share the
2287 problem with most other ports. */
2297 return _("bad call to md_atof");
2300 t
= atof_ieee (input_line_pointer
, type
, words
);
2302 input_line_pointer
= t
;
2306 for (i
= 0; i
< prec
; i
++)
2308 md_number_to_chars (litP
, (valueT
) words
[i
], 2);
2314 /* Convert variable-sized frags into one or more fixups. */
2317 md_convert_frag (abfd
, sec
, fragP
)
2318 bfd
*abfd ATTRIBUTE_UNUSED
;
2319 segT sec ATTRIBUTE_UNUSED
;
2322 /* Pointer to first byte in variable-sized part of the frag. */
2325 /* Pointer to first opcode byte in frag. */
2328 /* Size in bytes of variable-sized part of frag. */
2329 int var_part_size
= 0;
2331 /* This is part of *fragP. It contains all information about addresses
2332 and offsets to varying parts. */
2334 unsigned long var_part_offset
;
2336 /* This is the frag for the opcode. It, rather than fragP, must be used
2337 when emitting a frag for the opcode. */
2338 fragS
*opc_fragP
= fragP
->tc_frag_data
;
2341 /* Where, in file space, does addr point? */
2342 bfd_vma target_address
;
2343 bfd_vma opcode_address
;
2345 know (fragP
->fr_type
== rs_machine_dependent
);
2347 var_part_offset
= fragP
->fr_fix
;
2348 var_partp
= fragP
->fr_literal
+ var_part_offset
;
2349 opcodep
= fragP
->fr_opcode
;
2351 symbolP
= fragP
->fr_symbol
;
2354 = ((symbolP
? S_GET_VALUE (symbolP
) : 0) + fragP
->fr_offset
);
2356 /* The opcode that would be extended is the last four "fixed" bytes. */
2357 opcode_address
= fragP
->fr_address
+ fragP
->fr_fix
- 4;
2359 switch (fragP
->fr_subtype
)
2361 case ENCODE_RELAX (STATE_PUSHJSTUB
, STATE_ZERO
):
2362 /* Setting the unknown bits to 0 seems the most appropriate. */
2363 mmix_set_geta_branch_offset (opcodep
, 0);
2364 tmpfixP
= fix_new (opc_fragP
, opcodep
- opc_fragP
->fr_literal
, 8,
2365 fragP
->fr_symbol
, fragP
->fr_offset
, 1,
2366 BFD_RELOC_MMIX_PUSHJ_STUBBABLE
);
2367 COPY_FR_WHERE_TO_FX (fragP
, tmpfixP
);
2371 case ENCODE_RELAX (STATE_GETA
, STATE_ZERO
):
2372 case ENCODE_RELAX (STATE_BCC
, STATE_ZERO
):
2373 case ENCODE_RELAX (STATE_PUSHJ
, STATE_ZERO
):
2374 mmix_set_geta_branch_offset (opcodep
, target_address
- opcode_address
);
2378 = fix_new (opc_fragP
, opcodep
- opc_fragP
->fr_literal
, 4,
2379 fragP
->fr_symbol
, fragP
->fr_offset
, 1,
2380 BFD_RELOC_MMIX_ADDR19
);
2381 COPY_FR_WHERE_TO_FX (fragP
, tmpfixP
);
2386 case ENCODE_RELAX (STATE_JMP
, STATE_ZERO
):
2387 mmix_set_jmp_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_ADDR27
);
2394 COPY_FR_WHERE_TO_FX (fragP
, tmpfixP
);
2399 case STATE_GREG_DEF
:
2400 if (fragP
->tc_frag_data
== NULL
)
2402 /* We must initialize data that's supposed to be "fixed up" to
2403 avoid emitting garbage, because md_apply_fix3 won't do
2404 anything for undefined symbols. */
2405 md_number_to_chars (var_partp
, 0, 8);
2407 = fix_new (fragP
, var_partp
- fragP
->fr_literal
, 8,
2408 fragP
->fr_symbol
, fragP
->fr_offset
, 0, BFD_RELOC_64
);
2409 COPY_FR_WHERE_TO_FX (fragP
, tmpfixP
);
2410 mmix_gregs
[n_of_cooked_gregs
++] = tmpfixP
;
2417 #define HANDLE_MAX_RELOC(state, reloc) \
2418 case ENCODE_RELAX (state, STATE_MAX): \
2420 = mmix_relax_table[ENCODE_RELAX (state, STATE_MAX)].rlx_length; \
2421 mmix_fill_nops (var_partp, var_part_size / 4); \
2422 if (warn_on_expansion) \
2423 as_warn_where (fragP->fr_file, fragP->fr_line, \
2424 _("operand out of range, instruction expanded")); \
2425 tmpfixP = fix_new (fragP, var_partp - fragP->fr_literal - 4, 8, \
2426 fragP->fr_symbol, fragP->fr_offset, 1, reloc); \
2427 COPY_FR_WHERE_TO_FX (fragP, tmpfixP); \
2430 HANDLE_MAX_RELOC (STATE_GETA
, BFD_RELOC_MMIX_GETA
);
2431 HANDLE_MAX_RELOC (STATE_BCC
, BFD_RELOC_MMIX_CBRANCH
);
2432 HANDLE_MAX_RELOC (STATE_PUSHJ
, BFD_RELOC_MMIX_PUSHJ
);
2433 HANDLE_MAX_RELOC (STATE_JMP
, BFD_RELOC_MMIX_JMP
);
2436 BAD_CASE (fragP
->fr_subtype
);
2440 fragP
->fr_fix
+= var_part_size
;
2444 /* Applies the desired value to the specified location.
2445 Also sets up addends for RELA type relocations.
2446 Stolen from tc-mcore.c.
2448 Note that this function isn't called when linkrelax != 0. */
2451 md_apply_fix3 (fixP
, valP
, segment
)
2456 char *buf
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
2457 /* Note: use offsetT because it is signed, valueT is unsigned. */
2458 offsetT val
= (offsetT
) * valP
;
2460 = (fixP
->fx_addsy
== NULL
2461 ? absolute_section
: S_GET_SEGMENT (fixP
->fx_addsy
));
2463 /* If the fix is relative to a symbol which is not defined, or, (if
2464 pcrel), not in the same segment as the fix, we cannot resolve it
2466 if (fixP
->fx_addsy
!= NULL
2467 && (! S_IS_DEFINED (fixP
->fx_addsy
)
2468 || S_IS_WEAK (fixP
->fx_addsy
)
2469 || (fixP
->fx_pcrel
&& symsec
!= segment
)
2470 || (! fixP
->fx_pcrel
2471 && symsec
!= absolute_section
2472 && ((fixP
->fx_r_type
!= BFD_RELOC_MMIX_REG
2473 && fixP
->fx_r_type
!= BFD_RELOC_MMIX_REG_OR_BYTE
)
2474 || symsec
!= reg_section
))))
2479 else if (fixP
->fx_r_type
== BFD_RELOC_MMIX_LOCAL
2480 || fixP
->fx_r_type
== BFD_RELOC_VTABLE_INHERIT
2481 || fixP
->fx_r_type
== BFD_RELOC_VTABLE_ENTRY
)
2483 /* These are never "fixed". */
2488 /* We assume every other relocation is "fixed". */
2491 switch (fixP
->fx_r_type
)
2498 case BFD_RELOC_64_PCREL
:
2499 case BFD_RELOC_32_PCREL
:
2500 case BFD_RELOC_24_PCREL
:
2501 case BFD_RELOC_16_PCREL
:
2502 case BFD_RELOC_8_PCREL
:
2503 md_number_to_chars (buf
, val
, fixP
->fx_size
);
2506 case BFD_RELOC_MMIX_ADDR19
:
2509 /* This shouldn't happen. */
2510 BAD_CASE (fixP
->fx_r_type
);
2514 case BFD_RELOC_MMIX_GETA
:
2515 case BFD_RELOC_MMIX_CBRANCH
:
2516 case BFD_RELOC_MMIX_PUSHJ
:
2517 case BFD_RELOC_MMIX_PUSHJ_STUBBABLE
:
2518 /* If this fixup is out of range, punt to the linker to emit an
2519 error. This should only happen with -no-expand. */
2520 if (val
< -(((offsetT
) 1 << 19)/2)
2521 || val
>= ((offsetT
) 1 << 19)/2 - 1
2524 if (warn_on_expansion
)
2525 as_warn_where (fixP
->fx_file
, fixP
->fx_line
,
2526 _("operand out of range"));
2530 mmix_set_geta_branch_offset (buf
, val
);
2533 case BFD_RELOC_MMIX_ADDR27
:
2536 /* This shouldn't happen. */
2537 BAD_CASE (fixP
->fx_r_type
);
2541 case BFD_RELOC_MMIX_JMP
:
2542 /* If this fixup is out of range, punt to the linker to emit an
2543 error. This should only happen with -no-expand. */
2544 if (val
< -(((offsetT
) 1 << 27)/2)
2545 || val
>= ((offsetT
) 1 << 27)/2 - 1
2548 if (warn_on_expansion
)
2549 as_warn_where (fixP
->fx_file
, fixP
->fx_line
,
2550 _("operand out of range"));
2554 mmix_set_jmp_offset (buf
, val
);
2557 case BFD_RELOC_MMIX_REG_OR_BYTE
:
2558 if (fixP
->fx_addsy
!= NULL
2559 && (S_GET_SEGMENT (fixP
->fx_addsy
) != reg_section
2560 || S_GET_VALUE (fixP
->fx_addsy
) > 255)
2561 && S_GET_SEGMENT (fixP
->fx_addsy
) != absolute_section
)
2563 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
2564 _("invalid operands"));
2565 /* We don't want this "symbol" appearing in output, because
2572 /* If this reloc is for a Z field, we need to adjust
2573 the opcode if we got a constant here.
2574 FIXME: Can we make this more robust? */
2576 if ((fixP
->fx_where
& 3) == 3
2577 && (fixP
->fx_addsy
== NULL
2578 || S_GET_SEGMENT (fixP
->fx_addsy
) == absolute_section
))
2579 buf
[-3] |= IMM_OFFSET_BIT
;
2582 case BFD_RELOC_MMIX_REG
:
2583 if (fixP
->fx_addsy
== NULL
2584 || S_GET_SEGMENT (fixP
->fx_addsy
) != reg_section
2585 || S_GET_VALUE (fixP
->fx_addsy
) > 255)
2587 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
2588 _("invalid operands"));
2595 case BFD_RELOC_MMIX_BASE_PLUS_OFFSET
:
2596 /* These are never "fixed". */
2600 case BFD_RELOC_MMIX_PUSHJ_1
:
2601 case BFD_RELOC_MMIX_PUSHJ_2
:
2602 case BFD_RELOC_MMIX_PUSHJ_3
:
2603 case BFD_RELOC_MMIX_CBRANCH_J
:
2604 case BFD_RELOC_MMIX_CBRANCH_1
:
2605 case BFD_RELOC_MMIX_CBRANCH_2
:
2606 case BFD_RELOC_MMIX_CBRANCH_3
:
2607 case BFD_RELOC_MMIX_GETA_1
:
2608 case BFD_RELOC_MMIX_GETA_2
:
2609 case BFD_RELOC_MMIX_GETA_3
:
2610 case BFD_RELOC_MMIX_JMP_1
:
2611 case BFD_RELOC_MMIX_JMP_2
:
2612 case BFD_RELOC_MMIX_JMP_3
:
2614 BAD_CASE (fixP
->fx_r_type
);
2619 /* Make sure that for completed fixups we have the value around for
2620 use by e.g. mmix_frob_file. */
2621 fixP
->fx_offset
= val
;
2624 /* A bsearch function for looking up a value against offsets for GREG
2628 cmp_greg_val_greg_symbol_fixes (p1
, p2
)
2632 offsetT val1
= *(offsetT
*) p1
;
2633 offsetT val2
= ((struct mmix_symbol_greg_fixes
*) p2
)->offs
;
2635 if (val1
>= val2
&& val1
< val2
+ 255)
2644 /* Generate a machine-dependent relocation. */
2647 tc_gen_reloc (section
, fixP
)
2648 asection
*section ATTRIBUTE_UNUSED
;
2653 + (fixP
->fx_addsy
!= NULL
2654 && !S_IS_WEAK (fixP
->fx_addsy
)
2655 && !S_IS_COMMON (fixP
->fx_addsy
)
2656 ? S_GET_VALUE (fixP
->fx_addsy
) : 0);
2658 bfd_reloc_code_real_type code
= BFD_RELOC_NONE
;
2659 char *buf
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
2660 symbolS
*addsy
= fixP
->fx_addsy
;
2661 asection
*addsec
= addsy
== NULL
? NULL
: S_GET_SEGMENT (addsy
);
2662 asymbol
*baddsy
= addsy
!= NULL
? symbol_get_bfdsym (addsy
) : NULL
;
2664 = val
- (baddsy
== NULL
|| S_IS_COMMON (addsy
) || S_IS_WEAK (addsy
)
2665 ? 0 : bfd_asymbol_value (baddsy
));
2667 /* A single " LOCAL expression" in the wrong section will not work when
2668 linking to MMO; relocations for zero-content sections are then
2669 ignored. Normally, relocations would modify section contents, and
2670 you'd never think or be able to do something like that. The
2671 relocation resulting from a LOCAL directive doesn't have an obvious
2672 and mandatory location. I can't figure out a way to do this better
2673 than just helping the user around this limitation here; hopefully the
2674 code using the local expression is around. Putting the LOCAL
2675 semantics in a relocation still seems right; a section didn't do. */
2676 if (bfd_section_size (section
->owner
, section
) == 0)
2678 (fixP
->fx_file
, fixP
->fx_line
,
2679 fixP
->fx_r_type
== BFD_RELOC_MMIX_LOCAL
2680 /* The BFD_RELOC_MMIX_LOCAL-specific message is supposed to be
2681 user-friendly, though a little bit non-substantial. */
2682 ? _("directive LOCAL must be placed in code or data")
2683 : _("internal confusion: relocation in a section without contents"));
2685 /* FIXME: Range tests for all these. */
2686 switch (fixP
->fx_r_type
)
2693 code
= fixP
->fx_r_type
;
2695 if (addsy
== NULL
|| bfd_is_abs_section (addsec
))
2697 /* Resolve this reloc now, as md_apply_fix3 would have done (not
2698 called if -linkrelax). There is no point in keeping a reloc
2699 to an absolute symbol. No reloc that is subject to
2700 relaxation must be to an absolute symbol; difference
2701 involving symbols in a specific section must be signalled as
2702 an error if the relaxing cannot be expressed; having a reloc
2703 to the resolved (now absolute) value does not help. */
2704 md_number_to_chars (buf
, val
, fixP
->fx_size
);
2709 case BFD_RELOC_64_PCREL
:
2710 case BFD_RELOC_32_PCREL
:
2711 case BFD_RELOC_24_PCREL
:
2712 case BFD_RELOC_16_PCREL
:
2713 case BFD_RELOC_8_PCREL
:
2714 case BFD_RELOC_MMIX_LOCAL
:
2715 case BFD_RELOC_VTABLE_INHERIT
:
2716 case BFD_RELOC_VTABLE_ENTRY
:
2717 case BFD_RELOC_MMIX_GETA
:
2718 case BFD_RELOC_MMIX_GETA_1
:
2719 case BFD_RELOC_MMIX_GETA_2
:
2720 case BFD_RELOC_MMIX_GETA_3
:
2721 case BFD_RELOC_MMIX_CBRANCH
:
2722 case BFD_RELOC_MMIX_CBRANCH_J
:
2723 case BFD_RELOC_MMIX_CBRANCH_1
:
2724 case BFD_RELOC_MMIX_CBRANCH_2
:
2725 case BFD_RELOC_MMIX_CBRANCH_3
:
2726 case BFD_RELOC_MMIX_PUSHJ
:
2727 case BFD_RELOC_MMIX_PUSHJ_1
:
2728 case BFD_RELOC_MMIX_PUSHJ_2
:
2729 case BFD_RELOC_MMIX_PUSHJ_3
:
2730 case BFD_RELOC_MMIX_PUSHJ_STUBBABLE
:
2731 case BFD_RELOC_MMIX_JMP
:
2732 case BFD_RELOC_MMIX_JMP_1
:
2733 case BFD_RELOC_MMIX_JMP_2
:
2734 case BFD_RELOC_MMIX_JMP_3
:
2735 case BFD_RELOC_MMIX_ADDR19
:
2736 case BFD_RELOC_MMIX_ADDR27
:
2737 code
= fixP
->fx_r_type
;
2740 case BFD_RELOC_MMIX_REG_OR_BYTE
:
2741 /* If we have this kind of relocation to an unknown symbol or to the
2742 register contents section (that is, to a register), then we can't
2743 resolve the relocation here. */
2745 && (bfd_is_und_section (addsec
)
2746 || strcmp (bfd_get_section_name (addsec
->owner
, addsec
),
2747 MMIX_REG_CONTENTS_SECTION_NAME
) == 0))
2749 code
= fixP
->fx_r_type
;
2753 /* If the relocation is not to the register section or to the
2754 absolute section (a numeric value), then we have an error. */
2756 && (S_GET_SEGMENT (addsy
) != real_reg_section
2759 && ! bfd_is_abs_section (addsec
))
2762 /* Set the "immediate" bit of the insn if this relocation is to Z
2763 field when the value is a numeric value, i.e. not a register. */
2764 if ((fixP
->fx_where
& 3) == 3
2765 && (addsy
== NULL
|| bfd_is_abs_section (addsec
)))
2766 buf
[-3] |= IMM_OFFSET_BIT
;
2771 case BFD_RELOC_MMIX_BASE_PLUS_OFFSET
:
2773 && strcmp (bfd_get_section_name (addsec
->owner
, addsec
),
2774 MMIX_REG_CONTENTS_SECTION_NAME
) == 0)
2776 /* This changed into a register; the relocation is for the
2777 register-contents section. The constant part remains zero. */
2778 code
= BFD_RELOC_MMIX_REG
;
2782 /* If we've found out that this was indeed a register, then replace
2783 with the register number. The constant part is already zero.
2785 If we encounter any other defined symbol, then we must find a
2786 suitable register and emit a reloc. */
2787 if (addsy
== NULL
|| addsec
!= real_reg_section
)
2789 struct mmix_symbol_gregs
*gregs
;
2790 struct mmix_symbol_greg_fixes
*fix
;
2792 if (S_IS_DEFINED (addsy
)
2793 && !bfd_is_com_section (addsec
)
2794 && !S_IS_WEAK (addsy
))
2796 if (! symbol_section_p (addsy
) && ! bfd_is_abs_section (addsec
))
2797 as_fatal (_("internal: BFD_RELOC_MMIX_BASE_PLUS_OFFSET not resolved to section"));
2799 /* If this is an absolute symbol sufficiently near
2800 lowest_data_loc, then we canonicalize on the data
2801 section. Note that val is signed here; we may subtract
2802 lowest_data_loc which is unsigned. Careful with those
2804 if (lowest_data_loc
!= (bfd_vma
) -1
2805 && (bfd_vma
) val
+ 256 > lowest_data_loc
2806 && bfd_is_abs_section (addsec
))
2808 val
-= (offsetT
) lowest_data_loc
;
2809 addsy
= section_symbol (data_section
);
2811 /* Likewise text section. */
2812 else if (lowest_text_loc
!= (bfd_vma
) -1
2813 && (bfd_vma
) val
+ 256 > lowest_text_loc
2814 && bfd_is_abs_section (addsec
))
2816 val
-= (offsetT
) lowest_text_loc
;
2817 addsy
= section_symbol (text_section
);
2821 gregs
= *symbol_get_tc (addsy
);
2823 /* If that symbol does not have any associated GREG definitions,
2824 we can't do anything. */
2826 || (fix
= bsearch (&val
, gregs
->greg_fixes
, gregs
->n_gregs
,
2827 sizeof (gregs
->greg_fixes
[0]),
2828 cmp_greg_val_greg_symbol_fixes
)) == NULL
2829 /* The register must not point *after* the address we want. */
2831 /* Neither must the register point more than 255 bytes
2832 before the address we want. */
2833 || fix
->offs
+ 255 < val
)
2835 /* We can either let the linker allocate GREGs
2836 automatically, or emit an error. */
2837 if (allocate_undefined_gregs_in_linker
)
2839 /* The values in baddsy and addend are right. */
2840 code
= fixP
->fx_r_type
;
2844 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
2845 _("no suitable GREG definition for operands"));
2850 /* Transform the base-plus-offset reloc for the actual area
2851 to a reloc for the register with the address of the area.
2852 Put addend for register in Z operand. */
2853 buf
[1] = val
- fix
->offs
;
2854 code
= BFD_RELOC_MMIX_REG
;
2856 = (bfd_get_section_by_name (stdoutput
,
2857 MMIX_REG_CONTENTS_SECTION_NAME
)
2860 addend
= fix
->fix
->fx_frag
->fr_address
+ fix
->fix
->fx_where
;
2863 else if (S_GET_VALUE (addsy
) > 255)
2864 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
2865 _("invalid operands"));
2873 case BFD_RELOC_MMIX_REG
:
2875 && (bfd_is_und_section (addsec
)
2876 || strcmp (bfd_get_section_name (addsec
->owner
, addsec
),
2877 MMIX_REG_CONTENTS_SECTION_NAME
) == 0))
2879 code
= fixP
->fx_r_type
;
2884 && (addsec
!= real_reg_section
2887 && ! bfd_is_und_section (addsec
))
2888 /* Drop through to error message. */
2897 /* The others are supposed to be handled by md_apply_fix3.
2898 FIXME: ... which isn't called when -linkrelax. Move over
2899 md_apply_fix3 code here for everything reasonable. */
2903 (fixP
->fx_file
, fixP
->fx_line
,
2904 _("operands were not reducible at assembly-time"));
2906 /* Unmark this symbol as used in a reloc, so we don't bump into a BFD
2907 assert when trying to output reg_section. FIXME: A gas bug. */
2908 fixP
->fx_addsy
= NULL
;
2912 relP
= (arelent
*) xmalloc (sizeof (arelent
));
2914 relP
->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
2915 *relP
->sym_ptr_ptr
= baddsy
;
2916 relP
->address
= fixP
->fx_frag
->fr_address
+ fixP
->fx_where
;
2918 relP
->addend
= addend
;
2920 /* If this had been a.out, we would have had a kludge for weak symbols
2923 relP
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
2928 name
= S_GET_NAME (addsy
);
2930 name
= _("<unknown>");
2931 as_fatal (_("cannot generate relocation type for symbol %s, code %s"),
2932 name
, bfd_get_reloc_code_name (code
));
2938 /* Do some reformatting of a line. FIXME: We could transform a mmixal
2939 line into traditional (GNU?) format, unless #NO_APP, and get rid of all
2940 ugly labels_without_colons etc. */
2943 mmix_handle_mmixal ()
2945 char *s0
= input_line_pointer
;
2950 if (pending_label
!= NULL
)
2951 as_fatal (_("internal: unhandled label %s"), pending_label
);
2953 if (mmix_gnu_syntax
)
2956 /* If the first character is a '.', then it's a pseudodirective, not a
2957 label. Make GAS not handle label-without-colon on this line. We
2958 also don't do mmixal-specific stuff on this line. */
2959 if (input_line_pointer
[0] == '.')
2961 label_without_colon_this_line
= 0;
2965 /* Don't handle empty lines here. */
2968 if (*s0
== 0 || is_end_of_line
[(unsigned int) *s0
])
2971 if (! ISSPACE (*s0
))
2977 /* If we're on a line with a label, check if it's a mmixal fb-label.
2978 Save an indicator and skip the label; it must be set only after all
2979 fb-labels of expressions are evaluated. */
2980 if (ISDIGIT (input_line_pointer
[0])
2981 && input_line_pointer
[1] == 'H'
2982 && ISSPACE (input_line_pointer
[2]))
2985 current_fb_label
= input_line_pointer
[0] - '0';
2987 /* We have to skip the label, but also preserve the newlineness of
2988 the previous character, since the caller checks that. It's a
2989 mess we blame on the caller. */
2990 input_line_pointer
[1] = input_line_pointer
[-1];
2991 input_line_pointer
+= 2;
2993 s
= input_line_pointer
;
2994 while (*s
&& ISSPACE (*s
) && ! is_end_of_line
[(unsigned int) *s
])
2997 /* For errors emitted here, the book-keeping is off by one; the
2998 caller is about to bump the counters. Adjust the error messages. */
2999 if (is_end_of_line
[(unsigned int) *s
])
3003 as_where (&name
, &line
);
3004 as_bad_where (name
, line
+ 1,
3005 _("[0-9]H labels may not appear alone on a line"));
3006 current_fb_label
= -1;
3012 as_where (&name
, &line
);
3013 as_bad_where (name
, line
+ 1,
3014 _("[0-9]H labels do not mix with dot-pseudos"));
3015 current_fb_label
= -1;
3020 current_fb_label
= -1;
3021 if (is_name_beginner (input_line_pointer
[0]))
3022 label
= input_line_pointer
;
3025 s0
= input_line_pointer
;
3026 /* Skip over label. */
3027 while (*s0
&& is_part_of_name (*s0
))
3030 /* Remove trailing ":" off labels, as they'd otherwise be considered
3031 part of the name. But don't do it for local labels. */
3032 if (s0
!= input_line_pointer
&& s0
[-1] == ':'
3033 && (s0
- 2 != input_line_pointer
3034 || ! ISDIGIT (s0
[-2])))
3036 else if (label
!= NULL
)
3038 /* For labels that don't end in ":", we save it so we can later give
3039 it the same alignment and address as the associated instruction. */
3041 /* Make room for the label including the ending nul. */
3042 int len_0
= s0
- label
+ 1;
3044 /* Save this label on the MMIX symbol obstack. Saving it on an
3045 obstack is needless for "IS"-pseudos, but it's harmless and we
3046 avoid a little code-cluttering. */
3047 obstack_grow (&mmix_sym_obstack
, label
, len_0
);
3048 pending_label
= obstack_finish (&mmix_sym_obstack
);
3049 pending_label
[len_0
- 1] = 0;
3052 while (*s0
&& ISSPACE (*s0
) && ! is_end_of_line
[(unsigned int) *s0
])
3055 if (pending_label
!= NULL
&& is_end_of_line
[(unsigned int) *s0
])
3056 /* Whoops, this was actually a lone label on a line. Like :-ended
3057 labels, we don't attach such labels to the next instruction or
3059 pending_label
= NULL
;
3061 /* Find local labels of operands. Look for "[0-9][FB]" where the
3062 characters before and after are not part of words. Break if a single
3063 or double quote is seen anywhere. It means we can't have local
3064 labels as part of list with mixed quoted and unquoted members for
3065 mmixal compatibility but we can't have it all. For the moment.
3066 Replace the '<N>B' or '<N>F' with MAGIC_FB_BACKWARD_CHAR<N> and
3067 MAGIC_FB_FORWARD_CHAR<N> respectively. */
3069 /* First make sure we don't have any of the magic characters on the line
3070 appearing as input. */
3075 if (is_end_of_line
[(unsigned int) c
])
3077 if (c
== MAGIC_FB_BACKWARD_CHAR
|| c
== MAGIC_FB_FORWARD_CHAR
)
3078 as_bad (_("invalid characters in input"));
3081 /* Scan again, this time looking for ';' after operands. */
3084 /* Skip the insn. */
3088 && ! is_end_of_line
[(unsigned int) *s
])
3091 /* Skip the spaces after the insn. */
3095 && ! is_end_of_line
[(unsigned int) *s
])
3098 /* Skip the operands. While doing this, replace [0-9][BF] with
3099 (MAGIC_FB_BACKWARD_CHAR|MAGIC_FB_FORWARD_CHAR)[0-9]. */
3100 while ((c
= *s
) != 0
3103 && ! is_end_of_line
[(unsigned int) c
])
3109 /* FIXME: Test-case for semi-colon in string. */
3112 && (! is_end_of_line
[(unsigned int) *s
] || *s
== ';'))
3118 else if (ISDIGIT (c
))
3120 if ((s
[1] != 'B' && s
[1] != 'F')
3121 || is_part_of_name (s
[-1])
3122 || is_part_of_name (s
[2]))
3127 ? MAGIC_FB_BACKWARD_CHAR
: MAGIC_FB_FORWARD_CHAR
);
3135 /* Skip any spaces after the operands. */
3139 && !is_end_of_line
[(unsigned int) *s
])
3142 /* If we're now looking at a semi-colon, then it's an end-of-line
3144 mmix_next_semicolon_is_eoln
= (*s
== ';');
3146 /* Make IS into an EQU by replacing it with "= ". Only match upper-case
3147 though; let lower-case be a syntax error. */
3149 if (s
[0] == 'I' && s
[1] == 'S' && ISSPACE (s
[2]))
3154 /* Since labels can start without ":", we have to handle "X IS 42"
3155 in full here, or "X" will be parsed as a label to be set at ".". */
3156 input_line_pointer
= s
;
3158 /* Right after this function ends, line numbers will be bumped if
3159 input_line_pointer[-1] = '\n'. We want accurate line numbers for
3160 the equals call, so we bump them before the call, and make sure
3161 they aren't bumped afterwards. */
3162 bump_line_counters ();
3164 /* A fb-label is valid as an IS-label. */
3165 if (current_fb_label
>= 0)
3169 /* We need to save this name on our symbol obstack, since the
3170 string we got in fb_label_name is volatile and will change
3171 with every call to fb_label_name, like those resulting from
3172 parsing the IS-operand. */
3173 fb_name
= fb_label_name (current_fb_label
, 1);
3174 obstack_grow (&mmix_sym_obstack
, fb_name
, strlen (fb_name
) + 1);
3175 equals (obstack_finish (&mmix_sym_obstack
), 0);
3176 fb_label_instance_inc (current_fb_label
);
3177 current_fb_label
= -1;
3181 if (pending_label
== NULL
)
3182 as_bad (_("empty label field for IS"));
3184 equals (pending_label
, 0);
3185 pending_label
= NULL
;
3188 /* For mmixal, we can have comments without a comment-start
3190 mmix_handle_rest_of_empty_line ();
3191 input_line_pointer
--;
3193 input_line_pointer
[-1] = ' ';
3195 else if (s
[0] == 'G'
3197 && strncmp (s
, "GREG", 4) == 0
3198 && (ISSPACE (s
[4]) || is_end_of_line
[(unsigned char) s
[4]]))
3200 input_line_pointer
= s
+ 4;
3202 /* Right after this function ends, line numbers will be bumped if
3203 input_line_pointer[-1] = '\n'. We want accurate line numbers for
3204 the s_greg call, so we bump them before the call, and make sure
3205 they aren't bumped afterwards. */
3206 bump_line_counters ();
3208 /* A fb-label is valid as a GREG-label. */
3209 if (current_fb_label
>= 0)
3213 /* We need to save this name on our symbol obstack, since the
3214 string we got in fb_label_name is volatile and will change
3215 with every call to fb_label_name, like those resulting from
3216 parsing the IS-operand. */
3217 fb_name
= fb_label_name (current_fb_label
, 1);
3219 /* Make sure we save the canonical name and don't get bitten by
3221 obstack_1grow (&mmix_sym_obstack
, ':');
3222 obstack_grow (&mmix_sym_obstack
, fb_name
, strlen (fb_name
) + 1);
3223 mmix_greg_internal (obstack_finish (&mmix_sym_obstack
));
3224 fb_label_instance_inc (current_fb_label
);
3225 current_fb_label
= -1;
3228 mmix_greg_internal (pending_label
);
3230 /* Back up before the end-of-line marker that was skipped in
3231 mmix_greg_internal. */
3232 input_line_pointer
--;
3233 input_line_pointer
[-1] = ' ';
3235 pending_label
= NULL
;
3237 else if (pending_label
!= NULL
)
3239 input_line_pointer
+= strlen (pending_label
);
3241 /* See comment above about getting line numbers bumped. */
3242 input_line_pointer
[-1] = '\n';
3246 /* Give the value of an fb-label rewritten as in mmix_handle_mmixal, when
3247 parsing an expression.
3249 On valid calls, input_line_pointer points at a MAGIC_FB_BACKWARD_CHAR
3250 or MAGIC_FB_BACKWARD_CHAR, followed by an ascii digit for the label.
3251 We fill in the label as an expression. */
3254 mmix_fb_label (expP
)
3258 char *fb_internal_name
;
3260 /* This doesn't happen when not using mmixal syntax. */
3262 || (input_line_pointer
[0] != MAGIC_FB_BACKWARD_CHAR
3263 && input_line_pointer
[0] != MAGIC_FB_FORWARD_CHAR
))
3266 /* The current backward reference has augmentation 0. A forward
3267 reference has augmentation 1, unless it's the same as a fb-label on
3268 _this_ line, in which case we add one more so we don't refer to it.
3269 This is the semantics of mmixal; it differs to that of common
3270 fb-labels which refer to a here-label on the current line as a
3271 backward reference. */
3273 = fb_label_name (input_line_pointer
[1] - '0',
3274 (input_line_pointer
[0] == MAGIC_FB_FORWARD_CHAR
? 1 : 0)
3275 + ((input_line_pointer
[1] - '0' == current_fb_label
3276 && input_line_pointer
[0] == MAGIC_FB_FORWARD_CHAR
)
3279 input_line_pointer
+= 2;
3280 sym
= symbol_find_or_make (fb_internal_name
);
3282 /* We don't have to clean up unrelated fields here; we just do what the
3283 expr machinery does, but *not* just what it does for [0-9][fb], since
3284 we need to treat those as ordinary symbols sometimes; see testcases
3285 err-byte2.s and fb-2.s. */
3286 if (S_GET_SEGMENT (sym
) == absolute_section
)
3288 expP
->X_op
= O_constant
;
3289 expP
->X_add_number
= S_GET_VALUE (sym
);
3293 expP
->X_op
= O_symbol
;
3294 expP
->X_add_symbol
= sym
;
3295 expP
->X_add_number
= 0;
3299 /* See whether we need to force a relocation into the output file.
3300 This is used to force out switch and PC relative relocations when
3304 mmix_force_relocation (fixP
)
3307 if (fixP
->fx_r_type
== BFD_RELOC_MMIX_LOCAL
3308 || fixP
->fx_r_type
== BFD_RELOC_MMIX_BASE_PLUS_OFFSET
)
3314 /* All our pcrel relocations are must-keep. Note that md_apply_fix3 is
3315 called *after* this, and will handle getting rid of the presumed
3316 reloc; a relocation isn't *forced* other than to be handled by
3317 md_apply_fix3 (or tc_gen_reloc if linkrelax). */
3321 return generic_force_reloc (fixP
);
3324 /* The location from which a PC relative jump should be calculated,
3325 given a PC relative reloc. */
3328 md_pcrel_from_section (fixP
, sec
)
3332 if (fixP
->fx_addsy
!= (symbolS
*) NULL
3333 && (! S_IS_DEFINED (fixP
->fx_addsy
)
3334 || S_GET_SEGMENT (fixP
->fx_addsy
) != sec
))
3336 /* The symbol is undefined (or is defined but not in this section).
3337 Let the linker figure it out. */
3341 return (fixP
->fx_frag
->fr_address
+ fixP
->fx_where
);
3344 /* Adjust the symbol table. We make reg_section relative to the real
3345 register section. */
3348 mmix_adjust_symtab ()
3351 symbolS
*regsec
= section_symbol (reg_section
);
3353 for (sym
= symbol_rootP
; sym
!= NULL
; sym
= symbol_next (sym
))
3354 if (S_GET_SEGMENT (sym
) == reg_section
)
3358 if (S_IS_EXTERN (sym
) || symbol_used_in_reloc_p (sym
))
3360 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
3363 /* Change section to the *real* register section, so it gets
3364 proper treatment when writing it out. Only do this for
3365 global symbols. This also means we don't have to check for
3367 S_SET_SEGMENT (sym
, real_reg_section
);
3371 /* This is the expansion of LABELS_WITHOUT_COLONS.
3372 We let md_start_line_hook tweak label_without_colon_this_line, and then
3373 this function returns the tweaked value, and sets it to 1 for the next
3374 line. FIXME: Very, very brittle. Not sure it works the way I
3375 thought at the time I first wrote this. */
3378 mmix_label_without_colon_this_line ()
3380 int retval
= label_without_colon_this_line
;
3382 if (! mmix_gnu_syntax
)
3383 label_without_colon_this_line
= 1;
3388 /* This is the expansion of md_relax_frag. We go through the ordinary
3389 relax table function except when the frag is for a GREG. Then we have
3390 to check whether there's another GREG by the same value that we can
3394 mmix_md_relax_frag (seg
, fragP
, stretch
)
3399 switch (fragP
->fr_subtype
)
3401 /* Growth for this type has been handled by mmix_md_end and
3402 correctly estimated, so there's nothing more to do here. */
3403 case STATE_GREG_DEF
:
3406 case ENCODE_RELAX (STATE_PUSHJ
, STATE_ZERO
):
3408 /* We need to handle relaxation type ourselves, since relax_frag
3409 doesn't update fr_subtype if there's no size increase in the
3410 current section; when going from plain PUSHJ to a stub. This
3411 is otherwise functionally the same as relax_frag in write.c,
3412 simplified for this case. */
3417 target
= fragP
->fr_offset
;
3418 address
= fragP
->fr_address
;
3419 symbolP
= fragP
->fr_symbol
;
3425 sym_frag
= symbol_get_frag (symbolP
);
3426 know (S_GET_SEGMENT (symbolP
) != absolute_section
3427 || sym_frag
== &zero_address_frag
);
3428 target
+= S_GET_VALUE (symbolP
);
3430 /* If frag has yet to be reached on this pass, assume it will
3431 move by STRETCH just as we did. If this is not so, it will
3432 be because some frag between grows, and that will force
3436 && sym_frag
->relax_marker
!= fragP
->relax_marker
3437 && S_GET_SEGMENT (symbolP
) == seg
)
3441 aim
= target
- address
- fragP
->fr_fix
;
3442 if (aim
>= PUSHJ_0B
&& aim
<= PUSHJ_0F
)
3444 /* Target is reachable with a PUSHJ. */
3445 segment_info_type
*seginfo
= seg_info (seg
);
3447 /* If we're at the end of a relaxation round, clear the stub
3448 counter as initialization for the next round. */
3449 if (fragP
== seginfo
->tc_segment_info_data
.last_stubfrag
)
3450 seginfo
->tc_segment_info_data
.nstubs
= 0;
3454 /* Not reachable. Try a stub. */
3455 fragP
->fr_subtype
= ENCODE_RELAX (STATE_PUSHJSTUB
, STATE_ZERO
);
3459 /* See if this PUSHJ is redirectable to a stub. */
3460 case ENCODE_RELAX (STATE_PUSHJSTUB
, STATE_ZERO
):
3462 segment_info_type
*seginfo
= seg_info (seg
);
3463 fragS
*lastfrag
= seginfo
->frchainP
->frch_last
;
3464 relax_substateT prev_type
= fragP
->fr_subtype
;
3466 /* The last frag is always an empty frag, so it suffices to look
3467 at its address to know the ending address of this section. */
3468 know (lastfrag
->fr_type
== rs_fill
3469 && lastfrag
->fr_fix
== 0
3470 && lastfrag
->fr_var
== 0);
3472 /* For this PUSHJ to be relaxable into a call to a stub, the
3473 distance must be no longer than 256k bytes from the PUSHJ to
3474 the end of the section plus the maximum size of stubs so far. */
3475 if ((lastfrag
->fr_address
3477 + PUSHJ_MAX_LEN
* seginfo
->tc_segment_info_data
.nstubs
)
3478 - (fragP
->fr_address
+ fragP
->fr_fix
)
3481 fragP
->fr_subtype
= mmix_relax_table
[prev_type
].rlx_more
;
3483 seginfo
->tc_segment_info_data
.nstubs
++;
3485 /* If we're at the end of a relaxation round, clear the stub
3486 counter as initialization for the next round. */
3487 if (fragP
== seginfo
->tc_segment_info_data
.last_stubfrag
)
3488 seginfo
->tc_segment_info_data
.nstubs
= 0;
3491 (mmix_relax_table
[fragP
->fr_subtype
].rlx_length
3492 - mmix_relax_table
[prev_type
].rlx_length
);
3495 case ENCODE_RELAX (STATE_PUSHJ
, STATE_MAX
):
3497 segment_info_type
*seginfo
= seg_info (seg
);
3499 /* Need to cover all STATE_PUSHJ states to act on the last stub
3500 frag (the end of this relax round; initialization for the
3502 if (fragP
== seginfo
->tc_segment_info_data
.last_stubfrag
)
3503 seginfo
->tc_segment_info_data
.nstubs
= 0;
3509 return relax_frag (seg
, fragP
, stretch
);
3511 case STATE_GREG_UNDF
:
3512 BAD_CASE (fragP
->fr_subtype
);
3515 as_fatal (_("internal: unexpected relax type %d:%d"),
3516 fragP
->fr_type
, fragP
->fr_subtype
);
3520 /* Various things we punt until all input is seen. */
3529 /* The first frag of GREG:s going into the register contents section. */
3530 fragS
*mmix_reg_contents_frags
= NULL
;
3532 /* Reset prefix. All labels reachable at this point must be
3534 mmix_current_prefix
= NULL
;
3537 as_bad_where (bspec_file
, bspec_line
, _("BSPEC without ESPEC."));
3539 /* Emit the low LOC setting of .text. */
3540 if (text_has_contents
&& lowest_text_loc
!= (bfd_vma
) -1)
3543 char locsymbol
[sizeof (":") - 1
3544 + sizeof (MMIX_LOC_SECTION_START_SYMBOL_PREFIX
) - 1
3545 + sizeof (".text")];
3547 /* An exercise in non-ISO-C-ness, this one. */
3548 sprintf (locsymbol
, ":%s%s", MMIX_LOC_SECTION_START_SYMBOL_PREFIX
,
3551 = symbol_new (locsymbol
, absolute_section
, lowest_text_loc
,
3552 &zero_address_frag
);
3553 S_SET_EXTERNAL (symbolP
);
3557 if (data_has_contents
&& lowest_data_loc
!= (bfd_vma
) -1)
3560 char locsymbol
[sizeof (":") - 1
3561 + sizeof (MMIX_LOC_SECTION_START_SYMBOL_PREFIX
) - 1
3562 + sizeof (".data")];
3564 sprintf (locsymbol
, ":%s%s", MMIX_LOC_SECTION_START_SYMBOL_PREFIX
,
3567 = symbol_new (locsymbol
, absolute_section
, lowest_data_loc
,
3568 &zero_address_frag
);
3569 S_SET_EXTERNAL (symbolP
);
3572 /* Unless GNU syntax mode, set "Main" to be a function, so the
3573 disassembler doesn't get confused when we write truly
3574 mmixal-compatible code (and don't use .type). Similarly set it
3575 global (regardless of -globalize-symbols), so the linker sees it as
3576 the start symbol in ELF mode. */
3577 mainsym
= symbol_find (MMIX_START_SYMBOL_NAME
);
3578 if (mainsym
!= NULL
&& ! mmix_gnu_syntax
)
3580 symbol_get_bfdsym (mainsym
)->flags
|= BSF_FUNCTION
;
3581 S_SET_EXTERNAL (mainsym
);
3584 if (n_of_raw_gregs
!= 0)
3586 /* Emit GREGs. They are collected in order of appearance, but must
3587 be emitted in opposite order to both have section address regno*8
3588 and the same allocation order (within a file) as mmixal. */
3589 segT this_segment
= now_seg
;
3590 subsegT this_subsegment
= now_subseg
;
3592 = bfd_make_section_old_way (stdoutput
,
3593 MMIX_REG_CONTENTS_SECTION_NAME
);
3594 subseg_set (regsec
, 0);
3596 /* Finally emit the initialization-value. Emit a variable frag, which
3597 we'll fix in md_estimate_size_before_relax. We set the initializer
3598 for the tc_frag_data field to NULL, so we can use that field for
3599 relaxation purposes. */
3600 mmix_opcode_frag
= NULL
;
3603 mmix_reg_contents_frags
= frag_now
;
3605 for (i
= n_of_raw_gregs
- 1; i
>= 0; i
--)
3607 if (mmix_raw_gregs
[i
].label
!= NULL
)
3608 /* There's a symbol. Let it refer to this location in the
3609 register contents section. The symbol must be globalized
3611 colon (mmix_raw_gregs
[i
].label
);
3613 frag_var (rs_machine_dependent
, 8, 0, STATE_GREG_UNDF
,
3614 make_expr_symbol (&mmix_raw_gregs
[i
].exp
), 0, NULL
);
3617 subseg_set (this_segment
, this_subsegment
);
3620 /* Iterate over frags resulting from GREGs and move those that evidently
3621 have the same value together and point one to another.
3623 This works in time O(N^2) but since the upper bound for non-error use
3624 is 223, it's best to keep this simpler algorithm. */
3625 for (fragP
= mmix_reg_contents_frags
; fragP
!= NULL
; fragP
= fragP
->fr_next
)
3632 symbolS
*symbolP
= fragP
->fr_symbol
;
3634 if (fragP
->fr_type
!= rs_machine_dependent
3635 || fragP
->fr_subtype
!= STATE_GREG_UNDF
)
3638 /* Whatever the outcome, we will have this GREG judged merged or
3639 non-merged. Since the tc_frag_data is NULL at this point, we
3640 default to non-merged. */
3641 fragP
->fr_subtype
= STATE_GREG_DEF
;
3643 /* If we're not supposed to merge GREG definitions, then just don't
3644 look for equivalents. */
3648 osymval
= (offsetT
) S_GET_VALUE (symbolP
);
3649 osymfrag
= symbol_get_frag (symbolP
);
3651 /* If the symbol isn't defined, we can't say that another symbol
3652 equals this frag, then. FIXME: We can look at the "deepest"
3653 defined name; if a = c and b = c then obviously a == b. */
3654 if (! S_IS_DEFINED (symbolP
))
3657 oexpP
= symbol_get_value_expression (fragP
->fr_symbol
);
3659 /* If the initialization value is zero, then we must not merge them. */
3660 if (oexpP
->X_op
== O_constant
&& osymval
== 0)
3663 /* Iterate through the frags downward this one. If we find one that
3664 has the same non-zero value, move it to after this one and point
3665 to it as the equivalent. */
3666 for (fpp
= &fragP
->fr_next
; *fpp
!= NULL
; fpp
= &fpp
[0]->fr_next
)
3670 if (fp
->fr_type
!= rs_machine_dependent
3671 || fp
->fr_subtype
!= STATE_GREG_UNDF
)
3674 /* Calling S_GET_VALUE may simplify the symbol, changing from
3675 expr_section etc. so call it first. */
3676 if ((offsetT
) S_GET_VALUE (fp
->fr_symbol
) == osymval
3677 && symbol_get_frag (fp
->fr_symbol
) == osymfrag
)
3679 /* Move the frag links so the one we found equivalent comes
3680 after the current one, carefully considering that
3681 sometimes fpp == &fragP->fr_next and the moves must be a
3684 fp
->fr_next
= fragP
->fr_next
;
3685 fragP
->fr_next
= fp
;
3691 fragP
->tc_frag_data
= fp
;
3695 /* qsort function for mmix_symbol_gregs. */
3698 cmp_greg_symbol_fixes (parg
, qarg
)
3702 const struct mmix_symbol_greg_fixes
*p
3703 = (const struct mmix_symbol_greg_fixes
*) parg
;
3704 const struct mmix_symbol_greg_fixes
*q
3705 = (const struct mmix_symbol_greg_fixes
*) qarg
;
3707 return p
->offs
> q
->offs
? 1 : p
->offs
< q
->offs
? -1 : 0;
3710 /* Collect GREG definitions from mmix_gregs and hang them as lists sorted
3711 on increasing offsets onto each section symbol or undefined symbol.
3713 Also, remove the register convenience section so it doesn't get output
3714 as an ELF section. */
3720 struct mmix_symbol_gregs
*all_greg_symbols
[MAX_GREGS
];
3721 int n_greg_symbols
= 0;
3723 /* Collect all greg fixups and decorate each corresponding symbol with
3724 the greg fixups for it. */
3725 for (i
= 0; i
< n_of_cooked_gregs
; i
++)
3729 struct mmix_symbol_gregs
*gregs
;
3732 fixP
= mmix_gregs
[i
];
3733 know (fixP
->fx_r_type
== BFD_RELOC_64
);
3735 /* This case isn't doable in general anyway, methinks. */
3736 if (fixP
->fx_subsy
!= NULL
)
3738 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3739 _("GREG expression too complicated"));
3743 sym
= fixP
->fx_addsy
;
3744 offs
= (offsetT
) fixP
->fx_offset
;
3746 /* If the symbol is defined, then it must be resolved to a section
3747 symbol at this time, or else we don't know how to handle it. */
3748 if (S_IS_DEFINED (sym
)
3749 && !bfd_is_com_section (S_GET_SEGMENT (sym
))
3750 && !S_IS_WEAK (sym
))
3752 if (! symbol_section_p (sym
)
3753 && ! bfd_is_abs_section (S_GET_SEGMENT (sym
)))
3754 as_fatal (_("internal: GREG expression not resolved to section"));
3756 offs
+= S_GET_VALUE (sym
);
3759 /* If this is an absolute symbol sufficiently near lowest_data_loc,
3760 then we canonicalize on the data section. Note that offs is
3761 signed here; we may subtract lowest_data_loc which is unsigned.
3762 Careful with those comparisons. */
3763 if (lowest_data_loc
!= (bfd_vma
) -1
3764 && (bfd_vma
) offs
+ 256 > lowest_data_loc
3765 && bfd_is_abs_section (S_GET_SEGMENT (sym
)))
3767 offs
-= (offsetT
) lowest_data_loc
;
3768 sym
= section_symbol (data_section
);
3770 /* Likewise text section. */
3771 else if (lowest_text_loc
!= (bfd_vma
) -1
3772 && (bfd_vma
) offs
+ 256 > lowest_text_loc
3773 && bfd_is_abs_section (S_GET_SEGMENT (sym
)))
3775 offs
-= (offsetT
) lowest_text_loc
;
3776 sym
= section_symbol (text_section
);
3779 gregs
= *symbol_get_tc (sym
);
3783 gregs
= xmalloc (sizeof (*gregs
));
3785 symbol_set_tc (sym
, &gregs
);
3786 all_greg_symbols
[n_greg_symbols
++] = gregs
;
3789 gregs
->greg_fixes
[gregs
->n_gregs
].fix
= fixP
;
3790 gregs
->greg_fixes
[gregs
->n_gregs
++].offs
= offs
;
3793 /* For each symbol having a GREG definition, sort those definitions on
3795 for (i
= 0; i
< n_greg_symbols
; i
++)
3796 qsort (all_greg_symbols
[i
]->greg_fixes
, all_greg_symbols
[i
]->n_gregs
,
3797 sizeof (all_greg_symbols
[i
]->greg_fixes
[0]), cmp_greg_symbol_fixes
);
3799 if (real_reg_section
!= NULL
)
3803 /* FIXME: Pass error state gracefully. */
3804 if (bfd_get_section_flags (stdoutput
, real_reg_section
) & SEC_HAS_CONTENTS
)
3805 as_fatal (_("register section has contents\n"));
3807 /* Really remove the section. */
3808 for (secpp
= &stdoutput
->sections
;
3809 *secpp
!= real_reg_section
;
3810 secpp
= &(*secpp
)->next
)
3812 bfd_section_list_remove (stdoutput
, secpp
);
3813 --stdoutput
->section_count
;
3818 /* Provide an expression for a built-in name provided when-used.
3819 Either a symbol that is a handler; living in 0x10*[1..8] and having
3820 name [DVWIOUZX]_Handler, or a mmixal built-in symbol.
3822 If the name isn't a built-in name and parsed into *EXPP, return zero. */
3825 mmix_parse_predefined_name (name
, expP
)
3830 char *handler_charp
;
3831 const char handler_chars
[] = "DVWIOUZX";
3834 if (! predefined_syms
)
3837 canon_name
= tc_canonicalize_symbol_name (name
);
3839 if (canon_name
[1] == '_'
3840 && strcmp (canon_name
+ 2, "Handler") == 0
3841 && (handler_charp
= strchr (handler_chars
, *canon_name
)) != NULL
)
3843 /* If the symbol doesn't exist, provide one relative to the .text
3846 FIXME: We should provide separate sections, mapped in the linker
3848 symp
= symbol_find (name
);
3850 symp
= symbol_new (name
, text_section
,
3851 0x10 * (handler_charp
+ 1 - handler_chars
),
3852 &zero_address_frag
);
3856 /* These symbols appear when referenced; needed for
3857 mmixal-compatible programs. */
3864 } predefined_abs_syms
[] =
3866 {"Data_Segment", (valueT
) 0x20 << 56},
3867 {"Pool_Segment", (valueT
) 0x40 << 56},
3868 {"Stack_Segment", (valueT
) 0x60 << 56},
3876 {"BinaryReadWrite", 4},
3899 /* If it's already in the symbol table, we shouldn't do anything. */
3900 symp
= symbol_find (name
);
3905 i
< sizeof (predefined_abs_syms
) / sizeof (predefined_abs_syms
[0]);
3907 if (strcmp (canon_name
, predefined_abs_syms
[i
].name
) == 0)
3909 symbol_table_insert (symbol_new (predefined_abs_syms
[i
].name
,
3911 predefined_abs_syms
[i
].val
,
3912 &zero_address_frag
));
3914 /* Let gas find the symbol we just created, through its
3919 /* Not one of those symbols. Let gas handle it. */
3923 expP
->X_op
= O_symbol
;
3924 expP
->X_add_number
= 0;
3925 expP
->X_add_symbol
= symp
;
3926 expP
->X_op_symbol
= NULL
;
3931 /* Just check that we don't have a BSPEC/ESPEC pair active when changing
3932 sections "normally", and get knowledge about alignment from the new
3936 mmix_md_elf_section_change_hook ()
3939 as_bad (_("section change from within a BSPEC/ESPEC pair is not supported"));
3941 last_alignment
= bfd_get_section_alignment (now_seg
->owner
, now_seg
);
3945 /* The LOC worker. This is like s_org, but we have to support changing
3950 int ignore ATTRIBUTE_UNUSED
;
3958 /* Must not have a BSPEC in progress. */
3961 as_bad (_("directive LOC from within a BSPEC/ESPEC pair is not supported"));
3965 section
= expression (&exp
);
3967 if (exp
.X_op
== O_illegal
3968 || exp
.X_op
== O_absent
3969 || exp
.X_op
== O_big
3970 || section
== undefined_section
)
3972 as_bad (_("invalid LOC expression"));
3976 if (section
== absolute_section
)
3978 /* Translate a constant into a suitable section. */
3980 if (exp
.X_add_number
< ((offsetT
) 0x20 << 56))
3982 /* Lower than Data_Segment - assume it's .text. */
3983 section
= text_section
;
3985 /* Save the lowest seen location, so we can pass on this
3986 information to the linker. We don't actually org to this
3987 location here, we just pass on information to the linker so
3988 it can put the code there for us. */
3990 /* If there was already a loc (that has to be set lower than
3991 this one), we org at (this - lower). There's an implicit
3992 "LOC 0" before any entered code. FIXME: handled by spurious
3993 settings of text_has_contents. */
3994 if (exp
.X_add_number
< 0
3995 || exp
.X_add_number
< (offsetT
) lowest_text_loc
)
3997 as_bad (_("LOC expression stepping backwards is not supported"));
3998 exp
.X_op
= O_absent
;
4002 if (text_has_contents
&& lowest_text_loc
== (bfd_vma
) -1)
4003 lowest_text_loc
= 0;
4005 if (lowest_text_loc
== (bfd_vma
) -1)
4007 lowest_text_loc
= exp
.X_add_number
;
4009 /* We want only to change the section, not set an offset. */
4010 exp
.X_op
= O_absent
;
4013 exp
.X_add_number
-= lowest_text_loc
;
4018 /* Do the same for the .data section. */
4019 section
= data_section
;
4021 if (exp
.X_add_number
< (offsetT
) lowest_data_loc
)
4023 as_bad (_("LOC expression stepping backwards is not supported"));
4024 exp
.X_op
= O_absent
;
4028 if (data_has_contents
&& lowest_data_loc
== (bfd_vma
) -1)
4029 lowest_data_loc
= (bfd_vma
) 0x20 << 56;
4031 if (lowest_data_loc
== (bfd_vma
) -1)
4033 lowest_data_loc
= exp
.X_add_number
;
4035 /* We want only to change the section, not set an offset. */
4036 exp
.X_op
= O_absent
;
4039 exp
.X_add_number
-= lowest_data_loc
;
4044 if (section
!= now_seg
)
4046 obj_elf_section_change_hook ();
4047 subseg_set (section
, 0);
4049 /* Call our section change hooks using the official hook. */
4050 md_elf_section_change_hook ();
4053 if (exp
.X_op
!= O_absent
)
4055 if (exp
.X_op
!= O_constant
&& exp
.X_op
!= O_symbol
)
4057 /* Handle complex expressions. */
4058 sym
= make_expr_symbol (&exp
);
4063 sym
= exp
.X_add_symbol
;
4064 off
= exp
.X_add_number
;
4067 p
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, sym
, off
, (char *) 0);
4071 mmix_handle_rest_of_empty_line ();
4074 /* The BYTE worker. We have to support sequences of mixed "strings",
4075 numbers and other constant "first-pass" reducible expressions separated
4084 if (now_seg
== text_section
)
4085 text_has_contents
= 1;
4086 else if (now_seg
== data_section
)
4087 data_has_contents
= 1;
4092 switch (*input_line_pointer
)
4095 ++input_line_pointer
;
4096 start
= input_line_pointer
;
4097 while (is_a_char (c
= next_char_of_string ()))
4099 FRAG_APPEND_1_CHAR (c
);
4102 if (input_line_pointer
[-1] != '\"')
4104 /* We will only get here in rare cases involving #NO_APP,
4105 where the unterminated string is not recognized by the
4106 preformatting pass. */
4107 as_bad (_("unterminated string"));
4108 mmix_discard_rest_of_line ();
4116 segT expseg
= expression (&exp
);
4118 /* We have to allow special register names as constant numbers. */
4119 if ((expseg
!= absolute_section
&& expseg
!= reg_section
)
4120 || (exp
.X_op
!= O_constant
4121 && (exp
.X_op
!= O_register
4122 || exp
.X_add_number
<= 255)))
4124 as_bad (_("BYTE expression not a pure number"));
4125 mmix_discard_rest_of_line ();
4128 else if ((exp
.X_add_number
> 255 && exp
.X_op
!= O_register
)
4129 || exp
.X_add_number
< 0)
4131 /* Note that mmixal does not allow negative numbers in
4132 BYTE sequences, so neither should we. */
4133 as_bad (_("BYTE expression not in the range 0..255"));
4134 mmix_discard_rest_of_line ();
4138 FRAG_APPEND_1_CHAR (exp
.X_add_number
);
4144 c
= *input_line_pointer
++;
4148 input_line_pointer
--;
4150 if (mmix_gnu_syntax
)
4151 demand_empty_rest_of_line ();
4154 mmix_discard_rest_of_line ();
4155 /* Do like demand_empty_rest_of_line and step over the end-of-line
4157 input_line_pointer
++;
4160 /* Make sure we align for the next instruction. */
4164 /* Like cons_worker, but we have to ignore "naked comments", not barf on
4165 them. Implements WYDE, TETRA and OCTA. We're a little bit more
4166 lenient than mmix_byte but FIXME: they should eventually merge. */
4175 /* If we don't have any contents, then it's ok to have a specified start
4176 address that is not a multiple of the max data size. We will then
4177 align it as necessary when we get here. Otherwise, it's a fatal sin. */
4178 if (now_seg
== text_section
)
4180 if (lowest_text_loc
!= (bfd_vma
) -1
4181 && (lowest_text_loc
& (nbytes
- 1)) != 0)
4183 if (text_has_contents
)
4184 as_bad (_("data item with alignment larger than location"));
4185 else if (want_unaligned
)
4186 as_bad (_("unaligned data at an absolute location is not supported"));
4188 lowest_text_loc
&= ~((bfd_vma
) nbytes
- 1);
4189 lowest_text_loc
+= (bfd_vma
) nbytes
;
4192 text_has_contents
= 1;
4194 else if (now_seg
== data_section
)
4196 if (lowest_data_loc
!= (bfd_vma
) -1
4197 && (lowest_data_loc
& (nbytes
- 1)) != 0)
4199 if (data_has_contents
)
4200 as_bad (_("data item with alignment larger than location"));
4201 else if (want_unaligned
)
4202 as_bad (_("unaligned data at an absolute location is not supported"));
4204 lowest_data_loc
&= ~((bfd_vma
) nbytes
- 1);
4205 lowest_data_loc
+= (bfd_vma
) nbytes
;
4208 data_has_contents
= 1;
4211 /* Always align these unless asked not to (valid for the current pseudo). */
4212 if (! want_unaligned
)
4214 last_alignment
= nbytes
== 2 ? 1 : (nbytes
== 4 ? 2 : 3);
4215 frag_align (last_alignment
, 0, 0);
4216 record_alignment (now_seg
, last_alignment
);
4219 /* For mmixal compatibility, a label for an instruction (and emitting
4220 pseudo) refers to the _aligned_ address. So we have to emit the
4222 if (current_fb_label
>= 0)
4223 colon (fb_label_name (current_fb_label
, 1));
4224 else if (pending_label
!= NULL
)
4226 colon (pending_label
);
4227 pending_label
= NULL
;
4232 if (is_end_of_line
[(unsigned int) *input_line_pointer
])
4234 /* Default to zero if the expression was absent. */
4236 exp
.X_op
= O_constant
;
4237 exp
.X_add_number
= 0;
4239 exp
.X_add_symbol
= NULL
;
4240 exp
.X_op_symbol
= NULL
;
4241 emit_expr (&exp
, (unsigned int) nbytes
);
4248 switch (*input_line_pointer
)
4250 /* We support strings here too; each character takes up nbytes
4253 ++input_line_pointer
;
4254 start
= input_line_pointer
;
4255 while (is_a_char (c
= next_char_of_string ()))
4257 exp
.X_op
= O_constant
;
4258 exp
.X_add_number
= c
;
4260 emit_expr (&exp
, (unsigned int) nbytes
);
4263 if (input_line_pointer
[-1] != '\"')
4265 /* We will only get here in rare cases involving #NO_APP,
4266 where the unterminated string is not recognized by the
4267 preformatting pass. */
4268 as_bad (_("unterminated string"));
4269 mmix_discard_rest_of_line ();
4277 emit_expr (&exp
, (unsigned int) nbytes
);
4283 while (*input_line_pointer
++ == ',');
4285 input_line_pointer
--; /* Put terminator back into stream. */
4287 mmix_handle_rest_of_empty_line ();
4289 /* We don't need to step up the counter for the current_fb_label here;
4290 that's handled by the caller. */
4293 /* The md_do_align worker. At present, we just record an alignment to
4294 nullify the automatic alignment we do for WYDE, TETRA and OCTA, as gcc
4295 does not use the unaligned macros when attribute packed is used.
4296 Arguably this is a GCC bug. */
4299 mmix_md_do_align (n
, fill
, len
, max
)
4301 char *fill ATTRIBUTE_UNUSED
;
4302 int len ATTRIBUTE_UNUSED
;
4303 int max ATTRIBUTE_UNUSED
;
4306 want_unaligned
= n
== 0;