1 /* tc-mmix.c -- Assembler for Don Knuth's MMIX.
2 Copyright (C) 2001, 2002, 2003, 2004, 2005 Free Software Foundation.
4 This file is part of GAS, the GNU Assembler.
6 GAS is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GAS is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GAS; see the file COPYING. If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
21 /* Knuth's assembler mmixal does not provide a relocatable format; mmo is
22 to be considered a final link-format. In the final link, we make mmo,
23 but for relocatable files, we use ELF.
25 One goal is to provide a superset of what mmixal does, including
26 compatible syntax, but the main purpose is to serve GCC. */
35 #include "opcode/mmix.h"
36 #include "safe-ctype.h"
37 #include "dwarf2dbg.h"
40 /* Something to describe what we need to do with a fixup before output,
41 for example assert something of what it became or make a relocation. */
43 enum mmix_fixup_action
47 mmix_fixup_register_or_adjust_for_byte
50 static int get_spec_regno (char *);
51 static int get_operands (int, char *, expressionS
*);
52 static int get_putget_operands (struct mmix_opcode
*, char *, expressionS
*);
53 static void s_prefix (int);
54 static void s_greg (int);
55 static void s_loc (int);
56 static void s_bspec (int);
57 static void s_espec (int);
58 static void mmix_s_local (int);
59 static void mmix_greg_internal (char *);
60 static void mmix_set_geta_branch_offset (char *, offsetT
);
61 static void mmix_set_jmp_offset (char *, offsetT
);
62 static void mmix_fill_nops (char *, int);
63 static int cmp_greg_symbol_fixes (const void *, const void *);
64 static int cmp_greg_val_greg_symbol_fixes (const void *, const void *);
65 static void mmix_handle_rest_of_empty_line (void);
66 static void mmix_discard_rest_of_line (void);
67 static void mmix_byte (void);
68 static void mmix_cons (int);
70 /* Continue the tradition of symbols.c; use control characters to enforce
71 magic. These are used when replacing e.g. 8F and 8B so we can handle
72 such labels correctly with the common parser hooks. */
73 #define MAGIC_FB_BACKWARD_CHAR '\003'
74 #define MAGIC_FB_FORWARD_CHAR '\004'
76 /* Copy the location of a frag to a fix. */
77 #define COPY_FR_WHERE_TO_FX(FRAG, FIX) \
80 (FIX)->fx_file = (FRAG)->fr_file; \
81 (FIX)->fx_line = (FRAG)->fr_line; \
85 const char *md_shortopts
= "x";
86 static int current_fb_label
= -1;
87 static char *pending_label
= NULL
;
89 static bfd_vma lowest_text_loc
= (bfd_vma
) -1;
90 static int text_has_contents
= 0;
92 /* The alignment of the previous instruction, and a boolean for whether we
93 want to avoid aligning the next WYDE, TETRA, OCTA or insn. */
94 static int last_alignment
= 0;
95 static int want_unaligned
= 0;
97 static bfd_vma lowest_data_loc
= (bfd_vma
) -1;
98 static int data_has_contents
= 0;
100 /* The fragS of the instruction being assembled. Only valid from within
102 fragS
*mmix_opcode_frag
= NULL
;
104 /* Raw GREGs as appearing in input. These may be fewer than the number
106 static int n_of_raw_gregs
= 0;
111 } mmix_raw_gregs
[MAX_GREGS
];
113 /* Fixups for all unique GREG registers. We store the fixups here in
114 md_convert_frag, then we use the array to convert
115 BFD_RELOC_MMIX_BASE_PLUS_OFFSET fixups in tc_gen_reloc. The index is
116 just a running number and is not supposed to be correlated to a
118 static fixS
*mmix_gregs
[MAX_GREGS
];
119 static int n_of_cooked_gregs
= 0;
121 /* Pointing to the register section we use for output. */
122 static asection
*real_reg_section
;
124 /* For each symbol; unknown or section symbol, we keep a list of GREG
125 definitions sorted on increasing offset. It seems no use keeping count
126 to allocate less room than the maximum number of gregs when we've found
127 one for a section or symbol. */
128 struct mmix_symbol_gregs
131 struct mmix_symbol_greg_fixes
135 /* A signed type, since we may have GREGs pointing slightly before the
136 contents of a section. */
138 } greg_fixes
[MAX_GREGS
];
141 /* Should read insert a colon on something that starts in column 0 on
143 static int label_without_colon_this_line
= 1;
145 /* Should we automatically expand instructions into multiple insns in
146 order to generate working code? */
147 static int expand_op
= 1;
149 /* Should we warn when expanding operands? FIXME: test-cases for when -x
151 static int warn_on_expansion
= 1;
153 /* Should we merge non-zero GREG register definitions? */
154 static int merge_gregs
= 1;
156 /* Should we pass on undefined BFD_RELOC_MMIX_BASE_PLUS_OFFSET relocs
157 (missing suitable GREG definitions) to the linker? */
158 static int allocate_undefined_gregs_in_linker
= 0;
160 /* Should we emit built-in symbols? */
161 static int predefined_syms
= 1;
163 /* Should we allow anything but the listed special register name
164 (e.g. equated symbols)? */
165 static int equated_spec_regs
= 1;
167 /* Do we require standard GNU syntax? */
168 int mmix_gnu_syntax
= 0;
170 /* Do we globalize all symbols? */
171 int mmix_globalize_symbols
= 0;
173 /* When expanding insns, do we want to expand PUSHJ as a call to a stub
174 (or else as a series of insns)? */
177 /* Do we know that the next semicolon is at the end of the operands field
178 (in mmixal mode; constant 1 in GNU mode)? */
179 int mmix_next_semicolon_is_eoln
= 1;
181 /* Do we have a BSPEC in progress? */
182 static int doing_bspec
= 0;
183 static char *bspec_file
;
184 static unsigned int bspec_line
;
186 struct option md_longopts
[] =
188 #define OPTION_RELAX (OPTION_MD_BASE)
189 #define OPTION_NOEXPAND (OPTION_RELAX + 1)
190 #define OPTION_NOMERGEGREG (OPTION_NOEXPAND + 1)
191 #define OPTION_NOSYMS (OPTION_NOMERGEGREG + 1)
192 #define OPTION_GNU_SYNTAX (OPTION_NOSYMS + 1)
193 #define OPTION_GLOBALIZE_SYMBOLS (OPTION_GNU_SYNTAX + 1)
194 #define OPTION_FIXED_SPEC_REGS (OPTION_GLOBALIZE_SYMBOLS + 1)
195 #define OPTION_LINKER_ALLOCATED_GREGS (OPTION_FIXED_SPEC_REGS + 1)
196 #define OPTION_NOPUSHJSTUBS (OPTION_LINKER_ALLOCATED_GREGS + 1)
197 {"linkrelax", no_argument
, NULL
, OPTION_RELAX
},
198 {"no-expand", no_argument
, NULL
, OPTION_NOEXPAND
},
199 {"no-merge-gregs", no_argument
, NULL
, OPTION_NOMERGEGREG
},
200 {"no-predefined-syms", no_argument
, NULL
, OPTION_NOSYMS
},
201 {"gnu-syntax", no_argument
, NULL
, OPTION_GNU_SYNTAX
},
202 {"globalize-symbols", no_argument
, NULL
, OPTION_GLOBALIZE_SYMBOLS
},
203 {"fixed-special-register-names", no_argument
, NULL
,
204 OPTION_FIXED_SPEC_REGS
},
205 {"linker-allocated-gregs", no_argument
, NULL
,
206 OPTION_LINKER_ALLOCATED_GREGS
},
207 {"no-pushj-stubs", no_argument
, NULL
, OPTION_NOPUSHJSTUBS
},
208 {"no-stubs", no_argument
, NULL
, OPTION_NOPUSHJSTUBS
},
209 {NULL
, no_argument
, NULL
, 0}
212 size_t md_longopts_size
= sizeof (md_longopts
);
214 static struct hash_control
*mmix_opcode_hash
;
216 /* We use these when implementing the PREFIX pseudo. */
217 char *mmix_current_prefix
;
218 struct obstack mmix_sym_obstack
;
221 /* For MMIX, we encode the relax_substateT:s (in e.g. fr_substate) as one
222 bit length, and the relax-type shifted on top of that. There seems to
223 be no point in making the relaxation more fine-grained; the linker does
224 that better and we might interfere by changing non-optimal relaxations
225 into other insns that cannot be relaxed as easily.
227 Groups for MMIX relaxing:
230 extra length: zero or three insns.
233 extra length: zero or five insns.
236 extra length: zero or four insns.
237 Special handling to deal with transition to PUSHJSTUB.
240 extra length: zero or four insns.
243 special handling, allocates a named global register unless another
244 is within reach for all uses.
247 special handling (mostly) for external references; assumes the
248 linker will generate a stub if target is no longer than 256k from
249 the end of the section plus max size of previous stubs. Zero or
252 #define STATE_GETA (1)
253 #define STATE_BCC (2)
254 #define STATE_PUSHJ (3)
255 #define STATE_JMP (4)
256 #define STATE_GREG (5)
257 #define STATE_PUSHJSTUB (6)
259 /* No fine-grainedness here. */
260 #define STATE_LENGTH_MASK (1)
262 #define STATE_ZERO (0)
263 #define STATE_MAX (1)
265 /* More descriptive name for convenience. */
266 /* FIXME: We should start on something different, not MAX. */
267 #define STATE_UNDF STATE_MAX
269 /* FIXME: For GREG, we must have other definitions; UNDF == MAX isn't
270 appropriate; we need it the other way round. This value together with
271 fragP->tc_frag_data shows what state the frag is in: tc_frag_data
272 non-NULL means 0, NULL means 8 bytes. */
273 #define STATE_GREG_UNDF ENCODE_RELAX (STATE_GREG, STATE_ZERO)
274 #define STATE_GREG_DEF ENCODE_RELAX (STATE_GREG, STATE_MAX)
276 /* These displacements are relative to the address following the opcode
277 word of the instruction. The catch-all states have zero for "reach"
278 and "next" entries. */
280 #define GETA_0F (65536 * 4 - 8)
281 #define GETA_0B (-65536 * 4 - 4)
283 #define GETA_MAX_LEN 4 * 4
287 #define BCC_0F GETA_0F
288 #define BCC_0B GETA_0B
290 #define BCC_MAX_LEN 6 * 4
291 #define BCC_5F GETA_3F
292 #define BCC_5B GETA_3B
294 #define PUSHJ_0F GETA_0F
295 #define PUSHJ_0B GETA_0B
297 #define PUSHJ_MAX_LEN 5 * 4
298 #define PUSHJ_4F GETA_3F
299 #define PUSHJ_4B GETA_3B
301 /* We'll very rarely have sections longer than LONG_MAX, but we'll make a
302 feeble attempt at getting 64-bit values. */
303 #define PUSHJSTUB_MAX ((offsetT) (((addressT) -1) >> 1))
304 #define PUSHJSTUB_MIN (-PUSHJSTUB_MAX - 1)
306 #define JMP_0F (65536 * 256 * 4 - 8)
307 #define JMP_0B (-65536 * 256 * 4 - 4)
309 #define JMP_MAX_LEN 5 * 4
313 #define RELAX_ENCODE_SHIFT 1
314 #define ENCODE_RELAX(what, length) (((what) << RELAX_ENCODE_SHIFT) + (length))
316 const relax_typeS mmix_relax_table
[] =
318 /* Error sentinel (0, 0). */
325 {GETA_0F
, GETA_0B
, 0, ENCODE_RELAX (STATE_GETA
, STATE_MAX
)},
329 GETA_MAX_LEN
- 4, 0},
332 {BCC_0F
, BCC_0B
, 0, ENCODE_RELAX (STATE_BCC
, STATE_MAX
)},
338 /* PUSHJ (3, 0). Next state is actually PUSHJSTUB (6, 0). */
339 {PUSHJ_0F
, PUSHJ_0B
, 0, ENCODE_RELAX (STATE_PUSHJSTUB
, STATE_ZERO
)},
343 PUSHJ_MAX_LEN
- 4, 0},
346 {JMP_0F
, JMP_0B
, 0, ENCODE_RELAX (STATE_JMP
, STATE_MAX
)},
352 /* GREG (5, 0), (5, 1), though the table entry isn't used. */
353 {0, 0, 0, 0}, {0, 0, 0, 0},
355 /* PUSHJSTUB (6, 0). PUSHJ (3, 0) uses the range, so we set it to infinite. */
356 {PUSHJSTUB_MAX
, PUSHJSTUB_MIN
,
357 0, ENCODE_RELAX (STATE_PUSHJ
, STATE_MAX
)},
358 /* PUSHJSTUB (6, 1) isn't used. */
359 {0, 0, PUSHJ_MAX_LEN
, 0}
362 const pseudo_typeS md_pseudo_table
[] =
364 /* Support " .greg sym,expr" syntax. */
367 /* Support " .bspec expr" syntax. */
368 {"bspec", s_bspec
, 1},
370 /* Support " .espec" syntax. */
371 {"espec", s_espec
, 1},
373 /* Support " .local $45" syntax. */
374 {"local", mmix_s_local
, 1},
379 const char mmix_comment_chars
[] = "%!";
381 /* A ':' is a valid symbol character in mmixal. It's the prefix
382 delimiter, but other than that, it works like a symbol character,
383 except that we strip one off at the beginning of symbols. An '@' is a
384 symbol by itself (for the current location); space around it must not
386 const char mmix_symbol_chars
[] = ":@";
388 const char line_comment_chars
[] = "*#";
390 const char line_separator_chars
[] = ";";
392 const char mmix_exp_chars
[] = "eE";
394 const char mmix_flt_chars
[] = "rf";
397 /* Fill in the offset-related part of GETA or Bcc. */
400 mmix_set_geta_branch_offset (char *opcodep
, offsetT value
)
409 md_number_to_chars (opcodep
+ 2, value
, 2);
412 /* Fill in the offset-related part of JMP. */
415 mmix_set_jmp_offset (char *opcodep
, offsetT value
)
419 value
+= 65536 * 256 * 4;
424 md_number_to_chars (opcodep
+ 1, value
, 3);
427 /* Fill in NOP:s for the expanded part of GETA/JMP/Bcc/PUSHJ. */
430 mmix_fill_nops (char *opcodep
, int n
)
434 for (i
= 0; i
< n
; i
++)
435 md_number_to_chars (opcodep
+ i
* 4, SWYM_INSN_BYTE
<< 24, 4);
438 /* See macro md_parse_name in tc-mmix.h. */
441 mmix_current_location (void (*fn
) (expressionS
*), expressionS
*exp
)
448 /* Get up to three operands, filling them into the exp array.
449 General idea and code stolen from the tic80 port. */
452 get_operands (int max_operands
, char *s
, expressionS
*exp
)
458 while (nextchar
== ',')
460 /* Skip leading whitespace */
461 while (*p
== ' ' || *p
== '\t')
464 /* Check to see if we have any operands left to parse */
465 if (*p
== 0 || *p
== '\n' || *p
== '\r')
469 else if (numexp
== max_operands
)
471 /* This seems more sane than saying "too many operands". We'll
472 get here only if the trailing trash starts with a comma. */
473 as_bad (_("invalid operands"));
474 mmix_discard_rest_of_line ();
478 /* Begin operand parsing at the current scan point. */
480 input_line_pointer
= p
;
481 expression (&exp
[numexp
]);
483 if (exp
[numexp
].X_op
== O_illegal
)
485 as_bad (_("invalid operands"));
487 else if (exp
[numexp
].X_op
== O_absent
)
489 as_bad (_("missing operand"));
493 p
= input_line_pointer
;
495 /* Skip leading whitespace */
496 while (*p
== ' ' || *p
== '\t')
501 /* If we allow "naked" comments, ignore the rest of the line. */
504 mmix_handle_rest_of_empty_line ();
505 input_line_pointer
--;
508 /* Mark the end of the valid operands with an illegal expression. */
509 exp
[numexp
].X_op
= O_illegal
;
514 /* Get the value of a special register, or -1 if the name does not match
515 one. NAME is a null-terminated string. */
518 get_spec_regno (char *name
)
528 /* Well, it's a short array and we'll most often just match the first
530 for (i
= 0; mmix_spec_regs
[i
].name
!= NULL
; i
++)
531 if (strcmp (name
, mmix_spec_regs
[i
].name
) == 0)
532 return mmix_spec_regs
[i
].number
;
537 /* For GET and PUT, parse the register names "manually", so we don't use
540 get_putget_operands (struct mmix_opcode
*insn
, char *operands
,
543 expressionS
*expp_reg
;
544 expressionS
*expp_sreg
;
546 char *sregend
= operands
;
551 /* Skip leading whitespace */
552 while (*p
== ' ' || *p
== '\t')
555 input_line_pointer
= p
;
557 /* Initialize both possible operands to error state, in case we never
559 exp
[0].X_op
= O_illegal
;
560 exp
[1].X_op
= O_illegal
;
562 if (insn
->operands
== mmix_operands_get
)
567 expression (expp_reg
);
569 p
= input_line_pointer
;
571 /* Skip whitespace */
572 while (*p
== ' ' || *p
== '\t')
579 /* Skip whitespace */
580 while (*p
== ' ' || *p
== '\t')
583 input_line_pointer
= sregp
;
584 c
= get_symbol_end ();
585 sregend
= input_line_pointer
;
594 c
= get_symbol_end ();
595 sregend
= p
= input_line_pointer
;
598 /* Skip whitespace */
599 while (*p
== ' ' || *p
== '\t')
606 /* Skip whitespace */
607 while (*p
== ' ' || *p
== '\t')
610 input_line_pointer
= p
;
611 expression (expp_reg
);
616 regno
= get_spec_regno (sregp
);
619 /* Let the caller issue errors; we've made sure the operands are
621 if (expp_reg
->X_op
!= O_illegal
622 && expp_reg
->X_op
!= O_absent
625 expp_sreg
->X_op
= O_register
;
626 expp_sreg
->X_add_number
= regno
+ 256;
632 /* Handle MMIX-specific option. */
635 md_parse_option (int c
, char *arg ATTRIBUTE_UNUSED
)
640 warn_on_expansion
= 0;
641 allocate_undefined_gregs_in_linker
= 1;
648 case OPTION_NOEXPAND
:
652 case OPTION_NOMERGEGREG
:
658 equated_spec_regs
= 0;
661 case OPTION_GNU_SYNTAX
:
663 label_without_colon_this_line
= 0;
666 case OPTION_GLOBALIZE_SYMBOLS
:
667 mmix_globalize_symbols
= 1;
670 case OPTION_FIXED_SPEC_REGS
:
671 equated_spec_regs
= 0;
674 case OPTION_LINKER_ALLOCATED_GREGS
:
675 allocate_undefined_gregs_in_linker
= 1;
678 case OPTION_NOPUSHJSTUBS
:
689 /* Display MMIX-specific help text. */
692 md_show_usage (FILE * stream
)
694 fprintf (stream
, _(" MMIX-specific command line options:\n"));
695 fprintf (stream
, _("\
696 -fixed-special-register-names\n\
697 Allow only the original special register names.\n"));
698 fprintf (stream
, _("\
699 -globalize-symbols Make all symbols global.\n"));
700 fprintf (stream
, _("\
701 -gnu-syntax Turn off mmixal syntax compatibility.\n"));
702 fprintf (stream
, _("\
703 -relax Create linker relaxable code.\n"));
704 fprintf (stream
, _("\
705 -no-predefined-syms Do not provide mmixal built-in constants.\n\
706 Implies -fixed-special-register-names.\n"));
707 fprintf (stream
, _("\
708 -no-expand Do not expand GETA, branches, PUSHJ or JUMP\n\
709 into multiple instructions.\n"));
710 fprintf (stream
, _("\
711 -no-merge-gregs Do not merge GREG definitions with nearby values.\n"));
712 fprintf (stream
, _("\
713 -linker-allocated-gregs If there's no suitable GREG definition for the\
714 operands of an instruction, let the linker resolve.\n"));
715 fprintf (stream
, _("\
716 -x Do not warn when an operand to GETA, a branch,\n\
717 PUSHJ or JUMP is not known to be within range.\n\
718 The linker will catch any errors. Implies\n\
719 -linker-allocated-gregs."));
722 /* Step to end of line, but don't step over the end of the line. */
725 mmix_discard_rest_of_line (void)
727 while (*input_line_pointer
728 && (! is_end_of_line
[(unsigned char) *input_line_pointer
]
729 || TC_EOL_IN_INSN (input_line_pointer
)))
730 input_line_pointer
++;
733 /* Act as demand_empty_rest_of_line if we're in strict GNU syntax mode,
734 otherwise just ignore the rest of the line (and skip the end-of-line
738 mmix_handle_rest_of_empty_line (void)
741 demand_empty_rest_of_line ();
744 mmix_discard_rest_of_line ();
745 input_line_pointer
++;
749 /* Initialize GAS MMIX specifics. */
755 const struct mmix_opcode
*opcode
;
757 /* We assume nobody will use this, so don't allocate any room. */
758 obstack_begin (&mmix_sym_obstack
, 0);
760 /* This will break the day the "lex" thingy changes. For now, it's the
761 only way to make ':' part of a name, and a name beginner. */
762 lex_type
[':'] = (LEX_NAME
| LEX_BEGIN_NAME
);
764 mmix_opcode_hash
= hash_new ();
767 = bfd_make_section_old_way (stdoutput
, MMIX_REG_SECTION_NAME
);
769 for (opcode
= mmix_opcodes
; opcode
->name
; opcode
++)
770 hash_insert (mmix_opcode_hash
, opcode
->name
, (char *) opcode
);
772 /* We always insert the ordinary registers 0..255 as registers. */
773 for (i
= 0; i
< 256; i
++)
777 /* Alternatively, we could diddle with '$' and the following number,
778 but keeping the registers as symbols helps keep parsing simple. */
779 sprintf (buf
, "$%d", i
);
780 symbol_table_insert (symbol_new (buf
, reg_section
, i
,
781 &zero_address_frag
));
784 /* Insert mmixal built-in names if allowed. */
787 for (i
= 0; mmix_spec_regs
[i
].name
!= NULL
; i
++)
788 symbol_table_insert (symbol_new (mmix_spec_regs
[i
].name
,
790 mmix_spec_regs
[i
].number
+ 256,
791 &zero_address_frag
));
793 /* FIXME: Perhaps these should be recognized as specials; as field
794 names for those instructions. */
795 symbol_table_insert (symbol_new ("ROUND_CURRENT", reg_section
, 512,
796 &zero_address_frag
));
797 symbol_table_insert (symbol_new ("ROUND_OFF", reg_section
, 512 + 1,
798 &zero_address_frag
));
799 symbol_table_insert (symbol_new ("ROUND_UP", reg_section
, 512 + 2,
800 &zero_address_frag
));
801 symbol_table_insert (symbol_new ("ROUND_DOWN", reg_section
, 512 + 3,
802 &zero_address_frag
));
803 symbol_table_insert (symbol_new ("ROUND_NEAR", reg_section
, 512 + 4,
804 &zero_address_frag
));
808 /* Assemble one insn in STR. */
811 md_assemble (char *str
)
813 char *operands
= str
;
814 char modified_char
= 0;
815 struct mmix_opcode
*instruction
;
816 fragS
*opc_fragP
= NULL
;
817 int max_operands
= 3;
819 /* Note that the struct frag member fr_literal in frags.h is char[], so
820 I have to make this a plain char *. */
821 /* unsigned */ char *opcodep
= NULL
;
826 /* Move to end of opcode. */
828 is_part_of_name (*operands
);
832 if (ISSPACE (*operands
))
834 modified_char
= *operands
;
838 instruction
= (struct mmix_opcode
*) hash_find (mmix_opcode_hash
, str
);
839 if (instruction
== NULL
)
841 as_bad (_("unknown opcode: `%s'"), str
);
843 /* Avoid "unhandled label" errors. */
844 pending_label
= NULL
;
848 /* Put back the character after the opcode. */
849 if (modified_char
!= 0)
850 operands
[-1] = modified_char
;
852 input_line_pointer
= operands
;
854 /* Is this a mmixal pseudodirective? */
855 if (instruction
->type
== mmix_type_pseudo
)
857 /* For mmixal compatibility, a label for an instruction (and
858 emitting pseudo) refers to the _aligned_ address. We emit the
859 label here for the pseudos that don't handle it themselves. When
860 having an fb-label, emit it here, and increment the counter after
862 switch (instruction
->operands
)
864 case mmix_operands_loc
:
865 case mmix_operands_byte
:
866 case mmix_operands_prefix
:
867 case mmix_operands_local
:
868 case mmix_operands_bspec
:
869 case mmix_operands_espec
:
870 if (current_fb_label
>= 0)
871 colon (fb_label_name (current_fb_label
, 1));
872 else if (pending_label
!= NULL
)
874 colon (pending_label
);
875 pending_label
= NULL
;
883 /* Some of the pseudos emit contents, others don't. Set a
884 contents-emitted flag when we emit something into .text */
885 switch (instruction
->operands
)
887 case mmix_operands_loc
:
892 case mmix_operands_byte
:
897 case mmix_operands_wyde
:
902 case mmix_operands_tetra
:
907 case mmix_operands_octa
:
912 case mmix_operands_prefix
:
917 case mmix_operands_local
:
922 case mmix_operands_bspec
:
927 case mmix_operands_espec
:
933 BAD_CASE (instruction
->operands
);
936 /* These are all working like the pseudo functions in read.c:s_...,
937 in that they step over the end-of-line marker at the end of the
938 line. We don't want that here. */
939 input_line_pointer
--;
941 /* Step up the fb-label counter if there was a definition on this
943 if (current_fb_label
>= 0)
945 fb_label_instance_inc (current_fb_label
);
946 current_fb_label
= -1;
949 /* Reset any don't-align-next-datum request, unless this was a LOC
951 if (instruction
->operands
!= mmix_operands_loc
)
957 /* Not a pseudo; we *will* emit contents. */
958 if (now_seg
== data_section
)
960 if (lowest_data_loc
!= (bfd_vma
) -1 && (lowest_data_loc
& 3) != 0)
962 if (data_has_contents
)
963 as_bad (_("specified location wasn't TETRA-aligned"));
964 else if (want_unaligned
)
965 as_bad (_("unaligned data at an absolute location is not supported"));
967 lowest_data_loc
&= ~(bfd_vma
) 3;
968 lowest_data_loc
+= 4;
971 data_has_contents
= 1;
973 else if (now_seg
== text_section
)
975 if (lowest_text_loc
!= (bfd_vma
) -1 && (lowest_text_loc
& 3) != 0)
977 if (text_has_contents
)
978 as_bad (_("specified location wasn't TETRA-aligned"));
979 else if (want_unaligned
)
980 as_bad (_("unaligned data at an absolute location is not supported"));
982 lowest_text_loc
&= ~(bfd_vma
) 3;
983 lowest_text_loc
+= 4;
986 text_has_contents
= 1;
989 /* After a sequence of BYTEs or WYDEs, we need to get to instruction
990 alignment. For other pseudos, a ".p2align 2" is supposed to be
991 inserted by the user. */
992 if (last_alignment
< 2 && ! want_unaligned
)
994 frag_align (2, 0, 0);
995 record_alignment (now_seg
, 2);
999 /* Reset any don't-align-next-datum request. */
1002 /* For mmixal compatibility, a label for an instruction (and emitting
1003 pseudo) refers to the _aligned_ address. So we have to emit the
1005 if (pending_label
!= NULL
)
1007 colon (pending_label
);
1008 pending_label
= NULL
;
1011 /* We assume that mmix_opcodes keeps having unique mnemonics for each
1012 opcode, so we don't have to iterate over more than one opcode; if the
1013 syntax does not match, then there's a syntax error. */
1015 /* Operands have little or no context and are all comma-separated; it is
1016 easier to parse each expression first. */
1017 switch (instruction
->operands
)
1019 case mmix_operands_reg_yz
:
1020 case mmix_operands_pop
:
1021 case mmix_operands_regaddr
:
1022 case mmix_operands_pushj
:
1023 case mmix_operands_get
:
1024 case mmix_operands_put
:
1025 case mmix_operands_set
:
1026 case mmix_operands_save
:
1027 case mmix_operands_unsave
:
1031 case mmix_operands_sync
:
1032 case mmix_operands_jmp
:
1033 case mmix_operands_resume
:
1037 /* The original 3 is fine for the rest. */
1042 /* If this is GET or PUT, and we don't do allow those names to be
1043 equated, we need to parse the names ourselves, so we don't pick up a
1044 user label instead of the special register. */
1045 if (! equated_spec_regs
1046 && (instruction
->operands
== mmix_operands_get
1047 || instruction
->operands
== mmix_operands_put
))
1048 n_operands
= get_putget_operands (instruction
, operands
, exp
);
1050 n_operands
= get_operands (max_operands
, operands
, exp
);
1052 /* If there's a fb-label on the current line, set that label. This must
1053 be done *after* evaluating expressions of operands, since neither a
1054 "1B" nor a "1F" refers to "1H" on the same line. */
1055 if (current_fb_label
>= 0)
1057 fb_label_instance_inc (current_fb_label
);
1058 colon (fb_label_name (current_fb_label
, 0));
1059 current_fb_label
= -1;
1062 /* We also assume that the length of the instruction is at least 4, the
1063 size of an unexpanded instruction. We need a self-contained frag
1064 since we want the relocation to point to the instruction, not the
1067 opcodep
= frag_more (4);
1068 mmix_opcode_frag
= opc_fragP
= frag_now
;
1069 frag_now
->fr_opcode
= opcodep
;
1071 /* Mark start of insn for DWARF2 debug features. */
1072 if (OUTPUT_FLAVOR
== bfd_target_elf_flavour
)
1073 dwarf2_emit_insn (4);
1075 md_number_to_chars (opcodep
, instruction
->match
, 4);
1077 switch (instruction
->operands
)
1079 case mmix_operands_jmp
:
1080 if (n_operands
== 0 && ! mmix_gnu_syntax
)
1081 /* Zeros are in place - nothing needs to be done when we have no
1085 /* Add a frag for a JMP relaxation; we need room for max four
1086 extra instructions. We don't do any work around here to check if
1087 we can determine the offset right away. */
1088 if (n_operands
!= 1 || exp
[0].X_op
== O_register
)
1090 as_bad (_("invalid operand to opcode %s: `%s'"),
1091 instruction
->name
, operands
);
1096 frag_var (rs_machine_dependent
, 4 * 4, 0,
1097 ENCODE_RELAX (STATE_JMP
, STATE_UNDF
),
1098 exp
[0].X_add_symbol
,
1099 exp
[0].X_add_number
,
1102 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
, 4,
1103 exp
+ 0, 1, BFD_RELOC_MMIX_ADDR27
);
1106 case mmix_operands_pushj
:
1107 /* We take care of PUSHJ in full here. */
1109 || ((exp
[0].X_op
== O_constant
|| exp
[0].X_op
== O_register
)
1110 && (exp
[0].X_add_number
> 255 || exp
[0].X_add_number
< 0)))
1112 as_bad (_("invalid operands to opcode %s: `%s'"),
1113 instruction
->name
, operands
);
1117 if (exp
[0].X_op
== O_register
|| exp
[0].X_op
== O_constant
)
1118 opcodep
[1] = exp
[0].X_add_number
;
1120 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 1,
1121 1, exp
+ 0, 0, BFD_RELOC_MMIX_REG_OR_BYTE
);
1124 frag_var (rs_machine_dependent
, PUSHJ_MAX_LEN
- 4, 0,
1125 ENCODE_RELAX (STATE_PUSHJ
, STATE_UNDF
),
1126 exp
[1].X_add_symbol
,
1127 exp
[1].X_add_number
,
1130 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
, 4,
1131 exp
+ 1, 1, BFD_RELOC_MMIX_ADDR19
);
1134 case mmix_operands_regaddr
:
1135 /* GETA/branch: Add a frag for relaxation. We don't do any work
1136 around here to check if we can determine the offset right away. */
1137 if (n_operands
!= 2 || exp
[1].X_op
== O_register
)
1139 as_bad (_("invalid operands to opcode %s: `%s'"),
1140 instruction
->name
, operands
);
1145 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
, 4,
1146 exp
+ 1, 1, BFD_RELOC_MMIX_ADDR19
);
1147 else if (instruction
->type
== mmix_type_condbranch
)
1148 frag_var (rs_machine_dependent
, BCC_MAX_LEN
- 4, 0,
1149 ENCODE_RELAX (STATE_BCC
, STATE_UNDF
),
1150 exp
[1].X_add_symbol
,
1151 exp
[1].X_add_number
,
1154 frag_var (rs_machine_dependent
, GETA_MAX_LEN
- 4, 0,
1155 ENCODE_RELAX (STATE_GETA
, STATE_UNDF
),
1156 exp
[1].X_add_symbol
,
1157 exp
[1].X_add_number
,
1165 switch (instruction
->operands
)
1167 case mmix_operands_regs
:
1168 /* We check the number of operands here, since we're in a
1169 FALLTHROUGH sequence in the next switch. */
1170 if (n_operands
!= 3 || exp
[2].X_op
== O_constant
)
1172 as_bad (_("invalid operands to opcode %s: `%s'"),
1173 instruction
->name
, operands
);
1177 case mmix_operands_regs_z
:
1178 if (n_operands
!= 3)
1180 as_bad (_("invalid operands to opcode %s: `%s'"),
1181 instruction
->name
, operands
);
1185 case mmix_operands_reg_yz
:
1186 case mmix_operands_roundregs_z
:
1187 case mmix_operands_roundregs
:
1188 case mmix_operands_regs_z_opt
:
1189 case mmix_operands_neg
:
1190 case mmix_operands_regaddr
:
1191 case mmix_operands_get
:
1192 case mmix_operands_set
:
1193 case mmix_operands_save
:
1195 || (exp
[0].X_op
== O_register
&& exp
[0].X_add_number
> 255))
1197 as_bad (_("invalid operands to opcode %s: `%s'"),
1198 instruction
->name
, operands
);
1202 if (exp
[0].X_op
== O_register
)
1203 opcodep
[1] = exp
[0].X_add_number
;
1205 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 1,
1206 1, exp
+ 0, 0, BFD_RELOC_MMIX_REG
);
1213 /* A corresponding once-over for those who take an 8-bit constant as
1214 their first operand. */
1215 switch (instruction
->operands
)
1217 case mmix_operands_pushgo
:
1218 /* PUSHGO: X is a constant, but can be expressed as a register.
1219 We handle X here and use the common machinery of T,X,3,$ for
1220 the rest of the operands. */
1222 || ((exp
[0].X_op
== O_constant
|| exp
[0].X_op
== O_register
)
1223 && (exp
[0].X_add_number
> 255 || exp
[0].X_add_number
< 0)))
1225 as_bad (_("invalid operands to opcode %s: `%s'"),
1226 instruction
->name
, operands
);
1229 else if (exp
[0].X_op
== O_constant
|| exp
[0].X_op
== O_register
)
1230 opcodep
[1] = exp
[0].X_add_number
;
1232 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 1,
1233 1, exp
+ 0, 0, BFD_RELOC_MMIX_REG_OR_BYTE
);
1236 case mmix_operands_pop
:
1237 if ((n_operands
== 0 || n_operands
== 1) && ! mmix_gnu_syntax
)
1240 case mmix_operands_x_regs_z
:
1242 || (exp
[0].X_op
== O_constant
1243 && (exp
[0].X_add_number
> 255
1244 || exp
[0].X_add_number
< 0)))
1246 as_bad (_("invalid operands to opcode %s: `%s'"),
1247 instruction
->name
, operands
);
1251 if (exp
[0].X_op
== O_constant
)
1252 opcodep
[1] = exp
[0].X_add_number
;
1254 /* FIXME: This doesn't bring us unsignedness checking. */
1255 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 1,
1256 1, exp
+ 0, 0, BFD_RELOC_8
);
1261 /* Handle the rest. */
1262 switch (instruction
->operands
)
1264 case mmix_operands_set
:
1265 /* SET: Either two registers, "$X,$Y", with Z field as zero, or
1266 "$X,YZ", meaning change the opcode to SETL. */
1268 || (exp
[1].X_op
== O_constant
1269 && (exp
[1].X_add_number
> 0xffff || exp
[1].X_add_number
< 0)))
1271 as_bad (_("invalid operands to opcode %s: `%s'"),
1272 instruction
->name
, operands
);
1276 if (exp
[1].X_op
== O_constant
)
1278 /* There's an ambiguity with "SET $0,Y" when Y isn't defined
1279 yet. To keep things simple, we assume that Y is then a
1280 register, and only change the opcode if Y is defined at this
1283 There's no compatibility problem with mmixal, since it emits
1284 errors if the field is not defined at this point. */
1285 md_number_to_chars (opcodep
, SETL_INSN_BYTE
, 1);
1287 opcodep
[2] = (exp
[1].X_add_number
>> 8) & 255;
1288 opcodep
[3] = exp
[1].X_add_number
& 255;
1292 case mmix_operands_x_regs_z
:
1293 /* SYNCD: "X,$Y,$Z|Z". */
1295 case mmix_operands_regs
:
1296 /* Three registers, $X,$Y,$Z. */
1298 case mmix_operands_regs_z
:
1299 /* Operands "$X,$Y,$Z|Z", number of arguments checked above. */
1301 case mmix_operands_pushgo
:
1302 /* Operands "$X|X,$Y,$Z|Z", optional Z. */
1304 case mmix_operands_regs_z_opt
:
1305 /* Operands "$X,$Y,$Z|Z", with $Z|Z being optional, default 0. Any
1306 operands not completely decided yet are postponed to later in
1307 assembly (but not until link-time yet). */
1309 if ((n_operands
!= 2 && n_operands
!= 3)
1310 || (exp
[1].X_op
== O_register
&& exp
[1].X_add_number
> 255)
1312 && ((exp
[2].X_op
== O_register
1313 && exp
[2].X_add_number
> 255
1315 || (exp
[2].X_op
== O_constant
1316 && (exp
[2].X_add_number
> 255
1317 || exp
[2].X_add_number
< 0)))))
1319 as_bad (_("invalid operands to opcode %s: `%s'"),
1320 instruction
->name
, operands
);
1324 if (n_operands
== 2)
1328 /* The last operand is immediate whenever we see just two
1330 opcodep
[0] |= IMM_OFFSET_BIT
;
1332 /* Now, we could either have an implied "0" as the Z operand, or
1333 it could be the constant of a "base address plus offset". It
1334 depends on whether it is allowed; only memory operations, as
1335 signified by instruction->type and "T" and "X" operand types,
1336 and it depends on whether we find a register in the second
1338 if (exp
[1].X_op
== O_register
&& exp
[1].X_add_number
<= 255)
1340 /* A zero then; all done. */
1341 opcodep
[2] = exp
[1].X_add_number
;
1345 /* Not known as a register. Is base address plus offset
1346 allowed, or can we assume that it is a register anyway? */
1347 if ((instruction
->operands
!= mmix_operands_regs_z_opt
1348 && instruction
->operands
!= mmix_operands_x_regs_z
1349 && instruction
->operands
!= mmix_operands_pushgo
)
1350 || (instruction
->type
!= mmix_type_memaccess_octa
1351 && instruction
->type
!= mmix_type_memaccess_tetra
1352 && instruction
->type
!= mmix_type_memaccess_wyde
1353 && instruction
->type
!= mmix_type_memaccess_byte
1354 && instruction
->type
!= mmix_type_memaccess_block
1355 && instruction
->type
!= mmix_type_jsr
1356 && instruction
->type
!= mmix_type_branch
))
1358 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 2,
1359 1, exp
+ 1, 0, BFD_RELOC_MMIX_REG
);
1363 /* To avoid getting a NULL add_symbol for constants and then
1364 catching a SEGV in write_relocs since it doesn't handle
1365 constants well for relocs other than PC-relative, we need to
1366 pass expressions as symbols and use fix_new, not fix_new_exp. */
1367 sym
= make_expr_symbol (exp
+ 1);
1369 /* Now we know it can be a "base address plus offset". Add
1370 proper fixup types so we can handle this later, when we've
1371 parsed everything. */
1372 fix_new (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 2,
1373 8, sym
, 0, 0, BFD_RELOC_MMIX_BASE_PLUS_OFFSET
);
1377 if (exp
[1].X_op
== O_register
)
1378 opcodep
[2] = exp
[1].X_add_number
;
1380 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 2,
1381 1, exp
+ 1, 0, BFD_RELOC_MMIX_REG
);
1383 /* In mmixal compatibility mode, we allow special registers as
1384 constants for the Z operand. They have 256 added to their
1385 register numbers, so the right thing will happen if we just treat
1386 those as constants. */
1387 if (exp
[2].X_op
== O_register
&& exp
[2].X_add_number
<= 255)
1388 opcodep
[3] = exp
[2].X_add_number
;
1389 else if (exp
[2].X_op
== O_constant
1390 || (exp
[2].X_op
== O_register
&& exp
[2].X_add_number
> 255))
1392 opcodep
[3] = exp
[2].X_add_number
;
1393 opcodep
[0] |= IMM_OFFSET_BIT
;
1396 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 3,
1398 (instruction
->operands
== mmix_operands_set
1399 || instruction
->operands
== mmix_operands_regs
)
1400 ? BFD_RELOC_MMIX_REG
: BFD_RELOC_MMIX_REG_OR_BYTE
);
1403 case mmix_operands_pop
:
1404 /* POP, one eight and one 16-bit operand. */
1405 if (n_operands
== 0 && ! mmix_gnu_syntax
)
1407 if (n_operands
== 1 && ! mmix_gnu_syntax
)
1408 goto a_single_24_bit_number_operand
;
1410 case mmix_operands_reg_yz
:
1411 /* A register and a 16-bit unsigned number. */
1413 || exp
[1].X_op
== O_register
1414 || (exp
[1].X_op
== O_constant
1415 && (exp
[1].X_add_number
> 0xffff || exp
[1].X_add_number
< 0)))
1417 as_bad (_("invalid operands to opcode %s: `%s'"),
1418 instruction
->name
, operands
);
1422 if (exp
[1].X_op
== O_constant
)
1424 opcodep
[2] = (exp
[1].X_add_number
>> 8) & 255;
1425 opcodep
[3] = exp
[1].X_add_number
& 255;
1428 /* FIXME: This doesn't bring us unsignedness checking. */
1429 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 2,
1430 2, exp
+ 1, 0, BFD_RELOC_16
);
1433 case mmix_operands_jmp
:
1434 /* A JMP. Everything is already done. */
1437 case mmix_operands_roundregs
:
1438 /* Two registers with optional rounding mode or constant in between. */
1439 if ((n_operands
== 3 && exp
[2].X_op
== O_constant
)
1440 || (n_operands
== 2 && exp
[1].X_op
== O_constant
))
1442 as_bad (_("invalid operands to opcode %s: `%s'"),
1443 instruction
->name
, operands
);
1447 case mmix_operands_roundregs_z
:
1448 /* Like FLOT, "$X,ROUND_MODE,$Z|Z", but the rounding mode is
1449 optional and can be the corresponding constant. */
1451 /* Which exp index holds the second operand (not the rounding
1453 int op2no
= n_operands
- 1;
1455 if ((n_operands
!= 2 && n_operands
!= 3)
1456 || ((exp
[op2no
].X_op
== O_register
1457 && exp
[op2no
].X_add_number
> 255)
1458 || (exp
[op2no
].X_op
== O_constant
1459 && (exp
[op2no
].X_add_number
> 255
1460 || exp
[op2no
].X_add_number
< 0)))
1462 /* We don't allow for the rounding mode to be deferred; it
1463 must be determined in the "first pass". It cannot be a
1464 symbol equated to a rounding mode, but defined after
1466 && ((exp
[1].X_op
== O_register
1467 && exp
[1].X_add_number
< 512)
1468 || (exp
[1].X_op
== O_constant
1469 && exp
[1].X_add_number
< 0
1470 && exp
[1].X_add_number
> 4)
1471 || (exp
[1].X_op
!= O_register
1472 && exp
[1].X_op
!= O_constant
))))
1474 as_bad (_("invalid operands to opcode %s: `%s'"),
1475 instruction
->name
, operands
);
1479 /* Add rounding mode if present. */
1480 if (n_operands
== 3)
1481 opcodep
[2] = exp
[1].X_add_number
& 255;
1483 if (exp
[op2no
].X_op
== O_register
)
1484 opcodep
[3] = exp
[op2no
].X_add_number
;
1485 else if (exp
[op2no
].X_op
== O_constant
)
1487 opcodep
[3] = exp
[op2no
].X_add_number
;
1488 opcodep
[0] |= IMM_OFFSET_BIT
;
1491 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 3,
1493 instruction
->operands
== mmix_operands_roundregs
1494 ? BFD_RELOC_MMIX_REG
1495 : BFD_RELOC_MMIX_REG_OR_BYTE
);
1499 case mmix_operands_sync
:
1500 a_single_24_bit_number_operand
:
1502 || exp
[0].X_op
== O_register
1503 || (exp
[0].X_op
== O_constant
1504 && (exp
[0].X_add_number
> 0xffffff || exp
[0].X_add_number
< 0)))
1506 as_bad (_("invalid operands to opcode %s: `%s'"),
1507 instruction
->name
, operands
);
1511 if (exp
[0].X_op
== O_constant
)
1513 opcodep
[1] = (exp
[0].X_add_number
>> 16) & 255;
1514 opcodep
[2] = (exp
[0].X_add_number
>> 8) & 255;
1515 opcodep
[3] = exp
[0].X_add_number
& 255;
1518 /* FIXME: This doesn't bring us unsignedness checking. */
1519 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 1,
1520 3, exp
+ 0, 0, BFD_RELOC_24
);
1523 case mmix_operands_neg
:
1524 /* Operands "$X,Y,$Z|Z"; NEG or NEGU. Y is optional, 0 is default. */
1526 if ((n_operands
!= 3 && n_operands
!= 2)
1527 || (n_operands
== 3 && exp
[1].X_op
== O_register
)
1528 || ((exp
[1].X_op
== O_constant
|| exp
[1].X_op
== O_register
)
1529 && (exp
[1].X_add_number
> 255 || exp
[1].X_add_number
< 0))
1531 && ((exp
[2].X_op
== O_register
&& exp
[2].X_add_number
> 255)
1532 || (exp
[2].X_op
== O_constant
1533 && (exp
[2].X_add_number
> 255
1534 || exp
[2].X_add_number
< 0)))))
1536 as_bad (_("invalid operands to opcode %s: `%s'"),
1537 instruction
->name
, operands
);
1541 if (n_operands
== 2)
1543 if (exp
[1].X_op
== O_register
)
1544 opcodep
[3] = exp
[1].X_add_number
;
1545 else if (exp
[1].X_op
== O_constant
)
1547 opcodep
[3] = exp
[1].X_add_number
;
1548 opcodep
[0] |= IMM_OFFSET_BIT
;
1551 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 3,
1552 1, exp
+ 1, 0, BFD_RELOC_MMIX_REG_OR_BYTE
);
1556 if (exp
[1].X_op
== O_constant
)
1557 opcodep
[2] = exp
[1].X_add_number
;
1559 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 2,
1560 1, exp
+ 1, 0, BFD_RELOC_8
);
1562 if (exp
[2].X_op
== O_register
)
1563 opcodep
[3] = exp
[2].X_add_number
;
1564 else if (exp
[2].X_op
== O_constant
)
1566 opcodep
[3] = exp
[2].X_add_number
;
1567 opcodep
[0] |= IMM_OFFSET_BIT
;
1570 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 3,
1571 1, exp
+ 2, 0, BFD_RELOC_MMIX_REG_OR_BYTE
);
1574 case mmix_operands_regaddr
:
1575 /* A GETA/branch-type. */
1578 case mmix_operands_get
:
1579 /* "$X,spec_reg"; GET.
1580 Like with rounding modes, we demand that the special register or
1581 symbol is already defined when we get here at the point of use. */
1583 || (exp
[1].X_op
== O_register
1584 && (exp
[1].X_add_number
< 256 || exp
[1].X_add_number
>= 512))
1585 || (exp
[1].X_op
== O_constant
1586 && (exp
[1].X_add_number
< 0 || exp
[1].X_add_number
> 256))
1587 || (exp
[1].X_op
!= O_constant
&& exp
[1].X_op
!= O_register
))
1589 as_bad (_("invalid operands to opcode %s: `%s'"),
1590 instruction
->name
, operands
);
1594 opcodep
[3] = exp
[1].X_add_number
- 256;
1597 case mmix_operands_put
:
1598 /* "spec_reg,$Z|Z"; PUT. */
1600 || (exp
[0].X_op
== O_register
1601 && (exp
[0].X_add_number
< 256 || exp
[0].X_add_number
>= 512))
1602 || (exp
[0].X_op
== O_constant
1603 && (exp
[0].X_add_number
< 0 || exp
[0].X_add_number
> 256))
1604 || (exp
[0].X_op
!= O_constant
&& exp
[0].X_op
!= O_register
))
1606 as_bad (_("invalid operands to opcode %s: `%s'"),
1607 instruction
->name
, operands
);
1611 opcodep
[1] = exp
[0].X_add_number
- 256;
1613 /* Note that the Y field is zero. */
1615 if (exp
[1].X_op
== O_register
)
1616 opcodep
[3] = exp
[1].X_add_number
;
1617 else if (exp
[1].X_op
== O_constant
)
1619 opcodep
[3] = exp
[1].X_add_number
;
1620 opcodep
[0] |= IMM_OFFSET_BIT
;
1623 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 3,
1624 1, exp
+ 1, 0, BFD_RELOC_MMIX_REG_OR_BYTE
);
1627 case mmix_operands_save
:
1630 || exp
[1].X_op
!= O_constant
1631 || exp
[1].X_add_number
!= 0)
1633 as_bad (_("invalid operands to opcode %s: `%s'"),
1634 instruction
->name
, operands
);
1639 case mmix_operands_unsave
:
1640 if (n_operands
< 2 && ! mmix_gnu_syntax
)
1642 if (n_operands
== 1)
1644 if (exp
[0].X_op
== O_register
)
1645 opcodep
[3] = exp
[0].X_add_number
;
1647 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 3,
1648 1, exp
, 0, BFD_RELOC_MMIX_REG
);
1653 /* "0,$Z"; UNSAVE. */
1655 || exp
[0].X_op
!= O_constant
1656 || exp
[0].X_add_number
!= 0
1657 || exp
[1].X_op
== O_constant
1658 || (exp
[1].X_op
== O_register
1659 && exp
[1].X_add_number
> 255))
1661 as_bad (_("invalid operands to opcode %s: `%s'"),
1662 instruction
->name
, operands
);
1666 if (exp
[1].X_op
== O_register
)
1667 opcodep
[3] = exp
[1].X_add_number
;
1669 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 3,
1670 1, exp
+ 1, 0, BFD_RELOC_MMIX_REG
);
1673 case mmix_operands_xyz_opt
:
1674 /* SWYM, TRIP, TRAP: zero, one, two or three operands. */
1675 if (n_operands
== 0 && ! mmix_gnu_syntax
)
1676 /* Zeros are in place - nothing needs to be done for zero
1677 operands. We don't allow this in GNU syntax mode, because it
1678 was believed that the risk of missing to supply an operand is
1679 higher than the benefit of not having to specify a zero. */
1681 else if (n_operands
== 1 && exp
[0].X_op
!= O_register
)
1683 if (exp
[0].X_op
== O_constant
)
1685 if (exp
[0].X_add_number
> 255*255*255
1686 || exp
[0].X_add_number
< 0)
1688 as_bad (_("invalid operands to opcode %s: `%s'"),
1689 instruction
->name
, operands
);
1694 opcodep
[1] = (exp
[0].X_add_number
>> 16) & 255;
1695 opcodep
[2] = (exp
[0].X_add_number
>> 8) & 255;
1696 opcodep
[3] = exp
[0].X_add_number
& 255;
1700 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 1,
1701 3, exp
, 0, BFD_RELOC_24
);
1703 else if (n_operands
== 2
1704 && exp
[0].X_op
!= O_register
1705 && exp
[1].X_op
!= O_register
)
1709 if (exp
[0].X_op
== O_constant
)
1711 if (exp
[0].X_add_number
> 255
1712 || exp
[0].X_add_number
< 0)
1714 as_bad (_("invalid operands to opcode %s: `%s'"),
1715 instruction
->name
, operands
);
1719 opcodep
[1] = exp
[0].X_add_number
& 255;
1722 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 1,
1723 1, exp
, 0, BFD_RELOC_8
);
1725 if (exp
[1].X_op
== O_constant
)
1727 if (exp
[1].X_add_number
> 255*255
1728 || exp
[1].X_add_number
< 0)
1730 as_bad (_("invalid operands to opcode %s: `%s'"),
1731 instruction
->name
, operands
);
1736 opcodep
[2] = (exp
[1].X_add_number
>> 8) & 255;
1737 opcodep
[3] = exp
[1].X_add_number
& 255;
1741 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 2,
1742 2, exp
+ 1, 0, BFD_RELOC_16
);
1744 else if (n_operands
== 3
1745 && exp
[0].X_op
!= O_register
1746 && exp
[1].X_op
!= O_register
1747 && exp
[2].X_op
!= O_register
)
1749 /* Three operands. */
1751 if (exp
[0].X_op
== O_constant
)
1753 if (exp
[0].X_add_number
> 255
1754 || exp
[0].X_add_number
< 0)
1756 as_bad (_("invalid operands to opcode %s: `%s'"),
1757 instruction
->name
, operands
);
1761 opcodep
[1] = exp
[0].X_add_number
& 255;
1764 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 1,
1765 1, exp
, 0, BFD_RELOC_8
);
1767 if (exp
[1].X_op
== O_constant
)
1769 if (exp
[1].X_add_number
> 255
1770 || exp
[1].X_add_number
< 0)
1772 as_bad (_("invalid operands to opcode %s: `%s'"),
1773 instruction
->name
, operands
);
1777 opcodep
[2] = exp
[1].X_add_number
& 255;
1780 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 2,
1781 1, exp
+ 1, 0, BFD_RELOC_8
);
1783 if (exp
[2].X_op
== O_constant
)
1785 if (exp
[2].X_add_number
> 255
1786 || exp
[2].X_add_number
< 0)
1788 as_bad (_("invalid operands to opcode %s: `%s'"),
1789 instruction
->name
, operands
);
1793 opcodep
[3] = exp
[2].X_add_number
& 255;
1796 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 3,
1797 1, exp
+ 2, 0, BFD_RELOC_8
);
1799 else if (n_operands
<= 3
1800 && (strcmp (instruction
->name
, "trip") == 0
1801 || strcmp (instruction
->name
, "trap") == 0))
1803 /* The meaning of operands to TRIP and TRAP are not defined, so
1804 we add combinations not handled above here as we find them. */
1805 if (n_operands
== 3)
1807 /* Don't require non-register operands. Always generate
1808 fixups, so we don't have to copy lots of code and create
1809 maintenance problems. TRIP is supposed to be a rare
1810 instruction, so the overhead should not matter. We
1811 aren't allowed to fix_new_exp for an expression which is
1812 an O_register at this point, however. */
1813 if (exp
[0].X_op
== O_register
)
1814 opcodep
[1] = exp
[0].X_add_number
;
1816 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 1,
1817 1, exp
, 0, BFD_RELOC_MMIX_REG_OR_BYTE
);
1818 if (exp
[1].X_op
== O_register
)
1819 opcodep
[2] = exp
[1].X_add_number
;
1821 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 2,
1822 1, exp
+ 1, 0, BFD_RELOC_MMIX_REG_OR_BYTE
);
1823 if (exp
[2].X_op
== O_register
)
1824 opcodep
[3] = exp
[2].X_add_number
;
1826 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 3,
1827 1, exp
+ 2, 0, BFD_RELOC_MMIX_REG_OR_BYTE
);
1829 else if (n_operands
== 2)
1831 if (exp
[0].X_op
== O_register
)
1832 opcodep
[2] = exp
[0].X_add_number
;
1834 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 2,
1835 1, exp
, 0, BFD_RELOC_MMIX_REG_OR_BYTE
);
1836 if (exp
[1].X_op
== O_register
)
1837 opcodep
[3] = exp
[1].X_add_number
;
1839 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 3,
1840 1, exp
+ 1, 0, BFD_RELOC_MMIX_REG_OR_BYTE
);
1844 as_bad (_("unsupported operands to %s: `%s'"),
1845 instruction
->name
, operands
);
1851 as_bad (_("invalid operands to opcode %s: `%s'"),
1852 instruction
->name
, operands
);
1857 case mmix_operands_resume
:
1858 if (n_operands
== 0 && ! mmix_gnu_syntax
)
1862 || exp
[0].X_op
== O_register
1863 || (exp
[0].X_op
== O_constant
1864 && (exp
[0].X_add_number
< 0
1865 || exp
[0].X_add_number
> 255)))
1867 as_bad (_("invalid operands to opcode %s: `%s'"),
1868 instruction
->name
, operands
);
1872 if (exp
[0].X_op
== O_constant
)
1873 opcodep
[3] = exp
[0].X_add_number
;
1875 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 3,
1876 1, exp
+ 0, 0, BFD_RELOC_8
);
1879 case mmix_operands_pushj
:
1880 /* All is done for PUSHJ already. */
1884 BAD_CASE (instruction
->operands
);
1888 /* For the benefit of insns that start with a digit, we assemble by way of
1889 tc_unrecognized_line too, through this function. */
1892 mmix_assemble_return_nonzero (char *str
)
1894 int last_error_count
= had_errors ();
1898 /* Normal instruction handling downcases, so we must too. */
1899 while (ISALNUM (*s2
))
1901 if (ISUPPER ((unsigned char) *s2
))
1902 *s2
= TOLOWER (*s2
);
1906 /* Cut the line for sake of the assembly. */
1907 for (s2
= str
; *s2
&& *s2
!= '\n'; s2
++)
1915 return had_errors () == last_error_count
;
1918 /* The PREFIX pseudo. */
1921 s_prefix (int unused ATTRIBUTE_UNUSED
)
1928 p
= input_line_pointer
;
1930 c
= get_symbol_end ();
1932 /* Reseting prefix? */
1933 if (*p
== ':' && p
[1] == 0)
1934 mmix_current_prefix
= NULL
;
1937 /* Put this prefix on the mmix symbols obstack. We could malloc and
1938 free it separately, but then we'd have to worry about that.
1939 People using up memory on prefixes have other problems. */
1940 obstack_grow (&mmix_sym_obstack
, p
, strlen (p
) + 1);
1941 p
= obstack_finish (&mmix_sym_obstack
);
1943 /* Accumulate prefixes, and strip a leading ':'. */
1944 if (mmix_current_prefix
!= NULL
|| *p
== ':')
1945 p
= mmix_prefix_name (p
);
1947 mmix_current_prefix
= p
;
1950 *input_line_pointer
= c
;
1952 mmix_handle_rest_of_empty_line ();
1955 /* We implement prefixes by using the tc_canonicalize_symbol_name hook,
1956 and store each prefixed name on a (separate) obstack. This means that
1957 the name is on the "notes" obstack in non-prefixed form and on the
1958 mmix_sym_obstack in prefixed form, but currently it is not worth
1959 rewriting the whole GAS symbol handling to improve "hooking" to avoid
1960 that. (It might be worth a rewrite for other reasons, though). */
1963 mmix_prefix_name (char *shortname
)
1965 if (*shortname
== ':')
1966 return shortname
+ 1;
1968 if (mmix_current_prefix
== NULL
)
1969 as_fatal (_("internal: mmix_prefix_name but empty prefix"));
1971 if (*shortname
== '$')
1974 obstack_grow (&mmix_sym_obstack
, mmix_current_prefix
,
1975 strlen (mmix_current_prefix
));
1976 obstack_grow (&mmix_sym_obstack
, shortname
, strlen (shortname
) + 1);
1977 return obstack_finish (&mmix_sym_obstack
);
1980 /* The GREG pseudo. At LABEL, we have the name of a symbol that we
1981 want to make a register symbol, and which should be initialized with
1982 the value in the expression at INPUT_LINE_POINTER (defaulting to 0).
1983 Either and (perhaps less meaningful) both may be missing. LABEL must
1984 be persistent, perhaps allocated on an obstack. */
1987 mmix_greg_internal (char *label
)
1989 expressionS
*expP
= &mmix_raw_gregs
[n_of_raw_gregs
].exp
;
1991 /* Don't set the section to register contents section before the
1992 expression has been parsed; it may refer to the current position. */
1995 /* FIXME: Check that no expression refers to the register contents
1996 section. May need to be done in elf64-mmix.c. */
1997 if (expP
->X_op
== O_absent
)
1999 /* Default to zero if the expression was absent. */
2000 expP
->X_op
= O_constant
;
2001 expP
->X_add_number
= 0;
2002 expP
->X_unsigned
= 0;
2003 expP
->X_add_symbol
= NULL
;
2004 expP
->X_op_symbol
= NULL
;
2007 /* We must handle prefixes here, as we save the labels and expressions
2008 to be output later. */
2009 mmix_raw_gregs
[n_of_raw_gregs
].label
2010 = mmix_current_prefix
== NULL
? label
: mmix_prefix_name (label
);
2012 if (n_of_raw_gregs
== MAX_GREGS
- 1)
2013 as_bad (_("too many GREG registers allocated (max %d)"), MAX_GREGS
);
2017 mmix_handle_rest_of_empty_line ();
2020 /* The ".greg label,expr" worker. */
2023 s_greg (int unused ATTRIBUTE_UNUSED
)
2027 p
= input_line_pointer
;
2029 /* This will skip over what can be a symbol and zero out the next
2030 character, which we assume is a ',' or other meaningful delimiter.
2031 What comes after that is the initializer expression for the
2033 c
= get_symbol_end ();
2035 if (! is_end_of_line
[(unsigned char) c
])
2036 input_line_pointer
++;
2040 /* The label must be persistent; it's not used until after all input
2042 obstack_grow (&mmix_sym_obstack
, p
, strlen (p
) + 1);
2043 mmix_greg_internal (obstack_finish (&mmix_sym_obstack
));
2046 mmix_greg_internal (NULL
);
2049 /* The "BSPEC expr" worker. */
2052 s_bspec (int unused ATTRIBUTE_UNUSED
)
2056 char secname
[sizeof (MMIX_OTHER_SPEC_SECTION_PREFIX
) + 20]
2057 = MMIX_OTHER_SPEC_SECTION_PREFIX
;
2061 /* Get a constant expression which we can evaluate *now*. Supporting
2062 more complex (though assembly-time computable) expressions is
2063 feasible but Too Much Work for something of unknown usefulness like
2065 expsec
= expression (&exp
);
2066 mmix_handle_rest_of_empty_line ();
2068 /* Check that we don't have another BSPEC in progress. */
2071 as_bad (_("BSPEC already active. Nesting is not supported."));
2075 if (exp
.X_op
!= O_constant
2076 || expsec
!= absolute_section
2077 || exp
.X_add_number
< 0
2078 || exp
.X_add_number
> 65535)
2080 as_bad (_("invalid BSPEC expression"));
2081 exp
.X_add_number
= 0;
2084 n
= (int) exp
.X_add_number
;
2086 sprintf (secname
+ strlen (MMIX_OTHER_SPEC_SECTION_PREFIX
), "%d", n
);
2087 sec
= bfd_get_section_by_name (stdoutput
, secname
);
2090 /* We need a non-volatile name as it will be stored in the section
2092 char *newsecname
= xstrdup (secname
);
2093 sec
= bfd_make_section (stdoutput
, newsecname
);
2096 as_fatal (_("can't create section %s"), newsecname
);
2098 if (!bfd_set_section_flags (stdoutput
, sec
,
2099 bfd_get_section_flags (stdoutput
, sec
)
2101 as_fatal (_("can't set section flags for section %s"), newsecname
);
2104 /* Tell ELF about the pending section change. */
2105 obj_elf_section_change_hook ();
2106 subseg_set (sec
, 0);
2108 /* Save position for missing ESPEC. */
2109 as_where (&bspec_file
, &bspec_line
);
2114 /* The "ESPEC" worker. */
2117 s_espec (int unused ATTRIBUTE_UNUSED
)
2119 /* First, check that we *do* have a BSPEC in progress. */
2122 as_bad (_("ESPEC without preceding BSPEC"));
2126 mmix_handle_rest_of_empty_line ();
2129 /* When we told ELF about the section change in s_bspec, it stored the
2130 previous section for us so we can get at it with the equivalent of a
2131 .previous pseudo. */
2132 obj_elf_previous (0);
2135 /* The " .local expr" and " local expr" worker. We make a BFD_MMIX_LOCAL
2136 relocation against the current position against the expression.
2137 Implementing this by means of contents in a section lost. */
2140 mmix_s_local (int unused ATTRIBUTE_UNUSED
)
2144 /* Don't set the section to register contents section before the
2145 expression has been parsed; it may refer to the current position in
2146 some contorted way. */
2149 if (exp
.X_op
== O_absent
)
2151 as_bad (_("missing local expression"));
2154 else if (exp
.X_op
== O_register
)
2156 /* fix_new_exp doesn't like O_register. Should be configurable.
2157 We're fine with a constant here, though. */
2158 exp
.X_op
= O_constant
;
2161 fix_new_exp (frag_now
, 0, 0, &exp
, 0, BFD_RELOC_MMIX_LOCAL
);
2162 mmix_handle_rest_of_empty_line ();
2165 /* Set fragP->fr_var to the initial guess of the size of a relaxable insn
2166 and return it. Sizes of other instructions are not known. This
2167 function may be called multiple times. */
2170 md_estimate_size_before_relax (fragS
*fragP
, segT segment
)
2174 #define HANDLE_RELAXABLE(state) \
2175 case ENCODE_RELAX (state, STATE_UNDF): \
2176 if (fragP->fr_symbol != NULL \
2177 && S_GET_SEGMENT (fragP->fr_symbol) == segment \
2178 && !S_IS_WEAK (fragP->fr_symbol)) \
2180 /* The symbol lies in the same segment - a relaxable case. */ \
2182 = ENCODE_RELAX (state, STATE_ZERO); \
2186 switch (fragP
->fr_subtype
)
2188 HANDLE_RELAXABLE (STATE_GETA
);
2189 HANDLE_RELAXABLE (STATE_BCC
);
2190 HANDLE_RELAXABLE (STATE_JMP
);
2192 case ENCODE_RELAX (STATE_PUSHJ
, STATE_UNDF
):
2193 if (fragP
->fr_symbol
!= NULL
2194 && S_GET_SEGMENT (fragP
->fr_symbol
) == segment
2195 && !S_IS_WEAK (fragP
->fr_symbol
))
2196 /* The symbol lies in the same segment - a relaxable case. */
2197 fragP
->fr_subtype
= ENCODE_RELAX (STATE_PUSHJ
, STATE_ZERO
);
2198 else if (pushj_stubs
)
2199 /* If we're to generate stubs, assume we can reach a stub after
2201 fragP
->fr_subtype
= ENCODE_RELAX (STATE_PUSHJSTUB
, STATE_ZERO
);
2203 case ENCODE_RELAX (STATE_PUSHJ
, STATE_ZERO
):
2204 case ENCODE_RELAX (STATE_PUSHJSTUB
, STATE_ZERO
):
2205 /* We need to distinguish different relaxation rounds. */
2206 seg_info (segment
)->tc_segment_info_data
.last_stubfrag
= fragP
;
2209 case ENCODE_RELAX (STATE_GETA
, STATE_ZERO
):
2210 case ENCODE_RELAX (STATE_BCC
, STATE_ZERO
):
2211 case ENCODE_RELAX (STATE_JMP
, STATE_ZERO
):
2212 /* When relaxing a section for the second time, we don't need to do
2213 anything except making sure that fr_var is set right. */
2216 case STATE_GREG_DEF
:
2217 length
= fragP
->tc_frag_data
!= NULL
? 0 : 8;
2218 fragP
->fr_var
= length
;
2220 /* Don't consult the relax_table; it isn't valid for this
2226 BAD_CASE (fragP
->fr_subtype
);
2229 length
= mmix_relax_table
[fragP
->fr_subtype
].rlx_length
;
2230 fragP
->fr_var
= length
;
2235 /* Turn a string in input_line_pointer into a floating point constant of type
2236 type, and store the appropriate bytes in *litP. The number of LITTLENUMS
2237 emitted is stored in *sizeP . An error message is returned, or NULL on
2241 md_atof (int type
, char *litP
, int *sizeP
)
2244 LITTLENUM_TYPE words
[4];
2250 /* FIXME: Having 'f' in mmix_flt_chars (and here) makes it
2251 problematic to also have a forward reference in an expression.
2252 The testsuite wants it, and it's customary.
2253 We'll deal with the real problems when they come; we share the
2254 problem with most other ports. */
2264 return _("bad call to md_atof");
2267 t
= atof_ieee (input_line_pointer
, type
, words
);
2269 input_line_pointer
= t
;
2273 for (i
= 0; i
< prec
; i
++)
2275 md_number_to_chars (litP
, (valueT
) words
[i
], 2);
2281 /* Convert variable-sized frags into one or more fixups. */
2284 md_convert_frag (bfd
*abfd ATTRIBUTE_UNUSED
, segT sec ATTRIBUTE_UNUSED
,
2287 /* Pointer to first byte in variable-sized part of the frag. */
2290 /* Pointer to first opcode byte in frag. */
2293 /* Size in bytes of variable-sized part of frag. */
2294 int var_part_size
= 0;
2296 /* This is part of *fragP. It contains all information about addresses
2297 and offsets to varying parts. */
2299 unsigned long var_part_offset
;
2301 /* This is the frag for the opcode. It, rather than fragP, must be used
2302 when emitting a frag for the opcode. */
2303 fragS
*opc_fragP
= fragP
->tc_frag_data
;
2306 /* Where, in file space, does addr point? */
2307 bfd_vma target_address
;
2308 bfd_vma opcode_address
;
2310 know (fragP
->fr_type
== rs_machine_dependent
);
2312 var_part_offset
= fragP
->fr_fix
;
2313 var_partp
= fragP
->fr_literal
+ var_part_offset
;
2314 opcodep
= fragP
->fr_opcode
;
2316 symbolP
= fragP
->fr_symbol
;
2319 = ((symbolP
? S_GET_VALUE (symbolP
) : 0) + fragP
->fr_offset
);
2321 /* The opcode that would be extended is the last four "fixed" bytes. */
2322 opcode_address
= fragP
->fr_address
+ fragP
->fr_fix
- 4;
2324 switch (fragP
->fr_subtype
)
2326 case ENCODE_RELAX (STATE_PUSHJSTUB
, STATE_ZERO
):
2327 /* Setting the unknown bits to 0 seems the most appropriate. */
2328 mmix_set_geta_branch_offset (opcodep
, 0);
2329 tmpfixP
= fix_new (opc_fragP
, opcodep
- opc_fragP
->fr_literal
, 8,
2330 fragP
->fr_symbol
, fragP
->fr_offset
, 1,
2331 BFD_RELOC_MMIX_PUSHJ_STUBBABLE
);
2332 COPY_FR_WHERE_TO_FX (fragP
, tmpfixP
);
2336 case ENCODE_RELAX (STATE_GETA
, STATE_ZERO
):
2337 case ENCODE_RELAX (STATE_BCC
, STATE_ZERO
):
2338 case ENCODE_RELAX (STATE_PUSHJ
, STATE_ZERO
):
2339 mmix_set_geta_branch_offset (opcodep
, target_address
- opcode_address
);
2343 = fix_new (opc_fragP
, opcodep
- opc_fragP
->fr_literal
, 4,
2344 fragP
->fr_symbol
, fragP
->fr_offset
, 1,
2345 BFD_RELOC_MMIX_ADDR19
);
2346 COPY_FR_WHERE_TO_FX (fragP
, tmpfixP
);
2351 case ENCODE_RELAX (STATE_JMP
, STATE_ZERO
):
2352 mmix_set_jmp_offset (opcodep
, target_address
- opcode_address
);
2356 = fix_new (opc_fragP
, opcodep
- opc_fragP
->fr_literal
, 4,
2357 fragP
->fr_symbol
, fragP
->fr_offset
, 1,
2358 BFD_RELOC_MMIX_ADDR27
);
2359 COPY_FR_WHERE_TO_FX (fragP
, tmpfixP
);
2364 case STATE_GREG_DEF
:
2365 if (fragP
->tc_frag_data
== NULL
)
2367 /* We must initialize data that's supposed to be "fixed up" to
2368 avoid emitting garbage, because md_apply_fix3 won't do
2369 anything for undefined symbols. */
2370 md_number_to_chars (var_partp
, 0, 8);
2372 = fix_new (fragP
, var_partp
- fragP
->fr_literal
, 8,
2373 fragP
->fr_symbol
, fragP
->fr_offset
, 0, BFD_RELOC_64
);
2374 COPY_FR_WHERE_TO_FX (fragP
, tmpfixP
);
2375 mmix_gregs
[n_of_cooked_gregs
++] = tmpfixP
;
2382 #define HANDLE_MAX_RELOC(state, reloc) \
2383 case ENCODE_RELAX (state, STATE_MAX): \
2385 = mmix_relax_table[ENCODE_RELAX (state, STATE_MAX)].rlx_length; \
2386 mmix_fill_nops (var_partp, var_part_size / 4); \
2387 if (warn_on_expansion) \
2388 as_warn_where (fragP->fr_file, fragP->fr_line, \
2389 _("operand out of range, instruction expanded")); \
2390 tmpfixP = fix_new (fragP, var_partp - fragP->fr_literal - 4, 8, \
2391 fragP->fr_symbol, fragP->fr_offset, 1, reloc); \
2392 COPY_FR_WHERE_TO_FX (fragP, tmpfixP); \
2395 HANDLE_MAX_RELOC (STATE_GETA
, BFD_RELOC_MMIX_GETA
);
2396 HANDLE_MAX_RELOC (STATE_BCC
, BFD_RELOC_MMIX_CBRANCH
);
2397 HANDLE_MAX_RELOC (STATE_PUSHJ
, BFD_RELOC_MMIX_PUSHJ
);
2398 HANDLE_MAX_RELOC (STATE_JMP
, BFD_RELOC_MMIX_JMP
);
2401 BAD_CASE (fragP
->fr_subtype
);
2405 fragP
->fr_fix
+= var_part_size
;
2409 /* Applies the desired value to the specified location.
2410 Also sets up addends for RELA type relocations.
2411 Stolen from tc-mcore.c.
2413 Note that this function isn't called when linkrelax != 0. */
2416 md_apply_fix3 (fixS
*fixP
, valueT
*valP
, segT segment
)
2418 char *buf
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
2419 /* Note: use offsetT because it is signed, valueT is unsigned. */
2420 offsetT val
= (offsetT
) * valP
;
2422 = (fixP
->fx_addsy
== NULL
2423 ? absolute_section
: S_GET_SEGMENT (fixP
->fx_addsy
));
2425 /* If the fix is relative to a symbol which is not defined, or, (if
2426 pcrel), not in the same segment as the fix, we cannot resolve it
2428 if (fixP
->fx_addsy
!= NULL
2429 && (! S_IS_DEFINED (fixP
->fx_addsy
)
2430 || S_IS_WEAK (fixP
->fx_addsy
)
2431 || (fixP
->fx_pcrel
&& symsec
!= segment
)
2432 || (! fixP
->fx_pcrel
2433 && symsec
!= absolute_section
2434 && ((fixP
->fx_r_type
!= BFD_RELOC_MMIX_REG
2435 && fixP
->fx_r_type
!= BFD_RELOC_MMIX_REG_OR_BYTE
)
2436 || symsec
!= reg_section
))))
2441 else if (fixP
->fx_r_type
== BFD_RELOC_MMIX_LOCAL
2442 || fixP
->fx_r_type
== BFD_RELOC_VTABLE_INHERIT
2443 || fixP
->fx_r_type
== BFD_RELOC_VTABLE_ENTRY
)
2445 /* These are never "fixed". */
2450 /* We assume every other relocation is "fixed". */
2453 switch (fixP
->fx_r_type
)
2460 case BFD_RELOC_64_PCREL
:
2461 case BFD_RELOC_32_PCREL
:
2462 case BFD_RELOC_24_PCREL
:
2463 case BFD_RELOC_16_PCREL
:
2464 case BFD_RELOC_8_PCREL
:
2465 md_number_to_chars (buf
, val
, fixP
->fx_size
);
2468 case BFD_RELOC_MMIX_ADDR19
:
2471 /* This shouldn't happen. */
2472 BAD_CASE (fixP
->fx_r_type
);
2476 case BFD_RELOC_MMIX_GETA
:
2477 case BFD_RELOC_MMIX_CBRANCH
:
2478 case BFD_RELOC_MMIX_PUSHJ
:
2479 case BFD_RELOC_MMIX_PUSHJ_STUBBABLE
:
2480 /* If this fixup is out of range, punt to the linker to emit an
2481 error. This should only happen with -no-expand. */
2482 if (val
< -(((offsetT
) 1 << 19)/2)
2483 || val
>= ((offsetT
) 1 << 19)/2 - 1
2486 if (warn_on_expansion
)
2487 as_warn_where (fixP
->fx_file
, fixP
->fx_line
,
2488 _("operand out of range"));
2492 mmix_set_geta_branch_offset (buf
, val
);
2495 case BFD_RELOC_MMIX_ADDR27
:
2498 /* This shouldn't happen. */
2499 BAD_CASE (fixP
->fx_r_type
);
2503 case BFD_RELOC_MMIX_JMP
:
2504 /* If this fixup is out of range, punt to the linker to emit an
2505 error. This should only happen with -no-expand. */
2506 if (val
< -(((offsetT
) 1 << 27)/2)
2507 || val
>= ((offsetT
) 1 << 27)/2 - 1
2510 if (warn_on_expansion
)
2511 as_warn_where (fixP
->fx_file
, fixP
->fx_line
,
2512 _("operand out of range"));
2516 mmix_set_jmp_offset (buf
, val
);
2519 case BFD_RELOC_MMIX_REG_OR_BYTE
:
2520 if (fixP
->fx_addsy
!= NULL
2521 && (S_GET_SEGMENT (fixP
->fx_addsy
) != reg_section
2522 || S_GET_VALUE (fixP
->fx_addsy
) > 255)
2523 && S_GET_SEGMENT (fixP
->fx_addsy
) != absolute_section
)
2525 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
2526 _("invalid operands"));
2527 /* We don't want this "symbol" appearing in output, because
2534 /* If this reloc is for a Z field, we need to adjust
2535 the opcode if we got a constant here.
2536 FIXME: Can we make this more robust? */
2538 if ((fixP
->fx_where
& 3) == 3
2539 && (fixP
->fx_addsy
== NULL
2540 || S_GET_SEGMENT (fixP
->fx_addsy
) == absolute_section
))
2541 buf
[-3] |= IMM_OFFSET_BIT
;
2544 case BFD_RELOC_MMIX_REG
:
2545 if (fixP
->fx_addsy
== NULL
2546 || S_GET_SEGMENT (fixP
->fx_addsy
) != reg_section
2547 || S_GET_VALUE (fixP
->fx_addsy
) > 255)
2549 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
2550 _("invalid operands"));
2557 case BFD_RELOC_MMIX_BASE_PLUS_OFFSET
:
2558 /* These are never "fixed". */
2562 case BFD_RELOC_MMIX_PUSHJ_1
:
2563 case BFD_RELOC_MMIX_PUSHJ_2
:
2564 case BFD_RELOC_MMIX_PUSHJ_3
:
2565 case BFD_RELOC_MMIX_CBRANCH_J
:
2566 case BFD_RELOC_MMIX_CBRANCH_1
:
2567 case BFD_RELOC_MMIX_CBRANCH_2
:
2568 case BFD_RELOC_MMIX_CBRANCH_3
:
2569 case BFD_RELOC_MMIX_GETA_1
:
2570 case BFD_RELOC_MMIX_GETA_2
:
2571 case BFD_RELOC_MMIX_GETA_3
:
2572 case BFD_RELOC_MMIX_JMP_1
:
2573 case BFD_RELOC_MMIX_JMP_2
:
2574 case BFD_RELOC_MMIX_JMP_3
:
2576 BAD_CASE (fixP
->fx_r_type
);
2581 /* Make sure that for completed fixups we have the value around for
2582 use by e.g. mmix_frob_file. */
2583 fixP
->fx_offset
= val
;
2586 /* A bsearch function for looking up a value against offsets for GREG
2590 cmp_greg_val_greg_symbol_fixes (const void *p1
, const void *p2
)
2592 offsetT val1
= *(offsetT
*) p1
;
2593 offsetT val2
= ((struct mmix_symbol_greg_fixes
*) p2
)->offs
;
2595 if (val1
>= val2
&& val1
< val2
+ 255)
2604 /* Generate a machine-dependent relocation. */
2607 tc_gen_reloc (asection
*section ATTRIBUTE_UNUSED
, fixS
*fixP
)
2611 + (fixP
->fx_addsy
!= NULL
2612 && !S_IS_WEAK (fixP
->fx_addsy
)
2613 && !S_IS_COMMON (fixP
->fx_addsy
)
2614 ? S_GET_VALUE (fixP
->fx_addsy
) : 0);
2616 bfd_reloc_code_real_type code
= BFD_RELOC_NONE
;
2617 char *buf
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
2618 symbolS
*addsy
= fixP
->fx_addsy
;
2619 asection
*addsec
= addsy
== NULL
? NULL
: S_GET_SEGMENT (addsy
);
2620 asymbol
*baddsy
= addsy
!= NULL
? symbol_get_bfdsym (addsy
) : NULL
;
2622 = val
- (baddsy
== NULL
|| S_IS_COMMON (addsy
) || S_IS_WEAK (addsy
)
2623 ? 0 : bfd_asymbol_value (baddsy
));
2625 /* A single " LOCAL expression" in the wrong section will not work when
2626 linking to MMO; relocations for zero-content sections are then
2627 ignored. Normally, relocations would modify section contents, and
2628 you'd never think or be able to do something like that. The
2629 relocation resulting from a LOCAL directive doesn't have an obvious
2630 and mandatory location. I can't figure out a way to do this better
2631 than just helping the user around this limitation here; hopefully the
2632 code using the local expression is around. Putting the LOCAL
2633 semantics in a relocation still seems right; a section didn't do. */
2634 if (bfd_section_size (section
->owner
, section
) == 0)
2636 (fixP
->fx_file
, fixP
->fx_line
,
2637 fixP
->fx_r_type
== BFD_RELOC_MMIX_LOCAL
2638 /* The BFD_RELOC_MMIX_LOCAL-specific message is supposed to be
2639 user-friendly, though a little bit non-substantial. */
2640 ? _("directive LOCAL must be placed in code or data")
2641 : _("internal confusion: relocation in a section without contents"));
2643 /* FIXME: Range tests for all these. */
2644 switch (fixP
->fx_r_type
)
2651 code
= fixP
->fx_r_type
;
2653 if (addsy
== NULL
|| bfd_is_abs_section (addsec
))
2655 /* Resolve this reloc now, as md_apply_fix3 would have done (not
2656 called if -linkrelax). There is no point in keeping a reloc
2657 to an absolute symbol. No reloc that is subject to
2658 relaxation must be to an absolute symbol; difference
2659 involving symbols in a specific section must be signalled as
2660 an error if the relaxing cannot be expressed; having a reloc
2661 to the resolved (now absolute) value does not help. */
2662 md_number_to_chars (buf
, val
, fixP
->fx_size
);
2667 case BFD_RELOC_64_PCREL
:
2668 case BFD_RELOC_32_PCREL
:
2669 case BFD_RELOC_24_PCREL
:
2670 case BFD_RELOC_16_PCREL
:
2671 case BFD_RELOC_8_PCREL
:
2672 case BFD_RELOC_MMIX_LOCAL
:
2673 case BFD_RELOC_VTABLE_INHERIT
:
2674 case BFD_RELOC_VTABLE_ENTRY
:
2675 case BFD_RELOC_MMIX_GETA
:
2676 case BFD_RELOC_MMIX_GETA_1
:
2677 case BFD_RELOC_MMIX_GETA_2
:
2678 case BFD_RELOC_MMIX_GETA_3
:
2679 case BFD_RELOC_MMIX_CBRANCH
:
2680 case BFD_RELOC_MMIX_CBRANCH_J
:
2681 case BFD_RELOC_MMIX_CBRANCH_1
:
2682 case BFD_RELOC_MMIX_CBRANCH_2
:
2683 case BFD_RELOC_MMIX_CBRANCH_3
:
2684 case BFD_RELOC_MMIX_PUSHJ
:
2685 case BFD_RELOC_MMIX_PUSHJ_1
:
2686 case BFD_RELOC_MMIX_PUSHJ_2
:
2687 case BFD_RELOC_MMIX_PUSHJ_3
:
2688 case BFD_RELOC_MMIX_PUSHJ_STUBBABLE
:
2689 case BFD_RELOC_MMIX_JMP
:
2690 case BFD_RELOC_MMIX_JMP_1
:
2691 case BFD_RELOC_MMIX_JMP_2
:
2692 case BFD_RELOC_MMIX_JMP_3
:
2693 case BFD_RELOC_MMIX_ADDR19
:
2694 case BFD_RELOC_MMIX_ADDR27
:
2695 code
= fixP
->fx_r_type
;
2698 case BFD_RELOC_MMIX_REG_OR_BYTE
:
2699 /* If we have this kind of relocation to an unknown symbol or to the
2700 register contents section (that is, to a register), then we can't
2701 resolve the relocation here. */
2703 && (bfd_is_und_section (addsec
)
2704 || strcmp (bfd_get_section_name (addsec
->owner
, addsec
),
2705 MMIX_REG_CONTENTS_SECTION_NAME
) == 0))
2707 code
= fixP
->fx_r_type
;
2711 /* If the relocation is not to the register section or to the
2712 absolute section (a numeric value), then we have an error. */
2714 && (S_GET_SEGMENT (addsy
) != real_reg_section
2717 && ! bfd_is_abs_section (addsec
))
2720 /* Set the "immediate" bit of the insn if this relocation is to Z
2721 field when the value is a numeric value, i.e. not a register. */
2722 if ((fixP
->fx_where
& 3) == 3
2723 && (addsy
== NULL
|| bfd_is_abs_section (addsec
)))
2724 buf
[-3] |= IMM_OFFSET_BIT
;
2729 case BFD_RELOC_MMIX_BASE_PLUS_OFFSET
:
2731 && strcmp (bfd_get_section_name (addsec
->owner
, addsec
),
2732 MMIX_REG_CONTENTS_SECTION_NAME
) == 0)
2734 /* This changed into a register; the relocation is for the
2735 register-contents section. The constant part remains zero. */
2736 code
= BFD_RELOC_MMIX_REG
;
2740 /* If we've found out that this was indeed a register, then replace
2741 with the register number. The constant part is already zero.
2743 If we encounter any other defined symbol, then we must find a
2744 suitable register and emit a reloc. */
2745 if (addsy
== NULL
|| addsec
!= real_reg_section
)
2747 struct mmix_symbol_gregs
*gregs
;
2748 struct mmix_symbol_greg_fixes
*fix
;
2750 if (S_IS_DEFINED (addsy
)
2751 && !bfd_is_com_section (addsec
)
2752 && !S_IS_WEAK (addsy
))
2754 if (! symbol_section_p (addsy
) && ! bfd_is_abs_section (addsec
))
2755 as_fatal (_("internal: BFD_RELOC_MMIX_BASE_PLUS_OFFSET not resolved to section"));
2757 /* If this is an absolute symbol sufficiently near
2758 lowest_data_loc, then we canonicalize on the data
2759 section. Note that val is signed here; we may subtract
2760 lowest_data_loc which is unsigned. Careful with those
2762 if (lowest_data_loc
!= (bfd_vma
) -1
2763 && (bfd_vma
) val
+ 256 > lowest_data_loc
2764 && bfd_is_abs_section (addsec
))
2766 val
-= (offsetT
) lowest_data_loc
;
2767 addsy
= section_symbol (data_section
);
2769 /* Likewise text section. */
2770 else if (lowest_text_loc
!= (bfd_vma
) -1
2771 && (bfd_vma
) val
+ 256 > lowest_text_loc
2772 && bfd_is_abs_section (addsec
))
2774 val
-= (offsetT
) lowest_text_loc
;
2775 addsy
= section_symbol (text_section
);
2779 gregs
= *symbol_get_tc (addsy
);
2781 /* If that symbol does not have any associated GREG definitions,
2782 we can't do anything. */
2784 || (fix
= bsearch (&val
, gregs
->greg_fixes
, gregs
->n_gregs
,
2785 sizeof (gregs
->greg_fixes
[0]),
2786 cmp_greg_val_greg_symbol_fixes
)) == NULL
2787 /* The register must not point *after* the address we want. */
2789 /* Neither must the register point more than 255 bytes
2790 before the address we want. */
2791 || fix
->offs
+ 255 < val
)
2793 /* We can either let the linker allocate GREGs
2794 automatically, or emit an error. */
2795 if (allocate_undefined_gregs_in_linker
)
2797 /* The values in baddsy and addend are right. */
2798 code
= fixP
->fx_r_type
;
2802 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
2803 _("no suitable GREG definition for operands"));
2808 /* Transform the base-plus-offset reloc for the actual area
2809 to a reloc for the register with the address of the area.
2810 Put addend for register in Z operand. */
2811 buf
[1] = val
- fix
->offs
;
2812 code
= BFD_RELOC_MMIX_REG
;
2814 = (bfd_get_section_by_name (stdoutput
,
2815 MMIX_REG_CONTENTS_SECTION_NAME
)
2818 addend
= fix
->fix
->fx_frag
->fr_address
+ fix
->fix
->fx_where
;
2821 else if (S_GET_VALUE (addsy
) > 255)
2822 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
2823 _("invalid operands"));
2831 case BFD_RELOC_MMIX_REG
:
2833 && (bfd_is_und_section (addsec
)
2834 || strcmp (bfd_get_section_name (addsec
->owner
, addsec
),
2835 MMIX_REG_CONTENTS_SECTION_NAME
) == 0))
2837 code
= fixP
->fx_r_type
;
2842 && (addsec
!= real_reg_section
2845 && ! bfd_is_und_section (addsec
))
2846 /* Drop through to error message. */
2855 /* The others are supposed to be handled by md_apply_fix3.
2856 FIXME: ... which isn't called when -linkrelax. Move over
2857 md_apply_fix3 code here for everything reasonable. */
2861 (fixP
->fx_file
, fixP
->fx_line
,
2862 _("operands were not reducible at assembly-time"));
2864 /* Unmark this symbol as used in a reloc, so we don't bump into a BFD
2865 assert when trying to output reg_section. FIXME: A gas bug. */
2866 fixP
->fx_addsy
= NULL
;
2870 relP
= (arelent
*) xmalloc (sizeof (arelent
));
2872 relP
->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
2873 *relP
->sym_ptr_ptr
= baddsy
;
2874 relP
->address
= fixP
->fx_frag
->fr_address
+ fixP
->fx_where
;
2876 relP
->addend
= addend
;
2878 /* If this had been a.out, we would have had a kludge for weak symbols
2881 relP
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
2886 name
= S_GET_NAME (addsy
);
2888 name
= _("<unknown>");
2889 as_fatal (_("cannot generate relocation type for symbol %s, code %s"),
2890 name
, bfd_get_reloc_code_name (code
));
2896 /* Do some reformatting of a line. FIXME: We could transform a mmixal
2897 line into traditional (GNU?) format, unless #NO_APP, and get rid of all
2898 ugly labels_without_colons etc. */
2901 mmix_handle_mmixal (void)
2903 char *s0
= input_line_pointer
;
2908 if (pending_label
!= NULL
)
2909 as_fatal (_("internal: unhandled label %s"), pending_label
);
2911 if (mmix_gnu_syntax
)
2914 /* If the first character is a '.', then it's a pseudodirective, not a
2915 label. Make GAS not handle label-without-colon on this line. We
2916 also don't do mmixal-specific stuff on this line. */
2917 if (input_line_pointer
[0] == '.')
2919 label_without_colon_this_line
= 0;
2923 /* Don't handle empty lines here. */
2926 if (*s0
== 0 || is_end_of_line
[(unsigned int) *s0
])
2929 if (! ISSPACE (*s0
))
2935 /* If we're on a line with a label, check if it's a mmixal fb-label.
2936 Save an indicator and skip the label; it must be set only after all
2937 fb-labels of expressions are evaluated. */
2938 if (ISDIGIT (input_line_pointer
[0])
2939 && input_line_pointer
[1] == 'H'
2940 && ISSPACE (input_line_pointer
[2]))
2943 current_fb_label
= input_line_pointer
[0] - '0';
2945 /* We have to skip the label, but also preserve the newlineness of
2946 the previous character, since the caller checks that. It's a
2947 mess we blame on the caller. */
2948 input_line_pointer
[1] = input_line_pointer
[-1];
2949 input_line_pointer
+= 2;
2951 s
= input_line_pointer
;
2952 while (*s
&& ISSPACE (*s
) && ! is_end_of_line
[(unsigned int) *s
])
2955 /* For errors emitted here, the book-keeping is off by one; the
2956 caller is about to bump the counters. Adjust the error messages. */
2957 if (is_end_of_line
[(unsigned int) *s
])
2961 as_where (&name
, &line
);
2962 as_bad_where (name
, line
+ 1,
2963 _("[0-9]H labels may not appear alone on a line"));
2964 current_fb_label
= -1;
2970 as_where (&name
, &line
);
2971 as_bad_where (name
, line
+ 1,
2972 _("[0-9]H labels do not mix with dot-pseudos"));
2973 current_fb_label
= -1;
2978 current_fb_label
= -1;
2979 if (is_name_beginner (input_line_pointer
[0]))
2980 label
= input_line_pointer
;
2983 s0
= input_line_pointer
;
2984 /* Skip over label. */
2985 while (*s0
&& is_part_of_name (*s0
))
2988 /* Remove trailing ":" off labels, as they'd otherwise be considered
2989 part of the name. But don't do it for local labels. */
2990 if (s0
!= input_line_pointer
&& s0
[-1] == ':'
2991 && (s0
- 2 != input_line_pointer
2992 || ! ISDIGIT (s0
[-2])))
2994 else if (label
!= NULL
)
2996 /* For labels that don't end in ":", we save it so we can later give
2997 it the same alignment and address as the associated instruction. */
2999 /* Make room for the label including the ending nul. */
3000 int len_0
= s0
- label
+ 1;
3002 /* Save this label on the MMIX symbol obstack. Saving it on an
3003 obstack is needless for "IS"-pseudos, but it's harmless and we
3004 avoid a little code-cluttering. */
3005 obstack_grow (&mmix_sym_obstack
, label
, len_0
);
3006 pending_label
= obstack_finish (&mmix_sym_obstack
);
3007 pending_label
[len_0
- 1] = 0;
3010 while (*s0
&& ISSPACE (*s0
) && ! is_end_of_line
[(unsigned int) *s0
])
3013 if (pending_label
!= NULL
&& is_end_of_line
[(unsigned int) *s0
])
3014 /* Whoops, this was actually a lone label on a line. Like :-ended
3015 labels, we don't attach such labels to the next instruction or
3017 pending_label
= NULL
;
3019 /* Find local labels of operands. Look for "[0-9][FB]" where the
3020 characters before and after are not part of words. Break if a single
3021 or double quote is seen anywhere. It means we can't have local
3022 labels as part of list with mixed quoted and unquoted members for
3023 mmixal compatibility but we can't have it all. For the moment.
3024 Replace the '<N>B' or '<N>F' with MAGIC_FB_BACKWARD_CHAR<N> and
3025 MAGIC_FB_FORWARD_CHAR<N> respectively. */
3027 /* First make sure we don't have any of the magic characters on the line
3028 appearing as input. */
3033 if (is_end_of_line
[(unsigned int) c
])
3035 if (c
== MAGIC_FB_BACKWARD_CHAR
|| c
== MAGIC_FB_FORWARD_CHAR
)
3036 as_bad (_("invalid characters in input"));
3039 /* Scan again, this time looking for ';' after operands. */
3042 /* Skip the insn. */
3046 && ! is_end_of_line
[(unsigned int) *s
])
3049 /* Skip the spaces after the insn. */
3053 && ! is_end_of_line
[(unsigned int) *s
])
3056 /* Skip the operands. While doing this, replace [0-9][BF] with
3057 (MAGIC_FB_BACKWARD_CHAR|MAGIC_FB_FORWARD_CHAR)[0-9]. */
3058 while ((c
= *s
) != 0
3061 && ! is_end_of_line
[(unsigned int) c
])
3067 /* FIXME: Test-case for semi-colon in string. */
3070 && (! is_end_of_line
[(unsigned int) *s
] || *s
== ';'))
3076 else if (ISDIGIT (c
))
3078 if ((s
[1] != 'B' && s
[1] != 'F')
3079 || is_part_of_name (s
[-1])
3080 || is_part_of_name (s
[2]))
3085 ? MAGIC_FB_BACKWARD_CHAR
: MAGIC_FB_FORWARD_CHAR
);
3093 /* Skip any spaces after the operands. */
3097 && !is_end_of_line
[(unsigned int) *s
])
3100 /* If we're now looking at a semi-colon, then it's an end-of-line
3102 mmix_next_semicolon_is_eoln
= (*s
== ';');
3104 /* Make IS into an EQU by replacing it with "= ". Only match upper-case
3105 though; let lower-case be a syntax error. */
3107 if (s
[0] == 'I' && s
[1] == 'S' && ISSPACE (s
[2]))
3112 /* Since labels can start without ":", we have to handle "X IS 42"
3113 in full here, or "X" will be parsed as a label to be set at ".". */
3114 input_line_pointer
= s
;
3116 /* Right after this function ends, line numbers will be bumped if
3117 input_line_pointer[-1] = '\n'. We want accurate line numbers for
3118 the equals call, so we bump them before the call, and make sure
3119 they aren't bumped afterwards. */
3120 bump_line_counters ();
3122 /* A fb-label is valid as an IS-label. */
3123 if (current_fb_label
>= 0)
3127 /* We need to save this name on our symbol obstack, since the
3128 string we got in fb_label_name is volatile and will change
3129 with every call to fb_label_name, like those resulting from
3130 parsing the IS-operand. */
3131 fb_name
= fb_label_name (current_fb_label
, 1);
3132 obstack_grow (&mmix_sym_obstack
, fb_name
, strlen (fb_name
) + 1);
3133 equals (obstack_finish (&mmix_sym_obstack
), 0);
3134 fb_label_instance_inc (current_fb_label
);
3135 current_fb_label
= -1;
3139 if (pending_label
== NULL
)
3140 as_bad (_("empty label field for IS"));
3142 equals (pending_label
, 0);
3143 pending_label
= NULL
;
3146 /* For mmixal, we can have comments without a comment-start
3148 mmix_handle_rest_of_empty_line ();
3149 input_line_pointer
--;
3151 input_line_pointer
[-1] = ' ';
3153 else if (s
[0] == 'G'
3155 && strncmp (s
, "GREG", 4) == 0
3156 && (ISSPACE (s
[4]) || is_end_of_line
[(unsigned char) s
[4]]))
3158 input_line_pointer
= s
+ 4;
3160 /* Right after this function ends, line numbers will be bumped if
3161 input_line_pointer[-1] = '\n'. We want accurate line numbers for
3162 the s_greg call, so we bump them before the call, and make sure
3163 they aren't bumped afterwards. */
3164 bump_line_counters ();
3166 /* A fb-label is valid as a GREG-label. */
3167 if (current_fb_label
>= 0)
3171 /* We need to save this name on our symbol obstack, since the
3172 string we got in fb_label_name is volatile and will change
3173 with every call to fb_label_name, like those resulting from
3174 parsing the IS-operand. */
3175 fb_name
= fb_label_name (current_fb_label
, 1);
3177 /* Make sure we save the canonical name and don't get bitten by
3179 obstack_1grow (&mmix_sym_obstack
, ':');
3180 obstack_grow (&mmix_sym_obstack
, fb_name
, strlen (fb_name
) + 1);
3181 mmix_greg_internal (obstack_finish (&mmix_sym_obstack
));
3182 fb_label_instance_inc (current_fb_label
);
3183 current_fb_label
= -1;
3186 mmix_greg_internal (pending_label
);
3188 /* Back up before the end-of-line marker that was skipped in
3189 mmix_greg_internal. */
3190 input_line_pointer
--;
3191 input_line_pointer
[-1] = ' ';
3193 pending_label
= NULL
;
3195 else if (pending_label
!= NULL
)
3197 input_line_pointer
+= strlen (pending_label
);
3199 /* See comment above about getting line numbers bumped. */
3200 input_line_pointer
[-1] = '\n';
3204 /* Give the value of an fb-label rewritten as in mmix_handle_mmixal, when
3205 parsing an expression.
3207 On valid calls, input_line_pointer points at a MAGIC_FB_BACKWARD_CHAR
3208 or MAGIC_FB_BACKWARD_CHAR, followed by an ascii digit for the label.
3209 We fill in the label as an expression. */
3212 mmix_fb_label (expressionS
*expP
)
3215 char *fb_internal_name
;
3217 /* This doesn't happen when not using mmixal syntax. */
3219 || (input_line_pointer
[0] != MAGIC_FB_BACKWARD_CHAR
3220 && input_line_pointer
[0] != MAGIC_FB_FORWARD_CHAR
))
3223 /* The current backward reference has augmentation 0. A forward
3224 reference has augmentation 1, unless it's the same as a fb-label on
3225 _this_ line, in which case we add one more so we don't refer to it.
3226 This is the semantics of mmixal; it differs to that of common
3227 fb-labels which refer to a here-label on the current line as a
3228 backward reference. */
3230 = fb_label_name (input_line_pointer
[1] - '0',
3231 (input_line_pointer
[0] == MAGIC_FB_FORWARD_CHAR
? 1 : 0)
3232 + ((input_line_pointer
[1] - '0' == current_fb_label
3233 && input_line_pointer
[0] == MAGIC_FB_FORWARD_CHAR
)
3236 input_line_pointer
+= 2;
3237 sym
= symbol_find_or_make (fb_internal_name
);
3239 /* We don't have to clean up unrelated fields here; we just do what the
3240 expr machinery does, but *not* just what it does for [0-9][fb], since
3241 we need to treat those as ordinary symbols sometimes; see testcases
3242 err-byte2.s and fb-2.s. */
3243 if (S_GET_SEGMENT (sym
) == absolute_section
)
3245 expP
->X_op
= O_constant
;
3246 expP
->X_add_number
= S_GET_VALUE (sym
);
3250 expP
->X_op
= O_symbol
;
3251 expP
->X_add_symbol
= sym
;
3252 expP
->X_add_number
= 0;
3256 /* See whether we need to force a relocation into the output file.
3257 This is used to force out switch and PC relative relocations when
3261 mmix_force_relocation (fixS
*fixP
)
3263 if (fixP
->fx_r_type
== BFD_RELOC_MMIX_LOCAL
3264 || fixP
->fx_r_type
== BFD_RELOC_MMIX_BASE_PLUS_OFFSET
)
3270 /* All our pcrel relocations are must-keep. Note that md_apply_fix3 is
3271 called *after* this, and will handle getting rid of the presumed
3272 reloc; a relocation isn't *forced* other than to be handled by
3273 md_apply_fix3 (or tc_gen_reloc if linkrelax). */
3277 return generic_force_reloc (fixP
);
3280 /* The location from which a PC relative jump should be calculated,
3281 given a PC relative reloc. */
3284 md_pcrel_from_section (fixS
*fixP
, segT sec
)
3286 if (fixP
->fx_addsy
!= (symbolS
*) NULL
3287 && (! S_IS_DEFINED (fixP
->fx_addsy
)
3288 || S_GET_SEGMENT (fixP
->fx_addsy
) != sec
))
3290 /* The symbol is undefined (or is defined but not in this section).
3291 Let the linker figure it out. */
3295 return (fixP
->fx_frag
->fr_address
+ fixP
->fx_where
);
3298 /* Adjust the symbol table. We make reg_section relative to the real
3299 register section. */
3302 mmix_adjust_symtab (void)
3305 symbolS
*regsec
= section_symbol (reg_section
);
3307 for (sym
= symbol_rootP
; sym
!= NULL
; sym
= symbol_next (sym
))
3308 if (S_GET_SEGMENT (sym
) == reg_section
)
3312 if (S_IS_EXTERN (sym
) || symbol_used_in_reloc_p (sym
))
3314 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
3317 /* Change section to the *real* register section, so it gets
3318 proper treatment when writing it out. Only do this for
3319 global symbols. This also means we don't have to check for
3321 S_SET_SEGMENT (sym
, real_reg_section
);
3325 /* This is the expansion of LABELS_WITHOUT_COLONS.
3326 We let md_start_line_hook tweak label_without_colon_this_line, and then
3327 this function returns the tweaked value, and sets it to 1 for the next
3328 line. FIXME: Very, very brittle. Not sure it works the way I
3329 thought at the time I first wrote this. */
3332 mmix_label_without_colon_this_line (void)
3334 int retval
= label_without_colon_this_line
;
3336 if (! mmix_gnu_syntax
)
3337 label_without_colon_this_line
= 1;
3342 /* This is the expansion of md_relax_frag. We go through the ordinary
3343 relax table function except when the frag is for a GREG. Then we have
3344 to check whether there's another GREG by the same value that we can
3348 mmix_md_relax_frag (segT seg
, fragS
*fragP
, long stretch
)
3350 switch (fragP
->fr_subtype
)
3352 /* Growth for this type has been handled by mmix_md_end and
3353 correctly estimated, so there's nothing more to do here. */
3354 case STATE_GREG_DEF
:
3357 case ENCODE_RELAX (STATE_PUSHJ
, STATE_ZERO
):
3359 /* We need to handle relaxation type ourselves, since relax_frag
3360 doesn't update fr_subtype if there's no size increase in the
3361 current section; when going from plain PUSHJ to a stub. This
3362 is otherwise functionally the same as relax_frag in write.c,
3363 simplified for this case. */
3368 target
= fragP
->fr_offset
;
3369 address
= fragP
->fr_address
;
3370 symbolP
= fragP
->fr_symbol
;
3376 sym_frag
= symbol_get_frag (symbolP
);
3377 know (S_GET_SEGMENT (symbolP
) != absolute_section
3378 || sym_frag
== &zero_address_frag
);
3379 target
+= S_GET_VALUE (symbolP
);
3381 /* If frag has yet to be reached on this pass, assume it will
3382 move by STRETCH just as we did. If this is not so, it will
3383 be because some frag between grows, and that will force
3387 && sym_frag
->relax_marker
!= fragP
->relax_marker
3388 && S_GET_SEGMENT (symbolP
) == seg
)
3392 aim
= target
- address
- fragP
->fr_fix
;
3393 if (aim
>= PUSHJ_0B
&& aim
<= PUSHJ_0F
)
3395 /* Target is reachable with a PUSHJ. */
3396 segment_info_type
*seginfo
= seg_info (seg
);
3398 /* If we're at the end of a relaxation round, clear the stub
3399 counter as initialization for the next round. */
3400 if (fragP
== seginfo
->tc_segment_info_data
.last_stubfrag
)
3401 seginfo
->tc_segment_info_data
.nstubs
= 0;
3405 /* Not reachable. Try a stub. */
3406 fragP
->fr_subtype
= ENCODE_RELAX (STATE_PUSHJSTUB
, STATE_ZERO
);
3410 /* See if this PUSHJ is redirectable to a stub. */
3411 case ENCODE_RELAX (STATE_PUSHJSTUB
, STATE_ZERO
):
3413 segment_info_type
*seginfo
= seg_info (seg
);
3414 fragS
*lastfrag
= seginfo
->frchainP
->frch_last
;
3415 relax_substateT prev_type
= fragP
->fr_subtype
;
3417 /* The last frag is always an empty frag, so it suffices to look
3418 at its address to know the ending address of this section. */
3419 know (lastfrag
->fr_type
== rs_fill
3420 && lastfrag
->fr_fix
== 0
3421 && lastfrag
->fr_var
== 0);
3423 /* For this PUSHJ to be relaxable into a call to a stub, the
3424 distance must be no longer than 256k bytes from the PUSHJ to
3425 the end of the section plus the maximum size of stubs so far. */
3426 if ((lastfrag
->fr_address
3428 + PUSHJ_MAX_LEN
* seginfo
->tc_segment_info_data
.nstubs
)
3429 - (fragP
->fr_address
+ fragP
->fr_fix
)
3432 fragP
->fr_subtype
= mmix_relax_table
[prev_type
].rlx_more
;
3434 seginfo
->tc_segment_info_data
.nstubs
++;
3436 /* If we're at the end of a relaxation round, clear the stub
3437 counter as initialization for the next round. */
3438 if (fragP
== seginfo
->tc_segment_info_data
.last_stubfrag
)
3439 seginfo
->tc_segment_info_data
.nstubs
= 0;
3442 (mmix_relax_table
[fragP
->fr_subtype
].rlx_length
3443 - mmix_relax_table
[prev_type
].rlx_length
);
3446 case ENCODE_RELAX (STATE_PUSHJ
, STATE_MAX
):
3448 segment_info_type
*seginfo
= seg_info (seg
);
3450 /* Need to cover all STATE_PUSHJ states to act on the last stub
3451 frag (the end of this relax round; initialization for the
3453 if (fragP
== seginfo
->tc_segment_info_data
.last_stubfrag
)
3454 seginfo
->tc_segment_info_data
.nstubs
= 0;
3460 return relax_frag (seg
, fragP
, stretch
);
3462 case STATE_GREG_UNDF
:
3463 BAD_CASE (fragP
->fr_subtype
);
3466 as_fatal (_("internal: unexpected relax type %d:%d"),
3467 fragP
->fr_type
, fragP
->fr_subtype
);
3471 /* Various things we punt until all input is seen. */
3480 /* The first frag of GREG:s going into the register contents section. */
3481 fragS
*mmix_reg_contents_frags
= NULL
;
3483 /* Reset prefix. All labels reachable at this point must be
3485 mmix_current_prefix
= NULL
;
3488 as_bad_where (bspec_file
, bspec_line
, _("BSPEC without ESPEC."));
3490 /* Emit the low LOC setting of .text. */
3491 if (text_has_contents
&& lowest_text_loc
!= (bfd_vma
) -1)
3494 char locsymbol
[sizeof (":") - 1
3495 + sizeof (MMIX_LOC_SECTION_START_SYMBOL_PREFIX
) - 1
3496 + sizeof (".text")];
3498 /* An exercise in non-ISO-C-ness, this one. */
3499 sprintf (locsymbol
, ":%s%s", MMIX_LOC_SECTION_START_SYMBOL_PREFIX
,
3502 = symbol_new (locsymbol
, absolute_section
, lowest_text_loc
,
3503 &zero_address_frag
);
3504 S_SET_EXTERNAL (symbolP
);
3508 if (data_has_contents
&& lowest_data_loc
!= (bfd_vma
) -1)
3511 char locsymbol
[sizeof (":") - 1
3512 + sizeof (MMIX_LOC_SECTION_START_SYMBOL_PREFIX
) - 1
3513 + sizeof (".data")];
3515 sprintf (locsymbol
, ":%s%s", MMIX_LOC_SECTION_START_SYMBOL_PREFIX
,
3518 = symbol_new (locsymbol
, absolute_section
, lowest_data_loc
,
3519 &zero_address_frag
);
3520 S_SET_EXTERNAL (symbolP
);
3523 /* Unless GNU syntax mode, set "Main" to be a function, so the
3524 disassembler doesn't get confused when we write truly
3525 mmixal-compatible code (and don't use .type). Similarly set it
3526 global (regardless of -globalize-symbols), so the linker sees it as
3527 the start symbol in ELF mode. */
3528 mainsym
= symbol_find (MMIX_START_SYMBOL_NAME
);
3529 if (mainsym
!= NULL
&& ! mmix_gnu_syntax
)
3531 symbol_get_bfdsym (mainsym
)->flags
|= BSF_FUNCTION
;
3532 S_SET_EXTERNAL (mainsym
);
3535 if (n_of_raw_gregs
!= 0)
3537 /* Emit GREGs. They are collected in order of appearance, but must
3538 be emitted in opposite order to both have section address regno*8
3539 and the same allocation order (within a file) as mmixal. */
3540 segT this_segment
= now_seg
;
3541 subsegT this_subsegment
= now_subseg
;
3543 = bfd_make_section_old_way (stdoutput
,
3544 MMIX_REG_CONTENTS_SECTION_NAME
);
3545 subseg_set (regsec
, 0);
3547 /* Finally emit the initialization-value. Emit a variable frag, which
3548 we'll fix in md_estimate_size_before_relax. We set the initializer
3549 for the tc_frag_data field to NULL, so we can use that field for
3550 relaxation purposes. */
3551 mmix_opcode_frag
= NULL
;
3554 mmix_reg_contents_frags
= frag_now
;
3556 for (i
= n_of_raw_gregs
- 1; i
>= 0; i
--)
3558 if (mmix_raw_gregs
[i
].label
!= NULL
)
3559 /* There's a symbol. Let it refer to this location in the
3560 register contents section. The symbol must be globalized
3562 colon (mmix_raw_gregs
[i
].label
);
3564 frag_var (rs_machine_dependent
, 8, 0, STATE_GREG_UNDF
,
3565 make_expr_symbol (&mmix_raw_gregs
[i
].exp
), 0, NULL
);
3568 subseg_set (this_segment
, this_subsegment
);
3571 /* Iterate over frags resulting from GREGs and move those that evidently
3572 have the same value together and point one to another.
3574 This works in time O(N^2) but since the upper bound for non-error use
3575 is 223, it's best to keep this simpler algorithm. */
3576 for (fragP
= mmix_reg_contents_frags
; fragP
!= NULL
; fragP
= fragP
->fr_next
)
3583 symbolS
*symbolP
= fragP
->fr_symbol
;
3585 if (fragP
->fr_type
!= rs_machine_dependent
3586 || fragP
->fr_subtype
!= STATE_GREG_UNDF
)
3589 /* Whatever the outcome, we will have this GREG judged merged or
3590 non-merged. Since the tc_frag_data is NULL at this point, we
3591 default to non-merged. */
3592 fragP
->fr_subtype
= STATE_GREG_DEF
;
3594 /* If we're not supposed to merge GREG definitions, then just don't
3595 look for equivalents. */
3599 osymval
= (offsetT
) S_GET_VALUE (symbolP
);
3600 osymfrag
= symbol_get_frag (symbolP
);
3602 /* If the symbol isn't defined, we can't say that another symbol
3603 equals this frag, then. FIXME: We can look at the "deepest"
3604 defined name; if a = c and b = c then obviously a == b. */
3605 if (! S_IS_DEFINED (symbolP
))
3608 oexpP
= symbol_get_value_expression (fragP
->fr_symbol
);
3610 /* If the initialization value is zero, then we must not merge them. */
3611 if (oexpP
->X_op
== O_constant
&& osymval
== 0)
3614 /* Iterate through the frags downward this one. If we find one that
3615 has the same non-zero value, move it to after this one and point
3616 to it as the equivalent. */
3617 for (fpp
= &fragP
->fr_next
; *fpp
!= NULL
; fpp
= &fpp
[0]->fr_next
)
3621 if (fp
->fr_type
!= rs_machine_dependent
3622 || fp
->fr_subtype
!= STATE_GREG_UNDF
)
3625 /* Calling S_GET_VALUE may simplify the symbol, changing from
3626 expr_section etc. so call it first. */
3627 if ((offsetT
) S_GET_VALUE (fp
->fr_symbol
) == osymval
3628 && symbol_get_frag (fp
->fr_symbol
) == osymfrag
)
3630 /* Move the frag links so the one we found equivalent comes
3631 after the current one, carefully considering that
3632 sometimes fpp == &fragP->fr_next and the moves must be a
3635 fp
->fr_next
= fragP
->fr_next
;
3636 fragP
->fr_next
= fp
;
3642 fragP
->tc_frag_data
= fp
;
3646 /* qsort function for mmix_symbol_gregs. */
3649 cmp_greg_symbol_fixes (const void *parg
, const void *qarg
)
3651 const struct mmix_symbol_greg_fixes
*p
3652 = (const struct mmix_symbol_greg_fixes
*) parg
;
3653 const struct mmix_symbol_greg_fixes
*q
3654 = (const struct mmix_symbol_greg_fixes
*) qarg
;
3656 return p
->offs
> q
->offs
? 1 : p
->offs
< q
->offs
? -1 : 0;
3659 /* Collect GREG definitions from mmix_gregs and hang them as lists sorted
3660 on increasing offsets onto each section symbol or undefined symbol.
3662 Also, remove the register convenience section so it doesn't get output
3663 as an ELF section. */
3666 mmix_frob_file (void)
3669 struct mmix_symbol_gregs
*all_greg_symbols
[MAX_GREGS
];
3670 int n_greg_symbols
= 0;
3672 /* Collect all greg fixups and decorate each corresponding symbol with
3673 the greg fixups for it. */
3674 for (i
= 0; i
< n_of_cooked_gregs
; i
++)
3678 struct mmix_symbol_gregs
*gregs
;
3681 fixP
= mmix_gregs
[i
];
3682 know (fixP
->fx_r_type
== BFD_RELOC_64
);
3684 /* This case isn't doable in general anyway, methinks. */
3685 if (fixP
->fx_subsy
!= NULL
)
3687 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3688 _("GREG expression too complicated"));
3692 sym
= fixP
->fx_addsy
;
3693 offs
= (offsetT
) fixP
->fx_offset
;
3695 /* If the symbol is defined, then it must be resolved to a section
3696 symbol at this time, or else we don't know how to handle it. */
3697 if (S_IS_DEFINED (sym
)
3698 && !bfd_is_com_section (S_GET_SEGMENT (sym
))
3699 && !S_IS_WEAK (sym
))
3701 if (! symbol_section_p (sym
)
3702 && ! bfd_is_abs_section (S_GET_SEGMENT (sym
)))
3703 as_fatal (_("internal: GREG expression not resolved to section"));
3705 offs
+= S_GET_VALUE (sym
);
3708 /* If this is an absolute symbol sufficiently near lowest_data_loc,
3709 then we canonicalize on the data section. Note that offs is
3710 signed here; we may subtract lowest_data_loc which is unsigned.
3711 Careful with those comparisons. */
3712 if (lowest_data_loc
!= (bfd_vma
) -1
3713 && (bfd_vma
) offs
+ 256 > lowest_data_loc
3714 && bfd_is_abs_section (S_GET_SEGMENT (sym
)))
3716 offs
-= (offsetT
) lowest_data_loc
;
3717 sym
= section_symbol (data_section
);
3719 /* Likewise text section. */
3720 else if (lowest_text_loc
!= (bfd_vma
) -1
3721 && (bfd_vma
) offs
+ 256 > lowest_text_loc
3722 && bfd_is_abs_section (S_GET_SEGMENT (sym
)))
3724 offs
-= (offsetT
) lowest_text_loc
;
3725 sym
= section_symbol (text_section
);
3728 gregs
= *symbol_get_tc (sym
);
3732 gregs
= xmalloc (sizeof (*gregs
));
3734 symbol_set_tc (sym
, &gregs
);
3735 all_greg_symbols
[n_greg_symbols
++] = gregs
;
3738 gregs
->greg_fixes
[gregs
->n_gregs
].fix
= fixP
;
3739 gregs
->greg_fixes
[gregs
->n_gregs
++].offs
= offs
;
3742 /* For each symbol having a GREG definition, sort those definitions on
3744 for (i
= 0; i
< n_greg_symbols
; i
++)
3745 qsort (all_greg_symbols
[i
]->greg_fixes
, all_greg_symbols
[i
]->n_gregs
,
3746 sizeof (all_greg_symbols
[i
]->greg_fixes
[0]), cmp_greg_symbol_fixes
);
3748 if (real_reg_section
!= NULL
)
3752 /* FIXME: Pass error state gracefully. */
3753 if (bfd_get_section_flags (stdoutput
, real_reg_section
) & SEC_HAS_CONTENTS
)
3754 as_fatal (_("register section has contents\n"));
3756 /* Really remove the section. */
3757 for (secpp
= &stdoutput
->sections
;
3758 *secpp
!= real_reg_section
;
3759 secpp
= &(*secpp
)->next
)
3761 bfd_section_list_remove (stdoutput
, secpp
);
3762 --stdoutput
->section_count
;
3767 /* Provide an expression for a built-in name provided when-used.
3768 Either a symbol that is a handler; living in 0x10*[1..8] and having
3769 name [DVWIOUZX]_Handler, or a mmixal built-in symbol.
3771 If the name isn't a built-in name and parsed into *EXPP, return zero. */
3774 mmix_parse_predefined_name (char *name
, expressionS
*expP
)
3777 char *handler_charp
;
3778 const char handler_chars
[] = "DVWIOUZX";
3781 if (! predefined_syms
)
3784 canon_name
= tc_canonicalize_symbol_name (name
);
3786 if (canon_name
[1] == '_'
3787 && strcmp (canon_name
+ 2, "Handler") == 0
3788 && (handler_charp
= strchr (handler_chars
, *canon_name
)) != NULL
)
3790 /* If the symbol doesn't exist, provide one relative to the .text
3793 FIXME: We should provide separate sections, mapped in the linker
3795 symp
= symbol_find (name
);
3797 symp
= symbol_new (name
, text_section
,
3798 0x10 * (handler_charp
+ 1 - handler_chars
),
3799 &zero_address_frag
);
3803 /* These symbols appear when referenced; needed for
3804 mmixal-compatible programs. */
3811 } predefined_abs_syms
[] =
3813 {"Data_Segment", (valueT
) 0x20 << 56},
3814 {"Pool_Segment", (valueT
) 0x40 << 56},
3815 {"Stack_Segment", (valueT
) 0x60 << 56},
3823 {"BinaryReadWrite", 4},
3846 /* If it's already in the symbol table, we shouldn't do anything. */
3847 symp
= symbol_find (name
);
3852 i
< sizeof (predefined_abs_syms
) / sizeof (predefined_abs_syms
[0]);
3854 if (strcmp (canon_name
, predefined_abs_syms
[i
].name
) == 0)
3856 symbol_table_insert (symbol_new (predefined_abs_syms
[i
].name
,
3858 predefined_abs_syms
[i
].val
,
3859 &zero_address_frag
));
3861 /* Let gas find the symbol we just created, through its
3866 /* Not one of those symbols. Let gas handle it. */
3870 expP
->X_op
= O_symbol
;
3871 expP
->X_add_number
= 0;
3872 expP
->X_add_symbol
= symp
;
3873 expP
->X_op_symbol
= NULL
;
3878 /* Just check that we don't have a BSPEC/ESPEC pair active when changing
3879 sections "normally", and get knowledge about alignment from the new
3883 mmix_md_elf_section_change_hook (void)
3886 as_bad (_("section change from within a BSPEC/ESPEC pair is not supported"));
3888 last_alignment
= bfd_get_section_alignment (now_seg
->owner
, now_seg
);
3892 /* The LOC worker. This is like s_org, but we have to support changing
3896 s_loc (int ignore ATTRIBUTE_UNUSED
)
3904 /* Must not have a BSPEC in progress. */
3907 as_bad (_("directive LOC from within a BSPEC/ESPEC pair is not supported"));
3911 section
= expression (&exp
);
3913 if (exp
.X_op
== O_illegal
3914 || exp
.X_op
== O_absent
3915 || exp
.X_op
== O_big
3916 || section
== undefined_section
)
3918 as_bad (_("invalid LOC expression"));
3922 if (section
== absolute_section
)
3924 /* Translate a constant into a suitable section. */
3926 if (exp
.X_add_number
< ((offsetT
) 0x20 << 56))
3928 /* Lower than Data_Segment - assume it's .text. */
3929 section
= text_section
;
3931 /* Save the lowest seen location, so we can pass on this
3932 information to the linker. We don't actually org to this
3933 location here, we just pass on information to the linker so
3934 it can put the code there for us. */
3936 /* If there was already a loc (that has to be set lower than
3937 this one), we org at (this - lower). There's an implicit
3938 "LOC 0" before any entered code. FIXME: handled by spurious
3939 settings of text_has_contents. */
3940 if (exp
.X_add_number
< 0
3941 || exp
.X_add_number
< (offsetT
) lowest_text_loc
)
3943 as_bad (_("LOC expression stepping backwards is not supported"));
3944 exp
.X_op
= O_absent
;
3948 if (text_has_contents
&& lowest_text_loc
== (bfd_vma
) -1)
3949 lowest_text_loc
= 0;
3951 if (lowest_text_loc
== (bfd_vma
) -1)
3953 lowest_text_loc
= exp
.X_add_number
;
3955 /* We want only to change the section, not set an offset. */
3956 exp
.X_op
= O_absent
;
3959 exp
.X_add_number
-= lowest_text_loc
;
3964 /* Do the same for the .data section. */
3965 section
= data_section
;
3967 if (exp
.X_add_number
< (offsetT
) lowest_data_loc
)
3969 as_bad (_("LOC expression stepping backwards is not supported"));
3970 exp
.X_op
= O_absent
;
3974 if (data_has_contents
&& lowest_data_loc
== (bfd_vma
) -1)
3975 lowest_data_loc
= (bfd_vma
) 0x20 << 56;
3977 if (lowest_data_loc
== (bfd_vma
) -1)
3979 lowest_data_loc
= exp
.X_add_number
;
3981 /* We want only to change the section, not set an offset. */
3982 exp
.X_op
= O_absent
;
3985 exp
.X_add_number
-= lowest_data_loc
;
3990 if (section
!= now_seg
)
3992 obj_elf_section_change_hook ();
3993 subseg_set (section
, 0);
3995 /* Call our section change hooks using the official hook. */
3996 md_elf_section_change_hook ();
3999 if (exp
.X_op
!= O_absent
)
4001 if (exp
.X_op
!= O_constant
&& exp
.X_op
!= O_symbol
)
4003 /* Handle complex expressions. */
4004 sym
= make_expr_symbol (&exp
);
4009 sym
= exp
.X_add_symbol
;
4010 off
= exp
.X_add_number
;
4013 p
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, sym
, off
, (char *) 0);
4017 mmix_handle_rest_of_empty_line ();
4020 /* The BYTE worker. We have to support sequences of mixed "strings",
4021 numbers and other constant "first-pass" reducible expressions separated
4030 if (now_seg
== text_section
)
4031 text_has_contents
= 1;
4032 else if (now_seg
== data_section
)
4033 data_has_contents
= 1;
4038 switch (*input_line_pointer
)
4041 ++input_line_pointer
;
4042 start
= input_line_pointer
;
4043 while (is_a_char (c
= next_char_of_string ()))
4045 FRAG_APPEND_1_CHAR (c
);
4048 if (input_line_pointer
[-1] != '\"')
4050 /* We will only get here in rare cases involving #NO_APP,
4051 where the unterminated string is not recognized by the
4052 preformatting pass. */
4053 as_bad (_("unterminated string"));
4054 mmix_discard_rest_of_line ();
4062 segT expseg
= expression (&exp
);
4064 /* We have to allow special register names as constant numbers. */
4065 if ((expseg
!= absolute_section
&& expseg
!= reg_section
)
4066 || (exp
.X_op
!= O_constant
4067 && (exp
.X_op
!= O_register
4068 || exp
.X_add_number
<= 255)))
4070 as_bad (_("BYTE expression not a pure number"));
4071 mmix_discard_rest_of_line ();
4074 else if ((exp
.X_add_number
> 255 && exp
.X_op
!= O_register
)
4075 || exp
.X_add_number
< 0)
4077 /* Note that mmixal does not allow negative numbers in
4078 BYTE sequences, so neither should we. */
4079 as_bad (_("BYTE expression not in the range 0..255"));
4080 mmix_discard_rest_of_line ();
4084 FRAG_APPEND_1_CHAR (exp
.X_add_number
);
4090 c
= *input_line_pointer
++;
4094 input_line_pointer
--;
4096 if (mmix_gnu_syntax
)
4097 demand_empty_rest_of_line ();
4100 mmix_discard_rest_of_line ();
4101 /* Do like demand_empty_rest_of_line and step over the end-of-line
4103 input_line_pointer
++;
4106 /* Make sure we align for the next instruction. */
4110 /* Like cons_worker, but we have to ignore "naked comments", not barf on
4111 them. Implements WYDE, TETRA and OCTA. We're a little bit more
4112 lenient than mmix_byte but FIXME: they should eventually merge. */
4115 mmix_cons (int nbytes
)
4120 /* If we don't have any contents, then it's ok to have a specified start
4121 address that is not a multiple of the max data size. We will then
4122 align it as necessary when we get here. Otherwise, it's a fatal sin. */
4123 if (now_seg
== text_section
)
4125 if (lowest_text_loc
!= (bfd_vma
) -1
4126 && (lowest_text_loc
& (nbytes
- 1)) != 0)
4128 if (text_has_contents
)
4129 as_bad (_("data item with alignment larger than location"));
4130 else if (want_unaligned
)
4131 as_bad (_("unaligned data at an absolute location is not supported"));
4133 lowest_text_loc
&= ~((bfd_vma
) nbytes
- 1);
4134 lowest_text_loc
+= (bfd_vma
) nbytes
;
4137 text_has_contents
= 1;
4139 else if (now_seg
== data_section
)
4141 if (lowest_data_loc
!= (bfd_vma
) -1
4142 && (lowest_data_loc
& (nbytes
- 1)) != 0)
4144 if (data_has_contents
)
4145 as_bad (_("data item with alignment larger than location"));
4146 else if (want_unaligned
)
4147 as_bad (_("unaligned data at an absolute location is not supported"));
4149 lowest_data_loc
&= ~((bfd_vma
) nbytes
- 1);
4150 lowest_data_loc
+= (bfd_vma
) nbytes
;
4153 data_has_contents
= 1;
4156 /* Always align these unless asked not to (valid for the current pseudo). */
4157 if (! want_unaligned
)
4159 last_alignment
= nbytes
== 2 ? 1 : (nbytes
== 4 ? 2 : 3);
4160 frag_align (last_alignment
, 0, 0);
4161 record_alignment (now_seg
, last_alignment
);
4164 /* For mmixal compatibility, a label for an instruction (and emitting
4165 pseudo) refers to the _aligned_ address. So we have to emit the
4167 if (current_fb_label
>= 0)
4168 colon (fb_label_name (current_fb_label
, 1));
4169 else if (pending_label
!= NULL
)
4171 colon (pending_label
);
4172 pending_label
= NULL
;
4177 if (is_end_of_line
[(unsigned int) *input_line_pointer
])
4179 /* Default to zero if the expression was absent. */
4181 exp
.X_op
= O_constant
;
4182 exp
.X_add_number
= 0;
4184 exp
.X_add_symbol
= NULL
;
4185 exp
.X_op_symbol
= NULL
;
4186 emit_expr (&exp
, (unsigned int) nbytes
);
4193 switch (*input_line_pointer
)
4195 /* We support strings here too; each character takes up nbytes
4198 ++input_line_pointer
;
4199 start
= input_line_pointer
;
4200 while (is_a_char (c
= next_char_of_string ()))
4202 exp
.X_op
= O_constant
;
4203 exp
.X_add_number
= c
;
4205 emit_expr (&exp
, (unsigned int) nbytes
);
4208 if (input_line_pointer
[-1] != '\"')
4210 /* We will only get here in rare cases involving #NO_APP,
4211 where the unterminated string is not recognized by the
4212 preformatting pass. */
4213 as_bad (_("unterminated string"));
4214 mmix_discard_rest_of_line ();
4222 emit_expr (&exp
, (unsigned int) nbytes
);
4228 while (*input_line_pointer
++ == ',');
4230 input_line_pointer
--; /* Put terminator back into stream. */
4232 mmix_handle_rest_of_empty_line ();
4234 /* We don't need to step up the counter for the current_fb_label here;
4235 that's handled by the caller. */
4238 /* The md_do_align worker. At present, we just record an alignment to
4239 nullify the automatic alignment we do for WYDE, TETRA and OCTA, as gcc
4240 does not use the unaligned macros when attribute packed is used.
4241 Arguably this is a GCC bug. */
4244 mmix_md_do_align (int n
, char *fill ATTRIBUTE_UNUSED
,
4245 int len ATTRIBUTE_UNUSED
, int max ATTRIBUTE_UNUSED
)
4248 want_unaligned
= n
== 0;