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