1 /* tc-mmix.c -- Assembler for Don Knuth's MMIX.
2 Copyright (C) 2001-2020 Free Software Foundation, Inc.
4 This file is part of GAS, the GNU Assembler.
6 GAS is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3, or (at your option)
11 GAS is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GAS; see the file COPYING. If not, write to
18 the Free Software Foundation, 51 Franklin Street - Fifth Floor,
19 Boston, MA 02110-1301, USA. */
21 /* Knuth's assembler mmixal does not provide a relocatable format; mmo is
22 to be considered a final link-format. In the final link, we make mmo,
23 but for relocatable files, we use ELF.
25 One goal is to provide a superset of what mmixal does, including
26 compatible syntax, but the main purpose is to serve GCC. */
33 #include "opcode/mmix.h"
34 #include "safe-ctype.h"
35 #include "dwarf2dbg.h"
38 /* Something to describe what we need to do with a fixup before output,
39 for example assert something of what it became or make a relocation. */
41 enum mmix_fixup_action
45 mmix_fixup_register_or_adjust_for_byte
48 static int get_spec_regno (char *);
49 static int get_operands (int, char *, expressionS
*);
50 static int get_putget_operands (struct mmix_opcode
*, char *, expressionS
*);
51 static void s_prefix (int);
52 static void s_greg (int);
53 static void s_loc (int);
54 static void s_bspec (int);
55 static void s_espec (int);
56 static void mmix_s_local (int);
57 static void mmix_greg_internal (char *);
58 static void mmix_set_geta_branch_offset (char *, offsetT
);
59 static void mmix_set_jmp_offset (char *, offsetT
);
60 static void mmix_fill_nops (char *, int);
61 static int cmp_greg_symbol_fixes (const void *, const void *);
62 static int cmp_greg_val_greg_symbol_fixes (const void *, const void *);
63 static void mmix_handle_rest_of_empty_line (void);
64 static void mmix_discard_rest_of_line (void);
65 static void mmix_byte (void);
66 static void mmix_cons (int);
68 /* Continue the tradition of symbols.c; use control characters to enforce
69 magic. These are used when replacing e.g. 8F and 8B so we can handle
70 such labels correctly with the common parser hooks. */
71 #define MAGIC_FB_BACKWARD_CHAR '\003'
72 #define MAGIC_FB_FORWARD_CHAR '\004'
74 /* Copy the location of a frag to a fix. */
75 #define COPY_FR_WHERE_TO_FX(FRAG, FIX) \
78 (FIX)->fx_file = (FRAG)->fr_file; \
79 (FIX)->fx_line = (FRAG)->fr_line; \
83 const char *md_shortopts
= "x";
84 static int current_fb_label
= -1;
85 static char *pending_label
= NULL
;
87 static bfd_vma lowest_text_loc
= (bfd_vma
) -1;
88 static int text_has_contents
= 0;
90 /* The alignment of the previous instruction, and a boolean for whether we
91 want to avoid aligning the next WYDE, TETRA, OCTA or insn. */
92 static int last_alignment
= 0;
93 static int want_unaligned
= 0;
95 static bfd_vma lowest_data_loc
= (bfd_vma
) -1;
96 static int data_has_contents
= 0;
98 /* The fragS of the instruction being assembled. Only valid from within
100 fragS
*mmix_opcode_frag
= NULL
;
102 /* Raw GREGs as appearing in input. These may be fewer than the number
104 static int n_of_raw_gregs
= 0;
109 } mmix_raw_gregs
[MAX_GREGS
];
111 static struct loc_assert_s
116 struct loc_assert_s
*next
;
117 } *loc_asserts
= NULL
;
119 /* Fixups for all unique GREG registers. We store the fixups here in
120 md_convert_frag, then we use the array to convert
121 BFD_RELOC_MMIX_BASE_PLUS_OFFSET fixups in tc_gen_reloc. The index is
122 just a running number and is not supposed to be correlated to a
124 static fixS
*mmix_gregs
[MAX_GREGS
];
125 static int n_of_cooked_gregs
= 0;
127 /* Pointing to the register section we use for output. */
128 static asection
*real_reg_section
;
130 /* For each symbol; unknown or section symbol, we keep a list of GREG
131 definitions sorted on increasing offset. It seems no use keeping count
132 to allocate less room than the maximum number of gregs when we've found
133 one for a section or symbol. */
134 struct mmix_symbol_gregs
137 struct mmix_symbol_greg_fixes
141 /* A signed type, since we may have GREGs pointing slightly before the
142 contents of a section. */
144 } greg_fixes
[MAX_GREGS
];
147 /* Should read insert a colon on something that starts in column 0 on
149 static int label_without_colon_this_line
= 1;
151 /* Should we automatically expand instructions into multiple insns in
152 order to generate working code? */
153 static int expand_op
= 1;
155 /* Should we warn when expanding operands? FIXME: test-cases for when -x
157 static int warn_on_expansion
= 1;
159 /* Should we merge non-zero GREG register definitions? */
160 static int merge_gregs
= 1;
162 /* Should we pass on undefined BFD_RELOC_MMIX_BASE_PLUS_OFFSET relocs
163 (missing suitable GREG definitions) to the linker? */
164 static int allocate_undefined_gregs_in_linker
= 0;
166 /* Should we emit built-in symbols? */
167 static int predefined_syms
= 1;
169 /* Should we allow anything but the listed special register name
170 (e.g. equated symbols)? */
171 static int equated_spec_regs
= 1;
173 /* Do we require standard GNU syntax? */
174 int mmix_gnu_syntax
= 0;
176 /* Do we globalize all symbols? */
177 int mmix_globalize_symbols
= 0;
179 /* When expanding insns, do we want to expand PUSHJ as a call to a stub
180 (or else as a series of insns)? */
183 /* Do we know that the next semicolon is at the end of the operands field
184 (in mmixal mode; constant 1 in GNU mode)? */
185 int mmix_next_semicolon_is_eoln
= 1;
187 /* Do we have a BSPEC in progress? */
188 static int doing_bspec
= 0;
189 static const char *bspec_file
;
190 static unsigned int bspec_line
;
192 struct option md_longopts
[] =
194 #define OPTION_RELAX (OPTION_MD_BASE)
195 #define OPTION_NOEXPAND (OPTION_RELAX + 1)
196 #define OPTION_NOMERGEGREG (OPTION_NOEXPAND + 1)
197 #define OPTION_NOSYMS (OPTION_NOMERGEGREG + 1)
198 #define OPTION_GNU_SYNTAX (OPTION_NOSYMS + 1)
199 #define OPTION_GLOBALIZE_SYMBOLS (OPTION_GNU_SYNTAX + 1)
200 #define OPTION_FIXED_SPEC_REGS (OPTION_GLOBALIZE_SYMBOLS + 1)
201 #define OPTION_LINKER_ALLOCATED_GREGS (OPTION_FIXED_SPEC_REGS + 1)
202 #define OPTION_NOPUSHJSTUBS (OPTION_LINKER_ALLOCATED_GREGS + 1)
203 {"linkrelax", no_argument
, NULL
, OPTION_RELAX
},
204 {"no-expand", no_argument
, NULL
, OPTION_NOEXPAND
},
205 {"no-merge-gregs", no_argument
, NULL
, OPTION_NOMERGEGREG
},
206 {"no-predefined-syms", no_argument
, NULL
, OPTION_NOSYMS
},
207 {"gnu-syntax", no_argument
, NULL
, OPTION_GNU_SYNTAX
},
208 {"globalize-symbols", no_argument
, NULL
, OPTION_GLOBALIZE_SYMBOLS
},
209 {"fixed-special-register-names", no_argument
, NULL
,
210 OPTION_FIXED_SPEC_REGS
},
211 {"linker-allocated-gregs", no_argument
, NULL
,
212 OPTION_LINKER_ALLOCATED_GREGS
},
213 {"no-pushj-stubs", no_argument
, NULL
, OPTION_NOPUSHJSTUBS
},
214 {"no-stubs", no_argument
, NULL
, OPTION_NOPUSHJSTUBS
},
215 {NULL
, no_argument
, NULL
, 0}
218 size_t md_longopts_size
= sizeof (md_longopts
);
220 static struct hash_control
*mmix_opcode_hash
;
222 /* We use these when implementing the PREFIX pseudo. */
223 char *mmix_current_prefix
;
224 struct obstack mmix_sym_obstack
;
227 /* For MMIX, we encode the relax_substateT:s (in e.g. fr_substate) as one
228 bit length, and the relax-type shifted on top of that. There seems to
229 be no point in making the relaxation more fine-grained; the linker does
230 that better and we might interfere by changing non-optimal relaxations
231 into other insns that cannot be relaxed as easily.
233 Groups for MMIX relaxing:
236 extra length: zero or three insns.
239 extra length: zero or five insns.
242 extra length: zero or four insns.
243 Special handling to deal with transition to PUSHJSTUB.
246 extra length: zero or four insns.
249 special handling, allocates a named global register unless another
250 is within reach for all uses.
253 special handling (mostly) for external references; assumes the
254 linker will generate a stub if target is no longer than 256k from
255 the end of the section plus max size of previous stubs. Zero or
258 #define STATE_GETA (1)
259 #define STATE_BCC (2)
260 #define STATE_PUSHJ (3)
261 #define STATE_JMP (4)
262 #define STATE_GREG (5)
263 #define STATE_PUSHJSTUB (6)
265 /* No fine-grainedness here. */
266 #define STATE_LENGTH_MASK (1)
268 #define STATE_ZERO (0)
269 #define STATE_MAX (1)
271 /* More descriptive name for convenience. */
272 /* FIXME: We should start on something different, not MAX. */
273 #define STATE_UNDF STATE_MAX
275 /* FIXME: For GREG, we must have other definitions; UNDF == MAX isn't
276 appropriate; we need it the other way round. This value together with
277 fragP->tc_frag_data shows what state the frag is in: tc_frag_data
278 non-NULL means 0, NULL means 8 bytes. */
279 #define STATE_GREG_UNDF ENCODE_RELAX (STATE_GREG, STATE_ZERO)
280 #define STATE_GREG_DEF ENCODE_RELAX (STATE_GREG, STATE_MAX)
282 /* These displacements are relative to the address following the opcode
283 word of the instruction. The catch-all states have zero for "reach"
284 and "next" entries. */
286 #define GETA_0F (65536 * 4 - 8)
287 #define GETA_0B (-65536 * 4 - 4)
289 #define GETA_MAX_LEN 4 * 4
293 #define BCC_0F GETA_0F
294 #define BCC_0B GETA_0B
296 #define BCC_MAX_LEN 6 * 4
297 #define BCC_5F GETA_3F
298 #define BCC_5B GETA_3B
300 #define PUSHJ_0F GETA_0F
301 #define PUSHJ_0B GETA_0B
303 #define PUSHJ_MAX_LEN 5 * 4
304 #define PUSHJ_4F GETA_3F
305 #define PUSHJ_4B GETA_3B
307 /* We'll very rarely have sections longer than LONG_MAX, but we'll make a
308 feeble attempt at getting 64-bit values. */
309 #define PUSHJSTUB_MAX ((offsetT) (((addressT) -1) >> 1))
310 #define PUSHJSTUB_MIN (-PUSHJSTUB_MAX - 1)
312 #define JMP_0F (65536 * 256 * 4 - 8)
313 #define JMP_0B (-65536 * 256 * 4 - 4)
315 #define JMP_MAX_LEN 5 * 4
319 #define RELAX_ENCODE_SHIFT 1
320 #define ENCODE_RELAX(what, length) (((what) << RELAX_ENCODE_SHIFT) + (length))
322 const relax_typeS mmix_relax_table
[] =
324 /* Error sentinel (0, 0). */
331 {GETA_0F
, GETA_0B
, 0, ENCODE_RELAX (STATE_GETA
, STATE_MAX
)},
335 GETA_MAX_LEN
- 4, 0},
338 {BCC_0F
, BCC_0B
, 0, ENCODE_RELAX (STATE_BCC
, STATE_MAX
)},
344 /* PUSHJ (3, 0). Next state is actually PUSHJSTUB (6, 0). */
345 {PUSHJ_0F
, PUSHJ_0B
, 0, ENCODE_RELAX (STATE_PUSHJSTUB
, STATE_ZERO
)},
349 PUSHJ_MAX_LEN
- 4, 0},
352 {JMP_0F
, JMP_0B
, 0, ENCODE_RELAX (STATE_JMP
, STATE_MAX
)},
358 /* GREG (5, 0), (5, 1), though the table entry isn't used. */
359 {0, 0, 0, 0}, {0, 0, 0, 0},
361 /* PUSHJSTUB (6, 0). PUSHJ (3, 0) uses the range, so we set it to infinite. */
362 {PUSHJSTUB_MAX
, PUSHJSTUB_MIN
,
363 0, ENCODE_RELAX (STATE_PUSHJ
, STATE_MAX
)},
364 /* PUSHJSTUB (6, 1) isn't used. */
365 {0, 0, PUSHJ_MAX_LEN
, 0}
368 const pseudo_typeS md_pseudo_table
[] =
370 /* Support " .greg sym,expr" syntax. */
373 /* Support " .bspec expr" syntax. */
374 {"bspec", s_bspec
, 1},
376 /* Support " .espec" syntax. */
377 {"espec", s_espec
, 1},
379 /* Support " .local $45" syntax. */
380 {"local", mmix_s_local
, 1},
385 const char mmix_comment_chars
[] = "%!";
387 /* A ':' is a valid symbol character in mmixal. It's the prefix
388 delimiter, but other than that, it works like a symbol character,
389 except that we strip one off at the beginning of symbols. An '@' is a
390 symbol by itself (for the current location); space around it must not
392 const char mmix_symbol_chars
[] = ":@";
394 const char line_comment_chars
[] = "*#";
396 const char line_separator_chars
[] = ";";
398 const char EXP_CHARS
[] = "eE";
400 const char FLT_CHARS
[] = "rf";
403 /* Fill in the offset-related part of GETA or Bcc. */
406 mmix_set_geta_branch_offset (char *opcodep
, offsetT value
)
415 md_number_to_chars (opcodep
+ 2, value
, 2);
418 /* Fill in the offset-related part of JMP. */
421 mmix_set_jmp_offset (char *opcodep
, offsetT value
)
425 value
+= 65536 * 256 * 4;
430 md_number_to_chars (opcodep
+ 1, value
, 3);
433 /* Fill in NOP:s for the expanded part of GETA/JMP/Bcc/PUSHJ. */
436 mmix_fill_nops (char *opcodep
, int n
)
440 for (i
= 0; i
< n
; i
++)
441 md_number_to_chars (opcodep
+ i
* 4, SWYM_INSN_BYTE
<< 24, 4);
444 /* See macro md_parse_name in tc-mmix.h. */
447 mmix_current_location (void (*fn
) (expressionS
*), expressionS
*exp
)
454 /* Get up to three operands, filling them into the exp array.
455 General idea and code stolen from the tic80 port. */
458 get_operands (int max_operands
, char *s
, expressionS
*exp
)
464 while (nextchar
== ',')
466 /* Skip leading whitespace */
467 while (*p
== ' ' || *p
== '\t')
470 /* Check to see if we have any operands left to parse */
471 if (*p
== 0 || *p
== '\n' || *p
== '\r')
475 else if (numexp
== max_operands
)
477 /* This seems more sane than saying "too many operands". We'll
478 get here only if the trailing trash starts with a comma. */
479 as_bad (_("invalid operands"));
480 mmix_discard_rest_of_line ();
484 /* Begin operand parsing at the current scan point. */
486 input_line_pointer
= p
;
487 expression (&exp
[numexp
]);
489 if (exp
[numexp
].X_op
== O_illegal
)
491 as_bad (_("invalid operands"));
493 else if (exp
[numexp
].X_op
== O_absent
)
495 as_bad (_("missing operand"));
499 p
= input_line_pointer
;
501 /* Skip leading whitespace */
502 while (*p
== ' ' || *p
== '\t')
507 /* If we allow "naked" comments, ignore the rest of the line. */
510 mmix_handle_rest_of_empty_line ();
511 input_line_pointer
--;
514 /* Mark the end of the valid operands with an illegal expression. */
515 exp
[numexp
].X_op
= O_illegal
;
520 /* Get the value of a special register, or -1 if the name does not match
521 one. NAME is a null-terminated string. */
524 get_spec_regno (char *name
)
534 /* Well, it's a short array and we'll most often just match the first
536 for (i
= 0; mmix_spec_regs
[i
].name
!= NULL
; i
++)
537 if (strcmp (name
, mmix_spec_regs
[i
].name
) == 0)
538 return mmix_spec_regs
[i
].number
;
543 /* For GET and PUT, parse the register names "manually", so we don't use
546 get_putget_operands (struct mmix_opcode
*insn
, char *operands
,
549 expressionS
*expp_reg
;
550 expressionS
*expp_sreg
;
552 char *sregend
= operands
;
557 /* Skip leading whitespace */
558 while (*p
== ' ' || *p
== '\t')
561 input_line_pointer
= p
;
563 /* Initialize both possible operands to error state, in case we never
565 exp
[0].X_op
= O_illegal
;
566 exp
[1].X_op
= O_illegal
;
568 if (insn
->operands
== mmix_operands_get
)
573 expression (expp_reg
);
575 p
= input_line_pointer
;
577 /* Skip whitespace */
578 while (*p
== ' ' || *p
== '\t')
585 /* Skip whitespace */
586 while (*p
== ' ' || *p
== '\t')
589 input_line_pointer
= sregp
;
590 c
= get_symbol_name (&sregp
);
591 sregend
= input_line_pointer
;
593 ++ input_line_pointer
;
601 c
= get_symbol_name (&sregp
);
602 sregend
= input_line_pointer
;
603 restore_line_pointer (c
);
604 p
= input_line_pointer
;
606 /* Skip whitespace */
607 while (*p
== ' ' || *p
== '\t')
614 /* Skip whitespace */
615 while (*p
== ' ' || *p
== '\t')
618 input_line_pointer
= p
;
619 expression (expp_reg
);
624 regno
= get_spec_regno (sregp
);
627 /* Let the caller issue errors; we've made sure the operands are
629 if (expp_reg
->X_op
!= O_illegal
630 && expp_reg
->X_op
!= O_absent
633 expp_sreg
->X_op
= O_register
;
634 expp_sreg
->X_add_number
= regno
+ 256;
640 /* Handle MMIX-specific option. */
643 md_parse_option (int c
, const char *arg ATTRIBUTE_UNUSED
)
648 warn_on_expansion
= 0;
649 allocate_undefined_gregs_in_linker
= 1;
656 case OPTION_NOEXPAND
:
660 case OPTION_NOMERGEGREG
:
666 equated_spec_regs
= 0;
669 case OPTION_GNU_SYNTAX
:
671 label_without_colon_this_line
= 0;
674 case OPTION_GLOBALIZE_SYMBOLS
:
675 mmix_globalize_symbols
= 1;
678 case OPTION_FIXED_SPEC_REGS
:
679 equated_spec_regs
= 0;
682 case OPTION_LINKER_ALLOCATED_GREGS
:
683 allocate_undefined_gregs_in_linker
= 1;
686 case OPTION_NOPUSHJSTUBS
:
697 /* Display MMIX-specific help text. */
700 md_show_usage (FILE * stream
)
702 fprintf (stream
, _(" MMIX-specific command line options:\n"));
703 fprintf (stream
, _("\
704 -fixed-special-register-names\n\
705 Allow only the original special register names.\n"));
706 fprintf (stream
, _("\
707 -globalize-symbols Make all symbols global.\n"));
708 fprintf (stream
, _("\
709 -gnu-syntax Turn off mmixal syntax compatibility.\n"));
710 fprintf (stream
, _("\
711 -relax Create linker relaxable code.\n"));
712 fprintf (stream
, _("\
713 -no-predefined-syms Do not provide mmixal built-in constants.\n\
714 Implies -fixed-special-register-names.\n"));
715 fprintf (stream
, _("\
716 -no-expand Do not expand GETA, branches, PUSHJ or JUMP\n\
717 into multiple instructions.\n"));
718 fprintf (stream
, _("\
719 -no-merge-gregs Do not merge GREG definitions with nearby values.\n"));
720 fprintf (stream
, _("\
721 -linker-allocated-gregs If there's no suitable GREG definition for the\
722 operands of an instruction, let the linker resolve.\n"));
723 fprintf (stream
, _("\
724 -x Do not warn when an operand to GETA, a branch,\n\
725 PUSHJ or JUMP is not known to be within range.\n\
726 The linker will catch any errors. Implies\n\
727 -linker-allocated-gregs."));
730 /* Step to end of line, but don't step over the end of the line. */
733 mmix_discard_rest_of_line (void)
735 while (*input_line_pointer
736 && (! is_end_of_line
[(unsigned char) *input_line_pointer
]
737 || TC_EOL_IN_INSN (input_line_pointer
)))
738 input_line_pointer
++;
741 /* Act as demand_empty_rest_of_line if we're in strict GNU syntax mode,
742 otherwise just ignore the rest of the line (and skip the end-of-line
746 mmix_handle_rest_of_empty_line (void)
749 demand_empty_rest_of_line ();
752 mmix_discard_rest_of_line ();
753 input_line_pointer
++;
757 /* Initialize GAS MMIX specifics. */
763 const struct mmix_opcode
*opcode
;
765 /* We assume nobody will use this, so don't allocate any room. */
766 obstack_begin (&mmix_sym_obstack
, 0);
768 /* This will break the day the "lex" thingy changes. For now, it's the
769 only way to make ':' part of a name, and a name beginner. */
770 lex_type
[':'] = (LEX_NAME
| LEX_BEGIN_NAME
);
772 mmix_opcode_hash
= hash_new ();
775 = bfd_make_section_old_way (stdoutput
, MMIX_REG_SECTION_NAME
);
777 for (opcode
= mmix_opcodes
; opcode
->name
; opcode
++)
778 hash_insert (mmix_opcode_hash
, opcode
->name
, (char *) opcode
);
780 /* We always insert the ordinary registers 0..255 as registers. */
781 for (i
= 0; i
< 256; i
++)
785 /* Alternatively, we could diddle with '$' and the following number,
786 but keeping the registers as symbols helps keep parsing simple. */
787 sprintf (buf
, "$%d", i
);
788 symbol_table_insert (symbol_new (buf
, reg_section
, i
,
789 &zero_address_frag
));
792 /* Insert mmixal built-in names if allowed. */
795 for (i
= 0; mmix_spec_regs
[i
].name
!= NULL
; i
++)
796 symbol_table_insert (symbol_new (mmix_spec_regs
[i
].name
,
798 mmix_spec_regs
[i
].number
+ 256,
799 &zero_address_frag
));
801 /* FIXME: Perhaps these should be recognized as specials; as field
802 names for those instructions. */
803 symbol_table_insert (symbol_new ("ROUND_CURRENT", reg_section
, 512,
804 &zero_address_frag
));
805 symbol_table_insert (symbol_new ("ROUND_OFF", reg_section
, 512 + 1,
806 &zero_address_frag
));
807 symbol_table_insert (symbol_new ("ROUND_UP", reg_section
, 512 + 2,
808 &zero_address_frag
));
809 symbol_table_insert (symbol_new ("ROUND_DOWN", reg_section
, 512 + 3,
810 &zero_address_frag
));
811 symbol_table_insert (symbol_new ("ROUND_NEAR", reg_section
, 512 + 4,
812 &zero_address_frag
));
816 /* Assemble one insn in STR. */
819 md_assemble (char *str
)
821 char *operands
= str
;
822 char modified_char
= 0;
823 struct mmix_opcode
*instruction
;
824 fragS
*opc_fragP
= NULL
;
825 int max_operands
= 3;
827 /* Note that the struct frag member fr_literal in frags.h is char[], so
828 I have to make this a plain char *. */
829 /* unsigned */ char *opcodep
= NULL
;
834 /* Move to end of opcode. */
836 is_part_of_name (*operands
);
840 if (ISSPACE (*operands
))
842 modified_char
= *operands
;
846 instruction
= (struct mmix_opcode
*) hash_find (mmix_opcode_hash
, str
);
847 if (instruction
== NULL
)
849 as_bad (_("unknown opcode: `%s'"), str
);
851 /* Avoid "unhandled label" errors. */
852 pending_label
= NULL
;
856 /* Put back the character after the opcode. */
857 if (modified_char
!= 0)
858 operands
[-1] = modified_char
;
860 input_line_pointer
= operands
;
862 /* Is this a mmixal pseudodirective? */
863 if (instruction
->type
== mmix_type_pseudo
)
865 /* For mmixal compatibility, a label for an instruction (and
866 emitting pseudo) refers to the _aligned_ address. We emit the
867 label here for the pseudos that don't handle it themselves. When
868 having an fb-label, emit it here, and increment the counter after
870 switch (instruction
->operands
)
872 case mmix_operands_loc
:
873 case mmix_operands_byte
:
874 case mmix_operands_prefix
:
875 case mmix_operands_local
:
876 case mmix_operands_bspec
:
877 case mmix_operands_espec
:
878 if (current_fb_label
>= 0)
879 colon (fb_label_name (current_fb_label
, 1));
880 else if (pending_label
!= NULL
)
882 colon (pending_label
);
883 pending_label
= NULL
;
891 /* Some of the pseudos emit contents, others don't. Set a
892 contents-emitted flag when we emit something into .text */
893 switch (instruction
->operands
)
895 case mmix_operands_loc
:
900 case mmix_operands_byte
:
905 case mmix_operands_wyde
:
910 case mmix_operands_tetra
:
915 case mmix_operands_octa
:
920 case mmix_operands_prefix
:
925 case mmix_operands_local
:
930 case mmix_operands_bspec
:
935 case mmix_operands_espec
:
941 BAD_CASE (instruction
->operands
);
944 /* These are all working like the pseudo functions in read.c:s_...,
945 in that they step over the end-of-line marker at the end of the
946 line. We don't want that here. */
947 input_line_pointer
--;
949 /* Step up the fb-label counter if there was a definition on this
951 if (current_fb_label
>= 0)
953 fb_label_instance_inc (current_fb_label
);
954 current_fb_label
= -1;
957 /* Reset any don't-align-next-datum request, unless this was a LOC
959 if (instruction
->operands
!= mmix_operands_loc
)
965 /* Not a pseudo; we *will* emit contents. */
966 if (now_seg
== data_section
)
968 if (lowest_data_loc
!= (bfd_vma
) -1 && (lowest_data_loc
& 3) != 0)
970 if (data_has_contents
)
971 as_bad (_("specified location wasn't TETRA-aligned"));
972 else if (want_unaligned
)
973 as_bad (_("unaligned data at an absolute location is not supported"));
975 lowest_data_loc
&= ~(bfd_vma
) 3;
976 lowest_data_loc
+= 4;
979 data_has_contents
= 1;
981 else if (now_seg
== text_section
)
983 if (lowest_text_loc
!= (bfd_vma
) -1 && (lowest_text_loc
& 3) != 0)
985 if (text_has_contents
)
986 as_bad (_("specified location wasn't TETRA-aligned"));
987 else if (want_unaligned
)
988 as_bad (_("unaligned data at an absolute location is not supported"));
990 lowest_text_loc
&= ~(bfd_vma
) 3;
991 lowest_text_loc
+= 4;
994 text_has_contents
= 1;
997 /* After a sequence of BYTEs or WYDEs, we need to get to instruction
998 alignment. For other pseudos, a ".p2align 2" is supposed to be
999 inserted by the user. */
1000 if (last_alignment
< 2 && ! want_unaligned
)
1002 frag_align (2, 0, 0);
1003 record_alignment (now_seg
, 2);
1007 /* Reset any don't-align-next-datum request. */
1010 /* For mmixal compatibility, a label for an instruction (and emitting
1011 pseudo) refers to the _aligned_ address. So we have to emit the
1013 if (pending_label
!= NULL
)
1015 colon (pending_label
);
1016 pending_label
= NULL
;
1019 /* We assume that mmix_opcodes keeps having unique mnemonics for each
1020 opcode, so we don't have to iterate over more than one opcode; if the
1021 syntax does not match, then there's a syntax error. */
1023 /* Operands have little or no context and are all comma-separated; it is
1024 easier to parse each expression first. */
1025 switch (instruction
->operands
)
1027 case mmix_operands_reg_yz
:
1028 case mmix_operands_pop
:
1029 case mmix_operands_regaddr
:
1030 case mmix_operands_pushj
:
1031 case mmix_operands_get
:
1032 case mmix_operands_put
:
1033 case mmix_operands_set
:
1034 case mmix_operands_save
:
1035 case mmix_operands_unsave
:
1039 case mmix_operands_sync
:
1040 case mmix_operands_jmp
:
1041 case mmix_operands_resume
:
1045 /* The original 3 is fine for the rest. */
1050 /* If this is GET or PUT, and we don't do allow those names to be
1051 equated, we need to parse the names ourselves, so we don't pick up a
1052 user label instead of the special register. */
1053 if (! equated_spec_regs
1054 && (instruction
->operands
== mmix_operands_get
1055 || instruction
->operands
== mmix_operands_put
))
1056 n_operands
= get_putget_operands (instruction
, operands
, exp
);
1058 n_operands
= get_operands (max_operands
, operands
, exp
);
1060 /* If there's a fb-label on the current line, set that label. This must
1061 be done *after* evaluating expressions of operands, since neither a
1062 "1B" nor a "1F" refers to "1H" on the same line. */
1063 if (current_fb_label
>= 0)
1065 fb_label_instance_inc (current_fb_label
);
1066 colon (fb_label_name (current_fb_label
, 0));
1067 current_fb_label
= -1;
1070 /* We also assume that the length of the instruction is at least 4, the
1071 size of an unexpanded instruction. We need a self-contained frag
1072 since we want the relocation to point to the instruction, not the
1075 opcodep
= frag_more (4);
1076 mmix_opcode_frag
= opc_fragP
= frag_now
;
1077 frag_now
->fr_opcode
= opcodep
;
1079 /* Mark start of insn for DWARF2 debug features. */
1080 if (OUTPUT_FLAVOR
== bfd_target_elf_flavour
)
1081 dwarf2_emit_insn (4);
1083 md_number_to_chars (opcodep
, instruction
->match
, 4);
1085 switch (instruction
->operands
)
1087 case mmix_operands_jmp
:
1088 if (n_operands
== 0 && ! mmix_gnu_syntax
)
1089 /* Zeros are in place - nothing needs to be done when we have no
1093 /* Add a frag for a JMP relaxation; we need room for max four
1094 extra instructions. We don't do any work around here to check if
1095 we can determine the offset right away. */
1096 if (n_operands
!= 1 || exp
[0].X_op
== O_register
)
1098 as_bad (_("invalid operand to opcode %s: `%s'"),
1099 instruction
->name
, operands
);
1104 frag_var (rs_machine_dependent
, 4 * 4, 0,
1105 ENCODE_RELAX (STATE_JMP
, STATE_UNDF
),
1106 exp
[0].X_add_symbol
,
1107 exp
[0].X_add_number
,
1110 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
, 4,
1111 exp
+ 0, 1, BFD_RELOC_MMIX_ADDR27
);
1114 case mmix_operands_pushj
:
1115 /* We take care of PUSHJ in full here. */
1117 || ((exp
[0].X_op
== O_constant
|| exp
[0].X_op
== O_register
)
1118 && (exp
[0].X_add_number
> 255 || exp
[0].X_add_number
< 0)))
1120 as_bad (_("invalid operands to opcode %s: `%s'"),
1121 instruction
->name
, operands
);
1125 if (exp
[0].X_op
== O_register
|| exp
[0].X_op
== O_constant
)
1126 opcodep
[1] = exp
[0].X_add_number
;
1128 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 1,
1129 1, exp
+ 0, 0, BFD_RELOC_MMIX_REG_OR_BYTE
);
1132 frag_var (rs_machine_dependent
, PUSHJ_MAX_LEN
- 4, 0,
1133 ENCODE_RELAX (STATE_PUSHJ
, STATE_UNDF
),
1134 exp
[1].X_add_symbol
,
1135 exp
[1].X_add_number
,
1138 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
, 4,
1139 exp
+ 1, 1, BFD_RELOC_MMIX_ADDR19
);
1142 case mmix_operands_regaddr
:
1143 /* GETA/branch: Add a frag for relaxation. We don't do any work
1144 around here to check if we can determine the offset right away. */
1145 if (n_operands
!= 2 || exp
[1].X_op
== O_register
)
1147 as_bad (_("invalid operands to opcode %s: `%s'"),
1148 instruction
->name
, operands
);
1153 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
, 4,
1154 exp
+ 1, 1, BFD_RELOC_MMIX_ADDR19
);
1155 else if (instruction
->type
== mmix_type_condbranch
)
1156 frag_var (rs_machine_dependent
, BCC_MAX_LEN
- 4, 0,
1157 ENCODE_RELAX (STATE_BCC
, STATE_UNDF
),
1158 exp
[1].X_add_symbol
,
1159 exp
[1].X_add_number
,
1162 frag_var (rs_machine_dependent
, GETA_MAX_LEN
- 4, 0,
1163 ENCODE_RELAX (STATE_GETA
, STATE_UNDF
),
1164 exp
[1].X_add_symbol
,
1165 exp
[1].X_add_number
,
1173 switch (instruction
->operands
)
1175 case mmix_operands_regs
:
1176 /* We check the number of operands here, since we're in a
1177 FALLTHROUGH sequence in the next switch. */
1178 if (n_operands
!= 3 || exp
[2].X_op
== O_constant
)
1180 as_bad (_("invalid operands to opcode %s: `%s'"),
1181 instruction
->name
, operands
);
1185 case mmix_operands_regs_z
:
1186 if (n_operands
!= 3)
1188 as_bad (_("invalid operands to opcode %s: `%s'"),
1189 instruction
->name
, operands
);
1193 case mmix_operands_reg_yz
:
1194 case mmix_operands_roundregs_z
:
1195 case mmix_operands_roundregs
:
1196 case mmix_operands_regs_z_opt
:
1197 case mmix_operands_neg
:
1198 case mmix_operands_regaddr
:
1199 case mmix_operands_get
:
1200 case mmix_operands_set
:
1201 case mmix_operands_save
:
1203 || (exp
[0].X_op
== O_register
&& exp
[0].X_add_number
> 255))
1205 as_bad (_("invalid operands to opcode %s: `%s'"),
1206 instruction
->name
, operands
);
1210 if (exp
[0].X_op
== O_register
)
1211 opcodep
[1] = exp
[0].X_add_number
;
1213 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 1,
1214 1, exp
+ 0, 0, BFD_RELOC_MMIX_REG
);
1221 /* A corresponding once-over for those who take an 8-bit constant as
1222 their first operand. */
1223 switch (instruction
->operands
)
1225 case mmix_operands_pushgo
:
1226 /* PUSHGO: X is a constant, but can be expressed as a register.
1227 We handle X here and use the common machinery of T,X,3,$ for
1228 the rest of the operands. */
1230 || ((exp
[0].X_op
== O_constant
|| exp
[0].X_op
== O_register
)
1231 && (exp
[0].X_add_number
> 255 || exp
[0].X_add_number
< 0)))
1233 as_bad (_("invalid operands to opcode %s: `%s'"),
1234 instruction
->name
, operands
);
1237 else if (exp
[0].X_op
== O_constant
|| exp
[0].X_op
== O_register
)
1238 opcodep
[1] = exp
[0].X_add_number
;
1240 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 1,
1241 1, exp
+ 0, 0, BFD_RELOC_MMIX_REG_OR_BYTE
);
1244 case mmix_operands_pop
:
1245 if ((n_operands
== 0 || n_operands
== 1) && ! mmix_gnu_syntax
)
1248 case mmix_operands_x_regs_z
:
1250 || (exp
[0].X_op
== O_constant
1251 && (exp
[0].X_add_number
> 255
1252 || exp
[0].X_add_number
< 0)))
1254 as_bad (_("invalid operands to opcode %s: `%s'"),
1255 instruction
->name
, operands
);
1259 if (exp
[0].X_op
== O_constant
)
1260 opcodep
[1] = exp
[0].X_add_number
;
1262 /* FIXME: This doesn't bring us unsignedness checking. */
1263 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 1,
1264 1, exp
+ 0, 0, BFD_RELOC_8
);
1269 /* Handle the rest. */
1270 switch (instruction
->operands
)
1272 case mmix_operands_set
:
1273 /* SET: Either two registers, "$X,$Y", with Z field as zero, or
1274 "$X,YZ", meaning change the opcode to SETL. */
1276 || (exp
[1].X_op
== O_constant
1277 && (exp
[1].X_add_number
> 0xffff || exp
[1].X_add_number
< 0)))
1279 as_bad (_("invalid operands to opcode %s: `%s'"),
1280 instruction
->name
, operands
);
1284 if (exp
[1].X_op
== O_constant
)
1286 /* There's an ambiguity with "SET $0,Y" when Y isn't defined
1287 yet. To keep things simple, we assume that Y is then a
1288 register, and only change the opcode if Y is defined at this
1291 There's no compatibility problem with mmixal, since it emits
1292 errors if the field is not defined at this point. */
1293 md_number_to_chars (opcodep
, SETL_INSN_BYTE
, 1);
1295 opcodep
[2] = (exp
[1].X_add_number
>> 8) & 255;
1296 opcodep
[3] = exp
[1].X_add_number
& 255;
1300 case mmix_operands_x_regs_z
:
1301 /* SYNCD: "X,$Y,$Z|Z". */
1303 case mmix_operands_regs
:
1304 /* Three registers, $X,$Y,$Z. */
1306 case mmix_operands_regs_z
:
1307 /* Operands "$X,$Y,$Z|Z", number of arguments checked above. */
1309 case mmix_operands_pushgo
:
1310 /* Operands "$X|X,$Y,$Z|Z", optional Z. */
1312 case mmix_operands_regs_z_opt
:
1313 /* Operands "$X,$Y,$Z|Z", with $Z|Z being optional, default 0. Any
1314 operands not completely decided yet are postponed to later in
1315 assembly (but not until link-time yet). */
1317 if ((n_operands
!= 2 && n_operands
!= 3)
1318 || (exp
[1].X_op
== O_register
&& exp
[1].X_add_number
> 255)
1320 && ((exp
[2].X_op
== O_register
1321 && exp
[2].X_add_number
> 255
1323 || (exp
[2].X_op
== O_constant
1324 && (exp
[2].X_add_number
> 255
1325 || exp
[2].X_add_number
< 0)))))
1327 as_bad (_("invalid operands to opcode %s: `%s'"),
1328 instruction
->name
, operands
);
1332 if (n_operands
== 2)
1336 /* The last operand is immediate whenever we see just two
1338 opcodep
[0] |= IMM_OFFSET_BIT
;
1340 /* Now, we could either have an implied "0" as the Z operand, or
1341 it could be the constant of a "base address plus offset". It
1342 depends on whether it is allowed; only memory operations, as
1343 signified by instruction->type and "T" and "X" operand types,
1344 and it depends on whether we find a register in the second
1346 if (exp
[1].X_op
== O_register
&& exp
[1].X_add_number
<= 255)
1348 /* A zero then; all done. */
1349 opcodep
[2] = exp
[1].X_add_number
;
1353 /* Not known as a register. Is base address plus offset
1354 allowed, or can we assume that it is a register anyway? */
1355 if ((instruction
->operands
!= mmix_operands_regs_z_opt
1356 && instruction
->operands
!= mmix_operands_x_regs_z
1357 && instruction
->operands
!= mmix_operands_pushgo
)
1358 || (instruction
->type
!= mmix_type_memaccess_octa
1359 && instruction
->type
!= mmix_type_memaccess_tetra
1360 && instruction
->type
!= mmix_type_memaccess_wyde
1361 && instruction
->type
!= mmix_type_memaccess_byte
1362 && instruction
->type
!= mmix_type_memaccess_block
1363 && instruction
->type
!= mmix_type_jsr
1364 && instruction
->type
!= mmix_type_branch
))
1366 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 2,
1367 1, exp
+ 1, 0, BFD_RELOC_MMIX_REG
);
1371 /* To avoid getting a NULL add_symbol for constants and then
1372 catching a SEGV in write_relocs since it doesn't handle
1373 constants well for relocs other than PC-relative, we need to
1374 pass expressions as symbols and use fix_new, not fix_new_exp. */
1375 sym
= make_expr_symbol (exp
+ 1);
1377 /* Mark the symbol as being OK for a reloc. */
1378 symbol_get_bfdsym (sym
)->flags
|= BSF_KEEP
;
1380 /* Now we know it can be a "base address plus offset". Add
1381 proper fixup types so we can handle this later, when we've
1382 parsed everything. */
1383 fix_new (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 2,
1384 8, sym
, 0, 0, BFD_RELOC_MMIX_BASE_PLUS_OFFSET
);
1388 if (exp
[1].X_op
== O_register
)
1389 opcodep
[2] = exp
[1].X_add_number
;
1391 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 2,
1392 1, exp
+ 1, 0, BFD_RELOC_MMIX_REG
);
1394 /* In mmixal compatibility mode, we allow special registers as
1395 constants for the Z operand. They have 256 added to their
1396 register numbers, so the right thing will happen if we just treat
1397 those as constants. */
1398 if (exp
[2].X_op
== O_register
&& exp
[2].X_add_number
<= 255)
1399 opcodep
[3] = exp
[2].X_add_number
;
1400 else if (exp
[2].X_op
== O_constant
1401 || (exp
[2].X_op
== O_register
&& exp
[2].X_add_number
> 255))
1403 opcodep
[3] = exp
[2].X_add_number
;
1404 opcodep
[0] |= IMM_OFFSET_BIT
;
1407 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 3,
1409 (instruction
->operands
== mmix_operands_set
1410 || instruction
->operands
== mmix_operands_regs
)
1411 ? BFD_RELOC_MMIX_REG
: BFD_RELOC_MMIX_REG_OR_BYTE
);
1414 case mmix_operands_pop
:
1415 /* POP, one eight and one 16-bit operand. */
1416 if (n_operands
== 0 && ! mmix_gnu_syntax
)
1418 if (n_operands
== 1 && ! mmix_gnu_syntax
)
1419 goto a_single_24_bit_number_operand
;
1421 case mmix_operands_reg_yz
:
1422 /* A register and a 16-bit unsigned number. */
1424 || exp
[1].X_op
== O_register
1425 || (exp
[1].X_op
== O_constant
1426 && (exp
[1].X_add_number
> 0xffff || exp
[1].X_add_number
< 0)))
1428 as_bad (_("invalid operands to opcode %s: `%s'"),
1429 instruction
->name
, operands
);
1433 if (exp
[1].X_op
== O_constant
)
1435 opcodep
[2] = (exp
[1].X_add_number
>> 8) & 255;
1436 opcodep
[3] = exp
[1].X_add_number
& 255;
1439 /* FIXME: This doesn't bring us unsignedness checking. */
1440 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 2,
1441 2, exp
+ 1, 0, BFD_RELOC_16
);
1444 case mmix_operands_jmp
:
1445 /* A JMP. Everything is already done. */
1448 case mmix_operands_roundregs
:
1449 /* Two registers with optional rounding mode or constant in between. */
1450 if ((n_operands
== 3 && exp
[2].X_op
== O_constant
)
1451 || (n_operands
== 2 && exp
[1].X_op
== O_constant
))
1453 as_bad (_("invalid operands to opcode %s: `%s'"),
1454 instruction
->name
, operands
);
1458 case mmix_operands_roundregs_z
:
1459 /* Like FLOT, "$X,ROUND_MODE,$Z|Z", but the rounding mode is
1460 optional and can be the corresponding constant. */
1462 /* Which exp index holds the second operand (not the rounding
1464 int op2no
= n_operands
- 1;
1466 if ((n_operands
!= 2 && n_operands
!= 3)
1467 || ((exp
[op2no
].X_op
== O_register
1468 && exp
[op2no
].X_add_number
> 255)
1469 || (exp
[op2no
].X_op
== O_constant
1470 && (exp
[op2no
].X_add_number
> 255
1471 || exp
[op2no
].X_add_number
< 0)))
1473 /* We don't allow for the rounding mode to be deferred; it
1474 must be determined in the "first pass". It cannot be a
1475 symbol equated to a rounding mode, but defined after
1477 && ((exp
[1].X_op
== O_register
1478 && exp
[1].X_add_number
< 512)
1479 || (exp
[1].X_op
== O_constant
1480 && (exp
[1].X_add_number
< 0
1481 || exp
[1].X_add_number
> 4))
1482 || (exp
[1].X_op
!= O_register
1483 && exp
[1].X_op
!= O_constant
))))
1485 as_bad (_("invalid operands to opcode %s: `%s'"),
1486 instruction
->name
, operands
);
1490 /* Add rounding mode if present. */
1491 if (n_operands
== 3)
1492 opcodep
[2] = exp
[1].X_add_number
& 255;
1494 if (exp
[op2no
].X_op
== O_register
)
1495 opcodep
[3] = exp
[op2no
].X_add_number
;
1496 else if (exp
[op2no
].X_op
== O_constant
)
1498 opcodep
[3] = exp
[op2no
].X_add_number
;
1499 opcodep
[0] |= IMM_OFFSET_BIT
;
1502 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 3,
1504 instruction
->operands
== mmix_operands_roundregs
1505 ? BFD_RELOC_MMIX_REG
1506 : BFD_RELOC_MMIX_REG_OR_BYTE
);
1510 case mmix_operands_sync
:
1511 a_single_24_bit_number_operand
:
1513 || exp
[0].X_op
== O_register
1514 || (exp
[0].X_op
== O_constant
1515 && (exp
[0].X_add_number
> 0xffffff || exp
[0].X_add_number
< 0)))
1517 as_bad (_("invalid operands to opcode %s: `%s'"),
1518 instruction
->name
, operands
);
1522 if (exp
[0].X_op
== O_constant
)
1524 opcodep
[1] = (exp
[0].X_add_number
>> 16) & 255;
1525 opcodep
[2] = (exp
[0].X_add_number
>> 8) & 255;
1526 opcodep
[3] = exp
[0].X_add_number
& 255;
1529 /* FIXME: This doesn't bring us unsignedness checking. */
1530 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 1,
1531 3, exp
+ 0, 0, BFD_RELOC_24
);
1534 case mmix_operands_neg
:
1535 /* Operands "$X,Y,$Z|Z"; NEG or NEGU. Y is optional, 0 is default. */
1537 if ((n_operands
!= 3 && n_operands
!= 2)
1538 || (n_operands
== 3 && exp
[1].X_op
== O_register
)
1539 || ((exp
[1].X_op
== O_constant
|| exp
[1].X_op
== O_register
)
1540 && (exp
[1].X_add_number
> 255 || exp
[1].X_add_number
< 0))
1542 && ((exp
[2].X_op
== O_register
&& exp
[2].X_add_number
> 255)
1543 || (exp
[2].X_op
== O_constant
1544 && (exp
[2].X_add_number
> 255
1545 || exp
[2].X_add_number
< 0)))))
1547 as_bad (_("invalid operands to opcode %s: `%s'"),
1548 instruction
->name
, operands
);
1552 if (n_operands
== 2)
1554 if (exp
[1].X_op
== O_register
)
1555 opcodep
[3] = exp
[1].X_add_number
;
1556 else if (exp
[1].X_op
== O_constant
)
1558 opcodep
[3] = exp
[1].X_add_number
;
1559 opcodep
[0] |= IMM_OFFSET_BIT
;
1562 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 3,
1563 1, exp
+ 1, 0, BFD_RELOC_MMIX_REG_OR_BYTE
);
1567 if (exp
[1].X_op
== O_constant
)
1568 opcodep
[2] = exp
[1].X_add_number
;
1570 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 2,
1571 1, exp
+ 1, 0, BFD_RELOC_8
);
1573 if (exp
[2].X_op
== O_register
)
1574 opcodep
[3] = exp
[2].X_add_number
;
1575 else if (exp
[2].X_op
== O_constant
)
1577 opcodep
[3] = exp
[2].X_add_number
;
1578 opcodep
[0] |= IMM_OFFSET_BIT
;
1581 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 3,
1582 1, exp
+ 2, 0, BFD_RELOC_MMIX_REG_OR_BYTE
);
1585 case mmix_operands_regaddr
:
1586 /* A GETA/branch-type. */
1589 case mmix_operands_get
:
1590 /* "$X,spec_reg"; GET.
1591 Like with rounding modes, we demand that the special register or
1592 symbol is already defined when we get here at the point of use. */
1594 || (exp
[1].X_op
== O_register
1595 && (exp
[1].X_add_number
< 256 || exp
[1].X_add_number
>= 512))
1596 || (exp
[1].X_op
== O_constant
1597 && (exp
[1].X_add_number
< 0 || exp
[1].X_add_number
> 256))
1598 || (exp
[1].X_op
!= O_constant
&& exp
[1].X_op
!= O_register
))
1600 as_bad (_("invalid operands to opcode %s: `%s'"),
1601 instruction
->name
, operands
);
1605 opcodep
[3] = exp
[1].X_add_number
- 256;
1608 case mmix_operands_put
:
1609 /* "spec_reg,$Z|Z"; PUT. */
1611 || (exp
[0].X_op
== O_register
1612 && (exp
[0].X_add_number
< 256 || exp
[0].X_add_number
>= 512))
1613 || (exp
[0].X_op
== O_constant
1614 && (exp
[0].X_add_number
< 0 || exp
[0].X_add_number
> 256))
1615 || (exp
[0].X_op
!= O_constant
&& exp
[0].X_op
!= O_register
))
1617 as_bad (_("invalid operands to opcode %s: `%s'"),
1618 instruction
->name
, operands
);
1622 opcodep
[1] = exp
[0].X_add_number
- 256;
1624 /* Note that the Y field is zero. */
1626 if (exp
[1].X_op
== O_register
)
1627 opcodep
[3] = exp
[1].X_add_number
;
1628 else if (exp
[1].X_op
== O_constant
)
1630 opcodep
[3] = exp
[1].X_add_number
;
1631 opcodep
[0] |= IMM_OFFSET_BIT
;
1634 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 3,
1635 1, exp
+ 1, 0, BFD_RELOC_MMIX_REG_OR_BYTE
);
1638 case mmix_operands_save
:
1641 || exp
[1].X_op
!= O_constant
1642 || exp
[1].X_add_number
!= 0)
1644 as_bad (_("invalid operands to opcode %s: `%s'"),
1645 instruction
->name
, operands
);
1650 case mmix_operands_unsave
:
1651 if (n_operands
< 2 && ! mmix_gnu_syntax
)
1653 if (n_operands
== 1)
1655 if (exp
[0].X_op
== O_register
)
1656 opcodep
[3] = exp
[0].X_add_number
;
1658 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 3,
1659 1, exp
, 0, BFD_RELOC_MMIX_REG
);
1664 /* "0,$Z"; UNSAVE. */
1666 || exp
[0].X_op
!= O_constant
1667 || exp
[0].X_add_number
!= 0
1668 || exp
[1].X_op
== O_constant
1669 || (exp
[1].X_op
== O_register
1670 && exp
[1].X_add_number
> 255))
1672 as_bad (_("invalid operands to opcode %s: `%s'"),
1673 instruction
->name
, operands
);
1677 if (exp
[1].X_op
== O_register
)
1678 opcodep
[3] = exp
[1].X_add_number
;
1680 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 3,
1681 1, exp
+ 1, 0, BFD_RELOC_MMIX_REG
);
1684 case mmix_operands_xyz_opt
:
1685 /* SWYM, TRIP, TRAP: zero, one, two or three operands. It's
1686 unspecified whether operands are registers or constants, but
1687 when we find register syntax, we require operands to be literal and
1689 if (n_operands
== 0 && ! mmix_gnu_syntax
)
1690 /* Zeros are in place - nothing needs to be done for zero
1691 operands. We don't allow this in GNU syntax mode, because it
1692 was believed that the risk of missing to supply an operand is
1693 higher than the benefit of not having to specify a zero. */
1695 else if (n_operands
== 1 && exp
[0].X_op
!= O_register
)
1697 if (exp
[0].X_op
== O_constant
)
1699 if (exp
[0].X_add_number
> 255*256*256
1700 || exp
[0].X_add_number
< 0)
1702 as_bad (_("invalid operands to opcode %s: `%s'"),
1703 instruction
->name
, operands
);
1708 opcodep
[1] = (exp
[0].X_add_number
>> 16) & 255;
1709 opcodep
[2] = (exp
[0].X_add_number
>> 8) & 255;
1710 opcodep
[3] = exp
[0].X_add_number
& 255;
1714 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 1,
1715 3, exp
, 0, BFD_RELOC_24
);
1717 else if (n_operands
== 2
1718 && exp
[0].X_op
!= O_register
1719 && exp
[1].X_op
!= O_register
)
1723 if (exp
[0].X_op
== O_constant
)
1725 if (exp
[0].X_add_number
> 255
1726 || exp
[0].X_add_number
< 0)
1728 as_bad (_("invalid operands to opcode %s: `%s'"),
1729 instruction
->name
, operands
);
1733 opcodep
[1] = exp
[0].X_add_number
& 255;
1736 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 1,
1737 1, exp
, 0, BFD_RELOC_8
);
1739 if (exp
[1].X_op
== O_constant
)
1741 if (exp
[1].X_add_number
> 255*256
1742 || exp
[1].X_add_number
< 0)
1744 as_bad (_("invalid operands to opcode %s: `%s'"),
1745 instruction
->name
, operands
);
1750 opcodep
[2] = (exp
[1].X_add_number
>> 8) & 255;
1751 opcodep
[3] = exp
[1].X_add_number
& 255;
1755 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 2,
1756 2, exp
+ 1, 0, BFD_RELOC_16
);
1758 else if (n_operands
== 3
1759 && exp
[0].X_op
!= O_register
1760 && exp
[1].X_op
!= O_register
1761 && exp
[2].X_op
!= O_register
)
1763 /* Three operands. */
1765 if (exp
[0].X_op
== O_constant
)
1767 if (exp
[0].X_add_number
> 255
1768 || exp
[0].X_add_number
< 0)
1770 as_bad (_("invalid operands to opcode %s: `%s'"),
1771 instruction
->name
, operands
);
1775 opcodep
[1] = exp
[0].X_add_number
& 255;
1778 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 1,
1779 1, exp
, 0, BFD_RELOC_8
);
1781 if (exp
[1].X_op
== O_constant
)
1783 if (exp
[1].X_add_number
> 255
1784 || exp
[1].X_add_number
< 0)
1786 as_bad (_("invalid operands to opcode %s: `%s'"),
1787 instruction
->name
, operands
);
1791 opcodep
[2] = exp
[1].X_add_number
& 255;
1794 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 2,
1795 1, exp
+ 1, 0, BFD_RELOC_8
);
1797 if (exp
[2].X_op
== O_constant
)
1799 if (exp
[2].X_add_number
> 255
1800 || exp
[2].X_add_number
< 0)
1802 as_bad (_("invalid operands to opcode %s: `%s'"),
1803 instruction
->name
, operands
);
1807 opcodep
[3] = exp
[2].X_add_number
& 255;
1810 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 3,
1811 1, exp
+ 2, 0, BFD_RELOC_8
);
1815 /* We can't get here for other cases. */
1816 gas_assert (n_operands
<= 3);
1818 /* The meaning of operands to TRIP and TRAP is not defined (and
1819 SWYM operands aren't enforced in mmixal, so let's avoid
1820 that). We add combinations not handled above here as we find
1821 them and as they're reported. */
1822 if (n_operands
== 3)
1824 /* Don't require non-register operands. Always generate
1825 fixups, so we don't have to copy lots of code and create
1826 maintenance problems. TRIP is supposed to be a rare
1827 instruction, so the overhead should not matter. We
1828 aren't allowed to fix_new_exp for an expression which is
1829 an O_register at this point, however.
1831 Don't use BFD_RELOC_MMIX_REG_OR_BYTE as that modifies
1832 the insn for a register in the Z field and we want
1834 if (exp
[0].X_op
== O_register
)
1835 opcodep
[1] = exp
[0].X_add_number
;
1837 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 1,
1838 1, exp
, 0, BFD_RELOC_8
);
1839 if (exp
[1].X_op
== O_register
)
1840 opcodep
[2] = exp
[1].X_add_number
;
1842 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 2,
1843 1, exp
+ 1, 0, BFD_RELOC_8
);
1844 if (exp
[2].X_op
== O_register
)
1845 opcodep
[3] = exp
[2].X_add_number
;
1847 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 3,
1848 1, exp
+ 2, 0, BFD_RELOC_8
);
1850 else if (n_operands
== 2)
1852 if (exp
[0].X_op
== O_register
)
1853 opcodep
[1] = exp
[0].X_add_number
;
1855 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 1,
1856 1, exp
, 0, BFD_RELOC_8
);
1857 if (exp
[1].X_op
== O_register
)
1858 opcodep
[3] = exp
[1].X_add_number
;
1860 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 2,
1861 2, exp
+ 1, 0, BFD_RELOC_16
);
1865 /* We can't get here for other cases. */
1866 gas_assert (n_operands
== 1 && exp
[0].X_op
== O_register
);
1868 opcodep
[3] = exp
[0].X_add_number
;
1873 case mmix_operands_resume
:
1874 if (n_operands
== 0 && ! mmix_gnu_syntax
)
1878 || exp
[0].X_op
== O_register
1879 || (exp
[0].X_op
== O_constant
1880 && (exp
[0].X_add_number
< 0
1881 || exp
[0].X_add_number
> 255)))
1883 as_bad (_("invalid operands to opcode %s: `%s'"),
1884 instruction
->name
, operands
);
1888 if (exp
[0].X_op
== O_constant
)
1889 opcodep
[3] = exp
[0].X_add_number
;
1891 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 3,
1892 1, exp
+ 0, 0, BFD_RELOC_8
);
1895 case mmix_operands_pushj
:
1896 /* All is done for PUSHJ already. */
1900 BAD_CASE (instruction
->operands
);
1904 /* For the benefit of insns that start with a digit, we assemble by way of
1905 tc_unrecognized_line too, through this function. */
1908 mmix_assemble_return_nonzero (char *str
)
1910 int last_error_count
= had_errors ();
1914 /* Normal instruction handling downcases, so we must too. */
1915 while (ISALNUM (*s2
))
1917 if (ISUPPER ((unsigned char) *s2
))
1918 *s2
= TOLOWER (*s2
);
1922 /* Cut the line for sake of the assembly. */
1923 for (s2
= str
; *s2
&& *s2
!= '\n'; s2
++)
1931 return had_errors () == last_error_count
;
1934 /* The PREFIX pseudo. */
1937 s_prefix (int unused ATTRIBUTE_UNUSED
)
1944 c
= get_symbol_name (&p
);
1946 /* Resetting prefix? */
1947 if (*p
== ':' && p
[1] == 0)
1948 mmix_current_prefix
= NULL
;
1951 /* Put this prefix on the mmix symbols obstack. We could malloc and
1952 free it separately, but then we'd have to worry about that.
1953 People using up memory on prefixes have other problems. */
1954 obstack_grow (&mmix_sym_obstack
, p
, strlen (p
) + 1);
1955 p
= obstack_finish (&mmix_sym_obstack
);
1957 /* Accumulate prefixes, and strip a leading ':'. */
1958 if (mmix_current_prefix
!= NULL
|| *p
== ':')
1959 p
= mmix_prefix_name (p
);
1961 mmix_current_prefix
= p
;
1964 (void) restore_line_pointer (c
);
1966 mmix_handle_rest_of_empty_line ();
1969 /* We implement prefixes by using the tc_canonicalize_symbol_name hook,
1970 and store each prefixed name on a (separate) obstack. This means that
1971 the name is on the "notes" obstack in non-prefixed form and on the
1972 mmix_sym_obstack in prefixed form, but currently it is not worth
1973 rewriting the whole GAS symbol handling to improve "hooking" to avoid
1974 that. (It might be worth a rewrite for other reasons, though). */
1977 mmix_prefix_name (char *shortname
)
1979 if (*shortname
== ':')
1980 return shortname
+ 1;
1982 if (mmix_current_prefix
== NULL
)
1983 as_fatal (_("internal: mmix_prefix_name but empty prefix"));
1985 if (*shortname
== '$')
1988 obstack_grow (&mmix_sym_obstack
, mmix_current_prefix
,
1989 strlen (mmix_current_prefix
));
1990 obstack_grow (&mmix_sym_obstack
, shortname
, strlen (shortname
) + 1);
1991 return obstack_finish (&mmix_sym_obstack
);
1994 /* The GREG pseudo. At LABEL, we have the name of a symbol that we
1995 want to make a register symbol, and which should be initialized with
1996 the value in the expression at INPUT_LINE_POINTER (defaulting to 0).
1997 Either and (perhaps less meaningful) both may be missing. LABEL must
1998 be persistent, perhaps allocated on an obstack. */
2001 mmix_greg_internal (char *label
)
2003 expressionS
*expP
= &mmix_raw_gregs
[n_of_raw_gregs
].exp
;
2006 /* Don't set the section to register contents section before the
2007 expression has been parsed; it may refer to the current position. */
2008 section
= expression (expP
);
2010 /* FIXME: Check that no expression refers to the register contents
2011 section. May need to be done in elf64-mmix.c. */
2012 if (expP
->X_op
== O_absent
)
2014 /* Default to zero if the expression was absent. */
2015 expP
->X_op
= O_constant
;
2016 expP
->X_add_number
= 0;
2017 expP
->X_unsigned
= 0;
2018 expP
->X_add_symbol
= NULL
;
2019 expP
->X_op_symbol
= NULL
;
2022 if (section
== undefined_section
)
2024 /* This is an error or a LOC with an expression involving
2025 forward references. For the expression to be correctly
2026 evaluated, we need to force a proper symbol; gas loses track
2027 of the segment for "local symbols". */
2028 if (expP
->X_op
== O_add
)
2030 symbol_get_value_expression (expP
->X_op_symbol
);
2031 symbol_get_value_expression (expP
->X_add_symbol
);
2035 gas_assert (expP
->X_op
== O_symbol
);
2036 symbol_get_value_expression (expP
->X_add_symbol
);
2040 /* We must handle prefixes here, as we save the labels and expressions
2041 to be output later. */
2042 mmix_raw_gregs
[n_of_raw_gregs
].label
2043 = mmix_current_prefix
== NULL
? label
: mmix_prefix_name (label
);
2045 if (n_of_raw_gregs
== MAX_GREGS
- 1)
2046 as_bad (_("too many GREG registers allocated (max %d)"), MAX_GREGS
);
2050 mmix_handle_rest_of_empty_line ();
2053 /* The ".greg label,expr" worker. */
2056 s_greg (int unused ATTRIBUTE_UNUSED
)
2061 /* This will skip over what can be a symbol and zero out the next
2062 character, which we assume is a ',' or other meaningful delimiter.
2063 What comes after that is the initializer expression for the
2065 c
= get_symbol_name (&p
);
2068 c
= * ++ input_line_pointer
;
2070 if (! is_end_of_line
[(unsigned char) c
])
2071 input_line_pointer
++;
2075 /* The label must be persistent; it's not used until after all input
2077 obstack_grow (&mmix_sym_obstack
, p
, strlen (p
) + 1);
2078 mmix_greg_internal (obstack_finish (&mmix_sym_obstack
));
2081 mmix_greg_internal (NULL
);
2084 /* The "BSPEC expr" worker. */
2087 s_bspec (int unused ATTRIBUTE_UNUSED
)
2091 char secname
[sizeof (MMIX_OTHER_SPEC_SECTION_PREFIX
) + 20]
2092 = MMIX_OTHER_SPEC_SECTION_PREFIX
;
2096 /* Get a constant expression which we can evaluate *now*. Supporting
2097 more complex (though assembly-time computable) expressions is
2098 feasible but Too Much Work for something of unknown usefulness like
2100 expsec
= expression (&exp
);
2101 mmix_handle_rest_of_empty_line ();
2103 /* Check that we don't have another BSPEC in progress. */
2106 as_bad (_("BSPEC already active. Nesting is not supported."));
2110 if (exp
.X_op
!= O_constant
2111 || expsec
!= absolute_section
2112 || exp
.X_add_number
< 0
2113 || exp
.X_add_number
> 65535)
2115 as_bad (_("invalid BSPEC expression"));
2116 exp
.X_add_number
= 0;
2119 n
= (int) exp
.X_add_number
;
2121 sprintf (secname
+ strlen (MMIX_OTHER_SPEC_SECTION_PREFIX
), "%d", n
);
2122 sec
= bfd_get_section_by_name (stdoutput
, secname
);
2125 /* We need a non-volatile name as it will be stored in the section
2127 char *newsecname
= xstrdup (secname
);
2128 sec
= bfd_make_section (stdoutput
, newsecname
);
2131 as_fatal (_("can't create section %s"), newsecname
);
2133 if (!bfd_set_section_flags (sec
,
2134 bfd_section_flags (sec
) | SEC_READONLY
))
2135 as_fatal (_("can't set section flags for section %s"), newsecname
);
2138 /* Tell ELF about the pending section change. */
2139 obj_elf_section_change_hook ();
2140 subseg_set (sec
, 0);
2142 /* Save position for missing ESPEC. */
2143 bspec_file
= as_where (&bspec_line
);
2148 /* The "ESPEC" worker. */
2151 s_espec (int unused ATTRIBUTE_UNUSED
)
2153 /* First, check that we *do* have a BSPEC in progress. */
2156 as_bad (_("ESPEC without preceding BSPEC"));
2160 mmix_handle_rest_of_empty_line ();
2163 /* When we told ELF about the section change in s_bspec, it stored the
2164 previous section for us so we can get at it with the equivalent of a
2165 .previous pseudo. */
2166 obj_elf_previous (0);
2169 /* The " .local expr" and " local expr" worker. We make a BFD_MMIX_LOCAL
2170 relocation against the current position against the expression.
2171 Implementing this by means of contents in a section lost. */
2174 mmix_s_local (int unused ATTRIBUTE_UNUSED
)
2178 /* Don't set the section to register contents section before the
2179 expression has been parsed; it may refer to the current position in
2180 some contorted way. */
2183 if (exp
.X_op
== O_absent
)
2185 as_bad (_("missing local expression"));
2188 else if (exp
.X_op
== O_register
)
2190 /* fix_new_exp doesn't like O_register. Should be configurable.
2191 We're fine with a constant here, though. */
2192 exp
.X_op
= O_constant
;
2195 fix_new_exp (frag_now
, 0, 0, &exp
, 0, BFD_RELOC_MMIX_LOCAL
);
2196 mmix_handle_rest_of_empty_line ();
2199 /* Set fragP->fr_var to the initial guess of the size of a relaxable insn
2200 and return it. Sizes of other instructions are not known. This
2201 function may be called multiple times. */
2204 md_estimate_size_before_relax (fragS
*fragP
, segT segment
)
2208 #define HANDLE_RELAXABLE(state) \
2209 case ENCODE_RELAX (state, STATE_UNDF): \
2210 if (fragP->fr_symbol != NULL \
2211 && S_GET_SEGMENT (fragP->fr_symbol) == segment \
2212 && !S_IS_WEAK (fragP->fr_symbol)) \
2214 /* The symbol lies in the same segment - a relaxable case. */ \
2216 = ENCODE_RELAX (state, STATE_ZERO); \
2220 switch (fragP
->fr_subtype
)
2222 HANDLE_RELAXABLE (STATE_GETA
);
2223 HANDLE_RELAXABLE (STATE_BCC
);
2224 HANDLE_RELAXABLE (STATE_JMP
);
2226 case ENCODE_RELAX (STATE_PUSHJ
, STATE_UNDF
):
2227 if (fragP
->fr_symbol
!= NULL
2228 && S_GET_SEGMENT (fragP
->fr_symbol
) == segment
2229 && !S_IS_WEAK (fragP
->fr_symbol
))
2230 /* The symbol lies in the same segment - a relaxable case. */
2231 fragP
->fr_subtype
= ENCODE_RELAX (STATE_PUSHJ
, STATE_ZERO
);
2232 else if (pushj_stubs
)
2233 /* If we're to generate stubs, assume we can reach a stub after
2235 fragP
->fr_subtype
= ENCODE_RELAX (STATE_PUSHJSTUB
, STATE_ZERO
);
2237 case ENCODE_RELAX (STATE_PUSHJ
, STATE_ZERO
):
2238 case ENCODE_RELAX (STATE_PUSHJSTUB
, STATE_ZERO
):
2239 /* We need to distinguish different relaxation rounds. */
2240 seg_info (segment
)->tc_segment_info_data
.last_stubfrag
= fragP
;
2243 case ENCODE_RELAX (STATE_GETA
, STATE_ZERO
):
2244 case ENCODE_RELAX (STATE_BCC
, STATE_ZERO
):
2245 case ENCODE_RELAX (STATE_JMP
, STATE_ZERO
):
2246 /* When relaxing a section for the second time, we don't need to do
2247 anything except making sure that fr_var is set right. */
2250 case STATE_GREG_DEF
:
2251 length
= fragP
->tc_frag_data
!= NULL
? 0 : 8;
2252 fragP
->fr_var
= length
;
2254 /* Don't consult the relax_table; it isn't valid for this
2260 BAD_CASE (fragP
->fr_subtype
);
2263 length
= mmix_relax_table
[fragP
->fr_subtype
].rlx_length
;
2264 fragP
->fr_var
= length
;
2269 /* Turn a string in input_line_pointer into a floating point constant of type
2270 type, and store the appropriate bytes in *litP. The number of LITTLENUMS
2271 emitted is stored in *sizeP . An error message is returned, or NULL on
2275 md_atof (int type
, char *litP
, int *sizeP
)
2279 /* FIXME: Having 'f' in FLT_CHARS (and here) makes it
2280 problematic to also have a forward reference in an expression.
2281 The testsuite wants it, and it's customary.
2282 We'll deal with the real problems when they come; we share the
2283 problem with most other ports. */
2284 return ieee_md_atof (type
, litP
, sizeP
, TRUE
);
2287 /* Convert variable-sized frags into one or more fixups. */
2290 md_convert_frag (bfd
*abfd ATTRIBUTE_UNUSED
, segT sec ATTRIBUTE_UNUSED
,
2293 /* Pointer to first byte in variable-sized part of the frag. */
2296 /* Pointer to first opcode byte in frag. */
2299 /* Size in bytes of variable-sized part of frag. */
2300 int var_part_size
= 0;
2302 /* This is part of *fragP. It contains all information about addresses
2303 and offsets to varying parts. */
2305 unsigned long var_part_offset
;
2307 /* This is the frag for the opcode. It, rather than fragP, must be used
2308 when emitting a frag for the opcode. */
2309 fragS
*opc_fragP
= fragP
->tc_frag_data
;
2312 /* Where, in file space, does addr point? */
2313 bfd_vma target_address
;
2314 bfd_vma opcode_address
;
2316 know (fragP
->fr_type
== rs_machine_dependent
);
2318 var_part_offset
= fragP
->fr_fix
;
2319 var_partp
= fragP
->fr_literal
+ var_part_offset
;
2320 opcodep
= fragP
->fr_opcode
;
2322 symbolP
= fragP
->fr_symbol
;
2325 = ((symbolP
? S_GET_VALUE (symbolP
) : 0) + fragP
->fr_offset
);
2327 /* The opcode that would be extended is the last four "fixed" bytes. */
2328 opcode_address
= fragP
->fr_address
+ fragP
->fr_fix
- 4;
2330 switch (fragP
->fr_subtype
)
2332 case ENCODE_RELAX (STATE_PUSHJSTUB
, STATE_ZERO
):
2333 /* Setting the unknown bits to 0 seems the most appropriate. */
2334 mmix_set_geta_branch_offset (opcodep
, 0);
2335 tmpfixP
= fix_new (opc_fragP
, opcodep
- opc_fragP
->fr_literal
, 8,
2336 fragP
->fr_symbol
, fragP
->fr_offset
, 1,
2337 BFD_RELOC_MMIX_PUSHJ_STUBBABLE
);
2338 COPY_FR_WHERE_TO_FX (fragP
, tmpfixP
);
2342 case ENCODE_RELAX (STATE_GETA
, STATE_ZERO
):
2343 case ENCODE_RELAX (STATE_BCC
, STATE_ZERO
):
2344 case ENCODE_RELAX (STATE_PUSHJ
, STATE_ZERO
):
2345 mmix_set_geta_branch_offset (opcodep
, target_address
- opcode_address
);
2349 = fix_new (opc_fragP
, opcodep
- opc_fragP
->fr_literal
, 4,
2350 fragP
->fr_symbol
, fragP
->fr_offset
, 1,
2351 BFD_RELOC_MMIX_ADDR19
);
2352 COPY_FR_WHERE_TO_FX (fragP
, tmpfixP
);
2357 case ENCODE_RELAX (STATE_JMP
, STATE_ZERO
):
2358 mmix_set_jmp_offset (opcodep
, target_address
- opcode_address
);
2362 = fix_new (opc_fragP
, opcodep
- opc_fragP
->fr_literal
, 4,
2363 fragP
->fr_symbol
, fragP
->fr_offset
, 1,
2364 BFD_RELOC_MMIX_ADDR27
);
2365 COPY_FR_WHERE_TO_FX (fragP
, tmpfixP
);
2370 case STATE_GREG_DEF
:
2371 if (fragP
->tc_frag_data
== NULL
)
2373 /* We must initialize data that's supposed to be "fixed up" to
2374 avoid emitting garbage, because md_apply_fix won't do
2375 anything for undefined symbols. */
2376 md_number_to_chars (var_partp
, 0, 8);
2378 = fix_new (fragP
, var_partp
- fragP
->fr_literal
, 8,
2379 fragP
->fr_symbol
, fragP
->fr_offset
, 0, BFD_RELOC_64
);
2380 COPY_FR_WHERE_TO_FX (fragP
, tmpfixP
);
2381 mmix_gregs
[n_of_cooked_gregs
++] = tmpfixP
;
2388 #define HANDLE_MAX_RELOC(state, reloc) \
2389 case ENCODE_RELAX (state, STATE_MAX): \
2391 = mmix_relax_table[ENCODE_RELAX (state, STATE_MAX)].rlx_length; \
2392 mmix_fill_nops (var_partp, var_part_size / 4); \
2393 if (warn_on_expansion) \
2394 as_warn_where (fragP->fr_file, fragP->fr_line, \
2395 _("operand out of range, instruction expanded")); \
2396 tmpfixP = fix_new (fragP, var_partp - fragP->fr_literal - 4, 8, \
2397 fragP->fr_symbol, fragP->fr_offset, 1, reloc); \
2398 COPY_FR_WHERE_TO_FX (fragP, tmpfixP); \
2401 HANDLE_MAX_RELOC (STATE_GETA
, BFD_RELOC_MMIX_GETA
);
2402 HANDLE_MAX_RELOC (STATE_BCC
, BFD_RELOC_MMIX_CBRANCH
);
2403 HANDLE_MAX_RELOC (STATE_PUSHJ
, BFD_RELOC_MMIX_PUSHJ
);
2404 HANDLE_MAX_RELOC (STATE_JMP
, BFD_RELOC_MMIX_JMP
);
2407 BAD_CASE (fragP
->fr_subtype
);
2411 fragP
->fr_fix
+= var_part_size
;
2415 /* Applies the desired value to the specified location.
2416 Also sets up addends for RELA type relocations.
2417 Stolen from tc-mcore.c.
2419 Note that this function isn't called when linkrelax != 0. */
2422 md_apply_fix (fixS
*fixP
, valueT
*valP
, segT segment
)
2424 char *buf
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
2425 /* Note: use offsetT because it is signed, valueT is unsigned. */
2426 offsetT val
= (offsetT
) * valP
;
2428 = (fixP
->fx_addsy
== NULL
2429 ? absolute_section
: S_GET_SEGMENT (fixP
->fx_addsy
));
2431 /* If the fix is relative to a symbol which is not defined, or, (if
2432 pcrel), not in the same segment as the fix, we cannot resolve it
2434 if (fixP
->fx_addsy
!= NULL
2435 && (! S_IS_DEFINED (fixP
->fx_addsy
)
2436 || S_IS_WEAK (fixP
->fx_addsy
)
2437 || (fixP
->fx_pcrel
&& symsec
!= segment
)
2438 || (! fixP
->fx_pcrel
2439 && symsec
!= absolute_section
2440 && ((fixP
->fx_r_type
!= BFD_RELOC_MMIX_REG
2441 && fixP
->fx_r_type
!= BFD_RELOC_MMIX_REG_OR_BYTE
)
2442 || symsec
!= reg_section
))))
2447 else if (fixP
->fx_r_type
== BFD_RELOC_MMIX_LOCAL
2448 || fixP
->fx_r_type
== BFD_RELOC_VTABLE_INHERIT
2449 || fixP
->fx_r_type
== BFD_RELOC_VTABLE_ENTRY
)
2451 /* These are never "fixed". */
2456 /* We assume every other relocation is "fixed". */
2459 switch (fixP
->fx_r_type
)
2466 case BFD_RELOC_64_PCREL
:
2467 case BFD_RELOC_32_PCREL
:
2468 case BFD_RELOC_24_PCREL
:
2469 case BFD_RELOC_16_PCREL
:
2470 case BFD_RELOC_8_PCREL
:
2471 md_number_to_chars (buf
, val
, fixP
->fx_size
);
2474 case BFD_RELOC_MMIX_ADDR19
:
2477 /* This shouldn't happen. */
2478 BAD_CASE (fixP
->fx_r_type
);
2482 case BFD_RELOC_MMIX_GETA
:
2483 case BFD_RELOC_MMIX_CBRANCH
:
2484 case BFD_RELOC_MMIX_PUSHJ
:
2485 case BFD_RELOC_MMIX_PUSHJ_STUBBABLE
:
2486 /* If this fixup is out of range, punt to the linker to emit an
2487 error. This should only happen with -no-expand. */
2488 if (val
< -(((offsetT
) 1 << 19)/2)
2489 || val
>= ((offsetT
) 1 << 19)/2 - 1
2492 if (warn_on_expansion
)
2493 as_warn_where (fixP
->fx_file
, fixP
->fx_line
,
2494 _("operand out of range"));
2498 mmix_set_geta_branch_offset (buf
, val
);
2501 case BFD_RELOC_MMIX_ADDR27
:
2504 /* This shouldn't happen. */
2505 BAD_CASE (fixP
->fx_r_type
);
2509 case BFD_RELOC_MMIX_JMP
:
2510 /* If this fixup is out of range, punt to the linker to emit an
2511 error. This should only happen with -no-expand. */
2512 if (val
< -(((offsetT
) 1 << 27)/2)
2513 || val
>= ((offsetT
) 1 << 27)/2 - 1
2516 if (warn_on_expansion
)
2517 as_warn_where (fixP
->fx_file
, fixP
->fx_line
,
2518 _("operand out of range"));
2522 mmix_set_jmp_offset (buf
, val
);
2525 case BFD_RELOC_MMIX_REG_OR_BYTE
:
2526 if (fixP
->fx_addsy
!= NULL
2527 && (S_GET_SEGMENT (fixP
->fx_addsy
) != reg_section
2528 || S_GET_VALUE (fixP
->fx_addsy
) > 255)
2529 && S_GET_SEGMENT (fixP
->fx_addsy
) != absolute_section
)
2531 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
2532 _("invalid operands"));
2533 /* We don't want this "symbol" appearing in output, because
2540 /* If this reloc is for a Z field, we need to adjust
2541 the opcode if we got a constant here.
2542 FIXME: Can we make this more robust? */
2544 if ((fixP
->fx_where
& 3) == 3
2545 && (fixP
->fx_addsy
== NULL
2546 || S_GET_SEGMENT (fixP
->fx_addsy
) == absolute_section
))
2547 buf
[-3] |= IMM_OFFSET_BIT
;
2550 case BFD_RELOC_MMIX_REG
:
2551 if (fixP
->fx_addsy
== NULL
2552 || S_GET_SEGMENT (fixP
->fx_addsy
) != reg_section
2553 || S_GET_VALUE (fixP
->fx_addsy
) > 255)
2555 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
2556 _("invalid operands"));
2563 case BFD_RELOC_MMIX_BASE_PLUS_OFFSET
:
2564 /* These are never "fixed". */
2568 case BFD_RELOC_MMIX_PUSHJ_1
:
2569 case BFD_RELOC_MMIX_PUSHJ_2
:
2570 case BFD_RELOC_MMIX_PUSHJ_3
:
2571 case BFD_RELOC_MMIX_CBRANCH_J
:
2572 case BFD_RELOC_MMIX_CBRANCH_1
:
2573 case BFD_RELOC_MMIX_CBRANCH_2
:
2574 case BFD_RELOC_MMIX_CBRANCH_3
:
2575 case BFD_RELOC_MMIX_GETA_1
:
2576 case BFD_RELOC_MMIX_GETA_2
:
2577 case BFD_RELOC_MMIX_GETA_3
:
2578 case BFD_RELOC_MMIX_JMP_1
:
2579 case BFD_RELOC_MMIX_JMP_2
:
2580 case BFD_RELOC_MMIX_JMP_3
:
2582 BAD_CASE (fixP
->fx_r_type
);
2587 /* Make sure that for completed fixups we have the value around for
2588 use by e.g. mmix_frob_file. */
2589 fixP
->fx_offset
= val
;
2592 /* A bsearch function for looking up a value against offsets for GREG
2596 cmp_greg_val_greg_symbol_fixes (const void *p1
, const void *p2
)
2598 offsetT val1
= *(offsetT
*) p1
;
2599 offsetT val2
= ((struct mmix_symbol_greg_fixes
*) p2
)->offs
;
2601 if (val1
>= val2
&& val1
< val2
+ 255)
2610 /* Generate a machine-dependent relocation. */
2613 tc_gen_reloc (asection
*section ATTRIBUTE_UNUSED
, fixS
*fixP
)
2617 + (fixP
->fx_addsy
!= NULL
2618 && !S_IS_WEAK (fixP
->fx_addsy
)
2619 && !S_IS_COMMON (fixP
->fx_addsy
)
2620 ? S_GET_VALUE (fixP
->fx_addsy
) : 0);
2622 bfd_reloc_code_real_type code
= BFD_RELOC_NONE
;
2623 char *buf
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
2624 symbolS
*addsy
= fixP
->fx_addsy
;
2625 asection
*addsec
= addsy
== NULL
? NULL
: S_GET_SEGMENT (addsy
);
2626 asymbol
*baddsy
= addsy
!= NULL
? symbol_get_bfdsym (addsy
) : NULL
;
2628 = val
- (baddsy
== NULL
|| S_IS_COMMON (addsy
) || S_IS_WEAK (addsy
)
2629 ? 0 : bfd_asymbol_value (baddsy
));
2631 /* A single " LOCAL expression" in the wrong section will not work when
2632 linking to MMO; relocations for zero-content sections are then
2633 ignored. Normally, relocations would modify section contents, and
2634 you'd never think or be able to do something like that. The
2635 relocation resulting from a LOCAL directive doesn't have an obvious
2636 and mandatory location. I can't figure out a way to do this better
2637 than just helping the user around this limitation here; hopefully the
2638 code using the local expression is around. Putting the LOCAL
2639 semantics in a relocation still seems right; a section didn't do. */
2640 if (bfd_section_size (section
) == 0)
2642 (fixP
->fx_file
, fixP
->fx_line
,
2643 fixP
->fx_r_type
== BFD_RELOC_MMIX_LOCAL
2644 /* The BFD_RELOC_MMIX_LOCAL-specific message is supposed to be
2645 user-friendly, though a little bit non-substantial. */
2646 ? _("directive LOCAL must be placed in code or data")
2647 : _("internal confusion: relocation in a section without contents"));
2649 /* FIXME: Range tests for all these. */
2650 switch (fixP
->fx_r_type
)
2657 code
= fixP
->fx_r_type
;
2659 if (addsy
== NULL
|| bfd_is_abs_section (addsec
))
2661 /* Resolve this reloc now, as md_apply_fix would have done (not
2662 called if -linkrelax). There is no point in keeping a reloc
2663 to an absolute symbol. No reloc that is subject to
2664 relaxation must be to an absolute symbol; difference
2665 involving symbols in a specific section must be signalled as
2666 an error if the relaxing cannot be expressed; having a reloc
2667 to the resolved (now absolute) value does not help. */
2668 md_number_to_chars (buf
, val
, fixP
->fx_size
);
2673 case BFD_RELOC_64_PCREL
:
2674 case BFD_RELOC_32_PCREL
:
2675 case BFD_RELOC_24_PCREL
:
2676 case BFD_RELOC_16_PCREL
:
2677 case BFD_RELOC_8_PCREL
:
2678 case BFD_RELOC_MMIX_LOCAL
:
2679 case BFD_RELOC_VTABLE_INHERIT
:
2680 case BFD_RELOC_VTABLE_ENTRY
:
2681 case BFD_RELOC_MMIX_GETA
:
2682 case BFD_RELOC_MMIX_GETA_1
:
2683 case BFD_RELOC_MMIX_GETA_2
:
2684 case BFD_RELOC_MMIX_GETA_3
:
2685 case BFD_RELOC_MMIX_CBRANCH
:
2686 case BFD_RELOC_MMIX_CBRANCH_J
:
2687 case BFD_RELOC_MMIX_CBRANCH_1
:
2688 case BFD_RELOC_MMIX_CBRANCH_2
:
2689 case BFD_RELOC_MMIX_CBRANCH_3
:
2690 case BFD_RELOC_MMIX_PUSHJ
:
2691 case BFD_RELOC_MMIX_PUSHJ_1
:
2692 case BFD_RELOC_MMIX_PUSHJ_2
:
2693 case BFD_RELOC_MMIX_PUSHJ_3
:
2694 case BFD_RELOC_MMIX_PUSHJ_STUBBABLE
:
2695 case BFD_RELOC_MMIX_JMP
:
2696 case BFD_RELOC_MMIX_JMP_1
:
2697 case BFD_RELOC_MMIX_JMP_2
:
2698 case BFD_RELOC_MMIX_JMP_3
:
2699 case BFD_RELOC_MMIX_ADDR19
:
2700 case BFD_RELOC_MMIX_ADDR27
:
2701 code
= fixP
->fx_r_type
;
2704 case BFD_RELOC_MMIX_REG_OR_BYTE
:
2705 /* If we have this kind of relocation to an unknown symbol or to the
2706 register contents section (that is, to a register), then we can't
2707 resolve the relocation here. */
2709 && (bfd_is_und_section (addsec
)
2710 || strcmp (bfd_section_name (addsec
),
2711 MMIX_REG_CONTENTS_SECTION_NAME
) == 0))
2713 code
= fixP
->fx_r_type
;
2717 /* If the relocation is not to the register section or to the
2718 absolute section (a numeric value), then we have an error. */
2720 && (S_GET_SEGMENT (addsy
) != real_reg_section
2723 && ! bfd_is_abs_section (addsec
))
2726 /* Set the "immediate" bit of the insn if this relocation is to Z
2727 field when the value is a numeric value, i.e. not a register. */
2728 if ((fixP
->fx_where
& 3) == 3
2729 && (addsy
== NULL
|| bfd_is_abs_section (addsec
)))
2730 buf
[-3] |= IMM_OFFSET_BIT
;
2735 case BFD_RELOC_MMIX_BASE_PLUS_OFFSET
:
2737 && strcmp (bfd_section_name (addsec
),
2738 MMIX_REG_CONTENTS_SECTION_NAME
) == 0)
2740 /* This changed into a register; the relocation is for the
2741 register-contents section. The constant part remains zero. */
2742 code
= BFD_RELOC_MMIX_REG
;
2746 /* If we've found out that this was indeed a register, then replace
2747 with the register number. The constant part is already zero.
2749 If we encounter any other defined symbol, then we must find a
2750 suitable register and emit a reloc. */
2751 if (addsy
== NULL
|| addsec
!= real_reg_section
)
2753 struct mmix_symbol_gregs
*gregs
;
2754 struct mmix_symbol_greg_fixes
*fix
;
2756 if (S_IS_DEFINED (addsy
)
2757 && !bfd_is_com_section (addsec
)
2758 && !S_IS_WEAK (addsy
))
2760 if (! symbol_section_p (addsy
) && ! bfd_is_abs_section (addsec
))
2761 as_fatal (_("internal: BFD_RELOC_MMIX_BASE_PLUS_OFFSET not resolved to section"));
2763 /* If this is an absolute symbol sufficiently near
2764 lowest_data_loc, then we canonicalize on the data
2765 section. Note that val is signed here; we may subtract
2766 lowest_data_loc which is unsigned. Careful with those
2768 if (lowest_data_loc
!= (bfd_vma
) -1
2769 && (bfd_vma
) val
+ 256 > lowest_data_loc
2770 && bfd_is_abs_section (addsec
))
2772 val
-= (offsetT
) lowest_data_loc
;
2773 addsy
= section_symbol (data_section
);
2775 /* Likewise text section. */
2776 else if (lowest_text_loc
!= (bfd_vma
) -1
2777 && (bfd_vma
) val
+ 256 > lowest_text_loc
2778 && bfd_is_abs_section (addsec
))
2780 val
-= (offsetT
) lowest_text_loc
;
2781 addsy
= section_symbol (text_section
);
2785 gregs
= *symbol_get_tc (addsy
);
2787 /* If that symbol does not have any associated GREG definitions,
2788 we can't do anything. */
2790 || (fix
= bsearch (&val
, gregs
->greg_fixes
, gregs
->n_gregs
,
2791 sizeof (gregs
->greg_fixes
[0]),
2792 cmp_greg_val_greg_symbol_fixes
)) == NULL
2793 /* The register must not point *after* the address we want. */
2795 /* Neither must the register point more than 255 bytes
2796 before the address we want. */
2797 || fix
->offs
+ 255 < val
)
2799 /* We can either let the linker allocate GREGs
2800 automatically, or emit an error. */
2801 if (allocate_undefined_gregs_in_linker
)
2803 /* The values in baddsy and addend are right. */
2804 code
= fixP
->fx_r_type
;
2808 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
2809 _("no suitable GREG definition for operands"));
2814 /* Transform the base-plus-offset reloc for the actual area
2815 to a reloc for the register with the address of the area.
2816 Put addend for register in Z operand. */
2817 buf
[1] = val
- fix
->offs
;
2818 code
= BFD_RELOC_MMIX_REG
;
2820 = (bfd_get_section_by_name (stdoutput
,
2821 MMIX_REG_CONTENTS_SECTION_NAME
)
2824 addend
= fix
->fix
->fx_frag
->fr_address
+ fix
->fix
->fx_where
;
2827 else if (S_GET_VALUE (addsy
) > 255)
2828 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
2829 _("invalid operands"));
2837 case BFD_RELOC_MMIX_REG
:
2839 && (bfd_is_und_section (addsec
)
2840 || strcmp (bfd_section_name (addsec
),
2841 MMIX_REG_CONTENTS_SECTION_NAME
) == 0))
2843 code
= fixP
->fx_r_type
;
2848 && (addsec
!= real_reg_section
2851 && ! bfd_is_und_section (addsec
))
2852 /* Drop through to error message. */
2861 /* The others are supposed to be handled by md_apply_fix.
2862 FIXME: ... which isn't called when -linkrelax. Move over
2863 md_apply_fix code here for everything reasonable. */
2867 (fixP
->fx_file
, fixP
->fx_line
,
2868 _("operands were not reducible at assembly-time"));
2870 /* Unmark this symbol as used in a reloc, so we don't bump into a BFD
2871 assert when trying to output reg_section. FIXME: A gas bug. */
2872 fixP
->fx_addsy
= NULL
;
2876 relP
= XNEW (arelent
);
2877 gas_assert (relP
!= 0);
2878 relP
->sym_ptr_ptr
= XNEW (asymbol
*);
2879 *relP
->sym_ptr_ptr
= baddsy
;
2880 relP
->address
= fixP
->fx_frag
->fr_address
+ fixP
->fx_where
;
2882 relP
->addend
= addend
;
2884 /* If this had been a.out, we would have had a kludge for weak symbols
2887 relP
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
2892 name
= S_GET_NAME (addsy
);
2894 name
= _("<unknown>");
2895 as_fatal (_("cannot generate relocation type for symbol %s, code %s"),
2896 name
, bfd_get_reloc_code_name (code
));
2902 /* Do some reformatting of a line. FIXME: We could transform a mmixal
2903 line into traditional (GNU?) format, unless #NO_APP, and get rid of all
2904 ugly labels_without_colons etc. */
2907 mmix_handle_mmixal (void)
2910 char *s
= input_line_pointer
;
2914 if (pending_label
!= NULL
)
2915 as_fatal (_("internal: unhandled label %s"), pending_label
);
2917 if (mmix_gnu_syntax
)
2920 /* If we're on a line with a label, check if it's a mmixal fb-label.
2921 Save an indicator and skip the label; it must be set only after all
2922 fb-labels of expressions are evaluated. */
2923 if (ISDIGIT (s
[0]) && s
[1] == 'H' && ISSPACE (s
[2]))
2925 current_fb_label
= s
[0] - '0';
2927 /* We have to skip the label, but also preserve the newlineness of
2928 the previous character, since the caller checks that. It's a
2929 mess we blame on the caller. */
2932 input_line_pointer
= s
;
2934 while (*s
&& ISSPACE (*s
) && ! is_end_of_line
[(unsigned int) *s
])
2937 /* For errors emitted here, the book-keeping is off by one; the
2938 caller is about to bump the counters. Adjust the error messages. */
2939 if (is_end_of_line
[(unsigned int) *s
])
2942 const char * name
= as_where (&line
);
2943 as_bad_where (name
, line
+ 1,
2944 _("[0-9]H labels may not appear alone on a line"));
2945 current_fb_label
= -1;
2950 const char * name
= as_where (&line
);
2951 as_bad_where (name
, line
+ 1,
2952 _("[0-9]H labels do not mix with dot-pseudos"));
2953 current_fb_label
= -1;
2956 /* Back off to the last space before the opcode so we don't handle
2957 the opcode as a label. */
2961 current_fb_label
= -1;
2965 /* If the first character is a '.', then it's a pseudodirective, not a
2966 label. Make GAS not handle label-without-colon on this line. We
2967 also don't do mmixal-specific stuff on this line. */
2968 label_without_colon_this_line
= 0;
2972 if (*s
== 0 || is_end_of_line
[(unsigned int) *s
])
2973 /* We avoid handling empty lines here. */
2976 if (is_name_beginner (*s
))
2979 /* If there is a label, skip over it. */
2980 while (*s
&& is_part_of_name (*s
))
2983 /* Find the start of the instruction or pseudo following the label,
2986 *insn
&& ISSPACE (*insn
) && ! is_end_of_line
[(unsigned int) *insn
];
2991 /* Remove a trailing ":" off labels, as they'd otherwise be considered
2992 part of the name. But don't do this for local labels. */
2993 if (s
!= input_line_pointer
&& s
[-1] == ':'
2994 && (s
- 2 != input_line_pointer
2995 || ! ISDIGIT (s
[-2])))
2997 else if (label
!= NULL
2998 /* For a lone label on a line, we don't attach it to the next
2999 instruction or MMIXAL-pseudo (getting its alignment). Thus
3000 is acts like a "normal" :-ended label. Ditto if it's
3001 followed by a non-MMIXAL pseudo. */
3002 && !is_end_of_line
[(unsigned int) *insn
]
3005 /* For labels that don't end in ":", we save it so we can later give
3006 it the same alignment and address as the associated instruction. */
3008 /* Make room for the label including the ending nul. */
3009 size_t len_0
= s
- label
+ 1;
3011 /* Save this label on the MMIX symbol obstack. Saving it on an
3012 obstack is needless for "IS"-pseudos, but it's harmless and we
3013 avoid a little code-cluttering. */
3014 obstack_grow (&mmix_sym_obstack
, label
, len_0
);
3015 pending_label
= obstack_finish (&mmix_sym_obstack
);
3016 pending_label
[len_0
- 1] = 0;
3019 /* If we have a non-MMIXAL pseudo, we have not business with the rest of
3024 /* Find local labels of operands. Look for "[0-9][FB]" where the
3025 characters before and after are not part of words. Break if a single
3026 or double quote is seen anywhere. It means we can't have local
3027 labels as part of list with mixed quoted and unquoted members for
3028 mmixal compatibility but we can't have it all. For the moment.
3029 Replace the '<N>B' or '<N>F' with MAGIC_FB_BACKWARD_CHAR<N> and
3030 MAGIC_FB_FORWARD_CHAR<N> respectively. */
3032 /* First make sure we don't have any of the magic characters on the line
3033 appearing as input. */
3037 if (is_end_of_line
[(unsigned int) c
])
3039 if (c
== MAGIC_FB_BACKWARD_CHAR
|| c
== MAGIC_FB_FORWARD_CHAR
)
3040 as_bad (_("invalid characters in input"));
3043 /* Scan again, this time looking for ';' after operands. */
3046 /* Skip the insn. */
3050 && ! is_end_of_line
[(unsigned int) *s
])
3053 /* Skip the spaces after the insn. */
3057 && ! is_end_of_line
[(unsigned int) *s
])
3060 /* Skip the operands. While doing this, replace [0-9][BF] with
3061 (MAGIC_FB_BACKWARD_CHAR|MAGIC_FB_FORWARD_CHAR)[0-9]. */
3062 while ((c
= *s
) != 0
3065 && ! is_end_of_line
[(unsigned int) c
])
3071 /* FIXME: Test-case for semi-colon in string. */
3074 && (! is_end_of_line
[(unsigned int) *s
] || *s
== ';'))
3080 else if (ISDIGIT (c
))
3082 if ((s
[1] != 'B' && s
[1] != 'F')
3083 || is_part_of_name (s
[-1])
3084 || is_part_of_name (s
[2])
3085 /* Don't treat e.g. #1F as a local-label reference. */
3086 || (s
!= input_line_pointer
&& s
[-1] == '#'))
3091 ? MAGIC_FB_BACKWARD_CHAR
: MAGIC_FB_FORWARD_CHAR
);
3099 /* Skip any spaces after the operands. */
3103 && !is_end_of_line
[(unsigned int) *s
])
3106 /* If we're now looking at a semi-colon, then it's an end-of-line
3108 mmix_next_semicolon_is_eoln
= (*s
== ';');
3110 /* Make IS into an EQU by replacing it with "= ". Only match upper-case
3111 though; let lower-case be a syntax error. */
3113 if (s
[0] == 'I' && s
[1] == 'S' && ISSPACE (s
[2]))
3118 /* Since labels can start without ":", we have to handle "X IS 42"
3119 in full here, or "X" will be parsed as a label to be set at ".". */
3120 input_line_pointer
= s
;
3122 /* Right after this function ends, line numbers will be bumped if
3123 input_line_pointer[-1] = '\n'. We want accurate line numbers for
3124 the equals call, so we bump them before the call, and make sure
3125 they aren't bumped afterwards. */
3126 bump_line_counters ();
3128 /* A fb-label is valid as an IS-label. */
3129 if (current_fb_label
>= 0)
3133 /* We need to save this name on our symbol obstack, since the
3134 string we got in fb_label_name is volatile and will change
3135 with every call to fb_label_name, like those resulting from
3136 parsing the IS-operand. */
3137 fb_name
= fb_label_name (current_fb_label
, 1);
3138 obstack_grow (&mmix_sym_obstack
, fb_name
, strlen (fb_name
) + 1);
3139 equals (obstack_finish (&mmix_sym_obstack
), 0);
3140 fb_label_instance_inc (current_fb_label
);
3141 current_fb_label
= -1;
3145 if (pending_label
== NULL
)
3146 as_bad (_("empty label field for IS"));
3148 equals (pending_label
, 0);
3149 pending_label
= NULL
;
3152 /* For mmixal, we can have comments without a comment-start
3154 mmix_handle_rest_of_empty_line ();
3155 input_line_pointer
--;
3157 input_line_pointer
[-1] = ' ';
3159 else if (s
[0] == 'G'
3161 && strncmp (s
, "GREG", 4) == 0
3162 && (ISSPACE (s
[4]) || is_end_of_line
[(unsigned char) s
[4]]))
3164 input_line_pointer
= s
+ 4;
3166 /* Right after this function ends, line numbers will be bumped if
3167 input_line_pointer[-1] = '\n'. We want accurate line numbers for
3168 the s_greg call, so we bump them before the call, and make sure
3169 they aren't bumped afterwards. */
3170 bump_line_counters ();
3172 /* A fb-label is valid as a GREG-label. */
3173 if (current_fb_label
>= 0)
3177 /* We need to save this name on our symbol obstack, since the
3178 string we got in fb_label_name is volatile and will change
3179 with every call to fb_label_name, like those resulting from
3180 parsing the IS-operand. */
3181 fb_name
= fb_label_name (current_fb_label
, 1);
3183 /* Make sure we save the canonical name and don't get bitten by
3185 obstack_1grow (&mmix_sym_obstack
, ':');
3186 obstack_grow (&mmix_sym_obstack
, fb_name
, strlen (fb_name
) + 1);
3187 mmix_greg_internal (obstack_finish (&mmix_sym_obstack
));
3188 fb_label_instance_inc (current_fb_label
);
3189 current_fb_label
= -1;
3192 mmix_greg_internal (pending_label
);
3194 /* Back up before the end-of-line marker that was skipped in
3195 mmix_greg_internal. */
3196 input_line_pointer
--;
3197 input_line_pointer
[-1] = ' ';
3199 pending_label
= NULL
;
3201 else if (pending_label
!= NULL
)
3203 input_line_pointer
+= strlen (pending_label
);
3205 /* See comment above about getting line numbers bumped. */
3206 input_line_pointer
[-1] = '\n';
3210 /* Give the value of an fb-label rewritten as in mmix_handle_mmixal, when
3211 parsing an expression.
3213 On valid calls, input_line_pointer points at a MAGIC_FB_BACKWARD_CHAR
3214 or MAGIC_FB_BACKWARD_CHAR, followed by an ascii digit for the label.
3215 We fill in the label as an expression. */
3218 mmix_fb_label (expressionS
*expP
)
3221 char *fb_internal_name
;
3223 /* This doesn't happen when not using mmixal syntax. */
3225 || (input_line_pointer
[0] != MAGIC_FB_BACKWARD_CHAR
3226 && input_line_pointer
[0] != MAGIC_FB_FORWARD_CHAR
))
3229 /* The current backward reference has augmentation 0. A forward
3230 reference has augmentation 1, unless it's the same as a fb-label on
3231 _this_ line, in which case we add one more so we don't refer to it.
3232 This is the semantics of mmixal; it differs to that of common
3233 fb-labels which refer to a here-label on the current line as a
3234 backward reference. */
3236 = fb_label_name (input_line_pointer
[1] - '0',
3237 (input_line_pointer
[0] == MAGIC_FB_FORWARD_CHAR
? 1 : 0)
3238 + ((input_line_pointer
[1] - '0' == current_fb_label
3239 && input_line_pointer
[0] == MAGIC_FB_FORWARD_CHAR
)
3242 input_line_pointer
+= 2;
3243 sym
= symbol_find_or_make (fb_internal_name
);
3245 /* We don't have to clean up unrelated fields here; we just do what the
3246 expr machinery does, but *not* just what it does for [0-9][fb], since
3247 we need to treat those as ordinary symbols sometimes; see testcases
3248 err-byte2.s and fb-2.s. */
3249 if (S_GET_SEGMENT (sym
) == absolute_section
)
3251 expP
->X_op
= O_constant
;
3252 expP
->X_add_number
= S_GET_VALUE (sym
);
3256 expP
->X_op
= O_symbol
;
3257 expP
->X_add_symbol
= sym
;
3258 expP
->X_add_number
= 0;
3262 /* See whether we need to force a relocation into the output file.
3263 This is used to force out switch and PC relative relocations when
3267 mmix_force_relocation (fixS
*fixP
)
3269 if (fixP
->fx_r_type
== BFD_RELOC_MMIX_LOCAL
3270 || fixP
->fx_r_type
== BFD_RELOC_MMIX_BASE_PLUS_OFFSET
)
3276 /* All our pcrel relocations are must-keep. Note that md_apply_fix is
3277 called *after* this, and will handle getting rid of the presumed
3278 reloc; a relocation isn't *forced* other than to be handled by
3279 md_apply_fix (or tc_gen_reloc if linkrelax). */
3283 return generic_force_reloc (fixP
);
3286 /* The location from which a PC relative jump should be calculated,
3287 given a PC relative reloc. */
3290 md_pcrel_from_section (fixS
*fixP
, segT sec
)
3292 if (fixP
->fx_addsy
!= (symbolS
*) NULL
3293 && (! S_IS_DEFINED (fixP
->fx_addsy
)
3294 || S_GET_SEGMENT (fixP
->fx_addsy
) != sec
))
3296 /* The symbol is undefined (or is defined but not in this section).
3297 Let the linker figure it out. */
3301 return (fixP
->fx_frag
->fr_address
+ fixP
->fx_where
);
3304 /* Adjust the symbol table. We make reg_section relative to the real
3305 register section. */
3308 mmix_adjust_symtab (void)
3311 symbolS
*regsec
= section_symbol (reg_section
);
3313 for (sym
= symbol_rootP
; sym
!= NULL
; sym
= symbol_next (sym
))
3314 if (S_GET_SEGMENT (sym
) == reg_section
)
3318 if (S_IS_EXTERNAL (sym
) || symbol_used_in_reloc_p (sym
))
3320 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
3323 /* Change section to the *real* register section, so it gets
3324 proper treatment when writing it out. Only do this for
3325 global symbols. This also means we don't have to check for
3327 S_SET_SEGMENT (sym
, real_reg_section
);
3331 /* This is the expansion of LABELS_WITHOUT_COLONS.
3332 We let md_start_line_hook tweak label_without_colon_this_line, and then
3333 this function returns the tweaked value, and sets it to 1 for the next
3334 line. FIXME: Very, very brittle. Not sure it works the way I
3335 thought at the time I first wrote this. */
3338 mmix_label_without_colon_this_line (void)
3340 int retval
= label_without_colon_this_line
;
3342 if (! mmix_gnu_syntax
)
3343 label_without_colon_this_line
= 1;
3348 /* This is the expansion of md_relax_frag. We go through the ordinary
3349 relax table function except when the frag is for a GREG. Then we have
3350 to check whether there's another GREG by the same value that we can
3354 mmix_md_relax_frag (segT seg
, fragS
*fragP
, long stretch
)
3356 switch (fragP
->fr_subtype
)
3358 /* Growth for this type has been handled by mmix_md_end and
3359 correctly estimated, so there's nothing more to do here. */
3360 case STATE_GREG_DEF
:
3363 case ENCODE_RELAX (STATE_PUSHJ
, STATE_ZERO
):
3365 /* We need to handle relaxation type ourselves, since relax_frag
3366 doesn't update fr_subtype if there's no size increase in the
3367 current section; when going from plain PUSHJ to a stub. This
3368 is otherwise functionally the same as relax_frag in write.c,
3369 simplified for this case. */
3374 target
= fragP
->fr_offset
;
3375 address
= fragP
->fr_address
;
3376 symbolP
= fragP
->fr_symbol
;
3382 sym_frag
= symbol_get_frag (symbolP
);
3383 know (S_GET_SEGMENT (symbolP
) != absolute_section
3384 || sym_frag
== &zero_address_frag
);
3385 target
+= S_GET_VALUE (symbolP
);
3387 /* If frag has yet to be reached on this pass, assume it will
3388 move by STRETCH just as we did. If this is not so, it will
3389 be because some frag between grows, and that will force
3393 && sym_frag
->relax_marker
!= fragP
->relax_marker
3394 && S_GET_SEGMENT (symbolP
) == seg
)
3398 aim
= target
- address
- fragP
->fr_fix
;
3399 if (aim
>= PUSHJ_0B
&& aim
<= PUSHJ_0F
)
3401 /* Target is reachable with a PUSHJ. */
3402 segment_info_type
*seginfo
= seg_info (seg
);
3404 /* If we're at the end of a relaxation round, clear the stub
3405 counter as initialization for the next round. */
3406 if (fragP
== seginfo
->tc_segment_info_data
.last_stubfrag
)
3407 seginfo
->tc_segment_info_data
.nstubs
= 0;
3411 /* Not reachable. Try a stub. */
3412 fragP
->fr_subtype
= ENCODE_RELAX (STATE_PUSHJSTUB
, STATE_ZERO
);
3416 /* See if this PUSHJ is redirectable to a stub. */
3417 case ENCODE_RELAX (STATE_PUSHJSTUB
, STATE_ZERO
):
3419 segment_info_type
*seginfo
= seg_info (seg
);
3420 fragS
*lastfrag
= seginfo
->frchainP
->frch_last
;
3421 relax_substateT prev_type
= fragP
->fr_subtype
;
3423 /* The last frag is always an empty frag, so it suffices to look
3424 at its address to know the ending address of this section. */
3425 know (lastfrag
->fr_type
== rs_fill
3426 && lastfrag
->fr_fix
== 0
3427 && lastfrag
->fr_var
== 0);
3429 /* For this PUSHJ to be relaxable into a call to a stub, the
3430 distance must be no longer than 256k bytes from the PUSHJ to
3431 the end of the section plus the maximum size of stubs so far. */
3432 if ((lastfrag
->fr_address
3434 + PUSHJ_MAX_LEN
* seginfo
->tc_segment_info_data
.nstubs
)
3435 - (fragP
->fr_address
+ fragP
->fr_fix
)
3438 fragP
->fr_subtype
= mmix_relax_table
[prev_type
].rlx_more
;
3440 seginfo
->tc_segment_info_data
.nstubs
++;
3442 /* If we're at the end of a relaxation round, clear the stub
3443 counter as initialization for the next round. */
3444 if (fragP
== seginfo
->tc_segment_info_data
.last_stubfrag
)
3445 seginfo
->tc_segment_info_data
.nstubs
= 0;
3448 (mmix_relax_table
[fragP
->fr_subtype
].rlx_length
3449 - mmix_relax_table
[prev_type
].rlx_length
);
3452 case ENCODE_RELAX (STATE_PUSHJ
, STATE_MAX
):
3454 segment_info_type
*seginfo
= seg_info (seg
);
3456 /* Need to cover all STATE_PUSHJ states to act on the last stub
3457 frag (the end of this relax round; initialization for the
3459 if (fragP
== seginfo
->tc_segment_info_data
.last_stubfrag
)
3460 seginfo
->tc_segment_info_data
.nstubs
= 0;
3466 return relax_frag (seg
, fragP
, stretch
);
3468 case STATE_GREG_UNDF
:
3469 BAD_CASE (fragP
->fr_subtype
);
3472 as_fatal (_("internal: unexpected relax type %d:%d"),
3473 fragP
->fr_type
, fragP
->fr_subtype
);
3477 /* Various things we punt until all input is seen. */
3485 struct loc_assert_s
*loc_assert
;
3488 /* The first frag of GREG:s going into the register contents section. */
3489 fragS
*mmix_reg_contents_frags
= NULL
;
3491 /* Reset prefix. All labels reachable at this point must be
3493 mmix_current_prefix
= NULL
;
3496 as_bad_where (bspec_file
, bspec_line
, _("BSPEC without ESPEC."));
3498 /* Emit the low LOC setting of .text. */
3499 if (text_has_contents
&& lowest_text_loc
!= (bfd_vma
) -1)
3502 char locsymbol
[sizeof (":") - 1
3503 + sizeof (MMIX_LOC_SECTION_START_SYMBOL_PREFIX
) - 1
3504 + sizeof (".text")];
3506 /* An exercise in non-ISO-C-ness, this one. */
3507 sprintf (locsymbol
, ":%s%s", MMIX_LOC_SECTION_START_SYMBOL_PREFIX
,
3510 = symbol_new (locsymbol
, absolute_section
, lowest_text_loc
,
3511 &zero_address_frag
);
3512 S_SET_EXTERNAL (symbolP
);
3516 if (data_has_contents
&& lowest_data_loc
!= (bfd_vma
) -1)
3519 char locsymbol
[sizeof (":") - 1
3520 + sizeof (MMIX_LOC_SECTION_START_SYMBOL_PREFIX
) - 1
3521 + sizeof (".data")];
3523 sprintf (locsymbol
, ":%s%s", MMIX_LOC_SECTION_START_SYMBOL_PREFIX
,
3526 = symbol_new (locsymbol
, absolute_section
, lowest_data_loc
,
3527 &zero_address_frag
);
3528 S_SET_EXTERNAL (symbolP
);
3531 /* Unless GNU syntax mode, set "Main" to be a function, so the
3532 disassembler doesn't get confused when we write truly
3533 mmixal-compatible code (and don't use .type). Similarly set it
3534 global (regardless of -globalize-symbols), so the linker sees it as
3535 the start symbol in ELF mode. */
3536 mainsym
= symbol_find (MMIX_START_SYMBOL_NAME
);
3537 if (mainsym
!= NULL
&& ! mmix_gnu_syntax
)
3539 symbol_get_bfdsym (mainsym
)->flags
|= BSF_FUNCTION
;
3540 S_SET_EXTERNAL (mainsym
);
3543 /* Check that we didn't LOC into the unknown, or rather that when it
3544 was unknown, we actually change sections. */
3545 for (loc_assert
= loc_asserts
;
3547 loc_assert
= loc_assert
->next
)
3551 resolve_symbol_value (loc_assert
->loc_sym
);
3552 actual_seg
= S_GET_SEGMENT (loc_assert
->loc_sym
);
3553 if (actual_seg
!= loc_assert
->old_seg
)
3557 int e_valid
= expr_symbol_where (loc_assert
->loc_sym
, &fnam
, &line
);
3559 gas_assert (e_valid
== 1);
3560 as_bad_where (fnam
, line
,
3561 _("LOC to section unknown or indeterminable "
3564 /* Patch up the generic location data to avoid cascading
3565 error messages from later passes. (See original in
3566 write.c:relax_segment.) */
3567 fragP
= loc_assert
->frag
;
3568 fragP
->fr_type
= rs_align
;
3569 fragP
->fr_subtype
= 0;
3570 fragP
->fr_offset
= 0;
3575 if (n_of_raw_gregs
!= 0)
3577 /* Emit GREGs. They are collected in order of appearance, but must
3578 be emitted in opposite order to both have section address regno*8
3579 and the same allocation order (within a file) as mmixal. */
3580 segT this_segment
= now_seg
;
3581 subsegT this_subsegment
= now_subseg
;
3583 regsec
= bfd_make_section_old_way (stdoutput
,
3584 MMIX_REG_CONTENTS_SECTION_NAME
);
3585 subseg_set (regsec
, 0);
3587 /* Finally emit the initialization-value. Emit a variable frag, which
3588 we'll fix in md_estimate_size_before_relax. We set the initializer
3589 for the tc_frag_data field to NULL, so we can use that field for
3590 relaxation purposes. */
3591 mmix_opcode_frag
= NULL
;
3594 mmix_reg_contents_frags
= frag_now
;
3596 for (i
= n_of_raw_gregs
- 1; i
>= 0; i
--)
3598 if (mmix_raw_gregs
[i
].label
!= NULL
)
3599 /* There's a symbol. Let it refer to this location in the
3600 register contents section. The symbol must be globalized
3602 colon (mmix_raw_gregs
[i
].label
);
3604 frag_var (rs_machine_dependent
, 8, 0, STATE_GREG_UNDF
,
3605 make_expr_symbol (&mmix_raw_gregs
[i
].exp
), 0, NULL
);
3608 subseg_set (this_segment
, this_subsegment
);
3611 regsec
= bfd_get_section_by_name (stdoutput
, MMIX_REG_CONTENTS_SECTION_NAME
);
3612 /* Mark the section symbol as being OK for a reloc. */
3614 regsec
->symbol
->flags
|= BSF_KEEP
;
3616 /* Iterate over frags resulting from GREGs and move those that evidently
3617 have the same value together and point one to another.
3619 This works in time O(N^2) but since the upper bound for non-error use
3620 is 223, it's best to keep this simpler algorithm. */
3621 for (fragP
= mmix_reg_contents_frags
; fragP
!= NULL
; fragP
= fragP
->fr_next
)
3628 symbolS
*symbolP
= fragP
->fr_symbol
;
3630 if (fragP
->fr_type
!= rs_machine_dependent
3631 || fragP
->fr_subtype
!= STATE_GREG_UNDF
)
3634 /* Whatever the outcome, we will have this GREG judged merged or
3635 non-merged. Since the tc_frag_data is NULL at this point, we
3636 default to non-merged. */
3637 fragP
->fr_subtype
= STATE_GREG_DEF
;
3639 /* If we're not supposed to merge GREG definitions, then just don't
3640 look for equivalents. */
3644 osymval
= (offsetT
) S_GET_VALUE (symbolP
);
3645 osymfrag
= symbol_get_frag (symbolP
);
3647 /* If the symbol isn't defined, we can't say that another symbol
3648 equals this frag, then. FIXME: We can look at the "deepest"
3649 defined name; if a = c and b = c then obviously a == b. */
3650 if (! S_IS_DEFINED (symbolP
))
3653 oexpP
= symbol_get_value_expression (fragP
->fr_symbol
);
3655 /* If the initialization value is zero, then we must not merge them. */
3656 if (oexpP
->X_op
== O_constant
&& osymval
== 0)
3659 /* Iterate through the frags downward this one. If we find one that
3660 has the same non-zero value, move it to after this one and point
3661 to it as the equivalent. */
3662 for (fpp
= &fragP
->fr_next
; *fpp
!= NULL
; fpp
= &fpp
[0]->fr_next
)
3666 if (fp
->fr_type
!= rs_machine_dependent
3667 || fp
->fr_subtype
!= STATE_GREG_UNDF
)
3670 /* Calling S_GET_VALUE may simplify the symbol, changing from
3671 expr_section etc. so call it first. */
3672 if ((offsetT
) S_GET_VALUE (fp
->fr_symbol
) == osymval
3673 && symbol_get_frag (fp
->fr_symbol
) == osymfrag
)
3675 /* Move the frag links so the one we found equivalent comes
3676 after the current one, carefully considering that
3677 sometimes fpp == &fragP->fr_next and the moves must be a
3680 fp
->fr_next
= fragP
->fr_next
;
3681 fragP
->fr_next
= fp
;
3687 fragP
->tc_frag_data
= fp
;
3691 /* qsort function for mmix_symbol_gregs. */
3694 cmp_greg_symbol_fixes (const void *parg
, const void *qarg
)
3696 const struct mmix_symbol_greg_fixes
*p
3697 = (const struct mmix_symbol_greg_fixes
*) parg
;
3698 const struct mmix_symbol_greg_fixes
*q
3699 = (const struct mmix_symbol_greg_fixes
*) qarg
;
3701 return p
->offs
> q
->offs
? 1 : p
->offs
< q
->offs
? -1 : 0;
3704 /* Collect GREG definitions from mmix_gregs and hang them as lists sorted
3705 on increasing offsets onto each section symbol or undefined symbol.
3707 Also, remove the register convenience section so it doesn't get output
3708 as an ELF section. */
3711 mmix_frob_file (void)
3714 struct mmix_symbol_gregs
*all_greg_symbols
[MAX_GREGS
];
3715 int n_greg_symbols
= 0;
3717 /* Collect all greg fixups and decorate each corresponding symbol with
3718 the greg fixups for it. */
3719 for (i
= 0; i
< n_of_cooked_gregs
; i
++)
3723 struct mmix_symbol_gregs
*gregs
;
3726 fixP
= mmix_gregs
[i
];
3727 know (fixP
->fx_r_type
== BFD_RELOC_64
);
3729 /* This case isn't doable in general anyway, methinks. */
3730 if (fixP
->fx_subsy
!= NULL
)
3732 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3733 _("GREG expression too complicated"));
3737 sym
= fixP
->fx_addsy
;
3738 offs
= (offsetT
) fixP
->fx_offset
;
3740 /* If the symbol is defined, then it must be resolved to a section
3741 symbol at this time, or else we don't know how to handle it. */
3742 if (S_IS_DEFINED (sym
)
3743 && !bfd_is_com_section (S_GET_SEGMENT (sym
))
3744 && !S_IS_WEAK (sym
))
3746 if (! symbol_section_p (sym
)
3747 && ! bfd_is_abs_section (S_GET_SEGMENT (sym
)))
3748 as_fatal (_("internal: GREG expression not resolved to section"));
3750 offs
+= S_GET_VALUE (sym
);
3753 /* If this is an absolute symbol sufficiently near lowest_data_loc,
3754 then we canonicalize on the data section. Note that offs is
3755 signed here; we may subtract lowest_data_loc which is unsigned.
3756 Careful with those comparisons. */
3757 if (lowest_data_loc
!= (bfd_vma
) -1
3758 && (bfd_vma
) offs
+ 256 > lowest_data_loc
3759 && bfd_is_abs_section (S_GET_SEGMENT (sym
)))
3761 offs
-= (offsetT
) lowest_data_loc
;
3762 sym
= section_symbol (data_section
);
3764 /* Likewise text section. */
3765 else if (lowest_text_loc
!= (bfd_vma
) -1
3766 && (bfd_vma
) offs
+ 256 > lowest_text_loc
3767 && bfd_is_abs_section (S_GET_SEGMENT (sym
)))
3769 offs
-= (offsetT
) lowest_text_loc
;
3770 sym
= section_symbol (text_section
);
3773 gregs
= *symbol_get_tc (sym
);
3777 gregs
= XNEW (struct mmix_symbol_gregs
);
3779 symbol_set_tc (sym
, &gregs
);
3780 all_greg_symbols
[n_greg_symbols
++] = gregs
;
3783 gregs
->greg_fixes
[gregs
->n_gregs
].fix
= fixP
;
3784 gregs
->greg_fixes
[gregs
->n_gregs
++].offs
= offs
;
3787 /* For each symbol having a GREG definition, sort those definitions on
3789 for (i
= 0; i
< n_greg_symbols
; i
++)
3790 qsort (all_greg_symbols
[i
]->greg_fixes
, all_greg_symbols
[i
]->n_gregs
,
3791 sizeof (all_greg_symbols
[i
]->greg_fixes
[0]), cmp_greg_symbol_fixes
);
3793 if (real_reg_section
!= NULL
)
3795 /* FIXME: Pass error state gracefully. */
3796 if (bfd_section_flags (real_reg_section
) & SEC_HAS_CONTENTS
)
3797 as_fatal (_("register section has contents\n"));
3799 bfd_section_list_remove (stdoutput
, real_reg_section
);
3800 --stdoutput
->section_count
;
3805 /* Provide an expression for a built-in name provided when-used.
3806 Either a symbol that is a handler; living in 0x10*[1..8] and having
3807 name [DVWIOUZX]_Handler, or a mmixal built-in symbol.
3809 If the name isn't a built-in name and parsed into *EXPP, return zero. */
3812 mmix_parse_predefined_name (char *name
, expressionS
*expP
)
3815 const char *handler_charp
;
3816 const char handler_chars
[] = "DVWIOUZX";
3819 if (! predefined_syms
)
3822 canon_name
= tc_canonicalize_symbol_name (name
);
3824 if (canon_name
[1] == '_'
3825 && strcmp (canon_name
+ 2, "Handler") == 0
3826 && (handler_charp
= strchr (handler_chars
, *canon_name
)) != NULL
)
3828 /* If the symbol doesn't exist, provide one relative to the .text
3831 FIXME: We should provide separate sections, mapped in the linker
3833 symp
= symbol_find (name
);
3835 symp
= symbol_new (name
, text_section
,
3836 0x10 * (handler_charp
+ 1 - handler_chars
),
3837 &zero_address_frag
);
3841 /* These symbols appear when referenced; needed for
3842 mmixal-compatible programs. */
3849 } predefined_abs_syms
[] =
3851 {"Data_Segment", (valueT
) 0x20 << 56},
3852 {"Pool_Segment", (valueT
) 0x40 << 56},
3853 {"Stack_Segment", (valueT
) 0x60 << 56},
3861 {"BinaryReadWrite", 4},
3884 /* If it's already in the symbol table, we shouldn't do anything. */
3885 symp
= symbol_find (name
);
3890 i
< sizeof (predefined_abs_syms
) / sizeof (predefined_abs_syms
[0]);
3892 if (strcmp (canon_name
, predefined_abs_syms
[i
].name
) == 0)
3894 symbol_table_insert (symbol_new (predefined_abs_syms
[i
].name
,
3896 predefined_abs_syms
[i
].val
,
3897 &zero_address_frag
));
3899 /* Let gas find the symbol we just created, through its
3904 /* Not one of those symbols. Let gas handle it. */
3908 expP
->X_op
= O_symbol
;
3909 expP
->X_add_number
= 0;
3910 expP
->X_add_symbol
= symp
;
3911 expP
->X_op_symbol
= NULL
;
3916 /* Just check that we don't have a BSPEC/ESPEC pair active when changing
3917 sections "normally", and get knowledge about alignment from the new
3921 mmix_md_elf_section_change_hook (void)
3924 as_bad (_("section change from within a BSPEC/ESPEC pair is not supported"));
3926 last_alignment
= bfd_section_alignment (now_seg
);
3930 /* The LOC worker. This is like s_org, but we have to support changing
3934 s_loc (int ignore ATTRIBUTE_UNUSED
)
3942 /* Must not have a BSPEC in progress. */
3945 as_bad (_("directive LOC from within a BSPEC/ESPEC pair is not supported"));
3949 section
= expression (&exp
);
3951 if (exp
.X_op
== O_illegal
3952 || exp
.X_op
== O_absent
3953 || exp
.X_op
== O_big
)
3955 as_bad (_("invalid LOC expression"));
3959 if (section
== undefined_section
)
3961 /* This is an error or a LOC with an expression involving
3962 forward references. For the expression to be correctly
3963 evaluated, we need to force a proper symbol; gas loses track
3964 of the segment for "local symbols". */
3965 if (exp
.X_op
== O_add
)
3967 symbol_get_value_expression (exp
.X_op_symbol
);
3968 symbol_get_value_expression (exp
.X_add_symbol
);
3972 gas_assert (exp
.X_op
== O_symbol
);
3973 symbol_get_value_expression (exp
.X_add_symbol
);
3977 if (section
== absolute_section
)
3979 /* Translate a constant into a suitable section. */
3981 if (exp
.X_add_number
< ((offsetT
) 0x20 << 56))
3983 /* Lower than Data_Segment or in the reserved area (the
3984 segment number is >= 0x80, appearing negative) - assume
3986 section
= text_section
;
3988 /* Save the lowest seen location, so we can pass on this
3989 information to the linker. We don't actually org to this
3990 location here, we just pass on information to the linker so
3991 it can put the code there for us. */
3993 /* If there was already a loc (that has to be set lower than
3994 this one), we org at (this - lower). There's an implicit
3995 "LOC 0" before any entered code. FIXME: handled by spurious
3996 settings of text_has_contents. */
3997 if (lowest_text_loc
!= (bfd_vma
) -1
3998 && (bfd_vma
) exp
.X_add_number
< lowest_text_loc
)
4000 as_bad (_("LOC expression stepping backwards is not supported"));
4001 exp
.X_op
= O_absent
;
4005 if (text_has_contents
&& lowest_text_loc
== (bfd_vma
) -1)
4006 lowest_text_loc
= 0;
4008 if (lowest_text_loc
== (bfd_vma
) -1)
4010 lowest_text_loc
= exp
.X_add_number
;
4012 /* We want only to change the section, not set an offset. */
4013 exp
.X_op
= O_absent
;
4016 exp
.X_add_number
-= lowest_text_loc
;
4021 /* Do the same for the .data section, except we don't have
4022 to worry about exp.X_add_number carrying a sign. */
4023 section
= data_section
;
4025 if (exp
.X_add_number
< (offsetT
) lowest_data_loc
)
4027 as_bad (_("LOC expression stepping backwards is not supported"));
4028 exp
.X_op
= O_absent
;
4032 if (data_has_contents
&& lowest_data_loc
== (bfd_vma
) -1)
4033 lowest_data_loc
= (bfd_vma
) 0x20 << 56;
4035 if (lowest_data_loc
== (bfd_vma
) -1)
4037 lowest_data_loc
= exp
.X_add_number
;
4039 /* We want only to change the section, not set an offset. */
4040 exp
.X_op
= O_absent
;
4043 exp
.X_add_number
-= lowest_data_loc
;
4048 /* If we can't deduce the section, it must be the current one.
4049 Below, we arrange to assert this. */
4050 if (section
!= now_seg
&& section
!= undefined_section
)
4052 obj_elf_section_change_hook ();
4053 subseg_set (section
, 0);
4055 /* Call our section change hooks using the official hook. */
4056 md_elf_section_change_hook ();
4059 if (exp
.X_op
!= O_absent
)
4061 symbolS
*esym
= NULL
;
4063 if (exp
.X_op
!= O_constant
&& exp
.X_op
!= O_symbol
)
4065 /* Handle complex expressions. */
4066 esym
= sym
= make_expr_symbol (&exp
);
4071 sym
= exp
.X_add_symbol
;
4072 off
= exp
.X_add_number
;
4074 if (section
== undefined_section
)
4076 /* We need an expr_symbol when tracking sections. In
4077 order to make this an expr_symbol with file and line
4078 tracked, we have to make the exp non-trivial; not an
4079 O_symbol with .X_add_number == 0. The constant part
4081 exp
.X_add_number
= 1;
4082 esym
= make_expr_symbol (&exp
);
4086 /* Track the LOC's where we couldn't deduce the section: assert
4087 that we weren't supposed to change section. */
4088 if (section
== undefined_section
)
4090 struct loc_assert_s
*next
= loc_asserts
;
4091 loc_asserts
= XNEW (struct loc_assert_s
);
4092 loc_asserts
->next
= next
;
4093 loc_asserts
->old_seg
= now_seg
;
4094 loc_asserts
->loc_sym
= esym
;
4095 loc_asserts
->frag
= frag_now
;
4098 p
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, sym
, off
, (char *) 0);
4102 mmix_handle_rest_of_empty_line ();
4105 /* The BYTE worker. We have to support sequences of mixed "strings",
4106 numbers and other constant "first-pass" reducible expressions separated
4114 if (now_seg
== text_section
)
4115 text_has_contents
= 1;
4116 else if (now_seg
== data_section
)
4117 data_has_contents
= 1;
4122 switch (*input_line_pointer
)
4125 ++input_line_pointer
;
4126 while (is_a_char (c
= next_char_of_string ()))
4128 FRAG_APPEND_1_CHAR (c
);
4131 if (input_line_pointer
[-1] != '\"')
4133 /* We will only get here in rare cases involving #NO_APP,
4134 where the unterminated string is not recognized by the
4135 preformatting pass. */
4136 as_bad (_("unterminated string"));
4137 mmix_discard_rest_of_line ();
4145 segT expseg
= expression (&exp
);
4147 /* We have to allow special register names as constant numbers. */
4148 if ((expseg
!= absolute_section
&& expseg
!= reg_section
)
4149 || (exp
.X_op
!= O_constant
4150 && (exp
.X_op
!= O_register
4151 || exp
.X_add_number
<= 255)))
4153 as_bad (_("BYTE expression not a pure number"));
4154 mmix_discard_rest_of_line ();
4157 else if ((exp
.X_add_number
> 255 && exp
.X_op
!= O_register
)
4158 || exp
.X_add_number
< 0)
4160 /* Note that mmixal does not allow negative numbers in
4161 BYTE sequences, so neither should we. */
4162 as_bad (_("BYTE expression not in the range 0..255"));
4163 mmix_discard_rest_of_line ();
4167 FRAG_APPEND_1_CHAR (exp
.X_add_number
);
4173 c
= *input_line_pointer
++;
4177 input_line_pointer
--;
4179 if (mmix_gnu_syntax
)
4180 demand_empty_rest_of_line ();
4183 mmix_discard_rest_of_line ();
4184 /* Do like demand_empty_rest_of_line and step over the end-of-line
4186 input_line_pointer
++;
4189 /* Make sure we align for the next instruction. */
4193 /* Like cons_worker, but we have to ignore "naked comments", not barf on
4194 them. Implements WYDE, TETRA and OCTA. We're a little bit more
4195 lenient than mmix_byte but FIXME: they should eventually merge. */
4198 mmix_cons (int nbytes
)
4202 /* If we don't have any contents, then it's ok to have a specified start
4203 address that is not a multiple of the max data size. We will then
4204 align it as necessary when we get here. Otherwise, it's a fatal sin. */
4205 if (now_seg
== text_section
)
4207 if (lowest_text_loc
!= (bfd_vma
) -1
4208 && (lowest_text_loc
& (nbytes
- 1)) != 0)
4210 if (text_has_contents
)
4211 as_bad (_("data item with alignment larger than location"));
4212 else if (want_unaligned
)
4213 as_bad (_("unaligned data at an absolute location is not supported"));
4215 lowest_text_loc
&= ~((bfd_vma
) nbytes
- 1);
4216 lowest_text_loc
+= (bfd_vma
) nbytes
;
4219 text_has_contents
= 1;
4221 else if (now_seg
== data_section
)
4223 if (lowest_data_loc
!= (bfd_vma
) -1
4224 && (lowest_data_loc
& (nbytes
- 1)) != 0)
4226 if (data_has_contents
)
4227 as_bad (_("data item with alignment larger than location"));
4228 else if (want_unaligned
)
4229 as_bad (_("unaligned data at an absolute location is not supported"));
4231 lowest_data_loc
&= ~((bfd_vma
) nbytes
- 1);
4232 lowest_data_loc
+= (bfd_vma
) nbytes
;
4235 data_has_contents
= 1;
4238 /* Always align these unless asked not to (valid for the current pseudo). */
4239 if (! want_unaligned
)
4241 last_alignment
= nbytes
== 2 ? 1 : (nbytes
== 4 ? 2 : 3);
4242 frag_align (last_alignment
, 0, 0);
4243 record_alignment (now_seg
, last_alignment
);
4246 /* For mmixal compatibility, a label for an instruction (and emitting
4247 pseudo) refers to the _aligned_ address. So we have to emit the
4249 if (current_fb_label
>= 0)
4250 colon (fb_label_name (current_fb_label
, 1));
4251 else if (pending_label
!= NULL
)
4253 colon (pending_label
);
4254 pending_label
= NULL
;
4259 if (is_end_of_line
[(unsigned int) *input_line_pointer
])
4261 /* Default to zero if the expression was absent. */
4263 exp
.X_op
= O_constant
;
4264 exp
.X_add_number
= 0;
4266 exp
.X_add_symbol
= NULL
;
4267 exp
.X_op_symbol
= NULL
;
4268 emit_expr (&exp
, (unsigned int) nbytes
);
4275 switch (*input_line_pointer
)
4277 /* We support strings here too; each character takes up nbytes
4280 ++input_line_pointer
;
4281 while (is_a_char (c
= next_char_of_string ()))
4283 exp
.X_op
= O_constant
;
4284 exp
.X_add_number
= c
;
4286 emit_expr (&exp
, (unsigned int) nbytes
);
4289 if (input_line_pointer
[-1] != '\"')
4291 /* We will only get here in rare cases involving #NO_APP,
4292 where the unterminated string is not recognized by the
4293 preformatting pass. */
4294 as_bad (_("unterminated string"));
4295 mmix_discard_rest_of_line ();
4303 emit_expr (&exp
, (unsigned int) nbytes
);
4309 while (*input_line_pointer
++ == ',');
4311 input_line_pointer
--; /* Put terminator back into stream. */
4313 mmix_handle_rest_of_empty_line ();
4315 /* We don't need to step up the counter for the current_fb_label here;
4316 that's handled by the caller. */
4319 /* The md_do_align worker. At present, we just record an alignment to
4320 nullify the automatic alignment we do for WYDE, TETRA and OCTA, as gcc
4321 does not use the unaligned macros when attribute packed is used.
4322 Arguably this is a GCC bug. */
4325 mmix_md_do_align (int n
, char *fill ATTRIBUTE_UNUSED
,
4326 int len ATTRIBUTE_UNUSED
, int max ATTRIBUTE_UNUSED
)
4329 want_unaligned
= n
== 0;