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