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