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
;
2545 return 0; /* Return value is ignored. */
2548 /* A bsearch function for looking up a value against offsets for GREG
2552 cmp_greg_val_greg_symbol_fixes (p1
, p2
)
2556 offsetT val1
= *(offsetT
*) p1
;
2557 offsetT val2
= ((struct mmix_symbol_greg_fixes
*) p2
)->offs
;
2559 if (val1
>= val2
&& val1
< val2
+ 255)
2568 /* Generate a machine-dependent relocation. */
2571 tc_gen_reloc (section
, fixP
)
2572 asection
*section ATTRIBUTE_UNUSED
;
2576 = fixP
->fx_offset
+ (fixP
->fx_addsy
? S_GET_VALUE (fixP
->fx_addsy
) : 0);
2578 bfd_reloc_code_real_type code
= BFD_RELOC_NONE
;
2579 char *buf
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
2580 symbolS
*addsy
= fixP
->fx_addsy
;
2581 asection
*addsec
= addsy
== NULL
? NULL
: S_GET_SEGMENT (addsy
);
2582 bfd_vma addend
= fixP
->fx_offset
;
2583 asymbol
*baddsy
= addsy
!= NULL
? symbol_get_bfdsym (addsy
) : NULL
;
2585 /* A single " LOCAL expression" in the wrong section will not work when
2586 linking to MMO; relocations for zero-content sections are then
2587 ignored. Normally, relocations would modify section contents, and
2588 you'd never think or be able to do something like that. The
2589 relocation resulting from a LOCAL directive doesn't have an obvious
2590 and mandatory location. I can't figure out a way to do this better
2591 than just helping the user around this limitation here; hopefully the
2592 code using the local expression is around. Putting the LOCAL
2593 semantics in a relocation still seems right; a section didn't do. */
2594 if (bfd_section_size (section
->owner
, section
) == 0)
2596 (fixP
->fx_file
, fixP
->fx_line
,
2597 fixP
->fx_r_type
== BFD_RELOC_MMIX_LOCAL
2598 /* The BFD_RELOC_MMIX_LOCAL-specific message is supposed to be
2599 user-friendly, though a little bit non-substantial. */
2600 ? _("directive LOCAL must be placed in code or data")
2601 : _("internal confusion: relocation in a section without contents"));
2603 /* FIXME: Range tests for all these. */
2604 switch (fixP
->fx_r_type
)
2611 code
= fixP
->fx_r_type
;
2614 || bfd_is_abs_section (S_GET_SEGMENT (addsy
)))
2616 /* Resolve this reloc now, as md_apply_fix3 would have done (not
2617 called if -linkrelax). There is no point in keeping a reloc
2618 to an absolute symbol. No reloc that is subject to
2619 relaxation must be to an absolute symbol; difference
2620 involving symbols in a specific section must be signalled as
2621 an error if the relaxing cannot be expressed; having a reloc
2622 to the resolved (now absolute) value does not help. */
2623 md_number_to_chars (buf
, val
, fixP
->fx_size
);
2628 case BFD_RELOC_64_PCREL
:
2629 case BFD_RELOC_32_PCREL
:
2630 case BFD_RELOC_24_PCREL
:
2631 case BFD_RELOC_16_PCREL
:
2632 case BFD_RELOC_8_PCREL
:
2633 case BFD_RELOC_MMIX_LOCAL
:
2634 case BFD_RELOC_VTABLE_INHERIT
:
2635 case BFD_RELOC_VTABLE_ENTRY
:
2636 case BFD_RELOC_MMIX_GETA
:
2637 case BFD_RELOC_MMIX_GETA_1
:
2638 case BFD_RELOC_MMIX_GETA_2
:
2639 case BFD_RELOC_MMIX_GETA_3
:
2640 case BFD_RELOC_MMIX_CBRANCH
:
2641 case BFD_RELOC_MMIX_CBRANCH_J
:
2642 case BFD_RELOC_MMIX_CBRANCH_1
:
2643 case BFD_RELOC_MMIX_CBRANCH_2
:
2644 case BFD_RELOC_MMIX_CBRANCH_3
:
2645 case BFD_RELOC_MMIX_PUSHJ
:
2646 case BFD_RELOC_MMIX_PUSHJ_1
:
2647 case BFD_RELOC_MMIX_PUSHJ_2
:
2648 case BFD_RELOC_MMIX_PUSHJ_3
:
2649 case BFD_RELOC_MMIX_JMP
:
2650 case BFD_RELOC_MMIX_JMP_1
:
2651 case BFD_RELOC_MMIX_JMP_2
:
2652 case BFD_RELOC_MMIX_JMP_3
:
2653 case BFD_RELOC_MMIX_ADDR19
:
2654 case BFD_RELOC_MMIX_ADDR27
:
2655 code
= fixP
->fx_r_type
;
2658 case BFD_RELOC_MMIX_REG_OR_BYTE
:
2659 /* If we have this kind of relocation to an unknown symbol or to the
2660 register contents section (that is, to a register), then we can't
2661 resolve the relocation here. */
2663 && (bfd_is_und_section (S_GET_SEGMENT (addsy
))
2664 || strcmp (bfd_get_section_name (addsec
->owner
, addsec
),
2665 MMIX_REG_CONTENTS_SECTION_NAME
) == 0))
2667 code
= fixP
->fx_r_type
;
2671 /* If the relocation is not to the register section or to the
2672 absolute section (a numeric value), then we have an error. */
2674 && (S_GET_SEGMENT (addsy
) != real_reg_section
2677 && ! bfd_is_abs_section (S_GET_SEGMENT (addsy
)))
2680 /* Set the "immediate" bit of the insn if this relocation is to Z
2681 field when the value is a numeric value, i.e. not a register. */
2682 if ((fixP
->fx_where
& 3) == 3
2684 || S_GET_SEGMENT (addsy
) == absolute_section
))
2685 buf
[-3] |= IMM_OFFSET_BIT
;
2690 case BFD_RELOC_MMIX_BASE_PLUS_OFFSET
:
2692 && strcmp (bfd_get_section_name (addsec
->owner
, addsec
),
2693 MMIX_REG_CONTENTS_SECTION_NAME
) == 0)
2695 /* This changed into a register; the relocation is for the
2696 register-contents section. The constant part remains zero. */
2697 code
= BFD_RELOC_MMIX_REG
;
2701 /* If we've found out that this was indeed a register, then replace
2702 with the register number. The constant part is already zero.
2704 If we encounter any other defined symbol, then we must find a
2705 suitable register and emit a reloc. */
2707 || S_GET_SEGMENT (addsy
) != real_reg_section
)
2709 struct mmix_symbol_gregs
*gregs
;
2710 struct mmix_symbol_greg_fixes
*fix
;
2712 if (S_IS_DEFINED (addsy
))
2714 if (! symbol_section_p (addsy
)
2715 && ! bfd_is_abs_section (S_GET_SEGMENT (addsy
)))
2716 as_fatal (_("internal: BFD_RELOC_MMIX_BASE_PLUS_OFFSET not resolved to section"));
2718 /* If this is an absolute symbol sufficiently near
2719 lowest_data_loc, then we canonicalize on the data
2720 section. Note that val is signed here; we may subtract
2721 lowest_data_loc which is unsigned. Careful with those
2723 if (lowest_data_loc
!= (bfd_vma
) -1
2724 && (bfd_vma
) val
+ 256 > lowest_data_loc
2725 && bfd_is_abs_section (S_GET_SEGMENT (addsy
)))
2727 val
-= (offsetT
) lowest_data_loc
;
2728 addsy
= section_symbol (data_section
);
2730 /* Likewise text section. */
2731 else if (lowest_text_loc
!= (bfd_vma
) -1
2732 && (bfd_vma
) val
+ 256 > lowest_text_loc
2733 && bfd_is_abs_section (S_GET_SEGMENT (addsy
)))
2735 val
-= (offsetT
) lowest_text_loc
;
2736 addsy
= section_symbol (text_section
);
2740 gregs
= *symbol_get_tc (addsy
);
2742 /* If that symbol does not have any associated GREG definitions,
2743 we can't do anything. FIXME: implement allocate-on-demand in
2746 || (fix
= bsearch (&val
, gregs
->greg_fixes
, gregs
->n_gregs
,
2747 sizeof (gregs
->greg_fixes
[0]),
2748 cmp_greg_val_greg_symbol_fixes
)) == NULL
2749 /* The register must not point *after* the address we want. */
2751 /* Neither must the register point more than 255 bytes
2752 before the address we want. */
2753 || fix
->offs
+ 255 < val
)
2755 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
2756 _("no suitable GREG definition for operands"));
2761 /* Transform the base-plus-offset reloc for the actual area
2762 to a reloc for the register with the address of the area.
2763 Put addend for register in Z operand. */
2764 buf
[1] = val
- fix
->offs
;
2765 code
= BFD_RELOC_MMIX_REG
;
2767 = (bfd_get_section_by_name (stdoutput
,
2768 MMIX_REG_CONTENTS_SECTION_NAME
)
2771 addend
= fix
->fix
->fx_frag
->fr_address
+ fix
->fix
->fx_where
;
2774 else if (S_GET_VALUE (addsy
) > 255)
2775 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
2776 _("invalid operands"));
2784 case BFD_RELOC_MMIX_REG
:
2786 && (bfd_is_und_section (S_GET_SEGMENT (addsy
))
2787 || strcmp (bfd_get_section_name (addsec
->owner
, addsec
),
2788 MMIX_REG_CONTENTS_SECTION_NAME
) == 0))
2790 code
= fixP
->fx_r_type
;
2795 && (S_GET_SEGMENT (addsy
) != real_reg_section
2798 && ! bfd_is_und_section (S_GET_SEGMENT (addsy
)))
2799 /* Drop through to error message. */
2808 /* The others are supposed to be handled by md_apply_fix3.
2809 FIXME: ... which isn't called when -linkrelax. Move over
2810 md_apply_fix3 code here for everything reasonable. */
2814 (fixP
->fx_file
, fixP
->fx_line
,
2815 _("operands were not reducible at assembly-time"));
2817 /* Unmark this symbol as used in a reloc, so we don't bump into a BFD
2818 assert when trying to output reg_section. FIXME: A gas bug. */
2820 symbol_clear_used_in_reloc (addsy
);
2824 relP
= (arelent
*) xmalloc (sizeof (arelent
));
2826 relP
->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
2827 *relP
->sym_ptr_ptr
= baddsy
;
2828 relP
->address
= fixP
->fx_frag
->fr_address
+ fixP
->fx_where
;
2830 relP
->addend
= addend
;
2832 /* If this had been a.out, we would have had a kludge for weak symbols
2835 relP
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
2840 name
= S_GET_NAME (addsy
);
2842 name
= _("<unknown>");
2843 as_fatal (_("cannot generate relocation type for symbol %s, code %s"),
2844 name
, bfd_get_reloc_code_name (code
));
2850 /* Do some reformatting of a line. FIXME: We could transform a mmixal
2851 line into traditional (GNU?) format, unless #NO_APP, and get rid of all
2852 ugly labels_without_colons etc. */
2855 mmix_handle_mmixal ()
2857 char *s0
= input_line_pointer
;
2862 if (pending_label
!= NULL
)
2863 as_fatal (_("internal: unhandled label %s"), pending_label
);
2865 if (mmix_gnu_syntax
)
2868 /* If the first character is a '.', then it's a pseudodirective, not a
2869 label. Make GAS not handle label-without-colon on this line. We
2870 also don't do mmixal-specific stuff on this line. */
2871 if (input_line_pointer
[0] == '.')
2873 label_without_colon_this_line
= 0;
2877 /* Don't handle empty lines here. */
2880 if (*s0
== 0 || is_end_of_line
[(unsigned int) *s0
])
2883 if (! ISSPACE (*s0
))
2889 /* If we're on a line with a label, check if it's a mmixal fb-label.
2890 Save an indicator and skip the label; it must be set only after all
2891 fb-labels of expressions are evaluated. */
2892 if (ISDIGIT (input_line_pointer
[0])
2893 && input_line_pointer
[1] == 'H'
2894 && ISSPACE (input_line_pointer
[2]))
2897 current_fb_label
= input_line_pointer
[0] - '0';
2899 /* We have to skip the label, but also preserve the newlineness of
2900 the previous character, since the caller checks that. It's a
2901 mess we blame on the caller. */
2902 input_line_pointer
[1] = input_line_pointer
[-1];
2903 input_line_pointer
+= 2;
2905 s
= input_line_pointer
;
2906 while (*s
&& ISSPACE (*s
) && ! is_end_of_line
[(unsigned int) *s
])
2909 /* For errors emitted here, the book-keeping is off by one; the
2910 caller is about to bump the counters. Adjust the error messages. */
2911 if (is_end_of_line
[(unsigned int) *s
])
2915 as_where (&name
, &line
);
2916 as_bad_where (name
, line
+ 1,
2917 _("[0-9]H labels may not appear alone on a line"));
2918 current_fb_label
= -1;
2924 as_where (&name
, &line
);
2925 as_bad_where (name
, line
+ 1,
2926 _("[0-9]H labels do not mix with dot-pseudos"));
2927 current_fb_label
= -1;
2932 current_fb_label
= -1;
2933 if (is_name_beginner (input_line_pointer
[0]))
2934 label
= input_line_pointer
;
2937 s0
= input_line_pointer
;
2938 /* Skip over label. */
2939 while (*s0
&& is_part_of_name (*s0
))
2942 /* Remove trailing ":" off labels, as they'd otherwise be considered
2943 part of the name. But don't do it for local labels. */
2944 if (s0
!= input_line_pointer
&& s0
[-1] == ':'
2945 && (s0
- 2 != input_line_pointer
2946 || ! ISDIGIT (s0
[-2])))
2948 else if (label
!= NULL
)
2950 /* For labels that don't end in ":", we save it so we can later give
2951 it the same alignment and address as the associated instruction. */
2953 /* Make room for the label including the ending nul. */
2954 int len_0
= s0
- label
+ 1;
2956 /* Save this label on the MMIX symbol obstack. Saving it on an
2957 obstack is needless for "IS"-pseudos, but it's harmless and we
2958 avoid a little code-cluttering. */
2959 obstack_grow (&mmix_sym_obstack
, label
, len_0
);
2960 pending_label
= obstack_finish (&mmix_sym_obstack
);
2961 pending_label
[len_0
- 1] = 0;
2964 while (*s0
&& ISSPACE (*s0
) && ! is_end_of_line
[(unsigned int) *s0
])
2967 if (pending_label
!= NULL
&& is_end_of_line
[(unsigned int) *s0
])
2968 /* Whoops, this was actually a lone label on a line. Like :-ended
2969 labels, we don't attach such labels to the next instruction or
2971 pending_label
= NULL
;
2973 /* Find local labels of operands. Look for "[0-9][FB]" where the
2974 characters before and after are not part of words. Break if a single
2975 or double quote is seen anywhere. It means we can't have local
2976 labels as part of list with mixed quoted and unquoted members for
2977 mmixal compatibility but we can't have it all. For the moment.
2978 Replace the '<N>B' or '<N>F' with MAGIC_FB_BACKWARD_CHAR<N> and
2979 MAGIC_FB_FORWARD_CHAR<N> respectively. */
2981 /* First make sure we don't have any of the magic characters on the line
2982 appearing as input. */
2987 if (is_end_of_line
[(unsigned int) c
])
2989 if (c
== MAGIC_FB_BACKWARD_CHAR
|| c
== MAGIC_FB_FORWARD_CHAR
)
2990 as_bad (_("invalid characters in input"));
2993 /* Scan again, this time looking for ';' after operands. */
2996 /* Skip the insn. */
3000 && ! is_end_of_line
[(unsigned int) *s
])
3003 /* Skip the spaces after the insn. */
3007 && ! is_end_of_line
[(unsigned int) *s
])
3010 /* Skip the operands. While doing this, replace [0-9][BF] with
3011 (MAGIC_FB_BACKWARD_CHAR|MAGIC_FB_FORWARD_CHAR)[0-9]. */
3012 while ((c
= *s
) != 0
3015 && ! is_end_of_line
[(unsigned int) c
])
3021 /* FIXME: Test-case for semi-colon in string. */
3024 && (! is_end_of_line
[(unsigned int) *s
] || *s
== ';'))
3030 else if (ISDIGIT (c
))
3032 if ((s
[1] != 'B' && s
[1] != 'F')
3033 || is_part_of_name (s
[-1])
3034 || is_part_of_name (s
[2]))
3039 ? MAGIC_FB_BACKWARD_CHAR
: MAGIC_FB_FORWARD_CHAR
);
3047 /* Skip any spaces after the operands. */
3051 && !is_end_of_line
[(unsigned int) *s
])
3054 /* If we're now looking at a semi-colon, then it's an end-of-line
3056 mmix_next_semicolon_is_eoln
= (*s
== ';');
3058 /* Make IS into an EQU by replacing it with "= ". Only match upper-case
3059 though; let lower-case be a syntax error. */
3061 if (s
[0] == 'I' && s
[1] == 'S' && ISSPACE (s
[2]))
3066 /* Since labels can start without ":", we have to handle "X IS 42"
3067 in full here, or "X" will be parsed as a label to be set at ".". */
3068 input_line_pointer
= s
;
3070 /* Right after this function ends, line numbers will be bumped if
3071 input_line_pointer[-1] = '\n'. We want accurate line numbers for
3072 the equals call, so we bump them before the call, and make sure
3073 they aren't bumped afterwards. */
3074 bump_line_counters ();
3076 /* A fb-label is valid as an IS-label. */
3077 if (current_fb_label
>= 0)
3081 /* We need to save this name on our symbol obstack, since the
3082 string we got in fb_label_name is volatile and will change
3083 with every call to fb_label_name, like those resulting from
3084 parsing the IS-operand. */
3085 fb_name
= fb_label_name (current_fb_label
, 1);
3086 obstack_grow (&mmix_sym_obstack
, fb_name
, strlen (fb_name
) + 1);
3087 equals (obstack_finish (&mmix_sym_obstack
), 0);
3088 fb_label_instance_inc (current_fb_label
);
3089 current_fb_label
= -1;
3093 if (pending_label
== NULL
)
3094 as_bad (_("empty label field for IS"));
3096 equals (pending_label
, 0);
3097 pending_label
= NULL
;
3100 /* For mmixal, we can have comments without a comment-start
3102 mmix_handle_rest_of_empty_line ();
3103 input_line_pointer
--;
3105 input_line_pointer
[-1] = ' ';
3107 else if (s
[0] == 'G'
3109 && strncmp (s
, "GREG", 4) == 0
3110 && (ISSPACE (s
[4]) || is_end_of_line
[(unsigned char) s
[4]]))
3112 input_line_pointer
= s
+ 4;
3114 /* Right after this function ends, line numbers will be bumped if
3115 input_line_pointer[-1] = '\n'. We want accurate line numbers for
3116 the s_greg call, so we bump them before the call, and make sure
3117 they aren't bumped afterwards. */
3118 bump_line_counters ();
3120 /* A fb-label is valid as a GREG-label. */
3121 if (current_fb_label
>= 0)
3125 /* We need to save this name on our symbol obstack, since the
3126 string we got in fb_label_name is volatile and will change
3127 with every call to fb_label_name, like those resulting from
3128 parsing the IS-operand. */
3129 fb_name
= fb_label_name (current_fb_label
, 1);
3131 /* Make sure we save the canonical name and don't get bitten by
3133 obstack_1grow (&mmix_sym_obstack
, ':');
3134 obstack_grow (&mmix_sym_obstack
, fb_name
, strlen (fb_name
) + 1);
3135 mmix_greg_internal (obstack_finish (&mmix_sym_obstack
));
3136 fb_label_instance_inc (current_fb_label
);
3137 current_fb_label
= -1;
3140 mmix_greg_internal (pending_label
);
3142 /* Back up before the end-of-line marker that was skipped in
3143 mmix_greg_internal. */
3144 input_line_pointer
--;
3145 input_line_pointer
[-1] = ' ';
3147 pending_label
= NULL
;
3149 else if (pending_label
!= NULL
)
3151 input_line_pointer
+= strlen (pending_label
);
3153 /* See comment above about getting line numbers bumped. */
3154 input_line_pointer
[-1] = '\n';
3158 /* Give the value of an fb-label rewritten as in mmix_handle_mmixal, when
3159 parsing an expression.
3161 On valid calls, input_line_pointer points at a MAGIC_FB_BACKWARD_CHAR
3162 or MAGIC_FB_BACKWARD_CHAR, followed by an ascii digit for the label.
3163 We fill in the label as an expression. */
3166 mmix_fb_label (expP
)
3170 char *fb_internal_name
;
3172 /* This doesn't happen when not using mmixal syntax. */
3174 || (input_line_pointer
[0] != MAGIC_FB_BACKWARD_CHAR
3175 && input_line_pointer
[0] != MAGIC_FB_FORWARD_CHAR
))
3178 /* The current backward reference has augmentation 0. A forward
3179 reference has augmentation 1, unless it's the same as a fb-label on
3180 _this_ line, in which case we add one more so we don't refer to it.
3181 This is the semantics of mmixal; it differs to that of common
3182 fb-labels which refer to a here-label on the current line as a
3183 backward reference. */
3185 = fb_label_name (input_line_pointer
[1] - '0',
3186 (input_line_pointer
[0] == MAGIC_FB_FORWARD_CHAR
? 1 : 0)
3187 + ((input_line_pointer
[1] - '0' == current_fb_label
3188 && input_line_pointer
[0] == MAGIC_FB_FORWARD_CHAR
)
3191 input_line_pointer
+= 2;
3192 sym
= symbol_find_or_make (fb_internal_name
);
3194 /* We don't have to clean up unrelated fields here; we just do what the
3195 expr machinery does, but *not* just what it does for [0-9][fb], since
3196 we need to treat those as ordinary symbols sometimes; see testcases
3197 err-byte2.s and fb-2.s. */
3198 if (S_GET_SEGMENT (sym
) == absolute_section
)
3200 expP
->X_op
= O_constant
;
3201 expP
->X_add_number
= S_GET_VALUE (sym
);
3205 expP
->X_op
= O_symbol
;
3206 expP
->X_add_symbol
= sym
;
3207 expP
->X_add_number
= 0;
3211 /* See whether we need to force a relocation into the output file.
3212 This is used to force out switch and PC relative relocations when
3216 mmix_force_relocation (fixP
)
3219 if (fixP
->fx_r_type
== BFD_RELOC_MMIX_LOCAL
3220 || fixP
->fx_r_type
== BFD_RELOC_VTABLE_INHERIT
3221 || fixP
->fx_r_type
== BFD_RELOC_VTABLE_ENTRY
3222 || fixP
->fx_r_type
== BFD_RELOC_MMIX_BASE_PLUS_OFFSET
)
3225 /* FIXME: This is dubious. Handling of weak symbols should have been
3226 caught before we get here. */
3227 if ((fixP
->fx_addsy
&& S_IS_WEAK (fixP
->fx_addsy
)))
3233 /* All our pcrel relocations are must-keep. Note that md_apply_fix3 is
3234 called *after* this, and will handle getting rid of the presumed
3235 reloc; a relocation isn't *forced* other than to be handled by
3236 md_apply_fix3 (or tc_gen_reloc if linkrelax). */
3243 /* The location from which a PC relative jump should be calculated,
3244 given a PC relative reloc. */
3247 md_pcrel_from_section (fixP
, sec
)
3251 if (fixP
->fx_addsy
!= (symbolS
*) NULL
3252 && (! S_IS_DEFINED (fixP
->fx_addsy
)
3253 || S_GET_SEGMENT (fixP
->fx_addsy
) != sec
))
3255 /* The symbol is undefined (or is defined but not in this section).
3256 Let the linker figure it out. */
3260 return (fixP
->fx_frag
->fr_address
+ fixP
->fx_where
);
3263 /* Adjust the symbol table. We make reg_section relative to the real
3266 FIXME: There's a gas bug; should be fixed when the reg_section symbol
3267 is "accidentally" saved for relocs which are really fixups that will be
3271 mmix_adjust_symtab ()
3275 symbolS
*regsec
= section_symbol (reg_section
);
3276 segT realregsec
= NULL
;
3278 for (prevsym
= sym
= symbol_rootP
;
3280 prevsym
= sym
, sym
= symbol_next (sym
))
3281 if (S_GET_SEGMENT (sym
) == reg_section
)
3284 || (!S_IS_EXTERN (sym
) && !symbol_used_in_reloc_p (sym
)))
3286 symbol_remove (sym
, &symbol_rootP
, &symbol_lastP
);
3288 /* We make one extra turn, or we'll lose the next symbol. We
3289 assume that the symbol we remove is not the symbol root
3290 (.text normally is). */
3295 /* Change section to the *real* register section, so it gets
3296 proper treatment when writing it out. Only do this for
3297 global symbols. This also means we don't have to check for
3299 if (realregsec
== NULL
)
3301 = bfd_make_section_old_way (stdoutput
, MMIX_REG_SECTION_NAME
);
3303 S_SET_SEGMENT (sym
, realregsec
);
3308 /* This is the expansion of LABELS_WITHOUT_COLONS.
3309 We let md_start_line_hook tweak label_without_colon_this_line, and then
3310 this function returns the tweaked value, and sets it to 1 for the next
3311 line. FIXME: Very, very brittle. Not sure it works the way I
3312 thought at the time I first wrote this. */
3315 mmix_label_without_colon_this_line ()
3317 int retval
= label_without_colon_this_line
;
3319 if (! mmix_gnu_syntax
)
3320 label_without_colon_this_line
= 1;
3325 /* This is the expansion of md_relax_frag. We go through the ordinary
3326 relax table function except when the frag is for a GREG. Then we have
3327 to check whether there's another GREG by the same value that we can
3331 mmix_md_relax_frag (seg
, fragP
, stretch
)
3336 if (fragP
->fr_subtype
!= STATE_GREG_DEF
3337 && fragP
->fr_subtype
!= STATE_GREG_UNDF
)
3338 return relax_frag (seg
, fragP
, stretch
);
3340 /* If we're defined, we don't grow. */
3341 if (fragP
->fr_subtype
== STATE_GREG_DEF
)
3344 as_fatal (_("internal: unexpected relax type %d:%d"),
3345 fragP
->fr_type
, fragP
->fr_subtype
);
3349 /* Various things we punt until all input is seen. */
3358 /* The first frag of GREG:s going into the register contents section. */
3359 fragS
*mmix_reg_contents_frags
= NULL
;
3361 /* Reset prefix. All labels reachable at this point must be
3363 mmix_current_prefix
= NULL
;
3366 as_bad_where (bspec_file
, bspec_line
, _("BSPEC without ESPEC."));
3368 /* Emit the low LOC setting of .text. */
3369 if (text_has_contents
&& lowest_text_loc
!= (bfd_vma
) -1)
3372 char locsymbol
[sizeof (":") - 1
3373 + sizeof (MMIX_LOC_SECTION_START_SYMBOL_PREFIX
) - 1
3374 + sizeof (".text")];
3376 /* An exercise in non-ISO-C-ness, this one. */
3377 sprintf (locsymbol
, ":%s%s", MMIX_LOC_SECTION_START_SYMBOL_PREFIX
,
3380 = symbol_new (locsymbol
, absolute_section
, lowest_text_loc
,
3381 &zero_address_frag
);
3382 S_SET_EXTERNAL (symbolP
);
3386 if (data_has_contents
&& lowest_data_loc
!= (bfd_vma
) -1)
3389 char locsymbol
[sizeof (":") - 1
3390 + sizeof (MMIX_LOC_SECTION_START_SYMBOL_PREFIX
) - 1
3391 + sizeof (".data")];
3393 sprintf (locsymbol
, ":%s%s", MMIX_LOC_SECTION_START_SYMBOL_PREFIX
,
3396 = symbol_new (locsymbol
, absolute_section
, lowest_data_loc
,
3397 &zero_address_frag
);
3398 S_SET_EXTERNAL (symbolP
);
3401 /* Unless GNU syntax mode, set "Main" to be a function, so the
3402 disassembler doesn't get confused when we write truly
3403 mmixal-compatible code (and don't use .type). Similarly set it
3404 global (regardless of -globalize-symbols), so the linker sees it as
3405 the start symbol in ELF mode. */
3406 mainsym
= symbol_find (MMIX_START_SYMBOL_NAME
);
3407 if (mainsym
!= NULL
&& ! mmix_gnu_syntax
)
3409 symbol_get_bfdsym (mainsym
)->flags
|= BSF_FUNCTION
;
3410 S_SET_EXTERNAL (mainsym
);
3413 if (n_of_raw_gregs
!= 0)
3415 /* Emit GREGs. They are collected in order of appearance, but must
3416 be emitted in opposite order to both have section address regno*8
3417 and the same allocation order (within a file) as mmixal. */
3418 segT this_segment
= now_seg
;
3419 subsegT this_subsegment
= now_subseg
;
3421 = bfd_make_section_old_way (stdoutput
,
3422 MMIX_REG_CONTENTS_SECTION_NAME
);
3423 subseg_set (regsec
, 0);
3425 /* Finally emit the initialization-value. Emit a variable frag, which
3426 we'll fix in md_estimate_size_before_relax. We set the initializer
3427 for the tc_frag_data field to NULL, so we can use that field for
3428 relaxation purposes. */
3429 mmix_opcode_frag
= NULL
;
3432 mmix_reg_contents_frags
= frag_now
;
3434 for (i
= n_of_raw_gregs
- 1; i
>= 0; i
--)
3436 if (mmix_raw_gregs
[i
].label
!= NULL
)
3437 /* There's a symbol. Let it refer to this location in the
3438 register contents section. The symbol must be globalized
3440 colon (mmix_raw_gregs
[i
].label
);
3442 frag_var (rs_machine_dependent
, 8, 0, STATE_GREG_UNDF
,
3443 make_expr_symbol (&mmix_raw_gregs
[i
].exp
), 0, NULL
);
3446 subseg_set (this_segment
, this_subsegment
);
3449 /* Iterate over frags resulting from GREGs and move those that evidently
3450 have the same value together and point one to another.
3452 This works in time O(N^2) but since the upper bound for non-error use
3453 is 223, it's best to keep this simpler algorithm. */
3454 for (fragP
= mmix_reg_contents_frags
; fragP
!= NULL
; fragP
= fragP
->fr_next
)
3461 symbolS
*symbolP
= fragP
->fr_symbol
;
3463 if (fragP
->fr_type
!= rs_machine_dependent
3464 || fragP
->fr_subtype
!= STATE_GREG_UNDF
)
3467 /* Whatever the outcome, we will have this GREG judged merged or
3468 non-merged. Since the tc_frag_data is NULL at this point, we
3469 default to non-merged. */
3470 fragP
->fr_subtype
= STATE_GREG_DEF
;
3472 /* If we're not supposed to merge GREG definitions, then just don't
3473 look for equivalents. */
3477 osymval
= (offsetT
) S_GET_VALUE (symbolP
);
3478 osymfrag
= symbol_get_frag (symbolP
);
3480 /* If the symbol isn't defined, we can't say that another symbol
3481 equals this frag, then. FIXME: We can look at the "deepest"
3482 defined name; if a = c and b = c then obviously a == b. */
3483 if (! S_IS_DEFINED (symbolP
))
3486 oexpP
= symbol_get_value_expression (fragP
->fr_symbol
);
3488 /* If the initialization value is zero, then we must not merge them. */
3489 if (oexpP
->X_op
== O_constant
&& osymval
== 0)
3492 /* Iterate through the frags downward this one. If we find one that
3493 has the same non-zero value, move it to after this one and point
3494 to it as the equivalent. */
3495 for (fpp
= &fragP
->fr_next
; *fpp
!= NULL
; fpp
= &fpp
[0]->fr_next
)
3499 if (fp
->fr_type
!= rs_machine_dependent
3500 || fp
->fr_subtype
!= STATE_GREG_UNDF
)
3503 /* Calling S_GET_VALUE may simplify the symbol, changing from
3504 expr_section etc. so call it first. */
3505 if ((offsetT
) S_GET_VALUE (fp
->fr_symbol
) == osymval
3506 && symbol_get_frag (fp
->fr_symbol
) == osymfrag
)
3508 /* Move the frag links so the one we found equivalent comes
3509 after the current one, carefully considering that
3510 sometimes fpp == &fragP->fr_next and the moves must be a
3513 fp
->fr_next
= fragP
->fr_next
;
3514 fragP
->fr_next
= fp
;
3520 fragP
->tc_frag_data
= fp
;
3524 /* qsort function for mmix_symbol_gregs. */
3527 cmp_greg_symbol_fixes (parg
, qarg
)
3531 const struct mmix_symbol_greg_fixes
*p
3532 = (const struct mmix_symbol_greg_fixes
*) parg
;
3533 const struct mmix_symbol_greg_fixes
*q
3534 = (const struct mmix_symbol_greg_fixes
*) qarg
;
3536 return p
->offs
> q
->offs
? 1 : p
->offs
< q
->offs
? -1 : 0;
3539 /* Collect GREG definitions from mmix_gregs and hang them as lists sorted
3540 on increasing offsets onto each section symbol or undefined symbol.
3542 Also, remove the register convenience section so it doesn't get output
3543 as an ELF section. */
3549 struct mmix_symbol_gregs
*all_greg_symbols
[MAX_GREGS
];
3550 int n_greg_symbols
= 0;
3552 /* Collect all greg fixups and decorate each corresponding symbol with
3553 the greg fixups for it. */
3554 for (i
= 0; i
< n_of_cooked_gregs
; i
++)
3558 struct mmix_symbol_gregs
*gregs
;
3561 fixP
= mmix_gregs
[i
];
3562 know (fixP
->fx_r_type
== BFD_RELOC_64
);
3564 /* This case isn't doable in general anyway, methinks. */
3565 if (fixP
->fx_subsy
!= NULL
)
3567 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
3568 _("GREG expression too complicated"));
3572 sym
= fixP
->fx_addsy
;
3573 offs
= (offsetT
) fixP
->fx_offset
;
3575 /* If the symbol is defined, then it must be resolved to a section
3576 symbol at this time, or else we don't know how to handle it. */
3577 if (S_IS_DEFINED (sym
))
3579 if (! symbol_section_p (sym
)
3580 && ! bfd_is_abs_section (S_GET_SEGMENT (sym
)))
3581 as_fatal (_("internal: GREG expression not resolved to section"));
3583 offs
+= S_GET_VALUE (sym
);
3586 /* If this is an absolute symbol sufficiently near lowest_data_loc,
3587 then we canonicalize on the data section. Note that offs is
3588 signed here; we may subtract lowest_data_loc which is unsigned.
3589 Careful with those comparisons. */
3590 if (lowest_data_loc
!= (bfd_vma
) -1
3591 && (bfd_vma
) offs
+ 256 > lowest_data_loc
3592 && bfd_is_abs_section (S_GET_SEGMENT (sym
)))
3594 offs
-= (offsetT
) lowest_data_loc
;
3595 sym
= section_symbol (data_section
);
3597 /* Likewise text section. */
3598 else if (lowest_text_loc
!= (bfd_vma
) -1
3599 && (bfd_vma
) offs
+ 256 > lowest_text_loc
3600 && bfd_is_abs_section (S_GET_SEGMENT (sym
)))
3602 offs
-= (offsetT
) lowest_text_loc
;
3603 sym
= section_symbol (text_section
);
3606 gregs
= *symbol_get_tc (sym
);
3610 gregs
= xmalloc (sizeof (*gregs
));
3612 symbol_set_tc (sym
, &gregs
);
3613 all_greg_symbols
[n_greg_symbols
++] = gregs
;
3616 gregs
->greg_fixes
[gregs
->n_gregs
].fix
= fixP
;
3617 gregs
->greg_fixes
[gregs
->n_gregs
++].offs
= offs
;
3620 /* For each symbol having a GREG definition, sort those definitions on
3622 for (i
= 0; i
< n_greg_symbols
; i
++)
3623 qsort (all_greg_symbols
[i
]->greg_fixes
, all_greg_symbols
[i
]->n_gregs
,
3624 sizeof (all_greg_symbols
[i
]->greg_fixes
[0]), cmp_greg_symbol_fixes
);
3626 if (real_reg_section
!= NULL
)
3630 /* FIXME: Pass error state gracefully. */
3631 if (bfd_get_section_flags (stdoutput
, real_reg_section
) & SEC_HAS_CONTENTS
)
3632 as_fatal (_("register section has contents\n"));
3634 /* FIXME: This does not seem like the proper way to kill a section,
3635 but it's the way it's done elsewhere, like elf64-alpha.c. */
3636 /* Really remove the section. */
3637 for (secpp
= &stdoutput
->sections
;
3638 *secpp
!= real_reg_section
;
3639 secpp
= &(*secpp
)->next
)
3641 *secpp
= (*secpp
)->next
;
3642 --stdoutput
->section_count
;
3647 /* Provide an expression for a built-in name provided when-used.
3648 Either a symbol that is a handler; living in 0x10*[1..8] and having
3649 name [DVWIOUZX]_Handler, or a mmixal built-in symbol.
3651 If the name isn't a built-in name and parsed into *EXPP, return zero. */
3654 mmix_parse_predefined_name (name
, expP
)
3659 char *handler_charp
;
3660 const char handler_chars
[] = "DVWIOUZX";
3663 if (! predefined_syms
)
3666 canon_name
= tc_canonicalize_symbol_name (name
);
3668 if (canon_name
[1] == '_'
3669 && strcmp (canon_name
+ 2, "Handler") == 0
3670 && (handler_charp
= strchr (handler_chars
, *canon_name
)) != NULL
)
3672 /* If the symbol doesn't exist, provide one relative to the .text
3675 FIXME: We should provide separate sections, mapped in the linker
3677 symp
= symbol_find (name
);
3679 symp
= symbol_new (name
, text_section
,
3680 0x10 * (handler_charp
+ 1 - handler_chars
),
3681 &zero_address_frag
);
3685 /* These symbols appear when referenced; needed for
3686 mmixal-compatible programs. */
3693 } predefined_abs_syms
[] =
3695 {"Data_Segment", (valueT
) 0x20 << 56},
3696 {"Pool_Segment", (valueT
) 0x40 << 56},
3697 {"Stack_Segment", (valueT
) 0x60 << 56},
3705 {"BinaryReadWrite", 4},
3728 /* If it's already in the symbol table, we shouldn't do anything. */
3729 symp
= symbol_find (name
);
3734 i
< sizeof (predefined_abs_syms
)/sizeof (predefined_abs_syms
[0]);
3736 if (strcmp (canon_name
, predefined_abs_syms
[i
].name
) == 0)
3738 symbol_table_insert (symbol_new (predefined_abs_syms
[i
].name
,
3740 predefined_abs_syms
[i
].val
,
3741 &zero_address_frag
));
3743 /* Let gas find the symbol we just created, through its
3748 /* Not one of those symbols. Let gas handle it. */
3752 expP
->X_op
= O_symbol
;
3753 expP
->X_add_number
= 0;
3754 expP
->X_add_symbol
= symp
;
3755 expP
->X_op_symbol
= NULL
;
3760 /* Worker for mmix_frob_file_before_adjust. */
3763 mmix_frob_local_reloc (abfd
, sec
, xxx
)
3764 bfd
*abfd ATTRIBUTE_UNUSED
;
3766 PTR xxx ATTRIBUTE_UNUSED
;
3768 segment_info_type
*seginfo
= seg_info (sec
);
3771 if (seginfo
== NULL
)
3774 for (fixp
= seginfo
->fix_root
; fixp
; fixp
= fixp
->fx_next
)
3775 if (! fixp
->fx_done
&& fixp
->fx_addsy
!= NULL
)
3777 symbolS
*sym
= fixp
->fx_addsy
;
3778 asection
*section
= S_GET_SEGMENT (sym
);
3780 if (section
== reg_section
3781 && fixp
->fx_r_type
== BFD_RELOC_MMIX_LOCAL
)
3783 /* If the register is marked global, we don't need to replace
3784 with the *real* register section since that will be done
3785 when the symbol is changed. */
3786 if (! S_IS_EXTERNAL (sym
))
3787 /* If it's a local symbol, we replace it with an anonymous
3788 one with the same constant value. */
3789 fixp
->fx_addsy
= expr_build_uconstant (S_GET_VALUE (sym
));
3794 /* Change fixups for register symbols for BFD_MMIX_LOCAL to be for an
3798 mmix_frob_file_before_adjust ()
3801 bfd_map_over_sections (stdoutput
, mmix_frob_local_reloc
, (char *) 0);
3804 /* Just check that we don't have a BSPEC/ESPEC pair active when changing
3805 sections "normally", and get knowledge about alignment from the new
3809 mmix_md_elf_section_change_hook ()
3812 as_bad (_("section change from within a BSPEC/ESPEC pair is not supported"));
3814 last_alignment
= bfd_get_section_alignment (now_seg
->owner
, now_seg
);
3818 /* The LOC worker. This is like s_org, but we have to support changing
3823 int ignore ATTRIBUTE_UNUSED
;
3831 /* Must not have a BSPEC in progress. */
3834 as_bad (_("directive LOC from within a BSPEC/ESPEC pair is not supported"));
3838 section
= expression (&exp
);
3840 if (exp
.X_op
== O_illegal
3841 || exp
.X_op
== O_absent
3842 || exp
.X_op
== O_big
3843 || section
== undefined_section
)
3845 as_bad (_("invalid LOC expression"));
3849 if (section
== absolute_section
)
3851 /* Translate a constant into a suitable section. */
3853 if (exp
.X_add_number
< ((offsetT
) 0x20 << 56))
3855 /* Lower than Data_Segment - assume it's .text. */
3856 section
= text_section
;
3858 /* Save the lowest seen location, so we can pass on this
3859 information to the linker. We don't actually org to this
3860 location here, we just pass on information to the linker so
3861 it can put the code there for us. */
3863 /* If there was already a loc (that has to be set lower than
3864 this one), we org at (this - lower). There's an implicit
3865 "LOC 0" before any entered code. FIXME: handled by spurious
3866 settings of text_has_contents. */
3867 if (exp
.X_add_number
< 0
3868 || exp
.X_add_number
< (offsetT
) lowest_text_loc
)
3870 as_bad (_("LOC expression stepping backwards is not supported"));
3871 exp
.X_op
= O_absent
;
3875 if (text_has_contents
&& lowest_text_loc
== (bfd_vma
) -1)
3876 lowest_text_loc
= 0;
3878 if (lowest_text_loc
== (bfd_vma
) -1)
3880 lowest_text_loc
= exp
.X_add_number
;
3882 /* We want only to change the section, not set an offset. */
3883 exp
.X_op
= O_absent
;
3886 exp
.X_add_number
-= lowest_text_loc
;
3891 /* Do the same for the .data section. */
3892 section
= data_section
;
3894 if (exp
.X_add_number
< (offsetT
) lowest_data_loc
)
3896 as_bad (_("LOC expression stepping backwards is not supported"));
3897 exp
.X_op
= O_absent
;
3901 if (data_has_contents
&& lowest_data_loc
== (bfd_vma
) -1)
3902 lowest_data_loc
= (bfd_vma
) 0x20 << 56;
3904 if (lowest_data_loc
== (bfd_vma
) -1)
3906 lowest_data_loc
= exp
.X_add_number
;
3908 /* We want only to change the section, not set an offset. */
3909 exp
.X_op
= O_absent
;
3912 exp
.X_add_number
-= lowest_data_loc
;
3917 if (section
!= now_seg
)
3919 obj_elf_section_change_hook ();
3920 subseg_set (section
, 0);
3922 /* Call our section change hooks using the official hook. */
3923 md_elf_section_change_hook ();
3926 if (exp
.X_op
!= O_absent
)
3928 if (exp
.X_op
!= O_constant
&& exp
.X_op
!= O_symbol
)
3930 /* Handle complex expressions. */
3931 sym
= make_expr_symbol (&exp
);
3936 sym
= exp
.X_add_symbol
;
3937 off
= exp
.X_add_number
;
3940 p
= frag_var (rs_org
, 1, 1, (relax_substateT
) 0, sym
, off
, (char *) 0);
3944 mmix_handle_rest_of_empty_line ();
3947 /* The BYTE worker. We have to support sequences of mixed "strings",
3948 numbers and other constant "first-pass" reducible expressions separated
3957 if (now_seg
== text_section
)
3958 text_has_contents
= 1;
3959 else if (now_seg
== data_section
)
3960 data_has_contents
= 1;
3965 switch (*input_line_pointer
)
3968 ++input_line_pointer
;
3969 start
= input_line_pointer
;
3970 while (is_a_char (c
= next_char_of_string ()))
3972 FRAG_APPEND_1_CHAR (c
);
3975 if (input_line_pointer
[-1] != '\"')
3977 /* We will only get here in rare cases involving #NO_APP,
3978 where the unterminated string is not recognized by the
3979 preformatting pass. */
3980 as_bad (_("unterminated string"));
3981 mmix_discard_rest_of_line ();
3989 segT expseg
= expression (&exp
);
3991 /* We have to allow special register names as constant numbers. */
3992 if ((expseg
!= absolute_section
&& expseg
!= reg_section
)
3993 || (exp
.X_op
!= O_constant
3994 && (exp
.X_op
!= O_register
3995 || exp
.X_add_number
<= 255)))
3997 as_bad (_("BYTE expression not a pure number"));
3998 mmix_discard_rest_of_line ();
4001 else if ((exp
.X_add_number
> 255 && exp
.X_op
!= O_register
)
4002 || exp
.X_add_number
< 0)
4004 /* Note that mmixal does not allow negative numbers in
4005 BYTE sequences, so neither should we. */
4006 as_bad (_("BYTE expression not in the range 0..255"));
4007 mmix_discard_rest_of_line ();
4011 FRAG_APPEND_1_CHAR (exp
.X_add_number
);
4017 c
= *input_line_pointer
++;
4021 input_line_pointer
--;
4023 if (mmix_gnu_syntax
)
4024 demand_empty_rest_of_line ();
4027 mmix_discard_rest_of_line ();
4028 /* Do like demand_empty_rest_of_line and step over the end-of-line
4030 input_line_pointer
++;
4033 /* Make sure we align for the next instruction. */
4037 /* Like cons_worker, but we have to ignore "naked comments", not barf on
4038 them. Implements WYDE, TETRA and OCTA. We're a little bit more
4039 lenient than mmix_byte but FIXME: they should eventually merge. */
4048 /* If we don't have any contents, then it's ok to have a specified start
4049 address that is not a multiple of the max data size. We will then
4050 align it as necessary when we get here. Otherwise, it's a fatal sin. */
4051 if (now_seg
== text_section
)
4053 if (lowest_text_loc
!= (bfd_vma
) -1
4054 && (lowest_text_loc
& (nbytes
- 1)) != 0)
4056 if (text_has_contents
)
4057 as_bad (_("data item with alignment larger than location"));
4058 else if (want_unaligned
)
4059 as_bad (_("unaligned data at an absolute location is not supported"));
4061 lowest_text_loc
&= ~((bfd_vma
) nbytes
- 1);
4062 lowest_text_loc
+= (bfd_vma
) nbytes
;
4065 text_has_contents
= 1;
4067 else if (now_seg
== data_section
)
4069 if (lowest_data_loc
!= (bfd_vma
) -1
4070 && (lowest_data_loc
& (nbytes
- 1)) != 0)
4072 if (data_has_contents
)
4073 as_bad (_("data item with alignment larger than location"));
4074 else if (want_unaligned
)
4075 as_bad (_("unaligned data at an absolute location is not supported"));
4077 lowest_data_loc
&= ~((bfd_vma
) nbytes
- 1);
4078 lowest_data_loc
+= (bfd_vma
) nbytes
;
4081 data_has_contents
= 1;
4084 /* Always align these unless asked not to (valid for the current pseudo). */
4085 if (! want_unaligned
)
4087 last_alignment
= nbytes
== 2 ? 1 : (nbytes
== 4 ? 2 : 3);
4088 frag_align (last_alignment
, 0, 0);
4089 record_alignment (now_seg
, last_alignment
);
4092 /* For mmixal compatibility, a label for an instruction (and emitting
4093 pseudo) refers to the _aligned_ address. So we have to emit the
4095 if (current_fb_label
>= 0)
4096 colon (fb_label_name (current_fb_label
, 1));
4097 else if (pending_label
!= NULL
)
4099 colon (pending_label
);
4100 pending_label
= NULL
;
4105 if (is_end_of_line
[(unsigned int) *input_line_pointer
])
4107 /* Default to zero if the expression was absent. */
4109 exp
.X_op
= O_constant
;
4110 exp
.X_add_number
= 0;
4112 exp
.X_add_symbol
= NULL
;
4113 exp
.X_op_symbol
= NULL
;
4114 emit_expr (&exp
, (unsigned int) nbytes
);
4121 switch (*input_line_pointer
)
4123 /* We support strings here too; each character takes up nbytes
4126 ++input_line_pointer
;
4127 start
= input_line_pointer
;
4128 while (is_a_char (c
= next_char_of_string ()))
4130 exp
.X_op
= O_constant
;
4131 exp
.X_add_number
= c
;
4133 emit_expr (&exp
, (unsigned int) nbytes
);
4136 if (input_line_pointer
[-1] != '\"')
4138 /* We will only get here in rare cases involving #NO_APP,
4139 where the unterminated string is not recognized by the
4140 preformatting pass. */
4141 as_bad (_("unterminated string"));
4142 mmix_discard_rest_of_line ();
4150 emit_expr (&exp
, (unsigned int) nbytes
);
4156 while (*input_line_pointer
++ == ',');
4158 input_line_pointer
--; /* Put terminator back into stream. */
4160 mmix_handle_rest_of_empty_line ();
4162 /* We don't need to step up the counter for the current_fb_label here;
4163 that's handled by the caller. */
4166 /* The md_do_align worker. At present, we just record an alignment to
4167 nullify the automatic alignment we do for WYDE, TETRA and OCTA, as gcc
4168 does not use the unaligned macros when attribute packed is used.
4169 Arguably this is a GCC bug. */
4172 mmix_md_do_align (n
, fill
, len
, max
)
4174 char *fill ATTRIBUTE_UNUSED
;
4175 int len ATTRIBUTE_UNUSED
;
4176 int max ATTRIBUTE_UNUSED
;
4179 want_unaligned
= n
== 0;