1 /* tc-mmix.c -- Assembler for Don Knuth's MMIX.
2 Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
3 Free Software Foundation.
5 This file is part of GAS, the GNU Assembler.
7 GAS is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
12 GAS is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GAS; see the file COPYING. If not, write to
19 the Free Software Foundation, 51 Franklin Street - Fifth Floor,
20 Boston, MA 02110-1301, USA. */
22 /* Knuth's assembler mmixal does not provide a relocatable format; mmo is
23 to be considered a final link-format. In the final link, we make mmo,
24 but for relocatable files, we use ELF.
26 One goal is to provide a superset of what mmixal does, including
27 compatible syntax, but the main purpose is to serve GCC. */
34 #include "opcode/mmix.h"
35 #include "safe-ctype.h"
36 #include "dwarf2dbg.h"
39 /* Something to describe what we need to do with a fixup before output,
40 for example assert something of what it became or make a relocation. */
42 enum mmix_fixup_action
46 mmix_fixup_register_or_adjust_for_byte
49 static int get_spec_regno (char *);
50 static int get_operands (int, char *, expressionS
*);
51 static int get_putget_operands (struct mmix_opcode
*, char *, expressionS
*);
52 static void s_prefix (int);
53 static void s_greg (int);
54 static void s_loc (int);
55 static void s_bspec (int);
56 static void s_espec (int);
57 static void mmix_s_local (int);
58 static void mmix_greg_internal (char *);
59 static void mmix_set_geta_branch_offset (char *, offsetT
);
60 static void mmix_set_jmp_offset (char *, offsetT
);
61 static void mmix_fill_nops (char *, int);
62 static int cmp_greg_symbol_fixes (const void *, const void *);
63 static int cmp_greg_val_greg_symbol_fixes (const void *, const void *);
64 static void mmix_handle_rest_of_empty_line (void);
65 static void mmix_discard_rest_of_line (void);
66 static void mmix_byte (void);
67 static void mmix_cons (int);
69 /* Continue the tradition of symbols.c; use control characters to enforce
70 magic. These are used when replacing e.g. 8F and 8B so we can handle
71 such labels correctly with the common parser hooks. */
72 #define MAGIC_FB_BACKWARD_CHAR '\003'
73 #define MAGIC_FB_FORWARD_CHAR '\004'
75 /* Copy the location of a frag to a fix. */
76 #define COPY_FR_WHERE_TO_FX(FRAG, FIX) \
79 (FIX)->fx_file = (FRAG)->fr_file; \
80 (FIX)->fx_line = (FRAG)->fr_line; \
84 const char *md_shortopts
= "x";
85 static int current_fb_label
= -1;
86 static char *pending_label
= NULL
;
88 static bfd_vma lowest_text_loc
= (bfd_vma
) -1;
89 static int text_has_contents
= 0;
91 /* The alignment of the previous instruction, and a boolean for whether we
92 want to avoid aligning the next WYDE, TETRA, OCTA or insn. */
93 static int last_alignment
= 0;
94 static int want_unaligned
= 0;
96 static bfd_vma lowest_data_loc
= (bfd_vma
) -1;
97 static int data_has_contents
= 0;
99 /* The fragS of the instruction being assembled. Only valid from within
101 fragS
*mmix_opcode_frag
= NULL
;
103 /* Raw GREGs as appearing in input. These may be fewer than the number
105 static int n_of_raw_gregs
= 0;
110 } mmix_raw_gregs
[MAX_GREGS
];
112 /* Fixups for all unique GREG registers. We store the fixups here in
113 md_convert_frag, then we use the array to convert
114 BFD_RELOC_MMIX_BASE_PLUS_OFFSET fixups in tc_gen_reloc. The index is
115 just a running number and is not supposed to be correlated to a
117 static fixS
*mmix_gregs
[MAX_GREGS
];
118 static int n_of_cooked_gregs
= 0;
120 /* Pointing to the register section we use for output. */
121 static asection
*real_reg_section
;
123 /* For each symbol; unknown or section symbol, we keep a list of GREG
124 definitions sorted on increasing offset. It seems no use keeping count
125 to allocate less room than the maximum number of gregs when we've found
126 one for a section or symbol. */
127 struct mmix_symbol_gregs
130 struct mmix_symbol_greg_fixes
134 /* A signed type, since we may have GREGs pointing slightly before the
135 contents of a section. */
137 } greg_fixes
[MAX_GREGS
];
140 /* Should read insert a colon on something that starts in column 0 on
142 static int label_without_colon_this_line
= 1;
144 /* Should we automatically expand instructions into multiple insns in
145 order to generate working code? */
146 static int expand_op
= 1;
148 /* Should we warn when expanding operands? FIXME: test-cases for when -x
150 static int warn_on_expansion
= 1;
152 /* Should we merge non-zero GREG register definitions? */
153 static int merge_gregs
= 1;
155 /* Should we pass on undefined BFD_RELOC_MMIX_BASE_PLUS_OFFSET relocs
156 (missing suitable GREG definitions) to the linker? */
157 static int allocate_undefined_gregs_in_linker
= 0;
159 /* Should we emit built-in symbols? */
160 static int predefined_syms
= 1;
162 /* Should we allow anything but the listed special register name
163 (e.g. equated symbols)? */
164 static int equated_spec_regs
= 1;
166 /* Do we require standard GNU syntax? */
167 int mmix_gnu_syntax
= 0;
169 /* Do we globalize all symbols? */
170 int mmix_globalize_symbols
= 0;
172 /* When expanding insns, do we want to expand PUSHJ as a call to a stub
173 (or else as a series of insns)? */
176 /* Do we know that the next semicolon is at the end of the operands field
177 (in mmixal mode; constant 1 in GNU mode)? */
178 int mmix_next_semicolon_is_eoln
= 1;
180 /* Do we have a BSPEC in progress? */
181 static int doing_bspec
= 0;
182 static char *bspec_file
;
183 static unsigned int bspec_line
;
185 struct option md_longopts
[] =
187 #define OPTION_RELAX (OPTION_MD_BASE)
188 #define OPTION_NOEXPAND (OPTION_RELAX + 1)
189 #define OPTION_NOMERGEGREG (OPTION_NOEXPAND + 1)
190 #define OPTION_NOSYMS (OPTION_NOMERGEGREG + 1)
191 #define OPTION_GNU_SYNTAX (OPTION_NOSYMS + 1)
192 #define OPTION_GLOBALIZE_SYMBOLS (OPTION_GNU_SYNTAX + 1)
193 #define OPTION_FIXED_SPEC_REGS (OPTION_GLOBALIZE_SYMBOLS + 1)
194 #define OPTION_LINKER_ALLOCATED_GREGS (OPTION_FIXED_SPEC_REGS + 1)
195 #define OPTION_NOPUSHJSTUBS (OPTION_LINKER_ALLOCATED_GREGS + 1)
196 {"linkrelax", no_argument
, NULL
, OPTION_RELAX
},
197 {"no-expand", no_argument
, NULL
, OPTION_NOEXPAND
},
198 {"no-merge-gregs", no_argument
, NULL
, OPTION_NOMERGEGREG
},
199 {"no-predefined-syms", no_argument
, NULL
, OPTION_NOSYMS
},
200 {"gnu-syntax", no_argument
, NULL
, OPTION_GNU_SYNTAX
},
201 {"globalize-symbols", no_argument
, NULL
, OPTION_GLOBALIZE_SYMBOLS
},
202 {"fixed-special-register-names", no_argument
, NULL
,
203 OPTION_FIXED_SPEC_REGS
},
204 {"linker-allocated-gregs", no_argument
, NULL
,
205 OPTION_LINKER_ALLOCATED_GREGS
},
206 {"no-pushj-stubs", no_argument
, NULL
, OPTION_NOPUSHJSTUBS
},
207 {"no-stubs", no_argument
, NULL
, OPTION_NOPUSHJSTUBS
},
208 {NULL
, no_argument
, NULL
, 0}
211 size_t md_longopts_size
= sizeof (md_longopts
);
213 static struct hash_control
*mmix_opcode_hash
;
215 /* We use these when implementing the PREFIX pseudo. */
216 char *mmix_current_prefix
;
217 struct obstack mmix_sym_obstack
;
220 /* For MMIX, we encode the relax_substateT:s (in e.g. fr_substate) as one
221 bit length, and the relax-type shifted on top of that. There seems to
222 be no point in making the relaxation more fine-grained; the linker does
223 that better and we might interfere by changing non-optimal relaxations
224 into other insns that cannot be relaxed as easily.
226 Groups for MMIX relaxing:
229 extra length: zero or three insns.
232 extra length: zero or five insns.
235 extra length: zero or four insns.
236 Special handling to deal with transition to PUSHJSTUB.
239 extra length: zero or four insns.
242 special handling, allocates a named global register unless another
243 is within reach for all uses.
246 special handling (mostly) for external references; assumes the
247 linker will generate a stub if target is no longer than 256k from
248 the end of the section plus max size of previous stubs. Zero or
251 #define STATE_GETA (1)
252 #define STATE_BCC (2)
253 #define STATE_PUSHJ (3)
254 #define STATE_JMP (4)
255 #define STATE_GREG (5)
256 #define STATE_PUSHJSTUB (6)
258 /* No fine-grainedness here. */
259 #define STATE_LENGTH_MASK (1)
261 #define STATE_ZERO (0)
262 #define STATE_MAX (1)
264 /* More descriptive name for convenience. */
265 /* FIXME: We should start on something different, not MAX. */
266 #define STATE_UNDF STATE_MAX
268 /* FIXME: For GREG, we must have other definitions; UNDF == MAX isn't
269 appropriate; we need it the other way round. This value together with
270 fragP->tc_frag_data shows what state the frag is in: tc_frag_data
271 non-NULL means 0, NULL means 8 bytes. */
272 #define STATE_GREG_UNDF ENCODE_RELAX (STATE_GREG, STATE_ZERO)
273 #define STATE_GREG_DEF ENCODE_RELAX (STATE_GREG, STATE_MAX)
275 /* These displacements are relative to the address following the opcode
276 word of the instruction. The catch-all states have zero for "reach"
277 and "next" entries. */
279 #define GETA_0F (65536 * 4 - 8)
280 #define GETA_0B (-65536 * 4 - 4)
282 #define GETA_MAX_LEN 4 * 4
286 #define BCC_0F GETA_0F
287 #define BCC_0B GETA_0B
289 #define BCC_MAX_LEN 6 * 4
290 #define BCC_5F GETA_3F
291 #define BCC_5B GETA_3B
293 #define PUSHJ_0F GETA_0F
294 #define PUSHJ_0B GETA_0B
296 #define PUSHJ_MAX_LEN 5 * 4
297 #define PUSHJ_4F GETA_3F
298 #define PUSHJ_4B GETA_3B
300 /* We'll very rarely have sections longer than LONG_MAX, but we'll make a
301 feeble attempt at getting 64-bit values. */
302 #define PUSHJSTUB_MAX ((offsetT) (((addressT) -1) >> 1))
303 #define PUSHJSTUB_MIN (-PUSHJSTUB_MAX - 1)
305 #define JMP_0F (65536 * 256 * 4 - 8)
306 #define JMP_0B (-65536 * 256 * 4 - 4)
308 #define JMP_MAX_LEN 5 * 4
312 #define RELAX_ENCODE_SHIFT 1
313 #define ENCODE_RELAX(what, length) (((what) << RELAX_ENCODE_SHIFT) + (length))
315 const relax_typeS mmix_relax_table
[] =
317 /* Error sentinel (0, 0). */
324 {GETA_0F
, GETA_0B
, 0, ENCODE_RELAX (STATE_GETA
, STATE_MAX
)},
328 GETA_MAX_LEN
- 4, 0},
331 {BCC_0F
, BCC_0B
, 0, ENCODE_RELAX (STATE_BCC
, STATE_MAX
)},
337 /* PUSHJ (3, 0). Next state is actually PUSHJSTUB (6, 0). */
338 {PUSHJ_0F
, PUSHJ_0B
, 0, ENCODE_RELAX (STATE_PUSHJSTUB
, STATE_ZERO
)},
342 PUSHJ_MAX_LEN
- 4, 0},
345 {JMP_0F
, JMP_0B
, 0, ENCODE_RELAX (STATE_JMP
, STATE_MAX
)},
351 /* GREG (5, 0), (5, 1), though the table entry isn't used. */
352 {0, 0, 0, 0}, {0, 0, 0, 0},
354 /* PUSHJSTUB (6, 0). PUSHJ (3, 0) uses the range, so we set it to infinite. */
355 {PUSHJSTUB_MAX
, PUSHJSTUB_MIN
,
356 0, ENCODE_RELAX (STATE_PUSHJ
, STATE_MAX
)},
357 /* PUSHJSTUB (6, 1) isn't used. */
358 {0, 0, PUSHJ_MAX_LEN
, 0}
361 const pseudo_typeS md_pseudo_table
[] =
363 /* Support " .greg sym,expr" syntax. */
366 /* Support " .bspec expr" syntax. */
367 {"bspec", s_bspec
, 1},
369 /* Support " .espec" syntax. */
370 {"espec", s_espec
, 1},
372 /* Support " .local $45" syntax. */
373 {"local", mmix_s_local
, 1},
378 const char mmix_comment_chars
[] = "%!";
380 /* A ':' is a valid symbol character in mmixal. It's the prefix
381 delimiter, but other than that, it works like a symbol character,
382 except that we strip one off at the beginning of symbols. An '@' is a
383 symbol by itself (for the current location); space around it must not
385 const char mmix_symbol_chars
[] = ":@";
387 const char line_comment_chars
[] = "*#";
389 const char line_separator_chars
[] = ";";
391 const char mmix_exp_chars
[] = "eE";
393 const char mmix_flt_chars
[] = "rf";
396 /* Fill in the offset-related part of GETA or Bcc. */
399 mmix_set_geta_branch_offset (char *opcodep
, offsetT value
)
408 md_number_to_chars (opcodep
+ 2, value
, 2);
411 /* Fill in the offset-related part of JMP. */
414 mmix_set_jmp_offset (char *opcodep
, offsetT value
)
418 value
+= 65536 * 256 * 4;
423 md_number_to_chars (opcodep
+ 1, value
, 3);
426 /* Fill in NOP:s for the expanded part of GETA/JMP/Bcc/PUSHJ. */
429 mmix_fill_nops (char *opcodep
, int n
)
433 for (i
= 0; i
< n
; i
++)
434 md_number_to_chars (opcodep
+ i
* 4, SWYM_INSN_BYTE
<< 24, 4);
437 /* See macro md_parse_name in tc-mmix.h. */
440 mmix_current_location (void (*fn
) (expressionS
*), expressionS
*exp
)
447 /* Get up to three operands, filling them into the exp array.
448 General idea and code stolen from the tic80 port. */
451 get_operands (int max_operands
, char *s
, expressionS
*exp
)
457 while (nextchar
== ',')
459 /* Skip leading whitespace */
460 while (*p
== ' ' || *p
== '\t')
463 /* Check to see if we have any operands left to parse */
464 if (*p
== 0 || *p
== '\n' || *p
== '\r')
468 else if (numexp
== max_operands
)
470 /* This seems more sane than saying "too many operands". We'll
471 get here only if the trailing trash starts with a comma. */
472 as_bad (_("invalid operands"));
473 mmix_discard_rest_of_line ();
477 /* Begin operand parsing at the current scan point. */
479 input_line_pointer
= p
;
480 expression (&exp
[numexp
]);
482 if (exp
[numexp
].X_op
== O_illegal
)
484 as_bad (_("invalid operands"));
486 else if (exp
[numexp
].X_op
== O_absent
)
488 as_bad (_("missing operand"));
492 p
= input_line_pointer
;
494 /* Skip leading whitespace */
495 while (*p
== ' ' || *p
== '\t')
500 /* If we allow "naked" comments, ignore the rest of the line. */
503 mmix_handle_rest_of_empty_line ();
504 input_line_pointer
--;
507 /* Mark the end of the valid operands with an illegal expression. */
508 exp
[numexp
].X_op
= O_illegal
;
513 /* Get the value of a special register, or -1 if the name does not match
514 one. NAME is a null-terminated string. */
517 get_spec_regno (char *name
)
527 /* Well, it's a short array and we'll most often just match the first
529 for (i
= 0; mmix_spec_regs
[i
].name
!= NULL
; i
++)
530 if (strcmp (name
, mmix_spec_regs
[i
].name
) == 0)
531 return mmix_spec_regs
[i
].number
;
536 /* For GET and PUT, parse the register names "manually", so we don't use
539 get_putget_operands (struct mmix_opcode
*insn
, char *operands
,
542 expressionS
*expp_reg
;
543 expressionS
*expp_sreg
;
545 char *sregend
= operands
;
550 /* Skip leading whitespace */
551 while (*p
== ' ' || *p
== '\t')
554 input_line_pointer
= p
;
556 /* Initialize both possible operands to error state, in case we never
558 exp
[0].X_op
= O_illegal
;
559 exp
[1].X_op
= O_illegal
;
561 if (insn
->operands
== mmix_operands_get
)
566 expression (expp_reg
);
568 p
= input_line_pointer
;
570 /* Skip whitespace */
571 while (*p
== ' ' || *p
== '\t')
578 /* Skip whitespace */
579 while (*p
== ' ' || *p
== '\t')
582 input_line_pointer
= sregp
;
583 c
= get_symbol_end ();
584 sregend
= input_line_pointer
;
593 c
= get_symbol_end ();
594 sregend
= p
= input_line_pointer
;
597 /* Skip whitespace */
598 while (*p
== ' ' || *p
== '\t')
605 /* Skip whitespace */
606 while (*p
== ' ' || *p
== '\t')
609 input_line_pointer
= p
;
610 expression (expp_reg
);
615 regno
= get_spec_regno (sregp
);
618 /* Let the caller issue errors; we've made sure the operands are
620 if (expp_reg
->X_op
!= O_illegal
621 && expp_reg
->X_op
!= O_absent
624 expp_sreg
->X_op
= O_register
;
625 expp_sreg
->X_add_number
= regno
+ 256;
631 /* Handle MMIX-specific option. */
634 md_parse_option (int c
, char *arg ATTRIBUTE_UNUSED
)
639 warn_on_expansion
= 0;
640 allocate_undefined_gregs_in_linker
= 1;
647 case OPTION_NOEXPAND
:
651 case OPTION_NOMERGEGREG
:
657 equated_spec_regs
= 0;
660 case OPTION_GNU_SYNTAX
:
662 label_without_colon_this_line
= 0;
665 case OPTION_GLOBALIZE_SYMBOLS
:
666 mmix_globalize_symbols
= 1;
669 case OPTION_FIXED_SPEC_REGS
:
670 equated_spec_regs
= 0;
673 case OPTION_LINKER_ALLOCATED_GREGS
:
674 allocate_undefined_gregs_in_linker
= 1;
677 case OPTION_NOPUSHJSTUBS
:
688 /* Display MMIX-specific help text. */
691 md_show_usage (FILE * stream
)
693 fprintf (stream
, _(" MMIX-specific command line options:\n"));
694 fprintf (stream
, _("\
695 -fixed-special-register-names\n\
696 Allow only the original special register names.\n"));
697 fprintf (stream
, _("\
698 -globalize-symbols Make all symbols global.\n"));
699 fprintf (stream
, _("\
700 -gnu-syntax Turn off mmixal syntax compatibility.\n"));
701 fprintf (stream
, _("\
702 -relax Create linker relaxable code.\n"));
703 fprintf (stream
, _("\
704 -no-predefined-syms Do not provide mmixal built-in constants.\n\
705 Implies -fixed-special-register-names.\n"));
706 fprintf (stream
, _("\
707 -no-expand Do not expand GETA, branches, PUSHJ or JUMP\n\
708 into multiple instructions.\n"));
709 fprintf (stream
, _("\
710 -no-merge-gregs Do not merge GREG definitions with nearby values.\n"));
711 fprintf (stream
, _("\
712 -linker-allocated-gregs If there's no suitable GREG definition for the\
713 operands of an instruction, let the linker resolve.\n"));
714 fprintf (stream
, _("\
715 -x Do not warn when an operand to GETA, a branch,\n\
716 PUSHJ or JUMP is not known to be within range.\n\
717 The linker will catch any errors. Implies\n\
718 -linker-allocated-gregs."));
721 /* Step to end of line, but don't step over the end of the line. */
724 mmix_discard_rest_of_line (void)
726 while (*input_line_pointer
727 && (! is_end_of_line
[(unsigned char) *input_line_pointer
]
728 || TC_EOL_IN_INSN (input_line_pointer
)))
729 input_line_pointer
++;
732 /* Act as demand_empty_rest_of_line if we're in strict GNU syntax mode,
733 otherwise just ignore the rest of the line (and skip the end-of-line
737 mmix_handle_rest_of_empty_line (void)
740 demand_empty_rest_of_line ();
743 mmix_discard_rest_of_line ();
744 input_line_pointer
++;
748 /* Initialize GAS MMIX specifics. */
754 const struct mmix_opcode
*opcode
;
756 /* We assume nobody will use this, so don't allocate any room. */
757 obstack_begin (&mmix_sym_obstack
, 0);
759 /* This will break the day the "lex" thingy changes. For now, it's the
760 only way to make ':' part of a name, and a name beginner. */
761 lex_type
[':'] = (LEX_NAME
| LEX_BEGIN_NAME
);
763 mmix_opcode_hash
= hash_new ();
766 = bfd_make_section_old_way (stdoutput
, MMIX_REG_SECTION_NAME
);
768 for (opcode
= mmix_opcodes
; opcode
->name
; opcode
++)
769 hash_insert (mmix_opcode_hash
, opcode
->name
, (char *) opcode
);
771 /* We always insert the ordinary registers 0..255 as registers. */
772 for (i
= 0; i
< 256; i
++)
776 /* Alternatively, we could diddle with '$' and the following number,
777 but keeping the registers as symbols helps keep parsing simple. */
778 sprintf (buf
, "$%d", i
);
779 symbol_table_insert (symbol_new (buf
, reg_section
, i
,
780 &zero_address_frag
));
783 /* Insert mmixal built-in names if allowed. */
786 for (i
= 0; mmix_spec_regs
[i
].name
!= NULL
; i
++)
787 symbol_table_insert (symbol_new (mmix_spec_regs
[i
].name
,
789 mmix_spec_regs
[i
].number
+ 256,
790 &zero_address_frag
));
792 /* FIXME: Perhaps these should be recognized as specials; as field
793 names for those instructions. */
794 symbol_table_insert (symbol_new ("ROUND_CURRENT", reg_section
, 512,
795 &zero_address_frag
));
796 symbol_table_insert (symbol_new ("ROUND_OFF", reg_section
, 512 + 1,
797 &zero_address_frag
));
798 symbol_table_insert (symbol_new ("ROUND_UP", reg_section
, 512 + 2,
799 &zero_address_frag
));
800 symbol_table_insert (symbol_new ("ROUND_DOWN", reg_section
, 512 + 3,
801 &zero_address_frag
));
802 symbol_table_insert (symbol_new ("ROUND_NEAR", reg_section
, 512 + 4,
803 &zero_address_frag
));
807 /* Assemble one insn in STR. */
810 md_assemble (char *str
)
812 char *operands
= str
;
813 char modified_char
= 0;
814 struct mmix_opcode
*instruction
;
815 fragS
*opc_fragP
= NULL
;
816 int max_operands
= 3;
818 /* Note that the struct frag member fr_literal in frags.h is char[], so
819 I have to make this a plain char *. */
820 /* unsigned */ char *opcodep
= NULL
;
825 /* Move to end of opcode. */
827 is_part_of_name (*operands
);
831 if (ISSPACE (*operands
))
833 modified_char
= *operands
;
837 instruction
= (struct mmix_opcode
*) hash_find (mmix_opcode_hash
, str
);
838 if (instruction
== NULL
)
840 as_bad (_("unknown opcode: `%s'"), str
);
842 /* Avoid "unhandled label" errors. */
843 pending_label
= NULL
;
847 /* Put back the character after the opcode. */
848 if (modified_char
!= 0)
849 operands
[-1] = modified_char
;
851 input_line_pointer
= operands
;
853 /* Is this a mmixal pseudodirective? */
854 if (instruction
->type
== mmix_type_pseudo
)
856 /* For mmixal compatibility, a label for an instruction (and
857 emitting pseudo) refers to the _aligned_ address. We emit the
858 label here for the pseudos that don't handle it themselves. When
859 having an fb-label, emit it here, and increment the counter after
861 switch (instruction
->operands
)
863 case mmix_operands_loc
:
864 case mmix_operands_byte
:
865 case mmix_operands_prefix
:
866 case mmix_operands_local
:
867 case mmix_operands_bspec
:
868 case mmix_operands_espec
:
869 if (current_fb_label
>= 0)
870 colon (fb_label_name (current_fb_label
, 1));
871 else if (pending_label
!= NULL
)
873 colon (pending_label
);
874 pending_label
= NULL
;
882 /* Some of the pseudos emit contents, others don't. Set a
883 contents-emitted flag when we emit something into .text */
884 switch (instruction
->operands
)
886 case mmix_operands_loc
:
891 case mmix_operands_byte
:
896 case mmix_operands_wyde
:
901 case mmix_operands_tetra
:
906 case mmix_operands_octa
:
911 case mmix_operands_prefix
:
916 case mmix_operands_local
:
921 case mmix_operands_bspec
:
926 case mmix_operands_espec
:
932 BAD_CASE (instruction
->operands
);
935 /* These are all working like the pseudo functions in read.c:s_...,
936 in that they step over the end-of-line marker at the end of the
937 line. We don't want that here. */
938 input_line_pointer
--;
940 /* Step up the fb-label counter if there was a definition on this
942 if (current_fb_label
>= 0)
944 fb_label_instance_inc (current_fb_label
);
945 current_fb_label
= -1;
948 /* Reset any don't-align-next-datum request, unless this was a LOC
950 if (instruction
->operands
!= mmix_operands_loc
)
956 /* Not a pseudo; we *will* emit contents. */
957 if (now_seg
== data_section
)
959 if (lowest_data_loc
!= (bfd_vma
) -1 && (lowest_data_loc
& 3) != 0)
961 if (data_has_contents
)
962 as_bad (_("specified location wasn't TETRA-aligned"));
963 else if (want_unaligned
)
964 as_bad (_("unaligned data at an absolute location is not supported"));
966 lowest_data_loc
&= ~(bfd_vma
) 3;
967 lowest_data_loc
+= 4;
970 data_has_contents
= 1;
972 else if (now_seg
== text_section
)
974 if (lowest_text_loc
!= (bfd_vma
) -1 && (lowest_text_loc
& 3) != 0)
976 if (text_has_contents
)
977 as_bad (_("specified location wasn't TETRA-aligned"));
978 else if (want_unaligned
)
979 as_bad (_("unaligned data at an absolute location is not supported"));
981 lowest_text_loc
&= ~(bfd_vma
) 3;
982 lowest_text_loc
+= 4;
985 text_has_contents
= 1;
988 /* After a sequence of BYTEs or WYDEs, we need to get to instruction
989 alignment. For other pseudos, a ".p2align 2" is supposed to be
990 inserted by the user. */
991 if (last_alignment
< 2 && ! want_unaligned
)
993 frag_align (2, 0, 0);
994 record_alignment (now_seg
, 2);
998 /* Reset any don't-align-next-datum request. */
1001 /* For mmixal compatibility, a label for an instruction (and emitting
1002 pseudo) refers to the _aligned_ address. So we have to emit the
1004 if (pending_label
!= NULL
)
1006 colon (pending_label
);
1007 pending_label
= NULL
;
1010 /* We assume that mmix_opcodes keeps having unique mnemonics for each
1011 opcode, so we don't have to iterate over more than one opcode; if the
1012 syntax does not match, then there's a syntax error. */
1014 /* Operands have little or no context and are all comma-separated; it is
1015 easier to parse each expression first. */
1016 switch (instruction
->operands
)
1018 case mmix_operands_reg_yz
:
1019 case mmix_operands_pop
:
1020 case mmix_operands_regaddr
:
1021 case mmix_operands_pushj
:
1022 case mmix_operands_get
:
1023 case mmix_operands_put
:
1024 case mmix_operands_set
:
1025 case mmix_operands_save
:
1026 case mmix_operands_unsave
:
1030 case mmix_operands_sync
:
1031 case mmix_operands_jmp
:
1032 case mmix_operands_resume
:
1036 /* The original 3 is fine for the rest. */
1041 /* If this is GET or PUT, and we don't do allow those names to be
1042 equated, we need to parse the names ourselves, so we don't pick up a
1043 user label instead of the special register. */
1044 if (! equated_spec_regs
1045 && (instruction
->operands
== mmix_operands_get
1046 || instruction
->operands
== mmix_operands_put
))
1047 n_operands
= get_putget_operands (instruction
, operands
, exp
);
1049 n_operands
= get_operands (max_operands
, operands
, exp
);
1051 /* If there's a fb-label on the current line, set that label. This must
1052 be done *after* evaluating expressions of operands, since neither a
1053 "1B" nor a "1F" refers to "1H" on the same line. */
1054 if (current_fb_label
>= 0)
1056 fb_label_instance_inc (current_fb_label
);
1057 colon (fb_label_name (current_fb_label
, 0));
1058 current_fb_label
= -1;
1061 /* We also assume that the length of the instruction is at least 4, the
1062 size of an unexpanded instruction. We need a self-contained frag
1063 since we want the relocation to point to the instruction, not the
1066 opcodep
= frag_more (4);
1067 mmix_opcode_frag
= opc_fragP
= frag_now
;
1068 frag_now
->fr_opcode
= opcodep
;
1070 /* Mark start of insn for DWARF2 debug features. */
1071 if (OUTPUT_FLAVOR
== bfd_target_elf_flavour
)
1072 dwarf2_emit_insn (4);
1074 md_number_to_chars (opcodep
, instruction
->match
, 4);
1076 switch (instruction
->operands
)
1078 case mmix_operands_jmp
:
1079 if (n_operands
== 0 && ! mmix_gnu_syntax
)
1080 /* Zeros are in place - nothing needs to be done when we have no
1084 /* Add a frag for a JMP relaxation; we need room for max four
1085 extra instructions. We don't do any work around here to check if
1086 we can determine the offset right away. */
1087 if (n_operands
!= 1 || exp
[0].X_op
== O_register
)
1089 as_bad (_("invalid operand to opcode %s: `%s'"),
1090 instruction
->name
, operands
);
1095 frag_var (rs_machine_dependent
, 4 * 4, 0,
1096 ENCODE_RELAX (STATE_JMP
, STATE_UNDF
),
1097 exp
[0].X_add_symbol
,
1098 exp
[0].X_add_number
,
1101 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
, 4,
1102 exp
+ 0, 1, BFD_RELOC_MMIX_ADDR27
);
1105 case mmix_operands_pushj
:
1106 /* We take care of PUSHJ in full here. */
1108 || ((exp
[0].X_op
== O_constant
|| exp
[0].X_op
== O_register
)
1109 && (exp
[0].X_add_number
> 255 || exp
[0].X_add_number
< 0)))
1111 as_bad (_("invalid operands to opcode %s: `%s'"),
1112 instruction
->name
, operands
);
1116 if (exp
[0].X_op
== O_register
|| exp
[0].X_op
== O_constant
)
1117 opcodep
[1] = exp
[0].X_add_number
;
1119 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 1,
1120 1, exp
+ 0, 0, BFD_RELOC_MMIX_REG_OR_BYTE
);
1123 frag_var (rs_machine_dependent
, PUSHJ_MAX_LEN
- 4, 0,
1124 ENCODE_RELAX (STATE_PUSHJ
, STATE_UNDF
),
1125 exp
[1].X_add_symbol
,
1126 exp
[1].X_add_number
,
1129 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
, 4,
1130 exp
+ 1, 1, BFD_RELOC_MMIX_ADDR19
);
1133 case mmix_operands_regaddr
:
1134 /* GETA/branch: Add a frag for relaxation. We don't do any work
1135 around here to check if we can determine the offset right away. */
1136 if (n_operands
!= 2 || exp
[1].X_op
== O_register
)
1138 as_bad (_("invalid operands to opcode %s: `%s'"),
1139 instruction
->name
, operands
);
1144 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
, 4,
1145 exp
+ 1, 1, BFD_RELOC_MMIX_ADDR19
);
1146 else if (instruction
->type
== mmix_type_condbranch
)
1147 frag_var (rs_machine_dependent
, BCC_MAX_LEN
- 4, 0,
1148 ENCODE_RELAX (STATE_BCC
, STATE_UNDF
),
1149 exp
[1].X_add_symbol
,
1150 exp
[1].X_add_number
,
1153 frag_var (rs_machine_dependent
, GETA_MAX_LEN
- 4, 0,
1154 ENCODE_RELAX (STATE_GETA
, STATE_UNDF
),
1155 exp
[1].X_add_symbol
,
1156 exp
[1].X_add_number
,
1164 switch (instruction
->operands
)
1166 case mmix_operands_regs
:
1167 /* We check the number of operands here, since we're in a
1168 FALLTHROUGH sequence in the next switch. */
1169 if (n_operands
!= 3 || exp
[2].X_op
== O_constant
)
1171 as_bad (_("invalid operands to opcode %s: `%s'"),
1172 instruction
->name
, operands
);
1176 case mmix_operands_regs_z
:
1177 if (n_operands
!= 3)
1179 as_bad (_("invalid operands to opcode %s: `%s'"),
1180 instruction
->name
, operands
);
1184 case mmix_operands_reg_yz
:
1185 case mmix_operands_roundregs_z
:
1186 case mmix_operands_roundregs
:
1187 case mmix_operands_regs_z_opt
:
1188 case mmix_operands_neg
:
1189 case mmix_operands_regaddr
:
1190 case mmix_operands_get
:
1191 case mmix_operands_set
:
1192 case mmix_operands_save
:
1194 || (exp
[0].X_op
== O_register
&& exp
[0].X_add_number
> 255))
1196 as_bad (_("invalid operands to opcode %s: `%s'"),
1197 instruction
->name
, operands
);
1201 if (exp
[0].X_op
== O_register
)
1202 opcodep
[1] = exp
[0].X_add_number
;
1204 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 1,
1205 1, exp
+ 0, 0, BFD_RELOC_MMIX_REG
);
1212 /* A corresponding once-over for those who take an 8-bit constant as
1213 their first operand. */
1214 switch (instruction
->operands
)
1216 case mmix_operands_pushgo
:
1217 /* PUSHGO: X is a constant, but can be expressed as a register.
1218 We handle X here and use the common machinery of T,X,3,$ for
1219 the rest of the operands. */
1221 || ((exp
[0].X_op
== O_constant
|| exp
[0].X_op
== O_register
)
1222 && (exp
[0].X_add_number
> 255 || exp
[0].X_add_number
< 0)))
1224 as_bad (_("invalid operands to opcode %s: `%s'"),
1225 instruction
->name
, operands
);
1228 else if (exp
[0].X_op
== O_constant
|| exp
[0].X_op
== O_register
)
1229 opcodep
[1] = exp
[0].X_add_number
;
1231 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 1,
1232 1, exp
+ 0, 0, BFD_RELOC_MMIX_REG_OR_BYTE
);
1235 case mmix_operands_pop
:
1236 if ((n_operands
== 0 || n_operands
== 1) && ! mmix_gnu_syntax
)
1239 case mmix_operands_x_regs_z
:
1241 || (exp
[0].X_op
== O_constant
1242 && (exp
[0].X_add_number
> 255
1243 || exp
[0].X_add_number
< 0)))
1245 as_bad (_("invalid operands to opcode %s: `%s'"),
1246 instruction
->name
, operands
);
1250 if (exp
[0].X_op
== O_constant
)
1251 opcodep
[1] = exp
[0].X_add_number
;
1253 /* FIXME: This doesn't bring us unsignedness checking. */
1254 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 1,
1255 1, exp
+ 0, 0, BFD_RELOC_8
);
1260 /* Handle the rest. */
1261 switch (instruction
->operands
)
1263 case mmix_operands_set
:
1264 /* SET: Either two registers, "$X,$Y", with Z field as zero, or
1265 "$X,YZ", meaning change the opcode to SETL. */
1267 || (exp
[1].X_op
== O_constant
1268 && (exp
[1].X_add_number
> 0xffff || exp
[1].X_add_number
< 0)))
1270 as_bad (_("invalid operands to opcode %s: `%s'"),
1271 instruction
->name
, operands
);
1275 if (exp
[1].X_op
== O_constant
)
1277 /* There's an ambiguity with "SET $0,Y" when Y isn't defined
1278 yet. To keep things simple, we assume that Y is then a
1279 register, and only change the opcode if Y is defined at this
1282 There's no compatibility problem with mmixal, since it emits
1283 errors if the field is not defined at this point. */
1284 md_number_to_chars (opcodep
, SETL_INSN_BYTE
, 1);
1286 opcodep
[2] = (exp
[1].X_add_number
>> 8) & 255;
1287 opcodep
[3] = exp
[1].X_add_number
& 255;
1291 case mmix_operands_x_regs_z
:
1292 /* SYNCD: "X,$Y,$Z|Z". */
1294 case mmix_operands_regs
:
1295 /* Three registers, $X,$Y,$Z. */
1297 case mmix_operands_regs_z
:
1298 /* Operands "$X,$Y,$Z|Z", number of arguments checked above. */
1300 case mmix_operands_pushgo
:
1301 /* Operands "$X|X,$Y,$Z|Z", optional Z. */
1303 case mmix_operands_regs_z_opt
:
1304 /* Operands "$X,$Y,$Z|Z", with $Z|Z being optional, default 0. Any
1305 operands not completely decided yet are postponed to later in
1306 assembly (but not until link-time yet). */
1308 if ((n_operands
!= 2 && n_operands
!= 3)
1309 || (exp
[1].X_op
== O_register
&& exp
[1].X_add_number
> 255)
1311 && ((exp
[2].X_op
== O_register
1312 && exp
[2].X_add_number
> 255
1314 || (exp
[2].X_op
== O_constant
1315 && (exp
[2].X_add_number
> 255
1316 || exp
[2].X_add_number
< 0)))))
1318 as_bad (_("invalid operands to opcode %s: `%s'"),
1319 instruction
->name
, operands
);
1323 if (n_operands
== 2)
1327 /* The last operand is immediate whenever we see just two
1329 opcodep
[0] |= IMM_OFFSET_BIT
;
1331 /* Now, we could either have an implied "0" as the Z operand, or
1332 it could be the constant of a "base address plus offset". It
1333 depends on whether it is allowed; only memory operations, as
1334 signified by instruction->type and "T" and "X" operand types,
1335 and it depends on whether we find a register in the second
1337 if (exp
[1].X_op
== O_register
&& exp
[1].X_add_number
<= 255)
1339 /* A zero then; all done. */
1340 opcodep
[2] = exp
[1].X_add_number
;
1344 /* Not known as a register. Is base address plus offset
1345 allowed, or can we assume that it is a register anyway? */
1346 if ((instruction
->operands
!= mmix_operands_regs_z_opt
1347 && instruction
->operands
!= mmix_operands_x_regs_z
1348 && instruction
->operands
!= mmix_operands_pushgo
)
1349 || (instruction
->type
!= mmix_type_memaccess_octa
1350 && instruction
->type
!= mmix_type_memaccess_tetra
1351 && instruction
->type
!= mmix_type_memaccess_wyde
1352 && instruction
->type
!= mmix_type_memaccess_byte
1353 && instruction
->type
!= mmix_type_memaccess_block
1354 && instruction
->type
!= mmix_type_jsr
1355 && instruction
->type
!= mmix_type_branch
))
1357 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 2,
1358 1, exp
+ 1, 0, BFD_RELOC_MMIX_REG
);
1362 /* To avoid getting a NULL add_symbol for constants and then
1363 catching a SEGV in write_relocs since it doesn't handle
1364 constants well for relocs other than PC-relative, we need to
1365 pass expressions as symbols and use fix_new, not fix_new_exp. */
1366 sym
= make_expr_symbol (exp
+ 1);
1368 /* Mark the symbol as being OK for a reloc. */
1369 symbol_get_bfdsym (sym
)->flags
|= BSF_KEEP
;
1371 /* Now we know it can be a "base address plus offset". Add
1372 proper fixup types so we can handle this later, when we've
1373 parsed everything. */
1374 fix_new (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 2,
1375 8, sym
, 0, 0, BFD_RELOC_MMIX_BASE_PLUS_OFFSET
);
1379 if (exp
[1].X_op
== O_register
)
1380 opcodep
[2] = exp
[1].X_add_number
;
1382 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 2,
1383 1, exp
+ 1, 0, BFD_RELOC_MMIX_REG
);
1385 /* In mmixal compatibility mode, we allow special registers as
1386 constants for the Z operand. They have 256 added to their
1387 register numbers, so the right thing will happen if we just treat
1388 those as constants. */
1389 if (exp
[2].X_op
== O_register
&& exp
[2].X_add_number
<= 255)
1390 opcodep
[3] = exp
[2].X_add_number
;
1391 else if (exp
[2].X_op
== O_constant
1392 || (exp
[2].X_op
== O_register
&& exp
[2].X_add_number
> 255))
1394 opcodep
[3] = exp
[2].X_add_number
;
1395 opcodep
[0] |= IMM_OFFSET_BIT
;
1398 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 3,
1400 (instruction
->operands
== mmix_operands_set
1401 || instruction
->operands
== mmix_operands_regs
)
1402 ? BFD_RELOC_MMIX_REG
: BFD_RELOC_MMIX_REG_OR_BYTE
);
1405 case mmix_operands_pop
:
1406 /* POP, one eight and one 16-bit operand. */
1407 if (n_operands
== 0 && ! mmix_gnu_syntax
)
1409 if (n_operands
== 1 && ! mmix_gnu_syntax
)
1410 goto a_single_24_bit_number_operand
;
1412 case mmix_operands_reg_yz
:
1413 /* A register and a 16-bit unsigned number. */
1415 || exp
[1].X_op
== O_register
1416 || (exp
[1].X_op
== O_constant
1417 && (exp
[1].X_add_number
> 0xffff || exp
[1].X_add_number
< 0)))
1419 as_bad (_("invalid operands to opcode %s: `%s'"),
1420 instruction
->name
, operands
);
1424 if (exp
[1].X_op
== O_constant
)
1426 opcodep
[2] = (exp
[1].X_add_number
>> 8) & 255;
1427 opcodep
[3] = exp
[1].X_add_number
& 255;
1430 /* FIXME: This doesn't bring us unsignedness checking. */
1431 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 2,
1432 2, exp
+ 1, 0, BFD_RELOC_16
);
1435 case mmix_operands_jmp
:
1436 /* A JMP. Everything is already done. */
1439 case mmix_operands_roundregs
:
1440 /* Two registers with optional rounding mode or constant in between. */
1441 if ((n_operands
== 3 && exp
[2].X_op
== O_constant
)
1442 || (n_operands
== 2 && exp
[1].X_op
== O_constant
))
1444 as_bad (_("invalid operands to opcode %s: `%s'"),
1445 instruction
->name
, operands
);
1449 case mmix_operands_roundregs_z
:
1450 /* Like FLOT, "$X,ROUND_MODE,$Z|Z", but the rounding mode is
1451 optional and can be the corresponding constant. */
1453 /* Which exp index holds the second operand (not the rounding
1455 int op2no
= n_operands
- 1;
1457 if ((n_operands
!= 2 && n_operands
!= 3)
1458 || ((exp
[op2no
].X_op
== O_register
1459 && exp
[op2no
].X_add_number
> 255)
1460 || (exp
[op2no
].X_op
== O_constant
1461 && (exp
[op2no
].X_add_number
> 255
1462 || exp
[op2no
].X_add_number
< 0)))
1464 /* We don't allow for the rounding mode to be deferred; it
1465 must be determined in the "first pass". It cannot be a
1466 symbol equated to a rounding mode, but defined after
1468 && ((exp
[1].X_op
== O_register
1469 && exp
[1].X_add_number
< 512)
1470 || (exp
[1].X_op
== O_constant
1471 && exp
[1].X_add_number
< 0
1472 && exp
[1].X_add_number
> 4)
1473 || (exp
[1].X_op
!= O_register
1474 && exp
[1].X_op
!= O_constant
))))
1476 as_bad (_("invalid operands to opcode %s: `%s'"),
1477 instruction
->name
, operands
);
1481 /* Add rounding mode if present. */
1482 if (n_operands
== 3)
1483 opcodep
[2] = exp
[1].X_add_number
& 255;
1485 if (exp
[op2no
].X_op
== O_register
)
1486 opcodep
[3] = exp
[op2no
].X_add_number
;
1487 else if (exp
[op2no
].X_op
== O_constant
)
1489 opcodep
[3] = exp
[op2no
].X_add_number
;
1490 opcodep
[0] |= IMM_OFFSET_BIT
;
1493 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 3,
1495 instruction
->operands
== mmix_operands_roundregs
1496 ? BFD_RELOC_MMIX_REG
1497 : BFD_RELOC_MMIX_REG_OR_BYTE
);
1501 case mmix_operands_sync
:
1502 a_single_24_bit_number_operand
:
1504 || exp
[0].X_op
== O_register
1505 || (exp
[0].X_op
== O_constant
1506 && (exp
[0].X_add_number
> 0xffffff || exp
[0].X_add_number
< 0)))
1508 as_bad (_("invalid operands to opcode %s: `%s'"),
1509 instruction
->name
, operands
);
1513 if (exp
[0].X_op
== O_constant
)
1515 opcodep
[1] = (exp
[0].X_add_number
>> 16) & 255;
1516 opcodep
[2] = (exp
[0].X_add_number
>> 8) & 255;
1517 opcodep
[3] = exp
[0].X_add_number
& 255;
1520 /* FIXME: This doesn't bring us unsignedness checking. */
1521 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 1,
1522 3, exp
+ 0, 0, BFD_RELOC_24
);
1525 case mmix_operands_neg
:
1526 /* Operands "$X,Y,$Z|Z"; NEG or NEGU. Y is optional, 0 is default. */
1528 if ((n_operands
!= 3 && n_operands
!= 2)
1529 || (n_operands
== 3 && exp
[1].X_op
== O_register
)
1530 || ((exp
[1].X_op
== O_constant
|| exp
[1].X_op
== O_register
)
1531 && (exp
[1].X_add_number
> 255 || exp
[1].X_add_number
< 0))
1533 && ((exp
[2].X_op
== O_register
&& exp
[2].X_add_number
> 255)
1534 || (exp
[2].X_op
== O_constant
1535 && (exp
[2].X_add_number
> 255
1536 || exp
[2].X_add_number
< 0)))))
1538 as_bad (_("invalid operands to opcode %s: `%s'"),
1539 instruction
->name
, operands
);
1543 if (n_operands
== 2)
1545 if (exp
[1].X_op
== O_register
)
1546 opcodep
[3] = exp
[1].X_add_number
;
1547 else if (exp
[1].X_op
== O_constant
)
1549 opcodep
[3] = exp
[1].X_add_number
;
1550 opcodep
[0] |= IMM_OFFSET_BIT
;
1553 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 3,
1554 1, exp
+ 1, 0, BFD_RELOC_MMIX_REG_OR_BYTE
);
1558 if (exp
[1].X_op
== O_constant
)
1559 opcodep
[2] = exp
[1].X_add_number
;
1561 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 2,
1562 1, exp
+ 1, 0, BFD_RELOC_8
);
1564 if (exp
[2].X_op
== O_register
)
1565 opcodep
[3] = exp
[2].X_add_number
;
1566 else if (exp
[2].X_op
== O_constant
)
1568 opcodep
[3] = exp
[2].X_add_number
;
1569 opcodep
[0] |= IMM_OFFSET_BIT
;
1572 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 3,
1573 1, exp
+ 2, 0, BFD_RELOC_MMIX_REG_OR_BYTE
);
1576 case mmix_operands_regaddr
:
1577 /* A GETA/branch-type. */
1580 case mmix_operands_get
:
1581 /* "$X,spec_reg"; GET.
1582 Like with rounding modes, we demand that the special register or
1583 symbol is already defined when we get here at the point of use. */
1585 || (exp
[1].X_op
== O_register
1586 && (exp
[1].X_add_number
< 256 || exp
[1].X_add_number
>= 512))
1587 || (exp
[1].X_op
== O_constant
1588 && (exp
[1].X_add_number
< 0 || exp
[1].X_add_number
> 256))
1589 || (exp
[1].X_op
!= O_constant
&& exp
[1].X_op
!= O_register
))
1591 as_bad (_("invalid operands to opcode %s: `%s'"),
1592 instruction
->name
, operands
);
1596 opcodep
[3] = exp
[1].X_add_number
- 256;
1599 case mmix_operands_put
:
1600 /* "spec_reg,$Z|Z"; PUT. */
1602 || (exp
[0].X_op
== O_register
1603 && (exp
[0].X_add_number
< 256 || exp
[0].X_add_number
>= 512))
1604 || (exp
[0].X_op
== O_constant
1605 && (exp
[0].X_add_number
< 0 || exp
[0].X_add_number
> 256))
1606 || (exp
[0].X_op
!= O_constant
&& exp
[0].X_op
!= O_register
))
1608 as_bad (_("invalid operands to opcode %s: `%s'"),
1609 instruction
->name
, operands
);
1613 opcodep
[1] = exp
[0].X_add_number
- 256;
1615 /* Note that the Y field is zero. */
1617 if (exp
[1].X_op
== O_register
)
1618 opcodep
[3] = exp
[1].X_add_number
;
1619 else if (exp
[1].X_op
== O_constant
)
1621 opcodep
[3] = exp
[1].X_add_number
;
1622 opcodep
[0] |= IMM_OFFSET_BIT
;
1625 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 3,
1626 1, exp
+ 1, 0, BFD_RELOC_MMIX_REG_OR_BYTE
);
1629 case mmix_operands_save
:
1632 || exp
[1].X_op
!= O_constant
1633 || exp
[1].X_add_number
!= 0)
1635 as_bad (_("invalid operands to opcode %s: `%s'"),
1636 instruction
->name
, operands
);
1641 case mmix_operands_unsave
:
1642 if (n_operands
< 2 && ! mmix_gnu_syntax
)
1644 if (n_operands
== 1)
1646 if (exp
[0].X_op
== O_register
)
1647 opcodep
[3] = exp
[0].X_add_number
;
1649 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 3,
1650 1, exp
, 0, BFD_RELOC_MMIX_REG
);
1655 /* "0,$Z"; UNSAVE. */
1657 || exp
[0].X_op
!= O_constant
1658 || exp
[0].X_add_number
!= 0
1659 || exp
[1].X_op
== O_constant
1660 || (exp
[1].X_op
== O_register
1661 && exp
[1].X_add_number
> 255))
1663 as_bad (_("invalid operands to opcode %s: `%s'"),
1664 instruction
->name
, operands
);
1668 if (exp
[1].X_op
== O_register
)
1669 opcodep
[3] = exp
[1].X_add_number
;
1671 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 3,
1672 1, exp
+ 1, 0, BFD_RELOC_MMIX_REG
);
1675 case mmix_operands_xyz_opt
:
1676 /* SWYM, TRIP, TRAP: zero, one, two or three operands. It's
1677 unspecified whether operands are registers or constants, but
1678 when we find register syntax, we require operands to be literal and
1680 if (n_operands
== 0 && ! mmix_gnu_syntax
)
1681 /* Zeros are in place - nothing needs to be done for zero
1682 operands. We don't allow this in GNU syntax mode, because it
1683 was believed that the risk of missing to supply an operand is
1684 higher than the benefit of not having to specify a zero. */
1686 else if (n_operands
== 1 && exp
[0].X_op
!= O_register
)
1688 if (exp
[0].X_op
== O_constant
)
1690 if (exp
[0].X_add_number
> 255*256*256
1691 || exp
[0].X_add_number
< 0)
1693 as_bad (_("invalid operands to opcode %s: `%s'"),
1694 instruction
->name
, operands
);
1699 opcodep
[1] = (exp
[0].X_add_number
>> 16) & 255;
1700 opcodep
[2] = (exp
[0].X_add_number
>> 8) & 255;
1701 opcodep
[3] = exp
[0].X_add_number
& 255;
1705 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 1,
1706 3, exp
, 0, BFD_RELOC_24
);
1708 else if (n_operands
== 2
1709 && exp
[0].X_op
!= O_register
1710 && exp
[1].X_op
!= O_register
)
1714 if (exp
[0].X_op
== O_constant
)
1716 if (exp
[0].X_add_number
> 255
1717 || exp
[0].X_add_number
< 0)
1719 as_bad (_("invalid operands to opcode %s: `%s'"),
1720 instruction
->name
, operands
);
1724 opcodep
[1] = exp
[0].X_add_number
& 255;
1727 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 1,
1728 1, exp
, 0, BFD_RELOC_8
);
1730 if (exp
[1].X_op
== O_constant
)
1732 if (exp
[1].X_add_number
> 255*256
1733 || exp
[1].X_add_number
< 0)
1735 as_bad (_("invalid operands to opcode %s: `%s'"),
1736 instruction
->name
, operands
);
1741 opcodep
[2] = (exp
[1].X_add_number
>> 8) & 255;
1742 opcodep
[3] = exp
[1].X_add_number
& 255;
1746 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 2,
1747 2, exp
+ 1, 0, BFD_RELOC_16
);
1749 else if (n_operands
== 3
1750 && exp
[0].X_op
!= O_register
1751 && exp
[1].X_op
!= O_register
1752 && exp
[2].X_op
!= O_register
)
1754 /* Three operands. */
1756 if (exp
[0].X_op
== O_constant
)
1758 if (exp
[0].X_add_number
> 255
1759 || exp
[0].X_add_number
< 0)
1761 as_bad (_("invalid operands to opcode %s: `%s'"),
1762 instruction
->name
, operands
);
1766 opcodep
[1] = exp
[0].X_add_number
& 255;
1769 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 1,
1770 1, exp
, 0, BFD_RELOC_8
);
1772 if (exp
[1].X_op
== O_constant
)
1774 if (exp
[1].X_add_number
> 255
1775 || exp
[1].X_add_number
< 0)
1777 as_bad (_("invalid operands to opcode %s: `%s'"),
1778 instruction
->name
, operands
);
1782 opcodep
[2] = exp
[1].X_add_number
& 255;
1785 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 2,
1786 1, exp
+ 1, 0, BFD_RELOC_8
);
1788 if (exp
[2].X_op
== O_constant
)
1790 if (exp
[2].X_add_number
> 255
1791 || exp
[2].X_add_number
< 0)
1793 as_bad (_("invalid operands to opcode %s: `%s'"),
1794 instruction
->name
, operands
);
1798 opcodep
[3] = exp
[2].X_add_number
& 255;
1801 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 3,
1802 1, exp
+ 2, 0, BFD_RELOC_8
);
1806 /* We can't get here for other cases. */
1807 gas_assert (n_operands
<= 3);
1809 /* The meaning of operands to TRIP and TRAP is not defined (and
1810 SWYM operands aren't enforced in mmixal, so let's avoid
1811 that). We add combinations not handled above here as we find
1812 them and as they're reported. */
1813 if (n_operands
== 3)
1815 /* Don't require non-register operands. Always generate
1816 fixups, so we don't have to copy lots of code and create
1817 maintenance problems. TRIP is supposed to be a rare
1818 instruction, so the overhead should not matter. We
1819 aren't allowed to fix_new_exp for an expression which is
1820 an O_register at this point, however.
1822 Don't use BFD_RELOC_MMIX_REG_OR_BYTE as that modifies
1823 the insn for a register in the Z field and we want
1825 if (exp
[0].X_op
== O_register
)
1826 opcodep
[1] = exp
[0].X_add_number
;
1828 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 1,
1829 1, exp
, 0, BFD_RELOC_8
);
1830 if (exp
[1].X_op
== O_register
)
1831 opcodep
[2] = exp
[1].X_add_number
;
1833 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 2,
1834 1, exp
+ 1, 0, BFD_RELOC_8
);
1835 if (exp
[2].X_op
== O_register
)
1836 opcodep
[3] = exp
[2].X_add_number
;
1838 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 3,
1839 1, exp
+ 2, 0, BFD_RELOC_8
);
1841 else if (n_operands
== 2)
1843 if (exp
[0].X_op
== O_register
)
1844 opcodep
[1] = exp
[0].X_add_number
;
1846 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 1,
1847 1, exp
, 0, BFD_RELOC_8
);
1848 if (exp
[1].X_op
== O_register
)
1849 opcodep
[3] = exp
[1].X_add_number
;
1851 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 2,
1852 2, exp
+ 1, 0, BFD_RELOC_16
);
1856 /* We can't get here for other cases. */
1857 gas_assert (n_operands
== 1 && exp
[0].X_op
== O_register
);
1859 opcodep
[3] = exp
[0].X_add_number
;
1864 case mmix_operands_resume
:
1865 if (n_operands
== 0 && ! mmix_gnu_syntax
)
1869 || exp
[0].X_op
== O_register
1870 || (exp
[0].X_op
== O_constant
1871 && (exp
[0].X_add_number
< 0
1872 || exp
[0].X_add_number
> 255)))
1874 as_bad (_("invalid operands to opcode %s: `%s'"),
1875 instruction
->name
, operands
);
1879 if (exp
[0].X_op
== O_constant
)
1880 opcodep
[3] = exp
[0].X_add_number
;
1882 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 3,
1883 1, exp
+ 0, 0, BFD_RELOC_8
);
1886 case mmix_operands_pushj
:
1887 /* All is done for PUSHJ already. */
1891 BAD_CASE (instruction
->operands
);
1895 /* For the benefit of insns that start with a digit, we assemble by way of
1896 tc_unrecognized_line too, through this function. */
1899 mmix_assemble_return_nonzero (char *str
)
1901 int last_error_count
= had_errors ();
1905 /* Normal instruction handling downcases, so we must too. */
1906 while (ISALNUM (*s2
))
1908 if (ISUPPER ((unsigned char) *s2
))
1909 *s2
= TOLOWER (*s2
);
1913 /* Cut the line for sake of the assembly. */
1914 for (s2
= str
; *s2
&& *s2
!= '\n'; s2
++)
1922 return had_errors () == last_error_count
;
1925 /* The PREFIX pseudo. */
1928 s_prefix (int unused ATTRIBUTE_UNUSED
)
1935 p
= input_line_pointer
;
1937 c
= get_symbol_end ();
1939 /* Reseting prefix? */
1940 if (*p
== ':' && p
[1] == 0)
1941 mmix_current_prefix
= NULL
;
1944 /* Put this prefix on the mmix symbols obstack. We could malloc and
1945 free it separately, but then we'd have to worry about that.
1946 People using up memory on prefixes have other problems. */
1947 obstack_grow (&mmix_sym_obstack
, p
, strlen (p
) + 1);
1948 p
= obstack_finish (&mmix_sym_obstack
);
1950 /* Accumulate prefixes, and strip a leading ':'. */
1951 if (mmix_current_prefix
!= NULL
|| *p
== ':')
1952 p
= mmix_prefix_name (p
);
1954 mmix_current_prefix
= p
;
1957 *input_line_pointer
= c
;
1959 mmix_handle_rest_of_empty_line ();
1962 /* We implement prefixes by using the tc_canonicalize_symbol_name hook,
1963 and store each prefixed name on a (separate) obstack. This means that
1964 the name is on the "notes" obstack in non-prefixed form and on the
1965 mmix_sym_obstack in prefixed form, but currently it is not worth
1966 rewriting the whole GAS symbol handling to improve "hooking" to avoid
1967 that. (It might be worth a rewrite for other reasons, though). */
1970 mmix_prefix_name (char *shortname
)
1972 if (*shortname
== ':')
1973 return shortname
+ 1;
1975 if (mmix_current_prefix
== NULL
)
1976 as_fatal (_("internal: mmix_prefix_name but empty prefix"));
1978 if (*shortname
== '$')
1981 obstack_grow (&mmix_sym_obstack
, mmix_current_prefix
,
1982 strlen (mmix_current_prefix
));
1983 obstack_grow (&mmix_sym_obstack
, shortname
, strlen (shortname
) + 1);
1984 return obstack_finish (&mmix_sym_obstack
);
1987 /* The GREG pseudo. At LABEL, we have the name of a symbol that we
1988 want to make a register symbol, and which should be initialized with
1989 the value in the expression at INPUT_LINE_POINTER (defaulting to 0).
1990 Either and (perhaps less meaningful) both may be missing. LABEL must
1991 be persistent, perhaps allocated on an obstack. */
1994 mmix_greg_internal (char *label
)
1996 expressionS
*expP
= &mmix_raw_gregs
[n_of_raw_gregs
].exp
;
1998 /* Don't set the section to register contents section before the
1999 expression has been parsed; it may refer to the current position. */
2002 /* FIXME: Check that no expression refers to the register contents
2003 section. May need to be done in elf64-mmix.c. */
2004 if (expP
->X_op
== O_absent
)
2006 /* Default to zero if the expression was absent. */
2007 expP
->X_op
= O_constant
;
2008 expP
->X_add_number
= 0;
2009 expP
->X_unsigned
= 0;
2010 expP
->X_add_symbol
= NULL
;
2011 expP
->X_op_symbol
= NULL
;
2014 /* We must handle prefixes here, as we save the labels and expressions
2015 to be output later. */
2016 mmix_raw_gregs
[n_of_raw_gregs
].label
2017 = mmix_current_prefix
== NULL
? label
: mmix_prefix_name (label
);
2019 if (n_of_raw_gregs
== MAX_GREGS
- 1)
2020 as_bad (_("too many GREG registers allocated (max %d)"), MAX_GREGS
);
2024 mmix_handle_rest_of_empty_line ();
2027 /* The ".greg label,expr" worker. */
2030 s_greg (int unused ATTRIBUTE_UNUSED
)
2034 p
= input_line_pointer
;
2036 /* This will skip over what can be a symbol and zero out the next
2037 character, which we assume is a ',' or other meaningful delimiter.
2038 What comes after that is the initializer expression for the
2040 c
= get_symbol_end ();
2042 if (! is_end_of_line
[(unsigned char) c
])
2043 input_line_pointer
++;
2047 /* The label must be persistent; it's not used until after all input
2049 obstack_grow (&mmix_sym_obstack
, p
, strlen (p
) + 1);
2050 mmix_greg_internal (obstack_finish (&mmix_sym_obstack
));
2053 mmix_greg_internal (NULL
);
2056 /* The "BSPEC expr" worker. */
2059 s_bspec (int unused ATTRIBUTE_UNUSED
)
2063 char secname
[sizeof (MMIX_OTHER_SPEC_SECTION_PREFIX
) + 20]
2064 = MMIX_OTHER_SPEC_SECTION_PREFIX
;
2068 /* Get a constant expression which we can evaluate *now*. Supporting
2069 more complex (though assembly-time computable) expressions is
2070 feasible but Too Much Work for something of unknown usefulness like
2072 expsec
= expression (&exp
);
2073 mmix_handle_rest_of_empty_line ();
2075 /* Check that we don't have another BSPEC in progress. */
2078 as_bad (_("BSPEC already active. Nesting is not supported."));
2082 if (exp
.X_op
!= O_constant
2083 || expsec
!= absolute_section
2084 || exp
.X_add_number
< 0
2085 || exp
.X_add_number
> 65535)
2087 as_bad (_("invalid BSPEC expression"));
2088 exp
.X_add_number
= 0;
2091 n
= (int) exp
.X_add_number
;
2093 sprintf (secname
+ strlen (MMIX_OTHER_SPEC_SECTION_PREFIX
), "%d", n
);
2094 sec
= bfd_get_section_by_name (stdoutput
, secname
);
2097 /* We need a non-volatile name as it will be stored in the section
2099 char *newsecname
= xstrdup (secname
);
2100 sec
= bfd_make_section (stdoutput
, newsecname
);
2103 as_fatal (_("can't create section %s"), newsecname
);
2105 if (!bfd_set_section_flags (stdoutput
, sec
,
2106 bfd_get_section_flags (stdoutput
, sec
)
2108 as_fatal (_("can't set section flags for section %s"), newsecname
);
2111 /* Tell ELF about the pending section change. */
2112 obj_elf_section_change_hook ();
2113 subseg_set (sec
, 0);
2115 /* Save position for missing ESPEC. */
2116 as_where (&bspec_file
, &bspec_line
);
2121 /* The "ESPEC" worker. */
2124 s_espec (int unused ATTRIBUTE_UNUSED
)
2126 /* First, check that we *do* have a BSPEC in progress. */
2129 as_bad (_("ESPEC without preceding BSPEC"));
2133 mmix_handle_rest_of_empty_line ();
2136 /* When we told ELF about the section change in s_bspec, it stored the
2137 previous section for us so we can get at it with the equivalent of a
2138 .previous pseudo. */
2139 obj_elf_previous (0);
2142 /* The " .local expr" and " local expr" worker. We make a BFD_MMIX_LOCAL
2143 relocation against the current position against the expression.
2144 Implementing this by means of contents in a section lost. */
2147 mmix_s_local (int unused ATTRIBUTE_UNUSED
)
2151 /* Don't set the section to register contents section before the
2152 expression has been parsed; it may refer to the current position in
2153 some contorted way. */
2156 if (exp
.X_op
== O_absent
)
2158 as_bad (_("missing local expression"));
2161 else if (exp
.X_op
== O_register
)
2163 /* fix_new_exp doesn't like O_register. Should be configurable.
2164 We're fine with a constant here, though. */
2165 exp
.X_op
= O_constant
;
2168 fix_new_exp (frag_now
, 0, 0, &exp
, 0, BFD_RELOC_MMIX_LOCAL
);
2169 mmix_handle_rest_of_empty_line ();
2172 /* Set fragP->fr_var to the initial guess of the size of a relaxable insn
2173 and return it. Sizes of other instructions are not known. This
2174 function may be called multiple times. */
2177 md_estimate_size_before_relax (fragS
*fragP
, segT segment
)
2181 #define HANDLE_RELAXABLE(state) \
2182 case ENCODE_RELAX (state, STATE_UNDF): \
2183 if (fragP->fr_symbol != NULL \
2184 && S_GET_SEGMENT (fragP->fr_symbol) == segment \
2185 && !S_IS_WEAK (fragP->fr_symbol)) \
2187 /* The symbol lies in the same segment - a relaxable case. */ \
2189 = ENCODE_RELAX (state, STATE_ZERO); \
2193 switch (fragP
->fr_subtype
)
2195 HANDLE_RELAXABLE (STATE_GETA
);
2196 HANDLE_RELAXABLE (STATE_BCC
);
2197 HANDLE_RELAXABLE (STATE_JMP
);
2199 case ENCODE_RELAX (STATE_PUSHJ
, STATE_UNDF
):
2200 if (fragP
->fr_symbol
!= NULL
2201 && S_GET_SEGMENT (fragP
->fr_symbol
) == segment
2202 && !S_IS_WEAK (fragP
->fr_symbol
))
2203 /* The symbol lies in the same segment - a relaxable case. */
2204 fragP
->fr_subtype
= ENCODE_RELAX (STATE_PUSHJ
, STATE_ZERO
);
2205 else if (pushj_stubs
)
2206 /* If we're to generate stubs, assume we can reach a stub after
2208 fragP
->fr_subtype
= ENCODE_RELAX (STATE_PUSHJSTUB
, STATE_ZERO
);
2210 case ENCODE_RELAX (STATE_PUSHJ
, STATE_ZERO
):
2211 case ENCODE_RELAX (STATE_PUSHJSTUB
, STATE_ZERO
):
2212 /* We need to distinguish different relaxation rounds. */
2213 seg_info (segment
)->tc_segment_info_data
.last_stubfrag
= fragP
;
2216 case ENCODE_RELAX (STATE_GETA
, STATE_ZERO
):
2217 case ENCODE_RELAX (STATE_BCC
, STATE_ZERO
):
2218 case ENCODE_RELAX (STATE_JMP
, STATE_ZERO
):
2219 /* When relaxing a section for the second time, we don't need to do
2220 anything except making sure that fr_var is set right. */
2223 case STATE_GREG_DEF
:
2224 length
= fragP
->tc_frag_data
!= NULL
? 0 : 8;
2225 fragP
->fr_var
= length
;
2227 /* Don't consult the relax_table; it isn't valid for this
2233 BAD_CASE (fragP
->fr_subtype
);
2236 length
= mmix_relax_table
[fragP
->fr_subtype
].rlx_length
;
2237 fragP
->fr_var
= length
;
2242 /* Turn a string in input_line_pointer into a floating point constant of type
2243 type, and store the appropriate bytes in *litP. The number of LITTLENUMS
2244 emitted is stored in *sizeP . An error message is returned, or NULL on
2248 md_atof (int type
, char *litP
, int *sizeP
)
2252 /* FIXME: Having 'f' in mmix_flt_chars (and here) makes it
2253 problematic to also have a forward reference in an expression.
2254 The testsuite wants it, and it's customary.
2255 We'll deal with the real problems when they come; we share the
2256 problem with most other ports. */
2257 return ieee_md_atof (type
, litP
, sizeP
, TRUE
);
2260 /* Convert variable-sized frags into one or more fixups. */
2263 md_convert_frag (bfd
*abfd ATTRIBUTE_UNUSED
, segT sec ATTRIBUTE_UNUSED
,
2266 /* Pointer to first byte in variable-sized part of the frag. */
2269 /* Pointer to first opcode byte in frag. */
2272 /* Size in bytes of variable-sized part of frag. */
2273 int var_part_size
= 0;
2275 /* This is part of *fragP. It contains all information about addresses
2276 and offsets to varying parts. */
2278 unsigned long var_part_offset
;
2280 /* This is the frag for the opcode. It, rather than fragP, must be used
2281 when emitting a frag for the opcode. */
2282 fragS
*opc_fragP
= fragP
->tc_frag_data
;
2285 /* Where, in file space, does addr point? */
2286 bfd_vma target_address
;
2287 bfd_vma opcode_address
;
2289 know (fragP
->fr_type
== rs_machine_dependent
);
2291 var_part_offset
= fragP
->fr_fix
;
2292 var_partp
= fragP
->fr_literal
+ var_part_offset
;
2293 opcodep
= fragP
->fr_opcode
;
2295 symbolP
= fragP
->fr_symbol
;
2298 = ((symbolP
? S_GET_VALUE (symbolP
) : 0) + fragP
->fr_offset
);
2300 /* The opcode that would be extended is the last four "fixed" bytes. */
2301 opcode_address
= fragP
->fr_address
+ fragP
->fr_fix
- 4;
2303 switch (fragP
->fr_subtype
)
2305 case ENCODE_RELAX (STATE_PUSHJSTUB
, STATE_ZERO
):
2306 /* Setting the unknown bits to 0 seems the most appropriate. */
2307 mmix_set_geta_branch_offset (opcodep
, 0);
2308 tmpfixP
= fix_new (opc_fragP
, opcodep
- opc_fragP
->fr_literal
, 8,
2309 fragP
->fr_symbol
, fragP
->fr_offset
, 1,
2310 BFD_RELOC_MMIX_PUSHJ_STUBBABLE
);
2311 COPY_FR_WHERE_TO_FX (fragP
, tmpfixP
);
2315 case ENCODE_RELAX (STATE_GETA
, STATE_ZERO
):
2316 case ENCODE_RELAX (STATE_BCC
, STATE_ZERO
):
2317 case ENCODE_RELAX (STATE_PUSHJ
, STATE_ZERO
):
2318 mmix_set_geta_branch_offset (opcodep
, target_address
- opcode_address
);
2322 = fix_new (opc_fragP
, opcodep
- opc_fragP
->fr_literal
, 4,
2323 fragP
->fr_symbol
, fragP
->fr_offset
, 1,
2324 BFD_RELOC_MMIX_ADDR19
);
2325 COPY_FR_WHERE_TO_FX (fragP
, tmpfixP
);
2330 case ENCODE_RELAX (STATE_JMP
, STATE_ZERO
):
2331 mmix_set_jmp_offset (opcodep
, target_address
- opcode_address
);
2335 = fix_new (opc_fragP
, opcodep
- opc_fragP
->fr_literal
, 4,
2336 fragP
->fr_symbol
, fragP
->fr_offset
, 1,
2337 BFD_RELOC_MMIX_ADDR27
);
2338 COPY_FR_WHERE_TO_FX (fragP
, tmpfixP
);
2343 case STATE_GREG_DEF
:
2344 if (fragP
->tc_frag_data
== NULL
)
2346 /* We must initialize data that's supposed to be "fixed up" to
2347 avoid emitting garbage, because md_apply_fix won't do
2348 anything for undefined symbols. */
2349 md_number_to_chars (var_partp
, 0, 8);
2351 = fix_new (fragP
, var_partp
- fragP
->fr_literal
, 8,
2352 fragP
->fr_symbol
, fragP
->fr_offset
, 0, BFD_RELOC_64
);
2353 COPY_FR_WHERE_TO_FX (fragP
, tmpfixP
);
2354 mmix_gregs
[n_of_cooked_gregs
++] = tmpfixP
;
2361 #define HANDLE_MAX_RELOC(state, reloc) \
2362 case ENCODE_RELAX (state, STATE_MAX): \
2364 = mmix_relax_table[ENCODE_RELAX (state, STATE_MAX)].rlx_length; \
2365 mmix_fill_nops (var_partp, var_part_size / 4); \
2366 if (warn_on_expansion) \
2367 as_warn_where (fragP->fr_file, fragP->fr_line, \
2368 _("operand out of range, instruction expanded")); \
2369 tmpfixP = fix_new (fragP, var_partp - fragP->fr_literal - 4, 8, \
2370 fragP->fr_symbol, fragP->fr_offset, 1, reloc); \
2371 COPY_FR_WHERE_TO_FX (fragP, tmpfixP); \
2374 HANDLE_MAX_RELOC (STATE_GETA
, BFD_RELOC_MMIX_GETA
);
2375 HANDLE_MAX_RELOC (STATE_BCC
, BFD_RELOC_MMIX_CBRANCH
);
2376 HANDLE_MAX_RELOC (STATE_PUSHJ
, BFD_RELOC_MMIX_PUSHJ
);
2377 HANDLE_MAX_RELOC (STATE_JMP
, BFD_RELOC_MMIX_JMP
);
2380 BAD_CASE (fragP
->fr_subtype
);
2384 fragP
->fr_fix
+= var_part_size
;
2388 /* Applies the desired value to the specified location.
2389 Also sets up addends for RELA type relocations.
2390 Stolen from tc-mcore.c.
2392 Note that this function isn't called when linkrelax != 0. */
2395 md_apply_fix (fixS
*fixP
, valueT
*valP
, segT segment
)
2397 char *buf
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
2398 /* Note: use offsetT because it is signed, valueT is unsigned. */
2399 offsetT val
= (offsetT
) * valP
;
2401 = (fixP
->fx_addsy
== NULL
2402 ? absolute_section
: S_GET_SEGMENT (fixP
->fx_addsy
));
2404 /* If the fix is relative to a symbol which is not defined, or, (if
2405 pcrel), not in the same segment as the fix, we cannot resolve it
2407 if (fixP
->fx_addsy
!= NULL
2408 && (! S_IS_DEFINED (fixP
->fx_addsy
)
2409 || S_IS_WEAK (fixP
->fx_addsy
)
2410 || (fixP
->fx_pcrel
&& symsec
!= segment
)
2411 || (! fixP
->fx_pcrel
2412 && symsec
!= absolute_section
2413 && ((fixP
->fx_r_type
!= BFD_RELOC_MMIX_REG
2414 && fixP
->fx_r_type
!= BFD_RELOC_MMIX_REG_OR_BYTE
)
2415 || symsec
!= reg_section
))))
2420 else if (fixP
->fx_r_type
== BFD_RELOC_MMIX_LOCAL
2421 || fixP
->fx_r_type
== BFD_RELOC_VTABLE_INHERIT
2422 || fixP
->fx_r_type
== BFD_RELOC_VTABLE_ENTRY
)
2424 /* These are never "fixed". */
2429 /* We assume every other relocation is "fixed". */
2432 switch (fixP
->fx_r_type
)
2439 case BFD_RELOC_64_PCREL
:
2440 case BFD_RELOC_32_PCREL
:
2441 case BFD_RELOC_24_PCREL
:
2442 case BFD_RELOC_16_PCREL
:
2443 case BFD_RELOC_8_PCREL
:
2444 md_number_to_chars (buf
, val
, fixP
->fx_size
);
2447 case BFD_RELOC_MMIX_ADDR19
:
2450 /* This shouldn't happen. */
2451 BAD_CASE (fixP
->fx_r_type
);
2455 case BFD_RELOC_MMIX_GETA
:
2456 case BFD_RELOC_MMIX_CBRANCH
:
2457 case BFD_RELOC_MMIX_PUSHJ
:
2458 case BFD_RELOC_MMIX_PUSHJ_STUBBABLE
:
2459 /* If this fixup is out of range, punt to the linker to emit an
2460 error. This should only happen with -no-expand. */
2461 if (val
< -(((offsetT
) 1 << 19)/2)
2462 || val
>= ((offsetT
) 1 << 19)/2 - 1
2465 if (warn_on_expansion
)
2466 as_warn_where (fixP
->fx_file
, fixP
->fx_line
,
2467 _("operand out of range"));
2471 mmix_set_geta_branch_offset (buf
, val
);
2474 case BFD_RELOC_MMIX_ADDR27
:
2477 /* This shouldn't happen. */
2478 BAD_CASE (fixP
->fx_r_type
);
2482 case BFD_RELOC_MMIX_JMP
:
2483 /* If this fixup is out of range, punt to the linker to emit an
2484 error. This should only happen with -no-expand. */
2485 if (val
< -(((offsetT
) 1 << 27)/2)
2486 || val
>= ((offsetT
) 1 << 27)/2 - 1
2489 if (warn_on_expansion
)
2490 as_warn_where (fixP
->fx_file
, fixP
->fx_line
,
2491 _("operand out of range"));
2495 mmix_set_jmp_offset (buf
, val
);
2498 case BFD_RELOC_MMIX_REG_OR_BYTE
:
2499 if (fixP
->fx_addsy
!= NULL
2500 && (S_GET_SEGMENT (fixP
->fx_addsy
) != reg_section
2501 || S_GET_VALUE (fixP
->fx_addsy
) > 255)
2502 && S_GET_SEGMENT (fixP
->fx_addsy
) != absolute_section
)
2504 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
2505 _("invalid operands"));
2506 /* We don't want this "symbol" appearing in output, because
2513 /* If this reloc is for a Z field, we need to adjust
2514 the opcode if we got a constant here.
2515 FIXME: Can we make this more robust? */
2517 if ((fixP
->fx_where
& 3) == 3
2518 && (fixP
->fx_addsy
== NULL
2519 || S_GET_SEGMENT (fixP
->fx_addsy
) == absolute_section
))
2520 buf
[-3] |= IMM_OFFSET_BIT
;
2523 case BFD_RELOC_MMIX_REG
:
2524 if (fixP
->fx_addsy
== NULL
2525 || S_GET_SEGMENT (fixP
->fx_addsy
) != reg_section
2526 || S_GET_VALUE (fixP
->fx_addsy
) > 255)
2528 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
2529 _("invalid operands"));
2536 case BFD_RELOC_MMIX_BASE_PLUS_OFFSET
:
2537 /* These are never "fixed". */
2541 case BFD_RELOC_MMIX_PUSHJ_1
:
2542 case BFD_RELOC_MMIX_PUSHJ_2
:
2543 case BFD_RELOC_MMIX_PUSHJ_3
:
2544 case BFD_RELOC_MMIX_CBRANCH_J
:
2545 case BFD_RELOC_MMIX_CBRANCH_1
:
2546 case BFD_RELOC_MMIX_CBRANCH_2
:
2547 case BFD_RELOC_MMIX_CBRANCH_3
:
2548 case BFD_RELOC_MMIX_GETA_1
:
2549 case BFD_RELOC_MMIX_GETA_2
:
2550 case BFD_RELOC_MMIX_GETA_3
:
2551 case BFD_RELOC_MMIX_JMP_1
:
2552 case BFD_RELOC_MMIX_JMP_2
:
2553 case BFD_RELOC_MMIX_JMP_3
:
2555 BAD_CASE (fixP
->fx_r_type
);
2560 /* Make sure that for completed fixups we have the value around for
2561 use by e.g. mmix_frob_file. */
2562 fixP
->fx_offset
= val
;
2565 /* A bsearch function for looking up a value against offsets for GREG
2569 cmp_greg_val_greg_symbol_fixes (const void *p1
, const void *p2
)
2571 offsetT val1
= *(offsetT
*) p1
;
2572 offsetT val2
= ((struct mmix_symbol_greg_fixes
*) p2
)->offs
;
2574 if (val1
>= val2
&& val1
< val2
+ 255)
2583 /* Generate a machine-dependent relocation. */
2586 tc_gen_reloc (asection
*section ATTRIBUTE_UNUSED
, fixS
*fixP
)
2590 + (fixP
->fx_addsy
!= NULL
2591 && !S_IS_WEAK (fixP
->fx_addsy
)
2592 && !S_IS_COMMON (fixP
->fx_addsy
)
2593 ? S_GET_VALUE (fixP
->fx_addsy
) : 0);
2595 bfd_reloc_code_real_type code
= BFD_RELOC_NONE
;
2596 char *buf
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
2597 symbolS
*addsy
= fixP
->fx_addsy
;
2598 asection
*addsec
= addsy
== NULL
? NULL
: S_GET_SEGMENT (addsy
);
2599 asymbol
*baddsy
= addsy
!= NULL
? symbol_get_bfdsym (addsy
) : NULL
;
2601 = val
- (baddsy
== NULL
|| S_IS_COMMON (addsy
) || S_IS_WEAK (addsy
)
2602 ? 0 : bfd_asymbol_value (baddsy
));
2604 /* A single " LOCAL expression" in the wrong section will not work when
2605 linking to MMO; relocations for zero-content sections are then
2606 ignored. Normally, relocations would modify section contents, and
2607 you'd never think or be able to do something like that. The
2608 relocation resulting from a LOCAL directive doesn't have an obvious
2609 and mandatory location. I can't figure out a way to do this better
2610 than just helping the user around this limitation here; hopefully the
2611 code using the local expression is around. Putting the LOCAL
2612 semantics in a relocation still seems right; a section didn't do. */
2613 if (bfd_section_size (section
->owner
, section
) == 0)
2615 (fixP
->fx_file
, fixP
->fx_line
,
2616 fixP
->fx_r_type
== BFD_RELOC_MMIX_LOCAL
2617 /* The BFD_RELOC_MMIX_LOCAL-specific message is supposed to be
2618 user-friendly, though a little bit non-substantial. */
2619 ? _("directive LOCAL must be placed in code or data")
2620 : _("internal confusion: relocation in a section without contents"));
2622 /* FIXME: Range tests for all these. */
2623 switch (fixP
->fx_r_type
)
2630 code
= fixP
->fx_r_type
;
2632 if (addsy
== NULL
|| bfd_is_abs_section (addsec
))
2634 /* Resolve this reloc now, as md_apply_fix would have done (not
2635 called if -linkrelax). There is no point in keeping a reloc
2636 to an absolute symbol. No reloc that is subject to
2637 relaxation must be to an absolute symbol; difference
2638 involving symbols in a specific section must be signalled as
2639 an error if the relaxing cannot be expressed; having a reloc
2640 to the resolved (now absolute) value does not help. */
2641 md_number_to_chars (buf
, val
, fixP
->fx_size
);
2646 case BFD_RELOC_64_PCREL
:
2647 case BFD_RELOC_32_PCREL
:
2648 case BFD_RELOC_24_PCREL
:
2649 case BFD_RELOC_16_PCREL
:
2650 case BFD_RELOC_8_PCREL
:
2651 case BFD_RELOC_MMIX_LOCAL
:
2652 case BFD_RELOC_VTABLE_INHERIT
:
2653 case BFD_RELOC_VTABLE_ENTRY
:
2654 case BFD_RELOC_MMIX_GETA
:
2655 case BFD_RELOC_MMIX_GETA_1
:
2656 case BFD_RELOC_MMIX_GETA_2
:
2657 case BFD_RELOC_MMIX_GETA_3
:
2658 case BFD_RELOC_MMIX_CBRANCH
:
2659 case BFD_RELOC_MMIX_CBRANCH_J
:
2660 case BFD_RELOC_MMIX_CBRANCH_1
:
2661 case BFD_RELOC_MMIX_CBRANCH_2
:
2662 case BFD_RELOC_MMIX_CBRANCH_3
:
2663 case BFD_RELOC_MMIX_PUSHJ
:
2664 case BFD_RELOC_MMIX_PUSHJ_1
:
2665 case BFD_RELOC_MMIX_PUSHJ_2
:
2666 case BFD_RELOC_MMIX_PUSHJ_3
:
2667 case BFD_RELOC_MMIX_PUSHJ_STUBBABLE
:
2668 case BFD_RELOC_MMIX_JMP
:
2669 case BFD_RELOC_MMIX_JMP_1
:
2670 case BFD_RELOC_MMIX_JMP_2
:
2671 case BFD_RELOC_MMIX_JMP_3
:
2672 case BFD_RELOC_MMIX_ADDR19
:
2673 case BFD_RELOC_MMIX_ADDR27
:
2674 code
= fixP
->fx_r_type
;
2677 case BFD_RELOC_MMIX_REG_OR_BYTE
:
2678 /* If we have this kind of relocation to an unknown symbol or to the
2679 register contents section (that is, to a register), then we can't
2680 resolve the relocation here. */
2682 && (bfd_is_und_section (addsec
)
2683 || strcmp (bfd_get_section_name (addsec
->owner
, addsec
),
2684 MMIX_REG_CONTENTS_SECTION_NAME
) == 0))
2686 code
= fixP
->fx_r_type
;
2690 /* If the relocation is not to the register section or to the
2691 absolute section (a numeric value), then we have an error. */
2693 && (S_GET_SEGMENT (addsy
) != real_reg_section
2696 && ! bfd_is_abs_section (addsec
))
2699 /* Set the "immediate" bit of the insn if this relocation is to Z
2700 field when the value is a numeric value, i.e. not a register. */
2701 if ((fixP
->fx_where
& 3) == 3
2702 && (addsy
== NULL
|| bfd_is_abs_section (addsec
)))
2703 buf
[-3] |= IMM_OFFSET_BIT
;
2708 case BFD_RELOC_MMIX_BASE_PLUS_OFFSET
:
2710 && strcmp (bfd_get_section_name (addsec
->owner
, addsec
),
2711 MMIX_REG_CONTENTS_SECTION_NAME
) == 0)
2713 /* This changed into a register; the relocation is for the
2714 register-contents section. The constant part remains zero. */
2715 code
= BFD_RELOC_MMIX_REG
;
2719 /* If we've found out that this was indeed a register, then replace
2720 with the register number. The constant part is already zero.
2722 If we encounter any other defined symbol, then we must find a
2723 suitable register and emit a reloc. */
2724 if (addsy
== NULL
|| addsec
!= real_reg_section
)
2726 struct mmix_symbol_gregs
*gregs
;
2727 struct mmix_symbol_greg_fixes
*fix
;
2729 if (S_IS_DEFINED (addsy
)
2730 && !bfd_is_com_section (addsec
)
2731 && !S_IS_WEAK (addsy
))
2733 if (! symbol_section_p (addsy
) && ! bfd_is_abs_section (addsec
))
2734 as_fatal (_("internal: BFD_RELOC_MMIX_BASE_PLUS_OFFSET not resolved to section"));
2736 /* If this is an absolute symbol sufficiently near
2737 lowest_data_loc, then we canonicalize on the data
2738 section. Note that val is signed here; we may subtract
2739 lowest_data_loc which is unsigned. Careful with those
2741 if (lowest_data_loc
!= (bfd_vma
) -1
2742 && (bfd_vma
) val
+ 256 > lowest_data_loc
2743 && bfd_is_abs_section (addsec
))
2745 val
-= (offsetT
) lowest_data_loc
;
2746 addsy
= section_symbol (data_section
);
2748 /* Likewise text section. */
2749 else if (lowest_text_loc
!= (bfd_vma
) -1
2750 && (bfd_vma
) val
+ 256 > lowest_text_loc
2751 && bfd_is_abs_section (addsec
))
2753 val
-= (offsetT
) lowest_text_loc
;
2754 addsy
= section_symbol (text_section
);
2758 gregs
= *symbol_get_tc (addsy
);
2760 /* If that symbol does not have any associated GREG definitions,
2761 we can't do anything. */
2763 || (fix
= bsearch (&val
, gregs
->greg_fixes
, gregs
->n_gregs
,
2764 sizeof (gregs
->greg_fixes
[0]),
2765 cmp_greg_val_greg_symbol_fixes
)) == NULL
2766 /* The register must not point *after* the address we want. */
2768 /* Neither must the register point more than 255 bytes
2769 before the address we want. */
2770 || fix
->offs
+ 255 < val
)
2772 /* We can either let the linker allocate GREGs
2773 automatically, or emit an error. */
2774 if (allocate_undefined_gregs_in_linker
)
2776 /* The values in baddsy and addend are right. */
2777 code
= fixP
->fx_r_type
;
2781 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
2782 _("no suitable GREG definition for operands"));
2787 /* Transform the base-plus-offset reloc for the actual area
2788 to a reloc for the register with the address of the area.
2789 Put addend for register in Z operand. */
2790 buf
[1] = val
- fix
->offs
;
2791 code
= BFD_RELOC_MMIX_REG
;
2793 = (bfd_get_section_by_name (stdoutput
,
2794 MMIX_REG_CONTENTS_SECTION_NAME
)
2797 addend
= fix
->fix
->fx_frag
->fr_address
+ fix
->fix
->fx_where
;
2800 else if (S_GET_VALUE (addsy
) > 255)
2801 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
2802 _("invalid operands"));
2810 case BFD_RELOC_MMIX_REG
:
2812 && (bfd_is_und_section (addsec
)
2813 || strcmp (bfd_get_section_name (addsec
->owner
, addsec
),
2814 MMIX_REG_CONTENTS_SECTION_NAME
) == 0))
2816 code
= fixP
->fx_r_type
;
2821 && (addsec
!= real_reg_section
2824 && ! bfd_is_und_section (addsec
))
2825 /* Drop through to error message. */
2834 /* The others are supposed to be handled by md_apply_fix.
2835 FIXME: ... which isn't called when -linkrelax. Move over
2836 md_apply_fix code here for everything reasonable. */
2840 (fixP
->fx_file
, fixP
->fx_line
,
2841 _("operands were not reducible at assembly-time"));
2843 /* Unmark this symbol as used in a reloc, so we don't bump into a BFD
2844 assert when trying to output reg_section. FIXME: A gas bug. */
2845 fixP
->fx_addsy
= NULL
;
2849 relP
= (arelent
*) xmalloc (sizeof (arelent
));
2850 gas_assert (relP
!= 0);
2851 relP
->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
2852 *relP
->sym_ptr_ptr
= baddsy
;
2853 relP
->address
= fixP
->fx_frag
->fr_address
+ fixP
->fx_where
;
2855 relP
->addend
= addend
;
2857 /* If this had been a.out, we would have had a kludge for weak symbols
2860 relP
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
2865 name
= S_GET_NAME (addsy
);
2867 name
= _("<unknown>");
2868 as_fatal (_("cannot generate relocation type for symbol %s, code %s"),
2869 name
, bfd_get_reloc_code_name (code
));
2875 /* Do some reformatting of a line. FIXME: We could transform a mmixal
2876 line into traditional (GNU?) format, unless #NO_APP, and get rid of all
2877 ugly labels_without_colons etc. */
2880 mmix_handle_mmixal (void)
2883 char *s
= input_line_pointer
;
2887 if (pending_label
!= NULL
)
2888 as_fatal (_("internal: unhandled label %s"), pending_label
);
2890 if (mmix_gnu_syntax
)
2893 /* If we're on a line with a label, check if it's a mmixal fb-label.
2894 Save an indicator and skip the label; it must be set only after all
2895 fb-labels of expressions are evaluated. */
2896 if (ISDIGIT (s
[0]) && s
[1] == 'H' && ISSPACE (s
[2]))
2898 current_fb_label
= s
[0] - '0';
2900 /* We have to skip the label, but also preserve the newlineness of
2901 the previous character, since the caller checks that. It's a
2902 mess we blame on the caller. */
2905 input_line_pointer
= s
;
2907 while (*s
&& ISSPACE (*s
) && ! is_end_of_line
[(unsigned int) *s
])
2910 /* For errors emitted here, the book-keeping is off by one; the
2911 caller is about to bump the counters. Adjust the error messages. */
2912 if (is_end_of_line
[(unsigned int) *s
])
2916 as_where (&name
, &line
);
2917 as_bad_where (name
, line
+ 1,
2918 _("[0-9]H labels may not appear alone on a line"));
2919 current_fb_label
= -1;
2925 as_where (&name
, &line
);
2926 as_bad_where (name
, line
+ 1,
2927 _("[0-9]H labels do not mix with dot-pseudos"));
2928 current_fb_label
= -1;
2931 /* Back off to the last space before the opcode so we don't handle
2932 the opcode as a label. */
2936 current_fb_label
= -1;
2940 /* If the first character is a '.', then it's a pseudodirective, not a
2941 label. Make GAS not handle label-without-colon on this line. We
2942 also don't do mmixal-specific stuff on this line. */
2943 label_without_colon_this_line
= 0;
2947 if (*s
== 0 || is_end_of_line
[(unsigned int) *s
])
2948 /* We avoid handling empty lines here. */
2951 if (is_name_beginner (*s
))
2954 /* If there is a label, skip over it. */
2955 while (*s
&& is_part_of_name (*s
))
2958 /* Find the start of the instruction or pseudo following the label,
2961 *insn
&& ISSPACE (*insn
) && ! is_end_of_line
[(unsigned int) *insn
];
2966 /* Remove a trailing ":" off labels, as they'd otherwise be considered
2967 part of the name. But don't do this for local labels. */
2968 if (s
!= input_line_pointer
&& s
[-1] == ':'
2969 && (s
- 2 != input_line_pointer
2970 || ! ISDIGIT (s
[-2])))
2972 else if (label
!= NULL
2973 /* For a lone label on a line, we don't attach it to the next
2974 instruction or MMIXAL-pseudo (getting its alignment). Thus
2975 is acts like a "normal" :-ended label. Ditto if it's
2976 followed by a non-MMIXAL pseudo. */
2977 && !is_end_of_line
[(unsigned int) *insn
]
2980 /* For labels that don't end in ":", we save it so we can later give
2981 it the same alignment and address as the associated instruction. */
2983 /* Make room for the label including the ending nul. */
2984 int len_0
= s
- label
+ 1;
2986 /* Save this label on the MMIX symbol obstack. Saving it on an
2987 obstack is needless for "IS"-pseudos, but it's harmless and we
2988 avoid a little code-cluttering. */
2989 obstack_grow (&mmix_sym_obstack
, label
, len_0
);
2990 pending_label
= obstack_finish (&mmix_sym_obstack
);
2991 pending_label
[len_0
- 1] = 0;
2994 /* If we have a non-MMIXAL pseudo, we have not business with the rest of
2999 /* Find local labels of operands. Look for "[0-9][FB]" where the
3000 characters before and after are not part of words. Break if a single
3001 or double quote is seen anywhere. It means we can't have local
3002 labels as part of list with mixed quoted and unquoted members for
3003 mmixal compatibility but we can't have it all. For the moment.
3004 Replace the '<N>B' or '<N>F' with MAGIC_FB_BACKWARD_CHAR<N> and
3005 MAGIC_FB_FORWARD_CHAR<N> respectively. */
3007 /* First make sure we don't have any of the magic characters on the line
3008 appearing as input. */
3012 if (is_end_of_line
[(unsigned int) c
])
3014 if (c
== MAGIC_FB_BACKWARD_CHAR
|| c
== MAGIC_FB_FORWARD_CHAR
)
3015 as_bad (_("invalid characters in input"));
3018 /* Scan again, this time looking for ';' after operands. */
3021 /* Skip the insn. */
3025 && ! is_end_of_line
[(unsigned int) *s
])
3028 /* Skip the spaces after the insn. */
3032 && ! is_end_of_line
[(unsigned int) *s
])
3035 /* Skip the operands. While doing this, replace [0-9][BF] with
3036 (MAGIC_FB_BACKWARD_CHAR|MAGIC_FB_FORWARD_CHAR)[0-9]. */
3037 while ((c
= *s
) != 0
3040 && ! is_end_of_line
[(unsigned int) c
])
3046 /* FIXME: Test-case for semi-colon in string. */
3049 && (! is_end_of_line
[(unsigned int) *s
] || *s
== ';'))
3055 else if (ISDIGIT (c
))
3057 if ((s
[1] != 'B' && s
[1] != 'F')
3058 || is_part_of_name (s
[-1])
3059 || is_part_of_name (s
[2])
3060 /* Don't treat e.g. #1F as a local-label reference. */
3061 || (s
!= input_line_pointer
&& s
[-1] == '#'))
3066 ? MAGIC_FB_BACKWARD_CHAR
: MAGIC_FB_FORWARD_CHAR
);
3074 /* Skip any spaces after the operands. */
3078 && !is_end_of_line
[(unsigned int) *s
])
3081 /* If we're now looking at a semi-colon, then it's an end-of-line
3083 mmix_next_semicolon_is_eoln
= (*s
== ';');
3085 /* Make IS into an EQU by replacing it with "= ". Only match upper-case
3086 though; let lower-case be a syntax error. */
3088 if (s
[0] == 'I' && s
[1] == 'S' && ISSPACE (s
[2]))
3093 /* Since labels can start without ":", we have to handle "X IS 42"
3094 in full here, or "X" will be parsed as a label to be set at ".". */
3095 input_line_pointer
= s
;
3097 /* Right after this function ends, line numbers will be bumped if
3098 input_line_pointer[-1] = '\n'. We want accurate line numbers for
3099 the equals call, so we bump them before the call, and make sure
3100 they aren't bumped afterwards. */
3101 bump_line_counters ();
3103 /* A fb-label is valid as an IS-label. */
3104 if (current_fb_label
>= 0)
3108 /* We need to save this name on our symbol obstack, since the
3109 string we got in fb_label_name is volatile and will change
3110 with every call to fb_label_name, like those resulting from
3111 parsing the IS-operand. */
3112 fb_name
= fb_label_name (current_fb_label
, 1);
3113 obstack_grow (&mmix_sym_obstack
, fb_name
, strlen (fb_name
) + 1);
3114 equals (obstack_finish (&mmix_sym_obstack
), 0);
3115 fb_label_instance_inc (current_fb_label
);
3116 current_fb_label
= -1;
3120 if (pending_label
== NULL
)
3121 as_bad (_("empty label field for IS"));
3123 equals (pending_label
, 0);
3124 pending_label
= NULL
;
3127 /* For mmixal, we can have comments without a comment-start
3129 mmix_handle_rest_of_empty_line ();
3130 input_line_pointer
--;
3132 input_line_pointer
[-1] = ' ';
3134 else if (s
[0] == 'G'
3136 && strncmp (s
, "GREG", 4) == 0
3137 && (ISSPACE (s
[4]) || is_end_of_line
[(unsigned char) s
[4]]))
3139 input_line_pointer
= s
+ 4;
3141 /* Right after this function ends, line numbers will be bumped if
3142 input_line_pointer[-1] = '\n'. We want accurate line numbers for
3143 the s_greg call, so we bump them before the call, and make sure
3144 they aren't bumped afterwards. */
3145 bump_line_counters ();
3147 /* A fb-label is valid as a GREG-label. */
3148 if (current_fb_label
>= 0)
3152 /* We need to save this name on our symbol obstack, since the
3153 string we got in fb_label_name is volatile and will change
3154 with every call to fb_label_name, like those resulting from
3155 parsing the IS-operand. */
3156 fb_name
= fb_label_name (current_fb_label
, 1);
3158 /* Make sure we save the canonical name and don't get bitten by
3160 obstack_1grow (&mmix_sym_obstack
, ':');
3161 obstack_grow (&mmix_sym_obstack
, fb_name
, strlen (fb_name
) + 1);
3162 mmix_greg_internal (obstack_finish (&mmix_sym_obstack
));
3163 fb_label_instance_inc (current_fb_label
);
3164 current_fb_label
= -1;
3167 mmix_greg_internal (pending_label
);
3169 /* Back up before the end-of-line marker that was skipped in
3170 mmix_greg_internal. */
3171 input_line_pointer
--;
3172 input_line_pointer
[-1] = ' ';
3174 pending_label
= NULL
;
3176 else if (pending_label
!= NULL
)
3178 input_line_pointer
+= strlen (pending_label
);
3180 /* See comment above about getting line numbers bumped. */
3181 input_line_pointer
[-1] = '\n';
3185 /* Give the value of an fb-label rewritten as in mmix_handle_mmixal, when
3186 parsing an expression.
3188 On valid calls, input_line_pointer points at a MAGIC_FB_BACKWARD_CHAR
3189 or MAGIC_FB_BACKWARD_CHAR, followed by an ascii digit for the label.
3190 We fill in the label as an expression. */
3193 mmix_fb_label (expressionS
*expP
)
3196 char *fb_internal_name
;
3198 /* This doesn't happen when not using mmixal syntax. */
3200 || (input_line_pointer
[0] != MAGIC_FB_BACKWARD_CHAR
3201 && input_line_pointer
[0] != MAGIC_FB_FORWARD_CHAR
))
3204 /* The current backward reference has augmentation 0. A forward
3205 reference has augmentation 1, unless it's the same as a fb-label on
3206 _this_ line, in which case we add one more so we don't refer to it.
3207 This is the semantics of mmixal; it differs to that of common
3208 fb-labels which refer to a here-label on the current line as a
3209 backward reference. */
3211 = fb_label_name (input_line_pointer
[1] - '0',
3212 (input_line_pointer
[0] == MAGIC_FB_FORWARD_CHAR
? 1 : 0)
3213 + ((input_line_pointer
[1] - '0' == current_fb_label
3214 && input_line_pointer
[0] == MAGIC_FB_FORWARD_CHAR
)
3217 input_line_pointer
+= 2;
3218 sym
= symbol_find_or_make (fb_internal_name
);
3220 /* We don't have to clean up unrelated fields here; we just do what the
3221 expr machinery does, but *not* just what it does for [0-9][fb], since
3222 we need to treat those as ordinary symbols sometimes; see testcases
3223 err-byte2.s and fb-2.s. */
3224 if (S_GET_SEGMENT (sym
) == absolute_section
)
3226 expP
->X_op
= O_constant
;
3227 expP
->X_add_number
= S_GET_VALUE (sym
);
3231 expP
->X_op
= O_symbol
;
3232 expP
->X_add_symbol
= sym
;
3233 expP
->X_add_number
= 0;
3237 /* See whether we need to force a relocation into the output file.
3238 This is used to force out switch and PC relative relocations when
3242 mmix_force_relocation (fixS
*fixP
)
3244 if (fixP
->fx_r_type
== BFD_RELOC_MMIX_LOCAL
3245 || fixP
->fx_r_type
== BFD_RELOC_MMIX_BASE_PLUS_OFFSET
)
3251 /* All our pcrel relocations are must-keep. Note that md_apply_fix is
3252 called *after* this, and will handle getting rid of the presumed
3253 reloc; a relocation isn't *forced* other than to be handled by
3254 md_apply_fix (or tc_gen_reloc if linkrelax). */
3258 return generic_force_reloc (fixP
);
3261 /* The location from which a PC relative jump should be calculated,
3262 given a PC relative reloc. */
3265 md_pcrel_from_section (fixS
*fixP
, segT sec
)
3267 if (fixP
->fx_addsy
!= (symbolS
*) NULL
3268 && (! S_IS_DEFINED (fixP
->fx_addsy
)
3269 || S_GET_SEGMENT (fixP
->fx_addsy
) != sec
))
3271 /* The symbol is undefined (or is defined but not in this section).
3272 Let the linker figure it out. */
3276 return (fixP
->fx_frag
->fr_address
+ fixP
->fx_where
);
3279 /* Adjust the symbol table. We make reg_section relative to the real
3280 register section. */
3283 mmix_adjust_symtab (void)
3286 symbolS
*regsec
= section_symbol (reg_section
);
3288 for (sym
= symbol_rootP
; sym
!= NULL
; sym
= symbol_next (sym
))
3289 if (S_GET_SEGMENT (sym
) == reg_section
)
3293 if (S_IS_EXTERNAL (sym
) || symbol_used_in_reloc_p (sym
))
3295 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
3298 /* Change section to the *real* register section, so it gets
3299 proper treatment when writing it out. Only do this for
3300 global symbols. This also means we don't have to check for
3302 S_SET_SEGMENT (sym
, real_reg_section
);
3306 /* This is the expansion of LABELS_WITHOUT_COLONS.
3307 We let md_start_line_hook tweak label_without_colon_this_line, and then
3308 this function returns the tweaked value, and sets it to 1 for the next
3309 line. FIXME: Very, very brittle. Not sure it works the way I
3310 thought at the time I first wrote this. */
3313 mmix_label_without_colon_this_line (void)
3315 int retval
= label_without_colon_this_line
;
3317 if (! mmix_gnu_syntax
)
3318 label_without_colon_this_line
= 1;
3323 /* This is the expansion of md_relax_frag. We go through the ordinary
3324 relax table function except when the frag is for a GREG. Then we have
3325 to check whether there's another GREG by the same value that we can
3329 mmix_md_relax_frag (segT seg
, fragS
*fragP
, long stretch
)
3331 switch (fragP
->fr_subtype
)
3333 /* Growth for this type has been handled by mmix_md_end and
3334 correctly estimated, so there's nothing more to do here. */
3335 case STATE_GREG_DEF
:
3338 case ENCODE_RELAX (STATE_PUSHJ
, STATE_ZERO
):
3340 /* We need to handle relaxation type ourselves, since relax_frag
3341 doesn't update fr_subtype if there's no size increase in the
3342 current section; when going from plain PUSHJ to a stub. This
3343 is otherwise functionally the same as relax_frag in write.c,
3344 simplified for this case. */
3349 target
= fragP
->fr_offset
;
3350 address
= fragP
->fr_address
;
3351 symbolP
= fragP
->fr_symbol
;
3357 sym_frag
= symbol_get_frag (symbolP
);
3358 know (S_GET_SEGMENT (symbolP
) != absolute_section
3359 || sym_frag
== &zero_address_frag
);
3360 target
+= S_GET_VALUE (symbolP
);
3362 /* If frag has yet to be reached on this pass, assume it will
3363 move by STRETCH just as we did. If this is not so, it will
3364 be because some frag between grows, and that will force
3368 && sym_frag
->relax_marker
!= fragP
->relax_marker
3369 && S_GET_SEGMENT (symbolP
) == seg
)
3373 aim
= target
- address
- fragP
->fr_fix
;
3374 if (aim
>= PUSHJ_0B
&& aim
<= PUSHJ_0F
)
3376 /* Target is reachable with a PUSHJ. */
3377 segment_info_type
*seginfo
= seg_info (seg
);
3379 /* If we're at the end of a relaxation round, clear the stub
3380 counter as initialization for the next round. */
3381 if (fragP
== seginfo
->tc_segment_info_data
.last_stubfrag
)
3382 seginfo
->tc_segment_info_data
.nstubs
= 0;
3386 /* Not reachable. Try a stub. */
3387 fragP
->fr_subtype
= ENCODE_RELAX (STATE_PUSHJSTUB
, STATE_ZERO
);
3391 /* See if this PUSHJ is redirectable to a stub. */
3392 case ENCODE_RELAX (STATE_PUSHJSTUB
, STATE_ZERO
):
3394 segment_info_type
*seginfo
= seg_info (seg
);
3395 fragS
*lastfrag
= seginfo
->frchainP
->frch_last
;
3396 relax_substateT prev_type
= fragP
->fr_subtype
;
3398 /* The last frag is always an empty frag, so it suffices to look
3399 at its address to know the ending address of this section. */
3400 know (lastfrag
->fr_type
== rs_fill
3401 && lastfrag
->fr_fix
== 0
3402 && lastfrag
->fr_var
== 0);
3404 /* For this PUSHJ to be relaxable into a call to a stub, the
3405 distance must be no longer than 256k bytes from the PUSHJ to
3406 the end of the section plus the maximum size of stubs so far. */
3407 if ((lastfrag
->fr_address
3409 + PUSHJ_MAX_LEN
* seginfo
->tc_segment_info_data
.nstubs
)
3410 - (fragP
->fr_address
+ fragP
->fr_fix
)
3413 fragP
->fr_subtype
= mmix_relax_table
[prev_type
].rlx_more
;
3415 seginfo
->tc_segment_info_data
.nstubs
++;
3417 /* If we're at the end of a relaxation round, clear the stub
3418 counter as initialization for the next round. */
3419 if (fragP
== seginfo
->tc_segment_info_data
.last_stubfrag
)
3420 seginfo
->tc_segment_info_data
.nstubs
= 0;
3423 (mmix_relax_table
[fragP
->fr_subtype
].rlx_length
3424 - mmix_relax_table
[prev_type
].rlx_length
);
3427 case ENCODE_RELAX (STATE_PUSHJ
, STATE_MAX
):
3429 segment_info_type
*seginfo
= seg_info (seg
);
3431 /* Need to cover all STATE_PUSHJ states to act on the last stub
3432 frag (the end of this relax round; initialization for the
3434 if (fragP
== seginfo
->tc_segment_info_data
.last_stubfrag
)
3435 seginfo
->tc_segment_info_data
.nstubs
= 0;
3441 return relax_frag (seg
, fragP
, stretch
);
3443 case STATE_GREG_UNDF
:
3444 BAD_CASE (fragP
->fr_subtype
);
3447 as_fatal (_("internal: unexpected relax type %d:%d"),
3448 fragP
->fr_type
, fragP
->fr_subtype
);
3452 /* Various things we punt until all input is seen. */
3462 /* The first frag of GREG:s going into the register contents section. */
3463 fragS
*mmix_reg_contents_frags
= NULL
;
3465 /* Reset prefix. All labels reachable at this point must be
3467 mmix_current_prefix
= NULL
;
3470 as_bad_where (bspec_file
, bspec_line
, _("BSPEC without ESPEC."));
3472 /* Emit the low LOC setting of .text. */
3473 if (text_has_contents
&& lowest_text_loc
!= (bfd_vma
) -1)
3476 char locsymbol
[sizeof (":") - 1
3477 + sizeof (MMIX_LOC_SECTION_START_SYMBOL_PREFIX
) - 1
3478 + sizeof (".text")];
3480 /* An exercise in non-ISO-C-ness, this one. */
3481 sprintf (locsymbol
, ":%s%s", MMIX_LOC_SECTION_START_SYMBOL_PREFIX
,
3484 = symbol_new (locsymbol
, absolute_section
, lowest_text_loc
,
3485 &zero_address_frag
);
3486 S_SET_EXTERNAL (symbolP
);
3490 if (data_has_contents
&& lowest_data_loc
!= (bfd_vma
) -1)
3493 char locsymbol
[sizeof (":") - 1
3494 + sizeof (MMIX_LOC_SECTION_START_SYMBOL_PREFIX
) - 1
3495 + sizeof (".data")];
3497 sprintf (locsymbol
, ":%s%s", MMIX_LOC_SECTION_START_SYMBOL_PREFIX
,
3500 = symbol_new (locsymbol
, absolute_section
, lowest_data_loc
,
3501 &zero_address_frag
);
3502 S_SET_EXTERNAL (symbolP
);
3505 /* Unless GNU syntax mode, set "Main" to be a function, so the
3506 disassembler doesn't get confused when we write truly
3507 mmixal-compatible code (and don't use .type). Similarly set it
3508 global (regardless of -globalize-symbols), so the linker sees it as
3509 the start symbol in ELF mode. */
3510 mainsym
= symbol_find (MMIX_START_SYMBOL_NAME
);
3511 if (mainsym
!= NULL
&& ! mmix_gnu_syntax
)
3513 symbol_get_bfdsym (mainsym
)->flags
|= BSF_FUNCTION
;
3514 S_SET_EXTERNAL (mainsym
);
3517 if (n_of_raw_gregs
!= 0)
3519 /* Emit GREGs. They are collected in order of appearance, but must
3520 be emitted in opposite order to both have section address regno*8
3521 and the same allocation order (within a file) as mmixal. */
3522 segT this_segment
= now_seg
;
3523 subsegT this_subsegment
= now_subseg
;
3525 regsec
= bfd_make_section_old_way (stdoutput
,
3526 MMIX_REG_CONTENTS_SECTION_NAME
);
3527 subseg_set (regsec
, 0);
3529 /* Finally emit the initialization-value. Emit a variable frag, which
3530 we'll fix in md_estimate_size_before_relax. We set the initializer
3531 for the tc_frag_data field to NULL, so we can use that field for
3532 relaxation purposes. */
3533 mmix_opcode_frag
= NULL
;
3536 mmix_reg_contents_frags
= frag_now
;
3538 for (i
= n_of_raw_gregs
- 1; i
>= 0; i
--)
3540 if (mmix_raw_gregs
[i
].label
!= NULL
)
3541 /* There's a symbol. Let it refer to this location in the
3542 register contents section. The symbol must be globalized
3544 colon (mmix_raw_gregs
[i
].label
);
3546 frag_var (rs_machine_dependent
, 8, 0, STATE_GREG_UNDF
,
3547 make_expr_symbol (&mmix_raw_gregs
[i
].exp
), 0, NULL
);
3550 subseg_set (this_segment
, this_subsegment
);
3553 regsec
= bfd_get_section_by_name (stdoutput
, MMIX_REG_CONTENTS_SECTION_NAME
);
3554 /* Mark the section symbol as being OK for a reloc. */
3556 regsec
->symbol
->flags
|= BSF_KEEP
;
3558 /* Iterate over frags resulting from GREGs and move those that evidently
3559 have the same value together and point one to another.
3561 This works in time O(N^2) but since the upper bound for non-error use
3562 is 223, it's best to keep this simpler algorithm. */
3563 for (fragP
= mmix_reg_contents_frags
; fragP
!= NULL
; fragP
= fragP
->fr_next
)
3570 symbolS
*symbolP
= fragP
->fr_symbol
;
3572 if (fragP
->fr_type
!= rs_machine_dependent
3573 || fragP
->fr_subtype
!= STATE_GREG_UNDF
)
3576 /* Whatever the outcome, we will have this GREG judged merged or
3577 non-merged. Since the tc_frag_data is NULL at this point, we
3578 default to non-merged. */
3579 fragP
->fr_subtype
= STATE_GREG_DEF
;
3581 /* If we're not supposed to merge GREG definitions, then just don't
3582 look for equivalents. */
3586 osymval
= (offsetT
) S_GET_VALUE (symbolP
);
3587 osymfrag
= symbol_get_frag (symbolP
);
3589 /* If the symbol isn't defined, we can't say that another symbol
3590 equals this frag, then. FIXME: We can look at the "deepest"
3591 defined name; if a = c and b = c then obviously a == b. */
3592 if (! S_IS_DEFINED (symbolP
))
3595 oexpP
= symbol_get_value_expression (fragP
->fr_symbol
);
3597 /* If the initialization value is zero, then we must not merge them. */
3598 if (oexpP
->X_op
== O_constant
&& osymval
== 0)
3601 /* Iterate through the frags downward this one. If we find one that
3602 has the same non-zero value, move it to after this one and point
3603 to it as the equivalent. */
3604 for (fpp
= &fragP
->fr_next
; *fpp
!= NULL
; fpp
= &fpp
[0]->fr_next
)
3608 if (fp
->fr_type
!= rs_machine_dependent
3609 || fp
->fr_subtype
!= STATE_GREG_UNDF
)
3612 /* Calling S_GET_VALUE may simplify the symbol, changing from
3613 expr_section etc. so call it first. */
3614 if ((offsetT
) S_GET_VALUE (fp
->fr_symbol
) == osymval
3615 && symbol_get_frag (fp
->fr_symbol
) == osymfrag
)
3617 /* Move the frag links so the one we found equivalent comes
3618 after the current one, carefully considering that
3619 sometimes fpp == &fragP->fr_next and the moves must be a
3622 fp
->fr_next
= fragP
->fr_next
;
3623 fragP
->fr_next
= fp
;
3629 fragP
->tc_frag_data
= fp
;
3633 /* qsort function for mmix_symbol_gregs. */
3636 cmp_greg_symbol_fixes (const void *parg
, const void *qarg
)
3638 const struct mmix_symbol_greg_fixes
*p
3639 = (const struct mmix_symbol_greg_fixes
*) parg
;
3640 const struct mmix_symbol_greg_fixes
*q
3641 = (const struct mmix_symbol_greg_fixes
*) qarg
;
3643 return p
->offs
> q
->offs
? 1 : p
->offs
< q
->offs
? -1 : 0;
3646 /* Collect GREG definitions from mmix_gregs and hang them as lists sorted
3647 on increasing offsets onto each section symbol or undefined symbol.
3649 Also, remove the register convenience section so it doesn't get output
3650 as an ELF section. */
3653 mmix_frob_file (void)
3656 struct mmix_symbol_gregs
*all_greg_symbols
[MAX_GREGS
];
3657 int n_greg_symbols
= 0;
3659 /* Collect all greg fixups and decorate each corresponding symbol with
3660 the greg fixups for it. */
3661 for (i
= 0; i
< n_of_cooked_gregs
; i
++)
3665 struct mmix_symbol_gregs
*gregs
;
3668 fixP
= mmix_gregs
[i
];
3669 know (fixP
->fx_r_type
== BFD_RELOC_64
);
3671 /* This case isn't doable in general anyway, methinks. */
3672 if (fixP
->fx_subsy
!= NULL
)
3674 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3675 _("GREG expression too complicated"));
3679 sym
= fixP
->fx_addsy
;
3680 offs
= (offsetT
) fixP
->fx_offset
;
3682 /* If the symbol is defined, then it must be resolved to a section
3683 symbol at this time, or else we don't know how to handle it. */
3684 if (S_IS_DEFINED (sym
)
3685 && !bfd_is_com_section (S_GET_SEGMENT (sym
))
3686 && !S_IS_WEAK (sym
))
3688 if (! symbol_section_p (sym
)
3689 && ! bfd_is_abs_section (S_GET_SEGMENT (sym
)))
3690 as_fatal (_("internal: GREG expression not resolved to section"));
3692 offs
+= S_GET_VALUE (sym
);
3695 /* If this is an absolute symbol sufficiently near lowest_data_loc,
3696 then we canonicalize on the data section. Note that offs is
3697 signed here; we may subtract lowest_data_loc which is unsigned.
3698 Careful with those comparisons. */
3699 if (lowest_data_loc
!= (bfd_vma
) -1
3700 && (bfd_vma
) offs
+ 256 > lowest_data_loc
3701 && bfd_is_abs_section (S_GET_SEGMENT (sym
)))
3703 offs
-= (offsetT
) lowest_data_loc
;
3704 sym
= section_symbol (data_section
);
3706 /* Likewise text section. */
3707 else if (lowest_text_loc
!= (bfd_vma
) -1
3708 && (bfd_vma
) offs
+ 256 > lowest_text_loc
3709 && bfd_is_abs_section (S_GET_SEGMENT (sym
)))
3711 offs
-= (offsetT
) lowest_text_loc
;
3712 sym
= section_symbol (text_section
);
3715 gregs
= *symbol_get_tc (sym
);
3719 gregs
= xmalloc (sizeof (*gregs
));
3721 symbol_set_tc (sym
, &gregs
);
3722 all_greg_symbols
[n_greg_symbols
++] = gregs
;
3725 gregs
->greg_fixes
[gregs
->n_gregs
].fix
= fixP
;
3726 gregs
->greg_fixes
[gregs
->n_gregs
++].offs
= offs
;
3729 /* For each symbol having a GREG definition, sort those definitions on
3731 for (i
= 0; i
< n_greg_symbols
; i
++)
3732 qsort (all_greg_symbols
[i
]->greg_fixes
, all_greg_symbols
[i
]->n_gregs
,
3733 sizeof (all_greg_symbols
[i
]->greg_fixes
[0]), cmp_greg_symbol_fixes
);
3735 if (real_reg_section
!= NULL
)
3737 /* FIXME: Pass error state gracefully. */
3738 if (bfd_get_section_flags (stdoutput
, real_reg_section
) & SEC_HAS_CONTENTS
)
3739 as_fatal (_("register section has contents\n"));
3741 bfd_section_list_remove (stdoutput
, real_reg_section
);
3742 --stdoutput
->section_count
;
3747 /* Provide an expression for a built-in name provided when-used.
3748 Either a symbol that is a handler; living in 0x10*[1..8] and having
3749 name [DVWIOUZX]_Handler, or a mmixal built-in symbol.
3751 If the name isn't a built-in name and parsed into *EXPP, return zero. */
3754 mmix_parse_predefined_name (char *name
, expressionS
*expP
)
3757 char *handler_charp
;
3758 const char handler_chars
[] = "DVWIOUZX";
3761 if (! predefined_syms
)
3764 canon_name
= tc_canonicalize_symbol_name (name
);
3766 if (canon_name
[1] == '_'
3767 && strcmp (canon_name
+ 2, "Handler") == 0
3768 && (handler_charp
= strchr (handler_chars
, *canon_name
)) != NULL
)
3770 /* If the symbol doesn't exist, provide one relative to the .text
3773 FIXME: We should provide separate sections, mapped in the linker
3775 symp
= symbol_find (name
);
3777 symp
= symbol_new (name
, text_section
,
3778 0x10 * (handler_charp
+ 1 - handler_chars
),
3779 &zero_address_frag
);
3783 /* These symbols appear when referenced; needed for
3784 mmixal-compatible programs. */
3791 } predefined_abs_syms
[] =
3793 {"Data_Segment", (valueT
) 0x20 << 56},
3794 {"Pool_Segment", (valueT
) 0x40 << 56},
3795 {"Stack_Segment", (valueT
) 0x60 << 56},
3803 {"BinaryReadWrite", 4},
3826 /* If it's already in the symbol table, we shouldn't do anything. */
3827 symp
= symbol_find (name
);
3832 i
< sizeof (predefined_abs_syms
) / sizeof (predefined_abs_syms
[0]);
3834 if (strcmp (canon_name
, predefined_abs_syms
[i
].name
) == 0)
3836 symbol_table_insert (symbol_new (predefined_abs_syms
[i
].name
,
3838 predefined_abs_syms
[i
].val
,
3839 &zero_address_frag
));
3841 /* Let gas find the symbol we just created, through its
3846 /* Not one of those symbols. Let gas handle it. */
3850 expP
->X_op
= O_symbol
;
3851 expP
->X_add_number
= 0;
3852 expP
->X_add_symbol
= symp
;
3853 expP
->X_op_symbol
= NULL
;
3858 /* Just check that we don't have a BSPEC/ESPEC pair active when changing
3859 sections "normally", and get knowledge about alignment from the new
3863 mmix_md_elf_section_change_hook (void)
3866 as_bad (_("section change from within a BSPEC/ESPEC pair is not supported"));
3868 last_alignment
= bfd_get_section_alignment (now_seg
->owner
, now_seg
);
3872 /* The LOC worker. This is like s_org, but we have to support changing
3876 s_loc (int ignore ATTRIBUTE_UNUSED
)
3884 /* Must not have a BSPEC in progress. */
3887 as_bad (_("directive LOC from within a BSPEC/ESPEC pair is not supported"));
3891 section
= expression (&exp
);
3893 if (exp
.X_op
== O_illegal
3894 || exp
.X_op
== O_absent
3895 || exp
.X_op
== O_big
3896 || section
== undefined_section
)
3898 as_bad (_("invalid LOC expression"));
3902 if (section
== absolute_section
)
3904 /* Translate a constant into a suitable section. */
3906 if (exp
.X_add_number
< ((offsetT
) 0x20 << 56))
3908 /* Lower than Data_Segment or in the reserved area (the
3909 segment number is >= 0x80, appearing negative) - assume
3911 section
= text_section
;
3913 /* Save the lowest seen location, so we can pass on this
3914 information to the linker. We don't actually org to this
3915 location here, we just pass on information to the linker so
3916 it can put the code there for us. */
3918 /* If there was already a loc (that has to be set lower than
3919 this one), we org at (this - lower). There's an implicit
3920 "LOC 0" before any entered code. FIXME: handled by spurious
3921 settings of text_has_contents. */
3922 if (lowest_text_loc
!= (bfd_vma
) -1
3923 && (bfd_vma
) exp
.X_add_number
< lowest_text_loc
)
3925 as_bad (_("LOC expression stepping backwards is not supported"));
3926 exp
.X_op
= O_absent
;
3930 if (text_has_contents
&& lowest_text_loc
== (bfd_vma
) -1)
3931 lowest_text_loc
= 0;
3933 if (lowest_text_loc
== (bfd_vma
) -1)
3935 lowest_text_loc
= exp
.X_add_number
;
3937 /* We want only to change the section, not set an offset. */
3938 exp
.X_op
= O_absent
;
3941 exp
.X_add_number
-= lowest_text_loc
;
3946 /* Do the same for the .data section, except we don't have
3947 to worry about exp.X_add_number carrying a sign. */
3948 section
= data_section
;
3950 if (exp
.X_add_number
< (offsetT
) lowest_data_loc
)
3952 as_bad (_("LOC expression stepping backwards is not supported"));
3953 exp
.X_op
= O_absent
;
3957 if (data_has_contents
&& lowest_data_loc
== (bfd_vma
) -1)
3958 lowest_data_loc
= (bfd_vma
) 0x20 << 56;
3960 if (lowest_data_loc
== (bfd_vma
) -1)
3962 lowest_data_loc
= exp
.X_add_number
;
3964 /* We want only to change the section, not set an offset. */
3965 exp
.X_op
= O_absent
;
3968 exp
.X_add_number
-= lowest_data_loc
;
3973 if (section
!= now_seg
)
3975 obj_elf_section_change_hook ();
3976 subseg_set (section
, 0);
3978 /* Call our section change hooks using the official hook. */
3979 md_elf_section_change_hook ();
3982 if (exp
.X_op
!= O_absent
)
3984 if (exp
.X_op
!= O_constant
&& exp
.X_op
!= O_symbol
)
3986 /* Handle complex expressions. */
3987 sym
= make_expr_symbol (&exp
);
3992 sym
= exp
.X_add_symbol
;
3993 off
= exp
.X_add_number
;
3996 p
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, sym
, off
, (char *) 0);
4000 mmix_handle_rest_of_empty_line ();
4003 /* The BYTE worker. We have to support sequences of mixed "strings",
4004 numbers and other constant "first-pass" reducible expressions separated
4012 if (now_seg
== text_section
)
4013 text_has_contents
= 1;
4014 else if (now_seg
== data_section
)
4015 data_has_contents
= 1;
4020 switch (*input_line_pointer
)
4023 ++input_line_pointer
;
4024 while (is_a_char (c
= next_char_of_string ()))
4026 FRAG_APPEND_1_CHAR (c
);
4029 if (input_line_pointer
[-1] != '\"')
4031 /* We will only get here in rare cases involving #NO_APP,
4032 where the unterminated string is not recognized by the
4033 preformatting pass. */
4034 as_bad (_("unterminated string"));
4035 mmix_discard_rest_of_line ();
4043 segT expseg
= expression (&exp
);
4045 /* We have to allow special register names as constant numbers. */
4046 if ((expseg
!= absolute_section
&& expseg
!= reg_section
)
4047 || (exp
.X_op
!= O_constant
4048 && (exp
.X_op
!= O_register
4049 || exp
.X_add_number
<= 255)))
4051 as_bad (_("BYTE expression not a pure number"));
4052 mmix_discard_rest_of_line ();
4055 else if ((exp
.X_add_number
> 255 && exp
.X_op
!= O_register
)
4056 || exp
.X_add_number
< 0)
4058 /* Note that mmixal does not allow negative numbers in
4059 BYTE sequences, so neither should we. */
4060 as_bad (_("BYTE expression not in the range 0..255"));
4061 mmix_discard_rest_of_line ();
4065 FRAG_APPEND_1_CHAR (exp
.X_add_number
);
4071 c
= *input_line_pointer
++;
4075 input_line_pointer
--;
4077 if (mmix_gnu_syntax
)
4078 demand_empty_rest_of_line ();
4081 mmix_discard_rest_of_line ();
4082 /* Do like demand_empty_rest_of_line and step over the end-of-line
4084 input_line_pointer
++;
4087 /* Make sure we align for the next instruction. */
4091 /* Like cons_worker, but we have to ignore "naked comments", not barf on
4092 them. Implements WYDE, TETRA and OCTA. We're a little bit more
4093 lenient than mmix_byte but FIXME: they should eventually merge. */
4096 mmix_cons (int nbytes
)
4100 /* If we don't have any contents, then it's ok to have a specified start
4101 address that is not a multiple of the max data size. We will then
4102 align it as necessary when we get here. Otherwise, it's a fatal sin. */
4103 if (now_seg
== text_section
)
4105 if (lowest_text_loc
!= (bfd_vma
) -1
4106 && (lowest_text_loc
& (nbytes
- 1)) != 0)
4108 if (text_has_contents
)
4109 as_bad (_("data item with alignment larger than location"));
4110 else if (want_unaligned
)
4111 as_bad (_("unaligned data at an absolute location is not supported"));
4113 lowest_text_loc
&= ~((bfd_vma
) nbytes
- 1);
4114 lowest_text_loc
+= (bfd_vma
) nbytes
;
4117 text_has_contents
= 1;
4119 else if (now_seg
== data_section
)
4121 if (lowest_data_loc
!= (bfd_vma
) -1
4122 && (lowest_data_loc
& (nbytes
- 1)) != 0)
4124 if (data_has_contents
)
4125 as_bad (_("data item with alignment larger than location"));
4126 else if (want_unaligned
)
4127 as_bad (_("unaligned data at an absolute location is not supported"));
4129 lowest_data_loc
&= ~((bfd_vma
) nbytes
- 1);
4130 lowest_data_loc
+= (bfd_vma
) nbytes
;
4133 data_has_contents
= 1;
4136 /* Always align these unless asked not to (valid for the current pseudo). */
4137 if (! want_unaligned
)
4139 last_alignment
= nbytes
== 2 ? 1 : (nbytes
== 4 ? 2 : 3);
4140 frag_align (last_alignment
, 0, 0);
4141 record_alignment (now_seg
, last_alignment
);
4144 /* For mmixal compatibility, a label for an instruction (and emitting
4145 pseudo) refers to the _aligned_ address. So we have to emit the
4147 if (current_fb_label
>= 0)
4148 colon (fb_label_name (current_fb_label
, 1));
4149 else if (pending_label
!= NULL
)
4151 colon (pending_label
);
4152 pending_label
= NULL
;
4157 if (is_end_of_line
[(unsigned int) *input_line_pointer
])
4159 /* Default to zero if the expression was absent. */
4161 exp
.X_op
= O_constant
;
4162 exp
.X_add_number
= 0;
4164 exp
.X_add_symbol
= NULL
;
4165 exp
.X_op_symbol
= NULL
;
4166 emit_expr (&exp
, (unsigned int) nbytes
);
4173 switch (*input_line_pointer
)
4175 /* We support strings here too; each character takes up nbytes
4178 ++input_line_pointer
;
4179 while (is_a_char (c
= next_char_of_string ()))
4181 exp
.X_op
= O_constant
;
4182 exp
.X_add_number
= c
;
4184 emit_expr (&exp
, (unsigned int) nbytes
);
4187 if (input_line_pointer
[-1] != '\"')
4189 /* We will only get here in rare cases involving #NO_APP,
4190 where the unterminated string is not recognized by the
4191 preformatting pass. */
4192 as_bad (_("unterminated string"));
4193 mmix_discard_rest_of_line ();
4201 emit_expr (&exp
, (unsigned int) nbytes
);
4207 while (*input_line_pointer
++ == ',');
4209 input_line_pointer
--; /* Put terminator back into stream. */
4211 mmix_handle_rest_of_empty_line ();
4213 /* We don't need to step up the counter for the current_fb_label here;
4214 that's handled by the caller. */
4217 /* The md_do_align worker. At present, we just record an alignment to
4218 nullify the automatic alignment we do for WYDE, TETRA and OCTA, as gcc
4219 does not use the unaligned macros when attribute packed is used.
4220 Arguably this is a GCC bug. */
4223 mmix_md_do_align (int n
, char *fill ATTRIBUTE_UNUSED
,
4224 int len ATTRIBUTE_UNUSED
, int max ATTRIBUTE_UNUSED
)
4227 want_unaligned
= n
== 0;