1 /* tc-mmix.c -- Assembler for Don Knuth's MMIX.
2 Copyright (C) 2001, 2002 Free Software Foundation.
4 This file is part of GAS, the GNU Assembler.
6 GAS is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GAS is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GAS; see the file COPYING. If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
21 /* Knuth's assembler mmixal does not provide a relocatable format; mmo is
22 to be considered a final link-format. In the final link, we make mmo,
23 but for relocatable files, we use ELF.
25 One goal is to provide a superset of what mmixal does, including
26 compatible syntax, but the main purpose is to serve GCC. */
34 #include "opcode/mmix.h"
35 #include "safe-ctype.h"
36 #include "dwarf2dbg.h"
39 /* Something to describe what we need to do with a fixup before output,
40 for example assert something of what it became or make a relocation. */
42 enum mmix_fixup_action
46 mmix_fixup_register_or_adjust_for_byte
49 static int get_spec_regno
PARAMS ((char *));
50 static int get_operands
PARAMS ((int, char *, expressionS
[]));
51 static int get_putget_operands
52 PARAMS ((struct mmix_opcode
*, char *, expressionS
[]));
53 static void s_prefix
PARAMS ((int));
54 static void s_greg
PARAMS ((int));
55 static void s_loc
PARAMS ((int));
56 static void s_bspec
PARAMS ((int));
57 static void s_espec
PARAMS ((int));
58 static void mmix_s_local
PARAMS ((int));
59 static void mmix_greg_internal
PARAMS ((char *));
60 static void mmix_set_geta_branch_offset
PARAMS ((char *, offsetT value
));
61 static void mmix_set_jmp_offset
PARAMS ((char *, offsetT
));
62 static void mmix_fill_nops
PARAMS ((char *, int));
63 static int cmp_greg_symbol_fixes
PARAMS ((const PTR
, const PTR
));
64 static int cmp_greg_val_greg_symbol_fixes
65 PARAMS ((const PTR p1
, const PTR p2
));
66 static void mmix_handle_rest_of_empty_line
PARAMS ((void));
67 static void mmix_discard_rest_of_line
PARAMS ((void));
68 static void mmix_byte
PARAMS ((void));
69 static void mmix_cons
PARAMS ((int));
71 /* Continue the tradition of symbols.c; use control characters to enforce
72 magic. These are used when replacing e.g. 8F and 8B so we can handle
73 such labels correctly with the common parser hooks. */
74 #define MAGIC_FB_BACKWARD_CHAR '\003'
75 #define MAGIC_FB_FORWARD_CHAR '\004'
77 /* Copy the location of a frag to a fix. */
78 #define COPY_FR_WHERE_TO_FX(FRAG, FIX) \
81 (FIX)->fx_file = (FRAG)->fr_file; \
82 (FIX)->fx_line = (FRAG)->fr_line; \
86 const char *md_shortopts
= "x";
87 static int current_fb_label
= -1;
88 static char *pending_label
= NULL
;
90 static bfd_vma lowest_text_loc
= (bfd_vma
) -1;
91 static int text_has_contents
= 0;
93 /* The alignment of the previous instruction, and a boolean for whether we
94 want to avoid aligning the next WYDE, TETRA, OCTA or insn. */
95 static int last_alignment
= 0;
96 static int want_unaligned
= 0;
98 static bfd_vma lowest_data_loc
= (bfd_vma
) -1;
99 static int data_has_contents
= 0;
101 /* The fragS of the instruction being assembled. Only valid from within
103 fragS
*mmix_opcode_frag
= NULL
;
105 /* Raw GREGs as appearing in input. These may be fewer than the number
107 static int n_of_raw_gregs
= 0;
112 } mmix_raw_gregs
[MAX_GREGS
];
114 /* Fixups for all unique GREG registers. We store the fixups here in
115 md_convert_frag, then we use the array to convert
116 BFD_RELOC_MMIX_BASE_PLUS_OFFSET fixups in tc_gen_reloc. The index is
117 just a running number and is not supposed to be correlated to a
119 static fixS
*mmix_gregs
[MAX_GREGS
];
120 static int n_of_cooked_gregs
= 0;
122 /* Pointing to the register section we use for output. */
123 static asection
*real_reg_section
;
125 /* For each symbol; unknown or section symbol, we keep a list of GREG
126 definitions sorted on increasing offset. It seems no use keeping count
127 to allocate less room than the maximum number of gregs when we've found
128 one for a section or symbol. */
129 struct mmix_symbol_gregs
132 struct mmix_symbol_greg_fixes
136 /* A signed type, since we may have GREGs pointing slightly before the
137 contents of a section. */
139 } greg_fixes
[MAX_GREGS
];
142 /* Should read insert a colon on something that starts in column 0 on
144 static int label_without_colon_this_line
= 1;
146 /* Should we expand operands for external symbols? */
147 static int expand_op
= 1;
149 /* Should we warn when expanding operands? FIXME: test-cases for when -x
151 static int warn_on_expansion
= 1;
153 /* Should we merge non-zero GREG register definitions? */
154 static int merge_gregs
= 1;
156 /* Should we pass on undefined BFD_RELOC_MMIX_BASE_PLUS_OFFSET relocs
157 (missing suitable GREG definitions) to the linker? */
158 static int allocate_undefined_gregs_in_linker
= 0;
160 /* Should we emit built-in symbols? */
161 static int predefined_syms
= 1;
163 /* Should we allow anything but the listed special register name
164 (e.g. equated symbols)? */
165 static int equated_spec_regs
= 1;
167 /* Do we require standard GNU syntax? */
168 int mmix_gnu_syntax
= 0;
170 /* Do we globalize all symbols? */
171 int mmix_globalize_symbols
= 0;
173 /* Do we know that the next semicolon is at the end of the operands field
174 (in mmixal mode; constant 1 in GNU mode)? */
175 int mmix_next_semicolon_is_eoln
= 1;
177 /* Do we have a BSPEC in progress? */
178 static int doing_bspec
= 0;
179 static char *bspec_file
;
180 static unsigned int bspec_line
;
182 struct option md_longopts
[] =
184 #define OPTION_RELAX (OPTION_MD_BASE)
185 #define OPTION_NOEXPAND (OPTION_RELAX + 1)
186 #define OPTION_NOMERGEGREG (OPTION_NOEXPAND + 1)
187 #define OPTION_NOSYMS (OPTION_NOMERGEGREG + 1)
188 #define OPTION_GNU_SYNTAX (OPTION_NOSYMS + 1)
189 #define OPTION_GLOBALIZE_SYMBOLS (OPTION_GNU_SYNTAX + 1)
190 #define OPTION_FIXED_SPEC_REGS (OPTION_GLOBALIZE_SYMBOLS + 1)
191 #define OPTION_LINKER_ALLOCATED_GREGS (OPTION_FIXED_SPEC_REGS + 1)
192 {"linkrelax", no_argument
, NULL
, OPTION_RELAX
},
193 {"no-expand", no_argument
, NULL
, OPTION_NOEXPAND
},
194 {"no-merge-gregs", no_argument
, NULL
, OPTION_NOMERGEGREG
},
195 {"no-predefined-syms", no_argument
, NULL
, OPTION_NOSYMS
},
196 {"gnu-syntax", no_argument
, NULL
, OPTION_GNU_SYNTAX
},
197 {"globalize-symbols", no_argument
, NULL
, OPTION_GLOBALIZE_SYMBOLS
},
198 {"fixed-special-register-names", no_argument
, NULL
,
199 OPTION_FIXED_SPEC_REGS
},
200 {"linker-allocated-gregs", no_argument
, NULL
,
201 OPTION_LINKER_ALLOCATED_GREGS
},
202 {NULL
, no_argument
, NULL
, 0}
205 size_t md_longopts_size
= sizeof (md_longopts
);
207 static struct hash_control
*mmix_opcode_hash
;
209 /* We use these when implementing the PREFIX pseudo. */
210 char *mmix_current_prefix
;
211 struct obstack mmix_sym_obstack
;
214 /* For MMIX, we encode the relax_substateT:s (in e.g. fr_substate) as one
215 bit length, and the relax-type shifted on top of that. There seems to
216 be no point in making the relaxation more fine-grained; the linker does
217 that better and we might interfere by changing non-optimal relaxations
218 into other insns that cannot be relaxed as easily.
220 Groups for MMIX relaxing:
223 extra length: zero or three insns.
226 extra length: zero or five insns.
229 extra length: zero or four insns.
232 extra length: zero or four insns. */
234 #define STATE_GETA (1)
235 #define STATE_BCC (2)
236 #define STATE_PUSHJ (3)
237 #define STATE_JMP (4)
238 #define STATE_GREG (5)
240 /* No fine-grainedness here. */
241 #define STATE_LENGTH_MASK (1)
243 #define STATE_ZERO (0)
244 #define STATE_MAX (1)
246 /* More descriptive name for convenience. */
247 /* FIXME: We should start on something different, not MAX. */
248 #define STATE_UNDF STATE_MAX
250 /* FIXME: For GREG, we must have other definitions; UNDF == MAX isn't
251 appropriate; we need it the other way round. This value together with
252 fragP->tc_frag_data shows what state the frag is in: tc_frag_data
253 non-NULL means 0, NULL means 8 bytes. */
254 #define STATE_GREG_UNDF ENCODE_RELAX (STATE_GREG, STATE_ZERO)
255 #define STATE_GREG_DEF ENCODE_RELAX (STATE_GREG, STATE_MAX)
257 /* These displacements are relative to the adress following the opcode
258 word of the instruction. The catch-all states have zero for "reach"
259 and "next" entries. */
261 #define GETA_0F (65536 * 4 - 8)
262 #define GETA_0B (-65536 * 4 - 4)
264 #define GETA_MAX_LEN 4 * 4
268 #define BCC_0F GETA_0F
269 #define BCC_0B GETA_0B
271 #define BCC_MAX_LEN 6 * 4
272 #define BCC_5F GETA_3F
273 #define BCC_5B GETA_3B
275 #define PUSHJ_0F GETA_0F
276 #define PUSHJ_0B GETA_0B
278 #define PUSHJ_MAX_LEN 5 * 4
279 #define PUSHJ_4F GETA_3F
280 #define PUSHJ_4B GETA_3B
282 #define JMP_0F (65536 * 256 * 4 - 8)
283 #define JMP_0B (-65536 * 256 * 4 - 4)
285 #define JMP_MAX_LEN 5 * 4
289 #define RELAX_ENCODE_SHIFT 1
290 #define ENCODE_RELAX(what, length) (((what) << RELAX_ENCODE_SHIFT) + (length))
292 const relax_typeS mmix_relax_table
[] =
294 /* Error sentinel (0, 0). */
301 {GETA_0F
, GETA_0B
, 0, ENCODE_RELAX (STATE_GETA
, STATE_MAX
)},
305 GETA_MAX_LEN
- 4, 0},
308 {BCC_0F
, BCC_0B
, 0, ENCODE_RELAX (STATE_BCC
, STATE_MAX
)},
315 {PUSHJ_0F
, PUSHJ_0B
, 0, ENCODE_RELAX (STATE_PUSHJ
, STATE_MAX
)},
319 PUSHJ_MAX_LEN
- 4, 0},
322 {JMP_0F
, JMP_0B
, 0, ENCODE_RELAX (STATE_JMP
, STATE_MAX
)},
328 /* GREG (5, 0), (5, 1), though the table entry isn't used. */
329 {0, 0, 0, 0}, {0, 0, 0, 0}
332 const pseudo_typeS md_pseudo_table
[] =
334 /* Support " .greg sym,expr" syntax. */
337 /* Support " .bspec expr" syntax. */
338 {"bspec", s_bspec
, 1},
340 /* Support " .espec" syntax. */
341 {"espec", s_espec
, 1},
343 /* Support " .local $45" syntax. */
344 {"local", mmix_s_local
, 1},
346 /* Support DWARF2 debugging info. */
347 {"file", (void (*) PARAMS ((int))) dwarf2_directive_file
, 0},
348 {"loc", dwarf2_directive_loc
, 0},
353 const char mmix_comment_chars
[] = "%!";
355 /* A ':' is a valid symbol character in mmixal. It's the prefix
356 delimiter, but other than that, it works like a symbol character,
357 except that we strip one off at the beginning of symbols. An '@' is a
358 symbol by itself (for the current location); space around it must not
360 const char mmix_symbol_chars
[] = ":@";
362 const char line_comment_chars
[] = "*#";
364 const char line_separator_chars
[] = ";";
366 const char mmix_exp_chars
[] = "eE";
368 const char mmix_flt_chars
[] = "rf";
371 /* Fill in the offset-related part of GETA or Bcc. */
374 mmix_set_geta_branch_offset (opcodep
, value
)
385 md_number_to_chars (opcodep
+ 2, value
, 2);
388 /* Fill in the offset-related part of JMP. */
391 mmix_set_jmp_offset (opcodep
, value
)
397 value
+= 65536 * 256 * 4;
402 md_number_to_chars (opcodep
+ 1, value
, 3);
405 /* Fill in NOP:s for the expanded part of GETA/JMP/Bcc/PUSHJ. */
408 mmix_fill_nops (opcodep
, n
)
414 for (i
= 0; i
< n
; i
++)
415 md_number_to_chars (opcodep
+ i
* 4, SWYM_INSN_BYTE
<< 24, 4);
418 /* See macro md_parse_name in tc-mmix.h. */
421 mmix_current_location (fn
, exp
)
422 void (*fn
) PARAMS ((expressionS
*));
430 /* Get up to three operands, filling them into the exp array.
431 General idea and code stolen from the tic80 port. */
434 get_operands (max_operands
, s
, exp
)
443 while (nextchar
== ',')
445 /* Skip leading whitespace */
446 while (*p
== ' ' || *p
== '\t')
449 /* Check to see if we have any operands left to parse */
450 if (*p
== 0 || *p
== '\n' || *p
== '\r')
454 else if (numexp
== max_operands
)
456 /* This seems more sane than saying "too many operands". We'll
457 get here only if the trailing trash starts with a comma. */
458 as_bad (_("invalid operands"));
459 mmix_discard_rest_of_line ();
463 /* Begin operand parsing at the current scan point. */
465 input_line_pointer
= p
;
466 expression (&exp
[numexp
]);
468 if (exp
[numexp
].X_op
== O_illegal
)
470 as_bad (_("invalid operands"));
472 else if (exp
[numexp
].X_op
== O_absent
)
474 as_bad (_("missing operand"));
478 p
= input_line_pointer
;
480 /* Skip leading whitespace */
481 while (*p
== ' ' || *p
== '\t')
486 /* If we allow "naked" comments, ignore the rest of the line. */
489 mmix_handle_rest_of_empty_line ();
490 input_line_pointer
--;
493 /* Mark the end of the valid operands with an illegal expression. */
494 exp
[numexp
].X_op
= O_illegal
;
499 /* Get the value of a special register, or -1 if the name does not match
500 one. NAME is a null-terminated string. */
503 get_spec_regno (name
)
514 /* Well, it's a short array and we'll most often just match the first
516 for (i
= 0; mmix_spec_regs
[i
].name
!= NULL
; i
++)
517 if (strcmp (name
, mmix_spec_regs
[i
].name
) == 0)
518 return mmix_spec_regs
[i
].number
;
523 /* For GET and PUT, parse the register names "manually", so we don't use
526 get_putget_operands (insn
, operands
, exp
)
527 struct mmix_opcode
*insn
;
531 expressionS
*expp_reg
;
532 expressionS
*expp_sreg
;
534 char *sregend
= operands
;
539 /* Skip leading whitespace */
540 while (*p
== ' ' || *p
== '\t')
543 input_line_pointer
= p
;
545 if (insn
->operands
== mmix_operands_get
)
550 expression (expp_reg
);
552 p
= input_line_pointer
;
554 /* Skip whitespace */
555 while (*p
== ' ' || *p
== '\t')
562 /* Skip whitespace */
563 while (*p
== ' ' || *p
== '\t')
566 input_line_pointer
= sregp
;
567 c
= get_symbol_end ();
568 sregend
= input_line_pointer
;
576 /* Initialize to error state in case we'll never call expression on
578 expp_reg
->X_op
= O_illegal
;
581 c
= get_symbol_end ();
582 sregend
= p
= input_line_pointer
;
585 /* Skip whitespace */
586 while (*p
== ' ' || *p
== '\t')
593 /* Skip whitespace */
594 while (*p
== ' ' || *p
== '\t')
597 input_line_pointer
= p
;
598 expression (expp_reg
);
603 regno
= get_spec_regno (sregp
);
606 /* Let the caller issue errors; we've made sure the operands are
608 if (expp_reg
->X_op
!= O_illegal
609 && expp_reg
->X_op
!= O_absent
612 expp_sreg
->X_op
= O_register
;
613 expp_sreg
->X_add_number
= regno
+ 256;
619 /* Handle MMIX-specific option. */
622 md_parse_option (c
, arg
)
624 char *arg ATTRIBUTE_UNUSED
;
629 warn_on_expansion
= 0;
630 allocate_undefined_gregs_in_linker
= 1;
637 case OPTION_NOEXPAND
:
641 case OPTION_NOMERGEGREG
:
647 equated_spec_regs
= 0;
650 case OPTION_GNU_SYNTAX
:
652 label_without_colon_this_line
= 0;
655 case OPTION_GLOBALIZE_SYMBOLS
:
656 mmix_globalize_symbols
= 1;
659 case OPTION_FIXED_SPEC_REGS
:
660 equated_spec_regs
= 0;
663 case OPTION_LINKER_ALLOCATED_GREGS
:
664 allocate_undefined_gregs_in_linker
= 1;
674 /* Display MMIX-specific help text. */
677 md_show_usage (stream
)
680 fprintf (stream
, _(" MMIX-specific command line options:\n"));
681 fprintf (stream
, _("\
682 -fixed-special-register-names\n\
683 Allow only the original special register names.\n"));
684 fprintf (stream
, _("\
685 -globalize-symbols Make all symbols global.\n"));
686 fprintf (stream
, _("\
687 -gnu-syntax Turn off mmixal syntax compatibility.\n"));
688 fprintf (stream
, _("\
689 -relax Create linker relaxable code.\n"));
690 fprintf (stream
, _("\
691 -no-predefined-syms Do not provide mmixal built-in constants.\n\
692 Implies -fixed-special-register-names.\n"));
693 fprintf (stream
, _("\
694 -no-expand Do not expand GETA, branches, PUSHJ or JUMP\n\
695 into multiple instructions.\n"));
696 fprintf (stream
, _("\
697 -no-merge-gregs Do not merge GREG definitions with nearby values.\n"));
698 fprintf (stream
, _("\
699 -linker-allocated-gregs If there's no suitable GREG definition for the\
700 operands of an instruction, let the linker resolve.\n"));
701 fprintf (stream
, _("\
702 -x Do not warn when an operand to GETA, a branch,\n\
703 PUSHJ or JUMP is not known to be within range.\n\
704 The linker will catch any errors. Implies\n\
705 -linker-allocated-gregs."));
708 /* Step to end of line, but don't step over the end of the line. */
711 mmix_discard_rest_of_line ()
713 while (*input_line_pointer
714 && (! is_end_of_line
[(unsigned char) *input_line_pointer
]
715 || TC_EOL_IN_INSN (input_line_pointer
)))
716 input_line_pointer
++;
719 /* Act as demand_empty_rest_of_line if we're in strict GNU syntax mode,
720 otherwise just ignore the rest of the line (and skip the end-of-line
724 mmix_handle_rest_of_empty_line ()
727 demand_empty_rest_of_line ();
730 mmix_discard_rest_of_line ();
731 input_line_pointer
++;
735 /* Initialize GAS MMIX specifics. */
741 const struct mmix_opcode
*opcode
;
743 /* We assume nobody will use this, so don't allocate any room. */
744 obstack_begin (&mmix_sym_obstack
, 0);
746 /* This will break the day the "lex" thingy changes. For now, it's the
747 only way to make ':' part of a name, and a name beginner. */
748 lex_type
[':'] = (LEX_NAME
| LEX_BEGIN_NAME
);
750 mmix_opcode_hash
= hash_new ();
753 = bfd_make_section_old_way (stdoutput
, MMIX_REG_SECTION_NAME
);
755 for (opcode
= mmix_opcodes
; opcode
->name
; opcode
++)
756 hash_insert (mmix_opcode_hash
, opcode
->name
, (char *) opcode
);
758 /* We always insert the ordinary registers 0..255 as registers. */
759 for (i
= 0; i
< 256; i
++)
763 /* Alternatively, we could diddle with '$' and the following number,
764 but keeping the registers as symbols helps keep parsing simple. */
765 sprintf (buf
, "$%d", i
);
766 symbol_table_insert (symbol_new (buf
, reg_section
, i
,
767 &zero_address_frag
));
770 /* Insert mmixal built-in names if allowed. */
773 for (i
= 0; mmix_spec_regs
[i
].name
!= NULL
; i
++)
774 symbol_table_insert (symbol_new (mmix_spec_regs
[i
].name
,
776 mmix_spec_regs
[i
].number
+ 256,
777 &zero_address_frag
));
779 /* FIXME: Perhaps these should be recognized as specials; as field
780 names for those instructions. */
781 symbol_table_insert (symbol_new ("ROUND_CURRENT", reg_section
, 512,
782 &zero_address_frag
));
783 symbol_table_insert (symbol_new ("ROUND_OFF", reg_section
, 512 + 1,
784 &zero_address_frag
));
785 symbol_table_insert (symbol_new ("ROUND_UP", reg_section
, 512 + 2,
786 &zero_address_frag
));
787 symbol_table_insert (symbol_new ("ROUND_DOWN", reg_section
, 512 + 3,
788 &zero_address_frag
));
789 symbol_table_insert (symbol_new ("ROUND_NEAR", reg_section
, 512 + 4,
790 &zero_address_frag
));
794 /* Assemble one insn in STR. */
800 char *operands
= str
;
801 char modified_char
= 0;
802 struct mmix_opcode
*instruction
;
803 fragS
*opc_fragP
= NULL
;
804 int max_operands
= 3;
806 /* Note that the struct frag member fr_literal in frags.h is char[], so
807 I have to make this a plain char *. */
808 /* unsigned */ char *opcodep
= NULL
;
813 /* Move to end of opcode. */
815 is_part_of_name (*operands
);
819 if (ISSPACE (*operands
))
821 modified_char
= *operands
;
825 instruction
= (struct mmix_opcode
*) hash_find (mmix_opcode_hash
, str
);
826 if (instruction
== NULL
)
828 as_bad (_("unknown opcode: `%s'"), str
);
830 /* Avoid "unhandled label" errors. */
831 pending_label
= NULL
;
835 /* Put back the character after the opcode. */
836 if (modified_char
!= 0)
837 operands
[-1] = modified_char
;
839 input_line_pointer
= operands
;
841 /* Is this a mmixal pseudodirective? */
842 if (instruction
->type
== mmix_type_pseudo
)
844 /* For mmixal compatibility, a label for an instruction (and
845 emitting pseudo) refers to the _aligned_ address. We emit the
846 label here for the pseudos that don't handle it themselves. When
847 having an fb-label, emit it here, and increment the counter after
849 switch (instruction
->operands
)
851 case mmix_operands_loc
:
852 case mmix_operands_byte
:
853 case mmix_operands_prefix
:
854 case mmix_operands_local
:
855 case mmix_operands_bspec
:
856 case mmix_operands_espec
:
857 if (current_fb_label
>= 0)
858 colon (fb_label_name (current_fb_label
, 1));
859 else if (pending_label
!= NULL
)
861 colon (pending_label
);
862 pending_label
= NULL
;
870 /* Some of the pseudos emit contents, others don't. Set a
871 contents-emitted flag when we emit something into .text */
872 switch (instruction
->operands
)
874 case mmix_operands_loc
:
879 case mmix_operands_byte
:
884 case mmix_operands_wyde
:
889 case mmix_operands_tetra
:
894 case mmix_operands_octa
:
899 case mmix_operands_prefix
:
904 case mmix_operands_local
:
909 case mmix_operands_bspec
:
914 case mmix_operands_espec
:
920 BAD_CASE (instruction
->operands
);
923 /* These are all working like the pseudo functions in read.c:s_...,
924 in that they step over the end-of-line marker at the end of the
925 line. We don't want that here. */
926 input_line_pointer
--;
928 /* Step up the fb-label counter if there was a definition on this
930 if (current_fb_label
>= 0)
932 fb_label_instance_inc (current_fb_label
);
933 current_fb_label
= -1;
936 /* Reset any don't-align-next-datum request, unless this was a LOC
938 if (instruction
->operands
!= mmix_operands_loc
)
944 /* Not a pseudo; we *will* emit contents. */
945 if (now_seg
== data_section
)
947 if (lowest_data_loc
!= (bfd_vma
) -1 && (lowest_data_loc
& 3) != 0)
949 if (data_has_contents
)
950 as_bad (_("specified location wasn't TETRA-aligned"));
951 else if (want_unaligned
)
952 as_bad (_("unaligned data at an absolute location is not supported"));
954 lowest_data_loc
&= ~(bfd_vma
) 3;
955 lowest_data_loc
+= 4;
958 data_has_contents
= 1;
960 else if (now_seg
== text_section
)
962 if (lowest_text_loc
!= (bfd_vma
) -1 && (lowest_text_loc
& 3) != 0)
964 if (text_has_contents
)
965 as_bad (_("specified location wasn't TETRA-aligned"));
966 else if (want_unaligned
)
967 as_bad (_("unaligned data at an absolute location is not supported"));
969 lowest_text_loc
&= ~(bfd_vma
) 3;
970 lowest_text_loc
+= 4;
973 text_has_contents
= 1;
976 /* After a sequence of BYTEs or WYDEs, we need to get to instruction
977 alignment. For other pseudos, a ".p2align 2" is supposed to be
978 inserted by the user. */
979 if (last_alignment
< 2 && ! want_unaligned
)
981 frag_align (2, 0, 0);
982 record_alignment (now_seg
, 2);
986 /* Reset any don't-align-next-datum request. */
989 /* For mmixal compatibility, a label for an instruction (and emitting
990 pseudo) refers to the _aligned_ address. So we have to emit the
992 if (pending_label
!= NULL
)
994 colon (pending_label
);
995 pending_label
= NULL
;
998 /* We assume that mmix_opcodes keeps having unique mnemonics for each
999 opcode, so we don't have to iterate over more than one opcode; if the
1000 syntax does not match, then there's a syntax error. */
1002 /* Operands have little or no context and are all comma-separated; it is
1003 easier to parse each expression first. */
1004 switch (instruction
->operands
)
1006 case mmix_operands_reg_yz
:
1007 case mmix_operands_pop
:
1008 case mmix_operands_regaddr
:
1009 case mmix_operands_pushj
:
1010 case mmix_operands_get
:
1011 case mmix_operands_put
:
1012 case mmix_operands_set
:
1013 case mmix_operands_save
:
1014 case mmix_operands_unsave
:
1018 case mmix_operands_sync
:
1019 case mmix_operands_jmp
:
1020 case mmix_operands_resume
:
1024 /* The original 3 is fine for the rest. */
1029 /* If this is GET or PUT, and we don't do allow those names to be
1030 equated, we need to parse the names ourselves, so we don't pick up a
1031 user label instead of the special register. */
1032 if (! equated_spec_regs
1033 && (instruction
->operands
== mmix_operands_get
1034 || instruction
->operands
== mmix_operands_put
))
1035 n_operands
= get_putget_operands (instruction
, operands
, exp
);
1037 n_operands
= get_operands (max_operands
, operands
, exp
);
1039 /* If there's a fb-label on the current line, set that label. This must
1040 be done *after* evaluating expressions of operands, since neither a
1041 "1B" nor a "1F" refers to "1H" on the same line. */
1042 if (current_fb_label
>= 0)
1044 fb_label_instance_inc (current_fb_label
);
1045 colon (fb_label_name (current_fb_label
, 0));
1046 current_fb_label
= -1;
1049 /* We also assume that the length of the instruction is at least 4, the
1050 size of an unexpanded instruction. We need a self-contained frag
1051 since we want the relocation to point to the instruction, not the
1054 opcodep
= frag_more (4);
1055 mmix_opcode_frag
= opc_fragP
= frag_now
;
1056 frag_now
->fr_opcode
= opcodep
;
1058 /* Mark start of insn for DWARF2 debug features. */
1059 if (OUTPUT_FLAVOR
== bfd_target_elf_flavour
)
1060 dwarf2_emit_insn (4);
1062 md_number_to_chars (opcodep
, instruction
->match
, 4);
1064 switch (instruction
->operands
)
1066 case mmix_operands_jmp
:
1067 if (n_operands
== 0 && ! mmix_gnu_syntax
)
1068 /* Zeros are in place - nothing needs to be done when we have no
1072 /* Add a frag for a JMP relaxation; we need room for max four
1073 extra instructions. We don't do any work around here to check if
1074 we can determine the offset right away. */
1075 if (n_operands
!= 1 || exp
[0].X_op
== O_register
)
1077 as_bad (_("invalid operand to opcode %s: `%s'"),
1078 instruction
->name
, operands
);
1083 frag_var (rs_machine_dependent
, 4 * 4, 0,
1084 ENCODE_RELAX (STATE_JMP
, STATE_UNDF
),
1085 exp
[0].X_add_symbol
,
1086 exp
[0].X_add_number
,
1089 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
, 4,
1090 exp
+ 0, 1, BFD_RELOC_MMIX_ADDR27
);
1093 case mmix_operands_pushj
:
1094 /* We take care of PUSHJ in full here. */
1096 || ((exp
[0].X_op
== O_constant
|| exp
[0].X_op
== O_register
)
1097 && (exp
[0].X_add_number
> 255 || exp
[0].X_add_number
< 0)))
1099 as_bad (_("invalid operands to opcode %s: `%s'"),
1100 instruction
->name
, operands
);
1104 if (exp
[0].X_op
== O_register
|| exp
[0].X_op
== O_constant
)
1105 opcodep
[1] = exp
[0].X_add_number
;
1107 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 1,
1108 1, exp
+ 0, 0, BFD_RELOC_MMIX_REG_OR_BYTE
);
1111 frag_var (rs_machine_dependent
, PUSHJ_MAX_LEN
- 4, 0,
1112 ENCODE_RELAX (STATE_PUSHJ
, STATE_UNDF
),
1113 exp
[1].X_add_symbol
,
1114 exp
[1].X_add_number
,
1117 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
, 4,
1118 exp
+ 1, 1, BFD_RELOC_MMIX_ADDR19
);
1121 case mmix_operands_regaddr
:
1122 /* GETA/branch: Add a frag for relaxation. We don't do any work
1123 around here to check if we can determine the offset right away. */
1124 if (n_operands
!= 2 || exp
[1].X_op
== O_register
)
1126 as_bad (_("invalid operands to opcode %s: `%s'"),
1127 instruction
->name
, operands
);
1132 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
, 4,
1133 exp
+ 1, 1, BFD_RELOC_MMIX_ADDR19
);
1134 else if (instruction
->type
== mmix_type_condbranch
)
1135 frag_var (rs_machine_dependent
, BCC_MAX_LEN
- 4, 0,
1136 ENCODE_RELAX (STATE_BCC
, STATE_UNDF
),
1137 exp
[1].X_add_symbol
,
1138 exp
[1].X_add_number
,
1141 frag_var (rs_machine_dependent
, GETA_MAX_LEN
- 4, 0,
1142 ENCODE_RELAX (STATE_GETA
, STATE_UNDF
),
1143 exp
[1].X_add_symbol
,
1144 exp
[1].X_add_number
,
1152 switch (instruction
->operands
)
1154 case mmix_operands_regs
:
1155 /* We check the number of operands here, since we're in a
1156 FALLTHROUGH sequence in the next switch. */
1157 if (n_operands
!= 3 || exp
[2].X_op
== O_constant
)
1159 as_bad (_("invalid operands to opcode %s: `%s'"),
1160 instruction
->name
, operands
);
1164 case mmix_operands_regs_z
:
1165 if (n_operands
!= 3)
1167 as_bad (_("invalid operands to opcode %s: `%s'"),
1168 instruction
->name
, operands
);
1172 case mmix_operands_reg_yz
:
1173 case mmix_operands_roundregs_z
:
1174 case mmix_operands_roundregs
:
1175 case mmix_operands_regs_z_opt
:
1176 case mmix_operands_neg
:
1177 case mmix_operands_regaddr
:
1178 case mmix_operands_get
:
1179 case mmix_operands_set
:
1180 case mmix_operands_save
:
1182 || (exp
[0].X_op
== O_register
&& exp
[0].X_add_number
> 255))
1184 as_bad (_("invalid operands to opcode %s: `%s'"),
1185 instruction
->name
, operands
);
1189 if (exp
[0].X_op
== O_register
)
1190 opcodep
[1] = exp
[0].X_add_number
;
1192 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 1,
1193 1, exp
+ 0, 0, BFD_RELOC_MMIX_REG
);
1200 /* A corresponding once-over for those who take an 8-bit constant as
1201 their first operand. */
1202 switch (instruction
->operands
)
1204 case mmix_operands_pushgo
:
1205 /* PUSHGO: X is a constant, but can be expressed as a register.
1206 We handle X here and use the common machinery of T,X,3,$ for
1207 the rest of the operands. */
1209 || ((exp
[0].X_op
== O_constant
|| exp
[0].X_op
== O_register
)
1210 && (exp
[0].X_add_number
> 255 || exp
[0].X_add_number
< 0)))
1212 as_bad (_("invalid operands to opcode %s: `%s'"),
1213 instruction
->name
, operands
);
1216 else if (exp
[0].X_op
== O_constant
|| exp
[0].X_op
== O_register
)
1217 opcodep
[1] = exp
[0].X_add_number
;
1219 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 1,
1220 1, exp
+ 0, 0, BFD_RELOC_MMIX_REG_OR_BYTE
);
1223 case mmix_operands_pop
:
1224 if ((n_operands
== 0 || n_operands
== 1) && ! mmix_gnu_syntax
)
1227 case mmix_operands_x_regs_z
:
1229 || (exp
[0].X_op
== O_constant
1230 && (exp
[0].X_add_number
> 255
1231 || exp
[0].X_add_number
< 0)))
1233 as_bad (_("invalid operands to opcode %s: `%s'"),
1234 instruction
->name
, operands
);
1238 if (exp
[0].X_op
== O_constant
)
1239 opcodep
[1] = exp
[0].X_add_number
;
1241 /* FIXME: This doesn't bring us unsignedness checking. */
1242 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 1,
1243 1, exp
+ 0, 0, BFD_RELOC_8
);
1248 /* Handle the rest. */
1249 switch (instruction
->operands
)
1251 case mmix_operands_set
:
1252 /* SET: Either two registers, "$X,$Y", with Z field as zero, or
1253 "$X,YZ", meaning change the opcode to SETL. */
1255 || (exp
[1].X_op
== O_constant
1256 && (exp
[1].X_add_number
> 0xffff || exp
[1].X_add_number
< 0)))
1258 as_bad (_("invalid operands to opcode %s: `%s'"),
1259 instruction
->name
, operands
);
1263 if (exp
[1].X_op
== O_constant
)
1265 /* There's an ambiguity with "SET $0,Y" when Y isn't defined
1266 yet. To keep things simple, we assume that Y is then a
1267 register, and only change the opcode if Y is defined at this
1270 There's no compatibility problem with mmixal, since it emits
1271 errors if the field is not defined at this point. */
1272 md_number_to_chars (opcodep
, SETL_INSN_BYTE
, 1);
1274 opcodep
[2] = (exp
[1].X_add_number
>> 8) & 255;
1275 opcodep
[3] = exp
[1].X_add_number
& 255;
1279 case mmix_operands_x_regs_z
:
1280 /* SYNCD: "X,$Y,$Z|Z". */
1282 case mmix_operands_regs
:
1283 /* Three registers, $X,$Y,$Z. */
1285 case mmix_operands_regs_z
:
1286 /* Operands "$X,$Y,$Z|Z", number of arguments checked above. */
1288 case mmix_operands_pushgo
:
1289 /* Operands "$X|X,$Y,$Z|Z", optional Z. */
1291 case mmix_operands_regs_z_opt
:
1292 /* Operands "$X,$Y,$Z|Z", with $Z|Z being optional, default 0. Any
1293 operands not completely decided yet are postponed to later in
1294 assembly (but not until link-time yet). */
1296 if ((n_operands
!= 2 && n_operands
!= 3)
1297 || (exp
[1].X_op
== O_register
&& exp
[1].X_add_number
> 255)
1299 && ((exp
[2].X_op
== O_register
1300 && exp
[2].X_add_number
> 255
1302 || (exp
[2].X_op
== O_constant
1303 && (exp
[2].X_add_number
> 255
1304 || exp
[2].X_add_number
< 0)))))
1306 as_bad (_("invalid operands to opcode %s: `%s'"),
1307 instruction
->name
, operands
);
1311 if (n_operands
== 2)
1315 /* The last operand is immediate whenever we see just two
1317 opcodep
[0] |= IMM_OFFSET_BIT
;
1319 /* Now, we could either have an implied "0" as the Z operand, or
1320 it could be the constant of a "base address plus offset". It
1321 depends on whether it is allowed; only memory operations, as
1322 signified by instruction->type and "T" and "X" operand types,
1323 and it depends on whether we find a register in the second
1325 if (exp
[1].X_op
== O_register
&& exp
[1].X_add_number
<= 255)
1327 /* A zero then; all done. */
1328 opcodep
[2] = exp
[1].X_add_number
;
1332 /* Not known as a register. Is base address plus offset
1333 allowed, or can we assume that it is a register anyway? */
1334 if ((instruction
->operands
!= mmix_operands_regs_z_opt
1335 && instruction
->operands
!= mmix_operands_x_regs_z
1336 && instruction
->operands
!= mmix_operands_pushgo
)
1337 || (instruction
->type
!= mmix_type_memaccess_octa
1338 && instruction
->type
!= mmix_type_memaccess_tetra
1339 && instruction
->type
!= mmix_type_memaccess_wyde
1340 && instruction
->type
!= mmix_type_memaccess_byte
1341 && instruction
->type
!= mmix_type_memaccess_block
1342 && instruction
->type
!= mmix_type_jsr
1343 && instruction
->type
!= mmix_type_branch
))
1345 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 2,
1346 1, exp
+ 1, 0, BFD_RELOC_MMIX_REG
);
1350 /* To avoid getting a NULL add_symbol for constants and then
1351 catching a SEGV in write_relocs since it doesn't handle
1352 constants well for relocs other than PC-relative, we need to
1353 pass expressions as symbols and use fix_new, not fix_new_exp. */
1354 sym
= make_expr_symbol (exp
+ 1);
1356 /* Now we know it can be a "base address plus offset". Add
1357 proper fixup types so we can handle this later, when we've
1358 parsed everything. */
1359 fix_new (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 2,
1360 8, sym
, 0, 0, BFD_RELOC_MMIX_BASE_PLUS_OFFSET
);
1364 if (exp
[1].X_op
== O_register
)
1365 opcodep
[2] = exp
[1].X_add_number
;
1367 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 2,
1368 1, exp
+ 1, 0, BFD_RELOC_MMIX_REG
);
1370 /* In mmixal compatibility mode, we allow special registers as
1371 constants for the Z operand. They have 256 added to their
1372 register numbers, so the right thing will happen if we just treat
1373 those as constants. */
1374 if (exp
[2].X_op
== O_register
&& exp
[2].X_add_number
<= 255)
1375 opcodep
[3] = exp
[2].X_add_number
;
1376 else if (exp
[2].X_op
== O_constant
1377 || (exp
[2].X_op
== O_register
&& exp
[2].X_add_number
> 255))
1379 opcodep
[3] = exp
[2].X_add_number
;
1380 opcodep
[0] |= IMM_OFFSET_BIT
;
1383 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 3,
1385 (instruction
->operands
== mmix_operands_set
1386 || instruction
->operands
== mmix_operands_regs
)
1387 ? BFD_RELOC_MMIX_REG
: BFD_RELOC_MMIX_REG_OR_BYTE
);
1390 case mmix_operands_pop
:
1391 /* POP, one eight and one 16-bit operand. */
1392 if (n_operands
== 0 && ! mmix_gnu_syntax
)
1394 if (n_operands
== 1 && ! mmix_gnu_syntax
)
1395 goto a_single_24_bit_number_operand
;
1397 case mmix_operands_reg_yz
:
1398 /* A register and a 16-bit unsigned number. */
1400 || exp
[1].X_op
== O_register
1401 || (exp
[1].X_op
== O_constant
1402 && (exp
[1].X_add_number
> 0xffff || exp
[1].X_add_number
< 0)))
1404 as_bad (_("invalid operands to opcode %s: `%s'"),
1405 instruction
->name
, operands
);
1409 if (exp
[1].X_op
== O_constant
)
1411 opcodep
[2] = (exp
[1].X_add_number
>> 8) & 255;
1412 opcodep
[3] = exp
[1].X_add_number
& 255;
1415 /* FIXME: This doesn't bring us unsignedness checking. */
1416 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 2,
1417 2, exp
+ 1, 0, BFD_RELOC_16
);
1420 case mmix_operands_jmp
:
1421 /* A JMP. Everyhing is already done. */
1424 case mmix_operands_roundregs
:
1425 /* Two registers with optional rounding mode or constant in between. */
1426 if ((n_operands
== 3 && exp
[2].X_op
== O_constant
)
1427 || (n_operands
== 2 && exp
[1].X_op
== O_constant
))
1429 as_bad (_("invalid operands to opcode %s: `%s'"),
1430 instruction
->name
, operands
);
1434 case mmix_operands_roundregs_z
:
1435 /* Like FLOT, "$X,ROUND_MODE,$Z|Z", but the rounding mode is
1436 optional and can be the corresponding constant. */
1438 /* Which exp index holds the second operand (not the rounding
1440 int op2no
= n_operands
- 1;
1442 if ((n_operands
!= 2 && n_operands
!= 3)
1443 || ((exp
[op2no
].X_op
== O_register
1444 && exp
[op2no
].X_add_number
> 255)
1445 || (exp
[op2no
].X_op
== O_constant
1446 && (exp
[op2no
].X_add_number
> 255
1447 || exp
[op2no
].X_add_number
< 0)))
1449 /* We don't allow for the rounding mode to be deferred; it
1450 must be determined in the "first pass". It cannot be a
1451 symbol equated to a rounding mode, but defined after
1453 && ((exp
[1].X_op
== O_register
1454 && exp
[1].X_add_number
< 512)
1455 || (exp
[1].X_op
== O_constant
1456 && exp
[1].X_add_number
< 0
1457 && exp
[1].X_add_number
> 4)
1458 || (exp
[1].X_op
!= O_register
1459 && exp
[1].X_op
!= O_constant
))))
1461 as_bad (_("invalid operands to opcode %s: `%s'"),
1462 instruction
->name
, operands
);
1466 /* Add rounding mode if present. */
1467 if (n_operands
== 3)
1468 opcodep
[2] = exp
[1].X_add_number
& 255;
1470 if (exp
[op2no
].X_op
== O_register
)
1471 opcodep
[3] = exp
[op2no
].X_add_number
;
1472 else if (exp
[op2no
].X_op
== O_constant
)
1474 opcodep
[3] = exp
[op2no
].X_add_number
;
1475 opcodep
[0] |= IMM_OFFSET_BIT
;
1478 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 3,
1480 instruction
->operands
== mmix_operands_roundregs
1481 ? BFD_RELOC_MMIX_REG
1482 : BFD_RELOC_MMIX_REG_OR_BYTE
);
1486 case mmix_operands_sync
:
1487 a_single_24_bit_number_operand
:
1489 || exp
[0].X_op
== O_register
1490 || (exp
[0].X_op
== O_constant
1491 && (exp
[0].X_add_number
> 0xffffff || exp
[0].X_add_number
< 0)))
1493 as_bad (_("invalid operands to opcode %s: `%s'"),
1494 instruction
->name
, operands
);
1498 if (exp
[0].X_op
== O_constant
)
1500 opcodep
[1] = (exp
[0].X_add_number
>> 16) & 255;
1501 opcodep
[2] = (exp
[0].X_add_number
>> 8) & 255;
1502 opcodep
[3] = exp
[0].X_add_number
& 255;
1505 /* FIXME: This doesn't bring us unsignedness checking. */
1506 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 1,
1507 3, exp
+ 0, 0, BFD_RELOC_24
);
1510 case mmix_operands_neg
:
1511 /* Operands "$X,Y,$Z|Z"; NEG or NEGU. Y is optional, 0 is default. */
1513 if ((n_operands
!= 3 && n_operands
!= 2)
1514 || (n_operands
== 3 && exp
[1].X_op
== O_register
)
1515 || ((exp
[1].X_op
== O_constant
|| exp
[1].X_op
== O_register
)
1516 && (exp
[1].X_add_number
> 255 || exp
[1].X_add_number
< 0))
1518 && ((exp
[2].X_op
== O_register
&& exp
[2].X_add_number
> 255)
1519 || (exp
[2].X_op
== O_constant
1520 && (exp
[2].X_add_number
> 255
1521 || exp
[2].X_add_number
< 0)))))
1523 as_bad (_("invalid operands to opcode %s: `%s'"),
1524 instruction
->name
, operands
);
1528 if (n_operands
== 2)
1530 if (exp
[1].X_op
== O_register
)
1531 opcodep
[3] = exp
[1].X_add_number
;
1532 else if (exp
[1].X_op
== O_constant
)
1534 opcodep
[3] = exp
[1].X_add_number
;
1535 opcodep
[0] |= IMM_OFFSET_BIT
;
1538 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 3,
1539 1, exp
+ 1, 0, BFD_RELOC_MMIX_REG_OR_BYTE
);
1543 if (exp
[1].X_op
== O_constant
)
1544 opcodep
[2] = exp
[1].X_add_number
;
1546 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 2,
1547 1, exp
+ 1, 0, BFD_RELOC_8
);
1549 if (exp
[2].X_op
== O_register
)
1550 opcodep
[3] = exp
[2].X_add_number
;
1551 else if (exp
[2].X_op
== O_constant
)
1553 opcodep
[3] = exp
[2].X_add_number
;
1554 opcodep
[0] |= IMM_OFFSET_BIT
;
1557 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 3,
1558 1, exp
+ 2, 0, BFD_RELOC_MMIX_REG_OR_BYTE
);
1561 case mmix_operands_regaddr
:
1562 /* A GETA/branch-type. */
1565 case mmix_operands_get
:
1566 /* "$X,spec_reg"; GET.
1567 Like with rounding modes, we demand that the special register or
1568 symbol is already defined when we get here at the point of use. */
1570 || (exp
[1].X_op
== O_register
1571 && (exp
[1].X_add_number
< 256 || exp
[1].X_add_number
>= 512))
1572 || (exp
[1].X_op
== O_constant
1573 && (exp
[1].X_add_number
< 0 || exp
[1].X_add_number
> 256))
1574 || (exp
[1].X_op
!= O_constant
&& exp
[1].X_op
!= O_register
))
1576 as_bad (_("invalid operands to opcode %s: `%s'"),
1577 instruction
->name
, operands
);
1581 opcodep
[3] = exp
[1].X_add_number
- 256;
1584 case mmix_operands_put
:
1585 /* "spec_reg,$Z|Z"; PUT. */
1587 || (exp
[0].X_op
== O_register
1588 && (exp
[0].X_add_number
< 256 || exp
[0].X_add_number
>= 512))
1589 || (exp
[0].X_op
== O_constant
1590 && (exp
[0].X_add_number
< 0 || exp
[0].X_add_number
> 256))
1591 || (exp
[0].X_op
!= O_constant
&& exp
[0].X_op
!= O_register
))
1593 as_bad (_("invalid operands to opcode %s: `%s'"),
1594 instruction
->name
, operands
);
1598 opcodep
[1] = exp
[0].X_add_number
- 256;
1600 /* Note that the Y field is zero. */
1602 if (exp
[1].X_op
== O_register
)
1603 opcodep
[3] = exp
[1].X_add_number
;
1604 else if (exp
[1].X_op
== O_constant
)
1606 opcodep
[3] = exp
[1].X_add_number
;
1607 opcodep
[0] |= IMM_OFFSET_BIT
;
1610 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 3,
1611 1, exp
+ 1, 0, BFD_RELOC_MMIX_REG_OR_BYTE
);
1614 case mmix_operands_save
:
1617 || exp
[1].X_op
!= O_constant
1618 || exp
[1].X_add_number
!= 0)
1620 as_bad (_("invalid operands to opcode %s: `%s'"),
1621 instruction
->name
, operands
);
1626 case mmix_operands_unsave
:
1627 if (n_operands
< 2 && ! mmix_gnu_syntax
)
1629 if (n_operands
== 1)
1631 if (exp
[0].X_op
== O_register
)
1632 opcodep
[3] = exp
[0].X_add_number
;
1634 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 3,
1635 1, exp
, 0, BFD_RELOC_MMIX_REG
);
1640 /* "0,$Z"; UNSAVE. */
1642 || exp
[0].X_op
!= O_constant
1643 || exp
[0].X_add_number
!= 0
1644 || exp
[1].X_op
== O_constant
1645 || (exp
[1].X_op
== O_register
1646 && exp
[1].X_add_number
> 255))
1648 as_bad (_("invalid operands to opcode %s: `%s'"),
1649 instruction
->name
, operands
);
1653 if (exp
[1].X_op
== O_register
)
1654 opcodep
[3] = exp
[1].X_add_number
;
1656 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 3,
1657 1, exp
+ 1, 0, BFD_RELOC_MMIX_REG
);
1660 case mmix_operands_xyz_opt
:
1661 /* SWYM, TRIP, TRAP: zero, one, two or three operands. */
1662 if (n_operands
== 0 && ! mmix_gnu_syntax
)
1663 /* Zeros are in place - nothing needs to be done for zero
1664 operands. We don't allow this in GNU syntax mode, because it
1665 was believed that the risk of missing to supply an operand is
1666 higher than the benefit of not having to specify a zero. */
1668 else if (n_operands
== 1 && exp
[0].X_op
!= O_register
)
1670 if (exp
[0].X_op
== O_constant
)
1672 if (exp
[0].X_add_number
> 255*255*255
1673 || exp
[0].X_add_number
< 0)
1675 as_bad (_("invalid operands to opcode %s: `%s'"),
1676 instruction
->name
, operands
);
1681 opcodep
[1] = (exp
[0].X_add_number
>> 16) & 255;
1682 opcodep
[2] = (exp
[0].X_add_number
>> 8) & 255;
1683 opcodep
[3] = exp
[0].X_add_number
& 255;
1687 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 1,
1688 3, exp
, 0, BFD_RELOC_24
);
1690 else if (n_operands
== 2
1691 && exp
[0].X_op
!= O_register
1692 && exp
[1].X_op
!= O_register
)
1696 if (exp
[0].X_op
== O_constant
)
1698 if (exp
[0].X_add_number
> 255
1699 || exp
[0].X_add_number
< 0)
1701 as_bad (_("invalid operands to opcode %s: `%s'"),
1702 instruction
->name
, operands
);
1706 opcodep
[1] = exp
[0].X_add_number
& 255;
1709 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 1,
1710 1, exp
, 0, BFD_RELOC_8
);
1712 if (exp
[1].X_op
== O_constant
)
1714 if (exp
[1].X_add_number
> 255*255
1715 || exp
[1].X_add_number
< 0)
1717 as_bad (_("invalid operands to opcode %s: `%s'"),
1718 instruction
->name
, operands
);
1723 opcodep
[2] = (exp
[1].X_add_number
>> 8) & 255;
1724 opcodep
[3] = exp
[1].X_add_number
& 255;
1728 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 2,
1729 2, exp
+ 1, 0, BFD_RELOC_16
);
1731 else if (n_operands
== 3
1732 && exp
[0].X_op
!= O_register
1733 && exp
[1].X_op
!= O_register
1734 && exp
[2].X_op
!= O_register
)
1736 /* Three operands. */
1738 if (exp
[0].X_op
== O_constant
)
1740 if (exp
[0].X_add_number
> 255
1741 || exp
[0].X_add_number
< 0)
1743 as_bad (_("invalid operands to opcode %s: `%s'"),
1744 instruction
->name
, operands
);
1748 opcodep
[1] = exp
[0].X_add_number
& 255;
1751 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 1,
1752 1, exp
, 0, BFD_RELOC_8
);
1754 if (exp
[1].X_op
== O_constant
)
1756 if (exp
[1].X_add_number
> 255
1757 || exp
[1].X_add_number
< 0)
1759 as_bad (_("invalid operands to opcode %s: `%s'"),
1760 instruction
->name
, operands
);
1764 opcodep
[2] = exp
[1].X_add_number
& 255;
1767 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 2,
1768 1, exp
+ 1, 0, BFD_RELOC_8
);
1770 if (exp
[2].X_op
== O_constant
)
1772 if (exp
[2].X_add_number
> 255
1773 || exp
[2].X_add_number
< 0)
1775 as_bad (_("invalid operands to opcode %s: `%s'"),
1776 instruction
->name
, operands
);
1780 opcodep
[3] = exp
[2].X_add_number
& 255;
1783 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 3,
1784 1, exp
+ 2, 0, BFD_RELOC_8
);
1786 else if (n_operands
<= 3
1787 && (strcmp (instruction
->name
, "trip") == 0
1788 || strcmp (instruction
->name
, "trap") == 0))
1790 /* The meaning of operands to TRIP and TRAP are not defined, so
1791 we add combinations not handled above here as we find them. */
1792 if (n_operands
== 3)
1794 /* Don't require non-register operands. Always generate
1795 fixups, so we don't have to copy lots of code and create
1796 maintanance problems. TRIP is supposed to be a rare
1797 instruction, so the overhead should not matter. We
1798 aren't allowed to fix_new_exp for an expression which is
1799 an O_register at this point, however. */
1800 if (exp
[0].X_op
== O_register
)
1801 opcodep
[1] = exp
[0].X_add_number
;
1803 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 1,
1804 1, exp
, 0, BFD_RELOC_MMIX_REG_OR_BYTE
);
1805 if (exp
[1].X_op
== O_register
)
1806 opcodep
[2] = exp
[1].X_add_number
;
1808 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 2,
1809 1, exp
+ 1, 0, BFD_RELOC_MMIX_REG_OR_BYTE
);
1810 if (exp
[2].X_op
== O_register
)
1811 opcodep
[3] = exp
[2].X_add_number
;
1813 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 3,
1814 1, exp
+ 2, 0, BFD_RELOC_MMIX_REG_OR_BYTE
);
1816 else if (n_operands
== 2)
1818 if (exp
[0].X_op
== O_register
)
1819 opcodep
[2] = exp
[0].X_add_number
;
1821 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 2,
1822 1, exp
, 0, BFD_RELOC_MMIX_REG_OR_BYTE
);
1823 if (exp
[1].X_op
== O_register
)
1824 opcodep
[3] = exp
[1].X_add_number
;
1826 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 3,
1827 1, exp
+ 1, 0, BFD_RELOC_MMIX_REG_OR_BYTE
);
1831 as_bad (_("unsupported operands to %s: `%s'"),
1832 instruction
->name
, operands
);
1838 as_bad (_("invalid operands to opcode %s: `%s'"),
1839 instruction
->name
, operands
);
1844 case mmix_operands_resume
:
1845 if (n_operands
== 0 && ! mmix_gnu_syntax
)
1849 || exp
[0].X_op
== O_register
1850 || (exp
[0].X_op
== O_constant
1851 && (exp
[0].X_add_number
< 0
1852 || exp
[0].X_add_number
> 255)))
1854 as_bad (_("invalid operands to opcode %s: `%s'"),
1855 instruction
->name
, operands
);
1859 if (exp
[0].X_op
== O_constant
)
1860 opcodep
[3] = exp
[0].X_add_number
;
1862 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 3,
1863 1, exp
+ 0, 0, BFD_RELOC_8
);
1866 case mmix_operands_pushj
:
1867 /* All is done for PUSHJ already. */
1871 BAD_CASE (instruction
->operands
);
1875 /* For the benefit of insns that start with a digit, we assemble by way of
1876 tc_unrecognized_line too, through this function. */
1879 mmix_assemble_return_nonzero (str
)
1882 int last_error_count
= had_errors ();
1886 /* Normal instruction handling downcases, so we must too. */
1887 while (ISALNUM (*s2
))
1889 if (ISUPPER ((unsigned char) *s2
))
1890 *s2
= TOLOWER (*s2
);
1894 /* Cut the line for sake of the assembly. */
1895 for (s2
= str
; *s2
&& *s2
!= '\n'; s2
++)
1903 return had_errors () == last_error_count
;
1906 /* The PREFIX pseudo. */
1910 int unused ATTRIBUTE_UNUSED
;
1917 p
= input_line_pointer
;
1919 c
= get_symbol_end ();
1921 /* Reseting prefix? */
1922 if (*p
== ':' && p
[1] == 0)
1923 mmix_current_prefix
= NULL
;
1926 /* Put this prefix on the mmix symbols obstack. We could malloc and
1927 free it separately, but then we'd have to worry about that.
1928 People using up memory on prefixes have other problems. */
1929 obstack_grow (&mmix_sym_obstack
, p
, strlen (p
) + 1);
1930 p
= obstack_finish (&mmix_sym_obstack
);
1932 /* Accumulate prefixes, and strip a leading ':'. */
1933 if (mmix_current_prefix
!= NULL
|| *p
== ':')
1934 p
= mmix_prefix_name (p
);
1936 mmix_current_prefix
= p
;
1939 *input_line_pointer
= c
;
1941 mmix_handle_rest_of_empty_line ();
1944 /* We implement prefixes by using the tc_canonicalize_symbol_name hook,
1945 and store each prefixed name on a (separate) obstack. This means that
1946 the name is on the "notes" obstack in non-prefixed form and on the
1947 mmix_sym_obstack in prefixed form, but currently it is not worth
1948 rewriting the whole GAS symbol handling to improve "hooking" to avoid
1949 that. (It might be worth a rewrite for other reasons, though). */
1952 mmix_prefix_name (shortname
)
1955 if (*shortname
== ':')
1956 return shortname
+ 1;
1958 if (mmix_current_prefix
== NULL
)
1959 as_fatal (_("internal: mmix_prefix_name but empty prefix"));
1961 if (*shortname
== '$')
1964 obstack_grow (&mmix_sym_obstack
, mmix_current_prefix
,
1965 strlen (mmix_current_prefix
));
1966 obstack_grow (&mmix_sym_obstack
, shortname
, strlen (shortname
) + 1);
1967 return obstack_finish (&mmix_sym_obstack
);
1970 /* The GREG pseudo. At LABEL, we have the name of a symbol that we
1971 want to make a register symbol, and which should be initialized with
1972 the value in the expression at INPUT_LINE_POINTER (defaulting to 0).
1973 Either and (perhaps less meaningful) both may be missing. LABEL must
1974 be persistent, perhaps allocated on an obstack. */
1977 mmix_greg_internal (label
)
1980 expressionS
*expP
= &mmix_raw_gregs
[n_of_raw_gregs
].exp
;
1982 /* Don't set the section to register contents section before the
1983 expression has been parsed; it may refer to the current position. */
1986 /* FIXME: Check that no expression refers to the register contents
1987 section. May need to be done in elf64-mmix.c. */
1988 if (expP
->X_op
== O_absent
)
1990 /* Default to zero if the expression was absent. */
1991 expP
->X_op
= O_constant
;
1992 expP
->X_add_number
= 0;
1993 expP
->X_unsigned
= 0;
1994 expP
->X_add_symbol
= NULL
;
1995 expP
->X_op_symbol
= NULL
;
1998 /* We must handle prefixes here, as we save the labels and expressions
1999 to be output later. */
2000 mmix_raw_gregs
[n_of_raw_gregs
].label
2001 = mmix_current_prefix
== NULL
? label
: mmix_prefix_name (label
);
2003 if (n_of_raw_gregs
== MAX_GREGS
- 1)
2004 as_bad (_("too many GREG registers allocated (max %d)"), MAX_GREGS
);
2008 mmix_handle_rest_of_empty_line ();
2011 /* The ".greg label,expr" worker. */
2015 int unused ATTRIBUTE_UNUSED
;
2019 p
= input_line_pointer
;
2021 /* This will skip over what can be a symbol and zero out the next
2022 character, which we assume is a ',' or other meaningful delimiter.
2023 What comes after that is the initializer expression for the
2025 c
= get_symbol_end ();
2027 if (! is_end_of_line
[(unsigned char) c
])
2028 input_line_pointer
++;
2032 /* The label must be persistent; it's not used until after all input
2034 obstack_grow (&mmix_sym_obstack
, p
, strlen (p
) + 1);
2035 mmix_greg_internal (obstack_finish (&mmix_sym_obstack
));
2038 mmix_greg_internal (NULL
);
2041 /* The "BSPEC expr" worker. */
2045 int unused ATTRIBUTE_UNUSED
;
2049 char secname
[sizeof (MMIX_OTHER_SPEC_SECTION_PREFIX
) + 20]
2050 = MMIX_OTHER_SPEC_SECTION_PREFIX
;
2054 /* Get a constant expression which we can evaluate *now*. Supporting
2055 more complex (though assembly-time computable) expressions is
2056 feasible but Too Much Work for something of unknown usefulness like
2058 expsec
= expression (&exp
);
2059 mmix_handle_rest_of_empty_line ();
2061 /* Check that we don't have another BSPEC in progress. */
2064 as_bad (_("BSPEC already active. Nesting is not supported."));
2068 if (exp
.X_op
!= O_constant
2069 || expsec
!= absolute_section
2070 || exp
.X_add_number
< 0
2071 || exp
.X_add_number
> 65535)
2073 as_bad (_("invalid BSPEC expression"));
2074 exp
.X_add_number
= 0;
2077 n
= (int) exp
.X_add_number
;
2079 sprintf (secname
+ strlen (MMIX_OTHER_SPEC_SECTION_PREFIX
), "%d", n
);
2080 sec
= bfd_get_section_by_name (stdoutput
, secname
);
2083 /* We need a non-volatile name as it will be stored in the section
2085 char *newsecname
= xstrdup (secname
);
2086 sec
= bfd_make_section (stdoutput
, newsecname
);
2089 as_fatal (_("can't create section %s"), newsecname
);
2091 if (!bfd_set_section_flags (stdoutput
, sec
,
2092 bfd_get_section_flags (stdoutput
, sec
)
2094 as_fatal (_("can't set section flags for section %s"), newsecname
);
2097 /* Tell ELF about the pending section change. */
2098 obj_elf_section_change_hook ();
2099 subseg_set (sec
, 0);
2101 /* Save position for missing ESPEC. */
2102 as_where (&bspec_file
, &bspec_line
);
2107 /* The "ESPEC" worker. */
2111 int unused ATTRIBUTE_UNUSED
;
2113 /* First, check that we *do* have a BSPEC in progress. */
2116 as_bad (_("ESPEC without preceding BSPEC"));
2120 mmix_handle_rest_of_empty_line ();
2123 /* When we told ELF about the section change in s_bspec, it stored the
2124 previous section for us so we can get at it with the equivalent of a
2125 .previous pseudo. */
2126 obj_elf_previous (0);
2129 /* The " .local expr" and " local expr" worker. We make a BFD_MMIX_LOCAL
2130 relocation against the current position against the expression.
2131 Implementing this by means of contents in a section lost. */
2134 mmix_s_local (unused
)
2135 int unused ATTRIBUTE_UNUSED
;
2139 /* Don't set the section to register contents section before the
2140 expression has been parsed; it may refer to the current position in
2141 some contorted way. */
2144 if (exp
.X_op
== O_absent
)
2146 as_bad (_("missing local expression"));
2149 else if (exp
.X_op
== O_register
)
2151 /* fix_new_exp doesn't like O_register. Should be configurable.
2152 We're fine with a constant here, though. */
2153 exp
.X_op
= O_constant
;
2156 fix_new_exp (frag_now
, 0, 0, &exp
, 0, BFD_RELOC_MMIX_LOCAL
);
2157 mmix_handle_rest_of_empty_line ();
2160 /* Set fragP->fr_var to the initial guess of the size of a relaxable insn
2161 and return it. Sizes of other instructions are not known. This
2162 function may be called multiple times. */
2165 md_estimate_size_before_relax (fragP
, segment
)
2171 #define HANDLE_RELAXABLE(state) \
2172 case ENCODE_RELAX (state, STATE_UNDF): \
2173 if (fragP->fr_symbol != NULL \
2174 && S_GET_SEGMENT (fragP->fr_symbol) == segment \
2175 && !S_IS_WEAK (fragP->fr_symbol)) \
2177 /* The symbol lies in the same segment - a relaxable case. */ \
2179 = ENCODE_RELAX (state, STATE_ZERO); \
2183 switch (fragP
->fr_subtype
)
2185 HANDLE_RELAXABLE (STATE_GETA
);
2186 HANDLE_RELAXABLE (STATE_BCC
);
2187 HANDLE_RELAXABLE (STATE_PUSHJ
);
2188 HANDLE_RELAXABLE (STATE_JMP
);
2190 case ENCODE_RELAX (STATE_GETA
, STATE_ZERO
):
2191 case ENCODE_RELAX (STATE_BCC
, STATE_ZERO
):
2192 case ENCODE_RELAX (STATE_PUSHJ
, STATE_ZERO
):
2193 case ENCODE_RELAX (STATE_JMP
, STATE_ZERO
):
2194 /* When relaxing a section for the second time, we don't need to do
2195 anything except making sure that fr_var is set right. */
2198 case STATE_GREG_DEF
:
2199 length
= fragP
->tc_frag_data
!= NULL
? 0 : 8;
2200 fragP
->fr_var
= length
;
2202 /* Don't consult the relax_table; it isn't valid for this
2208 BAD_CASE (fragP
->fr_subtype
);
2211 length
= mmix_relax_table
[fragP
->fr_subtype
].rlx_length
;
2212 fragP
->fr_var
= length
;
2217 /* Turn a string in input_line_pointer into a floating point constant of type
2218 type, and store the appropriate bytes in *litP. The number of LITTLENUMS
2219 emitted is stored in *sizeP . An error message is returned, or NULL on
2223 md_atof (type
, litP
, sizeP
)
2229 LITTLENUM_TYPE words
[4];
2235 /* FIXME: Having 'f' in mmix_flt_chars (and here) makes it
2236 problematic to also have a forward reference in an expression.
2237 The testsuite wants it, and it's customary.
2238 We'll deal with the real problems when they come; we share the
2239 problem with most other ports. */
2249 return _("bad call to md_atof");
2252 t
= atof_ieee (input_line_pointer
, type
, words
);
2254 input_line_pointer
= t
;
2258 for (i
= 0; i
< prec
; i
++)
2260 md_number_to_chars (litP
, (valueT
) words
[i
], 2);
2266 /* Convert variable-sized frags into one or more fixups. */
2269 md_convert_frag (abfd
, sec
, fragP
)
2270 bfd
*abfd ATTRIBUTE_UNUSED
;
2271 segT sec ATTRIBUTE_UNUSED
;
2274 /* Pointer to first byte in variable-sized part of the frag. */
2277 /* Pointer to first opcode byte in frag. */
2280 /* Size in bytes of variable-sized part of frag. */
2281 int var_part_size
= 0;
2283 /* This is part of *fragP. It contains all information about addresses
2284 and offsets to varying parts. */
2286 unsigned long var_part_offset
;
2288 /* This is the frag for the opcode. It, rather than fragP, must be used
2289 when emitting a frag for the opcode. */
2290 fragS
*opc_fragP
= fragP
->tc_frag_data
;
2293 /* Where, in file space, does addr point? */
2294 bfd_vma target_address
;
2295 bfd_vma opcode_address
;
2297 know (fragP
->fr_type
== rs_machine_dependent
);
2299 var_part_offset
= fragP
->fr_fix
;
2300 var_partp
= fragP
->fr_literal
+ var_part_offset
;
2301 opcodep
= fragP
->fr_opcode
;
2303 symbolP
= fragP
->fr_symbol
;
2306 = ((symbolP
? S_GET_VALUE (symbolP
) : 0) + fragP
->fr_offset
);
2308 /* The opcode that would be extended is the last four "fixed" bytes. */
2309 opcode_address
= fragP
->fr_address
+ fragP
->fr_fix
- 4;
2311 switch (fragP
->fr_subtype
)
2313 case ENCODE_RELAX (STATE_GETA
, STATE_ZERO
):
2314 case ENCODE_RELAX (STATE_BCC
, STATE_ZERO
):
2315 case ENCODE_RELAX (STATE_PUSHJ
, STATE_ZERO
):
2316 mmix_set_geta_branch_offset (opcodep
, target_address
- opcode_address
);
2320 = fix_new (opc_fragP
, opcodep
- opc_fragP
->fr_literal
, 4,
2321 fragP
->fr_symbol
, fragP
->fr_offset
, 1,
2322 BFD_RELOC_MMIX_ADDR19
);
2323 COPY_FR_WHERE_TO_FX (fragP
, tmpfixP
);
2328 case ENCODE_RELAX (STATE_JMP
, STATE_ZERO
):
2329 mmix_set_jmp_offset (opcodep
, target_address
- opcode_address
);
2333 = fix_new (opc_fragP
, opcodep
- opc_fragP
->fr_literal
, 4,
2334 fragP
->fr_symbol
, fragP
->fr_offset
, 1,
2335 BFD_RELOC_MMIX_ADDR27
);
2336 COPY_FR_WHERE_TO_FX (fragP
, tmpfixP
);
2341 case STATE_GREG_DEF
:
2342 if (fragP
->tc_frag_data
== NULL
)
2344 /* We must initialize data that's supposed to be "fixed up" to
2345 avoid emitting garbage, because md_apply_fix3 won't do
2346 anything for undefined symbols. */
2347 md_number_to_chars (var_partp
, 0, 8);
2349 = fix_new (fragP
, var_partp
- fragP
->fr_literal
, 8,
2350 fragP
->fr_symbol
, fragP
->fr_offset
, 0, BFD_RELOC_64
);
2351 COPY_FR_WHERE_TO_FX (fragP
, tmpfixP
);
2352 mmix_gregs
[n_of_cooked_gregs
++] = tmpfixP
;
2359 #define HANDLE_MAX_RELOC(state, reloc) \
2360 case ENCODE_RELAX (state, STATE_MAX): \
2362 = mmix_relax_table[ENCODE_RELAX (state, STATE_MAX)].rlx_length; \
2363 mmix_fill_nops (var_partp, var_part_size / 4); \
2364 if (warn_on_expansion) \
2365 as_warn_where (fragP->fr_file, fragP->fr_line, \
2366 _("operand out of range, instruction expanded")); \
2367 tmpfixP = fix_new (fragP, var_partp - fragP->fr_literal - 4, 8, \
2368 fragP->fr_symbol, fragP->fr_offset, 1, reloc); \
2369 COPY_FR_WHERE_TO_FX (fragP, tmpfixP); \
2372 HANDLE_MAX_RELOC (STATE_GETA
, BFD_RELOC_MMIX_GETA
);
2373 HANDLE_MAX_RELOC (STATE_BCC
, BFD_RELOC_MMIX_CBRANCH
);
2374 HANDLE_MAX_RELOC (STATE_PUSHJ
, BFD_RELOC_MMIX_PUSHJ
);
2375 HANDLE_MAX_RELOC (STATE_JMP
, BFD_RELOC_MMIX_JMP
);
2378 BAD_CASE (fragP
->fr_subtype
);
2382 fragP
->fr_fix
+= var_part_size
;
2386 /* Applies the desired value to the specified location.
2387 Also sets up addends for RELA type relocations.
2388 Stolen from tc-mcore.c.
2390 Note that this function isn't called when linkrelax != 0. */
2393 md_apply_fix3 (fixP
, valP
, segment
)
2398 char *buf
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
2399 /* Note: use offsetT because it is signed, valueT is unsigned. */
2400 offsetT val
= (offsetT
) * valP
;
2402 = (fixP
->fx_addsy
== NULL
2403 ? absolute_section
: S_GET_SEGMENT (fixP
->fx_addsy
));
2405 /* If the fix is relative to a symbol which is not defined, or, (if
2406 pcrel), not in the same segment as the fix, we cannot resolve it
2408 if (fixP
->fx_addsy
!= NULL
2409 && (! S_IS_DEFINED (fixP
->fx_addsy
)
2410 || S_IS_WEAK (fixP
->fx_addsy
)
2411 || (fixP
->fx_pcrel
&& symsec
!= segment
)
2412 || (! fixP
->fx_pcrel
2413 && symsec
!= absolute_section
2414 && ((fixP
->fx_r_type
!= BFD_RELOC_MMIX_REG
2415 && fixP
->fx_r_type
!= BFD_RELOC_MMIX_REG_OR_BYTE
)
2416 || symsec
!= reg_section
))))
2421 else if (fixP
->fx_r_type
== BFD_RELOC_MMIX_LOCAL
2422 || fixP
->fx_r_type
== BFD_RELOC_VTABLE_INHERIT
2423 || fixP
->fx_r_type
== BFD_RELOC_VTABLE_ENTRY
)
2425 /* These are never "fixed". */
2430 /* We assume every other relocation is "fixed". */
2433 switch (fixP
->fx_r_type
)
2440 case BFD_RELOC_64_PCREL
:
2441 case BFD_RELOC_32_PCREL
:
2442 case BFD_RELOC_24_PCREL
:
2443 case BFD_RELOC_16_PCREL
:
2444 case BFD_RELOC_8_PCREL
:
2445 md_number_to_chars (buf
, val
, fixP
->fx_size
);
2448 case BFD_RELOC_MMIX_ADDR19
:
2451 /* This shouldn't happen. */
2452 BAD_CASE (fixP
->fx_r_type
);
2456 case BFD_RELOC_MMIX_GETA
:
2457 case BFD_RELOC_MMIX_CBRANCH
:
2458 case BFD_RELOC_MMIX_PUSHJ
:
2459 /* If this fixup is out of range, punt to the linker to emit an
2460 error. This should only happen with -no-expand. */
2461 if (val
< -(((offsetT
) 1 << 19)/2)
2462 || val
>= ((offsetT
) 1 << 19)/2 - 1
2465 if (warn_on_expansion
)
2466 as_warn_where (fixP
->fx_file
, fixP
->fx_line
,
2467 _("operand out of range"));
2471 mmix_set_geta_branch_offset (buf
, val
);
2474 case BFD_RELOC_MMIX_ADDR27
:
2477 /* This shouldn't happen. */
2478 BAD_CASE (fixP
->fx_r_type
);
2482 case BFD_RELOC_MMIX_JMP
:
2483 /* If this fixup is out of range, punt to the linker to emit an
2484 error. This should only happen with -no-expand. */
2485 if (val
< -(((offsetT
) 1 << 27)/2)
2486 || val
>= ((offsetT
) 1 << 27)/2 - 1
2489 if (warn_on_expansion
)
2490 as_warn_where (fixP
->fx_file
, fixP
->fx_line
,
2491 _("operand out of range"));
2495 mmix_set_jmp_offset (buf
, val
);
2498 case BFD_RELOC_MMIX_REG_OR_BYTE
:
2499 if (fixP
->fx_addsy
!= NULL
2500 && (S_GET_SEGMENT (fixP
->fx_addsy
) != reg_section
2501 || S_GET_VALUE (fixP
->fx_addsy
) > 255)
2502 && S_GET_SEGMENT (fixP
->fx_addsy
) != absolute_section
)
2504 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
2505 _("invalid operands"));
2506 /* We don't want this "symbol" appearing in output, because
2513 /* If this reloc is for a Z field, we need to adjust
2514 the opcode if we got a constant here.
2515 FIXME: Can we make this more robust? */
2517 if ((fixP
->fx_where
& 3) == 3
2518 && (fixP
->fx_addsy
== NULL
2519 || S_GET_SEGMENT (fixP
->fx_addsy
) == absolute_section
))
2520 buf
[-3] |= IMM_OFFSET_BIT
;
2523 case BFD_RELOC_MMIX_REG
:
2524 if (fixP
->fx_addsy
== NULL
2525 || S_GET_SEGMENT (fixP
->fx_addsy
) != reg_section
2526 || S_GET_VALUE (fixP
->fx_addsy
) > 255)
2528 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
2529 _("invalid operands"));
2536 case BFD_RELOC_MMIX_BASE_PLUS_OFFSET
:
2537 /* These are never "fixed". */
2541 case BFD_RELOC_MMIX_PUSHJ_1
:
2542 case BFD_RELOC_MMIX_PUSHJ_2
:
2543 case BFD_RELOC_MMIX_PUSHJ_3
:
2544 case BFD_RELOC_MMIX_CBRANCH_J
:
2545 case BFD_RELOC_MMIX_CBRANCH_1
:
2546 case BFD_RELOC_MMIX_CBRANCH_2
:
2547 case BFD_RELOC_MMIX_CBRANCH_3
:
2548 case BFD_RELOC_MMIX_GETA_1
:
2549 case BFD_RELOC_MMIX_GETA_2
:
2550 case BFD_RELOC_MMIX_GETA_3
:
2551 case BFD_RELOC_MMIX_JMP_1
:
2552 case BFD_RELOC_MMIX_JMP_2
:
2553 case BFD_RELOC_MMIX_JMP_3
:
2555 BAD_CASE (fixP
->fx_r_type
);
2560 /* Make sure that for completed fixups we have the value around for
2561 use by e.g. mmix_frob_file. */
2562 fixP
->fx_offset
= val
;
2565 /* A bsearch function for looking up a value against offsets for GREG
2569 cmp_greg_val_greg_symbol_fixes (p1
, p2
)
2573 offsetT val1
= *(offsetT
*) p1
;
2574 offsetT val2
= ((struct mmix_symbol_greg_fixes
*) p2
)->offs
;
2576 if (val1
>= val2
&& val1
< val2
+ 255)
2585 /* Generate a machine-dependent relocation. */
2588 tc_gen_reloc (section
, fixP
)
2589 asection
*section ATTRIBUTE_UNUSED
;
2594 + (fixP
->fx_addsy
!= NULL
2595 && !S_IS_WEAK (fixP
->fx_addsy
)
2596 && !S_IS_COMMON (fixP
->fx_addsy
)
2597 ? S_GET_VALUE (fixP
->fx_addsy
) : 0);
2599 bfd_reloc_code_real_type code
= BFD_RELOC_NONE
;
2600 char *buf
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
2601 symbolS
*addsy
= fixP
->fx_addsy
;
2602 asection
*addsec
= addsy
== NULL
? NULL
: S_GET_SEGMENT (addsy
);
2603 asymbol
*baddsy
= addsy
!= NULL
? symbol_get_bfdsym (addsy
) : NULL
;
2605 = val
- (baddsy
== NULL
|| S_IS_COMMON (addsy
) || S_IS_WEAK (addsy
)
2606 ? 0 : bfd_asymbol_value (baddsy
));
2608 /* A single " LOCAL expression" in the wrong section will not work when
2609 linking to MMO; relocations for zero-content sections are then
2610 ignored. Normally, relocations would modify section contents, and
2611 you'd never think or be able to do something like that. The
2612 relocation resulting from a LOCAL directive doesn't have an obvious
2613 and mandatory location. I can't figure out a way to do this better
2614 than just helping the user around this limitation here; hopefully the
2615 code using the local expression is around. Putting the LOCAL
2616 semantics in a relocation still seems right; a section didn't do. */
2617 if (bfd_section_size (section
->owner
, section
) == 0)
2619 (fixP
->fx_file
, fixP
->fx_line
,
2620 fixP
->fx_r_type
== BFD_RELOC_MMIX_LOCAL
2621 /* The BFD_RELOC_MMIX_LOCAL-specific message is supposed to be
2622 user-friendly, though a little bit non-substantial. */
2623 ? _("directive LOCAL must be placed in code or data")
2624 : _("internal confusion: relocation in a section without contents"));
2626 /* FIXME: Range tests for all these. */
2627 switch (fixP
->fx_r_type
)
2634 code
= fixP
->fx_r_type
;
2636 if (addsy
== NULL
|| bfd_is_abs_section (addsec
))
2638 /* Resolve this reloc now, as md_apply_fix3 would have done (not
2639 called if -linkrelax). There is no point in keeping a reloc
2640 to an absolute symbol. No reloc that is subject to
2641 relaxation must be to an absolute symbol; difference
2642 involving symbols in a specific section must be signalled as
2643 an error if the relaxing cannot be expressed; having a reloc
2644 to the resolved (now absolute) value does not help. */
2645 md_number_to_chars (buf
, val
, fixP
->fx_size
);
2650 case BFD_RELOC_64_PCREL
:
2651 case BFD_RELOC_32_PCREL
:
2652 case BFD_RELOC_24_PCREL
:
2653 case BFD_RELOC_16_PCREL
:
2654 case BFD_RELOC_8_PCREL
:
2655 case BFD_RELOC_MMIX_LOCAL
:
2656 case BFD_RELOC_VTABLE_INHERIT
:
2657 case BFD_RELOC_VTABLE_ENTRY
:
2658 case BFD_RELOC_MMIX_GETA
:
2659 case BFD_RELOC_MMIX_GETA_1
:
2660 case BFD_RELOC_MMIX_GETA_2
:
2661 case BFD_RELOC_MMIX_GETA_3
:
2662 case BFD_RELOC_MMIX_CBRANCH
:
2663 case BFD_RELOC_MMIX_CBRANCH_J
:
2664 case BFD_RELOC_MMIX_CBRANCH_1
:
2665 case BFD_RELOC_MMIX_CBRANCH_2
:
2666 case BFD_RELOC_MMIX_CBRANCH_3
:
2667 case BFD_RELOC_MMIX_PUSHJ
:
2668 case BFD_RELOC_MMIX_PUSHJ_1
:
2669 case BFD_RELOC_MMIX_PUSHJ_2
:
2670 case BFD_RELOC_MMIX_PUSHJ_3
:
2671 case BFD_RELOC_MMIX_JMP
:
2672 case BFD_RELOC_MMIX_JMP_1
:
2673 case BFD_RELOC_MMIX_JMP_2
:
2674 case BFD_RELOC_MMIX_JMP_3
:
2675 case BFD_RELOC_MMIX_ADDR19
:
2676 case BFD_RELOC_MMIX_ADDR27
:
2677 code
= fixP
->fx_r_type
;
2680 case BFD_RELOC_MMIX_REG_OR_BYTE
:
2681 /* If we have this kind of relocation to an unknown symbol or to the
2682 register contents section (that is, to a register), then we can't
2683 resolve the relocation here. */
2685 && (bfd_is_und_section (addsec
)
2686 || strcmp (bfd_get_section_name (addsec
->owner
, addsec
),
2687 MMIX_REG_CONTENTS_SECTION_NAME
) == 0))
2689 code
= fixP
->fx_r_type
;
2693 /* If the relocation is not to the register section or to the
2694 absolute section (a numeric value), then we have an error. */
2696 && (S_GET_SEGMENT (addsy
) != real_reg_section
2699 && ! bfd_is_abs_section (addsec
))
2702 /* Set the "immediate" bit of the insn if this relocation is to Z
2703 field when the value is a numeric value, i.e. not a register. */
2704 if ((fixP
->fx_where
& 3) == 3
2705 && (addsy
== NULL
|| bfd_is_abs_section (addsec
)))
2706 buf
[-3] |= IMM_OFFSET_BIT
;
2711 case BFD_RELOC_MMIX_BASE_PLUS_OFFSET
:
2713 && strcmp (bfd_get_section_name (addsec
->owner
, addsec
),
2714 MMIX_REG_CONTENTS_SECTION_NAME
) == 0)
2716 /* This changed into a register; the relocation is for the
2717 register-contents section. The constant part remains zero. */
2718 code
= BFD_RELOC_MMIX_REG
;
2722 /* If we've found out that this was indeed a register, then replace
2723 with the register number. The constant part is already zero.
2725 If we encounter any other defined symbol, then we must find a
2726 suitable register and emit a reloc. */
2727 if (addsy
== NULL
|| addsec
!= real_reg_section
)
2729 struct mmix_symbol_gregs
*gregs
;
2730 struct mmix_symbol_greg_fixes
*fix
;
2732 if (S_IS_DEFINED (addsy
)
2733 && !bfd_is_com_section (addsec
)
2734 && !S_IS_WEAK (addsy
))
2736 if (! symbol_section_p (addsy
) && ! bfd_is_abs_section (addsec
))
2737 as_fatal (_("internal: BFD_RELOC_MMIX_BASE_PLUS_OFFSET not resolved to section"));
2739 /* If this is an absolute symbol sufficiently near
2740 lowest_data_loc, then we canonicalize on the data
2741 section. Note that val is signed here; we may subtract
2742 lowest_data_loc which is unsigned. Careful with those
2744 if (lowest_data_loc
!= (bfd_vma
) -1
2745 && (bfd_vma
) val
+ 256 > lowest_data_loc
2746 && bfd_is_abs_section (addsec
))
2748 val
-= (offsetT
) lowest_data_loc
;
2749 addsy
= section_symbol (data_section
);
2751 /* Likewise text section. */
2752 else if (lowest_text_loc
!= (bfd_vma
) -1
2753 && (bfd_vma
) val
+ 256 > lowest_text_loc
2754 && bfd_is_abs_section (addsec
))
2756 val
-= (offsetT
) lowest_text_loc
;
2757 addsy
= section_symbol (text_section
);
2761 gregs
= *symbol_get_tc (addsy
);
2763 /* If that symbol does not have any associated GREG definitions,
2764 we can't do anything. */
2766 || (fix
= bsearch (&val
, gregs
->greg_fixes
, gregs
->n_gregs
,
2767 sizeof (gregs
->greg_fixes
[0]),
2768 cmp_greg_val_greg_symbol_fixes
)) == NULL
2769 /* The register must not point *after* the address we want. */
2771 /* Neither must the register point more than 255 bytes
2772 before the address we want. */
2773 || fix
->offs
+ 255 < val
)
2775 /* We can either let the linker allocate GREGs
2776 automatically, or emit an error. */
2777 if (allocate_undefined_gregs_in_linker
)
2779 /* The values in baddsy and addend are right. */
2780 code
= fixP
->fx_r_type
;
2784 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
2785 _("no suitable GREG definition for operands"));
2790 /* Transform the base-plus-offset reloc for the actual area
2791 to a reloc for the register with the address of the area.
2792 Put addend for register in Z operand. */
2793 buf
[1] = val
- fix
->offs
;
2794 code
= BFD_RELOC_MMIX_REG
;
2796 = (bfd_get_section_by_name (stdoutput
,
2797 MMIX_REG_CONTENTS_SECTION_NAME
)
2800 addend
= fix
->fix
->fx_frag
->fr_address
+ fix
->fix
->fx_where
;
2803 else if (S_GET_VALUE (addsy
) > 255)
2804 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
2805 _("invalid operands"));
2813 case BFD_RELOC_MMIX_REG
:
2815 && (bfd_is_und_section (addsec
)
2816 || strcmp (bfd_get_section_name (addsec
->owner
, addsec
),
2817 MMIX_REG_CONTENTS_SECTION_NAME
) == 0))
2819 code
= fixP
->fx_r_type
;
2824 && (addsec
!= real_reg_section
2827 && ! bfd_is_und_section (addsec
))
2828 /* Drop through to error message. */
2837 /* The others are supposed to be handled by md_apply_fix3.
2838 FIXME: ... which isn't called when -linkrelax. Move over
2839 md_apply_fix3 code here for everything reasonable. */
2843 (fixP
->fx_file
, fixP
->fx_line
,
2844 _("operands were not reducible at assembly-time"));
2846 /* Unmark this symbol as used in a reloc, so we don't bump into a BFD
2847 assert when trying to output reg_section. FIXME: A gas bug. */
2848 fixP
->fx_addsy
= NULL
;
2852 relP
= (arelent
*) xmalloc (sizeof (arelent
));
2854 relP
->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
2855 *relP
->sym_ptr_ptr
= baddsy
;
2856 relP
->address
= fixP
->fx_frag
->fr_address
+ fixP
->fx_where
;
2858 relP
->addend
= addend
;
2860 /* If this had been a.out, we would have had a kludge for weak symbols
2863 relP
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
2868 name
= S_GET_NAME (addsy
);
2870 name
= _("<unknown>");
2871 as_fatal (_("cannot generate relocation type for symbol %s, code %s"),
2872 name
, bfd_get_reloc_code_name (code
));
2878 /* Do some reformatting of a line. FIXME: We could transform a mmixal
2879 line into traditional (GNU?) format, unless #NO_APP, and get rid of all
2880 ugly labels_without_colons etc. */
2883 mmix_handle_mmixal ()
2885 char *s0
= input_line_pointer
;
2890 if (pending_label
!= NULL
)
2891 as_fatal (_("internal: unhandled label %s"), pending_label
);
2893 if (mmix_gnu_syntax
)
2896 /* If the first character is a '.', then it's a pseudodirective, not a
2897 label. Make GAS not handle label-without-colon on this line. We
2898 also don't do mmixal-specific stuff on this line. */
2899 if (input_line_pointer
[0] == '.')
2901 label_without_colon_this_line
= 0;
2905 /* Don't handle empty lines here. */
2908 if (*s0
== 0 || is_end_of_line
[(unsigned int) *s0
])
2911 if (! ISSPACE (*s0
))
2917 /* If we're on a line with a label, check if it's a mmixal fb-label.
2918 Save an indicator and skip the label; it must be set only after all
2919 fb-labels of expressions are evaluated. */
2920 if (ISDIGIT (input_line_pointer
[0])
2921 && input_line_pointer
[1] == 'H'
2922 && ISSPACE (input_line_pointer
[2]))
2925 current_fb_label
= input_line_pointer
[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. */
2930 input_line_pointer
[1] = input_line_pointer
[-1];
2931 input_line_pointer
+= 2;
2933 s
= input_line_pointer
;
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
])
2943 as_where (&name
, &line
);
2944 as_bad_where (name
, line
+ 1,
2945 _("[0-9]H labels may not appear alone on a line"));
2946 current_fb_label
= -1;
2952 as_where (&name
, &line
);
2953 as_bad_where (name
, line
+ 1,
2954 _("[0-9]H labels do not mix with dot-pseudos"));
2955 current_fb_label
= -1;
2960 current_fb_label
= -1;
2961 if (is_name_beginner (input_line_pointer
[0]))
2962 label
= input_line_pointer
;
2965 s0
= input_line_pointer
;
2966 /* Skip over label. */
2967 while (*s0
&& is_part_of_name (*s0
))
2970 /* Remove trailing ":" off labels, as they'd otherwise be considered
2971 part of the name. But don't do it for local labels. */
2972 if (s0
!= input_line_pointer
&& s0
[-1] == ':'
2973 && (s0
- 2 != input_line_pointer
2974 || ! ISDIGIT (s0
[-2])))
2976 else if (label
!= NULL
)
2978 /* For labels that don't end in ":", we save it so we can later give
2979 it the same alignment and address as the associated instruction. */
2981 /* Make room for the label including the ending nul. */
2982 int len_0
= s0
- label
+ 1;
2984 /* Save this label on the MMIX symbol obstack. Saving it on an
2985 obstack is needless for "IS"-pseudos, but it's harmless and we
2986 avoid a little code-cluttering. */
2987 obstack_grow (&mmix_sym_obstack
, label
, len_0
);
2988 pending_label
= obstack_finish (&mmix_sym_obstack
);
2989 pending_label
[len_0
- 1] = 0;
2992 while (*s0
&& ISSPACE (*s0
) && ! is_end_of_line
[(unsigned int) *s0
])
2995 if (pending_label
!= NULL
&& is_end_of_line
[(unsigned int) *s0
])
2996 /* Whoops, this was actually a lone label on a line. Like :-ended
2997 labels, we don't attach such labels to the next instruction or
2999 pending_label
= NULL
;
3001 /* Find local labels of operands. Look for "[0-9][FB]" where the
3002 characters before and after are not part of words. Break if a single
3003 or double quote is seen anywhere. It means we can't have local
3004 labels as part of list with mixed quoted and unquoted members for
3005 mmixal compatibility but we can't have it all. For the moment.
3006 Replace the '<N>B' or '<N>F' with MAGIC_FB_BACKWARD_CHAR<N> and
3007 MAGIC_FB_FORWARD_CHAR<N> respectively. */
3009 /* First make sure we don't have any of the magic characters on the line
3010 appearing as input. */
3015 if (is_end_of_line
[(unsigned int) c
])
3017 if (c
== MAGIC_FB_BACKWARD_CHAR
|| c
== MAGIC_FB_FORWARD_CHAR
)
3018 as_bad (_("invalid characters in input"));
3021 /* Scan again, this time looking for ';' after operands. */
3024 /* Skip the insn. */
3028 && ! is_end_of_line
[(unsigned int) *s
])
3031 /* Skip the spaces after the insn. */
3035 && ! is_end_of_line
[(unsigned int) *s
])
3038 /* Skip the operands. While doing this, replace [0-9][BF] with
3039 (MAGIC_FB_BACKWARD_CHAR|MAGIC_FB_FORWARD_CHAR)[0-9]. */
3040 while ((c
= *s
) != 0
3043 && ! is_end_of_line
[(unsigned int) c
])
3049 /* FIXME: Test-case for semi-colon in string. */
3052 && (! is_end_of_line
[(unsigned int) *s
] || *s
== ';'))
3058 else if (ISDIGIT (c
))
3060 if ((s
[1] != 'B' && s
[1] != 'F')
3061 || is_part_of_name (s
[-1])
3062 || is_part_of_name (s
[2]))
3067 ? MAGIC_FB_BACKWARD_CHAR
: MAGIC_FB_FORWARD_CHAR
);
3075 /* Skip any spaces after the operands. */
3079 && !is_end_of_line
[(unsigned int) *s
])
3082 /* If we're now looking at a semi-colon, then it's an end-of-line
3084 mmix_next_semicolon_is_eoln
= (*s
== ';');
3086 /* Make IS into an EQU by replacing it with "= ". Only match upper-case
3087 though; let lower-case be a syntax error. */
3089 if (s
[0] == 'I' && s
[1] == 'S' && ISSPACE (s
[2]))
3094 /* Since labels can start without ":", we have to handle "X IS 42"
3095 in full here, or "X" will be parsed as a label to be set at ".". */
3096 input_line_pointer
= s
;
3098 /* Right after this function ends, line numbers will be bumped if
3099 input_line_pointer[-1] = '\n'. We want accurate line numbers for
3100 the equals call, so we bump them before the call, and make sure
3101 they aren't bumped afterwards. */
3102 bump_line_counters ();
3104 /* A fb-label is valid as an IS-label. */
3105 if (current_fb_label
>= 0)
3109 /* We need to save this name on our symbol obstack, since the
3110 string we got in fb_label_name is volatile and will change
3111 with every call to fb_label_name, like those resulting from
3112 parsing the IS-operand. */
3113 fb_name
= fb_label_name (current_fb_label
, 1);
3114 obstack_grow (&mmix_sym_obstack
, fb_name
, strlen (fb_name
) + 1);
3115 equals (obstack_finish (&mmix_sym_obstack
), 0);
3116 fb_label_instance_inc (current_fb_label
);
3117 current_fb_label
= -1;
3121 if (pending_label
== NULL
)
3122 as_bad (_("empty label field for IS"));
3124 equals (pending_label
, 0);
3125 pending_label
= NULL
;
3128 /* For mmixal, we can have comments without a comment-start
3130 mmix_handle_rest_of_empty_line ();
3131 input_line_pointer
--;
3133 input_line_pointer
[-1] = ' ';
3135 else if (s
[0] == 'G'
3137 && strncmp (s
, "GREG", 4) == 0
3138 && (ISSPACE (s
[4]) || is_end_of_line
[(unsigned char) s
[4]]))
3140 input_line_pointer
= s
+ 4;
3142 /* Right after this function ends, line numbers will be bumped if
3143 input_line_pointer[-1] = '\n'. We want accurate line numbers for
3144 the s_greg call, so we bump them before the call, and make sure
3145 they aren't bumped afterwards. */
3146 bump_line_counters ();
3148 /* A fb-label is valid as a GREG-label. */
3149 if (current_fb_label
>= 0)
3153 /* We need to save this name on our symbol obstack, since the
3154 string we got in fb_label_name is volatile and will change
3155 with every call to fb_label_name, like those resulting from
3156 parsing the IS-operand. */
3157 fb_name
= fb_label_name (current_fb_label
, 1);
3159 /* Make sure we save the canonical name and don't get bitten by
3161 obstack_1grow (&mmix_sym_obstack
, ':');
3162 obstack_grow (&mmix_sym_obstack
, fb_name
, strlen (fb_name
) + 1);
3163 mmix_greg_internal (obstack_finish (&mmix_sym_obstack
));
3164 fb_label_instance_inc (current_fb_label
);
3165 current_fb_label
= -1;
3168 mmix_greg_internal (pending_label
);
3170 /* Back up before the end-of-line marker that was skipped in
3171 mmix_greg_internal. */
3172 input_line_pointer
--;
3173 input_line_pointer
[-1] = ' ';
3175 pending_label
= NULL
;
3177 else if (pending_label
!= NULL
)
3179 input_line_pointer
+= strlen (pending_label
);
3181 /* See comment above about getting line numbers bumped. */
3182 input_line_pointer
[-1] = '\n';
3186 /* Give the value of an fb-label rewritten as in mmix_handle_mmixal, when
3187 parsing an expression.
3189 On valid calls, input_line_pointer points at a MAGIC_FB_BACKWARD_CHAR
3190 or MAGIC_FB_BACKWARD_CHAR, followed by an ascii digit for the label.
3191 We fill in the label as an expression. */
3194 mmix_fb_label (expP
)
3198 char *fb_internal_name
;
3200 /* This doesn't happen when not using mmixal syntax. */
3202 || (input_line_pointer
[0] != MAGIC_FB_BACKWARD_CHAR
3203 && input_line_pointer
[0] != MAGIC_FB_FORWARD_CHAR
))
3206 /* The current backward reference has augmentation 0. A forward
3207 reference has augmentation 1, unless it's the same as a fb-label on
3208 _this_ line, in which case we add one more so we don't refer to it.
3209 This is the semantics of mmixal; it differs to that of common
3210 fb-labels which refer to a here-label on the current line as a
3211 backward reference. */
3213 = fb_label_name (input_line_pointer
[1] - '0',
3214 (input_line_pointer
[0] == MAGIC_FB_FORWARD_CHAR
? 1 : 0)
3215 + ((input_line_pointer
[1] - '0' == current_fb_label
3216 && input_line_pointer
[0] == MAGIC_FB_FORWARD_CHAR
)
3219 input_line_pointer
+= 2;
3220 sym
= symbol_find_or_make (fb_internal_name
);
3222 /* We don't have to clean up unrelated fields here; we just do what the
3223 expr machinery does, but *not* just what it does for [0-9][fb], since
3224 we need to treat those as ordinary symbols sometimes; see testcases
3225 err-byte2.s and fb-2.s. */
3226 if (S_GET_SEGMENT (sym
) == absolute_section
)
3228 expP
->X_op
= O_constant
;
3229 expP
->X_add_number
= S_GET_VALUE (sym
);
3233 expP
->X_op
= O_symbol
;
3234 expP
->X_add_symbol
= sym
;
3235 expP
->X_add_number
= 0;
3239 /* See whether we need to force a relocation into the output file.
3240 This is used to force out switch and PC relative relocations when
3244 mmix_force_relocation (fixP
)
3247 if (fixP
->fx_r_type
== BFD_RELOC_MMIX_LOCAL
3248 || fixP
->fx_r_type
== BFD_RELOC_VTABLE_INHERIT
3249 || fixP
->fx_r_type
== BFD_RELOC_VTABLE_ENTRY
3250 || fixP
->fx_r_type
== BFD_RELOC_MMIX_BASE_PLUS_OFFSET
)
3256 /* All our pcrel relocations are must-keep. Note that md_apply_fix3 is
3257 called *after* this, and will handle getting rid of the presumed
3258 reloc; a relocation isn't *forced* other than to be handled by
3259 md_apply_fix3 (or tc_gen_reloc if linkrelax). */
3263 return S_FORCE_RELOC (fixP
->fx_addsy
);
3266 /* The location from which a PC relative jump should be calculated,
3267 given a PC relative reloc. */
3270 md_pcrel_from_section (fixP
, sec
)
3274 if (fixP
->fx_addsy
!= (symbolS
*) NULL
3275 && (! S_IS_DEFINED (fixP
->fx_addsy
)
3276 || S_GET_SEGMENT (fixP
->fx_addsy
) != sec
))
3278 /* The symbol is undefined (or is defined but not in this section).
3279 Let the linker figure it out. */
3283 return (fixP
->fx_frag
->fr_address
+ fixP
->fx_where
);
3286 /* Adjust the symbol table. We make reg_section relative to the real
3287 register section. */
3290 mmix_adjust_symtab ()
3293 symbolS
*regsec
= section_symbol (reg_section
);
3295 for (sym
= symbol_rootP
; sym
!= NULL
; sym
= symbol_next (sym
))
3296 if (S_GET_SEGMENT (sym
) == reg_section
)
3300 if (S_IS_EXTERN (sym
) || symbol_used_in_reloc_p (sym
))
3302 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
3305 /* Change section to the *real* register section, so it gets
3306 proper treatment when writing it out. Only do this for
3307 global symbols. This also means we don't have to check for
3309 S_SET_SEGMENT (sym
, real_reg_section
);
3313 /* This is the expansion of LABELS_WITHOUT_COLONS.
3314 We let md_start_line_hook tweak label_without_colon_this_line, and then
3315 this function returns the tweaked value, and sets it to 1 for the next
3316 line. FIXME: Very, very brittle. Not sure it works the way I
3317 thought at the time I first wrote this. */
3320 mmix_label_without_colon_this_line ()
3322 int retval
= label_without_colon_this_line
;
3324 if (! mmix_gnu_syntax
)
3325 label_without_colon_this_line
= 1;
3330 /* This is the expansion of md_relax_frag. We go through the ordinary
3331 relax table function except when the frag is for a GREG. Then we have
3332 to check whether there's another GREG by the same value that we can
3336 mmix_md_relax_frag (seg
, fragP
, stretch
)
3341 if (fragP
->fr_subtype
!= STATE_GREG_DEF
3342 && fragP
->fr_subtype
!= STATE_GREG_UNDF
)
3343 return relax_frag (seg
, fragP
, stretch
);
3345 /* If we're defined, we don't grow. */
3346 if (fragP
->fr_subtype
== STATE_GREG_DEF
)
3349 as_fatal (_("internal: unexpected relax type %d:%d"),
3350 fragP
->fr_type
, fragP
->fr_subtype
);
3354 /* Various things we punt until all input is seen. */
3363 /* The first frag of GREG:s going into the register contents section. */
3364 fragS
*mmix_reg_contents_frags
= NULL
;
3366 /* Reset prefix. All labels reachable at this point must be
3368 mmix_current_prefix
= NULL
;
3371 as_bad_where (bspec_file
, bspec_line
, _("BSPEC without ESPEC."));
3373 /* Emit the low LOC setting of .text. */
3374 if (text_has_contents
&& lowest_text_loc
!= (bfd_vma
) -1)
3377 char locsymbol
[sizeof (":") - 1
3378 + sizeof (MMIX_LOC_SECTION_START_SYMBOL_PREFIX
) - 1
3379 + sizeof (".text")];
3381 /* An exercise in non-ISO-C-ness, this one. */
3382 sprintf (locsymbol
, ":%s%s", MMIX_LOC_SECTION_START_SYMBOL_PREFIX
,
3385 = symbol_new (locsymbol
, absolute_section
, lowest_text_loc
,
3386 &zero_address_frag
);
3387 S_SET_EXTERNAL (symbolP
);
3391 if (data_has_contents
&& lowest_data_loc
!= (bfd_vma
) -1)
3394 char locsymbol
[sizeof (":") - 1
3395 + sizeof (MMIX_LOC_SECTION_START_SYMBOL_PREFIX
) - 1
3396 + sizeof (".data")];
3398 sprintf (locsymbol
, ":%s%s", MMIX_LOC_SECTION_START_SYMBOL_PREFIX
,
3401 = symbol_new (locsymbol
, absolute_section
, lowest_data_loc
,
3402 &zero_address_frag
);
3403 S_SET_EXTERNAL (symbolP
);
3406 /* Unless GNU syntax mode, set "Main" to be a function, so the
3407 disassembler doesn't get confused when we write truly
3408 mmixal-compatible code (and don't use .type). Similarly set it
3409 global (regardless of -globalize-symbols), so the linker sees it as
3410 the start symbol in ELF mode. */
3411 mainsym
= symbol_find (MMIX_START_SYMBOL_NAME
);
3412 if (mainsym
!= NULL
&& ! mmix_gnu_syntax
)
3414 symbol_get_bfdsym (mainsym
)->flags
|= BSF_FUNCTION
;
3415 S_SET_EXTERNAL (mainsym
);
3418 if (n_of_raw_gregs
!= 0)
3420 /* Emit GREGs. They are collected in order of appearance, but must
3421 be emitted in opposite order to both have section address regno*8
3422 and the same allocation order (within a file) as mmixal. */
3423 segT this_segment
= now_seg
;
3424 subsegT this_subsegment
= now_subseg
;
3426 = bfd_make_section_old_way (stdoutput
,
3427 MMIX_REG_CONTENTS_SECTION_NAME
);
3428 subseg_set (regsec
, 0);
3430 /* Finally emit the initialization-value. Emit a variable frag, which
3431 we'll fix in md_estimate_size_before_relax. We set the initializer
3432 for the tc_frag_data field to NULL, so we can use that field for
3433 relaxation purposes. */
3434 mmix_opcode_frag
= NULL
;
3437 mmix_reg_contents_frags
= frag_now
;
3439 for (i
= n_of_raw_gregs
- 1; i
>= 0; i
--)
3441 if (mmix_raw_gregs
[i
].label
!= NULL
)
3442 /* There's a symbol. Let it refer to this location in the
3443 register contents section. The symbol must be globalized
3445 colon (mmix_raw_gregs
[i
].label
);
3447 frag_var (rs_machine_dependent
, 8, 0, STATE_GREG_UNDF
,
3448 make_expr_symbol (&mmix_raw_gregs
[i
].exp
), 0, NULL
);
3451 subseg_set (this_segment
, this_subsegment
);
3454 /* Iterate over frags resulting from GREGs and move those that evidently
3455 have the same value together and point one to another.
3457 This works in time O(N^2) but since the upper bound for non-error use
3458 is 223, it's best to keep this simpler algorithm. */
3459 for (fragP
= mmix_reg_contents_frags
; fragP
!= NULL
; fragP
= fragP
->fr_next
)
3466 symbolS
*symbolP
= fragP
->fr_symbol
;
3468 if (fragP
->fr_type
!= rs_machine_dependent
3469 || fragP
->fr_subtype
!= STATE_GREG_UNDF
)
3472 /* Whatever the outcome, we will have this GREG judged merged or
3473 non-merged. Since the tc_frag_data is NULL at this point, we
3474 default to non-merged. */
3475 fragP
->fr_subtype
= STATE_GREG_DEF
;
3477 /* If we're not supposed to merge GREG definitions, then just don't
3478 look for equivalents. */
3482 osymval
= (offsetT
) S_GET_VALUE (symbolP
);
3483 osymfrag
= symbol_get_frag (symbolP
);
3485 /* If the symbol isn't defined, we can't say that another symbol
3486 equals this frag, then. FIXME: We can look at the "deepest"
3487 defined name; if a = c and b = c then obviously a == b. */
3488 if (! S_IS_DEFINED (symbolP
))
3491 oexpP
= symbol_get_value_expression (fragP
->fr_symbol
);
3493 /* If the initialization value is zero, then we must not merge them. */
3494 if (oexpP
->X_op
== O_constant
&& osymval
== 0)
3497 /* Iterate through the frags downward this one. If we find one that
3498 has the same non-zero value, move it to after this one and point
3499 to it as the equivalent. */
3500 for (fpp
= &fragP
->fr_next
; *fpp
!= NULL
; fpp
= &fpp
[0]->fr_next
)
3504 if (fp
->fr_type
!= rs_machine_dependent
3505 || fp
->fr_subtype
!= STATE_GREG_UNDF
)
3508 /* Calling S_GET_VALUE may simplify the symbol, changing from
3509 expr_section etc. so call it first. */
3510 if ((offsetT
) S_GET_VALUE (fp
->fr_symbol
) == osymval
3511 && symbol_get_frag (fp
->fr_symbol
) == osymfrag
)
3513 /* Move the frag links so the one we found equivalent comes
3514 after the current one, carefully considering that
3515 sometimes fpp == &fragP->fr_next and the moves must be a
3518 fp
->fr_next
= fragP
->fr_next
;
3519 fragP
->fr_next
= fp
;
3525 fragP
->tc_frag_data
= fp
;
3529 /* qsort function for mmix_symbol_gregs. */
3532 cmp_greg_symbol_fixes (parg
, qarg
)
3536 const struct mmix_symbol_greg_fixes
*p
3537 = (const struct mmix_symbol_greg_fixes
*) parg
;
3538 const struct mmix_symbol_greg_fixes
*q
3539 = (const struct mmix_symbol_greg_fixes
*) qarg
;
3541 return p
->offs
> q
->offs
? 1 : p
->offs
< q
->offs
? -1 : 0;
3544 /* Collect GREG definitions from mmix_gregs and hang them as lists sorted
3545 on increasing offsets onto each section symbol or undefined symbol.
3547 Also, remove the register convenience section so it doesn't get output
3548 as an ELF section. */
3554 struct mmix_symbol_gregs
*all_greg_symbols
[MAX_GREGS
];
3555 int n_greg_symbols
= 0;
3557 /* Collect all greg fixups and decorate each corresponding symbol with
3558 the greg fixups for it. */
3559 for (i
= 0; i
< n_of_cooked_gregs
; i
++)
3563 struct mmix_symbol_gregs
*gregs
;
3566 fixP
= mmix_gregs
[i
];
3567 know (fixP
->fx_r_type
== BFD_RELOC_64
);
3569 /* This case isn't doable in general anyway, methinks. */
3570 if (fixP
->fx_subsy
!= NULL
)
3572 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3573 _("GREG expression too complicated"));
3577 sym
= fixP
->fx_addsy
;
3578 offs
= (offsetT
) fixP
->fx_offset
;
3580 /* If the symbol is defined, then it must be resolved to a section
3581 symbol at this time, or else we don't know how to handle it. */
3582 if (S_IS_DEFINED (sym
)
3583 && !bfd_is_com_section (S_GET_SEGMENT (sym
))
3584 && !S_IS_WEAK (sym
))
3586 if (! symbol_section_p (sym
)
3587 && ! bfd_is_abs_section (S_GET_SEGMENT (sym
)))
3588 as_fatal (_("internal: GREG expression not resolved to section"));
3590 offs
+= S_GET_VALUE (sym
);
3593 /* If this is an absolute symbol sufficiently near lowest_data_loc,
3594 then we canonicalize on the data section. Note that offs is
3595 signed here; we may subtract lowest_data_loc which is unsigned.
3596 Careful with those comparisons. */
3597 if (lowest_data_loc
!= (bfd_vma
) -1
3598 && (bfd_vma
) offs
+ 256 > lowest_data_loc
3599 && bfd_is_abs_section (S_GET_SEGMENT (sym
)))
3601 offs
-= (offsetT
) lowest_data_loc
;
3602 sym
= section_symbol (data_section
);
3604 /* Likewise text section. */
3605 else if (lowest_text_loc
!= (bfd_vma
) -1
3606 && (bfd_vma
) offs
+ 256 > lowest_text_loc
3607 && bfd_is_abs_section (S_GET_SEGMENT (sym
)))
3609 offs
-= (offsetT
) lowest_text_loc
;
3610 sym
= section_symbol (text_section
);
3613 gregs
= *symbol_get_tc (sym
);
3617 gregs
= xmalloc (sizeof (*gregs
));
3619 symbol_set_tc (sym
, &gregs
);
3620 all_greg_symbols
[n_greg_symbols
++] = gregs
;
3623 gregs
->greg_fixes
[gregs
->n_gregs
].fix
= fixP
;
3624 gregs
->greg_fixes
[gregs
->n_gregs
++].offs
= offs
;
3627 /* For each symbol having a GREG definition, sort those definitions on
3629 for (i
= 0; i
< n_greg_symbols
; i
++)
3630 qsort (all_greg_symbols
[i
]->greg_fixes
, all_greg_symbols
[i
]->n_gregs
,
3631 sizeof (all_greg_symbols
[i
]->greg_fixes
[0]), cmp_greg_symbol_fixes
);
3633 if (real_reg_section
!= NULL
)
3637 /* FIXME: Pass error state gracefully. */
3638 if (bfd_get_section_flags (stdoutput
, real_reg_section
) & SEC_HAS_CONTENTS
)
3639 as_fatal (_("register section has contents\n"));
3641 /* Really remove the section. */
3642 for (secpp
= &stdoutput
->sections
;
3643 *secpp
!= real_reg_section
;
3644 secpp
= &(*secpp
)->next
)
3646 bfd_section_list_remove (stdoutput
, secpp
);
3647 --stdoutput
->section_count
;
3652 /* Provide an expression for a built-in name provided when-used.
3653 Either a symbol that is a handler; living in 0x10*[1..8] and having
3654 name [DVWIOUZX]_Handler, or a mmixal built-in symbol.
3656 If the name isn't a built-in name and parsed into *EXPP, return zero. */
3659 mmix_parse_predefined_name (name
, expP
)
3664 char *handler_charp
;
3665 const char handler_chars
[] = "DVWIOUZX";
3668 if (! predefined_syms
)
3671 canon_name
= tc_canonicalize_symbol_name (name
);
3673 if (canon_name
[1] == '_'
3674 && strcmp (canon_name
+ 2, "Handler") == 0
3675 && (handler_charp
= strchr (handler_chars
, *canon_name
)) != NULL
)
3677 /* If the symbol doesn't exist, provide one relative to the .text
3680 FIXME: We should provide separate sections, mapped in the linker
3682 symp
= symbol_find (name
);
3684 symp
= symbol_new (name
, text_section
,
3685 0x10 * (handler_charp
+ 1 - handler_chars
),
3686 &zero_address_frag
);
3690 /* These symbols appear when referenced; needed for
3691 mmixal-compatible programs. */
3698 } predefined_abs_syms
[] =
3700 {"Data_Segment", (valueT
) 0x20 << 56},
3701 {"Pool_Segment", (valueT
) 0x40 << 56},
3702 {"Stack_Segment", (valueT
) 0x60 << 56},
3710 {"BinaryReadWrite", 4},
3733 /* If it's already in the symbol table, we shouldn't do anything. */
3734 symp
= symbol_find (name
);
3739 i
< sizeof (predefined_abs_syms
) / sizeof (predefined_abs_syms
[0]);
3741 if (strcmp (canon_name
, predefined_abs_syms
[i
].name
) == 0)
3743 symbol_table_insert (symbol_new (predefined_abs_syms
[i
].name
,
3745 predefined_abs_syms
[i
].val
,
3746 &zero_address_frag
));
3748 /* Let gas find the symbol we just created, through its
3753 /* Not one of those symbols. Let gas handle it. */
3757 expP
->X_op
= O_symbol
;
3758 expP
->X_add_number
= 0;
3759 expP
->X_add_symbol
= symp
;
3760 expP
->X_op_symbol
= NULL
;
3765 /* Just check that we don't have a BSPEC/ESPEC pair active when changing
3766 sections "normally", and get knowledge about alignment from the new
3770 mmix_md_elf_section_change_hook ()
3773 as_bad (_("section change from within a BSPEC/ESPEC pair is not supported"));
3775 last_alignment
= bfd_get_section_alignment (now_seg
->owner
, now_seg
);
3779 /* The LOC worker. This is like s_org, but we have to support changing
3784 int ignore ATTRIBUTE_UNUSED
;
3792 /* Must not have a BSPEC in progress. */
3795 as_bad (_("directive LOC from within a BSPEC/ESPEC pair is not supported"));
3799 section
= expression (&exp
);
3801 if (exp
.X_op
== O_illegal
3802 || exp
.X_op
== O_absent
3803 || exp
.X_op
== O_big
3804 || section
== undefined_section
)
3806 as_bad (_("invalid LOC expression"));
3810 if (section
== absolute_section
)
3812 /* Translate a constant into a suitable section. */
3814 if (exp
.X_add_number
< ((offsetT
) 0x20 << 56))
3816 /* Lower than Data_Segment - assume it's .text. */
3817 section
= text_section
;
3819 /* Save the lowest seen location, so we can pass on this
3820 information to the linker. We don't actually org to this
3821 location here, we just pass on information to the linker so
3822 it can put the code there for us. */
3824 /* If there was already a loc (that has to be set lower than
3825 this one), we org at (this - lower). There's an implicit
3826 "LOC 0" before any entered code. FIXME: handled by spurious
3827 settings of text_has_contents. */
3828 if (exp
.X_add_number
< 0
3829 || exp
.X_add_number
< (offsetT
) lowest_text_loc
)
3831 as_bad (_("LOC expression stepping backwards is not supported"));
3832 exp
.X_op
= O_absent
;
3836 if (text_has_contents
&& lowest_text_loc
== (bfd_vma
) -1)
3837 lowest_text_loc
= 0;
3839 if (lowest_text_loc
== (bfd_vma
) -1)
3841 lowest_text_loc
= exp
.X_add_number
;
3843 /* We want only to change the section, not set an offset. */
3844 exp
.X_op
= O_absent
;
3847 exp
.X_add_number
-= lowest_text_loc
;
3852 /* Do the same for the .data section. */
3853 section
= data_section
;
3855 if (exp
.X_add_number
< (offsetT
) lowest_data_loc
)
3857 as_bad (_("LOC expression stepping backwards is not supported"));
3858 exp
.X_op
= O_absent
;
3862 if (data_has_contents
&& lowest_data_loc
== (bfd_vma
) -1)
3863 lowest_data_loc
= (bfd_vma
) 0x20 << 56;
3865 if (lowest_data_loc
== (bfd_vma
) -1)
3867 lowest_data_loc
= exp
.X_add_number
;
3869 /* We want only to change the section, not set an offset. */
3870 exp
.X_op
= O_absent
;
3873 exp
.X_add_number
-= lowest_data_loc
;
3878 if (section
!= now_seg
)
3880 obj_elf_section_change_hook ();
3881 subseg_set (section
, 0);
3883 /* Call our section change hooks using the official hook. */
3884 md_elf_section_change_hook ();
3887 if (exp
.X_op
!= O_absent
)
3889 if (exp
.X_op
!= O_constant
&& exp
.X_op
!= O_symbol
)
3891 /* Handle complex expressions. */
3892 sym
= make_expr_symbol (&exp
);
3897 sym
= exp
.X_add_symbol
;
3898 off
= exp
.X_add_number
;
3901 p
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, sym
, off
, (char *) 0);
3905 mmix_handle_rest_of_empty_line ();
3908 /* The BYTE worker. We have to support sequences of mixed "strings",
3909 numbers and other constant "first-pass" reducible expressions separated
3918 if (now_seg
== text_section
)
3919 text_has_contents
= 1;
3920 else if (now_seg
== data_section
)
3921 data_has_contents
= 1;
3926 switch (*input_line_pointer
)
3929 ++input_line_pointer
;
3930 start
= input_line_pointer
;
3931 while (is_a_char (c
= next_char_of_string ()))
3933 FRAG_APPEND_1_CHAR (c
);
3936 if (input_line_pointer
[-1] != '\"')
3938 /* We will only get here in rare cases involving #NO_APP,
3939 where the unterminated string is not recognized by the
3940 preformatting pass. */
3941 as_bad (_("unterminated string"));
3942 mmix_discard_rest_of_line ();
3950 segT expseg
= expression (&exp
);
3952 /* We have to allow special register names as constant numbers. */
3953 if ((expseg
!= absolute_section
&& expseg
!= reg_section
)
3954 || (exp
.X_op
!= O_constant
3955 && (exp
.X_op
!= O_register
3956 || exp
.X_add_number
<= 255)))
3958 as_bad (_("BYTE expression not a pure number"));
3959 mmix_discard_rest_of_line ();
3962 else if ((exp
.X_add_number
> 255 && exp
.X_op
!= O_register
)
3963 || exp
.X_add_number
< 0)
3965 /* Note that mmixal does not allow negative numbers in
3966 BYTE sequences, so neither should we. */
3967 as_bad (_("BYTE expression not in the range 0..255"));
3968 mmix_discard_rest_of_line ();
3972 FRAG_APPEND_1_CHAR (exp
.X_add_number
);
3978 c
= *input_line_pointer
++;
3982 input_line_pointer
--;
3984 if (mmix_gnu_syntax
)
3985 demand_empty_rest_of_line ();
3988 mmix_discard_rest_of_line ();
3989 /* Do like demand_empty_rest_of_line and step over the end-of-line
3991 input_line_pointer
++;
3994 /* Make sure we align for the next instruction. */
3998 /* Like cons_worker, but we have to ignore "naked comments", not barf on
3999 them. Implements WYDE, TETRA and OCTA. We're a little bit more
4000 lenient than mmix_byte but FIXME: they should eventually merge. */
4009 /* If we don't have any contents, then it's ok to have a specified start
4010 address that is not a multiple of the max data size. We will then
4011 align it as necessary when we get here. Otherwise, it's a fatal sin. */
4012 if (now_seg
== text_section
)
4014 if (lowest_text_loc
!= (bfd_vma
) -1
4015 && (lowest_text_loc
& (nbytes
- 1)) != 0)
4017 if (text_has_contents
)
4018 as_bad (_("data item with alignment larger than location"));
4019 else if (want_unaligned
)
4020 as_bad (_("unaligned data at an absolute location is not supported"));
4022 lowest_text_loc
&= ~((bfd_vma
) nbytes
- 1);
4023 lowest_text_loc
+= (bfd_vma
) nbytes
;
4026 text_has_contents
= 1;
4028 else if (now_seg
== data_section
)
4030 if (lowest_data_loc
!= (bfd_vma
) -1
4031 && (lowest_data_loc
& (nbytes
- 1)) != 0)
4033 if (data_has_contents
)
4034 as_bad (_("data item with alignment larger than location"));
4035 else if (want_unaligned
)
4036 as_bad (_("unaligned data at an absolute location is not supported"));
4038 lowest_data_loc
&= ~((bfd_vma
) nbytes
- 1);
4039 lowest_data_loc
+= (bfd_vma
) nbytes
;
4042 data_has_contents
= 1;
4045 /* Always align these unless asked not to (valid for the current pseudo). */
4046 if (! want_unaligned
)
4048 last_alignment
= nbytes
== 2 ? 1 : (nbytes
== 4 ? 2 : 3);
4049 frag_align (last_alignment
, 0, 0);
4050 record_alignment (now_seg
, last_alignment
);
4053 /* For mmixal compatibility, a label for an instruction (and emitting
4054 pseudo) refers to the _aligned_ address. So we have to emit the
4056 if (current_fb_label
>= 0)
4057 colon (fb_label_name (current_fb_label
, 1));
4058 else if (pending_label
!= NULL
)
4060 colon (pending_label
);
4061 pending_label
= NULL
;
4066 if (is_end_of_line
[(unsigned int) *input_line_pointer
])
4068 /* Default to zero if the expression was absent. */
4070 exp
.X_op
= O_constant
;
4071 exp
.X_add_number
= 0;
4073 exp
.X_add_symbol
= NULL
;
4074 exp
.X_op_symbol
= NULL
;
4075 emit_expr (&exp
, (unsigned int) nbytes
);
4082 switch (*input_line_pointer
)
4084 /* We support strings here too; each character takes up nbytes
4087 ++input_line_pointer
;
4088 start
= input_line_pointer
;
4089 while (is_a_char (c
= next_char_of_string ()))
4091 exp
.X_op
= O_constant
;
4092 exp
.X_add_number
= c
;
4094 emit_expr (&exp
, (unsigned int) nbytes
);
4097 if (input_line_pointer
[-1] != '\"')
4099 /* We will only get here in rare cases involving #NO_APP,
4100 where the unterminated string is not recognized by the
4101 preformatting pass. */
4102 as_bad (_("unterminated string"));
4103 mmix_discard_rest_of_line ();
4111 emit_expr (&exp
, (unsigned int) nbytes
);
4117 while (*input_line_pointer
++ == ',');
4119 input_line_pointer
--; /* Put terminator back into stream. */
4121 mmix_handle_rest_of_empty_line ();
4123 /* We don't need to step up the counter for the current_fb_label here;
4124 that's handled by the caller. */
4127 /* The md_do_align worker. At present, we just record an alignment to
4128 nullify the automatic alignment we do for WYDE, TETRA and OCTA, as gcc
4129 does not use the unaligned macros when attribute packed is used.
4130 Arguably this is a GCC bug. */
4133 mmix_md_do_align (n
, fill
, len
, max
)
4135 char *fill ATTRIBUTE_UNUSED
;
4136 int len ATTRIBUTE_UNUSED
;
4137 int max ATTRIBUTE_UNUSED
;
4140 want_unaligned
= n
== 0;