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