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