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