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