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