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