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