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