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