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