26a75242c12329673589d21218226a59388af739
[platform/upstream/binutils.git] / gas / config / tc-tahoe.c
1 /* tc-tahoe.c
2    Not part of GAS yet. */
3
4 #include "as.h"
5 #include "obstack.h"
6
7 /* this bit glommed from tahoe-inst.h */
8
9 typedef unsigned char byte;
10 typedef byte tahoe_opcodeT;
11
12 /*
13  * This is part of tahoe-ins-parse.c & friends.
14  * We want to parse a tahoe instruction text into a tree defined here.
15  */
16
17 #define TIT_MAX_OPERANDS (4)    /* maximum number of operands in one
18                                    single tahoe instruction */
19
20 struct top                      /* tahoe instruction operand */
21 {
22   int top_ndx;                  /* -1, or index register. eg 7=[R7] */
23   int top_reg;                  /* -1, or register number. eg 7 = R7 or (R7) */
24   byte top_mode;                /* Addressing mode byte. This byte, defines
25                                    which of the 11 modes opcode is. */
26
27   char top_access;              /* Access type wanted for this opperand
28                                    'b'branch ' 'no-instruction 'amrvw' */
29   char top_width;               /* Operand width expected, one of "bwlq?-:!" */
30
31   char *top_error;              /* Say if operand is inappropriate         */
32
33   segT seg_of_operand;          /* segment as returned by expression()*/
34
35   expressionS exp_of_operand;   /* The expression as parsed by expression()*/
36
37   byte top_dispsize;            /* Number of bytes in the displacement if we
38                                    can figure it out */
39 };
40
41 /* The addressing modes for an operand. These numbers are the acutal values
42    for certain modes, so be carefull if you screw with them. */
43 #define TAHOE_DIRECT_REG (0x50)
44 #define TAHOE_REG_DEFERRED (0x60)
45
46 #define TAHOE_REG_DISP (0xE0)
47 #define TAHOE_REG_DISP_DEFERRED (0xF0)
48
49 #define TAHOE_IMMEDIATE (0x8F)
50 #define TAHOE_IMMEDIATE_BYTE (0x88)
51 #define TAHOE_IMMEDIATE_WORD (0x89)
52 #define TAHOE_IMMEDIATE_LONGWORD (0x8F)
53 #define TAHOE_ABSOLUTE_ADDR (0x9F)
54
55 #define TAHOE_DISPLACED_RELATIVE (0xEF)
56 #define TAHOE_DISP_REL_DEFERRED (0xFF)
57
58 #define TAHOE_AUTO_DEC (0x7E)
59 #define TAHOE_AUTO_INC (0x8E)
60 #define TAHOE_AUTO_INC_DEFERRED (0x9E)
61 /* INDEXED_REG is decided by the existance or lack of a [reg] */
62
63 /* These are encoded into top_width when top_access=='b'
64    and it's a psuedo op.*/
65 #define TAHOE_WIDTH_ALWAYS_JUMP      '-'
66 #define TAHOE_WIDTH_CONDITIONAL_JUMP '?'
67 #define TAHOE_WIDTH_BIG_REV_JUMP     '!'
68 #define TAHOE_WIDTH_BIG_NON_REV_JUMP ':'
69
70 /* The hex code for certain tahoe commands and modes.
71    This is just for readability. */
72 #define TAHOE_JMP (0x71)
73 #define TAHOE_PC_REL_LONG (0xEF)
74 #define TAHOE_BRB (0x11)
75 #define TAHOE_BRW (0x13)
76 /* These, when 'ored' with, or added to, a register number,
77    set up the number for the displacement mode. */
78 #define TAHOE_PC_OR_BYTE (0xA0)
79 #define TAHOE_PC_OR_WORD (0xC0)
80 #define TAHOE_PC_OR_LONG (0xE0)
81
82 struct tit                      /* get it out of the sewer, it stands for
83                                    tahoe instruction tree (Geeze!) */
84 {
85   tahoe_opcodeT tit_opcode;     /* The opcode. */
86   byte tit_operands;            /* How many operands are here. */
87   struct top tit_operand[TIT_MAX_OPERANDS];     /* Operands */
88   char *tit_error;              /* "" or fatal error text */
89 };
90
91 /* end: tahoe-inst.h */
92
93 /* tahoe.c - tahoe-specific -
94    Not part of gas yet.
95    */
96
97 #include "opcode/tahoe.h"
98
99 /* This is the number to put at the beginning of the a.out file */
100 long omagic = OMAGIC;
101
102 /* These chars start a comment anywhere in a source file (except inside
103    another comment or a quoted string. */
104 const char comment_chars[] = "#;";
105
106 /* These chars only start a comment at the beginning of a line. */
107 const char line_comment_chars[] = "#";
108
109 /* Chars that can be used to separate mant from exp in floating point nums */
110 const char EXP_CHARS[] = "eE";
111
112 /* Chars that mean this number is a floating point constant
113    as in 0f123.456
114    or    0d1.234E-12 (see exp chars above)
115    Note: The Tahoe port doesn't support floating point constants. This is
116          consistant with 'as' If it's needed, I can always add it later. */
117 const char FLT_CHARS[] = "df";
118
119 /* Also be aware that MAXIMUM_NUMBER_OF_CHARS_FOR_FLOAT may have to be
120    changed in read.c .  Ideally it shouldn't have to know about it at all,
121    but nothing is ideal around here.
122    (The tahoe has plenty of room, so the change currently isn't needed.)
123    */
124
125 static struct tit t;            /* A tahoe instruction after decoding. */
126
127 void float_cons ();
128 /* A table of pseudo ops (sans .), the function called, and an integer op
129    that the function is called with. */
130
131 const pseudo_typeS md_pseudo_table[] =
132 {
133   {"dfloat", float_cons, 'd'},
134   {"ffloat", float_cons, 'f'},
135   {0}
136 };
137 \f
138 /*
139  * For Tahoe, relative addresses of "just the right length" are pretty easy.
140  * The branch displacement is always the last operand, even in
141  * synthetic instructions.
142  * For Tahoe, we encode the relax_substateTs (in e.g. fr_substate) as:
143  *
144  *                  4       3       2       1       0        bit number
145  *      ---/ /--+-------+-------+-------+-------+-------+
146  *              |     what state ?      |  how long ?   |
147  *      ---/ /--+-------+-------+-------+-------+-------+
148  *
149  * The "how long" bits are 00=byte, 01=word, 10=long.
150  * This is a Un*x convention.
151  * Not all lengths are legit for a given value of (what state).
152  * The four states are listed below.
153  * The "how long" refers merely to the displacement length.
154  * The address usually has some constant bytes in it as well.
155  *
156
157 States for Tahoe address relaxing.
158 1.      TAHOE_WIDTH_ALWAYS_JUMP (-)
159         Format: "b-"
160         Tahoe opcodes are:      (Hex)
161                 jr              11
162                 jbr             11
163         Simple branch.
164         Always, 1 byte opcode, then displacement/absolute.
165         If word or longword, change opcode to brw or jmp.
166
167         
168 2.      TAHOE_WIDTH_CONDITIONAL_JUMP (?)
169         J<cond> where <cond> is a simple flag test.
170         Format: "b?"
171         Tahoe opcodes are:      (Hex)
172                 jneq/jnequ      21
173                 jeql/jeqlu      31
174                 jgtr            41
175                 jleq            51
176                 jgeq            81
177                 jlss            91
178                 jgtru           a1
179                 jlequ           b1
180                 jvc             c1
181                 jvs             d1
182                 jlssu/jcs       e1
183                 jgequ/jcc       f1
184         Always, you complement 4th bit to reverse the condition.
185         Always, 1-byte opcode, then 1-byte displacement.
186
187 3.      TAHOE_WIDTH_BIG_REV_JUMP (!)
188         Jbc/Jbs where cond tests a memory bit.
189         Format: "rlvlb!"
190         Tahoe opcodes are:      (Hex)
191                 jbs             0e
192                 jbc             1e
193         Always, you complement 4th bit to reverse the condition.
194         Always, 1-byte opcde, longword, longword-address, 1-word-displacement
195
196 4.      TAHOE_WIDTH_BIG_NON_REV_JUMP (:)
197         JaoblXX/Jbssi
198         Format: "rlmlb:"
199         Tahoe opcodes are:      (Hex)
200                 aojlss          2f
201                 jaoblss         2f
202                 aojleq          3f
203                 jaobleq         3f
204                 jbssi           5f
205         Always, we cannot reverse the sense of the branch; we have a word
206         displacement.
207
208 We need to modify the opcode is for class 1, 2 and 3 instructions.
209 After relax() we may complement the 4th bit of 2 or 3 to reverse sense of
210 branch.
211
212 We sometimes store context in the operand literal. This way we can figure out
213 after relax() what the original addressing mode was. (Was is pc_rel, or
214 pc_rel_disp? That sort of thing.) */
215 \f
216 /* These displacements are relative to the START address of the
217    displacement which is at the start of the displacement, not the end of
218    the instruction. The hardware pc_rel is at the end of the instructions.
219    That's why all the displacements have the length of the displacement added
220    to them. (WF + length(word))
221
222    The first letter is Byte, Word.
223    2nd letter is Forward, Backward. */
224 #define BF (1+ 127)
225 #define BB (1+-128)
226 #define WF (2+ 32767)
227 #define WB (2+-32768)
228 /* Dont need LF, LB because they always reach. [They are coded as 0.] */
229
230 #define C(a,b) ENCODE_RELAX(a,b)
231 /* This macro has no side-effects. */
232 #define ENCODE_RELAX(what,length) (((what) << 2) + (length))
233 #define RELAX_STATE(what) ((what) >> 2)
234 #define RELAX_LENGTH(length) ((length) && 3)
235
236 #define STATE_ALWAYS_BRANCH             (1)
237 #define STATE_CONDITIONAL_BRANCH        (2)
238 #define STATE_BIG_REV_BRANCH            (3)
239 #define STATE_BIG_NON_REV_BRANCH        (4)
240 #define STATE_PC_RELATIVE               (5)
241
242 #define STATE_BYTE                      (0)
243 #define STATE_WORD                      (1)
244 #define STATE_LONG                      (2)
245 #define STATE_UNDF                      (3)     /* Symbol undefined in pass1 */
246
247 /* This is the table used by gas to figure out relaxing modes. The fields are
248    forward_branch reach, backward_branch reach, number of bytes it would take,
249    where the next biggest branch is. */
250 const relax_typeS md_relax_table[] =
251 {
252   {
253     1, 1, 0, 0
254   },                            /* error sentinel   0,0 */
255   {
256     1, 1, 0, 0
257   },                            /* unused           0,1 */
258   {
259     1, 1, 0, 0
260   },                            /* unused           0,2 */
261   {
262     1, 1, 0, 0
263   },                            /* unused           0,3 */
264 /* Unconditional branch cases "jrb"
265      The relax part is the actual displacement */
266   {
267     BF, BB, 1, C (1, 1)
268   },                            /* brb B`foo        1,0 */
269   {
270     WF, WB, 2, C (1, 2)
271   },                            /* brw W`foo        1,1 */
272   {
273     0, 0, 5, 0
274   },                            /* Jmp L`foo        1,2 */
275   {
276     1, 1, 0, 0
277   },                            /* unused           1,3 */
278 /* Reversible Conditional Branch. If the branch won't reach, reverse
279      it, and jump over a brw or a jmp that will reach. The relax part is the
280      actual address. */
281   {
282     BF, BB, 1, C (2, 1)
283   },                            /* b<cond> B`foo    2,0 */
284   {
285     WF + 2, WB + 2, 4, C (2, 2)
286   },                            /* brev over, brw W`foo, over: 2,1 */
287   {
288     0, 0, 7, 0
289   },                            /* brev over, jmp L`foo, over: 2,2 */
290   {
291     1, 1, 0, 0
292   },                            /* unused           2,3 */
293 /* Another type of reversable branch. But this only has a word
294      displacement. */
295   {
296     1, 1, 0, 0
297   },                            /* unused           3,0 */
298   {
299     WF, WB, 2, C (3, 2)
300   },                            /* jbX W`foo        3,1 */
301   {
302     0, 0, 8, 0
303   },                            /* jrevX over, jmp L`foo, over:  3,2 */
304   {
305     1, 1, 0, 0
306   },                            /* unused           3,3 */
307 /* These are the non reversable branches, all of which have a word
308      displacement. If I can't reach, branch over a byte branch, to a
309      jump that will reach. The jumped branch jumps over the reaching
310      branch, to continue with the flow of the program. It's like playing
311      leap frog. */
312   {
313     1, 1, 0, 0
314   },                            /* unused           4,0 */
315   {
316     WF, WB, 2, C (4, 2)
317   },                            /* aobl_ W`foo      4,1 */
318   {
319     0, 0, 10, 0
320   },                            /*aobl_ W`hop,br over,hop: jmp L^foo,over 4,2*/
321   {
322     1, 1, 0, 0
323   },                            /* unused           4,3 */
324 /* Normal displacement mode, no jumping or anything like that.
325      The relax points to one byte before the address, thats why all
326      the numbers are up by one. */
327   {
328     BF + 1, BB + 1, 2, C (5, 1)
329   },                            /* B^"foo"          5,0 */
330   {
331     WF + 1, WB + 1, 3, C (5, 2)
332   },                            /* W^"foo"          5,1 */
333   {
334     0, 0, 5, 0
335   },                            /* L^"foo"          5,2 */
336   {
337     1, 1, 0, 0
338   },                            /* unused           5,3 */
339 };
340
341 #undef C
342 #undef BF
343 #undef BB
344 #undef WF
345 #undef WB
346 /* End relax stuff */
347 \f
348 /* Handle of the OPCODE hash table.  NULL means any use before
349    md_begin() will crash.  */
350 static struct hash_control *op_hash;
351
352 /* Init function. Build the hash table. */
353 void
354 md_begin ()
355 {
356   struct tot *tP;
357   char *errorval = 0;
358   int synthetic_too = 1;        /* If 0, just use real opcodes. */
359
360   op_hash = hash_new ();
361
362   for (tP = totstrs; *tP->name && !errorval; tP++)
363     errorval = hash_insert (op_hash, tP->name, &tP->detail);
364
365   if (synthetic_too)
366     for (tP = synthetic_totstrs; *tP->name && !errorval; tP++)
367       errorval = hash_insert (op_hash, tP->name, &tP->detail);
368
369   if (errorval)
370     as_fatal (errorval);
371 }
372 \f
373 CONST char *md_shortopts = "ad:STt:V";
374 struct option md_longopts[] = {
375   {NULL, no_argument, NULL, 0}
376 };
377 size_t md_longopts_size = sizeof(md_longopts);
378
379 int
380 md_parse_option (c, arg)
381      int c;
382      char *arg;
383 {
384   switch (c)
385     {
386     case 'a':
387       as_warn (_("The -a option doesn't exist. (Despite what the man page says!"));
388       break;
389
390     case 'd':
391       as_warn (_("Displacement length %s ignored!"), arg);
392       break;
393
394     case 'S':
395       as_warn (_("SYMBOL TABLE not implemented"));
396       break;
397
398     case 'T':
399       as_warn (_("TOKEN TRACE not implemented"));
400       break;
401
402     case 't':
403       as_warn (_("I don't need or use temp. file \"%s\"."), arg);
404       break;
405
406     case 'V':
407       as_warn (_("I don't use an interpass file! -V ignored"));
408       break;
409
410     default:
411       return 0;
412     }
413
414   return 1;
415 }
416
417 void
418 md_show_usage (stream)
419      FILE *stream;
420 {
421   fprintf(stream, _("\
422 Tahoe options:\n\
423 -a                      ignored\n\
424 -d LENGTH               ignored\n\
425 -J                      ignored\n\
426 -S                      ignored\n\
427 -t FILE                 ignored\n\
428 -T                      ignored\n\
429 -V                      ignored\n"));
430 }
431 \f
432 /* The functions in this section take numbers in the machine format, and
433    munges them into Tahoe byte order.
434    They exist primarily for cross assembly purpose. */
435 void                            /* Knows about order of bytes in address. */
436 md_number_to_chars (con, value, nbytes)
437      char con[];                /* Return 'nbytes' of chars here. */
438      valueT value;              /* The value of the bits. */
439      int nbytes;                /* Number of bytes in the output. */
440 {
441   number_to_chars_bigendian (con, value, nbytes);
442 }
443
444 #ifdef comment
445 void                            /* Knows about order of bytes in address. */
446 md_number_to_imm (con, value, nbytes)
447      char con[];                /* Return 'nbytes' of chars here. */
448      long int value;            /* The value of the bits. */
449      int nbytes;                /* Number of bytes in the output. */
450 {
451   md_number_to_chars (con, value, nbytes);
452 }
453
454 #endif /* comment */
455
456 void
457 tc_apply_fix (fixP, val)
458      fixS *fixP;
459      long val;
460 {
461   /* should never be called */
462   know (0);
463 }
464
465 void                            /* Knows about order of bytes in address. */
466 md_number_to_disp (con, value, nbytes)
467      char con[];                /* Return 'nbytes' of chars here. */
468      long int value;            /* The value of the bits. */
469      int nbytes;                /* Number of bytes in the output. */
470 {
471   md_number_to_chars (con, value, nbytes);
472 }
473
474 void                            /* Knows about order of bytes in address. */
475 md_number_to_field (con, value, nbytes)
476      char con[];                /* Return 'nbytes' of chars here. */
477      long int value;            /* The value of the bits. */
478      int nbytes;                /* Number of bytes in the output. */
479 {
480   md_number_to_chars (con, value, nbytes);
481 }
482
483 /* Put the bits in an order that a tahoe will understand, despite the ordering
484    of the native machine.
485    On Tahoe: first 4 bytes are normal unsigned big endian long,
486    next three bytes are symbolnum, in kind of 3 byte big endian (least sig. byte last).
487    The last byte is broken up with bit 7 as pcrel,
488         bits 6 & 5 as length,
489         bit 4 as extern and the last nibble as 'undefined'. */
490
491 #if comment
492 void
493 md_ri_to_chars (ri_p, ri)
494      struct relocation_info *ri_p, ri;
495 {
496   byte the_bytes[sizeof (struct relocation_info)];
497   /* The reason I can't just encode these directly into ri_p is that
498      ri_p may point to ri. */
499
500   /* This is easy */
501   md_number_to_chars (the_bytes, ri.r_address, sizeof (ri.r_address));
502
503   /* now the fun stuff */
504   the_bytes[4] = (ri.r_symbolnum >> 16) & 0x0ff;
505   the_bytes[5] = (ri.r_symbolnum >> 8) & 0x0ff;
506   the_bytes[6] = ri.r_symbolnum & 0x0ff;
507   the_bytes[7] = (((ri.r_extern << 4) & 0x10) | ((ri.r_length << 5) & 0x60) |
508                   ((ri.r_pcrel << 7) & 0x80)) & 0xf0;
509
510   bcopy (the_bytes, (char *) ri_p, sizeof (struct relocation_info));
511 }
512
513 #endif /* comment */
514
515 /* Put the bits in an order that a tahoe will understand, despite the ordering
516    of the native machine.
517    On Tahoe: first 4 bytes are normal unsigned big endian long,
518    next three bytes are symbolnum, in kind of 3 byte big endian (least sig. byte last).
519    The last byte is broken up with bit 7 as pcrel,
520         bits 6 & 5 as length,
521         bit 4 as extern and the last nibble as 'undefined'. */
522
523 void 
524 tc_aout_fix_to_chars (where, fixP, segment_address_in_file)
525      char *where;
526      fixS *fixP;
527      relax_addressT segment_address_in_file;
528 {
529   long r_symbolnum;
530
531   know (fixP->fx_addsy != NULL);
532
533   md_number_to_chars (where,
534        fixP->fx_frag->fr_address + fixP->fx_where - segment_address_in_file,
535                       4);
536
537   r_symbolnum = (S_IS_DEFINED (fixP->fx_addsy)
538                  ? S_GET_TYPE (fixP->fx_addsy)
539                  : fixP->fx_addsy->sy_number);
540
541   where[4] = (r_symbolnum >> 16) & 0x0ff;
542   where[5] = (r_symbolnum >> 8) & 0x0ff;
543   where[6] = r_symbolnum & 0x0ff;
544   where[7] = (((is_pcrel (fixP) << 7) & 0x80)
545               | ((((fixP->fx_type == FX_8 || fixP->fx_type == FX_PCREL8
546                     ? 0
547                     : (fixP->fx_type == FX_16 || fixP->fx_type == FX_PCREL16
548                        ? 1
549                     : (fixP->fx_type == FX_32 || fixP->fx_type == FX_PCREL32
550                        ? 2
551                        : 42)))) << 5) & 0x60)
552               | ((!S_IS_DEFINED (fixP->fx_addsy) << 4) & 0x10));
553 }
554
555 /* Relocate byte stuff */
556 \f
557 /* This is for broken word. */
558 const int md_short_jump_size = 3;
559
560 void
561 md_create_short_jump (ptr, from_addr, to_addr, frag, to_symbol)
562      char *ptr;
563      addressT from_addr, to_addr;
564      fragS *frag;
565      symbolS *to_symbol;
566 {
567   valueT offset;
568
569   offset = to_addr - (from_addr + 1);
570   *ptr++ = TAHOE_BRW;
571   md_number_to_chars (ptr, offset, 2);
572 }
573
574 const int md_long_jump_size = 6;
575 const int md_reloc_size = 8;    /* Size of relocation record */
576
577 void
578 md_create_long_jump (ptr, from_addr, to_addr, frag, to_symbol)
579      char *ptr;
580      addressT from_addr, to_addr;
581      fragS *frag;
582      symbolS *to_symbol;
583 {
584   valueT offset;
585
586   offset = to_addr - (from_addr + 4);
587   *ptr++ = TAHOE_JMP;
588   *ptr++ = TAHOE_PC_REL_LONG;
589   md_number_to_chars (ptr, offset, 4);
590 }
591 \f
592 /*
593  *                      md_estimate_size_before_relax()
594  *
595  * Called just before relax().
596  * Any symbol that is now undefined will not become defined, so we assumed
597  * that it will be resolved by the linker.
598  * Return the correct fr_subtype in the frag, for relax()
599  * Return the initial "guess for fr_var" to caller. (How big I think this
600  * will be.)
601  * The guess for fr_var is ACTUALLY the growth beyond fr_fix.
602  * Whatever we do to grow fr_fix or fr_var contributes to our returned value.
603  * Although it may not be explicit in the frag, pretend fr_var starts with a
604  * 0 value.
605  */
606 int
607 md_estimate_size_before_relax (fragP, segment_type)
608      register fragS *fragP;
609      segT segment_type;         /* N_DATA or N_TEXT. */
610 {
611   register char *p;
612   register int old_fr_fix;
613   /*  int pc_rel; FIXME: remove this */
614
615   old_fr_fix = fragP->fr_fix;
616   switch (fragP->fr_subtype)
617     {
618     case ENCODE_RELAX (STATE_PC_RELATIVE, STATE_UNDF):
619       if (S_GET_SEGMENT (fragP->fr_symbol) == segment_type)
620         {
621           /* The symbol was in the same segment as the opcode, and it's
622          a real pc_rel case so it's a relaxable case. */
623           fragP->fr_subtype = ENCODE_RELAX (STATE_PC_RELATIVE, STATE_BYTE);
624         }
625       else
626         {
627           /* This case is still undefined, so asume it's a long word for the
628          linker to fix. */
629           p = fragP->fr_literal + old_fr_fix;
630           *p |= TAHOE_PC_OR_LONG;
631           /* We now know how big it will be, one long word. */
632           fragP->fr_fix += 1 + 4;
633           fix_new (fragP, old_fr_fix + 1, fragP->fr_symbol,
634                    fragP->fr_offset, FX_PCREL32, NULL);
635           frag_wane (fragP);
636         }
637       break;
638
639     case ENCODE_RELAX (STATE_CONDITIONAL_BRANCH, STATE_UNDF):
640       if (S_GET_SEGMENT (fragP->fr_symbol) == segment_type)
641         {
642           fragP->fr_subtype = ENCODE_RELAX (STATE_CONDITIONAL_BRANCH, STATE_BYTE);
643         }
644       else
645         {
646           p = fragP->fr_literal + old_fr_fix;
647           *fragP->fr_opcode ^= 0x10;    /* Reverse sense of branch. */
648           *p++ = 6;
649           *p++ = TAHOE_JMP;
650           *p++ = TAHOE_PC_REL_LONG;
651           fragP->fr_fix += 1 + 1 + 1 + 4;
652           fix_new (fragP, old_fr_fix + 3, fragP->fr_symbol,
653                    fragP->fr_offset, FX_PCREL32, NULL);
654           frag_wane (fragP);
655         }
656       break;
657
658     case ENCODE_RELAX (STATE_BIG_REV_BRANCH, STATE_UNDF):
659       if (S_GET_SEGMENT (fragP->fr_symbol) == segment_type)
660         {
661           fragP->fr_subtype =
662             ENCODE_RELAX (STATE_BIG_REV_BRANCH, STATE_WORD);
663         }
664       else
665         {
666           p = fragP->fr_literal + old_fr_fix;
667           *fragP->fr_opcode ^= 0x10;    /* Reverse sense of branch. */
668           *p++ = 0;
669           *p++ = 6;
670           *p++ = TAHOE_JMP;
671           *p++ = TAHOE_PC_REL_LONG;
672           fragP->fr_fix += 2 + 2 + 4;
673           fix_new (fragP, old_fr_fix + 4, fragP->fr_symbol,
674                    fragP->fr_offset, FX_PCREL32, NULL);
675           frag_wane (fragP);
676         }
677       break;
678
679     case ENCODE_RELAX (STATE_BIG_NON_REV_BRANCH, STATE_UNDF):
680       if (S_GET_SEGMENT (fragP->fr_symbol) == segment_type)
681         {
682           fragP->fr_subtype = ENCODE_RELAX (STATE_BIG_NON_REV_BRANCH, STATE_WORD);
683         }
684       else
685         {
686           p = fragP->fr_literal + old_fr_fix;
687           *p++ = 2;
688           *p++ = 0;
689           *p++ = TAHOE_BRB;
690           *p++ = 6;
691           *p++ = TAHOE_JMP;
692           *p++ = TAHOE_PC_REL_LONG;
693           fragP->fr_fix += 2 + 2 + 2 + 4;
694           fix_new (fragP, old_fr_fix + 6, fragP->fr_symbol,
695                    fragP->fr_offset, FX_PCREL32, NULL);
696           frag_wane (fragP);
697         }
698       break;
699
700     case ENCODE_RELAX (STATE_ALWAYS_BRANCH, STATE_UNDF):
701       if (S_GET_SEGMENT (fragP->fr_symbol) == segment_type)
702         {
703           fragP->fr_subtype = ENCODE_RELAX (STATE_ALWAYS_BRANCH, STATE_BYTE);
704         }
705       else
706         {
707           p = fragP->fr_literal + old_fr_fix;
708           *fragP->fr_opcode = TAHOE_JMP;
709           *p++ = TAHOE_PC_REL_LONG;
710           fragP->fr_fix += 1 + 4;
711           fix_new (fragP, old_fr_fix + 1, fragP->fr_symbol,
712                    fragP->fr_offset, FX_PCREL32, NULL);
713           frag_wane (fragP);
714         }
715       break;
716
717     default:
718       break;
719     }
720   return (fragP->fr_var + fragP->fr_fix - old_fr_fix);
721 }                               /* md_estimate_size_before_relax() */
722 \f
723 /*
724  *                      md_convert_frag();
725  *
726  * Called after relax() is finished.
727  * In:  Address of frag.
728  *      fr_type == rs_machine_dependent.
729  *      fr_subtype is what the address relaxed to.
730  *
731  * Out: Any fixSs and constants are set up.
732  *      Caller will turn frag into a ".space 0".
733  */
734 void
735 md_convert_frag (headers, seg, fragP)
736      object_headers *headers;
737      segT seg;
738      register fragS *fragP;
739 {
740   register char *addressP;      /* -> _var to change. */
741   register char *opcodeP;       /* -> opcode char(s) to change. */
742   register short int length_code;       /* 2=long 1=word 0=byte */
743   register short int extension = 0;     /* Size of relaxed address.
744                                    Added to fr_fix: incl. ALL var chars. */
745   register symbolS *symbolP;
746   register long int where;
747   register long int address_of_var;
748   /* Where, in file space, is _var of *fragP? */
749   register long int target_address;
750   /* Where, in file space, does addr point? */
751
752   know (fragP->fr_type == rs_machine_dependent);
753   length_code = RELAX_LENGTH (fragP->fr_subtype);
754   know (length_code >= 0 && length_code < 3);
755   where = fragP->fr_fix;
756   addressP = fragP->fr_literal + where;
757   opcodeP = fragP->fr_opcode;
758   symbolP = fragP->fr_symbol;
759   know (symbolP);
760   target_address = S_GET_VALUE (symbolP) + fragP->fr_offset;
761   address_of_var = fragP->fr_address + where;
762   switch (fragP->fr_subtype)
763     {
764     case ENCODE_RELAX (STATE_PC_RELATIVE, STATE_BYTE):
765       /* *addressP holds the registers number, plus 0x10, if it's deferred
766        mode. To set up the right mode, just OR the size of this displacement */
767       /* Byte displacement. */
768       *addressP++ |= TAHOE_PC_OR_BYTE;
769       *addressP = target_address - (address_of_var + 2);
770       extension = 2;
771       break;
772
773     case ENCODE_RELAX (STATE_PC_RELATIVE, STATE_WORD):
774       /* Word displacement. */
775       *addressP++ |= TAHOE_PC_OR_WORD;
776       md_number_to_chars (addressP, target_address - (address_of_var + 3), 2);
777       extension = 3;
778       break;
779
780     case ENCODE_RELAX (STATE_PC_RELATIVE, STATE_LONG):
781       /* Long word displacement. */
782       *addressP++ |= TAHOE_PC_OR_LONG;
783       md_number_to_chars (addressP, target_address - (address_of_var + 5), 4);
784       extension = 5;
785       break;
786
787     case ENCODE_RELAX (STATE_CONDITIONAL_BRANCH, STATE_BYTE):
788       *addressP = target_address - (address_of_var + 1);
789       extension = 1;
790       break;
791
792     case ENCODE_RELAX (STATE_CONDITIONAL_BRANCH, STATE_WORD):
793       *opcodeP ^= 0x10;         /* Reverse sense of test. */
794       *addressP++ = 3;          /* Jump over word branch */
795       *addressP++ = TAHOE_BRW;
796       md_number_to_chars (addressP, target_address - (address_of_var + 4), 2);
797       extension = 4;
798       break;
799
800     case ENCODE_RELAX (STATE_CONDITIONAL_BRANCH, STATE_LONG):
801       *opcodeP ^= 0x10;         /* Reverse sense of test. */
802       *addressP++ = 6;
803       *addressP++ = TAHOE_JMP;
804       *addressP++ = TAHOE_PC_REL_LONG;
805       md_number_to_chars (addressP, target_address, 4);
806       extension = 7;
807       break;
808
809     case ENCODE_RELAX (STATE_ALWAYS_BRANCH, STATE_BYTE):
810       *addressP = target_address - (address_of_var + 1);
811       extension = 1;
812       break;
813
814     case ENCODE_RELAX (STATE_ALWAYS_BRANCH, STATE_WORD):
815       *opcodeP = TAHOE_BRW;
816       md_number_to_chars (addressP, target_address - (address_of_var + 2), 2);
817       extension = 2;
818       break;
819
820     case ENCODE_RELAX (STATE_ALWAYS_BRANCH, STATE_LONG):
821       *opcodeP = TAHOE_JMP;
822       *addressP++ = TAHOE_PC_REL_LONG;
823       md_number_to_chars (addressP, target_address - (address_of_var + 5), 4);
824       extension = 5;
825       break;
826
827     case ENCODE_RELAX (STATE_BIG_REV_BRANCH, STATE_WORD):
828       md_number_to_chars (addressP, target_address - (address_of_var + 2), 2);
829       extension = 2;
830       break;
831
832     case ENCODE_RELAX (STATE_BIG_REV_BRANCH, STATE_LONG):
833       *opcodeP ^= 0x10;
834       *addressP++ = 0;
835       *addressP++ = 6;
836       *addressP++ = TAHOE_JMP;
837       *addressP++ = TAHOE_PC_REL_LONG;
838       md_number_to_chars (addressP, target_address, 4);
839       extension = 8;
840       break;
841
842     case ENCODE_RELAX (STATE_BIG_NON_REV_BRANCH, STATE_WORD):
843       md_number_to_chars (addressP, target_address - (address_of_var + 2), 2);
844       extension = 2;
845       break;
846
847     case ENCODE_RELAX (STATE_BIG_NON_REV_BRANCH, STATE_LONG):
848       *addressP++ = 0;
849       *addressP++ = 2;
850       *addressP++ = TAHOE_BRB;
851       *addressP++ = 6;
852       *addressP++ = TAHOE_JMP;
853       *addressP++ = TAHOE_PC_REL_LONG;
854       md_number_to_chars (addressP, target_address, 4);
855       extension = 10;
856       break;
857
858     default:
859       BAD_CASE (fragP->fr_subtype);
860       break;
861     }
862   fragP->fr_fix += extension;
863 }                               /* md_convert_frag */
864 \f
865
866 /* This is the stuff for md_assemble. */
867 #define FP_REG 13
868 #define SP_REG 14
869 #define PC_REG 15
870 #define BIGGESTREG PC_REG
871
872 /*
873  * Parse the string pointed to by START
874  * If it represents a valid register, point START to the character after
875  * the last valid register char, and return the register number (0-15).
876  * If invalid, leave START alone, return -1.
877  * The format has to be exact. I don't do things like eat leading zeros
878  * or the like.
879  * Note: This doesn't check for the next character in the string making
880  * this invalid. Ex: R123 would return 12, it's the callers job to check
881  * what start is point to apon return.
882  *
883  * Valid registers are R1-R15, %1-%15, FP (13), SP (14), PC (15)
884  * Case doesn't matter.
885  */
886 int
887 tahoe_reg_parse (start)
888      char **start;              /* A pointer to the string to parse. */
889 {
890   register char *regpoint = *start;
891   register int regnum = -1;
892
893   switch (*regpoint++)
894     {
895     case '%':                   /* Registers can start with a %,
896                                    R or r, and then a number. */
897     case 'R':
898     case 'r':
899       if (isdigit (*regpoint))
900         {
901           /* Got the first digit. */
902           regnum = *regpoint++ - '0';
903           if ((regnum == 1) && isdigit (*regpoint))
904             {
905               /* Its a two digit number. */
906               regnum = 10 + (*regpoint++ - '0');
907               if (regnum > BIGGESTREG)
908                 {               /* Number too big? */
909                   regnum = -1;
910                 }
911             }
912         }
913       break;
914     case 'F':                   /* Is it the FP */
915     case 'f':
916       switch (*regpoint++)
917         {
918         case 'p':
919         case 'P':
920           regnum = FP_REG;
921         }
922       break;
923     case 's':                   /* How about the SP */
924     case 'S':
925       switch (*regpoint++)
926         {
927         case 'p':
928         case 'P':
929           regnum = SP_REG;
930         }
931       break;
932     case 'p':                   /* OR the PC even */
933     case 'P':
934       switch (*regpoint++)
935         {
936         case 'c':
937         case 'C':
938           regnum = PC_REG;
939         }
940       break;
941     }
942
943   if (regnum != -1)
944     {                           /* No error, so move string pointer */
945       *start = regpoint;
946     }
947   return regnum;                /* Return results */
948 }                               /* tahoe_reg_parse */
949 \f
950 /*
951  * This chops up an operand and figures out its modes and stuff.
952  * It's a little touchy about extra characters.
953  * Optex to start with one extra character so it can be overwritten for
954  * the backward part of the parsing.
955  * You can't put a bunch of extra characters in side to
956  * make the command look cute. ie: * foo ( r1 ) [  r0 ]
957  * If you like doing a lot of typing, try COBOL!
958  * Actually, this parser is a little weak all around. It's designed to be
959  * used with compliers, so I emphisise correct decoding of valid code quickly
960  * rather that catching every possable error.
961  * Note: This uses the expression function, so save input_line_pointer before
962  * calling.
963  *
964  * Sperry defines the semantics of address modes (and values)
965  * by a two-letter code, explained here.
966  *
967  *   letter 1:   access type
968  *
969  *     a         address calculation - no data access, registers forbidden
970  *     b         branch displacement
971  *     m         read - let go of bus - write back "modify"
972  *     r         read
973  *     w         write
974  *     v         bit field address: like 'a' but registers are OK
975  *
976  *   letter 2:   data type (i.e. width, alignment)
977  *
978  *     b         byte
979  *     w         word
980  *     l         longword
981  *     q         quadword (Even regs < 14 allowed) (if 12, you get a warning)
982  *     -         unconditional synthetic jbr operand
983  *     ?         simple synthetic reversable branch operand
984  *     !         complex synthetic reversable branch operand
985  *     :         complex synthetic non-reversable branch operand
986  *
987  * The '-?!:' letter 2's are not for external consumption. They are used
988  * by GAS for psuedo ops relaxing code.
989  *
990  * After parsing topP has:
991  *
992  *   top_ndx:        -1, or the index register. eg 7=[R7]
993  *   top_reg:        -1, or register number. eg 7 = R7 or (R7)
994  *   top_mode:       The addressing mode byte. This byte, defines which of
995  *                   the 11 modes opcode is.
996  *   top_access:     Access type wanted for this opperand 'b'branch ' '
997  *                   no-instruction 'amrvw'
998  *   top_width:      Operand width expected, one of "bwlq?-:!"
999  *   exp_of_operand: The expression as parsed by expression()
1000  *   top_dispsize:   Number of bytes in the displacement if we can figure it
1001  *                   out and it's relavent.
1002  *
1003  * Need syntax checks built.
1004  */
1005
1006 void
1007 tip_op (optex, topP)
1008      char *optex;               /* The users text input, with one leading character */
1009      struct top *topP;          /* The tahoe instruction with some fields already set:
1010                          in: access, width
1011                          out: ndx, reg, mode, error, dispsize */
1012
1013 {
1014   int mode = 0;                 /* This operand's mode. */
1015   char segfault = *optex;       /* To keep the back parsing from freaking. */
1016   char *point = optex + 1;      /* Parsing from front to back. */
1017   char *end;                    /* Parsing from back to front. */
1018   int reg = -1;                 /* major register, -1 means absent */
1019   int imreg = -1;               /* Major register in immediate mode */
1020   int ndx = -1;                 /* index register number, -1 means absent */
1021   char dec_inc = ' ';           /* Is the SP auto-incremented '+' or
1022                                    auto-decremented '-' or neither ' '. */
1023   int immediate = 0;            /* 1 if '$' immediate mode */
1024   int call_width = 0;           /* If the caller casts the displacement */
1025   int abs_width = 0;            /* The width of the absolute displacment */
1026   int com_width = 0;            /* Displacement width required by branch */
1027   int deferred = 0;             /* 1 if '*' deferral is used */
1028   byte disp_size = 0;           /* How big is this operand. 0 == don't know */
1029   char *op_bad = "";            /* Bad operand error */
1030
1031   char *tp, *temp, c;           /* Temporary holders */
1032
1033   char access = topP->top_access;       /* Save on a deref. */
1034   char width = topP->top_width;
1035
1036   int really_none = 0;          /* Empty expressions evaluate to 0
1037                                    but I need to know if it's there or not */
1038   expressionS *expP;            /* -> expression values for this operand */
1039
1040   /* Does this command restrict the displacement size. */
1041   if (access == 'b')
1042     com_width = (width == 'b' ? 1 :
1043                  (width == 'w' ? 2 :
1044                   (width == 'l' ? 4 : 0)));
1045
1046   *optex = '\0';                /* This is kind of a back stop for all
1047                                    the searches to fail on if needed.*/
1048   if (*point == '*')
1049     {                           /* A dereference? */
1050       deferred = 1;
1051       point++;
1052     }
1053
1054   /* Force words into a certain mode */
1055   /* Bitch, Bitch, Bitch! */
1056   /*
1057    * Using the ^ operator is ambigous. If I have an absolute label
1058    * called 'w' set to, say 2, and I have the expression 'w^1', do I get
1059    * 1, forced to be in word displacement mode, or do I get the value of
1060    * 'w' or'ed with 1 (3 in this case).
1061    * The default is 'w' as an offset, so that's what I use.
1062    * Stick with `, it does the same, and isn't ambig.
1063    */
1064
1065   if (*point != '\0' && ((point[1] == '^') || (point[1] == '`')))
1066     switch (*point)
1067       {
1068       case 'b':
1069       case 'B':
1070       case 'w':
1071       case 'W':
1072       case 'l':
1073       case 'L':
1074         if (com_width)
1075           as_warn (_("Casting a branch displacement is bad form, and is ignored."));
1076         else
1077           {
1078             c = (isupper (*point) ? tolower (*point) : *point);
1079             call_width = ((c == 'b') ? 1 :
1080                           ((c == 'w') ? 2 : 4));
1081           }
1082         point += 2;
1083         break;
1084       }
1085
1086   /* Setting immediate mode */
1087   if (*point == '$')
1088     {
1089       immediate = 1;
1090       point++;
1091     }
1092
1093   /*
1094    * I've pulled off all the easy stuff off the front, move to the end and
1095    * yank.
1096    */
1097
1098   for (end = point; *end != '\0'; end++)        /* Move to the end. */
1099     ;
1100
1101   if (end != point)             /* Null string? */
1102     end--;
1103
1104   if (end > point && *end == ' ' && end[-1] != '\'')
1105     end--;                      /* Hop white space */
1106
1107   /* Is this an index reg. */
1108   if ((*end == ']') && (end[-1] != '\''))
1109     {
1110       temp = end;
1111
1112       /* Find opening brace. */
1113       for (--end; (*end != '[' && end != point); end--)
1114         ;
1115
1116       /* If I found the opening brace, get the index register number. */
1117       if (*end == '[')
1118         {
1119           tp = end + 1;         /* tp should point to the start of a reg. */
1120           ndx = tahoe_reg_parse (&tp);
1121           if (tp != temp)
1122             {                   /* Reg. parse error. */
1123               ndx = -1;
1124             }
1125           else
1126             {
1127               end--;            /* Found it, move past brace. */
1128             }
1129           if (ndx == -1)
1130             {
1131               op_bad = _("Couldn't parse the [index] in this operand.");
1132               end = point;      /* Force all the rest of the tests to fail. */
1133             }
1134         }
1135       else
1136         {
1137           op_bad = _("Couldn't find the opening '[' for the index of this operand.");
1138           end = point;          /* Force all the rest of the tests to fail. */
1139         }
1140     }
1141
1142   /* Post increment? */
1143   if (*end == '+')
1144     {
1145       dec_inc = '+';
1146       /* was:    *end--; */
1147       end--;
1148     }
1149
1150   /* register in parens? */
1151   if ((*end == ')') && (end[-1] != '\''))
1152     {
1153       temp = end;
1154
1155       /* Find opening paren. */
1156       for (--end; (*end != '(' && end != point); end--)
1157         ;
1158
1159       /* If I found the opening paren, get the register number. */
1160       if (*end == '(')
1161         {
1162           tp = end + 1;
1163           reg = tahoe_reg_parse (&tp);
1164           if (tp != temp)
1165             {
1166               /* Not a register, but could be part of the expression. */
1167               reg = -1;
1168               end = temp;       /* Rest the pointer back */
1169             }
1170           else
1171             {
1172               end--;            /* Found the reg. move before opening paren. */
1173             }
1174         }
1175       else
1176         {
1177           op_bad = _("Couldn't find the opening '(' for the deref of this operand.");
1178           end = point;          /* Force all the rest of the tests to fail. */
1179         }
1180     }
1181
1182   /* Pre decrement? */
1183   if (*end == '-')
1184     {
1185       if (dec_inc != ' ')
1186         {
1187           op_bad = _("Operand can't be both pre-inc and post-dec.");
1188           end = point;
1189         }
1190       else
1191         {
1192           dec_inc = '-';
1193           /* was:      *end--; */
1194           end--;
1195         }
1196     }
1197
1198   /*
1199    * Everything between point and end is the 'expression', unless it's
1200    * a register name.
1201    */
1202
1203   c = end[1];
1204   end[1] = '\0';
1205
1206   tp = point;
1207   imreg = tahoe_reg_parse (&point);     /* Get the immediate register
1208                                       if it is there.*/
1209   if (*point != '\0')
1210     {
1211       /* If there is junk after point, then the it's not immediate reg. */
1212       point = tp;
1213       imreg = -1;
1214     }
1215
1216   if (imreg != -1 && reg != -1)
1217     op_bad = _("I parsed 2 registers in this operand.");
1218
1219   /*
1220    * Evaluate whats left of the expression to see if it's valid.
1221    * Note again: This assumes that the calling expression has saved
1222    * input_line_pointer. (Nag, nag, nag!)
1223    */
1224
1225   if (*op_bad == '\0')
1226     {
1227       /* statement has no syntax goofs yet: lets sniff the expression */
1228       input_line_pointer = point;
1229       expP = &(topP->exp_of_operand);
1230       topP->seg_of_operand = expression (expP);
1231       switch (expP->X_op)
1232         {
1233         case O_absent:
1234           /* No expression. For BSD4.2 compatibility, missing expression is
1235              absolute 0 */
1236           expP->X_op = O_constant;
1237           expP->X_add_number = 0;
1238           really_none = 1;
1239         case O_constant:
1240           /* for SEG_ABSOLUTE, we shouldnt need to set X_op_symbol,
1241              X_add_symbol to any particular value. */
1242           /* But, we will program defensively. Since this situation occurs
1243              rarely so it costs us little to do so. */
1244           expP->X_add_symbol = NULL;
1245           expP->X_op_symbol = NULL;
1246           /* How many bytes are needed to express this abs value? */
1247           abs_width =
1248             ((((expP->X_add_number & 0xFFFFFF80) == 0) ||
1249               ((expP->X_add_number & 0xFFFFFF80) == 0xFFFFFF80)) ? 1 :
1250              (((expP->X_add_number & 0xFFFF8000) == 0) ||
1251               ((expP->X_add_number & 0xFFFF8000) == 0xFFFF8000)) ? 2 : 4);
1252
1253         case O_symbol:
1254           break;
1255
1256         default:
1257           /*
1258            * Major bug. We can't handle the case of a operator
1259            * expression in a synthetic opcode variable-length
1260            * instruction.  We don't have a frag type that is smart
1261            * enough to relax a operator, and so we just force all
1262            * operators to behave like SEG_PASS1s.  Clearly, if there is
1263            * a demand we can invent a new or modified frag type and
1264            * then coding up a frag for this case will be easy.
1265            */
1266           need_pass_2 = 1;
1267           op_bad = _("Can't relocate expression error.");
1268           break;
1269
1270         case O_big:
1271           /* This is an error. Tahoe doesn't allow any expressions
1272              bigger that a 32 bit long word. Any bigger has to be referenced
1273              by address. */
1274           op_bad = _("Expression is too large for a 32 bits.");
1275           break;
1276         }
1277       if (*input_line_pointer != '\0')
1278         {
1279           op_bad = _("Junk at end of expression.");
1280         }
1281     }
1282
1283   end[1] = c;
1284
1285   /* I'm done, so restore optex */
1286   *optex = segfault;
1287
1288
1289   /*
1290    * At this point in the game, we (in theory) have all the components of
1291    * the operand at least parsed. Now it's time to check for syntax/semantic
1292    * errors, and build the mode.
1293    * This is what I have:
1294    *   deferred = 1 if '*'
1295    *   call_width = 0,1,2,4
1296    *   abs_width = 0,1,2,4
1297    *   com_width = 0,1,2,4
1298    *   immediate = 1 if '$'
1299    *   ndx = -1 or reg num
1300    *   dec_inc = '-' or '+' or ' '
1301    *   reg = -1 or reg num
1302    *   imreg = -1 or reg num
1303    *   topP->exp_of_operand
1304    *   really_none
1305    */
1306   /* Is there a displacement size? */
1307   disp_size = (call_width ? call_width :
1308                (com_width ? com_width :
1309                 abs_width ? abs_width : 0));
1310
1311   if (*op_bad == '\0')
1312     {
1313       if (imreg != -1)
1314         {
1315           /* Rn */
1316           mode = TAHOE_DIRECT_REG;
1317           if (deferred || immediate || (dec_inc != ' ') ||
1318               (reg != -1) || !really_none)
1319             op_bad = _("Syntax error in direct register mode.");
1320           else if (ndx != -1)
1321             op_bad = _("You can't index a register in direct register mode.");
1322           else if (imreg == SP_REG && access == 'r')
1323             op_bad =
1324               _("SP can't be the source operand with direct register addressing.");
1325           else if (access == 'a')
1326             op_bad = _("Can't take the address of a register.");
1327           else if (access == 'b')
1328             op_bad = _("Direct Register can't be used in a branch.");
1329           else if (width == 'q' && ((imreg % 2) || (imreg > 13)))
1330             op_bad = _("For quad access, the register must be even and < 14.");
1331           else if (call_width)
1332             op_bad = _("You can't cast a direct register.");
1333
1334           if (*op_bad == '\0')
1335             {
1336               /* No errors, check for warnings */
1337               if (width == 'q' && imreg == 12)
1338                 as_warn (_("Using reg 14 for quadwords can tromp the FP register."));
1339
1340               reg = imreg;
1341             }
1342
1343           /* We know: imm = -1 */
1344         }
1345       else if (dec_inc == '-')
1346         {
1347           /* -(SP) */
1348           mode = TAHOE_AUTO_DEC;
1349           if (deferred || immediate || !really_none)
1350             op_bad = _("Syntax error in auto-dec mode.");
1351           else if (ndx != -1)
1352             op_bad = _("You can't have an index auto dec mode.");
1353           else if (access == 'r')
1354             op_bad = _("Auto dec mode cant be used for reading.");
1355           else if (reg != SP_REG)
1356             op_bad = _("Auto dec only works of the SP register.");
1357           else if (access == 'b')
1358             op_bad = _("Auto dec can't be used in a branch.");
1359           else if (width == 'q')
1360             op_bad = _("Auto dec won't work with quadwords.");
1361
1362           /* We know: imm = -1, dec_inc != '-' */
1363         }
1364       else if (dec_inc == '+')
1365         {
1366           if (immediate || !really_none)
1367             op_bad = _("Syntax error in one of the auto-inc modes.");
1368           else if (deferred)
1369             {
1370               /* *(SP)+ */
1371               mode = TAHOE_AUTO_INC_DEFERRED;
1372               if (reg != SP_REG)
1373                 op_bad = _("Auto inc deferred only works of the SP register.");
1374               else if (ndx != -1)
1375                 op_bad = _("You can't have an index auto inc deferred mode.");
1376               else if (access == 'b')
1377                 op_bad = _("Auto inc can't be used in a branch.");
1378             }
1379           else
1380             {
1381               /* (SP)+ */
1382               mode = TAHOE_AUTO_INC;
1383               if (access == 'm' || access == 'w')
1384                 op_bad = _("You can't write to an auto inc register.");
1385               else if (reg != SP_REG)
1386                 op_bad = _("Auto inc only works of the SP register.");
1387               else if (access == 'b')
1388                 op_bad = _("Auto inc can't be used in a branch.");
1389               else if (width == 'q')
1390                 op_bad = _("Auto inc won't work with quadwords.");
1391               else if (ndx != -1)
1392                 op_bad = _("You can't have an index in auto inc mode.");
1393             }
1394
1395           /* We know: imm = -1, dec_inc == ' ' */
1396         }
1397       else if (reg != -1)
1398         {
1399           if ((ndx != -1) && (reg == SP_REG))
1400             op_bad = _("You can't index the sp register.");
1401           if (deferred)
1402             {
1403               /* *<disp>(Rn) */
1404               mode = TAHOE_REG_DISP_DEFERRED;
1405               if (immediate)
1406                 op_bad = _("Syntax error in register displaced mode.");
1407             }
1408           else if (really_none)
1409             {
1410               /* (Rn) */
1411               mode = TAHOE_REG_DEFERRED;
1412               /* if reg = SP then cant be indexed */
1413             }
1414           else
1415             {
1416               /* <disp>(Rn) */
1417               mode = TAHOE_REG_DISP;
1418             }
1419
1420           /* We know: imm = -1, dec_inc == ' ', Reg = -1 */
1421         }
1422       else
1423         {
1424           if (really_none)
1425             op_bad = _("An offest is needed for this operand.");
1426           if (deferred && immediate)
1427             {
1428               /* *$<ADDR> */
1429               mode = TAHOE_ABSOLUTE_ADDR;
1430               disp_size = 4;
1431             }
1432           else if (immediate)
1433             {
1434               /* $<disp> */
1435               mode = TAHOE_IMMEDIATE;
1436               if (ndx != -1)
1437                 op_bad = _("You can't index a register in immediate mode.");
1438               if (access == 'a')
1439                 op_bad = _("Immediate access can't be used as an address.");
1440               /* ponder the wisdom of a cast because it doesn't do any good. */
1441             }
1442           else if (deferred)
1443             {
1444               /* *<disp> */
1445               mode = TAHOE_DISP_REL_DEFERRED;
1446             }
1447           else
1448             {
1449               /* <disp> */
1450               mode = TAHOE_DISPLACED_RELATIVE;
1451             }
1452         }
1453     }
1454
1455   /*
1456    * At this point, all the errors we can do have be checked for.
1457    * We can build the 'top'. */
1458
1459   topP->top_ndx = ndx;
1460   topP->top_reg = reg;
1461   topP->top_mode = mode;
1462   topP->top_error = op_bad;
1463   topP->top_dispsize = disp_size;
1464 }                               /* tip_op */
1465 \f
1466 /*
1467  *                  t i p ( )
1468  *
1469  * This converts a string into a tahoe instruction.
1470  * The string must be a bare single instruction in tahoe (with BSD4 frobs)
1471  * format.
1472  * It provides at most one fatal error message (which stops the scan)
1473  * some warning messages as it finds them.
1474  * The tahoe instruction is returned in exploded form.
1475  *
1476  * The exploded instruction is returned to a struct tit of your choice.
1477  * #include "tahoe-inst.h" to know what a struct tit is.
1478  *
1479  */
1480
1481 static void
1482 tip (titP, instring)
1483      struct tit *titP;          /* We build an exploded instruction here. */
1484      char *instring;            /* Text of a vax instruction: we modify. */
1485 {
1486   register struct tot_wot *twP = NULL;  /* How to bit-encode this opcode. */
1487   register char *p;             /* 1/skip whitespace.2/scan vot_how */
1488   register char *q;             /*  */
1489   register unsigned char count; /* counts number of operands seen */
1490   register struct top *operandp;/* scan operands in struct tit */
1491   register char *alloperr = ""; /* error over all operands */
1492   register char c;              /* Remember char, (we clobber it
1493                                    with '\0' temporarily). */
1494   char *save_input_line_pointer;
1495
1496   if (*instring == ' ')
1497     ++instring;                 /* Skip leading whitespace. */
1498   for (p = instring; *p && *p != ' '; p++)
1499     ;                           /* MUST end in end-of-string or
1500                                    exactly 1 space. */
1501   /* Scanned up to end of operation-code. */
1502   /* Operation-code is ended with whitespace. */
1503   if (p == instring)
1504     {
1505       titP->tit_error = _("No operator");
1506       count = 0;
1507       titP->tit_opcode = 0;
1508     }
1509   else
1510     {
1511       c = *p;
1512       *p = '\0';
1513       /*
1514      * Here with instring pointing to what better be an op-name, and p
1515      * pointing to character just past that.
1516      * We trust instring points to an op-name, with no whitespace.
1517      */
1518       twP = (struct tot_wot *) hash_find (op_hash, instring);
1519       *p = c;                   /* Restore char after op-code. */
1520       if (twP == 0)
1521         {
1522           titP->tit_error = _("Unknown operator");
1523           count = 0;
1524           titP->tit_opcode = 0;
1525         }
1526       else
1527         {
1528           /*
1529        * We found a match! So lets pick up as many operands as the
1530        * instruction wants, and even gripe if there are too many.
1531        * We expect comma to seperate each operand.
1532        * We let instring track the text, while p tracks a part of the
1533        * struct tot.
1534        */
1535
1536           count = 0;            /* no operands seen yet */
1537           instring = p + (*p != '\0');  /* point past the operation code */
1538           /* tip_op() screws with the input_line_pointer, so save it before
1539          I jump in */
1540           save_input_line_pointer = input_line_pointer;
1541           for (p = twP->args, operandp = titP->tit_operand;
1542                !*alloperr && *p;
1543                operandp++, p += 2)
1544             {
1545               /*
1546          * Here to parse one operand. Leave instring pointing just
1547          * past any one ',' that marks the end of this operand.
1548          */
1549               if (!p[1])
1550                 as_fatal (_("Compiler bug: ODD number of bytes in arg structure %s."),
1551                           twP->args);
1552               else if (*instring)
1553                 {
1554                   for (q = instring; (*q != ',' && *q != '\0'); q++)
1555                     {
1556                       if (*q == '\'' && q[1] != '\0')   /* Jump quoted characters */
1557                         q++;
1558                     }
1559                   c = *q;
1560                   /*
1561            * Q points to ',' or '\0' that ends argument. C is that
1562            * character.
1563            */
1564                   *q = '\0';
1565                   operandp->top_access = p[0];
1566                   operandp->top_width = p[1];
1567                   tip_op (instring - 1, operandp);
1568                   *q = c;       /* Restore input text. */
1569                   if (*(operandp->top_error))
1570                     {
1571                       alloperr = operandp->top_error;
1572                     }
1573                   instring = q + (c ? 1 : 0);   /* next operand (if any) */
1574                   count++;      /*  won another argument, may have an operr */
1575                 }
1576               else
1577                 alloperr = _("Not enough operands");
1578             }
1579           /* Restore the pointer. */
1580           input_line_pointer = save_input_line_pointer;
1581
1582           if (!*alloperr)
1583             {
1584               if (*instring == ' ')
1585                 instring++;     /* Skip whitespace. */
1586               if (*instring)
1587                 alloperr = _("Too many operands");
1588             }
1589           titP->tit_error = alloperr;
1590         }
1591     }
1592
1593   titP->tit_opcode = twP->code; /* The op-code. */
1594   titP->tit_operands = count;
1595 }                               /* tip */
1596 \f
1597 /* md_assemble() emit frags for 1 instruction */
1598 void
1599 md_assemble (instruction_string)
1600      char *instruction_string;  /* A string: assemble 1 instruction. */
1601 {
1602   char *p;
1603   register struct top *operandP;/* An operand. Scans all operands. */
1604   /*  char c_save;      fixme: remove this line *//* What used to live after an expression. */
1605   /*  struct frag *fragP;       fixme: remove this line *//* Fragment of code we just made. */
1606   /*  register struct top *end_operandP; fixme: remove this line *//* -> slot just after last operand
1607                                         Limit of the for (each operand). */
1608   register expressionS *expP;   /* -> expression values for this operand */
1609
1610   /* These refer to an instruction operand expression. */
1611   segT to_seg;                  /* Target segment of the address.        */
1612
1613   register valueT this_add_number;
1614   register symbolS *this_add_symbol;    /* +ve (minuend) symbol. */
1615
1616   /*  tahoe_opcodeT opcode_as_number; fixme: remove this line *//* The opcode as a number. */
1617   char *opcodeP;                /* Where it is in a frag. */
1618   /*  char *opmodeP;    fixme: remove this line *//* Where opcode type is, in a frag. */
1619
1620   int dispsize;                 /* From top_dispsize: tahoe_operand_width
1621                                    (in bytes) */
1622   int is_undefined;             /* 1 if operand expression's
1623                                    segment not known yet. */
1624   int pc_rel;                   /* Is this operand pc relative? */
1625
1626   /* Decode the operand. */
1627   tip (&t, instruction_string);
1628
1629   /*
1630    * Check to see if this operand decode properly.
1631    * Notice that we haven't made any frags yet.
1632    * If it goofed, then this instruction will wedge in any pass,
1633    * and we can safely flush it, without causing interpass symbol phase
1634    * errors. That is, without changing label values in different passes.
1635    */
1636   if (*t.tit_error)
1637     {
1638       as_warn (_("Ignoring statement due to \"%s\""), t.tit_error);
1639     }
1640   else
1641     {
1642       /* We saw no errors in any operands - try to make frag(s) */
1643       /* Emit op-code. */
1644       /* Remember where it is, in case we want to modify the op-code later. */
1645       opcodeP = frag_more (1);
1646       *opcodeP = t.tit_opcode;
1647       /* Now do each operand. */
1648       for (operandP = t.tit_operand;
1649            operandP < t.tit_operand + t.tit_operands;
1650            operandP++)
1651         {                       /* for each operand */
1652           expP = &(operandP->exp_of_operand);
1653           if (operandP->top_ndx >= 0)
1654             {
1655               /* Indexed addressing byte
1656            Legality of indexed mode already checked: it is OK */
1657               FRAG_APPEND_1_CHAR (0x40 + operandP->top_ndx);
1658             }                   /* if(top_ndx>=0) */
1659
1660           /* Here to make main operand frag(s). */
1661           this_add_number = expP->X_add_number;
1662           this_add_symbol = expP->X_add_symbol;
1663           to_seg = operandP->seg_of_operand;
1664           know (to_seg == SEG_UNKNOWN || \
1665                 to_seg == SEG_ABSOLUTE || \
1666                 to_seg == SEG_DATA || \
1667                 to_seg == SEG_TEXT || \
1668                 to_seg == SEG_BSS);
1669           is_undefined = (to_seg == SEG_UNKNOWN);
1670           /* Do we know how big this opperand is? */
1671           dispsize = operandP->top_dispsize;
1672           pc_rel = 0;
1673           /* Deal with the branch possabilities. (Note, this doesn't include
1674          jumps.)*/
1675           if (operandP->top_access == 'b')
1676             {
1677               /* Branches must be expressions. A psuedo branch can also jump to
1678            an absolute address. */
1679               if (to_seg == now_seg || is_undefined)
1680                 {
1681                   /* If is_undefined, then it might BECOME now_seg by relax time. */
1682                   if (dispsize)
1683                     {
1684                       /* I know how big the branch is supposed to be (it's a normal
1685                branch), so I set up the frag, and let GAS do the rest. */
1686                       p = frag_more (dispsize);
1687                       fix_new (frag_now, p - frag_now->fr_literal,
1688                                this_add_symbol, this_add_number,
1689                                size_to_fx (dispsize, 1),
1690                                NULL);
1691                     }
1692                   else
1693                     {
1694                       /* (to_seg==now_seg || to_seg == SEG_UNKNOWN) && dispsize==0 */
1695                       /* If we don't know how big it is, then its a synthetic branch,
1696                so we set up a simple relax state. */
1697                       switch (operandP->top_width)
1698                         {
1699                         case TAHOE_WIDTH_CONDITIONAL_JUMP:
1700                           /* Simple (conditional) jump. I may have to reverse the
1701                  condition of opcodeP, and then jump to my destination.
1702                  I set 1 byte aside for the branch off set, and could need 6
1703                  more bytes for the pc_rel jump */
1704                           frag_var (rs_machine_dependent, 7, 1,
1705                                     ENCODE_RELAX (STATE_CONDITIONAL_BRANCH,
1706                                     is_undefined ? STATE_UNDF : STATE_BYTE),
1707                                  this_add_symbol, this_add_number, opcodeP);
1708                           break;
1709                         case TAHOE_WIDTH_ALWAYS_JUMP:
1710                           /* Simple (unconditional) jump. I may have to convert this to
1711                  a word branch, or an absolute jump. */
1712                           frag_var (rs_machine_dependent, 5, 1,
1713                                     ENCODE_RELAX (STATE_ALWAYS_BRANCH,
1714                                     is_undefined ? STATE_UNDF : STATE_BYTE),
1715                                  this_add_symbol, this_add_number, opcodeP);
1716                           break;
1717                           /* The smallest size for the next 2 cases is word. */
1718                         case TAHOE_WIDTH_BIG_REV_JUMP:
1719                           frag_var (rs_machine_dependent, 8, 2,
1720                                     ENCODE_RELAX (STATE_BIG_REV_BRANCH,
1721                                     is_undefined ? STATE_UNDF : STATE_WORD),
1722                                     this_add_symbol, this_add_number,
1723                                     opcodeP);
1724                           break;
1725                         case TAHOE_WIDTH_BIG_NON_REV_JUMP:
1726                           frag_var (rs_machine_dependent, 10, 2,
1727                                     ENCODE_RELAX (STATE_BIG_NON_REV_BRANCH,
1728                                     is_undefined ? STATE_UNDF : STATE_WORD),
1729                                     this_add_symbol, this_add_number,
1730                                     opcodeP);
1731                           break;
1732                         default:
1733                           as_fatal (_("Compliler bug: Got a case (%d) I wasn't expecting."),
1734                                     operandP->top_width);
1735                         }
1736                     }
1737                 }
1738               else
1739                 {
1740                   /* to_seg != now_seg && to_seg != seg_unknown (still in branch)
1741              In other words, I'm jumping out of my segment so extend the
1742              branches to jumps, and let GAS fix them. */
1743
1744                   /* These are "branches" what will always be branches around a jump
1745              to the correct addresss in real life.
1746              If to_seg is SEG_ABSOLUTE, just encode the branch in,
1747              else let GAS fix the address. */
1748
1749                   switch (operandP->top_width)
1750                     {
1751                       /* The theory:
1752                For SEG_ABSOLUTE, then mode is ABSOLUTE_ADDR, jump
1753                to that addresss (not pc_rel).
1754                For other segs, address is a long word PC rel jump. */
1755                     case TAHOE_WIDTH_CONDITIONAL_JUMP:
1756                       /* b<cond> */
1757                       /* To reverse the condition in a TAHOE branch,
1758                complement bit 4 */
1759                       *opcodeP ^= 0x10;
1760                       p = frag_more (7);
1761                       *p++ = 6;
1762                       *p++ = TAHOE_JMP;
1763                       *p++ = (operandP->top_mode ==
1764                               TAHOE_ABSOLUTE_ADDR ? TAHOE_ABSOLUTE_ADDR :
1765                               TAHOE_PC_REL_LONG);
1766                       fix_new (frag_now, p - frag_now->fr_literal,
1767                                this_add_symbol, this_add_number,
1768                        (to_seg != SEG_ABSOLUTE) ? FX_PCREL32 : FX_32, NULL);
1769                       /*
1770              * Now (eg) BLEQ    1f
1771              *          JMP     foo
1772              *  1:
1773              */
1774                       break;
1775                     case TAHOE_WIDTH_ALWAYS_JUMP:
1776                       /* br, just turn it into a jump */
1777                       *opcodeP = TAHOE_JMP;
1778                       p = frag_more (5);
1779                       *p++ = (operandP->top_mode ==
1780                               TAHOE_ABSOLUTE_ADDR ? TAHOE_ABSOLUTE_ADDR :
1781                               TAHOE_PC_REL_LONG);
1782                       fix_new (frag_now, p - frag_now->fr_literal,
1783                                this_add_symbol, this_add_number,
1784                        (to_seg != SEG_ABSOLUTE) ? FX_PCREL32 : FX_32, NULL);
1785                       /* Now (eg) JMP foo */
1786                       break;
1787                     case TAHOE_WIDTH_BIG_REV_JUMP:
1788                       p = frag_more (8);
1789                       *opcodeP ^= 0x10;
1790                       *p++ = 0;
1791                       *p++ = 6;
1792                       *p++ = TAHOE_JMP;
1793                       *p++ = (operandP->top_mode ==
1794                               TAHOE_ABSOLUTE_ADDR ? TAHOE_ABSOLUTE_ADDR :
1795                               TAHOE_PC_REL_LONG);
1796                       fix_new (frag_now, p - frag_now->fr_literal,
1797                                this_add_symbol, this_add_number,
1798                        (to_seg != SEG_ABSOLUTE) ? FX_PCREL32 : FX_32, NULL);
1799                       /*
1800              * Now (eg) ACBx    1f
1801              *          JMP     foo
1802              *  1:
1803              */
1804                       break;
1805                     case TAHOE_WIDTH_BIG_NON_REV_JUMP:
1806                       p = frag_more (10);
1807                       *p++ = 0;
1808                       *p++ = 2;
1809                       *p++ = TAHOE_BRB;
1810                       *p++ = 6;
1811                       *p++ = TAHOE_JMP;
1812                       *p++ = (operandP->top_mode ==
1813                               TAHOE_ABSOLUTE_ADDR ? TAHOE_ABSOLUTE_ADDR :
1814                               TAHOE_PC_REL_LONG);
1815                       fix_new (frag_now, p - frag_now->fr_literal,
1816                                this_add_symbol, this_add_number,
1817                        (to_seg != SEG_ABSOLUTE) ? FX_PCREL32 : FX_32, NULL);
1818                       /*
1819              * Now (eg) xOBxxx  1f
1820              *          BRB     2f
1821              *  1:      JMP     @#foo
1822              *  2:
1823              */
1824                       break;
1825                     case 'b':
1826                     case 'w':
1827                       as_warn (_("Real branch displacements must be expressions."));
1828                       break;
1829                     default:
1830                       as_fatal (_("Complier error: I got an unknown synthetic branch :%c"),
1831                                 operandP->top_width);
1832                       break;
1833                     }
1834                 }
1835             }
1836           else
1837             {
1838               /* It ain't a branch operand. */
1839               switch (operandP->top_mode)
1840                 {
1841                   /* Auto-foo access, only works for one reg (SP)
1842              so the only thing needed is the mode. */
1843                 case TAHOE_AUTO_DEC:
1844                 case TAHOE_AUTO_INC:
1845                 case TAHOE_AUTO_INC_DEFERRED:
1846                   FRAG_APPEND_1_CHAR (operandP->top_mode);
1847                   break;
1848
1849                   /* Numbered Register only access. Only thing needed is the
1850              mode + Register number */
1851                 case TAHOE_DIRECT_REG:
1852                 case TAHOE_REG_DEFERRED:
1853                   FRAG_APPEND_1_CHAR (operandP->top_mode + operandP->top_reg);
1854                   break;
1855
1856                   /* An absolute address. It's size is always 5 bytes.
1857              (mode_type + 4 byte address). */
1858                 case TAHOE_ABSOLUTE_ADDR:
1859                   know ((this_add_symbol == NULL));
1860                   p = frag_more (5);
1861                   *p = TAHOE_ABSOLUTE_ADDR;
1862                   md_number_to_chars (p + 1, this_add_number, 4);
1863                   break;
1864
1865                   /* Immediate data. If the size isn't known, then it's an address
1866              + and offset, which is 4 bytes big. */
1867                 case TAHOE_IMMEDIATE:
1868                   if (this_add_symbol != NULL)
1869                     {
1870                       p = frag_more (5);
1871                       *p++ = TAHOE_IMMEDIATE_LONGWORD;
1872                       fix_new (frag_now, p - frag_now->fr_literal,
1873                                this_add_symbol, this_add_number,
1874                                FX_32, NULL);
1875                     }
1876                   else
1877                     {
1878                       /* It's a integer, and I know it's size. */
1879                       if ((unsigned) this_add_number < 0x40)
1880                         {
1881                           /* Will it fit in a literal? */
1882                           FRAG_APPEND_1_CHAR ((byte) this_add_number);
1883                         }
1884                       else
1885                         {
1886                           p = frag_more (dispsize + 1);
1887                           switch (dispsize)
1888                             {
1889                             case 1:
1890                               *p++ = TAHOE_IMMEDIATE_BYTE;
1891                               *p = (byte) this_add_number;
1892                               break;
1893                             case 2:
1894                               *p++ = TAHOE_IMMEDIATE_WORD;
1895                               md_number_to_chars (p, this_add_number, 2);
1896                               break;
1897                             case 4:
1898                               *p++ = TAHOE_IMMEDIATE_LONGWORD;
1899                               md_number_to_chars (p, this_add_number, 4);
1900                               break;
1901                             }
1902                         }
1903                     }
1904                   break;
1905
1906                   /* Distance from the PC. If the size isn't known, we have to relax
1907              into it. The difference between this and disp(sp) is that
1908              this offset is pc_rel, and disp(sp) isn't.
1909              Note the drop through code. */
1910
1911                 case TAHOE_DISPLACED_RELATIVE:
1912                 case TAHOE_DISP_REL_DEFERRED:
1913                   operandP->top_reg = PC_REG;
1914                   pc_rel = 1;
1915
1916                   /* Register, plus a displacement mode. Save the register number,
1917              and weather its deffered or not, and relax the size if it isn't
1918              known. */
1919                 case TAHOE_REG_DISP:
1920                 case TAHOE_REG_DISP_DEFERRED:
1921                   if (operandP->top_mode == TAHOE_DISP_REL_DEFERRED ||
1922                       operandP->top_mode == TAHOE_REG_DISP_DEFERRED)
1923                     operandP->top_reg += 0x10;  /* deffered mode is always 0x10 higher
1924                                           than it's non-deffered sibling. */
1925
1926                   /* Is this a value out of this segment?
1927              The first part of this conditional is a cludge to make gas
1928              produce the same output as 'as' when there is a lable, in
1929              the current segment, displaceing a register. It's strange,
1930              and no one in their right mind would do it, but it's easy
1931              to cludge. */
1932                   if ((dispsize == 0 && !pc_rel) ||
1933                       (to_seg != now_seg && !is_undefined && to_seg != SEG_ABSOLUTE))
1934                     dispsize = 4;
1935
1936                   if (dispsize == 0)
1937                     {
1938                       /*
1939              * We have a SEG_UNKNOWN symbol, or the size isn't cast.
1940              * It might turn out to be in the same segment as
1941              * the instruction, permitting relaxation.
1942              */
1943                       p = frag_var (rs_machine_dependent, 5, 2,
1944                                     ENCODE_RELAX (STATE_PC_RELATIVE,
1945                                     is_undefined ? STATE_UNDF : STATE_BYTE),
1946                                     this_add_symbol, this_add_number, 0);
1947                       *p = operandP->top_reg;
1948                     }
1949                   else
1950                     {
1951                       /* Either this is an abs, or a cast. */
1952                       p = frag_more (dispsize + 1);
1953                       switch (dispsize)
1954                         {
1955                         case 1:
1956                           *p = TAHOE_PC_OR_BYTE + operandP->top_reg;
1957                           break;
1958                         case 2:
1959                           *p = TAHOE_PC_OR_WORD + operandP->top_reg;
1960                           break;
1961                         case 4:
1962                           *p = TAHOE_PC_OR_LONG + operandP->top_reg;
1963                           break;
1964                         };
1965                       fix_new (frag_now, p + 1 - frag_now->fr_literal,
1966                                this_add_symbol, this_add_number,
1967                                size_to_fx (dispsize, pc_rel), NULL);
1968                     }
1969                   break;
1970                 default:
1971                   as_fatal (_("Barf, bad mode %x\n"), operandP->top_mode);
1972                 }
1973             }
1974         }                       /* for(operandP) */
1975     }                           /* if(!need_pass_2 && !goofed) */
1976 }                               /* tahoe_assemble() */
1977
1978
1979 /* We have no need to default values of symbols. */
1980
1981 /* ARGSUSED */
1982 symbolS *
1983 md_undefined_symbol (name)
1984      char *name;
1985 {
1986   return 0;
1987 }                               /* md_undefined_symbol() */
1988
1989 /* Round up a section size to the appropriate boundary. */
1990 valueT
1991 md_section_align (segment, size)
1992      segT segment;
1993      valueT size;
1994 {
1995   return ((size + 7) & ~7);     /* Round all sects to multiple of 8 */
1996 }                               /* md_section_align() */
1997
1998 /* Exactly what point is a PC-relative offset relative TO?
1999    On the sparc, they're relative to the address of the offset, plus
2000    its size.  This gets us to the following instruction.
2001    (??? Is this right?  FIXME-SOON) */
2002 long 
2003 md_pcrel_from (fixP)
2004      fixS *fixP;
2005 {
2006   return (((fixP->fx_type == FX_8
2007             || fixP->fx_type == FX_PCREL8)
2008            ? 1
2009            : ((fixP->fx_type == FX_16
2010                || fixP->fx_type == FX_PCREL16)
2011               ? 2
2012               : ((fixP->fx_type == FX_32
2013                   || fixP->fx_type == FX_PCREL32)
2014                  ? 4
2015                  : 0))) + fixP->fx_where + fixP->fx_frag->fr_address);
2016 }                               /* md_pcrel_from() */
2017
2018 int 
2019 tc_is_pcrel (fixP)
2020      fixS *fixP;
2021 {
2022   /* should never be called */
2023   know (0);
2024   return (0);
2025 }                               /* tc_is_pcrel() */
2026
2027 /* end of tc-tahoe.c */