1 /* tc-vax.c - vax-specific -
2 Copyright 1987, 1991, 1992, 1993, 1994, 1995, 1998, 2000, 2001, 2002,
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 2, 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, 59 Temple Place - Suite 330, Boston, MA
26 #include "obstack.h" /* For FRAG_APPEND_1_CHAR macro in "frags.h" */
33 #if defined (OBJ_AOUT) && !defined (BFD_ASSEMBLER) && defined (TE_NetBSD)
34 #include <netinet/in.h>
37 /* These chars start a comment anywhere in a source file (except inside
39 const char comment_chars
[] = "#";
41 /* These chars only start a comment at the beginning of a line. */
42 /* Note that for the VAX the are the same as comment_chars above. */
43 const char line_comment_chars
[] = "#";
45 const char line_separator_chars
[] = ";";
47 /* Chars that can be used to separate mant from exp in floating point nums */
48 const char EXP_CHARS
[] = "eE";
50 /* Chars that mean this number is a floating point constant */
52 /* or 0H1.234E-12 (see exp chars above) */
53 const char FLT_CHARS
[] = "dDfFgGhH";
55 /* Also be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
56 changed in read.c . Ideally it shouldn't have to know about it at all,
57 but nothing is ideal around here. */
59 /* Hold details of an operand expression */
60 static expressionS exp_of_operand
[VIT_MAX_OPERANDS
];
61 static segT seg_of_operand
[VIT_MAX_OPERANDS
];
63 /* A vax instruction after decoding. */
66 /* Hold details of big operands. */
67 LITTLENUM_TYPE big_operand_bits
[VIT_MAX_OPERANDS
][SIZE_OF_LARGE_NUMBER
];
68 FLONUM_TYPE float_operand
[VIT_MAX_OPERANDS
];
69 /* Above is made to point into big_operand_bits by md_begin(). */
72 #define GLOBAL_OFFSET_TABLE_NAME "_GLOBAL_OFFSET_TABLE_"
73 #define PROCEDURE_LINKAGE_TABLE_NAME "_PROCEDURE_LINKAGE_TABLE_"
74 symbolS
*GOT_symbol
; /* Pre-defined "_GLOBAL_OFFSET_TABLE_" */
75 symbolS
*PLT_symbol
; /* Pre-defined "_PROCEDURE_LINKAGE_TABLE_" */
78 int flag_hash_long_names
; /* -+ */
79 int flag_one
; /* -1 */
80 int flag_show_after_trunc
; /* -H */
81 int flag_no_hash_mixed_case
; /* -h NUM */
83 int flag_want_pic
; /* -k */
87 * For VAX, relative addresses of "just the right length" are easy.
88 * The branch displacement is always the last operand, even in
89 * synthetic instructions.
90 * For VAX, we encode the relax_substateTs (in e.g. fr_substate) as:
92 * 4 3 2 1 0 bit number
93 * ---/ /--+-------+-------+-------+-------+-------+
94 * | what state ? | how long ? |
95 * ---/ /--+-------+-------+-------+-------+-------+
97 * The "how long" bits are 00=byte, 01=word, 10=long.
98 * This is a Un*x convention.
99 * Not all lengths are legit for a given value of (what state).
100 * The "how long" refers merely to the displacement length.
101 * The address usually has some constant bytes in it as well.
104 groups for VAX address relaxing.
106 1. "foo" pc-relative.
107 length of byte, word, long
109 2a. J<cond> where <cond> is a simple flag test.
110 length of byte, word, long.
111 VAX opcodes are: (Hex)
124 Always, you complement 0th bit to reverse condition.
125 Always, 1-byte opcode, then 1-byte displacement.
127 2b. J<cond> where cond tests a memory bit.
128 length of byte, word, long.
129 Vax opcodes are: (Hex)
136 Always, you complement 0th bit to reverse condition.
137 Always, 1-byte opcde, longword-address, byte-address, 1-byte-displacement
139 2c. J<cond> where cond tests low-order memory bit
140 length of byte,word,long.
141 Vax opcodes are: (Hex)
144 Always, you complement 0th bit to reverse condition.
145 Always, 1-byte opcode, longword-address, 1-byte displacement.
148 length of byte,word,long.
149 Vax opcodes are: (Hex)
152 These are like (2) but there is no condition to reverse.
153 Always, 1 byte opcode, then displacement/absolute.
156 length of word, long.
157 Vax opcodes are: (Hex)
165 Always, we cannot reverse the sense of the branch; we have a word
167 The double-byte op-codes don't hurt: we never want to modify the
168 opcode, so we don't care how many bytes are between the opcode and
172 length of long, long, byte.
173 Vax opcodes are: (Hex)
178 Always, we cannot reverse the sense of the branch; we have a byte
181 The only time we need to modify the opcode is for class 2 instructions.
182 After relax() we may complement the lowest order bit of such instruction
183 to reverse sense of branch.
185 For class 2 instructions, we store context of "where is the opcode literal".
186 We can change an opcode's lowest order bit without breaking anything else.
188 We sometimes store context in the operand literal. This way we can figure out
189 after relax() what the original addressing mode was.
192 /* These displacements are relative to the start address of the
193 displacement. The first letter is Byte, Word. 2nd letter is
194 Forward, Backward. */
197 #define WF (2+ 32767)
198 #define WB (2+-32768)
199 /* Dont need LF, LB because they always reach. [They are coded as 0.] */
201 #define C(a,b) ENCODE_RELAX(a,b)
202 /* This macro has no side-effects. */
203 #define ENCODE_RELAX(what,length) (((what) << 2) + (length))
204 #define RELAX_STATE(s) ((s) >> 2)
205 #define RELAX_LENGTH(s) ((s) & 3)
207 const relax_typeS md_relax_table
[] =
209 {1, 1, 0, 0}, /* error sentinel 0,0 */
210 {1, 1, 0, 0}, /* unused 0,1 */
211 {1, 1, 0, 0}, /* unused 0,2 */
212 {1, 1, 0, 0}, /* unused 0,3 */
214 {BF
+ 1, BB
+ 1, 2, C (1, 1)},/* B^"foo" 1,0 */
215 {WF
+ 1, WB
+ 1, 3, C (1, 2)},/* W^"foo" 1,1 */
216 {0, 0, 5, 0}, /* L^"foo" 1,2 */
217 {1, 1, 0, 0}, /* unused 1,3 */
219 {BF
, BB
, 1, C (2, 1)}, /* b<cond> B^"foo" 2,0 */
220 {WF
+ 2, WB
+ 2, 4, C (2, 2)},/* br.+? brw X 2,1 */
221 {0, 0, 7, 0}, /* br.+? jmp X 2,2 */
222 {1, 1, 0, 0}, /* unused 2,3 */
224 {BF
, BB
, 1, C (3, 1)}, /* brb B^foo 3,0 */
225 {WF
, WB
, 2, C (3, 2)}, /* brw W^foo 3,1 */
226 {0, 0, 5, 0}, /* Jmp L^foo 3,2 */
227 {1, 1, 0, 0}, /* unused 3,3 */
229 {1, 1, 0, 0}, /* unused 4,0 */
230 {WF
, WB
, 2, C (4, 2)}, /* acb_ ^Wfoo 4,1 */
231 {0, 0, 10, 0}, /* acb_,br,jmp L^foo4,2 */
232 {1, 1, 0, 0}, /* unused 4,3 */
234 {BF
, BB
, 1, C (5, 1)}, /* Xob___,,foo 5,0 */
235 {WF
+ 4, WB
+ 4, 6, C (5, 2)},/* Xob.+2,brb.+3,brw5,1 */
236 {0, 0, 9, 0}, /* Xob.+2,brb.+6,jmp5,2 */
237 {1, 1, 0, 0}, /* unused 5,3 */
246 void float_cons
PARAMS ((int));
248 const pseudo_typeS md_pseudo_table
[] =
250 {"dfloat", float_cons
, 'd'},
251 {"ffloat", float_cons
, 'f'},
252 {"gfloat", float_cons
, 'g'},
253 {"hfloat", float_cons
, 'h'},
257 #define STATE_PC_RELATIVE (1)
258 #define STATE_CONDITIONAL_BRANCH (2)
259 #define STATE_ALWAYS_BRANCH (3) /* includes BSB... */
260 #define STATE_COMPLEX_BRANCH (4)
261 #define STATE_COMPLEX_HOP (5)
263 #define STATE_BYTE (0)
264 #define STATE_WORD (1)
265 #define STATE_LONG (2)
266 #define STATE_UNDF (3) /* Symbol undefined in pass1 */
268 #define min(a, b) ((a) < (b) ? (a) : (b))
270 int flonum_gen2vax
PARAMS ((char format_letter
, FLONUM_TYPE
* f
,
271 LITTLENUM_TYPE
* words
));
272 static const char *vip_begin
PARAMS ((int, const char *, const char *,
274 static void vip_op_1
PARAMS ((int, const char *));
275 static void vip_op_defaults
PARAMS ((const char *, const char *, const char *));
276 static void vip_op
PARAMS ((char *, struct vop
*));
277 static void vip
PARAMS ((struct vit
*, char *));
279 static int vax_reg_parse
PARAMS ((char, char, char, char));
288 if ((errtxt
= vip_begin (1, "$", "*", "`")) != 0)
290 as_fatal (_("VIP_BEGIN error:%s"), errtxt
);
293 for (i
= 0, fP
= float_operand
;
294 fP
< float_operand
+ VIT_MAX_OPERANDS
;
297 fP
->low
= &big_operand_bits
[i
][0];
298 fP
->high
= &big_operand_bits
[i
][SIZE_OF_LARGE_NUMBER
- 1];
303 md_number_to_chars (con
, value
, nbytes
)
308 number_to_chars_littleendian (con
, value
, nbytes
);
311 /* Fix up some data or instructions after we find out the value of a symbol
312 that they reference. */
314 void /* Knows about order of bytes in address. */
315 md_apply_fix3 (fixP
, valueP
, seg
)
318 segT seg ATTRIBUTE_UNUSED
;
320 valueT value
= * valueP
;
322 if (((fixP
->fx_addsy
== NULL
&& fixP
->fx_subsy
== NULL
)
323 && fixP
->fx_r_type
!= BFD_RELOC_32_PLT_PCREL
324 && fixP
->fx_r_type
!= BFD_RELOC_32_GOT_PCREL
)
325 || fixP
->fx_r_type
== NO_RELOC
)
327 number_to_chars_littleendian (fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
,
328 value
, fixP
->fx_size
);
330 if (fixP
->fx_addsy
== NULL
&& fixP
->fx_pcrel
== 0)
335 md_chars_to_number (con
, nbytes
)
336 unsigned char con
[]; /* Low order byte 1st. */
337 int nbytes
; /* Number of bytes in the input. */
340 for (retval
= 0, con
+= nbytes
- 1; nbytes
--; con
--)
342 retval
<<= BITS_PER_CHAR
;
348 /* vax:md_assemble() emit frags for 1 instruction */
351 md_assemble (instruction_string
)
352 char *instruction_string
; /* A string: assemble 1 instruction. */
354 /* Non-zero if operand expression's segment is not known yet. */
356 /* Non-zero if operand expression's segment is absolute. */
361 /* An operand. Scans all operands. */
362 struct vop
*operandP
;
363 char *save_input_line_pointer
;
364 /* What used to live after an expression. */
366 /* 1: instruction_string bad for all passes. */
368 /* Points to slot just after last operand. */
369 struct vop
*end_operandP
;
370 /* Points to expression values for this operand. */
374 /* These refer to an instruction operand expression. */
375 /* Target segment of the address. */
377 valueT this_add_number
;
378 /* Positive (minuend) symbol. */
379 symbolS
*this_add_symbol
;
381 long opcode_as_number
;
382 /* Least significant byte 1st. */
383 char *opcode_as_chars
;
384 /* As an array of characters. */
385 /* Least significant byte 1st */
386 char *opcode_low_byteP
;
387 /* length (bytes) meant by vop_short. */
389 /* 0, or 1 if '@' is in addressing mode. */
391 /* From vop_nbytes: vax_operand_width (in bytes) */
394 LITTLENUM_TYPE literal_float
[8];
395 /* Big enough for any floating point literal. */
397 vip (&v
, instruction_string
);
400 * Now we try to find as many as_warn()s as we can. If we do any as_warn()s
401 * then goofed=1. Notice that we don't make any frags yet.
402 * Should goofed be 1, then this instruction will wedge in any pass,
403 * and we can safely flush it, without causing interpass symbol phase
404 * errors. That is, without changing label values in different passes.
406 if ((goofed
= (*v
.vit_error
)) != 0)
408 as_fatal (_("Ignoring statement due to \"%s\""), v
.vit_error
);
411 * We need to use expression() and friends, which require us to diddle
412 * input_line_pointer. So we save it and restore it later.
414 save_input_line_pointer
= input_line_pointer
;
415 for (operandP
= v
.vit_operand
,
416 expP
= exp_of_operand
,
417 segP
= seg_of_operand
,
418 floatP
= float_operand
,
419 end_operandP
= v
.vit_operand
+ v
.vit_operands
;
421 operandP
< end_operandP
;
423 operandP
++, expP
++, segP
++, floatP
++)
424 { /* for each operand */
425 if (operandP
->vop_error
)
427 as_fatal (_("Aborting because statement has \"%s\""), operandP
->vop_error
);
432 /* Statement has no syntax goofs: let's sniff the expression. */
433 int can_be_short
= 0; /* 1 if a bignum can be reduced to a short literal. */
435 input_line_pointer
= operandP
->vop_expr_begin
;
436 c_save
= operandP
->vop_expr_end
[1];
437 operandP
->vop_expr_end
[1] = '\0';
438 /* If to_seg == SEG_PASS1, expression() will have set need_pass_2 = 1. */
439 *segP
= expression (expP
);
443 /* for BSD4.2 compatibility, missing expression is absolute 0 */
444 expP
->X_op
= O_constant
;
445 expP
->X_add_number
= 0;
446 /* For SEG_ABSOLUTE, we shouldn't need to set X_op_symbol,
447 X_add_symbol to any particular value. But, we will program
448 defensively. Since this situation occurs rarely so it costs
449 us little to do, and stops Dean worrying about the origin of
450 random bits in expressionS's. */
451 expP
->X_add_symbol
= NULL
;
452 expP
->X_op_symbol
= NULL
;
461 * Major bug. We can't handle the case of a
462 * SEG_OP expression in a VIT_OPCODE_SYNTHETIC
463 * variable-length instruction.
464 * We don't have a frag type that is smart enough to
465 * relax a SEG_OP, and so we just force all
466 * SEG_OPs to behave like SEG_PASS1s.
467 * Clearly, if there is a demand we can invent a new or
468 * modified frag type and then coding up a frag for this
469 * case will be easy. SEG_OP was invented for the
470 * .words after a CASE opcode, and was never intended for
471 * instruction operands.
474 as_fatal (_("Can't relocate expression"));
478 /* Preserve the bits. */
479 if (expP
->X_add_number
> 0)
481 bignum_copy (generic_bignum
, expP
->X_add_number
,
482 floatP
->low
, SIZE_OF_LARGE_NUMBER
);
486 know (expP
->X_add_number
< 0);
487 flonum_copy (&generic_floating_point_number
,
489 if (strchr ("s i", operandP
->vop_short
))
491 /* Could possibly become S^# */
492 flonum_gen2vax (-expP
->X_add_number
, floatP
, literal_float
);
493 switch (-expP
->X_add_number
)
497 (literal_float
[0] & 0xFC0F) == 0x4000
498 && literal_float
[1] == 0;
503 (literal_float
[0] & 0xFC0F) == 0x4000
504 && literal_float
[1] == 0
505 && literal_float
[2] == 0
506 && literal_float
[3] == 0;
511 (literal_float
[0] & 0xFF81) == 0x4000
512 && literal_float
[1] == 0
513 && literal_float
[2] == 0
514 && literal_float
[3] == 0;
518 can_be_short
= ((literal_float
[0] & 0xFFF8) == 0x4000
519 && (literal_float
[1] & 0xE000) == 0
520 && literal_float
[2] == 0
521 && literal_float
[3] == 0
522 && literal_float
[4] == 0
523 && literal_float
[5] == 0
524 && literal_float
[6] == 0
525 && literal_float
[7] == 0);
529 BAD_CASE (-expP
->X_add_number
);
531 } /* switch (float type) */
532 } /* if (could want to become S^#...) */
533 } /* bignum or flonum ? */
535 if (operandP
->vop_short
== 's'
536 || operandP
->vop_short
== 'i'
537 || (operandP
->vop_short
== ' '
538 && operandP
->vop_reg
== 0xF
539 && (operandP
->vop_mode
& 0xE) == 0x8))
542 if (operandP
->vop_short
== ' ')
544 /* We must chose S^ or I^. */
545 if (expP
->X_add_number
> 0)
547 /* Bignum: Short literal impossible. */
548 operandP
->vop_short
= 'i';
549 operandP
->vop_mode
= 8;
550 operandP
->vop_reg
= 0xF; /* VAX PC. */
554 /* Flonum: Try to do it. */
557 operandP
->vop_short
= 's';
558 operandP
->vop_mode
= 0;
559 operandP
->vop_ndx
= -1;
560 operandP
->vop_reg
= -1;
561 expP
->X_op
= O_constant
;
565 operandP
->vop_short
= 'i';
566 operandP
->vop_mode
= 8;
567 operandP
->vop_reg
= 0xF; /* VAX PC */
569 } /* bignum or flonum ? */
570 } /* if #, but no S^ or I^ seen. */
571 /* No more ' ' case: either 's' or 'i'. */
572 if (operandP
->vop_short
== 's')
574 /* Wants to be a short literal. */
575 if (expP
->X_add_number
> 0)
577 as_warn (_("Bignum not permitted in short literal. Immediate mode assumed."));
578 operandP
->vop_short
= 'i';
579 operandP
->vop_mode
= 8;
580 operandP
->vop_reg
= 0xF; /* VAX PC. */
586 as_warn (_("Can't do flonum short literal: immediate mode used."));
587 operandP
->vop_short
= 'i';
588 operandP
->vop_mode
= 8;
589 operandP
->vop_reg
= 0xF; /* VAX PC. */
592 { /* Encode short literal now. */
595 switch (-expP
->X_add_number
)
599 temp
= literal_float
[0] >> 4;
603 temp
= literal_float
[0] >> 1;
607 temp
= ((literal_float
[0] << 3) & 070)
608 | ((literal_float
[1] >> 13) & 07);
612 BAD_CASE (-expP
->X_add_number
);
616 floatP
->low
[0] = temp
& 077;
618 } /* if can be short literal float */
619 } /* flonum or bignum ? */
622 { /* I^# seen: set it up if float. */
623 if (expP
->X_add_number
< 0)
625 memcpy (floatP
->low
, literal_float
, sizeof (literal_float
));
631 as_warn (_("A bignum/flonum may not be a displacement: 0x%lx used"),
632 (expP
->X_add_number
= 0x80000000L
));
633 /* Chosen so luser gets the most offset bits to patch later. */
635 expP
->X_add_number
= floatP
->low
[0]
636 | ((LITTLENUM_MASK
& (floatP
->low
[1])) << LITTLENUM_NUMBER_OF_BITS
);
638 * For the O_big case we have:
639 * If vop_short == 's' then a short floating literal is in the
640 * lowest 6 bits of floatP -> low [0], which is
641 * big_operand_bits [---] [0].
642 * If vop_short == 'i' then the appropriate number of elements
643 * of big_operand_bits [---] [...] are set up with the correct
645 * Also, just in case width is byte word or long, we copy the lowest
646 * 32 bits of the number to X_add_number.
650 if (input_line_pointer
!= operandP
->vop_expr_end
+ 1)
652 as_fatal ("Junk at end of expression \"%s\"", input_line_pointer
);
655 operandP
->vop_expr_end
[1] = c_save
;
657 } /* for(each operand) */
659 input_line_pointer
= save_input_line_pointer
;
661 if (need_pass_2
|| goofed
)
667 /* Remember where it is, in case we want to modify the op-code later. */
668 opcode_low_byteP
= frag_more (v
.vit_opcode_nbytes
);
669 memcpy (opcode_low_byteP
, v
.vit_opcode
, v
.vit_opcode_nbytes
);
670 opcode_as_chars
= v
.vit_opcode
;
671 opcode_as_number
= md_chars_to_number ((unsigned char *) opcode_as_chars
, 4);
672 for (operandP
= v
.vit_operand
,
673 expP
= exp_of_operand
,
674 segP
= seg_of_operand
,
675 floatP
= float_operand
,
676 end_operandP
= v
.vit_operand
+ v
.vit_operands
;
678 operandP
< end_operandP
;
685 if (operandP
->vop_ndx
>= 0)
687 /* indexed addressing byte */
688 /* Legality of indexed mode already checked: it is OK */
689 FRAG_APPEND_1_CHAR (0x40 + operandP
->vop_ndx
);
690 } /* if(vop_ndx>=0) */
692 /* Here to make main operand frag(s). */
693 this_add_number
= expP
->X_add_number
;
694 this_add_symbol
= expP
->X_add_symbol
;
697 is_undefined
= (to_seg
== undefined_section
);
698 is_absolute
= (to_seg
== absolute_section
);
700 is_undefined
= (to_seg
== SEG_UNKNOWN
);
701 is_absolute
= (to_seg
== SEG_ABSOLUTE
);
703 at
= operandP
->vop_mode
& 1;
704 length
= (operandP
->vop_short
== 'b'
705 ? 1 : (operandP
->vop_short
== 'w'
706 ? 2 : (operandP
->vop_short
== 'l'
708 nbytes
= operandP
->vop_nbytes
;
709 if (operandP
->vop_access
== 'b')
711 if (to_seg
== now_seg
|| is_undefined
)
713 /* If is_undefined, then it might BECOME now_seg. */
716 p
= frag_more (nbytes
);
717 fix_new (frag_now
, p
- frag_now
->fr_literal
, nbytes
,
718 this_add_symbol
, this_add_number
, 1, NO_RELOC
);
721 { /* to_seg==now_seg || to_seg == SEG_UNKNOWN */
723 length_code
= is_undefined
? STATE_UNDF
: STATE_BYTE
;
724 if (opcode_as_number
& VIT_OPCODE_SPECIAL
)
726 if (operandP
->vop_width
== VAX_WIDTH_UNCONDITIONAL_JUMP
)
729 frag_var (rs_machine_dependent
, 5, 1,
730 ENCODE_RELAX (STATE_ALWAYS_BRANCH
, length_code
),
731 this_add_symbol
, this_add_number
,
736 if (operandP
->vop_width
== VAX_WIDTH_WORD_JUMP
)
738 length_code
= STATE_WORD
;
739 /* JF: There is no state_byte for this one! */
740 frag_var (rs_machine_dependent
, 10, 2,
741 ENCODE_RELAX (STATE_COMPLEX_BRANCH
, length_code
),
742 this_add_symbol
, this_add_number
,
747 know (operandP
->vop_width
== VAX_WIDTH_BYTE_JUMP
);
748 frag_var (rs_machine_dependent
, 9, 1,
749 ENCODE_RELAX (STATE_COMPLEX_HOP
, length_code
),
750 this_add_symbol
, this_add_number
,
757 know (operandP
->vop_width
== VAX_WIDTH_CONDITIONAL_JUMP
);
758 frag_var (rs_machine_dependent
, 7, 1,
759 ENCODE_RELAX (STATE_CONDITIONAL_BRANCH
, length_code
),
760 this_add_symbol
, this_add_number
,
767 /* to_seg != now_seg && to_seg != SEG_UNKNOWN */
769 * --- SEG FLOAT MAY APPEAR HERE ----
775 know (!(opcode_as_number
& VIT_OPCODE_SYNTHETIC
));
776 p
= frag_more (nbytes
);
777 /* Conventional relocation. */
778 fix_new (frag_now
, p
- frag_now
->fr_literal
, nbytes
,
780 section_symbol (absolute_section
),
784 this_add_number
, 1, NO_RELOC
);
788 know (opcode_as_number
& VIT_OPCODE_SYNTHETIC
);
789 if (opcode_as_number
& VIT_OPCODE_SPECIAL
)
791 if (operandP
->vop_width
== VAX_WIDTH_UNCONDITIONAL_JUMP
)
794 *opcode_low_byteP
= opcode_as_chars
[0] + VAX_WIDEN_LONG
;
795 know (opcode_as_chars
[1] == 0);
797 p
[0] = VAX_ABSOLUTE_MODE
; /* @#... */
798 md_number_to_chars (p
+ 1, this_add_number
, 4);
799 /* Now (eg) JMP @#foo or JSB @#foo. */
803 if (operandP
->vop_width
== VAX_WIDTH_WORD_JUMP
)
811 p
[5] = VAX_ABSOLUTE_MODE
; /* @#... */
812 md_number_to_chars (p
+ 6, this_add_number
, 4);
822 know (operandP
->vop_width
== VAX_WIDTH_BYTE_JUMP
);
828 p
[4] = VAX_ABSOLUTE_MODE
; /* @#... */
829 md_number_to_chars (p
+ 5, this_add_number
, 4);
842 *opcode_low_byteP
^= 1;
843 /* To reverse the condition in a VAX branch,
844 complement the lowest order bit. */
848 p
[2] = VAX_ABSOLUTE_MODE
; /* @#... */
849 md_number_to_chars (p
+ 3, this_add_number
, 4);
860 /* to_seg != now_seg && !is_undefinfed && !is_absolute */
863 /* Pc-relative. Conventional relocation. */
864 know (!(opcode_as_number
& VIT_OPCODE_SYNTHETIC
));
865 p
= frag_more (nbytes
);
866 fix_new (frag_now
, p
- frag_now
->fr_literal
, nbytes
,
868 section_symbol (absolute_section
),
872 this_add_number
, 1, NO_RELOC
);
876 know (opcode_as_number
& VIT_OPCODE_SYNTHETIC
);
877 if (opcode_as_number
& VIT_OPCODE_SPECIAL
)
879 if (operandP
->vop_width
== VAX_WIDTH_UNCONDITIONAL_JUMP
)
882 know (opcode_as_chars
[1] == 0);
883 *opcode_low_byteP
= opcode_as_chars
[0] + VAX_WIDEN_LONG
;
885 p
[0] = VAX_PC_RELATIVE_MODE
;
887 p
+ 1 - frag_now
->fr_literal
, 4,
889 this_add_number
, 1, NO_RELOC
);
890 /* Now eg JMP foo or JSB foo. */
894 if (operandP
->vop_width
== VAX_WIDTH_WORD_JUMP
)
902 p
[5] = VAX_PC_RELATIVE_MODE
;
904 p
+ 6 - frag_now
->fr_literal
, 4,
906 this_add_number
, 1, NO_RELOC
);
916 know (operandP
->vop_width
== VAX_WIDTH_BYTE_JUMP
);
922 p
[4] = VAX_PC_RELATIVE_MODE
;
924 p
+ 5 - frag_now
->fr_literal
,
926 this_add_number
, 1, NO_RELOC
);
938 know (operandP
->vop_width
== VAX_WIDTH_CONDITIONAL_JUMP
);
939 *opcode_low_byteP
^= 1; /* Reverse branch condition. */
943 p
[2] = VAX_PC_RELATIVE_MODE
;
944 fix_new (frag_now
, p
+ 3 - frag_now
->fr_literal
,
946 this_add_number
, 1, NO_RELOC
);
954 know (operandP
->vop_access
!= 'b'); /* So it is ordinary operand. */
955 know (operandP
->vop_access
!= ' '); /* ' ' target-independent: elsewhere. */
956 know (operandP
->vop_access
== 'a'
957 || operandP
->vop_access
== 'm'
958 || operandP
->vop_access
== 'r'
959 || operandP
->vop_access
== 'v'
960 || operandP
->vop_access
== 'w');
961 if (operandP
->vop_short
== 's')
965 if (this_add_number
>= 64)
967 as_warn (_("Short literal overflow(%ld.), immediate mode assumed."),
968 (long) this_add_number
);
969 operandP
->vop_short
= 'i';
970 operandP
->vop_mode
= 8;
971 operandP
->vop_reg
= 0xF;
976 as_warn (_("Forced short literal to immediate mode. now_seg=%s to_seg=%s"),
977 segment_name (now_seg
), segment_name (to_seg
));
978 operandP
->vop_short
= 'i';
979 operandP
->vop_mode
= 8;
980 operandP
->vop_reg
= 0xF;
983 if (operandP
->vop_reg
>= 0 && (operandP
->vop_mode
< 8
984 || (operandP
->vop_reg
!= 0xF && operandP
->vop_mode
< 10)))
986 /* One byte operand. */
987 know (operandP
->vop_mode
> 3);
988 FRAG_APPEND_1_CHAR (operandP
->vop_mode
<< 4 | operandP
->vop_reg
);
989 /* All 1-bytes except S^# happen here. */
993 /* {@}{q^}foo{(Rn)} or S^#foo */
994 if (operandP
->vop_reg
== -1 && operandP
->vop_short
!= 's')
997 if (to_seg
== now_seg
)
1001 know (operandP
->vop_short
== ' ');
1002 length_code
= STATE_BYTE
;
1004 if (S_IS_EXTERNAL (this_add_symbol
)
1005 || S_IS_WEAK (this_add_symbol
))
1006 length_code
= STATE_UNDF
;
1008 p
= frag_var (rs_machine_dependent
, 10, 2,
1009 ENCODE_RELAX (STATE_PC_RELATIVE
, length_code
),
1010 this_add_symbol
, this_add_number
,
1012 know (operandP
->vop_mode
== 10 + at
);
1014 /* At is the only context we need to carry
1015 to other side of relax() process. Must
1016 be in the correct bit position of VAX
1017 operand spec. byte. */
1022 know (operandP
->vop_short
!= ' ');
1023 p
= frag_more (length
+ 1);
1024 p
[0] = 0xF | ((at
+ "?\12\14?\16"[length
]) << 4);
1025 fix_new (frag_now
, p
+ 1 - frag_now
->fr_literal
,
1026 length
, this_add_symbol
,
1027 this_add_number
, 1, NO_RELOC
);
1031 { /* to_seg != now_seg */
1032 if (this_add_symbol
== NULL
)
1035 /* Do @#foo: simpler relocation than foo-.(pc) anyway. */
1037 p
[0] = VAX_ABSOLUTE_MODE
; /* @#... */
1038 md_number_to_chars (p
+ 1, this_add_number
, 4);
1039 if (length
&& length
!= 4)
1041 as_warn (_("Length specification ignored. Address mode 9F used"));
1046 /* {@}{q^}other_seg */
1047 know ((length
== 0 && operandP
->vop_short
== ' ')
1048 || (length
> 0 && operandP
->vop_short
!= ' '));
1051 || S_IS_WEAK(this_add_symbol
)
1052 || S_IS_EXTERNAL(this_add_symbol
)
1058 default: length_code
= STATE_UNDF
; break;
1059 case 1: length_code
= STATE_BYTE
; break;
1060 case 2: length_code
= STATE_WORD
; break;
1061 case 4: length_code
= STATE_LONG
; break;
1064 * We have a SEG_UNKNOWN symbol. It might
1065 * turn out to be in the same segment as
1066 * the instruction, permitting relaxation.
1068 p
= frag_var (rs_machine_dependent
, 5, 2,
1069 ENCODE_RELAX (STATE_PC_RELATIVE
, length_code
),
1070 this_add_symbol
, this_add_number
,
1078 know (operandP
->vop_short
== ' ');
1079 length
= 4; /* Longest possible. */
1081 p
= frag_more (length
+ 1);
1082 p
[0] = 0xF | ((at
+ "?\12\14?\16"[length
]) << 4);
1083 md_number_to_chars (p
+ 1, this_add_number
, length
);
1085 p
+ 1 - frag_now
->fr_literal
,
1086 length
, this_add_symbol
,
1087 this_add_number
, 1, NO_RELOC
);
1094 /* {@}{q^}foo(Rn) or S^# or I^# or # */
1095 if (operandP
->vop_mode
< 0xA)
1097 /* # or S^# or I^# */
1098 if (operandP
->vop_access
== 'v'
1099 || operandP
->vop_access
== 'a')
1101 if (operandP
->vop_access
== 'v')
1102 as_warn (_("Invalid operand: immediate value used as base address."));
1104 as_warn (_("Invalid operand: immediate value used as address."));
1105 /* gcc 2.6.3 is known to generate these in at least
1109 && is_absolute
&& (expP
->X_op
!= O_big
)
1110 && operandP
->vop_mode
== 8 /* No '@'. */
1111 && this_add_number
< 64)
1113 operandP
->vop_short
= 's';
1115 if (operandP
->vop_short
== 's')
1117 FRAG_APPEND_1_CHAR (this_add_number
);
1123 p
= frag_more (nbytes
+ 1);
1124 know (operandP
->vop_reg
== 0xF);
1126 if (flag_want_pic
&& operandP
->vop_mode
== 8
1127 && this_add_symbol
!= NULL
)
1129 as_warn (_("Symbol used as immediate operand in PIC mode."));
1132 p
[0] = (operandP
->vop_mode
<< 4) | 0xF;
1133 if ((is_absolute
) && (expP
->X_op
!= O_big
))
1136 * If nbytes > 4, then we are scrod. We
1137 * don't know if the high order bytes
1138 * are to be 0xFF or 0x00. BSD4.2 & RMS
1139 * say use 0x00. OK --- but this
1140 * assembler needs ANOTHER rewrite to
1141 * cope properly with this bug. */
1142 md_number_to_chars (p
+ 1, this_add_number
, min (4, nbytes
));
1145 memset (p
+ 5, '\0', nbytes
- 4);
1150 if (expP
->X_op
== O_big
)
1153 * Problem here is to get the bytes
1154 * in the right order. We stored
1155 * our constant as LITTLENUMs, not
1167 for (p
++; nbytes
; nbytes
-= 2, p
+= 2, lP
++)
1169 md_number_to_chars (p
, *lP
, 2);
1175 fix_new (frag_now
, p
+ 1 - frag_now
->fr_literal
,
1176 nbytes
, this_add_symbol
,
1177 this_add_number
, 0, NO_RELOC
);
1183 { /* {@}{q^}foo(Rn) */
1184 know ((length
== 0 && operandP
->vop_short
== ' ')
1185 || (length
> 0 && operandP
->vop_short
!= ' '));
1192 test
= this_add_number
;
1197 length
= test
& 0xffff8000 ? 4
1198 : test
& 0xffffff80 ? 2
1206 p
= frag_more (1 + length
);
1207 know (operandP
->vop_reg
>= 0);
1208 p
[0] = operandP
->vop_reg
1209 | ((at
| "?\12\14?\16"[length
]) << 4);
1212 md_number_to_chars (p
+ 1, this_add_number
, length
);
1216 fix_new (frag_now
, p
+ 1 - frag_now
->fr_literal
,
1217 length
, this_add_symbol
,
1218 this_add_number
, 0, NO_RELOC
);
1222 } /* if(single-byte-operand) */
1224 } /* for(operandP) */
1225 } /* vax_assemble() */
1227 /* md_estimate_size_before_relax(), called just before relax().
1228 Any symbol that is now undefined will not become defined.
1229 Return the correct fr_subtype in the frag and the growth beyond
1232 md_estimate_size_before_relax (fragP
, segment
)
1236 if (RELAX_LENGTH (fragP
->fr_subtype
) == STATE_UNDF
)
1238 if (S_GET_SEGMENT (fragP
->fr_symbol
) != segment
1240 || S_IS_WEAK (fragP
->fr_symbol
)
1241 || S_IS_EXTERNAL (fragP
->fr_symbol
)
1245 /* Non-relaxable cases. */
1246 int reloc_type
= NO_RELOC
;
1250 old_fr_fix
= fragP
->fr_fix
;
1251 p
= fragP
->fr_literal
+ old_fr_fix
;
1253 /* If this is to an undefined symbol, then if it's an indirect
1254 reference indicate that is can mutated into a GLOB_DAT or
1255 JUMP_SLOT by the loader. We restrict ourselves to no offset
1256 due to a limitation in the NetBSD linker. */
1258 if (GOT_symbol
== NULL
)
1259 GOT_symbol
= symbol_find (GLOBAL_OFFSET_TABLE_NAME
);
1260 if (PLT_symbol
== NULL
)
1261 PLT_symbol
= symbol_find (PROCEDURE_LINKAGE_TABLE_NAME
);
1262 if ((GOT_symbol
== NULL
|| fragP
->fr_symbol
!= GOT_symbol
)
1263 && (PLT_symbol
== NULL
|| fragP
->fr_symbol
!= PLT_symbol
)
1264 && fragP
->fr_symbol
!= NULL
1266 && (!S_IS_DEFINED (fragP
->fr_symbol
)
1267 || S_IS_WEAK (fragP
->fr_symbol
)
1268 || S_IS_EXTERNAL (fragP
->fr_symbol
)))
1273 as_fatal ("PIC reference to %s is indirect.\n",
1274 S_GET_NAME (fragP
->fr_symbol
));
1278 if (((unsigned char *) fragP
->fr_opcode
)[0] == VAX_CALLS
1279 || ((unsigned char *) fragP
->fr_opcode
)[0] == VAX_CALLG
1280 || ((unsigned char *) fragP
->fr_opcode
)[0] == VAX_JSB
1281 || ((unsigned char *) fragP
->fr_opcode
)[0] == VAX_JMP
1282 || S_IS_FUNCTION (fragP
->fr_symbol
))
1283 reloc_type
= BFD_RELOC_32_PLT_PCREL
;
1285 reloc_type
= BFD_RELOC_32_GOT_PCREL
;
1289 switch (RELAX_STATE (fragP
->fr_subtype
))
1291 case STATE_PC_RELATIVE
:
1292 p
[0] |= VAX_PC_RELATIVE_MODE
; /* Preserve @ bit. */
1293 fragP
->fr_fix
+= 1 + 4;
1294 fix_new (fragP
, old_fr_fix
+ 1, 4, fragP
->fr_symbol
,
1295 fragP
->fr_offset
, 1, reloc_type
);
1298 case STATE_CONDITIONAL_BRANCH
:
1299 *fragP
->fr_opcode
^= 1; /* Reverse sense of branch. */
1302 p
[2] = VAX_PC_RELATIVE_MODE
; /* ...(PC) */
1303 fragP
->fr_fix
+= 1 + 1 + 1 + 4;
1304 fix_new (fragP
, old_fr_fix
+ 3, 4, fragP
->fr_symbol
,
1305 fragP
->fr_offset
, 1, NO_RELOC
);
1308 case STATE_COMPLEX_BRANCH
:
1314 p
[5] = VAX_PC_RELATIVE_MODE
; /* ...(pc) */
1315 fragP
->fr_fix
+= 2 + 2 + 1 + 1 + 4;
1316 fix_new (fragP
, old_fr_fix
+ 6, 4, fragP
->fr_symbol
,
1317 fragP
->fr_offset
, 1, NO_RELOC
);
1320 case STATE_COMPLEX_HOP
:
1325 p
[4] = VAX_PC_RELATIVE_MODE
; /* ...(pc) */
1326 fragP
->fr_fix
+= 1 + 2 + 1 + 1 + 4;
1327 fix_new (fragP
, old_fr_fix
+ 5, 4, fragP
->fr_symbol
,
1328 fragP
->fr_offset
, 1, NO_RELOC
);
1331 case STATE_ALWAYS_BRANCH
:
1332 *fragP
->fr_opcode
+= VAX_WIDEN_LONG
;
1333 p
[0] = VAX_PC_RELATIVE_MODE
; /* ...(PC) */
1334 fragP
->fr_fix
+= 1 + 4;
1335 fix_new (fragP
, old_fr_fix
+ 1, 4, fragP
->fr_symbol
,
1336 fragP
->fr_offset
, 1, NO_RELOC
);
1344 /* Return the growth in the fixed part of the frag. */
1345 return fragP
->fr_fix
- old_fr_fix
;
1348 /* Relaxable cases. Set up the initial guess for the variable
1349 part of the frag. */
1350 switch (RELAX_STATE (fragP
->fr_subtype
))
1352 case STATE_PC_RELATIVE
:
1353 fragP
->fr_subtype
= ENCODE_RELAX (STATE_PC_RELATIVE
, STATE_BYTE
);
1355 case STATE_CONDITIONAL_BRANCH
:
1356 fragP
->fr_subtype
= ENCODE_RELAX (STATE_CONDITIONAL_BRANCH
, STATE_BYTE
);
1358 case STATE_COMPLEX_BRANCH
:
1359 fragP
->fr_subtype
= ENCODE_RELAX (STATE_COMPLEX_BRANCH
, STATE_WORD
);
1361 case STATE_COMPLEX_HOP
:
1362 fragP
->fr_subtype
= ENCODE_RELAX (STATE_COMPLEX_HOP
, STATE_BYTE
);
1364 case STATE_ALWAYS_BRANCH
:
1365 fragP
->fr_subtype
= ENCODE_RELAX (STATE_ALWAYS_BRANCH
, STATE_BYTE
);
1370 if (fragP
->fr_subtype
>= sizeof (md_relax_table
) / sizeof (md_relax_table
[0]))
1373 /* Return the size of the variable part of the frag. */
1374 return md_relax_table
[fragP
->fr_subtype
].rlx_length
;
1378 * md_convert_frag();
1380 * Called after relax() is finished.
1381 * In: Address of frag.
1382 * fr_type == rs_machine_dependent.
1383 * fr_subtype is what the address relaxed to.
1385 * Out: Any fixSs and constants are set up.
1386 * Caller will turn frag into a ".space 0".
1388 #ifdef BFD_ASSEMBLER
1390 md_convert_frag (headers
, seg
, fragP
)
1391 bfd
*headers ATTRIBUTE_UNUSED
;
1392 segT seg ATTRIBUTE_UNUSED
;
1396 md_convert_frag (headers
, seg
, fragP
)
1397 object_headers
*headers ATTRIBUTE_UNUSED
;
1398 segT seg ATTRIBUTE_UNUSED
;
1402 char *addressP
; /* -> _var to change. */
1403 char *opcodeP
; /* -> opcode char(s) to change. */
1404 short int extension
= 0; /* Size of relaxed address. */
1405 /* Added to fr_fix: incl. ALL var chars. */
1409 know (fragP
->fr_type
== rs_machine_dependent
);
1410 where
= fragP
->fr_fix
;
1411 addressP
= fragP
->fr_literal
+ where
;
1412 opcodeP
= fragP
->fr_opcode
;
1413 symbolP
= fragP
->fr_symbol
;
1416 switch (fragP
->fr_subtype
)
1419 case ENCODE_RELAX (STATE_PC_RELATIVE
, STATE_BYTE
):
1420 know (*addressP
== 0 || *addressP
== 0x10); /* '@' bit. */
1421 addressP
[0] |= 0xAF; /* Byte displacement. */
1422 fix_new (fragP
, fragP
->fr_fix
+ 1, 1, fragP
->fr_symbol
,
1423 fragP
->fr_offset
, 1, NO_RELOC
);
1427 case ENCODE_RELAX (STATE_PC_RELATIVE
, STATE_WORD
):
1428 know (*addressP
== 0 || *addressP
== 0x10); /* '@' bit. */
1429 addressP
[0] |= 0xCF; /* Word displacement. */
1430 fix_new (fragP
, fragP
->fr_fix
+ 1, 2, fragP
->fr_symbol
,
1431 fragP
->fr_offset
, 1, NO_RELOC
);
1435 case ENCODE_RELAX (STATE_PC_RELATIVE
, STATE_LONG
):
1436 know (*addressP
== 0 || *addressP
== 0x10); /* '@' bit. */
1437 addressP
[0] |= 0xEF; /* Long word displacement. */
1438 fix_new (fragP
, fragP
->fr_fix
+ 1, 4, fragP
->fr_symbol
,
1439 fragP
->fr_offset
, 1, NO_RELOC
);
1443 case ENCODE_RELAX (STATE_CONDITIONAL_BRANCH
, STATE_BYTE
):
1444 fix_new (fragP
, fragP
->fr_fix
, 1, fragP
->fr_symbol
,
1445 fragP
->fr_offset
, 1, NO_RELOC
);
1449 case ENCODE_RELAX (STATE_CONDITIONAL_BRANCH
, STATE_WORD
):
1450 opcodeP
[0] ^= 1; /* Reverse sense of test. */
1452 addressP
[1] = VAX_BRW
;
1453 fix_new (fragP
, fragP
->fr_fix
+ 2, 2, fragP
->fr_symbol
,
1454 fragP
->fr_offset
, 1, NO_RELOC
);
1458 case ENCODE_RELAX (STATE_CONDITIONAL_BRANCH
, STATE_LONG
):
1459 opcodeP
[0] ^= 1; /* Reverse sense of test. */
1461 addressP
[1] = VAX_JMP
;
1462 addressP
[2] = VAX_PC_RELATIVE_MODE
;
1463 fix_new (fragP
, fragP
->fr_fix
+ 3, 4, fragP
->fr_symbol
,
1464 fragP
->fr_offset
, 1, NO_RELOC
);
1468 case ENCODE_RELAX (STATE_ALWAYS_BRANCH
, STATE_BYTE
):
1469 fix_new (fragP
, fragP
->fr_fix
, 1, fragP
->fr_symbol
,
1470 fragP
->fr_offset
, 1, NO_RELOC
);
1474 case ENCODE_RELAX (STATE_ALWAYS_BRANCH
, STATE_WORD
):
1475 opcodeP
[0] += VAX_WIDEN_WORD
; /* brb -> brw, bsbb -> bsbw */
1476 fix_new (fragP
, fragP
->fr_fix
, 2, fragP
->fr_symbol
, fragP
->fr_offset
,
1481 case ENCODE_RELAX (STATE_ALWAYS_BRANCH
, STATE_LONG
):
1482 opcodeP
[0] += VAX_WIDEN_LONG
; /* brb -> jmp, bsbb -> jsb */
1483 addressP
[0] = VAX_PC_RELATIVE_MODE
;
1484 fix_new (fragP
, fragP
->fr_fix
+ 1, 4, fragP
->fr_symbol
,
1485 fragP
->fr_offset
, 1, NO_RELOC
);
1489 case ENCODE_RELAX (STATE_COMPLEX_BRANCH
, STATE_WORD
):
1490 fix_new (fragP
, fragP
->fr_fix
, 2, fragP
->fr_symbol
,
1491 fragP
->fr_offset
, 1, NO_RELOC
);
1495 case ENCODE_RELAX (STATE_COMPLEX_BRANCH
, STATE_LONG
):
1498 addressP
[2] = VAX_BRB
;
1500 addressP
[4] = VAX_JMP
;
1501 addressP
[5] = VAX_PC_RELATIVE_MODE
;
1502 fix_new (fragP
, fragP
->fr_fix
+ 6, 4, fragP
->fr_symbol
,
1503 fragP
->fr_offset
, 1, NO_RELOC
);
1507 case ENCODE_RELAX (STATE_COMPLEX_HOP
, STATE_BYTE
):
1508 fix_new (fragP
, fragP
->fr_fix
, 1, fragP
->fr_symbol
,
1509 fragP
->fr_offset
, 1, NO_RELOC
);
1513 case ENCODE_RELAX (STATE_COMPLEX_HOP
, STATE_WORD
):
1515 addressP
[1] = VAX_BRB
;
1517 addressP
[3] = VAX_BRW
;
1518 fix_new (fragP
, fragP
->fr_fix
+ 4, 2, fragP
->fr_symbol
,
1519 fragP
->fr_offset
, 1, NO_RELOC
);
1523 case ENCODE_RELAX (STATE_COMPLEX_HOP
, STATE_LONG
):
1525 addressP
[1] = VAX_BRB
;
1527 addressP
[3] = VAX_JMP
;
1528 addressP
[4] = VAX_PC_RELATIVE_MODE
;
1529 fix_new (fragP
, fragP
->fr_fix
+ 5, 4, fragP
->fr_symbol
,
1530 fragP
->fr_offset
, 1, NO_RELOC
);
1535 BAD_CASE (fragP
->fr_subtype
);
1538 fragP
->fr_fix
+= extension
;
1539 } /* md_convert_frag() */
1541 /* Translate internal format of relocation info into target format.
1543 On vax: first 4 bytes are normal unsigned long, next three bytes
1544 are symbolnum, least sig. byte first. Last byte is broken up with
1545 the upper nibble as nuthin, bit 3 as extern, bits 2 & 1 as length, and
1549 md_ri_to_chars (the_bytes
, ri
)
1551 struct reloc_info_generic ri
;
1554 md_number_to_chars (the_bytes
, ri
.r_address
, sizeof (ri
.r_address
));
1555 /* now the fun stuff */
1556 the_bytes
[6] = (ri
.r_symbolnum
>> 16) & 0x0ff;
1557 the_bytes
[5] = (ri
.r_symbolnum
>> 8) & 0x0ff;
1558 the_bytes
[4] = ri
.r_symbolnum
& 0x0ff;
1559 the_bytes
[7] = (((ri
.r_extern
<< 3) & 0x08) | ((ri
.r_length
<< 1) & 0x06) |
1560 ((ri
.r_pcrel
<< 0) & 0x01)) & 0x0F;
1563 #endif /* comment */
1566 #ifndef BFD_ASSEMBLER
1568 tc_aout_fix_to_chars (where
, fixP
, segment_address_in_file
)
1571 relax_addressT segment_address_in_file
;
1574 * In: length of relocation (or of address) in chars: 1, 2 or 4.
1575 * Out: GNU LD relocation length code: 0, 1, or 2.
1578 static const unsigned char nbytes_r_length
[] = {42, 0, 1, 42, 2};
1581 know (fixP
->fx_addsy
!= NULL
);
1583 md_number_to_chars (where
,
1584 fixP
->fx_frag
->fr_address
+ fixP
->fx_where
- segment_address_in_file
,
1587 r_symbolnum
= (S_IS_DEFINED (fixP
->fx_addsy
)
1588 ? S_GET_TYPE (fixP
->fx_addsy
)
1589 : fixP
->fx_addsy
->sy_number
);
1591 where
[6] = (r_symbolnum
>> 16) & 0x0ff;
1592 where
[5] = (r_symbolnum
>> 8) & 0x0ff;
1593 where
[4] = r_symbolnum
& 0x0ff;
1594 where
[7] = ((((!S_IS_DEFINED (fixP
->fx_addsy
)) << 3) & 0x08)
1595 | ((nbytes_r_length
[fixP
->fx_size
] << 1) & 0x06)
1596 | (((fixP
->fx_pcrel
<< 0) & 0x01) & 0x0f));
1598 #endif /* !BFD_ASSEMBLER */
1599 #endif /* OBJ_AOUT */
1602 * BUGS, GRIPES, APOLOGIA, etc.
1604 * The opcode table 'votstrs' needs to be sorted on opcode frequency.
1605 * That is, AFTER we hash it with hash_...(), we want most-used opcodes
1606 * to come out of the hash table faster.
1608 * I am sorry to inflict yet another VAX assembler on the world, but
1609 * RMS says we must do everything from scratch, to prevent pin-heads
1610 * restricting this software.
1614 * This is a vaguely modular set of routines in C to parse VAX
1615 * assembly code using DEC mnemonics. It is NOT un*x specific.
1617 * The idea here is that the assembler has taken care of all:
1624 * condensing any whitespace down to exactly one space
1625 * and all we have to do is parse 1 line into a vax instruction
1626 * partially formed. We will accept a line, and deliver:
1627 * an error message (hopefully empty)
1628 * a skeleton VAX instruction (tree structure)
1629 * textual pointers to all the operand expressions
1630 * a warning message that notes a silly operand (hopefully empty)
1634 * E D I T H I S T O R Y
1636 * 17may86 Dean Elsner. Bug if line ends immediately after opcode.
1637 * 30apr86 Dean Elsner. New vip_op() uses arg block so change call.
1638 * 6jan86 Dean Elsner. Crock vip_begin() to call vip_op_defaults().
1639 * 2jan86 Dean Elsner. Invent synthetic opcodes.
1640 * Widen vax_opcodeT to 32 bits. Use a bit for VIT_OPCODE_SYNTHETIC,
1641 * which means this is not a real opcode, it is like a macro; it will
1642 * be relax()ed into 1 or more instructions.
1643 * Use another bit for VIT_OPCODE_SPECIAL if the op-code is not optimised
1644 * like a regular branch instruction. Option added to vip_begin():
1645 * exclude synthetic opcodes. Invent synthetic_votstrs[].
1646 * 31dec85 Dean Elsner. Invent vit_opcode_nbytes.
1647 * Also make vit_opcode into a char[]. We now have n-byte vax opcodes,
1648 * so caller's don't have to know the difference between a 1-byte & a
1649 * 2-byte op-code. Still need vax_opcodeT concept, so we know how
1650 * big an object must be to hold an op.code.
1651 * 30dec85 Dean Elsner. Widen typedef vax_opcodeT in "vax-inst.h"
1652 * because vax opcodes may be 16 bits. Our crufty C compiler was
1653 * happily initialising 8-bit vot_codes with 16-bit numbers!
1654 * (Wouldn't the 'phone company like to compress data so easily!)
1655 * 29dec85 Dean Elsner. New static table vax_operand_width_size[].
1656 * Invented so we know hw many bytes a "I^#42" needs in its immediate
1657 * operand. Revised struct vop in "vax-inst.h": explicitly include
1658 * byte length of each operand, and it's letter-code datum type.
1659 * 17nov85 Dean Elsner. Name Change.
1660 * Due to ar(1) truncating names, we learned the hard way that
1661 * "vax-inst-parse.c" -> "vax-inst-parse." dropping the "o" off
1662 * the archived object name. SO... we shortened the name of this
1663 * source file, and changed the makefile.
1666 /* handle of the OPCODE hash table */
1667 static struct hash_control
*op_hash
;
1670 * In: 1 character, from "bdfghloqpw" being the data-type of an operand
1671 * of a vax instruction.
1673 * Out: the length of an operand of that type, in bytes.
1674 * Special branch operands types "-?!" have length 0.
1677 static const short int vax_operand_width_size
[256] =
1679 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1680 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1681 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1682 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1683 0, 0, 1, 0, 8, 0, 4, 8, 16, 0, 0, 0, 4, 0, 0,16, /* ..b.d.fgh...l..o */
1684 0, 8, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, /* .q.....w........ */
1685 0, 0, 1, 0, 8, 0, 4, 8, 16, 0, 0, 0, 4, 0, 0,16, /* ..b.d.fgh...l..o */
1686 0, 8, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, /* .q.....w........ */
1687 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1688 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1689 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1690 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1691 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1692 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1693 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1694 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1698 * This perversion encodes all the vax opcodes as a bunch of strings.
1699 * RMS says we should build our hash-table at run-time. Hmm.
1700 * Please would someone arrange these in decreasing frequency of opcode?
1701 * Because of the way hash_...() works, the most frequently used opcode
1702 * should be textually first and so on.
1704 * Input for this table was 'vax.opcodes', awk(1)ed by 'vax.opcodes.c.awk' .
1705 * So change 'vax.opcodes', then re-generate this table.
1708 #include "opcode/vax.h"
1711 * This is a table of optional op-codes. All of them represent
1712 * 'synthetic' instructions that seem popular.
1714 * Here we make some pseudo op-codes. Every code has a bit set to say
1715 * it is synthetic. This lets you catch them if you want to
1716 * ban these opcodes. They are mnemonics for "elastic" instructions
1717 * that are supposed to assemble into the fewest bytes needed to do a
1718 * branch, or to do a conditional branch, or whatever.
1720 * The opcode is in the usual place [low-order n*8 bits]. This means
1721 * that if you mask off the bucky bits, the usual rules apply about
1722 * how long the opcode is.
1724 * All VAX branch displacements come at the end of the instruction.
1725 * For simple branches (1-byte opcode + 1-byte displacement) the last
1726 * operand is coded 'b?' where the "data type" '?' is a clue that we
1727 * may reverse the sense of the branch (complement lowest order bit)
1728 * and branch around a jump. This is by far the most common case.
1729 * That is why the VIT_OPCODE_SYNTHETIC bit is set: it says this is
1730 * a 0-byte op-code followed by 2 or more bytes of operand address.
1732 * If the op-code has VIT_OPCODE_SPECIAL set, then we have a more unusual
1735 * For JBSB & JBR the treatment is the similar, except (1) we have a 'bw'
1736 * option before (2) we can directly JSB/JMP because there is no condition.
1737 * These operands have 'b-' as their access/data type.
1739 * That leaves a bunch of random opcodes: JACBx, JxOBxxx. In these
1740 * cases, we do the same idea. JACBxxx are all marked with a 'b!'
1741 * JAOBxxx & JSOBxxx are marked with a 'b:'.
1744 #if (VIT_OPCODE_SYNTHETIC != 0x80000000)
1745 You have just broken the encoding below
, which assumes the sign bit
1746 means
'I am an imaginary instruction'.
1749 #if (VIT_OPCODE_SPECIAL != 0x40000000)
1750 You have just broken the encoding below
, which assumes the
0x40 M bit means
1751 'I am not to be "optimised" the way normal branches are'.
1754 static const struct vot
1755 synthetic_votstrs
[] =
1757 {"jbsb", {"b-", 0xC0000010}}, /* BSD 4.2 */
1758 /* jsb used already */
1759 {"jbr", {"b-", 0xC0000011}}, /* BSD 4.2 */
1760 {"jr", {"b-", 0xC0000011}}, /* consistent */
1761 {"jneq", {"b?", 0x80000012}},
1762 {"jnequ", {"b?", 0x80000012}},
1763 {"jeql", {"b?", 0x80000013}},
1764 {"jeqlu", {"b?", 0x80000013}},
1765 {"jgtr", {"b?", 0x80000014}},
1766 {"jleq", {"b?", 0x80000015}},
1767 /* un-used opcodes here */
1768 {"jgeq", {"b?", 0x80000018}},
1769 {"jlss", {"b?", 0x80000019}},
1770 {"jgtru", {"b?", 0x8000001a}},
1771 {"jlequ", {"b?", 0x8000001b}},
1772 {"jvc", {"b?", 0x8000001c}},
1773 {"jvs", {"b?", 0x8000001d}},
1774 {"jgequ", {"b?", 0x8000001e}},
1775 {"jcc", {"b?", 0x8000001e}},
1776 {"jlssu", {"b?", 0x8000001f}},
1777 {"jcs", {"b?", 0x8000001f}},
1779 {"jacbw", {"rwrwmwb!", 0xC000003d}},
1780 {"jacbf", {"rfrfmfb!", 0xC000004f}},
1781 {"jacbd", {"rdrdmdb!", 0xC000006f}},
1782 {"jacbb", {"rbrbmbb!", 0xC000009d}},
1783 {"jacbl", {"rlrlmlb!", 0xC00000f1}},
1784 {"jacbg", {"rgrgmgb!", 0xC0004ffd}},
1785 {"jacbh", {"rhrhmhb!", 0xC0006ffd}},
1787 {"jbs", {"rlvbb?", 0x800000e0}},
1788 {"jbc", {"rlvbb?", 0x800000e1}},
1789 {"jbss", {"rlvbb?", 0x800000e2}},
1790 {"jbcs", {"rlvbb?", 0x800000e3}},
1791 {"jbsc", {"rlvbb?", 0x800000e4}},
1792 {"jbcc", {"rlvbb?", 0x800000e5}},
1793 {"jlbs", {"rlb?", 0x800000e8}},
1794 {"jlbc", {"rlb?", 0x800000e9}},
1796 {"jaoblss", {"rlmlb:", 0xC00000f2}},
1797 {"jaobleq", {"rlmlb:", 0xC00000f3}},
1798 {"jsobgeq", {"mlb:", 0xC00000f4}},
1799 {"jsobgtr", {"mlb:", 0xC00000f5}},
1801 /* CASEx has no branch addresses in our conception of it. */
1802 /* You should use ".word ..." statements after the "case ...". */
1804 {"", {"", 0}} /* empty is end sentinel */
1806 }; /* synthetic_votstrs */
1809 * v i p _ b e g i n ( )
1811 * Call me once before you decode any lines.
1812 * I decode votstrs into a hash table at op_hash (which I create).
1813 * I return an error text or null.
1814 * If you want, I will include the 'synthetic' jXXX instructions in the
1815 * instruction table.
1816 * You must nominate metacharacters for eg DEC's "#", "@", "^".
1820 vip_begin (synthetic_too
, immediate
, indirect
, displen
)
1821 int synthetic_too
; /* 1 means include jXXX op-codes. */
1822 const char *immediate
, *indirect
, *displen
;
1824 const struct vot
*vP
; /* scan votstrs */
1825 const char *retval
= 0; /* error text */
1827 op_hash
= hash_new ();
1829 for (vP
= votstrs
; *vP
->vot_name
&& !retval
; vP
++)
1830 retval
= hash_insert (op_hash
, vP
->vot_name
, (PTR
) &vP
->vot_detail
);
1833 for (vP
= synthetic_votstrs
; *vP
->vot_name
&& !retval
; vP
++)
1834 retval
= hash_insert (op_hash
, vP
->vot_name
, (PTR
) &vP
->vot_detail
);
1837 vip_op_defaults (immediate
, indirect
, displen
);
1846 * This converts a string into a vax instruction.
1847 * The string must be a bare single instruction in dec-vax (with BSD4 frobs)
1849 * It provides some error messages: at most one fatal error message (which
1850 * stops the scan) and at most one warning message for each operand.
1851 * The vax instruction is returned in exploded form, since we have no
1852 * knowledge of how you parse (or evaluate) your expressions.
1853 * We do however strip off and decode addressing modes and operation
1856 * The exploded instruction is returned to a struct vit of your choice.
1857 * #include "vax-inst.h" to know what a struct vit is.
1859 * This function's value is a string. If it is not "" then an internal
1860 * logic error was found: read this code to assign meaning to the string.
1861 * No argument string should generate such an error string:
1862 * it means a bug in our code, not in the user's text.
1864 * You MUST have called vip_begin() once before using this function.
1868 vip (vitP
, instring
)
1869 struct vit
*vitP
; /* We build an exploded instruction here. */
1870 char *instring
; /* Text of a vax instruction: we modify. */
1872 /* How to bit-encode this opcode. */
1873 struct vot_wot
*vwP
;
1874 /* 1/skip whitespace.2/scan vot_how */
1877 /* counts number of operands seen */
1878 unsigned char count
;
1879 /* scan operands in struct vit */
1880 struct vop
*operandp
;
1881 /* error over all operands */
1882 const char *alloperr
;
1883 /* Remember char, (we clobber it with '\0' temporarily). */
1885 /* Op-code of this instruction. */
1888 if (*instring
== ' ')
1889 ++instring
; /* Skip leading whitespace. */
1890 for (p
= instring
; *p
&& *p
!= ' '; p
++);; /* MUST end in end-of-string or exactly 1 space. */
1891 /* Scanned up to end of operation-code. */
1892 /* Operation-code is ended with whitespace. */
1893 if (p
- instring
== 0)
1895 vitP
->vit_error
= _("No operator");
1897 memset (vitP
->vit_opcode
, '\0', sizeof (vitP
->vit_opcode
));
1904 * Here with instring pointing to what better be an op-name, and p
1905 * pointing to character just past that.
1906 * We trust instring points to an op-name, with no whitespace.
1908 vwP
= (struct vot_wot
*) hash_find (op_hash
, instring
);
1909 *p
= c
; /* Restore char after op-code. */
1912 vitP
->vit_error
= _("Unknown operator");
1914 memset (vitP
->vit_opcode
, '\0', sizeof (vitP
->vit_opcode
));
1919 * We found a match! So let's pick up as many operands as the
1920 * instruction wants, and even gripe if there are too many.
1921 * We expect comma to separate each operand.
1922 * We let instring track the text, while p tracks a part of the
1927 * The lines below know about 2-byte opcodes starting FD,FE or FF.
1928 * They also understand synthetic opcodes. Note:
1929 * we return 32 bits of opcode, including bucky bits, BUT
1930 * an opcode length is either 8 or 16 bits for vit_opcode_nbytes.
1932 oc
= vwP
->vot_code
; /* The op-code. */
1933 vitP
->vit_opcode_nbytes
= (oc
& 0xFF) >= 0xFD ? 2 : 1;
1934 md_number_to_chars (vitP
->vit_opcode
, oc
, 4);
1935 count
= 0; /* no operands seen yet */
1936 instring
= p
; /* point just past operation code */
1938 for (howp
= vwP
->vot_how
, operandp
= vitP
->vit_operand
;
1939 !(alloperr
&& *alloperr
) && *howp
;
1940 operandp
++, howp
+= 2)
1943 * Here to parse one operand. Leave instring pointing just
1944 * past any one ',' that marks the end of this operand.
1947 as_fatal (_("odd number of bytes in operand description"));
1950 for (q
= instring
; (c
= *q
) && c
!= ','; q
++)
1953 * Q points to ',' or '\0' that ends argument. C is that
1957 operandp
->vop_width
= howp
[1];
1958 operandp
->vop_nbytes
= vax_operand_width_size
[(unsigned) howp
[1]];
1959 operandp
->vop_access
= howp
[0];
1960 vip_op (instring
, operandp
);
1961 *q
= c
; /* Restore input text. */
1962 if (operandp
->vop_error
)
1963 alloperr
= _("Bad operand");
1964 instring
= q
+ (c
? 1 : 0); /* next operand (if any) */
1965 count
++; /* won another argument, may have an operr */
1968 alloperr
= _("Not enough operands");
1972 if (*instring
== ' ')
1973 instring
++; /* Skip whitespace. */
1975 alloperr
= _("Too many operands");
1977 vitP
->vit_error
= alloperr
;
1980 vitP
->vit_operands
= count
;
1986 * Test program for above.
1989 struct vit myvit
; /* build an exploded vax instruction here */
1990 char answer
[100]; /* human types a line of vax assembler here */
1991 char *mybug
; /* "" or an internal logic diagnostic */
1992 int mycount
; /* number of operands */
1993 struct vop
*myvop
; /* scan operands from myvit */
1994 int mysynth
; /* 1 means want synthetic opcodes. */
1995 char my_immediate
[200];
1996 char my_indirect
[200];
1997 char my_displen
[200];
2003 printf ("0 means no synthetic instructions. ");
2004 printf ("Value for vip_begin? ");
2006 sscanf (answer
, "%d", &mysynth
);
2007 printf ("Synthetic opcodes %s be included.\n", mysynth
? "will" : "will not");
2008 printf ("enter immediate symbols eg enter # ");
2009 gets (my_immediate
);
2010 printf ("enter indirect symbols eg enter @ ");
2012 printf ("enter displen symbols eg enter ^ ");
2014 if (p
= vip_begin (mysynth
, my_immediate
, my_indirect
, my_displen
))
2016 error ("vip_begin=%s", p
);
2018 printf ("An empty input line will quit you from the vax instruction parser\n");
2021 printf ("vax instruction: ");
2026 break; /* out of for each input text loop */
2028 vip (&myvit
, answer
);
2029 if (*myvit
.vit_error
)
2031 printf ("ERR:\"%s\"\n", myvit
.vit_error
);
2034 for (mycount
= myvit
.vit_opcode_nbytes
, p
= myvit
.vit_opcode
;
2039 printf ("%02x ", *p
& 0xFF);
2041 printf (" operand count=%d.\n", mycount
= myvit
.vit_operands
);
2042 for (myvop
= myvit
.vit_operand
; mycount
; mycount
--, myvop
++)
2044 printf ("mode=%xx reg=%xx ndx=%xx len='%c'=%c%c%d. expr=\"",
2045 myvop
->vop_mode
, myvop
->vop_reg
, myvop
->vop_ndx
,
2046 myvop
->vop_short
, myvop
->vop_access
, myvop
->vop_width
,
2048 for (p
= myvop
->vop_expr_begin
; p
<= myvop
->vop_expr_end
; p
++)
2053 if (myvop
->vop_error
)
2055 printf (" err:\"%s\"\n", myvop
->vop_error
);
2057 if (myvop
->vop_warn
)
2059 printf (" wrn:\"%s\"\n", myvop
->vop_warn
);
2064 exit (EXIT_SUCCESS
);
2067 #endif /* #ifdef test */
2069 /* end of vax_ins_parse.c */
2071 /* vax_reg_parse.c - convert a VAX register name to a number */
2073 /* Copyright (C) 1987 Free Software Foundation, Inc. A part of GNU. */
2076 * v a x _ r e g _ p a r s e ( )
2078 * Take 3 char.s, the last of which may be `\0` (non-existent)
2079 * and return the VAX register number that they represent.
2081 * Return -1 if they don't form a register name. Good names return
2082 * a number from 0:15 inclusive.
2084 * Case is not important in a name.
2086 * Register names understood are:
2107 #include "safe-ctype.h"
2113 int /* return -1 or 0:15 */
2114 vax_reg_parse (c1
, c2
, c3
, c4
) /* 3 chars of register name */
2115 char c1
, c2
, c3
, c4
; /* c3 == 0 if 2-character reg name */
2117 int retval
; /* return -1:15 */
2122 if (c1
!= '%') /* register prefixes are mandatory for ELF */
2129 if (c4
!= 0) /* register prefixes are not allowed under VMS */
2133 if (c1
== '%') /* register prefixes are optional under a.out */
2139 else if (c3
&& c4
) /* can't be 4 characters long. */
2145 if (ISDIGIT (c2
) && c1
== 'r')
2150 retval
= retval
* 10 + c3
- '0';
2151 retval
= (retval
> 15) ? -1 : retval
;
2152 /* clamp the register value to 1 hex digit */
2155 retval
= -1; /* c3 must be '\0' or a digit */
2157 else if (c3
) /* There are no three letter regs */
2176 else if (c1
== 'p' && c2
== 'c')
2186 * Parse a vax operand in DEC assembler notation.
2187 * For speed, expect a string of whitespace to be reduced to a single ' '.
2188 * This is the case for GNU AS, and is easy for other DEC-compatible
2191 * Knowledge about DEC VAX assembler operand notation lives here.
2192 * This doesn't even know what a register name is, except it believes
2193 * all register names are 2 or 3 characters, and lets vax_reg_parse() say
2194 * what number each name represents.
2195 * It does, however, know that PC, SP etc are special registers so it can
2196 * detect addressing modes that are silly for those registers.
2198 * Where possible, it delivers 1 fatal or 1 warning message if the operand
2199 * is suspect. Exactly what we test for is still evolving.
2207 * There were a number of 'mismatched argument type' bugs to vip_op.
2208 * The most general solution is to typedef each (of many) arguments.
2209 * We used instead a typedef'd argument block. This is less modular
2210 * than using separate return pointers for each result, but runs faster
2211 * on most engines, and seems to keep programmers happy. It will have
2212 * to be done properly if we ever want to use vip_op as a general-purpose
2213 * module (it was designed to be).
2217 * Doesn't support DEC "G^" format operands. These always take 5 bytes
2218 * to express, and code as modes 8F or 9F. Reason: "G^" deprives you of
2219 * optimising to (say) a "B^" if you are lucky in the way you link.
2220 * When someone builds a linker smart enough to convert "G^" to "B^", "W^"
2221 * whenever possible, then we should implement it.
2222 * If there is some other use for "G^", feel free to code it in!
2227 * If I nested if()s more, I could avoid testing (*err) which would save
2228 * time, space and page faults. I didn't nest all those if()s for clarity
2229 * and because I think the mode testing can be re-arranged 1st to test the
2230 * commoner constructs 1st. Does anybody have statistics on this?
2236 * In future, we should be able to 'compose' error messages in a scratch area
2237 * and give the user MUCH more informative error messages. Although this takes
2238 * a little more code at run-time, it will make this module much more self-
2239 * documenting. As an example of what sucks now: most error messages have
2240 * hardwired into them the DEC VAX metacharacters "#^@" which are nothing like
2241 * the Un*x characters "$`*", that most users will expect from this AS.
2245 * The input is a string, ending with '\0'.
2247 * We also require a 'hint' of what kind of operand is expected: so
2248 * we can remind caller not to write into literals for instance.
2250 * The output is a skeletal instruction.
2252 * The algorithm has two parts.
2253 * 1. extract the syntactic features (parse off all the @^#-()+[] mode crud);
2254 * 2. express the @^#-()+[] as some parameters suited to further analysis.
2256 * 2nd step is where we detect the googles of possible invalid combinations
2257 * a human (or compiler) might write. Note that if we do a half-way
2258 * decent assembler, we don't know how long to make (eg) displacement
2259 * fields when we first meet them (because they may not have defined values).
2260 * So we must wait until we know how many bits are needed for each address,
2261 * then we can know both length and opcodes of instructions.
2262 * For reason(s) above, we will pass to our caller a 'broken' instruction
2263 * of these major components, from which our caller can generate instructions:
2264 * - displacement length I^ S^ L^ B^ W^ unspecified
2266 * - register R0-R15 or absent
2267 * - index register R0-R15 or absent
2268 * - expression text what we don't parse
2269 * - error text(s) why we couldn't understand the operand
2273 * To decode output of this, test errtxt. If errtxt[0] == '\0', then
2274 * we had no errors that prevented parsing. Also, if we ever report
2275 * an internal bug, errtxt[0] is set non-zero. So one test tells you
2276 * if the other outputs are to be taken seriously.
2280 * Because this module is useful for both VMS and UN*X style assemblers
2281 * and because of the variety of UN*X assemblers we must recognise
2282 * the different conventions for assembler operand notation. For example
2283 * VMS says "#42" for immediate mode, while most UN*X say "$42".
2284 * We permit arbitrary sets of (single) characters to represent the
2285 * 3 concepts that DEC writes '#', '@', '^'.
2288 /* character tests */
2289 #define VIP_IMMEDIATE 01 /* Character is like DEC # */
2290 #define VIP_INDIRECT 02 /* Char is like DEC @ */
2291 #define VIP_DISPLEN 04 /* Char is like DEC ^ */
2293 #define IMMEDIATEP(c) (vip_metacharacters [(c)&0xff]&VIP_IMMEDIATE)
2294 #define INDIRECTP(c) (vip_metacharacters [(c)&0xff]&VIP_INDIRECT)
2295 #define DISPLENP(c) (vip_metacharacters [(c)&0xff]&VIP_DISPLEN)
2297 /* We assume 8 bits per byte. Use vip_op_defaults() to set these up BEFORE we
2301 #if defined(CONST_TABLE)
2303 #define I VIP_IMMEDIATE,
2304 #define S VIP_INDIRECT,
2305 #define D VIP_DISPLEN,
2307 vip_metacharacters
[256] =
2309 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/* ^@ ^A ^B ^C ^D ^E ^F ^G ^H ^I ^J ^K ^L ^M ^N ^O*/
2310 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/* ^P ^Q ^R ^S ^T ^U ^V ^W ^X ^Y ^Z ^[ ^\ ^] ^^ ^_ */
2311 _ _ _ _ I _ _ _ _ _ S _ _ _ _ _
/* sp ! " # $ % & ' ( ) * + , - . / */
2312 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/*0 1 2 3 4 5 6 7 8 9 : ; < = > ?*/
2313 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/*@ A B C D E F G H I J K L M N O*/
2314 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/*P Q R S T U V W X Y Z [ \ ] ^ _*/
2315 D _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/*` a b c d e f g h i j k l m n o*/
2316 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/*p q r s t u v w x y z { | } ~ ^?*/
2318 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
2319 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
2320 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
2321 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
2322 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
2323 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
2324 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
2325 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
2332 static char vip_metacharacters
[256];
2335 vip_op_1 (bit
, syms
)
2341 while ((t
= *syms
++) != 0)
2342 vip_metacharacters
[t
] |= bit
;
2345 /* Can be called any time. More arguments may appear in future. */
2347 vip_op_defaults (immediate
, indirect
, displen
)
2348 const char *immediate
;
2349 const char *indirect
;
2350 const char *displen
;
2352 vip_op_1 (VIP_IMMEDIATE
, immediate
);
2353 vip_op_1 (VIP_INDIRECT
, indirect
);
2354 vip_op_1 (VIP_DISPLEN
, displen
);
2361 * Dec defines the semantics of address modes (and values)
2362 * by a two-letter code, explained here.
2364 * letter 1: access type
2366 * a address calculation - no data access, registers forbidden
2367 * b branch displacement
2368 * m read - let go of bus - write back "modify"
2370 * v bit field address: like 'a' but registers are OK
2372 * space no operator (eg ".long foo") [our convention]
2374 * letter 2: data type (i.e. width, alignment)
2377 * d double precision floating point (D format)
2378 * f single precision floating point (F format)
2379 * g G format floating
2380 * h H format floating
2385 * ? simple synthetic branch operand
2386 * - unconditional synthetic JSB/JSR operand
2387 * ! complex synthetic branch operand
2389 * The '-?!' letter 2's are not for external consumption. They are used
2390 * for various assemblers. Generally, all unknown widths are assumed 0.
2391 * We don't limit your choice of width character.
2393 * DEC operands are hard work to parse. For example, '@' as the first
2394 * character means indirect (deferred) mode but elsewhere it is a shift
2396 * The long-winded explanation of how this is supposed to work is
2397 * cancelled. Read a DEC vax manual.
2398 * We try hard not to parse anything that MIGHT be part of the expression
2399 * buried in that syntax. For example if we see @...(Rn) we don't check
2400 * for '-' before the '(' because mode @-(Rn) does not exist.
2402 * After parsing we have:
2404 * at 1 if leading '@' (or Un*x '*')
2405 * len takes one value from " bilsw". eg B^ -> 'b'.
2406 * hash 1 if leading '#' (or Un*x '$')
2407 * expr_begin, expr_end the expression we did not parse
2408 * even though we don't interpret it, we make use
2409 * of its presence or absence.
2410 * sign -1: -(Rn) 0: absent +1: (Rn)+
2411 * paren 1 if () are around register
2412 * reg major register number 0:15 -1 means absent
2413 * ndx index register number 0:15 -1 means absent
2415 * Again, I dare not explain it: just trace ALL the code!
2419 vip_op (optext
, vopP
)
2420 /* user's input string e.g.: "@B^foo@bar(AP)[FP]:" */
2422 /* Input fields: vop_access, vop_width.
2423 Output fields: _ndx, _reg, _mode, _short, _warn,
2424 _error _expr_begin, _expr_end, _nbytes.
2425 vop_nbytes : number of bytes in a datum. */
2428 /* track operand text forward */
2430 /* track operand text backward */
2432 /* 1 if leading '@' ('*') seen */
2434 /* one of " bilsw" */
2436 /* 1 if leading '#' ('$') seen */
2440 /* 1 if () surround register */
2442 /* register number, -1:absent */
2444 /* index register number -1:absent */
2446 /* report illegal operand, ""==OK */
2447 /* " " is a FAKE error: means we won */
2448 /* ANY err that begins with ' ' is a fake. */
2449 /* " " is converted to "" before return */
2451 /* warn about weird modes pf address */
2453 /* preserve q in case we backup */
2455 /* build up 4-bit operand mode here */
2456 /* note: index mode is in ndx, this is */
2457 /* the major mode of operand address */
2460 * Notice how we move wrong-arg-type bugs INSIDE this module: if we
2461 * get the types wrong below, we lose at compile time rather than at
2464 char access_mode
; /* vop_access. */
2465 char width
; /* vop_width. */
2467 access_mode
= vopP
->vop_access
;
2468 width
= vopP
->vop_width
;
2469 /* None of our code bugs (yet), no user text errors, no warnings
2475 if (*p
== ' ') /* Expect all whitespace reduced to ' '. */
2476 p
++; /* skip over whitespace */
2478 if ((at
= INDIRECTP (*p
)) != 0)
2479 { /* 1 if *p=='@'(or '*' for Un*x) */
2480 p
++; /* at is determined */
2481 if (*p
== ' ') /* Expect all whitespace reduced to ' '. */
2482 p
++; /* skip over whitespace */
2486 * This code is subtle. It tries to detect all legal (letter)'^'
2487 * but it doesn't waste time explicitly testing for premature '\0' because
2488 * this case is rejected as a mismatch against either (letter) or '^'.
2495 if (DISPLENP (p
[1]) && strchr ("bilws", len
= c
))
2496 p
+= 2; /* skip (letter) '^' */
2497 else /* no (letter) '^' seen */
2498 len
= ' '; /* len is determined */
2501 if (*p
== ' ') /* Expect all whitespace reduced to ' '. */
2502 p
++; /* skip over whitespace */
2504 if ((hash
= IMMEDIATEP (*p
)) != 0) /* 1 if *p=='#' ('$' for Un*x) */
2505 p
++; /* hash is determined */
2508 * p points to what may be the beginning of an expression.
2509 * We have peeled off the front all that is peelable.
2510 * We know at, len, hash.
2512 * Lets point q at the end of the text and parse that (backwards).
2515 for (q
= p
; *q
; q
++)
2517 q
--; /* now q points at last char of text */
2519 if (*q
== ' ' && q
>= p
) /* Expect all whitespace reduced to ' '. */
2521 /* reverse over whitespace, but don't */
2522 /* run back over *p */
2525 * As a matter of policy here, we look for [Rn], although both Rn and S^#
2526 * forbid [Rn]. This is because it is easy, and because only a sick
2527 * cyborg would have [...] trailing an expression in a VAX-like assembler.
2528 * A meticulous parser would first check for Rn followed by '(' or '['
2529 * and not parse a trailing ']' if it found another. We just ban expressions
2534 while (q
>= p
&& *q
!= '[')
2536 /* either q<p or we got matching '[' */
2538 err
= _("no '[' to match ']'");
2542 * Confusers like "[]" will eventually lose with a bad register
2543 * name error. So again we don't need to check for early '\0'.
2546 ndx
= vax_reg_parse (q
[1], q
[2], 0, 0);
2547 else if (q
[4] == ']')
2548 ndx
= vax_reg_parse (q
[1], q
[2], q
[3], 0);
2549 else if (q
[5] == ']')
2550 ndx
= vax_reg_parse (q
[1], q
[2], q
[3], q
[4]);
2554 * Since we saw a ']' we will demand a register name in the [].
2555 * If luser hasn't given us one: be rude.
2558 err
= _("bad register in []");
2560 err
= _("[PC] index banned");
2562 q
--; /* point q just before "[...]" */
2566 ndx
= -1; /* no ']', so no iNDeX register */
2569 * If err = "..." then we lost: run away.
2570 * Otherwise ndx == -1 if there was no "[...]".
2571 * Otherwise, ndx is index register number, and q points before "[...]".
2574 if (*q
== ' ' && q
>= p
) /* Expect all whitespace reduced to ' '. */
2576 /* reverse over whitespace, but don't */
2577 /* run back over *p */
2580 sign
= 0; /* no ()+ or -() seen yet */
2582 if (q
> p
+ 3 && *q
== '+' && q
[-1] == ')')
2584 sign
= 1; /* we saw a ")+" */
2585 q
--; /* q points to ')' */
2588 if (*q
== ')' && q
> p
+ 2)
2590 paren
= 1; /* assume we have "(...)" */
2591 while (q
>= p
&& *q
!= '(')
2593 /* either q<p or we got matching '(' */
2595 err
= _("no '(' to match ')'");
2599 * Confusers like "()" will eventually lose with a bad register
2600 * name error. So again we don't need to check for early '\0'.
2603 reg
= vax_reg_parse (q
[1], q
[2], 0, 0);
2604 else if (q
[4] == ')')
2605 reg
= vax_reg_parse (q
[1], q
[2], q
[3], 0);
2606 else if (q
[5] == ')')
2607 reg
= vax_reg_parse (q
[1], q
[2], q
[3], q
[4]);
2611 * Since we saw a ')' we will demand a register name in the ')'.
2612 * This is nasty: why can't our hypothetical assembler permit
2613 * parenthesised expressions? BECAUSE I AM LAZY! That is why.
2614 * Abuse luser if we didn't spy a register name.
2618 /* JF allow parenthesized expressions. I hope this works */
2622 /* err = "unknown register in ()"; */
2625 q
--; /* point just before '(' of "(...)" */
2627 * If err == "..." then we lost. Run away.
2628 * Otherwise if reg >= 0 then we saw (Rn).
2632 * If err == "..." then we lost.
2633 * Otherwise paren==1 and reg = register in "()".
2639 * If err == "..." then we lost.
2640 * Otherwise, q points just before "(Rn)", if any.
2641 * If there was a "(...)" then paren==1, and reg is the register.
2645 * We should only seek '-' of "-(...)" if:
2646 * we saw "(...)" paren == 1
2647 * we have no errors so far ! *err
2648 * we did not see '+' of "(...)+" sign < 1
2649 * We don't check len. We want a specific error message later if
2650 * user tries "x^...-(Rn)". This is a feature not a bug.
2654 if (paren
&& sign
< 1)/* !sign is adequate test */
2663 * We have back-tracked over most
2664 * of the crud at the end of an operand.
2665 * Unless err, we know: sign, paren. If paren, we know reg.
2666 * The last case is of an expression "Rn".
2667 * This is worth hunting for if !err, !paren.
2668 * We wouldn't be here if err.
2669 * We remember to save q, in case we didn't want "Rn" anyway.
2673 if (*q
== ' ' && q
>= p
) /* Expect all whitespace reduced to ' '. */
2675 /* reverse over whitespace, but don't */
2676 /* run back over *p */
2677 /* room for Rn or Rnn (include prefix) exactly? */
2678 if (q
> p
&& q
< p
+ 4)
2679 reg
= vax_reg_parse (p
[0], p
[1],
2680 q
< p
+ 2 ? 0 : p
[2],
2681 q
< p
+ 3 ? 0 : p
[3]);
2683 reg
= -1; /* always comes here if no register at all */
2685 * Here with a definitive reg value.
2696 * have reg. -1:absent; else 0:15
2700 * We have: err, at, len, hash, ndx, sign, paren, reg.
2701 * Also, any remaining expression is from *p through *q inclusive.
2702 * Should there be no expression, q==p-1. So expression length = q-p+1.
2703 * This completes the first part: parsing the operand text.
2707 * We now want to boil the data down, checking consistency on the way.
2708 * We want: len, mode, reg, ndx, err, p, q, wrn, bug.
2709 * We will deliver a 4-bit reg, and a 4-bit mode.
2713 * Case of branch operand. Different. No L^B^W^I^S^ allowed for instance.
2727 * p:q whatever was input
2729 * err " " or error message, and other outputs trashed
2731 /* branch operands have restricted forms */
2732 if ((!err
|| !*err
) && access_mode
== 'b')
2734 if (at
|| hash
|| sign
|| paren
|| ndx
>= 0 || reg
>= 0 || len
!= ' ')
2735 err
= _("invalid branch operand");
2740 /* Since nobody seems to use it: comment this 'feature'(?) out for now. */
2743 * Case of stand-alone operand. e.g. ".long foo"
2757 * p:q whatever was input
2759 * err " " or error message, and other outputs trashed
2761 if ((!err
|| !*err
) && access_mode
== ' ')
2764 err
= _("address prohibits @");
2766 err
= _("address prohibits #");
2770 err
= _("address prohibits -()");
2772 err
= _("address prohibits ()+");
2775 err
= _("address prohibits ()");
2777 err
= _("address prohibits []");
2779 err
= _("address prohibits register");
2780 else if (len
!= ' ')
2781 err
= _("address prohibits displacement length specifier");
2784 err
= " "; /* succeed */
2788 #endif /*#Ifdef NEVER*/
2794 * len 's' definition
2796 * p:q demand not empty
2797 * sign 0 by paren==0
2798 * paren 0 by "()" scan logic because "S^" seen
2799 * reg -1 or nn by mistake
2808 if ((!err
|| !*err
) && len
== 's')
2810 if (!hash
|| paren
|| at
|| ndx
>= 0)
2811 err
= _("invalid operand of S^#");
2817 * SHIT! we saw S^#Rnn ! put the Rnn back in
2818 * expression. KLUDGE! Use oldq so we don't
2819 * need to know exact length of reg name.
2825 * We have all the expression we will ever get.
2828 err
= _("S^# needs expression");
2829 else if (access_mode
== 'r')
2831 err
= " "; /* WIN! */
2835 err
= _("S^# may only read-access");
2840 * Case of -(Rn), which is weird case.
2846 * sign -1 by definition
2847 * paren 1 by definition
2848 * reg present by definition
2854 * exp "" enforce empty expression
2855 * ndx optional warn if same as reg
2857 if ((!err
|| !*err
) && sign
< 0)
2859 if (len
!= ' ' || hash
|| at
|| p
<= q
)
2860 err
= _("invalid operand of -()");
2863 err
= " "; /* win */
2866 wrn
= _("-(PC) unpredictable");
2867 else if (reg
== ndx
)
2868 wrn
= _("[]index same as -()register: unpredictable");
2873 * We convert "(Rn)" to "@Rn" for our convenience.
2874 * (I hope this is convenient: has someone got a better way to parse this?)
2875 * A side-effect of this is that "@Rn" is a valid operand.
2877 if (paren
&& !sign
&& !hash
&& !at
&& len
== ' ' && p
> q
)
2884 * Case of (Rn)+, which is slightly different.
2890 * sign +1 by definition
2891 * paren 1 by definition
2892 * reg present by definition
2898 * exp "" enforce empty expression
2899 * ndx optional warn if same as reg
2901 if ((!err
|| !*err
) && sign
> 0)
2903 if (len
!= ' ' || hash
|| p
<= q
)
2904 err
= _("invalid operand of ()+");
2907 err
= " "; /* win */
2908 mode
= 8 + (at
? 1 : 0);
2910 wrn
= _("(PC)+ unpredictable");
2911 else if (reg
== ndx
)
2912 wrn
= _("[]index same as ()+register: unpredictable");
2917 * Case of #, without S^.
2921 * hash 1 by definition
2934 if ((!err
|| !*err
) && hash
)
2936 if (len
!= 'i' && len
!= ' ')
2937 err
= _("# conflicts length");
2939 err
= _("# bars register");
2945 * SHIT! we saw #Rnn! Put the Rnn back into the expression.
2946 * By using oldq, we don't need to know how long Rnn was.
2950 reg
= -1; /* no register any more */
2952 err
= " "; /* win */
2954 /* JF a bugfix, I think! */
2955 if (at
&& access_mode
== 'a')
2956 vopP
->vop_nbytes
= 4;
2958 mode
= (at
? 9 : 8);
2960 if ((access_mode
== 'm' || access_mode
== 'w') && !at
)
2961 wrn
= _("writing or modifying # is unpredictable");
2965 * If !*err, then sign == 0
2970 * Case of Rn. We separate this one because it has a few special
2971 * errors the remaining modes lack.
2975 * hash 0 by program logic
2977 * sign 0 by program logic
2978 * paren 0 by definition
2979 * reg present by definition
2984 * len ' ' enforce no length
2985 * exp "" enforce empty expression
2986 * ndx optional warn if same as reg
2988 if ((!err
|| !*err
) && !paren
&& reg
>= 0)
2991 err
= _("length not needed");
2994 err
= " "; /* win */
2998 err
= _("can't []index a register, because it has no address");
2999 else if (access_mode
== 'a')
3000 err
= _("a register has no address");
3004 * Idea here is to detect from length of datum
3005 * and from register number if we will touch PC.
3007 * vop_nbytes is number of bytes in operand.
3008 * Compute highest byte affected, compare to PC0.
3010 if ((vopP
->vop_nbytes
+ reg
* 4) > 60)
3011 wrn
= _("PC part of operand unpredictable");
3012 err
= " "; /* win */
3017 * If !*err, sign == 0
3019 * paren == 1 OR reg==-1
3023 * Rest of cases fit into one bunch.
3026 * len ' ' or 'b' or 'w' or 'l'
3027 * hash 0 by program logic
3028 * p:q expected (empty is not an error)
3029 * sign 0 by program logic
3034 * out: mode 10 + @ + len
3036 * len ' ' or 'b' or 'w' or 'l'
3038 * ndx optional warn if same as reg
3042 err
= " "; /* win (always) */
3043 mode
= 10 + (at
? 1 : 0);
3050 case ' ': /* assumed B^ until our caller changes it */
3057 * here with completely specified mode
3065 err
= 0; /* " " is no longer an error */
3067 vopP
->vop_mode
= mode
;
3068 vopP
->vop_reg
= reg
;
3069 vopP
->vop_short
= len
;
3070 vopP
->vop_expr_begin
= p
;
3071 vopP
->vop_expr_end
= q
;
3072 vopP
->vop_ndx
= ndx
;
3073 vopP
->vop_error
= err
;
3074 vopP
->vop_warn
= wrn
;
3079 Summary of vip_op outputs.
3083 {@}Rn 5+@ n ' ' optional
3084 branch operand 0 -1 ' ' -1
3086 -(Rn) 7 n ' ' optional
3087 {@}(Rn)+ 8+@ n ' ' optional
3088 {@}#foo, no S^ 8+@ PC " i" optional
3089 {@}{q^}{(Rn)} 10+@+q option " bwl" optional
3093 #ifdef TEST /* #Define to use this testbed. */
3096 * Follows a test program for this function.
3097 * We declare arrays non-local in case some of our tiny-minded machines
3098 * default to small stacks. Also, helps with some debuggers.
3103 char answer
[100]; /* human types into here */
3116 int my_operand_length
;
3117 char my_immediate
[200];
3118 char my_indirect
[200];
3119 char my_displen
[200];
3123 printf ("enter immediate symbols eg enter # ");
3124 gets (my_immediate
);
3125 printf ("enter indirect symbols eg enter @ ");
3127 printf ("enter displen symbols eg enter ^ ");
3129 vip_op_defaults (my_immediate
, my_indirect
, my_displen
);
3132 printf ("access,width (eg 'ab' or 'wh') [empty line to quit] : ");
3136 exit (EXIT_SUCCESS
);
3137 myaccess
= answer
[0];
3138 mywidth
= answer
[1];
3142 my_operand_length
= 1;
3145 my_operand_length
= 8;
3148 my_operand_length
= 4;
3151 my_operand_length
= 16;
3154 my_operand_length
= 32;
3157 my_operand_length
= 4;
3160 my_operand_length
= 16;
3163 my_operand_length
= 8;
3166 my_operand_length
= 2;
3171 my_operand_length
= 0;
3175 my_operand_length
= 2;
3176 printf ("I dn't understand access width %c\n", mywidth
);
3179 printf ("VAX assembler instruction operand: ");
3182 mybug
= vip_op (answer
, myaccess
, mywidth
, my_operand_length
,
3183 &mymode
, &myreg
, &mylen
, &myleft
, &myright
, &myndx
,
3187 printf ("error: \"%s\"\n", myerr
);
3189 printf (" bug: \"%s\"\n", mybug
);
3194 printf ("warning: \"%s\"\n", mywrn
);
3195 mumble ("mode", mymode
);
3196 mumble ("register", myreg
);
3197 mumble ("index", myndx
);
3198 printf ("width:'%c' ", mylen
);
3199 printf ("expression: \"");
3200 while (myleft
<= myright
)
3201 putchar (*myleft
++);
3207 mumble (text
, value
)
3211 printf ("%s:", text
);
3213 printf ("%xx", value
);
3219 #endif /* ifdef TEST */
3223 int md_short_jump_size
= 3;
3224 int md_long_jump_size
= 6;
3225 const int md_reloc_size
= 8; /* Size of relocation record */
3228 md_create_short_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
3231 addressT to_addr ATTRIBUTE_UNUSED
;
3232 fragS
*frag ATTRIBUTE_UNUSED
;
3233 symbolS
*to_symbol ATTRIBUTE_UNUSED
;
3237 /* This former calculation was off by two:
3238 offset = to_addr - (from_addr + 1);
3239 We need to account for the one byte instruction and also its
3240 two byte operand. */
3241 offset
= to_addr
- (from_addr
+ 1 + 2);
3242 *ptr
++ = VAX_BRW
; /* branch with word (16 bit) offset */
3243 md_number_to_chars (ptr
, offset
, 2);
3247 md_create_long_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
3249 addressT from_addr ATTRIBUTE_UNUSED
;
3256 offset
= to_addr
- S_GET_VALUE (to_symbol
);
3257 *ptr
++ = VAX_JMP
; /* arbitrary jump */
3258 *ptr
++ = VAX_ABSOLUTE_MODE
;
3259 md_number_to_chars (ptr
, offset
, 4);
3260 fix_new (frag
, ptr
- frag
->fr_literal
, 4, to_symbol
, (long) 0, 0, NO_RELOC
);
3264 const char *md_shortopts
= "d:STt:V+1h:Hv::";
3265 #elif defined(OBJ_ELF)
3266 const char *md_shortopts
= "d:STt:VkKQ:";
3268 const char *md_shortopts
= "d:STt:V";
3270 struct option md_longopts
[] = {
3272 #define OPTION_PIC (OPTION_MD_BASE)
3273 {"pic", no_argument
, NULL
, OPTION_PIC
},
3275 {NULL
, no_argument
, NULL
, 0}
3277 size_t md_longopts_size
= sizeof (md_longopts
);
3280 md_parse_option (c
, arg
)
3287 as_warn (_("SYMBOL TABLE not implemented"));
3291 as_warn (_("TOKEN TRACE not implemented"));
3295 as_warn (_("Displacement length %s ignored!"), arg
);
3299 as_warn (_("I don't need or use temp. file \"%s\"."), arg
);
3303 as_warn (_("I don't use an interpass file! -V ignored"));
3307 case '+': /* For g++. Hash any name > 31 chars long. */
3308 flag_hash_long_names
= 1;
3311 case '1': /* For backward compatibility */
3315 case 'H': /* Show new symbol after hash truncation */
3316 flag_show_after_trunc
= 1;
3319 case 'h': /* No hashing of mixed-case names */
3321 extern char vms_name_mapping
;
3322 vms_name_mapping
= atoi (arg
);
3323 flag_no_hash_mixed_case
= 1;
3329 extern char *compiler_version_string
;
3330 if (!arg
|| !*arg
|| access (arg
, 0) == 0)
3331 return 0; /* have caller show the assembler version */
3332 compiler_version_string
= arg
;
3341 break; /* -pic, Position Independent Code */
3343 /* -Qy, -Qn: SVR4 arguments controlling whether a .comment
3344 section should be emitted or not. FIXME: Not implemented. */
3357 md_show_usage (stream
)
3360 fprintf (stream
, _("\
3362 -d LENGTH ignored\n\
3369 fprintf (stream
, _("\
3371 -+ hash encode names longer than 31 characters\n\
3372 -1 `const' handling compatible with gcc 1.x\n\
3373 -H show new symbol after hash truncation\n\
3374 -h NUM don't hash mixed-case names, and adjust case:\n\
3375 0 = upper, 2 = lower, 3 = preserve case\n\
3376 -v\"VERSION\" code being assembled was produced by compiler \"VERSION\"\n"));
3380 /* We have no need to default values of symbols. */
3383 md_undefined_symbol (name
)
3384 char *name ATTRIBUTE_UNUSED
;
3389 /* Round up a section size to the appropriate boundary. */
3391 md_section_align (segment
, size
)
3392 segT segment ATTRIBUTE_UNUSED
;
3395 return size
; /* Byte alignment is fine */
3398 /* Exactly what point is a PC-relative offset relative TO?
3399 On the vax, they're relative to the address of the offset, plus
3402 md_pcrel_from (fixP
)
3405 return fixP
->fx_size
+ fixP
->fx_where
+ fixP
->fx_frag
->fr_address
;
3409 #ifndef BFD_ASSEMBLER
3411 tc_headers_hook(headers
)
3412 object_headers
*headers
;
3415 N_SET_INFO(headers
->header
, OMAGIC
, M_VAX4K_NETBSD
, 0);
3416 headers
->header
.a_info
= htonl (headers
->header
.a_info
);
3419 #endif /* !BFD_ASSEMBLER */
3420 #endif /* OBJ_AOUT */
3422 #ifdef BFD_ASSEMBLER
3424 tc_gen_reloc (section
, fixp
)
3425 asection
*section ATTRIBUTE_UNUSED
;
3429 bfd_reloc_code_real_type code
;
3434 if (fixp
->fx_r_type
!= BFD_RELOC_NONE
)
3436 code
= fixp
->fx_r_type
;
3442 case BFD_RELOC_8_PCREL
:
3443 case BFD_RELOC_16_PCREL
:
3444 case BFD_RELOC_32_PCREL
:
3446 case BFD_RELOC_8_GOT_PCREL
:
3447 case BFD_RELOC_16_GOT_PCREL
:
3448 case BFD_RELOC_32_GOT_PCREL
:
3449 case BFD_RELOC_8_PLT_PCREL
:
3450 case BFD_RELOC_16_PLT_PCREL
:
3451 case BFD_RELOC_32_PLT_PCREL
:
3455 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
3456 _("Cannot make %s relocation PC relative"),
3457 bfd_get_reloc_code_name (code
));
3463 #define F(SZ,PCREL) (((SZ) << 1) + (PCREL))
3464 switch (F (fixp
->fx_size
, fixp
->fx_pcrel
))
3466 #define MAP(SZ,PCREL,TYPE) case F(SZ,PCREL): code = (TYPE); break
3467 MAP (1, 0, BFD_RELOC_8
);
3468 MAP (2, 0, BFD_RELOC_16
);
3469 MAP (4, 0, BFD_RELOC_32
);
3470 MAP (1, 1, BFD_RELOC_8_PCREL
);
3471 MAP (2, 1, BFD_RELOC_16_PCREL
);
3472 MAP (4, 1, BFD_RELOC_32_PCREL
);
3480 reloc
= (arelent
*) xmalloc (sizeof (arelent
));
3481 reloc
->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
3482 *reloc
->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
3483 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
3486 reloc
->addend
= fixp
->fx_addnumber
;
3490 reloc
->addend
= fixp
->fx_offset
;
3493 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, code
);
3494 assert (reloc
->howto
!= 0);
3498 #endif /* BFD_ASSEMBLER */
3500 /* end of tc-vax.c */