| 1 | /* tc-pdp11.c - pdp11-specific - |
| 2 | Copyright (C) 2001-2020 Free Software Foundation, Inc. |
| 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 3, 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, 51 Franklin Street - Fifth Floor, |
| 19 | Boston, MA 02110-1301, USA. */ |
| 20 | |
| 21 | #include "as.h" |
| 22 | #include "safe-ctype.h" |
| 23 | #include "opcode/pdp11.h" |
| 24 | |
| 25 | extern int flonum_gen2vax (int, FLONUM_TYPE * f, LITTLENUM_TYPE *); |
| 26 | |
| 27 | #define TRUE 1 |
| 28 | #define FALSE 0 |
| 29 | |
| 30 | /* A representation for PDP-11 machine code. */ |
| 31 | struct pdp11_code |
| 32 | { |
| 33 | const char *error; |
| 34 | int code; |
| 35 | int additional; /* Is there an additional word? */ |
| 36 | int word; /* Additional word, if any. */ |
| 37 | struct |
| 38 | { |
| 39 | bfd_reloc_code_real_type type; |
| 40 | expressionS exp; |
| 41 | int pc_rel; |
| 42 | } reloc; |
| 43 | }; |
| 44 | |
| 45 | /* Instruction set extensions. |
| 46 | |
| 47 | If you change this from an array to something else, please update |
| 48 | the "PDP-11 instruction set extensions" comment in pdp11.h. */ |
| 49 | int pdp11_extension[PDP11_EXT_NUM]; |
| 50 | |
| 51 | /* Assembly options. */ |
| 52 | |
| 53 | #define ASM_OPT_PIC 1 |
| 54 | #define ASM_OPT_NUM 2 |
| 55 | |
| 56 | int asm_option[ASM_OPT_NUM]; |
| 57 | |
| 58 | /* These chars start a comment anywhere in a source file (except inside |
| 59 | another comment. */ |
| 60 | const char comment_chars[] = "#/"; |
| 61 | |
| 62 | /* These chars only start a comment at the beginning of a line. */ |
| 63 | const char line_comment_chars[] = "#/"; |
| 64 | |
| 65 | const char line_separator_chars[] = ";"; |
| 66 | |
| 67 | /* Chars that can be used to separate mant from exp in floating point nums. */ |
| 68 | const char EXP_CHARS[] = "eE"; |
| 69 | |
| 70 | /* Chars that mean this number is a floating point constant. */ |
| 71 | /* as in 0f123.456. */ |
| 72 | /* or 0H1.234E-12 (see exp chars above). */ |
| 73 | const char FLT_CHARS[] = "dDfF"; |
| 74 | |
| 75 | void pseudo_even (int); |
| 76 | void pseudo_bss (int); |
| 77 | |
| 78 | const pseudo_typeS md_pseudo_table[] = |
| 79 | { |
| 80 | { "bss", pseudo_bss, 0 }, |
| 81 | { "even", pseudo_even, 0 }, |
| 82 | { 0, 0, 0 }, |
| 83 | }; |
| 84 | |
| 85 | static struct hash_control *insn_hash = NULL; |
| 86 | \f |
| 87 | static int |
| 88 | set_option (const char *arg) |
| 89 | { |
| 90 | int yes = 1; |
| 91 | |
| 92 | if (strcmp (arg, "all-extensions") == 0 |
| 93 | || strcmp (arg, "all") == 0) |
| 94 | { |
| 95 | memset (pdp11_extension, ~0, sizeof pdp11_extension); |
| 96 | pdp11_extension[PDP11_NONE] = 0; |
| 97 | return 1; |
| 98 | } |
| 99 | else if (strcmp (arg, "no-extensions") == 0) |
| 100 | { |
| 101 | memset (pdp11_extension, 0, sizeof pdp11_extension); |
| 102 | pdp11_extension[PDP11_BASIC] = 1; |
| 103 | return 1; |
| 104 | } |
| 105 | |
| 106 | if (strncmp (arg, "no-", 3) == 0) |
| 107 | { |
| 108 | yes = 0; |
| 109 | arg += 3; |
| 110 | } |
| 111 | |
| 112 | /* Commercial instructions. */ |
| 113 | if (strcmp (arg, "cis") == 0) |
| 114 | pdp11_extension[PDP11_CIS] = yes; |
| 115 | /* Call supervisor mode. */ |
| 116 | else if (strcmp (arg, "csm") == 0) |
| 117 | pdp11_extension[PDP11_CSM] = yes; |
| 118 | /* Extended instruction set. */ |
| 119 | else if (strcmp (arg, "eis") == 0) |
| 120 | pdp11_extension[PDP11_EIS] = pdp11_extension[PDP11_LEIS] = yes; |
| 121 | /* KEV11 floating-point. */ |
| 122 | else if (strcmp (arg, "fis") == 0 |
| 123 | || strcmp (arg, "kev11") == 0 |
| 124 | || strcmp (arg, "kev-11") == 0) |
| 125 | pdp11_extension[PDP11_FIS] = yes; |
| 126 | /* FP-11 floating-point. */ |
| 127 | else if (strcmp (arg, "fpp") == 0 |
| 128 | || strcmp (arg, "fpu") == 0 |
| 129 | || strcmp (arg, "fp11") == 0 |
| 130 | || strcmp (arg, "fp-11") == 0 |
| 131 | || strcmp (arg, "fpj11") == 0 |
| 132 | || strcmp (arg, "fp-j11") == 0 |
| 133 | || strcmp (arg, "fpj-11") == 0) |
| 134 | pdp11_extension[PDP11_FPP] = yes; |
| 135 | /* Limited extended insns. */ |
| 136 | else if (strcmp (arg, "limited-eis") == 0) |
| 137 | { |
| 138 | pdp11_extension[PDP11_LEIS] = yes; |
| 139 | if (!pdp11_extension[PDP11_LEIS]) |
| 140 | pdp11_extension[PDP11_EIS] = 0; |
| 141 | } |
| 142 | /* Move from processor type. */ |
| 143 | else if (strcmp (arg, "mfpt") == 0) |
| 144 | pdp11_extension[PDP11_MFPT] = yes; |
| 145 | /* Multiprocessor insns: */ |
| 146 | else if (strncmp (arg, "mproc", 5) == 0 |
| 147 | /* TSTSET, WRTLCK */ |
| 148 | || strncmp (arg, "multiproc", 9) == 0) |
| 149 | pdp11_extension[PDP11_MPROC] = yes; |
| 150 | /* Move from/to proc status. */ |
| 151 | else if (strcmp (arg, "mxps") == 0) |
| 152 | pdp11_extension[PDP11_MXPS] = yes; |
| 153 | /* Position-independent code. */ |
| 154 | else if (strcmp (arg, "pic") == 0) |
| 155 | asm_option[ASM_OPT_PIC] = yes; |
| 156 | /* Set priority level. */ |
| 157 | else if (strcmp (arg, "spl") == 0) |
| 158 | pdp11_extension[PDP11_SPL] = yes; |
| 159 | /* Microcode instructions: */ |
| 160 | else if (strcmp (arg, "ucode") == 0 |
| 161 | /* LDUB, MED, XFC */ |
| 162 | || strcmp (arg, "microcode") == 0) |
| 163 | pdp11_extension[PDP11_UCODE] = yes; |
| 164 | else |
| 165 | return 0; |
| 166 | |
| 167 | return 1; |
| 168 | } |
| 169 | |
| 170 | |
| 171 | static void |
| 172 | init_defaults (void) |
| 173 | { |
| 174 | static int first = 1; |
| 175 | |
| 176 | if (first) |
| 177 | { |
| 178 | set_option ("all-extensions"); |
| 179 | set_option ("pic"); |
| 180 | first = 0; |
| 181 | } |
| 182 | } |
| 183 | |
| 184 | void |
| 185 | md_begin (void) |
| 186 | { |
| 187 | int i; |
| 188 | |
| 189 | init_defaults (); |
| 190 | |
| 191 | insn_hash = hash_new (); |
| 192 | if (insn_hash == NULL) |
| 193 | as_fatal (_("Virtual memory exhausted")); |
| 194 | |
| 195 | for (i = 0; i < pdp11_num_opcodes; i++) |
| 196 | hash_insert (insn_hash, pdp11_opcodes[i].name, (void *) (pdp11_opcodes + i)); |
| 197 | for (i = 0; i < pdp11_num_aliases; i++) |
| 198 | hash_insert (insn_hash, pdp11_aliases[i].name, (void *) (pdp11_aliases + i)); |
| 199 | } |
| 200 | |
| 201 | void |
| 202 | md_number_to_chars (char con[], valueT value, int nbytes) |
| 203 | { |
| 204 | /* On a PDP-11, 0x1234 is stored as "\x12\x34", and |
| 205 | 0x12345678 is stored as "\x56\x78\x12\x34". It's |
| 206 | anyone's guess what 0x123456 would be stored like. */ |
| 207 | |
| 208 | switch (nbytes) |
| 209 | { |
| 210 | case 0: |
| 211 | break; |
| 212 | case 1: |
| 213 | con[0] = value & 0xff; |
| 214 | break; |
| 215 | case 2: |
| 216 | con[0] = value & 0xff; |
| 217 | con[1] = (value >> 8) & 0xff; |
| 218 | break; |
| 219 | case 4: |
| 220 | con[0] = (value >> 16) & 0xff; |
| 221 | con[1] = (value >> 24) & 0xff; |
| 222 | con[2] = value & 0xff; |
| 223 | con[3] = (value >> 8) & 0xff; |
| 224 | break; |
| 225 | default: |
| 226 | BAD_CASE (nbytes); |
| 227 | } |
| 228 | } |
| 229 | |
| 230 | /* Fix up some data or instructions after we find out the value of a symbol |
| 231 | that they reference. Knows about order of bytes in address. */ |
| 232 | |
| 233 | void |
| 234 | md_apply_fix (fixS *fixP, |
| 235 | valueT * valP, |
| 236 | segT seg ATTRIBUTE_UNUSED) |
| 237 | { |
| 238 | valueT code; |
| 239 | valueT mask; |
| 240 | valueT val = * valP; |
| 241 | char *buf; |
| 242 | int shift; |
| 243 | int size; |
| 244 | |
| 245 | buf = fixP->fx_where + fixP->fx_frag->fr_literal; |
| 246 | size = fixP->fx_size; |
| 247 | code = md_chars_to_number ((unsigned char *) buf, size); |
| 248 | |
| 249 | switch (fixP->fx_r_type) |
| 250 | { |
| 251 | case BFD_RELOC_8: |
| 252 | mask = 0xff; |
| 253 | shift = 0; |
| 254 | break; |
| 255 | case BFD_RELOC_16: |
| 256 | case BFD_RELOC_16_PCREL: |
| 257 | mask = 0xffff; |
| 258 | shift = 0; |
| 259 | break; |
| 260 | case BFD_RELOC_PDP11_DISP_8_PCREL: |
| 261 | mask = 0x00ff; |
| 262 | shift = 1; |
| 263 | break; |
| 264 | case BFD_RELOC_PDP11_DISP_6_PCREL: |
| 265 | mask = 0x003f; |
| 266 | shift = 1; |
| 267 | val = -val; |
| 268 | break; |
| 269 | default: |
| 270 | BAD_CASE (fixP->fx_r_type); |
| 271 | } |
| 272 | |
| 273 | if (fixP->fx_addsy != NULL) |
| 274 | val += symbol_get_bfdsym (fixP->fx_addsy)->section->vma; |
| 275 | /* *value += fixP->fx_addsy->bsym->section->vma; */ |
| 276 | |
| 277 | code &= ~mask; |
| 278 | code |= (val >> shift) & mask; |
| 279 | number_to_chars_littleendian (buf, code, size); |
| 280 | |
| 281 | if (fixP->fx_addsy == NULL && fixP->fx_pcrel == 0) |
| 282 | fixP->fx_done = 1; |
| 283 | } |
| 284 | |
| 285 | long |
| 286 | md_chars_to_number (unsigned char *con, int nbytes) |
| 287 | { |
| 288 | /* On a PDP-11, 0x1234 is stored as "\x12\x34", and |
| 289 | 0x12345678 is stored as "\x56\x78\x12\x34". It's |
| 290 | anyone's guess what 0x123456 would be stored like. */ |
| 291 | switch (nbytes) |
| 292 | { |
| 293 | case 0: |
| 294 | return 0; |
| 295 | case 1: |
| 296 | return con[0]; |
| 297 | case 2: |
| 298 | return (con[1] << BITS_PER_CHAR) | con[0]; |
| 299 | case 4: |
| 300 | return |
| 301 | (((con[1] << BITS_PER_CHAR) | con[0]) << (2 * BITS_PER_CHAR)) |
| 302 | |((con[3] << BITS_PER_CHAR) | con[2]); |
| 303 | default: |
| 304 | BAD_CASE (nbytes); |
| 305 | return 0; |
| 306 | } |
| 307 | } |
| 308 | \f |
| 309 | static char * |
| 310 | skip_whitespace (char *str) |
| 311 | { |
| 312 | while (*str == ' ' || *str == '\t') |
| 313 | str++; |
| 314 | return str; |
| 315 | } |
| 316 | |
| 317 | static char * |
| 318 | find_whitespace (char *str) |
| 319 | { |
| 320 | while (*str != ' ' && *str != '\t' && *str != 0) |
| 321 | str++; |
| 322 | return str; |
| 323 | } |
| 324 | |
| 325 | static char * |
| 326 | parse_reg (char *str, struct pdp11_code *operand) |
| 327 | { |
| 328 | str = skip_whitespace (str); |
| 329 | if (TOLOWER (*str) == 'r') |
| 330 | { |
| 331 | str++; |
| 332 | switch (*str) |
| 333 | { |
| 334 | case '0': case '1': case '2': case '3': |
| 335 | case '4': case '5': case '6': case '7': |
| 336 | operand->code = *str - '0'; |
| 337 | str++; |
| 338 | break; |
| 339 | default: |
| 340 | operand->error = _("Bad register name"); |
| 341 | return str - 1; |
| 342 | } |
| 343 | } |
| 344 | else if (strncmp (str, "sp", 2) == 0 |
| 345 | || strncmp (str, "SP", 2) == 0) |
| 346 | { |
| 347 | operand->code = 6; |
| 348 | str += 2; |
| 349 | } |
| 350 | else if (strncmp (str, "pc", 2) == 0 |
| 351 | || strncmp (str, "PC", 2) == 0) |
| 352 | { |
| 353 | operand->code = 7; |
| 354 | str += 2; |
| 355 | } |
| 356 | else |
| 357 | operand->error = _("Bad register name"); |
| 358 | |
| 359 | return str; |
| 360 | } |
| 361 | |
| 362 | static char * |
| 363 | parse_ac5 (char *str, struct pdp11_code *operand) |
| 364 | { |
| 365 | str = skip_whitespace (str); |
| 366 | if (strncmp (str, "fr", 2) == 0 |
| 367 | || strncmp (str, "FR", 2) == 0 |
| 368 | || strncmp (str, "ac", 2) == 0 |
| 369 | || strncmp (str, "AC", 2) == 0) |
| 370 | { |
| 371 | str += 2; |
| 372 | switch (*str) |
| 373 | { |
| 374 | case '0': case '1': case '2': case '3': |
| 375 | case '4': case '5': |
| 376 | operand->code = *str - '0'; |
| 377 | str++; |
| 378 | break; |
| 379 | default: |
| 380 | operand->error = _("Bad register name"); |
| 381 | return str - 2; |
| 382 | } |
| 383 | } |
| 384 | else |
| 385 | { |
| 386 | operand->error = _("Bad register name"); |
| 387 | return str; |
| 388 | } |
| 389 | |
| 390 | return str; |
| 391 | } |
| 392 | |
| 393 | static char * |
| 394 | parse_ac (char *str, struct pdp11_code *operand) |
| 395 | { |
| 396 | str = parse_ac5 (str, operand); |
| 397 | if (!operand->error && operand->code > 3) |
| 398 | { |
| 399 | operand->error = _("Bad register name"); |
| 400 | return str - 3; |
| 401 | } |
| 402 | |
| 403 | return str; |
| 404 | } |
| 405 | |
| 406 | static char * |
| 407 | parse_expression (char *str, struct pdp11_code *operand) |
| 408 | { |
| 409 | char *save_input_line_pointer; |
| 410 | segT seg; |
| 411 | |
| 412 | save_input_line_pointer = input_line_pointer; |
| 413 | input_line_pointer = str; |
| 414 | seg = expression (&operand->reloc.exp); |
| 415 | if (seg == NULL) |
| 416 | { |
| 417 | input_line_pointer = save_input_line_pointer; |
| 418 | operand->error = _("Error in expression"); |
| 419 | return str; |
| 420 | } |
| 421 | |
| 422 | str = input_line_pointer; |
| 423 | input_line_pointer = save_input_line_pointer; |
| 424 | |
| 425 | operand->reloc.pc_rel = 0; |
| 426 | |
| 427 | return str; |
| 428 | } |
| 429 | |
| 430 | static char * |
| 431 | parse_op_no_deferred (char *str, struct pdp11_code *operand) |
| 432 | { |
| 433 | LITTLENUM_TYPE literal_float[2]; |
| 434 | |
| 435 | str = skip_whitespace (str); |
| 436 | |
| 437 | switch (*str) |
| 438 | { |
| 439 | case '(': /* (rn) and (rn)+ */ |
| 440 | str = parse_reg (str + 1, operand); |
| 441 | if (operand->error) |
| 442 | return str; |
| 443 | str = skip_whitespace (str); |
| 444 | if (*str != ')') |
| 445 | { |
| 446 | operand->error = _("Missing ')'"); |
| 447 | return str; |
| 448 | } |
| 449 | str++; |
| 450 | if (*str == '+') |
| 451 | { |
| 452 | operand->code |= 020; |
| 453 | str++; |
| 454 | } |
| 455 | else |
| 456 | { |
| 457 | operand->code |= 010; |
| 458 | } |
| 459 | break; |
| 460 | |
| 461 | /* Immediate. */ |
| 462 | case '#': |
| 463 | case '$': |
| 464 | str = parse_expression (str + 1, operand); |
| 465 | if (operand->error) |
| 466 | return str; |
| 467 | operand->additional = TRUE; |
| 468 | operand->word = operand->reloc.exp.X_add_number; |
| 469 | switch (operand->reloc.exp.X_op) |
| 470 | { |
| 471 | case O_constant: |
| 472 | break; |
| 473 | case O_symbol: |
| 474 | case O_add: |
| 475 | case O_subtract: |
| 476 | operand->reloc.type = BFD_RELOC_16; |
| 477 | operand->reloc.pc_rel = 0; |
| 478 | break; |
| 479 | case O_big: |
| 480 | if (operand->reloc.exp.X_add_number > 0) |
| 481 | { |
| 482 | operand->error = _("Error in expression"); |
| 483 | break; |
| 484 | } |
| 485 | /* It's a floating literal... */ |
| 486 | know (operand->reloc.exp.X_add_number < 0); |
| 487 | flonum_gen2vax ('f', &generic_floating_point_number, literal_float); |
| 488 | operand->word = literal_float[0]; |
| 489 | if (literal_float[1] != 0) |
| 490 | as_warn (_("Low order bits truncated in immediate float operand")); |
| 491 | break; |
| 492 | default: |
| 493 | operand->error = _("Error in expression"); |
| 494 | break; |
| 495 | } |
| 496 | operand->code = 027; |
| 497 | break; |
| 498 | |
| 499 | /* label, d(rn), -(rn) */ |
| 500 | default: |
| 501 | { |
| 502 | if (strncmp (str, "-(", 2) == 0) /* -(rn) */ |
| 503 | { |
| 504 | str = parse_reg (str + 2, operand); |
| 505 | if (operand->error) |
| 506 | return str; |
| 507 | str = skip_whitespace (str); |
| 508 | if (*str != ')') |
| 509 | { |
| 510 | operand->error = _("Missing ')'"); |
| 511 | return str; |
| 512 | } |
| 513 | operand->code |= 040; |
| 514 | str++; |
| 515 | break; |
| 516 | } |
| 517 | |
| 518 | str = parse_expression (str, operand); |
| 519 | if (operand->error) |
| 520 | return str; |
| 521 | |
| 522 | str = skip_whitespace (str); |
| 523 | |
| 524 | if (*str != '(') |
| 525 | { |
| 526 | operand->code = 067; |
| 527 | operand->additional = 1; |
| 528 | operand->word = 0; |
| 529 | operand->reloc.type = BFD_RELOC_16_PCREL; |
| 530 | operand->reloc.pc_rel = 1; |
| 531 | break; |
| 532 | } |
| 533 | |
| 534 | /* d(rn) */ |
| 535 | str++; |
| 536 | str = parse_reg (str, operand); |
| 537 | if (operand->error) |
| 538 | return str; |
| 539 | |
| 540 | str = skip_whitespace (str); |
| 541 | |
| 542 | if (*str != ')') |
| 543 | { |
| 544 | operand->error = _("Missing ')'"); |
| 545 | return str; |
| 546 | } |
| 547 | |
| 548 | str++; |
| 549 | operand->additional = TRUE; |
| 550 | operand->code |= 060; |
| 551 | switch (operand->reloc.exp.X_op) |
| 552 | { |
| 553 | case O_symbol: |
| 554 | operand->reloc.type = BFD_RELOC_16; |
| 555 | operand->reloc.pc_rel = 0; |
| 556 | break; |
| 557 | case O_constant: |
| 558 | if ((operand->code & 7) == 7) |
| 559 | { |
| 560 | operand->reloc.pc_rel = 1; |
| 561 | operand->word = operand->reloc.exp.X_add_number; |
| 562 | } |
| 563 | else |
| 564 | operand->word = operand->reloc.exp.X_add_number; |
| 565 | |
| 566 | break; |
| 567 | default: |
| 568 | BAD_CASE (operand->reloc.exp.X_op); |
| 569 | } |
| 570 | break; |
| 571 | } |
| 572 | } |
| 573 | |
| 574 | return str; |
| 575 | } |
| 576 | |
| 577 | static char * |
| 578 | parse_op_noreg (char *str, struct pdp11_code *operand) |
| 579 | { |
| 580 | str = skip_whitespace (str); |
| 581 | operand->error = NULL; |
| 582 | |
| 583 | if (*str == '@' || *str == '*') |
| 584 | { |
| 585 | /* @(Rn) == @0(Rn): Mode 7, Indexed deferred. |
| 586 | Check for auto-increment deferred. */ |
| 587 | if (str[1] == '(' |
| 588 | && str[2] != 0 |
| 589 | && str[3] != 0 |
| 590 | && str[4] != 0 |
| 591 | && str[5] != '+') |
| 592 | { |
| 593 | /* Change implied to explicit index deferred. */ |
| 594 | *str = '0'; |
| 595 | str = parse_op_no_deferred (str, operand); |
| 596 | } |
| 597 | else |
| 598 | { |
| 599 | /* @Rn == (Rn): Register deferred. */ |
| 600 | str = parse_reg (str + 1, operand); |
| 601 | |
| 602 | /* Not @Rn */ |
| 603 | if (operand->error) |
| 604 | { |
| 605 | operand->error = NULL; |
| 606 | str = parse_op_no_deferred (str, operand); |
| 607 | } |
| 608 | } |
| 609 | |
| 610 | if (operand->error) |
| 611 | return str; |
| 612 | |
| 613 | operand->code |= 010; |
| 614 | } |
| 615 | else |
| 616 | str = parse_op_no_deferred (str, operand); |
| 617 | |
| 618 | return str; |
| 619 | } |
| 620 | |
| 621 | static char * |
| 622 | parse_op (char *str, struct pdp11_code *operand) |
| 623 | { |
| 624 | str = skip_whitespace (str); |
| 625 | |
| 626 | str = parse_reg (str, operand); |
| 627 | if (!operand->error) |
| 628 | return str; |
| 629 | |
| 630 | operand->error = NULL; |
| 631 | parse_ac5 (str, operand); |
| 632 | if (!operand->error) |
| 633 | { |
| 634 | operand->error = _("Float AC not legal as integer operand"); |
| 635 | return str; |
| 636 | } |
| 637 | |
| 638 | return parse_op_noreg (str, operand); |
| 639 | } |
| 640 | |
| 641 | static char * |
| 642 | parse_fop (char *str, struct pdp11_code *operand) |
| 643 | { |
| 644 | str = skip_whitespace (str); |
| 645 | |
| 646 | str = parse_ac5 (str, operand); |
| 647 | if (!operand->error) |
| 648 | return str; |
| 649 | |
| 650 | operand->error = NULL; |
| 651 | parse_reg (str, operand); |
| 652 | if (!operand->error) |
| 653 | { |
| 654 | operand->error = _("General register not legal as float operand"); |
| 655 | return str; |
| 656 | } |
| 657 | |
| 658 | return parse_op_noreg (str, operand); |
| 659 | } |
| 660 | |
| 661 | static char * |
| 662 | parse_separator (char *str, int *error) |
| 663 | { |
| 664 | str = skip_whitespace (str); |
| 665 | *error = (*str != ','); |
| 666 | if (!*error) |
| 667 | str++; |
| 668 | return str; |
| 669 | } |
| 670 | |
| 671 | void |
| 672 | md_assemble (char *instruction_string) |
| 673 | { |
| 674 | const struct pdp11_opcode *op; |
| 675 | struct pdp11_code insn, op1, op2; |
| 676 | int error; |
| 677 | int size; |
| 678 | const char *err = NULL; |
| 679 | char *str; |
| 680 | char *p; |
| 681 | char c; |
| 682 | |
| 683 | str = skip_whitespace (instruction_string); |
| 684 | p = find_whitespace (str); |
| 685 | if (p - str == 0) |
| 686 | { |
| 687 | as_bad (_("No instruction found")); |
| 688 | return; |
| 689 | } |
| 690 | |
| 691 | c = *p; |
| 692 | *p = '\0'; |
| 693 | op = (struct pdp11_opcode *)hash_find (insn_hash, str); |
| 694 | *p = c; |
| 695 | if (op == 0) |
| 696 | { |
| 697 | as_bad (_("Unknown instruction '%s'"), str); |
| 698 | return; |
| 699 | } |
| 700 | |
| 701 | if (!pdp11_extension[op->extension]) |
| 702 | { |
| 703 | as_warn (_("Unsupported instruction set extension: %s"), op->name); |
| 704 | return; |
| 705 | } |
| 706 | |
| 707 | insn.error = NULL; |
| 708 | insn.code = op->opcode; |
| 709 | insn.reloc.type = BFD_RELOC_NONE; |
| 710 | op1.error = NULL; |
| 711 | op1.additional = FALSE; |
| 712 | op1.reloc.type = BFD_RELOC_NONE; |
| 713 | op2.error = NULL; |
| 714 | op2.additional = FALSE; |
| 715 | op2.reloc.type = BFD_RELOC_NONE; |
| 716 | |
| 717 | str = p; |
| 718 | size = 2; |
| 719 | |
| 720 | switch (op->type) |
| 721 | { |
| 722 | case PDP11_OPCODE_NO_OPS: |
| 723 | str = skip_whitespace (str); |
| 724 | break; |
| 725 | |
| 726 | case PDP11_OPCODE_IMM3: |
| 727 | case PDP11_OPCODE_IMM6: |
| 728 | case PDP11_OPCODE_IMM8: |
| 729 | str = skip_whitespace (str); |
| 730 | if (*str == '#' || *str == '$') |
| 731 | str++; |
| 732 | str = parse_expression (str, &op1); |
| 733 | if (op1.error) |
| 734 | break; |
| 735 | if (op1.reloc.exp.X_op != O_constant || op1.reloc.type != BFD_RELOC_NONE) |
| 736 | { |
| 737 | op1.error = _("operand is not an absolute constant"); |
| 738 | break; |
| 739 | } |
| 740 | switch (op->type) |
| 741 | { |
| 742 | case PDP11_OPCODE_IMM3: |
| 743 | if (op1.reloc.exp.X_add_number & ~7) |
| 744 | { |
| 745 | op1.error = _("3-bit immediate out of range"); |
| 746 | break; |
| 747 | } |
| 748 | break; |
| 749 | case PDP11_OPCODE_IMM6: |
| 750 | if (op1.reloc.exp.X_add_number & ~0x3f) |
| 751 | { |
| 752 | op1.error = _("6-bit immediate out of range"); |
| 753 | break; |
| 754 | } |
| 755 | break; |
| 756 | case PDP11_OPCODE_IMM8: |
| 757 | if (op1.reloc.exp.X_add_number & ~0xff) |
| 758 | { |
| 759 | op1.error = _("8-bit immediate out of range"); |
| 760 | break; |
| 761 | } |
| 762 | break; |
| 763 | } |
| 764 | insn.code |= op1.reloc.exp.X_add_number; |
| 765 | break; |
| 766 | |
| 767 | case PDP11_OPCODE_DISPL: |
| 768 | { |
| 769 | char *new_pointer; |
| 770 | new_pointer = parse_expression (str, &op1); |
| 771 | op1.code = 0; |
| 772 | op1.reloc.pc_rel = 1; |
| 773 | op1.reloc.type = BFD_RELOC_PDP11_DISP_8_PCREL; |
| 774 | if (op1.reloc.exp.X_op != O_symbol) |
| 775 | { |
| 776 | op1.error = _("Symbol expected"); |
| 777 | break; |
| 778 | } |
| 779 | if (op1.code & ~0xff) |
| 780 | { |
| 781 | err = _("8-bit displacement out of range"); |
| 782 | break; |
| 783 | } |
| 784 | str = new_pointer; |
| 785 | insn.code |= op1.code; |
| 786 | insn.reloc = op1.reloc; |
| 787 | } |
| 788 | break; |
| 789 | |
| 790 | case PDP11_OPCODE_REG: |
| 791 | str = parse_reg (str, &op1); |
| 792 | if (op1.error) |
| 793 | break; |
| 794 | insn.code |= op1.code; |
| 795 | break; |
| 796 | |
| 797 | case PDP11_OPCODE_OP: |
| 798 | str = parse_op (str, &op1); |
| 799 | if (op1.error) |
| 800 | break; |
| 801 | insn.code |= op1.code; |
| 802 | if (op1.additional) |
| 803 | size += 2; |
| 804 | break; |
| 805 | |
| 806 | case PDP11_OPCODE_FOP: |
| 807 | str = parse_fop (str, &op1); |
| 808 | if (op1.error) |
| 809 | break; |
| 810 | insn.code |= op1.code; |
| 811 | if (op1.additional) |
| 812 | size += 2; |
| 813 | break; |
| 814 | |
| 815 | case PDP11_OPCODE_REG_OP: |
| 816 | str = parse_reg (str, &op2); |
| 817 | if (op2.error) |
| 818 | break; |
| 819 | insn.code |= op2.code << 6; |
| 820 | str = parse_separator (str, &error); |
| 821 | if (error) |
| 822 | { |
| 823 | op2.error = _("Missing ','"); |
| 824 | break; |
| 825 | } |
| 826 | str = parse_op (str, &op1); |
| 827 | if (op1.error) |
| 828 | break; |
| 829 | insn.code |= op1.code; |
| 830 | if (op1.additional) |
| 831 | size += 2; |
| 832 | break; |
| 833 | |
| 834 | case PDP11_OPCODE_REG_OP_REV: |
| 835 | str = parse_op (str, &op1); |
| 836 | if (op1.error) |
| 837 | break; |
| 838 | insn.code |= op1.code; |
| 839 | if (op1.additional) |
| 840 | size += 2; |
| 841 | str = parse_separator (str, &error); |
| 842 | if (error) |
| 843 | { |
| 844 | op2.error = _("Missing ','"); |
| 845 | break; |
| 846 | } |
| 847 | str = parse_reg (str, &op2); |
| 848 | if (op2.error) |
| 849 | break; |
| 850 | insn.code |= op2.code << 6; |
| 851 | break; |
| 852 | |
| 853 | case PDP11_OPCODE_AC_FOP: |
| 854 | str = parse_ac (str, &op2); |
| 855 | if (op2.error) |
| 856 | break; |
| 857 | insn.code |= op2.code << 6; |
| 858 | str = parse_separator (str, &error); |
| 859 | if (error) |
| 860 | { |
| 861 | op1.error = _("Missing ','"); |
| 862 | break; |
| 863 | } |
| 864 | str = parse_fop (str, &op1); |
| 865 | if (op1.error) |
| 866 | break; |
| 867 | insn.code |= op1.code; |
| 868 | if (op1.additional) |
| 869 | size += 2; |
| 870 | break; |
| 871 | |
| 872 | case PDP11_OPCODE_FOP_AC: |
| 873 | str = parse_fop (str, &op1); |
| 874 | if (op1.error) |
| 875 | break; |
| 876 | insn.code |= op1.code; |
| 877 | if (op1.additional) |
| 878 | size += 2; |
| 879 | str = parse_separator (str, &error); |
| 880 | if (error) |
| 881 | { |
| 882 | op1.error = _("Missing ','"); |
| 883 | break; |
| 884 | } |
| 885 | str = parse_ac (str, &op2); |
| 886 | if (op2.error) |
| 887 | break; |
| 888 | insn.code |= op2.code << 6; |
| 889 | break; |
| 890 | |
| 891 | case PDP11_OPCODE_AC_OP: |
| 892 | str = parse_ac (str, &op2); |
| 893 | if (op2.error) |
| 894 | break; |
| 895 | insn.code |= op2.code << 6; |
| 896 | str = parse_separator (str, &error); |
| 897 | if (error) |
| 898 | { |
| 899 | op1.error = _("Missing ','"); |
| 900 | break; |
| 901 | } |
| 902 | str = parse_op (str, &op1); |
| 903 | if (op1.error) |
| 904 | break; |
| 905 | insn.code |= op1.code; |
| 906 | if (op1.additional) |
| 907 | size += 2; |
| 908 | break; |
| 909 | |
| 910 | case PDP11_OPCODE_OP_AC: |
| 911 | str = parse_op (str, &op1); |
| 912 | if (op1.error) |
| 913 | break; |
| 914 | insn.code |= op1.code; |
| 915 | if (op1.additional) |
| 916 | size += 2; |
| 917 | str = parse_separator (str, &error); |
| 918 | if (error) |
| 919 | { |
| 920 | op1.error = _("Missing ','"); |
| 921 | break; |
| 922 | } |
| 923 | str = parse_ac (str, &op2); |
| 924 | if (op2.error) |
| 925 | break; |
| 926 | insn.code |= op2.code << 6; |
| 927 | break; |
| 928 | |
| 929 | case PDP11_OPCODE_OP_OP: |
| 930 | str = parse_op (str, &op1); |
| 931 | if (op1.error) |
| 932 | break; |
| 933 | insn.code |= op1.code << 6; |
| 934 | if (op1.additional) |
| 935 | size += 2; |
| 936 | str = parse_separator (str, &error); |
| 937 | if (error) |
| 938 | { |
| 939 | op2.error = _("Missing ','"); |
| 940 | break; |
| 941 | } |
| 942 | str = parse_op (str, &op2); |
| 943 | if (op2.error) |
| 944 | break; |
| 945 | insn.code |= op2.code; |
| 946 | if (op2.additional) |
| 947 | size += 2; |
| 948 | break; |
| 949 | |
| 950 | case PDP11_OPCODE_REG_DISPL: |
| 951 | { |
| 952 | char *new_pointer; |
| 953 | str = parse_reg (str, &op2); |
| 954 | if (op2.error) |
| 955 | break; |
| 956 | insn.code |= op2.code << 6; |
| 957 | str = parse_separator (str, &error); |
| 958 | if (error) |
| 959 | { |
| 960 | op1.error = _("Missing ','"); |
| 961 | break; |
| 962 | } |
| 963 | new_pointer = parse_expression (str, &op1); |
| 964 | op1.code = 0; |
| 965 | op1.reloc.pc_rel = 1; |
| 966 | op1.reloc.type = BFD_RELOC_PDP11_DISP_6_PCREL; |
| 967 | if (op1.reloc.exp.X_op != O_symbol) |
| 968 | { |
| 969 | op1.error = _("Symbol expected"); |
| 970 | break; |
| 971 | } |
| 972 | if (op1.code & ~0x3f) |
| 973 | { |
| 974 | err = _("6-bit displacement out of range"); |
| 975 | break; |
| 976 | } |
| 977 | str = new_pointer; |
| 978 | insn.code |= op1.code; |
| 979 | insn.reloc = op1.reloc; |
| 980 | } |
| 981 | break; |
| 982 | |
| 983 | default: |
| 984 | BAD_CASE (op->type); |
| 985 | } |
| 986 | |
| 987 | if (op1.error) |
| 988 | err = op1.error; |
| 989 | else if (op2.error) |
| 990 | err = op2.error; |
| 991 | else |
| 992 | { |
| 993 | str = skip_whitespace (str); |
| 994 | if (*str) |
| 995 | err = _("Too many operands"); |
| 996 | } |
| 997 | |
| 998 | { |
| 999 | char *to = NULL; |
| 1000 | |
| 1001 | if (err) |
| 1002 | { |
| 1003 | as_bad ("%s", err); |
| 1004 | return; |
| 1005 | } |
| 1006 | |
| 1007 | to = frag_more (size); |
| 1008 | |
| 1009 | md_number_to_chars (to, insn.code, 2); |
| 1010 | if (insn.reloc.type != BFD_RELOC_NONE) |
| 1011 | fix_new_exp (frag_now, to - frag_now->fr_literal, 2, |
| 1012 | &insn.reloc.exp, insn.reloc.pc_rel, insn.reloc.type); |
| 1013 | to += 2; |
| 1014 | |
| 1015 | if (op1.additional) |
| 1016 | { |
| 1017 | md_number_to_chars (to, op1.word, 2); |
| 1018 | if (op1.reloc.type != BFD_RELOC_NONE) |
| 1019 | fix_new_exp (frag_now, to - frag_now->fr_literal, 2, |
| 1020 | &op1.reloc.exp, op1.reloc.pc_rel, op1.reloc.type); |
| 1021 | to += 2; |
| 1022 | } |
| 1023 | |
| 1024 | if (op2.additional) |
| 1025 | { |
| 1026 | md_number_to_chars (to, op2.word, 2); |
| 1027 | if (op2.reloc.type != BFD_RELOC_NONE) |
| 1028 | fix_new_exp (frag_now, to - frag_now->fr_literal, 2, |
| 1029 | &op2.reloc.exp, op2.reloc.pc_rel, op2.reloc.type); |
| 1030 | } |
| 1031 | } |
| 1032 | } |
| 1033 | |
| 1034 | int |
| 1035 | md_estimate_size_before_relax (fragS *fragP ATTRIBUTE_UNUSED, |
| 1036 | segT segment ATTRIBUTE_UNUSED) |
| 1037 | { |
| 1038 | return 0; |
| 1039 | } |
| 1040 | |
| 1041 | void |
| 1042 | md_convert_frag (bfd *headers ATTRIBUTE_UNUSED, |
| 1043 | segT seg ATTRIBUTE_UNUSED, |
| 1044 | fragS *fragP ATTRIBUTE_UNUSED) |
| 1045 | { |
| 1046 | } |
| 1047 | |
| 1048 | int md_short_jump_size = 2; |
| 1049 | int md_long_jump_size = 4; |
| 1050 | |
| 1051 | void |
| 1052 | md_create_short_jump (char *ptr ATTRIBUTE_UNUSED, |
| 1053 | addressT from_addr ATTRIBUTE_UNUSED, |
| 1054 | addressT to_addr ATTRIBUTE_UNUSED, |
| 1055 | fragS *frag ATTRIBUTE_UNUSED, |
| 1056 | symbolS *to_symbol ATTRIBUTE_UNUSED) |
| 1057 | { |
| 1058 | } |
| 1059 | |
| 1060 | void |
| 1061 | md_create_long_jump (char *ptr ATTRIBUTE_UNUSED, |
| 1062 | addressT from_addr ATTRIBUTE_UNUSED, |
| 1063 | addressT to_addr ATTRIBUTE_UNUSED, |
| 1064 | fragS *frag ATTRIBUTE_UNUSED, |
| 1065 | symbolS *to_symbol ATTRIBUTE_UNUSED) |
| 1066 | { |
| 1067 | } |
| 1068 | |
| 1069 | static int |
| 1070 | set_cpu_model (const char *arg) |
| 1071 | { |
| 1072 | char buf[4]; |
| 1073 | char *model = buf; |
| 1074 | |
| 1075 | if (arg[0] == 'k') |
| 1076 | arg++; |
| 1077 | |
| 1078 | *model++ = *arg++; |
| 1079 | |
| 1080 | if (strchr ("abdx", model[-1]) == NULL) |
| 1081 | return 0; |
| 1082 | |
| 1083 | if (model[-1] == 'd') |
| 1084 | { |
| 1085 | if (arg[0] == 'f' || arg[0] == 'j') |
| 1086 | model[-1] = *arg++; |
| 1087 | } |
| 1088 | else if (model[-1] == 'x') |
| 1089 | { |
| 1090 | if (arg[0] == 't') |
| 1091 | model[-1] = *arg++; |
| 1092 | } |
| 1093 | |
| 1094 | if (arg[0] == '-') |
| 1095 | arg++; |
| 1096 | |
| 1097 | if (strncmp (arg, "11", 2) != 0) |
| 1098 | return 0; |
| 1099 | arg += 2; |
| 1100 | |
| 1101 | if (arg[0] == '-') |
| 1102 | { |
| 1103 | if (*++arg == 0) |
| 1104 | return 0; |
| 1105 | } |
| 1106 | |
| 1107 | /* Allow up to two revision letters. */ |
| 1108 | if (arg[0] != 0) |
| 1109 | *model++ = *arg++; |
| 1110 | if (arg[0] != 0) |
| 1111 | *model++ = *arg++; |
| 1112 | |
| 1113 | *model++ = 0; |
| 1114 | |
| 1115 | set_option ("no-extensions"); |
| 1116 | |
| 1117 | /* KA11 (11/15/20). */ |
| 1118 | if (strncmp (buf, "a", 1) == 0) |
| 1119 | return 1; /* No extensions. */ |
| 1120 | |
| 1121 | /* KB11 (11/45/50/55/70). */ |
| 1122 | else if (strncmp (buf, "b", 1) == 0) |
| 1123 | return set_option ("eis") && set_option ("spl"); |
| 1124 | |
| 1125 | /* KD11-A (11/35/40). */ |
| 1126 | else if (strncmp (buf, "da", 2) == 0) |
| 1127 | return set_option ("limited-eis"); |
| 1128 | |
| 1129 | /* KD11-B (11/05/10). */ |
| 1130 | else if (strncmp (buf, "db", 2) == 0 |
| 1131 | /* KD11-D (11/04). */ |
| 1132 | || strncmp (buf, "dd", 2) == 0) |
| 1133 | return 1; /* no extensions */ |
| 1134 | |
| 1135 | /* KD11-E (11/34). */ |
| 1136 | else if (strncmp (buf, "de", 2) == 0) |
| 1137 | return set_option ("eis") && set_option ("mxps"); |
| 1138 | |
| 1139 | /* KD11-F (11/03). */ |
| 1140 | else if (strncmp (buf, "df", 2) == 0 |
| 1141 | /* KD11-H (11/03). */ |
| 1142 | || strncmp (buf, "dh", 2) == 0 |
| 1143 | /* KD11-Q (11/03). */ |
| 1144 | || strncmp (buf, "dq", 2) == 0) |
| 1145 | return set_option ("limited-eis") && set_option ("mxps"); |
| 1146 | |
| 1147 | /* KD11-K (11/60). */ |
| 1148 | else if (strncmp (buf, "dk", 2) == 0) |
| 1149 | return set_option ("eis") |
| 1150 | && set_option ("mxps") |
| 1151 | && set_option ("ucode"); |
| 1152 | |
| 1153 | /* KD11-Z (11/44). */ |
| 1154 | else if (strncmp (buf, "dz", 2) == 0) |
| 1155 | return set_option ("csm") |
| 1156 | && set_option ("eis") |
| 1157 | && set_option ("mfpt") |
| 1158 | && set_option ("mxps") |
| 1159 | && set_option ("spl"); |
| 1160 | |
| 1161 | /* F11 (11/23/24). */ |
| 1162 | else if (strncmp (buf, "f", 1) == 0) |
| 1163 | return set_option ("eis") |
| 1164 | && set_option ("mfpt") |
| 1165 | && set_option ("mxps"); |
| 1166 | |
| 1167 | /* J11 (11/53/73/83/84/93/94). */ |
| 1168 | else if (strncmp (buf, "j", 1) == 0) |
| 1169 | return set_option ("csm") |
| 1170 | && set_option ("eis") |
| 1171 | && set_option ("mfpt") |
| 1172 | && set_option ("multiproc") |
| 1173 | && set_option ("mxps") |
| 1174 | && set_option ("spl"); |
| 1175 | |
| 1176 | /* T11 (11/21). */ |
| 1177 | else if (strncmp (buf, "t", 1) == 0) |
| 1178 | return set_option ("limited-eis") |
| 1179 | && set_option ("mxps"); |
| 1180 | |
| 1181 | else |
| 1182 | return 0; |
| 1183 | } |
| 1184 | |
| 1185 | static int |
| 1186 | set_machine_model (const char *arg) |
| 1187 | { |
| 1188 | if (strncmp (arg, "pdp-11/", 7) != 0 |
| 1189 | && strncmp (arg, "pdp11/", 6) != 0 |
| 1190 | && strncmp (arg, "11/", 3) != 0) |
| 1191 | return 0; |
| 1192 | |
| 1193 | if (strncmp (arg, "pdp", 3) == 0) |
| 1194 | arg += 3; |
| 1195 | if (arg[0] == '-') |
| 1196 | arg++; |
| 1197 | if (strncmp (arg, "11/", 3) == 0) |
| 1198 | arg += 3; |
| 1199 | |
| 1200 | if (strcmp (arg, "03") == 0) |
| 1201 | return set_cpu_model ("kd11f"); |
| 1202 | |
| 1203 | else if (strcmp (arg, "04") == 0) |
| 1204 | return set_cpu_model ("kd11d"); |
| 1205 | |
| 1206 | else if (strcmp (arg, "05") == 0 |
| 1207 | || strcmp (arg, "10") == 0) |
| 1208 | return set_cpu_model ("kd11b"); |
| 1209 | |
| 1210 | else if (strcmp (arg, "15") == 0 |
| 1211 | || strcmp (arg, "20") == 0) |
| 1212 | return set_cpu_model ("ka11"); |
| 1213 | |
| 1214 | else if (strcmp (arg, "21") == 0) |
| 1215 | return set_cpu_model ("t11"); |
| 1216 | |
| 1217 | else if (strcmp (arg, "23") == 0 |
| 1218 | || strcmp (arg, "24") == 0) |
| 1219 | return set_cpu_model ("f11"); |
| 1220 | |
| 1221 | else if (strcmp (arg, "34") == 0 |
| 1222 | || strcmp (arg, "34a") == 0) |
| 1223 | return set_cpu_model ("kd11e"); |
| 1224 | |
| 1225 | else if (strcmp (arg, "35") == 0 |
| 1226 | || strcmp (arg, "40") == 0) |
| 1227 | return set_cpu_model ("kd11da"); |
| 1228 | |
| 1229 | else if (strcmp (arg, "44") == 0) |
| 1230 | return set_cpu_model ("kd11dz"); |
| 1231 | |
| 1232 | else if (strcmp (arg, "45") == 0 |
| 1233 | || strcmp (arg, "50") == 0 |
| 1234 | || strcmp (arg, "55") == 0 |
| 1235 | || strcmp (arg, "70") == 0) |
| 1236 | return set_cpu_model ("kb11"); |
| 1237 | |
| 1238 | else if (strcmp (arg, "60") == 0) |
| 1239 | return set_cpu_model ("kd11k"); |
| 1240 | |
| 1241 | else if (strcmp (arg, "53") == 0 |
| 1242 | || strcmp (arg, "73") == 0 |
| 1243 | || strcmp (arg, "83") == 0 |
| 1244 | || strcmp (arg, "84") == 0 |
| 1245 | || strcmp (arg, "93") == 0 |
| 1246 | || strcmp (arg, "94") == 0) |
| 1247 | return set_cpu_model ("j11") |
| 1248 | && set_option ("fpp"); |
| 1249 | |
| 1250 | else |
| 1251 | return 0; |
| 1252 | } |
| 1253 | |
| 1254 | const char *md_shortopts = "m:"; |
| 1255 | |
| 1256 | struct option md_longopts[] = |
| 1257 | { |
| 1258 | #define OPTION_CPU 257 |
| 1259 | { "cpu", required_argument, NULL, OPTION_CPU }, |
| 1260 | #define OPTION_MACHINE 258 |
| 1261 | { "machine", required_argument, NULL, OPTION_MACHINE }, |
| 1262 | #define OPTION_PIC 259 |
| 1263 | { "pic", no_argument, NULL, OPTION_PIC }, |
| 1264 | { NULL, no_argument, NULL, 0 } |
| 1265 | }; |
| 1266 | |
| 1267 | size_t md_longopts_size = sizeof (md_longopts); |
| 1268 | |
| 1269 | /* Invocation line includes a switch not recognized by the base assembler. |
| 1270 | See if it's a processor-specific option. */ |
| 1271 | |
| 1272 | int |
| 1273 | md_parse_option (int c, const char *arg) |
| 1274 | { |
| 1275 | init_defaults (); |
| 1276 | |
| 1277 | switch (c) |
| 1278 | { |
| 1279 | case 'm': |
| 1280 | if (set_option (arg)) |
| 1281 | return 1; |
| 1282 | if (set_cpu_model (arg)) |
| 1283 | return 1; |
| 1284 | if (set_machine_model (arg)) |
| 1285 | return 1; |
| 1286 | break; |
| 1287 | |
| 1288 | case OPTION_CPU: |
| 1289 | if (set_cpu_model (arg)) |
| 1290 | return 1; |
| 1291 | break; |
| 1292 | |
| 1293 | case OPTION_MACHINE: |
| 1294 | if (set_machine_model (arg)) |
| 1295 | return 1; |
| 1296 | break; |
| 1297 | |
| 1298 | case OPTION_PIC: |
| 1299 | if (set_option ("pic")) |
| 1300 | return 1; |
| 1301 | break; |
| 1302 | |
| 1303 | default: |
| 1304 | break; |
| 1305 | } |
| 1306 | |
| 1307 | return 0; |
| 1308 | } |
| 1309 | |
| 1310 | void |
| 1311 | md_show_usage (FILE *stream) |
| 1312 | { |
| 1313 | fprintf (stream, "\ |
| 1314 | \n\ |
| 1315 | PDP-11 instruction set extensions:\n\ |
| 1316 | \n\ |
| 1317 | -m(no-)cis allow (disallow) commercial instruction set\n\ |
| 1318 | -m(no-)csm allow (disallow) CSM instruction\n\ |
| 1319 | -m(no-)eis allow (disallow) full extended instruction set\n\ |
| 1320 | -m(no-)fis allow (disallow) KEV11 floating-point instructions\n\ |
| 1321 | -m(no-)fpp allow (disallow) FP-11 floating-point instructions\n\ |
| 1322 | -m(no-)fpu allow (disallow) FP-11 floating-point instructions\n\ |
| 1323 | -m(no-)limited-eis allow (disallow) limited extended instruction set\n\ |
| 1324 | -m(no-)mfpt allow (disallow) processor type instruction\n\ |
| 1325 | -m(no-)multiproc allow (disallow) multiprocessor instructions\n\ |
| 1326 | -m(no-)mxps allow (disallow) processor status instructions\n\ |
| 1327 | -m(no-)spl allow (disallow) SPL instruction\n\ |
| 1328 | -m(no-)ucode allow (disallow) microcode instructions\n\ |
| 1329 | -mall-extensions allow all instruction set extensions\n\ |
| 1330 | (this is the default)\n\ |
| 1331 | -mno-extensions disallow all instruction set extensions\n\ |
| 1332 | -pic generate position-independent code\n\ |
| 1333 | \n\ |
| 1334 | PDP-11 CPU model options:\n\ |
| 1335 | \n\ |
| 1336 | -mka11* KA11 CPU. base line instruction set only\n\ |
| 1337 | -mkb11* KB11 CPU. enable full EIS and SPL\n\ |
| 1338 | -mkd11a* KD11-A CPU. enable limited EIS\n\ |
| 1339 | -mkd11b* KD11-B CPU. base line instruction set only\n\ |
| 1340 | -mkd11d* KD11-D CPU. base line instruction set only\n\ |
| 1341 | -mkd11e* KD11-E CPU. enable full EIS, MTPS, and MFPS\n\ |
| 1342 | -mkd11f* KD11-F CPU. enable limited EIS, MTPS, and MFPS\n\ |
| 1343 | -mkd11h* KD11-H CPU. enable limited EIS, MTPS, and MFPS\n\ |
| 1344 | -mkd11q* KD11-Q CPU. enable limited EIS, MTPS, and MFPS\n\ |
| 1345 | -mkd11k* KD11-K CPU. enable full EIS, MTPS, MFPS, LDUB, MED,\n\ |
| 1346 | XFC, and MFPT\n\ |
| 1347 | -mkd11z* KD11-Z CPU. enable full EIS, MTPS, MFPS, MFPT, SPL,\n\ |
| 1348 | and CSM\n\ |
| 1349 | -mf11* F11 CPU. enable full EIS, MFPS, MTPS, and MFPT\n\ |
| 1350 | -mj11* J11 CPU. enable full EIS, MTPS, MFPS, MFPT, SPL,\n\ |
| 1351 | CSM, TSTSET, and WRTLCK\n\ |
| 1352 | -mt11* T11 CPU. enable limited EIS, MTPS, and MFPS\n\ |
| 1353 | \n\ |
| 1354 | PDP-11 machine model options:\n\ |
| 1355 | \n\ |
| 1356 | -m11/03 same as -mkd11f\n\ |
| 1357 | -m11/04 same as -mkd11d\n\ |
| 1358 | -m11/05 same as -mkd11b\n\ |
| 1359 | -m11/10 same as -mkd11b\n\ |
| 1360 | -m11/15 same as -mka11\n\ |
| 1361 | -m11/20 same as -mka11\n\ |
| 1362 | -m11/21 same as -mt11\n\ |
| 1363 | -m11/23 same as -mf11\n\ |
| 1364 | -m11/24 same as -mf11\n\ |
| 1365 | -m11/34 same as -mkd11e\n\ |
| 1366 | -m11/34a same as -mkd11e -mfpp\n\ |
| 1367 | -m11/35 same as -mkd11a\n\ |
| 1368 | -m11/40 same as -mkd11a\n\ |
| 1369 | -m11/44 same as -mkd11z\n\ |
| 1370 | -m11/45 same as -mkb11\n\ |
| 1371 | -m11/50 same as -mkb11\n\ |
| 1372 | -m11/53 same as -mj11\n\ |
| 1373 | -m11/55 same as -mkb11\n\ |
| 1374 | -m11/60 same as -mkd11k\n\ |
| 1375 | -m11/70 same as -mkb11\n\ |
| 1376 | -m11/73 same as -mj11\n\ |
| 1377 | -m11/83 same as -mj11\n\ |
| 1378 | -m11/84 same as -mj11\n\ |
| 1379 | -m11/93 same as -mj11\n\ |
| 1380 | -m11/94 same as -mj11\n\ |
| 1381 | "); |
| 1382 | } |
| 1383 | |
| 1384 | symbolS * |
| 1385 | md_undefined_symbol (char *name ATTRIBUTE_UNUSED) |
| 1386 | { |
| 1387 | return 0; |
| 1388 | } |
| 1389 | |
| 1390 | valueT |
| 1391 | md_section_align (segT segment ATTRIBUTE_UNUSED, |
| 1392 | valueT size) |
| 1393 | { |
| 1394 | return (size + 1) & ~1; |
| 1395 | } |
| 1396 | |
| 1397 | long |
| 1398 | md_pcrel_from (fixS *fixP) |
| 1399 | { |
| 1400 | return fixP->fx_frag->fr_address + fixP->fx_where + fixP->fx_size; |
| 1401 | } |
| 1402 | |
| 1403 | /* Translate internal representation of relocation info to BFD target |
| 1404 | format. */ |
| 1405 | |
| 1406 | arelent * |
| 1407 | tc_gen_reloc (asection *section ATTRIBUTE_UNUSED, |
| 1408 | fixS *fixp) |
| 1409 | { |
| 1410 | arelent *reloc; |
| 1411 | bfd_reloc_code_real_type code; |
| 1412 | |
| 1413 | reloc = XNEW (arelent); |
| 1414 | |
| 1415 | reloc->sym_ptr_ptr = XNEW (asymbol *); |
| 1416 | *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy); |
| 1417 | reloc->address = fixp->fx_frag->fr_address + fixp->fx_where; |
| 1418 | |
| 1419 | /* This is taken account for in md_apply_fix(). */ |
| 1420 | reloc->addend = -symbol_get_bfdsym (fixp->fx_addsy)->section->vma; |
| 1421 | |
| 1422 | switch (fixp->fx_r_type) |
| 1423 | { |
| 1424 | case BFD_RELOC_16: |
| 1425 | if (fixp->fx_pcrel) |
| 1426 | code = BFD_RELOC_16_PCREL; |
| 1427 | else |
| 1428 | code = BFD_RELOC_16; |
| 1429 | break; |
| 1430 | |
| 1431 | case BFD_RELOC_16_PCREL: |
| 1432 | code = BFD_RELOC_16_PCREL; |
| 1433 | break; |
| 1434 | |
| 1435 | default: |
| 1436 | BAD_CASE (fixp->fx_r_type); |
| 1437 | return NULL; |
| 1438 | } |
| 1439 | |
| 1440 | reloc->howto = bfd_reloc_type_lookup (stdoutput, code); |
| 1441 | |
| 1442 | if (reloc->howto == NULL) |
| 1443 | { |
| 1444 | as_bad_where (fixp->fx_file, fixp->fx_line, |
| 1445 | _("Can not represent %s relocation in this object file format"), |
| 1446 | bfd_get_reloc_code_name (code)); |
| 1447 | return NULL; |
| 1448 | } |
| 1449 | |
| 1450 | return reloc; |
| 1451 | } |
| 1452 | |
| 1453 | void |
| 1454 | pseudo_bss (int c ATTRIBUTE_UNUSED) |
| 1455 | { |
| 1456 | int temp; |
| 1457 | |
| 1458 | temp = get_absolute_expression (); |
| 1459 | subseg_set (bss_section, temp); |
| 1460 | demand_empty_rest_of_line (); |
| 1461 | } |
| 1462 | |
| 1463 | void |
| 1464 | pseudo_even (int c ATTRIBUTE_UNUSED) |
| 1465 | { |
| 1466 | int alignment = 1; /* 2^1 */ |
| 1467 | frag_align (alignment, 0, 1); |
| 1468 | record_alignment (now_seg, alignment); |
| 1469 | } |
| 1470 | |
| 1471 | const char * |
| 1472 | md_atof (int type, char * litP, int * sizeP) |
| 1473 | { |
| 1474 | return vax_md_atof (type, litP, sizeP); |
| 1475 | } |