1 /* Assembly backend for the OpenRISC 1000.
2 Copyright (C) 2002, 2003, 2005 Free Software Foundation, Inc.
3 Contributed by Damjan Lampret <lampret@opencores.org>.
4 Modified bu Johan Rydberg, <johan.rydberg@netinsight.se>.
7 This file is part of GAS, the GNU Assembler.
9 GAS is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2, or (at your option)
14 GAS is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with GAS; see the file COPYING. If not, write to
21 the Free Software Foundation, 51 Franklin Street - Fifth Floor,
22 Boston, MA 02110-1301, USA. */
24 /* tc-a29k.c used as a template. */
26 #include "safe-ctype.h"
28 #include "opcode/or32.h"
36 #ifndef REGISTER_PREFIX
37 #define REGISTER_PREFIX '%'
40 /* Make it easier to clone this machine desc into another one. */
41 #define machine_opcode or32_opcode
42 #define machine_opcodes or32_opcodes
43 #define machine_ip or32_ip
44 #define machine_it or32_it
46 /* Handle of the OPCODE hash table. */
47 static struct hash_control
*op_hash
= NULL
;
53 struct nlist
* nlistp
;
56 int reloc_offset
; /* Offset of reloc within insn. */
61 const pseudo_typeS md_pseudo_table
[] =
63 {"align", s_align_bytes
, 4 },
64 {"space", s_space
, 0 },
65 {"cputype", s_ignore
, 0 },
66 {"reg", s_lsym
, 0 }, /* Register equate, same as equ. */
67 {"sect", s_ignore
, 0 }, /* Creation of coff sections. */
68 {"proc", s_ignore
, 0 }, /* Start of a function. */
69 {"endproc", s_ignore
, 0 }, /* Function end. */
74 int md_short_jump_size
= 4;
75 int md_long_jump_size
= 4;
77 #if defined(BFD_HEADERS)
79 const int md_reloc_size
= RELSZ
; /* Coff headers. */
81 const int md_reloc_size
= 12; /* Something else headers. */
84 const int md_reloc_size
= 12; /* Not bfdized. */
87 /* This array holds the chars that always start a comment.
88 If the pre-processor is disabled, these aren't very useful. */
89 const char comment_chars
[] = "#";
91 /* This array holds the chars that only start a comment at the beginning of
92 a line. If the line seems to have the form '# 123 filename'
93 .line and .file directives will appear in the pre-processed output. */
94 /* Note that input_file.c hand checks for '#' at the beginning of the
95 first line of the input file. This is because the compiler outputs
96 #NO_APP at the beginning of its output. */
97 /* Also note that comments like this one will always work. */
98 const char line_comment_chars
[] = "#";
100 /* We needed an unused char for line separation to work around the
101 lack of macros, using sed and such. */
102 const char line_separator_chars
[] = ";";
104 /* Chars that can be used to separate mant from exp in floating point nums. */
105 const char EXP_CHARS
[] = "eE";
107 /* Chars that mean this number is a floating point constant.
110 const char FLT_CHARS
[] = "rRsSfFdDxXpP";
112 /* "l.jalr r9" precalculated opcode. */
113 static unsigned long jalr_r9_opcode
;
115 static void machine_ip (char *);
118 /* Set bits in machine opcode according to insn->encoding
119 description and passed operand. */
122 encode (const struct machine_opcode
*insn
,
123 unsigned long *opcode
,
124 signed long param_val
,
132 printf (" encode: opcode=%.8lx param_val=%.8lx abs=%.8lx param_ch=%c\n",
133 *opcode
, param_val
, abs (param_val
), param_ch
);
135 for (enc
= insn
->encoding
; *enc
!= '\0'; enc
++)
136 if (*enc
== param_ch
)
138 if (enc
- 2 >= insn
->encoding
&& (*(enc
- 2) == '0') && (*(enc
- 1) == 'x'))
146 for (enc
= insn
->encoding
; *enc
!= '\0';)
148 if ((*enc
== '0') && (*(enc
+ 1) == 'x'))
150 int tmp
= strtol (enc
, NULL
, 16);
153 *opcode
|= tmp
<< opc_pos
;
156 else if ((*enc
== '0') || (*enc
== '-'))
161 else if (*enc
== '1')
164 *opcode
|= 1 << opc_pos
;
167 else if (*enc
== param_ch
)
171 *opcode
|= ((param_val
>> param_pos
) & 0x1) << opc_pos
;
174 else if (ISALPHA (*enc
))
184 printf (" opcode=%.8lx\n", *opcode
);
188 /* This function is called once, at assembler startup time. It should
189 set up all the tables, etc., that the MD part of the assembler will
195 const char *retval
= NULL
;
200 /* Hash up all the opcodes for fast use later. */
201 op_hash
= hash_new ();
203 for (i
= 0; i
< or32_num_opcodes
; i
++)
205 const char *name
= machine_opcodes
[i
].name
;
213 retval
= hash_insert (op_hash
, name
, (void *) &machine_opcodes
[i
]);
216 fprintf (stderr
, "internal error: can't hash `%s': %s\n",
217 machine_opcodes
[i
].name
, retval
);
223 as_fatal (_("Broken assembler. No assembly attempted."));
225 encode (&machine_opcodes
[insn_index ("l.jalr")], &jalr_r9_opcode
, 9, 'B');
228 /* Returns non zero if instruction is to be used. */
231 check_invalid_opcode (unsigned long opcode
)
233 return opcode
== jalr_r9_opcode
;
236 /* Assemble a single instruction. Its label has already been handled
237 by the generic front end. We just parse opcode and operands, and
238 produce the bytes of data and relocation. */
241 md_assemble (char *str
)
246 printf ("NEW INSTRUCTION\n");
253 /* Put out the opcode. */
254 md_number_to_chars (toP
, the_insn
.opcode
, 4);
256 /* Put out the symbol-dependent stuff. */
258 if (the_insn
.reloc
!= BFD_RELOC_NONE
)
260 if (the_insn
.reloc
!= NO_RELOC
)
263 fix_new_exp (frag_now
,
264 (toP
- frag_now
->fr_literal
+ the_insn
.reloc_offset
),
272 /* This is true of the we have issued a "lo(" or "hi"(. */
273 static int waiting_for_shift
= 0;
275 static int mask_or_shift
= 0;
279 parse_operand (char *s
, expressionS
*operandp
, int opt
)
281 char *save
= input_line_pointer
;
285 printf (" PROCESS NEW OPERAND(%s) == %c (%d)\n", s
, opt
? opt
: '!', opt
);
288 input_line_pointer
= s
;
290 if (strncasecmp (s
, "HI(", 3) == 0)
292 waiting_for_shift
= 1;
293 mask_or_shift
= BFD_RELOC_HI16
;
295 input_line_pointer
+= 3;
297 else if (strncasecmp (s
, "LO(", 3) == 0)
299 mask_or_shift
= BFD_RELOC_LO16
;
301 input_line_pointer
+= 3;
306 if ((*s
== '(') && (*(s
+1) == 'r'))
309 if ((*s
== 'r') && ISDIGIT (*(s
+ 1)))
311 operandp
->X_add_number
= strtol (s
+ 1, NULL
, 10);
312 operandp
->X_op
= O_register
;
313 for (; (*s
!= ',') && (*s
!= '\0');)
315 input_line_pointer
= save
;
319 expression (operandp
);
321 if (operandp
->X_op
== O_absent
)
324 as_bad (_("missing operand"));
327 operandp
->X_add_number
= 0;
328 operandp
->X_op
= O_constant
;
332 new = input_line_pointer
;
333 input_line_pointer
= save
;
336 printf (" %s=parse_operand(%s): operandp->X_op = %u\n", new, s
, operandp
->X_op
);
344 parse_operand (char *s
, expressionS
*operandp
, int opt
)
346 char *save
= input_line_pointer
;
350 printf (" PROCESS NEW OPERAND(%s) == %c (%d)\n", s
, opt
? opt
: '!', opt
);
353 input_line_pointer
= s
;
355 if (strncasecmp (s
, "HI(", 3) == 0)
357 waiting_for_shift
= 1;
358 mask_or_shift
= RELOC_CONSTH
;
360 input_line_pointer
+= 3;
362 else if (strncasecmp (s
, "LO(", 3) == 0)
364 mask_or_shift
= RELOC_CONST
;
366 input_line_pointer
+= 3;
371 expression (operandp
);
373 if (operandp
->X_op
== O_absent
)
376 as_bad (_("missing operand"));
379 operandp
->X_add_number
= 0;
380 operandp
->X_op
= O_constant
;
384 new = input_line_pointer
;
385 input_line_pointer
= save
;
387 if ((operandp
->X_op
== O_symbol
) && (*s
!= '_'))
390 printf ("symbol: '%s'\n", save
);
393 for (save
= s
; s
< new; s
++)
394 if ((*s
== REGISTER_PREFIX
) && (*(s
+ 1) == 'r')) /* Register prefix. */
397 if ((*s
== 'r') && ISDIGIT (*(s
+ 1)))
399 operandp
->X_add_number
= strtol (s
+ 1, NULL
, 10);
400 operandp
->X_op
= O_register
;
406 printf (" %s=parse_operand(%s): operandp->X_op = %u\n", new, s
, operandp
->X_op
);
413 /* Instruction parsing. Takes a string containing the opcode.
414 Operands are at input_line_pointer. Output is in the_insn.
415 Warnings or errors are generated. */
419 machine_ip (char *str
)
423 const struct machine_opcode
*insn
;
425 unsigned long opcode
;
426 expressionS the_operand
;
427 expressionS
*operand
= &the_operand
;
429 int reloc
= BFD_RELOC_NONE
;
432 printf ("machine_ip(%s)\n", str
);
436 for (; ISALNUM (*s
) || *s
== '.'; ++s
)
445 case ' ': /* FIXME-SOMEDAY more whitespace. */
450 as_bad (_("unknown opcode1: `%s'"), str
);
454 if ((insn
= (struct machine_opcode
*) hash_find (op_hash
, str
)) == NULL
)
456 as_bad (_("unknown opcode2 `%s'."), str
);
462 memset (&the_insn
, '\0', sizeof (the_insn
));
463 the_insn
.reloc
= BFD_RELOC_NONE
;
465 reloc
= BFD_RELOC_NONE
;
467 /* Build the opcode, checking as we go to make sure that the
470 If an operand matches, we modify the_insn or opcode appropriately,
471 and do a "continue". If an operand fails to match, we "break". */
472 if (insn
->args
[0] != '\0')
473 /* Prime the pump. */
474 s
= parse_operand (s
, operand
, insn
->args
[0] == 'I');
476 for (args
= insn
->args
;; ++args
)
479 printf (" args = %s\n", args
);
483 case '\0': /* End of args. */
484 /* We have have 0 args, do the bazoooka! */
485 if (args
== insn
->args
)
486 encode (insn
, &opcode
, 0, 0);
490 /* We are truly done. */
491 the_insn
.opcode
= opcode
;
492 if (check_invalid_opcode (opcode
))
493 as_bad (_("instruction not allowed: %s"), str
);
496 as_bad (_("too many operands: %s"), s
);
499 case ',': /* Must match a comma. */
502 reloc
= BFD_RELOC_NONE
;
504 /* Parse next operand. */
505 s
= parse_operand (s
, operand
, args
[1] == 'I');
507 printf (" ',' case: operand->X_add_number = %d, *args = %s, *s = %s\n",
508 operand
->X_add_number
, args
, s
);
514 case '(': /* Must match a (. */
515 s
= parse_operand (s
, operand
, args
[1] == 'I');
518 case ')': /* Must match a ). */
521 case 'r': /* A general register. */
524 if (operand
->X_op
!= O_register
)
525 break; /* Only registers. */
527 know (operand
->X_add_symbol
== 0);
528 know (operand
->X_op_symbol
== 0);
529 regno
= operand
->X_add_number
;
530 encode (insn
, &opcode
, regno
, *args
);
532 printf (" r: operand->X_op = %d\n", operand
->X_op
);
537 /* if (! ISALPHA (*args))
538 break; */ /* Only immediate values. */
543 printf ("mask_or_shift = %d\n", mask_or_shift
);
545 reloc
= mask_or_shift
;
549 if (strncasecmp (args
, "LO(", 3) == 0)
552 printf ("reloc_const\n");
554 reloc
= BFD_RELOC_LO16
;
556 else if (strncasecmp (args
, "HI(", 3) == 0)
559 printf ("reloc_consth\n");
561 reloc
= BFD_RELOC_HI16
;
565 operand
->X_op
= O_constant
;
569 printf (" default case: operand->X_add_number = %d, *args = %s, *s = %s\n", operand
->X_add_number
, args
, s
);
571 if (operand
->X_op
== O_constant
)
573 if (reloc
== BFD_RELOC_NONE
)
578 v
= abs (operand
->X_add_number
) & ~ mask
;
580 as_bad (_("call/jmp target out of range (1)"));
583 if (reloc
== BFD_RELOC_HI16
)
584 operand
->X_add_number
= ((operand
->X_add_number
>> 16) & 0xffff);
587 encode (insn
, &opcode
, operand
->X_add_number
, *args
);
588 /* the_insn.reloc = BFD_RELOC_NONE; */
592 if (reloc
== BFD_RELOC_NONE
)
593 the_insn
.reloc
= BFD_RELOC_32_GOT_PCREL
;
595 the_insn
.reloc
= reloc
;
597 /* the_insn.reloc = insn->reloc; */
599 printf (" reloc sym=%d\n", the_insn
.reloc
);
600 printf (" BFD_RELOC_NONE=%d\n", BFD_RELOC_NONE
);
602 the_insn
.exp
= *operand
;
604 /* the_insn.reloc_offset = 1; */
605 the_insn
.pcrel
= 1; /* Assume PC-relative jump. */
607 /* FIXME-SOON, Do we figure out whether abs later, after
609 if (reloc
== BFD_RELOC_LO16
|| reloc
== BFD_RELOC_HI16
)
612 encode (insn
, &opcode
, operand
->X_add_number
, *args
);
616 /* Types or values of args don't match. */
617 as_bad (_("invalid operands"));
625 machine_ip (char *str
)
629 const struct machine_opcode
*insn
;
631 unsigned long opcode
;
632 expressionS the_operand
;
633 expressionS
*operand
= &the_operand
;
635 int reloc
= NO_RELOC
;
638 printf ("machine_ip(%s)\n", str
);
642 for (; ISALNUM (*s
) || *s
== '.'; ++s
)
651 case ' ': /* FIXME-SOMEDAY more whitespace. */
656 as_bad (_("unknown opcode1: `%s'"), str
);
660 if ((insn
= (struct machine_opcode
*) hash_find (op_hash
, str
)) == NULL
)
662 as_bad (_("unknown opcode2 `%s'."), str
);
668 memset (&the_insn
, '\0', sizeof (the_insn
));
669 the_insn
.reloc
= NO_RELOC
;
673 /* Build the opcode, checking as we go to make sure that the
676 If an operand matches, we modify the_insn or opcode appropriately,
677 and do a "continue". If an operand fails to match, we "break". */
678 if (insn
->args
[0] != '\0')
679 /* Prime the pump. */
680 s
= parse_operand (s
, operand
,
682 || strcmp (insn
->name
, "l.nop") == 0);
684 for (args
= insn
->args
;; ++args
)
687 printf (" args = %s\n", args
);
691 case '\0': /* End of args. */
692 /* We have have 0 args, do the bazoooka! */
693 if (args
== insn
->args
)
694 encode (insn
, &opcode
, 0, 0);
698 /* We are truly done. */
699 the_insn
.opcode
= opcode
;
700 if (check_invalid_opcode (opcode
))
701 as_bad (_("instruction not allowed: %s"), str
);
704 as_bad (_("too many operands: %s"), s
);
707 case ',': /* Must match a comma. */
712 /* Parse next operand. */
713 s
= parse_operand (s
, operand
, args
[1] == 'I');
715 printf (" ',' case: operand->X_add_number = %d, *args = %s, *s = %s\n",
716 operand
->X_add_number
, args
, s
);
722 case '(': /* Must match a (. */
723 s
= parse_operand (s
, operand
, args
[1] == 'I');
726 case ')': /* Must match a ). */
729 case 'r': /* A general register. */
732 if (operand
->X_op
!= O_register
)
733 break; /* Only registers. */
735 know (operand
->X_add_symbol
== 0);
736 know (operand
->X_op_symbol
== 0);
737 regno
= operand
->X_add_number
;
738 encode (insn
, &opcode
, regno
, *args
);
740 printf (" r: operand->X_op = %d\n", operand
->X_op
);
745 /* if (! ISALPHA (*args))
746 break; */ /* Only immediate values. */
751 printf ("mask_or_shift = %d\n", mask_or_shift
);
753 reloc
= mask_or_shift
;
757 if (strncasecmp (args
, "LO(", 3) == 0)
760 printf ("reloc_const\n");
764 else if (strncasecmp (args
, "HI(", 3) == 0)
767 printf ("reloc_consth\n");
769 reloc
= RELOC_CONSTH
;
773 operand
->X_op
= O_constant
;
777 printf (" default case: operand->X_add_number = %d, *args = %s, *s = %s\n",
778 operand
->X_add_number
, args
, s
);
780 if (operand
->X_op
== O_constant
)
782 if (reloc
== NO_RELOC
)
784 unsigned long v
, mask
;
787 v
= abs (operand
->X_add_number
) & ~ mask
;
789 as_bad (_("call/jmp target out of range (1)"));
792 if (reloc
== RELOC_CONSTH
)
793 operand
->X_add_number
= ((operand
->X_add_number
>>16) & 0xffff);
796 encode (insn
, &opcode
, operand
->X_add_number
, *args
);
797 /* the_insn.reloc = NO_RELOC; */
801 if (reloc
== NO_RELOC
)
802 the_insn
.reloc
= RELOC_JUMPTARG
;
804 the_insn
.reloc
= reloc
;
806 printf (" reloc sym=%d\n", the_insn
.reloc
);
807 printf (" NO_RELOC=%d\n", NO_RELOC
);
809 the_insn
.exp
= *operand
;
811 /* the_insn.reloc_offset = 1; */
812 the_insn
.pcrel
= 1; /* Assume PC-relative jump. */
814 /* FIXME-SOON, Do we figure out whether abs later, after
816 if (reloc
== RELOC_CONST
|| reloc
== RELOC_CONSTH
)
819 encode (insn
, &opcode
, operand
->X_add_number
, *args
);
823 /* Types or values of args don't match. */
824 as_bad (_("invalid operands"));
830 /* This is identical to the md_atof in m68k.c. I think this is right,
833 Turn a string in input_line_pointer into a floating point constant
834 of type type, and store the appropriate bytes in *litP. The number
835 of LITTLENUMS emitted is stored in *sizeP . An error message is
836 returned, or NULL on OK. */
838 /* Equal to MAX_PRECISION in atof-ieee.c. */
839 #define MAX_LITTLENUMS 6
842 md_atof (int type
, char * litP
, int * sizeP
)
845 LITTLENUM_TYPE words
[MAX_LITTLENUMS
];
846 LITTLENUM_TYPE
*wordP
;
877 return _("Bad call to MD_ATOF()");
880 t
= atof_ieee (input_line_pointer
, type
, words
);
882 input_line_pointer
= t
;
884 *sizeP
= prec
* sizeof (LITTLENUM_TYPE
);
886 for (wordP
= words
; prec
--;)
888 md_number_to_chars (litP
, (valueT
) (*wordP
++), sizeof (LITTLENUM_TYPE
));
889 litP
+= sizeof (LITTLENUM_TYPE
);
895 /* Write out big-endian. */
898 md_number_to_chars (char *buf
, valueT val
, int n
)
900 number_to_chars_bigendian (buf
, val
, n
);
905 md_apply_fix3 (fixS
* fixP
, valueT
* val
, segT seg ATTRIBUTE_UNUSED
)
907 char *buf
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
913 printf ("md_apply_fix val:%x\n", t_val
);
916 fixP
->fx_addnumber
= t_val
; /* Remember value for emit_reloc. */
918 know (fixP
->fx_size
== 4);
919 know (fixP
->fx_r_type
< BFD_RELOC_NONE
);
921 switch (fixP
->fx_r_type
)
923 case BFD_RELOC_32
: /* XXXXXXXX pattern in a word. */
925 printf ("reloc_const: val=%x\n", t_val
);
927 buf
[0] = t_val
>> 24;
928 buf
[1] = t_val
>> 16;
933 case BFD_RELOC_16
: /* XXXX0000 pattern in a word. */
935 printf ("reloc_const: val=%x\n", t_val
);
941 case BFD_RELOC_8
: /* XX000000 pattern in a word. */
943 printf ("reloc_const: val=%x\n", t_val
);
948 case BFD_RELOC_LO16
: /* 0000XXXX pattern in a word. */
950 printf ("reloc_const: val=%x\n", t_val
);
952 buf
[2] = t_val
>> 8; /* Holds bits 0000XXXX. */
956 case BFD_RELOC_HI16
: /* 0000XXXX pattern in a word. */
958 printf ("reloc_consth: val=%x\n", t_val
);
960 buf
[2] = t_val
>> 24; /* Holds bits XXXX0000. */
961 buf
[3] = t_val
>> 16;
964 case BFD_RELOC_32_GOT_PCREL
: /* 0000XXXX pattern in a word. */
967 else if (fixP
->fx_pcrel
)
969 long v
= t_val
>> 28;
971 if (v
!= 0 && v
!= -1)
972 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
973 _("call/jmp target out of range (2)"));
976 /* This case was supposed to be handled in machine_ip. */
979 buf
[0] |= (t_val
>> 26) & 0x03; /* Holds bits 0FFFFFFC of address. */
980 buf
[1] = t_val
>> 18;
981 buf
[2] = t_val
>> 10;
985 case BFD_RELOC_VTABLE_INHERIT
:
986 case BFD_RELOC_VTABLE_ENTRY
:
992 as_bad (_("bad relocation type: 0x%02x"), fixP
->fx_r_type
);
996 if (fixP
->fx_addsy
== (symbolS
*) NULL
)
1001 md_apply_fix3 (fixS
*fixP
, valueT
*valP
, segT seg ATTRIBUTE_UNUSED
)
1004 char *buf
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
1007 printf ("md_apply_fix val:%x\n", val
);
1010 fixP
->fx_addnumber
= val
; /* Remember value for emit_reloc. */
1012 know (fixP
->fx_size
== 4);
1013 know (fixP
->fx_r_type
< NO_RELOC
);
1015 /* This is a hack. There should be a better way to handle this. */
1016 if (fixP
->fx_r_type
== RELOC_WDISP30
&& fixP
->fx_addsy
)
1017 val
+= fixP
->fx_where
+ fixP
->fx_frag
->fr_address
;
1019 switch (fixP
->fx_r_type
)
1033 val
= (val
>> 2) + 1;
1034 buf
[0] |= (val
>> 24) & 0x3f;
1035 buf
[1] = (val
>> 16);
1041 buf
[1] |= (val
>> 26) & 0x3f;
1047 buf
[2] |= (val
>> 8) & 0x03;
1052 buf
[2] |= (val
>> 8) & 0x1f;
1057 val
= (val
>> 2) + 1;
1060 buf
[1] |= (val
>> 16) & 0x3f;
1065 case RELOC_JUMPTARG
: /* 0000XXXX pattern in a word. */
1068 /* The linker tries to support both AMD and old GNU style
1069 R_IREL relocs. That means that if the addend is exactly
1070 the negative of the address within the section, the
1071 linker will not handle it correctly. */
1073 else if (fixP
->fx_pcrel
)
1076 if (v
!= 0 && v
!= -1)
1077 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
1078 _("call/jmp target out of range (2)"));
1081 /* This case was supposed to be handled in machine_ip. */
1084 buf
[0] |= (val
>> 26) & 0x03; /* Holds bits 0FFFFFFC of address. */
1090 case RELOC_CONST
: /* 0000XXXX pattern in a word. */
1092 printf ("reloc_const: val=%x\n", val
);
1094 buf
[2] = val
>> 8; /* Holds bits 0000XXXX. */
1098 case RELOC_CONSTH
: /* 0000XXXX pattern in a word. */
1100 printf ("reloc_consth: val=%x\n", val
);
1102 buf
[2] = val
>> 24; /* Holds bits XXXX0000. */
1106 case BFD_RELOC_VTABLE_INHERIT
:
1107 case BFD_RELOC_VTABLE_ENTRY
:
1113 as_bad (_("bad relocation type: 0x%02x"), fixP
->fx_r_type
);
1117 if (fixP
->fx_addsy
== (symbolS
*) NULL
)
1124 tc_coff_fix2rtype (fixS
*fixP
)
1127 printf ("tc_coff_fix2rtype\n");
1130 switch (fixP
->fx_r_type
)
1132 case RELOC_32
: return R_WORD
;
1133 case RELOC_8
: return R_BYTE
;
1134 case RELOC_CONST
: return R_ILOHALF
;
1135 case RELOC_CONSTH
: return R_IHIHALF
;
1136 case RELOC_JUMPTARG
: return R_IREL
;
1138 printf ("need %d\n", fixP
->fx_r_type
);
1145 #endif /* OBJ_COFF */
1147 /* Should never be called for or32. */
1150 md_create_short_jump (char * ptr ATTRIBUTE_UNUSED
,
1151 addressT from_addr ATTRIBUTE_UNUSED
,
1152 addressT to_addr ATTRIBUTE_UNUSED
,
1153 fragS
* frag ATTRIBUTE_UNUSED
,
1154 symbolS
* to_symbol ATTRIBUTE_UNUSED
)
1156 as_fatal ("or32_create_short_jmp\n");
1159 /* Should never be called for or32. */
1161 #ifndef BFD_ASSEMBLER
1163 md_convert_frag (object_headers
* headers ATTRIBUTE_UNUSED
,
1164 segT seg ATTRIBUTE_UNUSED
,
1165 register fragS
* fragP ATTRIBUTE_UNUSED
)
1167 as_fatal ("or32_convert_frag\n");
1172 md_convert_frag (bfd
* headers ATTRIBUTE_UNUSED
,
1173 segT seg ATTRIBUTE_UNUSED
,
1174 fragS
* fragP ATTRIBUTE_UNUSED
)
1176 as_fatal ("or32_convert_frag\n");
1180 /* Should never be called for or32. */
1183 md_create_long_jump (char * ptr ATTRIBUTE_UNUSED
,
1184 addressT from_addr ATTRIBUTE_UNUSED
,
1185 addressT to_addr ATTRIBUTE_UNUSED
,
1186 fragS
* frag ATTRIBUTE_UNUSED
,
1187 symbolS
* to_symbol ATTRIBUTE_UNUSED
)
1189 as_fatal ("or32_create_long_jump\n");
1192 /* Should never be called for or32. */
1195 md_estimate_size_before_relax (fragS
* fragP ATTRIBUTE_UNUSED
,
1196 segT segtype ATTRIBUTE_UNUSED
)
1198 as_fatal ("or32_estimate_size_before_relax\n");
1202 /* Translate internal representation of relocation info to target format.
1204 On sparc/29k: first 4 bytes are normal unsigned long address, next three
1205 bytes are index, most sig. byte first. Byte 7 is broken up with
1206 bit 7 as external, bits 6 & 5 unused, and the lower
1207 five bits as relocation type. Next 4 bytes are long addend. */
1208 /* Thanx and a tip of the hat to Michael Bloom, mb@ttidca.tti.com. */
1212 tc_aout_fix_to_chars (char *where
,
1214 relax_addressT segment_address_in_file
)
1219 printf ("tc_aout_fix_to_chars\n");
1222 know (fixP
->fx_r_type
< BFD_RELOC_NONE
);
1223 know (fixP
->fx_addsy
!= NULL
);
1227 fixP
->fx_frag
->fr_address
+ fixP
->fx_where
- segment_address_in_file
,
1230 r_symbolnum
= (S_IS_DEFINED (fixP
->fx_addsy
)
1231 ? S_GET_TYPE (fixP
->fx_addsy
)
1232 : fixP
->fx_addsy
->sy_number
);
1234 where
[4] = (r_symbolnum
>> 16) & 0x0ff;
1235 where
[5] = (r_symbolnum
>> 8) & 0x0ff;
1236 where
[6] = r_symbolnum
& 0x0ff;
1237 where
[7] = (((!S_IS_DEFINED (fixP
->fx_addsy
)) << 7) & 0x80) | (0 & 0x60) | (fixP
->fx_r_type
& 0x1F);
1240 md_number_to_chars (&where
[8], fixP
->fx_addnumber
, 4);
1243 #endif /* OBJ_AOUT */
1245 const char *md_shortopts
= "";
1247 struct option md_longopts
[] =
1249 { NULL
, no_argument
, NULL
, 0 }
1251 size_t md_longopts_size
= sizeof (md_longopts
);
1254 md_parse_option (int c ATTRIBUTE_UNUSED
, char * arg ATTRIBUTE_UNUSED
)
1260 md_show_usage (FILE * stream ATTRIBUTE_UNUSED
)
1264 /* This is called when a line is unrecognized. This is used to handle
1265 definitions of or32 style local labels. */
1268 or32_unrecognized_line (int c
)
1274 || ! ISDIGIT ((unsigned char) input_line_pointer
[0]))
1277 s
= input_line_pointer
;
1280 while (ISDIGIT ((unsigned char) *s
))
1282 lab
= lab
* 10 + *s
- '0';
1287 /* Not a label definition. */
1290 if (dollar_label_defined (lab
))
1292 as_bad (_("label \"$%d\" redefined"), lab
);
1296 define_dollar_label (lab
);
1297 colon (dollar_label_name (lab
, 0));
1298 input_line_pointer
= s
+ 1;
1303 /* Default the values of symbols known that should be "predefined". We
1304 don't bother to predefine them unless you actually use one, since there
1305 are a lot of them. */
1308 md_undefined_symbol (char *name ATTRIBUTE_UNUSED
)
1310 #ifndef BFD_ASSEMBLER
1312 char testbuf
[5 + /*SLOP*/ 5];
1315 printf ("md_undefined_symbol(%s)\n", name
);
1318 /* Register name. */
1319 if (name
[0] == 'r' || name
[0] == 'R' || name
[0] == 'a' || name
[0] == 'b')
1321 /* Parse the number, make sure it has no extra zeroes or
1323 regnum
= atol (& name
[1]);
1326 as_fatal (_("register out of range"));
1328 sprintf (testbuf
, "%ld", regnum
);
1330 if (strcmp (testbuf
, &name
[1]) != 0)
1331 return NULL
; /* gr007 or lr7foo or whatever. */
1333 /* We have a wiener! Define and return a new symbol for it. */
1334 return (symbol_new (name
, SEG_REGISTER
, (valueT
) regnum
,
1335 &zero_address_frag
));
1341 /* Parse an operand that is machine-specific. */
1344 md_operand (expressionS
*expressionP
)
1347 printf (" md_operand(input_line_pointer = %s)\n", input_line_pointer
);
1350 if (input_line_pointer
[0] == REGISTER_PREFIX
&& input_line_pointer
[1] == 'r')
1352 /* We have a numeric register expression. No biggy. */
1353 input_line_pointer
+= 2; /* Skip %r */
1354 (void) expression (expressionP
);
1356 if (expressionP
->X_op
!= O_constant
1357 || expressionP
->X_add_number
> 255)
1358 as_bad (_("Invalid expression after %%%%\n"));
1359 expressionP
->X_op
= O_register
;
1361 else if (input_line_pointer
[0] == '&')
1363 /* We are taking the 'address' of a register...this one is not
1364 in the manual, but it *is* in traps/fpsymbol.h! What they
1365 seem to want is the register number, as an absolute number. */
1366 input_line_pointer
++; /* Skip & */
1367 (void) expression (expressionP
);
1369 if (expressionP
->X_op
!= O_register
)
1370 as_bad (_("invalid register in & expression"));
1372 expressionP
->X_op
= O_constant
;
1374 else if (input_line_pointer
[0] == '$'
1375 && ISDIGIT ((unsigned char) input_line_pointer
[1]))
1381 /* This is a local label. */
1382 ++input_line_pointer
;
1383 lab
= (long) get_absolute_expression ();
1385 if (dollar_label_defined (lab
))
1387 name
= dollar_label_name (lab
, 0);
1388 sym
= symbol_find (name
);
1392 name
= dollar_label_name (lab
, 1);
1393 sym
= symbol_find_or_make (name
);
1396 expressionP
->X_op
= O_symbol
;
1397 expressionP
->X_add_symbol
= sym
;
1398 expressionP
->X_add_number
= 0;
1400 else if (input_line_pointer
[0] == '$')
1404 int fieldnum
, fieldlimit
;
1405 LITTLENUM_TYPE floatbuf
[8];
1407 /* $float(), $doubleN(), or $extendN() convert floating values
1409 s
= input_line_pointer
;
1414 if (strncmp (s
, "double", sizeof "double" - 1) == 0)
1416 s
+= sizeof "double" - 1;
1420 else if (strncmp (s
, "float", sizeof "float" - 1) == 0)
1422 s
+= sizeof "float" - 1;
1426 else if (strncmp (s
, "extend", sizeof "extend" - 1) == 0)
1428 s
+= sizeof "extend" - 1;
1437 fieldnum
= *s
- '0';
1440 if (fieldnum
>= fieldlimit
)
1449 s
= atof_ieee (s
, type
, floatbuf
);
1460 input_line_pointer
= s
;
1461 expressionP
->X_op
= O_constant
;
1462 expressionP
->X_unsigned
= 1;
1463 expressionP
->X_add_number
= ((floatbuf
[fieldnum
* 2]
1464 << LITTLENUM_NUMBER_OF_BITS
)
1465 + floatbuf
[fieldnum
* 2 + 1]);
1469 /* Round up a section size to the appropriate boundary. */
1472 md_section_align (segT segment ATTRIBUTE_UNUSED
, valueT size ATTRIBUTE_UNUSED
)
1474 return size
; /* Byte alignment is fine. */
1477 /* Exactly what point is a PC-relative offset relative TO?
1478 On the 29000, they're relative to the address of the instruction,
1479 which we have set up as the address of the fixup too. */
1482 md_pcrel_from (fixS
*fixP
)
1484 return fixP
->fx_where
+ fixP
->fx_frag
->fr_address
;
1487 /* Generate a reloc for a fixup. */
1489 #ifdef BFD_ASSEMBLER
1491 tc_gen_reloc (asection
*seg ATTRIBUTE_UNUSED
, fixS
*fixp
)
1495 reloc
= xmalloc (sizeof (arelent
));
1496 reloc
->sym_ptr_ptr
= xmalloc (sizeof (asymbol
*));
1497 *reloc
->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
1498 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
1499 /* reloc->address = fixp->fx_frag->fr_address + fixp->fx_where + fixp->fx_addnumber;*/
1500 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, fixp
->fx_r_type
);
1502 if (reloc
->howto
== (reloc_howto_type
*) NULL
)
1504 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
1505 _("reloc %d not supported by object file format"),
1506 (int) fixp
->fx_r_type
);
1510 if (fixp
->fx_r_type
== BFD_RELOC_VTABLE_ENTRY
)
1511 reloc
->address
= fixp
->fx_offset
;
1513 reloc
->addend
= fixp
->fx_addnumber
;