1 /* tc-vax.c - vax-specific -
2 Copyright 1987, 1991, 1992, 1993, 1994, 1995, 1998, 2000, 2001, 2002,
3 2003, 2004, 2005, 2006, 2007, 2008
4 Free Software Foundation, Inc.
6 This file is part of GAS, the GNU Assembler.
8 GAS is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3, or (at your option)
13 GAS is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GAS; see the file COPYING. If not, write to the Free
20 Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA
26 #include "obstack.h" /* For FRAG_APPEND_1_CHAR macro in "frags.h" */
28 #include "safe-ctype.h"
34 /* These chars start a comment anywhere in a source file (except inside
36 const char comment_chars
[] = "#";
38 /* These chars only start a comment at the beginning of a line. */
39 /* Note that for the VAX the are the same as comment_chars above. */
40 const char line_comment_chars
[] = "#";
42 const char line_separator_chars
[] = ";";
44 /* Chars that can be used to separate mant from exp in floating point nums. */
45 const char EXP_CHARS
[] = "eE";
47 /* Chars that mean this number is a floating point constant
49 or 0H1.234E-12 (see exp chars above). */
50 const char FLT_CHARS
[] = "dDfFgGhH";
52 /* Also be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
53 changed in read.c . Ideally it shouldn't have to know about it at all,
54 but nothing is ideal around here. */
56 /* Hold details of an operand expression. */
57 static expressionS exp_of_operand
[VIT_MAX_OPERANDS
];
58 static segT seg_of_operand
[VIT_MAX_OPERANDS
];
60 /* A vax instruction after decoding. */
63 /* Hold details of big operands. */
64 LITTLENUM_TYPE big_operand_bits
[VIT_MAX_OPERANDS
][SIZE_OF_LARGE_NUMBER
];
65 FLONUM_TYPE float_operand
[VIT_MAX_OPERANDS
];
66 /* Above is made to point into big_operand_bits by md_begin(). */
69 #define GLOBAL_OFFSET_TABLE_NAME "_GLOBAL_OFFSET_TABLE_"
70 #define PROCEDURE_LINKAGE_TABLE_NAME "_PROCEDURE_LINKAGE_TABLE_"
71 symbolS
*GOT_symbol
; /* Pre-defined "_GLOBAL_OFFSET_TABLE_". */
72 symbolS
*PLT_symbol
; /* Pre-defined "_PROCEDURE_LINKAGE_TABLE_". */
75 int flag_hash_long_names
; /* -+ */
76 int flag_one
; /* -1 */
77 int flag_show_after_trunc
; /* -H */
78 int flag_no_hash_mixed_case
; /* -h NUM */
80 int flag_want_pic
; /* -k */
83 /* For VAX, relative addresses of "just the right length" are easy.
84 The branch displacement is always the last operand, even in
85 synthetic instructions.
86 For VAX, we encode the relax_substateTs (in e.g. fr_substate) as:
89 ---/ /--+-------+-------+-------+-------+-------+
90 | what state ? | how long ? |
91 ---/ /--+-------+-------+-------+-------+-------+
93 The "how long" bits are 00=byte, 01=word, 10=long.
94 This is a Un*x convention.
95 Not all lengths are legit for a given value of (what state).
96 The "how long" refers merely to the displacement length.
97 The address usually has some constant bytes in it as well.
99 groups for VAX address relaxing.
101 1. "foo" pc-relative.
102 length of byte, word, long
104 2a. J<cond> where <cond> is a simple flag test.
105 length of byte, word, long.
106 VAX opcodes are: (Hex)
119 Always, you complement 0th bit to reverse condition.
120 Always, 1-byte opcode, then 1-byte displacement.
122 2b. J<cond> where cond tests a memory bit.
123 length of byte, word, long.
124 Vax opcodes are: (Hex)
131 Always, you complement 0th bit to reverse condition.
132 Always, 1-byte opcde, longword-address, byte-address, 1-byte-displacement
134 2c. J<cond> where cond tests low-order memory bit
135 length of byte,word,long.
136 Vax opcodes are: (Hex)
139 Always, you complement 0th bit to reverse condition.
140 Always, 1-byte opcode, longword-address, 1-byte displacement.
143 length of byte,word,long.
144 Vax opcodes are: (Hex)
147 These are like (2) but there is no condition to reverse.
148 Always, 1 byte opcode, then displacement/absolute.
151 length of word, long.
152 Vax opcodes are: (Hex)
160 Always, we cannot reverse the sense of the branch; we have a word
162 The double-byte op-codes don't hurt: we never want to modify the
163 opcode, so we don't care how many bytes are between the opcode and
167 length of long, long, byte.
168 Vax opcodes are: (Hex)
173 Always, we cannot reverse the sense of the branch; we have a byte
176 The only time we need to modify the opcode is for class 2 instructions.
177 After relax() we may complement the lowest order bit of such instruction
178 to reverse sense of branch.
180 For class 2 instructions, we store context of "where is the opcode literal".
181 We can change an opcode's lowest order bit without breaking anything else.
183 We sometimes store context in the operand literal. This way we can figure out
184 after relax() what the original addressing mode was. */
186 /* These displacements are relative to the start address of the
187 displacement. The first letter is Byte, Word. 2nd letter is
188 Forward, Backward. */
191 #define WF (2+ 32767)
192 #define WB (2+-32768)
193 /* Dont need LF, LB because they always reach. [They are coded as 0.] */
195 #define C(a,b) ENCODE_RELAX(a,b)
196 /* This macro has no side-effects. */
197 #define ENCODE_RELAX(what,length) (((what) << 2) + (length))
198 #define RELAX_STATE(s) ((s) >> 2)
199 #define RELAX_LENGTH(s) ((s) & 3)
201 const relax_typeS md_relax_table
[] =
203 {1, 1, 0, 0}, /* error sentinel 0,0 */
204 {1, 1, 0, 0}, /* unused 0,1 */
205 {1, 1, 0, 0}, /* unused 0,2 */
206 {1, 1, 0, 0}, /* unused 0,3 */
208 {BF
+ 1, BB
+ 1, 2, C (1, 1)},/* B^"foo" 1,0 */
209 {WF
+ 1, WB
+ 1, 3, C (1, 2)},/* W^"foo" 1,1 */
210 {0, 0, 5, 0}, /* L^"foo" 1,2 */
211 {1, 1, 0, 0}, /* unused 1,3 */
213 {BF
, BB
, 1, C (2, 1)}, /* b<cond> B^"foo" 2,0 */
214 {WF
+ 2, WB
+ 2, 4, C (2, 2)},/* br.+? brw X 2,1 */
215 {0, 0, 7, 0}, /* br.+? jmp X 2,2 */
216 {1, 1, 0, 0}, /* unused 2,3 */
218 {BF
, BB
, 1, C (3, 1)}, /* brb B^foo 3,0 */
219 {WF
, WB
, 2, C (3, 2)}, /* brw W^foo 3,1 */
220 {0, 0, 5, 0}, /* Jmp L^foo 3,2 */
221 {1, 1, 0, 0}, /* unused 3,3 */
223 {1, 1, 0, 0}, /* unused 4,0 */
224 {WF
, WB
, 2, C (4, 2)}, /* acb_ ^Wfoo 4,1 */
225 {0, 0, 10, 0}, /* acb_,br,jmp L^foo4,2 */
226 {1, 1, 0, 0}, /* unused 4,3 */
228 {BF
, BB
, 1, C (5, 1)}, /* Xob___,,foo 5,0 */
229 {WF
+ 4, WB
+ 4, 6, C (5, 2)},/* Xob.+2,brb.+3,brw5,1 */
230 {0, 0, 9, 0}, /* Xob.+2,brb.+6,jmp5,2 */
231 {1, 1, 0, 0}, /* unused 5,3 */
240 void float_cons (int);
241 int flonum_gen2vax (char, FLONUM_TYPE
*, LITTLENUM_TYPE
*);
243 const pseudo_typeS md_pseudo_table
[] =
245 {"dfloat", float_cons
, 'd'},
246 {"ffloat", float_cons
, 'f'},
247 {"gfloat", float_cons
, 'g'},
248 {"hfloat", float_cons
, 'h'},
249 {"d_floating", float_cons
, 'd'},
250 {"f_floating", float_cons
, 'f'},
251 {"g_floating", float_cons
, 'g'},
252 {"h_floating", float_cons
, 'h'},
256 #define STATE_PC_RELATIVE (1)
257 #define STATE_CONDITIONAL_BRANCH (2)
258 #define STATE_ALWAYS_BRANCH (3) /* includes BSB... */
259 #define STATE_COMPLEX_BRANCH (4)
260 #define STATE_COMPLEX_HOP (5)
262 #define STATE_BYTE (0)
263 #define STATE_WORD (1)
264 #define STATE_LONG (2)
265 #define STATE_UNDF (3) /* Symbol undefined in pass1. */
267 #define min(a, b) ((a) < (b) ? (a) : (b))
270 md_number_to_chars (char con
[], valueT value
, int nbytes
)
272 number_to_chars_littleendian (con
, value
, nbytes
);
275 /* Fix up some data or instructions after we find out the value of a symbol
276 that they reference. */
278 void /* Knows about order of bytes in address. */
279 md_apply_fix (fixS
*fixP
, valueT
*valueP
, segT seg ATTRIBUTE_UNUSED
)
281 valueT value
= * valueP
;
283 if (((fixP
->fx_addsy
== NULL
&& fixP
->fx_subsy
== NULL
)
284 && fixP
->fx_r_type
!= BFD_RELOC_32_PLT_PCREL
285 && fixP
->fx_r_type
!= BFD_RELOC_32_GOT_PCREL
)
286 || fixP
->fx_r_type
== NO_RELOC
)
287 number_to_chars_littleendian (fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
,
288 value
, fixP
->fx_size
);
290 if (fixP
->fx_addsy
== NULL
&& fixP
->fx_pcrel
== 0)
294 /* Convert a number from VAX byte order (little endian)
295 into host byte order.
296 con is the buffer to convert,
297 nbytes is the length of the given buffer. */
299 md_chars_to_number (unsigned char con
[], int nbytes
)
303 for (retval
= 0, con
+= nbytes
- 1; nbytes
--; con
--)
305 retval
<<= BITS_PER_CHAR
;
311 /* Copy a bignum from in to out.
312 If the output is shorter than the input, copy lower-order
313 littlenums. Return 0 or the number of significant littlenums
314 dropped. Assumes littlenum arrays are densely packed: no unused
315 chars between the littlenums. Uses memcpy() to move littlenums, and
316 wants to know length (in chars) of the input bignum. */
319 bignum_copy (LITTLENUM_TYPE
*in
,
320 int in_length
, /* in sizeof(littlenum)s */
322 int out_length
/* in sizeof(littlenum)s */)
324 int significant_littlenums_dropped
;
326 if (out_length
< in_length
)
328 LITTLENUM_TYPE
*p
; /* -> most significant (non-zero) input
331 memcpy ((void *) out
, (void *) in
,
332 (unsigned int) out_length
<< LITTLENUM_SHIFT
);
333 for (p
= in
+ in_length
- 1; p
>= in
; --p
)
338 significant_littlenums_dropped
= p
- in
- in_length
+ 1;
340 if (significant_littlenums_dropped
< 0)
341 significant_littlenums_dropped
= 0;
345 memcpy ((char *) out
, (char *) in
,
346 (unsigned int) in_length
<< LITTLENUM_SHIFT
);
348 if (out_length
> in_length
)
349 memset ((char *) (out
+ in_length
), '\0',
350 (unsigned int) (out_length
- in_length
) << LITTLENUM_SHIFT
);
352 significant_littlenums_dropped
= 0;
355 return significant_littlenums_dropped
;
358 /* md_estimate_size_before_relax(), called just before relax().
359 Any symbol that is now undefined will not become defined.
360 Return the correct fr_subtype in the frag and the growth beyond
363 md_estimate_size_before_relax (fragS
*fragP
, segT segment
)
365 if (RELAX_LENGTH (fragP
->fr_subtype
) == STATE_UNDF
)
367 if (S_GET_SEGMENT (fragP
->fr_symbol
) != segment
369 || S_IS_WEAK (fragP
->fr_symbol
)
370 || S_IS_EXTERNAL (fragP
->fr_symbol
)
374 /* Non-relaxable cases. */
375 int reloc_type
= NO_RELOC
;
379 old_fr_fix
= fragP
->fr_fix
;
380 p
= fragP
->fr_literal
+ old_fr_fix
;
382 /* If this is to an undefined symbol, then if it's an indirect
383 reference indicate that is can mutated into a GLOB_DAT or
384 JUMP_SLOT by the loader. We restrict ourselves to no offset
385 due to a limitation in the NetBSD linker. */
387 if (GOT_symbol
== NULL
)
388 GOT_symbol
= symbol_find (GLOBAL_OFFSET_TABLE_NAME
);
389 if (PLT_symbol
== NULL
)
390 PLT_symbol
= symbol_find (PROCEDURE_LINKAGE_TABLE_NAME
);
391 if ((GOT_symbol
== NULL
|| fragP
->fr_symbol
!= GOT_symbol
)
392 && (PLT_symbol
== NULL
|| fragP
->fr_symbol
!= PLT_symbol
)
393 && fragP
->fr_symbol
!= NULL
395 && (!S_IS_DEFINED (fragP
->fr_symbol
)
396 || S_IS_WEAK (fragP
->fr_symbol
)
397 || S_IS_EXTERNAL (fragP
->fr_symbol
)))
402 as_fatal ("PIC reference to %s is indirect.\n",
403 S_GET_NAME (fragP
->fr_symbol
));
407 if (((unsigned char *) fragP
->fr_opcode
)[0] == VAX_CALLS
408 || ((unsigned char *) fragP
->fr_opcode
)[0] == VAX_CALLG
409 || ((unsigned char *) fragP
->fr_opcode
)[0] == VAX_JSB
410 || ((unsigned char *) fragP
->fr_opcode
)[0] == VAX_JMP
411 || S_IS_FUNCTION (fragP
->fr_symbol
))
412 reloc_type
= BFD_RELOC_32_PLT_PCREL
;
414 reloc_type
= BFD_RELOC_32_GOT_PCREL
;
418 switch (RELAX_STATE (fragP
->fr_subtype
))
420 case STATE_PC_RELATIVE
:
421 p
[0] |= VAX_PC_RELATIVE_MODE
; /* Preserve @ bit. */
422 fragP
->fr_fix
+= 1 + 4;
423 fix_new (fragP
, old_fr_fix
+ 1, 4, fragP
->fr_symbol
,
424 fragP
->fr_offset
, 1, reloc_type
);
427 case STATE_CONDITIONAL_BRANCH
:
428 *fragP
->fr_opcode
^= 1; /* Reverse sense of branch. */
431 p
[2] = VAX_PC_RELATIVE_MODE
; /* ...(PC) */
432 fragP
->fr_fix
+= 1 + 1 + 1 + 4;
433 fix_new (fragP
, old_fr_fix
+ 3, 4, fragP
->fr_symbol
,
434 fragP
->fr_offset
, 1, NO_RELOC
);
437 case STATE_COMPLEX_BRANCH
:
443 p
[5] = VAX_PC_RELATIVE_MODE
; /* ...(pc) */
444 fragP
->fr_fix
+= 2 + 2 + 1 + 1 + 4;
445 fix_new (fragP
, old_fr_fix
+ 6, 4, fragP
->fr_symbol
,
446 fragP
->fr_offset
, 1, NO_RELOC
);
449 case STATE_COMPLEX_HOP
:
454 p
[4] = VAX_PC_RELATIVE_MODE
; /* ...(pc) */
455 fragP
->fr_fix
+= 1 + 2 + 1 + 1 + 4;
456 fix_new (fragP
, old_fr_fix
+ 5, 4, fragP
->fr_symbol
,
457 fragP
->fr_offset
, 1, NO_RELOC
);
460 case STATE_ALWAYS_BRANCH
:
461 *fragP
->fr_opcode
+= VAX_WIDEN_LONG
;
462 p
[0] = VAX_PC_RELATIVE_MODE
; /* ...(PC) */
463 fragP
->fr_fix
+= 1 + 4;
464 fix_new (fragP
, old_fr_fix
+ 1, 4, fragP
->fr_symbol
,
465 fragP
->fr_offset
, 1, NO_RELOC
);
473 /* Return the growth in the fixed part of the frag. */
474 return fragP
->fr_fix
- old_fr_fix
;
477 /* Relaxable cases. Set up the initial guess for the variable
479 switch (RELAX_STATE (fragP
->fr_subtype
))
481 case STATE_PC_RELATIVE
:
482 fragP
->fr_subtype
= ENCODE_RELAX (STATE_PC_RELATIVE
, STATE_BYTE
);
484 case STATE_CONDITIONAL_BRANCH
:
485 fragP
->fr_subtype
= ENCODE_RELAX (STATE_CONDITIONAL_BRANCH
, STATE_BYTE
);
487 case STATE_COMPLEX_BRANCH
:
488 fragP
->fr_subtype
= ENCODE_RELAX (STATE_COMPLEX_BRANCH
, STATE_WORD
);
490 case STATE_COMPLEX_HOP
:
491 fragP
->fr_subtype
= ENCODE_RELAX (STATE_COMPLEX_HOP
, STATE_BYTE
);
493 case STATE_ALWAYS_BRANCH
:
494 fragP
->fr_subtype
= ENCODE_RELAX (STATE_ALWAYS_BRANCH
, STATE_BYTE
);
499 if (fragP
->fr_subtype
>= sizeof (md_relax_table
) / sizeof (md_relax_table
[0]))
502 /* Return the size of the variable part of the frag. */
503 return md_relax_table
[fragP
->fr_subtype
].rlx_length
;
506 /* Called after relax() is finished.
508 fr_type == rs_machine_dependent.
509 fr_subtype is what the address relaxed to.
511 Out: Any fixSs and constants are set up.
512 Caller will turn frag into a ".space 0". */
514 md_convert_frag (bfd
*headers ATTRIBUTE_UNUSED
,
515 segT seg ATTRIBUTE_UNUSED
,
518 char *addressP
; /* -> _var to change. */
519 char *opcodeP
; /* -> opcode char(s) to change. */
520 short int extension
= 0; /* Size of relaxed address. */
521 /* Added to fr_fix: incl. ALL var chars. */
525 know (fragP
->fr_type
== rs_machine_dependent
);
526 where
= fragP
->fr_fix
;
527 addressP
= fragP
->fr_literal
+ where
;
528 opcodeP
= fragP
->fr_opcode
;
529 symbolP
= fragP
->fr_symbol
;
532 switch (fragP
->fr_subtype
)
534 case ENCODE_RELAX (STATE_PC_RELATIVE
, STATE_BYTE
):
535 know (*addressP
== 0 || *addressP
== 0x10); /* '@' bit. */
536 addressP
[0] |= 0xAF; /* Byte displacement. */
537 fix_new (fragP
, fragP
->fr_fix
+ 1, 1, fragP
->fr_symbol
,
538 fragP
->fr_offset
, 1, NO_RELOC
);
542 case ENCODE_RELAX (STATE_PC_RELATIVE
, STATE_WORD
):
543 know (*addressP
== 0 || *addressP
== 0x10); /* '@' bit. */
544 addressP
[0] |= 0xCF; /* Word displacement. */
545 fix_new (fragP
, fragP
->fr_fix
+ 1, 2, fragP
->fr_symbol
,
546 fragP
->fr_offset
, 1, NO_RELOC
);
550 case ENCODE_RELAX (STATE_PC_RELATIVE
, STATE_LONG
):
551 know (*addressP
== 0 || *addressP
== 0x10); /* '@' bit. */
552 addressP
[0] |= 0xEF; /* Long word displacement. */
553 fix_new (fragP
, fragP
->fr_fix
+ 1, 4, fragP
->fr_symbol
,
554 fragP
->fr_offset
, 1, NO_RELOC
);
558 case ENCODE_RELAX (STATE_CONDITIONAL_BRANCH
, STATE_BYTE
):
559 fix_new (fragP
, fragP
->fr_fix
, 1, fragP
->fr_symbol
,
560 fragP
->fr_offset
, 1, NO_RELOC
);
564 case ENCODE_RELAX (STATE_CONDITIONAL_BRANCH
, STATE_WORD
):
565 opcodeP
[0] ^= 1; /* Reverse sense of test. */
567 addressP
[1] = VAX_BRW
;
568 fix_new (fragP
, fragP
->fr_fix
+ 2, 2, fragP
->fr_symbol
,
569 fragP
->fr_offset
, 1, NO_RELOC
);
573 case ENCODE_RELAX (STATE_CONDITIONAL_BRANCH
, STATE_LONG
):
574 opcodeP
[0] ^= 1; /* Reverse sense of test. */
576 addressP
[1] = VAX_JMP
;
577 addressP
[2] = VAX_PC_RELATIVE_MODE
;
578 fix_new (fragP
, fragP
->fr_fix
+ 3, 4, fragP
->fr_symbol
,
579 fragP
->fr_offset
, 1, NO_RELOC
);
583 case ENCODE_RELAX (STATE_ALWAYS_BRANCH
, STATE_BYTE
):
584 fix_new (fragP
, fragP
->fr_fix
, 1, fragP
->fr_symbol
,
585 fragP
->fr_offset
, 1, NO_RELOC
);
589 case ENCODE_RELAX (STATE_ALWAYS_BRANCH
, STATE_WORD
):
590 opcodeP
[0] += VAX_WIDEN_WORD
; /* brb -> brw, bsbb -> bsbw */
591 fix_new (fragP
, fragP
->fr_fix
, 2, fragP
->fr_symbol
, fragP
->fr_offset
,
596 case ENCODE_RELAX (STATE_ALWAYS_BRANCH
, STATE_LONG
):
597 opcodeP
[0] += VAX_WIDEN_LONG
; /* brb -> jmp, bsbb -> jsb */
598 addressP
[0] = VAX_PC_RELATIVE_MODE
;
599 fix_new (fragP
, fragP
->fr_fix
+ 1, 4, fragP
->fr_symbol
,
600 fragP
->fr_offset
, 1, NO_RELOC
);
604 case ENCODE_RELAX (STATE_COMPLEX_BRANCH
, STATE_WORD
):
605 fix_new (fragP
, fragP
->fr_fix
, 2, fragP
->fr_symbol
,
606 fragP
->fr_offset
, 1, NO_RELOC
);
610 case ENCODE_RELAX (STATE_COMPLEX_BRANCH
, STATE_LONG
):
613 addressP
[2] = VAX_BRB
;
615 addressP
[4] = VAX_JMP
;
616 addressP
[5] = VAX_PC_RELATIVE_MODE
;
617 fix_new (fragP
, fragP
->fr_fix
+ 6, 4, fragP
->fr_symbol
,
618 fragP
->fr_offset
, 1, NO_RELOC
);
622 case ENCODE_RELAX (STATE_COMPLEX_HOP
, STATE_BYTE
):
623 fix_new (fragP
, fragP
->fr_fix
, 1, fragP
->fr_symbol
,
624 fragP
->fr_offset
, 1, NO_RELOC
);
628 case ENCODE_RELAX (STATE_COMPLEX_HOP
, STATE_WORD
):
630 addressP
[1] = VAX_BRB
;
632 addressP
[3] = VAX_BRW
;
633 fix_new (fragP
, fragP
->fr_fix
+ 4, 2, fragP
->fr_symbol
,
634 fragP
->fr_offset
, 1, NO_RELOC
);
638 case ENCODE_RELAX (STATE_COMPLEX_HOP
, STATE_LONG
):
640 addressP
[1] = VAX_BRB
;
642 addressP
[3] = VAX_JMP
;
643 addressP
[4] = VAX_PC_RELATIVE_MODE
;
644 fix_new (fragP
, fragP
->fr_fix
+ 5, 4, fragP
->fr_symbol
,
645 fragP
->fr_offset
, 1, NO_RELOC
);
650 BAD_CASE (fragP
->fr_subtype
);
653 fragP
->fr_fix
+= extension
;
656 /* Translate internal format of relocation info into target format.
658 On vax: first 4 bytes are normal unsigned long, next three bytes
659 are symbolnum, least sig. byte first. Last byte is broken up with
660 the upper nibble as nuthin, bit 3 as extern, bits 2 & 1 as length, and
664 md_ri_to_chars (char *the_bytes
, struct reloc_info_generic ri
)
667 md_number_to_chars (the_bytes
, ri
.r_address
, sizeof (ri
.r_address
));
668 /* Now the fun stuff. */
669 the_bytes
[6] = (ri
.r_symbolnum
>> 16) & 0x0ff;
670 the_bytes
[5] = (ri
.r_symbolnum
>> 8) & 0x0ff;
671 the_bytes
[4] = ri
.r_symbolnum
& 0x0ff;
672 the_bytes
[7] = (((ri
.r_extern
<< 3) & 0x08) | ((ri
.r_length
<< 1) & 0x06)
673 | ((ri
.r_pcrel
<< 0) & 0x01)) & 0x0F;
678 /* BUGS, GRIPES, APOLOGIA, etc.
680 The opcode table 'votstrs' needs to be sorted on opcode frequency.
681 That is, AFTER we hash it with hash_...(), we want most-used opcodes
682 to come out of the hash table faster.
684 I am sorry to inflict yet another VAX assembler on the world, but
685 RMS says we must do everything from scratch, to prevent pin-heads
686 restricting this software.
688 This is a vaguely modular set of routines in C to parse VAX
689 assembly code using DEC mnemonics. It is NOT un*x specific.
691 The idea here is that the assembler has taken care of all:
698 condensing any whitespace down to exactly one space
699 and all we have to do is parse 1 line into a vax instruction
700 partially formed. We will accept a line, and deliver:
701 an error message (hopefully empty)
702 a skeleton VAX instruction (tree structure)
703 textual pointers to all the operand expressions
704 a warning message that notes a silly operand (hopefully empty)
706 E D I T H I S T O R Y
708 17may86 Dean Elsner. Bug if line ends immediately after opcode.
709 30apr86 Dean Elsner. New vip_op() uses arg block so change call.
710 6jan86 Dean Elsner. Crock vip_begin() to call vip_op_defaults().
711 2jan86 Dean Elsner. Invent synthetic opcodes.
712 Widen vax_opcodeT to 32 bits. Use a bit for VIT_OPCODE_SYNTHETIC,
713 which means this is not a real opcode, it is like a macro; it will
714 be relax()ed into 1 or more instructions.
715 Use another bit for VIT_OPCODE_SPECIAL if the op-code is not optimised
716 like a regular branch instruction. Option added to vip_begin():
717 exclude synthetic opcodes. Invent synthetic_votstrs[].
718 31dec85 Dean Elsner. Invent vit_opcode_nbytes.
719 Also make vit_opcode into a char[]. We now have n-byte vax opcodes,
720 so caller's don't have to know the difference between a 1-byte & a
721 2-byte op-code. Still need vax_opcodeT concept, so we know how
722 big an object must be to hold an op.code.
723 30dec85 Dean Elsner. Widen typedef vax_opcodeT in "vax-inst.h"
724 because vax opcodes may be 16 bits. Our crufty C compiler was
725 happily initialising 8-bit vot_codes with 16-bit numbers!
726 (Wouldn't the 'phone company like to compress data so easily!)
727 29dec85 Dean Elsner. New static table vax_operand_width_size[].
728 Invented so we know hw many bytes a "I^#42" needs in its immediate
729 operand. Revised struct vop in "vax-inst.h": explicitly include
730 byte length of each operand, and it's letter-code datum type.
731 17nov85 Dean Elsner. Name Change.
732 Due to ar(1) truncating names, we learned the hard way that
733 "vax-inst-parse.c" -> "vax-inst-parse." dropping the "o" off
734 the archived object name. SO... we shortened the name of this
735 source file, and changed the makefile. */
737 /* Handle of the OPCODE hash table. */
738 static struct hash_control
*op_hash
;
740 /* In: 1 character, from "bdfghloqpw" being the data-type of an operand
741 of a vax instruction.
743 Out: the length of an operand of that type, in bytes.
744 Special branch operands types "-?!" have length 0. */
746 static const short int vax_operand_width_size
[256] =
748 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
749 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
750 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
751 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
752 0, 0, 1, 0, 8, 0, 4, 8, 16, 0, 0, 0, 4, 0, 0,16, /* ..b.d.fgh...l..o */
753 0, 8, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, /* .q.....w........ */
754 0, 0, 1, 0, 8, 0, 4, 8, 16, 0, 0, 0, 4, 0, 0,16, /* ..b.d.fgh...l..o */
755 0, 8, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, /* .q.....w........ */
756 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
757 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
758 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
759 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
760 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
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,
766 /* This perversion encodes all the vax opcodes as a bunch of strings.
767 RMS says we should build our hash-table at run-time. Hmm.
768 Please would someone arrange these in decreasing frequency of opcode?
769 Because of the way hash_...() works, the most frequently used opcode
770 should be textually first and so on.
772 Input for this table was 'vax.opcodes', awk(1)ed by 'vax.opcodes.c.awk' .
773 So change 'vax.opcodes', then re-generate this table. */
775 #include "opcode/vax.h"
777 /* This is a table of optional op-codes. All of them represent
778 'synthetic' instructions that seem popular.
780 Here we make some pseudo op-codes. Every code has a bit set to say
781 it is synthetic. This lets you catch them if you want to
782 ban these opcodes. They are mnemonics for "elastic" instructions
783 that are supposed to assemble into the fewest bytes needed to do a
784 branch, or to do a conditional branch, or whatever.
786 The opcode is in the usual place [low-order n*8 bits]. This means
787 that if you mask off the bucky bits, the usual rules apply about
788 how long the opcode is.
790 All VAX branch displacements come at the end of the instruction.
791 For simple branches (1-byte opcode + 1-byte displacement) the last
792 operand is coded 'b?' where the "data type" '?' is a clue that we
793 may reverse the sense of the branch (complement lowest order bit)
794 and branch around a jump. This is by far the most common case.
795 That is why the VIT_OPCODE_SYNTHETIC bit is set: it says this is
796 a 0-byte op-code followed by 2 or more bytes of operand address.
798 If the op-code has VIT_OPCODE_SPECIAL set, then we have a more unusual
801 For JBSB & JBR the treatment is the similar, except (1) we have a 'bw'
802 option before (2) we can directly JSB/JMP because there is no condition.
803 These operands have 'b-' as their access/data type.
805 That leaves a bunch of random opcodes: JACBx, JxOBxxx. In these
806 cases, we do the same idea. JACBxxx are all marked with a 'b!'
807 JAOBxxx & JSOBxxx are marked with a 'b:'. */
808 #if (VIT_OPCODE_SYNTHETIC != 0x80000000)
809 #error "You have just broken the encoding below, which assumes the sign bit means 'I am an imaginary instruction'."
812 #if (VIT_OPCODE_SPECIAL != 0x40000000)
813 #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'."
816 static const struct vot
817 synthetic_votstrs
[] =
819 {"jbsb", {"b-", 0xC0000010}}, /* BSD 4.2 */
820 /* jsb used already */
821 {"jbr", {"b-", 0xC0000011}}, /* BSD 4.2 */
822 {"jr", {"b-", 0xC0000011}}, /* consistent */
823 {"jneq", {"b?", 0x80000012}},
824 {"jnequ", {"b?", 0x80000012}},
825 {"jeql", {"b?", 0x80000013}},
826 {"jeqlu", {"b?", 0x80000013}},
827 {"jgtr", {"b?", 0x80000014}},
828 {"jleq", {"b?", 0x80000015}},
829 /* un-used opcodes here */
830 {"jgeq", {"b?", 0x80000018}},
831 {"jlss", {"b?", 0x80000019}},
832 {"jgtru", {"b?", 0x8000001a}},
833 {"jlequ", {"b?", 0x8000001b}},
834 {"jvc", {"b?", 0x8000001c}},
835 {"jvs", {"b?", 0x8000001d}},
836 {"jgequ", {"b?", 0x8000001e}},
837 {"jcc", {"b?", 0x8000001e}},
838 {"jlssu", {"b?", 0x8000001f}},
839 {"jcs", {"b?", 0x8000001f}},
841 {"jacbw", {"rwrwmwb!", 0xC000003d}},
842 {"jacbf", {"rfrfmfb!", 0xC000004f}},
843 {"jacbd", {"rdrdmdb!", 0xC000006f}},
844 {"jacbb", {"rbrbmbb!", 0xC000009d}},
845 {"jacbl", {"rlrlmlb!", 0xC00000f1}},
846 {"jacbg", {"rgrgmgb!", 0xC0004ffd}},
847 {"jacbh", {"rhrhmhb!", 0xC0006ffd}},
849 {"jbs", {"rlvbb?", 0x800000e0}},
850 {"jbc", {"rlvbb?", 0x800000e1}},
851 {"jbss", {"rlvbb?", 0x800000e2}},
852 {"jbcs", {"rlvbb?", 0x800000e3}},
853 {"jbsc", {"rlvbb?", 0x800000e4}},
854 {"jbcc", {"rlvbb?", 0x800000e5}},
855 {"jbssi", {"rlvbb?", 0x800000e6}},
856 {"jbcci", {"rlvbb?", 0x800000e7}},
857 {"jlbs", {"rlb?", 0x800000e8}},
858 {"jlbc", {"rlb?", 0x800000e9}},
860 {"jaoblss", {"rlmlb:", 0xC00000f2}},
861 {"jaobleq", {"rlmlb:", 0xC00000f3}},
862 {"jsobgeq", {"mlb:", 0xC00000f4}},
863 {"jsobgtr", {"mlb:", 0xC00000f5}},
865 /* CASEx has no branch addresses in our conception of it. */
866 /* You should use ".word ..." statements after the "case ...". */
868 {"", {"", 0}} /* Empty is end sentinel. */
871 /* Because this module is useful for both VMS and UN*X style assemblers
872 and because of the variety of UN*X assemblers we must recognise
873 the different conventions for assembler operand notation. For example
874 VMS says "#42" for immediate mode, while most UN*X say "$42".
875 We permit arbitrary sets of (single) characters to represent the
876 3 concepts that DEC writes '#', '@', '^'. */
878 /* Character tests. */
879 #define VIP_IMMEDIATE 01 /* Character is like DEC # */
880 #define VIP_INDIRECT 02 /* Char is like DEC @ */
881 #define VIP_DISPLEN 04 /* Char is like DEC ^ */
883 #define IMMEDIATEP(c) (vip_metacharacters [(c) & 0xff] & VIP_IMMEDIATE)
884 #define INDIRECTP(c) (vip_metacharacters [(c) & 0xff] & VIP_INDIRECT)
885 #define DISPLENP(c) (vip_metacharacters [(c) & 0xff] & VIP_DISPLEN)
887 /* We assume 8 bits per byte. Use vip_op_defaults() to set these up BEFORE we
890 #if defined(CONST_TABLE)
892 #define I VIP_IMMEDIATE,
893 #define S VIP_INDIRECT,
894 #define D VIP_DISPLEN,
896 vip_metacharacters
[256] =
898 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/* ^@ ^A ^B ^C ^D ^E ^F ^G ^H ^I ^J ^K ^L ^M ^N ^O*/
899 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/* ^P ^Q ^R ^S ^T ^U ^V ^W ^X ^Y ^Z ^[ ^\ ^] ^^ ^_ */
900 _ _ _ _ I _ _ _ _ _ S _ _ _ _ _
/* sp ! " # $ % & ' ( ) * + , - . / */
901 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/*0 1 2 3 4 5 6 7 8 9 : ; < = > ?*/
902 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/*@ A B C D E F G H I J K L M N O*/
903 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/*P Q R S T U V W X Y Z [ \ ] ^ _*/
904 D _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/*` a b c d e f g h i j k l m n o*/
905 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/*p q r s t u v w x y z { | } ~ ^?*/
907 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
908 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
909 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
910 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
911 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
912 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
913 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
914 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
923 static char vip_metacharacters
[256];
926 vip_op_1 (int bit
, const char *syms
)
930 while ((t
= *syms
++) != 0)
931 vip_metacharacters
[t
] |= bit
;
934 /* Can be called any time. More arguments may appear in future. */
936 vip_op_defaults (const char *immediate
, const char *indirect
, const char *displen
)
938 vip_op_1 (VIP_IMMEDIATE
, immediate
);
939 vip_op_1 (VIP_INDIRECT
, indirect
);
940 vip_op_1 (VIP_DISPLEN
, displen
);
945 /* Call me once before you decode any lines.
946 I decode votstrs into a hash table at op_hash (which I create).
947 I return an error text or null.
948 If you want, I will include the 'synthetic' jXXX instructions in the
950 You must nominate metacharacters for eg DEC's "#", "@", "^". */
953 vip_begin (int synthetic_too
, /* 1 means include jXXX op-codes. */
954 const char *immediate
,
955 const char *indirect
,
958 const struct vot
*vP
; /* scan votstrs */
959 const char *retval
= 0; /* error text */
961 op_hash
= hash_new ();
963 for (vP
= votstrs
; *vP
->vot_name
&& !retval
; vP
++)
964 retval
= hash_insert (op_hash
, vP
->vot_name
, (void *) &vP
->vot_detail
);
967 for (vP
= synthetic_votstrs
; *vP
->vot_name
&& !retval
; vP
++)
968 retval
= hash_insert (op_hash
, vP
->vot_name
, (void *) &vP
->vot_detail
);
971 vip_op_defaults (immediate
, indirect
, displen
);
977 /* Take 3 char.s, the last of which may be `\0` (non-existent)
978 and return the VAX register number that they represent.
980 Return -1 if they don't form a register name. Good names return
981 a number from 0:15 inclusive.
983 Case is not important in a name.
985 Register names understood are:
1009 /* Returns the register number of something like '%r15' or 'ap', supplied
1010 in four single chars. Returns -1 if the register isn't recognized,
1013 vax_reg_parse (char c1
, char c2
, char c3
, char c4
)
1018 if (c1
!= '%') /* Register prefixes are mandatory for ELF. */
1025 if (c4
!= 0) /* Register prefixes are not allowed under VMS. */
1029 if (c1
== '%') /* Register prefixes are optional under a.out. */
1035 else if (c3
&& c4
) /* Can't be 4 characters long. */
1041 if (ISDIGIT (c2
) && c1
== 'r')
1046 retval
= retval
* 10 + c3
- '0';
1047 retval
= (retval
> 15) ? -1 : retval
;
1048 /* clamp the register value to 1 hex digit */
1051 retval
= -1; /* c3 must be '\0' or a digit. */
1053 else if (c3
) /* There are no three letter regs. */
1072 else if (c1
== 'p' && c2
== 'c')
1079 /* Parse a vax operand in DEC assembler notation.
1080 For speed, expect a string of whitespace to be reduced to a single ' '.
1081 This is the case for GNU AS, and is easy for other DEC-compatible
1084 Knowledge about DEC VAX assembler operand notation lives here.
1085 This doesn't even know what a register name is, except it believes
1086 all register names are 2 or 3 characters, and lets vax_reg_parse() say
1087 what number each name represents.
1088 It does, however, know that PC, SP etc are special registers so it can
1089 detect addressing modes that are silly for those registers.
1091 Where possible, it delivers 1 fatal or 1 warning message if the operand
1092 is suspect. Exactly what we test for is still evolving.
1097 There were a number of 'mismatched argument type' bugs to vip_op.
1098 The most general solution is to typedef each (of many) arguments.
1099 We used instead a typedef'd argument block. This is less modular
1100 than using separate return pointers for each result, but runs faster
1101 on most engines, and seems to keep programmers happy. It will have
1102 to be done properly if we ever want to use vip_op as a general-purpose
1103 module (it was designed to be).
1107 Doesn't support DEC "G^" format operands. These always take 5 bytes
1108 to express, and code as modes 8F or 9F. Reason: "G^" deprives you of
1109 optimising to (say) a "B^" if you are lucky in the way you link.
1110 When someone builds a linker smart enough to convert "G^" to "B^", "W^"
1111 whenever possible, then we should implement it.
1112 If there is some other use for "G^", feel free to code it in!
1116 If I nested if()s more, I could avoid testing (*err) which would save
1117 time, space and page faults. I didn't nest all those if()s for clarity
1118 and because I think the mode testing can be re-arranged 1st to test the
1119 commoner constructs 1st. Does anybody have statistics on this?
1123 In future, we should be able to 'compose' error messages in a scratch area
1124 and give the user MUCH more informative error messages. Although this takes
1125 a little more code at run-time, it will make this module much more self-
1126 documenting. As an example of what sucks now: most error messages have
1127 hardwired into them the DEC VAX metacharacters "#^@" which are nothing like
1128 the Un*x characters "$`*", that most users will expect from this AS.
1132 The input is a string, ending with '\0'.
1134 We also require a 'hint' of what kind of operand is expected: so
1135 we can remind caller not to write into literals for instance.
1137 The output is a skeletal instruction.
1139 The algorithm has two parts.
1140 1. extract the syntactic features (parse off all the @^#-()+[] mode crud);
1141 2. express the @^#-()+[] as some parameters suited to further analysis.
1143 2nd step is where we detect the googles of possible invalid combinations
1144 a human (or compiler) might write. Note that if we do a half-way
1145 decent assembler, we don't know how long to make (eg) displacement
1146 fields when we first meet them (because they may not have defined values).
1147 So we must wait until we know how many bits are needed for each address,
1148 then we can know both length and opcodes of instructions.
1149 For reason(s) above, we will pass to our caller a 'broken' instruction
1150 of these major components, from which our caller can generate instructions:
1151 - displacement length I^ S^ L^ B^ W^ unspecified
1153 - register R0-R15 or absent
1154 - index register R0-R15 or absent
1155 - expression text what we don't parse
1156 - error text(s) why we couldn't understand the operand
1160 To decode output of this, test errtxt. If errtxt[0] == '\0', then
1161 we had no errors that prevented parsing. Also, if we ever report
1162 an internal bug, errtxt[0] is set non-zero. So one test tells you
1163 if the other outputs are to be taken seriously.
1167 Dec defines the semantics of address modes (and values)
1168 by a two-letter code, explained here.
1170 letter 1: access type
1172 a address calculation - no data access, registers forbidden
1173 b branch displacement
1174 m read - let go of bus - write back "modify"
1176 v bit field address: like 'a' but registers are OK
1178 space no operator (eg ".long foo") [our convention]
1180 letter 2: data type (i.e. width, alignment)
1183 d double precision floating point (D format)
1184 f single precision floating point (F format)
1191 ? simple synthetic branch operand
1192 - unconditional synthetic JSB/JSR operand
1193 ! complex synthetic branch operand
1195 The '-?!' letter 2's are not for external consumption. They are used
1196 for various assemblers. Generally, all unknown widths are assumed 0.
1197 We don't limit your choice of width character.
1199 DEC operands are hard work to parse. For example, '@' as the first
1200 character means indirect (deferred) mode but elsewhere it is a shift
1202 The long-winded explanation of how this is supposed to work is
1203 cancelled. Read a DEC vax manual.
1204 We try hard not to parse anything that MIGHT be part of the expression
1205 buried in that syntax. For example if we see @...(Rn) we don't check
1206 for '-' before the '(' because mode @-(Rn) does not exist.
1208 After parsing we have:
1210 at 1 if leading '@' (or Un*x '*')
1211 len takes one value from " bilsw". eg B^ -> 'b'.
1212 hash 1 if leading '#' (or Un*x '$')
1213 expr_begin, expr_end the expression we did not parse
1214 even though we don't interpret it, we make use
1215 of its presence or absence.
1216 sign -1: -(Rn) 0: absent +1: (Rn)+
1217 paren 1 if () are around register
1218 reg major register number 0:15 -1 means absent
1219 ndx index register number 0:15 -1 means absent
1221 Again, I dare not explain it: just trace ALL the code!
1223 Summary of vip_op outputs.
1227 {@}Rn 5+@ n ' ' optional
1228 branch operand 0 -1 ' ' -1
1230 -(Rn) 7 n ' ' optional
1231 {@}(Rn)+ 8+@ n ' ' optional
1232 {@}#foo, no S^ 8+@ PC " i" optional
1233 {@}{q^}{(Rn)} 10+@+q option " bwl" optional */
1235 /* Dissect user-input 'optext' (which is something like "@B^foo@bar(AP)[FP]:")
1236 using the vop in vopP. vopP's vop_access and vop_width. We fill _ndx, _reg,
1237 _mode, _short, _warn, _error, _expr_begin, _expr_end and _nbytes. */
1240 vip_op (char *optext
, struct vop
*vopP
)
1242 /* Track operand text forward. */
1244 /* Track operand text backward. */
1246 /* 1 if leading '@' ('*') seen. */
1248 /* one of " bilsw" */
1250 /* 1 if leading '#' ('$') seen. */
1254 /* 1 if () surround register. */
1256 /* Register number, -1:absent. */
1258 /* Index register number -1:absent. */
1260 /* Report illegal operand, ""==OK. */
1261 /* " " is a FAKE error: means we won. */
1262 /* ANY err that begins with ' ' is a fake. */
1263 /* " " is converted to "" before return. */
1265 /* Warn about weird modes pf address. */
1267 /* Preserve q in case we backup. */
1269 /* Build up 4-bit operand mode here. */
1270 /* Note: index mode is in ndx, this is. */
1271 /* The major mode of operand address. */
1273 /* Notice how we move wrong-arg-type bugs INSIDE this module: if we
1274 get the types wrong below, we lose at compile time rather than at
1275 lint or run time. */
1276 char access_mode
; /* vop_access. */
1277 char width
; /* vop_width. */
1279 access_mode
= vopP
->vop_access
;
1280 width
= vopP
->vop_width
;
1281 /* None of our code bugs (yet), no user text errors, no warnings
1287 if (*p
== ' ') /* Expect all whitespace reduced to ' '. */
1288 p
++; /* skip over whitespace */
1290 if ((at
= INDIRECTP (*p
)) != 0)
1291 { /* 1 if *p=='@'(or '*' for Un*x) */
1292 p
++; /* at is determined */
1293 if (*p
== ' ') /* Expect all whitespace reduced to ' '. */
1294 p
++; /* skip over whitespace */
1297 /* This code is subtle. It tries to detect all legal (letter)'^'
1298 but it doesn't waste time explicitly testing for premature '\0' because
1299 this case is rejected as a mismatch against either (letter) or '^'. */
1305 if (DISPLENP (p
[1]) && strchr ("bilws", len
= c
))
1306 p
+= 2; /* Skip (letter) '^'. */
1307 else /* No (letter) '^' seen. */
1308 len
= ' '; /* Len is determined. */
1311 if (*p
== ' ') /* Expect all whitespace reduced to ' '. */
1314 if ((hash
= IMMEDIATEP (*p
)) != 0) /* 1 if *p=='#' ('$' for Un*x) */
1315 p
++; /* Hash is determined. */
1317 /* p points to what may be the beginning of an expression.
1318 We have peeled off the front all that is peelable.
1319 We know at, len, hash.
1321 Lets point q at the end of the text and parse that (backwards). */
1323 for (q
= p
; *q
; q
++)
1325 q
--; /* Now q points at last char of text. */
1327 if (*q
== ' ' && q
>= p
) /* Expect all whitespace reduced to ' '. */
1330 /* Reverse over whitespace, but don't. */
1331 /* Run back over *p. */
1333 /* As a matter of policy here, we look for [Rn], although both Rn and S^#
1334 forbid [Rn]. This is because it is easy, and because only a sick
1335 cyborg would have [...] trailing an expression in a VAX-like assembler.
1336 A meticulous parser would first check for Rn followed by '(' or '['
1337 and not parse a trailing ']' if it found another. We just ban expressions
1341 while (q
>= p
&& *q
!= '[')
1343 /* Either q<p or we got matching '['. */
1345 err
= _("no '[' to match ']'");
1348 /* Confusers like "[]" will eventually lose with a bad register
1349 * name error. So again we don't need to check for early '\0'. */
1351 ndx
= vax_reg_parse (q
[1], q
[2], 0, 0);
1352 else if (q
[4] == ']')
1353 ndx
= vax_reg_parse (q
[1], q
[2], q
[3], 0);
1354 else if (q
[5] == ']')
1355 ndx
= vax_reg_parse (q
[1], q
[2], q
[3], q
[4]);
1358 /* Since we saw a ']' we will demand a register name in the [].
1359 * If luser hasn't given us one: be rude. */
1361 err
= _("bad register in []");
1363 err
= _("[PC] index banned");
1365 /* Point q just before "[...]". */
1370 /* No ']', so no iNDeX register. */
1373 /* If err = "..." then we lost: run away.
1374 Otherwise ndx == -1 if there was no "[...]".
1375 Otherwise, ndx is index register number, and q points before "[...]". */
1377 if (*q
== ' ' && q
>= p
) /* Expect all whitespace reduced to ' '. */
1379 /* Reverse over whitespace, but don't. */
1380 /* Run back over *p. */
1383 /* no ()+ or -() seen yet */
1386 if (q
> p
+ 3 && *q
== '+' && q
[-1] == ')')
1388 sign
= 1; /* we saw a ")+" */
1389 q
--; /* q points to ')' */
1392 if (*q
== ')' && q
> p
+ 2)
1394 paren
= 1; /* assume we have "(...)" */
1395 while (q
>= p
&& *q
!= '(')
1397 /* either q<p or we got matching '(' */
1399 err
= _("no '(' to match ')'");
1402 /* Confusers like "()" will eventually lose with a bad register
1403 name error. So again we don't need to check for early '\0'. */
1405 reg
= vax_reg_parse (q
[1], q
[2], 0, 0);
1406 else if (q
[4] == ')')
1407 reg
= vax_reg_parse (q
[1], q
[2], q
[3], 0);
1408 else if (q
[5] == ')')
1409 reg
= vax_reg_parse (q
[1], q
[2], q
[3], q
[4]);
1412 /* Since we saw a ')' we will demand a register name in the ')'.
1413 This is nasty: why can't our hypothetical assembler permit
1414 parenthesised expressions? BECAUSE I AM LAZY! That is why.
1415 Abuse luser if we didn't spy a register name. */
1418 /* JF allow parenthesized expressions. I hope this works. */
1422 /* err = "unknown register in ()"; */
1425 q
--; /* point just before '(' of "(...)" */
1426 /* If err == "..." then we lost. Run away.
1427 Otherwise if reg >= 0 then we saw (Rn). */
1429 /* If err == "..." then we lost.
1430 Otherwise paren==1 and reg = register in "()". */
1434 /* If err == "..." then we lost.
1435 Otherwise, q points just before "(Rn)", if any.
1436 If there was a "(...)" then paren==1, and reg is the register. */
1438 /* We should only seek '-' of "-(...)" if:
1439 we saw "(...)" paren == 1
1440 we have no errors so far ! *err
1441 we did not see '+' of "(...)+" sign < 1
1442 We don't check len. We want a specific error message later if
1443 user tries "x^...-(Rn)". This is a feature not a bug. */
1446 if (paren
&& sign
< 1)/* !sign is adequate test */
1454 /* We have back-tracked over most
1455 of the crud at the end of an operand.
1456 Unless err, we know: sign, paren. If paren, we know reg.
1457 The last case is of an expression "Rn".
1458 This is worth hunting for if !err, !paren.
1459 We wouldn't be here if err.
1460 We remember to save q, in case we didn't want "Rn" anyway. */
1463 if (*q
== ' ' && q
>= p
) /* Expect all whitespace reduced to ' '. */
1465 /* Reverse over whitespace, but don't. */
1466 /* Run back over *p. */
1467 /* Room for Rn or Rnn (include prefix) exactly? */
1468 if (q
> p
&& q
< p
+ 4)
1469 reg
= vax_reg_parse (p
[0], p
[1],
1470 q
< p
+ 2 ? 0 : p
[2],
1471 q
< p
+ 3 ? 0 : p
[3]);
1473 reg
= -1; /* Always comes here if no register at all. */
1474 /* Here with a definitive reg value. */
1483 /* have reg. -1:absent; else 0:15. */
1485 /* We have: err, at, len, hash, ndx, sign, paren, reg.
1486 Also, any remaining expression is from *p through *q inclusive.
1487 Should there be no expression, q==p-1. So expression length = q-p+1.
1488 This completes the first part: parsing the operand text. */
1490 /* We now want to boil the data down, checking consistency on the way.
1491 We want: len, mode, reg, ndx, err, p, q, wrn, bug.
1492 We will deliver a 4-bit reg, and a 4-bit mode. */
1494 /* Case of branch operand. Different. No L^B^W^I^S^ allowed for instance.
1508 p:q whatever was input
1510 err " " or error message, and other outputs trashed. */
1511 /* Branch operands have restricted forms. */
1512 if ((!err
|| !*err
) && access_mode
== 'b')
1514 if (at
|| hash
|| sign
|| paren
|| ndx
>= 0 || reg
>= 0 || len
!= ' ')
1515 err
= _("invalid branch operand");
1520 /* Since nobody seems to use it: comment this 'feature'(?) out for now. */
1522 /* Case of stand-alone operand. e.g. ".long foo"
1536 p:q whatever was input
1538 err " " or error message, and other outputs trashed. */
1539 if ((!err
|| !*err
) && access_mode
== ' ')
1542 err
= _("address prohibits @");
1544 err
= _("address prohibits #");
1548 err
= _("address prohibits -()");
1550 err
= _("address prohibits ()+");
1553 err
= _("address prohibits ()");
1555 err
= _("address prohibits []");
1557 err
= _("address prohibits register");
1558 else if (len
!= ' ')
1559 err
= _("address prohibits displacement length specifier");
1562 err
= " "; /* succeed */
1573 p:q demand not empty
1575 paren 0 by "()" scan logic because "S^" seen
1576 reg -1 or nn by mistake
1584 if ((!err
|| !*err
) && len
== 's')
1586 if (!hash
|| paren
|| at
|| ndx
>= 0)
1587 err
= _("invalid operand of S^#");
1592 /* Darn! we saw S^#Rnn ! put the Rnn back in
1593 expression. KLUDGE! Use oldq so we don't
1594 need to know exact length of reg name. */
1598 /* We have all the expression we will ever get. */
1600 err
= _("S^# needs expression");
1601 else if (access_mode
== 'r')
1603 err
= " "; /* WIN! */
1607 err
= _("S^# may only read-access");
1611 /* Case of -(Rn), which is weird case.
1617 sign -1 by definition
1618 paren 1 by definition
1619 reg present by definition
1625 exp "" enforce empty expression
1626 ndx optional warn if same as reg. */
1627 if ((!err
|| !*err
) && sign
< 0)
1629 if (len
!= ' ' || hash
|| at
|| p
<= q
)
1630 err
= _("invalid operand of -()");
1633 err
= " "; /* win */
1636 wrn
= _("-(PC) unpredictable");
1637 else if (reg
== ndx
)
1638 wrn
= _("[]index same as -()register: unpredictable");
1642 /* We convert "(Rn)" to "@Rn" for our convenience.
1643 (I hope this is convenient: has someone got a better way to parse this?)
1644 A side-effect of this is that "@Rn" is a valid operand. */
1645 if (paren
&& !sign
&& !hash
&& !at
&& len
== ' ' && p
> q
)
1651 /* Case of (Rn)+, which is slightly different.
1657 sign +1 by definition
1658 paren 1 by definition
1659 reg present by definition
1665 exp "" enforce empty expression
1666 ndx optional warn if same as reg. */
1667 if ((!err
|| !*err
) && sign
> 0)
1669 if (len
!= ' ' || hash
|| p
<= q
)
1670 err
= _("invalid operand of ()+");
1673 err
= " "; /* win */
1674 mode
= 8 + (at
? 1 : 0);
1676 wrn
= _("(PC)+ unpredictable");
1677 else if (reg
== ndx
)
1678 wrn
= _("[]index same as ()+register: unpredictable");
1682 /* Case of #, without S^.
1686 hash 1 by definition
1698 if ((!err
|| !*err
) && hash
)
1700 if (len
!= 'i' && len
!= ' ')
1701 err
= _("# conflicts length");
1703 err
= _("# bars register");
1708 /* Darn! we saw #Rnn! Put the Rnn back into the expression.
1709 By using oldq, we don't need to know how long Rnn was.
1712 reg
= -1; /* No register any more. */
1714 err
= " "; /* Win. */
1716 /* JF a bugfix, I think! */
1717 if (at
&& access_mode
== 'a')
1718 vopP
->vop_nbytes
= 4;
1720 mode
= (at
? 9 : 8);
1722 if ((access_mode
== 'm' || access_mode
== 'w') && !at
)
1723 wrn
= _("writing or modifying # is unpredictable");
1726 /* If !*err, then sign == 0
1729 /* Case of Rn. We separate this one because it has a few special
1730 errors the remaining modes lack.
1734 hash 0 by program logic
1736 sign 0 by program logic
1737 paren 0 by definition
1738 reg present by definition
1743 len ' ' enforce no length
1744 exp "" enforce empty expression
1745 ndx optional warn if same as reg. */
1746 if ((!err
|| !*err
) && !paren
&& reg
>= 0)
1749 err
= _("length not needed");
1752 err
= " "; /* win */
1756 err
= _("can't []index a register, because it has no address");
1757 else if (access_mode
== 'a')
1758 err
= _("a register has no address");
1761 /* Idea here is to detect from length of datum
1762 and from register number if we will touch PC.
1764 vop_nbytes is number of bytes in operand.
1765 Compute highest byte affected, compare to PC0. */
1766 if ((vopP
->vop_nbytes
+ reg
* 4) > 60)
1767 wrn
= _("PC part of operand unpredictable");
1768 err
= " "; /* win */
1772 /* If !*err, sign == 0
1774 paren == 1 OR reg==-1 */
1776 /* Rest of cases fit into one bunch.
1779 len ' ' or 'b' or 'w' or 'l'
1780 hash 0 by program logic
1781 p:q expected (empty is not an error)
1782 sign 0 by program logic
1787 out: mode 10 + @ + len
1789 len ' ' or 'b' or 'w' or 'l'
1791 ndx optional warn if same as reg. */
1794 err
= " "; /* win (always) */
1795 mode
= 10 + (at
? 1 : 0);
1802 case ' ': /* Assumed B^ until our caller changes it. */
1808 /* here with completely specified mode
1815 err
= 0; /* " " is no longer an error. */
1817 vopP
->vop_mode
= mode
;
1818 vopP
->vop_reg
= reg
;
1819 vopP
->vop_short
= len
;
1820 vopP
->vop_expr_begin
= p
;
1821 vopP
->vop_expr_end
= q
;
1822 vopP
->vop_ndx
= ndx
;
1823 vopP
->vop_error
= err
;
1824 vopP
->vop_warn
= wrn
;
1827 /* This converts a string into a vax instruction.
1828 The string must be a bare single instruction in dec-vax (with BSD4 frobs)
1830 It provides some error messages: at most one fatal error message (which
1831 stops the scan) and at most one warning message for each operand.
1832 The vax instruction is returned in exploded form, since we have no
1833 knowledge of how you parse (or evaluate) your expressions.
1834 We do however strip off and decode addressing modes and operation
1837 The exploded instruction is returned to a struct vit of your choice.
1838 #include "vax-inst.h" to know what a struct vit is.
1840 This function's value is a string. If it is not "" then an internal
1841 logic error was found: read this code to assign meaning to the string.
1842 No argument string should generate such an error string:
1843 it means a bug in our code, not in the user's text.
1845 You MUST have called vip_begin() once before using this function. */
1848 vip (struct vit
*vitP
, /* We build an exploded instruction here. */
1849 char *instring
) /* Text of a vax instruction: we modify. */
1851 /* How to bit-encode this opcode. */
1852 struct vot_wot
*vwP
;
1853 /* 1/skip whitespace.2/scan vot_how */
1856 /* counts number of operands seen */
1857 unsigned char count
;
1858 /* scan operands in struct vit */
1859 struct vop
*operandp
;
1860 /* error over all operands */
1861 const char *alloperr
;
1862 /* Remember char, (we clobber it with '\0' temporarily). */
1864 /* Op-code of this instruction. */
1867 if (*instring
== ' ')
1870 /* MUST end in end-of-string or exactly 1 space. */
1871 for (p
= instring
; *p
&& *p
!= ' '; p
++)
1874 /* Scanned up to end of operation-code. */
1875 /* Operation-code is ended with whitespace. */
1876 if (p
- instring
== 0)
1878 vitP
->vit_error
= _("No operator");
1880 memset (vitP
->vit_opcode
, '\0', sizeof (vitP
->vit_opcode
));
1886 /* Here with instring pointing to what better be an op-name, and p
1887 pointing to character just past that.
1888 We trust instring points to an op-name, with no whitespace. */
1889 vwP
= (struct vot_wot
*) hash_find (op_hash
, instring
);
1890 /* Restore char after op-code. */
1894 vitP
->vit_error
= _("Unknown operator");
1896 memset (vitP
->vit_opcode
, '\0', sizeof (vitP
->vit_opcode
));
1900 /* We found a match! So let's pick up as many operands as the
1901 instruction wants, and even gripe if there are too many.
1902 We expect comma to separate each operand.
1903 We let instring track the text, while p tracks a part of the
1906 /* The lines below know about 2-byte opcodes starting FD,FE or FF.
1907 They also understand synthetic opcodes. Note:
1908 we return 32 bits of opcode, including bucky bits, BUT
1909 an opcode length is either 8 or 16 bits for vit_opcode_nbytes. */
1910 oc
= vwP
->vot_code
; /* The op-code. */
1911 vitP
->vit_opcode_nbytes
= (oc
& 0xFF) >= 0xFD ? 2 : 1;
1912 md_number_to_chars (vitP
->vit_opcode
, oc
, 4);
1913 count
= 0; /* No operands seen yet. */
1914 instring
= p
; /* Point just past operation code. */
1916 for (howp
= vwP
->vot_how
, operandp
= vitP
->vit_operand
;
1917 !(alloperr
&& *alloperr
) && *howp
;
1918 operandp
++, howp
+= 2)
1920 /* Here to parse one operand. Leave instring pointing just
1921 past any one ',' that marks the end of this operand. */
1923 as_fatal (_("odd number of bytes in operand description"));
1926 for (q
= instring
; (c
= *q
) && c
!= ','; q
++)
1928 /* Q points to ',' or '\0' that ends argument. C is that
1931 operandp
->vop_width
= howp
[1];
1932 operandp
->vop_nbytes
= vax_operand_width_size
[(unsigned) howp
[1]];
1933 operandp
->vop_access
= howp
[0];
1934 vip_op (instring
, operandp
);
1935 *q
= c
; /* Restore input text. */
1936 if (operandp
->vop_error
)
1937 alloperr
= _("Bad operand");
1938 instring
= q
+ (c
? 1 : 0); /* Next operand (if any). */
1939 count
++; /* Won another argument, may have an operr. */
1942 alloperr
= _("Not enough operands");
1946 if (*instring
== ' ')
1949 alloperr
= _("Too many operands");
1951 vitP
->vit_error
= alloperr
;
1954 vitP
->vit_operands
= count
;
1959 /* Test program for above. */
1961 struct vit myvit
; /* Build an exploded vax instruction here. */
1962 char answer
[100]; /* Human types a line of vax assembler here. */
1963 char *mybug
; /* "" or an internal logic diagnostic. */
1964 int mycount
; /* Number of operands. */
1965 struct vop
*myvop
; /* Scan operands from myvit. */
1966 int mysynth
; /* 1 means want synthetic opcodes. */
1967 char my_immediate
[200];
1968 char my_indirect
[200];
1969 char my_displen
[200];
1976 printf ("0 means no synthetic instructions. ");
1977 printf ("Value for vip_begin? ");
1979 sscanf (answer
, "%d", &mysynth
);
1980 printf ("Synthetic opcodes %s be included.\n", mysynth
? "will" : "will not");
1981 printf ("enter immediate symbols eg enter # ");
1982 gets (my_immediate
);
1983 printf ("enter indirect symbols eg enter @ ");
1985 printf ("enter displen symbols eg enter ^ ");
1988 if (p
= vip_begin (mysynth
, my_immediate
, my_indirect
, my_displen
))
1989 error ("vip_begin=%s", p
);
1991 printf ("An empty input line will quit you from the vax instruction parser\n");
1994 printf ("vax instruction: ");
1998 break; /* Out of for each input text loop. */
2000 vip (& myvit
, answer
);
2001 if (*myvit
.vit_error
)
2002 printf ("ERR:\"%s\"\n", myvit
.vit_error
);
2005 for (mycount
= myvit
.vit_opcode_nbytes
, p
= myvit
.vit_opcode
;
2008 printf ("%02x ", *p
& 0xFF);
2010 printf (" operand count=%d.\n", mycount
= myvit
.vit_operands
);
2011 for (myvop
= myvit
.vit_operand
; mycount
; mycount
--, myvop
++)
2013 printf ("mode=%xx reg=%xx ndx=%xx len='%c'=%c%c%d. expr=\"",
2014 myvop
->vop_mode
, myvop
->vop_reg
, myvop
->vop_ndx
,
2015 myvop
->vop_short
, myvop
->vop_access
, myvop
->vop_width
,
2017 for (p
= myvop
->vop_expr_begin
; p
<= myvop
->vop_expr_end
; p
++)
2021 if (myvop
->vop_error
)
2022 printf (" err:\"%s\"\n", myvop
->vop_error
);
2024 if (myvop
->vop_warn
)
2025 printf (" wrn:\"%s\"\n", myvop
->vop_warn
);
2029 exit (EXIT_SUCCESS
);
2034 #ifdef TEST /* #Define to use this testbed. */
2036 /* Follows a test program for this function.
2037 We declare arrays non-local in case some of our tiny-minded machines
2038 default to small stacks. Also, helps with some debuggers. */
2040 char answer
[100]; /* Human types into here. */
2053 int my_operand_length
;
2054 char my_immediate
[200];
2055 char my_indirect
[200];
2056 char my_displen
[200];
2061 printf ("enter immediate symbols eg enter # ");
2062 gets (my_immediate
);
2063 printf ("enter indirect symbols eg enter @ ");
2065 printf ("enter displen symbols eg enter ^ ");
2067 vip_op_defaults (my_immediate
, my_indirect
, my_displen
);
2071 printf ("access,width (eg 'ab' or 'wh') [empty line to quit] : ");
2075 exit (EXIT_SUCCESS
);
2076 myaccess
= answer
[0];
2077 mywidth
= answer
[1];
2081 my_operand_length
= 1;
2084 my_operand_length
= 8;
2087 my_operand_length
= 4;
2090 my_operand_length
= 16;
2093 my_operand_length
= 32;
2096 my_operand_length
= 4;
2099 my_operand_length
= 16;
2102 my_operand_length
= 8;
2105 my_operand_length
= 2;
2110 my_operand_length
= 0;
2114 my_operand_length
= 2;
2115 printf ("I dn't understand access width %c\n", mywidth
);
2118 printf ("VAX assembler instruction operand: ");
2121 mybug
= vip_op (answer
, myaccess
, mywidth
, my_operand_length
,
2122 &mymode
, &myreg
, &mylen
, &myleft
, &myright
, &myndx
,
2126 printf ("error: \"%s\"\n", myerr
);
2128 printf (" bug: \"%s\"\n", mybug
);
2133 printf ("warning: \"%s\"\n", mywrn
);
2134 mumble ("mode", mymode
);
2135 mumble ("register", myreg
);
2136 mumble ("index", myndx
);
2137 printf ("width:'%c' ", mylen
);
2138 printf ("expression: \"");
2139 while (myleft
<= myright
)
2140 putchar (*myleft
++);
2147 mumble (char *text
, int value
)
2149 printf ("%s:", text
);
2151 printf ("%xx", value
);
2159 int md_short_jump_size
= 3;
2160 int md_long_jump_size
= 6;
2163 md_create_short_jump (char *ptr
,
2165 addressT to_addr ATTRIBUTE_UNUSED
,
2166 fragS
*frag ATTRIBUTE_UNUSED
,
2167 symbolS
*to_symbol ATTRIBUTE_UNUSED
)
2171 /* This former calculation was off by two:
2172 offset = to_addr - (from_addr + 1);
2173 We need to account for the one byte instruction and also its
2174 two byte operand. */
2175 offset
= to_addr
- (from_addr
+ 1 + 2);
2176 *ptr
++ = VAX_BRW
; /* Branch with word (16 bit) offset. */
2177 md_number_to_chars (ptr
, offset
, 2);
2181 md_create_long_jump (char *ptr
,
2182 addressT from_addr ATTRIBUTE_UNUSED
,
2189 offset
= to_addr
- S_GET_VALUE (to_symbol
);
2190 *ptr
++ = VAX_JMP
; /* Arbitrary jump. */
2191 *ptr
++ = VAX_ABSOLUTE_MODE
;
2192 md_number_to_chars (ptr
, offset
, 4);
2193 fix_new (frag
, ptr
- frag
->fr_literal
, 4, to_symbol
, (long) 0, 0, NO_RELOC
);
2197 const char *md_shortopts
= "d:STt:V+1h:Hv::";
2198 #elif defined(OBJ_ELF)
2199 const char *md_shortopts
= "d:STt:VkKQ:";
2201 const char *md_shortopts
= "d:STt:V";
2203 struct option md_longopts
[] =
2206 #define OPTION_PIC (OPTION_MD_BASE)
2207 { "pic", no_argument
, NULL
, OPTION_PIC
},
2209 { NULL
, no_argument
, NULL
, 0 }
2211 size_t md_longopts_size
= sizeof (md_longopts
);
2214 md_parse_option (int c
, char *arg
)
2219 as_warn (_("SYMBOL TABLE not implemented"));
2223 as_warn (_("TOKEN TRACE not implemented"));
2227 as_warn (_("Displacement length %s ignored!"), arg
);
2231 as_warn (_("I don't need or use temp. file \"%s\"."), arg
);
2235 as_warn (_("I don't use an interpass file! -V ignored"));
2239 case '+': /* For g++. Hash any name > 31 chars long. */
2240 flag_hash_long_names
= 1;
2243 case '1': /* For backward compatibility. */
2247 case 'H': /* Show new symbol after hash truncation. */
2248 flag_show_after_trunc
= 1;
2251 case 'h': /* No hashing of mixed-case names. */
2253 extern char vms_name_mapping
;
2254 vms_name_mapping
= atoi (arg
);
2255 flag_no_hash_mixed_case
= 1;
2261 extern char *compiler_version_string
;
2263 if (!arg
|| !*arg
|| access (arg
, 0) == 0)
2264 return 0; /* Have caller show the assembler version. */
2265 compiler_version_string
= arg
;
2274 break; /* -pic, Position Independent Code. */
2276 /* -Qy, -Qn: SVR4 arguments controlling whether a .comment
2277 section should be emitted or not. FIXME: Not implemented. */
2290 md_show_usage (FILE *stream
)
2292 fprintf (stream
, _("\
2294 -d LENGTH ignored\n\
2301 fprintf (stream
, _("\
2303 -+ hash encode names longer than 31 characters\n\
2304 -1 `const' handling compatible with gcc 1.x\n\
2305 -H show new symbol after hash truncation\n\
2306 -h NUM don't hash mixed-case names, and adjust case:\n\
2307 0 = upper, 2 = lower, 3 = preserve case\n\
2308 -v\"VERSION\" code being assembled was produced by compiler \"VERSION\"\n"));
2312 /* We have no need to default values of symbols. */
2315 md_undefined_symbol (char *name ATTRIBUTE_UNUSED
)
2320 /* Round up a section size to the appropriate boundary. */
2322 md_section_align (segT segment ATTRIBUTE_UNUSED
, valueT size
)
2324 /* Byte alignment is fine */
2328 /* Exactly what point is a PC-relative offset relative TO?
2329 On the vax, they're relative to the address of the offset, plus
2332 md_pcrel_from (fixS
*fixP
)
2334 return fixP
->fx_size
+ fixP
->fx_where
+ fixP
->fx_frag
->fr_address
;
2338 tc_gen_reloc (asection
*section ATTRIBUTE_UNUSED
, fixS
*fixp
)
2341 bfd_reloc_code_real_type code
;
2346 if (fixp
->fx_r_type
!= BFD_RELOC_NONE
)
2348 code
= fixp
->fx_r_type
;
2354 case BFD_RELOC_8_PCREL
:
2355 case BFD_RELOC_16_PCREL
:
2356 case BFD_RELOC_32_PCREL
:
2358 case BFD_RELOC_8_GOT_PCREL
:
2359 case BFD_RELOC_16_GOT_PCREL
:
2360 case BFD_RELOC_32_GOT_PCREL
:
2361 case BFD_RELOC_8_PLT_PCREL
:
2362 case BFD_RELOC_16_PLT_PCREL
:
2363 case BFD_RELOC_32_PLT_PCREL
:
2367 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
2368 _("Cannot make %s relocation PC relative"),
2369 bfd_get_reloc_code_name (code
));
2375 #define F(SZ,PCREL) (((SZ) << 1) + (PCREL))
2376 switch (F (fixp
->fx_size
, fixp
->fx_pcrel
))
2378 #define MAP(SZ,PCREL,TYPE) case F(SZ,PCREL): code = (TYPE); break
2379 MAP (1, 0, BFD_RELOC_8
);
2380 MAP (2, 0, BFD_RELOC_16
);
2381 MAP (4, 0, BFD_RELOC_32
);
2382 MAP (1, 1, BFD_RELOC_8_PCREL
);
2383 MAP (2, 1, BFD_RELOC_16_PCREL
);
2384 MAP (4, 1, BFD_RELOC_32_PCREL
);
2392 reloc
= xmalloc (sizeof (arelent
));
2393 reloc
->sym_ptr_ptr
= xmalloc (sizeof (asymbol
*));
2394 *reloc
->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
2395 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
2398 reloc
->addend
= fixp
->fx_addnumber
;
2402 reloc
->addend
= fixp
->fx_offset
;
2405 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
2406 assert (reloc
->howto
!= 0);
2411 /* vax:md_assemble() emit frags for 1 instruction given in textual form. */
2413 md_assemble (char *instruction_string
)
2415 /* Non-zero if operand expression's segment is not known yet. */
2417 /* Non-zero if operand expression's segment is absolute. */
2421 /* An operand. Scans all operands. */
2422 struct vop
*operandP
;
2423 char *save_input_line_pointer
;
2424 /* What used to live after an expression. */
2426 /* 1: instruction_string bad for all passes. */
2428 /* Points to slot just after last operand. */
2429 struct vop
*end_operandP
;
2430 /* Points to expression values for this operand. */
2434 /* These refer to an instruction operand expression. */
2435 /* Target segment of the address. */
2437 valueT this_add_number
;
2438 /* Positive (minuend) symbol. */
2439 symbolS
*this_add_symbol
;
2441 long opcode_as_number
;
2442 /* Least significant byte 1st. */
2443 char *opcode_as_chars
;
2444 /* As an array of characters. */
2445 /* Least significant byte 1st */
2446 char *opcode_low_byteP
;
2447 /* length (bytes) meant by vop_short. */
2449 /* 0, or 1 if '@' is in addressing mode. */
2451 /* From vop_nbytes: vax_operand_width (in bytes) */
2453 FLONUM_TYPE
*floatP
;
2454 LITTLENUM_TYPE literal_float
[8];
2455 /* Big enough for any floating point literal. */
2457 vip (&v
, instruction_string
);
2459 /* Now we try to find as many as_warn()s as we can. If we do any as_warn()s
2460 then goofed=1. Notice that we don't make any frags yet.
2461 Should goofed be 1, then this instruction will wedge in any pass,
2462 and we can safely flush it, without causing interpass symbol phase
2463 errors. That is, without changing label values in different passes. */
2464 if ((goofed
= (*v
.vit_error
)) != 0)
2466 as_fatal (_("Ignoring statement due to \"%s\""), v
.vit_error
);
2468 /* We need to use expression() and friends, which require us to diddle
2469 input_line_pointer. So we save it and restore it later. */
2470 save_input_line_pointer
= input_line_pointer
;
2471 for (operandP
= v
.vit_operand
,
2472 expP
= exp_of_operand
,
2473 segP
= seg_of_operand
,
2474 floatP
= float_operand
,
2475 end_operandP
= v
.vit_operand
+ v
.vit_operands
;
2477 operandP
< end_operandP
;
2479 operandP
++, expP
++, segP
++, floatP
++)
2481 if (operandP
->vop_error
)
2483 as_fatal (_("Aborting because statement has \"%s\""), operandP
->vop_error
);
2488 /* Statement has no syntax goofs: let's sniff the expression. */
2489 int can_be_short
= 0; /* 1 if a bignum can be reduced to a short literal. */
2491 input_line_pointer
= operandP
->vop_expr_begin
;
2492 c_save
= operandP
->vop_expr_end
[1];
2493 operandP
->vop_expr_end
[1] = '\0';
2494 /* If to_seg == SEG_PASS1, expression() will have set need_pass_2 = 1. */
2495 *segP
= expression (expP
);
2499 /* for BSD4.2 compatibility, missing expression is absolute 0 */
2500 expP
->X_op
= O_constant
;
2501 expP
->X_add_number
= 0;
2502 /* For SEG_ABSOLUTE, we shouldn't need to set X_op_symbol,
2503 X_add_symbol to any particular value. But, we will program
2504 defensively. Since this situation occurs rarely so it costs
2505 us little to do, and stops Dean worrying about the origin of
2506 random bits in expressionS's. */
2507 expP
->X_add_symbol
= NULL
;
2508 expP
->X_op_symbol
= NULL
;
2516 /* Major bug. We can't handle the case of a
2517 SEG_OP expression in a VIT_OPCODE_SYNTHETIC
2518 variable-length instruction.
2519 We don't have a frag type that is smart enough to
2520 relax a SEG_OP, and so we just force all
2521 SEG_OPs to behave like SEG_PASS1s.
2522 Clearly, if there is a demand we can invent a new or
2523 modified frag type and then coding up a frag for this
2524 case will be easy. SEG_OP was invented for the
2525 .words after a CASE opcode, and was never intended for
2526 instruction operands. */
2528 as_fatal (_("Can't relocate expression"));
2532 /* Preserve the bits. */
2533 if (expP
->X_add_number
> 0)
2535 bignum_copy (generic_bignum
, expP
->X_add_number
,
2536 floatP
->low
, SIZE_OF_LARGE_NUMBER
);
2540 know (expP
->X_add_number
< 0);
2541 flonum_copy (&generic_floating_point_number
,
2543 if (strchr ("s i", operandP
->vop_short
))
2545 /* Could possibly become S^# */
2546 flonum_gen2vax (-expP
->X_add_number
, floatP
, literal_float
);
2547 switch (-expP
->X_add_number
)
2551 (literal_float
[0] & 0xFC0F) == 0x4000
2552 && literal_float
[1] == 0;
2557 (literal_float
[0] & 0xFC0F) == 0x4000
2558 && literal_float
[1] == 0
2559 && literal_float
[2] == 0
2560 && literal_float
[3] == 0;
2565 (literal_float
[0] & 0xFF81) == 0x4000
2566 && literal_float
[1] == 0
2567 && literal_float
[2] == 0
2568 && literal_float
[3] == 0;
2572 can_be_short
= ((literal_float
[0] & 0xFFF8) == 0x4000
2573 && (literal_float
[1] & 0xE000) == 0
2574 && literal_float
[2] == 0
2575 && literal_float
[3] == 0
2576 && literal_float
[4] == 0
2577 && literal_float
[5] == 0
2578 && literal_float
[6] == 0
2579 && literal_float
[7] == 0);
2583 BAD_CASE (-expP
->X_add_number
);
2589 if (operandP
->vop_short
== 's'
2590 || operandP
->vop_short
== 'i'
2591 || (operandP
->vop_short
== ' '
2592 && operandP
->vop_reg
== 0xF
2593 && (operandP
->vop_mode
& 0xE) == 0x8))
2596 if (operandP
->vop_short
== ' ')
2598 /* We must chose S^ or I^. */
2599 if (expP
->X_add_number
> 0)
2601 /* Bignum: Short literal impossible. */
2602 operandP
->vop_short
= 'i';
2603 operandP
->vop_mode
= 8;
2604 operandP
->vop_reg
= 0xF; /* VAX PC. */
2608 /* Flonum: Try to do it. */
2611 operandP
->vop_short
= 's';
2612 operandP
->vop_mode
= 0;
2613 operandP
->vop_ndx
= -1;
2614 operandP
->vop_reg
= -1;
2615 expP
->X_op
= O_constant
;
2619 operandP
->vop_short
= 'i';
2620 operandP
->vop_mode
= 8;
2621 operandP
->vop_reg
= 0xF; /* VAX PC */
2623 } /* bignum or flonum ? */
2624 } /* if #, but no S^ or I^ seen. */
2625 /* No more ' ' case: either 's' or 'i'. */
2626 if (operandP
->vop_short
== 's')
2628 /* Wants to be a short literal. */
2629 if (expP
->X_add_number
> 0)
2631 as_warn (_("Bignum not permitted in short literal. Immediate mode assumed."));
2632 operandP
->vop_short
= 'i';
2633 operandP
->vop_mode
= 8;
2634 operandP
->vop_reg
= 0xF; /* VAX PC. */
2640 as_warn (_("Can't do flonum short literal: immediate mode used."));
2641 operandP
->vop_short
= 'i';
2642 operandP
->vop_mode
= 8;
2643 operandP
->vop_reg
= 0xF; /* VAX PC. */
2647 /* Encode short literal now. */
2650 switch (-expP
->X_add_number
)
2654 temp
= literal_float
[0] >> 4;
2658 temp
= literal_float
[0] >> 1;
2662 temp
= ((literal_float
[0] << 3) & 070)
2663 | ((literal_float
[1] >> 13) & 07);
2667 BAD_CASE (-expP
->X_add_number
);
2671 floatP
->low
[0] = temp
& 077;
2678 /* I^# seen: set it up if float. */
2679 if (expP
->X_add_number
< 0)
2681 memcpy (floatP
->low
, literal_float
, sizeof (literal_float
));
2683 } /* if S^# seen. */
2687 as_warn (_("A bignum/flonum may not be a displacement: 0x%lx used"),
2688 (expP
->X_add_number
= 0x80000000L
));
2689 /* Chosen so luser gets the most offset bits to patch later. */
2691 expP
->X_add_number
= floatP
->low
[0]
2692 | ((LITTLENUM_MASK
& (floatP
->low
[1])) << LITTLENUM_NUMBER_OF_BITS
);
2694 /* For the O_big case we have:
2695 If vop_short == 's' then a short floating literal is in the
2696 lowest 6 bits of floatP -> low [0], which is
2697 big_operand_bits [---] [0].
2698 If vop_short == 'i' then the appropriate number of elements
2699 of big_operand_bits [---] [...] are set up with the correct
2701 Also, just in case width is byte word or long, we copy the lowest
2702 32 bits of the number to X_add_number. */
2705 if (input_line_pointer
!= operandP
->vop_expr_end
+ 1)
2707 as_fatal ("Junk at end of expression \"%s\"", input_line_pointer
);
2710 operandP
->vop_expr_end
[1] = c_save
;
2714 input_line_pointer
= save_input_line_pointer
;
2716 if (need_pass_2
|| goofed
)
2720 /* Remember where it is, in case we want to modify the op-code later. */
2721 opcode_low_byteP
= frag_more (v
.vit_opcode_nbytes
);
2722 memcpy (opcode_low_byteP
, v
.vit_opcode
, v
.vit_opcode_nbytes
);
2723 opcode_as_chars
= v
.vit_opcode
;
2724 opcode_as_number
= md_chars_to_number ((unsigned char *) opcode_as_chars
, 4);
2725 for (operandP
= v
.vit_operand
,
2726 expP
= exp_of_operand
,
2727 segP
= seg_of_operand
,
2728 floatP
= float_operand
,
2729 end_operandP
= v
.vit_operand
+ v
.vit_operands
;
2731 operandP
< end_operandP
;
2738 if (operandP
->vop_ndx
>= 0)
2740 /* Indexed addressing byte. */
2741 /* Legality of indexed mode already checked: it is OK. */
2742 FRAG_APPEND_1_CHAR (0x40 + operandP
->vop_ndx
);
2743 } /* if(vop_ndx>=0) */
2745 /* Here to make main operand frag(s). */
2746 this_add_number
= expP
->X_add_number
;
2747 this_add_symbol
= expP
->X_add_symbol
;
2749 is_undefined
= (to_seg
== undefined_section
);
2750 is_absolute
= (to_seg
== absolute_section
);
2751 at
= operandP
->vop_mode
& 1;
2752 length
= (operandP
->vop_short
== 'b'
2753 ? 1 : (operandP
->vop_short
== 'w'
2754 ? 2 : (operandP
->vop_short
== 'l'
2756 nbytes
= operandP
->vop_nbytes
;
2757 if (operandP
->vop_access
== 'b')
2759 if (to_seg
== now_seg
|| is_undefined
)
2761 /* If is_undefined, then it might BECOME now_seg. */
2764 p
= frag_more (nbytes
);
2765 fix_new (frag_now
, p
- frag_now
->fr_literal
, nbytes
,
2766 this_add_symbol
, this_add_number
, 1, NO_RELOC
);
2770 /* to_seg==now_seg || to_seg == SEG_UNKNOWN */
2772 length_code
= is_undefined
? STATE_UNDF
: STATE_BYTE
;
2773 if (opcode_as_number
& VIT_OPCODE_SPECIAL
)
2775 if (operandP
->vop_width
== VAX_WIDTH_UNCONDITIONAL_JUMP
)
2778 frag_var (rs_machine_dependent
, 5, 1,
2779 ENCODE_RELAX (STATE_ALWAYS_BRANCH
, length_code
),
2780 this_add_symbol
, this_add_number
,
2785 if (operandP
->vop_width
== VAX_WIDTH_WORD_JUMP
)
2787 length_code
= STATE_WORD
;
2788 /* JF: There is no state_byte for this one! */
2789 frag_var (rs_machine_dependent
, 10, 2,
2790 ENCODE_RELAX (STATE_COMPLEX_BRANCH
, length_code
),
2791 this_add_symbol
, this_add_number
,
2796 know (operandP
->vop_width
== VAX_WIDTH_BYTE_JUMP
);
2797 frag_var (rs_machine_dependent
, 9, 1,
2798 ENCODE_RELAX (STATE_COMPLEX_HOP
, length_code
),
2799 this_add_symbol
, this_add_number
,
2806 know (operandP
->vop_width
== VAX_WIDTH_CONDITIONAL_JUMP
);
2807 frag_var (rs_machine_dependent
, 7, 1,
2808 ENCODE_RELAX (STATE_CONDITIONAL_BRANCH
, length_code
),
2809 this_add_symbol
, this_add_number
,
2816 /* to_seg != now_seg && to_seg != SEG_UNKNOWN */
2817 /* --- SEG FLOAT MAY APPEAR HERE --- */
2822 know (!(opcode_as_number
& VIT_OPCODE_SYNTHETIC
));
2823 p
= frag_more (nbytes
);
2824 /* Conventional relocation. */
2825 fix_new (frag_now
, p
- frag_now
->fr_literal
, nbytes
,
2826 section_symbol (absolute_section
),
2827 this_add_number
, 1, NO_RELOC
);
2831 know (opcode_as_number
& VIT_OPCODE_SYNTHETIC
);
2832 if (opcode_as_number
& VIT_OPCODE_SPECIAL
)
2834 if (operandP
->vop_width
== VAX_WIDTH_UNCONDITIONAL_JUMP
)
2837 *opcode_low_byteP
= opcode_as_chars
[0] + VAX_WIDEN_LONG
;
2838 know (opcode_as_chars
[1] == 0);
2840 p
[0] = VAX_ABSOLUTE_MODE
; /* @#... */
2841 md_number_to_chars (p
+ 1, this_add_number
, 4);
2842 /* Now (eg) JMP @#foo or JSB @#foo. */
2846 if (operandP
->vop_width
== VAX_WIDTH_WORD_JUMP
)
2854 p
[5] = VAX_ABSOLUTE_MODE
; /* @#... */
2855 md_number_to_chars (p
+ 6, this_add_number
, 4);
2863 know (operandP
->vop_width
== VAX_WIDTH_BYTE_JUMP
);
2869 p
[4] = VAX_ABSOLUTE_MODE
; /* @#... */
2870 md_number_to_chars (p
+ 5, this_add_number
, 4);
2871 /* Now (eg) xOBxxx 1f
2881 *opcode_low_byteP
^= 1;
2882 /* To reverse the condition in a VAX branch,
2883 complement the lowest order bit. */
2887 p
[2] = VAX_ABSOLUTE_MODE
; /* @#... */
2888 md_number_to_chars (p
+ 3, this_add_number
, 4);
2897 /* to_seg != now_seg && !is_undefinfed && !is_absolute */
2900 /* Pc-relative. Conventional relocation. */
2901 know (!(opcode_as_number
& VIT_OPCODE_SYNTHETIC
));
2902 p
= frag_more (nbytes
);
2903 fix_new (frag_now
, p
- frag_now
->fr_literal
, nbytes
,
2904 section_symbol (absolute_section
),
2905 this_add_number
, 1, NO_RELOC
);
2909 know (opcode_as_number
& VIT_OPCODE_SYNTHETIC
);
2910 if (opcode_as_number
& VIT_OPCODE_SPECIAL
)
2912 if (operandP
->vop_width
== VAX_WIDTH_UNCONDITIONAL_JUMP
)
2915 know (opcode_as_chars
[1] == 0);
2916 *opcode_low_byteP
= opcode_as_chars
[0] + VAX_WIDEN_LONG
;
2918 p
[0] = VAX_PC_RELATIVE_MODE
;
2920 p
+ 1 - frag_now
->fr_literal
, 4,
2922 this_add_number
, 1, NO_RELOC
);
2923 /* Now eg JMP foo or JSB foo. */
2927 if (operandP
->vop_width
== VAX_WIDTH_WORD_JUMP
)
2935 p
[5] = VAX_PC_RELATIVE_MODE
;
2937 p
+ 6 - frag_now
->fr_literal
, 4,
2939 this_add_number
, 1, NO_RELOC
);
2947 know (operandP
->vop_width
== VAX_WIDTH_BYTE_JUMP
);
2953 p
[4] = VAX_PC_RELATIVE_MODE
;
2955 p
+ 5 - frag_now
->fr_literal
,
2957 this_add_number
, 1, NO_RELOC
);
2958 /* Now (eg) xOBxxx 1f
2967 know (operandP
->vop_width
== VAX_WIDTH_CONDITIONAL_JUMP
);
2968 *opcode_low_byteP
^= 1; /* Reverse branch condition. */
2972 p
[2] = VAX_PC_RELATIVE_MODE
;
2973 fix_new (frag_now
, p
+ 3 - frag_now
->fr_literal
,
2975 this_add_number
, 1, NO_RELOC
);
2983 /* So it is ordinary operand. */
2984 know (operandP
->vop_access
!= 'b');
2985 /* ' ' target-independent: elsewhere. */
2986 know (operandP
->vop_access
!= ' ');
2987 know (operandP
->vop_access
== 'a'
2988 || operandP
->vop_access
== 'm'
2989 || operandP
->vop_access
== 'r'
2990 || operandP
->vop_access
== 'v'
2991 || operandP
->vop_access
== 'w');
2992 if (operandP
->vop_short
== 's')
2996 if (this_add_number
>= 64)
2998 as_warn (_("Short literal overflow(%ld.), immediate mode assumed."),
2999 (long) this_add_number
);
3000 operandP
->vop_short
= 'i';
3001 operandP
->vop_mode
= 8;
3002 operandP
->vop_reg
= 0xF;
3007 as_warn (_("Forced short literal to immediate mode. now_seg=%s to_seg=%s"),
3008 segment_name (now_seg
), segment_name (to_seg
));
3009 operandP
->vop_short
= 'i';
3010 operandP
->vop_mode
= 8;
3011 operandP
->vop_reg
= 0xF;
3014 if (operandP
->vop_reg
>= 0 && (operandP
->vop_mode
< 8
3015 || (operandP
->vop_reg
!= 0xF && operandP
->vop_mode
< 10)))
3017 /* One byte operand. */
3018 know (operandP
->vop_mode
> 3);
3019 FRAG_APPEND_1_CHAR (operandP
->vop_mode
<< 4 | operandP
->vop_reg
);
3020 /* All 1-bytes except S^# happen here. */
3024 /* {@}{q^}foo{(Rn)} or S^#foo */
3025 if (operandP
->vop_reg
== -1 && operandP
->vop_short
!= 's')
3028 if (to_seg
== now_seg
)
3032 know (operandP
->vop_short
== ' ');
3033 length_code
= STATE_BYTE
;
3035 if (S_IS_EXTERNAL (this_add_symbol
)
3036 || S_IS_WEAK (this_add_symbol
))
3037 length_code
= STATE_UNDF
;
3039 p
= frag_var (rs_machine_dependent
, 10, 2,
3040 ENCODE_RELAX (STATE_PC_RELATIVE
, length_code
),
3041 this_add_symbol
, this_add_number
,
3043 know (operandP
->vop_mode
== 10 + at
);
3045 /* At is the only context we need to carry
3046 to other side of relax() process. Must
3047 be in the correct bit position of VAX
3048 operand spec. byte. */
3053 know (operandP
->vop_short
!= ' ');
3054 p
= frag_more (length
+ 1);
3055 p
[0] = 0xF | ((at
+ "?\12\14?\16"[length
]) << 4);
3056 fix_new (frag_now
, p
+ 1 - frag_now
->fr_literal
,
3057 length
, this_add_symbol
,
3058 this_add_number
, 1, NO_RELOC
);
3063 /* to_seg != now_seg */
3064 if (this_add_symbol
== NULL
)
3067 /* Do @#foo: simpler relocation than foo-.(pc) anyway. */
3069 p
[0] = VAX_ABSOLUTE_MODE
; /* @#... */
3070 md_number_to_chars (p
+ 1, this_add_number
, 4);
3071 if (length
&& length
!= 4)
3072 as_warn (_("Length specification ignored. Address mode 9F used"));
3076 /* {@}{q^}other_seg */
3077 know ((length
== 0 && operandP
->vop_short
== ' ')
3078 || (length
> 0 && operandP
->vop_short
!= ' '));
3081 || S_IS_WEAK(this_add_symbol
)
3082 || S_IS_EXTERNAL(this_add_symbol
)
3088 default: length_code
= STATE_UNDF
; break;
3089 case 1: length_code
= STATE_BYTE
; break;
3090 case 2: length_code
= STATE_WORD
; break;
3091 case 4: length_code
= STATE_LONG
; break;
3093 /* We have a SEG_UNKNOWN symbol. It might
3094 turn out to be in the same segment as
3095 the instruction, permitting relaxation. */
3096 p
= frag_var (rs_machine_dependent
, 5, 2,
3097 ENCODE_RELAX (STATE_PC_RELATIVE
, length_code
),
3098 this_add_symbol
, this_add_number
,
3106 know (operandP
->vop_short
== ' ');
3107 length
= 4; /* Longest possible. */
3109 p
= frag_more (length
+ 1);
3110 p
[0] = 0xF | ((at
+ "?\12\14?\16"[length
]) << 4);
3111 md_number_to_chars (p
+ 1, this_add_number
, length
);
3113 p
+ 1 - frag_now
->fr_literal
,
3114 length
, this_add_symbol
,
3115 this_add_number
, 1, NO_RELOC
);
3122 /* {@}{q^}foo(Rn) or S^# or I^# or # */
3123 if (operandP
->vop_mode
< 0xA)
3125 /* # or S^# or I^# */
3126 if (operandP
->vop_access
== 'v'
3127 || operandP
->vop_access
== 'a')
3129 if (operandP
->vop_access
== 'v')
3130 as_warn (_("Invalid operand: immediate value used as base address."));
3132 as_warn (_("Invalid operand: immediate value used as address."));
3133 /* gcc 2.6.3 is known to generate these in at least
3137 && is_absolute
&& (expP
->X_op
!= O_big
)
3138 && operandP
->vop_mode
== 8 /* No '@'. */
3139 && this_add_number
< 64)
3141 operandP
->vop_short
= 's';
3143 if (operandP
->vop_short
== 's')
3145 FRAG_APPEND_1_CHAR (this_add_number
);
3151 p
= frag_more (nbytes
+ 1);
3152 know (operandP
->vop_reg
== 0xF);
3154 if (flag_want_pic
&& operandP
->vop_mode
== 8
3155 && this_add_symbol
!= NULL
)
3157 as_warn (_("Symbol %s used as immediate operand in PIC mode."),
3158 S_GET_NAME (this_add_symbol
));
3161 p
[0] = (operandP
->vop_mode
<< 4) | 0xF;
3162 if ((is_absolute
) && (expP
->X_op
!= O_big
))
3164 /* If nbytes > 4, then we are scrod. We
3165 don't know if the high order bytes
3166 are to be 0xFF or 0x00. BSD4.2 & RMS
3167 say use 0x00. OK --- but this
3168 assembler needs ANOTHER rewrite to
3169 cope properly with this bug. */
3170 md_number_to_chars (p
+ 1, this_add_number
,
3171 min (sizeof (valueT
),
3173 if ((size_t) nbytes
> sizeof (valueT
))
3174 memset (p
+ 1 + sizeof (valueT
),
3175 '\0', nbytes
- sizeof (valueT
));
3179 if (expP
->X_op
== O_big
)
3181 /* Problem here is to get the bytes
3182 in the right order. We stored
3183 our constant as LITTLENUMs, not
3195 for (p
++; nbytes
; nbytes
-= 2, p
+= 2, lP
++)
3196 md_number_to_chars (p
, *lP
, 2);
3201 fix_new (frag_now
, p
+ 1 - frag_now
->fr_literal
,
3202 nbytes
, this_add_symbol
,
3203 this_add_number
, 0, NO_RELOC
);
3210 /* {@}{q^}foo(Rn) */
3211 know ((length
== 0 && operandP
->vop_short
== ' ')
3212 || (length
> 0 && operandP
->vop_short
!= ' '));
3219 test
= this_add_number
;
3224 length
= test
& 0xffff8000 ? 4
3225 : test
& 0xffffff80 ? 2
3233 p
= frag_more (1 + length
);
3234 know (operandP
->vop_reg
>= 0);
3235 p
[0] = operandP
->vop_reg
3236 | ((at
| "?\12\14?\16"[length
]) << 4);
3239 md_number_to_chars (p
+ 1, this_add_number
, length
);
3243 fix_new (frag_now
, p
+ 1 - frag_now
->fr_literal
,
3244 length
, this_add_symbol
,
3245 this_add_number
, 0, NO_RELOC
);
3261 if ((errtxt
= vip_begin (1, "$", "*", "`")) != 0)
3262 as_fatal (_("VIP_BEGIN error:%s"), errtxt
);
3264 for (i
= 0, fP
= float_operand
;
3265 fP
< float_operand
+ VIT_MAX_OPERANDS
;
3268 fP
->low
= &big_operand_bits
[i
][0];
3269 fP
->high
= &big_operand_bits
[i
][SIZE_OF_LARGE_NUMBER
- 1];
3273 static char *vax_cons_special_reloc
;
3276 vax_cons (expressionS
*exp
, int size
)
3281 vax_cons_special_reloc
= NULL
;
3282 save
= input_line_pointer
;
3283 if (input_line_pointer
[0] == '%')
3285 if (strncmp (input_line_pointer
+ 1, "pcrel", 5) == 0)
3287 input_line_pointer
+= 6;
3288 vax_cons_special_reloc
= "pcrel";
3290 if (vax_cons_special_reloc
)
3297 if (*input_line_pointer
!= '8')
3299 input_line_pointer
--;
3302 if (input_line_pointer
[0] != '1' || input_line_pointer
[1] != '6')
3306 if (input_line_pointer
[0] != '3' || input_line_pointer
[1] != '2')
3316 as_bad (_("Illegal operands: Only %%r_%s%d allowed in %d-byte data fields"),
3317 vax_cons_special_reloc
, size
* 8, size
);
3321 input_line_pointer
+= 2;
3322 if (*input_line_pointer
!= '(')
3324 as_bad (_("Illegal operands: %%r_%s%d requires arguments in ()"),
3325 vax_cons_special_reloc
, size
* 8);
3332 input_line_pointer
= save
;
3333 vax_cons_special_reloc
= NULL
;
3338 char *end
= ++input_line_pointer
;
3341 while (! is_end_of_line
[(c
= *end
)])
3355 as_bad (_("Illegal operands: %%r_%s%d requires arguments in ()"),
3356 vax_cons_special_reloc
, size
* 8);
3362 if (input_line_pointer
!= end
)
3364 as_bad (_("Illegal operands: %%r_%s%d requires arguments in ()"),
3365 vax_cons_special_reloc
, size
* 8);
3369 input_line_pointer
++;
3371 c
= *input_line_pointer
;
3372 if (! is_end_of_line
[c
] && c
!= ',')
3373 as_bad (_("Illegal operands: garbage after %%r_%s%d()"),
3374 vax_cons_special_reloc
, size
* 8);
3380 if (vax_cons_special_reloc
== NULL
)
3384 /* This is called by emit_expr via TC_CONS_FIX_NEW when creating a
3385 reloc for a cons. */
3388 vax_cons_fix_new (fragS
*frag
, int where
, unsigned int nbytes
, expressionS
*exp
)
3390 bfd_reloc_code_real_type r
;
3392 r
= (nbytes
== 1 ? BFD_RELOC_8
:
3393 (nbytes
== 2 ? BFD_RELOC_16
: BFD_RELOC_32
));
3395 if (vax_cons_special_reloc
)
3397 if (*vax_cons_special_reloc
== 'p')
3401 case 1: r
= BFD_RELOC_8_PCREL
; break;
3402 case 2: r
= BFD_RELOC_16_PCREL
; break;
3403 case 4: r
= BFD_RELOC_32_PCREL
; break;
3409 fix_new_exp (frag
, where
, (int) nbytes
, exp
, 0, r
);
3410 vax_cons_special_reloc
= NULL
;
3414 md_atof (int type
, char * litP
, int * sizeP
)
3416 return vax_md_atof (type
, litP
, sizeP
);