tc-mmix.c revision 1.1.1.7 1 1.1 skrll /* tc-mmix.c -- Assembler for Don Knuth's MMIX.
2 1.1.1.7 christos Copyright (C) 2001-2020 Free Software Foundation, Inc.
3 1.1 skrll
4 1.1 skrll This file is part of GAS, the GNU Assembler.
5 1.1 skrll
6 1.1 skrll GAS is free software; you can redistribute it and/or modify
7 1.1 skrll it under the terms of the GNU General Public License as published by
8 1.1 skrll the Free Software Foundation; either version 3, or (at your option)
9 1.1 skrll any later version.
10 1.1 skrll
11 1.1 skrll GAS is distributed in the hope that it will be useful,
12 1.1 skrll but WITHOUT ANY WARRANTY; without even the implied warranty of
13 1.1 skrll MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 1.1 skrll GNU General Public License for more details.
15 1.1 skrll
16 1.1 skrll You should have received a copy of the GNU General Public License
17 1.1 skrll along with GAS; see the file COPYING. If not, write to
18 1.1 skrll the Free Software Foundation, 51 Franklin Street - Fifth Floor,
19 1.1 skrll Boston, MA 02110-1301, USA. */
20 1.1 skrll
21 1.1 skrll /* Knuth's assembler mmixal does not provide a relocatable format; mmo is
22 1.1 skrll to be considered a final link-format. In the final link, we make mmo,
23 1.1 skrll but for relocatable files, we use ELF.
24 1.1 skrll
25 1.1 skrll One goal is to provide a superset of what mmixal does, including
26 1.1 skrll compatible syntax, but the main purpose is to serve GCC. */
27 1.1 skrll
28 1.1 skrll
29 1.1 skrll #include "as.h"
30 1.1.1.3 christos #include <limits.h>
31 1.1 skrll #include "subsegs.h"
32 1.1 skrll #include "elf/mmix.h"
33 1.1 skrll #include "opcode/mmix.h"
34 1.1 skrll #include "safe-ctype.h"
35 1.1 skrll #include "dwarf2dbg.h"
36 1.1 skrll #include "obstack.h"
37 1.1 skrll
38 1.1 skrll /* Something to describe what we need to do with a fixup before output,
39 1.1 skrll for example assert something of what it became or make a relocation. */
40 1.1 skrll
41 1.1 skrll enum mmix_fixup_action
42 1.1.1.3 christos {
43 1.1.1.3 christos mmix_fixup_byte,
44 1.1.1.3 christos mmix_fixup_register,
45 1.1.1.3 christos mmix_fixup_register_or_adjust_for_byte
46 1.1.1.3 christos };
47 1.1 skrll
48 1.1 skrll static int get_spec_regno (char *);
49 1.1 skrll static int get_operands (int, char *, expressionS *);
50 1.1 skrll static int get_putget_operands (struct mmix_opcode *, char *, expressionS *);
51 1.1 skrll static void s_prefix (int);
52 1.1 skrll static void s_greg (int);
53 1.1 skrll static void s_loc (int);
54 1.1 skrll static void s_bspec (int);
55 1.1 skrll static void s_espec (int);
56 1.1 skrll static void mmix_s_local (int);
57 1.1 skrll static void mmix_greg_internal (char *);
58 1.1 skrll static void mmix_set_geta_branch_offset (char *, offsetT);
59 1.1 skrll static void mmix_set_jmp_offset (char *, offsetT);
60 1.1 skrll static void mmix_fill_nops (char *, int);
61 1.1 skrll static int cmp_greg_symbol_fixes (const void *, const void *);
62 1.1 skrll static int cmp_greg_val_greg_symbol_fixes (const void *, const void *);
63 1.1 skrll static void mmix_handle_rest_of_empty_line (void);
64 1.1 skrll static void mmix_discard_rest_of_line (void);
65 1.1 skrll static void mmix_byte (void);
66 1.1 skrll static void mmix_cons (int);
67 1.1 skrll
68 1.1 skrll /* Continue the tradition of symbols.c; use control characters to enforce
69 1.1 skrll magic. These are used when replacing e.g. 8F and 8B so we can handle
70 1.1 skrll such labels correctly with the common parser hooks. */
71 1.1 skrll #define MAGIC_FB_BACKWARD_CHAR '\003'
72 1.1 skrll #define MAGIC_FB_FORWARD_CHAR '\004'
73 1.1 skrll
74 1.1 skrll /* Copy the location of a frag to a fix. */
75 1.1 skrll #define COPY_FR_WHERE_TO_FX(FRAG, FIX) \
76 1.1 skrll do \
77 1.1 skrll { \
78 1.1 skrll (FIX)->fx_file = (FRAG)->fr_file; \
79 1.1 skrll (FIX)->fx_line = (FRAG)->fr_line; \
80 1.1 skrll } \
81 1.1 skrll while (0)
82 1.1 skrll
83 1.1 skrll const char *md_shortopts = "x";
84 1.1 skrll static int current_fb_label = -1;
85 1.1 skrll static char *pending_label = NULL;
86 1.1 skrll
87 1.1 skrll static bfd_vma lowest_text_loc = (bfd_vma) -1;
88 1.1 skrll static int text_has_contents = 0;
89 1.1 skrll
90 1.1 skrll /* The alignment of the previous instruction, and a boolean for whether we
91 1.1 skrll want to avoid aligning the next WYDE, TETRA, OCTA or insn. */
92 1.1 skrll static int last_alignment = 0;
93 1.1 skrll static int want_unaligned = 0;
94 1.1 skrll
95 1.1 skrll static bfd_vma lowest_data_loc = (bfd_vma) -1;
96 1.1 skrll static int data_has_contents = 0;
97 1.1 skrll
98 1.1 skrll /* The fragS of the instruction being assembled. Only valid from within
99 1.1 skrll md_assemble. */
100 1.1 skrll fragS *mmix_opcode_frag = NULL;
101 1.1 skrll
102 1.1 skrll /* Raw GREGs as appearing in input. These may be fewer than the number
103 1.1 skrll after relaxing. */
104 1.1 skrll static int n_of_raw_gregs = 0;
105 1.1 skrll static struct
106 1.1 skrll {
107 1.1 skrll char *label;
108 1.1 skrll expressionS exp;
109 1.1 skrll } mmix_raw_gregs[MAX_GREGS];
110 1.1 skrll
111 1.1.1.3 christos static struct loc_assert_s
112 1.1.1.3 christos {
113 1.1.1.3 christos segT old_seg;
114 1.1.1.3 christos symbolS *loc_sym;
115 1.1.1.4 christos fragS *frag;
116 1.1.1.3 christos struct loc_assert_s *next;
117 1.1.1.3 christos } *loc_asserts = NULL;
118 1.1.1.3 christos
119 1.1 skrll /* Fixups for all unique GREG registers. We store the fixups here in
120 1.1 skrll md_convert_frag, then we use the array to convert
121 1.1 skrll BFD_RELOC_MMIX_BASE_PLUS_OFFSET fixups in tc_gen_reloc. The index is
122 1.1 skrll just a running number and is not supposed to be correlated to a
123 1.1 skrll register number. */
124 1.1 skrll static fixS *mmix_gregs[MAX_GREGS];
125 1.1 skrll static int n_of_cooked_gregs = 0;
126 1.1 skrll
127 1.1 skrll /* Pointing to the register section we use for output. */
128 1.1 skrll static asection *real_reg_section;
129 1.1 skrll
130 1.1 skrll /* For each symbol; unknown or section symbol, we keep a list of GREG
131 1.1 skrll definitions sorted on increasing offset. It seems no use keeping count
132 1.1 skrll to allocate less room than the maximum number of gregs when we've found
133 1.1 skrll one for a section or symbol. */
134 1.1 skrll struct mmix_symbol_gregs
135 1.1 skrll {
136 1.1 skrll int n_gregs;
137 1.1 skrll struct mmix_symbol_greg_fixes
138 1.1 skrll {
139 1.1 skrll fixS *fix;
140 1.1 skrll
141 1.1 skrll /* A signed type, since we may have GREGs pointing slightly before the
142 1.1 skrll contents of a section. */
143 1.1 skrll offsetT offs;
144 1.1 skrll } greg_fixes[MAX_GREGS];
145 1.1 skrll };
146 1.1 skrll
147 1.1 skrll /* Should read insert a colon on something that starts in column 0 on
148 1.1 skrll this line? */
149 1.1 skrll static int label_without_colon_this_line = 1;
150 1.1 skrll
151 1.1 skrll /* Should we automatically expand instructions into multiple insns in
152 1.1 skrll order to generate working code? */
153 1.1 skrll static int expand_op = 1;
154 1.1 skrll
155 1.1 skrll /* Should we warn when expanding operands? FIXME: test-cases for when -x
156 1.1 skrll is absent. */
157 1.1 skrll static int warn_on_expansion = 1;
158 1.1 skrll
159 1.1 skrll /* Should we merge non-zero GREG register definitions? */
160 1.1 skrll static int merge_gregs = 1;
161 1.1 skrll
162 1.1 skrll /* Should we pass on undefined BFD_RELOC_MMIX_BASE_PLUS_OFFSET relocs
163 1.1 skrll (missing suitable GREG definitions) to the linker? */
164 1.1 skrll static int allocate_undefined_gregs_in_linker = 0;
165 1.1 skrll
166 1.1 skrll /* Should we emit built-in symbols? */
167 1.1 skrll static int predefined_syms = 1;
168 1.1 skrll
169 1.1 skrll /* Should we allow anything but the listed special register name
170 1.1 skrll (e.g. equated symbols)? */
171 1.1 skrll static int equated_spec_regs = 1;
172 1.1 skrll
173 1.1 skrll /* Do we require standard GNU syntax? */
174 1.1 skrll int mmix_gnu_syntax = 0;
175 1.1 skrll
176 1.1 skrll /* Do we globalize all symbols? */
177 1.1 skrll int mmix_globalize_symbols = 0;
178 1.1 skrll
179 1.1 skrll /* When expanding insns, do we want to expand PUSHJ as a call to a stub
180 1.1 skrll (or else as a series of insns)? */
181 1.1 skrll int pushj_stubs = 1;
182 1.1 skrll
183 1.1 skrll /* Do we know that the next semicolon is at the end of the operands field
184 1.1 skrll (in mmixal mode; constant 1 in GNU mode)? */
185 1.1 skrll int mmix_next_semicolon_is_eoln = 1;
186 1.1 skrll
187 1.1 skrll /* Do we have a BSPEC in progress? */
188 1.1 skrll static int doing_bspec = 0;
189 1.1.1.5 christos static const char *bspec_file;
190 1.1 skrll static unsigned int bspec_line;
191 1.1 skrll
192 1.1 skrll struct option md_longopts[] =
193 1.1 skrll {
194 1.1 skrll #define OPTION_RELAX (OPTION_MD_BASE)
195 1.1 skrll #define OPTION_NOEXPAND (OPTION_RELAX + 1)
196 1.1 skrll #define OPTION_NOMERGEGREG (OPTION_NOEXPAND + 1)
197 1.1 skrll #define OPTION_NOSYMS (OPTION_NOMERGEGREG + 1)
198 1.1 skrll #define OPTION_GNU_SYNTAX (OPTION_NOSYMS + 1)
199 1.1 skrll #define OPTION_GLOBALIZE_SYMBOLS (OPTION_GNU_SYNTAX + 1)
200 1.1 skrll #define OPTION_FIXED_SPEC_REGS (OPTION_GLOBALIZE_SYMBOLS + 1)
201 1.1 skrll #define OPTION_LINKER_ALLOCATED_GREGS (OPTION_FIXED_SPEC_REGS + 1)
202 1.1 skrll #define OPTION_NOPUSHJSTUBS (OPTION_LINKER_ALLOCATED_GREGS + 1)
203 1.1 skrll {"linkrelax", no_argument, NULL, OPTION_RELAX},
204 1.1 skrll {"no-expand", no_argument, NULL, OPTION_NOEXPAND},
205 1.1 skrll {"no-merge-gregs", no_argument, NULL, OPTION_NOMERGEGREG},
206 1.1 skrll {"no-predefined-syms", no_argument, NULL, OPTION_NOSYMS},
207 1.1 skrll {"gnu-syntax", no_argument, NULL, OPTION_GNU_SYNTAX},
208 1.1 skrll {"globalize-symbols", no_argument, NULL, OPTION_GLOBALIZE_SYMBOLS},
209 1.1 skrll {"fixed-special-register-names", no_argument, NULL,
210 1.1 skrll OPTION_FIXED_SPEC_REGS},
211 1.1 skrll {"linker-allocated-gregs", no_argument, NULL,
212 1.1 skrll OPTION_LINKER_ALLOCATED_GREGS},
213 1.1 skrll {"no-pushj-stubs", no_argument, NULL, OPTION_NOPUSHJSTUBS},
214 1.1 skrll {"no-stubs", no_argument, NULL, OPTION_NOPUSHJSTUBS},
215 1.1 skrll {NULL, no_argument, NULL, 0}
216 1.1 skrll };
217 1.1 skrll
218 1.1 skrll size_t md_longopts_size = sizeof (md_longopts);
219 1.1 skrll
220 1.1 skrll static struct hash_control *mmix_opcode_hash;
221 1.1 skrll
222 1.1 skrll /* We use these when implementing the PREFIX pseudo. */
223 1.1 skrll char *mmix_current_prefix;
224 1.1 skrll struct obstack mmix_sym_obstack;
225 1.1 skrll
226 1.1 skrll
227 1.1 skrll /* For MMIX, we encode the relax_substateT:s (in e.g. fr_substate) as one
228 1.1 skrll bit length, and the relax-type shifted on top of that. There seems to
229 1.1 skrll be no point in making the relaxation more fine-grained; the linker does
230 1.1 skrll that better and we might interfere by changing non-optimal relaxations
231 1.1 skrll into other insns that cannot be relaxed as easily.
232 1.1 skrll
233 1.1 skrll Groups for MMIX relaxing:
234 1.1 skrll
235 1.1 skrll 1. GETA
236 1.1 skrll extra length: zero or three insns.
237 1.1 skrll
238 1.1 skrll 2. Bcc
239 1.1 skrll extra length: zero or five insns.
240 1.1 skrll
241 1.1 skrll 3. PUSHJ
242 1.1 skrll extra length: zero or four insns.
243 1.1 skrll Special handling to deal with transition to PUSHJSTUB.
244 1.1 skrll
245 1.1 skrll 4. JMP
246 1.1 skrll extra length: zero or four insns.
247 1.1 skrll
248 1.1 skrll 5. GREG
249 1.1 skrll special handling, allocates a named global register unless another
250 1.1 skrll is within reach for all uses.
251 1.1 skrll
252 1.1 skrll 6. PUSHJSTUB
253 1.1 skrll special handling (mostly) for external references; assumes the
254 1.1 skrll linker will generate a stub if target is no longer than 256k from
255 1.1 skrll the end of the section plus max size of previous stubs. Zero or
256 1.1 skrll four insns. */
257 1.1 skrll
258 1.1 skrll #define STATE_GETA (1)
259 1.1 skrll #define STATE_BCC (2)
260 1.1 skrll #define STATE_PUSHJ (3)
261 1.1 skrll #define STATE_JMP (4)
262 1.1 skrll #define STATE_GREG (5)
263 1.1 skrll #define STATE_PUSHJSTUB (6)
264 1.1 skrll
265 1.1 skrll /* No fine-grainedness here. */
266 1.1 skrll #define STATE_LENGTH_MASK (1)
267 1.1 skrll
268 1.1 skrll #define STATE_ZERO (0)
269 1.1 skrll #define STATE_MAX (1)
270 1.1 skrll
271 1.1 skrll /* More descriptive name for convenience. */
272 1.1 skrll /* FIXME: We should start on something different, not MAX. */
273 1.1 skrll #define STATE_UNDF STATE_MAX
274 1.1 skrll
275 1.1 skrll /* FIXME: For GREG, we must have other definitions; UNDF == MAX isn't
276 1.1 skrll appropriate; we need it the other way round. This value together with
277 1.1 skrll fragP->tc_frag_data shows what state the frag is in: tc_frag_data
278 1.1 skrll non-NULL means 0, NULL means 8 bytes. */
279 1.1 skrll #define STATE_GREG_UNDF ENCODE_RELAX (STATE_GREG, STATE_ZERO)
280 1.1 skrll #define STATE_GREG_DEF ENCODE_RELAX (STATE_GREG, STATE_MAX)
281 1.1 skrll
282 1.1 skrll /* These displacements are relative to the address following the opcode
283 1.1 skrll word of the instruction. The catch-all states have zero for "reach"
284 1.1 skrll and "next" entries. */
285 1.1 skrll
286 1.1 skrll #define GETA_0F (65536 * 4 - 8)
287 1.1 skrll #define GETA_0B (-65536 * 4 - 4)
288 1.1 skrll
289 1.1 skrll #define GETA_MAX_LEN 4 * 4
290 1.1 skrll #define GETA_3F 0
291 1.1 skrll #define GETA_3B 0
292 1.1 skrll
293 1.1 skrll #define BCC_0F GETA_0F
294 1.1 skrll #define BCC_0B GETA_0B
295 1.1 skrll
296 1.1 skrll #define BCC_MAX_LEN 6 * 4
297 1.1 skrll #define BCC_5F GETA_3F
298 1.1 skrll #define BCC_5B GETA_3B
299 1.1 skrll
300 1.1 skrll #define PUSHJ_0F GETA_0F
301 1.1 skrll #define PUSHJ_0B GETA_0B
302 1.1 skrll
303 1.1 skrll #define PUSHJ_MAX_LEN 5 * 4
304 1.1 skrll #define PUSHJ_4F GETA_3F
305 1.1 skrll #define PUSHJ_4B GETA_3B
306 1.1 skrll
307 1.1 skrll /* We'll very rarely have sections longer than LONG_MAX, but we'll make a
308 1.1 skrll feeble attempt at getting 64-bit values. */
309 1.1 skrll #define PUSHJSTUB_MAX ((offsetT) (((addressT) -1) >> 1))
310 1.1 skrll #define PUSHJSTUB_MIN (-PUSHJSTUB_MAX - 1)
311 1.1 skrll
312 1.1 skrll #define JMP_0F (65536 * 256 * 4 - 8)
313 1.1 skrll #define JMP_0B (-65536 * 256 * 4 - 4)
314 1.1 skrll
315 1.1 skrll #define JMP_MAX_LEN 5 * 4
316 1.1 skrll #define JMP_4F 0
317 1.1 skrll #define JMP_4B 0
318 1.1 skrll
319 1.1 skrll #define RELAX_ENCODE_SHIFT 1
320 1.1 skrll #define ENCODE_RELAX(what, length) (((what) << RELAX_ENCODE_SHIFT) + (length))
321 1.1 skrll
322 1.1 skrll const relax_typeS mmix_relax_table[] =
323 1.1 skrll {
324 1.1 skrll /* Error sentinel (0, 0). */
325 1.1 skrll {1, 1, 0, 0},
326 1.1 skrll
327 1.1 skrll /* Unused (0, 1). */
328 1.1 skrll {1, 1, 0, 0},
329 1.1 skrll
330 1.1 skrll /* GETA (1, 0). */
331 1.1 skrll {GETA_0F, GETA_0B, 0, ENCODE_RELAX (STATE_GETA, STATE_MAX)},
332 1.1 skrll
333 1.1 skrll /* GETA (1, 1). */
334 1.1 skrll {GETA_3F, GETA_3B,
335 1.1 skrll GETA_MAX_LEN - 4, 0},
336 1.1 skrll
337 1.1 skrll /* BCC (2, 0). */
338 1.1 skrll {BCC_0F, BCC_0B, 0, ENCODE_RELAX (STATE_BCC, STATE_MAX)},
339 1.1 skrll
340 1.1 skrll /* BCC (2, 1). */
341 1.1 skrll {BCC_5F, BCC_5B,
342 1.1 skrll BCC_MAX_LEN - 4, 0},
343 1.1 skrll
344 1.1 skrll /* PUSHJ (3, 0). Next state is actually PUSHJSTUB (6, 0). */
345 1.1 skrll {PUSHJ_0F, PUSHJ_0B, 0, ENCODE_RELAX (STATE_PUSHJSTUB, STATE_ZERO)},
346 1.1 skrll
347 1.1 skrll /* PUSHJ (3, 1). */
348 1.1 skrll {PUSHJ_4F, PUSHJ_4B,
349 1.1 skrll PUSHJ_MAX_LEN - 4, 0},
350 1.1 skrll
351 1.1 skrll /* JMP (4, 0). */
352 1.1 skrll {JMP_0F, JMP_0B, 0, ENCODE_RELAX (STATE_JMP, STATE_MAX)},
353 1.1 skrll
354 1.1 skrll /* JMP (4, 1). */
355 1.1 skrll {JMP_4F, JMP_4B,
356 1.1 skrll JMP_MAX_LEN - 4, 0},
357 1.1 skrll
358 1.1 skrll /* GREG (5, 0), (5, 1), though the table entry isn't used. */
359 1.1 skrll {0, 0, 0, 0}, {0, 0, 0, 0},
360 1.1 skrll
361 1.1 skrll /* PUSHJSTUB (6, 0). PUSHJ (3, 0) uses the range, so we set it to infinite. */
362 1.1 skrll {PUSHJSTUB_MAX, PUSHJSTUB_MIN,
363 1.1 skrll 0, ENCODE_RELAX (STATE_PUSHJ, STATE_MAX)},
364 1.1 skrll /* PUSHJSTUB (6, 1) isn't used. */
365 1.1 skrll {0, 0, PUSHJ_MAX_LEN, 0}
366 1.1 skrll };
367 1.1 skrll
368 1.1 skrll const pseudo_typeS md_pseudo_table[] =
369 1.1 skrll {
370 1.1 skrll /* Support " .greg sym,expr" syntax. */
371 1.1 skrll {"greg", s_greg, 0},
372 1.1 skrll
373 1.1 skrll /* Support " .bspec expr" syntax. */
374 1.1 skrll {"bspec", s_bspec, 1},
375 1.1 skrll
376 1.1 skrll /* Support " .espec" syntax. */
377 1.1 skrll {"espec", s_espec, 1},
378 1.1 skrll
379 1.1 skrll /* Support " .local $45" syntax. */
380 1.1 skrll {"local", mmix_s_local, 1},
381 1.1 skrll
382 1.1 skrll {NULL, 0, 0}
383 1.1 skrll };
384 1.1 skrll
385 1.1 skrll const char mmix_comment_chars[] = "%!";
386 1.1 skrll
387 1.1 skrll /* A ':' is a valid symbol character in mmixal. It's the prefix
388 1.1 skrll delimiter, but other than that, it works like a symbol character,
389 1.1 skrll except that we strip one off at the beginning of symbols. An '@' is a
390 1.1 skrll symbol by itself (for the current location); space around it must not
391 1.1 skrll be stripped. */
392 1.1 skrll const char mmix_symbol_chars[] = ":@";
393 1.1 skrll
394 1.1 skrll const char line_comment_chars[] = "*#";
395 1.1 skrll
396 1.1 skrll const char line_separator_chars[] = ";";
397 1.1 skrll
398 1.1.1.5 christos const char EXP_CHARS[] = "eE";
399 1.1 skrll
400 1.1.1.5 christos const char FLT_CHARS[] = "rf";
401 1.1 skrll
402 1.1 skrll
403 1.1 skrll /* Fill in the offset-related part of GETA or Bcc. */
404 1.1 skrll
405 1.1 skrll static void
406 1.1 skrll mmix_set_geta_branch_offset (char *opcodep, offsetT value)
407 1.1 skrll {
408 1.1 skrll if (value < 0)
409 1.1 skrll {
410 1.1 skrll value += 65536 * 4;
411 1.1 skrll opcodep[0] |= 1;
412 1.1 skrll }
413 1.1 skrll
414 1.1 skrll value /= 4;
415 1.1 skrll md_number_to_chars (opcodep + 2, value, 2);
416 1.1 skrll }
417 1.1 skrll
418 1.1 skrll /* Fill in the offset-related part of JMP. */
419 1.1 skrll
420 1.1 skrll static void
421 1.1 skrll mmix_set_jmp_offset (char *opcodep, offsetT value)
422 1.1 skrll {
423 1.1 skrll if (value < 0)
424 1.1 skrll {
425 1.1 skrll value += 65536 * 256 * 4;
426 1.1 skrll opcodep[0] |= 1;
427 1.1 skrll }
428 1.1 skrll
429 1.1 skrll value /= 4;
430 1.1 skrll md_number_to_chars (opcodep + 1, value, 3);
431 1.1 skrll }
432 1.1 skrll
433 1.1 skrll /* Fill in NOP:s for the expanded part of GETA/JMP/Bcc/PUSHJ. */
434 1.1 skrll
435 1.1 skrll static void
436 1.1 skrll mmix_fill_nops (char *opcodep, int n)
437 1.1 skrll {
438 1.1 skrll int i;
439 1.1 skrll
440 1.1 skrll for (i = 0; i < n; i++)
441 1.1 skrll md_number_to_chars (opcodep + i * 4, SWYM_INSN_BYTE << 24, 4);
442 1.1 skrll }
443 1.1 skrll
444 1.1 skrll /* See macro md_parse_name in tc-mmix.h. */
445 1.1 skrll
446 1.1 skrll int
447 1.1 skrll mmix_current_location (void (*fn) (expressionS *), expressionS *exp)
448 1.1 skrll {
449 1.1 skrll (*fn) (exp);
450 1.1 skrll
451 1.1 skrll return 1;
452 1.1 skrll }
453 1.1 skrll
454 1.1 skrll /* Get up to three operands, filling them into the exp array.
455 1.1 skrll General idea and code stolen from the tic80 port. */
456 1.1 skrll
457 1.1 skrll static int
458 1.1 skrll get_operands (int max_operands, char *s, expressionS *exp)
459 1.1 skrll {
460 1.1 skrll char *p = s;
461 1.1 skrll int numexp = 0;
462 1.1 skrll int nextchar = ',';
463 1.1 skrll
464 1.1 skrll while (nextchar == ',')
465 1.1 skrll {
466 1.1 skrll /* Skip leading whitespace */
467 1.1 skrll while (*p == ' ' || *p == '\t')
468 1.1 skrll p++;
469 1.1 skrll
470 1.1 skrll /* Check to see if we have any operands left to parse */
471 1.1 skrll if (*p == 0 || *p == '\n' || *p == '\r')
472 1.1 skrll {
473 1.1 skrll break;
474 1.1 skrll }
475 1.1 skrll else if (numexp == max_operands)
476 1.1 skrll {
477 1.1 skrll /* This seems more sane than saying "too many operands". We'll
478 1.1 skrll get here only if the trailing trash starts with a comma. */
479 1.1 skrll as_bad (_("invalid operands"));
480 1.1 skrll mmix_discard_rest_of_line ();
481 1.1 skrll return 0;
482 1.1 skrll }
483 1.1 skrll
484 1.1 skrll /* Begin operand parsing at the current scan point. */
485 1.1 skrll
486 1.1 skrll input_line_pointer = p;
487 1.1 skrll expression (&exp[numexp]);
488 1.1 skrll
489 1.1 skrll if (exp[numexp].X_op == O_illegal)
490 1.1 skrll {
491 1.1 skrll as_bad (_("invalid operands"));
492 1.1 skrll }
493 1.1 skrll else if (exp[numexp].X_op == O_absent)
494 1.1 skrll {
495 1.1 skrll as_bad (_("missing operand"));
496 1.1 skrll }
497 1.1 skrll
498 1.1 skrll numexp++;
499 1.1 skrll p = input_line_pointer;
500 1.1 skrll
501 1.1 skrll /* Skip leading whitespace */
502 1.1 skrll while (*p == ' ' || *p == '\t')
503 1.1 skrll p++;
504 1.1 skrll nextchar = *p++;
505 1.1 skrll }
506 1.1 skrll
507 1.1 skrll /* If we allow "naked" comments, ignore the rest of the line. */
508 1.1 skrll if (nextchar != ',')
509 1.1 skrll {
510 1.1 skrll mmix_handle_rest_of_empty_line ();
511 1.1 skrll input_line_pointer--;
512 1.1 skrll }
513 1.1 skrll
514 1.1 skrll /* Mark the end of the valid operands with an illegal expression. */
515 1.1 skrll exp[numexp].X_op = O_illegal;
516 1.1 skrll
517 1.1 skrll return (numexp);
518 1.1 skrll }
519 1.1 skrll
520 1.1 skrll /* Get the value of a special register, or -1 if the name does not match
521 1.1 skrll one. NAME is a null-terminated string. */
522 1.1 skrll
523 1.1 skrll static int
524 1.1 skrll get_spec_regno (char *name)
525 1.1 skrll {
526 1.1 skrll int i;
527 1.1 skrll
528 1.1 skrll if (name == NULL)
529 1.1 skrll return -1;
530 1.1 skrll
531 1.1 skrll if (*name == ':')
532 1.1 skrll name++;
533 1.1 skrll
534 1.1 skrll /* Well, it's a short array and we'll most often just match the first
535 1.1 skrll entry, rJ. */
536 1.1 skrll for (i = 0; mmix_spec_regs[i].name != NULL; i++)
537 1.1 skrll if (strcmp (name, mmix_spec_regs[i].name) == 0)
538 1.1 skrll return mmix_spec_regs[i].number;
539 1.1 skrll
540 1.1 skrll return -1;
541 1.1 skrll }
542 1.1 skrll
543 1.1 skrll /* For GET and PUT, parse the register names "manually", so we don't use
544 1.1 skrll user labels. */
545 1.1 skrll static int
546 1.1 skrll get_putget_operands (struct mmix_opcode *insn, char *operands,
547 1.1 skrll expressionS *exp)
548 1.1 skrll {
549 1.1 skrll expressionS *expp_reg;
550 1.1 skrll expressionS *expp_sreg;
551 1.1 skrll char *sregp = NULL;
552 1.1 skrll char *sregend = operands;
553 1.1 skrll char *p = operands;
554 1.1 skrll char c = *sregend;
555 1.1 skrll int regno;
556 1.1 skrll
557 1.1 skrll /* Skip leading whitespace */
558 1.1 skrll while (*p == ' ' || *p == '\t')
559 1.1 skrll p++;
560 1.1 skrll
561 1.1 skrll input_line_pointer = p;
562 1.1 skrll
563 1.1 skrll /* Initialize both possible operands to error state, in case we never
564 1.1 skrll get further. */
565 1.1 skrll exp[0].X_op = O_illegal;
566 1.1 skrll exp[1].X_op = O_illegal;
567 1.1 skrll
568 1.1 skrll if (insn->operands == mmix_operands_get)
569 1.1 skrll {
570 1.1 skrll expp_reg = &exp[0];
571 1.1 skrll expp_sreg = &exp[1];
572 1.1 skrll
573 1.1 skrll expression (expp_reg);
574 1.1 skrll
575 1.1 skrll p = input_line_pointer;
576 1.1 skrll
577 1.1 skrll /* Skip whitespace */
578 1.1 skrll while (*p == ' ' || *p == '\t')
579 1.1 skrll p++;
580 1.1 skrll
581 1.1 skrll if (*p == ',')
582 1.1 skrll {
583 1.1 skrll p++;
584 1.1 skrll
585 1.1 skrll /* Skip whitespace */
586 1.1 skrll while (*p == ' ' || *p == '\t')
587 1.1 skrll p++;
588 1.1 skrll sregp = p;
589 1.1 skrll input_line_pointer = sregp;
590 1.1.1.4 christos c = get_symbol_name (&sregp);
591 1.1 skrll sregend = input_line_pointer;
592 1.1.1.4 christos if (c == '"')
593 1.1.1.4 christos ++ input_line_pointer;
594 1.1 skrll }
595 1.1 skrll }
596 1.1 skrll else
597 1.1 skrll {
598 1.1 skrll expp_sreg = &exp[0];
599 1.1 skrll expp_reg = &exp[1];
600 1.1 skrll
601 1.1.1.4 christos c = get_symbol_name (&sregp);
602 1.1.1.4 christos sregend = input_line_pointer;
603 1.1.1.4 christos restore_line_pointer (c);
604 1.1.1.4 christos p = input_line_pointer;
605 1.1 skrll
606 1.1 skrll /* Skip whitespace */
607 1.1 skrll while (*p == ' ' || *p == '\t')
608 1.1 skrll p++;
609 1.1 skrll
610 1.1 skrll if (*p == ',')
611 1.1 skrll {
612 1.1 skrll p++;
613 1.1 skrll
614 1.1 skrll /* Skip whitespace */
615 1.1 skrll while (*p == ' ' || *p == '\t')
616 1.1 skrll p++;
617 1.1 skrll
618 1.1 skrll input_line_pointer = p;
619 1.1 skrll expression (expp_reg);
620 1.1 skrll }
621 1.1 skrll *sregend = 0;
622 1.1 skrll }
623 1.1 skrll
624 1.1 skrll regno = get_spec_regno (sregp);
625 1.1 skrll *sregend = c;
626 1.1 skrll
627 1.1 skrll /* Let the caller issue errors; we've made sure the operands are
628 1.1 skrll invalid. */
629 1.1 skrll if (expp_reg->X_op != O_illegal
630 1.1 skrll && expp_reg->X_op != O_absent
631 1.1 skrll && regno != -1)
632 1.1 skrll {
633 1.1 skrll expp_sreg->X_op = O_register;
634 1.1 skrll expp_sreg->X_add_number = regno + 256;
635 1.1 skrll }
636 1.1 skrll
637 1.1 skrll return 2;
638 1.1 skrll }
639 1.1 skrll
640 1.1 skrll /* Handle MMIX-specific option. */
641 1.1 skrll
642 1.1 skrll int
643 1.1.1.5 christos md_parse_option (int c, const char *arg ATTRIBUTE_UNUSED)
644 1.1 skrll {
645 1.1 skrll switch (c)
646 1.1 skrll {
647 1.1 skrll case 'x':
648 1.1 skrll warn_on_expansion = 0;
649 1.1 skrll allocate_undefined_gregs_in_linker = 1;
650 1.1 skrll break;
651 1.1 skrll
652 1.1 skrll case OPTION_RELAX:
653 1.1 skrll linkrelax = 1;
654 1.1 skrll break;
655 1.1 skrll
656 1.1 skrll case OPTION_NOEXPAND:
657 1.1 skrll expand_op = 0;
658 1.1 skrll break;
659 1.1 skrll
660 1.1 skrll case OPTION_NOMERGEGREG:
661 1.1 skrll merge_gregs = 0;
662 1.1 skrll break;
663 1.1 skrll
664 1.1 skrll case OPTION_NOSYMS:
665 1.1 skrll predefined_syms = 0;
666 1.1 skrll equated_spec_regs = 0;
667 1.1 skrll break;
668 1.1 skrll
669 1.1 skrll case OPTION_GNU_SYNTAX:
670 1.1 skrll mmix_gnu_syntax = 1;
671 1.1 skrll label_without_colon_this_line = 0;
672 1.1 skrll break;
673 1.1 skrll
674 1.1 skrll case OPTION_GLOBALIZE_SYMBOLS:
675 1.1 skrll mmix_globalize_symbols = 1;
676 1.1 skrll break;
677 1.1 skrll
678 1.1 skrll case OPTION_FIXED_SPEC_REGS:
679 1.1 skrll equated_spec_regs = 0;
680 1.1 skrll break;
681 1.1 skrll
682 1.1 skrll case OPTION_LINKER_ALLOCATED_GREGS:
683 1.1 skrll allocate_undefined_gregs_in_linker = 1;
684 1.1 skrll break;
685 1.1 skrll
686 1.1 skrll case OPTION_NOPUSHJSTUBS:
687 1.1 skrll pushj_stubs = 0;
688 1.1 skrll break;
689 1.1 skrll
690 1.1 skrll default:
691 1.1 skrll return 0;
692 1.1 skrll }
693 1.1 skrll
694 1.1 skrll return 1;
695 1.1 skrll }
696 1.1 skrll
697 1.1 skrll /* Display MMIX-specific help text. */
698 1.1 skrll
699 1.1 skrll void
700 1.1 skrll md_show_usage (FILE * stream)
701 1.1 skrll {
702 1.1 skrll fprintf (stream, _(" MMIX-specific command line options:\n"));
703 1.1 skrll fprintf (stream, _("\
704 1.1 skrll -fixed-special-register-names\n\
705 1.1 skrll Allow only the original special register names.\n"));
706 1.1 skrll fprintf (stream, _("\
707 1.1 skrll -globalize-symbols Make all symbols global.\n"));
708 1.1 skrll fprintf (stream, _("\
709 1.1 skrll -gnu-syntax Turn off mmixal syntax compatibility.\n"));
710 1.1 skrll fprintf (stream, _("\
711 1.1 skrll -relax Create linker relaxable code.\n"));
712 1.1 skrll fprintf (stream, _("\
713 1.1 skrll -no-predefined-syms Do not provide mmixal built-in constants.\n\
714 1.1 skrll Implies -fixed-special-register-names.\n"));
715 1.1 skrll fprintf (stream, _("\
716 1.1 skrll -no-expand Do not expand GETA, branches, PUSHJ or JUMP\n\
717 1.1 skrll into multiple instructions.\n"));
718 1.1 skrll fprintf (stream, _("\
719 1.1 skrll -no-merge-gregs Do not merge GREG definitions with nearby values.\n"));
720 1.1 skrll fprintf (stream, _("\
721 1.1 skrll -linker-allocated-gregs If there's no suitable GREG definition for the\
722 1.1 skrll operands of an instruction, let the linker resolve.\n"));
723 1.1 skrll fprintf (stream, _("\
724 1.1 skrll -x Do not warn when an operand to GETA, a branch,\n\
725 1.1 skrll PUSHJ or JUMP is not known to be within range.\n\
726 1.1 skrll The linker will catch any errors. Implies\n\
727 1.1 skrll -linker-allocated-gregs."));
728 1.1 skrll }
729 1.1 skrll
730 1.1 skrll /* Step to end of line, but don't step over the end of the line. */
731 1.1 skrll
732 1.1 skrll static void
733 1.1 skrll mmix_discard_rest_of_line (void)
734 1.1 skrll {
735 1.1 skrll while (*input_line_pointer
736 1.1 skrll && (! is_end_of_line[(unsigned char) *input_line_pointer]
737 1.1 skrll || TC_EOL_IN_INSN (input_line_pointer)))
738 1.1 skrll input_line_pointer++;
739 1.1 skrll }
740 1.1 skrll
741 1.1 skrll /* Act as demand_empty_rest_of_line if we're in strict GNU syntax mode,
742 1.1 skrll otherwise just ignore the rest of the line (and skip the end-of-line
743 1.1 skrll delimiter). */
744 1.1 skrll
745 1.1 skrll static void
746 1.1 skrll mmix_handle_rest_of_empty_line (void)
747 1.1 skrll {
748 1.1 skrll if (mmix_gnu_syntax)
749 1.1 skrll demand_empty_rest_of_line ();
750 1.1 skrll else
751 1.1 skrll {
752 1.1 skrll mmix_discard_rest_of_line ();
753 1.1 skrll input_line_pointer++;
754 1.1 skrll }
755 1.1 skrll }
756 1.1 skrll
757 1.1 skrll /* Initialize GAS MMIX specifics. */
758 1.1 skrll
759 1.1 skrll void
760 1.1 skrll mmix_md_begin (void)
761 1.1 skrll {
762 1.1 skrll int i;
763 1.1 skrll const struct mmix_opcode *opcode;
764 1.1 skrll
765 1.1 skrll /* We assume nobody will use this, so don't allocate any room. */
766 1.1 skrll obstack_begin (&mmix_sym_obstack, 0);
767 1.1 skrll
768 1.1 skrll /* This will break the day the "lex" thingy changes. For now, it's the
769 1.1 skrll only way to make ':' part of a name, and a name beginner. */
770 1.1 skrll lex_type[':'] = (LEX_NAME | LEX_BEGIN_NAME);
771 1.1 skrll
772 1.1 skrll mmix_opcode_hash = hash_new ();
773 1.1 skrll
774 1.1 skrll real_reg_section
775 1.1 skrll = bfd_make_section_old_way (stdoutput, MMIX_REG_SECTION_NAME);
776 1.1 skrll
777 1.1 skrll for (opcode = mmix_opcodes; opcode->name; opcode++)
778 1.1 skrll hash_insert (mmix_opcode_hash, opcode->name, (char *) opcode);
779 1.1 skrll
780 1.1 skrll /* We always insert the ordinary registers 0..255 as registers. */
781 1.1 skrll for (i = 0; i < 256; i++)
782 1.1 skrll {
783 1.1 skrll char buf[5];
784 1.1 skrll
785 1.1 skrll /* Alternatively, we could diddle with '$' and the following number,
786 1.1 skrll but keeping the registers as symbols helps keep parsing simple. */
787 1.1 skrll sprintf (buf, "$%d", i);
788 1.1 skrll symbol_table_insert (symbol_new (buf, reg_section, i,
789 1.1 skrll &zero_address_frag));
790 1.1 skrll }
791 1.1 skrll
792 1.1 skrll /* Insert mmixal built-in names if allowed. */
793 1.1 skrll if (predefined_syms)
794 1.1 skrll {
795 1.1 skrll for (i = 0; mmix_spec_regs[i].name != NULL; i++)
796 1.1 skrll symbol_table_insert (symbol_new (mmix_spec_regs[i].name,
797 1.1 skrll reg_section,
798 1.1 skrll mmix_spec_regs[i].number + 256,
799 1.1 skrll &zero_address_frag));
800 1.1 skrll
801 1.1 skrll /* FIXME: Perhaps these should be recognized as specials; as field
802 1.1 skrll names for those instructions. */
803 1.1 skrll symbol_table_insert (symbol_new ("ROUND_CURRENT", reg_section, 512,
804 1.1 skrll &zero_address_frag));
805 1.1 skrll symbol_table_insert (symbol_new ("ROUND_OFF", reg_section, 512 + 1,
806 1.1 skrll &zero_address_frag));
807 1.1 skrll symbol_table_insert (symbol_new ("ROUND_UP", reg_section, 512 + 2,
808 1.1 skrll &zero_address_frag));
809 1.1 skrll symbol_table_insert (symbol_new ("ROUND_DOWN", reg_section, 512 + 3,
810 1.1 skrll &zero_address_frag));
811 1.1 skrll symbol_table_insert (symbol_new ("ROUND_NEAR", reg_section, 512 + 4,
812 1.1 skrll &zero_address_frag));
813 1.1 skrll }
814 1.1 skrll }
815 1.1 skrll
816 1.1 skrll /* Assemble one insn in STR. */
817 1.1 skrll
818 1.1 skrll void
819 1.1 skrll md_assemble (char *str)
820 1.1 skrll {
821 1.1 skrll char *operands = str;
822 1.1 skrll char modified_char = 0;
823 1.1 skrll struct mmix_opcode *instruction;
824 1.1 skrll fragS *opc_fragP = NULL;
825 1.1 skrll int max_operands = 3;
826 1.1 skrll
827 1.1 skrll /* Note that the struct frag member fr_literal in frags.h is char[], so
828 1.1 skrll I have to make this a plain char *. */
829 1.1 skrll /* unsigned */ char *opcodep = NULL;
830 1.1 skrll
831 1.1 skrll expressionS exp[4];
832 1.1 skrll int n_operands = 0;
833 1.1 skrll
834 1.1 skrll /* Move to end of opcode. */
835 1.1 skrll for (operands = str;
836 1.1 skrll is_part_of_name (*operands);
837 1.1 skrll ++operands)
838 1.1 skrll ;
839 1.1 skrll
840 1.1 skrll if (ISSPACE (*operands))
841 1.1 skrll {
842 1.1 skrll modified_char = *operands;
843 1.1 skrll *operands++ = '\0';
844 1.1 skrll }
845 1.1 skrll
846 1.1 skrll instruction = (struct mmix_opcode *) hash_find (mmix_opcode_hash, str);
847 1.1 skrll if (instruction == NULL)
848 1.1 skrll {
849 1.1 skrll as_bad (_("unknown opcode: `%s'"), str);
850 1.1 skrll
851 1.1 skrll /* Avoid "unhandled label" errors. */
852 1.1 skrll pending_label = NULL;
853 1.1 skrll return;
854 1.1 skrll }
855 1.1 skrll
856 1.1 skrll /* Put back the character after the opcode. */
857 1.1 skrll if (modified_char != 0)
858 1.1 skrll operands[-1] = modified_char;
859 1.1 skrll
860 1.1 skrll input_line_pointer = operands;
861 1.1 skrll
862 1.1 skrll /* Is this a mmixal pseudodirective? */
863 1.1 skrll if (instruction->type == mmix_type_pseudo)
864 1.1 skrll {
865 1.1 skrll /* For mmixal compatibility, a label for an instruction (and
866 1.1 skrll emitting pseudo) refers to the _aligned_ address. We emit the
867 1.1 skrll label here for the pseudos that don't handle it themselves. When
868 1.1 skrll having an fb-label, emit it here, and increment the counter after
869 1.1 skrll the pseudo. */
870 1.1 skrll switch (instruction->operands)
871 1.1 skrll {
872 1.1 skrll case mmix_operands_loc:
873 1.1 skrll case mmix_operands_byte:
874 1.1 skrll case mmix_operands_prefix:
875 1.1 skrll case mmix_operands_local:
876 1.1 skrll case mmix_operands_bspec:
877 1.1 skrll case mmix_operands_espec:
878 1.1 skrll if (current_fb_label >= 0)
879 1.1 skrll colon (fb_label_name (current_fb_label, 1));
880 1.1 skrll else if (pending_label != NULL)
881 1.1 skrll {
882 1.1 skrll colon (pending_label);
883 1.1 skrll pending_label = NULL;
884 1.1 skrll }
885 1.1 skrll break;
886 1.1 skrll
887 1.1 skrll default:
888 1.1 skrll break;
889 1.1 skrll }
890 1.1 skrll
891 1.1 skrll /* Some of the pseudos emit contents, others don't. Set a
892 1.1 skrll contents-emitted flag when we emit something into .text */
893 1.1 skrll switch (instruction->operands)
894 1.1 skrll {
895 1.1 skrll case mmix_operands_loc:
896 1.1 skrll /* LOC */
897 1.1 skrll s_loc (0);
898 1.1 skrll break;
899 1.1 skrll
900 1.1 skrll case mmix_operands_byte:
901 1.1 skrll /* BYTE */
902 1.1 skrll mmix_byte ();
903 1.1 skrll break;
904 1.1 skrll
905 1.1 skrll case mmix_operands_wyde:
906 1.1 skrll /* WYDE */
907 1.1 skrll mmix_cons (2);
908 1.1 skrll break;
909 1.1 skrll
910 1.1 skrll case mmix_operands_tetra:
911 1.1 skrll /* TETRA */
912 1.1 skrll mmix_cons (4);
913 1.1 skrll break;
914 1.1 skrll
915 1.1 skrll case mmix_operands_octa:
916 1.1 skrll /* OCTA */
917 1.1 skrll mmix_cons (8);
918 1.1 skrll break;
919 1.1 skrll
920 1.1 skrll case mmix_operands_prefix:
921 1.1 skrll /* PREFIX */
922 1.1 skrll s_prefix (0);
923 1.1 skrll break;
924 1.1 skrll
925 1.1 skrll case mmix_operands_local:
926 1.1 skrll /* LOCAL */
927 1.1 skrll mmix_s_local (0);
928 1.1 skrll break;
929 1.1 skrll
930 1.1 skrll case mmix_operands_bspec:
931 1.1 skrll /* BSPEC */
932 1.1 skrll s_bspec (0);
933 1.1 skrll break;
934 1.1 skrll
935 1.1 skrll case mmix_operands_espec:
936 1.1 skrll /* ESPEC */
937 1.1 skrll s_espec (0);
938 1.1 skrll break;
939 1.1 skrll
940 1.1 skrll default:
941 1.1 skrll BAD_CASE (instruction->operands);
942 1.1 skrll }
943 1.1 skrll
944 1.1 skrll /* These are all working like the pseudo functions in read.c:s_...,
945 1.1 skrll in that they step over the end-of-line marker at the end of the
946 1.1 skrll line. We don't want that here. */
947 1.1 skrll input_line_pointer--;
948 1.1 skrll
949 1.1 skrll /* Step up the fb-label counter if there was a definition on this
950 1.1 skrll line. */
951 1.1 skrll if (current_fb_label >= 0)
952 1.1 skrll {
953 1.1 skrll fb_label_instance_inc (current_fb_label);
954 1.1 skrll current_fb_label = -1;
955 1.1 skrll }
956 1.1 skrll
957 1.1 skrll /* Reset any don't-align-next-datum request, unless this was a LOC
958 1.1 skrll directive. */
959 1.1 skrll if (instruction->operands != mmix_operands_loc)
960 1.1 skrll want_unaligned = 0;
961 1.1 skrll
962 1.1 skrll return;
963 1.1 skrll }
964 1.1 skrll
965 1.1 skrll /* Not a pseudo; we *will* emit contents. */
966 1.1 skrll if (now_seg == data_section)
967 1.1 skrll {
968 1.1 skrll if (lowest_data_loc != (bfd_vma) -1 && (lowest_data_loc & 3) != 0)
969 1.1 skrll {
970 1.1 skrll if (data_has_contents)
971 1.1 skrll as_bad (_("specified location wasn't TETRA-aligned"));
972 1.1 skrll else if (want_unaligned)
973 1.1 skrll as_bad (_("unaligned data at an absolute location is not supported"));
974 1.1 skrll
975 1.1 skrll lowest_data_loc &= ~(bfd_vma) 3;
976 1.1 skrll lowest_data_loc += 4;
977 1.1 skrll }
978 1.1 skrll
979 1.1 skrll data_has_contents = 1;
980 1.1 skrll }
981 1.1 skrll else if (now_seg == text_section)
982 1.1 skrll {
983 1.1 skrll if (lowest_text_loc != (bfd_vma) -1 && (lowest_text_loc & 3) != 0)
984 1.1 skrll {
985 1.1 skrll if (text_has_contents)
986 1.1 skrll as_bad (_("specified location wasn't TETRA-aligned"));
987 1.1 skrll else if (want_unaligned)
988 1.1 skrll as_bad (_("unaligned data at an absolute location is not supported"));
989 1.1 skrll
990 1.1 skrll lowest_text_loc &= ~(bfd_vma) 3;
991 1.1 skrll lowest_text_loc += 4;
992 1.1 skrll }
993 1.1 skrll
994 1.1 skrll text_has_contents = 1;
995 1.1 skrll }
996 1.1 skrll
997 1.1 skrll /* After a sequence of BYTEs or WYDEs, we need to get to instruction
998 1.1 skrll alignment. For other pseudos, a ".p2align 2" is supposed to be
999 1.1 skrll inserted by the user. */
1000 1.1 skrll if (last_alignment < 2 && ! want_unaligned)
1001 1.1 skrll {
1002 1.1 skrll frag_align (2, 0, 0);
1003 1.1 skrll record_alignment (now_seg, 2);
1004 1.1 skrll last_alignment = 2;
1005 1.1 skrll }
1006 1.1 skrll else
1007 1.1 skrll /* Reset any don't-align-next-datum request. */
1008 1.1 skrll want_unaligned = 0;
1009 1.1 skrll
1010 1.1 skrll /* For mmixal compatibility, a label for an instruction (and emitting
1011 1.1 skrll pseudo) refers to the _aligned_ address. So we have to emit the
1012 1.1 skrll label here. */
1013 1.1 skrll if (pending_label != NULL)
1014 1.1 skrll {
1015 1.1 skrll colon (pending_label);
1016 1.1 skrll pending_label = NULL;
1017 1.1 skrll }
1018 1.1 skrll
1019 1.1 skrll /* We assume that mmix_opcodes keeps having unique mnemonics for each
1020 1.1 skrll opcode, so we don't have to iterate over more than one opcode; if the
1021 1.1 skrll syntax does not match, then there's a syntax error. */
1022 1.1 skrll
1023 1.1 skrll /* Operands have little or no context and are all comma-separated; it is
1024 1.1 skrll easier to parse each expression first. */
1025 1.1 skrll switch (instruction->operands)
1026 1.1 skrll {
1027 1.1 skrll case mmix_operands_reg_yz:
1028 1.1 skrll case mmix_operands_pop:
1029 1.1 skrll case mmix_operands_regaddr:
1030 1.1 skrll case mmix_operands_pushj:
1031 1.1 skrll case mmix_operands_get:
1032 1.1 skrll case mmix_operands_put:
1033 1.1 skrll case mmix_operands_set:
1034 1.1 skrll case mmix_operands_save:
1035 1.1 skrll case mmix_operands_unsave:
1036 1.1 skrll max_operands = 2;
1037 1.1 skrll break;
1038 1.1 skrll
1039 1.1 skrll case mmix_operands_sync:
1040 1.1 skrll case mmix_operands_jmp:
1041 1.1 skrll case mmix_operands_resume:
1042 1.1 skrll max_operands = 1;
1043 1.1 skrll break;
1044 1.1 skrll
1045 1.1 skrll /* The original 3 is fine for the rest. */
1046 1.1 skrll default:
1047 1.1 skrll break;
1048 1.1 skrll }
1049 1.1 skrll
1050 1.1 skrll /* If this is GET or PUT, and we don't do allow those names to be
1051 1.1 skrll equated, we need to parse the names ourselves, so we don't pick up a
1052 1.1 skrll user label instead of the special register. */
1053 1.1 skrll if (! equated_spec_regs
1054 1.1 skrll && (instruction->operands == mmix_operands_get
1055 1.1 skrll || instruction->operands == mmix_operands_put))
1056 1.1 skrll n_operands = get_putget_operands (instruction, operands, exp);
1057 1.1 skrll else
1058 1.1 skrll n_operands = get_operands (max_operands, operands, exp);
1059 1.1 skrll
1060 1.1 skrll /* If there's a fb-label on the current line, set that label. This must
1061 1.1 skrll be done *after* evaluating expressions of operands, since neither a
1062 1.1 skrll "1B" nor a "1F" refers to "1H" on the same line. */
1063 1.1 skrll if (current_fb_label >= 0)
1064 1.1 skrll {
1065 1.1 skrll fb_label_instance_inc (current_fb_label);
1066 1.1 skrll colon (fb_label_name (current_fb_label, 0));
1067 1.1 skrll current_fb_label = -1;
1068 1.1 skrll }
1069 1.1 skrll
1070 1.1 skrll /* We also assume that the length of the instruction is at least 4, the
1071 1.1 skrll size of an unexpanded instruction. We need a self-contained frag
1072 1.1 skrll since we want the relocation to point to the instruction, not the
1073 1.1 skrll variant part. */
1074 1.1 skrll
1075 1.1 skrll opcodep = frag_more (4);
1076 1.1 skrll mmix_opcode_frag = opc_fragP = frag_now;
1077 1.1 skrll frag_now->fr_opcode = opcodep;
1078 1.1 skrll
1079 1.1 skrll /* Mark start of insn for DWARF2 debug features. */
1080 1.1 skrll if (OUTPUT_FLAVOR == bfd_target_elf_flavour)
1081 1.1 skrll dwarf2_emit_insn (4);
1082 1.1 skrll
1083 1.1 skrll md_number_to_chars (opcodep, instruction->match, 4);
1084 1.1 skrll
1085 1.1 skrll switch (instruction->operands)
1086 1.1 skrll {
1087 1.1 skrll case mmix_operands_jmp:
1088 1.1 skrll if (n_operands == 0 && ! mmix_gnu_syntax)
1089 1.1 skrll /* Zeros are in place - nothing needs to be done when we have no
1090 1.1 skrll operands. */
1091 1.1 skrll break;
1092 1.1 skrll
1093 1.1 skrll /* Add a frag for a JMP relaxation; we need room for max four
1094 1.1 skrll extra instructions. We don't do any work around here to check if
1095 1.1 skrll we can determine the offset right away. */
1096 1.1 skrll if (n_operands != 1 || exp[0].X_op == O_register)
1097 1.1 skrll {
1098 1.1 skrll as_bad (_("invalid operand to opcode %s: `%s'"),
1099 1.1 skrll instruction->name, operands);
1100 1.1 skrll return;
1101 1.1 skrll }
1102 1.1 skrll
1103 1.1 skrll if (expand_op)
1104 1.1 skrll frag_var (rs_machine_dependent, 4 * 4, 0,
1105 1.1 skrll ENCODE_RELAX (STATE_JMP, STATE_UNDF),
1106 1.1 skrll exp[0].X_add_symbol,
1107 1.1 skrll exp[0].X_add_number,
1108 1.1 skrll opcodep);
1109 1.1 skrll else
1110 1.1 skrll fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal, 4,
1111 1.1 skrll exp + 0, 1, BFD_RELOC_MMIX_ADDR27);
1112 1.1 skrll break;
1113 1.1 skrll
1114 1.1 skrll case mmix_operands_pushj:
1115 1.1 skrll /* We take care of PUSHJ in full here. */
1116 1.1 skrll if (n_operands != 2
1117 1.1 skrll || ((exp[0].X_op == O_constant || exp[0].X_op == O_register)
1118 1.1 skrll && (exp[0].X_add_number > 255 || exp[0].X_add_number < 0)))
1119 1.1 skrll {
1120 1.1 skrll as_bad (_("invalid operands to opcode %s: `%s'"),
1121 1.1 skrll instruction->name, operands);
1122 1.1 skrll return;
1123 1.1 skrll }
1124 1.1 skrll
1125 1.1 skrll if (exp[0].X_op == O_register || exp[0].X_op == O_constant)
1126 1.1 skrll opcodep[1] = exp[0].X_add_number;
1127 1.1 skrll else
1128 1.1 skrll fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 1,
1129 1.1 skrll 1, exp + 0, 0, BFD_RELOC_MMIX_REG_OR_BYTE);
1130 1.1 skrll
1131 1.1 skrll if (expand_op)
1132 1.1 skrll frag_var (rs_machine_dependent, PUSHJ_MAX_LEN - 4, 0,
1133 1.1 skrll ENCODE_RELAX (STATE_PUSHJ, STATE_UNDF),
1134 1.1 skrll exp[1].X_add_symbol,
1135 1.1 skrll exp[1].X_add_number,
1136 1.1 skrll opcodep);
1137 1.1 skrll else
1138 1.1 skrll fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal, 4,
1139 1.1 skrll exp + 1, 1, BFD_RELOC_MMIX_ADDR19);
1140 1.1 skrll break;
1141 1.1 skrll
1142 1.1 skrll case mmix_operands_regaddr:
1143 1.1 skrll /* GETA/branch: Add a frag for relaxation. We don't do any work
1144 1.1 skrll around here to check if we can determine the offset right away. */
1145 1.1 skrll if (n_operands != 2 || exp[1].X_op == O_register)
1146 1.1 skrll {
1147 1.1 skrll as_bad (_("invalid operands to opcode %s: `%s'"),
1148 1.1 skrll instruction->name, operands);
1149 1.1 skrll return;
1150 1.1 skrll }
1151 1.1 skrll
1152 1.1 skrll if (! expand_op)
1153 1.1 skrll fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal, 4,
1154 1.1 skrll exp + 1, 1, BFD_RELOC_MMIX_ADDR19);
1155 1.1 skrll else if (instruction->type == mmix_type_condbranch)
1156 1.1 skrll frag_var (rs_machine_dependent, BCC_MAX_LEN - 4, 0,
1157 1.1 skrll ENCODE_RELAX (STATE_BCC, STATE_UNDF),
1158 1.1 skrll exp[1].X_add_symbol,
1159 1.1 skrll exp[1].X_add_number,
1160 1.1 skrll opcodep);
1161 1.1 skrll else
1162 1.1 skrll frag_var (rs_machine_dependent, GETA_MAX_LEN - 4, 0,
1163 1.1 skrll ENCODE_RELAX (STATE_GETA, STATE_UNDF),
1164 1.1 skrll exp[1].X_add_symbol,
1165 1.1 skrll exp[1].X_add_number,
1166 1.1 skrll opcodep);
1167 1.1 skrll break;
1168 1.1 skrll
1169 1.1 skrll default:
1170 1.1 skrll break;
1171 1.1 skrll }
1172 1.1 skrll
1173 1.1 skrll switch (instruction->operands)
1174 1.1 skrll {
1175 1.1 skrll case mmix_operands_regs:
1176 1.1 skrll /* We check the number of operands here, since we're in a
1177 1.1 skrll FALLTHROUGH sequence in the next switch. */
1178 1.1 skrll if (n_operands != 3 || exp[2].X_op == O_constant)
1179 1.1 skrll {
1180 1.1 skrll as_bad (_("invalid operands to opcode %s: `%s'"),
1181 1.1 skrll instruction->name, operands);
1182 1.1 skrll return;
1183 1.1 skrll }
1184 1.1 skrll /* FALLTHROUGH. */
1185 1.1 skrll case mmix_operands_regs_z:
1186 1.1 skrll if (n_operands != 3)
1187 1.1 skrll {
1188 1.1 skrll as_bad (_("invalid operands to opcode %s: `%s'"),
1189 1.1 skrll instruction->name, operands);
1190 1.1 skrll return;
1191 1.1 skrll }
1192 1.1 skrll /* FALLTHROUGH. */
1193 1.1 skrll case mmix_operands_reg_yz:
1194 1.1 skrll case mmix_operands_roundregs_z:
1195 1.1 skrll case mmix_operands_roundregs:
1196 1.1 skrll case mmix_operands_regs_z_opt:
1197 1.1 skrll case mmix_operands_neg:
1198 1.1 skrll case mmix_operands_regaddr:
1199 1.1 skrll case mmix_operands_get:
1200 1.1 skrll case mmix_operands_set:
1201 1.1 skrll case mmix_operands_save:
1202 1.1 skrll if (n_operands < 1
1203 1.1 skrll || (exp[0].X_op == O_register && exp[0].X_add_number > 255))
1204 1.1 skrll {
1205 1.1 skrll as_bad (_("invalid operands to opcode %s: `%s'"),
1206 1.1 skrll instruction->name, operands);
1207 1.1 skrll return;
1208 1.1 skrll }
1209 1.1 skrll
1210 1.1 skrll if (exp[0].X_op == O_register)
1211 1.1 skrll opcodep[1] = exp[0].X_add_number;
1212 1.1 skrll else
1213 1.1 skrll fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 1,
1214 1.1 skrll 1, exp + 0, 0, BFD_RELOC_MMIX_REG);
1215 1.1 skrll break;
1216 1.1 skrll
1217 1.1 skrll default:
1218 1.1 skrll ;
1219 1.1 skrll }
1220 1.1 skrll
1221 1.1 skrll /* A corresponding once-over for those who take an 8-bit constant as
1222 1.1 skrll their first operand. */
1223 1.1 skrll switch (instruction->operands)
1224 1.1 skrll {
1225 1.1 skrll case mmix_operands_pushgo:
1226 1.1 skrll /* PUSHGO: X is a constant, but can be expressed as a register.
1227 1.1 skrll We handle X here and use the common machinery of T,X,3,$ for
1228 1.1 skrll the rest of the operands. */
1229 1.1 skrll if (n_operands < 2
1230 1.1 skrll || ((exp[0].X_op == O_constant || exp[0].X_op == O_register)
1231 1.1 skrll && (exp[0].X_add_number > 255 || exp[0].X_add_number < 0)))
1232 1.1 skrll {
1233 1.1 skrll as_bad (_("invalid operands to opcode %s: `%s'"),
1234 1.1 skrll instruction->name, operands);
1235 1.1 skrll return;
1236 1.1 skrll }
1237 1.1 skrll else if (exp[0].X_op == O_constant || exp[0].X_op == O_register)
1238 1.1 skrll opcodep[1] = exp[0].X_add_number;
1239 1.1 skrll else
1240 1.1 skrll fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 1,
1241 1.1 skrll 1, exp + 0, 0, BFD_RELOC_MMIX_REG_OR_BYTE);
1242 1.1 skrll break;
1243 1.1 skrll
1244 1.1 skrll case mmix_operands_pop:
1245 1.1 skrll if ((n_operands == 0 || n_operands == 1) && ! mmix_gnu_syntax)
1246 1.1 skrll break;
1247 1.1 skrll /* FALLTHROUGH. */
1248 1.1 skrll case mmix_operands_x_regs_z:
1249 1.1 skrll if (n_operands < 1
1250 1.1 skrll || (exp[0].X_op == O_constant
1251 1.1 skrll && (exp[0].X_add_number > 255
1252 1.1 skrll || exp[0].X_add_number < 0)))
1253 1.1 skrll {
1254 1.1 skrll as_bad (_("invalid operands to opcode %s: `%s'"),
1255 1.1 skrll instruction->name, operands);
1256 1.1 skrll return;
1257 1.1 skrll }
1258 1.1 skrll
1259 1.1 skrll if (exp[0].X_op == O_constant)
1260 1.1 skrll opcodep[1] = exp[0].X_add_number;
1261 1.1 skrll else
1262 1.1 skrll /* FIXME: This doesn't bring us unsignedness checking. */
1263 1.1 skrll fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 1,
1264 1.1 skrll 1, exp + 0, 0, BFD_RELOC_8);
1265 1.1 skrll default:
1266 1.1 skrll ;
1267 1.1 skrll }
1268 1.1 skrll
1269 1.1 skrll /* Handle the rest. */
1270 1.1 skrll switch (instruction->operands)
1271 1.1 skrll {
1272 1.1 skrll case mmix_operands_set:
1273 1.1 skrll /* SET: Either two registers, "$X,$Y", with Z field as zero, or
1274 1.1 skrll "$X,YZ", meaning change the opcode to SETL. */
1275 1.1 skrll if (n_operands != 2
1276 1.1 skrll || (exp[1].X_op == O_constant
1277 1.1 skrll && (exp[1].X_add_number > 0xffff || exp[1].X_add_number < 0)))
1278 1.1 skrll {
1279 1.1 skrll as_bad (_("invalid operands to opcode %s: `%s'"),
1280 1.1 skrll instruction->name, operands);
1281 1.1 skrll return;
1282 1.1 skrll }
1283 1.1 skrll
1284 1.1 skrll if (exp[1].X_op == O_constant)
1285 1.1 skrll {
1286 1.1 skrll /* There's an ambiguity with "SET $0,Y" when Y isn't defined
1287 1.1 skrll yet. To keep things simple, we assume that Y is then a
1288 1.1 skrll register, and only change the opcode if Y is defined at this
1289 1.1 skrll point.
1290 1.1 skrll
1291 1.1 skrll There's no compatibility problem with mmixal, since it emits
1292 1.1 skrll errors if the field is not defined at this point. */
1293 1.1 skrll md_number_to_chars (opcodep, SETL_INSN_BYTE, 1);
1294 1.1 skrll
1295 1.1 skrll opcodep[2] = (exp[1].X_add_number >> 8) & 255;
1296 1.1 skrll opcodep[3] = exp[1].X_add_number & 255;
1297 1.1 skrll break;
1298 1.1 skrll }
1299 1.1 skrll /* FALLTHROUGH. */
1300 1.1 skrll case mmix_operands_x_regs_z:
1301 1.1 skrll /* SYNCD: "X,$Y,$Z|Z". */
1302 1.1 skrll /* FALLTHROUGH. */
1303 1.1 skrll case mmix_operands_regs:
1304 1.1 skrll /* Three registers, $X,$Y,$Z. */
1305 1.1 skrll /* FALLTHROUGH. */
1306 1.1 skrll case mmix_operands_regs_z:
1307 1.1 skrll /* Operands "$X,$Y,$Z|Z", number of arguments checked above. */
1308 1.1 skrll /* FALLTHROUGH. */
1309 1.1 skrll case mmix_operands_pushgo:
1310 1.1 skrll /* Operands "$X|X,$Y,$Z|Z", optional Z. */
1311 1.1 skrll /* FALLTHROUGH. */
1312 1.1 skrll case mmix_operands_regs_z_opt:
1313 1.1 skrll /* Operands "$X,$Y,$Z|Z", with $Z|Z being optional, default 0. Any
1314 1.1 skrll operands not completely decided yet are postponed to later in
1315 1.1 skrll assembly (but not until link-time yet). */
1316 1.1 skrll
1317 1.1 skrll if ((n_operands != 2 && n_operands != 3)
1318 1.1 skrll || (exp[1].X_op == O_register && exp[1].X_add_number > 255)
1319 1.1 skrll || (n_operands == 3
1320 1.1 skrll && ((exp[2].X_op == O_register
1321 1.1 skrll && exp[2].X_add_number > 255
1322 1.1 skrll && mmix_gnu_syntax)
1323 1.1 skrll || (exp[2].X_op == O_constant
1324 1.1 skrll && (exp[2].X_add_number > 255
1325 1.1 skrll || exp[2].X_add_number < 0)))))
1326 1.1 skrll {
1327 1.1 skrll as_bad (_("invalid operands to opcode %s: `%s'"),
1328 1.1 skrll instruction->name, operands);
1329 1.1 skrll return;
1330 1.1 skrll }
1331 1.1 skrll
1332 1.1 skrll if (n_operands == 2)
1333 1.1 skrll {
1334 1.1 skrll symbolS *sym;
1335 1.1 skrll
1336 1.1 skrll /* The last operand is immediate whenever we see just two
1337 1.1 skrll operands. */
1338 1.1 skrll opcodep[0] |= IMM_OFFSET_BIT;
1339 1.1 skrll
1340 1.1 skrll /* Now, we could either have an implied "0" as the Z operand, or
1341 1.1 skrll it could be the constant of a "base address plus offset". It
1342 1.1 skrll depends on whether it is allowed; only memory operations, as
1343 1.1 skrll signified by instruction->type and "T" and "X" operand types,
1344 1.1 skrll and it depends on whether we find a register in the second
1345 1.1 skrll operand, exp[1]. */
1346 1.1 skrll if (exp[1].X_op == O_register && exp[1].X_add_number <= 255)
1347 1.1 skrll {
1348 1.1 skrll /* A zero then; all done. */
1349 1.1 skrll opcodep[2] = exp[1].X_add_number;
1350 1.1 skrll break;
1351 1.1 skrll }
1352 1.1 skrll
1353 1.1 skrll /* Not known as a register. Is base address plus offset
1354 1.1 skrll allowed, or can we assume that it is a register anyway? */
1355 1.1 skrll if ((instruction->operands != mmix_operands_regs_z_opt
1356 1.1 skrll && instruction->operands != mmix_operands_x_regs_z
1357 1.1 skrll && instruction->operands != mmix_operands_pushgo)
1358 1.1 skrll || (instruction->type != mmix_type_memaccess_octa
1359 1.1 skrll && instruction->type != mmix_type_memaccess_tetra
1360 1.1 skrll && instruction->type != mmix_type_memaccess_wyde
1361 1.1 skrll && instruction->type != mmix_type_memaccess_byte
1362 1.1 skrll && instruction->type != mmix_type_memaccess_block
1363 1.1 skrll && instruction->type != mmix_type_jsr
1364 1.1 skrll && instruction->type != mmix_type_branch))
1365 1.1 skrll {
1366 1.1 skrll fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 2,
1367 1.1 skrll 1, exp + 1, 0, BFD_RELOC_MMIX_REG);
1368 1.1 skrll break;
1369 1.1 skrll }
1370 1.1 skrll
1371 1.1 skrll /* To avoid getting a NULL add_symbol for constants and then
1372 1.1 skrll catching a SEGV in write_relocs since it doesn't handle
1373 1.1 skrll constants well for relocs other than PC-relative, we need to
1374 1.1 skrll pass expressions as symbols and use fix_new, not fix_new_exp. */
1375 1.1 skrll sym = make_expr_symbol (exp + 1);
1376 1.1 skrll
1377 1.1 skrll /* Mark the symbol as being OK for a reloc. */
1378 1.1 skrll symbol_get_bfdsym (sym)->flags |= BSF_KEEP;
1379 1.1 skrll
1380 1.1 skrll /* Now we know it can be a "base address plus offset". Add
1381 1.1 skrll proper fixup types so we can handle this later, when we've
1382 1.1 skrll parsed everything. */
1383 1.1 skrll fix_new (opc_fragP, opcodep - opc_fragP->fr_literal + 2,
1384 1.1 skrll 8, sym, 0, 0, BFD_RELOC_MMIX_BASE_PLUS_OFFSET);
1385 1.1 skrll break;
1386 1.1 skrll }
1387 1.1 skrll
1388 1.1 skrll if (exp[1].X_op == O_register)
1389 1.1 skrll opcodep[2] = exp[1].X_add_number;
1390 1.1 skrll else
1391 1.1 skrll fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 2,
1392 1.1 skrll 1, exp + 1, 0, BFD_RELOC_MMIX_REG);
1393 1.1 skrll
1394 1.1 skrll /* In mmixal compatibility mode, we allow special registers as
1395 1.1 skrll constants for the Z operand. They have 256 added to their
1396 1.1 skrll register numbers, so the right thing will happen if we just treat
1397 1.1 skrll those as constants. */
1398 1.1 skrll if (exp[2].X_op == O_register && exp[2].X_add_number <= 255)
1399 1.1 skrll opcodep[3] = exp[2].X_add_number;
1400 1.1 skrll else if (exp[2].X_op == O_constant
1401 1.1 skrll || (exp[2].X_op == O_register && exp[2].X_add_number > 255))
1402 1.1 skrll {
1403 1.1 skrll opcodep[3] = exp[2].X_add_number;
1404 1.1 skrll opcodep[0] |= IMM_OFFSET_BIT;
1405 1.1 skrll }
1406 1.1 skrll else
1407 1.1 skrll fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 3,
1408 1.1 skrll 1, exp + 2, 0,
1409 1.1 skrll (instruction->operands == mmix_operands_set
1410 1.1 skrll || instruction->operands == mmix_operands_regs)
1411 1.1 skrll ? BFD_RELOC_MMIX_REG : BFD_RELOC_MMIX_REG_OR_BYTE);
1412 1.1 skrll break;
1413 1.1 skrll
1414 1.1 skrll case mmix_operands_pop:
1415 1.1 skrll /* POP, one eight and one 16-bit operand. */
1416 1.1 skrll if (n_operands == 0 && ! mmix_gnu_syntax)
1417 1.1 skrll break;
1418 1.1 skrll if (n_operands == 1 && ! mmix_gnu_syntax)
1419 1.1 skrll goto a_single_24_bit_number_operand;
1420 1.1 skrll /* FALLTHROUGH. */
1421 1.1 skrll case mmix_operands_reg_yz:
1422 1.1 skrll /* A register and a 16-bit unsigned number. */
1423 1.1 skrll if (n_operands != 2
1424 1.1 skrll || exp[1].X_op == O_register
1425 1.1 skrll || (exp[1].X_op == O_constant
1426 1.1 skrll && (exp[1].X_add_number > 0xffff || exp[1].X_add_number < 0)))
1427 1.1 skrll {
1428 1.1 skrll as_bad (_("invalid operands to opcode %s: `%s'"),
1429 1.1 skrll instruction->name, operands);
1430 1.1 skrll return;
1431 1.1 skrll }
1432 1.1 skrll
1433 1.1 skrll if (exp[1].X_op == O_constant)
1434 1.1 skrll {
1435 1.1 skrll opcodep[2] = (exp[1].X_add_number >> 8) & 255;
1436 1.1 skrll opcodep[3] = exp[1].X_add_number & 255;
1437 1.1 skrll }
1438 1.1 skrll else
1439 1.1 skrll /* FIXME: This doesn't bring us unsignedness checking. */
1440 1.1 skrll fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 2,
1441 1.1 skrll 2, exp + 1, 0, BFD_RELOC_16);
1442 1.1 skrll break;
1443 1.1 skrll
1444 1.1 skrll case mmix_operands_jmp:
1445 1.1 skrll /* A JMP. Everything is already done. */
1446 1.1 skrll break;
1447 1.1 skrll
1448 1.1 skrll case mmix_operands_roundregs:
1449 1.1 skrll /* Two registers with optional rounding mode or constant in between. */
1450 1.1 skrll if ((n_operands == 3 && exp[2].X_op == O_constant)
1451 1.1 skrll || (n_operands == 2 && exp[1].X_op == O_constant))
1452 1.1 skrll {
1453 1.1 skrll as_bad (_("invalid operands to opcode %s: `%s'"),
1454 1.1 skrll instruction->name, operands);
1455 1.1 skrll return;
1456 1.1 skrll }
1457 1.1 skrll /* FALLTHROUGH. */
1458 1.1 skrll case mmix_operands_roundregs_z:
1459 1.1 skrll /* Like FLOT, "$X,ROUND_MODE,$Z|Z", but the rounding mode is
1460 1.1 skrll optional and can be the corresponding constant. */
1461 1.1 skrll {
1462 1.1 skrll /* Which exp index holds the second operand (not the rounding
1463 1.1 skrll mode). */
1464 1.1 skrll int op2no = n_operands - 1;
1465 1.1 skrll
1466 1.1 skrll if ((n_operands != 2 && n_operands != 3)
1467 1.1 skrll || ((exp[op2no].X_op == O_register
1468 1.1 skrll && exp[op2no].X_add_number > 255)
1469 1.1 skrll || (exp[op2no].X_op == O_constant
1470 1.1 skrll && (exp[op2no].X_add_number > 255
1471 1.1 skrll || exp[op2no].X_add_number < 0)))
1472 1.1 skrll || (n_operands == 3
1473 1.1 skrll /* We don't allow for the rounding mode to be deferred; it
1474 1.1 skrll must be determined in the "first pass". It cannot be a
1475 1.1 skrll symbol equated to a rounding mode, but defined after
1476 1.1 skrll the first use. */
1477 1.1 skrll && ((exp[1].X_op == O_register
1478 1.1 skrll && exp[1].X_add_number < 512)
1479 1.1 skrll || (exp[1].X_op == O_constant
1480 1.1.1.4 christos && (exp[1].X_add_number < 0
1481 1.1.1.4 christos || exp[1].X_add_number > 4))
1482 1.1 skrll || (exp[1].X_op != O_register
1483 1.1 skrll && exp[1].X_op != O_constant))))
1484 1.1 skrll {
1485 1.1 skrll as_bad (_("invalid operands to opcode %s: `%s'"),
1486 1.1 skrll instruction->name, operands);
1487 1.1 skrll return;
1488 1.1 skrll }
1489 1.1 skrll
1490 1.1 skrll /* Add rounding mode if present. */
1491 1.1 skrll if (n_operands == 3)
1492 1.1 skrll opcodep[2] = exp[1].X_add_number & 255;
1493 1.1 skrll
1494 1.1 skrll if (exp[op2no].X_op == O_register)
1495 1.1 skrll opcodep[3] = exp[op2no].X_add_number;
1496 1.1 skrll else if (exp[op2no].X_op == O_constant)
1497 1.1 skrll {
1498 1.1 skrll opcodep[3] = exp[op2no].X_add_number;
1499 1.1 skrll opcodep[0] |= IMM_OFFSET_BIT;
1500 1.1 skrll }
1501 1.1 skrll else
1502 1.1 skrll fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 3,
1503 1.1 skrll 1, exp + op2no, 0,
1504 1.1 skrll instruction->operands == mmix_operands_roundregs
1505 1.1 skrll ? BFD_RELOC_MMIX_REG
1506 1.1 skrll : BFD_RELOC_MMIX_REG_OR_BYTE);
1507 1.1 skrll break;
1508 1.1 skrll }
1509 1.1 skrll
1510 1.1 skrll case mmix_operands_sync:
1511 1.1 skrll a_single_24_bit_number_operand:
1512 1.1 skrll if (n_operands != 1
1513 1.1 skrll || exp[0].X_op == O_register
1514 1.1 skrll || (exp[0].X_op == O_constant
1515 1.1 skrll && (exp[0].X_add_number > 0xffffff || exp[0].X_add_number < 0)))
1516 1.1 skrll {
1517 1.1 skrll as_bad (_("invalid operands to opcode %s: `%s'"),
1518 1.1 skrll instruction->name, operands);
1519 1.1 skrll return;
1520 1.1 skrll }
1521 1.1 skrll
1522 1.1 skrll if (exp[0].X_op == O_constant)
1523 1.1 skrll {
1524 1.1 skrll opcodep[1] = (exp[0].X_add_number >> 16) & 255;
1525 1.1 skrll opcodep[2] = (exp[0].X_add_number >> 8) & 255;
1526 1.1 skrll opcodep[3] = exp[0].X_add_number & 255;
1527 1.1 skrll }
1528 1.1 skrll else
1529 1.1 skrll /* FIXME: This doesn't bring us unsignedness checking. */
1530 1.1 skrll fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 1,
1531 1.1 skrll 3, exp + 0, 0, BFD_RELOC_24);
1532 1.1 skrll break;
1533 1.1 skrll
1534 1.1 skrll case mmix_operands_neg:
1535 1.1 skrll /* Operands "$X,Y,$Z|Z"; NEG or NEGU. Y is optional, 0 is default. */
1536 1.1 skrll
1537 1.1 skrll if ((n_operands != 3 && n_operands != 2)
1538 1.1 skrll || (n_operands == 3 && exp[1].X_op == O_register)
1539 1.1 skrll || ((exp[1].X_op == O_constant || exp[1].X_op == O_register)
1540 1.1 skrll && (exp[1].X_add_number > 255 || exp[1].X_add_number < 0))
1541 1.1 skrll || (n_operands == 3
1542 1.1 skrll && ((exp[2].X_op == O_register && exp[2].X_add_number > 255)
1543 1.1 skrll || (exp[2].X_op == O_constant
1544 1.1 skrll && (exp[2].X_add_number > 255
1545 1.1 skrll || exp[2].X_add_number < 0)))))
1546 1.1 skrll {
1547 1.1 skrll as_bad (_("invalid operands to opcode %s: `%s'"),
1548 1.1 skrll instruction->name, operands);
1549 1.1 skrll return;
1550 1.1 skrll }
1551 1.1 skrll
1552 1.1 skrll if (n_operands == 2)
1553 1.1 skrll {
1554 1.1 skrll if (exp[1].X_op == O_register)
1555 1.1 skrll opcodep[3] = exp[1].X_add_number;
1556 1.1 skrll else if (exp[1].X_op == O_constant)
1557 1.1 skrll {
1558 1.1 skrll opcodep[3] = exp[1].X_add_number;
1559 1.1 skrll opcodep[0] |= IMM_OFFSET_BIT;
1560 1.1 skrll }
1561 1.1 skrll else
1562 1.1 skrll fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 3,
1563 1.1 skrll 1, exp + 1, 0, BFD_RELOC_MMIX_REG_OR_BYTE);
1564 1.1 skrll break;
1565 1.1 skrll }
1566 1.1 skrll
1567 1.1 skrll if (exp[1].X_op == O_constant)
1568 1.1 skrll opcodep[2] = exp[1].X_add_number;
1569 1.1 skrll else
1570 1.1 skrll fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 2,
1571 1.1 skrll 1, exp + 1, 0, BFD_RELOC_8);
1572 1.1 skrll
1573 1.1 skrll if (exp[2].X_op == O_register)
1574 1.1 skrll opcodep[3] = exp[2].X_add_number;
1575 1.1 skrll else if (exp[2].X_op == O_constant)
1576 1.1 skrll {
1577 1.1 skrll opcodep[3] = exp[2].X_add_number;
1578 1.1 skrll opcodep[0] |= IMM_OFFSET_BIT;
1579 1.1 skrll }
1580 1.1 skrll else
1581 1.1 skrll fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 3,
1582 1.1 skrll 1, exp + 2, 0, BFD_RELOC_MMIX_REG_OR_BYTE);
1583 1.1 skrll break;
1584 1.1 skrll
1585 1.1 skrll case mmix_operands_regaddr:
1586 1.1 skrll /* A GETA/branch-type. */
1587 1.1 skrll break;
1588 1.1 skrll
1589 1.1 skrll case mmix_operands_get:
1590 1.1 skrll /* "$X,spec_reg"; GET.
1591 1.1 skrll Like with rounding modes, we demand that the special register or
1592 1.1 skrll symbol is already defined when we get here at the point of use. */
1593 1.1 skrll if (n_operands != 2
1594 1.1 skrll || (exp[1].X_op == O_register
1595 1.1 skrll && (exp[1].X_add_number < 256 || exp[1].X_add_number >= 512))
1596 1.1 skrll || (exp[1].X_op == O_constant
1597 1.1 skrll && (exp[1].X_add_number < 0 || exp[1].X_add_number > 256))
1598 1.1 skrll || (exp[1].X_op != O_constant && exp[1].X_op != O_register))
1599 1.1 skrll {
1600 1.1 skrll as_bad (_("invalid operands to opcode %s: `%s'"),
1601 1.1 skrll instruction->name, operands);
1602 1.1 skrll return;
1603 1.1 skrll }
1604 1.1 skrll
1605 1.1 skrll opcodep[3] = exp[1].X_add_number - 256;
1606 1.1 skrll break;
1607 1.1 skrll
1608 1.1 skrll case mmix_operands_put:
1609 1.1 skrll /* "spec_reg,$Z|Z"; PUT. */
1610 1.1 skrll if (n_operands != 2
1611 1.1 skrll || (exp[0].X_op == O_register
1612 1.1 skrll && (exp[0].X_add_number < 256 || exp[0].X_add_number >= 512))
1613 1.1 skrll || (exp[0].X_op == O_constant
1614 1.1 skrll && (exp[0].X_add_number < 0 || exp[0].X_add_number > 256))
1615 1.1 skrll || (exp[0].X_op != O_constant && exp[0].X_op != O_register))
1616 1.1 skrll {
1617 1.1 skrll as_bad (_("invalid operands to opcode %s: `%s'"),
1618 1.1 skrll instruction->name, operands);
1619 1.1 skrll return;
1620 1.1 skrll }
1621 1.1 skrll
1622 1.1 skrll opcodep[1] = exp[0].X_add_number - 256;
1623 1.1 skrll
1624 1.1 skrll /* Note that the Y field is zero. */
1625 1.1 skrll
1626 1.1 skrll if (exp[1].X_op == O_register)
1627 1.1 skrll opcodep[3] = exp[1].X_add_number;
1628 1.1 skrll else if (exp[1].X_op == O_constant)
1629 1.1 skrll {
1630 1.1 skrll opcodep[3] = exp[1].X_add_number;
1631 1.1 skrll opcodep[0] |= IMM_OFFSET_BIT;
1632 1.1 skrll }
1633 1.1 skrll else
1634 1.1 skrll fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 3,
1635 1.1 skrll 1, exp + 1, 0, BFD_RELOC_MMIX_REG_OR_BYTE);
1636 1.1 skrll break;
1637 1.1 skrll
1638 1.1 skrll case mmix_operands_save:
1639 1.1 skrll /* "$X,0"; SAVE. */
1640 1.1 skrll if (n_operands != 2
1641 1.1 skrll || exp[1].X_op != O_constant
1642 1.1 skrll || exp[1].X_add_number != 0)
1643 1.1 skrll {
1644 1.1 skrll as_bad (_("invalid operands to opcode %s: `%s'"),
1645 1.1 skrll instruction->name, operands);
1646 1.1 skrll return;
1647 1.1 skrll }
1648 1.1 skrll break;
1649 1.1 skrll
1650 1.1 skrll case mmix_operands_unsave:
1651 1.1 skrll if (n_operands < 2 && ! mmix_gnu_syntax)
1652 1.1 skrll {
1653 1.1 skrll if (n_operands == 1)
1654 1.1 skrll {
1655 1.1 skrll if (exp[0].X_op == O_register)
1656 1.1 skrll opcodep[3] = exp[0].X_add_number;
1657 1.1 skrll else
1658 1.1 skrll fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 3,
1659 1.1 skrll 1, exp, 0, BFD_RELOC_MMIX_REG);
1660 1.1 skrll }
1661 1.1 skrll break;
1662 1.1 skrll }
1663 1.1 skrll
1664 1.1 skrll /* "0,$Z"; UNSAVE. */
1665 1.1 skrll if (n_operands != 2
1666 1.1 skrll || exp[0].X_op != O_constant
1667 1.1 skrll || exp[0].X_add_number != 0
1668 1.1 skrll || exp[1].X_op == O_constant
1669 1.1 skrll || (exp[1].X_op == O_register
1670 1.1 skrll && exp[1].X_add_number > 255))
1671 1.1 skrll {
1672 1.1 skrll as_bad (_("invalid operands to opcode %s: `%s'"),
1673 1.1 skrll instruction->name, operands);
1674 1.1 skrll return;
1675 1.1 skrll }
1676 1.1 skrll
1677 1.1 skrll if (exp[1].X_op == O_register)
1678 1.1 skrll opcodep[3] = exp[1].X_add_number;
1679 1.1 skrll else
1680 1.1 skrll fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 3,
1681 1.1 skrll 1, exp + 1, 0, BFD_RELOC_MMIX_REG);
1682 1.1 skrll break;
1683 1.1 skrll
1684 1.1 skrll case mmix_operands_xyz_opt:
1685 1.1.1.2 christos /* SWYM, TRIP, TRAP: zero, one, two or three operands. It's
1686 1.1.1.2 christos unspecified whether operands are registers or constants, but
1687 1.1.1.2 christos when we find register syntax, we require operands to be literal and
1688 1.1.1.2 christos within 0..255. */
1689 1.1 skrll if (n_operands == 0 && ! mmix_gnu_syntax)
1690 1.1 skrll /* Zeros are in place - nothing needs to be done for zero
1691 1.1 skrll operands. We don't allow this in GNU syntax mode, because it
1692 1.1 skrll was believed that the risk of missing to supply an operand is
1693 1.1 skrll higher than the benefit of not having to specify a zero. */
1694 1.1 skrll ;
1695 1.1 skrll else if (n_operands == 1 && exp[0].X_op != O_register)
1696 1.1 skrll {
1697 1.1 skrll if (exp[0].X_op == O_constant)
1698 1.1 skrll {
1699 1.1.1.2 christos if (exp[0].X_add_number > 255*256*256
1700 1.1 skrll || exp[0].X_add_number < 0)
1701 1.1 skrll {
1702 1.1 skrll as_bad (_("invalid operands to opcode %s: `%s'"),
1703 1.1 skrll instruction->name, operands);
1704 1.1 skrll return;
1705 1.1 skrll }
1706 1.1 skrll else
1707 1.1 skrll {
1708 1.1 skrll opcodep[1] = (exp[0].X_add_number >> 16) & 255;
1709 1.1 skrll opcodep[2] = (exp[0].X_add_number >> 8) & 255;
1710 1.1 skrll opcodep[3] = exp[0].X_add_number & 255;
1711 1.1 skrll }
1712 1.1 skrll }
1713 1.1 skrll else
1714 1.1 skrll fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 1,
1715 1.1 skrll 3, exp, 0, BFD_RELOC_24);
1716 1.1 skrll }
1717 1.1 skrll else if (n_operands == 2
1718 1.1 skrll && exp[0].X_op != O_register
1719 1.1 skrll && exp[1].X_op != O_register)
1720 1.1 skrll {
1721 1.1 skrll /* Two operands. */
1722 1.1 skrll
1723 1.1 skrll if (exp[0].X_op == O_constant)
1724 1.1 skrll {
1725 1.1 skrll if (exp[0].X_add_number > 255
1726 1.1 skrll || exp[0].X_add_number < 0)
1727 1.1 skrll {
1728 1.1 skrll as_bad (_("invalid operands to opcode %s: `%s'"),
1729 1.1 skrll instruction->name, operands);
1730 1.1 skrll return;
1731 1.1 skrll }
1732 1.1 skrll else
1733 1.1 skrll opcodep[1] = exp[0].X_add_number & 255;
1734 1.1 skrll }
1735 1.1 skrll else
1736 1.1 skrll fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 1,
1737 1.1 skrll 1, exp, 0, BFD_RELOC_8);
1738 1.1 skrll
1739 1.1 skrll if (exp[1].X_op == O_constant)
1740 1.1 skrll {
1741 1.1.1.2 christos if (exp[1].X_add_number > 255*256
1742 1.1 skrll || exp[1].X_add_number < 0)
1743 1.1 skrll {
1744 1.1 skrll as_bad (_("invalid operands to opcode %s: `%s'"),
1745 1.1 skrll instruction->name, operands);
1746 1.1 skrll return;
1747 1.1 skrll }
1748 1.1 skrll else
1749 1.1 skrll {
1750 1.1 skrll opcodep[2] = (exp[1].X_add_number >> 8) & 255;
1751 1.1 skrll opcodep[3] = exp[1].X_add_number & 255;
1752 1.1 skrll }
1753 1.1 skrll }
1754 1.1 skrll else
1755 1.1 skrll fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 2,
1756 1.1 skrll 2, exp + 1, 0, BFD_RELOC_16);
1757 1.1 skrll }
1758 1.1 skrll else if (n_operands == 3
1759 1.1 skrll && exp[0].X_op != O_register
1760 1.1 skrll && exp[1].X_op != O_register
1761 1.1 skrll && exp[2].X_op != O_register)
1762 1.1 skrll {
1763 1.1 skrll /* Three operands. */
1764 1.1 skrll
1765 1.1 skrll if (exp[0].X_op == O_constant)
1766 1.1 skrll {
1767 1.1 skrll if (exp[0].X_add_number > 255
1768 1.1 skrll || exp[0].X_add_number < 0)
1769 1.1 skrll {
1770 1.1 skrll as_bad (_("invalid operands to opcode %s: `%s'"),
1771 1.1 skrll instruction->name, operands);
1772 1.1 skrll return;
1773 1.1 skrll }
1774 1.1 skrll else
1775 1.1 skrll opcodep[1] = exp[0].X_add_number & 255;
1776 1.1 skrll }
1777 1.1 skrll else
1778 1.1 skrll fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 1,
1779 1.1 skrll 1, exp, 0, BFD_RELOC_8);
1780 1.1 skrll
1781 1.1 skrll if (exp[1].X_op == O_constant)
1782 1.1 skrll {
1783 1.1 skrll if (exp[1].X_add_number > 255
1784 1.1 skrll || exp[1].X_add_number < 0)
1785 1.1 skrll {
1786 1.1 skrll as_bad (_("invalid operands to opcode %s: `%s'"),
1787 1.1 skrll instruction->name, operands);
1788 1.1 skrll return;
1789 1.1 skrll }
1790 1.1 skrll else
1791 1.1 skrll opcodep[2] = exp[1].X_add_number & 255;
1792 1.1 skrll }
1793 1.1 skrll else
1794 1.1 skrll fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 2,
1795 1.1 skrll 1, exp + 1, 0, BFD_RELOC_8);
1796 1.1 skrll
1797 1.1 skrll if (exp[2].X_op == O_constant)
1798 1.1 skrll {
1799 1.1 skrll if (exp[2].X_add_number > 255
1800 1.1 skrll || exp[2].X_add_number < 0)
1801 1.1 skrll {
1802 1.1 skrll as_bad (_("invalid operands to opcode %s: `%s'"),
1803 1.1 skrll instruction->name, operands);
1804 1.1 skrll return;
1805 1.1 skrll }
1806 1.1 skrll else
1807 1.1 skrll opcodep[3] = exp[2].X_add_number & 255;
1808 1.1 skrll }
1809 1.1 skrll else
1810 1.1 skrll fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 3,
1811 1.1 skrll 1, exp + 2, 0, BFD_RELOC_8);
1812 1.1 skrll }
1813 1.1.1.2 christos else
1814 1.1 skrll {
1815 1.1.1.2 christos /* We can't get here for other cases. */
1816 1.1.1.2 christos gas_assert (n_operands <= 3);
1817 1.1.1.2 christos
1818 1.1.1.2 christos /* The meaning of operands to TRIP and TRAP is not defined (and
1819 1.1.1.2 christos SWYM operands aren't enforced in mmixal, so let's avoid
1820 1.1.1.2 christos that). We add combinations not handled above here as we find
1821 1.1.1.2 christos them and as they're reported. */
1822 1.1 skrll if (n_operands == 3)
1823 1.1 skrll {
1824 1.1 skrll /* Don't require non-register operands. Always generate
1825 1.1 skrll fixups, so we don't have to copy lots of code and create
1826 1.1 skrll maintenance problems. TRIP is supposed to be a rare
1827 1.1 skrll instruction, so the overhead should not matter. We
1828 1.1 skrll aren't allowed to fix_new_exp for an expression which is
1829 1.1.1.2 christos an O_register at this point, however.
1830 1.1.1.2 christos
1831 1.1.1.2 christos Don't use BFD_RELOC_MMIX_REG_OR_BYTE as that modifies
1832 1.1.1.2 christos the insn for a register in the Z field and we want
1833 1.1.1.2 christos consistency. */
1834 1.1 skrll if (exp[0].X_op == O_register)
1835 1.1 skrll opcodep[1] = exp[0].X_add_number;
1836 1.1 skrll else
1837 1.1 skrll fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 1,
1838 1.1.1.2 christos 1, exp, 0, BFD_RELOC_8);
1839 1.1 skrll if (exp[1].X_op == O_register)
1840 1.1 skrll opcodep[2] = exp[1].X_add_number;
1841 1.1 skrll else
1842 1.1 skrll fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 2,
1843 1.1.1.2 christos 1, exp + 1, 0, BFD_RELOC_8);
1844 1.1 skrll if (exp[2].X_op == O_register)
1845 1.1 skrll opcodep[3] = exp[2].X_add_number;
1846 1.1 skrll else
1847 1.1 skrll fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 3,
1848 1.1.1.2 christos 1, exp + 2, 0, BFD_RELOC_8);
1849 1.1 skrll }
1850 1.1 skrll else if (n_operands == 2)
1851 1.1 skrll {
1852 1.1 skrll if (exp[0].X_op == O_register)
1853 1.1.1.2 christos opcodep[1] = exp[0].X_add_number;
1854 1.1 skrll else
1855 1.1.1.2 christos fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 1,
1856 1.1.1.2 christos 1, exp, 0, BFD_RELOC_8);
1857 1.1 skrll if (exp[1].X_op == O_register)
1858 1.1 skrll opcodep[3] = exp[1].X_add_number;
1859 1.1 skrll else
1860 1.1.1.2 christos fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 2,
1861 1.1.1.2 christos 2, exp + 1, 0, BFD_RELOC_16);
1862 1.1 skrll }
1863 1.1 skrll else
1864 1.1 skrll {
1865 1.1.1.2 christos /* We can't get here for other cases. */
1866 1.1.1.2 christos gas_assert (n_operands == 1 && exp[0].X_op == O_register);
1867 1.1.1.2 christos
1868 1.1.1.2 christos opcodep[3] = exp[0].X_add_number;
1869 1.1 skrll }
1870 1.1 skrll }
1871 1.1 skrll break;
1872 1.1 skrll
1873 1.1 skrll case mmix_operands_resume:
1874 1.1 skrll if (n_operands == 0 && ! mmix_gnu_syntax)
1875 1.1 skrll break;
1876 1.1 skrll
1877 1.1 skrll if (n_operands != 1
1878 1.1 skrll || exp[0].X_op == O_register
1879 1.1 skrll || (exp[0].X_op == O_constant
1880 1.1 skrll && (exp[0].X_add_number < 0
1881 1.1 skrll || exp[0].X_add_number > 255)))
1882 1.1 skrll {
1883 1.1 skrll as_bad (_("invalid operands to opcode %s: `%s'"),
1884 1.1 skrll instruction->name, operands);
1885 1.1 skrll return;
1886 1.1 skrll }
1887 1.1 skrll
1888 1.1 skrll if (exp[0].X_op == O_constant)
1889 1.1 skrll opcodep[3] = exp[0].X_add_number;
1890 1.1 skrll else
1891 1.1 skrll fix_new_exp (opc_fragP, opcodep - opc_fragP->fr_literal + 3,
1892 1.1 skrll 1, exp + 0, 0, BFD_RELOC_8);
1893 1.1 skrll break;
1894 1.1 skrll
1895 1.1 skrll case mmix_operands_pushj:
1896 1.1 skrll /* All is done for PUSHJ already. */
1897 1.1 skrll break;
1898 1.1 skrll
1899 1.1 skrll default:
1900 1.1 skrll BAD_CASE (instruction->operands);
1901 1.1 skrll }
1902 1.1 skrll }
1903 1.1 skrll
1904 1.1 skrll /* For the benefit of insns that start with a digit, we assemble by way of
1905 1.1 skrll tc_unrecognized_line too, through this function. */
1906 1.1 skrll
1907 1.1 skrll int
1908 1.1 skrll mmix_assemble_return_nonzero (char *str)
1909 1.1 skrll {
1910 1.1 skrll int last_error_count = had_errors ();
1911 1.1 skrll char *s2 = str;
1912 1.1 skrll char c;
1913 1.1 skrll
1914 1.1 skrll /* Normal instruction handling downcases, so we must too. */
1915 1.1 skrll while (ISALNUM (*s2))
1916 1.1 skrll {
1917 1.1 skrll if (ISUPPER ((unsigned char) *s2))
1918 1.1 skrll *s2 = TOLOWER (*s2);
1919 1.1 skrll s2++;
1920 1.1 skrll }
1921 1.1 skrll
1922 1.1 skrll /* Cut the line for sake of the assembly. */
1923 1.1 skrll for (s2 = str; *s2 && *s2 != '\n'; s2++)
1924 1.1 skrll ;
1925 1.1 skrll
1926 1.1 skrll c = *s2;
1927 1.1 skrll *s2 = 0;
1928 1.1 skrll md_assemble (str);
1929 1.1 skrll *s2 = c;
1930 1.1 skrll
1931 1.1 skrll return had_errors () == last_error_count;
1932 1.1 skrll }
1933 1.1 skrll
1934 1.1 skrll /* The PREFIX pseudo. */
1935 1.1 skrll
1936 1.1 skrll static void
1937 1.1 skrll s_prefix (int unused ATTRIBUTE_UNUSED)
1938 1.1 skrll {
1939 1.1 skrll char *p;
1940 1.1 skrll int c;
1941 1.1 skrll
1942 1.1 skrll SKIP_WHITESPACE ();
1943 1.1 skrll
1944 1.1.1.4 christos c = get_symbol_name (&p);
1945 1.1.1.4 christos
1946 1.1.1.6 christos /* Resetting prefix? */
1947 1.1 skrll if (*p == ':' && p[1] == 0)
1948 1.1 skrll mmix_current_prefix = NULL;
1949 1.1 skrll else
1950 1.1 skrll {
1951 1.1 skrll /* Put this prefix on the mmix symbols obstack. We could malloc and
1952 1.1 skrll free it separately, but then we'd have to worry about that.
1953 1.1 skrll People using up memory on prefixes have other problems. */
1954 1.1 skrll obstack_grow (&mmix_sym_obstack, p, strlen (p) + 1);
1955 1.1 skrll p = obstack_finish (&mmix_sym_obstack);
1956 1.1 skrll
1957 1.1 skrll /* Accumulate prefixes, and strip a leading ':'. */
1958 1.1 skrll if (mmix_current_prefix != NULL || *p == ':')
1959 1.1 skrll p = mmix_prefix_name (p);
1960 1.1 skrll
1961 1.1 skrll mmix_current_prefix = p;
1962 1.1 skrll }
1963 1.1 skrll
1964 1.1.1.4 christos (void) restore_line_pointer (c);
1965 1.1 skrll
1966 1.1 skrll mmix_handle_rest_of_empty_line ();
1967 1.1 skrll }
1968 1.1 skrll
1969 1.1 skrll /* We implement prefixes by using the tc_canonicalize_symbol_name hook,
1970 1.1 skrll and store each prefixed name on a (separate) obstack. This means that
1971 1.1 skrll the name is on the "notes" obstack in non-prefixed form and on the
1972 1.1 skrll mmix_sym_obstack in prefixed form, but currently it is not worth
1973 1.1 skrll rewriting the whole GAS symbol handling to improve "hooking" to avoid
1974 1.1 skrll that. (It might be worth a rewrite for other reasons, though). */
1975 1.1 skrll
1976 1.1 skrll char *
1977 1.1 skrll mmix_prefix_name (char *shortname)
1978 1.1 skrll {
1979 1.1 skrll if (*shortname == ':')
1980 1.1 skrll return shortname + 1;
1981 1.1 skrll
1982 1.1 skrll if (mmix_current_prefix == NULL)
1983 1.1 skrll as_fatal (_("internal: mmix_prefix_name but empty prefix"));
1984 1.1 skrll
1985 1.1 skrll if (*shortname == '$')
1986 1.1 skrll return shortname;
1987 1.1 skrll
1988 1.1 skrll obstack_grow (&mmix_sym_obstack, mmix_current_prefix,
1989 1.1 skrll strlen (mmix_current_prefix));
1990 1.1 skrll obstack_grow (&mmix_sym_obstack, shortname, strlen (shortname) + 1);
1991 1.1 skrll return obstack_finish (&mmix_sym_obstack);
1992 1.1 skrll }
1993 1.1 skrll
1994 1.1 skrll /* The GREG pseudo. At LABEL, we have the name of a symbol that we
1995 1.1 skrll want to make a register symbol, and which should be initialized with
1996 1.1 skrll the value in the expression at INPUT_LINE_POINTER (defaulting to 0).
1997 1.1 skrll Either and (perhaps less meaningful) both may be missing. LABEL must
1998 1.1 skrll be persistent, perhaps allocated on an obstack. */
1999 1.1 skrll
2000 1.1 skrll static void
2001 1.1 skrll mmix_greg_internal (char *label)
2002 1.1 skrll {
2003 1.1 skrll expressionS *expP = &mmix_raw_gregs[n_of_raw_gregs].exp;
2004 1.1.1.3 christos segT section;
2005 1.1 skrll
2006 1.1 skrll /* Don't set the section to register contents section before the
2007 1.1 skrll expression has been parsed; it may refer to the current position. */
2008 1.1.1.3 christos section = expression (expP);
2009 1.1 skrll
2010 1.1 skrll /* FIXME: Check that no expression refers to the register contents
2011 1.1 skrll section. May need to be done in elf64-mmix.c. */
2012 1.1 skrll if (expP->X_op == O_absent)
2013 1.1 skrll {
2014 1.1 skrll /* Default to zero if the expression was absent. */
2015 1.1 skrll expP->X_op = O_constant;
2016 1.1 skrll expP->X_add_number = 0;
2017 1.1 skrll expP->X_unsigned = 0;
2018 1.1 skrll expP->X_add_symbol = NULL;
2019 1.1 skrll expP->X_op_symbol = NULL;
2020 1.1 skrll }
2021 1.1 skrll
2022 1.1.1.3 christos if (section == undefined_section)
2023 1.1.1.3 christos {
2024 1.1.1.3 christos /* This is an error or a LOC with an expression involving
2025 1.1.1.3 christos forward references. For the expression to be correctly
2026 1.1.1.3 christos evaluated, we need to force a proper symbol; gas loses track
2027 1.1.1.3 christos of the segment for "local symbols". */
2028 1.1.1.3 christos if (expP->X_op == O_add)
2029 1.1.1.3 christos {
2030 1.1.1.3 christos symbol_get_value_expression (expP->X_op_symbol);
2031 1.1.1.3 christos symbol_get_value_expression (expP->X_add_symbol);
2032 1.1.1.3 christos }
2033 1.1.1.3 christos else
2034 1.1.1.3 christos {
2035 1.1.1.3 christos gas_assert (expP->X_op == O_symbol);
2036 1.1.1.3 christos symbol_get_value_expression (expP->X_add_symbol);
2037 1.1.1.3 christos }
2038 1.1.1.3 christos }
2039 1.1.1.3 christos
2040 1.1 skrll /* We must handle prefixes here, as we save the labels and expressions
2041 1.1 skrll to be output later. */
2042 1.1 skrll mmix_raw_gregs[n_of_raw_gregs].label
2043 1.1 skrll = mmix_current_prefix == NULL ? label : mmix_prefix_name (label);
2044 1.1 skrll
2045 1.1 skrll if (n_of_raw_gregs == MAX_GREGS - 1)
2046 1.1 skrll as_bad (_("too many GREG registers allocated (max %d)"), MAX_GREGS);
2047 1.1 skrll else
2048 1.1 skrll n_of_raw_gregs++;
2049 1.1 skrll
2050 1.1 skrll mmix_handle_rest_of_empty_line ();
2051 1.1 skrll }
2052 1.1 skrll
2053 1.1 skrll /* The ".greg label,expr" worker. */
2054 1.1 skrll
2055 1.1 skrll static void
2056 1.1 skrll s_greg (int unused ATTRIBUTE_UNUSED)
2057 1.1 skrll {
2058 1.1 skrll char *p;
2059 1.1 skrll char c;
2060 1.1 skrll
2061 1.1 skrll /* This will skip over what can be a symbol and zero out the next
2062 1.1 skrll character, which we assume is a ',' or other meaningful delimiter.
2063 1.1 skrll What comes after that is the initializer expression for the
2064 1.1 skrll register. */
2065 1.1.1.4 christos c = get_symbol_name (&p);
2066 1.1.1.4 christos
2067 1.1.1.4 christos if (c == '"')
2068 1.1.1.4 christos c = * ++ input_line_pointer;
2069 1.1 skrll
2070 1.1 skrll if (! is_end_of_line[(unsigned char) c])
2071 1.1 skrll input_line_pointer++;
2072 1.1 skrll
2073 1.1 skrll if (*p)
2074 1.1 skrll {
2075 1.1 skrll /* The label must be persistent; it's not used until after all input
2076 1.1 skrll has been seen. */
2077 1.1 skrll obstack_grow (&mmix_sym_obstack, p, strlen (p) + 1);
2078 1.1 skrll mmix_greg_internal (obstack_finish (&mmix_sym_obstack));
2079 1.1 skrll }
2080 1.1 skrll else
2081 1.1 skrll mmix_greg_internal (NULL);
2082 1.1 skrll }
2083 1.1 skrll
2084 1.1 skrll /* The "BSPEC expr" worker. */
2085 1.1 skrll
2086 1.1 skrll static void
2087 1.1 skrll s_bspec (int unused ATTRIBUTE_UNUSED)
2088 1.1 skrll {
2089 1.1 skrll asection *expsec;
2090 1.1 skrll asection *sec;
2091 1.1 skrll char secname[sizeof (MMIX_OTHER_SPEC_SECTION_PREFIX) + 20]
2092 1.1 skrll = MMIX_OTHER_SPEC_SECTION_PREFIX;
2093 1.1 skrll expressionS exp;
2094 1.1 skrll int n;
2095 1.1 skrll
2096 1.1 skrll /* Get a constant expression which we can evaluate *now*. Supporting
2097 1.1 skrll more complex (though assembly-time computable) expressions is
2098 1.1 skrll feasible but Too Much Work for something of unknown usefulness like
2099 1.1 skrll BSPEC-ESPEC. */
2100 1.1 skrll expsec = expression (&exp);
2101 1.1 skrll mmix_handle_rest_of_empty_line ();
2102 1.1 skrll
2103 1.1 skrll /* Check that we don't have another BSPEC in progress. */
2104 1.1 skrll if (doing_bspec)
2105 1.1 skrll {
2106 1.1 skrll as_bad (_("BSPEC already active. Nesting is not supported."));
2107 1.1 skrll return;
2108 1.1 skrll }
2109 1.1 skrll
2110 1.1 skrll if (exp.X_op != O_constant
2111 1.1 skrll || expsec != absolute_section
2112 1.1 skrll || exp.X_add_number < 0
2113 1.1 skrll || exp.X_add_number > 65535)
2114 1.1 skrll {
2115 1.1 skrll as_bad (_("invalid BSPEC expression"));
2116 1.1 skrll exp.X_add_number = 0;
2117 1.1 skrll }
2118 1.1 skrll
2119 1.1 skrll n = (int) exp.X_add_number;
2120 1.1 skrll
2121 1.1 skrll sprintf (secname + strlen (MMIX_OTHER_SPEC_SECTION_PREFIX), "%d", n);
2122 1.1 skrll sec = bfd_get_section_by_name (stdoutput, secname);
2123 1.1 skrll if (sec == NULL)
2124 1.1 skrll {
2125 1.1 skrll /* We need a non-volatile name as it will be stored in the section
2126 1.1 skrll struct. */
2127 1.1 skrll char *newsecname = xstrdup (secname);
2128 1.1 skrll sec = bfd_make_section (stdoutput, newsecname);
2129 1.1 skrll
2130 1.1 skrll if (sec == NULL)
2131 1.1 skrll as_fatal (_("can't create section %s"), newsecname);
2132 1.1 skrll
2133 1.1.1.7 christos if (!bfd_set_section_flags (sec,
2134 1.1.1.7 christos bfd_section_flags (sec) | SEC_READONLY))
2135 1.1 skrll as_fatal (_("can't set section flags for section %s"), newsecname);
2136 1.1 skrll }
2137 1.1 skrll
2138 1.1 skrll /* Tell ELF about the pending section change. */
2139 1.1 skrll obj_elf_section_change_hook ();
2140 1.1 skrll subseg_set (sec, 0);
2141 1.1 skrll
2142 1.1 skrll /* Save position for missing ESPEC. */
2143 1.1.1.5 christos bspec_file = as_where (&bspec_line);
2144 1.1 skrll
2145 1.1 skrll doing_bspec = 1;
2146 1.1 skrll }
2147 1.1 skrll
2148 1.1 skrll /* The "ESPEC" worker. */
2149 1.1 skrll
2150 1.1 skrll static void
2151 1.1 skrll s_espec (int unused ATTRIBUTE_UNUSED)
2152 1.1 skrll {
2153 1.1 skrll /* First, check that we *do* have a BSPEC in progress. */
2154 1.1 skrll if (! doing_bspec)
2155 1.1 skrll {
2156 1.1 skrll as_bad (_("ESPEC without preceding BSPEC"));
2157 1.1 skrll return;
2158 1.1 skrll }
2159 1.1 skrll
2160 1.1 skrll mmix_handle_rest_of_empty_line ();
2161 1.1 skrll doing_bspec = 0;
2162 1.1 skrll
2163 1.1 skrll /* When we told ELF about the section change in s_bspec, it stored the
2164 1.1 skrll previous section for us so we can get at it with the equivalent of a
2165 1.1 skrll .previous pseudo. */
2166 1.1 skrll obj_elf_previous (0);
2167 1.1 skrll }
2168 1.1 skrll
2169 1.1 skrll /* The " .local expr" and " local expr" worker. We make a BFD_MMIX_LOCAL
2170 1.1 skrll relocation against the current position against the expression.
2171 1.1 skrll Implementing this by means of contents in a section lost. */
2172 1.1 skrll
2173 1.1 skrll static void
2174 1.1 skrll mmix_s_local (int unused ATTRIBUTE_UNUSED)
2175 1.1 skrll {
2176 1.1 skrll expressionS exp;
2177 1.1 skrll
2178 1.1 skrll /* Don't set the section to register contents section before the
2179 1.1 skrll expression has been parsed; it may refer to the current position in
2180 1.1 skrll some contorted way. */
2181 1.1 skrll expression (&exp);
2182 1.1 skrll
2183 1.1 skrll if (exp.X_op == O_absent)
2184 1.1 skrll {
2185 1.1 skrll as_bad (_("missing local expression"));
2186 1.1 skrll return;
2187 1.1 skrll }
2188 1.1 skrll else if (exp.X_op == O_register)
2189 1.1 skrll {
2190 1.1 skrll /* fix_new_exp doesn't like O_register. Should be configurable.
2191 1.1 skrll We're fine with a constant here, though. */
2192 1.1 skrll exp.X_op = O_constant;
2193 1.1 skrll }
2194 1.1 skrll
2195 1.1 skrll fix_new_exp (frag_now, 0, 0, &exp, 0, BFD_RELOC_MMIX_LOCAL);
2196 1.1 skrll mmix_handle_rest_of_empty_line ();
2197 1.1 skrll }
2198 1.1 skrll
2199 1.1 skrll /* Set fragP->fr_var to the initial guess of the size of a relaxable insn
2200 1.1 skrll and return it. Sizes of other instructions are not known. This
2201 1.1 skrll function may be called multiple times. */
2202 1.1 skrll
2203 1.1 skrll int
2204 1.1 skrll md_estimate_size_before_relax (fragS *fragP, segT segment)
2205 1.1 skrll {
2206 1.1 skrll int length;
2207 1.1 skrll
2208 1.1 skrll #define HANDLE_RELAXABLE(state) \
2209 1.1 skrll case ENCODE_RELAX (state, STATE_UNDF): \
2210 1.1 skrll if (fragP->fr_symbol != NULL \
2211 1.1 skrll && S_GET_SEGMENT (fragP->fr_symbol) == segment \
2212 1.1 skrll && !S_IS_WEAK (fragP->fr_symbol)) \
2213 1.1 skrll { \
2214 1.1 skrll /* The symbol lies in the same segment - a relaxable case. */ \
2215 1.1 skrll fragP->fr_subtype \
2216 1.1 skrll = ENCODE_RELAX (state, STATE_ZERO); \
2217 1.1 skrll } \
2218 1.1 skrll break;
2219 1.1 skrll
2220 1.1 skrll switch (fragP->fr_subtype)
2221 1.1 skrll {
2222 1.1 skrll HANDLE_RELAXABLE (STATE_GETA);
2223 1.1 skrll HANDLE_RELAXABLE (STATE_BCC);
2224 1.1 skrll HANDLE_RELAXABLE (STATE_JMP);
2225 1.1 skrll
2226 1.1 skrll case ENCODE_RELAX (STATE_PUSHJ, STATE_UNDF):
2227 1.1 skrll if (fragP->fr_symbol != NULL
2228 1.1 skrll && S_GET_SEGMENT (fragP->fr_symbol) == segment
2229 1.1 skrll && !S_IS_WEAK (fragP->fr_symbol))
2230 1.1 skrll /* The symbol lies in the same segment - a relaxable case. */
2231 1.1 skrll fragP->fr_subtype = ENCODE_RELAX (STATE_PUSHJ, STATE_ZERO);
2232 1.1 skrll else if (pushj_stubs)
2233 1.1 skrll /* If we're to generate stubs, assume we can reach a stub after
2234 1.1 skrll the section. */
2235 1.1 skrll fragP->fr_subtype = ENCODE_RELAX (STATE_PUSHJSTUB, STATE_ZERO);
2236 1.1 skrll /* FALLTHROUGH. */
2237 1.1 skrll case ENCODE_RELAX (STATE_PUSHJ, STATE_ZERO):
2238 1.1 skrll case ENCODE_RELAX (STATE_PUSHJSTUB, STATE_ZERO):
2239 1.1 skrll /* We need to distinguish different relaxation rounds. */
2240 1.1 skrll seg_info (segment)->tc_segment_info_data.last_stubfrag = fragP;
2241 1.1 skrll break;
2242 1.1 skrll
2243 1.1 skrll case ENCODE_RELAX (STATE_GETA, STATE_ZERO):
2244 1.1 skrll case ENCODE_RELAX (STATE_BCC, STATE_ZERO):
2245 1.1 skrll case ENCODE_RELAX (STATE_JMP, STATE_ZERO):
2246 1.1 skrll /* When relaxing a section for the second time, we don't need to do
2247 1.1 skrll anything except making sure that fr_var is set right. */
2248 1.1 skrll break;
2249 1.1 skrll
2250 1.1 skrll case STATE_GREG_DEF:
2251 1.1 skrll length = fragP->tc_frag_data != NULL ? 0 : 8;
2252 1.1 skrll fragP->fr_var = length;
2253 1.1 skrll
2254 1.1 skrll /* Don't consult the relax_table; it isn't valid for this
2255 1.1 skrll relaxation. */
2256 1.1 skrll return length;
2257 1.1 skrll break;
2258 1.1 skrll
2259 1.1 skrll default:
2260 1.1 skrll BAD_CASE (fragP->fr_subtype);
2261 1.1 skrll }
2262 1.1 skrll
2263 1.1 skrll length = mmix_relax_table[fragP->fr_subtype].rlx_length;
2264 1.1 skrll fragP->fr_var = length;
2265 1.1 skrll
2266 1.1 skrll return length;
2267 1.1 skrll }
2268 1.1 skrll
2269 1.1 skrll /* Turn a string in input_line_pointer into a floating point constant of type
2270 1.1 skrll type, and store the appropriate bytes in *litP. The number of LITTLENUMS
2271 1.1 skrll emitted is stored in *sizeP . An error message is returned, or NULL on
2272 1.1 skrll OK. */
2273 1.1 skrll
2274 1.1.1.5 christos const char *
2275 1.1 skrll md_atof (int type, char *litP, int *sizeP)
2276 1.1 skrll {
2277 1.1 skrll if (type == 'r')
2278 1.1 skrll type = 'f';
2279 1.1.1.5 christos /* FIXME: Having 'f' in FLT_CHARS (and here) makes it
2280 1.1 skrll problematic to also have a forward reference in an expression.
2281 1.1 skrll The testsuite wants it, and it's customary.
2282 1.1 skrll We'll deal with the real problems when they come; we share the
2283 1.1 skrll problem with most other ports. */
2284 1.1 skrll return ieee_md_atof (type, litP, sizeP, TRUE);
2285 1.1 skrll }
2286 1.1 skrll
2287 1.1 skrll /* Convert variable-sized frags into one or more fixups. */
2288 1.1 skrll
2289 1.1 skrll void
2290 1.1 skrll md_convert_frag (bfd *abfd ATTRIBUTE_UNUSED, segT sec ATTRIBUTE_UNUSED,
2291 1.1 skrll fragS *fragP)
2292 1.1 skrll {
2293 1.1 skrll /* Pointer to first byte in variable-sized part of the frag. */
2294 1.1 skrll char *var_partp;
2295 1.1 skrll
2296 1.1 skrll /* Pointer to first opcode byte in frag. */
2297 1.1 skrll char *opcodep;
2298 1.1 skrll
2299 1.1 skrll /* Size in bytes of variable-sized part of frag. */
2300 1.1 skrll int var_part_size = 0;
2301 1.1 skrll
2302 1.1 skrll /* This is part of *fragP. It contains all information about addresses
2303 1.1 skrll and offsets to varying parts. */
2304 1.1 skrll symbolS *symbolP;
2305 1.1 skrll unsigned long var_part_offset;
2306 1.1 skrll
2307 1.1 skrll /* This is the frag for the opcode. It, rather than fragP, must be used
2308 1.1 skrll when emitting a frag for the opcode. */
2309 1.1 skrll fragS *opc_fragP = fragP->tc_frag_data;
2310 1.1 skrll fixS *tmpfixP;
2311 1.1 skrll
2312 1.1 skrll /* Where, in file space, does addr point? */
2313 1.1 skrll bfd_vma target_address;
2314 1.1 skrll bfd_vma opcode_address;
2315 1.1 skrll
2316 1.1 skrll know (fragP->fr_type == rs_machine_dependent);
2317 1.1 skrll
2318 1.1 skrll var_part_offset = fragP->fr_fix;
2319 1.1 skrll var_partp = fragP->fr_literal + var_part_offset;
2320 1.1 skrll opcodep = fragP->fr_opcode;
2321 1.1 skrll
2322 1.1 skrll symbolP = fragP->fr_symbol;
2323 1.1 skrll
2324 1.1 skrll target_address
2325 1.1 skrll = ((symbolP ? S_GET_VALUE (symbolP) : 0) + fragP->fr_offset);
2326 1.1 skrll
2327 1.1 skrll /* The opcode that would be extended is the last four "fixed" bytes. */
2328 1.1 skrll opcode_address = fragP->fr_address + fragP->fr_fix - 4;
2329 1.1 skrll
2330 1.1 skrll switch (fragP->fr_subtype)
2331 1.1 skrll {
2332 1.1 skrll case ENCODE_RELAX (STATE_PUSHJSTUB, STATE_ZERO):
2333 1.1 skrll /* Setting the unknown bits to 0 seems the most appropriate. */
2334 1.1 skrll mmix_set_geta_branch_offset (opcodep, 0);
2335 1.1 skrll tmpfixP = fix_new (opc_fragP, opcodep - opc_fragP->fr_literal, 8,
2336 1.1 skrll fragP->fr_symbol, fragP->fr_offset, 1,
2337 1.1 skrll BFD_RELOC_MMIX_PUSHJ_STUBBABLE);
2338 1.1 skrll COPY_FR_WHERE_TO_FX (fragP, tmpfixP);
2339 1.1 skrll var_part_size = 0;
2340 1.1 skrll break;
2341 1.1 skrll
2342 1.1 skrll case ENCODE_RELAX (STATE_GETA, STATE_ZERO):
2343 1.1 skrll case ENCODE_RELAX (STATE_BCC, STATE_ZERO):
2344 1.1 skrll case ENCODE_RELAX (STATE_PUSHJ, STATE_ZERO):
2345 1.1 skrll mmix_set_geta_branch_offset (opcodep, target_address - opcode_address);
2346 1.1 skrll if (linkrelax)
2347 1.1 skrll {
2348 1.1 skrll tmpfixP
2349 1.1 skrll = fix_new (opc_fragP, opcodep - opc_fragP->fr_literal, 4,
2350 1.1 skrll fragP->fr_symbol, fragP->fr_offset, 1,
2351 1.1 skrll BFD_RELOC_MMIX_ADDR19);
2352 1.1 skrll COPY_FR_WHERE_TO_FX (fragP, tmpfixP);
2353 1.1 skrll }
2354 1.1 skrll var_part_size = 0;
2355 1.1 skrll break;
2356 1.1 skrll
2357 1.1 skrll case ENCODE_RELAX (STATE_JMP, STATE_ZERO):
2358 1.1 skrll mmix_set_jmp_offset (opcodep, target_address - opcode_address);
2359 1.1 skrll if (linkrelax)
2360 1.1 skrll {
2361 1.1 skrll tmpfixP
2362 1.1 skrll = fix_new (opc_fragP, opcodep - opc_fragP->fr_literal, 4,
2363 1.1 skrll fragP->fr_symbol, fragP->fr_offset, 1,
2364 1.1 skrll BFD_RELOC_MMIX_ADDR27);
2365 1.1 skrll COPY_FR_WHERE_TO_FX (fragP, tmpfixP);
2366 1.1 skrll }
2367 1.1 skrll var_part_size = 0;
2368 1.1 skrll break;
2369 1.1 skrll
2370 1.1 skrll case STATE_GREG_DEF:
2371 1.1 skrll if (fragP->tc_frag_data == NULL)
2372 1.1 skrll {
2373 1.1 skrll /* We must initialize data that's supposed to be "fixed up" to
2374 1.1 skrll avoid emitting garbage, because md_apply_fix won't do
2375 1.1 skrll anything for undefined symbols. */
2376 1.1 skrll md_number_to_chars (var_partp, 0, 8);
2377 1.1 skrll tmpfixP
2378 1.1 skrll = fix_new (fragP, var_partp - fragP->fr_literal, 8,
2379 1.1 skrll fragP->fr_symbol, fragP->fr_offset, 0, BFD_RELOC_64);
2380 1.1 skrll COPY_FR_WHERE_TO_FX (fragP, tmpfixP);
2381 1.1 skrll mmix_gregs[n_of_cooked_gregs++] = tmpfixP;
2382 1.1 skrll var_part_size = 8;
2383 1.1 skrll }
2384 1.1 skrll else
2385 1.1 skrll var_part_size = 0;
2386 1.1 skrll break;
2387 1.1 skrll
2388 1.1 skrll #define HANDLE_MAX_RELOC(state, reloc) \
2389 1.1 skrll case ENCODE_RELAX (state, STATE_MAX): \
2390 1.1 skrll var_part_size \
2391 1.1 skrll = mmix_relax_table[ENCODE_RELAX (state, STATE_MAX)].rlx_length; \
2392 1.1 skrll mmix_fill_nops (var_partp, var_part_size / 4); \
2393 1.1 skrll if (warn_on_expansion) \
2394 1.1 skrll as_warn_where (fragP->fr_file, fragP->fr_line, \
2395 1.1 skrll _("operand out of range, instruction expanded")); \
2396 1.1 skrll tmpfixP = fix_new (fragP, var_partp - fragP->fr_literal - 4, 8, \
2397 1.1 skrll fragP->fr_symbol, fragP->fr_offset, 1, reloc); \
2398 1.1 skrll COPY_FR_WHERE_TO_FX (fragP, tmpfixP); \
2399 1.1 skrll break
2400 1.1 skrll
2401 1.1 skrll HANDLE_MAX_RELOC (STATE_GETA, BFD_RELOC_MMIX_GETA);
2402 1.1 skrll HANDLE_MAX_RELOC (STATE_BCC, BFD_RELOC_MMIX_CBRANCH);
2403 1.1 skrll HANDLE_MAX_RELOC (STATE_PUSHJ, BFD_RELOC_MMIX_PUSHJ);
2404 1.1 skrll HANDLE_MAX_RELOC (STATE_JMP, BFD_RELOC_MMIX_JMP);
2405 1.1 skrll
2406 1.1 skrll default:
2407 1.1 skrll BAD_CASE (fragP->fr_subtype);
2408 1.1 skrll break;
2409 1.1 skrll }
2410 1.1 skrll
2411 1.1 skrll fragP->fr_fix += var_part_size;
2412 1.1 skrll fragP->fr_var = 0;
2413 1.1 skrll }
2414 1.1 skrll
2415 1.1 skrll /* Applies the desired value to the specified location.
2416 1.1 skrll Also sets up addends for RELA type relocations.
2417 1.1 skrll Stolen from tc-mcore.c.
2418 1.1 skrll
2419 1.1 skrll Note that this function isn't called when linkrelax != 0. */
2420 1.1 skrll
2421 1.1 skrll void
2422 1.1 skrll md_apply_fix (fixS *fixP, valueT *valP, segT segment)
2423 1.1 skrll {
2424 1.1 skrll char *buf = fixP->fx_where + fixP->fx_frag->fr_literal;
2425 1.1 skrll /* Note: use offsetT because it is signed, valueT is unsigned. */
2426 1.1 skrll offsetT val = (offsetT) * valP;
2427 1.1 skrll segT symsec
2428 1.1 skrll = (fixP->fx_addsy == NULL
2429 1.1 skrll ? absolute_section : S_GET_SEGMENT (fixP->fx_addsy));
2430 1.1 skrll
2431 1.1 skrll /* If the fix is relative to a symbol which is not defined, or, (if
2432 1.1 skrll pcrel), not in the same segment as the fix, we cannot resolve it
2433 1.1 skrll here. */
2434 1.1 skrll if (fixP->fx_addsy != NULL
2435 1.1 skrll && (! S_IS_DEFINED (fixP->fx_addsy)
2436 1.1 skrll || S_IS_WEAK (fixP->fx_addsy)
2437 1.1 skrll || (fixP->fx_pcrel && symsec != segment)
2438 1.1 skrll || (! fixP->fx_pcrel
2439 1.1 skrll && symsec != absolute_section
2440 1.1 skrll && ((fixP->fx_r_type != BFD_RELOC_MMIX_REG
2441 1.1 skrll && fixP->fx_r_type != BFD_RELOC_MMIX_REG_OR_BYTE)
2442 1.1 skrll || symsec != reg_section))))
2443 1.1 skrll {
2444 1.1 skrll fixP->fx_done = 0;
2445 1.1 skrll return;
2446 1.1 skrll }
2447 1.1 skrll else if (fixP->fx_r_type == BFD_RELOC_MMIX_LOCAL
2448 1.1 skrll || fixP->fx_r_type == BFD_RELOC_VTABLE_INHERIT
2449 1.1 skrll || fixP->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
2450 1.1 skrll {
2451 1.1 skrll /* These are never "fixed". */
2452 1.1 skrll fixP->fx_done = 0;
2453 1.1 skrll return;
2454 1.1 skrll }
2455 1.1 skrll else
2456 1.1 skrll /* We assume every other relocation is "fixed". */
2457 1.1 skrll fixP->fx_done = 1;
2458 1.1 skrll
2459 1.1 skrll switch (fixP->fx_r_type)
2460 1.1 skrll {
2461 1.1 skrll case BFD_RELOC_64:
2462 1.1 skrll case BFD_RELOC_32:
2463 1.1 skrll case BFD_RELOC_24:
2464 1.1 skrll case BFD_RELOC_16:
2465 1.1 skrll case BFD_RELOC_8:
2466 1.1 skrll case BFD_RELOC_64_PCREL:
2467 1.1 skrll case BFD_RELOC_32_PCREL:
2468 1.1 skrll case BFD_RELOC_24_PCREL:
2469 1.1 skrll case BFD_RELOC_16_PCREL:
2470 1.1 skrll case BFD_RELOC_8_PCREL:
2471 1.1 skrll md_number_to_chars (buf, val, fixP->fx_size);
2472 1.1 skrll break;
2473 1.1 skrll
2474 1.1 skrll case BFD_RELOC_MMIX_ADDR19:
2475 1.1 skrll if (expand_op)
2476 1.1 skrll {
2477 1.1 skrll /* This shouldn't happen. */
2478 1.1 skrll BAD_CASE (fixP->fx_r_type);
2479 1.1 skrll break;
2480 1.1 skrll }
2481 1.1 skrll /* FALLTHROUGH. */
2482 1.1 skrll case BFD_RELOC_MMIX_GETA:
2483 1.1 skrll case BFD_RELOC_MMIX_CBRANCH:
2484 1.1 skrll case BFD_RELOC_MMIX_PUSHJ:
2485 1.1 skrll case BFD_RELOC_MMIX_PUSHJ_STUBBABLE:
2486 1.1 skrll /* If this fixup is out of range, punt to the linker to emit an
2487 1.1 skrll error. This should only happen with -no-expand. */
2488 1.1 skrll if (val < -(((offsetT) 1 << 19)/2)
2489 1.1 skrll || val >= ((offsetT) 1 << 19)/2 - 1
2490 1.1 skrll || (val & 3) != 0)
2491 1.1 skrll {
2492 1.1 skrll if (warn_on_expansion)
2493 1.1 skrll as_warn_where (fixP->fx_file, fixP->fx_line,
2494 1.1 skrll _("operand out of range"));
2495 1.1 skrll fixP->fx_done = 0;
2496 1.1 skrll val = 0;
2497 1.1 skrll }
2498 1.1 skrll mmix_set_geta_branch_offset (buf, val);
2499 1.1 skrll break;
2500 1.1 skrll
2501 1.1 skrll case BFD_RELOC_MMIX_ADDR27:
2502 1.1 skrll if (expand_op)
2503 1.1 skrll {
2504 1.1 skrll /* This shouldn't happen. */
2505 1.1 skrll BAD_CASE (fixP->fx_r_type);
2506 1.1 skrll break;
2507 1.1 skrll }
2508 1.1 skrll /* FALLTHROUGH. */
2509 1.1 skrll case BFD_RELOC_MMIX_JMP:
2510 1.1 skrll /* If this fixup is out of range, punt to the linker to emit an
2511 1.1 skrll error. This should only happen with -no-expand. */
2512 1.1 skrll if (val < -(((offsetT) 1 << 27)/2)
2513 1.1 skrll || val >= ((offsetT) 1 << 27)/2 - 1
2514 1.1 skrll || (val & 3) != 0)
2515 1.1 skrll {
2516 1.1 skrll if (warn_on_expansion)
2517 1.1 skrll as_warn_where (fixP->fx_file, fixP->fx_line,
2518 1.1 skrll _("operand out of range"));
2519 1.1 skrll fixP->fx_done = 0;
2520 1.1 skrll val = 0;
2521 1.1 skrll }
2522 1.1 skrll mmix_set_jmp_offset (buf, val);
2523 1.1 skrll break;
2524 1.1 skrll
2525 1.1 skrll case BFD_RELOC_MMIX_REG_OR_BYTE:
2526 1.1 skrll if (fixP->fx_addsy != NULL
2527 1.1 skrll && (S_GET_SEGMENT (fixP->fx_addsy) != reg_section
2528 1.1 skrll || S_GET_VALUE (fixP->fx_addsy) > 255)
2529 1.1 skrll && S_GET_SEGMENT (fixP->fx_addsy) != absolute_section)
2530 1.1 skrll {
2531 1.1 skrll as_bad_where (fixP->fx_file, fixP->fx_line,
2532 1.1 skrll _("invalid operands"));
2533 1.1 skrll /* We don't want this "symbol" appearing in output, because
2534 1.1 skrll that will fail. */
2535 1.1 skrll fixP->fx_done = 1;
2536 1.1 skrll }
2537 1.1 skrll
2538 1.1 skrll buf[0] = val;
2539 1.1 skrll
2540 1.1 skrll /* If this reloc is for a Z field, we need to adjust
2541 1.1 skrll the opcode if we got a constant here.
2542 1.1 skrll FIXME: Can we make this more robust? */
2543 1.1 skrll
2544 1.1 skrll if ((fixP->fx_where & 3) == 3
2545 1.1 skrll && (fixP->fx_addsy == NULL
2546 1.1 skrll || S_GET_SEGMENT (fixP->fx_addsy) == absolute_section))
2547 1.1 skrll buf[-3] |= IMM_OFFSET_BIT;
2548 1.1 skrll break;
2549 1.1 skrll
2550 1.1 skrll case BFD_RELOC_MMIX_REG:
2551 1.1 skrll if (fixP->fx_addsy == NULL
2552 1.1 skrll || S_GET_SEGMENT (fixP->fx_addsy) != reg_section
2553 1.1 skrll || S_GET_VALUE (fixP->fx_addsy) > 255)
2554 1.1 skrll {
2555 1.1 skrll as_bad_where (fixP->fx_file, fixP->fx_line,
2556 1.1 skrll _("invalid operands"));
2557 1.1 skrll fixP->fx_done = 1;
2558 1.1 skrll }
2559 1.1 skrll
2560 1.1 skrll *buf = val;
2561 1.1 skrll break;
2562 1.1 skrll
2563 1.1 skrll case BFD_RELOC_MMIX_BASE_PLUS_OFFSET:
2564 1.1 skrll /* These are never "fixed". */
2565 1.1 skrll fixP->fx_done = 0;
2566 1.1 skrll return;
2567 1.1 skrll
2568 1.1 skrll case BFD_RELOC_MMIX_PUSHJ_1:
2569 1.1 skrll case BFD_RELOC_MMIX_PUSHJ_2:
2570 1.1 skrll case BFD_RELOC_MMIX_PUSHJ_3:
2571 1.1 skrll case BFD_RELOC_MMIX_CBRANCH_J:
2572 1.1 skrll case BFD_RELOC_MMIX_CBRANCH_1:
2573 1.1 skrll case BFD_RELOC_MMIX_CBRANCH_2:
2574 1.1 skrll case BFD_RELOC_MMIX_CBRANCH_3:
2575 1.1 skrll case BFD_RELOC_MMIX_GETA_1:
2576 1.1 skrll case BFD_RELOC_MMIX_GETA_2:
2577 1.1 skrll case BFD_RELOC_MMIX_GETA_3:
2578 1.1 skrll case BFD_RELOC_MMIX_JMP_1:
2579 1.1 skrll case BFD_RELOC_MMIX_JMP_2:
2580 1.1 skrll case BFD_RELOC_MMIX_JMP_3:
2581 1.1 skrll default:
2582 1.1 skrll BAD_CASE (fixP->fx_r_type);
2583 1.1 skrll break;
2584 1.1 skrll }
2585 1.1 skrll
2586 1.1 skrll if (fixP->fx_done)
2587 1.1 skrll /* Make sure that for completed fixups we have the value around for
2588 1.1 skrll use by e.g. mmix_frob_file. */
2589 1.1 skrll fixP->fx_offset = val;
2590 1.1 skrll }
2591 1.1 skrll
2592 1.1 skrll /* A bsearch function for looking up a value against offsets for GREG
2593 1.1 skrll definitions. */
2594 1.1 skrll
2595 1.1 skrll static int
2596 1.1 skrll cmp_greg_val_greg_symbol_fixes (const void *p1, const void *p2)
2597 1.1 skrll {
2598 1.1 skrll offsetT val1 = *(offsetT *) p1;
2599 1.1 skrll offsetT val2 = ((struct mmix_symbol_greg_fixes *) p2)->offs;
2600 1.1 skrll
2601 1.1 skrll if (val1 >= val2 && val1 < val2 + 255)
2602 1.1 skrll return 0;
2603 1.1 skrll
2604 1.1 skrll if (val1 > val2)
2605 1.1 skrll return 1;
2606 1.1 skrll
2607 1.1 skrll return -1;
2608 1.1 skrll }
2609 1.1 skrll
2610 1.1 skrll /* Generate a machine-dependent relocation. */
2611 1.1 skrll
2612 1.1 skrll arelent *
2613 1.1 skrll tc_gen_reloc (asection *section ATTRIBUTE_UNUSED, fixS *fixP)
2614 1.1 skrll {
2615 1.1 skrll bfd_signed_vma val
2616 1.1 skrll = fixP->fx_offset
2617 1.1 skrll + (fixP->fx_addsy != NULL
2618 1.1 skrll && !S_IS_WEAK (fixP->fx_addsy)
2619 1.1 skrll && !S_IS_COMMON (fixP->fx_addsy)
2620 1.1 skrll ? S_GET_VALUE (fixP->fx_addsy) : 0);
2621 1.1 skrll arelent *relP;
2622 1.1 skrll bfd_reloc_code_real_type code = BFD_RELOC_NONE;
2623 1.1 skrll char *buf = fixP->fx_where + fixP->fx_frag->fr_literal;
2624 1.1 skrll symbolS *addsy = fixP->fx_addsy;
2625 1.1 skrll asection *addsec = addsy == NULL ? NULL : S_GET_SEGMENT (addsy);
2626 1.1 skrll asymbol *baddsy = addsy != NULL ? symbol_get_bfdsym (addsy) : NULL;
2627 1.1 skrll bfd_vma addend
2628 1.1 skrll = val - (baddsy == NULL || S_IS_COMMON (addsy) || S_IS_WEAK (addsy)
2629 1.1 skrll ? 0 : bfd_asymbol_value (baddsy));
2630 1.1 skrll
2631 1.1 skrll /* A single " LOCAL expression" in the wrong section will not work when
2632 1.1 skrll linking to MMO; relocations for zero-content sections are then
2633 1.1 skrll ignored. Normally, relocations would modify section contents, and
2634 1.1 skrll you'd never think or be able to do something like that. The
2635 1.1 skrll relocation resulting from a LOCAL directive doesn't have an obvious
2636 1.1 skrll and mandatory location. I can't figure out a way to do this better
2637 1.1 skrll than just helping the user around this limitation here; hopefully the
2638 1.1 skrll code using the local expression is around. Putting the LOCAL
2639 1.1 skrll semantics in a relocation still seems right; a section didn't do. */
2640 1.1.1.7 christos if (bfd_section_size (section) == 0)
2641 1.1 skrll as_bad_where
2642 1.1 skrll (fixP->fx_file, fixP->fx_line,
2643 1.1 skrll fixP->fx_r_type == BFD_RELOC_MMIX_LOCAL
2644 1.1 skrll /* The BFD_RELOC_MMIX_LOCAL-specific message is supposed to be
2645 1.1 skrll user-friendly, though a little bit non-substantial. */
2646 1.1 skrll ? _("directive LOCAL must be placed in code or data")
2647 1.1 skrll : _("internal confusion: relocation in a section without contents"));
2648 1.1 skrll
2649 1.1 skrll /* FIXME: Range tests for all these. */
2650 1.1 skrll switch (fixP->fx_r_type)
2651 1.1 skrll {
2652 1.1 skrll case BFD_RELOC_64:
2653 1.1 skrll case BFD_RELOC_32:
2654 1.1 skrll case BFD_RELOC_24:
2655 1.1 skrll case BFD_RELOC_16:
2656 1.1 skrll case BFD_RELOC_8:
2657 1.1 skrll code = fixP->fx_r_type;
2658 1.1 skrll
2659 1.1 skrll if (addsy == NULL || bfd_is_abs_section (addsec))
2660 1.1 skrll {
2661 1.1 skrll /* Resolve this reloc now, as md_apply_fix would have done (not
2662 1.1 skrll called if -linkrelax). There is no point in keeping a reloc
2663 1.1 skrll to an absolute symbol. No reloc that is subject to
2664 1.1 skrll relaxation must be to an absolute symbol; difference
2665 1.1 skrll involving symbols in a specific section must be signalled as
2666 1.1 skrll an error if the relaxing cannot be expressed; having a reloc
2667 1.1 skrll to the resolved (now absolute) value does not help. */
2668 1.1 skrll md_number_to_chars (buf, val, fixP->fx_size);
2669 1.1 skrll return NULL;
2670 1.1 skrll }
2671 1.1 skrll break;
2672 1.1 skrll
2673 1.1 skrll case BFD_RELOC_64_PCREL:
2674 1.1 skrll case BFD_RELOC_32_PCREL:
2675 1.1 skrll case BFD_RELOC_24_PCREL:
2676 1.1 skrll case BFD_RELOC_16_PCREL:
2677 1.1 skrll case BFD_RELOC_8_PCREL:
2678 1.1 skrll case BFD_RELOC_MMIX_LOCAL:
2679 1.1 skrll case BFD_RELOC_VTABLE_INHERIT:
2680 1.1 skrll case BFD_RELOC_VTABLE_ENTRY:
2681 1.1 skrll case BFD_RELOC_MMIX_GETA:
2682 1.1 skrll case BFD_RELOC_MMIX_GETA_1:
2683 1.1 skrll case BFD_RELOC_MMIX_GETA_2:
2684 1.1 skrll case BFD_RELOC_MMIX_GETA_3:
2685 1.1 skrll case BFD_RELOC_MMIX_CBRANCH:
2686 1.1 skrll case BFD_RELOC_MMIX_CBRANCH_J:
2687 1.1 skrll case BFD_RELOC_MMIX_CBRANCH_1:
2688 1.1 skrll case BFD_RELOC_MMIX_CBRANCH_2:
2689 1.1 skrll case BFD_RELOC_MMIX_CBRANCH_3:
2690 1.1 skrll case BFD_RELOC_MMIX_PUSHJ:
2691 1.1 skrll case BFD_RELOC_MMIX_PUSHJ_1:
2692 1.1 skrll case BFD_RELOC_MMIX_PUSHJ_2:
2693 1.1 skrll case BFD_RELOC_MMIX_PUSHJ_3:
2694 1.1 skrll case BFD_RELOC_MMIX_PUSHJ_STUBBABLE:
2695 1.1 skrll case BFD_RELOC_MMIX_JMP:
2696 1.1 skrll case BFD_RELOC_MMIX_JMP_1:
2697 1.1 skrll case BFD_RELOC_MMIX_JMP_2:
2698 1.1 skrll case BFD_RELOC_MMIX_JMP_3:
2699 1.1 skrll case BFD_RELOC_MMIX_ADDR19:
2700 1.1 skrll case BFD_RELOC_MMIX_ADDR27:
2701 1.1 skrll code = fixP->fx_r_type;
2702 1.1 skrll break;
2703 1.1 skrll
2704 1.1 skrll case BFD_RELOC_MMIX_REG_OR_BYTE:
2705 1.1 skrll /* If we have this kind of relocation to an unknown symbol or to the
2706 1.1 skrll register contents section (that is, to a register), then we can't
2707 1.1 skrll resolve the relocation here. */
2708 1.1 skrll if (addsy != NULL
2709 1.1 skrll && (bfd_is_und_section (addsec)
2710 1.1.1.7 christos || strcmp (bfd_section_name (addsec),
2711 1.1 skrll MMIX_REG_CONTENTS_SECTION_NAME) == 0))
2712 1.1 skrll {
2713 1.1 skrll code = fixP->fx_r_type;
2714 1.1 skrll break;
2715 1.1 skrll }
2716 1.1 skrll
2717 1.1 skrll /* If the relocation is not to the register section or to the
2718 1.1 skrll absolute section (a numeric value), then we have an error. */
2719 1.1 skrll if (addsy != NULL
2720 1.1 skrll && (S_GET_SEGMENT (addsy) != real_reg_section
2721 1.1 skrll || val > 255
2722 1.1 skrll || val < 0)
2723 1.1 skrll && ! bfd_is_abs_section (addsec))
2724 1.1 skrll goto badop;
2725 1.1 skrll
2726 1.1 skrll /* Set the "immediate" bit of the insn if this relocation is to Z
2727 1.1 skrll field when the value is a numeric value, i.e. not a register. */
2728 1.1 skrll if ((fixP->fx_where & 3) == 3
2729 1.1 skrll && (addsy == NULL || bfd_is_abs_section (addsec)))
2730 1.1 skrll buf[-3] |= IMM_OFFSET_BIT;
2731 1.1 skrll
2732 1.1 skrll buf[0] = val;
2733 1.1 skrll return NULL;
2734 1.1 skrll
2735 1.1 skrll case BFD_RELOC_MMIX_BASE_PLUS_OFFSET:
2736 1.1 skrll if (addsy != NULL
2737 1.1.1.7 christos && strcmp (bfd_section_name (addsec),
2738 1.1 skrll MMIX_REG_CONTENTS_SECTION_NAME) == 0)
2739 1.1 skrll {
2740 1.1 skrll /* This changed into a register; the relocation is for the
2741 1.1 skrll register-contents section. The constant part remains zero. */
2742 1.1 skrll code = BFD_RELOC_MMIX_REG;
2743 1.1 skrll break;
2744 1.1 skrll }
2745 1.1 skrll
2746 1.1 skrll /* If we've found out that this was indeed a register, then replace
2747 1.1 skrll with the register number. The constant part is already zero.
2748 1.1 skrll
2749 1.1 skrll If we encounter any other defined symbol, then we must find a
2750 1.1 skrll suitable register and emit a reloc. */
2751 1.1 skrll if (addsy == NULL || addsec != real_reg_section)
2752 1.1 skrll {
2753 1.1 skrll struct mmix_symbol_gregs *gregs;
2754 1.1 skrll struct mmix_symbol_greg_fixes *fix;
2755 1.1 skrll
2756 1.1 skrll if (S_IS_DEFINED (addsy)
2757 1.1 skrll && !bfd_is_com_section (addsec)
2758 1.1 skrll && !S_IS_WEAK (addsy))
2759 1.1 skrll {
2760 1.1 skrll if (! symbol_section_p (addsy) && ! bfd_is_abs_section (addsec))
2761 1.1 skrll as_fatal (_("internal: BFD_RELOC_MMIX_BASE_PLUS_OFFSET not resolved to section"));
2762 1.1 skrll
2763 1.1 skrll /* If this is an absolute symbol sufficiently near
2764 1.1 skrll lowest_data_loc, then we canonicalize on the data
2765 1.1 skrll section. Note that val is signed here; we may subtract
2766 1.1 skrll lowest_data_loc which is unsigned. Careful with those
2767 1.1 skrll comparisons. */
2768 1.1 skrll if (lowest_data_loc != (bfd_vma) -1
2769 1.1 skrll && (bfd_vma) val + 256 > lowest_data_loc
2770 1.1 skrll && bfd_is_abs_section (addsec))
2771 1.1 skrll {
2772 1.1 skrll val -= (offsetT) lowest_data_loc;
2773 1.1 skrll addsy = section_symbol (data_section);
2774 1.1 skrll }
2775 1.1 skrll /* Likewise text section. */
2776 1.1 skrll else if (lowest_text_loc != (bfd_vma) -1
2777 1.1 skrll && (bfd_vma) val + 256 > lowest_text_loc
2778 1.1 skrll && bfd_is_abs_section (addsec))
2779 1.1 skrll {
2780 1.1 skrll val -= (offsetT) lowest_text_loc;
2781 1.1 skrll addsy = section_symbol (text_section);
2782 1.1 skrll }
2783 1.1 skrll }
2784 1.1 skrll
2785 1.1 skrll gregs = *symbol_get_tc (addsy);
2786 1.1 skrll
2787 1.1 skrll /* If that symbol does not have any associated GREG definitions,
2788 1.1 skrll we can't do anything. */
2789 1.1 skrll if (gregs == NULL
2790 1.1 skrll || (fix = bsearch (&val, gregs->greg_fixes, gregs->n_gregs,
2791 1.1 skrll sizeof (gregs->greg_fixes[0]),
2792 1.1 skrll cmp_greg_val_greg_symbol_fixes)) == NULL
2793 1.1 skrll /* The register must not point *after* the address we want. */
2794 1.1 skrll || fix->offs > val
2795 1.1 skrll /* Neither must the register point more than 255 bytes
2796 1.1 skrll before the address we want. */
2797 1.1 skrll || fix->offs + 255 < val)
2798 1.1 skrll {
2799 1.1 skrll /* We can either let the linker allocate GREGs
2800 1.1 skrll automatically, or emit an error. */
2801 1.1 skrll if (allocate_undefined_gregs_in_linker)
2802 1.1 skrll {
2803 1.1 skrll /* The values in baddsy and addend are right. */
2804 1.1 skrll code = fixP->fx_r_type;
2805 1.1 skrll break;
2806 1.1 skrll }
2807 1.1 skrll else
2808 1.1 skrll as_bad_where (fixP->fx_file, fixP->fx_line,
2809 1.1 skrll _("no suitable GREG definition for operands"));
2810 1.1 skrll return NULL;
2811 1.1 skrll }
2812 1.1 skrll else
2813 1.1 skrll {
2814 1.1 skrll /* Transform the base-plus-offset reloc for the actual area
2815 1.1 skrll to a reloc for the register with the address of the area.
2816 1.1 skrll Put addend for register in Z operand. */
2817 1.1 skrll buf[1] = val - fix->offs;
2818 1.1 skrll code = BFD_RELOC_MMIX_REG;
2819 1.1 skrll baddsy
2820 1.1 skrll = (bfd_get_section_by_name (stdoutput,
2821 1.1 skrll MMIX_REG_CONTENTS_SECTION_NAME)
2822 1.1 skrll ->symbol);
2823 1.1 skrll
2824 1.1 skrll addend = fix->fix->fx_frag->fr_address + fix->fix->fx_where;
2825 1.1 skrll }
2826 1.1 skrll }
2827 1.1 skrll else if (S_GET_VALUE (addsy) > 255)
2828 1.1 skrll as_bad_where (fixP->fx_file, fixP->fx_line,
2829 1.1 skrll _("invalid operands"));
2830 1.1 skrll else
2831 1.1 skrll {
2832 1.1 skrll *buf = val;
2833 1.1 skrll return NULL;
2834 1.1 skrll }
2835 1.1 skrll break;
2836 1.1 skrll
2837 1.1 skrll case BFD_RELOC_MMIX_REG:
2838 1.1 skrll if (addsy != NULL
2839 1.1 skrll && (bfd_is_und_section (addsec)
2840 1.1.1.7 christos || strcmp (bfd_section_name (addsec),
2841 1.1 skrll MMIX_REG_CONTENTS_SECTION_NAME) == 0))
2842 1.1 skrll {
2843 1.1 skrll code = fixP->fx_r_type;
2844 1.1 skrll break;
2845 1.1 skrll }
2846 1.1 skrll
2847 1.1 skrll if (addsy != NULL
2848 1.1 skrll && (addsec != real_reg_section
2849 1.1 skrll || val > 255
2850 1.1 skrll || val < 0)
2851 1.1 skrll && ! bfd_is_und_section (addsec))
2852 1.1 skrll /* Drop through to error message. */
2853 1.1 skrll ;
2854 1.1 skrll else
2855 1.1 skrll {
2856 1.1 skrll buf[0] = val;
2857 1.1 skrll return NULL;
2858 1.1 skrll }
2859 1.1 skrll /* FALLTHROUGH. */
2860 1.1 skrll
2861 1.1 skrll /* The others are supposed to be handled by md_apply_fix.
2862 1.1 skrll FIXME: ... which isn't called when -linkrelax. Move over
2863 1.1 skrll md_apply_fix code here for everything reasonable. */
2864 1.1 skrll badop:
2865 1.1 skrll default:
2866 1.1 skrll as_bad_where
2867 1.1 skrll (fixP->fx_file, fixP->fx_line,
2868 1.1 skrll _("operands were not reducible at assembly-time"));
2869 1.1 skrll
2870 1.1 skrll /* Unmark this symbol as used in a reloc, so we don't bump into a BFD
2871 1.1 skrll assert when trying to output reg_section. FIXME: A gas bug. */
2872 1.1 skrll fixP->fx_addsy = NULL;
2873 1.1 skrll return NULL;
2874 1.1 skrll }
2875 1.1 skrll
2876 1.1.1.5 christos relP = XNEW (arelent);
2877 1.1.1.2 christos gas_assert (relP != 0);
2878 1.1.1.5 christos relP->sym_ptr_ptr = XNEW (asymbol *);
2879 1.1 skrll *relP->sym_ptr_ptr = baddsy;
2880 1.1 skrll relP->address = fixP->fx_frag->fr_address + fixP->fx_where;
2881 1.1 skrll
2882 1.1 skrll relP->addend = addend;
2883 1.1 skrll
2884 1.1 skrll /* If this had been a.out, we would have had a kludge for weak symbols
2885 1.1 skrll here. */
2886 1.1 skrll
2887 1.1 skrll relP->howto = bfd_reloc_type_lookup (stdoutput, code);
2888 1.1 skrll if (! relP->howto)
2889 1.1 skrll {
2890 1.1 skrll const char *name;
2891 1.1 skrll
2892 1.1 skrll name = S_GET_NAME (addsy);
2893 1.1 skrll if (name == NULL)
2894 1.1 skrll name = _("<unknown>");
2895 1.1 skrll as_fatal (_("cannot generate relocation type for symbol %s, code %s"),
2896 1.1 skrll name, bfd_get_reloc_code_name (code));
2897 1.1 skrll }
2898 1.1 skrll
2899 1.1 skrll return relP;
2900 1.1 skrll }
2901 1.1 skrll
2902 1.1 skrll /* Do some reformatting of a line. FIXME: We could transform a mmixal
2903 1.1 skrll line into traditional (GNU?) format, unless #NO_APP, and get rid of all
2904 1.1 skrll ugly labels_without_colons etc. */
2905 1.1 skrll
2906 1.1 skrll void
2907 1.1 skrll mmix_handle_mmixal (void)
2908 1.1 skrll {
2909 1.1 skrll char *insn;
2910 1.1 skrll char *s = input_line_pointer;
2911 1.1 skrll char *label = NULL;
2912 1.1 skrll char c;
2913 1.1 skrll
2914 1.1 skrll if (pending_label != NULL)
2915 1.1 skrll as_fatal (_("internal: unhandled label %s"), pending_label);
2916 1.1 skrll
2917 1.1 skrll if (mmix_gnu_syntax)
2918 1.1 skrll return;
2919 1.1 skrll
2920 1.1 skrll /* If we're on a line with a label, check if it's a mmixal fb-label.
2921 1.1 skrll Save an indicator and skip the label; it must be set only after all
2922 1.1 skrll fb-labels of expressions are evaluated. */
2923 1.1 skrll if (ISDIGIT (s[0]) && s[1] == 'H' && ISSPACE (s[2]))
2924 1.1 skrll {
2925 1.1 skrll current_fb_label = s[0] - '0';
2926 1.1 skrll
2927 1.1 skrll /* We have to skip the label, but also preserve the newlineness of
2928 1.1 skrll the previous character, since the caller checks that. It's a
2929 1.1 skrll mess we blame on the caller. */
2930 1.1 skrll s[1] = s[-1];
2931 1.1 skrll s += 2;
2932 1.1 skrll input_line_pointer = s;
2933 1.1 skrll
2934 1.1 skrll while (*s && ISSPACE (*s) && ! is_end_of_line[(unsigned int) *s])
2935 1.1 skrll s++;
2936 1.1 skrll
2937 1.1 skrll /* For errors emitted here, the book-keeping is off by one; the
2938 1.1 skrll caller is about to bump the counters. Adjust the error messages. */
2939 1.1 skrll if (is_end_of_line[(unsigned int) *s])
2940 1.1 skrll {
2941 1.1 skrll unsigned int line;
2942 1.1.1.5 christos const char * name = as_where (&line);
2943 1.1 skrll as_bad_where (name, line + 1,
2944 1.1 skrll _("[0-9]H labels may not appear alone on a line"));
2945 1.1 skrll current_fb_label = -1;
2946 1.1 skrll }
2947 1.1 skrll if (*s == '.')
2948 1.1 skrll {
2949 1.1 skrll unsigned int line;
2950 1.1.1.5 christos const char * name = as_where (&line);
2951 1.1 skrll as_bad_where (name, line + 1,
2952 1.1 skrll _("[0-9]H labels do not mix with dot-pseudos"));
2953 1.1 skrll current_fb_label = -1;
2954 1.1 skrll }
2955 1.1 skrll
2956 1.1 skrll /* Back off to the last space before the opcode so we don't handle
2957 1.1 skrll the opcode as a label. */
2958 1.1 skrll s--;
2959 1.1 skrll }
2960 1.1 skrll else
2961 1.1 skrll current_fb_label = -1;
2962 1.1 skrll
2963 1.1 skrll if (*s == '.')
2964 1.1 skrll {
2965 1.1 skrll /* If the first character is a '.', then it's a pseudodirective, not a
2966 1.1 skrll label. Make GAS not handle label-without-colon on this line. We
2967 1.1 skrll also don't do mmixal-specific stuff on this line. */
2968 1.1 skrll label_without_colon_this_line = 0;
2969 1.1 skrll return;
2970 1.1 skrll }
2971 1.1 skrll
2972 1.1 skrll if (*s == 0 || is_end_of_line[(unsigned int) *s])
2973 1.1 skrll /* We avoid handling empty lines here. */
2974 1.1 skrll return;
2975 1.1.1.4 christos
2976 1.1 skrll if (is_name_beginner (*s))
2977 1.1 skrll label = s;
2978 1.1 skrll
2979 1.1 skrll /* If there is a label, skip over it. */
2980 1.1 skrll while (*s && is_part_of_name (*s))
2981 1.1 skrll s++;
2982 1.1 skrll
2983 1.1 skrll /* Find the start of the instruction or pseudo following the label,
2984 1.1 skrll if there is one. */
2985 1.1 skrll for (insn = s;
2986 1.1 skrll *insn && ISSPACE (*insn) && ! is_end_of_line[(unsigned int) *insn];
2987 1.1 skrll insn++)
2988 1.1 skrll /* Empty */
2989 1.1 skrll ;
2990 1.1 skrll
2991 1.1 skrll /* Remove a trailing ":" off labels, as they'd otherwise be considered
2992 1.1 skrll part of the name. But don't do this for local labels. */
2993 1.1 skrll if (s != input_line_pointer && s[-1] == ':'
2994 1.1 skrll && (s - 2 != input_line_pointer
2995 1.1 skrll || ! ISDIGIT (s[-2])))
2996 1.1 skrll s[-1] = ' ';
2997 1.1 skrll else if (label != NULL
2998 1.1 skrll /* For a lone label on a line, we don't attach it to the next
2999 1.1 skrll instruction or MMIXAL-pseudo (getting its alignment). Thus
3000 1.1 skrll is acts like a "normal" :-ended label. Ditto if it's
3001 1.1 skrll followed by a non-MMIXAL pseudo. */
3002 1.1 skrll && !is_end_of_line[(unsigned int) *insn]
3003 1.1 skrll && *insn != '.')
3004 1.1 skrll {
3005 1.1 skrll /* For labels that don't end in ":", we save it so we can later give
3006 1.1 skrll it the same alignment and address as the associated instruction. */
3007 1.1 skrll
3008 1.1 skrll /* Make room for the label including the ending nul. */
3009 1.1.1.4 christos size_t len_0 = s - label + 1;
3010 1.1 skrll
3011 1.1 skrll /* Save this label on the MMIX symbol obstack. Saving it on an
3012 1.1 skrll obstack is needless for "IS"-pseudos, but it's harmless and we
3013 1.1 skrll avoid a little code-cluttering. */
3014 1.1 skrll obstack_grow (&mmix_sym_obstack, label, len_0);
3015 1.1 skrll pending_label = obstack_finish (&mmix_sym_obstack);
3016 1.1 skrll pending_label[len_0 - 1] = 0;
3017 1.1 skrll }
3018 1.1 skrll
3019 1.1 skrll /* If we have a non-MMIXAL pseudo, we have not business with the rest of
3020 1.1 skrll the line. */
3021 1.1 skrll if (*insn == '.')
3022 1.1 skrll return;
3023 1.1 skrll
3024 1.1 skrll /* Find local labels of operands. Look for "[0-9][FB]" where the
3025 1.1 skrll characters before and after are not part of words. Break if a single
3026 1.1 skrll or double quote is seen anywhere. It means we can't have local
3027 1.1 skrll labels as part of list with mixed quoted and unquoted members for
3028 1.1 skrll mmixal compatibility but we can't have it all. For the moment.
3029 1.1 skrll Replace the '<N>B' or '<N>F' with MAGIC_FB_BACKWARD_CHAR<N> and
3030 1.1 skrll MAGIC_FB_FORWARD_CHAR<N> respectively. */
3031 1.1 skrll
3032 1.1 skrll /* First make sure we don't have any of the magic characters on the line
3033 1.1 skrll appearing as input. */
3034 1.1 skrll while (*s)
3035 1.1 skrll {
3036 1.1 skrll c = *s++;
3037 1.1 skrll if (is_end_of_line[(unsigned int) c])
3038 1.1 skrll break;
3039 1.1 skrll if (c == MAGIC_FB_BACKWARD_CHAR || c == MAGIC_FB_FORWARD_CHAR)
3040 1.1 skrll as_bad (_("invalid characters in input"));
3041 1.1 skrll }
3042 1.1 skrll
3043 1.1 skrll /* Scan again, this time looking for ';' after operands. */
3044 1.1 skrll s = insn;
3045 1.1 skrll
3046 1.1 skrll /* Skip the insn. */
3047 1.1 skrll while (*s
3048 1.1 skrll && ! ISSPACE (*s)
3049 1.1 skrll && *s != ';'
3050 1.1 skrll && ! is_end_of_line[(unsigned int) *s])
3051 1.1 skrll s++;
3052 1.1 skrll
3053 1.1 skrll /* Skip the spaces after the insn. */
3054 1.1 skrll while (*s
3055 1.1 skrll && ISSPACE (*s)
3056 1.1 skrll && *s != ';'
3057 1.1 skrll && ! is_end_of_line[(unsigned int) *s])
3058 1.1 skrll s++;
3059 1.1 skrll
3060 1.1 skrll /* Skip the operands. While doing this, replace [0-9][BF] with
3061 1.1 skrll (MAGIC_FB_BACKWARD_CHAR|MAGIC_FB_FORWARD_CHAR)[0-9]. */
3062 1.1 skrll while ((c = *s) != 0
3063 1.1 skrll && ! ISSPACE (c)
3064 1.1 skrll && c != ';'
3065 1.1 skrll && ! is_end_of_line[(unsigned int) c])
3066 1.1 skrll {
3067 1.1 skrll if (c == '"')
3068 1.1 skrll {
3069 1.1 skrll s++;
3070 1.1 skrll
3071 1.1 skrll /* FIXME: Test-case for semi-colon in string. */
3072 1.1 skrll while (*s
3073 1.1 skrll && *s != '"'
3074 1.1 skrll && (! is_end_of_line[(unsigned int) *s] || *s == ';'))
3075 1.1 skrll s++;
3076 1.1 skrll
3077 1.1 skrll if (*s == '"')
3078 1.1 skrll s++;
3079 1.1 skrll }
3080 1.1 skrll else if (ISDIGIT (c))
3081 1.1 skrll {
3082 1.1 skrll if ((s[1] != 'B' && s[1] != 'F')
3083 1.1 skrll || is_part_of_name (s[-1])
3084 1.1 skrll || is_part_of_name (s[2])
3085 1.1 skrll /* Don't treat e.g. #1F as a local-label reference. */
3086 1.1 skrll || (s != input_line_pointer && s[-1] == '#'))
3087 1.1 skrll s++;
3088 1.1 skrll else
3089 1.1 skrll {
3090 1.1 skrll s[0] = (s[1] == 'B'
3091 1.1 skrll ? MAGIC_FB_BACKWARD_CHAR : MAGIC_FB_FORWARD_CHAR);
3092 1.1 skrll s[1] = c;
3093 1.1 skrll }
3094 1.1 skrll }
3095 1.1 skrll else
3096 1.1 skrll s++;
3097 1.1 skrll }
3098 1.1 skrll
3099 1.1 skrll /* Skip any spaces after the operands. */
3100 1.1 skrll while (*s
3101 1.1 skrll && ISSPACE (*s)
3102 1.1 skrll && *s != ';'
3103 1.1 skrll && !is_end_of_line[(unsigned int) *s])
3104 1.1 skrll s++;
3105 1.1 skrll
3106 1.1 skrll /* If we're now looking at a semi-colon, then it's an end-of-line
3107 1.1 skrll delimiter. */
3108 1.1 skrll mmix_next_semicolon_is_eoln = (*s == ';');
3109 1.1 skrll
3110 1.1 skrll /* Make IS into an EQU by replacing it with "= ". Only match upper-case
3111 1.1 skrll though; let lower-case be a syntax error. */
3112 1.1 skrll s = insn;
3113 1.1 skrll if (s[0] == 'I' && s[1] == 'S' && ISSPACE (s[2]))
3114 1.1 skrll {
3115 1.1 skrll *s = '=';
3116 1.1 skrll s[1] = ' ';
3117 1.1 skrll
3118 1.1 skrll /* Since labels can start without ":", we have to handle "X IS 42"
3119 1.1 skrll in full here, or "X" will be parsed as a label to be set at ".". */
3120 1.1 skrll input_line_pointer = s;
3121 1.1 skrll
3122 1.1 skrll /* Right after this function ends, line numbers will be bumped if
3123 1.1 skrll input_line_pointer[-1] = '\n'. We want accurate line numbers for
3124 1.1 skrll the equals call, so we bump them before the call, and make sure
3125 1.1 skrll they aren't bumped afterwards. */
3126 1.1 skrll bump_line_counters ();
3127 1.1 skrll
3128 1.1 skrll /* A fb-label is valid as an IS-label. */
3129 1.1 skrll if (current_fb_label >= 0)
3130 1.1 skrll {
3131 1.1 skrll char *fb_name;
3132 1.1 skrll
3133 1.1 skrll /* We need to save this name on our symbol obstack, since the
3134 1.1 skrll string we got in fb_label_name is volatile and will change
3135 1.1 skrll with every call to fb_label_name, like those resulting from
3136 1.1 skrll parsing the IS-operand. */
3137 1.1 skrll fb_name = fb_label_name (current_fb_label, 1);
3138 1.1 skrll obstack_grow (&mmix_sym_obstack, fb_name, strlen (fb_name) + 1);
3139 1.1 skrll equals (obstack_finish (&mmix_sym_obstack), 0);
3140 1.1 skrll fb_label_instance_inc (current_fb_label);
3141 1.1 skrll current_fb_label = -1;
3142 1.1 skrll }
3143 1.1 skrll else
3144 1.1 skrll {
3145 1.1 skrll if (pending_label == NULL)
3146 1.1 skrll as_bad (_("empty label field for IS"));
3147 1.1 skrll else
3148 1.1 skrll equals (pending_label, 0);
3149 1.1 skrll pending_label = NULL;
3150 1.1 skrll }
3151 1.1 skrll
3152 1.1 skrll /* For mmixal, we can have comments without a comment-start
3153 1.1 skrll character. */
3154 1.1 skrll mmix_handle_rest_of_empty_line ();
3155 1.1 skrll input_line_pointer--;
3156 1.1 skrll
3157 1.1 skrll input_line_pointer[-1] = ' ';
3158 1.1 skrll }
3159 1.1 skrll else if (s[0] == 'G'
3160 1.1 skrll && s[1] == 'R'
3161 1.1 skrll && strncmp (s, "GREG", 4) == 0
3162 1.1 skrll && (ISSPACE (s[4]) || is_end_of_line[(unsigned char) s[4]]))
3163 1.1 skrll {
3164 1.1 skrll input_line_pointer = s + 4;
3165 1.1 skrll
3166 1.1 skrll /* Right after this function ends, line numbers will be bumped if
3167 1.1 skrll input_line_pointer[-1] = '\n'. We want accurate line numbers for
3168 1.1 skrll the s_greg call, so we bump them before the call, and make sure
3169 1.1 skrll they aren't bumped afterwards. */
3170 1.1 skrll bump_line_counters ();
3171 1.1 skrll
3172 1.1 skrll /* A fb-label is valid as a GREG-label. */
3173 1.1 skrll if (current_fb_label >= 0)
3174 1.1 skrll {
3175 1.1 skrll char *fb_name;
3176 1.1 skrll
3177 1.1 skrll /* We need to save this name on our symbol obstack, since the
3178 1.1 skrll string we got in fb_label_name is volatile and will change
3179 1.1 skrll with every call to fb_label_name, like those resulting from
3180 1.1 skrll parsing the IS-operand. */
3181 1.1 skrll fb_name = fb_label_name (current_fb_label, 1);
3182 1.1 skrll
3183 1.1 skrll /* Make sure we save the canonical name and don't get bitten by
3184 1.1 skrll prefixes. */
3185 1.1 skrll obstack_1grow (&mmix_sym_obstack, ':');
3186 1.1 skrll obstack_grow (&mmix_sym_obstack, fb_name, strlen (fb_name) + 1);
3187 1.1 skrll mmix_greg_internal (obstack_finish (&mmix_sym_obstack));
3188 1.1 skrll fb_label_instance_inc (current_fb_label);
3189 1.1 skrll current_fb_label = -1;
3190 1.1 skrll }
3191 1.1 skrll else
3192 1.1 skrll mmix_greg_internal (pending_label);
3193 1.1 skrll
3194 1.1 skrll /* Back up before the end-of-line marker that was skipped in
3195 1.1 skrll mmix_greg_internal. */
3196 1.1 skrll input_line_pointer--;
3197 1.1 skrll input_line_pointer[-1] = ' ';
3198 1.1 skrll
3199 1.1 skrll pending_label = NULL;
3200 1.1 skrll }
3201 1.1 skrll else if (pending_label != NULL)
3202 1.1 skrll {
3203 1.1 skrll input_line_pointer += strlen (pending_label);
3204 1.1 skrll
3205 1.1 skrll /* See comment above about getting line numbers bumped. */
3206 1.1 skrll input_line_pointer[-1] = '\n';
3207 1.1 skrll }
3208 1.1 skrll }
3209 1.1 skrll
3210 1.1 skrll /* Give the value of an fb-label rewritten as in mmix_handle_mmixal, when
3211 1.1 skrll parsing an expression.
3212 1.1 skrll
3213 1.1 skrll On valid calls, input_line_pointer points at a MAGIC_FB_BACKWARD_CHAR
3214 1.1 skrll or MAGIC_FB_BACKWARD_CHAR, followed by an ascii digit for the label.
3215 1.1 skrll We fill in the label as an expression. */
3216 1.1 skrll
3217 1.1 skrll void
3218 1.1 skrll mmix_fb_label (expressionS *expP)
3219 1.1 skrll {
3220 1.1 skrll symbolS *sym;
3221 1.1 skrll char *fb_internal_name;
3222 1.1 skrll
3223 1.1 skrll /* This doesn't happen when not using mmixal syntax. */
3224 1.1 skrll if (mmix_gnu_syntax
3225 1.1 skrll || (input_line_pointer[0] != MAGIC_FB_BACKWARD_CHAR
3226 1.1 skrll && input_line_pointer[0] != MAGIC_FB_FORWARD_CHAR))
3227 1.1 skrll return;
3228 1.1 skrll
3229 1.1 skrll /* The current backward reference has augmentation 0. A forward
3230 1.1 skrll reference has augmentation 1, unless it's the same as a fb-label on
3231 1.1 skrll _this_ line, in which case we add one more so we don't refer to it.
3232 1.1 skrll This is the semantics of mmixal; it differs to that of common
3233 1.1 skrll fb-labels which refer to a here-label on the current line as a
3234 1.1 skrll backward reference. */
3235 1.1 skrll fb_internal_name
3236 1.1 skrll = fb_label_name (input_line_pointer[1] - '0',
3237 1.1 skrll (input_line_pointer[0] == MAGIC_FB_FORWARD_CHAR ? 1 : 0)
3238 1.1 skrll + ((input_line_pointer[1] - '0' == current_fb_label
3239 1.1 skrll && input_line_pointer[0] == MAGIC_FB_FORWARD_CHAR)
3240 1.1 skrll ? 1 : 0));
3241 1.1 skrll
3242 1.1 skrll input_line_pointer += 2;
3243 1.1 skrll sym = symbol_find_or_make (fb_internal_name);
3244 1.1 skrll
3245 1.1 skrll /* We don't have to clean up unrelated fields here; we just do what the
3246 1.1 skrll expr machinery does, but *not* just what it does for [0-9][fb], since
3247 1.1 skrll we need to treat those as ordinary symbols sometimes; see testcases
3248 1.1 skrll err-byte2.s and fb-2.s. */
3249 1.1 skrll if (S_GET_SEGMENT (sym) == absolute_section)
3250 1.1 skrll {
3251 1.1 skrll expP->X_op = O_constant;
3252 1.1 skrll expP->X_add_number = S_GET_VALUE (sym);
3253 1.1 skrll }
3254 1.1 skrll else
3255 1.1 skrll {
3256 1.1 skrll expP->X_op = O_symbol;
3257 1.1 skrll expP->X_add_symbol = sym;
3258 1.1 skrll expP->X_add_number = 0;
3259 1.1 skrll }
3260 1.1 skrll }
3261 1.1 skrll
3262 1.1 skrll /* See whether we need to force a relocation into the output file.
3263 1.1 skrll This is used to force out switch and PC relative relocations when
3264 1.1 skrll relaxing. */
3265 1.1 skrll
3266 1.1 skrll int
3267 1.1 skrll mmix_force_relocation (fixS *fixP)
3268 1.1 skrll {
3269 1.1 skrll if (fixP->fx_r_type == BFD_RELOC_MMIX_LOCAL
3270 1.1 skrll || fixP->fx_r_type == BFD_RELOC_MMIX_BASE_PLUS_OFFSET)
3271 1.1 skrll return 1;
3272 1.1 skrll
3273 1.1 skrll if (linkrelax)
3274 1.1 skrll return 1;
3275 1.1 skrll
3276 1.1 skrll /* All our pcrel relocations are must-keep. Note that md_apply_fix is
3277 1.1 skrll called *after* this, and will handle getting rid of the presumed
3278 1.1 skrll reloc; a relocation isn't *forced* other than to be handled by
3279 1.1 skrll md_apply_fix (or tc_gen_reloc if linkrelax). */
3280 1.1 skrll if (fixP->fx_pcrel)
3281 1.1 skrll return 1;
3282 1.1 skrll
3283 1.1 skrll return generic_force_reloc (fixP);
3284 1.1 skrll }
3285 1.1 skrll
3286 1.1 skrll /* The location from which a PC relative jump should be calculated,
3287 1.1 skrll given a PC relative reloc. */
3288 1.1 skrll
3289 1.1 skrll long
3290 1.1 skrll md_pcrel_from_section (fixS *fixP, segT sec)
3291 1.1 skrll {
3292 1.1 skrll if (fixP->fx_addsy != (symbolS *) NULL
3293 1.1 skrll && (! S_IS_DEFINED (fixP->fx_addsy)
3294 1.1 skrll || S_GET_SEGMENT (fixP->fx_addsy) != sec))
3295 1.1 skrll {
3296 1.1 skrll /* The symbol is undefined (or is defined but not in this section).
3297 1.1 skrll Let the linker figure it out. */
3298 1.1 skrll return 0;
3299 1.1 skrll }
3300 1.1 skrll
3301 1.1 skrll return (fixP->fx_frag->fr_address + fixP->fx_where);
3302 1.1 skrll }
3303 1.1 skrll
3304 1.1 skrll /* Adjust the symbol table. We make reg_section relative to the real
3305 1.1 skrll register section. */
3306 1.1 skrll
3307 1.1 skrll void
3308 1.1 skrll mmix_adjust_symtab (void)
3309 1.1 skrll {
3310 1.1 skrll symbolS *sym;
3311 1.1 skrll symbolS *regsec = section_symbol (reg_section);
3312 1.1 skrll
3313 1.1 skrll for (sym = symbol_rootP; sym != NULL; sym = symbol_next (sym))
3314 1.1 skrll if (S_GET_SEGMENT (sym) == reg_section)
3315 1.1 skrll {
3316 1.1 skrll if (sym == regsec)
3317 1.1 skrll {
3318 1.1 skrll if (S_IS_EXTERNAL (sym) || symbol_used_in_reloc_p (sym))
3319 1.1 skrll abort ();
3320 1.1 skrll symbol_remove (sym, &symbol_rootP, &symbol_lastP);
3321 1.1 skrll }
3322 1.1 skrll else
3323 1.1 skrll /* Change section to the *real* register section, so it gets
3324 1.1 skrll proper treatment when writing it out. Only do this for
3325 1.1 skrll global symbols. This also means we don't have to check for
3326 1.1 skrll $0..$255. */
3327 1.1 skrll S_SET_SEGMENT (sym, real_reg_section);
3328 1.1 skrll }
3329 1.1 skrll }
3330 1.1 skrll
3331 1.1 skrll /* This is the expansion of LABELS_WITHOUT_COLONS.
3332 1.1 skrll We let md_start_line_hook tweak label_without_colon_this_line, and then
3333 1.1 skrll this function returns the tweaked value, and sets it to 1 for the next
3334 1.1 skrll line. FIXME: Very, very brittle. Not sure it works the way I
3335 1.1 skrll thought at the time I first wrote this. */
3336 1.1 skrll
3337 1.1 skrll int
3338 1.1 skrll mmix_label_without_colon_this_line (void)
3339 1.1 skrll {
3340 1.1 skrll int retval = label_without_colon_this_line;
3341 1.1 skrll
3342 1.1 skrll if (! mmix_gnu_syntax)
3343 1.1 skrll label_without_colon_this_line = 1;
3344 1.1 skrll
3345 1.1 skrll return retval;
3346 1.1 skrll }
3347 1.1 skrll
3348 1.1 skrll /* This is the expansion of md_relax_frag. We go through the ordinary
3349 1.1 skrll relax table function except when the frag is for a GREG. Then we have
3350 1.1 skrll to check whether there's another GREG by the same value that we can
3351 1.1 skrll join with. */
3352 1.1 skrll
3353 1.1 skrll long
3354 1.1 skrll mmix_md_relax_frag (segT seg, fragS *fragP, long stretch)
3355 1.1 skrll {
3356 1.1 skrll switch (fragP->fr_subtype)
3357 1.1 skrll {
3358 1.1 skrll /* Growth for this type has been handled by mmix_md_end and
3359 1.1 skrll correctly estimated, so there's nothing more to do here. */
3360 1.1 skrll case STATE_GREG_DEF:
3361 1.1 skrll return 0;
3362 1.1 skrll
3363 1.1 skrll case ENCODE_RELAX (STATE_PUSHJ, STATE_ZERO):
3364 1.1 skrll {
3365 1.1 skrll /* We need to handle relaxation type ourselves, since relax_frag
3366 1.1 skrll doesn't update fr_subtype if there's no size increase in the
3367 1.1 skrll current section; when going from plain PUSHJ to a stub. This
3368 1.1 skrll is otherwise functionally the same as relax_frag in write.c,
3369 1.1 skrll simplified for this case. */
3370 1.1 skrll offsetT aim;
3371 1.1 skrll addressT target;
3372 1.1 skrll addressT address;
3373 1.1 skrll symbolS *symbolP;
3374 1.1 skrll target = fragP->fr_offset;
3375 1.1 skrll address = fragP->fr_address;
3376 1.1 skrll symbolP = fragP->fr_symbol;
3377 1.1 skrll
3378 1.1 skrll if (symbolP)
3379 1.1 skrll {
3380 1.1 skrll fragS *sym_frag;
3381 1.1 skrll
3382 1.1 skrll sym_frag = symbol_get_frag (symbolP);
3383 1.1 skrll know (S_GET_SEGMENT (symbolP) != absolute_section
3384 1.1 skrll || sym_frag == &zero_address_frag);
3385 1.1 skrll target += S_GET_VALUE (symbolP);
3386 1.1 skrll
3387 1.1 skrll /* If frag has yet to be reached on this pass, assume it will
3388 1.1 skrll move by STRETCH just as we did. If this is not so, it will
3389 1.1 skrll be because some frag between grows, and that will force
3390 1.1 skrll another pass. */
3391 1.1 skrll
3392 1.1 skrll if (stretch != 0
3393 1.1 skrll && sym_frag->relax_marker != fragP->relax_marker
3394 1.1 skrll && S_GET_SEGMENT (symbolP) == seg)
3395 1.1 skrll target += stretch;
3396 1.1 skrll }
3397 1.1 skrll
3398 1.1 skrll aim = target - address - fragP->fr_fix;
3399 1.1 skrll if (aim >= PUSHJ_0B && aim <= PUSHJ_0F)
3400 1.1 skrll {
3401 1.1 skrll /* Target is reachable with a PUSHJ. */
3402 1.1 skrll segment_info_type *seginfo = seg_info (seg);
3403 1.1 skrll
3404 1.1 skrll /* If we're at the end of a relaxation round, clear the stub
3405 1.1 skrll counter as initialization for the next round. */
3406 1.1 skrll if (fragP == seginfo->tc_segment_info_data.last_stubfrag)
3407 1.1 skrll seginfo->tc_segment_info_data.nstubs = 0;
3408 1.1 skrll return 0;
3409 1.1 skrll }
3410 1.1 skrll
3411 1.1 skrll /* Not reachable. Try a stub. */
3412 1.1 skrll fragP->fr_subtype = ENCODE_RELAX (STATE_PUSHJSTUB, STATE_ZERO);
3413 1.1 skrll }
3414 1.1 skrll /* FALLTHROUGH. */
3415 1.1.1.4 christos
3416 1.1 skrll /* See if this PUSHJ is redirectable to a stub. */
3417 1.1 skrll case ENCODE_RELAX (STATE_PUSHJSTUB, STATE_ZERO):
3418 1.1 skrll {
3419 1.1 skrll segment_info_type *seginfo = seg_info (seg);
3420 1.1 skrll fragS *lastfrag = seginfo->frchainP->frch_last;
3421 1.1 skrll relax_substateT prev_type = fragP->fr_subtype;
3422 1.1 skrll
3423 1.1 skrll /* The last frag is always an empty frag, so it suffices to look
3424 1.1 skrll at its address to know the ending address of this section. */
3425 1.1 skrll know (lastfrag->fr_type == rs_fill
3426 1.1 skrll && lastfrag->fr_fix == 0
3427 1.1 skrll && lastfrag->fr_var == 0);
3428 1.1 skrll
3429 1.1 skrll /* For this PUSHJ to be relaxable into a call to a stub, the
3430 1.1 skrll distance must be no longer than 256k bytes from the PUSHJ to
3431 1.1 skrll the end of the section plus the maximum size of stubs so far. */
3432 1.1 skrll if ((lastfrag->fr_address
3433 1.1 skrll + stretch
3434 1.1 skrll + PUSHJ_MAX_LEN * seginfo->tc_segment_info_data.nstubs)
3435 1.1 skrll - (fragP->fr_address + fragP->fr_fix)
3436 1.1 skrll > GETA_0F
3437 1.1 skrll || !pushj_stubs)
3438 1.1 skrll fragP->fr_subtype = mmix_relax_table[prev_type].rlx_more;
3439 1.1 skrll else
3440 1.1 skrll seginfo->tc_segment_info_data.nstubs++;
3441 1.1 skrll
3442 1.1 skrll /* If we're at the end of a relaxation round, clear the stub
3443 1.1 skrll counter as initialization for the next round. */
3444 1.1 skrll if (fragP == seginfo->tc_segment_info_data.last_stubfrag)
3445 1.1 skrll seginfo->tc_segment_info_data.nstubs = 0;
3446 1.1 skrll
3447 1.1 skrll return
3448 1.1 skrll (mmix_relax_table[fragP->fr_subtype].rlx_length
3449 1.1 skrll - mmix_relax_table[prev_type].rlx_length);
3450 1.1 skrll }
3451 1.1 skrll
3452 1.1 skrll case ENCODE_RELAX (STATE_PUSHJ, STATE_MAX):
3453 1.1 skrll {
3454 1.1 skrll segment_info_type *seginfo = seg_info (seg);
3455 1.1 skrll
3456 1.1 skrll /* Need to cover all STATE_PUSHJ states to act on the last stub
3457 1.1 skrll frag (the end of this relax round; initialization for the
3458 1.1 skrll next). */
3459 1.1 skrll if (fragP == seginfo->tc_segment_info_data.last_stubfrag)
3460 1.1 skrll seginfo->tc_segment_info_data.nstubs = 0;
3461 1.1 skrll
3462 1.1 skrll return 0;
3463 1.1 skrll }
3464 1.1 skrll
3465 1.1 skrll default:
3466 1.1 skrll return relax_frag (seg, fragP, stretch);
3467 1.1 skrll
3468 1.1 skrll case STATE_GREG_UNDF:
3469 1.1 skrll BAD_CASE (fragP->fr_subtype);
3470 1.1 skrll }
3471 1.1 skrll
3472 1.1 skrll as_fatal (_("internal: unexpected relax type %d:%d"),
3473 1.1 skrll fragP->fr_type, fragP->fr_subtype);
3474 1.1 skrll return 0;
3475 1.1 skrll }
3476 1.1 skrll
3477 1.1 skrll /* Various things we punt until all input is seen. */
3478 1.1 skrll
3479 1.1 skrll void
3480 1.1 skrll mmix_md_end (void)
3481 1.1 skrll {
3482 1.1 skrll fragS *fragP;
3483 1.1 skrll symbolS *mainsym;
3484 1.1 skrll asection *regsec;
3485 1.1.1.3 christos struct loc_assert_s *loc_assert;
3486 1.1 skrll int i;
3487 1.1 skrll
3488 1.1 skrll /* The first frag of GREG:s going into the register contents section. */
3489 1.1 skrll fragS *mmix_reg_contents_frags = NULL;
3490 1.1 skrll
3491 1.1 skrll /* Reset prefix. All labels reachable at this point must be
3492 1.1 skrll canonicalized. */
3493 1.1 skrll mmix_current_prefix = NULL;
3494 1.1 skrll
3495 1.1 skrll if (doing_bspec)
3496 1.1 skrll as_bad_where (bspec_file, bspec_line, _("BSPEC without ESPEC."));
3497 1.1 skrll
3498 1.1 skrll /* Emit the low LOC setting of .text. */
3499 1.1 skrll if (text_has_contents && lowest_text_loc != (bfd_vma) -1)
3500 1.1 skrll {
3501 1.1 skrll symbolS *symbolP;
3502 1.1 skrll char locsymbol[sizeof (":") - 1
3503 1.1 skrll + sizeof (MMIX_LOC_SECTION_START_SYMBOL_PREFIX) - 1
3504 1.1 skrll + sizeof (".text")];
3505 1.1 skrll
3506 1.1 skrll /* An exercise in non-ISO-C-ness, this one. */
3507 1.1 skrll sprintf (locsymbol, ":%s%s", MMIX_LOC_SECTION_START_SYMBOL_PREFIX,
3508 1.1 skrll ".text");
3509 1.1 skrll symbolP
3510 1.1 skrll = symbol_new (locsymbol, absolute_section, lowest_text_loc,
3511 1.1 skrll &zero_address_frag);
3512 1.1 skrll S_SET_EXTERNAL (symbolP);
3513 1.1 skrll }
3514 1.1 skrll
3515 1.1 skrll /* Ditto .data. */
3516 1.1 skrll if (data_has_contents && lowest_data_loc != (bfd_vma) -1)
3517 1.1 skrll {
3518 1.1 skrll symbolS *symbolP;
3519 1.1 skrll char locsymbol[sizeof (":") - 1
3520 1.1 skrll + sizeof (MMIX_LOC_SECTION_START_SYMBOL_PREFIX) - 1
3521 1.1 skrll + sizeof (".data")];
3522 1.1 skrll
3523 1.1 skrll sprintf (locsymbol, ":%s%s", MMIX_LOC_SECTION_START_SYMBOL_PREFIX,
3524 1.1 skrll ".data");
3525 1.1 skrll symbolP
3526 1.1 skrll = symbol_new (locsymbol, absolute_section, lowest_data_loc,
3527 1.1 skrll &zero_address_frag);
3528 1.1 skrll S_SET_EXTERNAL (symbolP);
3529 1.1 skrll }
3530 1.1 skrll
3531 1.1 skrll /* Unless GNU syntax mode, set "Main" to be a function, so the
3532 1.1 skrll disassembler doesn't get confused when we write truly
3533 1.1 skrll mmixal-compatible code (and don't use .type). Similarly set it
3534 1.1 skrll global (regardless of -globalize-symbols), so the linker sees it as
3535 1.1 skrll the start symbol in ELF mode. */
3536 1.1 skrll mainsym = symbol_find (MMIX_START_SYMBOL_NAME);
3537 1.1 skrll if (mainsym != NULL && ! mmix_gnu_syntax)
3538 1.1 skrll {
3539 1.1 skrll symbol_get_bfdsym (mainsym)->flags |= BSF_FUNCTION;
3540 1.1 skrll S_SET_EXTERNAL (mainsym);
3541 1.1 skrll }
3542 1.1 skrll
3543 1.1.1.3 christos /* Check that we didn't LOC into the unknown, or rather that when it
3544 1.1.1.3 christos was unknown, we actually change sections. */
3545 1.1.1.3 christos for (loc_assert = loc_asserts;
3546 1.1.1.3 christos loc_assert != NULL;
3547 1.1.1.3 christos loc_assert = loc_assert->next)
3548 1.1.1.3 christos {
3549 1.1.1.3 christos segT actual_seg;
3550 1.1.1.3 christos
3551 1.1.1.3 christos resolve_symbol_value (loc_assert->loc_sym);
3552 1.1.1.3 christos actual_seg = S_GET_SEGMENT (loc_assert->loc_sym);
3553 1.1.1.3 christos if (actual_seg != loc_assert->old_seg)
3554 1.1.1.3 christos {
3555 1.1.1.5 christos const char *fnam;
3556 1.1.1.3 christos unsigned int line;
3557 1.1.1.3 christos int e_valid = expr_symbol_where (loc_assert->loc_sym, &fnam, &line);
3558 1.1.1.3 christos
3559 1.1.1.3 christos gas_assert (e_valid == 1);
3560 1.1.1.3 christos as_bad_where (fnam, line,
3561 1.1.1.3 christos _("LOC to section unknown or indeterminable "
3562 1.1.1.3 christos "at first pass"));
3563 1.1.1.4 christos
3564 1.1.1.4 christos /* Patch up the generic location data to avoid cascading
3565 1.1.1.4 christos error messages from later passes. (See original in
3566 1.1.1.4 christos write.c:relax_segment.) */
3567 1.1.1.4 christos fragP = loc_assert->frag;
3568 1.1.1.4 christos fragP->fr_type = rs_align;
3569 1.1.1.4 christos fragP->fr_subtype = 0;
3570 1.1.1.4 christos fragP->fr_offset = 0;
3571 1.1.1.4 christos fragP->fr_fix = 0;
3572 1.1.1.3 christos }
3573 1.1.1.3 christos }
3574 1.1.1.3 christos
3575 1.1 skrll if (n_of_raw_gregs != 0)
3576 1.1 skrll {
3577 1.1 skrll /* Emit GREGs. They are collected in order of appearance, but must
3578 1.1 skrll be emitted in opposite order to both have section address regno*8
3579 1.1 skrll and the same allocation order (within a file) as mmixal. */
3580 1.1 skrll segT this_segment = now_seg;
3581 1.1 skrll subsegT this_subsegment = now_subseg;
3582 1.1 skrll
3583 1.1 skrll regsec = bfd_make_section_old_way (stdoutput,
3584 1.1 skrll MMIX_REG_CONTENTS_SECTION_NAME);
3585 1.1 skrll subseg_set (regsec, 0);
3586 1.1 skrll
3587 1.1 skrll /* Finally emit the initialization-value. Emit a variable frag, which
3588 1.1 skrll we'll fix in md_estimate_size_before_relax. We set the initializer
3589 1.1 skrll for the tc_frag_data field to NULL, so we can use that field for
3590 1.1 skrll relaxation purposes. */
3591 1.1 skrll mmix_opcode_frag = NULL;
3592 1.1 skrll
3593 1.1 skrll frag_grow (0);
3594 1.1 skrll mmix_reg_contents_frags = frag_now;
3595 1.1 skrll
3596 1.1 skrll for (i = n_of_raw_gregs - 1; i >= 0; i--)
3597 1.1 skrll {
3598 1.1 skrll if (mmix_raw_gregs[i].label != NULL)
3599 1.1 skrll /* There's a symbol. Let it refer to this location in the
3600 1.1 skrll register contents section. The symbol must be globalized
3601 1.1 skrll separately. */
3602 1.1 skrll colon (mmix_raw_gregs[i].label);
3603 1.1 skrll
3604 1.1 skrll frag_var (rs_machine_dependent, 8, 0, STATE_GREG_UNDF,
3605 1.1 skrll make_expr_symbol (&mmix_raw_gregs[i].exp), 0, NULL);
3606 1.1 skrll }
3607 1.1 skrll
3608 1.1 skrll subseg_set (this_segment, this_subsegment);
3609 1.1 skrll }
3610 1.1 skrll
3611 1.1 skrll regsec = bfd_get_section_by_name (stdoutput, MMIX_REG_CONTENTS_SECTION_NAME);
3612 1.1 skrll /* Mark the section symbol as being OK for a reloc. */
3613 1.1 skrll if (regsec != NULL)
3614 1.1 skrll regsec->symbol->flags |= BSF_KEEP;
3615 1.1 skrll
3616 1.1 skrll /* Iterate over frags resulting from GREGs and move those that evidently
3617 1.1 skrll have the same value together and point one to another.
3618 1.1 skrll
3619 1.1 skrll This works in time O(N^2) but since the upper bound for non-error use
3620 1.1 skrll is 223, it's best to keep this simpler algorithm. */
3621 1.1 skrll for (fragP = mmix_reg_contents_frags; fragP != NULL; fragP = fragP->fr_next)
3622 1.1 skrll {
3623 1.1 skrll fragS **fpp;
3624 1.1 skrll fragS *fp = NULL;
3625 1.1 skrll fragS *osymfrag;
3626 1.1 skrll offsetT osymval;
3627 1.1 skrll expressionS *oexpP;
3628 1.1 skrll symbolS *symbolP = fragP->fr_symbol;
3629 1.1 skrll
3630 1.1 skrll if (fragP->fr_type != rs_machine_dependent
3631 1.1 skrll || fragP->fr_subtype != STATE_GREG_UNDF)
3632 1.1 skrll continue;
3633 1.1 skrll
3634 1.1 skrll /* Whatever the outcome, we will have this GREG judged merged or
3635 1.1 skrll non-merged. Since the tc_frag_data is NULL at this point, we
3636 1.1 skrll default to non-merged. */
3637 1.1 skrll fragP->fr_subtype = STATE_GREG_DEF;
3638 1.1 skrll
3639 1.1 skrll /* If we're not supposed to merge GREG definitions, then just don't
3640 1.1 skrll look for equivalents. */
3641 1.1 skrll if (! merge_gregs)
3642 1.1 skrll continue;
3643 1.1 skrll
3644 1.1 skrll osymval = (offsetT) S_GET_VALUE (symbolP);
3645 1.1 skrll osymfrag = symbol_get_frag (symbolP);
3646 1.1 skrll
3647 1.1 skrll /* If the symbol isn't defined, we can't say that another symbol
3648 1.1 skrll equals this frag, then. FIXME: We can look at the "deepest"
3649 1.1 skrll defined name; if a = c and b = c then obviously a == b. */
3650 1.1 skrll if (! S_IS_DEFINED (symbolP))
3651 1.1 skrll continue;
3652 1.1 skrll
3653 1.1 skrll oexpP = symbol_get_value_expression (fragP->fr_symbol);
3654 1.1 skrll
3655 1.1 skrll /* If the initialization value is zero, then we must not merge them. */
3656 1.1 skrll if (oexpP->X_op == O_constant && osymval == 0)
3657 1.1 skrll continue;
3658 1.1 skrll
3659 1.1 skrll /* Iterate through the frags downward this one. If we find one that
3660 1.1 skrll has the same non-zero value, move it to after this one and point
3661 1.1 skrll to it as the equivalent. */
3662 1.1 skrll for (fpp = &fragP->fr_next; *fpp != NULL; fpp = &fpp[0]->fr_next)
3663 1.1 skrll {
3664 1.1 skrll fp = *fpp;
3665 1.1 skrll
3666 1.1 skrll if (fp->fr_type != rs_machine_dependent
3667 1.1 skrll || fp->fr_subtype != STATE_GREG_UNDF)
3668 1.1 skrll continue;
3669 1.1 skrll
3670 1.1 skrll /* Calling S_GET_VALUE may simplify the symbol, changing from
3671 1.1 skrll expr_section etc. so call it first. */
3672 1.1 skrll if ((offsetT) S_GET_VALUE (fp->fr_symbol) == osymval
3673 1.1 skrll && symbol_get_frag (fp->fr_symbol) == osymfrag)
3674 1.1 skrll {
3675 1.1 skrll /* Move the frag links so the one we found equivalent comes
3676 1.1 skrll after the current one, carefully considering that
3677 1.1 skrll sometimes fpp == &fragP->fr_next and the moves must be a
3678 1.1 skrll NOP then. */
3679 1.1 skrll *fpp = fp->fr_next;
3680 1.1 skrll fp->fr_next = fragP->fr_next;
3681 1.1 skrll fragP->fr_next = fp;
3682 1.1 skrll break;
3683 1.1 skrll }
3684 1.1 skrll }
3685 1.1 skrll
3686 1.1 skrll if (*fpp != NULL)
3687 1.1 skrll fragP->tc_frag_data = fp;
3688 1.1 skrll }
3689 1.1 skrll }
3690 1.1 skrll
3691 1.1 skrll /* qsort function for mmix_symbol_gregs. */
3692 1.1 skrll
3693 1.1 skrll static int
3694 1.1 skrll cmp_greg_symbol_fixes (const void *parg, const void *qarg)
3695 1.1 skrll {
3696 1.1 skrll const struct mmix_symbol_greg_fixes *p
3697 1.1 skrll = (const struct mmix_symbol_greg_fixes *) parg;
3698 1.1 skrll const struct mmix_symbol_greg_fixes *q
3699 1.1 skrll = (const struct mmix_symbol_greg_fixes *) qarg;
3700 1.1 skrll
3701 1.1 skrll return p->offs > q->offs ? 1 : p->offs < q->offs ? -1 : 0;
3702 1.1 skrll }
3703 1.1 skrll
3704 1.1 skrll /* Collect GREG definitions from mmix_gregs and hang them as lists sorted
3705 1.1 skrll on increasing offsets onto each section symbol or undefined symbol.
3706 1.1 skrll
3707 1.1 skrll Also, remove the register convenience section so it doesn't get output
3708 1.1 skrll as an ELF section. */
3709 1.1 skrll
3710 1.1 skrll void
3711 1.1 skrll mmix_frob_file (void)
3712 1.1 skrll {
3713 1.1 skrll int i;
3714 1.1 skrll struct mmix_symbol_gregs *all_greg_symbols[MAX_GREGS];
3715 1.1 skrll int n_greg_symbols = 0;
3716 1.1 skrll
3717 1.1 skrll /* Collect all greg fixups and decorate each corresponding symbol with
3718 1.1 skrll the greg fixups for it. */
3719 1.1 skrll for (i = 0; i < n_of_cooked_gregs; i++)
3720 1.1 skrll {
3721 1.1 skrll offsetT offs;
3722 1.1 skrll symbolS *sym;
3723 1.1 skrll struct mmix_symbol_gregs *gregs;
3724 1.1 skrll fixS *fixP;
3725 1.1 skrll
3726 1.1 skrll fixP = mmix_gregs[i];
3727 1.1 skrll know (fixP->fx_r_type == BFD_RELOC_64);
3728 1.1 skrll
3729 1.1 skrll /* This case isn't doable in general anyway, methinks. */
3730 1.1 skrll if (fixP->fx_subsy != NULL)
3731 1.1 skrll {
3732 1.1 skrll as_bad_where (fixP->fx_file, fixP->fx_line,
3733 1.1 skrll _("GREG expression too complicated"));
3734 1.1 skrll continue;
3735 1.1 skrll }
3736 1.1 skrll
3737 1.1 skrll sym = fixP->fx_addsy;
3738 1.1 skrll offs = (offsetT) fixP->fx_offset;
3739 1.1 skrll
3740 1.1 skrll /* If the symbol is defined, then it must be resolved to a section
3741 1.1 skrll symbol at this time, or else we don't know how to handle it. */
3742 1.1 skrll if (S_IS_DEFINED (sym)
3743 1.1 skrll && !bfd_is_com_section (S_GET_SEGMENT (sym))
3744 1.1 skrll && !S_IS_WEAK (sym))
3745 1.1 skrll {
3746 1.1 skrll if (! symbol_section_p (sym)
3747 1.1 skrll && ! bfd_is_abs_section (S_GET_SEGMENT (sym)))
3748 1.1 skrll as_fatal (_("internal: GREG expression not resolved to section"));
3749 1.1 skrll
3750 1.1 skrll offs += S_GET_VALUE (sym);
3751 1.1 skrll }
3752 1.1 skrll
3753 1.1 skrll /* If this is an absolute symbol sufficiently near lowest_data_loc,
3754 1.1 skrll then we canonicalize on the data section. Note that offs is
3755 1.1 skrll signed here; we may subtract lowest_data_loc which is unsigned.
3756 1.1 skrll Careful with those comparisons. */
3757 1.1 skrll if (lowest_data_loc != (bfd_vma) -1
3758 1.1 skrll && (bfd_vma) offs + 256 > lowest_data_loc
3759 1.1 skrll && bfd_is_abs_section (S_GET_SEGMENT (sym)))
3760 1.1 skrll {
3761 1.1 skrll offs -= (offsetT) lowest_data_loc;
3762 1.1 skrll sym = section_symbol (data_section);
3763 1.1 skrll }
3764 1.1 skrll /* Likewise text section. */
3765 1.1 skrll else if (lowest_text_loc != (bfd_vma) -1
3766 1.1 skrll && (bfd_vma) offs + 256 > lowest_text_loc
3767 1.1 skrll && bfd_is_abs_section (S_GET_SEGMENT (sym)))
3768 1.1 skrll {
3769 1.1 skrll offs -= (offsetT) lowest_text_loc;
3770 1.1 skrll sym = section_symbol (text_section);
3771 1.1 skrll }
3772 1.1 skrll
3773 1.1 skrll gregs = *symbol_get_tc (sym);
3774 1.1 skrll
3775 1.1 skrll if (gregs == NULL)
3776 1.1 skrll {
3777 1.1.1.5 christos gregs = XNEW (struct mmix_symbol_gregs);
3778 1.1 skrll gregs->n_gregs = 0;
3779 1.1 skrll symbol_set_tc (sym, &gregs);
3780 1.1 skrll all_greg_symbols[n_greg_symbols++] = gregs;
3781 1.1 skrll }
3782 1.1 skrll
3783 1.1 skrll gregs->greg_fixes[gregs->n_gregs].fix = fixP;
3784 1.1 skrll gregs->greg_fixes[gregs->n_gregs++].offs = offs;
3785 1.1 skrll }
3786 1.1 skrll
3787 1.1 skrll /* For each symbol having a GREG definition, sort those definitions on
3788 1.1 skrll offset. */
3789 1.1 skrll for (i = 0; i < n_greg_symbols; i++)
3790 1.1 skrll qsort (all_greg_symbols[i]->greg_fixes, all_greg_symbols[i]->n_gregs,
3791 1.1 skrll sizeof (all_greg_symbols[i]->greg_fixes[0]), cmp_greg_symbol_fixes);
3792 1.1 skrll
3793 1.1 skrll if (real_reg_section != NULL)
3794 1.1 skrll {
3795 1.1 skrll /* FIXME: Pass error state gracefully. */
3796 1.1.1.7 christos if (bfd_section_flags (real_reg_section) & SEC_HAS_CONTENTS)
3797 1.1 skrll as_fatal (_("register section has contents\n"));
3798 1.1 skrll
3799 1.1 skrll bfd_section_list_remove (stdoutput, real_reg_section);
3800 1.1 skrll --stdoutput->section_count;
3801 1.1 skrll }
3802 1.1 skrll
3803 1.1 skrll }
3804 1.1 skrll
3805 1.1 skrll /* Provide an expression for a built-in name provided when-used.
3806 1.1 skrll Either a symbol that is a handler; living in 0x10*[1..8] and having
3807 1.1 skrll name [DVWIOUZX]_Handler, or a mmixal built-in symbol.
3808 1.1 skrll
3809 1.1 skrll If the name isn't a built-in name and parsed into *EXPP, return zero. */
3810 1.1 skrll
3811 1.1 skrll int
3812 1.1 skrll mmix_parse_predefined_name (char *name, expressionS *expP)
3813 1.1 skrll {
3814 1.1 skrll char *canon_name;
3815 1.1.1.5 christos const char *handler_charp;
3816 1.1 skrll const char handler_chars[] = "DVWIOUZX";
3817 1.1 skrll symbolS *symp;
3818 1.1 skrll
3819 1.1 skrll if (! predefined_syms)
3820 1.1 skrll return 0;
3821 1.1 skrll
3822 1.1 skrll canon_name = tc_canonicalize_symbol_name (name);
3823 1.1 skrll
3824 1.1 skrll if (canon_name[1] == '_'
3825 1.1 skrll && strcmp (canon_name + 2, "Handler") == 0
3826 1.1 skrll && (handler_charp = strchr (handler_chars, *canon_name)) != NULL)
3827 1.1 skrll {
3828 1.1 skrll /* If the symbol doesn't exist, provide one relative to the .text
3829 1.1 skrll section.
3830 1.1 skrll
3831 1.1 skrll FIXME: We should provide separate sections, mapped in the linker
3832 1.1 skrll script. */
3833 1.1 skrll symp = symbol_find (name);
3834 1.1 skrll if (symp == NULL)
3835 1.1 skrll symp = symbol_new (name, text_section,
3836 1.1 skrll 0x10 * (handler_charp + 1 - handler_chars),
3837 1.1 skrll &zero_address_frag);
3838 1.1 skrll }
3839 1.1 skrll else
3840 1.1 skrll {
3841 1.1 skrll /* These symbols appear when referenced; needed for
3842 1.1 skrll mmixal-compatible programs. */
3843 1.1 skrll unsigned int i;
3844 1.1 skrll
3845 1.1 skrll static const struct
3846 1.1 skrll {
3847 1.1 skrll const char *name;
3848 1.1 skrll valueT val;
3849 1.1 skrll } predefined_abs_syms[] =
3850 1.1 skrll {
3851 1.1 skrll {"Data_Segment", (valueT) 0x20 << 56},
3852 1.1 skrll {"Pool_Segment", (valueT) 0x40 << 56},
3853 1.1 skrll {"Stack_Segment", (valueT) 0x60 << 56},
3854 1.1 skrll {"StdIn", 0},
3855 1.1 skrll {"StdOut", 1},
3856 1.1 skrll {"StdErr", 2},
3857 1.1 skrll {"TextRead", 0},
3858 1.1 skrll {"TextWrite", 1},
3859 1.1 skrll {"BinaryRead", 2},
3860 1.1 skrll {"BinaryWrite", 3},
3861 1.1 skrll {"BinaryReadWrite", 4},
3862 1.1 skrll {"Halt", 0},
3863 1.1 skrll {"Fopen", 1},
3864 1.1 skrll {"Fclose", 2},
3865 1.1 skrll {"Fread", 3},
3866 1.1 skrll {"Fgets", 4},
3867 1.1 skrll {"Fgetws", 5},
3868 1.1 skrll {"Fwrite", 6},
3869 1.1 skrll {"Fputs", 7},
3870 1.1 skrll {"Fputws", 8},
3871 1.1 skrll {"Fseek", 9},
3872 1.1 skrll {"Ftell", 10},
3873 1.1 skrll {"D_BIT", 0x80},
3874 1.1 skrll {"V_BIT", 0x40},
3875 1.1 skrll {"W_BIT", 0x20},
3876 1.1 skrll {"I_BIT", 0x10},
3877 1.1 skrll {"O_BIT", 0x08},
3878 1.1 skrll {"U_BIT", 0x04},
3879 1.1 skrll {"Z_BIT", 0x02},
3880 1.1 skrll {"X_BIT", 0x01},
3881 1.1 skrll {"Inf", 0x7ff00000}
3882 1.1 skrll };
3883 1.1 skrll
3884 1.1 skrll /* If it's already in the symbol table, we shouldn't do anything. */
3885 1.1 skrll symp = symbol_find (name);
3886 1.1 skrll if (symp != NULL)
3887 1.1 skrll return 0;
3888 1.1 skrll
3889 1.1 skrll for (i = 0;
3890 1.1 skrll i < sizeof (predefined_abs_syms) / sizeof (predefined_abs_syms[0]);
3891 1.1 skrll i++)
3892 1.1 skrll if (strcmp (canon_name, predefined_abs_syms[i].name) == 0)
3893 1.1 skrll {
3894 1.1 skrll symbol_table_insert (symbol_new (predefined_abs_syms[i].name,
3895 1.1 skrll absolute_section,
3896 1.1 skrll predefined_abs_syms[i].val,
3897 1.1 skrll &zero_address_frag));
3898 1.1 skrll
3899 1.1 skrll /* Let gas find the symbol we just created, through its
3900 1.1 skrll ordinary lookup. */
3901 1.1 skrll return 0;
3902 1.1 skrll }
3903 1.1 skrll
3904 1.1 skrll /* Not one of those symbols. Let gas handle it. */
3905 1.1 skrll return 0;
3906 1.1 skrll }
3907 1.1 skrll
3908 1.1 skrll expP->X_op = O_symbol;
3909 1.1 skrll expP->X_add_number = 0;
3910 1.1 skrll expP->X_add_symbol = symp;
3911 1.1 skrll expP->X_op_symbol = NULL;
3912 1.1 skrll
3913 1.1 skrll return 1;
3914 1.1 skrll }
3915 1.1 skrll
3916 1.1 skrll /* Just check that we don't have a BSPEC/ESPEC pair active when changing
3917 1.1 skrll sections "normally", and get knowledge about alignment from the new
3918 1.1 skrll section. */
3919 1.1 skrll
3920 1.1 skrll void
3921 1.1 skrll mmix_md_elf_section_change_hook (void)
3922 1.1 skrll {
3923 1.1 skrll if (doing_bspec)
3924 1.1 skrll as_bad (_("section change from within a BSPEC/ESPEC pair is not supported"));
3925 1.1 skrll
3926 1.1.1.7 christos last_alignment = bfd_section_alignment (now_seg);
3927 1.1 skrll want_unaligned = 0;
3928 1.1 skrll }
3929 1.1 skrll
3930 1.1 skrll /* The LOC worker. This is like s_org, but we have to support changing
3931 1.1 skrll section too. */
3932 1.1 skrll
3933 1.1 skrll static void
3934 1.1 skrll s_loc (int ignore ATTRIBUTE_UNUSED)
3935 1.1 skrll {
3936 1.1 skrll segT section;
3937 1.1 skrll expressionS exp;
3938 1.1 skrll char *p;
3939 1.1 skrll symbolS *sym;
3940 1.1 skrll offsetT off;
3941 1.1 skrll
3942 1.1 skrll /* Must not have a BSPEC in progress. */
3943 1.1 skrll if (doing_bspec)
3944 1.1 skrll {
3945 1.1 skrll as_bad (_("directive LOC from within a BSPEC/ESPEC pair is not supported"));
3946 1.1 skrll return;
3947 1.1 skrll }
3948 1.1 skrll
3949 1.1 skrll section = expression (&exp);
3950 1.1 skrll
3951 1.1 skrll if (exp.X_op == O_illegal
3952 1.1 skrll || exp.X_op == O_absent
3953 1.1.1.3 christos || exp.X_op == O_big)
3954 1.1 skrll {
3955 1.1 skrll as_bad (_("invalid LOC expression"));
3956 1.1 skrll return;
3957 1.1 skrll }
3958 1.1 skrll
3959 1.1.1.3 christos if (section == undefined_section)
3960 1.1.1.3 christos {
3961 1.1.1.3 christos /* This is an error or a LOC with an expression involving
3962 1.1.1.3 christos forward references. For the expression to be correctly
3963 1.1.1.3 christos evaluated, we need to force a proper symbol; gas loses track
3964 1.1.1.3 christos of the segment for "local symbols". */
3965 1.1.1.3 christos if (exp.X_op == O_add)
3966 1.1.1.3 christos {
3967 1.1.1.3 christos symbol_get_value_expression (exp.X_op_symbol);
3968 1.1.1.3 christos symbol_get_value_expression (exp.X_add_symbol);
3969 1.1.1.3 christos }
3970 1.1.1.3 christos else
3971 1.1.1.3 christos {
3972 1.1.1.3 christos gas_assert (exp.X_op == O_symbol);
3973 1.1.1.3 christos symbol_get_value_expression (exp.X_add_symbol);
3974 1.1.1.3 christos }
3975 1.1.1.3 christos }
3976 1.1.1.3 christos
3977 1.1 skrll if (section == absolute_section)
3978 1.1 skrll {
3979 1.1 skrll /* Translate a constant into a suitable section. */
3980 1.1 skrll
3981 1.1 skrll if (exp.X_add_number < ((offsetT) 0x20 << 56))
3982 1.1 skrll {
3983 1.1 skrll /* Lower than Data_Segment or in the reserved area (the
3984 1.1 skrll segment number is >= 0x80, appearing negative) - assume
3985 1.1 skrll it's .text. */
3986 1.1 skrll section = text_section;
3987 1.1 skrll
3988 1.1 skrll /* Save the lowest seen location, so we can pass on this
3989 1.1 skrll information to the linker. We don't actually org to this
3990 1.1 skrll location here, we just pass on information to the linker so
3991 1.1 skrll it can put the code there for us. */
3992 1.1 skrll
3993 1.1 skrll /* If there was already a loc (that has to be set lower than
3994 1.1 skrll this one), we org at (this - lower). There's an implicit
3995 1.1 skrll "LOC 0" before any entered code. FIXME: handled by spurious
3996 1.1 skrll settings of text_has_contents. */
3997 1.1 skrll if (lowest_text_loc != (bfd_vma) -1
3998 1.1 skrll && (bfd_vma) exp.X_add_number < lowest_text_loc)
3999 1.1 skrll {
4000 1.1 skrll as_bad (_("LOC expression stepping backwards is not supported"));
4001 1.1 skrll exp.X_op = O_absent;
4002 1.1 skrll }
4003 1.1 skrll else
4004 1.1 skrll {
4005 1.1 skrll if (text_has_contents && lowest_text_loc == (bfd_vma) -1)
4006 1.1 skrll lowest_text_loc = 0;
4007 1.1 skrll
4008 1.1 skrll if (lowest_text_loc == (bfd_vma) -1)
4009 1.1 skrll {
4010 1.1 skrll lowest_text_loc = exp.X_add_number;
4011 1.1 skrll
4012 1.1 skrll /* We want only to change the section, not set an offset. */
4013 1.1 skrll exp.X_op = O_absent;
4014 1.1 skrll }
4015 1.1 skrll else
4016 1.1 skrll exp.X_add_number -= lowest_text_loc;
4017 1.1 skrll }
4018 1.1 skrll }
4019 1.1 skrll else
4020 1.1 skrll {
4021 1.1 skrll /* Do the same for the .data section, except we don't have
4022 1.1 skrll to worry about exp.X_add_number carrying a sign. */
4023 1.1 skrll section = data_section;
4024 1.1 skrll
4025 1.1 skrll if (exp.X_add_number < (offsetT) lowest_data_loc)
4026 1.1 skrll {
4027 1.1 skrll as_bad (_("LOC expression stepping backwards is not supported"));
4028 1.1 skrll exp.X_op = O_absent;
4029 1.1 skrll }
4030 1.1 skrll else
4031 1.1 skrll {
4032 1.1 skrll if (data_has_contents && lowest_data_loc == (bfd_vma) -1)
4033 1.1 skrll lowest_data_loc = (bfd_vma) 0x20 << 56;
4034 1.1 skrll
4035 1.1 skrll if (lowest_data_loc == (bfd_vma) -1)
4036 1.1 skrll {
4037 1.1 skrll lowest_data_loc = exp.X_add_number;
4038 1.1 skrll
4039 1.1 skrll /* We want only to change the section, not set an offset. */
4040 1.1 skrll exp.X_op = O_absent;
4041 1.1 skrll }
4042 1.1 skrll else
4043 1.1 skrll exp.X_add_number -= lowest_data_loc;
4044 1.1 skrll }
4045 1.1 skrll }
4046 1.1 skrll }
4047 1.1 skrll
4048 1.1.1.3 christos /* If we can't deduce the section, it must be the current one.
4049 1.1.1.3 christos Below, we arrange to assert this. */
4050 1.1.1.3 christos if (section != now_seg && section != undefined_section)
4051 1.1 skrll {
4052 1.1 skrll obj_elf_section_change_hook ();
4053 1.1 skrll subseg_set (section, 0);
4054 1.1 skrll
4055 1.1 skrll /* Call our section change hooks using the official hook. */
4056 1.1 skrll md_elf_section_change_hook ();
4057 1.1 skrll }
4058 1.1 skrll
4059 1.1 skrll if (exp.X_op != O_absent)
4060 1.1 skrll {
4061 1.1.1.3 christos symbolS *esym = NULL;
4062 1.1.1.3 christos
4063 1.1 skrll if (exp.X_op != O_constant && exp.X_op != O_symbol)
4064 1.1 skrll {
4065 1.1 skrll /* Handle complex expressions. */
4066 1.1.1.3 christos esym = sym = make_expr_symbol (&exp);
4067 1.1 skrll off = 0;
4068 1.1 skrll }
4069 1.1 skrll else
4070 1.1 skrll {
4071 1.1 skrll sym = exp.X_add_symbol;
4072 1.1 skrll off = exp.X_add_number;
4073 1.1.1.3 christos
4074 1.1.1.3 christos if (section == undefined_section)
4075 1.1.1.3 christos {
4076 1.1.1.3 christos /* We need an expr_symbol when tracking sections. In
4077 1.1.1.3 christos order to make this an expr_symbol with file and line
4078 1.1.1.3 christos tracked, we have to make the exp non-trivial; not an
4079 1.1.1.3 christos O_symbol with .X_add_number == 0. The constant part
4080 1.1.1.3 christos is unused. */
4081 1.1.1.3 christos exp.X_add_number = 1;
4082 1.1.1.3 christos esym = make_expr_symbol (&exp);
4083 1.1.1.3 christos }
4084 1.1.1.3 christos }
4085 1.1.1.3 christos
4086 1.1.1.3 christos /* Track the LOC's where we couldn't deduce the section: assert
4087 1.1.1.3 christos that we weren't supposed to change section. */
4088 1.1.1.3 christos if (section == undefined_section)
4089 1.1.1.3 christos {
4090 1.1.1.3 christos struct loc_assert_s *next = loc_asserts;
4091 1.1.1.5 christos loc_asserts = XNEW (struct loc_assert_s);
4092 1.1.1.3 christos loc_asserts->next = next;
4093 1.1.1.3 christos loc_asserts->old_seg = now_seg;
4094 1.1.1.3 christos loc_asserts->loc_sym = esym;
4095 1.1.1.4 christos loc_asserts->frag = frag_now;
4096 1.1 skrll }
4097 1.1 skrll
4098 1.1 skrll p = frag_var (rs_org, 1, 1, (relax_substateT) 0, sym, off, (char *) 0);
4099 1.1 skrll *p = 0;
4100 1.1 skrll }
4101 1.1 skrll
4102 1.1 skrll mmix_handle_rest_of_empty_line ();
4103 1.1 skrll }
4104 1.1 skrll
4105 1.1 skrll /* The BYTE worker. We have to support sequences of mixed "strings",
4106 1.1 skrll numbers and other constant "first-pass" reducible expressions separated
4107 1.1 skrll by comma. */
4108 1.1 skrll
4109 1.1 skrll static void
4110 1.1 skrll mmix_byte (void)
4111 1.1 skrll {
4112 1.1 skrll unsigned int c;
4113 1.1 skrll
4114 1.1 skrll if (now_seg == text_section)
4115 1.1 skrll text_has_contents = 1;
4116 1.1 skrll else if (now_seg == data_section)
4117 1.1 skrll data_has_contents = 1;
4118 1.1 skrll
4119 1.1 skrll do
4120 1.1 skrll {
4121 1.1 skrll SKIP_WHITESPACE ();
4122 1.1 skrll switch (*input_line_pointer)
4123 1.1 skrll {
4124 1.1 skrll case '\"':
4125 1.1 skrll ++input_line_pointer;
4126 1.1 skrll while (is_a_char (c = next_char_of_string ()))
4127 1.1 skrll {
4128 1.1 skrll FRAG_APPEND_1_CHAR (c);
4129 1.1 skrll }
4130 1.1 skrll
4131 1.1 skrll if (input_line_pointer[-1] != '\"')
4132 1.1 skrll {
4133 1.1 skrll /* We will only get here in rare cases involving #NO_APP,
4134 1.1 skrll where the unterminated string is not recognized by the
4135 1.1 skrll preformatting pass. */
4136 1.1 skrll as_bad (_("unterminated string"));
4137 1.1 skrll mmix_discard_rest_of_line ();
4138 1.1 skrll return;
4139 1.1 skrll }
4140 1.1 skrll break;
4141 1.1 skrll
4142 1.1 skrll default:
4143 1.1 skrll {
4144 1.1 skrll expressionS exp;
4145 1.1 skrll segT expseg = expression (&exp);
4146 1.1 skrll
4147 1.1 skrll /* We have to allow special register names as constant numbers. */
4148 1.1 skrll if ((expseg != absolute_section && expseg != reg_section)
4149 1.1 skrll || (exp.X_op != O_constant
4150 1.1 skrll && (exp.X_op != O_register
4151 1.1 skrll || exp.X_add_number <= 255)))
4152 1.1 skrll {
4153 1.1 skrll as_bad (_("BYTE expression not a pure number"));
4154 1.1 skrll mmix_discard_rest_of_line ();
4155 1.1 skrll return;
4156 1.1 skrll }
4157 1.1 skrll else if ((exp.X_add_number > 255 && exp.X_op != O_register)
4158 1.1 skrll || exp.X_add_number < 0)
4159 1.1 skrll {
4160 1.1 skrll /* Note that mmixal does not allow negative numbers in
4161 1.1 skrll BYTE sequences, so neither should we. */
4162 1.1 skrll as_bad (_("BYTE expression not in the range 0..255"));
4163 1.1 skrll mmix_discard_rest_of_line ();
4164 1.1 skrll return;
4165 1.1 skrll }
4166 1.1 skrll
4167 1.1 skrll FRAG_APPEND_1_CHAR (exp.X_add_number);
4168 1.1 skrll }
4169 1.1 skrll break;
4170 1.1 skrll }
4171 1.1 skrll
4172 1.1 skrll SKIP_WHITESPACE ();
4173 1.1 skrll c = *input_line_pointer++;
4174 1.1 skrll }
4175 1.1 skrll while (c == ',');
4176 1.1 skrll
4177 1.1 skrll input_line_pointer--;
4178 1.1 skrll
4179 1.1 skrll if (mmix_gnu_syntax)
4180 1.1 skrll demand_empty_rest_of_line ();
4181 1.1 skrll else
4182 1.1 skrll {
4183 1.1 skrll mmix_discard_rest_of_line ();
4184 1.1 skrll /* Do like demand_empty_rest_of_line and step over the end-of-line
4185 1.1 skrll boundary. */
4186 1.1 skrll input_line_pointer++;
4187 1.1 skrll }
4188 1.1 skrll
4189 1.1 skrll /* Make sure we align for the next instruction. */
4190 1.1 skrll last_alignment = 0;
4191 1.1 skrll }
4192 1.1 skrll
4193 1.1 skrll /* Like cons_worker, but we have to ignore "naked comments", not barf on
4194 1.1 skrll them. Implements WYDE, TETRA and OCTA. We're a little bit more
4195 1.1 skrll lenient than mmix_byte but FIXME: they should eventually merge. */
4196 1.1 skrll
4197 1.1 skrll static void
4198 1.1 skrll mmix_cons (int nbytes)
4199 1.1 skrll {
4200 1.1 skrll expressionS exp;
4201 1.1 skrll
4202 1.1 skrll /* If we don't have any contents, then it's ok to have a specified start
4203 1.1 skrll address that is not a multiple of the max data size. We will then
4204 1.1 skrll align it as necessary when we get here. Otherwise, it's a fatal sin. */
4205 1.1 skrll if (now_seg == text_section)
4206 1.1 skrll {
4207 1.1 skrll if (lowest_text_loc != (bfd_vma) -1
4208 1.1 skrll && (lowest_text_loc & (nbytes - 1)) != 0)
4209 1.1 skrll {
4210 1.1 skrll if (text_has_contents)
4211 1.1 skrll as_bad (_("data item with alignment larger than location"));
4212 1.1 skrll else if (want_unaligned)
4213 1.1 skrll as_bad (_("unaligned data at an absolute location is not supported"));
4214 1.1 skrll
4215 1.1 skrll lowest_text_loc &= ~((bfd_vma) nbytes - 1);
4216 1.1 skrll lowest_text_loc += (bfd_vma) nbytes;
4217 1.1 skrll }
4218 1.1 skrll
4219 1.1 skrll text_has_contents = 1;
4220 1.1 skrll }
4221 1.1 skrll else if (now_seg == data_section)
4222 1.1 skrll {
4223 1.1 skrll if (lowest_data_loc != (bfd_vma) -1
4224 1.1 skrll && (lowest_data_loc & (nbytes - 1)) != 0)
4225 1.1 skrll {
4226 1.1 skrll if (data_has_contents)
4227 1.1 skrll as_bad (_("data item with alignment larger than location"));
4228 1.1 skrll else if (want_unaligned)
4229 1.1 skrll as_bad (_("unaligned data at an absolute location is not supported"));
4230 1.1 skrll
4231 1.1 skrll lowest_data_loc &= ~((bfd_vma) nbytes - 1);
4232 1.1 skrll lowest_data_loc += (bfd_vma) nbytes;
4233 1.1 skrll }
4234 1.1 skrll
4235 1.1 skrll data_has_contents = 1;
4236 1.1 skrll }
4237 1.1 skrll
4238 1.1 skrll /* Always align these unless asked not to (valid for the current pseudo). */
4239 1.1 skrll if (! want_unaligned)
4240 1.1 skrll {
4241 1.1 skrll last_alignment = nbytes == 2 ? 1 : (nbytes == 4 ? 2 : 3);
4242 1.1 skrll frag_align (last_alignment, 0, 0);
4243 1.1 skrll record_alignment (now_seg, last_alignment);
4244 1.1 skrll }
4245 1.1 skrll
4246 1.1 skrll /* For mmixal compatibility, a label for an instruction (and emitting
4247 1.1 skrll pseudo) refers to the _aligned_ address. So we have to emit the
4248 1.1 skrll label here. */
4249 1.1 skrll if (current_fb_label >= 0)
4250 1.1 skrll colon (fb_label_name (current_fb_label, 1));
4251 1.1 skrll else if (pending_label != NULL)
4252 1.1 skrll {
4253 1.1 skrll colon (pending_label);
4254 1.1 skrll pending_label = NULL;
4255 1.1 skrll }
4256 1.1 skrll
4257 1.1 skrll SKIP_WHITESPACE ();
4258 1.1 skrll
4259 1.1 skrll if (is_end_of_line[(unsigned int) *input_line_pointer])
4260 1.1 skrll {
4261 1.1 skrll /* Default to zero if the expression was absent. */
4262 1.1 skrll
4263 1.1 skrll exp.X_op = O_constant;
4264 1.1 skrll exp.X_add_number = 0;
4265 1.1 skrll exp.X_unsigned = 0;
4266 1.1 skrll exp.X_add_symbol = NULL;
4267 1.1 skrll exp.X_op_symbol = NULL;
4268 1.1 skrll emit_expr (&exp, (unsigned int) nbytes);
4269 1.1 skrll }
4270 1.1 skrll else
4271 1.1 skrll do
4272 1.1 skrll {
4273 1.1 skrll unsigned int c;
4274 1.1 skrll
4275 1.1 skrll switch (*input_line_pointer)
4276 1.1 skrll {
4277 1.1 skrll /* We support strings here too; each character takes up nbytes
4278 1.1 skrll bytes. */
4279 1.1 skrll case '\"':
4280 1.1 skrll ++input_line_pointer;
4281 1.1 skrll while (is_a_char (c = next_char_of_string ()))
4282 1.1 skrll {
4283 1.1 skrll exp.X_op = O_constant;
4284 1.1 skrll exp.X_add_number = c;
4285 1.1 skrll exp.X_unsigned = 1;
4286 1.1 skrll emit_expr (&exp, (unsigned int) nbytes);
4287 1.1 skrll }
4288 1.1 skrll
4289 1.1 skrll if (input_line_pointer[-1] != '\"')
4290 1.1 skrll {
4291 1.1 skrll /* We will only get here in rare cases involving #NO_APP,
4292 1.1 skrll where the unterminated string is not recognized by the
4293 1.1 skrll preformatting pass. */
4294 1.1 skrll as_bad (_("unterminated string"));
4295 1.1 skrll mmix_discard_rest_of_line ();
4296 1.1 skrll return;
4297 1.1 skrll }
4298 1.1 skrll break;
4299 1.1 skrll
4300 1.1 skrll default:
4301 1.1 skrll {
4302 1.1 skrll expression (&exp);
4303 1.1 skrll emit_expr (&exp, (unsigned int) nbytes);
4304 1.1 skrll SKIP_WHITESPACE ();
4305 1.1 skrll }
4306 1.1 skrll break;
4307 1.1 skrll }
4308 1.1 skrll }
4309 1.1 skrll while (*input_line_pointer++ == ',');
4310 1.1 skrll
4311 1.1 skrll input_line_pointer--; /* Put terminator back into stream. */
4312 1.1 skrll
4313 1.1 skrll mmix_handle_rest_of_empty_line ();
4314 1.1 skrll
4315 1.1 skrll /* We don't need to step up the counter for the current_fb_label here;
4316 1.1 skrll that's handled by the caller. */
4317 1.1 skrll }
4318 1.1 skrll
4319 1.1 skrll /* The md_do_align worker. At present, we just record an alignment to
4320 1.1 skrll nullify the automatic alignment we do for WYDE, TETRA and OCTA, as gcc
4321 1.1 skrll does not use the unaligned macros when attribute packed is used.
4322 1.1 skrll Arguably this is a GCC bug. */
4323 1.1 skrll
4324 1.1 skrll void
4325 1.1 skrll mmix_md_do_align (int n, char *fill ATTRIBUTE_UNUSED,
4326 1.1 skrll int len ATTRIBUTE_UNUSED, int max ATTRIBUTE_UNUSED)
4327 1.1 skrll {
4328 1.1 skrll last_alignment = n;
4329 1.1 skrll want_unaligned = n == 0;
4330 1.1 skrll }
4331