* config/tc-z8k.c (s_segm): Fix indentation.
[external/binutils.git] / gas / config / tc-z8k.c
1 /* tc-z8k.c -- Assemble code for the Zilog Z800n
2    Copyright 1992, 1993, 1994, 1995, 1996, 1998, 2000, 2001, 2002, 2003
3    Free Software Foundation, Inc.
4
5    This file is part of GAS, the GNU Assembler.
6
7    GAS is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 2, or (at your option)
10    any later version.
11
12    GAS is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16
17    You should have received a copy of the GNU General Public License
18    along with GAS; see the file COPYING.  If not, write to the Free
19    Software Foundation, 59 Temple Place - Suite 330, Boston, MA
20    02111-1307, USA.  */
21
22 /* Written By Steve Chamberlain <sac@cygnus.com>.  */
23
24 #define DEFINE_TABLE
25 #include <stdio.h>
26
27 #include "as.h"
28 #include "bfd.h"
29 #include "safe-ctype.h"
30 #include "opcodes/z8k-opc.h"
31
32 const char comment_chars[] = "!";
33 const char line_comment_chars[] = "#";
34 const char line_separator_chars[] = ";";
35
36 extern int machine;
37 extern int coff_flags;
38 int segmented_mode;
39 const int md_reloc_size;
40
41 /* This is non-zero if target was set from the command line.  */
42 static int z8k_target_from_cmdline;
43
44 static void s_segm PARAMS ((int));
45 static void even PARAMS ((int));
46 static int tohex PARAMS ((int));
47 static void sval PARAMS ((int));
48
49 static void
50 s_segm (segm)
51      int segm;
52 {
53   if (segm)
54     {
55       segmented_mode = 1;
56       machine = bfd_mach_z8001;
57       coff_flags = F_Z8001;
58     }
59   else
60     {
61       segmented_mode = 0;
62       machine = bfd_mach_z8002;
63       coff_flags = F_Z8002;
64     }
65 }
66
67 static void
68 even (ignore)
69      int ignore ATTRIBUTE_UNUSED;
70 {
71   frag_align (1, 0, 0);
72   record_alignment (now_seg, 1);
73 }
74
75 static int
76 tohex (c)
77      int c;
78 {
79   if (ISDIGIT (c))
80     return c - '0';
81   if (ISLOWER (c))
82     return c - 'a' + 10;
83   return c - 'A' + 10;
84 }
85
86 static void
87 sval (ignore)
88      int ignore ATTRIBUTE_UNUSED;
89 {
90   SKIP_WHITESPACE ();
91   if (*input_line_pointer == '\'')
92     {
93       int c;
94       input_line_pointer++;
95       c = *input_line_pointer++;
96       while (c != '\'')
97         {
98           if (c == '%')
99             {
100               c = (tohex (input_line_pointer[0]) << 4)
101                 | tohex (input_line_pointer[1]);
102               input_line_pointer += 2;
103             }
104           FRAG_APPEND_1_CHAR (c);
105           c = *input_line_pointer++;
106         }
107       demand_empty_rest_of_line ();
108     }
109 }
110
111 /* This table describes all the machine specific pseudo-ops the assembler
112    has to support.  The fields are:
113    pseudo-op name without dot
114    function to call to execute this pseudo-op
115    Integer arg to pass to the function
116    */
117
118 const pseudo_typeS md_pseudo_table[] = {
119   {"int"    , cons            , 2},
120   {"data.b" , cons            , 1},
121   {"data.w" , cons            , 2},
122   {"data.l" , cons            , 4},
123   {"form"   , listing_psize   , 0},
124   {"heading", listing_title   , 0},
125   {"import" , s_ignore        , 0},
126   {"page"   , listing_eject   , 0},
127   {"program", s_ignore        , 0},
128   {"z8001"  , s_segm          , 1},
129   {"z8002"  , s_segm          , 0},
130
131   {"segm"   , s_segm          , 1},
132   {"unsegm" , s_segm          , 0},
133   {"unseg"  , s_segm          , 0},
134   {"name"   , s_app_file      , 0},
135   {"global" , s_globl         , 0},
136   {"wval"   , cons            , 2},
137   {"lval"   , cons            , 4},
138   {"bval"   , cons            , 1},
139   {"sval"   , sval            , 0},
140   {"rsect"  , obj_coff_section, 0},
141   {"sect"   , obj_coff_section, 0},
142   {"block"  , s_space         , 0},
143   {"even"   , even            , 0},
144   {0        , 0               , 0}
145 };
146
147 const char EXP_CHARS[] = "eE";
148
149 /* Chars that mean this number is a floating point constant.
150    As in 0f12.456
151    or    0d1.2345e12  */
152 const char FLT_CHARS[] = "rRsSfFdDxXpP";
153
154 /* Opcode mnemonics.  */
155 static struct hash_control *opcode_hash_control;
156
157 void
158 md_begin ()
159 {
160   const opcode_entry_type *opcode;
161   int idx = -1;
162
163   opcode_hash_control = hash_new ();
164
165   for (opcode = z8k_table; opcode->name; opcode++)
166     {
167       /* Only enter unique codes into the table.  */
168       if (idx != opcode->idx)
169         hash_insert (opcode_hash_control, opcode->name, (char *) opcode);
170       idx = opcode->idx;
171     }
172
173   /* Default to z8002.  */
174   if (! z8k_target_from_cmdline)
175     s_segm (0);
176
177   /* Insert the pseudo ops, too.  */
178   for (idx = 0; md_pseudo_table[idx].poc_name; idx++)
179     {
180       opcode_entry_type *fake_opcode;
181       fake_opcode = (opcode_entry_type *) malloc (sizeof (opcode_entry_type));
182       fake_opcode->name = md_pseudo_table[idx].poc_name;
183       fake_opcode->func = (void *) (md_pseudo_table + idx);
184       fake_opcode->opcode = 250;
185       hash_insert (opcode_hash_control, fake_opcode->name, fake_opcode);
186     }
187 }
188
189 struct z8k_exp {
190   char *e_beg;
191   char *e_end;
192   expressionS e_exp;
193 };
194
195 typedef struct z8k_op {
196   /* CLASS_REG_xxx.  */
197   int regsize;
198
199   /* 0 .. 15.  */
200   unsigned int reg;
201
202   int mode;
203
204   /* Any other register associated with the mode.  */
205   unsigned int x_reg;
206
207   /* Any expression.  */
208   expressionS exp;
209 } op_type;
210
211 static expressionS *da_operand;
212 static expressionS *imm_operand;
213
214 int reg[16];
215 int the_cc;
216 int the_ctrl;
217 int the_flags;
218 int the_interrupt;
219
220 static char *whatreg PARAMS ((int *, char *));
221 static char *parse_reg PARAMS ((char *, int *, unsigned int *));
222 static char *parse_exp PARAMS ((char *, expressionS *));
223 static char *checkfor PARAMS ((char *, char));
224 static void regword PARAMS ((int, char *));
225 static void regaddr PARAMS ((int, char *));
226 static void get_ctrl_operand
227   PARAMS ((char **, struct z8k_op *, unsigned int));
228 static void get_flags_operand
229   PARAMS ((char **, struct z8k_op *, unsigned int));
230 static void get_interrupt_operand
231   PARAMS ((char **, struct z8k_op *, unsigned int));
232 static void get_cc_operand
233   PARAMS ((char **, struct z8k_op *, unsigned int));
234 static void get_operand
235   PARAMS ((char **, struct z8k_op *, unsigned int));
236 static char *get_operands
237   PARAMS ((const opcode_entry_type *, char *, op_type *));
238 static opcode_entry_type *get_specific
239   PARAMS ((opcode_entry_type *, op_type *));
240 static void newfix
241   PARAMS ((int, int, int, expressionS *));
242 static char *apply_fix
243   PARAMS ((char *, int, expressionS *, int));
244 static void build_bytes
245   PARAMS ((opcode_entry_type *, struct z8k_op *));
246
247 static char *
248 whatreg (reg, src)
249      int *reg;
250      char *src;
251 {
252   if (ISDIGIT (src[1]))
253     {
254       *reg = (src[0] - '0') * 10 + src[1] - '0';
255       return src + 2;
256     }
257   else
258     {
259       *reg = (src[0] - '0');
260       return src + 1;
261     }
262 }
263
264 /* Parse operands
265
266    rh0-rh7, rl0-rl7
267    r0-r15
268    rr0-rr14
269    rq0--rq12
270    WREG r0,r1,r2,r3,r4,r5,r6,r7,fp,sp
271    r0l,r0h,..r7l,r7h
272    @WREG
273    @WREG+
274    @-WREG
275    #const
276 */
277
278 /* Try to parse a reg name.  Return a pointer to the first character
279    in SRC after the reg name.  */
280
281 static char *
282 parse_reg (src, mode, reg)
283      char *src;
284      int *mode;
285      unsigned int *reg;
286 {
287   char *res = 0;
288   char regno;
289
290   if (src[0] == 's' && src[1] == 'p' && (src[2] == 0 || src[2] == ','))
291     {
292       if (segmented_mode)
293         {
294           *mode = CLASS_REG_LONG;
295           *reg = 14;
296         }
297       else
298         {
299           *mode = CLASS_REG_WORD;
300           *reg = 15;
301         }
302       return src + 2;
303     }
304   if (src[0] == 'r')
305     {
306       if (src[1] == 'r')
307         {
308           if (src[2] < '0' || src[2] > '9')
309             return res;  /* Assume no register name but a label starting with 'rr'.  */
310           *mode = CLASS_REG_LONG;
311           res = whatreg (reg, src + 2);
312           regno = *reg;
313           if (regno > 14)
314             as_bad (_("register rr%d out of range"), regno);
315           if (regno & 1)
316             as_bad (_("register rr%d does not exist"), regno);
317         }
318       else if (src[1] == 'h')
319         {
320           if (src[2] < '0' || src[2] > '9')
321             return res;  /* Assume no register name but a label starting with 'rh'.  */
322           *mode = CLASS_REG_BYTE;
323           res = whatreg (reg, src + 2);
324           regno = *reg;
325           if (regno > 7)
326             as_bad (_("register rh%d out of range"), regno);
327         }
328       else if (src[1] == 'l')
329         {
330           if (src[2] < '0' || src[2] > '9')
331             return res;  /* Assume no register name but a label starting with 'rl'.  */
332           *mode = CLASS_REG_BYTE;
333           res = whatreg (reg, src + 2);
334           regno = *reg;
335           if (regno > 7)
336             as_bad (_("register rl%d out of range"), regno);
337           *reg += 8;
338         }
339       else if (src[1] == 'q')
340         {
341           if (src[2] < '0' || src[2] > '9')
342             return res;  /* Assume no register name but a label starting with 'rq'.  */
343           *mode = CLASS_REG_QUAD;
344           res = whatreg (reg, src + 2);
345           regno = *reg;
346           if (regno > 12)
347             as_bad (_("register rq%d out of range"), regno);
348           if (regno & 3)
349             as_bad (_("register rq%d does not exist"), regno);
350         }
351       else
352         {
353           if (src[1] < '0' || src[1] > '9')
354             return res;  /* Assume no register name but a label starting with 'r'.  */
355           *mode = CLASS_REG_WORD;
356           res = whatreg (reg, src + 1);
357           regno = *reg;
358           if (regno > 15)
359             as_bad (_("register r%d out of range"), regno);
360         }
361     }
362   return res;
363 }
364
365 static char *
366 parse_exp (s, op)
367      char *s;
368      expressionS *op;
369 {
370   char *save = input_line_pointer;
371   char *new;
372
373   input_line_pointer = s;
374   expression (op);
375   if (op->X_op == O_absent)
376     as_bad (_("missing operand"));
377   new = input_line_pointer;
378   input_line_pointer = save;
379   return new;
380 }
381
382 /* The many forms of operand:
383
384    <rb>
385    <r>
386    <rr>
387    <rq>
388    @r
389    #exp
390    exp
391    exp(r)
392    r(#exp)
393    r(r)
394    */
395
396 static char *
397 checkfor (ptr, what)
398      char *ptr;
399      char what;
400 {
401   if (*ptr == what)
402     ptr++;
403   else
404     as_bad (_("expected %c"), what);
405
406   return ptr;
407 }
408
409 /* Make sure the mode supplied is the size of a word.  */
410
411 static void
412 regword (mode, string)
413      int mode;
414      char *string;
415 {
416   int ok;
417
418   ok = CLASS_REG_WORD;
419   if (ok != mode)
420     {
421       as_bad (_("register is wrong size for a word %s"), string);
422     }
423 }
424
425 /* Make sure the mode supplied is the size of an address.  */
426
427 static void
428 regaddr (mode, string)
429      int mode;
430      char *string;
431 {
432   int ok;
433
434   ok = segmented_mode ? CLASS_REG_LONG : CLASS_REG_WORD;
435   if (ok != mode)
436     {
437       as_bad (_("register is wrong size for address %s"), string);
438     }
439 }
440
441 struct ctrl_names {
442   int value;
443   char *name;
444 };
445
446 struct ctrl_names ctrl_table[] = {
447   { 0x2, "fcw" },
448   { 0x3, "refresh" },
449   { 0x4, "psapseg" },
450   { 0x5, "psapoff" },
451   { 0x5, "psap" },
452   { 0x6, "nspseg" },
453   { 0x7, "nspoff" },
454   { 0x7, "nsp" },
455   { 0  , 0 }
456 };
457
458 static void
459 get_ctrl_operand (ptr, mode, dst)
460      char **ptr;
461      struct z8k_op *mode;
462      unsigned int dst ATTRIBUTE_UNUSED;
463 {
464   char *src = *ptr;
465   int i;
466
467   while (*src == ' ')
468     src++;
469
470   mode->mode = CLASS_CTRL;
471   for (i = 0; ctrl_table[i].name; i++)
472     {
473       int j;
474
475       for (j = 0; ctrl_table[i].name[j]; j++)
476         {
477           if (ctrl_table[i].name[j] != src[j])
478             goto fail;
479         }
480       the_ctrl = ctrl_table[i].value;
481       *ptr = src + j;
482       return;
483     fail:
484       ;
485     }
486   the_ctrl = 0;
487   return;
488 }
489
490 struct flag_names {
491   int value;
492   char *name;
493
494 };
495
496 struct flag_names flag_table[] = {
497   { 0x1, "p" },
498   { 0x1, "v" },
499   { 0x2, "s" },
500   { 0x4, "z" },
501   { 0x8, "c" },
502   { 0x0, "+" },
503   { 0, 0 }
504 };
505
506 static void
507 get_flags_operand (ptr, mode, dst)
508      char **ptr;
509      struct z8k_op *mode;
510      unsigned int dst ATTRIBUTE_UNUSED;
511 {
512   char *src = *ptr;
513   int i;
514   int j;
515
516   while (*src == ' ')
517     src++;
518
519   mode->mode = CLASS_FLAGS;
520   the_flags = 0;
521   for (j = 0; j <= 9; j++)
522     {
523       if (!src[j])
524         goto done;
525       for (i = 0; flag_table[i].name; i++)
526         {
527           if (flag_table[i].name[0] == src[j])
528             {
529               the_flags = the_flags | flag_table[i].value;
530               goto match;
531             }
532         }
533       goto done;
534     match:
535       ;
536     }
537  done:
538   *ptr = src + j;
539   return;
540 }
541
542 struct interrupt_names {
543   int value;
544   char *name;
545
546 };
547
548 struct interrupt_names intr_table[] = {
549   { 0x1, "nvi" },
550   { 0x2, "vi" },
551   { 0x3, "both" },
552   { 0x3, "all" },
553   { 0, 0 }
554 };
555
556 static void
557 get_interrupt_operand (ptr, mode, dst)
558      char **ptr;
559      struct z8k_op *mode;
560      unsigned int dst ATTRIBUTE_UNUSED;
561 {
562   char *src = *ptr;
563   int i;
564
565   while (*src == ' ')
566     src++;
567
568   mode->mode = CLASS_IMM;
569   for (i = 0; intr_table[i].name; i++)
570     {
571       int j;
572
573       for (j = 0; intr_table[i].name[j]; j++)
574         {
575           if (intr_table[i].name[j] != src[j])
576             goto fail;
577         }
578       the_interrupt = intr_table[i].value;
579       *ptr = src + j;
580       return;
581     fail:
582       ;
583     }
584   /* No interrupt type specified, opcode won't do anything.  */
585   as_warn (_("opcode has no effect"));
586   the_interrupt = 0x0;
587   return;
588 }
589
590 struct cc_names {
591   int value;
592   char *name;
593 };
594
595 struct cc_names table[] = {
596   { 0x0, "f" },
597   { 0x1, "lt" },
598   { 0x2, "le" },
599   { 0x3, "ule" },
600   { 0x4, "ov/pe" },
601   { 0x4, "ov" },
602   { 0x4, "pe/ov" },
603   { 0x4, "pe" },
604   { 0x5, "mi" },
605   { 0x6, "eq" },
606   { 0x6, "z" },
607   { 0x7, "c/ult" },
608   { 0x7, "c" },
609   { 0x7, "ult/c" },
610   { 0x7, "ult" },
611   { 0x8, "t" },
612   { 0x9, "ge" },
613   { 0xa, "gt" },
614   { 0xb, "ugt" },
615   { 0xc, "nov/po" },
616   { 0xc, "nov" },
617   { 0xc, "po/nov" },
618   { 0xc, "po" },
619   { 0xd, "pl" },
620   { 0xe, "ne" },
621   { 0xe, "nz" },
622   { 0xf, "nc/uge" },
623   { 0xf, "nc" },
624   { 0xf, "uge/nc" },
625   { 0xf, "uge" },
626   { 0  ,  0 }
627 };
628
629 static void
630 get_cc_operand (ptr, mode, dst)
631      char **ptr;
632      struct z8k_op *mode;
633      unsigned int dst ATTRIBUTE_UNUSED;
634 {
635   char *src = *ptr;
636   int i, l;
637
638   while (*src == ' ')
639     src++;
640
641   mode->mode = CLASS_CC;
642   for (i = 0; table[i].name; i++)
643     {
644       l = strlen (table[i].name);
645       if (! strncasecmp (table[i].name, src, l))
646         {
647           the_cc = table[i].value;
648           if (*(src + l) && *(src + l) != ',')
649             break;
650           *ptr = src + l;  /* Valid cc found: "consume" it.  */
651           return;
652         }
653     }
654   the_cc = 0x8;  /* Not recognizing the cc defaults to t.  (Assuming no cc present.)  */
655 }
656
657 static void
658 get_operand (ptr, mode, dst)
659      char **ptr;
660      struct z8k_op *mode;
661      unsigned int dst ATTRIBUTE_UNUSED;
662 {
663   char *src = *ptr;
664   char *end;
665
666   mode->mode = 0;
667
668   while (*src == ' ')
669     src++;
670   if (*src == '#')
671     {
672       mode->mode = CLASS_IMM;
673       imm_operand = &(mode->exp);
674       src = parse_exp (src + 1, &(mode->exp));
675     }
676   else if (*src == '@')
677     {
678       mode->mode = CLASS_IR;
679       src = parse_reg (src + 1, &mode->regsize, &mode->reg);
680     }
681   else
682     {
683       int regn;
684
685       end = parse_reg (src, &mode->mode, &regn);
686
687       if (end)
688         {
689           int nw, nr;
690
691           src = end;
692           if (*src == '(')
693             {
694               src++;
695               end = parse_reg (src, &nw, &nr);
696               if (end)
697                 {
698                   /* Got Ra(Rb).  */
699                   src = end;
700
701                   if (*src != ')')
702                     as_bad (_("Missing ) in ra(rb)"));
703                   else
704                     src++;
705
706                   regaddr (mode->mode, "ra(rb) ra");
707 #if 0
708                   regword (mode->mode, "ra(rb) rb");
709 #endif
710                   mode->mode = CLASS_BX;
711                   mode->reg = regn;
712                   mode->x_reg = nr;
713                   reg[ARG_RX] = nr;
714                 }
715               else
716                 {
717                   /* Got Ra(disp).  */
718                   if (*src == '#')
719                     src++;
720                   src = parse_exp (src, &(mode->exp));
721                   src = checkfor (src, ')');
722                   mode->mode = CLASS_BA;
723                   mode->reg = regn;
724                   mode->x_reg = 0;
725                   imm_operand = &(mode->exp);
726                 }
727             }
728           else
729             {
730               mode->reg = regn;
731               mode->x_reg = 0;
732             }
733         }
734       else
735         {
736           /* No initial reg.  */
737           src = parse_exp (src, &(mode->exp));
738           if (*src == '(')
739             {
740               src++;
741               end = parse_reg (src, &(mode->mode), &regn);
742               regword (mode->mode, "addr(Ra) ra");
743               mode->mode = CLASS_X;
744               mode->reg = regn;
745               mode->x_reg = 0;
746               da_operand = &(mode->exp);
747               src = checkfor (end, ')');
748             }
749           else
750             {
751               /* Just an address.  */
752               mode->mode = CLASS_DA;
753               mode->reg = 0;
754               mode->x_reg = 0;
755               da_operand = &(mode->exp);
756             }
757         }
758     }
759   *ptr = src;
760 }
761
762 static char *
763 get_operands (opcode, op_end, operand)
764      const opcode_entry_type *opcode;
765      char *op_end;
766      op_type *operand;
767 {
768   char *ptr = op_end;
769   char *savptr;
770
771   switch (opcode->noperands)
772     {
773     case 0:
774       operand[0].mode = 0;
775       operand[1].mode = 0;
776       while (*ptr == ' ')
777         ptr++;
778       break;
779
780     case 1:
781       if (opcode->arg_info[0] == CLASS_CC)
782         {
783           get_cc_operand (&ptr, operand + 0, 0);
784           while (*ptr == ' ')
785             ptr++;
786           if (*ptr && ! is_end_of_line[(unsigned char) *ptr])
787             {
788               as_bad (_("invalid condition code '%s'"), ptr);
789               while (*ptr && ! is_end_of_line[(unsigned char) *ptr])
790                 ptr++;   /* Consume rest of line.  */
791             }
792         }
793
794       else if (opcode->arg_info[0] == CLASS_FLAGS)
795         get_flags_operand (&ptr, operand + 0, 0);
796
797       else if (opcode->arg_info[0] == (CLASS_IMM + (ARG_IMM2)))
798         get_interrupt_operand (&ptr, operand + 0, 0);
799
800       else
801         get_operand (&ptr, operand + 0, 0);
802
803       operand[1].mode = 0;
804       break;
805
806     case 2:
807       savptr = ptr;
808       if (opcode->arg_info[0] == CLASS_CC)
809         {
810           get_cc_operand (&ptr, operand + 0, 0);
811           while (*ptr == ' ')
812             ptr++;
813           if (*ptr != ',' && strchr (ptr + 1, ','))
814             {
815               savptr = ptr;
816               while (*ptr != ',')
817                 ptr++;
818               *ptr = 0;
819               ptr++;
820               as_bad (_("invalid condition code '%s'"), savptr);
821             }
822         }
823
824       else if (opcode->arg_info[0] == CLASS_CTRL)
825         {
826           get_ctrl_operand (&ptr, operand + 0, 0);
827
828           if (the_ctrl == 0)
829             {
830               ptr = savptr;
831               get_operand (&ptr, operand + 0, 0);
832
833               if (ptr == 0)
834                 return NULL;
835               if (*ptr == ',')
836                 ptr++;
837               get_ctrl_operand (&ptr, operand + 1, 1);
838               return ptr;
839             }
840         }
841       else
842         get_operand (&ptr, operand + 0, 0);
843
844       if (ptr == 0)
845         return NULL;
846       if (*ptr == ',')
847         ptr++;
848       get_operand (&ptr, operand + 1, 1);
849       break;
850
851     case 3:
852       get_operand (&ptr, operand + 0, 0);
853       if (*ptr == ',')
854         ptr++;
855       get_operand (&ptr, operand + 1, 1);
856       if (*ptr == ',')
857         ptr++;
858       get_operand (&ptr, operand + 2, 2);
859       break;
860
861     case 4:
862       get_operand (&ptr, operand + 0, 0);
863       if (*ptr == ',')
864         ptr++;
865       get_operand (&ptr, operand + 1, 1);
866       if (*ptr == ',')
867         ptr++;
868       get_operand (&ptr, operand + 2, 2);
869       if (*ptr == ',')
870         ptr++;
871       get_cc_operand (&ptr, operand + 3, 3);
872       break;
873
874     default:
875       abort ();
876     }
877
878   return ptr;
879 }
880
881 /* Passed a pointer to a list of opcodes which use different
882    addressing modes.  Return the opcode which matches the opcodes
883    provided.  */
884
885 static opcode_entry_type *
886 get_specific (opcode, operands)
887      opcode_entry_type *opcode;
888      op_type *operands;
889 {
890   opcode_entry_type *this_try = opcode;
891   int found = 0;
892   unsigned int noperands = opcode->noperands;
893
894   int this_index = opcode->idx;
895
896   while (this_index == opcode->idx && !found)
897     {
898       unsigned int i;
899
900       this_try = opcode++;
901       for (i = 0; i < noperands; i++)
902         {
903           unsigned int mode = operands[i].mode;
904
905           if (((mode & CLASS_MASK) == CLASS_IR) && ((this_try->arg_info[i] & CLASS_MASK) == CLASS_IRO))
906             {
907               mode = operands[i].mode = (operands[i].mode & ~CLASS_MASK) | CLASS_IRO;
908             }
909
910           if ((mode & CLASS_MASK) != (this_try->arg_info[i] & CLASS_MASK))
911             {
912               /* It could be a pc rel operand, if this is a da mode
913                  and we like disps, then insert it.  */
914
915               if (mode == CLASS_DA && this_try->arg_info[i] == CLASS_DISP)
916                 {
917                   /* This is the case.  */
918                   operands[i].mode = CLASS_DISP;
919                 }
920               else if (mode == CLASS_BA && this_try->arg_info[i])
921                 {
922                   /* Can't think of a way to turn what we've been
923                      given into something that's OK.  */
924                   goto fail;
925                 }
926               else if (this_try->arg_info[i] & CLASS_PR)
927                 {
928                   if (mode == CLASS_REG_LONG && segmented_mode)
929                     {
930                       /* OK.  */
931                     }
932                   else if (mode == CLASS_REG_WORD && !segmented_mode)
933                     {
934                       /* OK.  */
935                     }
936                   else
937                     goto fail;
938                 }
939               else
940                 goto fail;
941             }
942           switch (mode & CLASS_MASK)
943             {
944             default:
945               break;
946             case CLASS_IRO:
947               if (operands[i].regsize != CLASS_REG_WORD)
948                 as_bad (_("invalid indirect register size"));
949               reg[this_try->arg_info[i] & ARG_MASK] = operands[i].reg;
950               break;
951             case CLASS_IR:
952               if ((segmented_mode && operands[i].regsize != CLASS_REG_LONG)
953                   || (!segmented_mode && operands[i].regsize != CLASS_REG_WORD))
954                 as_bad (_("invalid indirect register size"));
955               reg[this_try->arg_info[i] & ARG_MASK] = operands[i].reg;
956               break;
957             case CLASS_X:
958             case CLASS_BA:
959             case CLASS_BX:
960             case CLASS_DISP:
961             case CLASS_REG:
962             case CLASS_REG_WORD:
963             case CLASS_REG_BYTE:
964             case CLASS_REG_QUAD:
965             case CLASS_REG_LONG:
966             case CLASS_REGN0:
967               reg[this_try->arg_info[i] & ARG_MASK] = operands[i].reg;
968               break;
969             }
970         }
971
972       found = 1;
973     fail:
974       ;
975     }
976   if (found)
977     return this_try;
978   else
979     return 0;
980 }
981
982 static char buffer[20];
983
984 static void
985 newfix (ptr, type, size, operand)
986      int ptr;
987      int type;
988      int size;   /* nibbles.  */
989      expressionS *operand;
990 {
991   int is_pcrel = 0;
992
993   if (operand->X_add_symbol
994       || operand->X_op_symbol
995       || operand->X_add_number)
996     {
997       switch(type)
998         {
999         case R_JR:
1000         case R_DISP7:
1001         case R_CALLR:
1002           is_pcrel = 1;
1003         }
1004       fix_new_exp (frag_now,
1005                    ptr,
1006                    size / 2,
1007                    operand,
1008                    is_pcrel,
1009                    type);
1010     }
1011 }
1012
1013 static char *
1014 apply_fix (ptr, type, operand, size)
1015      char *ptr;
1016      int type;
1017      expressionS *operand;
1018      int size;   /* nibbles.  */
1019 {
1020   long n = operand->X_add_number;
1021
1022   newfix ((ptr - buffer) / 2, type, size + 1, operand);
1023   switch (size)
1024     {
1025     case 8:                     /* 8 nibbles == 32 bits.  */
1026       *ptr++ = n >> 28;
1027       *ptr++ = n >> 24;
1028       *ptr++ = n >> 20;
1029       *ptr++ = n >> 16;
1030     case 4:                     /* 4 nibbles == 16 bits.  */
1031       *ptr++ = n >> 12;
1032       *ptr++ = n >> 8;
1033     case 2:
1034       *ptr++ = n >> 4;
1035     case 1:
1036       *ptr++ = n >> 0;
1037       break;
1038     }
1039   return ptr;
1040 }
1041
1042 /* Now we know what sort of opcodes it is.  Let's build the bytes.  */
1043
1044 #define INSERT(x,y) *x++ = y>>24; *x++ = y>> 16; *x++=y>>8; *x++ =y;
1045
1046 static void
1047 build_bytes (this_try, operand)
1048      opcode_entry_type *this_try;
1049      struct z8k_op *operand ATTRIBUTE_UNUSED;
1050 {
1051   char *output_ptr = buffer;
1052   int c;
1053   int nibble;
1054   unsigned int *class_ptr;
1055
1056   frag_wane (frag_now);
1057   frag_new (0);
1058
1059   memset (buffer, 0, sizeof (buffer));
1060   class_ptr = this_try->byte_info;
1061
1062   for (nibble = 0; (c = *class_ptr++); nibble++)
1063     {
1064
1065       switch (c & CLASS_MASK)
1066         {
1067         default:
1068           abort ();
1069
1070         case CLASS_ADDRESS:
1071           /* Direct address, we don't cope with the SS mode right now.  */
1072           if (segmented_mode)
1073             {
1074               /* da_operand->X_add_number |= 0x80000000;  --  Now set at relocation time.  */
1075               output_ptr = apply_fix (output_ptr, R_IMM32, da_operand, 8);
1076             }
1077           else
1078             {
1079               output_ptr = apply_fix (output_ptr, R_IMM16, da_operand, 4);
1080             }
1081           da_operand = 0;
1082           break;
1083         case CLASS_DISP8:
1084           /* pc rel 8 bit  */
1085           output_ptr = apply_fix (output_ptr, R_JR, da_operand, 2);
1086           da_operand = 0;
1087           break;
1088
1089         case CLASS_0DISP7:
1090           /* pc rel 7 bit  */
1091           *output_ptr = 0;
1092           output_ptr = apply_fix (output_ptr, R_DISP7, da_operand, 2);
1093           da_operand = 0;
1094           break;
1095
1096         case CLASS_1DISP7:
1097           /* pc rel 7 bit  */
1098           *output_ptr = 0x80;
1099           output_ptr = apply_fix (output_ptr, R_DISP7, da_operand, 2);
1100           output_ptr[-2] = 0x8;
1101           da_operand = 0;
1102           break;
1103
1104         case CLASS_BIT_1OR2:
1105           *output_ptr = c & 0xf;
1106           if (imm_operand)
1107             {
1108               if (imm_operand->X_add_number == 2)
1109                 *output_ptr |= 2;
1110               else if (imm_operand->X_add_number != 1)
1111                 as_bad (_("immediate must be 1 or 2"));
1112             }
1113           else
1114             as_bad (_("immediate 1 or 2 expected"));
1115           output_ptr++;
1116           break;
1117         case CLASS_CC:
1118           *output_ptr++ = the_cc;
1119           break;
1120         case CLASS_0CCC:
1121           *output_ptr++ = the_ctrl;
1122           break;
1123         case CLASS_1CCC:
1124           *output_ptr++ = the_ctrl | 0x8;
1125           break;
1126         case CLASS_00II:
1127           *output_ptr++ = (~the_interrupt & 0x3);
1128           break;
1129         case CLASS_01II:
1130           *output_ptr++ = (~the_interrupt & 0x3) | 0x4;
1131           break;
1132         case CLASS_FLAGS:
1133           *output_ptr++ = the_flags;
1134           break;
1135         case CLASS_IGNORE:
1136         case CLASS_BIT:
1137           *output_ptr++ = c & 0xf;
1138           break;
1139         case CLASS_REGN0:
1140           if (reg[c & 0xf] == 0)
1141             as_bad (_("can't use R0 here"));
1142           /* Fall through.  */
1143         case CLASS_REG:
1144         case CLASS_REG_BYTE:
1145         case CLASS_REG_WORD:
1146         case CLASS_REG_LONG:
1147         case CLASS_REG_QUAD:
1148           /* Insert bit mattern of right reg.  */
1149           *output_ptr++ = reg[c & 0xf];
1150           break;
1151         case CLASS_DISP:
1152           switch (c & ARG_MASK)
1153             {
1154             case ARG_DISP12:
1155               output_ptr = apply_fix (output_ptr, R_CALLR, da_operand, 4);
1156               break;
1157             case ARG_DISP16:
1158               output_ptr = apply_fix (output_ptr, R_REL16, da_operand, 4);
1159               break;
1160             default:
1161               output_ptr = apply_fix (output_ptr, R_IMM16, da_operand, 4);
1162             }
1163           da_operand = 0;
1164           break;
1165
1166         case CLASS_IMM:
1167           {
1168             switch (c & ARG_MASK)
1169               {
1170               case ARG_NIM4:
1171                 if (imm_operand->X_add_number > 15)
1172                   {
1173                     as_bad (_("immediate value out of range"));
1174                   }
1175                 imm_operand->X_add_number = -imm_operand->X_add_number;
1176                 output_ptr = apply_fix (output_ptr, R_IMM4L, imm_operand, 1);
1177                 break;
1178               /*case ARG_IMMNMINUS1: not used.  */
1179               case ARG_IMM4M1:
1180                 imm_operand->X_add_number--;
1181                 /* Drop through.  */
1182               case ARG_IMM4:
1183                 if (imm_operand->X_add_number > 15)
1184                   {
1185                     as_bad (_("immediate value out of range"));
1186                   }
1187                 output_ptr = apply_fix (output_ptr, R_IMM4L, imm_operand, 1);
1188                 break;
1189               case ARG_NIM8:
1190                 imm_operand->X_add_number = -imm_operand->X_add_number;
1191                 /* Drop through.  */
1192               case ARG_IMM8:
1193                 output_ptr = apply_fix (output_ptr, R_IMM8, imm_operand, 2);
1194                 break;
1195               case ARG_IMM16:
1196                 output_ptr = apply_fix (output_ptr, R_IMM16, imm_operand, 4);
1197                 break;
1198               case ARG_IMM32:
1199                 output_ptr = apply_fix (output_ptr, R_IMM32, imm_operand, 8);
1200                 break;
1201               default:
1202                 abort ();
1203               }
1204           }
1205         }
1206     }
1207
1208   /* Copy from the nibble buffer into the frag.  */
1209   {
1210     int length = (output_ptr - buffer) / 2;
1211     char *src = buffer;
1212     char *fragp = frag_more (length);
1213
1214     while (src < output_ptr)
1215       {
1216         *fragp = (src[0] << 4) | src[1];
1217         src += 2;
1218         fragp++;
1219       }
1220   }
1221 }
1222
1223 /* This is the guts of the machine-dependent assembler.  STR points to a
1224    machine dependent instruction.  This function is supposed to emit
1225    the frags/bytes it assembles to.  */
1226
1227 void
1228 md_assemble (str)
1229      char *str;
1230 {
1231   char c;
1232   char *op_start;
1233   char *op_end;
1234   struct z8k_op operand[3];
1235   opcode_entry_type *opcode;
1236
1237   /* Drop leading whitespace.  */
1238   while (*str == ' ')
1239     str++;
1240
1241   /* Find the op code end.  */
1242   for (op_start = op_end = str;
1243        *op_end != 0 && *op_end != ' ' && ! is_end_of_line[(unsigned char) *op_end];
1244        op_end++)
1245     ;
1246
1247   if (op_end == op_start)
1248     {
1249       as_bad (_("can't find opcode "));
1250     }
1251   c = *op_end;
1252
1253   *op_end = 0;  /* Zero-terminate op code string for hash_find() call.  */
1254
1255   opcode = (opcode_entry_type *) hash_find (opcode_hash_control, op_start);
1256
1257   if (opcode == NULL)
1258     {
1259       as_bad (_("unknown opcode"));
1260       return;
1261     }
1262
1263   *op_end = c;  /* Restore original string.  */
1264
1265   if (opcode->opcode == 250)
1266     {
1267       pseudo_typeS *p;
1268       char oc;
1269       char *old = input_line_pointer;
1270
1271       /* Was really a pseudo op.  */
1272
1273       input_line_pointer = op_end;
1274
1275       oc = *old;
1276       *old = '\n';
1277       while (*input_line_pointer == ' ')
1278         input_line_pointer++;
1279       p = (pseudo_typeS *) (opcode->func);
1280
1281       (p->poc_handler) (p->poc_val);
1282       input_line_pointer = old;
1283       *old = oc;
1284     }
1285   else
1286     {
1287       char *new_input_line_pointer;
1288
1289       new_input_line_pointer = get_operands (opcode, op_end, operand);
1290       if (new_input_line_pointer)
1291         input_line_pointer = new_input_line_pointer;
1292
1293       opcode = get_specific (opcode, operand);
1294
1295       if (opcode == 0)
1296         {
1297           /* Couldn't find an opcode which matched the operands.  */
1298           char *where = frag_more (2);
1299
1300           where[0] = 0x0;
1301           where[1] = 0x0;
1302
1303           as_bad (_("Can't find opcode to match operands"));
1304           return;
1305         }
1306
1307       build_bytes (opcode, operand);
1308     }
1309 }
1310
1311 void
1312 tc_crawl_symbol_chain (headers)
1313      object_headers *headers ATTRIBUTE_UNUSED;
1314 {
1315   printf (_("call to tc_crawl_symbol_chain \n"));
1316 }
1317
1318 /* We have no need to default values of symbols.  */
1319
1320 symbolS *
1321 md_undefined_symbol (name)
1322      char *name ATTRIBUTE_UNUSED;
1323 {
1324   return 0;
1325 }
1326
1327 void
1328 tc_headers_hook (headers)
1329      object_headers *headers ATTRIBUTE_UNUSED;
1330 {
1331   printf (_("call to tc_headers_hook \n"));
1332 }
1333
1334 /* Various routines to kill one day.  */
1335 /* Equal to MAX_PRECISION in atof-ieee.c.  */
1336 #define MAX_LITTLENUMS 6
1337
1338 /* Turn a string in input_line_pointer into a floating point constant
1339    of type TYPE, and store the appropriate bytes in *LITP.  The number
1340    of LITTLENUMS emitted is stored in *SIZEP.  An error message is
1341    returned, or NULL on OK.  */
1342
1343 char *
1344 md_atof (type, litP, sizeP)
1345      char type;
1346      char *litP;
1347      int *sizeP;
1348 {
1349   int prec;
1350   LITTLENUM_TYPE words[MAX_LITTLENUMS];
1351   LITTLENUM_TYPE *wordP;
1352   char *t;
1353
1354   switch (type)
1355     {
1356     case 'f':
1357     case 'F':
1358     case 's':
1359     case 'S':
1360       prec = 2;
1361       break;
1362
1363     case 'd':
1364     case 'D':
1365     case 'r':
1366     case 'R':
1367       prec = 4;
1368       break;
1369
1370     case 'x':
1371     case 'X':
1372       prec = 6;
1373       break;
1374
1375     case 'p':
1376     case 'P':
1377       prec = 6;
1378       break;
1379
1380     default:
1381       *sizeP = 0;
1382       return _("Bad call to MD_ATOF()");
1383     }
1384   t = atof_ieee (input_line_pointer, type, words);
1385   if (t)
1386     input_line_pointer = t;
1387
1388   *sizeP = prec * sizeof (LITTLENUM_TYPE);
1389   for (wordP = words; prec--;)
1390     {
1391       md_number_to_chars (litP, (long) (*wordP++), sizeof (LITTLENUM_TYPE));
1392       litP += sizeof (LITTLENUM_TYPE);
1393     }
1394   return 0;
1395 }
1396 \f
1397 const char *md_shortopts = "z:";
1398
1399 struct option md_longopts[] =
1400   {
1401 #define OPTION_RELAX  (OPTION_MD_BASE)
1402     {"linkrelax", no_argument, NULL, OPTION_RELAX},
1403     {NULL, no_argument, NULL, 0}
1404   };
1405
1406 size_t md_longopts_size = sizeof (md_longopts);
1407
1408 int
1409 md_parse_option (c, arg)
1410      int c;
1411      char *arg;
1412 {
1413   switch (c)
1414     {
1415     case 'z':
1416       if (!strcmp (arg, "8001"))
1417         s_segm (1);
1418       else if (!strcmp (arg, "8002"))
1419         s_segm (0);
1420       else
1421         {
1422           as_bad (_("invalid architecture -z%s"), arg);
1423           return 0;
1424         }
1425       z8k_target_from_cmdline = 1;
1426       break;
1427
1428     case OPTION_RELAX:
1429       linkrelax = 1;
1430       break;
1431
1432     default:
1433       return 0;
1434     }
1435
1436   return 1;
1437 }
1438
1439 void
1440 md_show_usage (stream)
1441      FILE *stream;
1442 {
1443   fprintf (stream, _("\
1444  Z8K options:\n\
1445   -z8001                  generate segmented code\n\
1446   -z8002                  generate unsegmented code\n\
1447   -linkrelax              create linker relaxable code\n"));
1448 }
1449 \f
1450 void
1451 md_convert_frag (headers, seg, fragP)
1452      object_headers *headers ATTRIBUTE_UNUSED;
1453      segT seg ATTRIBUTE_UNUSED;
1454      fragS *fragP ATTRIBUTE_UNUSED;
1455 {
1456   printf (_("call to md_convert_frag\n"));
1457   abort ();
1458 }
1459
1460 valueT
1461 md_section_align (seg, size)
1462      segT seg;
1463      valueT size;
1464 {
1465   return ((size + (1 << section_alignment[(int) seg]) - 1)
1466           & (-1 << section_alignment[(int) seg]));
1467 }
1468
1469 /* Attempt to simplify or eliminate a fixup. To indicate that a fixup
1470    has been eliminated, set fix->fx_done. If fix->fx_addsy is non-NULL,
1471    we will have to generate a reloc entry.  */
1472 void
1473 md_apply_fix3 (fixP, valP, segment)
1474      fixS * fixP;
1475      valueT * valP;
1476      segT segment ATTRIBUTE_UNUSED;
1477 {
1478   long val = * (long *) valP;
1479   char *buf = fixP->fx_where + fixP->fx_frag->fr_literal;
1480
1481   switch (fixP->fx_r_type)
1482     {
1483     case R_IMM4L:
1484       buf[0] = (buf[0] & 0xf0) | (val & 0xf);
1485       break;
1486
1487     case R_JR:
1488       if (fixP->fx_addsy)
1489         {
1490           fixP->fx_no_overflow = 1;
1491           fixP->fx_done = 0;
1492         }
1493       else
1494         {
1495       if (val & 1)
1496         as_bad (_("cannot branch to odd address"));
1497       val /= 2;
1498       if (val > 127 || val < -128)
1499             as_warn (_("relative jump out of range"));
1500       *buf++ = val;
1501       fixP->fx_no_overflow = 1;
1502           fixP->fx_done = 1;
1503         }
1504       break;
1505
1506     case R_DISP7:
1507       if (fixP->fx_addsy)
1508         {
1509           fixP->fx_no_overflow = 1;
1510           fixP->fx_done = 0;
1511         }
1512       else
1513         {
1514           if (val & 1)
1515             as_bad (_("cannot branch to odd address"));
1516           val /= 2;
1517           if (val > 0 || val < -127)
1518             as_bad (_("relative jump out of range"));
1519           *buf = (*buf & 0x80) | (-val & 0x7f);
1520           fixP->fx_no_overflow = 1;
1521           fixP->fx_done = 1;
1522         }
1523       break;
1524
1525     case R_CALLR:
1526       if (fixP->fx_addsy)
1527         {
1528           fixP->fx_no_overflow = 1;
1529           fixP->fx_done = 0;
1530         }
1531       else
1532         {
1533           if (val & 1)
1534             as_bad (_("cannot branch to odd address"));
1535           if (val > 4096 || val < -4095)
1536             as_bad (_("relative call out of range"));
1537           val = -val / 2;
1538           *buf = (*buf & 0xf0) | ((val >> 8) & 0xf);
1539           buf++;
1540           *buf++ = val & 0xff;
1541           fixP->fx_no_overflow = 1;
1542           fixP->fx_done = 1;
1543         }
1544       break;
1545
1546     case R_IMM8:
1547       *buf++ = val;
1548       break;
1549
1550     case R_IMM16:
1551       *buf++ = (val >> 8);
1552       *buf++ = val;
1553       break;
1554
1555     case R_IMM32:
1556       *buf++ = (val >> 24);
1557       *buf++ = (val >> 16);
1558       *buf++ = (val >> 8);
1559       *buf++ = val;
1560       break;
1561
1562     case R_REL16:
1563       val = val - fixP->fx_frag->fr_address + fixP->fx_where - fixP->fx_size;
1564       if (val > 32767 || val < -32768)
1565         as_bad (_("relative address out of range"));
1566       *buf++ = (val >> 8);
1567       *buf++ = val;
1568       fixP->fx_no_overflow = 1;
1569       break;
1570
1571 #if 0
1572     case R_DA | R_SEG:
1573       *buf++ = (val >> 16);
1574       *buf++ = 0x00;
1575       *buf++ = (val >> 8);
1576       *buf++ = val;
1577       break;
1578 #endif
1579
1580     case 0:
1581       md_number_to_chars (buf, val, fixP->fx_size);
1582       break;
1583
1584     default:
1585       printf(_("md_apply_fix3: unknown r_type 0x%x\n"), fixP->fx_r_type);
1586       abort ();
1587     }
1588
1589   if (fixP->fx_addsy == NULL && fixP->fx_pcrel == 0)
1590     fixP->fx_done = 1;
1591 }
1592
1593 int
1594 md_estimate_size_before_relax (fragP, segment_type)
1595      register fragS *fragP ATTRIBUTE_UNUSED;
1596      register segT segment_type ATTRIBUTE_UNUSED;
1597 {
1598   printf (_("call to md_estimate_size_before_relax\n"));
1599   abort ();
1600 }
1601
1602 /* Put number into target byte order.  */
1603
1604 void
1605 md_number_to_chars (ptr, use, nbytes)
1606      char *ptr;
1607      valueT use;
1608      int nbytes;
1609 {
1610   number_to_chars_bigendian (ptr, use, nbytes);
1611 }
1612
1613 /* On the Z8000, a PC-relative offset is relative to the address of the
1614    instruction plus its size.  */
1615 long
1616 md_pcrel_from (fixP)
1617      fixS *fixP;
1618 {
1619   return fixP->fx_size + fixP->fx_where + fixP->fx_frag->fr_address;
1620 }
1621
1622 void
1623 tc_coff_symbol_emit_hook (s)
1624      symbolS *s ATTRIBUTE_UNUSED;
1625 {
1626 }
1627
1628 void
1629 tc_reloc_mangle (fix_ptr, intr, base)
1630      fixS *fix_ptr;
1631      struct internal_reloc *intr;
1632      bfd_vma base;
1633
1634 {
1635   symbolS *symbol_ptr;
1636
1637   if (fix_ptr->fx_addsy
1638       && fix_ptr->fx_subsy)
1639     {
1640       symbolS *add = fix_ptr->fx_addsy;
1641       symbolS *sub = fix_ptr->fx_subsy;
1642
1643       if (S_GET_SEGMENT (add) != S_GET_SEGMENT (sub))
1644         as_bad (_("Can't subtract symbols in different sections %s %s"),
1645                 S_GET_NAME (add), S_GET_NAME (sub));
1646       else
1647         {
1648           int diff = S_GET_VALUE (add) - S_GET_VALUE (sub);
1649
1650           fix_ptr->fx_addsy = 0;
1651           fix_ptr->fx_subsy = 0;
1652           fix_ptr->fx_offset += diff;
1653         }
1654     }
1655   symbol_ptr = fix_ptr->fx_addsy;
1656
1657   /* If this relocation is attached to a symbol then it's ok
1658      to output it.  */
1659   if (fix_ptr->fx_r_type == 0)
1660     {
1661       /* cons likes to create reloc32's whatever the size of the reloc.  */
1662       switch (fix_ptr->fx_size)
1663         {
1664         case 2:
1665           intr->r_type = R_IMM16;
1666           break;
1667         case 1:
1668           intr->r_type = R_IMM8;
1669           break;
1670         case 4:
1671           intr->r_type = R_IMM32;
1672           break;
1673         default:
1674           abort ();
1675         }
1676     }
1677   else
1678     intr->r_type = fix_ptr->fx_r_type;
1679
1680   intr->r_vaddr = fix_ptr->fx_frag->fr_address + fix_ptr->fx_where + base;
1681   intr->r_offset = fix_ptr->fx_offset;
1682
1683   if (symbol_ptr)
1684     intr->r_symndx = symbol_ptr->sy_number;
1685   else
1686     intr->r_symndx = -1;
1687 }