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