1 /* Assembly backend for the OpenRISC 1000.
2 Copyright (C) 2002 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, 59 Temple Place - Suite 330,
22 Boston, MA 02111-1307, 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 static void machine_ip
PARAMS ((char *));
63 const pseudo_typeS md_pseudo_table
[] =
65 {"align", s_align_bytes
, 4 },
66 {"space", s_space
, 0 },
67 {"cputype", s_ignore
, 0 },
68 {"reg", s_lsym
, 0 }, /* Register equate, same as equ. */
69 {"sect", s_ignore
, 0 }, /* Creation of coff sections. */
70 {"proc", s_ignore
, 0 }, /* Start of a function. */
71 {"endproc", s_ignore
, 0 }, /* Function end. */
76 int md_short_jump_size
= 4;
77 int md_long_jump_size
= 4;
79 #if defined(BFD_HEADERS)
81 const int md_reloc_size
= RELSZ
; /* Coff headers. */
83 const int md_reloc_size
= 12; /* Something else headers. */
86 const int md_reloc_size
= 12; /* Not bfdized. */
89 /* This array holds the chars that always start a comment.
90 If the pre-processor is disabled, these aren't very useful. */
91 const char comment_chars
[] = "#";
93 /* This array holds the chars that only start a comment at the beginning of
94 a line. If the line seems to have the form '# 123 filename'
95 .line and .file directives will appear in the pre-processed output. */
96 /* Note that input_file.c hand checks for '#' at the beginning of the
97 first line of the input file. This is because the compiler outputs
98 #NO_APP at the beginning of its output. */
99 /* Also note that comments like this one will always work. */
100 const char line_comment_chars
[] = "#";
102 /* We needed an unused char for line separation to work around the
103 lack of macros, using sed and such. */
104 const char line_separator_chars
[] = ";";
106 /* Chars that can be used to separate mant from exp in floating point nums. */
107 const char EXP_CHARS
[] = "eE";
109 /* Chars that mean this number is a floating point constant.
112 const char FLT_CHARS
[] = "rRsSfFdDxXpP";
114 /* "l.jalr r9" precalculated opcode. */
115 static unsigned long jalr_r9_opcode
;
118 static int check_invalid_opcode
PARAMS ((unsigned long));
119 static void encode
PARAMS ((const struct machine_opcode
*, unsigned long *, signed long, char));
120 static char *parse_operand
PARAMS ((char *, expressionS
*, int));
122 /* Set bits in machine opcode according to insn->encoding
123 description and passed operand. */
126 encode (insn
, opcode
, param_val
, param_ch
)
127 const struct machine_opcode
*insn
;
128 unsigned long *opcode
;
129 signed long param_val
;
137 printf (" encode: opcode=%.8lx param_val=%.8lx abs=%.8lx param_ch=%c\n",
138 *opcode
, param_val
, abs (param_val
), param_ch
);
140 for (enc
= insn
->encoding
; *enc
!= '\0'; enc
++)
141 if (*enc
== param_ch
)
143 if (enc
- 2 >= insn
->encoding
&& (*(enc
- 2) == '0') && (*(enc
- 1) == 'x'))
151 for (enc
= insn
->encoding
; *enc
!= '\0';)
153 if ((*enc
== '0') && (*(enc
+ 1) == 'x'))
155 int tmp
= strtol (enc
, NULL
, 16);
158 *opcode
|= tmp
<< opc_pos
;
161 else if ((*enc
== '0') || (*enc
== '-'))
166 else if (*enc
== '1')
169 *opcode
|= 1 << opc_pos
;
172 else if (*enc
== param_ch
)
176 *opcode
|= ((param_val
>> param_pos
) & 0x1) << opc_pos
;
179 else if (ISALPHA (*enc
))
189 printf (" opcode=%.8lx\n", *opcode
);
193 /* This function is called once, at assembler startup time. It should
194 set up all the tables, etc., that the MD part of the assembler will
200 const char *retval
= NULL
;
205 /* Hash up all the opcodes for fast use later. */
206 op_hash
= hash_new ();
208 for (i
= 0; i
< or32_num_opcodes
; i
++)
210 const char *name
= machine_opcodes
[i
].name
;
218 retval
= hash_insert (op_hash
, name
, (PTR
) &machine_opcodes
[i
]);
221 fprintf (stderr
, "internal error: can't hash `%s': %s\n",
222 machine_opcodes
[i
].name
, retval
);
228 as_fatal (_("Broken assembler. No assembly attempted."));
230 encode (&machine_opcodes
[insn_index ("l.jalr")], &jalr_r9_opcode
, 9, 'B');
233 /* Returns non zero if instruction is to be used. */
236 check_invalid_opcode (opcode
)
237 unsigned long opcode
;
239 return opcode
== jalr_r9_opcode
;
242 /* Assemble a single instruction. Its label has already been handled
243 by the generic front end. We just parse opcode and operands, and
244 produce the bytes of data and relocation. */
253 printf ("NEW INSTRUCTION\n");
260 /* Put out the opcode. */
261 md_number_to_chars (toP
, the_insn
.opcode
, 4);
263 /* Put out the symbol-dependent stuff. */
265 if (the_insn
.reloc
!= BFD_RELOC_NONE
)
267 if (the_insn
.reloc
!= NO_RELOC
)
270 fix_new_exp (frag_now
,
271 (toP
- frag_now
->fr_literal
+ the_insn
.reloc_offset
),
279 /* This is true of the we have issued a "lo(" or "hi"(. */
280 static int waiting_for_shift
= 0;
282 static int mask_or_shift
= 0;
286 parse_operand (s
, operandp
, opt
)
288 expressionS
*operandp
;
291 char *save
= input_line_pointer
;
295 printf (" PROCESS NEW OPERAND(%s) == %c (%d)\n", s
, opt
? opt
: '!', opt
);
298 input_line_pointer
= s
;
300 if (strncasecmp (s
, "HI(", 3) == 0)
302 waiting_for_shift
= 1;
303 mask_or_shift
= BFD_RELOC_HI16
;
305 input_line_pointer
+= 3;
307 else if (strncasecmp (s
, "LO(", 3) == 0)
309 mask_or_shift
= BFD_RELOC_LO16
;
311 input_line_pointer
+= 3;
316 if ((*s
== '(') && (*(s
+1) == 'r'))
319 if ((*s
== 'r') && ISDIGIT (*(s
+ 1)))
321 operandp
->X_add_number
= strtol (s
+ 1, NULL
, 10);
322 operandp
->X_op
= O_register
;
323 for (; (*s
!= ',') && (*s
!= '\0');)
325 input_line_pointer
= save
;
329 expression (operandp
);
331 if (operandp
->X_op
== O_absent
)
334 as_bad (_("missing operand"));
337 operandp
->X_add_number
= 0;
338 operandp
->X_op
= O_constant
;
342 new = input_line_pointer
;
343 input_line_pointer
= save
;
346 printf (" %s=parse_operand(%s): operandp->X_op = %u\n", new, s
, operandp
->X_op
);
354 parse_operand (s
, operandp
, opt
)
356 expressionS
*operandp
;
359 char *save
= input_line_pointer
;
363 printf (" PROCESS NEW OPERAND(%s) == %c (%d)\n", s
, opt
? opt
: '!', opt
);
366 input_line_pointer
= s
;
368 if (strncasecmp (s
, "HI(", 3) == 0)
370 waiting_for_shift
= 1;
371 mask_or_shift
= RELOC_CONSTH
;
373 input_line_pointer
+= 3;
375 else if (strncasecmp (s
, "LO(", 3) == 0)
377 mask_or_shift
= RELOC_CONST
;
379 input_line_pointer
+= 3;
385 expression (operandp
);
387 if (operandp
->X_op
== O_absent
)
390 as_bad (_("missing operand"));
393 operandp
->X_add_number
= 0;
394 operandp
->X_op
= O_constant
;
398 new = input_line_pointer
;
399 input_line_pointer
= save
;
401 if ((operandp
->X_op
== O_symbol
) && (*s
!= '_'))
404 printf ("symbol: '%s'\n", save
);
407 for (save
= s
; s
< new; s
++)
408 if ((*s
== REGISTER_PREFIX
) && (*(s
+ 1) == 'r')) /* Register prefix. */
411 if ((*s
== 'r') && ISDIGIT (*(s
+ 1)))
413 operandp
->X_add_number
= strtol (s
+ 1, NULL
, 10);
414 operandp
->X_op
= O_register
;
420 printf (" %s=parse_operand(%s): operandp->X_op = %u\n", new, s
, operandp
->X_op
);
427 /* Instruction parsing. Takes a string containing the opcode.
428 Operands are at input_line_pointer. Output is in the_insn.
429 Warnings or errors are generated. */
438 const struct machine_opcode
*insn
;
440 unsigned long opcode
;
441 expressionS the_operand
;
442 expressionS
*operand
= &the_operand
;
444 int reloc
= BFD_RELOC_NONE
;
447 printf ("machine_ip(%s)\n", str
);
451 for (; ISALNUM (*s
) || *s
== '.'; ++s
)
460 case ' ': /* FIXME-SOMEDAY more whitespace. */
465 as_bad (_("unknown opcode1: `%s'"), str
);
469 if ((insn
= (struct machine_opcode
*) hash_find (op_hash
, str
)) == NULL
)
471 as_bad (_("unknown opcode2 `%s'."), str
);
477 memset (&the_insn
, '\0', sizeof (the_insn
));
478 the_insn
.reloc
= BFD_RELOC_NONE
;
480 reloc
= BFD_RELOC_NONE
;
482 /* Build the opcode, checking as we go to make sure that the
485 If an operand matches, we modify the_insn or opcode appropriately,
486 and do a "continue". If an operand fails to match, we "break". */
487 if (insn
->args
[0] != '\0')
489 /* Prime the pump. */
490 s
= parse_operand (s
, operand
, insn
->args
[0] == 'I');
493 for (args
= insn
->args
;; ++args
)
496 printf (" args = %s\n", args
);
500 case '\0': /* End of args. */
501 /* We have have 0 args, do the bazoooka! */
502 if (args
== insn
->args
)
503 encode (insn
, &opcode
, 0, 0);
507 /* We are truly done. */
508 the_insn
.opcode
= opcode
;
509 if (check_invalid_opcode (opcode
))
510 as_bad (_("instruction not allowed: %s"), str
);
513 as_bad (_("too many operands: %s"), s
);
516 case ',': /* Must match a comma. */
519 reloc
= BFD_RELOC_NONE
;
521 /* Parse next operand. */
522 s
= parse_operand (s
, operand
, args
[1] == 'I');
524 printf (" ',' case: operand->X_add_number = %d, *args = %s, *s = %s\n",
525 operand
->X_add_number
, args
, s
);
531 case '(': /* Must match a (. */
532 s
= parse_operand (s
, operand
, args
[1] == 'I');
535 case ')': /* Must match a ). */
538 case 'r': /* A general register. */
541 if (operand
->X_op
!= O_register
)
542 break; /* Only registers. */
544 know (operand
->X_add_symbol
== 0);
545 know (operand
->X_op_symbol
== 0);
546 regno
= operand
->X_add_number
;
547 encode (insn
, &opcode
, regno
, *args
);
549 printf (" r: operand->X_op = %d\n", operand
->X_op
);
554 /* if (! ISALPHA (*args))
555 break; */ /* Only immediate values. */
560 printf ("mask_or_shift = %d\n", mask_or_shift
);
562 reloc
= mask_or_shift
;
566 if (strncasecmp (args
, "LO(", 3) == 0)
569 printf ("reloc_const\n");
571 reloc
= BFD_RELOC_LO16
;
573 else if (strncasecmp (args
, "HI(", 3) == 0)
576 printf ("reloc_consth\n");
578 reloc
= BFD_RELOC_HI16
;
583 operand
->X_op
= O_constant
;
585 operand
->X_add_number
= 0; /* ??? if enabled load/store offsets
592 printf (" default case: operand->X_add_number = %d, *args = %s, *s = %s\n", operand
->X_add_number
, args
, s
);
594 if (operand
->X_op
== O_constant
)
596 if (reloc
== BFD_RELOC_NONE
)
601 v
= abs (operand
->X_add_number
) & ~ mask
;
603 as_bad (_("call/jmp target out of range (1)"));
606 if (reloc
== BFD_RELOC_HI16
)
607 operand
->X_add_number
= ((operand
->X_add_number
>> 16) & 0xffff);
610 encode (insn
, &opcode
, operand
->X_add_number
, *args
);
611 /* the_insn.reloc = BFD_RELOC_NONE; */
615 if (reloc
== BFD_RELOC_NONE
)
616 the_insn
.reloc
= BFD_RELOC_32_GOT_PCREL
;
618 the_insn
.reloc
= reloc
;
620 /* the_insn.reloc = insn->reloc; */
622 printf (" reloc sym=%d\n", the_insn
.reloc
);
623 printf (" BFD_RELOC_NONE=%d\n", BFD_RELOC_NONE
);
625 the_insn
.exp
= *operand
;
627 /* the_insn.reloc_offset = 1; */
628 the_insn
.pcrel
= 1; /* Assume PC-relative jump. */
630 /* FIXME-SOON, Do we figure out whether abs later, after
632 if (reloc
== BFD_RELOC_LO16
|| reloc
== BFD_RELOC_HI16
)
635 encode (insn
, &opcode
, operand
->X_add_number
, *args
);
639 /* Types or values of args don't match. */
640 as_bad (_("invalid operands"));
653 const struct machine_opcode
*insn
;
655 unsigned long opcode
;
656 expressionS the_operand
;
657 expressionS
*operand
= &the_operand
;
659 int reloc
= NO_RELOC
;
662 printf ("machine_ip(%s)\n", str
);
666 for (; ISALNUM (*s
) || *s
== '.'; ++s
)
675 case ' ': /* FIXME-SOMEDAY more whitespace. */
680 as_bad (_("unknown opcode1: `%s'"), str
);
684 if ((insn
= (struct machine_opcode
*) hash_find (op_hash
, str
)) == NULL
)
686 as_bad (_("unknown opcode2 `%s'."), str
);
692 memset (&the_insn
, '\0', sizeof (the_insn
));
693 the_insn
.reloc
= NO_RELOC
;
697 /* Build the opcode, checking as we go to make sure that the
700 If an operand matches, we modify the_insn or opcode appropriately,
701 and do a "continue". If an operand fails to match, we "break". */
702 if (insn
->args
[0] != '\0')
703 /* Prime the pump. */
704 s
= parse_operand (s
, operand
,
706 || strcmp (insn
->name
, "l.nop") == 0);
708 for (args
= insn
->args
;; ++args
)
711 printf (" args = %s\n", args
);
715 case '\0': /* End of args. */
716 /* We have have 0 args, do the bazoooka! */
717 if (args
== insn
->args
)
718 encode (insn
, &opcode
, 0, 0);
722 /* We are truly done. */
723 the_insn
.opcode
= opcode
;
724 if (check_invalid_opcode (opcode
))
725 as_bad (_("instruction not allowed: %s"), str
);
728 as_bad (_("too many operands: %s"), s
);
731 case ',': /* Must match a comma. */
736 /* Parse next operand. */
737 s
= parse_operand (s
, operand
, args
[1] == 'I');
739 printf (" ',' case: operand->X_add_number = %d, *args = %s, *s = %s\n",
740 operand
->X_add_number
, args
, s
);
746 case '(': /* Must match a (. */
747 s
= parse_operand (s
, operand
, args
[1] == 'I');
750 case ')': /* Must match a ). */
753 case 'r': /* A general register. */
756 if (operand
->X_op
!= O_register
)
757 break; /* Only registers. */
759 know (operand
->X_add_symbol
== 0);
760 know (operand
->X_op_symbol
== 0);
761 regno
= operand
->X_add_number
;
762 encode (insn
, &opcode
, regno
, *args
);
764 printf (" r: operand->X_op = %d\n", operand
->X_op
);
769 /* if (! ISALPHA (*args))
770 break; */ /* Only immediate values. */
775 printf ("mask_or_shift = %d\n", mask_or_shift
);
777 reloc
= mask_or_shift
;
781 if (strncasecmp (args
, "LO(", 3) == 0)
784 printf ("reloc_const\n");
788 else if (strncasecmp (args
, "HI(", 3) == 0)
791 printf ("reloc_consth\n");
793 reloc
= RELOC_CONSTH
;
798 operand
->X_op
= O_constant
;
800 operand
->X_add_number
= 0; /* ??? if enabled load/store offsets
807 printf (" default case: operand->X_add_number = %d, *args = %s, *s = %s\n",
808 operand
->X_add_number
, args
, s
);
810 if (operand
->X_op
== O_constant
)
812 if (reloc
== NO_RELOC
)
814 unsigned long v
, mask
;
817 v
= abs (operand
->X_add_number
) & ~ mask
;
819 as_bad (_("call/jmp target out of range (1)"));
822 if (reloc
== RELOC_CONSTH
)
823 operand
->X_add_number
= ((operand
->X_add_number
>>16) & 0xffff);
826 encode (insn
, &opcode
, operand
->X_add_number
, *args
);
827 /* the_insn.reloc = NO_RELOC; */
831 if (reloc
== NO_RELOC
)
832 the_insn
.reloc
= RELOC_JUMPTARG
;
834 the_insn
.reloc
= reloc
;
836 printf (" reloc sym=%d\n", the_insn
.reloc
);
837 printf (" NO_RELOC=%d\n", NO_RELOC
);
839 the_insn
.exp
= *operand
;
841 /* the_insn.reloc_offset = 1; */
842 the_insn
.pcrel
= 1; /* Assume PC-relative jump. */
844 /* FIXME-SOON, Do we figure out whether abs later, after
846 if (reloc
== RELOC_CONST
|| reloc
== RELOC_CONSTH
)
849 encode (insn
, &opcode
, operand
->X_add_number
, *args
);
853 /* Types or values of args don't match. */
854 as_bad (_("invalid operands"));
860 /* This is identical to the md_atof in m68k.c. I think this is right,
863 Turn a string in input_line_pointer into a floating point constant
864 of type type, and store the appropriate bytes in *litP. The number
865 of LITTLENUMS emitted is stored in *sizeP . An error message is
866 returned, or NULL on OK. */
868 /* Equal to MAX_PRECISION in atof-ieee.c. */
869 #define MAX_LITTLENUMS 6
872 md_atof (type
, litP
, sizeP
)
878 LITTLENUM_TYPE words
[MAX_LITTLENUMS
];
879 LITTLENUM_TYPE
*wordP
;
910 return _("Bad call to MD_ATOF()");
913 t
= atof_ieee (input_line_pointer
, type
, words
);
915 input_line_pointer
= t
;
917 *sizeP
= prec
* sizeof (LITTLENUM_TYPE
);
919 for (wordP
= words
; prec
--;)
921 md_number_to_chars (litP
, (valueT
) (*wordP
++), sizeof (LITTLENUM_TYPE
));
922 litP
+= sizeof (LITTLENUM_TYPE
);
928 /* Write out big-endian. */
931 md_number_to_chars (buf
, val
, n
)
936 number_to_chars_bigendian (buf
, val
, n
);
941 md_apply_fix3 (fixP
, val
, seg
)
944 segT seg ATTRIBUTE_UNUSED
;
946 char *buf
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
952 printf ("md_apply_fix val:%x\n", t_val
);
955 fixP
->fx_addnumber
= t_val
; /* Remember value for emit_reloc. */
957 know (fixP
->fx_size
== 4);
958 know (fixP
->fx_r_type
< BFD_RELOC_NONE
);
960 switch (fixP
->fx_r_type
)
962 case BFD_RELOC_32
: /* XXXXXXXX pattern in a word. */
964 printf ("reloc_const: val=%x\n", t_val
);
966 buf
[0] = t_val
>> 24;
967 buf
[1] = t_val
>> 16;
972 case BFD_RELOC_16
: /* XXXX0000 pattern in a word. */
974 printf ("reloc_const: val=%x\n", t_val
);
980 case BFD_RELOC_8
: /* XX000000 pattern in a word. */
982 printf ("reloc_const: val=%x\n", t_val
);
987 case BFD_RELOC_LO16
: /* 0000XXXX pattern in a word. */
989 printf ("reloc_const: val=%x\n", t_val
);
991 buf
[2] = t_val
>> 8; /* Holds bits 0000XXXX. */
995 case BFD_RELOC_HI16
: /* 0000XXXX pattern in a word. */
997 printf ("reloc_consth: val=%x\n", t_val
);
999 buf
[2] = t_val
>> 24; /* Holds bits XXXX0000. */
1000 buf
[3] = t_val
>> 16;
1003 case BFD_RELOC_32_GOT_PCREL
: /* 0000XXXX pattern in a word. */
1006 /* The linker tries to support both AMD and old GNU style
1007 R_IREL relocs. That means that if the addend is exactly
1008 the negative of the address within the section, the
1009 linker will not handle it correctly. */
1013 && t_val
== - (fixP
->fx_frag
->fr_address
+ fixP
->fx_where
))
1015 (fixP
->fx_file
, fixP
->fx_line
,
1016 _("the linker will not handle this relocation correctly (1)"));
1019 else if (fixP
->fx_pcrel
)
1021 long v
= t_val
>> 28;
1023 if (v
!= 0 && v
!= -1)
1024 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
1025 _("call/jmp target out of range (2)"));
1028 /* This case was supposed to be handled in machine_ip. */
1031 buf
[0] |= (t_val
>> 26) & 0x03; /* Holds bits 0FFFFFFC of address. */
1032 buf
[1] = t_val
>> 18;
1033 buf
[2] = t_val
>> 10;
1034 buf
[3] = t_val
>> 2;
1037 case BFD_RELOC_VTABLE_INHERIT
:
1038 case BFD_RELOC_VTABLE_ENTRY
:
1042 case BFD_RELOC_NONE
:
1044 as_bad (_("bad relocation type: 0x%02x"), fixP
->fx_r_type
);
1048 if (fixP
->fx_addsy
== (symbolS
*) NULL
)
1053 md_apply_fix3 (fixP
, valP
, seg
)
1056 segT seg ATTRIBUTE_UNUSED
;
1059 char *buf
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
1062 printf ("md_apply_fix val:%x\n", val
);
1065 fixP
->fx_addnumber
= val
; /* Remember value for emit_reloc. */
1067 know (fixP
->fx_size
== 4);
1068 know (fixP
->fx_r_type
< NO_RELOC
);
1070 /* This is a hack. There should be a better way to handle this. */
1071 if (fixP
->fx_r_type
== RELOC_WDISP30
&& fixP
->fx_addsy
)
1072 val
+= fixP
->fx_where
+ fixP
->fx_frag
->fr_address
;
1074 switch (fixP
->fx_r_type
)
1088 val
= (val
>> 2) + 1;
1089 buf
[0] |= (val
>> 24) & 0x3f;
1090 buf
[1] = (val
>> 16);
1096 buf
[1] |= (val
>> 26) & 0x3f;
1102 buf
[2] |= (val
>> 8) & 0x03;
1107 buf
[2] |= (val
>> 8) & 0x1f;
1112 val
= (val
>> 2) + 1;
1115 buf
[1] |= (val
>> 16) & 0x3f;
1120 case RELOC_JUMPTARG
: /* 0000XXXX pattern in a word. */
1123 /* The linker tries to support both AMD and old GNU style
1124 R_IREL relocs. That means that if the addend is exactly
1125 the negative of the address within the section, the
1126 linker will not handle it correctly. */
1130 && val
== - (fixP
->fx_frag
->fr_address
+ fixP
->fx_where
))
1132 (fixP
->fx_file
, fixP
->fx_line
,
1133 _("the linker will not handle this relocation correctly (1)"));
1136 else if (fixP
->fx_pcrel
)
1140 if (v
!= 0 && v
!= -1)
1141 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
1142 _("call/jmp target out of range (2)"));
1146 /* This case was supposed to be handled in machine_ip. */
1149 buf
[0] |= (val
>> 26) & 0x03; /* Holds bits 0FFFFFFC of address. */
1155 case RELOC_CONST
: /* 0000XXXX pattern in a word. */
1157 printf ("reloc_const: val=%x\n", val
);
1159 buf
[2] = val
>> 8; /* Holds bits 0000XXXX. */
1163 case RELOC_CONSTH
: /* 0000XXXX pattern in a word. */
1165 printf ("reloc_consth: val=%x\n", val
);
1167 buf
[2] = val
>> 24; /* Holds bits XXXX0000. */
1171 case BFD_RELOC_VTABLE_INHERIT
:
1172 case BFD_RELOC_VTABLE_ENTRY
:
1178 as_bad (_("bad relocation type: 0x%02x"), fixP
->fx_r_type
);
1182 if (fixP
->fx_addsy
== (symbolS
*) NULL
)
1189 tc_coff_fix2rtype (fixP
)
1193 printf ("tc_coff_fix2rtype\n");
1196 switch (fixP
->fx_r_type
)
1206 case RELOC_JUMPTARG
:
1209 printf ("need %d\n", fixP
->fx_r_type
);
1216 #endif /* OBJ_COFF */
1218 /* Should never be called for or32. */
1221 md_create_short_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
1222 char * ptr ATTRIBUTE_UNUSED
;
1223 addressT from_addr ATTRIBUTE_UNUSED
;
1224 addressT to_addr ATTRIBUTE_UNUSED
;
1225 fragS
* frag ATTRIBUTE_UNUSED
;
1226 symbolS
* to_symbol ATTRIBUTE_UNUSED
;
1228 as_fatal ("or32_create_short_jmp\n");
1231 /* Should never be called for or32. */
1233 #ifndef BFD_ASSEMBLER
1235 md_convert_frag (headers
, seg
, fragP
)
1236 object_headers
* headers ATTRIBUTE_UNUSED
;
1237 segT seg ATTRIBUTE_UNUSED
;
1238 register fragS
* fragP ATTRIBUTE_UNUSED
;
1240 as_fatal ("or32_convert_frag\n");
1245 md_convert_frag (headers
, seg
, fragP
)
1246 bfd
* headers ATTRIBUTE_UNUSED
;
1247 segT seg ATTRIBUTE_UNUSED
;
1248 fragS
* fragP ATTRIBUTE_UNUSED
;
1250 as_fatal ("or32_convert_frag\n");
1254 /* Should never be called for or32. */
1257 md_create_long_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
1258 char * ptr ATTRIBUTE_UNUSED
;
1259 addressT from_addr ATTRIBUTE_UNUSED
;
1260 addressT to_addr ATTRIBUTE_UNUSED
;
1261 fragS
* frag ATTRIBUTE_UNUSED
;
1262 symbolS
* to_symbol ATTRIBUTE_UNUSED
;
1264 as_fatal ("or32_create_long_jump\n");
1267 /* Should never be called for or32. */
1270 md_estimate_size_before_relax (fragP
, segtype
)
1271 fragS
* fragP ATTRIBUTE_UNUSED
;
1272 segT segtype ATTRIBUTE_UNUSED
;
1274 as_fatal ("or32_estimate_size_before_relax\n");
1278 /* Translate internal representation of relocation info to target format.
1280 On sparc/29k: first 4 bytes are normal unsigned long address, next three
1281 bytes are index, most sig. byte first. Byte 7 is broken up with
1282 bit 7 as external, bits 6 & 5 unused, and the lower
1283 five bits as relocation type. Next 4 bytes are long addend. */
1284 /* Thanx and a tip of the hat to Michael Bloom, mb@ttidca.tti.com. */
1288 tc_aout_fix_to_chars (where
, fixP
, segment_address_in_file
)
1291 relax_addressT segment_address_in_file
;
1296 printf ("tc_aout_fix_to_chars\n");
1299 know (fixP
->fx_r_type
< BFD_RELOC_NONE
);
1300 know (fixP
->fx_addsy
!= NULL
);
1304 fixP
->fx_frag
->fr_address
+ fixP
->fx_where
- segment_address_in_file
,
1307 r_symbolnum
= (S_IS_DEFINED (fixP
->fx_addsy
)
1308 ? S_GET_TYPE (fixP
->fx_addsy
)
1309 : fixP
->fx_addsy
->sy_number
);
1311 where
[4] = (r_symbolnum
>> 16) & 0x0ff;
1312 where
[5] = (r_symbolnum
>> 8) & 0x0ff;
1313 where
[6] = r_symbolnum
& 0x0ff;
1314 where
[7] = (((!S_IS_DEFINED (fixP
->fx_addsy
)) << 7) & 0x80) | (0 & 0x60) | (fixP
->fx_r_type
& 0x1F);
1317 md_number_to_chars (&where
[8], fixP
->fx_addnumber
, 4);
1320 #endif /* OBJ_AOUT */
1322 const char *md_shortopts
= "";
1324 struct option md_longopts
[] =
1326 { NULL
, no_argument
, NULL
, 0 }
1328 size_t md_longopts_size
= sizeof (md_longopts
);
1331 md_parse_option (c
, arg
)
1332 int c ATTRIBUTE_UNUSED
;
1333 char * arg ATTRIBUTE_UNUSED
;
1339 md_show_usage (stream
)
1340 FILE * stream ATTRIBUTE_UNUSED
;
1344 /* This is called when a line is unrecognized. This is used to handle
1345 definitions of or32 style local labels. */
1348 or32_unrecognized_line (c
)
1355 || ! ISDIGIT ((unsigned char) input_line_pointer
[0]))
1358 s
= input_line_pointer
;
1361 while (ISDIGIT ((unsigned char) *s
))
1363 lab
= lab
* 10 + *s
- '0';
1368 /* Not a label definition. */
1371 if (dollar_label_defined (lab
))
1373 as_bad (_("label \"$%d\" redefined"), lab
);
1377 define_dollar_label (lab
);
1378 colon (dollar_label_name (lab
, 0));
1379 input_line_pointer
= s
+ 1;
1384 #ifndef BFD_ASSEMBLER
1385 /* Record a fixup for a cons expression. */
1388 or32_cons_fix_new (frag, where, nbytes, exp)
1394 fix_new_exp (frag, where, nbytes, exp, 0,
1395 nbytes == 5 ? RELOC_32
1396 : nbytes == 2 ? RELOC_16
1400 tc_aout_pre_write_hook ()
1403 printf ("In tc_aout_pre_write_hook()\n");
1409 /* Default the values of symbols known that should be "predefined". We
1410 don't bother to predefine them unless you actually use one, since there
1411 are a lot of them. */
1414 md_undefined_symbol (name
)
1415 char *name ATTRIBUTE_UNUSED
;
1417 #ifndef BFD_ASSEMBLER
1419 char testbuf
[5 + /*SLOP*/ 5];
1422 printf ("md_undefined_symbol(%s)\n", name
);
1425 /* Register name. */
1426 if (name
[0] == 'r' || name
[0] == 'R' || name
[0] == 'a' || name
[0] == 'b')
1428 /* Parse the number, make sure it has no extra zeroes or
1430 regnum
= atol (& name
[1]);
1433 as_fatal (_("register out of range"));
1435 sprintf (testbuf
, "%ld", regnum
);
1437 if (strcmp (testbuf
, &name
[1]) != 0)
1438 return NULL
; /* gr007 or lr7foo or whatever. */
1440 /* We have a wiener! Define and return a new symbol for it. */
1441 return (symbol_new (name
, SEG_REGISTER
, (valueT
) regnum
,
1442 &zero_address_frag
));
1448 /* Parse an operand that is machine-specific. */
1451 md_operand (expressionP
)
1452 expressionS
*expressionP
;
1455 printf (" md_operand(input_line_pointer = %s)\n", input_line_pointer
);
1458 if (input_line_pointer
[0] == REGISTER_PREFIX
&& input_line_pointer
[1] == 'r')
1460 /* We have a numeric register expression. No biggy. */
1461 input_line_pointer
+= 2; /* Skip %r */
1462 (void) expression (expressionP
);
1464 if (expressionP
->X_op
!= O_constant
1465 || expressionP
->X_add_number
> 255)
1466 as_bad (_("Invalid expression after %%%%\n"));
1467 expressionP
->X_op
= O_register
;
1469 else if (input_line_pointer
[0] == '&')
1471 /* We are taking the 'address' of a register...this one is not
1472 in the manual, but it *is* in traps/fpsymbol.h! What they
1473 seem to want is the register number, as an absolute number. */
1474 input_line_pointer
++; /* Skip & */
1475 (void) expression (expressionP
);
1477 if (expressionP
->X_op
!= O_register
)
1478 as_bad (_("invalid register in & expression"));
1480 expressionP
->X_op
= O_constant
;
1482 else if (input_line_pointer
[0] == '$'
1483 && ISDIGIT ((unsigned char) input_line_pointer
[1]))
1489 /* This is a local label. */
1490 ++input_line_pointer
;
1491 lab
= (long) get_absolute_expression ();
1493 if (dollar_label_defined (lab
))
1495 name
= dollar_label_name (lab
, 0);
1496 sym
= symbol_find (name
);
1500 name
= dollar_label_name (lab
, 1);
1501 sym
= symbol_find_or_make (name
);
1504 expressionP
->X_op
= O_symbol
;
1505 expressionP
->X_add_symbol
= sym
;
1506 expressionP
->X_add_number
= 0;
1508 else if (input_line_pointer
[0] == '$')
1512 int fieldnum
, fieldlimit
;
1513 LITTLENUM_TYPE floatbuf
[8];
1515 /* $float(), $doubleN(), or $extendN() convert floating values
1517 s
= input_line_pointer
;
1522 if (strncmp (s
, "double", sizeof "double" - 1) == 0)
1524 s
+= sizeof "double" - 1;
1528 else if (strncmp (s
, "float", sizeof "float" - 1) == 0)
1530 s
+= sizeof "float" - 1;
1534 else if (strncmp (s
, "extend", sizeof "extend" - 1) == 0)
1536 s
+= sizeof "extend" - 1;
1545 fieldnum
= *s
- '0';
1548 if (fieldnum
>= fieldlimit
)
1557 s
= atof_ieee (s
, type
, floatbuf
);
1568 input_line_pointer
= s
;
1569 expressionP
->X_op
= O_constant
;
1570 expressionP
->X_unsigned
= 1;
1571 expressionP
->X_add_number
= ((floatbuf
[fieldnum
* 2]
1572 << LITTLENUM_NUMBER_OF_BITS
)
1573 + floatbuf
[fieldnum
* 2 + 1]);
1577 /* Round up a section size to the appropriate boundary. */
1580 md_section_align (segment
, size
)
1581 segT segment ATTRIBUTE_UNUSED
;
1582 valueT size ATTRIBUTE_UNUSED
;
1584 return size
; /* Byte alignment is fine. */
1587 /* Exactly what point is a PC-relative offset relative TO?
1588 On the 29000, they're relative to the address of the instruction,
1589 which we have set up as the address of the fixup too. */
1592 md_pcrel_from (fixP
)
1595 return fixP
->fx_where
+ fixP
->fx_frag
->fr_address
;
1598 /* Generate a reloc for a fixup. */
1600 #ifdef BFD_ASSEMBLER
1602 tc_gen_reloc (seg
, fixp
)
1603 asection
*seg ATTRIBUTE_UNUSED
;
1608 reloc
= (arelent
*) xmalloc (sizeof (arelent
));
1609 reloc
->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
1610 *reloc
->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
1611 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
1612 /* reloc->address = fixp->fx_frag->fr_address + fixp->fx_where + fixp->fx_addnumber;*/
1613 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, fixp
->fx_r_type
);
1615 if (reloc
->howto
== (reloc_howto_type
*) NULL
)
1617 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
1618 _("reloc %d not supported by object file format"),
1619 (int) fixp
->fx_r_type
);
1623 if (fixp
->fx_r_type
== BFD_RELOC_VTABLE_ENTRY
)
1624 reloc
->address
= fixp
->fx_offset
;
1626 reloc
->addend
= fixp
->fx_addnumber
;