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