Home | History | Annotate | Line # | Download | only in config
tc-vax.c revision 1.13.6.2
      1 /* tc-vax.c - vax-specific -
      2    Copyright (C) 1987-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 the Free
     18    Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
     19    02110-1301, USA.  */
     20 
     21 #include "as.h"
     22 
     23 #include "vax-inst.h"
     24 #include "obstack.h"		/* For FRAG_APPEND_1_CHAR macro in "frags.h" */
     25 #include "dw2gencfi.h"
     26 #include "subsegs.h"
     27 #include "safe-ctype.h"
     28 
     29 #ifdef OBJ_ELF
     30 #include "elf/vax.h"
     31 #endif
     32 
     33 /* These chars start a comment anywhere in a source file (except inside
     34    another comment */
     35 const char comment_chars[] = "#";
     36 
     37 /* These chars only start a comment at the beginning of a line.  */
     38 /* Note that for the VAX the are the same as comment_chars above.  */
     39 const char line_comment_chars[] = "#";
     40 
     41 const char line_separator_chars[] = ";";
     42 
     43 /* Chars that can be used to separate mant from exp in floating point nums.  */
     44 const char EXP_CHARS[] = "eE";
     45 
     46 /* Chars that mean this number is a floating point constant
     47    as in 0f123.456
     48    or    0H1.234E-12 (see exp chars above).  */
     49 const char FLT_CHARS[] = "dDfFgGhH";
     50 
     51 /* Also be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
     52    changed in read.c .  Ideally it shouldn't have to know about it at all,
     53    but nothing is ideal around here.  */
     54 
     55 /* Hold details of an operand expression.  */
     56 static expressionS exp_of_operand[VIT_MAX_OPERANDS];
     57 static segT seg_of_operand[VIT_MAX_OPERANDS];
     58 
     59 /* A vax instruction after decoding.  */
     60 static struct vit v;
     61 
     62 /* Hold details of big operands.  */
     63 LITTLENUM_TYPE big_operand_bits[VIT_MAX_OPERANDS][SIZE_OF_LARGE_NUMBER];
     64 FLONUM_TYPE float_operand[VIT_MAX_OPERANDS];
     65 /* Above is made to point into big_operand_bits by md_begin().  */
     66 
     67 #ifdef OBJ_ELF
     68 #define GLOBAL_OFFSET_TABLE_NAME	"_GLOBAL_OFFSET_TABLE_"
     69 #define PROCEDURE_LINKAGE_TABLE_NAME	"_PROCEDURE_LINKAGE_TABLE_"
     70 symbolS *GOT_symbol;		/* Pre-defined "_GLOBAL_OFFSET_TABLE_".  */
     71 symbolS *PLT_symbol;		/* Pre-defined "_PROCEDURE_LINKAGE_TABLE_".  */
     72 #endif
     73 
     74 int flag_hash_long_names;	/* -+ */
     75 int flag_one;			/* -1 */
     76 int flag_show_after_trunc;	/* -H */
     77 int flag_no_hash_mixed_case;	/* -h NUM */
     78 #ifdef OBJ_ELF
     79 int flag_want_pic;		/* -k */
     80 #endif
     81 
     82 /* For VAX, relative addresses of "just the right length" are easy.
     84    The branch displacement is always the last operand, even in
     85    synthetic instructions.
     86    For VAX, we encode the relax_substateTs (in e.g. fr_substate) as:
     87 
     88   		    4       3       2       1       0	     bit number
     89   	---/ /--+-------+-------+-------+-------+-------+
     90   		|     what state ?	|  how long ?	|
     91   	---/ /--+-------+-------+-------+-------+-------+
     92 
     93    The "how long" bits are 00=byte, 01=word, 10=long.
     94    This is a Un*x convention.
     95    Not all lengths are legit for a given value of (what state).
     96    The "how long" refers merely to the displacement length.
     97    The address usually has some constant bytes in it as well.
     98 
     99  groups for VAX address relaxing.
    100 
    101  1.	"foo" pc-relative.
    102  length of byte, word, long
    103 
    104  2a.	J<cond> where <cond> is a simple flag test.
    105  length of byte, word, long.
    106  VAX opcodes are:	(Hex)
    107  bneq/bnequ	12
    108  beql/beqlu	13
    109  bgtr		14
    110  bleq		15
    111  bgeq		18
    112  blss		19
    113  bgtru		1a
    114  blequ		1b
    115  bvc		1c
    116  bvs		1d
    117  bgequ/bcc	1e
    118  blssu/bcs	1f
    119  Always, you complement 0th bit to reverse condition.
    120  Always, 1-byte opcode, then 1-byte displacement.
    121 
    122  2b.	J<cond> where cond tests a memory bit.
    123  length of byte, word, long.
    124  Vax opcodes are:	(Hex)
    125  bbs		e0
    126  bbc		e1
    127  bbss		e2
    128  bbcs		e3
    129  bbsc		e4
    130  bbcc		e5
    131  Always, you complement 0th bit to reverse condition.
    132  Always, 1-byte opcode, longword-address, byte-address, 1-byte-displacement
    133 
    134  2c.	J<cond> where cond tests low-order memory bit
    135  length of byte,word,long.
    136  Vax opcodes are:	(Hex)
    137  blbs		e8
    138  blbc		e9
    139  Always, you complement 0th bit to reverse condition.
    140  Always, 1-byte opcode, longword-address, 1-byte displacement.
    141 
    142  3.	Jbs/Jbr.
    143  length of byte,word,long.
    144  Vax opcodes are:	(Hex)
    145  bsbb		10
    146  brb		11
    147  These are like (2) but there is no condition to reverse.
    148  Always, 1 byte opcode, then displacement/absolute.
    149 
    150  4a.	JacbX
    151  length of word, long.
    152  Vax opcodes are:	(Hex)
    153  acbw		3d
    154  acbf		4f
    155  acbd		6f
    156  abcb		9d
    157  acbl		f1
    158  acbg	      4ffd
    159  acbh	      6ffd
    160  Always, we cannot reverse the sense of the branch; we have a word
    161  displacement.
    162  The double-byte op-codes don't hurt: we never want to modify the
    163  opcode, so we don't care how many bytes are between the opcode and
    164  the operand.
    165 
    166  4b.	JXobXXX
    167  length of long, long, byte.
    168  Vax opcodes are:	(Hex)
    169  aoblss		f2
    170  aobleq		f3
    171  sobgeq		f4
    172  sobgtr		f5
    173  Always, we cannot reverse the sense of the branch; we have a byte
    174  displacement.
    175 
    176  The only time we need to modify the opcode is for class 2 instructions.
    177  After relax() we may complement the lowest order bit of such instruction
    178  to reverse sense of branch.
    179 
    180  For class 2 instructions, we store context of "where is the opcode literal".
    181  We can change an opcode's lowest order bit without breaking anything else.
    182 
    183  We sometimes store context in the operand literal. This way we can figure out
    184  after relax() what the original addressing mode was.  */
    185 
    186 /* These displacements are relative to the start address of the
    188    displacement.  The first letter is Byte, Word.  2nd letter is
    189    Forward, Backward.  */
    190 #define BF (1+ 127)
    191 #define BB (1+-128)
    192 #define WF (2+ 32767)
    193 #define WB (2+-32768)
    194 /* Don't need LF, LB because they always reach. [They are coded as 0.]  */
    195 
    196 #define C(a,b) ENCODE_RELAX(a,b)
    197 /* This macro has no side-effects.  */
    198 #define ENCODE_RELAX(what,length) (((what) << 2) + (length))
    199 #define RELAX_STATE(s) ((s) >> 2)
    200 #define RELAX_LENGTH(s) ((s) & 3)
    201 
    202 const relax_typeS md_relax_table[] =
    203 {
    204   {1, 1, 0, 0},			/* error sentinel   0,0	*/
    205   {1, 1, 0, 0},			/* unused	    0,1	*/
    206   {1, 1, 0, 0},			/* unused	    0,2	*/
    207   {1, 1, 0, 0},			/* unused	    0,3	*/
    208 
    209   {BF + 1, BB + 1, 2, C (1, 1)},/* B^"foo"	    1,0 */
    210   {WF + 1, WB + 1, 3, C (1, 2)},/* W^"foo"	    1,1 */
    211   {0, 0, 5, 0},			/* L^"foo"	    1,2 */
    212   {1, 1, 0, 0},			/* unused	    1,3 */
    213 
    214   {BF, BB, 1, C (2, 1)},	/* b<cond> B^"foo"  2,0 */
    215   {WF + 2, WB + 2, 4, C (2, 2)},/* br.+? brw X	    2,1 */
    216   {0, 0, 7, 0},			/* br.+? jmp X	    2,2 */
    217   {1, 1, 0, 0},			/* unused	    2,3 */
    218 
    219   {BF, BB, 1, C (3, 1)},	/* brb B^foo	    3,0 */
    220   {WF, WB, 2, C (3, 2)},	/* brw W^foo	    3,1 */
    221   {0, 0, 5, 0},			/* Jmp L^foo	    3,2 */
    222   {1, 1, 0, 0},			/* unused	    3,3 */
    223 
    224   {1, 1, 0, 0},			/* unused	    4,0 */
    225   {WF, WB, 2, C (4, 2)},	/* acb_ ^Wfoo	    4,1 */
    226   {0, 0, 10, 0},		/* acb_,br,jmp L^foo4,2 */
    227   {1, 1, 0, 0},			/* unused	    4,3 */
    228 
    229   {BF, BB, 1, C (5, 1)},	/* Xob___,,foo      5,0 */
    230   {WF + 4, WB + 4, 6, C (5, 2)},/* Xob.+2,brb.+3,brw5,1 */
    231   {0, 0, 9, 0},			/* Xob.+2,brb.+6,jmp5,2 */
    232   {1, 1, 0, 0},			/* unused	    5,3 */
    233 };
    234 
    235 #undef C
    236 #undef BF
    237 #undef BB
    238 #undef WF
    239 #undef WB
    240 
    241 void float_cons (int);
    242 int flonum_gen2vax (int, FLONUM_TYPE *, LITTLENUM_TYPE *);
    243 
    244 const pseudo_typeS md_pseudo_table[] =
    245 {
    246   {"dfloat", float_cons, 'd'},
    247   {"ffloat", float_cons, 'f'},
    248   {"gfloat", float_cons, 'g'},
    249   {"hfloat", float_cons, 'h'},
    250   {"d_floating", float_cons, 'd'},
    251   {"f_floating", float_cons, 'f'},
    252   {"g_floating", float_cons, 'g'},
    253   {"h_floating", float_cons, 'h'},
    254   {NULL, NULL, 0},
    255 };
    256 
    257 #define STATE_PC_RELATIVE		(1)
    258 #define STATE_CONDITIONAL_BRANCH	(2)
    259 #define STATE_ALWAYS_BRANCH		(3)	/* includes BSB...  */
    260 #define STATE_COMPLEX_BRANCH	        (4)
    261 #define STATE_COMPLEX_HOP		(5)
    262 
    263 #define STATE_BYTE			(0)
    264 #define STATE_WORD			(1)
    265 #define STATE_LONG			(2)
    266 #define STATE_UNDF			(3)	/* Symbol undefined in pass1.  */
    267 
    268 #define min(a, b)	((a) < (b) ? (a) : (b))
    269 
    270 void
    272 md_number_to_chars (char con[], valueT value, int nbytes)
    273 {
    274   number_to_chars_littleendian (con, value, nbytes);
    275 }
    276 
    277 /* Fix up some data or instructions after we find out the value of a symbol
    278    that they reference.  */
    279 
    280 void				/* Knows about order of bytes in address.  */
    281 md_apply_fix (fixS *fixP, valueT *valueP, segT seg ATTRIBUTE_UNUSED)
    282 {
    283   valueT value = * valueP;
    284 
    285   if (fixP->fx_subsy != (symbolS *) NULL)
    286     as_bad_where (fixP->fx_file, fixP->fx_line, _("expression too complex"));
    287 
    288   if (fixP->fx_pcrel)
    289     {
    290       switch (fixP->fx_r_type)
    291 	{
    292 	case BFD_RELOC_32:
    293 	  /* change the relocation type to 32 bit PC-relative */
    294 	  fixP->fx_r_type = BFD_RELOC_32_PCREL;
    295 	  if (fixP->fx_addsy != NULL)
    296 	    {
    297 	      /* Hack around bfd_install_relocation brain damage.  */
    298 	      value += fixP->fx_frag->fr_address + fixP->fx_where;
    299 	    }
    300 	  if (fixP->fx_addsy == abs_section_sym)
    301 	    fixP->fx_done = 1;
    302 	  break;
    303 	default:
    304 	  break;
    305 	}
    306     }
    307 
    308   /*
    309    * Common code for pc-relative and non-pc-relative cases
    310    */
    311   if (fixP->fx_addsy == NULL)
    312     fixP->fx_done = 1;
    313 
    314   if (fixP->fx_done)
    315     number_to_chars_littleendian (fixP->fx_where + fixP->fx_frag->fr_literal,
    316 				  value, fixP->fx_size);
    317   else
    318     /* Initialise the part of an instruction frag covered by the
    319        relocation.  (Many occurrences of frag_more followed by fix_new
    320        lack any init of the frag.)  Since VAX uses RELA relocs the
    321        value we write into this field doesn't really matter.  */
    322     memset (fixP->fx_where + fixP->fx_frag->fr_literal, 0, fixP->fx_size);
    323 }
    324 
    325 /* Convert a number from VAX byte order (little endian)
    326    into host byte order.
    327    con		is the buffer to convert,
    328    nbytes	is the length of the given buffer.  */
    329 static long
    330 md_chars_to_number (unsigned char con[], int nbytes)
    331 {
    332   long retval;
    333 
    334   for (retval = 0, con += nbytes - 1; nbytes--; con--)
    335     {
    336       retval <<= BITS_PER_CHAR;
    337       retval |= *con;
    338     }
    339   return retval;
    340 }
    341 
    342 /* Copy a bignum from in to out.
    343    If the output is shorter than the input, copy lower-order
    344    littlenums.  Return 0 or the number of significant littlenums
    345    dropped.  Assumes littlenum arrays are densely packed: no unused
    346    chars between the littlenums. Uses memcpy() to move littlenums, and
    347    wants to know length (in chars) of the input bignum.  */
    348 
    349 static int
    350 bignum_copy (LITTLENUM_TYPE *in,
    351 	     int in_length,	/* in sizeof(littlenum)s */
    352 	     LITTLENUM_TYPE *out,
    353 	     int out_length	/* in sizeof(littlenum)s */)
    354 {
    355   int significant_littlenums_dropped;
    356 
    357   if (out_length < in_length)
    358     {
    359       LITTLENUM_TYPE *p;	/* -> most significant (non-zero) input
    360 				      littlenum.  */
    361 
    362       memcpy ((void *) out, (void *) in,
    363 	      (unsigned int) out_length << LITTLENUM_SHIFT);
    364       for (p = in + in_length - 1; p >= in; --p)
    365 	{
    366 	  if (*p)
    367 	    break;
    368 	}
    369       significant_littlenums_dropped = p - in - in_length + 1;
    370 
    371       if (significant_littlenums_dropped < 0)
    372 	significant_littlenums_dropped = 0;
    373     }
    374   else
    375     {
    376       memcpy ((char *) out, (char *) in,
    377 	      (unsigned int) in_length << LITTLENUM_SHIFT);
    378 
    379       if (out_length > in_length)
    380 	memset ((char *) (out + in_length), '\0',
    381 		(unsigned int) (out_length - in_length) << LITTLENUM_SHIFT);
    382 
    383       significant_littlenums_dropped = 0;
    384     }
    385 
    386   return significant_littlenums_dropped;
    387 }
    388 
    389 /* md_estimate_size_before_relax(), called just before relax().
    391    Any symbol that is now undefined will not become defined.
    392    Return the correct fr_subtype in the frag and the growth beyond
    393    fr_fix.  */
    394 int
    395 md_estimate_size_before_relax (fragS *fragP, segT segment)
    396 {
    397   if (RELAX_LENGTH (fragP->fr_subtype) == STATE_UNDF)
    398     {
    399       if (S_GET_SEGMENT (fragP->fr_symbol) != segment
    400 #ifdef OBJ_ELF
    401 	  || S_IS_WEAK (fragP->fr_symbol)
    402 	  || S_IS_EXTERNAL (fragP->fr_symbol)
    403 #endif
    404 	  )
    405 	{
    406 	  /* Non-relaxable cases.  */
    407 	  int reloc_type = NO_RELOC;
    408 	  char *p;
    409 	  int old_fr_fix;
    410 
    411 	  old_fr_fix = fragP->fr_fix;
    412 	  p = fragP->fr_literal + old_fr_fix;
    413 #ifdef OBJ_ELF
    414 	  /* If this is to an undefined symbol, then if it's an indirect
    415 	     reference indicate that is can mutated into a GLOB_DAT or
    416 	     JUMP_SLOT by the loader.  We restrict ourselves to no offset
    417 	     due to a limitation in the NetBSD linker.  */
    418 
    419 	  if (GOT_symbol == NULL)
    420 	    GOT_symbol = symbol_find (GLOBAL_OFFSET_TABLE_NAME);
    421 	  if (PLT_symbol == NULL)
    422 	    PLT_symbol = symbol_find (PROCEDURE_LINKAGE_TABLE_NAME);
    423 	  if ((GOT_symbol == NULL || fragP->fr_symbol != GOT_symbol)
    424 	      && (PLT_symbol == NULL || fragP->fr_symbol != PLT_symbol)
    425 	      && fragP->fr_symbol != NULL
    426 	      && flag_want_pic
    427 #ifdef OBJ_ELF
    428 	      && ELF_ST_VISIBILITY (S_GET_OTHER (fragP->fr_symbol)) != STV_HIDDEN
    429 #endif
    430 	      && (!S_IS_DEFINED (fragP->fr_symbol)
    431 	          || S_IS_WEAK (fragP->fr_symbol)
    432 	          || S_IS_EXTERNAL (fragP->fr_symbol)))
    433 	    {
    434 	      /* Indirect references cannot go through the GOT or PLT,
    435 	         let's hope they'll become local in the final link.  */
    436 	      if ((ELF_ST_VISIBILITY (S_GET_OTHER (fragP->fr_symbol))
    437 		   != STV_DEFAULT)
    438 		  || (p[0] & 0x10))
    439 		reloc_type = BFD_RELOC_32_PCREL;
    440 	      else if (((unsigned char *) fragP->fr_opcode)[0] == VAX_CALLS
    441 		       || ((unsigned char *) fragP->fr_opcode)[0] == VAX_CALLG
    442 		       || ((unsigned char *) fragP->fr_opcode)[0] == VAX_JSB
    443 		       || ((unsigned char *) fragP->fr_opcode)[0] == VAX_JMP
    444 #if 0 /* port-vax/59326 */
    445 		       || S_IS_FUNCTION (fragP->fr_symbol)
    446 #endif
    447 	              )
    448 		reloc_type = BFD_RELOC_32_PLT_PCREL;
    449 	      else
    450 		reloc_type = BFD_RELOC_32_GOT_PCREL;
    451 	    }
    452 #endif
    453 	  switch (RELAX_STATE (fragP->fr_subtype))
    454 	    {
    455 	    case STATE_PC_RELATIVE:
    456 	      p[0] |= VAX_PC_RELATIVE_MODE;	/* Preserve @ bit.  */
    457 	      fragP->fr_fix += 1 + 4;
    458 	      fix_new (fragP, old_fr_fix + 1, 4, fragP->fr_symbol,
    459 		       fragP->fr_offset, 1, reloc_type);
    460 	      break;
    461 
    462 	    case STATE_CONDITIONAL_BRANCH:
    463 	      *fragP->fr_opcode ^= 1;		/* Reverse sense of branch.  */
    464 	      p[0] = 6;
    465 	      p[1] = VAX_JMP;
    466 	      p[2] = VAX_PC_RELATIVE_MODE;	/* ...(PC) */
    467 	      fragP->fr_fix += 1 + 1 + 1 + 4;
    468 	      fix_new (fragP, old_fr_fix + 3, 4, fragP->fr_symbol,
    469 		       fragP->fr_offset, 1, NO_RELOC);
    470 	      break;
    471 
    472 	    case STATE_COMPLEX_BRANCH:
    473 	      p[0] = 2;
    474 	      p[1] = 0;
    475 	      p[2] = VAX_BRB;
    476 	      p[3] = 6;
    477 	      p[4] = VAX_JMP;
    478 	      p[5] = VAX_PC_RELATIVE_MODE;	/* ...(pc) */
    479 	      fragP->fr_fix += 2 + 2 + 1 + 1 + 4;
    480 	      fix_new (fragP, old_fr_fix + 6, 4, fragP->fr_symbol,
    481 		       fragP->fr_offset, 1, NO_RELOC);
    482 	      break;
    483 
    484 	    case STATE_COMPLEX_HOP:
    485 	      p[0] = 2;
    486 	      p[1] = VAX_BRB;
    487 	      p[2] = 6;
    488 	      p[3] = VAX_JMP;
    489 	      p[4] = VAX_PC_RELATIVE_MODE;	/* ...(pc) */
    490 	      fragP->fr_fix += 1 + 2 + 1 + 1 + 4;
    491 	      fix_new (fragP, old_fr_fix + 5, 4, fragP->fr_symbol,
    492 		       fragP->fr_offset, 1, NO_RELOC);
    493 	      break;
    494 
    495 	    case STATE_ALWAYS_BRANCH:
    496 	      *fragP->fr_opcode += VAX_WIDEN_LONG;
    497 	      p[0] = VAX_PC_RELATIVE_MODE;	/* ...(PC) */
    498 	      fragP->fr_fix += 1 + 4;
    499 	      fix_new (fragP, old_fr_fix + 1, 4, fragP->fr_symbol,
    500 		       fragP->fr_offset, 1, NO_RELOC);
    501 	      break;
    502 
    503 	    default:
    504 	      abort ();
    505 	    }
    506 	  frag_wane (fragP);
    507 
    508 	  /* Return the growth in the fixed part of the frag.  */
    509 	  return fragP->fr_fix - old_fr_fix;
    510 	}
    511 
    512       /* Relaxable cases.  Set up the initial guess for the variable
    513 	 part of the frag.  */
    514       switch (RELAX_STATE (fragP->fr_subtype))
    515 	{
    516 	case STATE_PC_RELATIVE:
    517 	  fragP->fr_subtype = ENCODE_RELAX (STATE_PC_RELATIVE, STATE_BYTE);
    518 	  break;
    519 	case STATE_CONDITIONAL_BRANCH:
    520 	  fragP->fr_subtype = ENCODE_RELAX (STATE_CONDITIONAL_BRANCH, STATE_BYTE);
    521 	  break;
    522 	case STATE_COMPLEX_BRANCH:
    523 	  fragP->fr_subtype = ENCODE_RELAX (STATE_COMPLEX_BRANCH, STATE_WORD);
    524 	  break;
    525 	case STATE_COMPLEX_HOP:
    526 	  fragP->fr_subtype = ENCODE_RELAX (STATE_COMPLEX_HOP, STATE_BYTE);
    527 	  break;
    528 	case STATE_ALWAYS_BRANCH:
    529 	  fragP->fr_subtype = ENCODE_RELAX (STATE_ALWAYS_BRANCH, STATE_BYTE);
    530 	  break;
    531 	}
    532     }
    533 
    534   if (fragP->fr_subtype >= sizeof (md_relax_table) / sizeof (md_relax_table[0]))
    535     abort ();
    536 
    537   /* Return the size of the variable part of the frag.  */
    538   return md_relax_table[fragP->fr_subtype].rlx_length;
    539 }
    540 
    541 /* Called after relax() is finished.
    543    In:	Address of frag.
    544   	fr_type == rs_machine_dependent.
    545   	fr_subtype is what the address relaxed to.
    546 
    547    Out:	Any fixSs and constants are set up.
    548   	Caller will turn frag into a ".space 0".  */
    549 void
    550 md_convert_frag (bfd *headers ATTRIBUTE_UNUSED,
    551 		 segT seg ATTRIBUTE_UNUSED,
    552 		 fragS *fragP)
    553 {
    554   char *addressP;		/* -> _var to change.  */
    555   char *opcodeP;		/* -> opcode char(s) to change.  */
    556   short int extension = 0;	/* Size of relaxed address.  */
    557   /* Added to fr_fix: incl. ALL var chars.  */
    558   symbolS *symbolP;
    559   long where;
    560 
    561   know (fragP->fr_type == rs_machine_dependent);
    562   where = fragP->fr_fix;
    563   addressP = fragP->fr_literal + where;
    564   opcodeP = fragP->fr_opcode;
    565   symbolP = fragP->fr_symbol;
    566   know (symbolP);
    567 
    568   switch (fragP->fr_subtype)
    569     {
    570     case ENCODE_RELAX (STATE_PC_RELATIVE, STATE_BYTE):
    571       know (*addressP == 0 || *addressP == 0x10);	/* '@' bit.  */
    572       addressP[0] |= 0xAF;	/* Byte displacement. */
    573       fix_new (fragP, fragP->fr_fix + 1, 1, fragP->fr_symbol,
    574 	       fragP->fr_offset, 1, NO_RELOC);
    575       extension = 2;
    576       break;
    577 
    578     case ENCODE_RELAX (STATE_PC_RELATIVE, STATE_WORD):
    579       know (*addressP == 0 || *addressP == 0x10);	/* '@' bit.  */
    580       addressP[0] |= 0xCF;	/* Word displacement. */
    581       fix_new (fragP, fragP->fr_fix + 1, 2, fragP->fr_symbol,
    582 	       fragP->fr_offset, 1, NO_RELOC);
    583       extension = 3;
    584       break;
    585 
    586     case ENCODE_RELAX (STATE_PC_RELATIVE, STATE_LONG):
    587       know (*addressP == 0 || *addressP == 0x10);	/* '@' bit.  */
    588       addressP[0] |= 0xEF;	/* Long word displacement. */
    589       fix_new (fragP, fragP->fr_fix + 1, 4, fragP->fr_symbol,
    590 	       fragP->fr_offset, 1, NO_RELOC);
    591       extension = 5;
    592       break;
    593 
    594     case ENCODE_RELAX (STATE_CONDITIONAL_BRANCH, STATE_BYTE):
    595       fix_new (fragP, fragP->fr_fix, 1, fragP->fr_symbol,
    596 	       fragP->fr_offset, 1, NO_RELOC);
    597       extension = 1;
    598       break;
    599 
    600     case ENCODE_RELAX (STATE_CONDITIONAL_BRANCH, STATE_WORD):
    601       opcodeP[0] ^= 1;		/* Reverse sense of test.  */
    602       addressP[0] = 3;
    603       addressP[1] = VAX_BRW;
    604       fix_new (fragP, fragP->fr_fix + 2, 2, fragP->fr_symbol,
    605 	       fragP->fr_offset, 1, NO_RELOC);
    606       extension = 4;
    607       break;
    608 
    609     case ENCODE_RELAX (STATE_CONDITIONAL_BRANCH, STATE_LONG):
    610       opcodeP[0] ^= 1;		/* Reverse sense of test.  */
    611       addressP[0] = 6;
    612       addressP[1] = VAX_JMP;
    613       addressP[2] = VAX_PC_RELATIVE_MODE;
    614       fix_new (fragP, fragP->fr_fix + 3, 4, fragP->fr_symbol,
    615 	       fragP->fr_offset, 1, NO_RELOC);
    616       extension = 7;
    617       break;
    618 
    619     case ENCODE_RELAX (STATE_ALWAYS_BRANCH, STATE_BYTE):
    620       fix_new (fragP, fragP->fr_fix, 1, fragP->fr_symbol,
    621 	       fragP->fr_offset, 1, NO_RELOC);
    622       extension = 1;
    623       break;
    624 
    625     case ENCODE_RELAX (STATE_ALWAYS_BRANCH, STATE_WORD):
    626       opcodeP[0] += VAX_WIDEN_WORD;	/* brb -> brw, bsbb -> bsbw */
    627       fix_new (fragP, fragP->fr_fix, 2, fragP->fr_symbol, fragP->fr_offset,
    628 	       1, NO_RELOC);
    629       extension = 2;
    630       break;
    631 
    632     case ENCODE_RELAX (STATE_ALWAYS_BRANCH, STATE_LONG):
    633       opcodeP[0] += VAX_WIDEN_LONG;	/* brb -> jmp, bsbb -> jsb */
    634       addressP[0] = VAX_PC_RELATIVE_MODE;
    635       fix_new (fragP, fragP->fr_fix + 1, 4, fragP->fr_symbol,
    636 	       fragP->fr_offset, 1, NO_RELOC);
    637       extension = 5;
    638       break;
    639 
    640     case ENCODE_RELAX (STATE_COMPLEX_BRANCH, STATE_WORD):
    641       fix_new (fragP, fragP->fr_fix, 2, fragP->fr_symbol,
    642 	       fragP->fr_offset, 1, NO_RELOC);
    643       extension = 2;
    644       break;
    645 
    646     case ENCODE_RELAX (STATE_COMPLEX_BRANCH, STATE_LONG):
    647       addressP[0] = 2;
    648       addressP[1] = 0;
    649       addressP[2] = VAX_BRB;
    650       addressP[3] = 6;
    651       addressP[4] = VAX_JMP;
    652       addressP[5] = VAX_PC_RELATIVE_MODE;
    653       fix_new (fragP, fragP->fr_fix + 6, 4, fragP->fr_symbol,
    654 	       fragP->fr_offset, 1, NO_RELOC);
    655       extension = 10;
    656       break;
    657 
    658     case ENCODE_RELAX (STATE_COMPLEX_HOP, STATE_BYTE):
    659       fix_new (fragP, fragP->fr_fix, 1, fragP->fr_symbol,
    660 	       fragP->fr_offset, 1, NO_RELOC);
    661       extension = 1;
    662       break;
    663 
    664     case ENCODE_RELAX (STATE_COMPLEX_HOP, STATE_WORD):
    665       addressP[0] = 2;
    666       addressP[1] = VAX_BRB;
    667       addressP[2] = 3;
    668       addressP[3] = VAX_BRW;
    669       fix_new (fragP, fragP->fr_fix + 4, 2, fragP->fr_symbol,
    670 	       fragP->fr_offset, 1, NO_RELOC);
    671       extension = 6;
    672       break;
    673 
    674     case ENCODE_RELAX (STATE_COMPLEX_HOP, STATE_LONG):
    675       addressP[0] = 2;
    676       addressP[1] = VAX_BRB;
    677       addressP[2] = 6;
    678       addressP[3] = VAX_JMP;
    679       addressP[4] = VAX_PC_RELATIVE_MODE;
    680       fix_new (fragP, fragP->fr_fix + 5, 4, fragP->fr_symbol,
    681 	       fragP->fr_offset, 1, NO_RELOC);
    682       extension = 9;
    683       break;
    684 
    685     default:
    686       BAD_CASE (fragP->fr_subtype);
    687       break;
    688     }
    689   fragP->fr_fix += extension;
    690 }
    691 
    692 /* Translate internal format of relocation info into target format.
    693 
    694    On vax: first 4 bytes are normal unsigned long, next three bytes
    695    are symbolnum, least sig. byte first.  Last byte is broken up with
    696    the upper nibble as nuthin, bit 3 as extern, bits 2 & 1 as length, and
    697    bit 0 as pcrel.  */
    698 #ifdef comment
    699 void
    700 md_ri_to_chars (char *the_bytes, struct reloc_info_generic ri)
    701 {
    702   /* This is easy.  */
    703   md_number_to_chars (the_bytes, ri.r_address, sizeof (ri.r_address));
    704   /* Now the fun stuff.  */
    705   the_bytes[6] = (ri.r_symbolnum >> 16) & 0x0ff;
    706   the_bytes[5] = (ri.r_symbolnum >> 8) & 0x0ff;
    707   the_bytes[4] = ri.r_symbolnum & 0x0ff;
    708   the_bytes[7] = (((ri.r_extern << 3) & 0x08) | ((ri.r_length << 1) & 0x06)
    709 		  | ((ri.r_pcrel << 0) & 0x01)) & 0x0F;
    710 }
    711 
    712 #endif /* comment */
    713 
    714 /*       BUGS, GRIPES,  APOLOGIA, etc.
    715 
    716    The opcode table 'votstrs' needs to be sorted on opcode frequency.
    717    That is, AFTER we hash it with hash_...(), we want most-used opcodes
    718    to come out of the hash table faster.
    719 
    720    I am sorry to inflict yet another VAX assembler on the world, but
    721    RMS says we must do everything from scratch, to prevent pin-heads
    722    restricting this software.
    723 
    724    This is a vaguely modular set of routines in C to parse VAX
    725    assembly code using DEC mnemonics. It is NOT un*x specific.
    726 
    727    The idea here is that the assembler has taken care of all:
    728      labels
    729      macros
    730      listing
    731      pseudo-ops
    732      line continuation
    733      comments
    734      condensing any whitespace down to exactly one space
    735    and all we have to do is parse 1 line into a vax instruction
    736    partially formed. We will accept a line, and deliver:
    737      an error message (hopefully empty)
    738      a skeleton VAX instruction (tree structure)
    739      textual pointers to all the operand expressions
    740      a warning message that notes a silly operand (hopefully empty)
    741 
    742   		E D I T   H I S T O R Y
    743 
    744    17may86 Dean Elsner. Bug if line ends immediately after opcode.
    745    30apr86 Dean Elsner. New vip_op() uses arg block so change call.
    746     6jan86 Dean Elsner. Crock vip_begin() to call vip_op_defaults().
    747     2jan86 Dean Elsner. Invent synthetic opcodes.
    748   	Widen vax_opcodeT to 32 bits. Use a bit for VIT_OPCODE_SYNTHETIC,
    749   	which means this is not a real opcode, it is like a macro; it will
    750   	be relax()ed into 1 or more instructions.
    751   	Use another bit for VIT_OPCODE_SPECIAL if the op-code is not optimised
    752   	like a regular branch instruction. Option added to vip_begin():
    753   	exclude	synthetic opcodes. Invent synthetic_votstrs[].
    754    31dec85 Dean Elsner. Invent vit_opcode_nbytes.
    755   	Also make vit_opcode into a char[]. We now have n-byte vax opcodes,
    756   	so caller's don't have to know the difference between a 1-byte & a
    757   	2-byte op-code. Still need vax_opcodeT concept, so we know how
    758   	big an object must be to hold an op.code.
    759    30dec85 Dean Elsner. Widen typedef vax_opcodeT in "vax-inst.h"
    760   	because vax opcodes may be 16 bits. Our crufty C compiler was
    761   	happily initialising 8-bit vot_codes with 16-bit numbers!
    762   	(Wouldn't the 'phone company like to compress data so easily!)
    763    29dec85 Dean Elsner. New static table vax_operand_width_size[].
    764   	Invented so we know hw many bytes a "I^#42" needs in its immediate
    765   	operand. Revised struct vop in "vax-inst.h": explicitly include
    766   	byte length of each operand, and it's letter-code datum type.
    767    17nov85 Dean Elsner. Name Change.
    768   	Due to ar(1) truncating names, we learned the hard way that
    769   	"vax-inst-parse.c" -> "vax-inst-parse." dropping the "o" off
    770   	the archived object name. SO... we shortened the name of this
    771   	source file, and changed the makefile.  */
    772 
    773 /* Handle of the OPCODE hash table.  */
    774 static struct hash_control *op_hash;
    775 
    776 /* In:	1 character, from "bdfghloqpw" being the data-type of an operand
    777   	of a vax instruction.
    778 
    779    Out:	the length of an operand of that type, in bytes.
    780   	Special branch operands types "-?!" have length 0.  */
    781 
    782 static const short int vax_operand_width_size[256] =
    783 {
    784   0, 0, 0, 0, 0, 0, 0, 0,  0, 0, 0, 0, 0, 0, 0, 0,
    785   0, 0, 0, 0, 0, 0, 0, 0,  0, 0, 0, 0, 0, 0, 0, 0,
    786   0, 0, 0, 0, 0, 0, 0, 0,  0, 0, 0, 0, 0, 0, 0, 0,
    787   0, 0, 0, 0, 0, 0, 0, 0,  0, 0, 0, 0, 0, 0, 0, 0,
    788   0, 0, 1, 0, 8, 0, 4, 8, 16, 0, 0, 0, 4, 0, 0,16,	/* ..b.d.fgh...l..o  */
    789   0, 8, 0, 0, 0, 0, 0, 2,  0, 0, 0, 0, 0, 0, 0, 0,	/* .q.....w........  */
    790   0, 0, 1, 0, 8, 0, 4, 8, 16, 0, 0, 0, 4, 0, 0,16,	/* ..b.d.fgh...l..o  */
    791   0, 8, 0, 0, 0, 0, 0, 2,  0, 0, 0, 0, 0, 0, 0, 0,	/* .q.....w........  */
    792   0, 0, 0, 0, 0, 0, 0, 0,  0, 0, 0, 0, 0, 0, 0, 0,
    793   0, 0, 0, 0, 0, 0, 0, 0,  0, 0, 0, 0, 0, 0, 0, 0,
    794   0, 0, 0, 0, 0, 0, 0, 0,  0, 0, 0, 0, 0, 0, 0, 0,
    795   0, 0, 0, 0, 0, 0, 0, 0,  0, 0, 0, 0, 0, 0, 0, 0,
    796   0, 0, 0, 0, 0, 0, 0, 0,  0, 0, 0, 0, 0, 0, 0, 0,
    797   0, 0, 0, 0, 0, 0, 0, 0,  0, 0, 0, 0, 0, 0, 0, 0,
    798   0, 0, 0, 0, 0, 0, 0, 0,  0, 0, 0, 0, 0, 0, 0, 0,
    799   0, 0, 0, 0, 0, 0, 0, 0,  0, 0, 0, 0, 0, 0, 0, 0,
    800 };
    801 
    802 /* This perversion encodes all the vax opcodes as a bunch of strings.
    804    RMS says we should build our hash-table at run-time. Hmm.
    805    Please would someone arrange these in decreasing frequency of opcode?
    806    Because of the way hash_...() works, the most frequently used opcode
    807    should be textually first and so on.
    808 
    809    Input for this table was 'vax.opcodes', awk(1)ed by 'vax.opcodes.c.awk' .
    810    So change 'vax.opcodes', then re-generate this table.  */
    811 
    812 #include "opcode/vax.h"
    813 
    814 /* This is a table of optional op-codes. All of them represent
    816    'synthetic' instructions that seem popular.
    817 
    818    Here we make some pseudo op-codes. Every code has a bit set to say
    819    it is synthetic. This lets you catch them if you want to
    820    ban these opcodes. They are mnemonics for "elastic" instructions
    821    that are supposed to assemble into the fewest bytes needed to do a
    822    branch, or to do a conditional branch, or whatever.
    823 
    824    The opcode is in the usual place [low-order n*8 bits]. This means
    825    that if you mask off the bucky bits, the usual rules apply about
    826    how long the opcode is.
    827 
    828    All VAX branch displacements come at the end of the instruction.
    829    For simple branches (1-byte opcode + 1-byte displacement) the last
    830    operand is coded 'b?' where the "data type" '?' is a clue that we
    831    may reverse the sense of the branch (complement lowest order bit)
    832    and branch around a jump. This is by far the most common case.
    833    That is why the VIT_OPCODE_SYNTHETIC bit is set: it says this is
    834    a 0-byte op-code followed by 2 or more bytes of operand address.
    835 
    836    If the op-code has VIT_OPCODE_SPECIAL set, then we have a more unusual
    837    case.
    838 
    839    For JBSB & JBR the treatment is the similar, except (1) we have a 'bw'
    840    option before (2) we can directly JSB/JMP because there is no condition.
    841    These operands have 'b-' as their access/data type.
    842 
    843    That leaves a bunch of random opcodes: JACBx, JxOBxxx. In these
    844    cases, we do the same idea. JACBxxx are all marked with a 'b!'
    845    JAOBxxx & JSOBxxx are marked with a 'b:'.  */
    846 #if (VIT_OPCODE_SYNTHETIC != 0x80000000)
    847 #error "You have just broken the encoding below, which assumes the sign bit means 'I am an imaginary instruction'."
    848 #endif
    849 
    850 #if (VIT_OPCODE_SPECIAL != 0x40000000)
    851 #error "You have just broken the encoding below, which assumes the 0x40 M bit means 'I am not to be "optimised" the way normal branches are'."
    852 #endif
    853 
    854 static const struct vot
    855   synthetic_votstrs[] =
    856 {
    857   {"jbsb",	{"b-", 0xC0000010}},		/* BSD 4.2 */
    858 /* jsb used already */
    859   {"jbr",	{"b-", 0xC0000011}},		/* BSD 4.2 */
    860   {"jr",	{"b-", 0xC0000011}},		/* consistent */
    861   {"jneq",	{"b?", 0x80000012}},
    862   {"jnequ",	{"b?", 0x80000012}},
    863   {"jeql",	{"b?", 0x80000013}},
    864   {"jeqlu",	{"b?", 0x80000013}},
    865   {"jgtr",	{"b?", 0x80000014}},
    866   {"jleq",	{"b?", 0x80000015}},
    867 /* un-used opcodes here */
    868   {"jgeq",	{"b?", 0x80000018}},
    869   {"jlss",	{"b?", 0x80000019}},
    870   {"jgtru",	{"b?", 0x8000001a}},
    871   {"jlequ",	{"b?", 0x8000001b}},
    872   {"jvc",	{"b?", 0x8000001c}},
    873   {"jvs",	{"b?", 0x8000001d}},
    874   {"jgequ",	{"b?", 0x8000001e}},
    875   {"jcc",	{"b?", 0x8000001e}},
    876   {"jlssu",	{"b?", 0x8000001f}},
    877   {"jcs",	{"b?", 0x8000001f}},
    878 
    879   {"jacbw",	{"rwrwmwb!", 0xC000003d}},
    880   {"jacbf",	{"rfrfmfb!", 0xC000004f}},
    881   {"jacbd",	{"rdrdmdb!", 0xC000006f}},
    882   {"jacbb",	{"rbrbmbb!", 0xC000009d}},
    883   {"jacbl",	{"rlrlmlb!", 0xC00000f1}},
    884   {"jacbg",	{"rgrgmgb!", 0xC0004ffd}},
    885   {"jacbh",	{"rhrhmhb!", 0xC0006ffd}},
    886 
    887   {"jbs",	{"rlvbb?", 0x800000e0}},
    888   {"jbc",	{"rlvbb?", 0x800000e1}},
    889   {"jbss",	{"rlvbb?", 0x800000e2}},
    890   {"jbcs",	{"rlvbb?", 0x800000e3}},
    891   {"jbsc",	{"rlvbb?", 0x800000e4}},
    892   {"jbcc",	{"rlvbb?", 0x800000e5}},
    893   {"jbssi",	{"rlvbb?", 0x800000e6}},
    894   {"jbcci",	{"rlvbb?", 0x800000e7}},
    895   {"jlbs",	{"rlb?", 0x800000e8}},
    896   {"jlbc",	{"rlb?", 0x800000e9}},
    897 
    898   {"jaoblss",	{"rlmlb:", 0xC00000f2}},
    899   {"jaobleq",	{"rlmlb:", 0xC00000f3}},
    900   {"jsobgeq",	{"mlb:", 0xC00000f4}},
    901   {"jsobgtr",	{"mlb:", 0xC00000f5}},
    902 
    903 /* CASEx has no branch addresses in our conception of it.  */
    904 /* You should use ".word ..." statements after the "case ...".  */
    905 
    906   {"",		{"", 0}}	/* Empty is end sentinel.  */
    907 };
    908 
    909 /* Because this module is useful for both VMS and UN*X style assemblers
    911    and because of the variety of UN*X assemblers we must recognise
    912    the different conventions for assembler operand notation. For example
    913    VMS says "#42" for immediate mode, while most UN*X say "$42".
    914    We permit arbitrary sets of (single) characters to represent the
    915    3 concepts that DEC writes '#', '@', '^'.  */
    916 
    917 /* Character tests.  */
    918 #define VIP_IMMEDIATE 01	/* Character is like DEC # */
    919 #define VIP_INDIRECT  02	/* Char is like DEC @ */
    920 #define VIP_DISPLEN   04	/* Char is like DEC ^ */
    921 
    922 #define IMMEDIATEP(c)	(vip_metacharacters [(c) & 0xff] & VIP_IMMEDIATE)
    923 #define INDIRECTP(c)	(vip_metacharacters [(c) & 0xff] & VIP_INDIRECT)
    924 #define DISPLENP(c)	(vip_metacharacters [(c) & 0xff] & VIP_DISPLEN)
    925 
    926 /* We assume 8 bits per byte. Use vip_op_defaults() to set these up BEFORE we
    927    are ever called.  */
    928 
    929 #if defined(CONST_TABLE)
    930 #define _ 0,
    931 #define I VIP_IMMEDIATE,
    932 #define S VIP_INDIRECT,
    933 #define D VIP_DISPLEN,
    934 static const char
    935 vip_metacharacters[256] =
    936 {
    937   _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _	/* ^@ ^A ^B ^C ^D ^E ^F ^G ^H ^I ^J ^K ^L ^M ^N ^O*/
    938   _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _	/* ^P ^Q ^R ^S ^T ^U ^V ^W ^X ^Y ^Z ^[ ^\ ^] ^^ ^_ */
    939   _ _ _ _ I _ _ _ _ _ S _ _ _ _ _	/* sp !  "  #  $  %  & '  (  )  *  +  ,  -  .  / */
    940   _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _	/*0  1  2  3  4  5  6  7  8  9  :  ;  <  =  >  ?*/
    941   _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _	/*@  A  B  C  D  E  F  G  H  I  J  K  L  M  N  O*/
    942   _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _	/*P  Q  R  S  T  U  V  W  X  Y  Z  [  \  ]  ^  _*/
    943   D _ _ _ _ _ _ _ _ _ _ _ _ _ _ _	/*`  a  b  c  d  e  f  g  h  i  j  k  l  m  n  o*/
    944   _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _	/*p  q  r  s  t  u  v  w  x  y  z  {  |  }  ~  ^?*/
    945 
    946   _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
    947   _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
    948   _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
    949   _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
    950   _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
    951   _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
    952   _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
    953   _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
    954 };
    955 #undef _
    956 #undef I
    957 #undef S
    958 #undef D
    959 
    960 #else
    961 
    962 static char vip_metacharacters[256];
    963 
    964 static void
    965 vip_op_1 (int bit, const char *syms)
    966 {
    967   unsigned char t;
    968 
    969   while ((t = *syms++) != 0)
    970     vip_metacharacters[t] |= bit;
    971 }
    972 
    973 /* Can be called any time.  More arguments may appear in future.  */
    974 static void
    975 vip_op_defaults (const char *immediate, const char *indirect, const char *displen)
    976 {
    977   vip_op_1 (VIP_IMMEDIATE, immediate);
    978   vip_op_1 (VIP_INDIRECT, indirect);
    979   vip_op_1 (VIP_DISPLEN, displen);
    980 }
    981 
    982 #endif
    983 
    984 /* Call me once before you decode any lines.
    985    I decode votstrs into a hash table at op_hash (which I create).
    986    I return an error text or null.
    987    If you want, I will include the 'synthetic' jXXX instructions in the
    988    instruction table.
    989    You must nominate metacharacters for eg DEC's "#", "@", "^".  */
    990 
    991 static const char *
    992 vip_begin (int synthetic_too,		/* 1 means include jXXX op-codes.  */
    993 	   const char *immediate,
    994 	   const char *indirect,
    995 	   const char *displen)
    996 {
    997   const struct vot *vP;		/* scan votstrs */
    998   const char *retval = 0;	/* error text */
    999 
   1000   op_hash = hash_new ();
   1001 
   1002   for (vP = votstrs; *vP->vot_name && !retval; vP++)
   1003     retval = hash_insert (op_hash, vP->vot_name, (void *) &vP->vot_detail);
   1004 
   1005   if (synthetic_too)
   1006     for (vP = synthetic_votstrs; *vP->vot_name && !retval; vP++)
   1007       retval = hash_insert (op_hash, vP->vot_name, (void *) &vP->vot_detail);
   1008 
   1009 #ifndef CONST_TABLE
   1010   vip_op_defaults (immediate, indirect, displen);
   1011 #endif
   1012 
   1013   return retval;
   1014 }
   1015 
   1016 /* Take 3 char.s, the last of which may be `\0` (non-existent)
   1017    and return the VAX register number that they represent.
   1018 
   1019    Return -1 if they don't form a register name. Good names return
   1020    a number from 0:15 inclusive.
   1021 
   1022    Case is not important in a name.
   1023 
   1024    Register names understood are:
   1025 
   1026   	R0
   1027   	R1
   1028   	R2
   1029   	R3
   1030   	R4
   1031   	R5
   1032   	R6
   1033    	R7
   1034   	R8
   1035   	R9
   1036   	R10
   1037   	R11
   1038   	R12	AP
   1039   	R13	FP
   1040   	R14	SP
   1041   	R15	PC  */
   1042 
   1043 #define AP 12
   1044 #define FP 13
   1045 #define SP 14
   1046 #define PC 15
   1047 
   1048 /* Returns the register number of something like '%r15' or 'ap', supplied
   1049    in four single chars. Returns -1 if the register isn't recognized,
   1050    0..15 otherwise.  */
   1051 static int
   1052 vax_reg_parse (char c1, char c2, char c3, char c4)
   1053 {
   1054   int retval = -1;
   1055 
   1056 #ifdef OBJ_ELF
   1057   if (c1 != '%')	/* Register prefixes are mandatory for ELF.  */
   1058     return retval;
   1059   c1 = c2;
   1060   c2 = c3;
   1061   c3 = c4;
   1062 #endif
   1063 #ifdef OBJ_VMS
   1064   if (c4 != 0)		/* Register prefixes are not allowed under VMS.  */
   1065     return retval;
   1066 #endif
   1067 #ifdef OBJ_AOUT
   1068   if (c1 == '%')	/* Register prefixes are optional under a.out.  */
   1069     {
   1070       c1 = c2;
   1071       c2 = c3;
   1072       c3 = c4;
   1073     }
   1074   else if (c3 && c4)	/* Can't be 4 characters long.  */
   1075     return retval;
   1076 #endif
   1077 
   1078   c1 = TOLOWER (c1);
   1079   c2 = TOLOWER (c2);
   1080   if (ISDIGIT (c2) && c1 == 'r')
   1081     {
   1082       retval = c2 - '0';
   1083       if (ISDIGIT (c3))
   1084 	{
   1085 	  retval = retval * 10 + c3 - '0';
   1086 	  retval = (retval > 15) ? -1 : retval;
   1087 	  /* clamp the register value to 1 hex digit */
   1088 	}
   1089       else if (c3)
   1090 	retval = -1;		/* c3 must be '\0' or a digit.  */
   1091     }
   1092   else if (c3)			/* There are no three letter regs.  */
   1093     retval = -1;
   1094   else if (c2 == 'p')
   1095     {
   1096       switch (c1)
   1097 	{
   1098 	case 's':
   1099 	  retval = SP;
   1100 	  break;
   1101 	case 'f':
   1102 	  retval = FP;
   1103 	  break;
   1104 	case 'a':
   1105 	  retval = AP;
   1106 	  break;
   1107 	default:
   1108 	  retval = -1;
   1109 	}
   1110     }
   1111   else if (c1 == 'p' && c2 == 'c')
   1112     retval = PC;
   1113   else
   1114     retval = -1;
   1115   return retval;
   1116 }
   1117 
   1118 #ifdef OBJ_AOUT
   1119 #ifndef BFD_ASSEMBLER
   1120 void
   1121 tc_aout_fix_to_chars (where, fixP, segment_address_in_file)
   1122      char *where;
   1123      fixS *fixP;
   1124      relax_addressT segment_address_in_file;
   1125 {
   1126   /*
   1127    * In: length of relocation (or of address) in chars: 1, 2 or 4.
   1128    * Out: GNU LD relocation length code: 0, 1, or 2.
   1129    */
   1130 
   1131   static const unsigned char nbytes_r_length[] = {42, 0, 1, 42, 2};
   1132   int r_symbolnum;
   1133   int r_flags;
   1134 
   1135   know (fixP->fx_addsy != NULL);
   1136 
   1137   md_number_to_chars (where,
   1138        fixP->fx_frag->fr_address + fixP->fx_where - segment_address_in_file,
   1139 		      4);
   1140 
   1141   r_symbolnum = (S_IS_DEFINED (fixP->fx_addsy)
   1142 		 ? S_GET_TYPE (fixP->fx_addsy)
   1143 		 : fixP->fx_addsy->sy_number);
   1144   r_flags = (fixP->fx_pcrel ? 1 : 0)
   1145       | (!S_IS_DEFINED (fixP->fx_addsy) ? 8 : 0)	/* extern */
   1146       | ((nbytes_r_length[fixP->fx_size] & 3) << 1);
   1147 
   1148 #if 0
   1149   r_flags |= ((!S_IS_DEFINED(fixP->fx_addsy)
   1150       && fixP->fx_pcrel
   1151       && fixP->fx_addsy != GOT_symbol
   1152       && fixP->fx_addsy != PLT_symbol
   1153       && flags_want_pic) ? 0x10 : 0);
   1154 #endif
   1155 
   1156   switch (fixP->fx_r_type) {
   1157 	case NO_RELOC:
   1158 		break;
   1159 	case NO_RELOC2:
   1160 		if (r_flags & 8)
   1161 		    r_flags |= 0x80;		/* setting the copy bit */
   1162 						/*   says we can convert */
   1163 						/*   to gotslot if needed */
   1164 		break;
   1165 	case RELOC_32:
   1166 		if (flag_want_pic && S_IS_EXTERNAL(fixP->fx_addsy)) {
   1167 			r_symbolnum = fixP->fx_addsy->sy_number;
   1168 			r_flags |= 8;		/* set extern bit */
   1169 		}
   1170 		break;
   1171 	case RELOC_JMP_SLOT:
   1172 		if (flag_want_pic) {
   1173 			r_flags |= 0x20;	/* set jmptable */
   1174 			r_flags &= ~0x08;	/* clear extern bit */
   1175 		}
   1176 		break;
   1177 	case RELOC_JMP_TBL:
   1178 		if (flag_want_pic) {
   1179 			r_flags |= 0x20;	/* set jmptable */
   1180 			r_flags |= 0x08;	/* set extern bit */
   1181 		}
   1182 		break;
   1183 	case RELOC_GLOB_DAT:
   1184 		if (flag_want_pic) {
   1185 			r_flags |= 0x10;	/* set baserel bit */
   1186 			r_symbolnum = fixP->fx_addsy->sy_number;
   1187 			if (S_IS_EXTERNAL(fixP->fx_addsy))
   1188 				r_flags |= 8;	/* set extern bit */
   1189 		}
   1190 		break;
   1191   }
   1192 
   1193   where[4] = (r_symbolnum >>  0) & 0xff;
   1194   where[5] = (r_symbolnum >>  8) & 0xff;
   1195   where[6] = (r_symbolnum >> 16) & 0xff;
   1196   where[7] = r_flags;
   1197 }
   1198 #endif /* !BFD_ASSEMBLER */
   1199 #endif /* OBJ_AOUT */
   1200 
   1201 /*
   1202  *       BUGS, GRIPES,  APOLOGIA, etc.
   1203  *
   1204  * The opcode table 'votstrs' needs to be sorted on opcode frequency.
   1205  * That is, AFTER we hash it with hash_...(), we want most-used opcodes
   1206  * to come out of the hash table faster.
   1207  *
   1208  * I am sorry to inflict yet another VAX assembler on the world, but
   1209  * RMS says we must do everything from scratch, to prevent pin-heads
   1210  * restricting this software.
   1211  */
   1212 
   1213 /*
   1214  * This is a vaguely modular set of routines in C to parse VAX
   1215  * assembly code using DEC mnemonics. It is NOT un*x specific.
   1216  *
   1217  * The idea here is that the assembler has taken care of all:
   1218  *   labels
   1219  *   macros
   1220  *   listing
   1221  *   pseudo-ops
   1222  *   line continuation
   1223  *   comments
   1224  *   condensing any whitespace down to exactly one space
   1225  * and all we have to do is parse 1 line into a vax instruction
   1226  * partially formed. We will accept a line, and deliver:
   1227  *   an error message (hopefully empty)
   1228  *   a skeleton VAX instruction (tree structure)
   1229  *   textual pointers to all the operand expressions
   1230  *   a warning message that notes a silly operand (hopefully empty)
   1231  */
   1232 
   1233 /*
   1235  *		E D I T   H I S T O R Y
   1236  *
   1237  * 17may86 Dean Elsner. Bug if line ends immediately after opcode.
   1238  * 30apr86 Dean Elsner. New vip_op() uses arg block so change call.
   1239  *  6jan86 Dean Elsner. Crock vip_begin() to call vip_op_defaults().
   1240  *  2jan86 Dean Elsner. Invent synthetic opcodes.
   1241  *	Widen vax_opcodeT to 32 bits. Use a bit for VIT_OPCODE_SYNTHETIC,
   1242  *	which means this is not a real opcode, it is like a macro; it will
   1243  *	be relax()ed into 1 or more instructions.
   1244  *	Use another bit for VIT_OPCODE_SPECIAL if the op-code is not optimised
   1245  *	like a regular branch instruction. Option added to vip_begin():
   1246  *	exclude	synthetic opcodes. Invent synthetic_votstrs[].
   1247  * 31dec85 Dean Elsner. Invent vit_opcode_nbytes.
   1248  *	Also make vit_opcode into a char[]. We now have n-byte vax opcodes,
   1249  *	so caller's don't have to know the difference between a 1-byte & a
   1250  *	2-byte op-code. Still need vax_opcodeT concept, so we know how
   1251  *	big an object must be to hold an op.code.
   1252  * 30dec85 Dean Elsner. Widen typedef vax_opcodeT in "vax-inst.h"
   1253  *	because vax opcodes may be 16 bits. Our crufty C compiler was
   1254  *	happily initialising 8-bit vot_codes with 16-bit numbers!
   1255  *	(Wouldn't the 'phone company like to compress data so easily!)
   1256  * 29dec85 Dean Elsner. New static table vax_operand_width_size[].
   1257  *	Invented so we know hw many bytes a "I^#42" needs in its immediate
   1258  *	operand. Revised struct vop in "vax-inst.h": explicitly include
   1259  *	byte length of each operand, and it's letter-code datum type.
   1260  * 17nov85 Dean Elsner. Name Change.
   1261  *	Due to ar(1) truncating names, we learned the hard way that
   1262  *	"vax-inst-parse.c" -> "vax-inst-parse." dropping the "o" off
   1263  *	the archived object name. SO... we shortened the name of this
   1264  *	source file, and changed the makefile.
   1265  */
   1266 
   1267 /* Parse a vax operand in DEC assembler notation.
   1268    For speed, expect a string of whitespace to be reduced to a single ' '.
   1269    This is the case for GNU AS, and is easy for other DEC-compatible
   1270    assemblers.
   1271 
   1272    Knowledge about DEC VAX assembler operand notation lives here.
   1273    This doesn't even know what a register name is, except it believes
   1274    all register names are 2 or 3 characters, and lets vax_reg_parse() say
   1275    what number each name represents.
   1276    It does, however, know that PC, SP etc are special registers so it can
   1277    detect addressing modes that are silly for those registers.
   1278 
   1279    Where possible, it delivers 1 fatal or 1 warning message if the operand
   1280    is suspect. Exactly what we test for is still evolving.
   1281 
   1282    ---
   1283   	Arg block.
   1284 
   1285    There were a number of 'mismatched argument type' bugs to vip_op.
   1286    The most general solution is to typedef each (of many) arguments.
   1287    We used instead a typedef'd argument block. This is less modular
   1288    than using separate return pointers for each result, but runs faster
   1289    on most engines, and seems to keep programmers happy. It will have
   1290    to be done properly if we ever want to use vip_op as a general-purpose
   1291    module (it was designed to be).
   1292 
   1293  	G^
   1294 
   1295    Doesn't support DEC "G^" format operands. These always take 5 bytes
   1296    to express, and code as modes 8F or 9F. Reason: "G^" deprives you of
   1297    optimising to (say) a "B^" if you are lucky in the way you link.
   1298    When someone builds a linker smart enough to convert "G^" to "B^", "W^"
   1299    whenever possible, then we should implement it.
   1300    If there is some other use for "G^", feel free to code it in!
   1301 
   1302   	speed
   1303 
   1304    If I nested if()s more, I could avoid testing (*err) which would save
   1305    time, space and page faults. I didn't nest all those if()s for clarity
   1306    and because I think the mode testing can be re-arranged 1st to test the
   1307    commoner constructs 1st. Does anybody have statistics on this?
   1308 
   1309   	error messages
   1310 
   1311    In future, we should be able to 'compose' error messages in a scratch area
   1312    and give the user MUCH more informative error messages. Although this takes
   1313    a little more code at run-time, it will make this module much more self-
   1314    documenting. As an example of what sucks now: most error messages have
   1315    hardwired into them the DEC VAX metacharacters "#^@" which are nothing like
   1316    the Un*x characters "$`*", that most users will expect from this AS.
   1317 
   1318    ----
   1319 
   1320    The input is a string, ending with '\0'.
   1321 
   1322    We also require a 'hint' of what kind of operand is expected: so
   1323    we can remind caller not to write into literals for instance.
   1324 
   1325    The output is a skeletal instruction.
   1326 
   1327    The algorithm has two parts.
   1328    1. extract the syntactic features (parse off all the @^#-()+[] mode crud);
   1329    2. express the @^#-()+[] as some parameters suited to further analysis.
   1330 
   1331    2nd step is where we detect the googles of possible invalid combinations
   1332    a human (or compiler) might write. Note that if we do a half-way
   1333    decent assembler, we don't know how long to make (eg) displacement
   1334    fields when we first meet them (because they may not have defined values).
   1335    So we must wait until we know how many bits are needed for each address,
   1336    then we can know both length and opcodes of instructions.
   1337    For reason(s) above, we will pass to our caller a 'broken' instruction
   1338    of these major components, from which our caller can generate instructions:
   1339     -  displacement length      I^ S^ L^ B^ W^ unspecified
   1340     -  mode                     (many)
   1341     -  register                 R0-R15 or absent
   1342     -  index register           R0-R15 or absent
   1343     -  expression text          what we don't parse
   1344     -  error text(s)            why we couldn't understand the operand
   1345 
   1346    ----
   1347 
   1348    To decode output of this, test errtxt. If errtxt[0] == '\0', then
   1349    we had no errors that prevented parsing. Also, if we ever report
   1350    an internal bug, errtxt[0] is set non-zero. So one test tells you
   1351    if the other outputs are to be taken seriously.
   1352 
   1353    ----
   1354 
   1355    Dec defines the semantics of address modes (and values)
   1356    by a two-letter code, explained here.
   1357 
   1358      letter 1:   access type
   1359 
   1360        a         address calculation - no data access, registers forbidden
   1361        b         branch displacement
   1362        m         read - let go of bus - write back    "modify"
   1363        r         read
   1364        v         bit field address: like 'a' but registers are OK
   1365        w         write
   1366        space	 no operator (eg ".long foo") [our convention]
   1367 
   1368      letter 2:   data type (i.e. width, alignment)
   1369 
   1370        b         byte
   1371        d         double precision floating point (D format)
   1372        f         single precision floating point (F format)
   1373        g         G format floating
   1374        h         H format floating
   1375        l         longword
   1376        o         octaword
   1377        q         quadword
   1378        w         word
   1379        ?	 simple synthetic branch operand
   1380        -	 unconditional synthetic JSB/JSR operand
   1381        !	 complex synthetic branch operand
   1382 
   1383    The '-?!' letter 2's are not for external consumption. They are used
   1384    for various assemblers. Generally, all unknown widths are assumed 0.
   1385    We don't limit your choice of width character.
   1386 
   1387    DEC operands are hard work to parse. For example, '@' as the first
   1388    character means indirect (deferred) mode but elsewhere it is a shift
   1389    operator.
   1390    The long-winded explanation of how this is supposed to work is
   1391    cancelled. Read a DEC vax manual.
   1392    We try hard not to parse anything that MIGHT be part of the expression
   1393    buried in that syntax. For example if we see @...(Rn) we don't check
   1394    for '-' before the '(' because mode @-(Rn) does not exist.
   1395 
   1396    After parsing we have:
   1397 
   1398    at                     1 if leading '@' (or Un*x '*')
   1399    len                    takes one value from " bilsw". eg B^ -> 'b'.
   1400    hash                   1 if leading '#' (or Un*x '$')
   1401    expr_begin, expr_end   the expression we did not parse
   1402                           even though we don't interpret it, we make use
   1403                           of its presence or absence.
   1404    sign                   -1: -(Rn)    0: absent    +1: (Rn)+
   1405    paren                  1 if () are around register
   1406    reg                    major register number 0:15    -1 means absent
   1407    ndx                    index register number 0:15    -1 means absent
   1408 
   1409    Again, I dare not explain it: just trace ALL the code!
   1410 
   1411    Summary of vip_op outputs.
   1412 
   1413   mode	reg	len	ndx
   1414   (Rn) => @Rn
   1415   {@}Rn			5+@	n	' '	optional
   1416   branch operand		0	-1	' '	-1
   1417   S^#foo			0	-1	's'	-1
   1418   -(Rn)			7	n	' '	optional
   1419   {@}(Rn)+		8+@	n	' '	optional
   1420   {@}#foo, no S^		8+@	PC	" i"	optional
   1421   {@}{q^}{(Rn)}		10+@+q	option	" bwl"	optional  */
   1422 
   1423 /* Dissect user-input 'optext' (which is something like "@B^foo@bar(AP)[FP]:")
   1424    using the vop in vopP. vopP's vop_access and vop_width. We fill _ndx, _reg,
   1425    _mode, _short, _warn, _error, _expr_begin, _expr_end and _nbytes.  */
   1426 
   1427 static void
   1428 vip_op (char *optext, struct vop *vopP)
   1429 {
   1430   /* Track operand text forward.  */
   1431   char *p;
   1432   /* Track operand text backward.  */
   1433   char *q;
   1434   /* 1 if leading '@' ('*') seen.  */
   1435   int at;
   1436   /* one of " bilsw" */
   1437   char len;
   1438   /* 1 if leading '#' ('$') seen.  */
   1439   int hash;
   1440   /* -1, 0 or +1.  */
   1441   int sign = 0;
   1442   /* 1 if () surround register.  */
   1443   int paren = 0;
   1444   /* Register number, -1:absent.  */
   1445   int reg = 0;
   1446   /* Index register number -1:absent.  */
   1447   int ndx = 0;
   1448   /* Report illegal operand, ""==OK.  */
   1449   /* " " is a FAKE error: means we won.  */
   1450   /* ANY err that begins with ' ' is a fake.  */
   1451   /* " " is converted to "" before return.  */
   1452   const char *err;
   1453   /* Warn about weird modes pf address.  */
   1454   const char *wrn;
   1455   /* Preserve q in case we backup.  */
   1456   char *oldq = NULL;
   1457   /* Build up 4-bit operand mode here.  */
   1458   /* Note: index mode is in ndx, this is.  */
   1459   /* The major mode of operand address.  */
   1460   int mode = 0;
   1461   /* Notice how we move wrong-arg-type bugs INSIDE this module: if we
   1462      get the types wrong below, we lose at compile time rather than at
   1463      lint or run time.  */
   1464   char access_mode;		/* vop_access.  */
   1465 
   1466   access_mode = vopP->vop_access;
   1467   /* None of our code bugs (yet), no user text errors, no warnings
   1468      even.  */
   1469   err = wrn = 0;
   1470 
   1471   p = optext;
   1472 
   1473   if (*p == ' ')		/* Expect all whitespace reduced to ' '.  */
   1474     p++;			/* skip over whitespace */
   1475 
   1476   if ((at = INDIRECTP (*p)) != 0)
   1477     {				/* 1 if *p=='@'(or '*' for Un*x) */
   1478       p++;			/* at is determined */
   1479       if (*p == ' ')		/* Expect all whitespace reduced to ' '.  */
   1480 	p++;			/* skip over whitespace */
   1481     }
   1482 
   1483   /* This code is subtle. It tries to detect all legal (letter)'^'
   1484      but it doesn't waste time explicitly testing for premature '\0' because
   1485      this case is rejected as a mismatch against either (letter) or '^'.  */
   1486   {
   1487     char c;
   1488 
   1489     c = *p;
   1490     c = TOLOWER (c);
   1491     if (DISPLENP (p[1]) && strchr ("bilws", len = c))
   1492       p += 2;			/* Skip (letter) '^'.  */
   1493     else			/* No (letter) '^' seen.  */
   1494       len = ' ';		/* Len is determined.  */
   1495   }
   1496 
   1497   if (*p == ' ')		/* Expect all whitespace reduced to ' '.  */
   1498     p++;
   1499 
   1500   if ((hash = IMMEDIATEP (*p)) != 0)	/* 1 if *p=='#' ('$' for Un*x) */
   1501     p++;			/* Hash is determined.  */
   1502 
   1503   /* p points to what may be the beginning of an expression.
   1504      We have peeled off the front all that is peelable.
   1505      We know at, len, hash.
   1506 
   1507      Lets point q at the end of the text and parse that (backwards).  */
   1508 
   1509   for (q = p; *q; q++)
   1510     ;
   1511   q--;				/* Now q points at last char of text.  */
   1512 
   1513   if (*q == ' ' && q >= p)	/* Expect all whitespace reduced to ' '.  */
   1514     q--;
   1515 
   1516   /* Reverse over whitespace, but don't.  */
   1517   /* Run back over *p.  */
   1518 
   1519   /* As a matter of policy here, we look for [Rn], although both Rn and S^#
   1520      forbid [Rn]. This is because it is easy, and because only a sick
   1521      cyborg would have [...] trailing an expression in a VAX-like assembler.
   1522      A meticulous parser would first check for Rn followed by '(' or '['
   1523      and not parse a trailing ']' if it found another. We just ban expressions
   1524      ending in ']'.  */
   1525   if (*q == ']')
   1526     {
   1527       while (q >= p && *q != '[')
   1528 	q--;
   1529       /* Either q<p or we got matching '['.  */
   1530       if (q < p)
   1531 	err = _("no '[' to match ']'");
   1532       else
   1533 	{
   1534 	  /* Confusers like "[]" will eventually lose with a bad register
   1535 	   * name error. So again we don't need to check for early '\0'.  */
   1536 	  if (q[3] == ']')
   1537 	    ndx = vax_reg_parse (q[1], q[2], 0, 0);
   1538 	  else if (q[4] == ']')
   1539 	    ndx = vax_reg_parse (q[1], q[2], q[3], 0);
   1540 	  else if (q[5] == ']')
   1541 	    ndx = vax_reg_parse (q[1], q[2], q[3], q[4]);
   1542 	  else
   1543 	    ndx = -1;
   1544 	  /* Since we saw a ']' we will demand a register name in the [].
   1545 	   * If luser hasn't given us one: be rude.  */
   1546 	  if (ndx < 0)
   1547 	    err = _("bad register in []");
   1548 	  else if (ndx == PC)
   1549 	    err = _("[PC] index banned");
   1550 	  else
   1551 	    /* Point q just before "[...]".  */
   1552 	    q--;
   1553 	}
   1554     }
   1555   else
   1556     /* No ']', so no iNDeX register.  */
   1557     ndx = -1;
   1558 
   1559   /* If err = "..." then we lost: run away.
   1560      Otherwise ndx == -1 if there was no "[...]".
   1561      Otherwise, ndx is index register number, and q points before "[...]".  */
   1562 
   1563   if (*q == ' ' && q >= p)	/* Expect all whitespace reduced to ' '.  */
   1564     q--;
   1565   /* Reverse over whitespace, but don't.  */
   1566   /* Run back over *p.  */
   1567   if (!err || !*err)
   1568     {
   1569       /* no ()+ or -() seen yet */
   1570       sign = 0;
   1571 
   1572       if (q > p + 3 && *q == '+' && q[-1] == ')')
   1573 	{
   1574 	  sign = 1;		/* we saw a ")+" */
   1575 	  q--;			/* q points to ')' */
   1576 	}
   1577 
   1578       if (*q == ')' && q > p + 2)
   1579 	{
   1580 	  paren = 1;		/* assume we have "(...)" */
   1581 	  while (q >= p && *q != '(')
   1582 	    q--;
   1583 	  /* either q<p or we got matching '(' */
   1584 	  if (q < p)
   1585 	    err = _("no '(' to match ')'");
   1586 	  else
   1587 	    {
   1588 	      /* Confusers like "()" will eventually lose with a bad register
   1589 	         name error. So again we don't need to check for early '\0'.  */
   1590 	      if (q[3] == ')')
   1591 		reg = vax_reg_parse (q[1], q[2], 0, 0);
   1592 	      else if (q[4] == ')')
   1593 		reg = vax_reg_parse (q[1], q[2], q[3], 0);
   1594 	      else if (q[5] == ')')
   1595 		reg = vax_reg_parse (q[1], q[2], q[3], q[4]);
   1596 	      else
   1597 		reg = -1;
   1598 	      /* Since we saw a ')' we will demand a register name in the ')'.
   1599 	         This is nasty: why can't our hypothetical assembler permit
   1600 	         parenthesised expressions? BECAUSE I AM LAZY! That is why.
   1601 	         Abuse luser if we didn't spy a register name.  */
   1602 	      if (reg < 0)
   1603 		{
   1604 		  /* JF allow parenthesized expressions.  I hope this works.  */
   1605 		  paren = 0;
   1606 		  while (*q != ')')
   1607 		    q++;
   1608 		  /* err = "unknown register in ()"; */
   1609 		}
   1610 	      else
   1611 		q--;		/* point just before '(' of "(...)" */
   1612 	      /* If err == "..." then we lost. Run away.
   1613 	         Otherwise if reg >= 0 then we saw (Rn).  */
   1614 	    }
   1615 	  /* If err == "..." then we lost.
   1616 	     Otherwise paren==1 and reg = register in "()".  */
   1617 	}
   1618       else
   1619 	paren = 0;
   1620       /* If err == "..." then we lost.
   1621          Otherwise, q points just before "(Rn)", if any.
   1622          If there was a "(...)" then paren==1, and reg is the register.  */
   1623 
   1624       /* We should only seek '-' of "-(...)" if:
   1625            we saw "(...)"                    paren == 1
   1626            we have no errors so far          ! *err
   1627            we did not see '+' of "(...)+"    sign < 1
   1628          We don't check len. We want a specific error message later if
   1629          user tries "x^...-(Rn)". This is a feature not a bug.  */
   1630       if (!err || !*err)
   1631 	{
   1632 	  if (paren && sign < 1)/* !sign is adequate test */
   1633 	    {
   1634 	      if (*q == '-')
   1635 		{
   1636 		  sign = -1;
   1637 		  q--;
   1638 		}
   1639 	    }
   1640 	  /* We have back-tracked over most
   1641 	     of the crud at the end of an operand.
   1642 	     Unless err, we know: sign, paren. If paren, we know reg.
   1643 	     The last case is of an expression "Rn".
   1644 	     This is worth hunting for if !err, !paren.
   1645 	     We wouldn't be here if err.
   1646 	     We remember to save q, in case we didn't want "Rn" anyway.  */
   1647 	  if (!paren)
   1648 	    {
   1649 	      if (*q == ' ' && q >= p)	/* Expect all whitespace reduced to ' '.  */
   1650 		q--;
   1651 	      /* Reverse over whitespace, but don't.  */
   1652 	      /* Run back over *p.  */
   1653 	      /* Room for Rn or Rnn (include prefix) exactly?  */
   1654 	      if (q > p && q < p + 4)
   1655 		reg = vax_reg_parse (p[0], p[1],
   1656 		  q < p + 2 ? 0 : p[2],
   1657 		  q < p + 3 ? 0 : p[3]);
   1658 	      else
   1659 		reg = -1;	/* Always comes here if no register at all.  */
   1660 	      /* Here with a definitive reg value.  */
   1661 	      if (reg >= 0)
   1662 		{
   1663 		  oldq = q;
   1664 		  q = p - 1;
   1665 		}
   1666 	    }
   1667 	}
   1668     }
   1669   /* have reg. -1:absent; else 0:15.  */
   1670 
   1671   /* We have:  err, at, len, hash, ndx, sign, paren, reg.
   1672      Also, any remaining expression is from *p through *q inclusive.
   1673      Should there be no expression, q==p-1. So expression length = q-p+1.
   1674      This completes the first part: parsing the operand text.  */
   1675 
   1676   /* We now want to boil the data down, checking consistency on the way.
   1678      We want:  len, mode, reg, ndx, err, p, q, wrn, bug.
   1679      We will deliver a 4-bit reg, and a 4-bit mode.  */
   1680 
   1681   /* Case of branch operand. Different. No L^B^W^I^S^ allowed for instance.
   1682 
   1683      in:  at	?
   1684           len	?
   1685           hash	?
   1686           p:q	?
   1687           sign  ?
   1688           paren	?
   1689           reg   ?
   1690           ndx   ?
   1691 
   1692      out: mode  0
   1693           reg   -1
   1694           len	' '
   1695           p:q	whatever was input
   1696           ndx	-1
   1697           err	" "		 or error message, and other outputs trashed.  */
   1698   /* Branch operands have restricted forms.  */
   1699   if ((!err || !*err) && access_mode == 'b')
   1700     {
   1701       if (at || hash || sign || paren || ndx >= 0 || reg >= 0 || len != ' ')
   1702 	err = _("invalid branch operand");
   1703       else
   1704 	err = " ";
   1705     }
   1706 
   1707   /* Since nobody seems to use it: comment this 'feature'(?) out for now.  */
   1708 #ifdef NEVER
   1709   /* Case of stand-alone operand. e.g. ".long foo"
   1710 
   1711      in:  at	?
   1712           len	?
   1713           hash	?
   1714           p:q	?
   1715           sign  ?
   1716           paren	?
   1717           reg   ?
   1718           ndx   ?
   1719 
   1720      out: mode  0
   1721           reg   -1
   1722           len	' '
   1723           p:q	whatever was input
   1724           ndx	-1
   1725           err	" "		 or error message, and other outputs trashed.  */
   1726   if ((!err || !*err) && access_mode == ' ')
   1727     {
   1728       if (at)
   1729 	err = _("address prohibits @");
   1730       else if (hash)
   1731 	err = _("address prohibits #");
   1732       else if (sign)
   1733 	{
   1734 	  if (sign < 0)
   1735 	    err = _("address prohibits -()");
   1736 	  else
   1737 	    err = _("address prohibits ()+");
   1738 	}
   1739       else if (paren)
   1740 	err = _("address prohibits ()");
   1741       else if (ndx >= 0)
   1742 	err = _("address prohibits []");
   1743       else if (reg >= 0)
   1744 	err = _("address prohibits register");
   1745       else if (len != ' ')
   1746 	err = _("address prohibits displacement length specifier");
   1747       else
   1748 	{
   1749 	  err = " ";	/* succeed */
   1750 	  mode = 0;
   1751 	}
   1752     }
   1753 #endif
   1754 
   1755   /* Case of S^#.
   1756 
   1757      in:  at       0
   1758           len      's'               definition
   1759           hash     1              demand
   1760           p:q                        demand not empty
   1761           sign     0                 by paren==0
   1762           paren    0             by "()" scan logic because "S^" seen
   1763           reg      -1                or nn by mistake
   1764           ndx      -1
   1765 
   1766      out: mode     0
   1767           reg      -1
   1768           len      's'
   1769           exp
   1770           ndx      -1  */
   1771   if ((!err || !*err) && len == 's')
   1772     {
   1773       if (!hash || paren || at || ndx >= 0)
   1774 	err = _("invalid operand of S^#");
   1775       else
   1776 	{
   1777 	  if (reg >= 0)
   1778 	    {
   1779 	      /* Darn! we saw S^#Rnn ! put the Rnn back in
   1780 	         expression. KLUDGE! Use oldq so we don't
   1781 	         need to know exact length of reg name.  */
   1782 	      q = oldq;
   1783 	      reg = 0;
   1784 	    }
   1785 	  /* We have all the expression we will ever get.  */
   1786 	  if (p > q)
   1787 	    err = _("S^# needs expression");
   1788 	  else if (access_mode == 'r')
   1789 	    {
   1790 	      err = " ";	/* WIN! */
   1791 	      mode = 0;
   1792 	    }
   1793 	  else
   1794 	    err = _("S^# may only read-access");
   1795 	}
   1796     }
   1797 
   1798   /* Case of -(Rn), which is weird case.
   1799 
   1800      in:  at       0
   1801           len      '
   1802           hash     0
   1803           p:q      q<p
   1804           sign     -1                by definition
   1805           paren    1              by definition
   1806           reg      present           by definition
   1807           ndx      optional
   1808 
   1809      out: mode     7
   1810           reg      present
   1811           len      ' '
   1812           exp      ""                enforce empty expression
   1813           ndx      optional          warn if same as reg.  */
   1814   if ((!err || !*err) && sign < 0)
   1815     {
   1816       if (len != ' ' || hash || at || p <= q)
   1817 	err = _("invalid operand of -()");
   1818       else
   1819 	{
   1820 	  err = " ";		/* win */
   1821 	  mode = 7;
   1822 	  if (reg == PC)
   1823 	    wrn = _("-(PC) unpredictable");
   1824 	  else if (reg == ndx)
   1825 	    wrn = _("[]index same as -()register: unpredictable");
   1826 	}
   1827     }
   1828 
   1829   /* We convert "(Rn)" to "@Rn" for our convenience.
   1830      (I hope this is convenient: has someone got a better way to parse this?)
   1831      A side-effect of this is that "@Rn" is a valid operand.  */
   1832   if (paren && !sign && !hash && !at && len == ' ' && p > q)
   1833     {
   1834       at = 1;
   1835       paren = 0;
   1836     }
   1837 
   1838   /* Case of (Rn)+, which is slightly different.
   1839 
   1840      in:  at
   1841           len      ' '
   1842           hash     0
   1843           p:q      q<p
   1844           sign     +1                by definition
   1845           paren    1              by definition
   1846           reg      present           by definition
   1847           ndx      optional
   1848 
   1849      out: mode     8+@
   1850           reg      present
   1851           len      ' '
   1852           exp      ""                enforce empty expression
   1853           ndx      optional          warn if same as reg.  */
   1854   if ((!err || !*err) && sign > 0)
   1855     {
   1856       if (len != ' ' || hash || p <= q)
   1857 	err = _("invalid operand of ()+");
   1858       else
   1859 	{
   1860 	  err = " ";		/* win */
   1861 	  mode = 8 + (at ? 1 : 0);
   1862 	  if (reg == PC)
   1863 	    wrn = _("(PC)+ unpredictable");
   1864 	  else if (reg == ndx)
   1865 	    wrn = _("[]index same as ()+register: unpredictable");
   1866 	}
   1867     }
   1868 
   1869   /* Case of #, without S^.
   1870 
   1871      in:  at
   1872           len      ' ' or 'i'
   1873           hash     1              by definition
   1874           p:q
   1875           sign     0
   1876           paren    0
   1877           reg      absent
   1878           ndx      optional
   1879 
   1880      out: mode     8+@
   1881           reg      PC
   1882           len      ' ' or 'i'
   1883           exp
   1884           ndx      optional.  */
   1885   if ((!err || !*err) && hash)
   1886     {
   1887       if (len != 'i' && len != ' ')
   1888 	err = _("# conflicts length");
   1889       else if (paren)
   1890 	err = _("# bars register");
   1891       else
   1892 	{
   1893 	  if (reg >= 0)
   1894 	    {
   1895 	      /* Darn! we saw #Rnn! Put the Rnn back into the expression.
   1896 	         By using oldq, we don't need to know how long Rnn was.
   1897 	         KLUDGE!  */
   1898 	      q = oldq;
   1899 	      reg = -1;		/* No register any more.  */
   1900 	    }
   1901 	  err = " ";		/* Win.  */
   1902 
   1903 	  /* JF a bugfix, I think!  */
   1904 	  if (at && access_mode == 'a')
   1905 	    vopP->vop_nbytes = 4;
   1906 
   1907 	  mode = (at ? 9 : 8);
   1908 	  reg = PC;
   1909 	  if ((access_mode == 'm' || access_mode == 'w') && !at)
   1910 	    wrn = _("writing or modifying # is unpredictable");
   1911 	}
   1912     }
   1913   /* If !*err, then       sign == 0
   1914                           hash == 0 */
   1915 
   1916   /* Case of Rn. We separate this one because it has a few special
   1917      errors the remaining modes lack.
   1918 
   1919      in:  at       optional
   1920           len      ' '
   1921           hash     0             by program logic
   1922           p:q      empty
   1923           sign     0                 by program logic
   1924           paren    0             by definition
   1925           reg      present           by definition
   1926           ndx      optional
   1927 
   1928      out: mode     5+@
   1929           reg      present
   1930           len      ' '               enforce no length
   1931           exp      ""                enforce empty expression
   1932           ndx      optional          warn if same as reg.  */
   1933   if ((!err || !*err) && !paren && reg >= 0)
   1934     {
   1935       if (len != ' ')
   1936 	err = _("length not needed");
   1937       else if (at)
   1938 	{
   1939 	  err = " ";		/* win */
   1940 	  mode = 6;		/* @Rn */
   1941 	}
   1942       else if (ndx >= 0)
   1943 	err = _("can't []index a register, because it has no address");
   1944       else if (access_mode == 'a')
   1945 	err = _("a register has no address");
   1946       else
   1947 	{
   1948 	  /* Idea here is to detect from length of datum
   1949 	     and from register number if we will touch PC.
   1950 	     Warn if we do.
   1951 	     vop_nbytes is number of bytes in operand.
   1952 	     Compute highest byte affected, compare to PC0.  */
   1953 	  if ((vopP->vop_nbytes + reg * 4) > 60)
   1954 	    wrn = _("PC part of operand unpredictable");
   1955 	  err = " ";		/* win */
   1956 	  mode = 5;		/* Rn */
   1957 	}
   1958     }
   1959   /* If !*err,        sign  == 0
   1960                       hash  == 0
   1961                       paren == 1  OR reg==-1  */
   1962 
   1963   /* Rest of cases fit into one bunch.
   1964 
   1965      in:  at       optional
   1966           len      ' ' or 'b' or 'w' or 'l'
   1967           hash     0             by program logic
   1968           p:q      expected          (empty is not an error)
   1969           sign     0                 by program logic
   1970           paren    optional
   1971           reg      optional
   1972           ndx      optional
   1973 
   1974      out: mode     10 + @ + len
   1975           reg      optional
   1976           len      ' ' or 'b' or 'w' or 'l'
   1977           exp                        maybe empty
   1978           ndx      optional          warn if same as reg.  */
   1979   if (!err || !*err)
   1980     {
   1981       err = " ";		/* win (always) */
   1982       mode = 10 + (at ? 1 : 0);
   1983       switch (len)
   1984 	{
   1985 	case 'l':
   1986 	  mode += 2;
   1987 	  /* Fall through.  */
   1988 	case 'w':
   1989 	  mode += 2;
   1990 	  /* Fall through.  */
   1991 	case ' ':	/* Assumed B^ until our caller changes it.  */
   1992 	case 'b':
   1993 	  break;
   1994 	}
   1995     }
   1996 
   1997   /* here with completely specified     mode
   1998     					len
   1999     					reg
   2000     					expression   p,q
   2001     					ndx.  */
   2002 
   2003   if (*err == ' ')
   2004     err = 0;			/* " " is no longer an error.  */
   2005 
   2006   vopP->vop_mode = mode;
   2007   vopP->vop_reg = reg;
   2008   vopP->vop_short = len;
   2009   vopP->vop_expr_begin = p;
   2010   vopP->vop_expr_end = q;
   2011   vopP->vop_ndx = ndx;
   2012   vopP->vop_error = err;
   2013   vopP->vop_warn = wrn;
   2014 }
   2015 
   2016 /* This converts a string into a vax instruction.
   2017    The string must be a bare single instruction in dec-vax (with BSD4 frobs)
   2018    format.
   2019    It provides some error messages: at most one fatal error message (which
   2020    stops the scan) and at most one warning message for each operand.
   2021    The vax instruction is returned in exploded form, since we have no
   2022    knowledge of how you parse (or evaluate) your expressions.
   2023    We do however strip off and decode addressing modes and operation
   2024    mnemonic.
   2025 
   2026    The exploded instruction is returned to a struct vit of your choice.
   2027    #include "vax-inst.h" to know what a struct vit is.
   2028 
   2029    This function's value is a string. If it is not "" then an internal
   2030    logic error was found: read this code to assign meaning to the string.
   2031    No argument string should generate such an error string:
   2032    it means a bug in our code, not in the user's text.
   2033 
   2034    You MUST have called vip_begin() once before using this function.  */
   2035 
   2036 static void
   2037 vip (struct vit *vitP,		/* We build an exploded instruction here.  */
   2038      char *instring)		/* Text of a vax instruction: we modify.  */
   2039 {
   2040   /* How to bit-encode this opcode.  */
   2041   struct vot_wot *vwP;
   2042   /* 1/skip whitespace.2/scan vot_how */
   2043   char *p;
   2044   char *q;
   2045   /* counts number of operands seen */
   2046   unsigned char count;
   2047   /* scan operands in struct vit */
   2048   struct vop *operandp;
   2049   /* error over all operands */
   2050   const char *alloperr;
   2051   /* Remember char, (we clobber it with '\0' temporarily).  */
   2052   char c;
   2053   /* Op-code of this instruction.  */
   2054   vax_opcodeT oc;
   2055 
   2056   if (*instring == ' ')
   2057     ++instring;
   2058 
   2059   /* MUST end in end-of-string or exactly 1 space.  */
   2060   for (p = instring; *p && *p != ' '; p++)
   2061     ;
   2062 
   2063   /* Scanned up to end of operation-code.  */
   2064   /* Operation-code is ended with whitespace.  */
   2065   if (p - instring == 0)
   2066     {
   2067       vitP->vit_error = _("No operator");
   2068       count = 0;
   2069       memset (vitP->vit_opcode, '\0', sizeof (vitP->vit_opcode));
   2070     }
   2071   else
   2072     {
   2073       c = *p;
   2074       *p = '\0';
   2075       /* Here with instring pointing to what better be an op-name, and p
   2076          pointing to character just past that.
   2077          We trust instring points to an op-name, with no whitespace.  */
   2078       vwP = (struct vot_wot *) hash_find (op_hash, instring);
   2079       /* Restore char after op-code.  */
   2080       *p = c;
   2081       if (vwP == 0)
   2082 	{
   2083 	  vitP->vit_error = _("Unknown operator");
   2084 	  count = 0;
   2085 	  memset (vitP->vit_opcode, '\0', sizeof (vitP->vit_opcode));
   2086 	}
   2087       else
   2088 	{
   2089 	  /* We found a match! So let's pick up as many operands as the
   2090 	     instruction wants, and even gripe if there are too many.
   2091 	     We expect comma to separate each operand.
   2092 	     We let instring track the text, while p tracks a part of the
   2093 	     struct vot.  */
   2094 	  const char *howp;
   2095 	  /* The lines below know about 2-byte opcodes starting FD,FE or FF.
   2096 	     They also understand synthetic opcodes. Note:
   2097 	     we return 32 bits of opcode, including bucky bits, BUT
   2098 	     an opcode length is either 8 or 16 bits for vit_opcode_nbytes.  */
   2099 	  oc = vwP->vot_code;	/* The op-code.  */
   2100 	  vitP->vit_opcode_nbytes = (oc & 0xFF) >= 0xFD ? 2 : 1;
   2101 	  md_number_to_chars (vitP->vit_opcode, oc, 4);
   2102 	  count = 0;		/* No operands seen yet.  */
   2103 	  instring = p;		/* Point just past operation code.  */
   2104 	  alloperr = "";
   2105 	  for (howp = vwP->vot_how, operandp = vitP->vit_operand;
   2106 	       !(alloperr && *alloperr) && *howp;
   2107 	       operandp++, howp += 2)
   2108 	    {
   2109 	      /* Here to parse one operand. Leave instring pointing just
   2110 	         past any one ',' that marks the end of this operand.  */
   2111 	      if (!howp[1])
   2112 		as_fatal (_("odd number of bytes in operand description"));
   2113 	      else if (*instring)
   2114 		{
   2115 		  for (q = instring; (c = *q) && c != ','; q++)
   2116 		    ;
   2117 		  /* Q points to ',' or '\0' that ends argument. C is that
   2118 		     character.  */
   2119 		  *q = 0;
   2120 		  operandp->vop_width = howp[1];
   2121 		  operandp->vop_nbytes = vax_operand_width_size[(unsigned) howp[1]];
   2122 		  operandp->vop_access = howp[0];
   2123 		  vip_op (instring, operandp);
   2124 		  *q = c;	/* Restore input text.  */
   2125 		  if (operandp->vop_error)
   2126 		    alloperr = _("Bad operand");
   2127 		  instring = q + (c ? 1 : 0);	/* Next operand (if any).  */
   2128 		  count++;	/*  Won another argument, may have an operr.  */
   2129 		}
   2130 	      else
   2131 		alloperr = _("Not enough operands");
   2132 	    }
   2133 	  if (!*alloperr)
   2134 	    {
   2135 	      if (*instring == ' ')
   2136 		instring++;
   2137 	      if (*instring)
   2138 		alloperr = _("Too many operands");
   2139 	    }
   2140 	  vitP->vit_error = alloperr;
   2141 	}
   2142     }
   2143   vitP->vit_operands = count;
   2144 }
   2145 
   2146 #ifdef test
   2148 
   2149 /* Test program for above.  */
   2150 
   2151 struct vit myvit;		/* Build an exploded vax instruction here.  */
   2152 char answer[100];		/* Human types a line of vax assembler here.  */
   2153 char *mybug;			/* "" or an internal logic diagnostic.  */
   2154 int mycount;			/* Number of operands.  */
   2155 struct vop *myvop;		/* Scan operands from myvit.  */
   2156 int mysynth;			/* 1 means want synthetic opcodes.  */
   2157 char my_immediate[200];
   2158 char my_indirect[200];
   2159 char my_displen[200];
   2160 
   2161 int
   2162 main (void)
   2163 {
   2164   char *p;
   2165 
   2166   printf ("0 means no synthetic instructions.   ");
   2167   printf ("Value for vip_begin?  ");
   2168   gets (answer);
   2169   sscanf (answer, "%d", &mysynth);
   2170   printf ("Synthetic opcodes %s be included.\n", mysynth ? "will" : "will not");
   2171   printf ("enter immediate symbols eg enter #   ");
   2172   gets (my_immediate);
   2173   printf ("enter indirect symbols  eg enter @   ");
   2174   gets (my_indirect);
   2175   printf ("enter displen symbols   eg enter ^   ");
   2176   gets (my_displen);
   2177 
   2178   if (p = vip_begin (mysynth, my_immediate, my_indirect, my_displen))
   2179     error ("vip_begin=%s", p);
   2180 
   2181   printf ("An empty input line will quit you from the vax instruction parser\n");
   2182   for (;;)
   2183     {
   2184       printf ("vax instruction: ");
   2185       fflush (stdout);
   2186       gets (answer);
   2187       if (!*answer)
   2188 	break;		/* Out of for each input text loop.  */
   2189 
   2190       vip (& myvit, answer);
   2191       if (*myvit.vit_error)
   2192 	printf ("ERR:\"%s\"\n", myvit.vit_error);
   2193 
   2194       printf ("opcode=");
   2195       for (mycount = myvit.vit_opcode_nbytes, p = myvit.vit_opcode;
   2196 	   mycount;
   2197 	   mycount--, p++)
   2198 	printf ("%02x ", *p & 0xFF);
   2199 
   2200       printf ("   operand count=%d.\n", mycount = myvit.vit_operands);
   2201       for (myvop = myvit.vit_operand; mycount; mycount--, myvop++)
   2202 	{
   2203 	  printf ("mode=%xx reg=%xx ndx=%xx len='%c'=%c%c%d. expr=\"",
   2204 		  myvop->vop_mode, myvop->vop_reg, myvop->vop_ndx,
   2205 		  myvop->vop_short, myvop->vop_access, myvop->vop_width,
   2206 		  myvop->vop_nbytes);
   2207 	  for (p = myvop->vop_expr_begin; p <= myvop->vop_expr_end; p++)
   2208 	    putchar (*p);
   2209 
   2210 	  printf ("\"\n");
   2211 	  if (myvop->vop_error)
   2212 	    printf ("  err:\"%s\"\n", myvop->vop_error);
   2213 
   2214 	  if (myvop->vop_warn)
   2215 	    printf ("  wrn:\"%s\"\n", myvop->vop_warn);
   2216 	}
   2217     }
   2218   vip_end ();
   2219   exit (EXIT_SUCCESS);
   2220 }
   2221 
   2222 #endif
   2223 
   2224 #ifdef TEST			/* #Define to use this testbed.  */
   2226 
   2227 /* Follows a test program for this function.
   2228    We declare arrays non-local in case some of our tiny-minded machines
   2229    default to small stacks. Also, helps with some debuggers.  */
   2230 
   2231 char answer[100];		/* Human types into here.  */
   2232 char *p;			/*  */
   2233 char *myerr;
   2234 char *mywrn;
   2235 char *mybug;
   2236 char myaccess;
   2237 char mywidth;
   2238 char mymode;
   2239 char myreg;
   2240 char mylen;
   2241 char *myleft;
   2242 char *myright;
   2243 char myndx;
   2244 int my_operand_length;
   2245 char my_immediate[200];
   2246 char my_indirect[200];
   2247 char my_displen[200];
   2248 
   2249 int
   2250 main (void)
   2251 {
   2252   printf ("enter immediate symbols eg enter #   ");
   2253   gets (my_immediate);
   2254   printf ("enter indirect symbols  eg enter @   ");
   2255   gets (my_indirect);
   2256   printf ("enter displen symbols   eg enter ^   ");
   2257   gets (my_displen);
   2258   vip_op_defaults (my_immediate, my_indirect, my_displen);
   2259 
   2260   for (;;)
   2261     {
   2262       printf ("access,width (eg 'ab' or 'wh') [empty line to quit] :  ");
   2263       fflush (stdout);
   2264       gets (answer);
   2265       if (!answer[0])
   2266 	exit (EXIT_SUCCESS);
   2267       myaccess = answer[0];
   2268       mywidth = answer[1];
   2269       switch (mywidth)
   2270 	{
   2271 	case 'b':
   2272 	  my_operand_length = 1;
   2273 	  break;
   2274 	case 'd':
   2275 	  my_operand_length = 8;
   2276 	  break;
   2277 	case 'f':
   2278 	  my_operand_length = 4;
   2279 	  break;
   2280 	case 'g':
   2281 	  my_operand_length = 16;
   2282 	  break;
   2283 	case 'h':
   2284 	  my_operand_length = 32;
   2285 	  break;
   2286 	case 'l':
   2287 	  my_operand_length = 4;
   2288 	  break;
   2289 	case 'o':
   2290 	  my_operand_length = 16;
   2291 	  break;
   2292 	case 'q':
   2293 	  my_operand_length = 8;
   2294 	  break;
   2295 	case 'w':
   2296 	  my_operand_length = 2;
   2297 	  break;
   2298 	case '!':
   2299 	case '?':
   2300 	case '-':
   2301 	  my_operand_length = 0;
   2302 	  break;
   2303 
   2304 	default:
   2305 	  my_operand_length = 2;
   2306 	  printf ("I don't understand access width %c\n", mywidth);
   2307 	  break;
   2308 	}
   2309       printf ("VAX assembler instruction operand: ");
   2310       fflush (stdout);
   2311       gets (answer);
   2312       mybug = vip_op (answer, myaccess, mywidth, my_operand_length,
   2313 		      &mymode, &myreg, &mylen, &myleft, &myright, &myndx,
   2314 		      &myerr, &mywrn);
   2315       if (*myerr)
   2316 	{
   2317 	  printf ("error: \"%s\"\n", myerr);
   2318 	  if (*mybug)
   2319 	    printf (" bug: \"%s\"\n", mybug);
   2320 	}
   2321       else
   2322 	{
   2323 	  if (*mywrn)
   2324 	    printf ("warning: \"%s\"\n", mywrn);
   2325 	  mumble ("mode", mymode);
   2326 	  mumble ("register", myreg);
   2327 	  mumble ("index", myndx);
   2328 	  printf ("width:'%c'  ", mylen);
   2329 	  printf ("expression: \"");
   2330 	  while (myleft <= myright)
   2331 	    putchar (*myleft++);
   2332 	  printf ("\"\n");
   2333 	}
   2334     }
   2335 }
   2336 
   2337 void
   2338 mumble (char *text, int value)
   2339 {
   2340   printf ("%s:", text);
   2341   if (value >= 0)
   2342     printf ("%xx", value);
   2343   else
   2344     printf ("ABSENT");
   2345   printf ("  ");
   2346 }
   2347 
   2348 #endif
   2349 
   2350 int md_short_jump_size = 3;
   2351 int md_long_jump_size = 6;
   2352 
   2353 void
   2354 md_create_short_jump (char *ptr,
   2355 		      addressT from_addr,
   2356 		      addressT to_addr ATTRIBUTE_UNUSED,
   2357 		      fragS *frag ATTRIBUTE_UNUSED,
   2358 		      symbolS *to_symbol ATTRIBUTE_UNUSED)
   2359 {
   2360   valueT offset;
   2361 
   2362   /* This former calculation was off by two:
   2363       offset = to_addr - (from_addr + 1);
   2364      We need to account for the one byte instruction and also its
   2365      two byte operand.  */
   2366   offset = to_addr - (from_addr + 1 + 2);
   2367   *ptr++ = VAX_BRW;		/* Branch with word (16 bit) offset.  */
   2368   md_number_to_chars (ptr, offset, 2);
   2369 }
   2370 
   2371 void
   2372 md_create_long_jump (char *ptr,
   2373 		     addressT from_addr,
   2374 		     addressT to_addr,
   2375 		     fragS *frag ATTRIBUTE_UNUSED,
   2376 		     symbolS *to_symbol ATTRIBUTE_UNUSED)
   2377 {
   2378   valueT offset;
   2379 
   2380   /* Account for 1 byte instruction, 1 byte of address specifier and
   2381      4 bytes of offset from PC.  */
   2382   offset = to_addr - (from_addr + 1 + 1 + 4);
   2383   *ptr++ = VAX_JMP;
   2384   *ptr++ = VAX_PC_RELATIVE_MODE;
   2385   md_number_to_chars (ptr, offset, 4);
   2386 }
   2387 
   2388 #ifdef OBJ_VMS
   2390 const char *md_shortopts = "d:STt:V+1h:Hv::";
   2391 #elif defined(OBJ_ELF)
   2392 const char *md_shortopts = "d:STt:VkKQ:";
   2393 #else
   2394 const char *md_shortopts = "d:STt:V";
   2395 #endif
   2396 struct option md_longopts[] =
   2397 {
   2398 #ifdef OBJ_ELF
   2399 #define OPTION_PIC (OPTION_MD_BASE)
   2400   { "pic", no_argument, NULL, OPTION_PIC },
   2401 #endif
   2402   { NULL, no_argument, NULL, 0 }
   2403 };
   2404 size_t md_longopts_size = sizeof (md_longopts);
   2405 
   2406 int
   2407 md_parse_option (int c, const char *arg)
   2408 {
   2409   switch (c)
   2410     {
   2411     case 'S':
   2412       as_warn (_("SYMBOL TABLE not implemented"));
   2413       break;
   2414 
   2415     case 'T':
   2416       as_warn (_("TOKEN TRACE not implemented"));
   2417       break;
   2418 
   2419     case 'd':
   2420       as_warn (_("Displacement length %s ignored!"), arg);
   2421       break;
   2422 
   2423     case 't':
   2424       as_warn (_("I don't need or use temp. file \"%s\"."), arg);
   2425       break;
   2426 
   2427     case 'V':
   2428       as_warn (_("I don't use an interpass file! -V ignored"));
   2429       break;
   2430 
   2431 #ifdef OBJ_VMS
   2432     case '+':			/* For g++.  Hash any name > 31 chars long.  */
   2433       flag_hash_long_names = 1;
   2434       break;
   2435 
   2436     case '1':			/* For backward compatibility.  */
   2437       flag_one = 1;
   2438       break;
   2439 
   2440     case 'H':			/* Show new symbol after hash truncation.  */
   2441       flag_show_after_trunc = 1;
   2442       break;
   2443 
   2444     case 'h':			/* No hashing of mixed-case names.  */
   2445       {
   2446 	extern char vms_name_mapping;
   2447 	vms_name_mapping = atoi (arg);
   2448 	flag_no_hash_mixed_case = 1;
   2449       }
   2450       break;
   2451 
   2452     case 'v':
   2453       {
   2454 	extern char *compiler_version_string;
   2455 
   2456 	if (!arg || !*arg || access (arg, 0) == 0)
   2457 	  return 0;		/* Have caller show the assembler version.  */
   2458 	compiler_version_string = arg;
   2459       }
   2460       break;
   2461 #endif
   2462 
   2463 #ifdef OBJ_ELF
   2464     case OPTION_PIC:
   2465     case 'k':
   2466       flag_want_pic = 1;
   2467       break;			/* -pic, Position Independent Code.  */
   2468 
   2469      /* -Qy, -Qn: SVR4 arguments controlling whether a .comment
   2470 	section should be emitted or not.  FIXME: Not implemented.  */
   2471     case 'Q':
   2472       break;
   2473 #endif
   2474 
   2475     default:
   2476       return 0;
   2477     }
   2478 
   2479   return 1;
   2480 }
   2481 
   2482 void
   2483 md_show_usage (FILE *stream)
   2484 {
   2485   fprintf (stream, _("\
   2486 VAX options:\n\
   2487 -d LENGTH		ignored\n\
   2488 -J			ignored\n\
   2489 -S			ignored\n\
   2490 -t FILE			ignored\n\
   2491 -T			ignored\n\
   2492 -V			ignored\n"));
   2493 #ifdef OBJ_VMS
   2494   fprintf (stream, _("\
   2495 VMS options:\n\
   2496 -+			hash encode names longer than 31 characters\n\
   2497 -1			`const' handling compatible with gcc 1.x\n\
   2498 -H			show new symbol after hash truncation\n\
   2499 -h NUM			don't hash mixed-case names, and adjust case:\n\
   2500 			0 = upper, 2 = lower, 3 = preserve case\n\
   2501 -v\"VERSION\"		code being assembled was produced by compiler \"VERSION\"\n"));
   2502 #endif
   2503 }
   2504 
   2505 /* We have no need to default values of symbols.  */
   2507 
   2508 symbolS *
   2509 md_undefined_symbol (char *name ATTRIBUTE_UNUSED)
   2510 {
   2511   return NULL;
   2512 }
   2513 
   2514 /* Round up a section size to the appropriate boundary.  */
   2515 valueT
   2516 md_section_align (segT segment ATTRIBUTE_UNUSED, valueT size)
   2517 {
   2518   /* Byte alignment is fine */
   2519   return size;
   2520 }
   2521 
   2522 /* Exactly what point is a PC-relative offset relative TO?
   2523    On the vax, they're relative to the address of the offset, plus
   2524    its size. */
   2525 long
   2526 md_pcrel_from (fixS *fixP)
   2527 {
   2528   return fixP->fx_size + fixP->fx_where + fixP->fx_frag->fr_address;
   2529 }
   2530 
   2531 arelent *
   2532 tc_gen_reloc (asection *section ATTRIBUTE_UNUSED, fixS *fixp)
   2533 {
   2534   arelent *reloc;
   2535   bfd_reloc_code_real_type code;
   2536 
   2537   if (fixp->fx_tcbit)
   2538     abort ();
   2539 
   2540   if (fixp->fx_r_type != NO_RELOC)
   2541     {
   2542       code = fixp->fx_r_type;
   2543 
   2544       if (fixp->fx_pcrel)
   2545 	{
   2546 	  switch (code)
   2547 	    {
   2548 	    case BFD_RELOC_8_PCREL:
   2549 	    case BFD_RELOC_16_PCREL:
   2550 	    case BFD_RELOC_32_PCREL:
   2551 #ifdef OBJ_ELF
   2552 	    case BFD_RELOC_8_GOT_PCREL:
   2553 	    case BFD_RELOC_16_GOT_PCREL:
   2554 	    case BFD_RELOC_32_GOT_PCREL:
   2555 	    case BFD_RELOC_8_PLT_PCREL:
   2556 	    case BFD_RELOC_16_PLT_PCREL:
   2557 	    case BFD_RELOC_32_PLT_PCREL:
   2558 #endif
   2559 	      break;
   2560 	    default:
   2561 	      as_bad_where (fixp->fx_file, fixp->fx_line,
   2562 			    _("Cannot make %s relocation PC relative"),
   2563 			    bfd_get_reloc_code_name (code));
   2564 	    }
   2565 	}
   2566     }
   2567   else
   2568     {
   2569 #define F(SZ,PCREL)		(((SZ) << 1) + (PCREL))
   2570       switch (F (fixp->fx_size, fixp->fx_pcrel))
   2571 	{
   2572 #define MAP(SZ,PCREL,TYPE)	case F(SZ,PCREL): code = (TYPE); break
   2573 	  MAP (1, 0, BFD_RELOC_8);
   2574 	  MAP (2, 0, BFD_RELOC_16);
   2575 	  MAP (4, 0, BFD_RELOC_32);
   2576 	  MAP (1, 1, BFD_RELOC_8_PCREL);
   2577 	  MAP (2, 1, BFD_RELOC_16_PCREL);
   2578 	  MAP (4, 1, BFD_RELOC_32_PCREL);
   2579 	default:
   2580 	  abort ();
   2581 	}
   2582     }
   2583 #undef F
   2584 #undef MAP
   2585 
   2586   reloc = XNEW (arelent);
   2587   reloc->sym_ptr_ptr = XNEW (asymbol *);
   2588   *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
   2589   reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
   2590 #ifndef OBJ_ELF
   2591   if (fixp->fx_pcrel)
   2592     reloc->addend = fixp->fx_addnumber;
   2593   else
   2594     reloc->addend = 0;
   2595 #else
   2596   reloc->addend = fixp->fx_offset;
   2597 #endif
   2598 
   2599   reloc->howto = bfd_reloc_type_lookup (stdoutput, code);
   2600   gas_assert (reloc->howto != 0);
   2601 
   2602   return reloc;
   2603 }
   2604 
   2605 /* vax:md_assemble() emit frags for 1 instruction given in textual form.  */
   2606 void
   2607 md_assemble (char *instruction_string)
   2608 {
   2609   /* Non-zero if operand expression's segment is not known yet.  */
   2610   int is_undefined;
   2611   /* Non-zero if operand expression's segment is absolute.  */
   2612   int is_absolute;
   2613   int length_code;
   2614   char *p;
   2615   /* An operand. Scans all operands.  */
   2616   struct vop *operandP;
   2617   char *save_input_line_pointer;
   2618 			/* What used to live after an expression.  */
   2619   char c_save;
   2620   /* 1: instruction_string bad for all passes.  */
   2621   int goofed;
   2622   /* Points to slot just after last operand.  */
   2623   struct vop *end_operandP;
   2624   /* Points to expression values for this operand.  */
   2625   expressionS *expP;
   2626   segT *segP;
   2627 
   2628   /* These refer to an instruction operand expression.  */
   2629   /* Target segment of the address.	 */
   2630   segT to_seg;
   2631   valueT this_add_number;
   2632   /* Positive (minuend) symbol.  */
   2633   symbolS *this_add_symbol;
   2634   /* As a number.  */
   2635   long opcode_as_number;
   2636   /* Least significant byte 1st.  */
   2637   char *opcode_as_chars;
   2638   /* As an array of characters.  */
   2639   /* Least significant byte 1st */
   2640   char *opcode_low_byteP;
   2641   /* length (bytes) meant by vop_short.  */
   2642   int length;
   2643   /* 0, or 1 if '@' is in addressing mode.  */
   2644   int at;
   2645   /* From vop_nbytes: vax_operand_width (in bytes) */
   2646   int nbytes;
   2647   FLONUM_TYPE *floatP;
   2648   LITTLENUM_TYPE literal_float[8];
   2649   /* Big enough for any floating point literal.  */
   2650 
   2651   vip (&v, instruction_string);
   2652 
   2653   /* Now we try to find as many as_warn()s as we can. If we do any as_warn()s
   2654      then goofed=1. Notice that we don't make any frags yet.
   2655      Should goofed be 1, then this instruction will wedge in any pass,
   2656      and we can safely flush it, without causing interpass symbol phase
   2657      errors. That is, without changing label values in different passes.  */
   2658   if ((goofed = (*v.vit_error)) != 0)
   2659     {
   2660       as_fatal (_("Ignoring statement due to \"%s\""), v.vit_error);
   2661     }
   2662   /* We need to use expression() and friends, which require us to diddle
   2663      input_line_pointer. So we save it and restore it later.  */
   2664   save_input_line_pointer = input_line_pointer;
   2665   for (operandP = v.vit_operand,
   2666        expP = exp_of_operand,
   2667        segP = seg_of_operand,
   2668        floatP = float_operand,
   2669        end_operandP = v.vit_operand + v.vit_operands;
   2670 
   2671        operandP < end_operandP;
   2672 
   2673        operandP++, expP++, segP++, floatP++)
   2674     {
   2675       if (operandP->vop_error)
   2676 	{
   2677 	  as_fatal (_("Aborting because statement has \"%s\""), operandP->vop_error);
   2678 	  goofed = 1;
   2679 	}
   2680       else
   2681 	{
   2682 	  /* Statement has no syntax goofs: let's sniff the expression.  */
   2683 	  int can_be_short = 0;	/* 1 if a bignum can be reduced to a short literal.  */
   2684 
   2685 	  input_line_pointer = operandP->vop_expr_begin;
   2686 	  c_save = operandP->vop_expr_end[1];
   2687 	  operandP->vop_expr_end[1] = '\0';
   2688 	  /* If to_seg == SEG_PASS1, expression() will have set need_pass_2 = 1.  */
   2689 	  *segP = expression (expP);
   2690 	  switch (expP->X_op)
   2691 	    {
   2692 	    case O_absent:
   2693 	      /* for BSD4.2 compatibility, missing expression is absolute 0 */
   2694 	      expP->X_op = O_constant;
   2695 	      expP->X_add_number = 0;
   2696 	      /* For SEG_ABSOLUTE, we shouldn't need to set X_op_symbol,
   2697 		 X_add_symbol to any particular value.  But, we will program
   2698 		 defensively. Since this situation occurs rarely so it costs
   2699 		 us little to do, and stops Dean worrying about the origin of
   2700 		 random bits in expressionS's.  */
   2701 	      expP->X_add_symbol = NULL;
   2702 	      expP->X_op_symbol = NULL;
   2703 	      break;
   2704 
   2705 	    case O_symbol:
   2706 	    case O_constant:
   2707 	      break;
   2708 
   2709 	    default:
   2710 	      /* Major bug. We can't handle the case of a
   2711 	         SEG_OP expression in a VIT_OPCODE_SYNTHETIC
   2712 	         variable-length instruction.
   2713 	         We don't have a frag type that is smart enough to
   2714 	         relax a SEG_OP, and so we just force all
   2715 	         SEG_OPs to behave like SEG_PASS1s.
   2716 	         Clearly, if there is a demand we can invent a new or
   2717 	         modified frag type and then coding up a frag for this
   2718 	         case will be easy. SEG_OP was invented for the
   2719 	         .words after a CASE opcode, and was never intended for
   2720 	         instruction operands.  */
   2721 	      need_pass_2 = 1;
   2722 	      as_fatal (_("Can't relocate expression"));
   2723 	      break;
   2724 
   2725 	    case O_big:
   2726 	      /* Preserve the bits.  */
   2727 	      if (expP->X_add_number > 0)
   2728 		{
   2729 		  bignum_copy (generic_bignum, expP->X_add_number,
   2730 			       floatP->low, SIZE_OF_LARGE_NUMBER);
   2731 		}
   2732 	      else
   2733 		{
   2734 		  know (expP->X_add_number < 0);
   2735 		  flonum_copy (&generic_floating_point_number,
   2736 			       floatP);
   2737 		  if (strchr ("s i", operandP->vop_short))
   2738 		    {
   2739 		      /* Could possibly become S^# */
   2740 		      flonum_gen2vax (-expP->X_add_number, floatP, literal_float);
   2741 		      switch (-expP->X_add_number)
   2742 			{
   2743 			case 'f':
   2744 			  can_be_short =
   2745 			    (literal_float[0] & 0xFC0F) == 0x4000
   2746 			    && literal_float[1] == 0;
   2747 			  break;
   2748 
   2749 			case 'd':
   2750 			  can_be_short =
   2751 			    (literal_float[0] & 0xFC0F) == 0x4000
   2752 			    && literal_float[1] == 0
   2753 			    && literal_float[2] == 0
   2754 			    && literal_float[3] == 0;
   2755 			  break;
   2756 
   2757 			case 'g':
   2758 			  can_be_short =
   2759 			    (literal_float[0] & 0xFF81) == 0x4000
   2760 			    && literal_float[1] == 0
   2761 			    && literal_float[2] == 0
   2762 			    && literal_float[3] == 0;
   2763 			  break;
   2764 
   2765 			case 'h':
   2766 			  can_be_short = ((literal_float[0] & 0xFFF8) == 0x4000
   2767 					  && (literal_float[1] & 0xE000) == 0
   2768 					  && literal_float[2] == 0
   2769 					  && literal_float[3] == 0
   2770 					  && literal_float[4] == 0
   2771 					  && literal_float[5] == 0
   2772 					  && literal_float[6] == 0
   2773 					  && literal_float[7] == 0);
   2774 			  break;
   2775 
   2776 			default:
   2777 			  BAD_CASE (-expP->X_add_number);
   2778 			  break;
   2779 			}
   2780 		    }
   2781 		}
   2782 
   2783 	      if (operandP->vop_short == 's'
   2784 		  || operandP->vop_short == 'i'
   2785 		  || (operandP->vop_short == ' '
   2786 		      && operandP->vop_reg == 0xF
   2787 		      && (operandP->vop_mode & 0xE) == 0x8))
   2788 		{
   2789 		  /* Saw a '#'.  */
   2790 		  if (operandP->vop_short == ' ')
   2791 		    {
   2792 		      /* We must chose S^ or I^.  */
   2793 		      if (expP->X_add_number > 0)
   2794 			{
   2795 			  /* Bignum: Short literal impossible.  */
   2796 			  operandP->vop_short = 'i';
   2797 			  operandP->vop_mode = 8;
   2798 			  operandP->vop_reg = 0xF;	/* VAX PC.  */
   2799 			}
   2800 		      else
   2801 			{
   2802 			  /* Flonum: Try to do it.  */
   2803 			  if (can_be_short)
   2804 			    {
   2805 			      operandP->vop_short = 's';
   2806 			      operandP->vop_mode = 0;
   2807 			      operandP->vop_ndx = -1;
   2808 			      operandP->vop_reg = -1;
   2809 			      expP->X_op = O_constant;
   2810 			    }
   2811 			  else
   2812 			    {
   2813 			      operandP->vop_short = 'i';
   2814 			      operandP->vop_mode = 8;
   2815 			      operandP->vop_reg = 0xF;	/* VAX PC */
   2816 			    }
   2817 			}	/* bignum or flonum ? */
   2818 		    }		/*  if #, but no S^ or I^ seen.  */
   2819 		  /* No more ' ' case: either 's' or 'i'.  */
   2820 		  if (operandP->vop_short == 's')
   2821 		    {
   2822 		      /* Wants to be a short literal.  */
   2823 		      if (expP->X_add_number > 0)
   2824 			{
   2825 			  as_warn (_("Bignum not permitted in short literal. Immediate mode assumed."));
   2826 			  operandP->vop_short = 'i';
   2827 			  operandP->vop_mode = 8;
   2828 			  operandP->vop_reg = 0xF;	/* VAX PC.  */
   2829 			}
   2830 		      else
   2831 			{
   2832 			  if (!can_be_short)
   2833 			    {
   2834 			      as_warn (_("Can't do flonum short literal: immediate mode used."));
   2835 			      operandP->vop_short = 'i';
   2836 			      operandP->vop_mode = 8;
   2837 			      operandP->vop_reg = 0xF;	/* VAX PC.  */
   2838 			    }
   2839 			  else
   2840 			    {
   2841 			      /* Encode short literal now.  */
   2842 			      int temp = 0;
   2843 
   2844 			      switch (-expP->X_add_number)
   2845 				{
   2846 				case 'f':
   2847 				case 'd':
   2848 				  temp = literal_float[0] >> 4;
   2849 				  break;
   2850 
   2851 				case 'g':
   2852 				  temp = literal_float[0] >> 1;
   2853 				  break;
   2854 
   2855 				case 'h':
   2856 				  temp = ((literal_float[0] << 3) & 070)
   2857 				    | ((literal_float[1] >> 13) & 07);
   2858 				  break;
   2859 
   2860 				default:
   2861 				  BAD_CASE (-expP->X_add_number);
   2862 				  break;
   2863 				}
   2864 
   2865 			      floatP->low[0] = temp & 077;
   2866 			      floatP->low[1] = 0;
   2867 			    }
   2868 			}
   2869 		    }
   2870 		  else
   2871 		    {
   2872 		      /* I^# seen: set it up if float.  */
   2873 		      if (expP->X_add_number < 0)
   2874 			{
   2875 			  memcpy (floatP->low, literal_float, sizeof (literal_float));
   2876 			}
   2877 		    }		/* if S^# seen.  */
   2878 		}
   2879 	      else
   2880 		{
   2881 		  as_warn (_("A bignum/flonum may not be a displacement: 0x%lx used"),
   2882 			   (expP->X_add_number = 0x80000000L));
   2883 		  /* Chosen so luser gets the most offset bits to patch later.  */
   2884 		}
   2885 	      expP->X_add_number = floatP->low[0]
   2886 		| ((LITTLENUM_MASK & (floatP->low[1])) << LITTLENUM_NUMBER_OF_BITS);
   2887 
   2888 	      /* For the O_big case we have:
   2889 	         If vop_short == 's' then a short floating literal is in the
   2890 	        	lowest 6 bits of floatP -> low [0], which is
   2891 	        	big_operand_bits [---] [0].
   2892 	         If vop_short == 'i' then the appropriate number of elements
   2893 	        	of big_operand_bits [---] [...] are set up with the correct
   2894 	        	bits.
   2895 	         Also, just in case width is byte word or long, we copy the lowest
   2896 	         32 bits of the number to X_add_number.  */
   2897 	      break;
   2898 	    }
   2899 	  if (input_line_pointer != operandP->vop_expr_end + 1)
   2900 	    {
   2901 	      as_fatal ("Junk at end of expression \"%s\"", input_line_pointer);
   2902 	      goofed = 1;
   2903 	    }
   2904 	  operandP->vop_expr_end[1] = c_save;
   2905 	}
   2906     }
   2907 
   2908   input_line_pointer = save_input_line_pointer;
   2909 
   2910   if (need_pass_2 || goofed)
   2911     return;
   2912 
   2913   dwarf2_emit_insn (0);
   2914   /* Emit op-code.  */
   2915   /* Remember where it is, in case we want to modify the op-code later.  */
   2916   opcode_low_byteP = frag_more (v.vit_opcode_nbytes);
   2917   memcpy (opcode_low_byteP, v.vit_opcode, v.vit_opcode_nbytes);
   2918   opcode_as_chars = v.vit_opcode;
   2919   opcode_as_number = md_chars_to_number ((unsigned char *) opcode_as_chars, 4);
   2920   for (operandP = v.vit_operand,
   2921        expP = exp_of_operand,
   2922        segP = seg_of_operand,
   2923        floatP = float_operand,
   2924        end_operandP = v.vit_operand + v.vit_operands;
   2925 
   2926        operandP < end_operandP;
   2927 
   2928        operandP++,
   2929        floatP++,
   2930        segP++,
   2931        expP++)
   2932     {
   2933       if (operandP->vop_ndx >= 0)
   2934 	{
   2935 	  /* Indexed addressing byte.  */
   2936 	  /* Legality of indexed mode already checked: it is OK.  */
   2937 	  FRAG_APPEND_1_CHAR (0x40 + operandP->vop_ndx);
   2938 	}			/* if(vop_ndx>=0) */
   2939 
   2940       /* Here to make main operand frag(s).  */
   2941       this_add_number = expP->X_add_number;
   2942       this_add_symbol = expP->X_add_symbol;
   2943       to_seg = *segP;
   2944       is_undefined = (to_seg == undefined_section);
   2945       is_absolute = (to_seg == absolute_section);
   2946       at = operandP->vop_mode & 1;
   2947       length = (operandP->vop_short == 'b'
   2948 		? 1 : (operandP->vop_short == 'w'
   2949 		       ? 2 : (operandP->vop_short == 'l'
   2950 			      ? 4 : 0)));
   2951       nbytes = operandP->vop_nbytes;
   2952       if (operandP->vop_access == 'b')
   2953 	{
   2954 	  if (to_seg == now_seg || is_undefined)
   2955 	    {
   2956 	      /* If is_undefined, then it might BECOME now_seg.  */
   2957 	      if (nbytes)
   2958 		{
   2959 		  p = frag_more (nbytes);
   2960 		  fix_new (frag_now, p - frag_now->fr_literal, nbytes,
   2961 			   this_add_symbol, this_add_number, 1, NO_RELOC);
   2962 		}
   2963 	      else
   2964 		{
   2965 		  /* to_seg==now_seg || to_seg == SEG_UNKNOWN */
   2966 		  /* nbytes==0 */
   2967 		  length_code = is_undefined ? STATE_UNDF : STATE_BYTE;
   2968 		  if (opcode_as_number & VIT_OPCODE_SPECIAL)
   2969 		    {
   2970 		      if (operandP->vop_width == VAX_WIDTH_UNCONDITIONAL_JUMP)
   2971 			{
   2972 			  /* br or jsb */
   2973 			  frag_var (rs_machine_dependent, 5, 1,
   2974 			    ENCODE_RELAX (STATE_ALWAYS_BRANCH, length_code),
   2975 				    this_add_symbol, this_add_number,
   2976 				    opcode_low_byteP);
   2977 			}
   2978 		      else
   2979 			{
   2980 			  if (operandP->vop_width == VAX_WIDTH_WORD_JUMP)
   2981 			    {
   2982 			      length_code = STATE_WORD;
   2983 			      /* JF: There is no state_byte for this one! */
   2984 			      frag_var (rs_machine_dependent, 10, 2,
   2985 					ENCODE_RELAX (STATE_COMPLEX_BRANCH, length_code),
   2986 					this_add_symbol, this_add_number,
   2987 					opcode_low_byteP);
   2988 			    }
   2989 			  else
   2990 			    {
   2991 			      know (operandP->vop_width == VAX_WIDTH_BYTE_JUMP);
   2992 			      frag_var (rs_machine_dependent, 9, 1,
   2993 			      ENCODE_RELAX (STATE_COMPLEX_HOP, length_code),
   2994 					this_add_symbol, this_add_number,
   2995 					opcode_low_byteP);
   2996 			    }
   2997 			}
   2998 		    }
   2999 		  else
   3000 		    {
   3001 		      know (operandP->vop_width == VAX_WIDTH_CONDITIONAL_JUMP);
   3002 		      frag_var (rs_machine_dependent, 7, 1,
   3003 		       ENCODE_RELAX (STATE_CONDITIONAL_BRANCH, length_code),
   3004 				this_add_symbol, this_add_number,
   3005 				opcode_low_byteP);
   3006 		    }
   3007 		}
   3008 	    }
   3009 	  else
   3010 	    {
   3011 	      /* to_seg != now_seg && to_seg != SEG_UNKNOWN */
   3012 	      /* --- SEG FLOAT MAY APPEAR HERE ---  */
   3013 	      if (is_absolute)
   3014 		{
   3015 		  if (nbytes)
   3016 		    {
   3017 		      know (!(opcode_as_number & VIT_OPCODE_SYNTHETIC));
   3018 		      p = frag_more (nbytes);
   3019 		      /* Conventional relocation.  */
   3020 		      fix_new (frag_now, p - frag_now->fr_literal, nbytes,
   3021 			       section_symbol (absolute_section),
   3022 			       this_add_number, 1, NO_RELOC);
   3023 		    }
   3024 		  else
   3025 		    {
   3026 		      know (opcode_as_number & VIT_OPCODE_SYNTHETIC);
   3027 		      if (opcode_as_number & VIT_OPCODE_SPECIAL)
   3028 			{
   3029 			  if (operandP->vop_width == VAX_WIDTH_UNCONDITIONAL_JUMP)
   3030 			    {
   3031 			      /* br or jsb */
   3032 			      *opcode_low_byteP = opcode_as_chars[0] + VAX_WIDEN_LONG;
   3033 			      know (opcode_as_chars[1] == 0);
   3034 			      p = frag_more (5);
   3035 			      p[0] = VAX_ABSOLUTE_MODE;	/* @#...  */
   3036 			      md_number_to_chars (p + 1, this_add_number, 4);
   3037 			      /* Now (eg) JMP @#foo or JSB @#foo.  */
   3038 			    }
   3039 			  else
   3040 			    {
   3041 			      if (operandP->vop_width == VAX_WIDTH_WORD_JUMP)
   3042 				{
   3043 				  p = frag_more (10);
   3044 				  p[0] = 2;
   3045 				  p[1] = 0;
   3046 				  p[2] = VAX_BRB;
   3047 				  p[3] = 6;
   3048 				  p[4] = VAX_JMP;
   3049 				  p[5] = VAX_ABSOLUTE_MODE;	/* @#...  */
   3050 				  md_number_to_chars (p + 6, this_add_number, 4);
   3051 				  /* Now (eg)	ACBx	1f
   3052 				    		BRB	2f
   3053 				    	1:	JMP	@#foo
   3054 				    	2:  */
   3055 				}
   3056 			      else
   3057 				{
   3058 				  know (operandP->vop_width == VAX_WIDTH_BYTE_JUMP);
   3059 				  p = frag_more (9);
   3060 				  p[0] = 2;
   3061 				  p[1] = VAX_BRB;
   3062 				  p[2] = 6;
   3063 				  p[3] = VAX_JMP;
   3064                                   p[4] = VAX_ABSOLUTE_MODE;     /* @#...  */
   3065 				  md_number_to_chars (p + 5, this_add_number, 4);
   3066 				  /* Now (eg)	xOBxxx	1f
   3067 				   		BRB	2f
   3068 				   	1:	JMP	@#foo
   3069 				   	2:  */
   3070 				}
   3071 			    }
   3072 			}
   3073 		      else
   3074 			{
   3075 			  /* b<cond> */
   3076 			  *opcode_low_byteP ^= 1;
   3077 			  /* To reverse the condition in a VAX branch,
   3078 			     complement the lowest order bit.  */
   3079 			  p = frag_more (7);
   3080 			  p[0] = 6;
   3081 			  p[1] = VAX_JMP;
   3082 			  p[2] = VAX_ABSOLUTE_MODE;	/* @#...  */
   3083 			  md_number_to_chars (p + 3, this_add_number, 4);
   3084 			  /* Now (eg)	BLEQ	1f
   3085 			   		JMP	@#foo
   3086 			   	1:  */
   3087 			}
   3088 		    }
   3089 		}
   3090 	      else
   3091 		{
   3092 		  /* to_seg != now_seg && !is_undefinfed && !is_absolute */
   3093 		  if (nbytes > 0)
   3094 		    {
   3095 		      /* Pc-relative. Conventional relocation.  */
   3096 		      know (!(opcode_as_number & VIT_OPCODE_SYNTHETIC));
   3097 		      p = frag_more (nbytes);
   3098 		      fix_new (frag_now, p - frag_now->fr_literal, nbytes,
   3099 			       section_symbol (absolute_section),
   3100 			       this_add_number, 1, NO_RELOC);
   3101 		    }
   3102 		  else
   3103 		    {
   3104 		      know (opcode_as_number & VIT_OPCODE_SYNTHETIC);
   3105 		      if (opcode_as_number & VIT_OPCODE_SPECIAL)
   3106 			{
   3107 			  if (operandP->vop_width == VAX_WIDTH_UNCONDITIONAL_JUMP)
   3108 			    {
   3109 			      /* br or jsb */
   3110 			      know (opcode_as_chars[1] == 0);
   3111 			      *opcode_low_byteP = opcode_as_chars[0] + VAX_WIDEN_LONG;
   3112 			      p = frag_more (5);
   3113 			      p[0] = VAX_PC_RELATIVE_MODE;
   3114 			      fix_new (frag_now,
   3115 				       p + 1 - frag_now->fr_literal, 4,
   3116 				       this_add_symbol,
   3117 				       this_add_number, 1, NO_RELOC);
   3118 			      /* Now eg JMP foo or JSB foo.  */
   3119 			    }
   3120 			  else
   3121 			    {
   3122 			      if (operandP->vop_width == VAX_WIDTH_WORD_JUMP)
   3123 				{
   3124 				  p = frag_more (10);
   3125 				  p[0] = 0;
   3126 				  p[1] = 2;
   3127 				  p[2] = VAX_BRB;
   3128 				  p[3] = 6;
   3129 				  p[4] = VAX_JMP;
   3130 				  p[5] = VAX_PC_RELATIVE_MODE;
   3131 				  fix_new (frag_now,
   3132 					   p + 6 - frag_now->fr_literal, 4,
   3133 					   this_add_symbol,
   3134 					   this_add_number, 1, NO_RELOC);
   3135 				  /* Now (eg)	ACBx	1f
   3136 				   		BRB	2f
   3137 				   	1:	JMP	foo
   3138 				   	2:  */
   3139 				}
   3140 			      else
   3141 				{
   3142 				  know (operandP->vop_width == VAX_WIDTH_BYTE_JUMP);
   3143 				  p = frag_more (10);
   3144 				  p[0] = 2;
   3145 				  p[1] = VAX_BRB;
   3146 				  p[2] = 6;
   3147 				  p[3] = VAX_JMP;
   3148 				  p[4] = VAX_PC_RELATIVE_MODE;
   3149 				  fix_new (frag_now,
   3150 					   p + 5 - frag_now->fr_literal,
   3151 					   4, this_add_symbol,
   3152 					   this_add_number, 1, NO_RELOC);
   3153 				  /* Now (eg)	xOBxxx	1f
   3154 				   		BRB	2f
   3155 				   	1:	JMP	foo
   3156 				   	2:  */
   3157 				}
   3158 			    }
   3159 			}
   3160 		      else
   3161 			{
   3162 			  know (operandP->vop_width == VAX_WIDTH_CONDITIONAL_JUMP);
   3163 			  *opcode_low_byteP ^= 1;	/* Reverse branch condition.  */
   3164 			  p = frag_more (7);
   3165 			  p[0] = 6;
   3166 			  p[1] = VAX_JMP;
   3167 			  p[2] = VAX_PC_RELATIVE_MODE;
   3168 			  fix_new (frag_now, p + 3 - frag_now->fr_literal,
   3169 				   4, this_add_symbol,
   3170 				   this_add_number, 1, NO_RELOC);
   3171 			}
   3172 		    }
   3173 		}
   3174 	    }
   3175 	}
   3176       else
   3177 	{
   3178 	  /* So it is ordinary operand.  */
   3179 	  know (operandP->vop_access != 'b');
   3180 	  /* ' ' target-independent: elsewhere.  */
   3181 	  know (operandP->vop_access != ' ');
   3182 	  know (operandP->vop_access == 'a'
   3183 		|| operandP->vop_access == 'm'
   3184 		|| operandP->vop_access == 'r'
   3185 		|| operandP->vop_access == 'v'
   3186 		|| operandP->vop_access == 'w');
   3187 	  if (operandP->vop_short == 's')
   3188 	    {
   3189 	      if (is_absolute)
   3190 		{
   3191 		  if (this_add_number >= 64)
   3192 		    {
   3193 		      as_warn (_("Short literal overflow(%ld.), immediate mode assumed."),
   3194 			       (long) this_add_number);
   3195 		      operandP->vop_short = 'i';
   3196 		      operandP->vop_mode = 8;
   3197 		      operandP->vop_reg = 0xF;
   3198 		    }
   3199 		}
   3200 	      else
   3201 		{
   3202 		  as_warn (_("Forced short literal to immediate mode. now_seg=%s to_seg=%s"),
   3203 			   segment_name (now_seg), segment_name (to_seg));
   3204 		  operandP->vop_short = 'i';
   3205 		  operandP->vop_mode = 8;
   3206 		  operandP->vop_reg = 0xF;
   3207 		}
   3208 	    }
   3209 	  if (operandP->vop_reg >= 0 && (operandP->vop_mode < 8
   3210 		  || (operandP->vop_reg != 0xF && operandP->vop_mode < 10)))
   3211 	    {
   3212 	      /* One byte operand.  */
   3213 	      know (operandP->vop_mode > 3);
   3214 	      FRAG_APPEND_1_CHAR (operandP->vop_mode << 4 | operandP->vop_reg);
   3215 	      /* All 1-bytes except S^# happen here.  */
   3216 	    }
   3217 	  else
   3218 	    {
   3219 	      /* {@}{q^}foo{(Rn)} or S^#foo */
   3220 	      if (operandP->vop_reg == -1 && operandP->vop_short != 's')
   3221 		{
   3222 		  /* "{@}{q^}foo" */
   3223 		  if (to_seg == now_seg)
   3224 		    {
   3225 		      if (length == 0)
   3226 			{
   3227 			  know (operandP->vop_short == ' ');
   3228 			  length_code = STATE_BYTE;
   3229 #ifdef OBJ_ELF
   3230 			  if (S_IS_EXTERNAL (this_add_symbol)
   3231 			      || S_IS_WEAK (this_add_symbol))
   3232 			    length_code = STATE_UNDF;
   3233 #endif
   3234 			  p = frag_var (rs_machine_dependent, 10, 2,
   3235 			       ENCODE_RELAX (STATE_PC_RELATIVE, length_code),
   3236 					this_add_symbol, this_add_number,
   3237 					opcode_low_byteP);
   3238 			  know (operandP->vop_mode == 10 + at);
   3239 			  *p = at << 4;
   3240 			  /* At is the only context we need to carry
   3241 			     to other side of relax() process.  Must
   3242 			     be in the correct bit position of VAX
   3243 			     operand spec. byte.  */
   3244 			}
   3245 		      else
   3246 			{
   3247 			  know (length);
   3248 			  know (operandP->vop_short != ' ');
   3249 			  p = frag_more (length + 1);
   3250 			  p[0] = 0xF | ((at + "?\12\14?\16"[length]) << 4);
   3251 			  fix_new (frag_now, p + 1 - frag_now->fr_literal,
   3252 				   length, this_add_symbol,
   3253 				   this_add_number, 1, NO_RELOC);
   3254 			}
   3255 		    }
   3256 		  else
   3257 		    {
   3258 		      /* to_seg != now_seg */
   3259 		      if (this_add_symbol == NULL)
   3260 			{
   3261 			  know (is_absolute);
   3262 			  /* Do @#foo: simpler relocation than foo-.(pc) anyway.  */
   3263 			  p = frag_more (5);
   3264 			  p[0] = VAX_ABSOLUTE_MODE;	/* @#...  */
   3265 			  md_number_to_chars (p + 1, this_add_number, 4);
   3266 			  if (length && length != 4)
   3267 			    as_warn (_("Length specification ignored. Address mode 9F used"));
   3268 			}
   3269 		      else
   3270 			{
   3271 			  /* {@}{q^}other_seg */
   3272 			  know ((length == 0 && operandP->vop_short == ' ')
   3273 			     || (length > 0 && operandP->vop_short != ' '));
   3274 			  if (is_undefined
   3275 #ifdef OBJ_ELF
   3276 			      || S_IS_WEAK(this_add_symbol)
   3277 			      || S_IS_EXTERNAL(this_add_symbol)
   3278 #endif
   3279 			      )
   3280 			    {
   3281 			      switch (length)
   3282 				{
   3283 				default: length_code = STATE_UNDF; break;
   3284 				case 1: length_code = STATE_BYTE; break;
   3285 				case 2: length_code = STATE_WORD; break;
   3286 				case 4: length_code = STATE_LONG; break;
   3287 				}
   3288 			      /* We have a SEG_UNKNOWN symbol. It might
   3289 			         turn out to be in the same segment as
   3290 			         the instruction, permitting relaxation.  */
   3291 			      p = frag_var (rs_machine_dependent, 5, 2,
   3292 			       ENCODE_RELAX (STATE_PC_RELATIVE, length_code),
   3293 					    this_add_symbol, this_add_number,
   3294 					    opcode_low_byteP);
   3295 			      p[0] = at << 4;
   3296 			    }
   3297 			  else
   3298 			    {
   3299 			      if (length == 0)
   3300 				{
   3301 				  know (operandP->vop_short == ' ');
   3302 				  length = 4;	/* Longest possible.  */
   3303 				}
   3304 			      p = frag_more (length + 1);
   3305 			      p[0] = 0xF | ((at + "?\12\14?\16"[length]) << 4);
   3306 			      md_number_to_chars (p + 1, this_add_number, length);
   3307 			      fix_new (frag_now,
   3308 				       p + 1 - frag_now->fr_literal,
   3309 				       length, this_add_symbol,
   3310 				       this_add_number, 1, NO_RELOC);
   3311 			    }
   3312 			}
   3313 		    }
   3314 		}
   3315 	      else
   3316 		{
   3317 		  /* {@}{q^}foo(Rn) or S^# or I^# or # */
   3318 		  if (operandP->vop_mode < 0xA)
   3319 		    {
   3320 		      /* # or S^# or I^# */
   3321 		      if (operandP->vop_access == 'v'
   3322 			  || operandP->vop_access == 'a')
   3323 			{
   3324 			  if (operandP->vop_access == 'v')
   3325 			    as_warn (_("Invalid operand: immediate value used as base address."));
   3326 			  else
   3327 			    as_warn (_("Invalid operand: immediate value used as address."));
   3328 			  /* gcc 2.6.3 is known to generate these in at least
   3329 			     one case.  */
   3330 			}
   3331 		      if (length == 0
   3332 			  && is_absolute && (expP->X_op != O_big)
   3333 			  && operandP->vop_mode == 8	/* No '@'.  */
   3334 			  && this_add_number < 64)
   3335 			{
   3336 			  operandP->vop_short = 's';
   3337 			}
   3338 		      if (operandP->vop_short == 's')
   3339 			{
   3340 			  FRAG_APPEND_1_CHAR (this_add_number);
   3341 			}
   3342 		      else
   3343 			{
   3344 			  /* I^#...  */
   3345 			  know (nbytes);
   3346 			  p = frag_more (nbytes + 1);
   3347 			  know (operandP->vop_reg == 0xF);
   3348 #ifdef OBJ_ELF
   3349 			  if (flag_want_pic && operandP->vop_mode == 8
   3350 				&& this_add_symbol != NULL)
   3351 			    {
   3352 			      as_warn (_("Symbol '%s' used as immediate operand in PIC mode."),
   3353 				       S_GET_NAME (this_add_symbol));
   3354 			    }
   3355 #endif
   3356 			  p[0] = (operandP->vop_mode << 4) | 0xF;
   3357 			  if ((is_absolute) && (expP->X_op != O_big))
   3358 			    {
   3359 			      /* If nbytes > 4, then we are scrod. We
   3360 			         don't know if the high order bytes
   3361 			         are to be 0xFF or 0x00.  BSD4.2 & RMS
   3362 			         say use 0x00. OK --- but this
   3363 			         assembler needs ANOTHER rewrite to
   3364 			         cope properly with this bug.  */
   3365 			      md_number_to_chars (p + 1, this_add_number,
   3366 						  min (sizeof (valueT),
   3367 						       (size_t) nbytes));
   3368 			      if ((size_t) nbytes > sizeof (valueT))
   3369 				memset (p + 1 + sizeof (valueT),
   3370 				        '\0', nbytes - sizeof (valueT));
   3371 			    }
   3372 			  else
   3373 			    {
   3374 			      if (expP->X_op == O_big)
   3375 				{
   3376 				  /* Problem here is to get the bytes
   3377 				     in the right order.  We stored
   3378 				     our constant as LITTLENUMs, not
   3379 				     bytes.  */
   3380 				  LITTLENUM_TYPE *lP;
   3381 
   3382 				  lP = floatP->low;
   3383 				  if (nbytes & 1)
   3384 				    {
   3385 				      know (nbytes == 1);
   3386 				      p[1] = *lP;
   3387 				    }
   3388 				  else
   3389 				    {
   3390 				      for (p++; nbytes; nbytes -= 2, p += 2, lP++)
   3391 					md_number_to_chars (p, *lP, 2);
   3392 				    }
   3393 				}
   3394 			      else
   3395 				{
   3396 				  fix_new (frag_now, p + 1 - frag_now->fr_literal,
   3397 					   nbytes, this_add_symbol,
   3398 					   this_add_number, 0, NO_RELOC);
   3399 				}
   3400 			    }
   3401 			}
   3402 		    }
   3403 		  else
   3404 		    {
   3405 		      /* {@}{q^}foo(Rn) */
   3406 		      know ((length == 0 && operandP->vop_short == ' ')
   3407 			    || (length > 0 && operandP->vop_short != ' '));
   3408 		      if (length == 0)
   3409 			{
   3410 			  if (is_absolute)
   3411 			    {
   3412 			      long test;
   3413 
   3414 			      test = this_add_number;
   3415 
   3416 			      if (test < 0)
   3417 				test = ~test;
   3418 
   3419 			      length = test & 0xffff8000 ? 4
   3420 				: test & 0xffffff80 ? 2
   3421 				: 1;
   3422 			    }
   3423 			  else
   3424 			    {
   3425 			      length = 4;
   3426 			    }
   3427 			}
   3428 #ifdef OBJ_ELF
   3429 		      if (flag_want_pic && this_add_symbol != NULL)
   3430 		        {
   3431 			  as_warn (_("Symbol '%s' used as displacement in PIC mode."),
   3432 			       S_GET_NAME (this_add_symbol));
   3433 		        }
   3434 #endif
   3435 		      p = frag_more (1 + length);
   3436 		      know (operandP->vop_reg != 0xf);
   3437 		      know (operandP->vop_reg >= 0);
   3438 		      p[0] = operandP->vop_reg
   3439 			| ((at | "?\12\14?\16"[length]) << 4);
   3440 		      if (is_absolute)
   3441 			{
   3442 			  md_number_to_chars (p + 1, this_add_number, length);
   3443 			}
   3444 		      else
   3445 			{
   3446 			  fix_new (frag_now, p + 1 - frag_now->fr_literal,
   3447 				   length, this_add_symbol,
   3448 				   this_add_number, 0, NO_RELOC);
   3449 			}
   3450 		    }
   3451 		}
   3452 	    }
   3453 	}
   3454     }
   3455 }
   3456 
   3457 void
   3458 md_begin (void)
   3459 {
   3460   const char *errtxt;
   3461   FLONUM_TYPE *fP;
   3462   int i;
   3463 
   3464   if ((errtxt = vip_begin (1, "$", "*", "`")) != 0)
   3465     as_fatal (_("VIP_BEGIN error:%s"), errtxt);
   3466 
   3467   for (i = 0, fP = float_operand;
   3468        fP < float_operand + VIT_MAX_OPERANDS;
   3469        i++, fP++)
   3470     {
   3471       fP->low = &big_operand_bits[i][0];
   3472       fP->high = &big_operand_bits[i][SIZE_OF_LARGE_NUMBER - 1];
   3473     }
   3474 }
   3475 
   3476 bfd_reloc_code_real_type
   3477 vax_cons (expressionS *exp, int size)
   3478 {
   3479   char *save;
   3480   const char *vax_cons_special_reloc;
   3481 
   3482   SKIP_WHITESPACE ();
   3483   vax_cons_special_reloc = NULL;
   3484   save = input_line_pointer;
   3485   if (input_line_pointer[0] == '%')
   3486     {
   3487       if (strncmp (input_line_pointer + 1, "pcrel", 5) == 0)
   3488 	{
   3489 	  input_line_pointer += 6;
   3490 	  vax_cons_special_reloc = "pcrel";
   3491 	}
   3492       if (vax_cons_special_reloc)
   3493 	{
   3494 	  int bad = 0;
   3495 
   3496 	  switch (size)
   3497 	    {
   3498 	    case 1:
   3499 	      if (*input_line_pointer != '8')
   3500 		bad = 1;
   3501 	      input_line_pointer--;
   3502 	      break;
   3503 	    case 2:
   3504 	      if (input_line_pointer[0] != '1' || input_line_pointer[1] != '6')
   3505 		bad = 1;
   3506 	      break;
   3507 	    case 4:
   3508 	      if (input_line_pointer[0] != '3' || input_line_pointer[1] != '2')
   3509 		bad = 1;
   3510 	      break;
   3511 	    default:
   3512 	      bad = 1;
   3513 	      break;
   3514 	    }
   3515 
   3516 	  if (bad)
   3517 	    {
   3518 	      as_bad (_("Illegal operands: Only %%r_%s%d allowed in %d-byte data fields"),
   3519 		      vax_cons_special_reloc, size * 8, size);
   3520 	    }
   3521 	  else
   3522 	    {
   3523 	      input_line_pointer += 2;
   3524 	      if (*input_line_pointer != '(')
   3525 		{
   3526 		  as_bad (_("Illegal operands: %%r_%s%d requires arguments in ()"),
   3527 			  vax_cons_special_reloc, size * 8);
   3528 		  bad = 1;
   3529 		}
   3530 	    }
   3531 
   3532 	  if (bad)
   3533 	    {
   3534 	      input_line_pointer = save;
   3535 	      vax_cons_special_reloc = NULL;
   3536 	    }
   3537 	  else
   3538 	    {
   3539 	      int c;
   3540 	      char *end = ++input_line_pointer;
   3541 	      int npar = 0;
   3542 
   3543 	      while (! is_end_of_line[(c = *end)])
   3544 		{
   3545 		  if (c == '(')
   3546 	  	    npar++;
   3547 		  else if (c == ')')
   3548 	  	    {
   3549 		      if (!npar)
   3550 	      		break;
   3551 		      npar--;
   3552 		    }
   3553 	    	  end++;
   3554 		}
   3555 
   3556 	      if (c != ')')
   3557 		as_bad (_("Illegal operands: %%r_%s%d requires arguments in ()"),
   3558 			vax_cons_special_reloc, size * 8);
   3559 	      else
   3560 		{
   3561 		  *end = '\0';
   3562 		  expression (exp);
   3563 		  *end = c;
   3564 		  if (input_line_pointer != end)
   3565 		    {
   3566 		      as_bad (_("Illegal operands: %%r_%s%d requires arguments in ()"),
   3567 			      vax_cons_special_reloc, size * 8);
   3568 		    }
   3569 		  else
   3570 		    {
   3571 		      input_line_pointer++;
   3572 		      SKIP_WHITESPACE ();
   3573 		      c = *input_line_pointer;
   3574 		      if (! is_end_of_line[c] && c != ',')
   3575 			as_bad (_("Illegal operands: garbage after %%r_%s%d()"),
   3576 			        vax_cons_special_reloc, size * 8);
   3577 		    }
   3578 		}
   3579 	    }
   3580 	}
   3581     }
   3582   if (vax_cons_special_reloc == NULL)
   3583     expression (exp);
   3584   else
   3585     switch (size)
   3586       {
   3587       case 1: return BFD_RELOC_8_PCREL;
   3588       case 2: return BFD_RELOC_16_PCREL;
   3589       case 4: return BFD_RELOC_32_PCREL;
   3590       }
   3591   return NO_RELOC;
   3592 }
   3593 
   3594 /* This is called by emit_expr via TC_CONS_FIX_NEW when creating a
   3595    reloc for a cons.  */
   3596 
   3597 void
   3598 vax_cons_fix_new (fragS *frag, int where, unsigned int nbytes, expressionS *exp,
   3599 		  bfd_reloc_code_real_type r)
   3600 {
   3601   int pcrel;
   3602   // fix PC relative frags too ...
   3603   switch (r)
   3604     {
   3605     case BFD_RELOC_8_PCREL:
   3606     case BFD_RELOC_16_PCREL:
   3607     case BFD_RELOC_32_PCREL:
   3608       pcrel = 1;
   3609       /*
   3610        * Displacement mode addressing (of which PC relative is one
   3611        * type) uses the updated contents of the register as the base
   3612        * address.  VARM, Leonard 1987, pp34
   3613        */
   3614       switch (exp->X_op)
   3615 	{
   3616 	case O_constant:
   3617 	case O_symbol:
   3618 	  exp->X_add_number += nbytes;
   3619 	  break;
   3620 	}
   3621       break;
   3622     case NO_RELOC:
   3623     r = (nbytes == 1 ? BFD_RELOC_8
   3624 	 : nbytes == 2 ? BFD_RELOC_16
   3625 	 : BFD_RELOC_32);
   3626       pcrel = 0;
   3627       break;
   3628     default:
   3629       pcrel = 0;
   3630       break;
   3631     }
   3632 
   3633   fix_new_exp (frag, where, (int) nbytes, exp, pcrel, r);
   3634 }
   3635 
   3636 const char *
   3637 md_atof (int type, char * litP, int * sizeP)
   3638 {
   3639   return vax_md_atof (type, litP, sizeP);
   3640 }
   3641 
   3642 void
   3643 vax_cfi_frame_initial_instructions (void)
   3644 {
   3645   cfi_add_CFA_def_cfa (14, 0);
   3646 }
   3647 
   3648 int
   3649 tc_vax_regname_to_dw2regnum (char *regname)
   3650 {
   3651   unsigned int i;
   3652   static const struct { char *name; int dw2regnum; } regnames[] =
   3653     {
   3654       { "r0",   0 }, { "r1",  1 }, { "r2",   2 }, { "r3",   3 },
   3655       { "r4",   4 }, { "r5",  5 }, { "r6",   6 }, { "r7",   7 },
   3656       { "r8",   8 }, { "r9",  9 }, { "r10", 10 }, { "r11", 11 },
   3657       { "ap",  12 }, { "fp", 13 }, { "sp",  14 }, { "pc",  15 },
   3658       { "psw", 16 },
   3659     };
   3660 
   3661   for (i = 0; i < ARRAY_SIZE (regnames); ++i)
   3662     if (strcmp (regnames[i].name, regname) == 0)
   3663       return regnames[i].dw2regnum;
   3664 
   3665   return -1;
   3666 }
   3667 
   3668 void
   3669 vax_cfi_emit_pcrel_expr (expressionS *expP, unsigned int nbytes)
   3670 {
   3671   expressionS tmp = *expP;
   3672 
   3673   tmp.X_op = O_subtract;
   3674   tmp.X_op_symbol = symbol_temp_new_now ();
   3675   expP = &tmp;
   3676   expP->X_add_number += nbytes;
   3677   emit_expr (expP, nbytes);
   3678 }
   3679