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