1 /* tc-mmix.c -- Assembler for Don Knuth's MMIX.
2 Copyright (C) 2001 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));
70 static void mmix_frob_local_reloc
PARAMS ((bfd
*, asection
*, PTR
));
72 /* Continue the tradition of symbols.c; use control characters to enforce
73 magic. These are used when replacing e.g. 8F and 8B so we can handle
74 such labels correctly with the common parser hooks. */
75 #define MAGIC_FB_BACKWARD_CHAR '\003'
76 #define MAGIC_FB_FORWARD_CHAR '\004'
78 /* Copy the location of a frag to a fix. */
79 #define COPY_FR_WHERE_TO_FX(FRAG, FIX) \
82 (FIX)->fx_file = (FRAG)->fr_file; \
83 (FIX)->fx_line = (FRAG)->fr_line; \
87 const char *md_shortopts
= "x";
88 static int current_fb_label
= -1;
89 static char *pending_label
= NULL
;
91 static bfd_vma lowest_text_loc
= (bfd_vma
) -1;
92 static int text_has_contents
= 0;
94 /* The alignment of the previous instruction, and a boolean for whether we
95 want to avoid aligning the next WYDE, TETRA, OCTA or insn. */
96 static int last_alignment
= 0;
97 static int want_unaligned
= 0;
99 static bfd_vma lowest_data_loc
= (bfd_vma
) -1;
100 static int data_has_contents
= 0;
102 /* The fragS of the instruction being assembled. Only valid from within
104 fragS
*mmix_opcode_frag
= NULL
;
106 /* Raw GREGs as appearing in input. These may be fewer than the number
108 static int n_of_raw_gregs
= 0;
113 } mmix_raw_gregs
[MAX_GREGS
];
115 /* Fixups for all unique GREG registers. We store the fixups here in
116 md_convert_frag, then we use the array to convert
117 BFD_RELOC_MMIX_BASE_PLUS_OFFSET fixups in tc_gen_reloc. The index is
118 just a running number and is not supposed to be correlated to a
120 static fixS
*mmix_gregs
[MAX_GREGS
];
121 static int n_of_cooked_gregs
= 0;
123 /* Pointing to the register section we use for output. */
124 static asection
*real_reg_section
;
126 /* For each symbol; unknown or section symbol, we keep a list of GREG
127 definitions sorted on increasing offset. It seems no use keeping count
128 to allocate less room than the maximum number of gregs when we've found
129 one for a section or symbol. */
130 struct mmix_symbol_gregs
133 struct mmix_symbol_greg_fixes
137 /* A signed type, since we may have GREGs pointing slightly before the
138 contents of a section. */
140 } greg_fixes
[MAX_GREGS
];
143 /* Should read insert a colon on something that starts in column 0 on
145 static int label_without_colon_this_line
= 1;
147 /* Should we expand operands for external symbols? */
148 static int expand_op
= 1;
150 /* Should we warn when expanding operands? FIXME: test-cases for when -x
152 static int warn_on_expansion
= 1;
154 /* Should we merge non-zero GREG register definitions? */
155 static int merge_gregs
= 1;
157 /* Should we emit built-in symbols? */
158 static int predefined_syms
= 1;
160 /* Should we anything but the listed special register name (e.g. equated
162 static int equated_spec_regs
= 1;
164 /* Do we require standard GNU syntax? */
165 int mmix_gnu_syntax
= 0;
167 /* Do we globalize all symbols? */
168 int mmix_globalize_symbols
= 0;
170 /* Do we know that the next semicolon is at the end of the operands field
171 (in mmixal mode; constant 1 in GNU mode)? */
172 int mmix_next_semicolon_is_eoln
= 1;
174 /* Do we have a BSPEC in progress? */
175 static int doing_bspec
= 0;
176 static char *bspec_file
;
177 static unsigned int bspec_line
;
179 struct option md_longopts
[] =
181 #define OPTION_RELAX (OPTION_MD_BASE)
182 #define OPTION_NOEXPAND (OPTION_RELAX + 1)
183 #define OPTION_NOMERGEGREG (OPTION_NOEXPAND + 1)
184 #define OPTION_NOSYMS (OPTION_NOMERGEGREG + 1)
185 #define OPTION_GNU_SYNTAX (OPTION_NOSYMS + 1)
186 #define OPTION_GLOBALIZE_SYMBOLS (OPTION_GNU_SYNTAX + 1)
187 #define OPTION_FIXED_SPEC_REGS (OPTION_GLOBALIZE_SYMBOLS + 1)
188 {"linkrelax", no_argument
, NULL
, OPTION_RELAX
},
189 {"no-expand", no_argument
, NULL
, OPTION_NOEXPAND
},
190 {"no-merge-gregs", no_argument
, NULL
, OPTION_NOMERGEGREG
},
191 {"no-predefined-syms", no_argument
, NULL
, OPTION_NOSYMS
},
192 {"gnu-syntax", no_argument
, NULL
, OPTION_GNU_SYNTAX
},
193 {"globalize-symbols", no_argument
, NULL
, OPTION_GLOBALIZE_SYMBOLS
},
194 {"fixed-special-register-names", no_argument
, NULL
,
195 OPTION_FIXED_SPEC_REGS
},
196 {NULL
, no_argument
, NULL
, 0}
199 size_t md_longopts_size
= sizeof (md_longopts
);
201 static struct hash_control
*mmix_opcode_hash
;
203 /* We use these when implementing the PREFIX pseudo. */
204 char *mmix_current_prefix
;
205 struct obstack mmix_sym_obstack
;
208 /* For MMIX, we encode the relax_substateT:s (in e.g. fr_substate) as one
209 bit length, and the relax-type shifted on top of that. There seems to
210 be no point in making the relaxation more fine-grained; the linker does
211 that better and we might interfere by changing non-optimal relaxations
212 into other insns that cannot be relaxed as easily.
214 Groups for MMIX relaxing:
217 extra length: zero or three insns.
220 extra length: zero or five insns.
223 extra length: zero or four insns.
226 extra length: zero or four insns. */
228 #define STATE_GETA (1)
229 #define STATE_BCC (2)
230 #define STATE_PUSHJ (3)
231 #define STATE_JMP (4)
232 #define STATE_GREG (5)
234 /* No fine-grainedness here. */
235 #define STATE_LENGTH_MASK (1)
237 #define STATE_ZERO (0)
238 #define STATE_MAX (1)
240 /* More descriptive name for convenience. */
241 /* FIXME: We should start on something different, not MAX. */
242 #define STATE_UNDF STATE_MAX
244 /* FIXME: For GREG, we must have other definitions; UNDF == MAX isn't
245 appropriate; we need it the other way round. This value together with
246 fragP->tc_frag_data shows what state the frag is in: tc_frag_data
247 non-NULL means 0, NULL means 8 bytes. */
248 #define STATE_GREG_UNDF ENCODE_RELAX (STATE_GREG, STATE_ZERO)
249 #define STATE_GREG_DEF ENCODE_RELAX (STATE_GREG, STATE_MAX)
251 /* These displacements are relative to the adress following the opcode
252 word of the instruction. The catch-all states have zero for "reach"
253 and "next" entries. */
255 #define GETA_0F (65536 * 4 - 8)
256 #define GETA_0B (-65536 * 4 - 4)
258 #define GETA_MAX_LEN 4*4
262 #define BCC_0F GETA_0F
263 #define BCC_0B GETA_0B
265 #define BCC_MAX_LEN 6*4
266 #define BCC_5F GETA_3F
267 #define BCC_5B GETA_3B
269 #define PUSHJ_0F GETA_0F
270 #define PUSHJ_0B GETA_0B
272 #define PUSHJ_MAX_LEN 5*4
273 #define PUSHJ_4F GETA_3F
274 #define PUSHJ_4B GETA_3B
276 #define JMP_0F (65536 * 256 * 4 - 8)
277 #define JMP_0B (-65536 * 256 * 4 - 4)
279 #define JMP_MAX_LEN 5*4
283 #define RELAX_ENCODE_SHIFT 1
284 #define ENCODE_RELAX(what, length) (((what) << RELAX_ENCODE_SHIFT) + (length))
286 const relax_typeS mmix_relax_table
[] =
288 /* Error sentinel (0, 0). */
295 {GETA_0F
, GETA_0B
, 0, ENCODE_RELAX (STATE_GETA
, STATE_MAX
)},
299 GETA_MAX_LEN
- 4, 0},
302 {BCC_0F
, BCC_0B
, 0, ENCODE_RELAX (STATE_BCC
, STATE_MAX
)},
309 {PUSHJ_0F
, PUSHJ_0B
, 0, ENCODE_RELAX (STATE_PUSHJ
, STATE_MAX
)},
313 PUSHJ_MAX_LEN
- 4, 0},
316 {JMP_0F
, JMP_0B
, 0, ENCODE_RELAX (STATE_JMP
, STATE_MAX
)},
322 /* GREG (5, 0), (5, 1), though the table entry isn't used. */
323 {0, 0, 0, 0}, {0, 0, 0, 0}
326 const pseudo_typeS md_pseudo_table
[] =
328 /* Support " .greg sym,expr" syntax. */
331 /* Support " .bspec expr" syntax. */
332 {"bspec", s_bspec
, 1},
334 /* Support " .espec" syntax. */
335 {"espec", s_espec
, 1},
337 /* Support " .local $45" syntax. */
338 {"local", mmix_s_local
, 1},
340 /* Support DWARF2 debugging info. */
341 {"file", dwarf2_directive_file
, 0},
342 {"loc", dwarf2_directive_loc
, 0},
347 const char mmix_comment_chars
[] = "%!";
349 /* A ':' is a valid symbol character in mmixal. It's the prefix
350 delimiter, but other than that, it works like a symbol character,
351 except that we strip one off at the beginning of symbols. An '@' is a
352 symbol by itself (for the current location); space around it must not
354 const char mmix_symbol_chars
[] = ":@";
356 const char line_comment_chars
[] = "*#";
358 const char line_separator_chars
[] = ";";
360 const char mmix_exp_chars
[] = "eE";
362 const char mmix_flt_chars
[] = "rf";
365 /* Fill in the offset-related part of GETA or Bcc. */
368 mmix_set_geta_branch_offset (opcodep
, value
)
379 md_number_to_chars (opcodep
+ 2, value
, 2);
382 /* Fill in the offset-related part of JMP. */
385 mmix_set_jmp_offset (opcodep
, value
)
391 value
+= 65536 * 256 * 4;
396 md_number_to_chars (opcodep
+ 1, value
, 3);
399 /* Fill in NOP:s for the expanded part of GETA/JMP/Bcc/PUSHJ. */
402 mmix_fill_nops (opcodep
, n
)
408 for (i
= 0; i
< n
; i
++)
409 md_number_to_chars (opcodep
+ i
*4, SWYM_INSN_BYTE
<< 24, 4);
412 /* See macro md_parse_name in tc-mmix.h. */
415 mmix_current_location (fn
, exp
)
416 void (*fn
) PARAMS ((expressionS
*));
424 /* Get up to three operands, filling them into the exp array.
425 General idea and code stolen from the tic80 port. */
428 get_operands (max_operands
, s
, exp
)
437 while (nextchar
== ',')
439 /* Skip leading whitespace */
440 while (*p
== ' ' || *p
== '\t')
443 /* Check to see if we have any operands left to parse */
444 if (*p
== 0 || *p
== '\n' || *p
== '\r')
448 else if (numexp
== max_operands
)
450 /* This seems more sane than saying "too many operands". We'll
451 get here only if the trailing trash starts with a comma. */
452 as_bad (_("invalid operands"));
453 mmix_discard_rest_of_line ();
457 /* Begin operand parsing at the current scan point. */
459 input_line_pointer
= p
;
460 expression (&exp
[numexp
]);
462 if (exp
[numexp
].X_op
== O_illegal
)
464 as_bad (_("invalid operands"));
466 else if (exp
[numexp
].X_op
== O_absent
)
468 as_bad (_("missing operand"));
472 p
= input_line_pointer
;
474 /* Skip leading whitespace */
475 while (*p
== ' ' || *p
== '\t')
480 /* If we allow "naked" comments, ignore the rest of the line. */
483 mmix_handle_rest_of_empty_line ();
484 input_line_pointer
--;
487 /* Mark the end of the valid operands with an illegal expression. */
488 exp
[numexp
].X_op
= O_illegal
;
493 /* Get the value of a special register, or -1 if the name does not match
494 one. NAME is a null-terminated string. */
497 get_spec_regno (name
)
508 /* Well, it's a short array and we'll most often just match the first
510 for (i
= 0; mmix_spec_regs
[i
].name
!= NULL
; i
++)
511 if (strcmp (name
, mmix_spec_regs
[i
].name
) == 0)
512 return mmix_spec_regs
[i
].number
;
517 /* For GET and PUT, parse the register names "manually", so we don't use
520 get_putget_operands (insn
, operands
, exp
)
521 struct mmix_opcode
*insn
;
525 expressionS
*expp_reg
;
526 expressionS
*expp_sreg
;
528 char *sregend
= operands
;
533 /* Skip leading whitespace */
534 while (*p
== ' ' || *p
== '\t')
537 input_line_pointer
= p
;
539 if (insn
->operands
== mmix_operands_get
)
544 expression (expp_reg
);
546 p
= input_line_pointer
;
548 /* Skip whitespace */
549 while (*p
== ' ' || *p
== '\t')
556 /* Skip whitespace */
557 while (*p
== ' ' || *p
== '\t')
560 input_line_pointer
= sregp
;
561 c
= get_symbol_end ();
562 sregend
= input_line_pointer
;
570 /* Initialize to error state in case we'll never call expression on
572 expp_reg
->X_op
= O_illegal
;
575 c
= get_symbol_end ();
576 sregend
= p
= input_line_pointer
;
579 /* Skip whitespace */
580 while (*p
== ' ' || *p
== '\t')
587 /* Skip whitespace */
588 while (*p
== ' ' || *p
== '\t')
591 input_line_pointer
= p
;
592 expression (expp_reg
);
597 regno
= get_spec_regno (sregp
);
600 /* Let the caller issue errors; we've made sure the operands are
602 if (expp_reg
->X_op
!= O_illegal
603 && expp_reg
->X_op
!= O_absent
606 expp_sreg
->X_op
= O_register
;
607 expp_sreg
->X_add_number
= regno
+ 256;
613 /* Handle MMIX-specific option. */
616 md_parse_option (c
, arg
)
618 char *arg ATTRIBUTE_UNUSED
;
623 warn_on_expansion
= 0;
630 case OPTION_NOEXPAND
:
634 case OPTION_NOMERGEGREG
:
640 equated_spec_regs
= 0;
643 case OPTION_GNU_SYNTAX
:
645 label_without_colon_this_line
= 0;
648 case OPTION_GLOBALIZE_SYMBOLS
:
649 mmix_globalize_symbols
= 1;
652 case OPTION_FIXED_SPEC_REGS
:
653 equated_spec_regs
= 0;
663 /* Display MMIX-specific help text. */
666 md_show_usage (stream
)
669 fprintf (stream
, _(" MMIX-specific command line options:\n"));
670 fprintf (stream
, _("\
671 -fixed-special-register-names\n\
672 Allow only the original special register names.\n"));
673 fprintf (stream
, _("\
674 -globalize-symbols Make all symbols global.\n"));
675 fprintf (stream
, _("\
676 -gnu-syntax Turn off mmixal syntax compatibility.\n"));
677 fprintf (stream
, _("\
678 -relax Create linker relaxable code.\n"));
679 fprintf (stream
, _("\
680 -no-predefined-syms Do not provide mmixal built-in constants.\n\
681 Implies -fixed-special-register-names.\n"));
682 fprintf (stream
, _("\
683 -no-expand Do not expand GETA, branches, PUSHJ or JUMP\n\
684 into multiple instructions.\n"));
685 fprintf (stream
, _("\
686 -no-merge-gregs Do not merge GREG definitions with nearby values.\n"));
687 fprintf (stream
, _("\
688 -x Do not warn when an operand to GETA, a branch,\n\
689 PUSHJ or JUMP is not known to be within range.\n\
690 The linker will catch any errors.\n"));
693 /* Step to end of line, but don't step over the end of the line. */
696 mmix_discard_rest_of_line ()
698 while (*input_line_pointer
699 && (! is_end_of_line
[(unsigned char) *input_line_pointer
]
700 || TC_EOL_IN_INSN (input_line_pointer
)))
701 input_line_pointer
++;
704 /* Act as demand_empty_rest_of_line if we're in strict GNU syntax mode,
705 otherwise just ignore the rest of the line (and skip the end-of-line
709 mmix_handle_rest_of_empty_line ()
712 demand_empty_rest_of_line ();
715 mmix_discard_rest_of_line ();
716 input_line_pointer
++;
720 /* Initialize GAS MMIX specifics. */
726 const struct mmix_opcode
*opcode
;
728 /* We assume nobody will use this, so don't allocate any room. */
729 obstack_begin (&mmix_sym_obstack
, 0);
731 /* This will break the day the "lex" thingy changes. For now, it's the
732 only way to make ':' part of a name, and a name beginner. */
733 lex_type
[':'] = (LEX_NAME
| LEX_BEGIN_NAME
);
735 mmix_opcode_hash
= hash_new ();
738 = bfd_make_section_old_way (stdoutput
, MMIX_REG_SECTION_NAME
);
740 for (opcode
= mmix_opcodes
; opcode
->name
; opcode
++)
741 hash_insert (mmix_opcode_hash
, opcode
->name
, (char *) opcode
);
743 /* We always insert the ordinary registers 0..255 as registers. */
744 for (i
= 0; i
< 256; i
++)
748 /* Alternatively, we could diddle with '$' and the following number,
749 but keeping the registers as symbols helps keep parsing simple. */
750 sprintf (buf
, "$%d", i
);
751 symbol_table_insert (symbol_new (buf
, reg_section
, i
,
752 &zero_address_frag
));
755 /* Insert mmixal built-in names if allowed. */
758 for (i
= 0; mmix_spec_regs
[i
].name
!= NULL
; i
++)
759 symbol_table_insert (symbol_new (mmix_spec_regs
[i
].name
,
761 mmix_spec_regs
[i
].number
+ 256,
762 &zero_address_frag
));
764 /* FIXME: Perhaps these should be recognized as specials; as field
765 names for those instructions. */
766 symbol_table_insert (symbol_new ("ROUND_CURRENT", reg_section
, 512,
767 &zero_address_frag
));
768 symbol_table_insert (symbol_new ("ROUND_OFF", reg_section
, 512 + 1,
769 &zero_address_frag
));
770 symbol_table_insert (symbol_new ("ROUND_UP", reg_section
, 512 + 2,
771 &zero_address_frag
));
772 symbol_table_insert (symbol_new ("ROUND_DOWN", reg_section
, 512 + 3,
773 &zero_address_frag
));
774 symbol_table_insert (symbol_new ("ROUND_NEAR", reg_section
, 512 + 4,
775 &zero_address_frag
));
779 /* Assemble one insn in STR. */
785 char *operands
= str
;
786 char modified_char
= 0;
787 struct mmix_opcode
*instruction
;
788 fragS
*opc_fragP
= NULL
;
789 int max_operands
= 3;
791 /* Note that the struct frag member fr_literal in frags.h is char[], so
792 I have to make this a plain char *. */
793 /* unsigned */ char *opcodep
= NULL
;
798 /* Move to end of opcode. */
800 is_part_of_name (*operands
);
804 if (ISSPACE (*operands
))
806 modified_char
= *operands
;
810 instruction
= (struct mmix_opcode
*) hash_find (mmix_opcode_hash
, str
);
811 if (instruction
== NULL
)
813 as_bad (_("unknown opcode: `%s'"), str
);
815 /* Avoid "unhandled label" errors. */
816 pending_label
= NULL
;
820 /* Put back the character after the opcode. */
821 if (modified_char
!= 0)
822 operands
[-1] = modified_char
;
824 input_line_pointer
= operands
;
826 /* Is this a mmixal pseudodirective? */
827 if (instruction
->type
== mmix_type_pseudo
)
829 /* For mmixal compatibility, a label for an instruction (and
830 emitting pseudo) refers to the _aligned_ address. We emit the
831 label here for the pseudos that don't handle it themselves. When
832 having an fb-label, emit it here, and increment the counter after
834 switch (instruction
->operands
)
836 case mmix_operands_loc
:
837 case mmix_operands_byte
:
838 case mmix_operands_prefix
:
839 case mmix_operands_local
:
840 case mmix_operands_bspec
:
841 case mmix_operands_espec
:
842 if (current_fb_label
>= 0)
843 colon (fb_label_name (current_fb_label
, 1));
844 else if (pending_label
!= NULL
)
846 colon (pending_label
);
847 pending_label
= NULL
;
855 /* Some of the pseudos emit contents, others don't. Set a
856 contents-emitted flag when we emit something into .text */
857 switch (instruction
->operands
)
859 case mmix_operands_loc
:
864 case mmix_operands_byte
:
869 case mmix_operands_wyde
:
874 case mmix_operands_tetra
:
879 case mmix_operands_octa
:
884 case mmix_operands_prefix
:
889 case mmix_operands_local
:
894 case mmix_operands_bspec
:
899 case mmix_operands_espec
:
905 BAD_CASE (instruction
->operands
);
908 /* These are all working like the pseudo functions in read.c:s_...,
909 in that they step over the end-of-line marker at the end of the
910 line. We don't want that here. */
911 input_line_pointer
--;
913 /* Step up the fb-label counter if there was a definition on this
915 if (current_fb_label
>= 0)
917 fb_label_instance_inc (current_fb_label
);
918 current_fb_label
= -1;
921 /* Reset any don't-align-next-datum request, unless this was a LOC
923 if (instruction
->operands
!= mmix_operands_loc
)
929 /* Not a pseudo; we *will* emit contents. */
930 if (now_seg
== data_section
)
932 if (lowest_data_loc
!= (bfd_vma
) -1 && (lowest_data_loc
& 3) != 0)
934 if (data_has_contents
)
935 as_bad (_("specified location wasn't TETRA-aligned"));
936 else if (want_unaligned
)
937 as_bad (_("unaligned data at an absolute location is not supported"));
939 lowest_data_loc
&= ~(bfd_vma
) 3;
940 lowest_data_loc
+= 4;
943 data_has_contents
= 1;
945 else if (now_seg
== text_section
)
947 if (lowest_text_loc
!= (bfd_vma
) -1 && (lowest_text_loc
& 3) != 0)
949 if (text_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_text_loc
&= ~(bfd_vma
) 3;
955 lowest_text_loc
+= 4;
958 text_has_contents
= 1;
961 /* After a sequence of BYTEs or WYDEs, we need to get to instruction
962 alignment. For other pseudos, a ".p2align 2" is supposed to be
963 inserted by the user. */
964 if (last_alignment
< 2 && ! want_unaligned
)
966 frag_align (2, 0, 0);
967 record_alignment (now_seg
, 2);
971 /* Reset any don't-align-next-datum request. */
974 /* For mmixal compatibility, a label for an instruction (and emitting
975 pseudo) refers to the _aligned_ address. So we have to emit the
977 if (pending_label
!= NULL
)
979 colon (pending_label
);
980 pending_label
= NULL
;
983 /* We assume that mmix_opcodes keeps having unique mnemonics for each
984 opcode, so we don't have to iterate over more than one opcode; if the
985 syntax does not match, then there's a syntax error. */
987 /* Operands have little or no context and are all comma-separated; it is
988 easier to parse each expression first. */
989 switch (instruction
->operands
)
991 case mmix_operands_reg_yz
:
992 case mmix_operands_pop
:
993 case mmix_operands_regaddr
:
994 case mmix_operands_pushj
:
995 case mmix_operands_get
:
996 case mmix_operands_put
:
997 case mmix_operands_set
:
998 case mmix_operands_save
:
999 case mmix_operands_unsave
:
1003 case mmix_operands_sync
:
1004 case mmix_operands_jmp
:
1005 case mmix_operands_resume
:
1009 /* The original 3 is fine for the rest. */
1014 /* If this is GET or PUT, and we don't do allow those names to be
1015 equated, we need to parse the names ourselves, so we don't pick up a
1016 user label instead of the special register. */
1017 if (! equated_spec_regs
1018 && (instruction
->operands
== mmix_operands_get
1019 || instruction
->operands
== mmix_operands_put
))
1020 n_operands
= get_putget_operands (instruction
, operands
, exp
);
1022 n_operands
= get_operands (max_operands
, operands
, exp
);
1024 /* If there's a fb-label on the current line, set that label. This must
1025 be done *after* evaluating expressions of operands, since neither a
1026 "1B" nor a "1F" refers to "1H" on the same line. */
1027 if (current_fb_label
>= 0)
1029 fb_label_instance_inc (current_fb_label
);
1030 colon (fb_label_name (current_fb_label
, 0));
1031 current_fb_label
= -1;
1034 /* We also assume that the length of the instruction is determinable
1035 from the first format character. Currently *all* the information is
1036 in the first character. We need a self-contained frag since we want
1037 the relocation to point to the instruction, not the variant part. */
1039 opcodep
= frag_more (4);
1040 mmix_opcode_frag
= opc_fragP
= frag_now
;
1041 frag_now
->fr_opcode
= opcodep
;
1043 /* Mark start of insn for DWARF2 debug features. */
1044 if (OUTPUT_FLAVOR
== bfd_target_elf_flavour
)
1045 dwarf2_emit_insn (4);
1047 md_number_to_chars (opcodep
, instruction
->match
, 4);
1049 switch (instruction
->operands
)
1051 case mmix_operands_jmp
:
1052 if (n_operands
== 0 && ! mmix_gnu_syntax
)
1053 /* Zeros are in place - nothing needs to be done when we have no
1057 /* Add a frag for a JMP relaxation; we need room for max four
1058 extra instructions. We don't do any work around here to check if
1059 we can determine the offset right away. */
1060 if (n_operands
!= 1 || exp
[0].X_op
== O_register
)
1062 as_bad (_("invalid operand to opcode %s: `%s'"),
1063 instruction
->name
, operands
);
1068 frag_var (rs_machine_dependent
, 4*4, 0,
1069 ENCODE_RELAX (STATE_JMP
, STATE_UNDF
),
1070 exp
[0].X_add_symbol
,
1071 exp
[0].X_add_number
,
1074 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
, 4,
1075 exp
+ 0, 1, BFD_RELOC_MMIX_ADDR27
);
1078 case mmix_operands_pushj
:
1079 /* We take care of PUSHJ in full here. */
1081 || ((exp
[0].X_op
== O_constant
|| exp
[0].X_op
== O_register
)
1082 && (exp
[0].X_add_number
> 255 || exp
[0].X_add_number
< 0)))
1084 as_bad (_("invalid operands to opcode %s: `%s'"),
1085 instruction
->name
, operands
);
1089 if (exp
[0].X_op
== O_register
|| exp
[0].X_op
== O_constant
)
1090 opcodep
[1] = exp
[0].X_add_number
;
1092 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 1,
1093 1, exp
+ 0, 0, BFD_RELOC_MMIX_REG_OR_BYTE
);
1096 frag_var (rs_machine_dependent
, PUSHJ_MAX_LEN
- 4, 0,
1097 ENCODE_RELAX (STATE_PUSHJ
, STATE_UNDF
),
1098 exp
[1].X_add_symbol
,
1099 exp
[1].X_add_number
,
1102 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
, 4,
1103 exp
+ 1, 1, BFD_RELOC_MMIX_ADDR19
);
1106 case mmix_operands_regaddr
:
1107 /* GETA/branch: Add a frag for relaxation. We don't do any work
1108 around here to check if we can determine the offset right away. */
1109 if (n_operands
!= 2 || exp
[1].X_op
== O_register
)
1111 as_bad (_("invalid operands to opcode %s: `%s'"),
1112 instruction
->name
, operands
);
1117 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
, 4,
1118 exp
+ 1, 1, BFD_RELOC_MMIX_ADDR19
);
1119 else if (instruction
->type
== mmix_type_condbranch
)
1120 frag_var (rs_machine_dependent
, BCC_MAX_LEN
- 4, 0,
1121 ENCODE_RELAX (STATE_BCC
, STATE_UNDF
),
1122 exp
[1].X_add_symbol
,
1123 exp
[1].X_add_number
,
1126 frag_var (rs_machine_dependent
, GETA_MAX_LEN
- 4, 0,
1127 ENCODE_RELAX (STATE_GETA
, STATE_UNDF
),
1128 exp
[1].X_add_symbol
,
1129 exp
[1].X_add_number
,
1137 switch (instruction
->operands
)
1139 case mmix_operands_regs
:
1140 /* We check the number of operands here, since we're in a
1141 FALLTHROUGH sequence in the next switch. */
1142 if (n_operands
!= 3 || exp
[2].X_op
== O_constant
)
1144 as_bad (_("invalid operands to opcode %s: `%s'"),
1145 instruction
->name
, operands
);
1149 case mmix_operands_regs_z
:
1150 if (n_operands
!= 3)
1152 as_bad (_("invalid operands to opcode %s: `%s'"),
1153 instruction
->name
, operands
);
1157 case mmix_operands_reg_yz
:
1158 case mmix_operands_roundregs_z
:
1159 case mmix_operands_roundregs
:
1160 case mmix_operands_regs_z_opt
:
1161 case mmix_operands_neg
:
1162 case mmix_operands_regaddr
:
1163 case mmix_operands_get
:
1164 case mmix_operands_set
:
1165 case mmix_operands_save
:
1167 || (exp
[0].X_op
== O_register
&& exp
[0].X_add_number
> 255))
1169 as_bad (_("invalid operands to opcode %s: `%s'"),
1170 instruction
->name
, operands
);
1174 if (exp
[0].X_op
== O_register
)
1175 opcodep
[1] = exp
[0].X_add_number
;
1177 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 1,
1178 1, exp
+ 0, 0, BFD_RELOC_MMIX_REG
);
1185 /* A corresponding once-over for those who take an 8-bit constant as
1186 their first operand. */
1187 switch (instruction
->operands
)
1189 case mmix_operands_pushgo
:
1190 /* PUSHGO: X is a constant, but can be expressed as a register.
1191 We handle X here and use the common machinery of T,X,3,$ for
1192 the rest of the operands. */
1194 || ((exp
[0].X_op
== O_constant
|| exp
[0].X_op
== O_register
)
1195 && (exp
[0].X_add_number
> 255 || exp
[0].X_add_number
< 0)))
1197 as_bad (_("invalid operands to opcode %s: `%s'"),
1198 instruction
->name
, operands
);
1201 else if (exp
[0].X_op
== O_constant
|| exp
[0].X_op
== O_register
)
1202 opcodep
[1] = exp
[0].X_add_number
;
1204 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 1,
1205 1, exp
+ 0, 0, BFD_RELOC_MMIX_REG_OR_BYTE
);
1208 case mmix_operands_pop
:
1209 if ((n_operands
== 0 || n_operands
== 1) && ! mmix_gnu_syntax
)
1212 case mmix_operands_x_regs_z
:
1214 || (exp
[0].X_op
== O_constant
1215 && (exp
[0].X_add_number
> 255
1216 || exp
[0].X_add_number
< 0)))
1218 as_bad (_("invalid operands to opcode %s: `%s'"),
1219 instruction
->name
, operands
);
1223 if (exp
[0].X_op
== O_constant
)
1224 opcodep
[1] = exp
[0].X_add_number
;
1226 /* FIXME: This doesn't bring us unsignedness checking. */
1227 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 1,
1228 1, exp
+ 0, 0, BFD_RELOC_8
);
1233 /* Handle the rest. */
1234 switch (instruction
->operands
)
1236 case mmix_operands_set
:
1237 /* SET: Either two registers, "$X,$Y", with Z field as zero, or
1238 "$X,YZ", meaning change the opcode to SETL. */
1240 || (exp
[1].X_op
== O_constant
1241 && (exp
[1].X_add_number
> 0xffff || exp
[1].X_add_number
< 0)))
1243 as_bad (_("invalid operands to opcode %s: `%s'"),
1244 instruction
->name
, operands
);
1248 if (exp
[1].X_op
== O_constant
)
1250 /* There's an ambiguity with "SET $0,Y" when Y isn't defined
1251 yet. To keep things simple, we assume that Y is then a
1252 register, and only change the opcode if Y is defined at this
1255 There's no compatibility problem with mmixal, since it emits
1256 errors if the field is not defined at this point. */
1257 md_number_to_chars (opcodep
, SETL_INSN_BYTE
, 1);
1259 opcodep
[2] = (exp
[1].X_add_number
>> 8) & 255;
1260 opcodep
[3] = exp
[1].X_add_number
& 255;
1264 case mmix_operands_x_regs_z
:
1265 /* SYNCD: "X,$Y,$Z|Z". */
1267 case mmix_operands_regs
:
1268 /* Three registers, $X,$Y,$Z. */
1270 case mmix_operands_regs_z
:
1271 /* Operands "$X,$Y,$Z|Z", number of arguments checked above. */
1273 case mmix_operands_pushgo
:
1274 /* Operands "$X|X,$Y,$Z|Z", optional Z. */
1276 case mmix_operands_regs_z_opt
:
1277 /* Operands "$X,$Y,$Z|Z", with $Z|Z being optional, default 0. Any
1278 operands not completely decided yet are postponed to later in
1279 assembly (but not until link-time yet). */
1281 if ((n_operands
!= 2 && n_operands
!= 3)
1282 || (exp
[1].X_op
== O_register
&& exp
[1].X_add_number
> 255)
1284 && ((exp
[2].X_op
== O_register
1285 && exp
[2].X_add_number
> 255
1287 || (exp
[2].X_op
== O_constant
1288 && (exp
[2].X_add_number
> 255
1289 || exp
[2].X_add_number
< 0)))))
1291 as_bad (_("invalid operands to opcode %s: `%s'"),
1292 instruction
->name
, operands
);
1296 if (n_operands
== 2)
1300 /* The last operand is immediate whenever we see just two
1302 opcodep
[0] |= IMM_OFFSET_BIT
;
1304 /* Now, we could either have an implied "0" as the Z operand, or
1305 it could be the constant of a "base address plus offset". It
1306 depends on whether it is allowed; only memory operations, as
1307 signified by instruction->type and "T" and "X" operand types,
1308 and it depends on whether we find a register in the second
1310 if (exp
[1].X_op
== O_register
&& exp
[1].X_add_number
<= 255)
1312 /* A zero then; all done. */
1313 opcodep
[2] = exp
[1].X_add_number
;
1317 /* Not known as a register. Is base address plus offset
1318 allowed, or can we assume that it is a register anyway? */
1319 if ((instruction
->operands
!= mmix_operands_regs_z_opt
1320 && instruction
->operands
!= mmix_operands_x_regs_z
1321 && instruction
->operands
!= mmix_operands_pushgo
)
1322 || (instruction
->type
!= mmix_type_memaccess_octa
1323 && instruction
->type
!= mmix_type_memaccess_tetra
1324 && instruction
->type
!= mmix_type_memaccess_wyde
1325 && instruction
->type
!= mmix_type_memaccess_byte
1326 && instruction
->type
!= mmix_type_memaccess_block
1327 && instruction
->type
!= mmix_type_jsr
1328 && instruction
->type
!= mmix_type_branch
))
1330 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 2,
1331 1, exp
+ 1, 0, BFD_RELOC_MMIX_REG
);
1335 /* To avoid getting a NULL add_symbol for constants and then
1336 catching a SEGV in write_relocs since it doesn't handle
1337 constants well for relocs other than PC-relative, we need to
1338 pass expressions as symbols and use fix_new, not fix_new_exp. */
1339 sym
= make_expr_symbol (exp
+ 1);
1341 /* Now we know it can be a "base address plus offset". Add
1342 proper fixup types so we can handle this later, when we've
1343 parsed everything. */
1344 fix_new (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 2,
1345 8, sym
, 0, 0, BFD_RELOC_MMIX_BASE_PLUS_OFFSET
);
1349 if (exp
[1].X_op
== O_register
)
1350 opcodep
[2] = exp
[1].X_add_number
;
1352 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 2,
1353 1, exp
+ 1, 0, BFD_RELOC_MMIX_REG
);
1355 /* In mmixal compatibility mode, we allow special registers as
1356 constants for the Z operand. They have 256 added to their
1357 register numbers, so the right thing will happen if we just treat
1358 those as constants. */
1359 if (exp
[2].X_op
== O_register
&& exp
[2].X_add_number
<= 255)
1360 opcodep
[3] = exp
[2].X_add_number
;
1361 else if (exp
[2].X_op
== O_constant
1362 || (exp
[2].X_op
== O_register
&& exp
[2].X_add_number
> 255))
1364 opcodep
[3] = exp
[2].X_add_number
;
1365 opcodep
[0] |= IMM_OFFSET_BIT
;
1368 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 3,
1370 (instruction
->operands
== mmix_operands_set
1371 || instruction
->operands
== mmix_operands_regs
)
1372 ? BFD_RELOC_MMIX_REG
: BFD_RELOC_MMIX_REG_OR_BYTE
);
1375 case mmix_operands_pop
:
1376 /* POP, one eight and one 16-bit operand. */
1377 if (n_operands
== 0 && ! mmix_gnu_syntax
)
1379 if (n_operands
== 1 && ! mmix_gnu_syntax
)
1380 goto a_single_24_bit_number_operand
;
1382 case mmix_operands_reg_yz
:
1383 /* A register and a 16-bit unsigned number. */
1385 || exp
[1].X_op
== O_register
1386 || (exp
[1].X_op
== O_constant
1387 && (exp
[1].X_add_number
> 0xffff || exp
[1].X_add_number
< 0)))
1389 as_bad (_("invalid operands to opcode %s: `%s'"),
1390 instruction
->name
, operands
);
1394 if (exp
[1].X_op
== O_constant
)
1396 opcodep
[2] = (exp
[1].X_add_number
>> 8) & 255;
1397 opcodep
[3] = exp
[1].X_add_number
& 255;
1400 /* FIXME: This doesn't bring us unsignedness checking. */
1401 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 2,
1402 2, exp
+ 1, 0, BFD_RELOC_16
);
1405 case mmix_operands_jmp
:
1406 /* A JMP. Everyhing is already done. */
1409 case mmix_operands_roundregs
:
1410 /* Two registers with optional rounding mode or constant in between. */
1411 if ((n_operands
== 3 && exp
[2].X_op
== O_constant
)
1412 || (n_operands
== 2 && exp
[1].X_op
== O_constant
))
1414 as_bad (_("invalid operands to opcode %s: `%s'"),
1415 instruction
->name
, operands
);
1419 case mmix_operands_roundregs_z
:
1420 /* Like FLOT, "$X,ROUND_MODE,$Z|Z", but the rounding mode is
1421 optional and can be the corresponding constant. */
1423 /* Which exp index holds the second operand (not the rounding
1425 int op2no
= n_operands
- 1;
1427 if ((n_operands
!= 2 && n_operands
!= 3)
1428 || ((exp
[op2no
].X_op
== O_register
1429 && exp
[op2no
].X_add_number
> 255)
1430 || (exp
[op2no
].X_op
== O_constant
1431 && (exp
[op2no
].X_add_number
> 255
1432 || exp
[op2no
].X_add_number
< 0)))
1434 /* We don't allow for the rounding mode to be deferred; it
1435 must be determined in the "first pass". It cannot be a
1436 symbol equated to a rounding mode, but defined after
1438 && ((exp
[1].X_op
== O_register
1439 && exp
[1].X_add_number
< 512)
1440 || (exp
[1].X_op
== O_constant
1441 && exp
[1].X_add_number
< 0
1442 && exp
[1].X_add_number
> 4)
1443 || (exp
[1].X_op
!= O_register
1444 && exp
[1].X_op
!= O_constant
))))
1446 as_bad (_("invalid operands to opcode %s: `%s'"),
1447 instruction
->name
, operands
);
1451 /* Add rounding mode if present. */
1452 if (n_operands
== 3)
1453 opcodep
[2] = exp
[1].X_add_number
& 255;
1455 if (exp
[op2no
].X_op
== O_register
)
1456 opcodep
[3] = exp
[op2no
].X_add_number
;
1457 else if (exp
[op2no
].X_op
== O_constant
)
1459 opcodep
[3] = exp
[op2no
].X_add_number
;
1460 opcodep
[0] |= IMM_OFFSET_BIT
;
1463 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 3,
1465 instruction
->operands
== mmix_operands_roundregs
1466 ? BFD_RELOC_MMIX_REG
1467 : BFD_RELOC_MMIX_REG_OR_BYTE
);
1471 case mmix_operands_sync
:
1472 a_single_24_bit_number_operand
:
1474 || exp
[0].X_op
== O_register
1475 || (exp
[0].X_op
== O_constant
1476 && (exp
[0].X_add_number
> 0xffffff || exp
[0].X_add_number
< 0)))
1478 as_bad (_("invalid operands to opcode %s: `%s'"),
1479 instruction
->name
, operands
);
1483 if (exp
[0].X_op
== O_constant
)
1485 opcodep
[1] = (exp
[0].X_add_number
>> 16) & 255;
1486 opcodep
[2] = (exp
[0].X_add_number
>> 8) & 255;
1487 opcodep
[3] = exp
[0].X_add_number
& 255;
1490 /* FIXME: This doesn't bring us unsignedness checking. */
1491 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 1,
1492 3, exp
+ 0, 0, BFD_RELOC_24
);
1495 case mmix_operands_neg
:
1496 /* Operands "$X,Y,$Z|Z"; NEG or NEGU. Y is optional, 0 is default. */
1498 if ((n_operands
!= 3 && n_operands
!= 2)
1499 || (n_operands
== 3 && exp
[1].X_op
== O_register
)
1500 || ((exp
[1].X_op
== O_constant
|| exp
[1].X_op
== O_register
)
1501 && (exp
[1].X_add_number
> 255 || exp
[1].X_add_number
< 0))
1503 && ((exp
[2].X_op
== O_register
&& exp
[2].X_add_number
> 255)
1504 || (exp
[2].X_op
== O_constant
1505 && (exp
[2].X_add_number
> 255
1506 || exp
[2].X_add_number
< 0)))))
1508 as_bad (_("invalid operands to opcode %s: `%s'"),
1509 instruction
->name
, operands
);
1513 if (n_operands
== 2)
1515 if (exp
[1].X_op
== O_register
)
1516 opcodep
[3] = exp
[1].X_add_number
;
1517 else if (exp
[1].X_op
== O_constant
)
1519 opcodep
[3] = exp
[1].X_add_number
;
1520 opcodep
[0] |= IMM_OFFSET_BIT
;
1523 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 3,
1524 1, exp
+ 1, 0, BFD_RELOC_MMIX_REG_OR_BYTE
);
1528 if (exp
[1].X_op
== O_constant
)
1529 opcodep
[2] = exp
[1].X_add_number
;
1531 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 2,
1532 1, exp
+ 1, 0, BFD_RELOC_8
);
1534 if (exp
[2].X_op
== O_register
)
1535 opcodep
[3] = exp
[2].X_add_number
;
1536 else if (exp
[2].X_op
== O_constant
)
1538 opcodep
[3] = exp
[2].X_add_number
;
1539 opcodep
[0] |= IMM_OFFSET_BIT
;
1542 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 3,
1543 1, exp
+ 2, 0, BFD_RELOC_MMIX_REG_OR_BYTE
);
1546 case mmix_operands_regaddr
:
1547 /* A GETA/branch-type. */
1550 case mmix_operands_get
:
1551 /* "$X,spec_reg"; GET.
1552 Like with rounding modes, we demand that the special register or
1553 symbol is already defined when we get here at the point of use. */
1555 || (exp
[1].X_op
== O_register
1556 && (exp
[1].X_add_number
< 256 || exp
[1].X_add_number
>= 512))
1557 || (exp
[1].X_op
== O_constant
1558 && (exp
[1].X_add_number
< 0 || exp
[1].X_add_number
> 256))
1559 || (exp
[1].X_op
!= O_constant
&& exp
[1].X_op
!= O_register
))
1561 as_bad (_("invalid operands to opcode %s: `%s'"),
1562 instruction
->name
, operands
);
1566 opcodep
[3] = exp
[1].X_add_number
- 256;
1569 case mmix_operands_put
:
1570 /* "spec_reg,$Z|Z"; PUT. */
1572 || (exp
[0].X_op
== O_register
1573 && (exp
[0].X_add_number
< 256 || exp
[0].X_add_number
>= 512))
1574 || (exp
[0].X_op
== O_constant
1575 && (exp
[0].X_add_number
< 0 || exp
[0].X_add_number
> 256))
1576 || (exp
[0].X_op
!= O_constant
&& exp
[0].X_op
!= O_register
))
1578 as_bad (_("invalid operands to opcode %s: `%s'"),
1579 instruction
->name
, operands
);
1583 opcodep
[1] = exp
[0].X_add_number
- 256;
1585 /* Note that the Y field is zero. */
1587 if (exp
[1].X_op
== O_register
)
1588 opcodep
[3] = exp
[1].X_add_number
;
1589 else if (exp
[1].X_op
== O_constant
)
1591 opcodep
[3] = exp
[1].X_add_number
;
1592 opcodep
[0] |= IMM_OFFSET_BIT
;
1595 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 3,
1596 1, exp
+ 1, 0, BFD_RELOC_MMIX_REG_OR_BYTE
);
1599 case mmix_operands_save
:
1602 || exp
[1].X_op
!= O_constant
1603 || exp
[1].X_add_number
!= 0)
1605 as_bad (_("invalid operands to opcode %s: `%s'"),
1606 instruction
->name
, operands
);
1611 case mmix_operands_unsave
:
1612 if (n_operands
< 2 && ! mmix_gnu_syntax
)
1614 if (n_operands
== 1)
1616 if (exp
[0].X_op
== O_register
)
1617 opcodep
[3] = exp
[0].X_add_number
;
1619 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 3,
1620 1, exp
, 0, BFD_RELOC_MMIX_REG
);
1625 /* "0,$Z"; UNSAVE. */
1627 || exp
[0].X_op
!= O_constant
1628 || exp
[0].X_add_number
!= 0
1629 || exp
[1].X_op
== O_constant
1630 || (exp
[1].X_op
== O_register
1631 && exp
[1].X_add_number
> 255))
1633 as_bad (_("invalid operands to opcode %s: `%s'"),
1634 instruction
->name
, operands
);
1638 if (exp
[1].X_op
== O_register
)
1639 opcodep
[3] = exp
[1].X_add_number
;
1641 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 3,
1642 1, exp
+ 1, 0, BFD_RELOC_MMIX_REG
);
1645 case mmix_operands_xyz_opt
:
1646 /* SWYM, TRIP, TRAP: zero, one, two or three operands. */
1647 if (n_operands
== 0 && ! mmix_gnu_syntax
)
1648 /* Zeros are in place - nothing needs to be done for zero
1649 operands. We don't allow this in GNU syntax mode, because it
1650 was believed that the risk of missing to supply an operand is
1651 higher than the benefit of not having to specify a zero. */
1653 else if (n_operands
== 1 && exp
[0].X_op
!= O_register
)
1655 if (exp
[0].X_op
== O_constant
)
1657 if (exp
[0].X_add_number
> 255*255*255
1658 || exp
[0].X_add_number
< 0)
1660 as_bad (_("invalid operands to opcode %s: `%s'"),
1661 instruction
->name
, operands
);
1666 opcodep
[1] = (exp
[0].X_add_number
>> 16) & 255;
1667 opcodep
[2] = (exp
[0].X_add_number
>> 8) & 255;
1668 opcodep
[3] = exp
[0].X_add_number
& 255;
1672 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 1,
1673 3, exp
, 0, BFD_RELOC_24
);
1675 else if (n_operands
== 2
1676 && exp
[0].X_op
!= O_register
1677 && exp
[1].X_op
!= O_register
)
1681 if (exp
[0].X_op
== O_constant
)
1683 if (exp
[0].X_add_number
> 255
1684 || exp
[0].X_add_number
< 0)
1686 as_bad (_("invalid operands to opcode %s: `%s'"),
1687 instruction
->name
, operands
);
1691 opcodep
[1] = exp
[0].X_add_number
& 255;
1694 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 1,
1695 1, exp
, 0, BFD_RELOC_8
);
1697 if (exp
[1].X_op
== O_constant
)
1699 if (exp
[1].X_add_number
> 255*255
1700 || exp
[1].X_add_number
< 0)
1702 as_bad (_("invalid operands to opcode %s: `%s'"),
1703 instruction
->name
, operands
);
1708 opcodep
[2] = (exp
[1].X_add_number
>> 8) & 255;
1709 opcodep
[3] = exp
[1].X_add_number
& 255;
1713 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 2,
1714 2, exp
+ 1, 0, BFD_RELOC_16
);
1716 else if (n_operands
== 3
1717 && exp
[0].X_op
!= O_register
1718 && exp
[1].X_op
!= O_register
1719 && exp
[2].X_op
!= O_register
)
1721 /* Three operands. */
1723 if (exp
[0].X_op
== O_constant
)
1725 if (exp
[0].X_add_number
> 255
1726 || exp
[0].X_add_number
< 0)
1728 as_bad (_("invalid operands to opcode %s: `%s'"),
1729 instruction
->name
, operands
);
1733 opcodep
[1] = exp
[0].X_add_number
& 255;
1736 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 1,
1737 1, exp
, 0, BFD_RELOC_8
);
1739 if (exp
[1].X_op
== O_constant
)
1741 if (exp
[1].X_add_number
> 255
1742 || exp
[1].X_add_number
< 0)
1744 as_bad (_("invalid operands to opcode %s: `%s'"),
1745 instruction
->name
, operands
);
1749 opcodep
[2] = exp
[1].X_add_number
& 255;
1752 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 2,
1753 1, exp
+ 1, 0, BFD_RELOC_8
);
1755 if (exp
[2].X_op
== O_constant
)
1757 if (exp
[2].X_add_number
> 255
1758 || exp
[2].X_add_number
< 0)
1760 as_bad (_("invalid operands to opcode %s: `%s'"),
1761 instruction
->name
, operands
);
1765 opcodep
[3] = exp
[2].X_add_number
& 255;
1768 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 3,
1769 1, exp
+ 2, 0, BFD_RELOC_8
);
1771 else if (n_operands
<= 3
1772 && (strcmp (instruction
->name
, "trip") == 0
1773 || strcmp (instruction
->name
, "trap") == 0))
1775 /* The meaning of operands to TRIP and TRAP are not defined, so
1776 we add combinations not handled above here as we find them. */
1777 if (n_operands
== 3)
1779 /* Don't require non-register operands. Always generate
1780 fixups, so we don't have to copy lots of code and create
1781 maintanance problems. TRIP is supposed to be a rare
1782 instruction, so the overhead should not matter. We
1783 aren't allowed to fix_new_exp for an expression which is
1784 an O_register at this point, however. */
1785 if (exp
[0].X_op
== O_register
)
1786 opcodep
[1] = exp
[0].X_add_number
;
1788 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 1,
1789 1, exp
, 0, BFD_RELOC_MMIX_REG_OR_BYTE
);
1790 if (exp
[1].X_op
== O_register
)
1791 opcodep
[2] = exp
[1].X_add_number
;
1793 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 2,
1794 1, exp
+ 1, 0, BFD_RELOC_MMIX_REG_OR_BYTE
);
1795 if (exp
[2].X_op
== O_register
)
1796 opcodep
[3] = exp
[2].X_add_number
;
1798 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 3,
1799 1, exp
+ 2, 0, BFD_RELOC_MMIX_REG_OR_BYTE
);
1801 else if (n_operands
== 2)
1803 if (exp
[0].X_op
== O_register
)
1804 opcodep
[2] = exp
[0].X_add_number
;
1806 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 2,
1807 1, exp
, 0, BFD_RELOC_MMIX_REG_OR_BYTE
);
1808 if (exp
[1].X_op
== O_register
)
1809 opcodep
[3] = exp
[1].X_add_number
;
1811 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 3,
1812 1, exp
+ 1, 0, BFD_RELOC_MMIX_REG_OR_BYTE
);
1816 as_bad (_("unsupported operands to %s: `%s'"),
1817 instruction
->name
, operands
);
1823 as_bad (_("invalid operands to opcode %s: `%s'"),
1824 instruction
->name
, operands
);
1829 case mmix_operands_resume
:
1830 if (n_operands
== 0 && ! mmix_gnu_syntax
)
1834 || exp
[0].X_op
== O_register
1835 || (exp
[0].X_op
== O_constant
1836 && (exp
[0].X_add_number
< 0
1837 || exp
[0].X_add_number
> 255)))
1839 as_bad (_("invalid operands to opcode %s: `%s'"),
1840 instruction
->name
, operands
);
1844 if (exp
[0].X_op
== O_constant
)
1845 opcodep
[3] = exp
[0].X_add_number
;
1847 fix_new_exp (opc_fragP
, opcodep
- opc_fragP
->fr_literal
+ 3,
1848 1, exp
+ 0, 0, BFD_RELOC_8
);
1851 case mmix_operands_pushj
:
1852 /* All is done for PUSHJ already. */
1856 BAD_CASE (instruction
->operands
);
1860 /* For the benefit of insns that start with a digit, we assemble by way of
1861 tc_unrecognized_line too, through this function. */
1864 mmix_assemble_return_nonzero (str
)
1867 int last_error_count
= had_errors ();
1871 /* Normal instruction handling downcases, so we must too. */
1872 while (ISALNUM (*s2
))
1874 if (ISUPPER ((unsigned char) *s2
))
1875 *s2
= TOLOWER (*s2
);
1879 /* Cut the line for sake of the assembly. */
1880 for (s2
= str
; *s2
&& *s2
!= '\n'; s2
++)
1888 return had_errors () == last_error_count
;
1891 /* The PREFIX pseudo. */
1895 int unused ATTRIBUTE_UNUSED
;
1902 p
= input_line_pointer
;
1904 c
= get_symbol_end ();
1906 /* Reseting prefix? */
1907 if (*p
== ':' && p
[1] == 0)
1908 mmix_current_prefix
= NULL
;
1911 /* Put this prefix on the mmix symbols obstack. We could malloc and
1912 free it separately, but then we'd have to worry about that.
1913 People using up memory on prefixes have other problems. */
1914 obstack_grow (&mmix_sym_obstack
, p
, strlen (p
) + 1);
1915 p
= obstack_finish (&mmix_sym_obstack
);
1917 /* Accumulate prefixes, and strip a leading ':'. */
1918 if (mmix_current_prefix
!= NULL
|| *p
== ':')
1919 p
= mmix_prefix_name (p
);
1921 mmix_current_prefix
= p
;
1924 *input_line_pointer
= c
;
1926 mmix_handle_rest_of_empty_line ();
1929 /* We implement prefixes by using the tc_canonicalize_symbol_name hook,
1930 and store each prefixed name on a (separate) obstack. This means that
1931 the name is on the "notes" obstack in non-prefixed form and on the
1932 mmix_sym_obstack in prefixed form, but currently it is not worth
1933 rewriting the whole GAS symbol handling to improve "hooking" to avoid
1934 that. (It might be worth a rewrite for other reasons, though). */
1937 mmix_prefix_name (shortname
)
1940 if (*shortname
== ':')
1941 return shortname
+ 1;
1943 if (mmix_current_prefix
== NULL
)
1944 as_fatal (_("internal: mmix_prefix_name but empty prefix"));
1946 if (*shortname
== '$')
1949 obstack_grow (&mmix_sym_obstack
, mmix_current_prefix
,
1950 strlen (mmix_current_prefix
));
1951 obstack_grow (&mmix_sym_obstack
, shortname
, strlen (shortname
) + 1);
1952 return obstack_finish (&mmix_sym_obstack
);
1955 /* The GREG pseudo. At LABEL, we have the name of a symbol that we
1956 want to make a register symbol, and which should be initialized with
1957 the value in the expression at INPUT_LINE_POINTER (defaulting to 0).
1958 Either and (perhaps less meaningful) both may be missing. LABEL must
1959 be persistent, perhaps allocated on an obstack. */
1962 mmix_greg_internal (label
)
1965 expressionS
*expP
= &mmix_raw_gregs
[n_of_raw_gregs
].exp
;
1967 /* Don't set the section to register contents section before the
1968 expression has been parsed; it may refer to the current position. */
1971 /* FIXME: Check that no expression refers to the register contents
1972 section. May need to be done in elf64-mmix.c. */
1973 if (expP
->X_op
== O_absent
)
1975 /* Default to zero if the expression was absent. */
1976 expP
->X_op
= O_constant
;
1977 expP
->X_add_number
= 0;
1978 expP
->X_unsigned
= 0;
1979 expP
->X_add_symbol
= NULL
;
1980 expP
->X_op_symbol
= NULL
;
1983 /* We must handle prefixes here, as we save the labels and expressions
1984 to be output later. */
1985 mmix_raw_gregs
[n_of_raw_gregs
].label
1986 = mmix_current_prefix
== NULL
? label
: mmix_prefix_name (label
);
1988 if (n_of_raw_gregs
== MAX_GREGS
- 1)
1989 as_bad (_("too many GREG registers allocated (max %d)"), MAX_GREGS
);
1993 mmix_handle_rest_of_empty_line ();
1996 /* The ".greg label,expr" worker. */
2000 int unused ATTRIBUTE_UNUSED
;
2004 p
= input_line_pointer
;
2006 /* This will skip over what can be a symbol and zero out the next
2007 character, which we assume is a ',' or other meaningful delimiter.
2008 What comes after that is the initializer expression for the
2010 c
= get_symbol_end ();
2012 if (! is_end_of_line
[(unsigned char) c
])
2013 input_line_pointer
++;
2017 /* The label must be persistent; it's not used until after all input
2019 obstack_grow (&mmix_sym_obstack
, p
, strlen (p
) + 1);
2020 mmix_greg_internal (obstack_finish (&mmix_sym_obstack
));
2023 mmix_greg_internal (NULL
);
2026 /* The "BSPEC expr" worker. */
2030 int unused ATTRIBUTE_UNUSED
;
2034 char secname
[sizeof (MMIX_OTHER_SPEC_SECTION_PREFIX
) + 20]
2035 = MMIX_OTHER_SPEC_SECTION_PREFIX
;
2039 /* Get a constant expression which we can evaluate *now*. Supporting
2040 more complex (though assembly-time computable) expressions is
2041 feasible but Too Much Work for something of unknown usefulness like
2043 expsec
= expression (&exp
);
2044 mmix_handle_rest_of_empty_line ();
2046 /* Check that we don't have another BSPEC in progress. */
2049 as_bad (_("BSPEC already active. Nesting is not supported."));
2053 if (exp
.X_op
!= O_constant
2054 || expsec
!= absolute_section
2055 || exp
.X_add_number
< 0
2056 || exp
.X_add_number
> 65535)
2058 as_bad (_("invalid BSPEC expression"));
2059 exp
.X_add_number
= 0;
2062 n
= (int) exp
.X_add_number
;
2064 sprintf (secname
+ strlen (MMIX_OTHER_SPEC_SECTION_PREFIX
), "%d", n
);
2065 sec
= bfd_get_section_by_name (stdoutput
, secname
);
2068 /* We need a non-volatile name as it will be stored in the section
2070 char *newsecname
= xstrdup (secname
);
2071 sec
= bfd_make_section (stdoutput
, newsecname
);
2074 as_fatal (_("can't create section %s"), newsecname
);
2076 if (!bfd_set_section_flags (stdoutput
, sec
,
2077 bfd_get_section_flags (stdoutput
, sec
)
2079 as_fatal (_("can't set section flags for section %s"), newsecname
);
2082 /* Tell ELF about the pending section change. */
2083 obj_elf_section_change_hook ();
2084 subseg_set (sec
, 0);
2086 /* Save position for missing ESPEC. */
2087 as_where (&bspec_file
, &bspec_line
);
2092 /* The "ESPEC" worker. */
2096 int unused ATTRIBUTE_UNUSED
;
2098 /* First, check that we *do* have a BSPEC in progress. */
2101 as_bad (_("ESPEC without preceding BSPEC"));
2105 mmix_handle_rest_of_empty_line ();
2108 /* When we told ELF about the section change in s_bspec, it stored the
2109 previous section for us so we can get at it with the equivalent of a
2110 .previous pseudo. */
2111 obj_elf_previous (0);
2114 /* The " .local expr" and " local expr" worker. We make a BFD_MMIX_LOCAL
2115 relocation against the current position against the expression.
2116 Implementing this by means of contents in a section lost. */
2119 mmix_s_local (unused
)
2120 int unused ATTRIBUTE_UNUSED
;
2124 /* Don't set the section to register contents section before the
2125 expression has been parsed; it may refer to the current position in
2126 some contorted way. */
2129 if (exp
.X_op
== O_absent
)
2131 as_bad (_("missing local expression"));
2134 else if (exp
.X_op
== O_register
)
2136 /* fix_new_exp doesn't like O_register. Should be configurable.
2137 We're fine with a constant here, though. */
2138 exp
.X_op
= O_constant
;
2141 fix_new_exp (frag_now
, 0, 0, &exp
, 0, BFD_RELOC_MMIX_LOCAL
);
2142 mmix_handle_rest_of_empty_line ();
2145 /* Set fragP->fr_var to the initial guess of the size of a relaxable insn
2146 and return it. Sizes of other instructions are not known. This
2147 function may be called multiple times. */
2150 md_estimate_size_before_relax (fragP
, segment
)
2156 #define HANDLE_RELAXABLE(state) \
2157 case ENCODE_RELAX (state, STATE_UNDF): \
2158 if (fragP->fr_symbol != NULL \
2159 && S_GET_SEGMENT (fragP->fr_symbol) == segment) \
2161 /* The symbol lies in the same segment - a relaxable case. */ \
2163 = ENCODE_RELAX (state, STATE_ZERO); \
2167 switch (fragP
->fr_subtype
)
2169 HANDLE_RELAXABLE (STATE_GETA
);
2170 HANDLE_RELAXABLE (STATE_BCC
);
2171 HANDLE_RELAXABLE (STATE_PUSHJ
);
2172 HANDLE_RELAXABLE (STATE_JMP
);
2174 case ENCODE_RELAX (STATE_GETA
, STATE_ZERO
):
2175 case ENCODE_RELAX (STATE_BCC
, STATE_ZERO
):
2176 case ENCODE_RELAX (STATE_PUSHJ
, STATE_ZERO
):
2177 case ENCODE_RELAX (STATE_JMP
, STATE_ZERO
):
2178 /* When relaxing a section for the second time, we don't need to do
2179 anything except making sure that fr_var is set right. */
2182 case STATE_GREG_DEF
:
2183 length
= fragP
->tc_frag_data
!= NULL
? 0 : 8;
2184 fragP
->fr_var
= length
;
2186 /* Don't consult the relax_table; it isn't valid for this
2192 BAD_CASE (fragP
->fr_subtype
);
2195 length
= mmix_relax_table
[fragP
->fr_subtype
].rlx_length
;
2196 fragP
->fr_var
= length
;
2201 /* Turn a string in input_line_pointer into a floating point constant of type
2202 type, and store the appropriate bytes in *litP. The number of LITTLENUMS
2203 emitted is stored in *sizeP . An error message is returned, or NULL on
2207 md_atof (type
, litP
, sizeP
)
2213 LITTLENUM_TYPE words
[4];
2219 /* FIXME: Having 'f' in mmix_flt_chars (and here) makes it
2220 problematic to also have a forward reference in an expression.
2221 The testsuite wants it, and it's customary.
2222 We'll deal with the real problems when they come; we share the
2223 problem with most other ports. */
2233 return _("bad call to md_atof");
2236 t
= atof_ieee (input_line_pointer
, type
, words
);
2238 input_line_pointer
= t
;
2242 for (i
= 0; i
< prec
; i
++)
2244 md_number_to_chars (litP
, (valueT
) words
[i
], 2);
2250 /* Convert variable-sized frags into one or more fixups. */
2253 md_convert_frag (abfd
, sec
, fragP
)
2254 bfd
*abfd ATTRIBUTE_UNUSED
;
2255 segT sec ATTRIBUTE_UNUSED
;
2258 /* Pointer to first byte in variable-sized part of the frag. */
2261 /* Pointer to first opcode byte in frag. */
2264 /* Size in bytes of variable-sized part of frag. */
2265 int var_part_size
= 0;
2267 /* This is part of *fragP. It contains all information about addresses
2268 and offsets to varying parts. */
2270 unsigned long var_part_offset
;
2272 /* This is the frag for the opcode. It, rather than fragP, must be used
2273 when emitting a frag for the opcode. */
2274 fragS
*opc_fragP
= fragP
->tc_frag_data
;
2277 /* Where, in file space, does addr point? */
2278 bfd_vma target_address
;
2279 bfd_vma opcode_address
;
2281 know (fragP
->fr_type
== rs_machine_dependent
);
2283 var_part_offset
= fragP
->fr_fix
;
2284 var_partp
= fragP
->fr_literal
+ var_part_offset
;
2285 opcodep
= fragP
->fr_opcode
;
2287 symbolP
= fragP
->fr_symbol
;
2290 = ((symbolP
? S_GET_VALUE (symbolP
) : 0) + fragP
->fr_offset
);
2292 /* The opcode that would be extended is the last four "fixed" bytes. */
2293 opcode_address
= fragP
->fr_address
+ fragP
->fr_fix
- 4;
2295 switch (fragP
->fr_subtype
)
2297 case ENCODE_RELAX (STATE_GETA
, STATE_ZERO
):
2298 case ENCODE_RELAX (STATE_BCC
, STATE_ZERO
):
2299 case ENCODE_RELAX (STATE_PUSHJ
, STATE_ZERO
):
2300 mmix_set_geta_branch_offset (opcodep
, target_address
- opcode_address
);
2304 = fix_new (opc_fragP
, opcodep
- opc_fragP
->fr_literal
, 4,
2305 fragP
->fr_symbol
, fragP
->fr_offset
, 1,
2306 BFD_RELOC_MMIX_ADDR19
);
2307 COPY_FR_WHERE_TO_FX (fragP
, tmpfixP
);
2312 case ENCODE_RELAX (STATE_JMP
, STATE_ZERO
):
2313 mmix_set_jmp_offset (opcodep
, target_address
- opcode_address
);
2317 = fix_new (opc_fragP
, opcodep
- opc_fragP
->fr_literal
, 4,
2318 fragP
->fr_symbol
, fragP
->fr_offset
, 1,
2319 BFD_RELOC_MMIX_ADDR27
);
2320 COPY_FR_WHERE_TO_FX (fragP
, tmpfixP
);
2325 case STATE_GREG_DEF
:
2326 if (fragP
->tc_frag_data
== NULL
)
2329 = fix_new (fragP
, var_partp
- fragP
->fr_literal
, 8,
2330 fragP
->fr_symbol
, fragP
->fr_offset
, 0, BFD_RELOC_64
);
2331 COPY_FR_WHERE_TO_FX (fragP
, tmpfixP
);
2332 mmix_gregs
[n_of_cooked_gregs
++] = tmpfixP
;
2339 #define HANDLE_MAX_RELOC(state, reloc) \
2340 case ENCODE_RELAX (state, STATE_MAX): \
2342 = mmix_relax_table[ENCODE_RELAX (state, STATE_MAX)].rlx_length; \
2343 mmix_fill_nops (var_partp, var_part_size / 4); \
2344 if (warn_on_expansion) \
2345 as_warn_where (fragP->fr_file, fragP->fr_line, \
2346 _("operand out of range, instruction expanded")); \
2347 tmpfixP = fix_new (fragP, var_partp - fragP->fr_literal - 4, 8, \
2348 fragP->fr_symbol, fragP->fr_offset, 1, reloc); \
2349 COPY_FR_WHERE_TO_FX (fragP, tmpfixP); \
2352 HANDLE_MAX_RELOC (STATE_GETA
, BFD_RELOC_MMIX_GETA
);
2353 HANDLE_MAX_RELOC (STATE_BCC
, BFD_RELOC_MMIX_CBRANCH
);
2354 HANDLE_MAX_RELOC (STATE_PUSHJ
, BFD_RELOC_MMIX_PUSHJ
);
2355 HANDLE_MAX_RELOC (STATE_JMP
, BFD_RELOC_MMIX_JMP
);
2358 BAD_CASE (fragP
->fr_subtype
);
2362 fragP
->fr_fix
+= var_part_size
;
2366 /* Applies the desired value to the specified location.
2367 Also sets up addends for RELA type relocations.
2368 Stolen from tc-mcore.c.
2370 Note that this function isn't called when linkrelax != 0. */
2373 md_apply_fix3 (fixP
, valP
, segment
)
2378 char *buf
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
2379 /* Note: use offsetT because it is signed, valueT is unsigned. */
2380 offsetT val
= (offsetT
) * valP
;
2382 = (fixP
->fx_addsy
== NULL
2383 ? absolute_section
: S_GET_SEGMENT (fixP
->fx_addsy
));
2385 /* If the fix is relative to a symbol which is not defined, or, (if
2386 pcrel), not in the same segment as the fix, we cannot resolve it
2388 if (fixP
->fx_addsy
!= NULL
2389 && (! S_IS_DEFINED (fixP
->fx_addsy
)
2390 || S_IS_WEAK (fixP
->fx_addsy
)
2391 || (fixP
->fx_pcrel
&& symsec
!= segment
)
2392 || (! fixP
->fx_pcrel
2393 && symsec
!= absolute_section
2394 && ((fixP
->fx_r_type
!= BFD_RELOC_MMIX_REG
2395 && fixP
->fx_r_type
!= BFD_RELOC_MMIX_REG_OR_BYTE
)
2396 || (symsec
!= reg_section
2397 && symsec
!= real_reg_section
)))))
2402 else if (fixP
->fx_r_type
== BFD_RELOC_MMIX_LOCAL
2403 || fixP
->fx_r_type
== BFD_RELOC_VTABLE_INHERIT
2404 || fixP
->fx_r_type
== BFD_RELOC_VTABLE_ENTRY
)
2406 /* These are never "fixed". */
2411 /* We assume every other relocation is "fixed". */
2414 switch (fixP
->fx_r_type
)
2421 case BFD_RELOC_64_PCREL
:
2422 case BFD_RELOC_32_PCREL
:
2423 case BFD_RELOC_24_PCREL
:
2424 case BFD_RELOC_16_PCREL
:
2425 case BFD_RELOC_8_PCREL
:
2426 md_number_to_chars (buf
, val
, fixP
->fx_size
);
2429 case BFD_RELOC_MMIX_ADDR19
:
2432 /* This shouldn't happen. */
2433 BAD_CASE (fixP
->fx_r_type
);
2437 case BFD_RELOC_MMIX_GETA
:
2438 case BFD_RELOC_MMIX_CBRANCH
:
2439 case BFD_RELOC_MMIX_PUSHJ
:
2440 /* If this fixup is out of range, punt to the linker to emit an
2441 error. This should only happen with -no-expand. */
2442 if (val
< -(((offsetT
) 1 << 19)/2)
2443 || val
>= ((offsetT
) 1 << 19)/2 - 1
2446 if (warn_on_expansion
)
2447 as_warn_where (fixP
->fx_file
, fixP
->fx_line
,
2448 _("operand out of range"));
2452 mmix_set_geta_branch_offset (buf
, val
);
2455 case BFD_RELOC_MMIX_ADDR27
:
2458 /* This shouldn't happen. */
2459 BAD_CASE (fixP
->fx_r_type
);
2463 case BFD_RELOC_MMIX_JMP
:
2464 /* If this fixup is out of range, punt to the linker to emit an
2465 error. This should only happen with -no-expand. */
2466 if (val
< -(((offsetT
) 1 << 27)/2)
2467 || val
>= ((offsetT
) 1 << 27)/2 - 1
2470 if (warn_on_expansion
)
2471 as_warn_where (fixP
->fx_file
, fixP
->fx_line
,
2472 _("operand out of range"));
2476 mmix_set_jmp_offset (buf
, val
);
2479 case BFD_RELOC_MMIX_REG_OR_BYTE
:
2480 if (fixP
->fx_addsy
!= NULL
2481 && (S_GET_SEGMENT (fixP
->fx_addsy
) != real_reg_section
2482 || S_GET_VALUE (fixP
->fx_addsy
) > 255)
2483 && S_GET_SEGMENT (fixP
->fx_addsy
) != absolute_section
)
2484 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
2485 _("invalid operands"));
2488 /* If this reloc is for a Z field, we need to adjust
2489 the opcode if we got a constant here.
2490 FIXME: Can we make this more robust? */
2492 if ((fixP
->fx_where
& 3) == 3
2493 && (fixP
->fx_addsy
== NULL
2494 || S_GET_SEGMENT (fixP
->fx_addsy
) == absolute_section
))
2495 buf
[-3] |= IMM_OFFSET_BIT
;
2497 /* We don't want this "symbol" appearing in output, because that
2500 && S_GET_SEGMENT (fixP
->fx_addsy
) == real_reg_section
)
2501 symbol_clear_used_in_reloc (fixP
->fx_addsy
);
2504 case BFD_RELOC_MMIX_REG
:
2505 if (fixP
->fx_addsy
== NULL
2506 || S_GET_SEGMENT (fixP
->fx_addsy
) != real_reg_section
2507 || S_GET_VALUE (fixP
->fx_addsy
) > 255)
2508 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
2509 _("invalid operands"));
2513 && S_GET_SEGMENT (fixP
->fx_addsy
) == real_reg_section
)
2514 symbol_clear_used_in_reloc (fixP
->fx_addsy
);
2517 case BFD_RELOC_MMIX_BASE_PLUS_OFFSET
:
2518 /* These are never "fixed". */
2522 case BFD_RELOC_MMIX_PUSHJ_1
:
2523 case BFD_RELOC_MMIX_PUSHJ_2
:
2524 case BFD_RELOC_MMIX_PUSHJ_3
:
2525 case BFD_RELOC_MMIX_CBRANCH_J
:
2526 case BFD_RELOC_MMIX_CBRANCH_1
:
2527 case BFD_RELOC_MMIX_CBRANCH_2
:
2528 case BFD_RELOC_MMIX_CBRANCH_3
:
2529 case BFD_RELOC_MMIX_GETA_1
:
2530 case BFD_RELOC_MMIX_GETA_2
:
2531 case BFD_RELOC_MMIX_GETA_3
:
2532 case BFD_RELOC_MMIX_JMP_1
:
2533 case BFD_RELOC_MMIX_JMP_2
:
2534 case BFD_RELOC_MMIX_JMP_3
:
2536 BAD_CASE (fixP
->fx_r_type
);
2541 /* Make sure that for completed fixups we have the value around for
2542 use by e.g. mmix_frob_file. */
2543 fixP
->fx_offset
= val
;
2546 /* A bsearch function for looking up a value against offsets for GREG
2550 cmp_greg_val_greg_symbol_fixes (p1
, p2
)
2554 offsetT val1
= *(offsetT
*) p1
;
2555 offsetT val2
= ((struct mmix_symbol_greg_fixes
*) p2
)->offs
;
2557 if (val1
>= val2
&& val1
< val2
+ 255)
2566 /* Generate a machine-dependent relocation. */
2569 tc_gen_reloc (section
, fixP
)
2570 asection
*section ATTRIBUTE_UNUSED
;
2574 = fixP
->fx_offset
+ (fixP
->fx_addsy
? S_GET_VALUE (fixP
->fx_addsy
) : 0);
2576 bfd_reloc_code_real_type code
= BFD_RELOC_NONE
;
2577 char *buf
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
2578 symbolS
*addsy
= fixP
->fx_addsy
;
2579 asection
*addsec
= addsy
== NULL
? NULL
: S_GET_SEGMENT (addsy
);
2580 bfd_vma addend
= fixP
->fx_offset
;
2581 asymbol
*baddsy
= addsy
!= NULL
? symbol_get_bfdsym (addsy
) : NULL
;
2583 /* A single " LOCAL expression" in the wrong section will not work when
2584 linking to MMO; relocations for zero-content sections are then
2585 ignored. Normally, relocations would modify section contents, and
2586 you'd never think or be able to do something like that. The
2587 relocation resulting from a LOCAL directive doesn't have an obvious
2588 and mandatory location. I can't figure out a way to do this better
2589 than just helping the user around this limitation here; hopefully the
2590 code using the local expression is around. Putting the LOCAL
2591 semantics in a relocation still seems right; a section didn't do. */
2592 if (bfd_section_size (section
->owner
, section
) == 0)
2594 (fixP
->fx_file
, fixP
->fx_line
,
2595 fixP
->fx_r_type
== BFD_RELOC_MMIX_LOCAL
2596 /* The BFD_RELOC_MMIX_LOCAL-specific message is supposed to be
2597 user-friendly, though a little bit non-substantial. */
2598 ? _("directive LOCAL must be placed in code or data")
2599 : _("internal confusion: relocation in a section without contents"));
2601 /* FIXME: Range tests for all these. */
2602 switch (fixP
->fx_r_type
)
2609 code
= fixP
->fx_r_type
;
2612 || bfd_is_abs_section (S_GET_SEGMENT (addsy
)))
2614 /* Resolve this reloc now, as md_apply_fix3 would have done (not
2615 called if -linkrelax). There is no point in keeping a reloc
2616 to an absolute symbol. No reloc that is subject to
2617 relaxation must be to an absolute symbol; difference
2618 involving symbols in a specific section must be signalled as
2619 an error if the relaxing cannot be expressed; having a reloc
2620 to the resolved (now absolute) value does not help. */
2621 md_number_to_chars (buf
, val
, fixP
->fx_size
);
2626 case BFD_RELOC_64_PCREL
:
2627 case BFD_RELOC_32_PCREL
:
2628 case BFD_RELOC_24_PCREL
:
2629 case BFD_RELOC_16_PCREL
:
2630 case BFD_RELOC_8_PCREL
:
2631 case BFD_RELOC_MMIX_LOCAL
:
2632 case BFD_RELOC_VTABLE_INHERIT
:
2633 case BFD_RELOC_VTABLE_ENTRY
:
2634 case BFD_RELOC_MMIX_GETA
:
2635 case BFD_RELOC_MMIX_GETA_1
:
2636 case BFD_RELOC_MMIX_GETA_2
:
2637 case BFD_RELOC_MMIX_GETA_3
:
2638 case BFD_RELOC_MMIX_CBRANCH
:
2639 case BFD_RELOC_MMIX_CBRANCH_J
:
2640 case BFD_RELOC_MMIX_CBRANCH_1
:
2641 case BFD_RELOC_MMIX_CBRANCH_2
:
2642 case BFD_RELOC_MMIX_CBRANCH_3
:
2643 case BFD_RELOC_MMIX_PUSHJ
:
2644 case BFD_RELOC_MMIX_PUSHJ_1
:
2645 case BFD_RELOC_MMIX_PUSHJ_2
:
2646 case BFD_RELOC_MMIX_PUSHJ_3
:
2647 case BFD_RELOC_MMIX_JMP
:
2648 case BFD_RELOC_MMIX_JMP_1
:
2649 case BFD_RELOC_MMIX_JMP_2
:
2650 case BFD_RELOC_MMIX_JMP_3
:
2651 case BFD_RELOC_MMIX_ADDR19
:
2652 case BFD_RELOC_MMIX_ADDR27
:
2653 code
= fixP
->fx_r_type
;
2656 case BFD_RELOC_MMIX_REG_OR_BYTE
:
2657 /* If we have this kind of relocation to an unknown symbol or to the
2658 register contents section (that is, to a register), then we can't
2659 resolve the relocation here. */
2661 && (bfd_is_und_section (S_GET_SEGMENT (addsy
))
2662 || strcmp (bfd_get_section_name (addsec
->owner
, addsec
),
2663 MMIX_REG_CONTENTS_SECTION_NAME
) == 0))
2665 code
= fixP
->fx_r_type
;
2669 /* If the relocation is not to the register section or to the
2670 absolute section (a numeric value), then we have an error. */
2672 && (S_GET_SEGMENT (addsy
) != real_reg_section
2675 && ! bfd_is_abs_section (S_GET_SEGMENT (addsy
)))
2678 /* Set the "immediate" bit of the insn if this relocation is to Z
2679 field when the value is a numeric value, i.e. not a register. */
2680 if ((fixP
->fx_where
& 3) == 3
2682 || S_GET_SEGMENT (addsy
) == absolute_section
))
2683 buf
[-3] |= IMM_OFFSET_BIT
;
2688 case BFD_RELOC_MMIX_BASE_PLUS_OFFSET
:
2690 && strcmp (bfd_get_section_name (addsec
->owner
, addsec
),
2691 MMIX_REG_CONTENTS_SECTION_NAME
) == 0)
2693 /* This changed into a register; the relocation is for the
2694 register-contents section. The constant part remains zero. */
2695 code
= BFD_RELOC_MMIX_REG
;
2699 /* If we've found out that this was indeed a register, then replace
2700 with the register number. The constant part is already zero.
2702 If we encounter any other defined symbol, then we must find a
2703 suitable register and emit a reloc. */
2705 || S_GET_SEGMENT (addsy
) != real_reg_section
)
2707 struct mmix_symbol_gregs
*gregs
;
2708 struct mmix_symbol_greg_fixes
*fix
;
2710 if (S_IS_DEFINED (addsy
))
2712 if (! symbol_section_p (addsy
)
2713 && ! bfd_is_abs_section (S_GET_SEGMENT (addsy
)))
2714 as_fatal (_("internal: BFD_RELOC_MMIX_BASE_PLUS_OFFSET not resolved to section"));
2716 /* If this is an absolute symbol sufficiently near
2717 lowest_data_loc, then we canonicalize on the data
2718 section. Note that val is signed here; we may subtract
2719 lowest_data_loc which is unsigned. Careful with those
2721 if (lowest_data_loc
!= (bfd_vma
) -1
2722 && (bfd_vma
) val
+ 256 > lowest_data_loc
2723 && bfd_is_abs_section (S_GET_SEGMENT (addsy
)))
2725 val
-= (offsetT
) lowest_data_loc
;
2726 addsy
= section_symbol (data_section
);
2728 /* Likewise text section. */
2729 else if (lowest_text_loc
!= (bfd_vma
) -1
2730 && (bfd_vma
) val
+ 256 > lowest_text_loc
2731 && bfd_is_abs_section (S_GET_SEGMENT (addsy
)))
2733 val
-= (offsetT
) lowest_text_loc
;
2734 addsy
= section_symbol (text_section
);
2738 gregs
= *symbol_get_tc (addsy
);
2740 /* If that symbol does not have any associated GREG definitions,
2741 we can't do anything. FIXME: implement allocate-on-demand in
2744 || (fix
= bsearch (&val
, gregs
->greg_fixes
, gregs
->n_gregs
,
2745 sizeof (gregs
->greg_fixes
[0]),
2746 cmp_greg_val_greg_symbol_fixes
)) == NULL
2747 /* The register must not point *after* the address we want. */
2749 /* Neither must the register point more than 255 bytes
2750 before the address we want. */
2751 || fix
->offs
+ 255 < val
)
2753 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
2754 _("no suitable GREG definition for operands"));
2759 /* Transform the base-plus-offset reloc for the actual area
2760 to a reloc for the register with the address of the area.
2761 Put addend for register in Z operand. */
2762 buf
[1] = val
- fix
->offs
;
2763 code
= BFD_RELOC_MMIX_REG
;
2765 = (bfd_get_section_by_name (stdoutput
,
2766 MMIX_REG_CONTENTS_SECTION_NAME
)
2769 addend
= fix
->fix
->fx_frag
->fr_address
+ fix
->fix
->fx_where
;
2772 else if (S_GET_VALUE (addsy
) > 255)
2773 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
2774 _("invalid operands"));
2782 case BFD_RELOC_MMIX_REG
:
2784 && (bfd_is_und_section (S_GET_SEGMENT (addsy
))
2785 || strcmp (bfd_get_section_name (addsec
->owner
, addsec
),
2786 MMIX_REG_CONTENTS_SECTION_NAME
) == 0))
2788 code
= fixP
->fx_r_type
;
2793 && (S_GET_SEGMENT (addsy
) != real_reg_section
2796 && ! bfd_is_und_section (S_GET_SEGMENT (addsy
)))
2797 /* Drop through to error message. */
2806 /* The others are supposed to be handled by md_apply_fix3.
2807 FIXME: ... which isn't called when -linkrelax. Move over
2808 md_apply_fix3 code here for everything reasonable. */
2812 (fixP
->fx_file
, fixP
->fx_line
,
2813 _("operands were not reducible at assembly-time"));
2815 /* Unmark this symbol as used in a reloc, so we don't bump into a BFD
2816 assert when trying to output reg_section. FIXME: A gas bug. */
2818 symbol_clear_used_in_reloc (addsy
);
2822 relP
= (arelent
*) xmalloc (sizeof (arelent
));
2824 relP
->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
2825 *relP
->sym_ptr_ptr
= baddsy
;
2826 relP
->address
= fixP
->fx_frag
->fr_address
+ fixP
->fx_where
;
2828 relP
->addend
= addend
;
2830 /* If this had been a.out, we would have had a kludge for weak symbols
2833 relP
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
2838 name
= S_GET_NAME (addsy
);
2840 name
= _("<unknown>");
2841 as_fatal (_("cannot generate relocation type for symbol %s, code %s"),
2842 name
, bfd_get_reloc_code_name (code
));
2848 /* Do some reformatting of a line. FIXME: We could transform a mmixal
2849 line into traditional (GNU?) format, unless #NO_APP, and get rid of all
2850 ugly labels_without_colons etc. */
2853 mmix_handle_mmixal ()
2855 char *s0
= input_line_pointer
;
2860 if (pending_label
!= NULL
)
2861 as_fatal (_("internal: unhandled label %s"), pending_label
);
2863 if (mmix_gnu_syntax
)
2866 /* If the first character is a '.', then it's a pseudodirective, not a
2867 label. Make GAS not handle label-without-colon on this line. We
2868 also don't do mmixal-specific stuff on this line. */
2869 if (input_line_pointer
[0] == '.')
2871 label_without_colon_this_line
= 0;
2875 /* Don't handle empty lines here. */
2878 if (*s0
== 0 || is_end_of_line
[(unsigned int) *s0
])
2881 if (! ISSPACE (*s0
))
2887 /* If we're on a line with a label, check if it's a mmixal fb-label.
2888 Save an indicator and skip the label; it must be set only after all
2889 fb-labels of expressions are evaluated. */
2890 if (ISDIGIT (input_line_pointer
[0])
2891 && input_line_pointer
[1] == 'H'
2892 && ISSPACE (input_line_pointer
[2]))
2895 current_fb_label
= input_line_pointer
[0] - '0';
2897 /* We have to skip the label, but also preserve the newlineness of
2898 the previous character, since the caller checks that. It's a
2899 mess we blame on the caller. */
2900 input_line_pointer
[1] = input_line_pointer
[-1];
2901 input_line_pointer
+= 2;
2903 s
= input_line_pointer
;
2904 while (*s
&& ISSPACE (*s
) && ! is_end_of_line
[(unsigned int) *s
])
2907 /* For errors emitted here, the book-keeping is off by one; the
2908 caller is about to bump the counters. Adjust the error messages. */
2909 if (is_end_of_line
[(unsigned int) *s
])
2913 as_where (&name
, &line
);
2914 as_bad_where (name
, line
+ 1,
2915 _("[0-9]H labels may not appear alone on a line"));
2916 current_fb_label
= -1;
2922 as_where (&name
, &line
);
2923 as_bad_where (name
, line
+ 1,
2924 _("[0-9]H labels do not mix with dot-pseudos"));
2925 current_fb_label
= -1;
2930 current_fb_label
= -1;
2931 if (is_name_beginner (input_line_pointer
[0]))
2932 label
= input_line_pointer
;
2935 s0
= input_line_pointer
;
2936 /* Skip over label. */
2937 while (*s0
&& is_part_of_name (*s0
))
2940 /* Remove trailing ":" off labels, as they'd otherwise be considered
2941 part of the name. But don't do it for local labels. */
2942 if (s0
!= input_line_pointer
&& s0
[-1] == ':'
2943 && (s0
- 2 != input_line_pointer
2944 || ! ISDIGIT (s0
[-2])))
2946 else if (label
!= NULL
)
2948 /* For labels that don't end in ":", we save it so we can later give
2949 it the same alignment and address as the associated instruction. */
2951 /* Make room for the label including the ending nul. */
2952 int len_0
= s0
- label
+ 1;
2954 /* Save this label on the MMIX symbol obstack. Saving it on an
2955 obstack is needless for "IS"-pseudos, but it's harmless and we
2956 avoid a little code-cluttering. */
2957 obstack_grow (&mmix_sym_obstack
, label
, len_0
);
2958 pending_label
= obstack_finish (&mmix_sym_obstack
);
2959 pending_label
[len_0
- 1] = 0;
2962 while (*s0
&& ISSPACE (*s0
) && ! is_end_of_line
[(unsigned int) *s0
])
2965 if (pending_label
!= NULL
&& is_end_of_line
[(unsigned int) *s0
])
2966 /* Whoops, this was actually a lone label on a line. Like :-ended
2967 labels, we don't attach such labels to the next instruction or
2969 pending_label
= NULL
;
2971 /* Find local labels of operands. Look for "[0-9][FB]" where the
2972 characters before and after are not part of words. Break if a single
2973 or double quote is seen anywhere. It means we can't have local
2974 labels as part of list with mixed quoted and unquoted members for
2975 mmixal compatibility but we can't have it all. For the moment.
2976 Replace the '<N>B' or '<N>F' with MAGIC_FB_BACKWARD_CHAR<N> and
2977 MAGIC_FB_FORWARD_CHAR<N> respectively. */
2979 /* First make sure we don't have any of the magic characters on the line
2980 appearing as input. */
2985 if (is_end_of_line
[(unsigned int) c
])
2987 if (c
== MAGIC_FB_BACKWARD_CHAR
|| c
== MAGIC_FB_FORWARD_CHAR
)
2988 as_bad (_("invalid characters in input"));
2991 /* Scan again, this time looking for ';' after operands. */
2994 /* Skip the insn. */
2998 && ! is_end_of_line
[(unsigned int) *s
])
3001 /* Skip the spaces after the insn. */
3005 && ! is_end_of_line
[(unsigned int) *s
])
3008 /* Skip the operands. While doing this, replace [0-9][BF] with
3009 (MAGIC_FB_BACKWARD_CHAR|MAGIC_FB_FORWARD_CHAR)[0-9]. */
3010 while ((c
= *s
) != 0
3013 && ! is_end_of_line
[(unsigned int) c
])
3019 /* FIXME: Test-case for semi-colon in string. */
3022 && (! is_end_of_line
[(unsigned int) *s
] || *s
== ';'))
3028 else if (ISDIGIT (c
))
3030 if ((s
[1] != 'B' && s
[1] != 'F')
3031 || is_part_of_name (s
[-1])
3032 || is_part_of_name (s
[2]))
3037 ? MAGIC_FB_BACKWARD_CHAR
: MAGIC_FB_FORWARD_CHAR
);
3045 /* Skip any spaces after the operands. */
3049 && !is_end_of_line
[(unsigned int) *s
])
3052 /* If we're now looking at a semi-colon, then it's an end-of-line
3054 mmix_next_semicolon_is_eoln
= (*s
== ';');
3056 /* Make IS into an EQU by replacing it with "= ". Only match upper-case
3057 though; let lower-case be a syntax error. */
3059 if (s
[0] == 'I' && s
[1] == 'S' && ISSPACE (s
[2]))
3064 /* Since labels can start without ":", we have to handle "X IS 42"
3065 in full here, or "X" will be parsed as a label to be set at ".". */
3066 input_line_pointer
= s
;
3068 /* Right after this function ends, line numbers will be bumped if
3069 input_line_pointer[-1] = '\n'. We want accurate line numbers for
3070 the equals call, so we bump them before the call, and make sure
3071 they aren't bumped afterwards. */
3072 bump_line_counters ();
3074 /* A fb-label is valid as an IS-label. */
3075 if (current_fb_label
>= 0)
3079 /* We need to save this name on our symbol obstack, since the
3080 string we got in fb_label_name is volatile and will change
3081 with every call to fb_label_name, like those resulting from
3082 parsing the IS-operand. */
3083 fb_name
= fb_label_name (current_fb_label
, 1);
3084 obstack_grow (&mmix_sym_obstack
, fb_name
, strlen (fb_name
) + 1);
3085 equals (obstack_finish (&mmix_sym_obstack
), 0);
3086 fb_label_instance_inc (current_fb_label
);
3087 current_fb_label
= -1;
3091 if (pending_label
== NULL
)
3092 as_bad (_("empty label field for IS"));
3094 equals (pending_label
, 0);
3095 pending_label
= NULL
;
3098 /* For mmixal, we can have comments without a comment-start
3100 mmix_handle_rest_of_empty_line ();
3101 input_line_pointer
--;
3103 input_line_pointer
[-1] = ' ';
3105 else if (s
[0] == 'G'
3107 && strncmp (s
, "GREG", 4) == 0
3108 && (ISSPACE (s
[4]) || is_end_of_line
[(unsigned char) s
[4]]))
3110 input_line_pointer
= s
+ 4;
3112 /* Right after this function ends, line numbers will be bumped if
3113 input_line_pointer[-1] = '\n'. We want accurate line numbers for
3114 the s_greg call, so we bump them before the call, and make sure
3115 they aren't bumped afterwards. */
3116 bump_line_counters ();
3118 /* A fb-label is valid as a GREG-label. */
3119 if (current_fb_label
>= 0)
3123 /* We need to save this name on our symbol obstack, since the
3124 string we got in fb_label_name is volatile and will change
3125 with every call to fb_label_name, like those resulting from
3126 parsing the IS-operand. */
3127 fb_name
= fb_label_name (current_fb_label
, 1);
3129 /* Make sure we save the canonical name and don't get bitten by
3131 obstack_1grow (&mmix_sym_obstack
, ':');
3132 obstack_grow (&mmix_sym_obstack
, fb_name
, strlen (fb_name
) + 1);
3133 mmix_greg_internal (obstack_finish (&mmix_sym_obstack
));
3134 fb_label_instance_inc (current_fb_label
);
3135 current_fb_label
= -1;
3138 mmix_greg_internal (pending_label
);
3140 /* Back up before the end-of-line marker that was skipped in
3141 mmix_greg_internal. */
3142 input_line_pointer
--;
3143 input_line_pointer
[-1] = ' ';
3145 pending_label
= NULL
;
3147 else if (pending_label
!= NULL
)
3149 input_line_pointer
+= strlen (pending_label
);
3151 /* See comment above about getting line numbers bumped. */
3152 input_line_pointer
[-1] = '\n';
3156 /* Give the value of an fb-label rewritten as in mmix_handle_mmixal, when
3157 parsing an expression.
3159 On valid calls, input_line_pointer points at a MAGIC_FB_BACKWARD_CHAR
3160 or MAGIC_FB_BACKWARD_CHAR, followed by an ascii digit for the label.
3161 We fill in the label as an expression. */
3164 mmix_fb_label (expP
)
3168 char *fb_internal_name
;
3170 /* This doesn't happen when not using mmixal syntax. */
3172 || (input_line_pointer
[0] != MAGIC_FB_BACKWARD_CHAR
3173 && input_line_pointer
[0] != MAGIC_FB_FORWARD_CHAR
))
3176 /* The current backward reference has augmentation 0. A forward
3177 reference has augmentation 1, unless it's the same as a fb-label on
3178 _this_ line, in which case we add one more so we don't refer to it.
3179 This is the semantics of mmixal; it differs to that of common
3180 fb-labels which refer to a here-label on the current line as a
3181 backward reference. */
3183 = fb_label_name (input_line_pointer
[1] - '0',
3184 (input_line_pointer
[0] == MAGIC_FB_FORWARD_CHAR
? 1 : 0)
3185 + ((input_line_pointer
[1] - '0' == current_fb_label
3186 && input_line_pointer
[0] == MAGIC_FB_FORWARD_CHAR
)
3189 input_line_pointer
+= 2;
3190 sym
= symbol_find_or_make (fb_internal_name
);
3192 /* We don't have to clean up unrelated fields here; we just do what the
3193 expr machinery does, but *not* just what it does for [0-9][fb], since
3194 we need to treat those as ordinary symbols sometimes; see testcases
3195 err-byte2.s and fb-2.s. */
3196 if (S_GET_SEGMENT (sym
) == absolute_section
)
3198 expP
->X_op
= O_constant
;
3199 expP
->X_add_number
= S_GET_VALUE (sym
);
3203 expP
->X_op
= O_symbol
;
3204 expP
->X_add_symbol
= sym
;
3205 expP
->X_add_number
= 0;
3209 /* See whether we need to force a relocation into the output file.
3210 This is used to force out switch and PC relative relocations when
3214 mmix_force_relocation (fixP
)
3217 if (fixP
->fx_r_type
== BFD_RELOC_MMIX_LOCAL
3218 || fixP
->fx_r_type
== BFD_RELOC_VTABLE_INHERIT
3219 || fixP
->fx_r_type
== BFD_RELOC_VTABLE_ENTRY
3220 || fixP
->fx_r_type
== BFD_RELOC_MMIX_BASE_PLUS_OFFSET
)
3223 /* FIXME: This is dubious. Handling of weak symbols should have been
3224 caught before we get here. */
3225 if ((fixP
->fx_addsy
&& S_IS_WEAK (fixP
->fx_addsy
)))
3231 /* All our pcrel relocations are must-keep. Note that md_apply_fix3 is
3232 called *after* this, and will handle getting rid of the presumed
3233 reloc; a relocation isn't *forced* other than to be handled by
3234 md_apply_fix3 (or tc_gen_reloc if linkrelax). */
3241 /* The location from which a PC relative jump should be calculated,
3242 given a PC relative reloc. */
3245 md_pcrel_from_section (fixP
, sec
)
3249 if (fixP
->fx_addsy
!= (symbolS
*) NULL
3250 && (! S_IS_DEFINED (fixP
->fx_addsy
)
3251 || S_GET_SEGMENT (fixP
->fx_addsy
) != sec
))
3253 /* The symbol is undefined (or is defined but not in this section).
3254 Let the linker figure it out. */
3258 return (fixP
->fx_frag
->fr_address
+ fixP
->fx_where
);
3261 /* Adjust the symbol table. We make reg_section relative to the real
3264 FIXME: There's a gas bug; should be fixed when the reg_section symbol
3265 is "accidentally" saved for relocs which are really fixups that will be
3269 mmix_adjust_symtab ()
3273 symbolS
*regsec
= section_symbol (reg_section
);
3274 segT realregsec
= NULL
;
3276 for (prevsym
= sym
= symbol_rootP
;
3278 prevsym
= sym
, sym
= symbol_next (sym
))
3279 if (S_GET_SEGMENT (sym
) == reg_section
)
3282 || (!S_IS_EXTERN (sym
) && !symbol_used_in_reloc_p (sym
)))
3284 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
3286 /* We make one extra turn, or we'll lose the next symbol. We
3287 assume that the symbol we remove is not the symbol root
3288 (.text normally is). */
3293 /* Change section to the *real* register section, so it gets
3294 proper treatment when writing it out. Only do this for
3295 global symbols. This also means we don't have to check for
3297 if (realregsec
== NULL
)
3299 = bfd_make_section_old_way (stdoutput
, MMIX_REG_SECTION_NAME
);
3301 S_SET_SEGMENT (sym
, realregsec
);
3306 /* This is the expansion of LABELS_WITHOUT_COLONS.
3307 We let md_start_line_hook tweak label_without_colon_this_line, and then
3308 this function returns the tweaked value, and sets it to 1 for the next
3309 line. FIXME: Very, very brittle. Not sure it works the way I
3310 thought at the time I first wrote this. */
3313 mmix_label_without_colon_this_line ()
3315 int retval
= label_without_colon_this_line
;
3317 if (! mmix_gnu_syntax
)
3318 label_without_colon_this_line
= 1;
3323 /* This is the expansion of md_relax_frag. We go through the ordinary
3324 relax table function except when the frag is for a GREG. Then we have
3325 to check whether there's another GREG by the same value that we can
3329 mmix_md_relax_frag (seg
, fragP
, stretch
)
3334 if (fragP
->fr_subtype
!= STATE_GREG_DEF
3335 && fragP
->fr_subtype
!= STATE_GREG_UNDF
)
3336 return relax_frag (seg
, fragP
, stretch
);
3338 /* If we're defined, we don't grow. */
3339 if (fragP
->fr_subtype
== STATE_GREG_DEF
)
3342 as_fatal (_("internal: unexpected relax type %d:%d"),
3343 fragP
->fr_type
, fragP
->fr_subtype
);
3347 /* Various things we punt until all input is seen. */
3356 /* The first frag of GREG:s going into the register contents section. */
3357 fragS
*mmix_reg_contents_frags
= NULL
;
3359 /* Reset prefix. All labels reachable at this point must be
3361 mmix_current_prefix
= NULL
;
3364 as_bad_where (bspec_file
, bspec_line
, _("BSPEC without ESPEC."));
3366 /* Emit the low LOC setting of .text. */
3367 if (text_has_contents
&& lowest_text_loc
!= (bfd_vma
) -1)
3370 char locsymbol
[sizeof (":") - 1
3371 + sizeof (MMIX_LOC_SECTION_START_SYMBOL_PREFIX
) - 1
3372 + sizeof (".text")];
3374 /* An exercise in non-ISO-C-ness, this one. */
3375 sprintf (locsymbol
, ":%s%s", MMIX_LOC_SECTION_START_SYMBOL_PREFIX
,
3378 = symbol_new (locsymbol
, absolute_section
, lowest_text_loc
,
3379 &zero_address_frag
);
3380 S_SET_EXTERNAL (symbolP
);
3384 if (data_has_contents
&& lowest_data_loc
!= (bfd_vma
) -1)
3387 char locsymbol
[sizeof (":") - 1
3388 + sizeof (MMIX_LOC_SECTION_START_SYMBOL_PREFIX
) - 1
3389 + sizeof (".data")];
3391 sprintf (locsymbol
, ":%s%s", MMIX_LOC_SECTION_START_SYMBOL_PREFIX
,
3394 = symbol_new (locsymbol
, absolute_section
, lowest_data_loc
,
3395 &zero_address_frag
);
3396 S_SET_EXTERNAL (symbolP
);
3399 /* Unless GNU syntax mode, set "Main" to be a function, so the
3400 disassembler doesn't get confused when we write truly
3401 mmixal-compatible code (and don't use .type). Similarly set it
3402 global (regardless of -globalize-symbols), so the linker sees it as
3403 the start symbol in ELF mode. */
3404 mainsym
= symbol_find (MMIX_START_SYMBOL_NAME
);
3405 if (mainsym
!= NULL
&& ! mmix_gnu_syntax
)
3407 symbol_get_bfdsym (mainsym
)->flags
|= BSF_FUNCTION
;
3408 S_SET_EXTERNAL (mainsym
);
3411 if (n_of_raw_gregs
!= 0)
3413 /* Emit GREGs. They are collected in order of appearance, but must
3414 be emitted in opposite order to both have section address regno*8
3415 and the same allocation order (within a file) as mmixal. */
3416 segT this_segment
= now_seg
;
3417 subsegT this_subsegment
= now_subseg
;
3419 = bfd_make_section_old_way (stdoutput
,
3420 MMIX_REG_CONTENTS_SECTION_NAME
);
3421 subseg_set (regsec
, 0);
3423 /* Finally emit the initialization-value. Emit a variable frag, which
3424 we'll fix in md_estimate_size_before_relax. We set the initializer
3425 for the tc_frag_data field to NULL, so we can use that field for
3426 relaxation purposes. */
3427 mmix_opcode_frag
= NULL
;
3430 mmix_reg_contents_frags
= frag_now
;
3432 for (i
= n_of_raw_gregs
- 1; i
>= 0; i
--)
3434 if (mmix_raw_gregs
[i
].label
!= NULL
)
3435 /* There's a symbol. Let it refer to this location in the
3436 register contents section. The symbol must be globalized
3438 colon (mmix_raw_gregs
[i
].label
);
3440 frag_var (rs_machine_dependent
, 8, 0, STATE_GREG_UNDF
,
3441 make_expr_symbol (&mmix_raw_gregs
[i
].exp
), 0, NULL
);
3444 subseg_set (this_segment
, this_subsegment
);
3447 /* Iterate over frags resulting from GREGs and move those that evidently
3448 have the same value together and point one to another.
3450 This works in time O(N^2) but since the upper bound for non-error use
3451 is 223, it's best to keep this simpler algorithm. */
3452 for (fragP
= mmix_reg_contents_frags
; fragP
!= NULL
; fragP
= fragP
->fr_next
)
3459 symbolS
*symbolP
= fragP
->fr_symbol
;
3461 if (fragP
->fr_type
!= rs_machine_dependent
3462 || fragP
->fr_subtype
!= STATE_GREG_UNDF
)
3465 /* Whatever the outcome, we will have this GREG judged merged or
3466 non-merged. Since the tc_frag_data is NULL at this point, we
3467 default to non-merged. */
3468 fragP
->fr_subtype
= STATE_GREG_DEF
;
3470 /* If we're not supposed to merge GREG definitions, then just don't
3471 look for equivalents. */
3475 osymval
= (offsetT
) S_GET_VALUE (symbolP
);
3476 osymfrag
= symbol_get_frag (symbolP
);
3478 /* If the symbol isn't defined, we can't say that another symbol
3479 equals this frag, then. FIXME: We can look at the "deepest"
3480 defined name; if a = c and b = c then obviously a == b. */
3481 if (! S_IS_DEFINED (symbolP
))
3484 oexpP
= symbol_get_value_expression (fragP
->fr_symbol
);
3486 /* If the initialization value is zero, then we must not merge them. */
3487 if (oexpP
->X_op
== O_constant
&& osymval
== 0)
3490 /* Iterate through the frags downward this one. If we find one that
3491 has the same non-zero value, move it to after this one and point
3492 to it as the equivalent. */
3493 for (fpp
= &fragP
->fr_next
; *fpp
!= NULL
; fpp
= &fpp
[0]->fr_next
)
3497 if (fp
->fr_type
!= rs_machine_dependent
3498 || fp
->fr_subtype
!= STATE_GREG_UNDF
)
3501 /* Calling S_GET_VALUE may simplify the symbol, changing from
3502 expr_section etc. so call it first. */
3503 if ((offsetT
) S_GET_VALUE (fp
->fr_symbol
) == osymval
3504 && symbol_get_frag (fp
->fr_symbol
) == osymfrag
)
3506 /* Move the frag links so the one we found equivalent comes
3507 after the current one, carefully considering that
3508 sometimes fpp == &fragP->fr_next and the moves must be a
3511 fp
->fr_next
= fragP
->fr_next
;
3512 fragP
->fr_next
= fp
;
3518 fragP
->tc_frag_data
= fp
;
3522 /* qsort function for mmix_symbol_gregs. */
3525 cmp_greg_symbol_fixes (parg
, qarg
)
3529 const struct mmix_symbol_greg_fixes
*p
3530 = (const struct mmix_symbol_greg_fixes
*) parg
;
3531 const struct mmix_symbol_greg_fixes
*q
3532 = (const struct mmix_symbol_greg_fixes
*) qarg
;
3534 return p
->offs
> q
->offs
? 1 : p
->offs
< q
->offs
? -1 : 0;
3537 /* Collect GREG definitions from mmix_gregs and hang them as lists sorted
3538 on increasing offsets onto each section symbol or undefined symbol.
3540 Also, remove the register convenience section so it doesn't get output
3541 as an ELF section. */
3547 struct mmix_symbol_gregs
*all_greg_symbols
[MAX_GREGS
];
3548 int n_greg_symbols
= 0;
3550 /* Collect all greg fixups and decorate each corresponding symbol with
3551 the greg fixups for it. */
3552 for (i
= 0; i
< n_of_cooked_gregs
; i
++)
3556 struct mmix_symbol_gregs
*gregs
;
3559 fixP
= mmix_gregs
[i
];
3560 know (fixP
->fx_r_type
== BFD_RELOC_64
);
3562 /* This case isn't doable in general anyway, methinks. */
3563 if (fixP
->fx_subsy
!= NULL
)
3565 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3566 _("GREG expression too complicated"));
3570 sym
= fixP
->fx_addsy
;
3571 offs
= (offsetT
) fixP
->fx_offset
;
3573 /* If the symbol is defined, then it must be resolved to a section
3574 symbol at this time, or else we don't know how to handle it. */
3575 if (S_IS_DEFINED (sym
))
3577 if (! symbol_section_p (sym
)
3578 && ! bfd_is_abs_section (S_GET_SEGMENT (sym
)))
3579 as_fatal (_("internal: GREG expression not resolved to section"));
3581 offs
+= S_GET_VALUE (sym
);
3584 /* If this is an absolute symbol sufficiently near lowest_data_loc,
3585 then we canonicalize on the data section. Note that offs is
3586 signed here; we may subtract lowest_data_loc which is unsigned.
3587 Careful with those comparisons. */
3588 if (lowest_data_loc
!= (bfd_vma
) -1
3589 && (bfd_vma
) offs
+ 256 > lowest_data_loc
3590 && bfd_is_abs_section (S_GET_SEGMENT (sym
)))
3592 offs
-= (offsetT
) lowest_data_loc
;
3593 sym
= section_symbol (data_section
);
3595 /* Likewise text section. */
3596 else if (lowest_text_loc
!= (bfd_vma
) -1
3597 && (bfd_vma
) offs
+ 256 > lowest_text_loc
3598 && bfd_is_abs_section (S_GET_SEGMENT (sym
)))
3600 offs
-= (offsetT
) lowest_text_loc
;
3601 sym
= section_symbol (text_section
);
3604 gregs
= *symbol_get_tc (sym
);
3608 gregs
= xmalloc (sizeof (*gregs
));
3610 symbol_set_tc (sym
, &gregs
);
3611 all_greg_symbols
[n_greg_symbols
++] = gregs
;
3614 gregs
->greg_fixes
[gregs
->n_gregs
].fix
= fixP
;
3615 gregs
->greg_fixes
[gregs
->n_gregs
++].offs
= offs
;
3618 /* For each symbol having a GREG definition, sort those definitions on
3620 for (i
= 0; i
< n_greg_symbols
; i
++)
3621 qsort (all_greg_symbols
[i
]->greg_fixes
, all_greg_symbols
[i
]->n_gregs
,
3622 sizeof (all_greg_symbols
[i
]->greg_fixes
[0]), cmp_greg_symbol_fixes
);
3624 if (real_reg_section
!= NULL
)
3628 /* FIXME: Pass error state gracefully. */
3629 if (bfd_get_section_flags (stdoutput
, real_reg_section
) & SEC_HAS_CONTENTS
)
3630 as_fatal (_("register section has contents\n"));
3632 /* FIXME: This does not seem like the proper way to kill a section,
3633 but it's the way it's done elsewhere, like elf64-alpha.c. */
3634 /* Really remove the section. */
3635 for (secpp
= &stdoutput
->sections
;
3636 *secpp
!= real_reg_section
;
3637 secpp
= &(*secpp
)->next
)
3639 *secpp
= (*secpp
)->next
;
3640 --stdoutput
->section_count
;
3645 /* Provide an expression for a built-in name provided when-used.
3646 Either a symbol that is a handler; living in 0x10*[1..8] and having
3647 name [DVWIOUZX]_Handler, or a mmixal built-in symbol.
3649 If the name isn't a built-in name and parsed into *EXPP, return zero. */
3652 mmix_parse_predefined_name (name
, expP
)
3657 char *handler_charp
;
3658 const char handler_chars
[] = "DVWIOUZX";
3661 if (! predefined_syms
)
3664 canon_name
= tc_canonicalize_symbol_name (name
);
3666 if (canon_name
[1] == '_'
3667 && strcmp (canon_name
+ 2, "Handler") == 0
3668 && (handler_charp
= strchr (handler_chars
, *canon_name
)) != NULL
)
3670 /* If the symbol doesn't exist, provide one relative to the .text
3673 FIXME: We should provide separate sections, mapped in the linker
3675 symp
= symbol_find (name
);
3677 symp
= symbol_new (name
, text_section
,
3678 0x10 * (handler_charp
+ 1 - handler_chars
),
3679 &zero_address_frag
);
3683 /* These symbols appear when referenced; needed for
3684 mmixal-compatible programs. */
3691 } predefined_abs_syms
[] =
3693 {"Data_Segment", (valueT
) 0x20 << 56},
3694 {"Pool_Segment", (valueT
) 0x40 << 56},
3695 {"Stack_Segment", (valueT
) 0x60 << 56},
3703 {"BinaryReadWrite", 4},
3726 /* If it's already in the symbol table, we shouldn't do anything. */
3727 symp
= symbol_find (name
);
3732 i
< sizeof (predefined_abs_syms
)/sizeof (predefined_abs_syms
[0]);
3734 if (strcmp (canon_name
, predefined_abs_syms
[i
].name
) == 0)
3736 symbol_table_insert (symbol_new (predefined_abs_syms
[i
].name
,
3738 predefined_abs_syms
[i
].val
,
3739 &zero_address_frag
));
3741 /* Let gas find the symbol we just created, through its
3746 /* Not one of those symbols. Let gas handle it. */
3750 expP
->X_op
= O_symbol
;
3751 expP
->X_add_number
= 0;
3752 expP
->X_add_symbol
= symp
;
3753 expP
->X_op_symbol
= NULL
;
3758 /* Worker for mmix_frob_file_before_adjust. */
3761 mmix_frob_local_reloc (abfd
, sec
, xxx
)
3762 bfd
*abfd ATTRIBUTE_UNUSED
;
3764 PTR xxx ATTRIBUTE_UNUSED
;
3766 segment_info_type
*seginfo
= seg_info (sec
);
3769 if (seginfo
== NULL
)
3772 for (fixp
= seginfo
->fix_root
; fixp
; fixp
= fixp
->fx_next
)
3773 if (! fixp
->fx_done
&& fixp
->fx_addsy
!= NULL
)
3775 symbolS
*sym
= fixp
->fx_addsy
;
3776 asection
*section
= S_GET_SEGMENT (sym
);
3778 if (section
== reg_section
3779 && fixp
->fx_r_type
== BFD_RELOC_MMIX_LOCAL
)
3781 /* If the register is marked global, we don't need to replace
3782 with the *real* register section since that will be done
3783 when the symbol is changed. */
3784 if (! S_IS_EXTERNAL (sym
))
3785 /* If it's a local symbol, we replace it with an anonymous
3786 one with the same constant value. */
3787 fixp
->fx_addsy
= expr_build_uconstant (S_GET_VALUE (sym
));
3792 /* Change fixups for register symbols for BFD_MMIX_LOCAL to be for an
3796 mmix_frob_file_before_adjust ()
3799 bfd_map_over_sections (stdoutput
, mmix_frob_local_reloc
, (char *) 0);
3802 /* Just check that we don't have a BSPEC/ESPEC pair active when changing
3803 sections "normally", and get knowledge about alignment from the new
3807 mmix_md_elf_section_change_hook ()
3810 as_bad (_("section change from within a BSPEC/ESPEC pair is not supported"));
3812 last_alignment
= bfd_get_section_alignment (now_seg
->owner
, now_seg
);
3816 /* The LOC worker. This is like s_org, but we have to support changing
3821 int ignore ATTRIBUTE_UNUSED
;
3829 /* Must not have a BSPEC in progress. */
3832 as_bad (_("directive LOC from within a BSPEC/ESPEC pair is not supported"));
3836 section
= expression (&exp
);
3838 if (exp
.X_op
== O_illegal
3839 || exp
.X_op
== O_absent
3840 || exp
.X_op
== O_big
3841 || section
== undefined_section
)
3843 as_bad (_("invalid LOC expression"));
3847 if (section
== absolute_section
)
3849 /* Translate a constant into a suitable section. */
3851 if (exp
.X_add_number
< ((offsetT
) 0x20 << 56))
3853 /* Lower than Data_Segment - assume it's .text. */
3854 section
= text_section
;
3856 /* Save the lowest seen location, so we can pass on this
3857 information to the linker. We don't actually org to this
3858 location here, we just pass on information to the linker so
3859 it can put the code there for us. */
3861 /* If there was already a loc (that has to be set lower than
3862 this one), we org at (this - lower). There's an implicit
3863 "LOC 0" before any entered code. FIXME: handled by spurious
3864 settings of text_has_contents. */
3865 if (exp
.X_add_number
< 0
3866 || exp
.X_add_number
< (offsetT
) lowest_text_loc
)
3868 as_bad (_("LOC expression stepping backwards is not supported"));
3869 exp
.X_op
= O_absent
;
3873 if (text_has_contents
&& lowest_text_loc
== (bfd_vma
) -1)
3874 lowest_text_loc
= 0;
3876 if (lowest_text_loc
== (bfd_vma
) -1)
3878 lowest_text_loc
= exp
.X_add_number
;
3880 /* We want only to change the section, not set an offset. */
3881 exp
.X_op
= O_absent
;
3884 exp
.X_add_number
-= lowest_text_loc
;
3889 /* Do the same for the .data section. */
3890 section
= data_section
;
3892 if (exp
.X_add_number
< (offsetT
) lowest_data_loc
)
3894 as_bad (_("LOC expression stepping backwards is not supported"));
3895 exp
.X_op
= O_absent
;
3899 if (data_has_contents
&& lowest_data_loc
== (bfd_vma
) -1)
3900 lowest_data_loc
= (bfd_vma
) 0x20 << 56;
3902 if (lowest_data_loc
== (bfd_vma
) -1)
3904 lowest_data_loc
= exp
.X_add_number
;
3906 /* We want only to change the section, not set an offset. */
3907 exp
.X_op
= O_absent
;
3910 exp
.X_add_number
-= lowest_data_loc
;
3915 if (section
!= now_seg
)
3917 obj_elf_section_change_hook ();
3918 subseg_set (section
, 0);
3920 /* Call our section change hooks using the official hook. */
3921 md_elf_section_change_hook ();
3924 if (exp
.X_op
!= O_absent
)
3926 if (exp
.X_op
!= O_constant
&& exp
.X_op
!= O_symbol
)
3928 /* Handle complex expressions. */
3929 sym
= make_expr_symbol (&exp
);
3934 sym
= exp
.X_add_symbol
;
3935 off
= exp
.X_add_number
;
3938 p
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, sym
, off
, (char *) 0);
3942 mmix_handle_rest_of_empty_line ();
3945 /* The BYTE worker. We have to support sequences of mixed "strings",
3946 numbers and other constant "first-pass" reducible expressions separated
3955 if (now_seg
== text_section
)
3956 text_has_contents
= 1;
3957 else if (now_seg
== data_section
)
3958 data_has_contents
= 1;
3963 switch (*input_line_pointer
)
3966 ++input_line_pointer
;
3967 start
= input_line_pointer
;
3968 while (is_a_char (c
= next_char_of_string ()))
3970 FRAG_APPEND_1_CHAR (c
);
3973 if (input_line_pointer
[-1] != '\"')
3975 /* We will only get here in rare cases involving #NO_APP,
3976 where the unterminated string is not recognized by the
3977 preformatting pass. */
3978 as_bad (_("unterminated string"));
3979 mmix_discard_rest_of_line ();
3987 segT expseg
= expression (&exp
);
3989 /* We have to allow special register names as constant numbers. */
3990 if ((expseg
!= absolute_section
&& expseg
!= reg_section
)
3991 || (exp
.X_op
!= O_constant
3992 && (exp
.X_op
!= O_register
3993 || exp
.X_add_number
<= 255)))
3995 as_bad (_("BYTE expression not a pure number"));
3996 mmix_discard_rest_of_line ();
3999 else if ((exp
.X_add_number
> 255 && exp
.X_op
!= O_register
)
4000 || exp
.X_add_number
< 0)
4002 /* Note that mmixal does not allow negative numbers in
4003 BYTE sequences, so neither should we. */
4004 as_bad (_("BYTE expression not in the range 0..255"));
4005 mmix_discard_rest_of_line ();
4009 FRAG_APPEND_1_CHAR (exp
.X_add_number
);
4015 c
= *input_line_pointer
++;
4019 input_line_pointer
--;
4021 if (mmix_gnu_syntax
)
4022 demand_empty_rest_of_line ();
4025 mmix_discard_rest_of_line ();
4026 /* Do like demand_empty_rest_of_line and step over the end-of-line
4028 input_line_pointer
++;
4031 /* Make sure we align for the next instruction. */
4035 /* Like cons_worker, but we have to ignore "naked comments", not barf on
4036 them. Implements WYDE, TETRA and OCTA. We're a little bit more
4037 lenient than mmix_byte but FIXME: they should eventually merge. */
4046 /* If we don't have any contents, then it's ok to have a specified start
4047 address that is not a multiple of the max data size. We will then
4048 align it as necessary when we get here. Otherwise, it's a fatal sin. */
4049 if (now_seg
== text_section
)
4051 if (lowest_text_loc
!= (bfd_vma
) -1
4052 && (lowest_text_loc
& (nbytes
- 1)) != 0)
4054 if (text_has_contents
)
4055 as_bad (_("data item with alignment larger than location"));
4056 else if (want_unaligned
)
4057 as_bad (_("unaligned data at an absolute location is not supported"));
4059 lowest_text_loc
&= ~((bfd_vma
) nbytes
- 1);
4060 lowest_text_loc
+= (bfd_vma
) nbytes
;
4063 text_has_contents
= 1;
4065 else if (now_seg
== data_section
)
4067 if (lowest_data_loc
!= (bfd_vma
) -1
4068 && (lowest_data_loc
& (nbytes
- 1)) != 0)
4070 if (data_has_contents
)
4071 as_bad (_("data item with alignment larger than location"));
4072 else if (want_unaligned
)
4073 as_bad (_("unaligned data at an absolute location is not supported"));
4075 lowest_data_loc
&= ~((bfd_vma
) nbytes
- 1);
4076 lowest_data_loc
+= (bfd_vma
) nbytes
;
4079 data_has_contents
= 1;
4082 /* Always align these unless asked not to (valid for the current pseudo). */
4083 if (! want_unaligned
)
4085 last_alignment
= nbytes
== 2 ? 1 : (nbytes
== 4 ? 2 : 3);
4086 frag_align (last_alignment
, 0, 0);
4087 record_alignment (now_seg
, last_alignment
);
4090 /* For mmixal compatibility, a label for an instruction (and emitting
4091 pseudo) refers to the _aligned_ address. So we have to emit the
4093 if (current_fb_label
>= 0)
4094 colon (fb_label_name (current_fb_label
, 1));
4095 else if (pending_label
!= NULL
)
4097 colon (pending_label
);
4098 pending_label
= NULL
;
4103 if (is_end_of_line
[(unsigned int) *input_line_pointer
])
4105 /* Default to zero if the expression was absent. */
4107 exp
.X_op
= O_constant
;
4108 exp
.X_add_number
= 0;
4110 exp
.X_add_symbol
= NULL
;
4111 exp
.X_op_symbol
= NULL
;
4112 emit_expr (&exp
, (unsigned int) nbytes
);
4119 switch (*input_line_pointer
)
4121 /* We support strings here too; each character takes up nbytes
4124 ++input_line_pointer
;
4125 start
= input_line_pointer
;
4126 while (is_a_char (c
= next_char_of_string ()))
4128 exp
.X_op
= O_constant
;
4129 exp
.X_add_number
= c
;
4131 emit_expr (&exp
, (unsigned int) nbytes
);
4134 if (input_line_pointer
[-1] != '\"')
4136 /* We will only get here in rare cases involving #NO_APP,
4137 where the unterminated string is not recognized by the
4138 preformatting pass. */
4139 as_bad (_("unterminated string"));
4140 mmix_discard_rest_of_line ();
4148 emit_expr (&exp
, (unsigned int) nbytes
);
4154 while (*input_line_pointer
++ == ',');
4156 input_line_pointer
--; /* Put terminator back into stream. */
4158 mmix_handle_rest_of_empty_line ();
4160 /* We don't need to step up the counter for the current_fb_label here;
4161 that's handled by the caller. */
4164 /* The md_do_align worker. At present, we just record an alignment to
4165 nullify the automatic alignment we do for WYDE, TETRA and OCTA, as gcc
4166 does not use the unaligned macros when attribute packed is used.
4167 Arguably this is a GCC bug. */
4170 mmix_md_do_align (n
, fill
, len
, max
)
4172 char *fill ATTRIBUTE_UNUSED
;
4173 int len ATTRIBUTE_UNUSED
;
4174 int max ATTRIBUTE_UNUSED
;
4177 want_unaligned
= n
== 0;