| 1 | /* Assembly backend for the OpenRISC 1000. |
| 2 | Copyright (C) 2002-2014 Free Software Foundation, Inc. |
| 3 | Contributed by Damjan Lampret <lampret@opencores.org>. |
| 4 | Modified bu Johan Rydberg, <johan.rydberg@netinsight.se>. |
| 5 | Based upon a29k port. |
| 6 | |
| 7 | This file is part of GAS, the GNU Assembler. |
| 8 | |
| 9 | GAS is free software; you can redistribute it and/or modify |
| 10 | it under the terms of the GNU General Public License as published by |
| 11 | the Free Software Foundation; either version 3, or (at your option) |
| 12 | any later version. |
| 13 | |
| 14 | GAS is distributed in the hope that it will be useful, |
| 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | GNU General Public License for more details. |
| 18 | |
| 19 | You should have received a copy of the GNU General Public License |
| 20 | along with GAS; see the file COPYING. If not, write to |
| 21 | the Free Software Foundation, 51 Franklin Street - Fifth Floor, |
| 22 | Boston, MA 02110-1301, USA. */ |
| 23 | |
| 24 | /* tc-a29k.c used as a template. */ |
| 25 | |
| 26 | #include "as.h" |
| 27 | #include "safe-ctype.h" |
| 28 | #include "opcode/or32.h" |
| 29 | #include "elf/or32.h" |
| 30 | |
| 31 | #define DEBUG 0 |
| 32 | |
| 33 | #ifndef REGISTER_PREFIX |
| 34 | #define REGISTER_PREFIX '%' |
| 35 | #endif |
| 36 | |
| 37 | /* Make it easier to clone this machine desc into another one. */ |
| 38 | #define machine_opcode or32_opcode |
| 39 | #define machine_opcodes or32_opcodes |
| 40 | #define machine_ip or32_ip |
| 41 | #define machine_it or32_it |
| 42 | |
| 43 | /* Handle of the OPCODE hash table. */ |
| 44 | static struct hash_control *op_hash = NULL; |
| 45 | |
| 46 | struct machine_it |
| 47 | { |
| 48 | char * error; |
| 49 | unsigned long opcode; |
| 50 | struct nlist * nlistp; |
| 51 | expressionS exp; |
| 52 | int pcrel; |
| 53 | int reloc_offset; /* Offset of reloc within insn. */ |
| 54 | int reloc; |
| 55 | } |
| 56 | the_insn; |
| 57 | |
| 58 | const pseudo_typeS md_pseudo_table[] = |
| 59 | { |
| 60 | {"align", s_align_bytes, 4 }, |
| 61 | {"space", s_space, 0 }, |
| 62 | {"cputype", s_ignore, 0 }, |
| 63 | {"reg", s_lsym, 0 }, /* Register equate, same as equ. */ |
| 64 | {"sect", s_ignore, 0 }, /* Creation of coff sections. */ |
| 65 | {"proc", s_ignore, 0 }, /* Start of a function. */ |
| 66 | {"endproc", s_ignore, 0 }, /* Function end. */ |
| 67 | {"word", cons, 4 }, |
| 68 | {NULL, 0, 0 }, |
| 69 | }; |
| 70 | |
| 71 | int md_short_jump_size = 4; |
| 72 | int md_long_jump_size = 4; |
| 73 | |
| 74 | /* This array holds the chars that always start a comment. |
| 75 | If the pre-processor is disabled, these aren't very useful. */ |
| 76 | const char comment_chars[] = "#"; |
| 77 | |
| 78 | /* This array holds the chars that only start a comment at the beginning of |
| 79 | a line. If the line seems to have the form '# 123 filename' |
| 80 | .line and .file directives will appear in the pre-processed output. */ |
| 81 | /* Note that input_file.c hand checks for '#' at the beginning of the |
| 82 | first line of the input file. This is because the compiler outputs |
| 83 | #NO_APP at the beginning of its output. */ |
| 84 | /* Also note that comments like this one will always work. */ |
| 85 | const char line_comment_chars[] = "#"; |
| 86 | |
| 87 | /* We needed an unused char for line separation to work around the |
| 88 | lack of macros, using sed and such. */ |
| 89 | const char line_separator_chars[] = ";"; |
| 90 | |
| 91 | /* Chars that can be used to separate mant from exp in floating point nums. */ |
| 92 | const char EXP_CHARS[] = "eE"; |
| 93 | |
| 94 | /* Chars that mean this number is a floating point constant. |
| 95 | As in 0f12.456 |
| 96 | or 0d1.2345e12. */ |
| 97 | const char FLT_CHARS[] = "rRsSfFdDxXpP"; |
| 98 | |
| 99 | /* "l.jalr r9" precalculated opcode. */ |
| 100 | static unsigned long jalr_r9_opcode; |
| 101 | |
| 102 | static void machine_ip (char *); |
| 103 | |
| 104 | |
| 105 | /* Set bits in machine opcode according to insn->encoding |
| 106 | description and passed operand. */ |
| 107 | |
| 108 | static void |
| 109 | encode (const struct machine_opcode *insn, |
| 110 | unsigned long *opcode, |
| 111 | signed long param_val, |
| 112 | char param_ch) |
| 113 | { |
| 114 | int opc_pos = 0; |
| 115 | int param_pos = 0; |
| 116 | char *enc; |
| 117 | |
| 118 | #if DEBUG |
| 119 | printf (" encode: opcode=%.8lx param_val=%.8lx abs=%.8lx param_ch=%c\n", |
| 120 | *opcode, param_val, abs (param_val), param_ch); |
| 121 | #endif |
| 122 | for (enc = insn->encoding; *enc != '\0'; enc++) |
| 123 | if (*enc == param_ch) |
| 124 | { |
| 125 | if (enc - 2 >= insn->encoding && (*(enc - 2) == '0') && (*(enc - 1) == 'x')) |
| 126 | continue; |
| 127 | else |
| 128 | param_pos ++; |
| 129 | } |
| 130 | |
| 131 | opc_pos = 32; |
| 132 | |
| 133 | for (enc = insn->encoding; *enc != '\0';) |
| 134 | { |
| 135 | if ((*enc == '0') && (*(enc + 1) == 'x')) |
| 136 | { |
| 137 | int tmp = strtol (enc, NULL, 16); |
| 138 | |
| 139 | opc_pos -= 4; |
| 140 | *opcode |= tmp << opc_pos; |
| 141 | enc += 3; |
| 142 | } |
| 143 | else if ((*enc == '0') || (*enc == '-')) |
| 144 | { |
| 145 | opc_pos--; |
| 146 | enc++; |
| 147 | } |
| 148 | else if (*enc == '1') |
| 149 | { |
| 150 | opc_pos--; |
| 151 | *opcode |= 1 << opc_pos; |
| 152 | enc++; |
| 153 | } |
| 154 | else if (*enc == param_ch) |
| 155 | { |
| 156 | opc_pos--; |
| 157 | param_pos--; |
| 158 | *opcode |= ((param_val >> param_pos) & 0x1) << opc_pos; |
| 159 | enc++; |
| 160 | } |
| 161 | else if (ISALPHA (*enc)) |
| 162 | { |
| 163 | opc_pos--; |
| 164 | enc++; |
| 165 | } |
| 166 | else |
| 167 | enc++; |
| 168 | } |
| 169 | |
| 170 | #if DEBUG |
| 171 | printf (" opcode=%.8lx\n", *opcode); |
| 172 | #endif |
| 173 | } |
| 174 | |
| 175 | /* This function is called once, at assembler startup time. It should |
| 176 | set up all the tables, etc., that the MD part of the assembler will |
| 177 | need. */ |
| 178 | |
| 179 | void |
| 180 | md_begin (void) |
| 181 | { |
| 182 | const char *retval = NULL; |
| 183 | int lose = 0; |
| 184 | int skipnext = 0; |
| 185 | unsigned int i; |
| 186 | |
| 187 | /* Hash up all the opcodes for fast use later. */ |
| 188 | op_hash = hash_new (); |
| 189 | |
| 190 | for (i = 0; i < or32_num_opcodes; i++) |
| 191 | { |
| 192 | const char *name = machine_opcodes[i].name; |
| 193 | |
| 194 | if (skipnext) |
| 195 | { |
| 196 | skipnext = 0; |
| 197 | continue; |
| 198 | } |
| 199 | |
| 200 | retval = hash_insert (op_hash, name, (void *) &machine_opcodes[i]); |
| 201 | if (retval != NULL) |
| 202 | { |
| 203 | fprintf (stderr, "internal error: can't hash `%s': %s\n", |
| 204 | machine_opcodes[i].name, retval); |
| 205 | lose = 1; |
| 206 | } |
| 207 | } |
| 208 | |
| 209 | if (lose) |
| 210 | as_fatal (_("Broken assembler. No assembly attempted.")); |
| 211 | |
| 212 | encode (&machine_opcodes[insn_index ("l.jalr")], &jalr_r9_opcode, 9, 'B'); |
| 213 | } |
| 214 | |
| 215 | /* Returns non zero if instruction is to be used. */ |
| 216 | |
| 217 | static int |
| 218 | check_invalid_opcode (unsigned long opcode) |
| 219 | { |
| 220 | return opcode == jalr_r9_opcode; |
| 221 | } |
| 222 | |
| 223 | /* Assemble a single instruction. Its label has already been handled |
| 224 | by the generic front end. We just parse opcode and operands, and |
| 225 | produce the bytes of data and relocation. */ |
| 226 | |
| 227 | void |
| 228 | md_assemble (char *str) |
| 229 | { |
| 230 | char *toP; |
| 231 | |
| 232 | #if DEBUG |
| 233 | printf ("NEW INSTRUCTION\n"); |
| 234 | #endif |
| 235 | |
| 236 | know (str); |
| 237 | machine_ip (str); |
| 238 | toP = frag_more (4); |
| 239 | |
| 240 | /* Put out the opcode. */ |
| 241 | md_number_to_chars (toP, the_insn.opcode, 4); |
| 242 | |
| 243 | /* Put out the symbol-dependent stuff. */ |
| 244 | if (the_insn.reloc != BFD_RELOC_NONE) |
| 245 | { |
| 246 | fix_new_exp (frag_now, |
| 247 | (toP - frag_now->fr_literal + the_insn.reloc_offset), |
| 248 | 4, /* size */ |
| 249 | &the_insn.exp, |
| 250 | the_insn.pcrel, |
| 251 | the_insn.reloc); |
| 252 | } |
| 253 | } |
| 254 | |
| 255 | /* This is true of the we have issued a "lo(" or "hi"(. */ |
| 256 | static int waiting_for_shift = 0; |
| 257 | |
| 258 | static int mask_or_shift = 0; |
| 259 | |
| 260 | static char * |
| 261 | parse_operand (char *s, expressionS *operandp, int opt) |
| 262 | { |
| 263 | char *save = input_line_pointer; |
| 264 | char *new_pointer; |
| 265 | |
| 266 | #if DEBUG |
| 267 | printf (" PROCESS NEW OPERAND(%s) == %c (%d)\n", s, opt ? opt : '!', opt); |
| 268 | #endif |
| 269 | |
| 270 | input_line_pointer = s; |
| 271 | |
| 272 | if (strncasecmp (s, "HI(", 3) == 0) |
| 273 | { |
| 274 | waiting_for_shift = 1; |
| 275 | mask_or_shift = BFD_RELOC_HI16; |
| 276 | |
| 277 | input_line_pointer += 3; |
| 278 | } |
| 279 | else if (strncasecmp (s, "LO(", 3) == 0) |
| 280 | { |
| 281 | mask_or_shift = BFD_RELOC_LO16; |
| 282 | |
| 283 | input_line_pointer += 3; |
| 284 | } |
| 285 | else |
| 286 | mask_or_shift = 0; |
| 287 | |
| 288 | if ((*s == '(') && (*(s+1) == 'r')) |
| 289 | s++; |
| 290 | |
| 291 | if ((*s == 'r') && ISDIGIT (*(s + 1))) |
| 292 | { |
| 293 | operandp->X_add_number = strtol (s + 1, NULL, 10); |
| 294 | operandp->X_op = O_register; |
| 295 | for (; (*s != ',') && (*s != '\0');) |
| 296 | s++; |
| 297 | input_line_pointer = save; |
| 298 | return s; |
| 299 | } |
| 300 | |
| 301 | expression (operandp); |
| 302 | |
| 303 | if (operandp->X_op == O_absent) |
| 304 | { |
| 305 | if (! opt) |
| 306 | as_bad (_("missing operand")); |
| 307 | else |
| 308 | { |
| 309 | operandp->X_add_number = 0; |
| 310 | operandp->X_op = O_constant; |
| 311 | } |
| 312 | } |
| 313 | |
| 314 | new_pointer = input_line_pointer; |
| 315 | input_line_pointer = save; |
| 316 | |
| 317 | #if DEBUG |
| 318 | printf (" %s=parse_operand(%s): operandp->X_op = %u\n", new_pointer, s, |
| 319 | operandp->X_op); |
| 320 | #endif |
| 321 | |
| 322 | return new_pointer; |
| 323 | } |
| 324 | |
| 325 | /* Instruction parsing. Takes a string containing the opcode. |
| 326 | Operands are at input_line_pointer. Output is in the_insn. |
| 327 | Warnings or errors are generated. */ |
| 328 | |
| 329 | static void |
| 330 | machine_ip (char *str) |
| 331 | { |
| 332 | char *s; |
| 333 | const char *args; |
| 334 | const struct machine_opcode *insn; |
| 335 | unsigned long opcode; |
| 336 | expressionS the_operand; |
| 337 | expressionS *operand = &the_operand; |
| 338 | unsigned int regno; |
| 339 | int reloc = BFD_RELOC_NONE; |
| 340 | |
| 341 | #if DEBUG |
| 342 | printf ("machine_ip(%s)\n", str); |
| 343 | #endif |
| 344 | |
| 345 | s = str; |
| 346 | for (; ISALNUM (*s) || *s == '.'; ++s) |
| 347 | if (ISUPPER (*s)) |
| 348 | *s = TOLOWER (*s); |
| 349 | |
| 350 | switch (*s) |
| 351 | { |
| 352 | case '\0': |
| 353 | break; |
| 354 | |
| 355 | case ' ': /* FIXME-SOMEDAY more whitespace. */ |
| 356 | *s++ = '\0'; |
| 357 | break; |
| 358 | |
| 359 | default: |
| 360 | as_bad (_("unknown opcode1: `%s'"), str); |
| 361 | return; |
| 362 | } |
| 363 | |
| 364 | if ((insn = (struct machine_opcode *) hash_find (op_hash, str)) == NULL) |
| 365 | { |
| 366 | as_bad (_("unknown opcode2 `%s'."), str); |
| 367 | return; |
| 368 | } |
| 369 | |
| 370 | opcode = 0; |
| 371 | memset (&the_insn, '\0', sizeof (the_insn)); |
| 372 | the_insn.reloc = BFD_RELOC_NONE; |
| 373 | |
| 374 | reloc = BFD_RELOC_NONE; |
| 375 | |
| 376 | /* Build the opcode, checking as we go to make sure that the |
| 377 | operands match. |
| 378 | |
| 379 | If an operand matches, we modify the_insn or opcode appropriately, |
| 380 | and do a "continue". If an operand fails to match, we "break". */ |
| 381 | if (insn->args[0] != '\0') |
| 382 | /* Prime the pump. */ |
| 383 | s = parse_operand (s, operand, insn->args[0] == 'I'); |
| 384 | |
| 385 | for (args = insn->args;; ++args) |
| 386 | { |
| 387 | #if DEBUG |
| 388 | printf (" args = %s\n", args); |
| 389 | #endif |
| 390 | switch (*args) |
| 391 | { |
| 392 | case '\0': /* End of args. */ |
| 393 | /* We have have 0 args, do the bazoooka! */ |
| 394 | if (args == insn->args) |
| 395 | encode (insn, &opcode, 0, 0); |
| 396 | |
| 397 | if (*s == '\0') |
| 398 | { |
| 399 | /* We are truly done. */ |
| 400 | the_insn.opcode = opcode; |
| 401 | if (check_invalid_opcode (opcode)) |
| 402 | as_bad (_("instruction not allowed: %s"), str); |
| 403 | return; |
| 404 | } |
| 405 | as_bad (_("too many operands: %s"), s); |
| 406 | break; |
| 407 | |
| 408 | case ',': /* Must match a comma. */ |
| 409 | if (*s++ == ',') |
| 410 | { |
| 411 | reloc = BFD_RELOC_NONE; |
| 412 | |
| 413 | /* Parse next operand. */ |
| 414 | s = parse_operand (s, operand, args[1] == 'I'); |
| 415 | #if DEBUG |
| 416 | printf (" ',' case: operand->X_add_number = %d, *args = %s, *s = %s\n", |
| 417 | operand->X_add_number, args, s); |
| 418 | #endif |
| 419 | continue; |
| 420 | } |
| 421 | break; |
| 422 | |
| 423 | case '(': /* Must match a (. */ |
| 424 | s = parse_operand (s, operand, args[1] == 'I'); |
| 425 | continue; |
| 426 | |
| 427 | case ')': /* Must match a ). */ |
| 428 | continue; |
| 429 | |
| 430 | case 'r': /* A general register. */ |
| 431 | args++; |
| 432 | |
| 433 | if (operand->X_op != O_register) |
| 434 | break; /* Only registers. */ |
| 435 | |
| 436 | know (operand->X_add_symbol == 0); |
| 437 | know (operand->X_op_symbol == 0); |
| 438 | regno = operand->X_add_number; |
| 439 | encode (insn, &opcode, regno, *args); |
| 440 | #if DEBUG |
| 441 | printf (" r: operand->X_op = %d\n", operand->X_op); |
| 442 | #endif |
| 443 | continue; |
| 444 | |
| 445 | default: |
| 446 | /* if (! ISALPHA (*args)) |
| 447 | break; */ /* Only immediate values. */ |
| 448 | |
| 449 | if (mask_or_shift) |
| 450 | { |
| 451 | #if DEBUG |
| 452 | printf ("mask_or_shift = %d\n", mask_or_shift); |
| 453 | #endif |
| 454 | reloc = mask_or_shift; |
| 455 | } |
| 456 | mask_or_shift = 0; |
| 457 | |
| 458 | if (strncasecmp (args, "LO(", 3) == 0) |
| 459 | { |
| 460 | #if DEBUG |
| 461 | printf ("reloc_const\n"); |
| 462 | #endif |
| 463 | reloc = BFD_RELOC_LO16; |
| 464 | } |
| 465 | else if (strncasecmp (args, "HI(", 3) == 0) |
| 466 | { |
| 467 | #if DEBUG |
| 468 | printf ("reloc_consth\n"); |
| 469 | #endif |
| 470 | reloc = BFD_RELOC_HI16; |
| 471 | } |
| 472 | |
| 473 | if (*s == '(') |
| 474 | operand->X_op = O_constant; |
| 475 | else if (*s == ')') |
| 476 | s += 1; |
| 477 | #if DEBUG |
| 478 | printf (" default case: operand->X_add_number = %d, *args = %s, *s = %s\n", operand->X_add_number, args, s); |
| 479 | #endif |
| 480 | if (operand->X_op == O_constant) |
| 481 | { |
| 482 | if (reloc == BFD_RELOC_NONE) |
| 483 | { |
| 484 | bfd_vma v, mask; |
| 485 | |
| 486 | mask = 0x3ffffff; |
| 487 | v = abs (operand->X_add_number) & ~ mask; |
| 488 | if (v) |
| 489 | as_bad (_("call/jmp target out of range (1)")); |
| 490 | } |
| 491 | |
| 492 | if (reloc == BFD_RELOC_HI16) |
| 493 | operand->X_add_number = ((operand->X_add_number >> 16) & 0xffff); |
| 494 | |
| 495 | the_insn.pcrel = 0; |
| 496 | encode (insn, &opcode, operand->X_add_number, *args); |
| 497 | /* the_insn.reloc = BFD_RELOC_NONE; */ |
| 498 | continue; |
| 499 | } |
| 500 | |
| 501 | if (reloc == BFD_RELOC_NONE) |
| 502 | the_insn.reloc = BFD_RELOC_32_GOT_PCREL; |
| 503 | else |
| 504 | the_insn.reloc = reloc; |
| 505 | |
| 506 | /* the_insn.reloc = insn->reloc; */ |
| 507 | #if DEBUG |
| 508 | printf (" reloc sym=%d\n", the_insn.reloc); |
| 509 | printf (" BFD_RELOC_NONE=%d\n", BFD_RELOC_NONE); |
| 510 | #endif |
| 511 | the_insn.exp = *operand; |
| 512 | |
| 513 | /* the_insn.reloc_offset = 1; */ |
| 514 | the_insn.pcrel = 1; /* Assume PC-relative jump. */ |
| 515 | |
| 516 | /* FIXME-SOON, Do we figure out whether abs later, after |
| 517 | know sym val? */ |
| 518 | if (reloc == BFD_RELOC_LO16 || reloc == BFD_RELOC_HI16) |
| 519 | the_insn.pcrel = 0; |
| 520 | |
| 521 | encode (insn, &opcode, operand->X_add_number, *args); |
| 522 | continue; |
| 523 | } |
| 524 | |
| 525 | /* Types or values of args don't match. */ |
| 526 | as_bad (_("invalid operands")); |
| 527 | return; |
| 528 | } |
| 529 | } |
| 530 | |
| 531 | char * |
| 532 | md_atof (int type, char * litP, int * sizeP) |
| 533 | { |
| 534 | return ieee_md_atof (type, litP, sizeP, TRUE); |
| 535 | } |
| 536 | |
| 537 | /* Write out big-endian. */ |
| 538 | |
| 539 | void |
| 540 | md_number_to_chars (char *buf, valueT val, int n) |
| 541 | { |
| 542 | number_to_chars_bigendian (buf, val, n); |
| 543 | } |
| 544 | |
| 545 | void |
| 546 | md_apply_fix (fixS * fixP, valueT * val, segT seg ATTRIBUTE_UNUSED) |
| 547 | { |
| 548 | char *buf = fixP->fx_where + fixP->fx_frag->fr_literal; |
| 549 | long t_val; |
| 550 | |
| 551 | t_val = (long) *val; |
| 552 | |
| 553 | #if DEBUG |
| 554 | printf ("md_apply_fix val:%x\n", t_val); |
| 555 | #endif |
| 556 | |
| 557 | fixP->fx_addnumber = t_val; /* Remember value for emit_reloc. */ |
| 558 | |
| 559 | switch (fixP->fx_r_type) |
| 560 | { |
| 561 | case BFD_RELOC_32: /* XXXXXXXX pattern in a word. */ |
| 562 | #if DEBUG |
| 563 | printf ("reloc_const: val=%x\n", t_val); |
| 564 | #endif |
| 565 | buf[0] = t_val >> 24; |
| 566 | buf[1] = t_val >> 16; |
| 567 | buf[2] = t_val >> 8; |
| 568 | buf[3] = t_val; |
| 569 | break; |
| 570 | |
| 571 | case BFD_RELOC_16: /* XXXX0000 pattern in a word. */ |
| 572 | #if DEBUG |
| 573 | printf ("reloc_const: val=%x\n", t_val); |
| 574 | #endif |
| 575 | buf[0] = t_val >> 8; |
| 576 | buf[1] = t_val; |
| 577 | break; |
| 578 | |
| 579 | case BFD_RELOC_8: /* XX000000 pattern in a word. */ |
| 580 | #if DEBUG |
| 581 | printf ("reloc_const: val=%x\n", t_val); |
| 582 | #endif |
| 583 | buf[0] = t_val; |
| 584 | break; |
| 585 | |
| 586 | case BFD_RELOC_LO16: /* 0000XXXX pattern in a word. */ |
| 587 | #if DEBUG |
| 588 | printf ("reloc_const: val=%x\n", t_val); |
| 589 | #endif |
| 590 | buf[2] = t_val >> 8; /* Holds bits 0000XXXX. */ |
| 591 | buf[3] = t_val; |
| 592 | break; |
| 593 | |
| 594 | case BFD_RELOC_HI16: /* 0000XXXX pattern in a word. */ |
| 595 | #if DEBUG |
| 596 | printf ("reloc_consth: val=%x\n", t_val); |
| 597 | #endif |
| 598 | buf[2] = t_val >> 24; /* Holds bits XXXX0000. */ |
| 599 | buf[3] = t_val >> 16; |
| 600 | break; |
| 601 | |
| 602 | case BFD_RELOC_32_GOT_PCREL: /* 0000XXXX pattern in a word. */ |
| 603 | if (!fixP->fx_done) |
| 604 | ; |
| 605 | else if (fixP->fx_pcrel) |
| 606 | { |
| 607 | long v = t_val >> 28; |
| 608 | |
| 609 | if (v != 0 && v != -1) |
| 610 | as_bad_where (fixP->fx_file, fixP->fx_line, |
| 611 | _("call/jmp target out of range (2)")); |
| 612 | } |
| 613 | else |
| 614 | /* This case was supposed to be handled in machine_ip. */ |
| 615 | abort (); |
| 616 | |
| 617 | buf[0] |= (t_val >> 26) & 0x03; /* Holds bits 0FFFFFFC of address. */ |
| 618 | buf[1] = t_val >> 18; |
| 619 | buf[2] = t_val >> 10; |
| 620 | buf[3] = t_val >> 2; |
| 621 | break; |
| 622 | |
| 623 | case BFD_RELOC_VTABLE_INHERIT: |
| 624 | case BFD_RELOC_VTABLE_ENTRY: |
| 625 | fixP->fx_done = 0; |
| 626 | break; |
| 627 | |
| 628 | case BFD_RELOC_NONE: |
| 629 | default: |
| 630 | as_bad (_("bad relocation type: 0x%02x"), fixP->fx_r_type); |
| 631 | break; |
| 632 | } |
| 633 | |
| 634 | if (fixP->fx_addsy == (symbolS *) NULL) |
| 635 | fixP->fx_done = 1; |
| 636 | } |
| 637 | |
| 638 | /* Should never be called for or32. */ |
| 639 | |
| 640 | void |
| 641 | md_create_short_jump (char * ptr ATTRIBUTE_UNUSED, |
| 642 | addressT from_addr ATTRIBUTE_UNUSED, |
| 643 | addressT to_addr ATTRIBUTE_UNUSED, |
| 644 | fragS * frag ATTRIBUTE_UNUSED, |
| 645 | symbolS * to_symbol ATTRIBUTE_UNUSED) |
| 646 | { |
| 647 | as_fatal ("or32_create_short_jmp\n"); |
| 648 | } |
| 649 | |
| 650 | /* Should never be called for or32. */ |
| 651 | |
| 652 | void |
| 653 | md_convert_frag (bfd * headers ATTRIBUTE_UNUSED, |
| 654 | segT seg ATTRIBUTE_UNUSED, |
| 655 | fragS * fragP ATTRIBUTE_UNUSED) |
| 656 | { |
| 657 | as_fatal ("or32_convert_frag\n"); |
| 658 | } |
| 659 | |
| 660 | /* Should never be called for or32. */ |
| 661 | |
| 662 | void |
| 663 | md_create_long_jump (char * ptr ATTRIBUTE_UNUSED, |
| 664 | addressT from_addr ATTRIBUTE_UNUSED, |
| 665 | addressT to_addr ATTRIBUTE_UNUSED, |
| 666 | fragS * frag ATTRIBUTE_UNUSED, |
| 667 | symbolS * to_symbol ATTRIBUTE_UNUSED) |
| 668 | { |
| 669 | as_fatal ("or32_create_long_jump\n"); |
| 670 | } |
| 671 | |
| 672 | /* Should never be called for or32. */ |
| 673 | |
| 674 | int |
| 675 | md_estimate_size_before_relax (fragS * fragP ATTRIBUTE_UNUSED, |
| 676 | segT segtype ATTRIBUTE_UNUSED) |
| 677 | { |
| 678 | as_fatal ("or32_estimate_size_before_relax\n"); |
| 679 | return 0; |
| 680 | } |
| 681 | |
| 682 | /* Translate internal representation of relocation info to target format. |
| 683 | |
| 684 | On sparc/29k: first 4 bytes are normal unsigned long address, next three |
| 685 | bytes are index, most sig. byte first. Byte 7 is broken up with |
| 686 | bit 7 as external, bits 6 & 5 unused, and the lower |
| 687 | five bits as relocation type. Next 4 bytes are long addend. */ |
| 688 | /* Thanx and a tip of the hat to Michael Bloom, mb@ttidca.tti.com. */ |
| 689 | |
| 690 | #ifdef OBJ_AOUT |
| 691 | void |
| 692 | tc_aout_fix_to_chars (char *where, |
| 693 | fixS *fixP, |
| 694 | relax_addressT segment_address_in_file) |
| 695 | { |
| 696 | long r_symbolnum; |
| 697 | |
| 698 | #if DEBUG |
| 699 | printf ("tc_aout_fix_to_chars\n"); |
| 700 | #endif |
| 701 | |
| 702 | know (fixP->fx_r_type < BFD_RELOC_NONE); |
| 703 | know (fixP->fx_addsy != NULL); |
| 704 | |
| 705 | md_number_to_chars |
| 706 | (where, |
| 707 | fixP->fx_frag->fr_address + fixP->fx_where - segment_address_in_file, |
| 708 | 4); |
| 709 | |
| 710 | r_symbolnum = (S_IS_DEFINED (fixP->fx_addsy) |
| 711 | ? S_GET_TYPE (fixP->fx_addsy) |
| 712 | : fixP->fx_addsy->sy_number); |
| 713 | |
| 714 | where[4] = (r_symbolnum >> 16) & 0x0ff; |
| 715 | where[5] = (r_symbolnum >> 8) & 0x0ff; |
| 716 | where[6] = r_symbolnum & 0x0ff; |
| 717 | where[7] = (((!S_IS_DEFINED (fixP->fx_addsy)) << 7) & 0x80) | (0 & 0x60) | (fixP->fx_r_type & 0x1F); |
| 718 | |
| 719 | /* Also easy. */ |
| 720 | md_number_to_chars (&where[8], fixP->fx_addnumber, 4); |
| 721 | } |
| 722 | |
| 723 | #endif /* OBJ_AOUT */ |
| 724 | \f |
| 725 | const char *md_shortopts = ""; |
| 726 | |
| 727 | struct option md_longopts[] = |
| 728 | { |
| 729 | { NULL, no_argument, NULL, 0 } |
| 730 | }; |
| 731 | size_t md_longopts_size = sizeof (md_longopts); |
| 732 | |
| 733 | int |
| 734 | md_parse_option (int c ATTRIBUTE_UNUSED, char * arg ATTRIBUTE_UNUSED) |
| 735 | { |
| 736 | return 0; |
| 737 | } |
| 738 | |
| 739 | void |
| 740 | md_show_usage (FILE * stream ATTRIBUTE_UNUSED) |
| 741 | { |
| 742 | } |
| 743 | \f |
| 744 | /* This is called when a line is unrecognized. This is used to handle |
| 745 | definitions of or32 style local labels. */ |
| 746 | |
| 747 | int |
| 748 | or32_unrecognized_line (int c) |
| 749 | { |
| 750 | int lab; |
| 751 | char *s; |
| 752 | |
| 753 | if (c != '$' |
| 754 | || ! ISDIGIT ((unsigned char) input_line_pointer[0])) |
| 755 | return 0; |
| 756 | |
| 757 | s = input_line_pointer; |
| 758 | |
| 759 | lab = 0; |
| 760 | while (ISDIGIT ((unsigned char) *s)) |
| 761 | { |
| 762 | lab = lab * 10 + *s - '0'; |
| 763 | ++s; |
| 764 | } |
| 765 | |
| 766 | if (*s != ':') |
| 767 | /* Not a label definition. */ |
| 768 | return 0; |
| 769 | |
| 770 | if (dollar_label_defined (lab)) |
| 771 | { |
| 772 | as_bad (_("label \"$%d\" redefined"), lab); |
| 773 | return 0; |
| 774 | } |
| 775 | |
| 776 | define_dollar_label (lab); |
| 777 | colon (dollar_label_name (lab, 0)); |
| 778 | input_line_pointer = s + 1; |
| 779 | |
| 780 | return 1; |
| 781 | } |
| 782 | |
| 783 | /* Default the values of symbols known that should be "predefined". We |
| 784 | don't bother to predefine them unless you actually use one, since there |
| 785 | are a lot of them. */ |
| 786 | |
| 787 | symbolS * |
| 788 | md_undefined_symbol (char *name ATTRIBUTE_UNUSED) |
| 789 | { |
| 790 | return NULL; |
| 791 | } |
| 792 | |
| 793 | /* Parse an operand that is machine-specific. */ |
| 794 | |
| 795 | void |
| 796 | md_operand (expressionS *expressionP) |
| 797 | { |
| 798 | #if DEBUG |
| 799 | printf (" md_operand(input_line_pointer = %s)\n", input_line_pointer); |
| 800 | #endif |
| 801 | |
| 802 | if (input_line_pointer[0] == REGISTER_PREFIX && input_line_pointer[1] == 'r') |
| 803 | { |
| 804 | /* We have a numeric register expression. No biggy. */ |
| 805 | input_line_pointer += 2; /* Skip %r */ |
| 806 | (void) expression (expressionP); |
| 807 | |
| 808 | if (expressionP->X_op != O_constant |
| 809 | || expressionP->X_add_number > 255) |
| 810 | as_bad (_("Invalid expression after %%%%\n")); |
| 811 | expressionP->X_op = O_register; |
| 812 | } |
| 813 | else if (input_line_pointer[0] == '&') |
| 814 | { |
| 815 | /* We are taking the 'address' of a register...this one is not |
| 816 | in the manual, but it *is* in traps/fpsymbol.h! What they |
| 817 | seem to want is the register number, as an absolute number. */ |
| 818 | input_line_pointer++; /* Skip & */ |
| 819 | (void) expression (expressionP); |
| 820 | |
| 821 | if (expressionP->X_op != O_register) |
| 822 | as_bad (_("invalid register in & expression")); |
| 823 | else |
| 824 | expressionP->X_op = O_constant; |
| 825 | } |
| 826 | else if (input_line_pointer[0] == '$' |
| 827 | && ISDIGIT ((unsigned char) input_line_pointer[1])) |
| 828 | { |
| 829 | long lab; |
| 830 | char *name; |
| 831 | symbolS *sym; |
| 832 | |
| 833 | /* This is a local label. */ |
| 834 | ++input_line_pointer; |
| 835 | lab = (long) get_absolute_expression (); |
| 836 | |
| 837 | if (dollar_label_defined (lab)) |
| 838 | { |
| 839 | name = dollar_label_name (lab, 0); |
| 840 | sym = symbol_find (name); |
| 841 | } |
| 842 | else |
| 843 | { |
| 844 | name = dollar_label_name (lab, 1); |
| 845 | sym = symbol_find_or_make (name); |
| 846 | } |
| 847 | |
| 848 | expressionP->X_op = O_symbol; |
| 849 | expressionP->X_add_symbol = sym; |
| 850 | expressionP->X_add_number = 0; |
| 851 | } |
| 852 | else if (input_line_pointer[0] == '$') |
| 853 | { |
| 854 | char *s; |
| 855 | char type; |
| 856 | int fieldnum, fieldlimit; |
| 857 | LITTLENUM_TYPE floatbuf[8]; |
| 858 | |
| 859 | /* $float(), $doubleN(), or $extendN() convert floating values |
| 860 | to integers. */ |
| 861 | s = input_line_pointer; |
| 862 | |
| 863 | ++s; |
| 864 | |
| 865 | fieldnum = 0; |
| 866 | if (strncmp (s, "double", sizeof "double" - 1) == 0) |
| 867 | { |
| 868 | s += sizeof "double" - 1; |
| 869 | type = 'd'; |
| 870 | fieldlimit = 2; |
| 871 | } |
| 872 | else if (strncmp (s, "float", sizeof "float" - 1) == 0) |
| 873 | { |
| 874 | s += sizeof "float" - 1; |
| 875 | type = 'f'; |
| 876 | fieldlimit = 1; |
| 877 | } |
| 878 | else if (strncmp (s, "extend", sizeof "extend" - 1) == 0) |
| 879 | { |
| 880 | s += sizeof "extend" - 1; |
| 881 | type = 'x'; |
| 882 | fieldlimit = 4; |
| 883 | } |
| 884 | else |
| 885 | return; |
| 886 | |
| 887 | if (ISDIGIT (*s)) |
| 888 | { |
| 889 | fieldnum = *s - '0'; |
| 890 | ++s; |
| 891 | } |
| 892 | if (fieldnum >= fieldlimit) |
| 893 | return; |
| 894 | |
| 895 | SKIP_WHITESPACE (); |
| 896 | if (*s != '(') |
| 897 | return; |
| 898 | ++s; |
| 899 | SKIP_WHITESPACE (); |
| 900 | |
| 901 | s = atof_ieee (s, type, floatbuf); |
| 902 | if (s == NULL) |
| 903 | return; |
| 904 | s = s; |
| 905 | |
| 906 | SKIP_WHITESPACE (); |
| 907 | if (*s != ')') |
| 908 | return; |
| 909 | ++s; |
| 910 | SKIP_WHITESPACE (); |
| 911 | |
| 912 | input_line_pointer = s; |
| 913 | expressionP->X_op = O_constant; |
| 914 | expressionP->X_unsigned = 1; |
| 915 | expressionP->X_add_number = ((floatbuf[fieldnum * 2] |
| 916 | << LITTLENUM_NUMBER_OF_BITS) |
| 917 | + floatbuf[fieldnum * 2 + 1]); |
| 918 | } |
| 919 | } |
| 920 | |
| 921 | /* Round up a section size to the appropriate boundary. */ |
| 922 | |
| 923 | valueT |
| 924 | md_section_align (segT segment ATTRIBUTE_UNUSED, valueT size ATTRIBUTE_UNUSED) |
| 925 | { |
| 926 | return size; /* Byte alignment is fine. */ |
| 927 | } |
| 928 | |
| 929 | /* Exactly what point is a PC-relative offset relative TO? |
| 930 | On the 29000, they're relative to the address of the instruction, |
| 931 | which we have set up as the address of the fixup too. */ |
| 932 | |
| 933 | long |
| 934 | md_pcrel_from (fixS *fixP) |
| 935 | { |
| 936 | return fixP->fx_where + fixP->fx_frag->fr_address; |
| 937 | } |
| 938 | |
| 939 | /* Generate a reloc for a fixup. */ |
| 940 | |
| 941 | arelent * |
| 942 | tc_gen_reloc (asection *seg ATTRIBUTE_UNUSED, fixS *fixp) |
| 943 | { |
| 944 | arelent *reloc; |
| 945 | |
| 946 | reloc = xmalloc (sizeof (arelent)); |
| 947 | reloc->sym_ptr_ptr = xmalloc (sizeof (asymbol *)); |
| 948 | *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy); |
| 949 | reloc->address = fixp->fx_frag->fr_address + fixp->fx_where; |
| 950 | /* reloc->address = fixp->fx_frag->fr_address + fixp->fx_where + fixp->fx_addnumber;*/ |
| 951 | reloc->howto = bfd_reloc_type_lookup (stdoutput, fixp->fx_r_type); |
| 952 | |
| 953 | if (reloc->howto == (reloc_howto_type *) NULL) |
| 954 | { |
| 955 | as_bad_where (fixp->fx_file, fixp->fx_line, |
| 956 | _("reloc %d not supported by object file format"), |
| 957 | (int) fixp->fx_r_type); |
| 958 | return NULL; |
| 959 | } |
| 960 | |
| 961 | if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY) |
| 962 | reloc->address = fixp->fx_offset; |
| 963 | |
| 964 | reloc->addend = fixp->fx_addnumber; |
| 965 | return reloc; |
| 966 | } |