1 /* tc-vax.c - vax-specific -
2 Copyright (C) 1987, 91, 92, 93, 94, 95, 98, 1999
3 Free Software Foundation, Inc.
5 This file is part of GAS, the GNU Assembler.
7 GAS is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GAS is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GAS; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
25 #include "obstack.h" /* For FRAG_APPEND_1_CHAR macro in "frags.h" */
27 /* These chars start a comment anywhere in a source file (except inside
29 const char comment_chars
[] = "#";
31 /* These chars only start a comment at the beginning of a line. */
32 /* Note that for the VAX the are the same as comment_chars above. */
33 const char line_comment_chars
[] = "#";
35 const char line_separator_chars
[] = "";
37 /* Chars that can be used to separate mant from exp in floating point nums */
38 const char EXP_CHARS
[] = "eE";
40 /* Chars that mean this number is a floating point constant */
42 /* or 0H1.234E-12 (see exp chars above) */
43 const char FLT_CHARS
[] = "dDfFgGhH";
45 /* Also be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
46 changed in read.c . Ideally it shouldn't have to know about it at all,
47 but nothing is ideal around here. */
49 /* Hold details of an operand expression */
50 static expressionS exp_of_operand
[VIT_MAX_OPERANDS
];
51 static segT seg_of_operand
[VIT_MAX_OPERANDS
];
53 /* A vax instruction after decoding. */
56 /* Hold details of big operands. */
57 LITTLENUM_TYPE big_operand_bits
[VIT_MAX_OPERANDS
][SIZE_OF_LARGE_NUMBER
];
58 FLONUM_TYPE float_operand
[VIT_MAX_OPERANDS
];
59 /* Above is made to point into big_operand_bits by md_begin(). */
61 int flag_hash_long_names
; /* -+ */
62 int flag_one
; /* -1 */
63 int flag_show_after_trunc
; /* -H */
64 int flag_no_hash_mixed_case
; /* -h NUM */
67 * For VAX, relative addresses of "just the right length" are easy.
68 * The branch displacement is always the last operand, even in
69 * synthetic instructions.
70 * For VAX, we encode the relax_substateTs (in e.g. fr_substate) as:
72 * 4 3 2 1 0 bit number
73 * ---/ /--+-------+-------+-------+-------+-------+
74 * | what state ? | how long ? |
75 * ---/ /--+-------+-------+-------+-------+-------+
77 * The "how long" bits are 00=byte, 01=word, 10=long.
78 * This is a Un*x convention.
79 * Not all lengths are legit for a given value of (what state).
80 * The "how long" refers merely to the displacement length.
81 * The address usually has some constant bytes in it as well.
84 groups for VAX address relaxing.
87 length of byte, word, long
89 2a. J<cond> where <cond> is a simple flag test.
90 length of byte, word, long.
91 VAX opcodes are: (Hex)
104 Always, you complement 0th bit to reverse condition.
105 Always, 1-byte opcode, then 1-byte displacement.
107 2b. J<cond> where cond tests a memory bit.
108 length of byte, word, long.
109 Vax opcodes are: (Hex)
118 Always, you complement 0th bit to reverse condition.
119 Always, 1-byte opcde, longword-address, byte-address, 1-byte-displacement
121 2c. J<cond> where cond tests low-order memory bit
122 length of byte,word,long.
123 Vax opcodes are: (Hex)
126 Always, you complement 0th bit to reverse condition.
127 Always, 1-byte opcode, longword-address, 1-byte displacement.
130 length of byte,word,long.
131 Vax opcodes are: (Hex)
134 These are like (2) but there is no condition to reverse.
135 Always, 1 byte opcode, then displacement/absolute.
138 length of word, long.
139 Vax opcodes are: (Hex)
147 Always, we cannot reverse the sense of the branch; we have a word
149 The double-byte op-codes don't hurt: we never want to modify the
150 opcode, so we don't care how many bytes are between the opcode and
154 length of long, long, byte.
155 Vax opcodes are: (Hex)
160 Always, we cannot reverse the sense of the branch; we have a byte
163 The only time we need to modify the opcode is for class 2 instructions.
164 After relax() we may complement the lowest order bit of such instruction
165 to reverse sense of branch.
167 For class 2 instructions, we store context of "where is the opcode literal".
168 We can change an opcode's lowest order bit without breaking anything else.
170 We sometimes store context in the operand literal. This way we can figure out
171 after relax() what the original addressing mode was.
174 /* These displacements are relative to the start address of the
175 displacement. The first letter is Byte, Word. 2nd letter is
176 Forward, Backward. */
179 #define WF (2+ 32767)
180 #define WB (2+-32768)
181 /* Dont need LF, LB because they always reach. [They are coded as 0.] */
184 #define C(a,b) ENCODE_RELAX(a,b)
185 /* This macro has no side-effects. */
186 #define ENCODE_RELAX(what,length) (((what) << 2) + (length))
188 const relax_typeS md_relax_table
[] =
190 {1, 1, 0, 0}, /* error sentinel 0,0 */
191 {1, 1, 0, 0}, /* unused 0,1 */
192 {1, 1, 0, 0}, /* unused 0,2 */
193 {1, 1, 0, 0}, /* unused 0,3 */
194 {BF
+ 1, BB
+ 1, 2, C (1, 1)},/* B^"foo" 1,0 */
195 {WF
+ 1, WB
+ 1, 3, C (1, 2)},/* W^"foo" 1,1 */
196 {0, 0, 5, 0}, /* L^"foo" 1,2 */
197 {1, 1, 0, 0}, /* unused 1,3 */
198 {BF
, BB
, 1, C (2, 1)}, /* b<cond> B^"foo" 2,0 */
199 {WF
+ 2, WB
+ 2, 4, C (2, 2)},/* br.+? brw X 2,1 */
200 {0, 0, 7, 0}, /* br.+? jmp X 2,2 */
201 {1, 1, 0, 0}, /* unused 2,3 */
202 {BF
, BB
, 1, C (3, 1)}, /* brb B^foo 3,0 */
203 {WF
, WB
, 2, C (3, 2)}, /* brw W^foo 3,1 */
204 {0, 0, 5, 0}, /* Jmp L^foo 3,2 */
205 {1, 1, 0, 0}, /* unused 3,3 */
206 {1, 1, 0, 0}, /* unused 4,0 */
207 {WF
, WB
, 2, C (4, 2)}, /* acb_ ^Wfoo 4,1 */
208 {0, 0, 10, 0}, /* acb_,br,jmp L^foo4,2 */
209 {1, 1, 0, 0}, /* unused 4,3 */
210 {BF
, BB
, 1, C (5, 1)}, /* Xob___,,foo 5,0 */
211 {WF
+ 4, WB
+ 4, 6, C (5, 2)},/* Xob.+2,brb.+3,brw5,1 */
212 {0, 0, 9, 0}, /* Xob.+2,brb.+6,jmp5,2 */
223 const pseudo_typeS md_pseudo_table
[] =
225 {"dfloat", float_cons
, 'd'},
226 {"ffloat", float_cons
, 'f'},
227 {"gfloat", float_cons
, 'g'},
228 {"hfloat", float_cons
, 'h'},
232 #define STATE_PC_RELATIVE (1)
233 #define STATE_CONDITIONAL_BRANCH (2)
234 #define STATE_ALWAYS_BRANCH (3) /* includes BSB... */
235 #define STATE_COMPLEX_BRANCH (4)
236 #define STATE_COMPLEX_HOP (5)
238 #define STATE_BYTE (0)
239 #define STATE_WORD (1)
240 #define STATE_LONG (2)
241 #define STATE_UNDF (3) /* Symbol undefined in pass1 */
244 #define min(a, b) ((a) < (b) ? (a) : (b))
246 int flonum_gen2vax
PARAMS ((char format_letter
, FLONUM_TYPE
* f
,
247 LITTLENUM_TYPE
* words
));
248 static const char *vip_begin
PARAMS ((int, const char *, const char *,
250 static void vip_op_defaults
PARAMS ((const char *, const char *, const char *));
251 static void vip_op
PARAMS ((char *, struct vop
*));
252 static void vip
PARAMS ((struct vit
*, char *));
261 if ((errtxt
= vip_begin (1, "$", "*", "`")) != 0)
263 as_fatal (_("VIP_BEGIN error:%s"), errtxt
);
266 for (i
= 0, fP
= float_operand
;
267 fP
< float_operand
+ VIT_MAX_OPERANDS
;
270 fP
->low
= &big_operand_bits
[i
][0];
271 fP
->high
= &big_operand_bits
[i
][SIZE_OF_LARGE_NUMBER
- 1];
276 md_number_to_chars (con
, value
, nbytes
)
281 number_to_chars_littleendian (con
, value
, nbytes
);
284 /* Fix up some data or instructions after we find out the value of a symbol
285 that they reference. */
287 void /* Knows about order of bytes in address. */
288 md_apply_fix (fixP
, value
)
292 number_to_chars_littleendian (fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
,
293 (valueT
) value
, fixP
->fx_size
);
297 md_chars_to_number (con
, nbytes
)
298 unsigned char con
[]; /* Low order byte 1st. */
299 int nbytes
; /* Number of bytes in the input. */
302 for (retval
= 0, con
+= nbytes
- 1; nbytes
--; con
--)
304 retval
<<= BITS_PER_CHAR
;
310 /* vax:md_assemble() emit frags for 1 instruction */
313 md_assemble (instruction_string
)
314 char *instruction_string
; /* A string: assemble 1 instruction. */
316 /* Non-zero if operand expression's segment is not known yet. */
321 /* An operand. Scans all operands. */
322 struct vop
*operandP
;
323 char *save_input_line_pointer
;
324 /* What used to live after an expression. */
326 /* 1: instruction_string bad for all passes. */
328 /* Points to slot just after last operand. */
329 struct vop
*end_operandP
;
330 /* Points to expression values for this operand. */
334 /* These refer to an instruction operand expression. */
335 /* Target segment of the address. */
337 valueT this_add_number
;
338 /* Positive (minuend) symbol. */
339 symbolS
*this_add_symbol
;
341 long opcode_as_number
;
342 /* Least significant byte 1st. */
343 char *opcode_as_chars
;
344 /* As an array of characters. */
345 /* Least significant byte 1st */
346 char *opcode_low_byteP
;
347 /* length (bytes) meant by vop_short. */
349 /* 0, or 1 if '@' is in addressing mode. */
351 /* From vop_nbytes: vax_operand_width (in bytes) */
354 LITTLENUM_TYPE literal_float
[8];
355 /* Big enough for any floating point literal. */
357 vip (&v
, instruction_string
);
360 * Now we try to find as many as_warn()s as we can. If we do any as_warn()s
361 * then goofed=1. Notice that we don't make any frags yet.
362 * Should goofed be 1, then this instruction will wedge in any pass,
363 * and we can safely flush it, without causing interpass symbol phase
364 * errors. That is, without changing label values in different passes.
366 if ((goofed
= (*v
.vit_error
)) != 0)
368 as_warn (_("Ignoring statement due to \"%s\""), v
.vit_error
);
371 * We need to use expression() and friends, which require us to diddle
372 * input_line_pointer. So we save it and restore it later.
374 save_input_line_pointer
= input_line_pointer
;
375 for (operandP
= v
.vit_operand
,
376 expP
= exp_of_operand
,
377 segP
= seg_of_operand
,
378 floatP
= float_operand
,
379 end_operandP
= v
.vit_operand
+ v
.vit_operands
;
381 operandP
< end_operandP
;
383 operandP
++, expP
++, segP
++, floatP
++)
384 { /* for each operand */
385 if (operandP
->vop_error
)
387 as_warn (_("Ignoring statement because \"%s\""), operandP
->vop_error
);
392 /* statement has no syntax goofs: lets sniff the expression */
393 int can_be_short
= 0; /* 1 if a bignum can be reduced to a short literal. */
395 input_line_pointer
= operandP
->vop_expr_begin
;
396 c_save
= operandP
->vop_expr_end
[1];
397 operandP
->vop_expr_end
[1] = '\0';
398 /* If to_seg == SEG_PASS1, expression() will have set need_pass_2 = 1. */
399 *segP
= expression (expP
);
403 /* for BSD4.2 compatibility, missing expression is absolute 0 */
404 expP
->X_op
= O_constant
;
405 expP
->X_add_number
= 0;
406 /* For SEG_ABSOLUTE, we shouldn't need to set X_op_symbol,
407 X_add_symbol to any particular value. But, we will program
408 defensively. Since this situation occurs rarely so it costs
409 us little to do, and stops Dean worrying about the origin of
410 random bits in expressionS's. */
411 expP
->X_add_symbol
= NULL
;
412 expP
->X_op_symbol
= NULL
;
421 * Major bug. We can't handle the case of a
422 * SEG_OP expression in a VIT_OPCODE_SYNTHETIC
423 * variable-length instruction.
424 * We don't have a frag type that is smart enough to
425 * relax a SEG_OP, and so we just force all
426 * SEG_OPs to behave like SEG_PASS1s.
427 * Clearly, if there is a demand we can invent a new or
428 * modified frag type and then coding up a frag for this
429 * case will be easy. SEG_OP was invented for the
430 * .words after a CASE opcode, and was never intended for
431 * instruction operands.
434 as_warn (_("Can't relocate expression"));
438 /* Preserve the bits. */
439 if (expP
->X_add_number
> 0)
441 bignum_copy (generic_bignum
, expP
->X_add_number
,
442 floatP
->low
, SIZE_OF_LARGE_NUMBER
);
446 know (expP
->X_add_number
< 0);
447 flonum_copy (&generic_floating_point_number
,
449 if (strchr ("s i", operandP
->vop_short
))
451 /* Could possibly become S^# */
452 flonum_gen2vax (-expP
->X_add_number
, floatP
, literal_float
);
453 switch (-expP
->X_add_number
)
457 (literal_float
[0] & 0xFC0F) == 0x4000
458 && literal_float
[1] == 0;
463 (literal_float
[0] & 0xFC0F) == 0x4000
464 && literal_float
[1] == 0
465 && literal_float
[2] == 0
466 && literal_float
[3] == 0;
471 (literal_float
[0] & 0xFF81) == 0x4000
472 && literal_float
[1] == 0
473 && literal_float
[2] == 0
474 && literal_float
[3] == 0;
478 can_be_short
= ((literal_float
[0] & 0xFFF8) == 0x4000
479 && (literal_float
[1] & 0xE000) == 0
480 && literal_float
[2] == 0
481 && literal_float
[3] == 0
482 && literal_float
[4] == 0
483 && literal_float
[5] == 0
484 && literal_float
[6] == 0
485 && literal_float
[7] == 0);
489 BAD_CASE (-expP
->X_add_number
);
491 } /* switch (float type) */
492 } /* if (could want to become S^#...) */
493 } /* bignum or flonum ? */
495 if (operandP
->vop_short
== 's'
496 || operandP
->vop_short
== 'i'
497 || (operandP
->vop_short
== ' '
498 && operandP
->vop_reg
== 0xF
499 && (operandP
->vop_mode
& 0xE) == 0x8))
502 if (operandP
->vop_short
== ' ')
504 /* We must chose S^ or I^. */
505 if (expP
->X_add_number
> 0)
507 /* Bignum: Short literal impossible. */
508 operandP
->vop_short
= 'i';
509 operandP
->vop_mode
= 8;
510 operandP
->vop_reg
= 0xF; /* VAX PC. */
514 /* Flonum: Try to do it. */
517 operandP
->vop_short
= 's';
518 operandP
->vop_mode
= 0;
519 operandP
->vop_ndx
= -1;
520 operandP
->vop_reg
= -1;
521 expP
->X_op
= O_constant
;
525 operandP
->vop_short
= 'i';
526 operandP
->vop_mode
= 8;
527 operandP
->vop_reg
= 0xF; /* VAX PC */
529 } /* bignum or flonum ? */
530 } /* if #, but no S^ or I^ seen. */
531 /* No more ' ' case: either 's' or 'i'. */
532 if (operandP
->vop_short
== 's')
534 /* Wants to be a short literal. */
535 if (expP
->X_add_number
> 0)
537 as_warn (_("Bignum not permitted in short literal. Immediate mode assumed."));
538 operandP
->vop_short
= 'i';
539 operandP
->vop_mode
= 8;
540 operandP
->vop_reg
= 0xF; /* VAX PC. */
546 as_warn (_("Can't do flonum short literal: immediate mode used."));
547 operandP
->vop_short
= 'i';
548 operandP
->vop_mode
= 8;
549 operandP
->vop_reg
= 0xF; /* VAX PC. */
552 { /* Encode short literal now. */
555 switch (-expP
->X_add_number
)
559 temp
= literal_float
[0] >> 4;
563 temp
= literal_float
[0] >> 1;
567 temp
= ((literal_float
[0] << 3) & 070)
568 | ((literal_float
[1] >> 13) & 07);
572 BAD_CASE (-expP
->X_add_number
);
576 floatP
->low
[0] = temp
& 077;
578 } /* if can be short literal float */
579 } /* flonum or bignum ? */
582 { /* I^# seen: set it up if float. */
583 if (expP
->X_add_number
< 0)
585 memcpy (floatP
->low
, literal_float
, sizeof (literal_float
));
591 as_warn (_("A bignum/flonum may not be a displacement: 0x%lx used"),
592 (expP
->X_add_number
= 0x80000000L
));
593 /* Chosen so luser gets the most offset bits to patch later. */
595 expP
->X_add_number
= floatP
->low
[0]
596 | ((LITTLENUM_MASK
& (floatP
->low
[1])) << LITTLENUM_NUMBER_OF_BITS
);
598 * For the O_big case we have:
599 * If vop_short == 's' then a short floating literal is in the
600 * lowest 6 bits of floatP -> low [0], which is
601 * big_operand_bits [---] [0].
602 * If vop_short == 'i' then the appropriate number of elements
603 * of big_operand_bits [---] [...] are set up with the correct
605 * Also, just in case width is byte word or long, we copy the lowest
606 * 32 bits of the number to X_add_number.
610 if (input_line_pointer
!= operandP
->vop_expr_end
+ 1)
612 as_warn ("Junk at end of expression \"%s\"", input_line_pointer
);
615 operandP
->vop_expr_end
[1] = c_save
;
617 } /* for(each operand) */
619 input_line_pointer
= save_input_line_pointer
;
621 if (need_pass_2
|| goofed
)
628 /* Remember where it is, in case we want to modify the op-code later. */
629 opcode_low_byteP
= frag_more (v
.vit_opcode_nbytes
);
630 memcpy (opcode_low_byteP
, v
.vit_opcode
, v
.vit_opcode_nbytes
);
631 opcode_as_number
= md_chars_to_number (opcode_as_chars
= v
.vit_opcode
, 4);
632 for (operandP
= v
.vit_operand
,
633 expP
= exp_of_operand
,
634 segP
= seg_of_operand
,
635 floatP
= float_operand
,
636 end_operandP
= v
.vit_operand
+ v
.vit_operands
;
638 operandP
< end_operandP
;
645 if (operandP
->vop_ndx
>= 0)
647 /* indexed addressing byte */
648 /* Legality of indexed mode already checked: it is OK */
649 FRAG_APPEND_1_CHAR (0x40 + operandP
->vop_ndx
);
650 } /* if(vop_ndx>=0) */
652 /* Here to make main operand frag(s). */
653 this_add_number
= expP
->X_add_number
;
654 this_add_symbol
= expP
->X_add_symbol
;
656 is_undefined
= (to_seg
== SEG_UNKNOWN
);
657 at
= operandP
->vop_mode
& 1;
658 length
= (operandP
->vop_short
== 'b'
659 ? 1 : (operandP
->vop_short
== 'w'
660 ? 2 : (operandP
->vop_short
== 'l'
662 nbytes
= operandP
->vop_nbytes
;
663 if (operandP
->vop_access
== 'b')
665 if (to_seg
== now_seg
|| is_undefined
)
667 /* If is_undefined, then it might BECOME now_seg. */
670 p
= frag_more (nbytes
);
671 fix_new (frag_now
, p
- frag_now
->fr_literal
, nbytes
,
672 this_add_symbol
, this_add_number
, 1, NO_RELOC
);
675 { /* to_seg==now_seg || to_seg == SEG_UNKNOWN */
677 length_code
= is_undefined
? STATE_UNDF
: STATE_BYTE
;
678 if (opcode_as_number
& VIT_OPCODE_SPECIAL
)
680 if (operandP
->vop_width
== VAX_WIDTH_UNCONDITIONAL_JUMP
)
683 frag_var (rs_machine_dependent
, 5, 1,
684 ENCODE_RELAX (STATE_ALWAYS_BRANCH
, length_code
),
685 this_add_symbol
, this_add_number
,
690 if (operandP
->vop_width
== VAX_WIDTH_WORD_JUMP
)
692 length_code
= STATE_WORD
;
693 /* JF: There is no state_byte for this one! */
694 frag_var (rs_machine_dependent
, 10, 2,
695 ENCODE_RELAX (STATE_COMPLEX_BRANCH
, length_code
),
696 this_add_symbol
, this_add_number
,
701 know (operandP
->vop_width
== VAX_WIDTH_BYTE_JUMP
);
702 frag_var (rs_machine_dependent
, 9, 1,
703 ENCODE_RELAX (STATE_COMPLEX_HOP
, length_code
),
704 this_add_symbol
, this_add_number
,
711 know (operandP
->vop_width
== VAX_WIDTH_CONDITIONAL_JUMP
);
712 frag_var (rs_machine_dependent
, 7, 1,
713 ENCODE_RELAX (STATE_CONDITIONAL_BRANCH
, length_code
),
714 this_add_symbol
, this_add_number
,
721 /* to_seg != now_seg && to_seg != SEG_UNKNOWN */
723 * --- SEG FLOAT MAY APPEAR HERE ----
725 if (to_seg
== SEG_ABSOLUTE
)
729 know (!(opcode_as_number
& VIT_OPCODE_SYNTHETIC
));
730 p
= frag_more (nbytes
);
731 /* Conventional relocation. */
732 fix_new (frag_now
, p
- frag_now
->fr_literal
,
733 nbytes
, &abs_symbol
, this_add_number
,
738 know (opcode_as_number
& VIT_OPCODE_SYNTHETIC
);
739 if (opcode_as_number
& VIT_OPCODE_SPECIAL
)
741 if (operandP
->vop_width
== VAX_WIDTH_UNCONDITIONAL_JUMP
)
744 *opcode_low_byteP
= opcode_as_chars
[0] + VAX_WIDEN_LONG
;
745 know (opcode_as_chars
[1] == 0);
747 p
[0] = VAX_ABSOLUTE_MODE
; /* @#... */
748 md_number_to_chars (p
+ 1, this_add_number
, 4);
749 /* Now (eg) JMP @#foo or JSB @#foo. */
753 if (operandP
->vop_width
== VAX_WIDTH_WORD_JUMP
)
761 p
[5] = VAX_ABSOLUTE_MODE
; /* @#... */
762 md_number_to_chars (p
+ 6, this_add_number
, 4);
772 know (operandP
->vop_width
== VAX_WIDTH_BYTE_JUMP
);
778 p
[4] = VAX_PC_RELATIVE_MODE
+ 1; /* @#... */
779 md_number_to_chars (p
+ 5, this_add_number
, 4);
792 *opcode_low_byteP
^= 1;
793 /* To reverse the condition in a VAX branch,
794 complement the lowest order bit. */
798 p
[2] = VAX_ABSOLUTE_MODE
; /* @#... */
799 md_number_to_chars (p
+ 3, this_add_number
, 4);
810 /* to_seg != now_seg && to_seg != SEG_UNKNOWN && to_Seg != SEG_ABSOLUTE */
813 /* Pc-relative. Conventional relocation. */
814 know (!(opcode_as_number
& VIT_OPCODE_SYNTHETIC
));
815 p
= frag_more (nbytes
);
816 fix_new (frag_now
, p
- frag_now
->fr_literal
,
817 nbytes
, &abs_symbol
, this_add_number
,
822 know (opcode_as_number
& VIT_OPCODE_SYNTHETIC
);
823 if (opcode_as_number
& VIT_OPCODE_SPECIAL
)
825 if (operandP
->vop_width
== VAX_WIDTH_UNCONDITIONAL_JUMP
)
828 know (opcode_as_chars
[1] == 0);
829 *opcode_low_byteP
= opcode_as_chars
[0] + VAX_WIDEN_LONG
;
831 p
[0] = VAX_PC_RELATIVE_MODE
;
833 p
+ 1 - frag_now
->fr_literal
, 4,
835 this_add_number
, 1, NO_RELOC
);
836 /* Now eg JMP foo or JSB foo. */
840 if (operandP
->vop_width
== VAX_WIDTH_WORD_JUMP
)
848 p
[5] = VAX_PC_RELATIVE_MODE
;
850 p
+ 6 - frag_now
->fr_literal
, 4,
852 this_add_number
, 1, NO_RELOC
);
862 know (operandP
->vop_width
== VAX_WIDTH_BYTE_JUMP
);
868 p
[4] = VAX_PC_RELATIVE_MODE
;
870 p
+ 5 - frag_now
->fr_literal
,
872 this_add_number
, 1, NO_RELOC
);
884 know (operandP
->vop_width
== VAX_WIDTH_CONDITIONAL_JUMP
);
885 *opcode_low_byteP
^= 1; /* Reverse branch condition. */
889 p
[2] = VAX_PC_RELATIVE_MODE
;
890 fix_new (frag_now
, p
+ 3 - frag_now
->fr_literal
,
892 this_add_number
, 1, NO_RELOC
);
900 know (operandP
->vop_access
!= 'b'); /* So it is ordinary operand. */
901 know (operandP
->vop_access
!= ' '); /* ' ' target-independent: elsewhere. */
902 know (operandP
->vop_access
== 'a'
903 || operandP
->vop_access
== 'm'
904 || operandP
->vop_access
== 'r'
905 || operandP
->vop_access
== 'v'
906 || operandP
->vop_access
== 'w');
907 if (operandP
->vop_short
== 's')
909 if (to_seg
== SEG_ABSOLUTE
)
911 if (this_add_number
>= 64)
913 as_warn (_("Short literal overflow(%ld.), immediate mode assumed."),
914 (long) this_add_number
);
915 operandP
->vop_short
= 'i';
916 operandP
->vop_mode
= 8;
917 operandP
->vop_reg
= 0xF;
922 as_warn (_("Forced short literal to immediate mode. now_seg=%s to_seg=%s"),
923 segment_name (now_seg
), segment_name (to_seg
));
924 operandP
->vop_short
= 'i';
925 operandP
->vop_mode
= 8;
926 operandP
->vop_reg
= 0xF;
929 if (operandP
->vop_reg
>= 0 && (operandP
->vop_mode
< 8
930 || (operandP
->vop_reg
!= 0xF && operandP
->vop_mode
< 10)))
932 /* One byte operand. */
933 know (operandP
->vop_mode
> 3);
934 FRAG_APPEND_1_CHAR (operandP
->vop_mode
<< 4 | operandP
->vop_reg
);
935 /* All 1-bytes except S^# happen here. */
939 /* {@}{q^}foo{(Rn)} or S^#foo */
940 if (operandP
->vop_reg
== -1 && operandP
->vop_short
!= 's')
943 if (to_seg
== now_seg
)
947 know (operandP
->vop_short
== ' ');
948 p
= frag_var (rs_machine_dependent
, 10, 2,
949 ENCODE_RELAX (STATE_PC_RELATIVE
, STATE_BYTE
),
950 this_add_symbol
, this_add_number
,
952 know (operandP
->vop_mode
== 10 + at
);
954 /* At is the only context we need to carry
955 to other side of relax() process. Must
956 be in the correct bit position of VAX
957 operand spec. byte. */
962 know (operandP
->vop_short
!= ' ');
963 p
= frag_more (length
+ 1);
964 p
[0] = 0xF | ((at
+ "?\12\14?\16"[length
]) << 4);
965 fix_new (frag_now
, p
+ 1 - frag_now
->fr_literal
,
966 length
, this_add_symbol
,
967 this_add_number
, 1, NO_RELOC
);
971 { /* to_seg != now_seg */
972 if (this_add_symbol
== NULL
)
974 know (to_seg
== SEG_ABSOLUTE
);
975 /* Do @#foo: simpler relocation than foo-.(pc) anyway. */
977 p
[0] = VAX_ABSOLUTE_MODE
; /* @#... */
978 md_number_to_chars (p
+ 1, this_add_number
, 4);
979 if (length
&& length
!= 4)
981 as_warn (_("Length specification ignored. Address mode 9F used"));
986 /* {@}{q^}other_seg */
987 know ((length
== 0 && operandP
->vop_short
== ' ')
988 || (length
> 0 && operandP
->vop_short
!= ' '));
992 * We have a SEG_UNKNOWN symbol. It might
993 * turn out to be in the same segment as
994 * the instruction, permitting relaxation.
996 p
= frag_var (rs_machine_dependent
, 5, 2,
997 ENCODE_RELAX (STATE_PC_RELATIVE
, STATE_UNDF
),
998 this_add_symbol
, this_add_number
,
1006 know (operandP
->vop_short
== ' ');
1007 length
= 4; /* Longest possible. */
1009 p
= frag_more (length
+ 1);
1010 p
[0] = 0xF | ((at
+ "?\12\14?\16"[length
]) << 4);
1011 md_number_to_chars (p
+ 1, this_add_number
, length
);
1013 p
+ 1 - frag_now
->fr_literal
,
1014 length
, this_add_symbol
,
1015 this_add_number
, 1, NO_RELOC
);
1022 /* {@}{q^}foo(Rn) or S^# or I^# or # */
1023 if (operandP
->vop_mode
< 0xA)
1025 /* # or S^# or I^# */
1026 if (operandP
->vop_access
== 'v'
1027 || operandP
->vop_access
== 'a')
1029 if (operandP
->vop_access
== 'v')
1030 as_warn (_("Invalid operand: immediate value used as base address."));
1032 as_warn (_("Invalid operand: immediate value used as address."));
1033 /* gcc 2.6.3 is known to generate these in at least
1037 && to_seg
== SEG_ABSOLUTE
&& (expP
->X_op
!= O_big
)
1038 && operandP
->vop_mode
== 8 /* No '@'. */
1039 && this_add_number
< 64)
1041 operandP
->vop_short
= 's';
1043 if (operandP
->vop_short
== 's')
1045 FRAG_APPEND_1_CHAR (this_add_number
);
1051 p
= frag_more (nbytes
+ 1);
1052 know (operandP
->vop_reg
== 0xF);
1053 p
[0] = (operandP
->vop_mode
<< 4) | 0xF;
1054 if ((to_seg
== SEG_ABSOLUTE
) && (expP
->X_op
!= O_big
))
1057 * If nbytes > 4, then we are scrod. We
1058 * don't know if the high order bytes
1059 * are to be 0xFF or 0x00. BSD4.2 & RMS
1060 * say use 0x00. OK --- but this
1061 * assembler needs ANOTHER rewrite to
1062 * cope properly with this bug. */
1063 md_number_to_chars (p
+ 1, this_add_number
, min (4, nbytes
));
1066 memset (p
+ 5, '\0', nbytes
- 4);
1071 if (expP
->X_op
== O_big
)
1074 * Problem here is to get the bytes
1075 * in the right order. We stored
1076 * our constant as LITTLENUMs, not
1088 for (p
++; nbytes
; nbytes
-= 2, p
+= 2, lP
++)
1090 md_number_to_chars (p
, *lP
, 2);
1096 fix_new (frag_now
, p
+ 1 - frag_now
->fr_literal
,
1097 nbytes
, this_add_symbol
,
1098 this_add_number
, 0, NO_RELOC
);
1104 { /* {@}{q^}foo(Rn) */
1105 know ((length
== 0 && operandP
->vop_short
== ' ')
1106 || (length
> 0 && operandP
->vop_short
!= ' '));
1109 if (to_seg
== SEG_ABSOLUTE
)
1113 test
= this_add_number
;
1118 length
= test
& 0xffff8000 ? 4
1119 : test
& 0xffffff80 ? 2
1127 p
= frag_more (1 + length
);
1128 know (operandP
->vop_reg
>= 0);
1129 p
[0] = operandP
->vop_reg
1130 | ((at
| "?\12\14?\16"[length
]) << 4);
1131 if (to_seg
== SEG_ABSOLUTE
)
1133 md_number_to_chars (p
+ 1, this_add_number
, length
);
1137 fix_new (frag_now
, p
+ 1 - frag_now
->fr_literal
,
1138 length
, this_add_symbol
,
1139 this_add_number
, 0, NO_RELOC
);
1143 } /* if(single-byte-operand) */
1145 } /* for(operandP) */
1146 } /* vax_assemble() */
1149 * md_estimate_size_before_relax()
1151 * Called just before relax().
1152 * Any symbol that is now undefined will not become defined.
1153 * Return the correct fr_subtype in the frag.
1154 * Return the initial "guess for fr_var" to caller.
1155 * The guess for fr_var is ACTUALLY the growth beyond fr_fix.
1156 * Whatever we do to grow fr_fix or fr_var contributes to our returned value.
1157 * Although it may not be explicit in the frag, pretend fr_var starts with a
1161 md_estimate_size_before_relax (fragP
, segment
)
1168 old_fr_fix
= fragP
->fr_fix
;
1169 switch (fragP
->fr_subtype
)
1171 case ENCODE_RELAX (STATE_PC_RELATIVE
, STATE_UNDF
):
1172 if (S_GET_SEGMENT (fragP
->fr_symbol
) == segment
)
1173 { /* A relaxable case. */
1174 fragP
->fr_subtype
= ENCODE_RELAX (STATE_PC_RELATIVE
, STATE_BYTE
);
1178 p
= fragP
->fr_literal
+ old_fr_fix
;
1179 p
[0] |= VAX_PC_RELATIVE_MODE
; /* Preserve @ bit. */
1180 fragP
->fr_fix
+= 1 + 4;
1181 fix_new (fragP
, old_fr_fix
+ 1, 4, fragP
->fr_symbol
,
1182 fragP
->fr_offset
, 1, NO_RELOC
);
1187 case ENCODE_RELAX (STATE_CONDITIONAL_BRANCH
, STATE_UNDF
):
1188 if (S_GET_SEGMENT (fragP
->fr_symbol
) == segment
)
1190 fragP
->fr_subtype
= ENCODE_RELAX (STATE_CONDITIONAL_BRANCH
, STATE_BYTE
);
1194 p
= fragP
->fr_literal
+ old_fr_fix
;
1195 *fragP
->fr_opcode
^= 1; /* Reverse sense of branch. */
1198 p
[2] = VAX_PC_RELATIVE_MODE
; /* ...(PC) */
1199 fragP
->fr_fix
+= 1 + 1 + 1 + 4;
1200 fix_new (fragP
, old_fr_fix
+ 3, 4, fragP
->fr_symbol
,
1201 fragP
->fr_offset
, 1, NO_RELOC
);
1206 case ENCODE_RELAX (STATE_COMPLEX_BRANCH
, STATE_UNDF
):
1207 if (S_GET_SEGMENT (fragP
->fr_symbol
) == segment
)
1209 fragP
->fr_subtype
= ENCODE_RELAX (STATE_COMPLEX_BRANCH
, STATE_WORD
);
1213 p
= fragP
->fr_literal
+ old_fr_fix
;
1219 p
[5] = VAX_PC_RELATIVE_MODE
; /* ...(pc) */
1220 fragP
->fr_fix
+= 2 + 2 + 1 + 1 + 4;
1221 fix_new (fragP
, old_fr_fix
+ 6, 4, fragP
->fr_symbol
,
1222 fragP
->fr_offset
, 1, NO_RELOC
);
1227 case ENCODE_RELAX (STATE_COMPLEX_HOP
, STATE_UNDF
):
1228 if (S_GET_SEGMENT (fragP
->fr_symbol
) == segment
)
1230 fragP
->fr_subtype
= ENCODE_RELAX (STATE_COMPLEX_HOP
, STATE_BYTE
);
1234 p
= fragP
->fr_literal
+ old_fr_fix
;
1239 p
[4] = VAX_PC_RELATIVE_MODE
; /* ...(pc) */
1240 fragP
->fr_fix
+= 1 + 2 + 1 + 1 + 4;
1241 fix_new (fragP
, old_fr_fix
+ 5, 4, fragP
->fr_symbol
,
1242 fragP
->fr_offset
, 1, NO_RELOC
);
1247 case ENCODE_RELAX (STATE_ALWAYS_BRANCH
, STATE_UNDF
):
1248 if (S_GET_SEGMENT (fragP
->fr_symbol
) == segment
)
1250 fragP
->fr_subtype
= ENCODE_RELAX (STATE_ALWAYS_BRANCH
, STATE_BYTE
);
1254 p
= fragP
->fr_literal
+ old_fr_fix
;
1255 *fragP
->fr_opcode
+= VAX_WIDEN_LONG
;
1256 p
[0] = VAX_PC_RELATIVE_MODE
; /* ...(PC) */
1257 fragP
->fr_fix
+= 1 + 4;
1258 fix_new (fragP
, old_fr_fix
+ 1, 4, fragP
->fr_symbol
,
1259 fragP
->fr_offset
, 1, NO_RELOC
);
1267 return (fragP
->fr_var
+ fragP
->fr_fix
- old_fr_fix
);
1268 } /* md_estimate_size_before_relax() */
1271 * md_convert_frag();
1273 * Called after relax() is finished.
1274 * In: Address of frag.
1275 * fr_type == rs_machine_dependent.
1276 * fr_subtype is what the address relaxed to.
1278 * Out: Any fixSs and constants are set up.
1279 * Caller will turn frag into a ".space 0".
1282 md_convert_frag (headers
, seg
, fragP
)
1283 object_headers
*headers
;
1287 char *addressP
; /* -> _var to change. */
1288 char *opcodeP
; /* -> opcode char(s) to change. */
1289 short int length_code
; /* 2=long 1=word 0=byte */
1290 short int extension
= 0; /* Size of relaxed address. */
1291 /* Added to fr_fix: incl. ALL var chars. */
1294 long address_of_var
;
1295 /* Where, in file space, is _var of *fragP? */
1296 long target_address
= 0;
1297 /* Where, in file space, does addr point? */
1299 know (fragP
->fr_type
== rs_machine_dependent
);
1300 length_code
= fragP
->fr_subtype
& 3; /* depends on ENCODE_RELAX() */
1301 know (length_code
>= 0 && length_code
< 3);
1302 where
= fragP
->fr_fix
;
1303 addressP
= fragP
->fr_literal
+ where
;
1304 opcodeP
= fragP
->fr_opcode
;
1305 symbolP
= fragP
->fr_symbol
;
1307 target_address
= S_GET_VALUE (symbolP
) + fragP
->fr_offset
;
1308 address_of_var
= fragP
->fr_address
+ where
;
1310 switch (fragP
->fr_subtype
)
1313 case ENCODE_RELAX (STATE_PC_RELATIVE
, STATE_BYTE
):
1314 know (*addressP
== 0 || *addressP
== 0x10); /* '@' bit. */
1315 addressP
[0] |= 0xAF; /* Byte displacement. */
1316 addressP
[1] = target_address
- (address_of_var
+ 2);
1320 case ENCODE_RELAX (STATE_PC_RELATIVE
, STATE_WORD
):
1321 know (*addressP
== 0 || *addressP
== 0x10); /* '@' bit. */
1322 addressP
[0] |= 0xCF; /* Word displacement. */
1323 md_number_to_chars (addressP
+ 1, target_address
- (address_of_var
+ 3), 2);
1327 case ENCODE_RELAX (STATE_PC_RELATIVE
, STATE_LONG
):
1328 know (*addressP
== 0 || *addressP
== 0x10); /* '@' bit. */
1329 addressP
[0] |= 0xEF; /* Long word displacement. */
1330 md_number_to_chars (addressP
+ 1, target_address
- (address_of_var
+ 5), 4);
1334 case ENCODE_RELAX (STATE_CONDITIONAL_BRANCH
, STATE_BYTE
):
1335 addressP
[0] = target_address
- (address_of_var
+ 1);
1339 case ENCODE_RELAX (STATE_CONDITIONAL_BRANCH
, STATE_WORD
):
1340 opcodeP
[0] ^= 1; /* Reverse sense of test. */
1342 addressP
[1] = VAX_BRB
+ VAX_WIDEN_WORD
;
1343 md_number_to_chars (addressP
+ 2, target_address
- (address_of_var
+ 4), 2);
1347 case ENCODE_RELAX (STATE_CONDITIONAL_BRANCH
, STATE_LONG
):
1348 opcodeP
[0] ^= 1; /* Reverse sense of test. */
1350 addressP
[1] = VAX_JMP
;
1351 addressP
[2] = VAX_PC_RELATIVE_MODE
;
1352 md_number_to_chars (addressP
+ 3, target_address
, 4);
1356 case ENCODE_RELAX (STATE_ALWAYS_BRANCH
, STATE_BYTE
):
1357 addressP
[0] = target_address
- (address_of_var
+ 1);
1361 case ENCODE_RELAX (STATE_ALWAYS_BRANCH
, STATE_WORD
):
1362 opcodeP
[0] += VAX_WIDEN_WORD
; /* brb -> brw, bsbb -> bsbw */
1363 md_number_to_chars (addressP
, target_address
- (address_of_var
+ 2), 2);
1367 case ENCODE_RELAX (STATE_ALWAYS_BRANCH
, STATE_LONG
):
1368 opcodeP
[0] += VAX_WIDEN_LONG
; /* brb -> jmp, bsbb -> jsb */
1369 addressP
[0] = VAX_PC_RELATIVE_MODE
;
1370 md_number_to_chars (addressP
+ 1, target_address
- (address_of_var
+ 5), 4);
1374 case ENCODE_RELAX (STATE_COMPLEX_BRANCH
, STATE_WORD
):
1375 md_number_to_chars (addressP
, target_address
- (address_of_var
+ 2), 2);
1379 case ENCODE_RELAX (STATE_COMPLEX_BRANCH
, STATE_LONG
):
1382 addressP
[2] = VAX_BRB
;
1384 addressP
[4] = VAX_JMP
;
1385 addressP
[5] = VAX_PC_RELATIVE_MODE
;
1386 md_number_to_chars (addressP
+ 6, target_address
, 4);
1390 case ENCODE_RELAX (STATE_COMPLEX_HOP
, STATE_BYTE
):
1391 addressP
[0] = target_address
- (address_of_var
+ 1);
1395 case ENCODE_RELAX (STATE_COMPLEX_HOP
, STATE_WORD
):
1397 addressP
[1] = VAX_BRB
;
1399 addressP
[3] = VAX_BRW
;
1400 md_number_to_chars (addressP
+ 4, target_address
- (address_of_var
+ 6), 2);
1404 case ENCODE_RELAX (STATE_COMPLEX_HOP
, STATE_LONG
):
1406 addressP
[1] = VAX_BRB
;
1408 addressP
[3] = VAX_JMP
;
1409 addressP
[4] = VAX_PC_RELATIVE_MODE
;
1410 md_number_to_chars (addressP
+ 5, target_address
, 4);
1415 BAD_CASE (fragP
->fr_subtype
);
1418 fragP
->fr_fix
+= extension
;
1419 } /* md_convert_frag() */
1421 /* Translate internal format of relocation info into target format.
1423 On vax: first 4 bytes are normal unsigned long, next three bytes
1424 are symbolnum, least sig. byte first. Last byte is broken up with
1425 the upper nibble as nuthin, bit 3 as extern, bits 2 & 1 as length, and
1429 md_ri_to_chars (the_bytes
, ri
)
1431 struct reloc_info_generic ri
;
1434 md_number_to_chars (the_bytes
, ri
.r_address
, sizeof (ri
.r_address
));
1435 /* now the fun stuff */
1436 the_bytes
[6] = (ri
.r_symbolnum
>> 16) & 0x0ff;
1437 the_bytes
[5] = (ri
.r_symbolnum
>> 8) & 0x0ff;
1438 the_bytes
[4] = ri
.r_symbolnum
& 0x0ff;
1439 the_bytes
[7] = (((ri
.r_extern
<< 3) & 0x08) | ((ri
.r_length
<< 1) & 0x06) |
1440 ((ri
.r_pcrel
<< 0) & 0x01)) & 0x0F;
1443 #endif /* comment */
1446 tc_aout_fix_to_chars (where
, fixP
, segment_address_in_file
)
1449 relax_addressT segment_address_in_file
;
1452 * In: length of relocation (or of address) in chars: 1, 2 or 4.
1453 * Out: GNU LD relocation length code: 0, 1, or 2.
1456 static const unsigned char nbytes_r_length
[] = {42, 0, 1, 42, 2};
1459 know (fixP
->fx_addsy
!= NULL
);
1461 md_number_to_chars (where
,
1462 fixP
->fx_frag
->fr_address
+ fixP
->fx_where
- segment_address_in_file
,
1465 r_symbolnum
= (S_IS_DEFINED (fixP
->fx_addsy
)
1466 ? S_GET_TYPE (fixP
->fx_addsy
)
1467 : fixP
->fx_addsy
->sy_number
);
1469 where
[6] = (r_symbolnum
>> 16) & 0x0ff;
1470 where
[5] = (r_symbolnum
>> 8) & 0x0ff;
1471 where
[4] = r_symbolnum
& 0x0ff;
1472 where
[7] = ((((!S_IS_DEFINED (fixP
->fx_addsy
)) << 3) & 0x08)
1473 | ((nbytes_r_length
[fixP
->fx_size
] << 1) & 0x06)
1474 | (((fixP
->fx_pcrel
<< 0) & 0x01) & 0x0f));
1478 * BUGS, GRIPES, APOLOGIA, etc.
1480 * The opcode table 'votstrs' needs to be sorted on opcode frequency.
1481 * That is, AFTER we hash it with hash_...(), we want most-used opcodes
1482 * to come out of the hash table faster.
1484 * I am sorry to inflict yet another VAX assembler on the world, but
1485 * RMS says we must do everything from scratch, to prevent pin-heads
1486 * restricting this software.
1490 * This is a vaguely modular set of routines in C to parse VAX
1491 * assembly code using DEC mnemonics. It is NOT un*x specific.
1493 * The idea here is that the assembler has taken care of all:
1500 * condensing any whitespace down to exactly one space
1501 * and all we have to do is parse 1 line into a vax instruction
1502 * partially formed. We will accept a line, and deliver:
1503 * an error message (hopefully empty)
1504 * a skeleton VAX instruction (tree structure)
1505 * textual pointers to all the operand expressions
1506 * a warning message that notes a silly operand (hopefully empty)
1510 * E D I T H I S T O R Y
1512 * 17may86 Dean Elsner. Bug if line ends immediately after opcode.
1513 * 30apr86 Dean Elsner. New vip_op() uses arg block so change call.
1514 * 6jan86 Dean Elsner. Crock vip_begin() to call vip_op_defaults().
1515 * 2jan86 Dean Elsner. Invent synthetic opcodes.
1516 * Widen vax_opcodeT to 32 bits. Use a bit for VIT_OPCODE_SYNTHETIC,
1517 * which means this is not a real opcode, it is like a macro; it will
1518 * be relax()ed into 1 or more instructions.
1519 * Use another bit for VIT_OPCODE_SPECIAL if the op-code is not optimised
1520 * like a regular branch instruction. Option added to vip_begin():
1521 * exclude synthetic opcodes. Invent synthetic_votstrs[].
1522 * 31dec85 Dean Elsner. Invent vit_opcode_nbytes.
1523 * Also make vit_opcode into a char[]. We now have n-byte vax opcodes,
1524 * so caller's don't have to know the difference between a 1-byte & a
1525 * 2-byte op-code. Still need vax_opcodeT concept, so we know how
1526 * big an object must be to hold an op.code.
1527 * 30dec85 Dean Elsner. Widen typedef vax_opcodeT in "vax-inst.h"
1528 * because vax opcodes may be 16 bits. Our crufty C compiler was
1529 * happily initialising 8-bit vot_codes with 16-bit numbers!
1530 * (Wouldn't the 'phone company like to compress data so easily!)
1531 * 29dec85 Dean Elsner. New static table vax_operand_width_size[].
1532 * Invented so we know hw many bytes a "I^#42" needs in its immediate
1533 * operand. Revised struct vop in "vax-inst.h": explicitly include
1534 * byte length of each operand, and it's letter-code datum type.
1535 * 17nov85 Dean Elsner. Name Change.
1536 * Due to ar(1) truncating names, we learned the hard way that
1537 * "vax-inst-parse.c" -> "vax-inst-parse." dropping the "o" off
1538 * the archived object name. SO... we shortened the name of this
1539 * source file, and changed the makefile.
1542 /* handle of the OPCODE hash table */
1543 static struct hash_control
*op_hash
;
1546 * In: 1 character, from "bdfghloqpw" being the data-type of an operand
1547 * of a vax instruction.
1549 * Out: the length of an operand of that type, in bytes.
1550 * Special branch operands types "-?!" have length 0.
1553 static const short int vax_operand_width_size
[256] =
1555 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1556 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1557 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1558 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1559 0, 0, 1, 0, 8, 0, 4, 8, 16, 0, 0, 0, 4, 0, 0,16, /* ..b.d.fgh...l..o */
1560 0, 8, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, /* .q.....w........ */
1561 0, 0, 1, 0, 8, 0, 4, 8, 16, 0, 0, 0, 4, 0, 0,16, /* ..b.d.fgh...l..o */
1562 0, 8, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, /* .q.....w........ */
1563 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1564 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1565 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1566 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1567 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1568 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1569 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1570 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1574 * This perversion encodes all the vax opcodes as a bunch of strings.
1575 * RMS says we should build our hash-table at run-time. Hmm.
1576 * Please would someone arrange these in decreasing frequency of opcode?
1577 * Because of the way hash_...() works, the most frequently used opcode
1578 * should be textually first and so on.
1580 * Input for this table was 'vax.opcodes', awk(1)ed by 'vax.opcodes.c.awk' .
1581 * So change 'vax.opcodes', then re-generate this table.
1584 #include "opcode/vax.h"
1587 * This is a table of optional op-codes. All of them represent
1588 * 'synthetic' instructions that seem popular.
1590 * Here we make some pseudo op-codes. Every code has a bit set to say
1591 * it is synthetic. This lets you catch them if you want to
1592 * ban these opcodes. They are mnemonics for "elastic" instructions
1593 * that are supposed to assemble into the fewest bytes needed to do a
1594 * branch, or to do a conditional branch, or whatever.
1596 * The opcode is in the usual place [low-order n*8 bits]. This means
1597 * that if you mask off the bucky bits, the usual rules apply about
1598 * how long the opcode is.
1600 * All VAX branch displacements come at the end of the instruction.
1601 * For simple branches (1-byte opcode + 1-byte displacement) the last
1602 * operand is coded 'b?' where the "data type" '?' is a clue that we
1603 * may reverse the sense of the branch (complement lowest order bit)
1604 * and branch around a jump. This is by far the most common case.
1605 * That is why the VIT_OPCODE_SYNTHETIC bit is set: it says this is
1606 * a 0-byte op-code followed by 2 or more bytes of operand address.
1608 * If the op-code has VIT_OPCODE_SPECIAL set, then we have a more unusual
1611 * For JBSB & JBR the treatment is the similar, except (1) we have a 'bw'
1612 * option before (2) we can directly JSB/JMP because there is no condition.
1613 * These operands have 'b-' as their access/data type.
1615 * That leaves a bunch of random opcodes: JACBx, JxOBxxx. In these
1616 * cases, we do the same idea. JACBxxx are all marked with a 'b!'
1617 * JAOBxxx & JSOBxxx are marked with a 'b:'.
1620 #if (VIT_OPCODE_SYNTHETIC != 0x80000000)
1621 You have just broken the encoding below
, which assumes the sign bit
1622 means
'I am an imaginary instruction'.
1625 #if (VIT_OPCODE_SPECIAL != 0x40000000)
1626 You have just broken the encoding below
, which assumes the
0x40 M bit means
1627 'I am not to be "optimised" the way normal branches are'.
1630 static const struct vot
1631 synthetic_votstrs
[] =
1633 {"jbsb", {"b-", 0xC0000010}}, /* BSD 4.2 */
1634 /* jsb used already */
1635 {"jbr", {"b-", 0xC0000011}}, /* BSD 4.2 */
1636 {"jr", {"b-", 0xC0000011}}, /* consistent */
1637 {"jneq", {"b?", 0x80000012}},
1638 {"jnequ", {"b?", 0x80000012}},
1639 {"jeql", {"b?", 0x80000013}},
1640 {"jeqlu", {"b?", 0x80000013}},
1641 {"jgtr", {"b?", 0x80000014}},
1642 {"jleq", {"b?", 0x80000015}},
1643 /* un-used opcodes here */
1644 {"jgeq", {"b?", 0x80000018}},
1645 {"jlss", {"b?", 0x80000019}},
1646 {"jgtru", {"b?", 0x8000001a}},
1647 {"jlequ", {"b?", 0x8000001b}},
1648 {"jvc", {"b?", 0x8000001c}},
1649 {"jvs", {"b?", 0x8000001d}},
1650 {"jgequ", {"b?", 0x8000001e}},
1651 {"jcc", {"b?", 0x8000001e}},
1652 {"jlssu", {"b?", 0x8000001f}},
1653 {"jcs", {"b?", 0x8000001f}},
1655 {"jacbw", {"rwrwmwb!", 0xC000003d}},
1656 {"jacbf", {"rfrfmfb!", 0xC000004f}},
1657 {"jacbd", {"rdrdmdb!", 0xC000006f}},
1658 {"jacbb", {"rbrbmbb!", 0xC000009d}},
1659 {"jacbl", {"rlrlmlb!", 0xC00000f1}},
1660 {"jacbg", {"rgrgmgb!", 0xC0004ffd}},
1661 {"jacbh", {"rhrhmhb!", 0xC0006ffd}},
1663 {"jbs", {"rlvbb?", 0x800000e0}},
1664 {"jbc", {"rlvbb?", 0x800000e1}},
1665 {"jbss", {"rlvbb?", 0x800000e2}},
1666 {"jbcs", {"rlvbb?", 0x800000e3}},
1667 {"jbsc", {"rlvbb?", 0x800000e4}},
1668 {"jbcc", {"rlvbb?", 0x800000e5}},
1669 {"jbssi", {"rlvbb?", 0x800000e6}},
1670 {"jbcci", {"rlvbb?", 0x800000e7}},
1671 {"jlbs", {"rlb?", 0x800000e8}},
1672 {"jlbc", {"rlb?", 0x800000e9}},
1674 {"jaoblss", {"rlmlb:", 0xC00000f2}},
1675 {"jaobleq", {"rlmlb:", 0xC00000f3}},
1676 {"jsobgeq", {"mlb:", 0xC00000f4}},
1677 {"jsobgtr", {"mlb:", 0xC00000f5}},
1679 /* CASEx has no branch addresses in our conception of it. */
1680 /* You should use ".word ..." statements after the "case ...". */
1682 {"", {"", 0}} /* empty is end sentinel */
1684 }; /* synthetic_votstrs */
1687 * v i p _ b e g i n ( )
1689 * Call me once before you decode any lines.
1690 * I decode votstrs into a hash table at op_hash (which I create).
1691 * I return an error text or null.
1692 * If you want, I will include the 'synthetic' jXXX instructions in the
1693 * instruction table.
1694 * You must nominate metacharacters for eg DEC's "#", "@", "^".
1698 vip_begin (synthetic_too
, immediate
, indirect
, displen
)
1699 int synthetic_too
; /* 1 means include jXXX op-codes. */
1700 const char *immediate
, *indirect
, *displen
;
1702 const struct vot
*vP
; /* scan votstrs */
1703 const char *retval
= 0; /* error text */
1705 op_hash
= hash_new ();
1707 for (vP
= votstrs
; *vP
->vot_name
&& !retval
; vP
++)
1708 retval
= hash_insert (op_hash
, vP
->vot_name
, (PTR
) &vP
->vot_detail
);
1711 for (vP
= synthetic_votstrs
; *vP
->vot_name
&& !retval
; vP
++)
1712 retval
= hash_insert (op_hash
, vP
->vot_name
, (PTR
) &vP
->vot_detail
);
1715 vip_op_defaults (immediate
, indirect
, displen
);
1725 * This converts a string into a vax instruction.
1726 * The string must be a bare single instruction in dec-vax (with BSD4 frobs)
1728 * It provides some error messages: at most one fatal error message (which
1729 * stops the scan) and at most one warning message for each operand.
1730 * The vax instruction is returned in exploded form, since we have no
1731 * knowledge of how you parse (or evaluate) your expressions.
1732 * We do however strip off and decode addressing modes and operation
1735 * The exploded instruction is returned to a struct vit of your choice.
1736 * #include "vax-inst.h" to know what a struct vit is.
1738 * This function's value is a string. If it is not "" then an internal
1739 * logic error was found: read this code to assign meaning to the string.
1740 * No argument string should generate such an error string:
1741 * it means a bug in our code, not in the user's text.
1743 * You MUST have called vip_begin() once before using this function.
1747 vip (vitP
, instring
)
1748 struct vit
*vitP
; /* We build an exploded instruction here. */
1749 char *instring
; /* Text of a vax instruction: we modify. */
1751 /* How to bit-encode this opcode. */
1752 struct vot_wot
*vwP
;
1753 /* 1/skip whitespace.2/scan vot_how */
1756 /* counts number of operands seen */
1757 unsigned char count
;
1758 /* scan operands in struct vit */
1759 struct vop
*operandp
;
1760 /* error over all operands */
1761 const char *alloperr
;
1762 /* Remember char, (we clobber it with '\0' temporarily). */
1764 /* Op-code of this instruction. */
1767 if (*instring
== ' ')
1768 ++instring
; /* Skip leading whitespace. */
1769 for (p
= instring
; *p
&& *p
!= ' '; p
++);; /* MUST end in end-of-string or exactly 1 space. */
1770 /* Scanned up to end of operation-code. */
1771 /* Operation-code is ended with whitespace. */
1772 if (p
- instring
== 0)
1774 vitP
->vit_error
= _("No operator");
1776 memset (vitP
->vit_opcode
, '\0', sizeof (vitP
->vit_opcode
));
1783 * Here with instring pointing to what better be an op-name, and p
1784 * pointing to character just past that.
1785 * We trust instring points to an op-name, with no whitespace.
1787 vwP
= (struct vot_wot
*) hash_find (op_hash
, instring
);
1788 *p
= c
; /* Restore char after op-code. */
1791 vitP
->vit_error
= _("Unknown operator");
1793 memset (vitP
->vit_opcode
, '\0', sizeof (vitP
->vit_opcode
));
1798 * We found a match! So lets pick up as many operands as the
1799 * instruction wants, and even gripe if there are too many.
1800 * We expect comma to seperate each operand.
1801 * We let instring track the text, while p tracks a part of the
1806 * The lines below know about 2-byte opcodes starting FD,FE or FF.
1807 * They also understand synthetic opcodes. Note:
1808 * we return 32 bits of opcode, including bucky bits, BUT
1809 * an opcode length is either 8 or 16 bits for vit_opcode_nbytes.
1811 oc
= vwP
->vot_code
; /* The op-code. */
1812 vitP
->vit_opcode_nbytes
= (oc
& 0xFF) >= 0xFD ? 2 : 1;
1813 md_number_to_chars (vitP
->vit_opcode
, oc
, 4);
1814 count
= 0; /* no operands seen yet */
1815 instring
= p
; /* point just past operation code */
1817 for (howp
= vwP
->vot_how
, operandp
= vitP
->vit_operand
;
1818 !(alloperr
&& *alloperr
) && *howp
;
1819 operandp
++, howp
+= 2)
1822 * Here to parse one operand. Leave instring pointing just
1823 * past any one ',' that marks the end of this operand.
1826 as_fatal (_("odd number of bytes in operand description"));
1829 for (q
= instring
; (c
= *q
) && c
!= ','; q
++)
1832 * Q points to ',' or '\0' that ends argument. C is that
1836 operandp
->vop_width
= howp
[1];
1837 operandp
->vop_nbytes
= vax_operand_width_size
[(unsigned) howp
[1]];
1838 operandp
->vop_access
= howp
[0];
1839 vip_op (instring
, operandp
);
1840 *q
= c
; /* Restore input text. */
1841 if (operandp
->vop_error
)
1842 alloperr
= _("Bad operand");
1843 instring
= q
+ (c
? 1 : 0); /* next operand (if any) */
1844 count
++; /* won another argument, may have an operr */
1847 alloperr
= _("Not enough operands");
1851 if (*instring
== ' ')
1852 instring
++; /* Skip whitespace. */
1854 alloperr
= _("Too many operands");
1856 vitP
->vit_error
= alloperr
;
1859 vitP
->vit_operands
= count
;
1865 * Test program for above.
1868 struct vit myvit
; /* build an exploded vax instruction here */
1869 char answer
[100]; /* human types a line of vax assembler here */
1870 char *mybug
; /* "" or an internal logic diagnostic */
1871 int mycount
; /* number of operands */
1872 struct vop
*myvop
; /* scan operands from myvit */
1873 int mysynth
; /* 1 means want synthetic opcodes. */
1874 char my_immediate
[200];
1875 char my_indirect
[200];
1876 char my_displen
[200];
1882 printf ("0 means no synthetic instructions. ");
1883 printf ("Value for vip_begin? ");
1885 sscanf (answer
, "%d", &mysynth
);
1886 printf ("Synthetic opcodes %s be included.\n", mysynth
? "will" : "will not");
1887 printf ("enter immediate symbols eg enter # ");
1888 gets (my_immediate
);
1889 printf ("enter indirect symbols eg enter @ ");
1891 printf ("enter displen symbols eg enter ^ ");
1893 if (p
= vip_begin (mysynth
, my_immediate
, my_indirect
, my_displen
))
1895 error ("vip_begin=%s", p
);
1897 printf ("An empty input line will quit you from the vax instruction parser\n");
1900 printf ("vax instruction: ");
1905 break; /* out of for each input text loop */
1907 vip (&myvit
, answer
);
1908 if (*myvit
.vit_error
)
1910 printf ("ERR:\"%s\"\n", myvit
.vit_error
);
1913 for (mycount
= myvit
.vit_opcode_nbytes
, p
= myvit
.vit_opcode
;
1918 printf ("%02x ", *p
& 0xFF);
1920 printf (" operand count=%d.\n", mycount
= myvit
.vit_operands
);
1921 for (myvop
= myvit
.vit_operand
; mycount
; mycount
--, myvop
++)
1923 printf ("mode=%xx reg=%xx ndx=%xx len='%c'=%c%c%d. expr=\"",
1924 myvop
->vop_mode
, myvop
->vop_reg
, myvop
->vop_ndx
,
1925 myvop
->vop_short
, myvop
->vop_access
, myvop
->vop_width
,
1927 for (p
= myvop
->vop_expr_begin
; p
<= myvop
->vop_expr_end
; p
++)
1932 if (myvop
->vop_error
)
1934 printf (" err:\"%s\"\n", myvop
->vop_error
);
1936 if (myvop
->vop_warn
)
1938 printf (" wrn:\"%s\"\n", myvop
->vop_warn
);
1943 exit (EXIT_SUCCESS
);
1946 #endif /* #ifdef test */
1948 /* end of vax_ins_parse.c */
1950 /* vax_reg_parse.c - convert a VAX register name to a number */
1952 /* Copyright (C) 1987 Free Software Foundation, Inc. A part of GNU. */
1955 * v a x _ r e g _ p a r s e ( )
1957 * Take 3 char.s, the last of which may be `\0` (non-existent)
1958 * and return the VAX register number that they represent.
1960 * Return -1 if they don't form a register name. Good names return
1961 * a number from 0:15 inclusive.
1963 * Case is not important in a name.
1965 * Register names understood are:
1992 int /* return -1 or 0:15 */
1993 vax_reg_parse (c1
, c2
, c3
) /* 3 chars of register name */
1994 char c1
, c2
, c3
; /* c3 == 0 if 2-character reg name */
1996 int retval
; /* return -1:15 */
2004 if (isdigit (c2
) && c1
== 'r')
2009 retval
= retval
* 10 + c3
- '0';
2010 retval
= (retval
> 15) ? -1 : retval
;
2011 /* clamp the register value to 1 hex digit */
2014 retval
= -1; /* c3 must be '\0' or a digit */
2016 else if (c3
) /* There are no three letter regs */
2035 else if (c1
== 'p' && c2
== 'c')
2045 * Parse a vax operand in DEC assembler notation.
2046 * For speed, expect a string of whitespace to be reduced to a single ' '.
2047 * This is the case for GNU AS, and is easy for other DEC-compatible
2050 * Knowledge about DEC VAX assembler operand notation lives here.
2051 * This doesn't even know what a register name is, except it believes
2052 * all register names are 2 or 3 characters, and lets vax_reg_parse() say
2053 * what number each name represents.
2054 * It does, however, know that PC, SP etc are special registers so it can
2055 * detect addressing modes that are silly for those registers.
2057 * Where possible, it delivers 1 fatal or 1 warning message if the operand
2058 * is suspect. Exactly what we test for is still evolving.
2066 * There were a number of 'mismatched argument type' bugs to vip_op.
2067 * The most general solution is to typedef each (of many) arguments.
2068 * We used instead a typedef'd argument block. This is less modular
2069 * than using seperate return pointers for each result, but runs faster
2070 * on most engines, and seems to keep programmers happy. It will have
2071 * to be done properly if we ever want to use vip_op as a general-purpose
2072 * module (it was designed to be).
2076 * Doesn't support DEC "G^" format operands. These always take 5 bytes
2077 * to express, and code as modes 8F or 9F. Reason: "G^" deprives you of
2078 * optimising to (say) a "B^" if you are lucky in the way you link.
2079 * When someone builds a linker smart enough to convert "G^" to "B^", "W^"
2080 * whenever possible, then we should implement it.
2081 * If there is some other use for "G^", feel free to code it in!
2086 * If I nested if()s more, I could avoid testing (*err) which would save
2087 * time, space and page faults. I didn't nest all those if()s for clarity
2088 * and because I think the mode testing can be re-arranged 1st to test the
2089 * commoner constructs 1st. Does anybody have statistics on this?
2095 * In future, we should be able to 'compose' error messages in a scratch area
2096 * and give the user MUCH more informative error messages. Although this takes
2097 * a little more code at run-time, it will make this module much more self-
2098 * documenting. As an example of what sucks now: most error messages have
2099 * hardwired into them the DEC VAX metacharacters "#^@" which are nothing like
2100 * the Un*x characters "$`*", that most users will expect from this AS.
2104 * The input is a string, ending with '\0'.
2106 * We also require a 'hint' of what kind of operand is expected: so
2107 * we can remind caller not to write into literals for instance.
2109 * The output is a skeletal instruction.
2111 * The algorithm has two parts.
2112 * 1. extract the syntactic features (parse off all the @^#-()+[] mode crud);
2113 * 2. express the @^#-()+[] as some parameters suited to further analysis.
2115 * 2nd step is where we detect the googles of possible invalid combinations
2116 * a human (or compiler) might write. Note that if we do a half-way
2117 * decent assembler, we don't know how long to make (eg) displacement
2118 * fields when we first meet them (because they may not have defined values).
2119 * So we must wait until we know how many bits are needed for each address,
2120 * then we can know both length and opcodes of instructions.
2121 * For reason(s) above, we will pass to our caller a 'broken' instruction
2122 * of these major components, from which our caller can generate instructions:
2123 * - displacement length I^ S^ L^ B^ W^ unspecified
2125 * - register R0-R15 or absent
2126 * - index register R0-R15 or absent
2127 * - expression text what we don't parse
2128 * - error text(s) why we couldn't understand the operand
2132 * To decode output of this, test errtxt. If errtxt[0] == '\0', then
2133 * we had no errors that prevented parsing. Also, if we ever report
2134 * an internal bug, errtxt[0] is set non-zero. So one test tells you
2135 * if the other outputs are to be taken seriously.
2140 * Because this module is useful for both VMS and UN*X style assemblers
2141 * and because of the variety of UN*X assemblers we must recognise
2142 * the different conventions for assembler operand notation. For example
2143 * VMS says "#42" for immediate mode, while most UN*X say "$42".
2144 * We permit arbitrary sets of (single) characters to represent the
2145 * 3 concepts that DEC writes '#', '@', '^'.
2148 /* character tests */
2149 #define VIP_IMMEDIATE 01 /* Character is like DEC # */
2150 #define VIP_INDIRECT 02 /* Char is like DEC @ */
2151 #define VIP_DISPLEN 04 /* Char is like DEC ^ */
2153 #define IMMEDIATEP(c) (vip_metacharacters [(c)&0xff]&VIP_IMMEDIATE)
2154 #define INDIRECTP(c) (vip_metacharacters [(c)&0xff]&VIP_INDIRECT)
2155 #define DISPLENP(c) (vip_metacharacters [(c)&0xff]&VIP_DISPLEN)
2157 /* We assume 8 bits per byte. Use vip_op_defaults() to set these up BEFORE we
2161 #if defined(CONST_TABLE)
2163 #define I VIP_IMMEDIATE,
2164 #define S VIP_INDIRECT,
2165 #define D VIP_DISPLEN,
2167 vip_metacharacters
[256] =
2169 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/* ^@ ^A ^B ^C ^D ^E ^F ^G ^H ^I ^J ^K ^L ^M ^N ^O*/
2170 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/* ^P ^Q ^R ^S ^T ^U ^V ^W ^X ^Y ^Z ^[ ^\ ^] ^^ ^_ */
2171 _ _ _ _ I _ _ _ _ _ S _ _ _ _ _
/* sp ! " # $ % & ' ( ) * + , - . / */
2172 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/*0 1 2 3 4 5 6 7 8 9 : ; < = > ?*/
2173 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/*@ A B C D E F G H I J K L M N O*/
2174 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/*P Q R S T U V W X Y Z [ \ ] ^ _*/
2175 D _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/*` a b c d e f g h i j k l m n o*/
2176 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
/*p q r s t u v w x y z { | } ~ ^?*/
2178 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
2179 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
2180 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
2181 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
2182 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
2183 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
2184 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
2185 _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
2192 static char vip_metacharacters
[256];
2195 vip_op_1 (bit
, syms
)
2201 while ((t
= *syms
++) != 0)
2202 vip_metacharacters
[t
] |= bit
;
2205 /* Can be called any time. More arguments may appear in future. */
2207 vip_op_defaults (immediate
, indirect
, displen
)
2208 const char *immediate
;
2209 const char *indirect
;
2210 const char *displen
;
2212 vip_op_1 (VIP_IMMEDIATE
, immediate
);
2213 vip_op_1 (VIP_INDIRECT
, indirect
);
2214 vip_op_1 (VIP_DISPLEN
, displen
);
2221 * Dec defines the semantics of address modes (and values)
2222 * by a two-letter code, explained here.
2224 * letter 1: access type
2226 * a address calculation - no data access, registers forbidden
2227 * b branch displacement
2228 * m read - let go of bus - write back "modify"
2230 * v bit field address: like 'a' but registers are OK
2232 * space no operator (eg ".long foo") [our convention]
2234 * letter 2: data type (i.e. width, alignment)
2237 * d double precision floating point (D format)
2238 * f single precision floating point (F format)
2239 * g G format floating
2240 * h H format floating
2245 * ? simple synthetic branch operand
2246 * - unconditional synthetic JSB/JSR operand
2247 * ! complex synthetic branch operand
2249 * The '-?!' letter 2's are not for external consumption. They are used
2250 * for various assemblers. Generally, all unknown widths are assumed 0.
2251 * We don't limit your choice of width character.
2253 * DEC operands are hard work to parse. For example, '@' as the first
2254 * character means indirect (deferred) mode but elswhere it is a shift
2256 * The long-winded explanation of how this is supposed to work is
2257 * cancelled. Read a DEC vax manual.
2258 * We try hard not to parse anything that MIGHT be part of the expression
2259 * buried in that syntax. For example if we see @...(Rn) we don't check
2260 * for '-' before the '(' because mode @-(Rn) does not exist.
2262 * After parsing we have:
2264 * at 1 if leading '@' (or Un*x '*')
2265 * len takes one value from " bilsw". eg B^ -> 'b'.
2266 * hash 1 if leading '#' (or Un*x '$')
2267 * expr_begin, expr_end the expression we did not parse
2268 * even though we don't interpret it, we make use
2269 * of its presence or absence.
2270 * sign -1: -(Rn) 0: absent +1: (Rn)+
2271 * paren 1 if () are around register
2272 * reg major register number 0:15 -1 means absent
2273 * ndx index register number 0:15 -1 means absent
2275 * Again, I dare not explain it: just trace ALL the code!
2279 vip_op (optext
, vopP
)
2280 /* user's input string e.g.: "@B^foo@bar(AP)[FP]:" */
2282 /* Input fields: vop_access, vop_width.
2283 Output fields: _ndx, _reg, _mode, _short, _warn,
2284 _error _expr_begin, _expr_end, _nbytes.
2285 vop_nbytes : number of bytes in a datum. */
2288 /* track operand text forward */
2290 /* track operand text backward */
2292 /* 1 if leading '@' ('*') seen */
2294 /* one of " bilsw" */
2296 /* 1 if leading '#' ('$') seen */
2300 /* 1 if () surround register */
2302 /* register number, -1:absent */
2304 /* index register number -1:absent */
2306 /* report illegal operand, ""==OK */
2307 /* " " is a FAKE error: means we won */
2308 /* ANY err that begins with ' ' is a fake. */
2309 /* " " is converted to "" before return */
2311 /* warn about weird modes pf address */
2313 /* preserve q in case we backup */
2315 /* build up 4-bit operand mode here */
2316 /* note: index mode is in ndx, this is */
2317 /* the major mode of operand address */
2320 * Notice how we move wrong-arg-type bugs INSIDE this module: if we
2321 * get the types wrong below, we lose at compile time rather than at
2324 char access_mode
; /* vop_access. */
2325 char width
; /* vop_width. */
2327 access_mode
= vopP
->vop_access
;
2328 width
= vopP
->vop_width
;
2329 /* None of our code bugs (yet), no user text errors, no warnings
2335 if (*p
== ' ') /* Expect all whitespace reduced to ' '. */
2336 p
++; /* skip over whitespace */
2338 if ((at
= INDIRECTP (*p
)) != 0)
2339 { /* 1 if *p=='@'(or '*' for Un*x) */
2340 p
++; /* at is determined */
2341 if (*p
== ' ') /* Expect all whitespace reduced to ' '. */
2342 p
++; /* skip over whitespace */
2346 * This code is subtle. It tries to detect all legal (letter)'^'
2347 * but it doesn't waste time explicitly testing for premature '\0' because
2348 * this case is rejected as a mismatch against either (letter) or '^'.
2356 if (DISPLENP (p
[1]) && strchr ("bilws", len
= c
))
2357 p
+= 2; /* skip (letter) '^' */
2358 else /* no (letter) '^' seen */
2359 len
= ' '; /* len is determined */
2362 if (*p
== ' ') /* Expect all whitespace reduced to ' '. */
2363 p
++; /* skip over whitespace */
2365 if ((hash
= IMMEDIATEP (*p
)) != 0) /* 1 if *p=='#' ('$' for Un*x) */
2366 p
++; /* hash is determined */
2369 * p points to what may be the beginning of an expression.
2370 * We have peeled off the front all that is peelable.
2371 * We know at, len, hash.
2373 * Lets point q at the end of the text and parse that (backwards).
2376 for (q
= p
; *q
; q
++)
2378 q
--; /* now q points at last char of text */
2380 if (*q
== ' ' && q
>= p
) /* Expect all whitespace reduced to ' '. */
2382 /* reverse over whitespace, but don't */
2383 /* run back over *p */
2386 * As a matter of policy here, we look for [Rn], although both Rn and S^#
2387 * forbid [Rn]. This is because it is easy, and because only a sick
2388 * cyborg would have [...] trailing an expression in a VAX-like assembler.
2389 * A meticulous parser would first check for Rn followed by '(' or '['
2390 * and not parse a trailing ']' if it found another. We just ban expressions
2395 while (q
>= p
&& *q
!= '[')
2397 /* either q<p or we got matching '[' */
2399 err
= _("no '[' to match ']'");
2403 * Confusers like "[]" will eventually lose with a bad register
2404 * name error. So again we don't need to check for early '\0'.
2407 ndx
= vax_reg_parse (q
[1], q
[2], 0);
2408 else if (q
[4] == ']')
2409 ndx
= vax_reg_parse (q
[1], q
[2], q
[3]);
2413 * Since we saw a ']' we will demand a register name in the [].
2414 * If luser hasn't given us one: be rude.
2417 err
= _("bad register in []");
2419 err
= _("[PC] index banned");
2421 q
--; /* point q just before "[...]" */
2425 ndx
= -1; /* no ']', so no iNDeX register */
2428 * If err = "..." then we lost: run away.
2429 * Otherwise ndx == -1 if there was no "[...]".
2430 * Otherwise, ndx is index register number, and q points before "[...]".
2433 if (*q
== ' ' && q
>= p
) /* Expect all whitespace reduced to ' '. */
2435 /* reverse over whitespace, but don't */
2436 /* run back over *p */
2439 sign
= 0; /* no ()+ or -() seen yet */
2441 if (q
> p
+ 3 && *q
== '+' && q
[-1] == ')')
2443 sign
= 1; /* we saw a ")+" */
2444 q
--; /* q points to ')' */
2447 if (*q
== ')' && q
> p
+ 2)
2449 paren
= 1; /* assume we have "(...)" */
2450 while (q
>= p
&& *q
!= '(')
2452 /* either q<p or we got matching '(' */
2454 err
= _("no '(' to match ')'");
2458 * Confusers like "()" will eventually lose with a bad register
2459 * name error. So again we don't need to check for early '\0'.
2462 reg
= vax_reg_parse (q
[1], q
[2], 0);
2463 else if (q
[4] == ')')
2464 reg
= vax_reg_parse (q
[1], q
[2], q
[3]);
2468 * Since we saw a ')' we will demand a register name in the ')'.
2469 * This is nasty: why can't our hypothetical assembler permit
2470 * parenthesised expressions? BECAUSE I AM LAZY! That is why.
2471 * Abuse luser if we didn't spy a register name.
2475 /* JF allow parenthasized expressions. I hope this works */
2479 /* err = "unknown register in ()"; */
2482 q
--; /* point just before '(' of "(...)" */
2484 * If err == "..." then we lost. Run away.
2485 * Otherwise if reg >= 0 then we saw (Rn).
2489 * If err == "..." then we lost.
2490 * Otherwise paren==1 and reg = register in "()".
2496 * If err == "..." then we lost.
2497 * Otherwise, q points just before "(Rn)", if any.
2498 * If there was a "(...)" then paren==1, and reg is the register.
2502 * We should only seek '-' of "-(...)" if:
2503 * we saw "(...)" paren == 1
2504 * we have no errors so far ! *err
2505 * we did not see '+' of "(...)+" sign < 1
2506 * We don't check len. We want a specific error message later if
2507 * user tries "x^...-(Rn)". This is a feature not a bug.
2511 if (paren
&& sign
< 1)/* !sign is adequate test */
2520 * We have back-tracked over most
2521 * of the crud at the end of an operand.
2522 * Unless err, we know: sign, paren. If paren, we know reg.
2523 * The last case is of an expression "Rn".
2524 * This is worth hunting for if !err, !paren.
2525 * We wouldn't be here if err.
2526 * We remember to save q, in case we didn't want "Rn" anyway.
2530 if (*q
== ' ' && q
>= p
) /* Expect all whitespace reduced to ' '. */
2532 /* reverse over whitespace, but don't */
2533 /* run back over *p */
2534 if (q
> p
&& q
< p
+ 3) /* room for Rn or Rnn exactly? */
2535 reg
= vax_reg_parse (p
[0], p
[1], q
< p
+ 2 ? 0 : p
[2]);
2537 reg
= -1; /* always comes here if no register at all */
2539 * Here with a definitive reg value.
2550 * have reg. -1:absent; else 0:15
2554 * We have: err, at, len, hash, ndx, sign, paren, reg.
2555 * Also, any remaining expression is from *p through *q inclusive.
2556 * Should there be no expression, q==p-1. So expression length = q-p+1.
2557 * This completes the first part: parsing the operand text.
2561 * We now want to boil the data down, checking consistency on the way.
2562 * We want: len, mode, reg, ndx, err, p, q, wrn, bug.
2563 * We will deliver a 4-bit reg, and a 4-bit mode.
2567 * Case of branch operand. Different. No L^B^W^I^S^ allowed for instance.
2581 * p:q whatever was input
2583 * err " " or error message, and other outputs trashed
2585 /* branch operands have restricted forms */
2586 if ((!err
|| !*err
) && access_mode
== 'b')
2588 if (at
|| hash
|| sign
|| paren
|| ndx
>= 0 || reg
>= 0 || len
!= ' ')
2589 err
= _("invalid branch operand");
2594 /* Since nobody seems to use it: comment this 'feature'(?) out for now. */
2597 * Case of stand-alone operand. e.g. ".long foo"
2611 * p:q whatever was input
2613 * err " " or error message, and other outputs trashed
2615 if ((!err
|| !*err
) && access_mode
== ' ')
2618 err
= _("address prohibits @");
2620 err
= _("address prohibits #");
2624 err
= _("address prohibits -()");
2626 err
= _("address prohibits ()+");
2629 err
= _("address prohibits ()");
2631 err
= _("address prohibits []");
2633 err
= _("address prohibits register");
2634 else if (len
!= ' ')
2635 err
= _("address prohibits displacement length specifier");
2638 err
= " "; /* succeed */
2642 #endif /*#Ifdef NEVER*/
2648 * len 's' definition
2650 * p:q demand not empty
2651 * sign 0 by paren==0
2652 * paren 0 by "()" scan logic because "S^" seen
2653 * reg -1 or nn by mistake
2662 if ((!err
|| !*err
) && len
== 's')
2664 if (!hash
|| paren
|| at
|| ndx
>= 0)
2665 err
= _("invalid operand of S^#");
2671 * SHIT! we saw S^#Rnn ! put the Rnn back in
2672 * expression. KLUDGE! Use oldq so we don't
2673 * need to know exact length of reg name.
2679 * We have all the expression we will ever get.
2682 err
= _("S^# needs expression");
2683 else if (access_mode
== 'r')
2685 err
= " "; /* WIN! */
2689 err
= _("S^# may only read-access");
2694 * Case of -(Rn), which is weird case.
2700 * sign -1 by definition
2701 * paren 1 by definition
2702 * reg present by definition
2708 * exp "" enforce empty expression
2709 * ndx optional warn if same as reg
2711 if ((!err
|| !*err
) && sign
< 0)
2713 if (len
!= ' ' || hash
|| at
|| p
<= q
)
2714 err
= _("invalid operand of -()");
2717 err
= " "; /* win */
2720 wrn
= _("-(PC) unpredictable");
2721 else if (reg
== ndx
)
2722 wrn
= _("[]index same as -()register: unpredictable");
2727 * We convert "(Rn)" to "@Rn" for our convenience.
2728 * (I hope this is convenient: has someone got a better way to parse this?)
2729 * A side-effect of this is that "@Rn" is a valid operand.
2731 if (paren
&& !sign
&& !hash
&& !at
&& len
== ' ' && p
> q
)
2738 * Case of (Rn)+, which is slightly different.
2744 * sign +1 by definition
2745 * paren 1 by definition
2746 * reg present by definition
2752 * exp "" enforce empty expression
2753 * ndx optional warn if same as reg
2755 if ((!err
|| !*err
) && sign
> 0)
2757 if (len
!= ' ' || hash
|| p
<= q
)
2758 err
= _("invalid operand of ()+");
2761 err
= " "; /* win */
2762 mode
= 8 + (at
? 1 : 0);
2764 wrn
= _("(PC)+ unpredictable");
2765 else if (reg
== ndx
)
2766 wrn
= _("[]index same as ()+register: unpredictable");
2771 * Case of #, without S^.
2775 * hash 1 by definition
2788 if ((!err
|| !*err
) && hash
)
2790 if (len
!= 'i' && len
!= ' ')
2791 err
= _("# conflicts length");
2793 err
= _("# bars register");
2799 * SHIT! we saw #Rnn! Put the Rnn back into the expression.
2800 * By using oldq, we don't need to know how long Rnn was.
2804 reg
= -1; /* no register any more */
2806 err
= " "; /* win */
2808 /* JF a bugfix, I think! */
2809 if (at
&& access_mode
== 'a')
2810 vopP
->vop_nbytes
= 4;
2812 mode
= (at
? 9 : 8);
2814 if ((access_mode
== 'm' || access_mode
== 'w') && !at
)
2815 wrn
= _("writing or modifying # is unpredictable");
2819 * If !*err, then sign == 0
2824 * Case of Rn. We seperate this one because it has a few special
2825 * errors the remaining modes lack.
2829 * hash 0 by program logic
2831 * sign 0 by program logic
2832 * paren 0 by definition
2833 * reg present by definition
2838 * len ' ' enforce no length
2839 * exp "" enforce empty expression
2840 * ndx optional warn if same as reg
2842 if ((!err
|| !*err
) && !paren
&& reg
>= 0)
2845 err
= _("length not needed");
2848 err
= " "; /* win */
2852 err
= _("can't []index a register, because it has no address");
2853 else if (access_mode
== 'a')
2854 err
= _("a register has no address");
2858 * Idea here is to detect from length of datum
2859 * and from register number if we will touch PC.
2861 * vop_nbytes is number of bytes in operand.
2862 * Compute highest byte affected, compare to PC0.
2864 if ((vopP
->vop_nbytes
+ reg
* 4) > 60)
2865 wrn
= _("PC part of operand unpredictable");
2866 err
= " "; /* win */
2871 * If !*err, sign == 0
2873 * paren == 1 OR reg==-1
2877 * Rest of cases fit into one bunch.
2880 * len ' ' or 'b' or 'w' or 'l'
2881 * hash 0 by program logic
2882 * p:q expected (empty is not an error)
2883 * sign 0 by program logic
2888 * out: mode 10 + @ + len
2890 * len ' ' or 'b' or 'w' or 'l'
2892 * ndx optional warn if same as reg
2896 err
= " "; /* win (always) */
2897 mode
= 10 + (at
? 1 : 0);
2904 case ' ': /* assumed B^ until our caller changes it */
2911 * here with completely specified mode
2919 err
= 0; /* " " is no longer an error */
2921 vopP
->vop_mode
= mode
;
2922 vopP
->vop_reg
= reg
;
2923 vopP
->vop_short
= len
;
2924 vopP
->vop_expr_begin
= p
;
2925 vopP
->vop_expr_end
= q
;
2926 vopP
->vop_ndx
= ndx
;
2927 vopP
->vop_error
= err
;
2928 vopP
->vop_warn
= wrn
;
2933 Summary of vip_op outputs.
2937 {@}Rn 5+@ n ' ' optional
2938 branch operand 0 -1 ' ' -1
2940 -(Rn) 7 n ' ' optional
2941 {@}(Rn)+ 8+@ n ' ' optional
2942 {@}#foo, no S^ 8+@ PC " i" optional
2943 {@}{q^}{(Rn)} 10+@+q option " bwl" optional
2947 #ifdef TEST /* #Define to use this testbed. */
2950 * Follows a test program for this function.
2951 * We declare arrays non-local in case some of our tiny-minded machines
2952 * default to small stacks. Also, helps with some debuggers.
2957 char answer
[100]; /* human types into here */
2970 int my_operand_length
;
2971 char my_immediate
[200];
2972 char my_indirect
[200];
2973 char my_displen
[200];
2977 printf ("enter immediate symbols eg enter # ");
2978 gets (my_immediate
);
2979 printf ("enter indirect symbols eg enter @ ");
2981 printf ("enter displen symbols eg enter ^ ");
2983 vip_op_defaults (my_immediate
, my_indirect
, my_displen
);
2986 printf ("access,width (eg 'ab' or 'wh') [empty line to quit] : ");
2990 exit (EXIT_SUCCESS
);
2991 myaccess
= answer
[0];
2992 mywidth
= answer
[1];
2996 my_operand_length
= 1;
2999 my_operand_length
= 8;
3002 my_operand_length
= 4;
3005 my_operand_length
= 16;
3008 my_operand_length
= 32;
3011 my_operand_length
= 4;
3014 my_operand_length
= 16;
3017 my_operand_length
= 8;
3020 my_operand_length
= 2;
3025 my_operand_length
= 0;
3029 my_operand_length
= 2;
3030 printf ("I dn't understand access width %c\n", mywidth
);
3033 printf ("VAX assembler instruction operand: ");
3036 mybug
= vip_op (answer
, myaccess
, mywidth
, my_operand_length
,
3037 &mymode
, &myreg
, &mylen
, &myleft
, &myright
, &myndx
,
3041 printf ("error: \"%s\"\n", myerr
);
3043 printf (" bug: \"%s\"\n", mybug
);
3048 printf ("warning: \"%s\"\n", mywrn
);
3049 mumble ("mode", mymode
);
3050 mumble ("register", myreg
);
3051 mumble ("index", myndx
);
3052 printf ("width:'%c' ", mylen
);
3053 printf ("expression: \"");
3054 while (myleft
<= myright
)
3055 putchar (*myleft
++);
3061 mumble (text
, value
)
3065 printf ("%s:", text
);
3067 printf ("%xx", value
);
3073 #endif /* ifdef TEST */
3077 const int md_short_jump_size
= 3;
3078 const int md_long_jump_size
= 6;
3079 const int md_reloc_size
= 8; /* Size of relocation record */
3082 md_create_short_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
3084 addressT from_addr
, to_addr
;
3090 /* This former calculation was off by two:
3091 offset = to_addr - (from_addr + 1);
3092 We need to account for the one byte instruction and also its
3093 two byte operand. */
3094 offset
= to_addr
- (from_addr
+ 1 + 2);
3095 *ptr
++ = VAX_BRW
; /* branch with word (16 bit) offset */
3096 md_number_to_chars (ptr
, offset
, 2);
3100 md_create_long_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
3102 addressT from_addr
, to_addr
;
3108 offset
= to_addr
- S_GET_VALUE (to_symbol
);
3109 *ptr
++ = VAX_JMP
; /* arbitrary jump */
3110 *ptr
++ = VAX_ABSOLUTE_MODE
;
3111 md_number_to_chars (ptr
, offset
, 4);
3112 fix_new (frag
, ptr
- frag
->fr_literal
, 4, to_symbol
, (long) 0, 0, NO_RELOC
);
3116 CONST
char *md_shortopts
= "d:STt:V+1h:Hv::";
3118 CONST
char *md_shortopts
= "d:STt:V";
3120 struct option md_longopts
[] = {
3121 {NULL
, no_argument
, NULL
, 0}
3123 size_t md_longopts_size
= sizeof(md_longopts
);
3126 md_parse_option (c
, arg
)
3133 as_warn (_("SYMBOL TABLE not implemented"));
3137 as_warn (_("TOKEN TRACE not implemented"));
3141 as_warn (_("Displacement length %s ignored!"), arg
);
3145 as_warn (_("I don't need or use temp. file \"%s\"."), arg
);
3149 as_warn (_("I don't use an interpass file! -V ignored"));
3153 case '+': /* For g++. Hash any name > 31 chars long. */
3154 flag_hash_long_names
= 1;
3157 case '1': /* For backward compatibility */
3161 case 'H': /* Show new symbol after hash truncation */
3162 flag_show_after_trunc
= 1;
3165 case 'h': /* No hashing of mixed-case names */
3167 extern char vms_name_mapping
;
3168 vms_name_mapping
= atoi (arg
);
3169 flag_no_hash_mixed_case
= 1;
3175 extern char *compiler_version_string
;
3176 if (!arg
|| !*arg
|| access (arg
, 0) == 0)
3177 return 0; /* have caller show the assembler version */
3178 compiler_version_string
= arg
;
3191 md_show_usage (stream
)
3194 fprintf(stream
, _("\
3196 -d LENGTH ignored\n\
3203 fprintf (stream
, _("\
3205 -+ hash encode names longer than 31 characters\n\
3206 -1 `const' handling compatible with gcc 1.x\n\
3207 -H show new symbol after hash truncation\n\
3208 -h NUM don't hash mixed-case names, and adjust case:\n\
3209 0 = upper, 2 = lower, 3 = preserve case\n\
3210 -v\"VERSION\" code being assembled was produced by compiler \"VERSION\"\n"));
3214 /* We have no need to default values of symbols. */
3218 md_undefined_symbol (name
)
3224 /* Round up a section size to the appropriate boundary. */
3226 md_section_align (segment
, size
)
3230 return size
; /* Byte alignment is fine */
3233 /* Exactly what point is a PC-relative offset relative TO?
3234 On the vax, they're relative to the address of the offset, plus
3235 its size. (??? Is this right? FIXME-SOON) */
3237 md_pcrel_from (fixP
)
3240 return fixP
->fx_size
+ fixP
->fx_where
+ fixP
->fx_frag
->fr_address
;
3243 /* end of tc-vax.c */