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