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, 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
;
588 printf (" default case: operand->X_add_number = %d, *args = %s, *s = %s\n", operand
->X_add_number
, args
, s
);
590 if (operand
->X_op
== O_constant
)
592 if (reloc
== BFD_RELOC_NONE
)
597 v
= abs (operand
->X_add_number
) & ~ mask
;
599 as_bad (_("call/jmp target out of range (1)"));
602 if (reloc
== BFD_RELOC_HI16
)
603 operand
->X_add_number
= ((operand
->X_add_number
>> 16) & 0xffff);
606 encode (insn
, &opcode
, operand
->X_add_number
, *args
);
607 /* the_insn.reloc = BFD_RELOC_NONE; */
611 if (reloc
== BFD_RELOC_NONE
)
612 the_insn
.reloc
= BFD_RELOC_32_GOT_PCREL
;
614 the_insn
.reloc
= reloc
;
616 /* the_insn.reloc = insn->reloc; */
618 printf (" reloc sym=%d\n", the_insn
.reloc
);
619 printf (" BFD_RELOC_NONE=%d\n", BFD_RELOC_NONE
);
621 the_insn
.exp
= *operand
;
623 /* the_insn.reloc_offset = 1; */
624 the_insn
.pcrel
= 1; /* Assume PC-relative jump. */
626 /* FIXME-SOON, Do we figure out whether abs later, after
628 if (reloc
== BFD_RELOC_LO16
|| reloc
== BFD_RELOC_HI16
)
631 encode (insn
, &opcode
, operand
->X_add_number
, *args
);
635 /* Types or values of args don't match. */
636 as_bad (_("invalid operands"));
649 const struct machine_opcode
*insn
;
651 unsigned long opcode
;
652 expressionS the_operand
;
653 expressionS
*operand
= &the_operand
;
655 int reloc
= NO_RELOC
;
658 printf ("machine_ip(%s)\n", str
);
662 for (; ISALNUM (*s
) || *s
== '.'; ++s
)
671 case ' ': /* FIXME-SOMEDAY more whitespace. */
676 as_bad (_("unknown opcode1: `%s'"), str
);
680 if ((insn
= (struct machine_opcode
*) hash_find (op_hash
, str
)) == NULL
)
682 as_bad (_("unknown opcode2 `%s'."), str
);
688 memset (&the_insn
, '\0', sizeof (the_insn
));
689 the_insn
.reloc
= NO_RELOC
;
693 /* Build the opcode, checking as we go to make sure that the
696 If an operand matches, we modify the_insn or opcode appropriately,
697 and do a "continue". If an operand fails to match, we "break". */
698 if (insn
->args
[0] != '\0')
699 /* Prime the pump. */
700 s
= parse_operand (s
, operand
,
702 || strcmp (insn
->name
, "l.nop") == 0);
704 for (args
= insn
->args
;; ++args
)
707 printf (" args = %s\n", args
);
711 case '\0': /* End of args. */
712 /* We have have 0 args, do the bazoooka! */
713 if (args
== insn
->args
)
714 encode (insn
, &opcode
, 0, 0);
718 /* We are truly done. */
719 the_insn
.opcode
= opcode
;
720 if (check_invalid_opcode (opcode
))
721 as_bad (_("instruction not allowed: %s"), str
);
724 as_bad (_("too many operands: %s"), s
);
727 case ',': /* Must match a comma. */
732 /* Parse next operand. */
733 s
= parse_operand (s
, operand
, args
[1] == 'I');
735 printf (" ',' case: operand->X_add_number = %d, *args = %s, *s = %s\n",
736 operand
->X_add_number
, args
, s
);
742 case '(': /* Must match a (. */
743 s
= parse_operand (s
, operand
, args
[1] == 'I');
746 case ')': /* Must match a ). */
749 case 'r': /* A general register. */
752 if (operand
->X_op
!= O_register
)
753 break; /* Only registers. */
755 know (operand
->X_add_symbol
== 0);
756 know (operand
->X_op_symbol
== 0);
757 regno
= operand
->X_add_number
;
758 encode (insn
, &opcode
, regno
, *args
);
760 printf (" r: operand->X_op = %d\n", operand
->X_op
);
765 /* if (! ISALPHA (*args))
766 break; */ /* Only immediate values. */
771 printf ("mask_or_shift = %d\n", mask_or_shift
);
773 reloc
= mask_or_shift
;
777 if (strncasecmp (args
, "LO(", 3) == 0)
780 printf ("reloc_const\n");
784 else if (strncasecmp (args
, "HI(", 3) == 0)
787 printf ("reloc_consth\n");
789 reloc
= RELOC_CONSTH
;
794 operand
->X_op
= O_constant
;
799 printf (" default case: operand->X_add_number = %d, *args = %s, *s = %s\n",
800 operand
->X_add_number
, args
, s
);
802 if (operand
->X_op
== O_constant
)
804 if (reloc
== NO_RELOC
)
806 unsigned long v
, mask
;
809 v
= abs (operand
->X_add_number
) & ~ mask
;
811 as_bad (_("call/jmp target out of range (1)"));
814 if (reloc
== RELOC_CONSTH
)
815 operand
->X_add_number
= ((operand
->X_add_number
>>16) & 0xffff);
818 encode (insn
, &opcode
, operand
->X_add_number
, *args
);
819 /* the_insn.reloc = NO_RELOC; */
823 if (reloc
== NO_RELOC
)
824 the_insn
.reloc
= RELOC_JUMPTARG
;
826 the_insn
.reloc
= reloc
;
828 printf (" reloc sym=%d\n", the_insn
.reloc
);
829 printf (" NO_RELOC=%d\n", NO_RELOC
);
831 the_insn
.exp
= *operand
;
833 /* the_insn.reloc_offset = 1; */
834 the_insn
.pcrel
= 1; /* Assume PC-relative jump. */
836 /* FIXME-SOON, Do we figure out whether abs later, after
838 if (reloc
== RELOC_CONST
|| reloc
== RELOC_CONSTH
)
841 encode (insn
, &opcode
, operand
->X_add_number
, *args
);
845 /* Types or values of args don't match. */
846 as_bad (_("invalid operands"));
852 /* This is identical to the md_atof in m68k.c. I think this is right,
855 Turn a string in input_line_pointer into a floating point constant
856 of type type, and store the appropriate bytes in *litP. The number
857 of LITTLENUMS emitted is stored in *sizeP . An error message is
858 returned, or NULL on OK. */
860 /* Equal to MAX_PRECISION in atof-ieee.c. */
861 #define MAX_LITTLENUMS 6
864 md_atof (type
, litP
, sizeP
)
870 LITTLENUM_TYPE words
[MAX_LITTLENUMS
];
871 LITTLENUM_TYPE
*wordP
;
902 return _("Bad call to MD_ATOF()");
905 t
= atof_ieee (input_line_pointer
, type
, words
);
907 input_line_pointer
= t
;
909 *sizeP
= prec
* sizeof (LITTLENUM_TYPE
);
911 for (wordP
= words
; prec
--;)
913 md_number_to_chars (litP
, (valueT
) (*wordP
++), sizeof (LITTLENUM_TYPE
));
914 litP
+= sizeof (LITTLENUM_TYPE
);
920 /* Write out big-endian. */
923 md_number_to_chars (buf
, val
, n
)
928 number_to_chars_bigendian (buf
, val
, n
);
933 md_apply_fix3 (fixP
, val
, seg
)
936 segT seg ATTRIBUTE_UNUSED
;
938 char *buf
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
944 printf ("md_apply_fix val:%x\n", t_val
);
947 fixP
->fx_addnumber
= t_val
; /* Remember value for emit_reloc. */
949 know (fixP
->fx_size
== 4);
950 know (fixP
->fx_r_type
< BFD_RELOC_NONE
);
952 switch (fixP
->fx_r_type
)
954 case BFD_RELOC_32
: /* XXXXXXXX pattern in a word. */
956 printf ("reloc_const: val=%x\n", t_val
);
958 buf
[0] = t_val
>> 24;
959 buf
[1] = t_val
>> 16;
964 case BFD_RELOC_16
: /* XXXX0000 pattern in a word. */
966 printf ("reloc_const: val=%x\n", t_val
);
972 case BFD_RELOC_8
: /* XX000000 pattern in a word. */
974 printf ("reloc_const: val=%x\n", t_val
);
979 case BFD_RELOC_LO16
: /* 0000XXXX pattern in a word. */
981 printf ("reloc_const: val=%x\n", t_val
);
983 buf
[2] = t_val
>> 8; /* Holds bits 0000XXXX. */
987 case BFD_RELOC_HI16
: /* 0000XXXX pattern in a word. */
989 printf ("reloc_consth: val=%x\n", t_val
);
991 buf
[2] = t_val
>> 24; /* Holds bits XXXX0000. */
992 buf
[3] = t_val
>> 16;
995 case BFD_RELOC_32_GOT_PCREL
: /* 0000XXXX pattern in a word. */
998 else if (fixP
->fx_pcrel
)
1000 long v
= t_val
>> 28;
1002 if (v
!= 0 && v
!= -1)
1003 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
1004 _("call/jmp target out of range (2)"));
1007 /* This case was supposed to be handled in machine_ip. */
1010 buf
[0] |= (t_val
>> 26) & 0x03; /* Holds bits 0FFFFFFC of address. */
1011 buf
[1] = t_val
>> 18;
1012 buf
[2] = t_val
>> 10;
1013 buf
[3] = t_val
>> 2;
1016 case BFD_RELOC_VTABLE_INHERIT
:
1017 case BFD_RELOC_VTABLE_ENTRY
:
1021 case BFD_RELOC_NONE
:
1023 as_bad (_("bad relocation type: 0x%02x"), fixP
->fx_r_type
);
1027 if (fixP
->fx_addsy
== (symbolS
*) NULL
)
1032 md_apply_fix3 (fixP
, valP
, seg
)
1035 segT seg ATTRIBUTE_UNUSED
;
1038 char *buf
= fixP
->fx_where
+ fixP
->fx_frag
->fr_literal
;
1041 printf ("md_apply_fix val:%x\n", val
);
1044 fixP
->fx_addnumber
= val
; /* Remember value for emit_reloc. */
1046 know (fixP
->fx_size
== 4);
1047 know (fixP
->fx_r_type
< NO_RELOC
);
1049 /* This is a hack. There should be a better way to handle this. */
1050 if (fixP
->fx_r_type
== RELOC_WDISP30
&& fixP
->fx_addsy
)
1051 val
+= fixP
->fx_where
+ fixP
->fx_frag
->fr_address
;
1053 switch (fixP
->fx_r_type
)
1067 val
= (val
>> 2) + 1;
1068 buf
[0] |= (val
>> 24) & 0x3f;
1069 buf
[1] = (val
>> 16);
1075 buf
[1] |= (val
>> 26) & 0x3f;
1081 buf
[2] |= (val
>> 8) & 0x03;
1086 buf
[2] |= (val
>> 8) & 0x1f;
1091 val
= (val
>> 2) + 1;
1094 buf
[1] |= (val
>> 16) & 0x3f;
1099 case RELOC_JUMPTARG
: /* 0000XXXX pattern in a word. */
1102 /* The linker tries to support both AMD and old GNU style
1103 R_IREL relocs. That means that if the addend is exactly
1104 the negative of the address within the section, the
1105 linker will not handle it correctly. */
1107 else if (fixP
->fx_pcrel
)
1110 if (v
!= 0 && v
!= -1)
1111 as_bad_where (fixP
->fx_file
, fixP
->fx_line
,
1112 _("call/jmp target out of range (2)"));
1115 /* This case was supposed to be handled in machine_ip. */
1118 buf
[0] |= (val
>> 26) & 0x03; /* Holds bits 0FFFFFFC of address. */
1124 case RELOC_CONST
: /* 0000XXXX pattern in a word. */
1126 printf ("reloc_const: val=%x\n", val
);
1128 buf
[2] = val
>> 8; /* Holds bits 0000XXXX. */
1132 case RELOC_CONSTH
: /* 0000XXXX pattern in a word. */
1134 printf ("reloc_consth: val=%x\n", val
);
1136 buf
[2] = val
>> 24; /* Holds bits XXXX0000. */
1140 case BFD_RELOC_VTABLE_INHERIT
:
1141 case BFD_RELOC_VTABLE_ENTRY
:
1147 as_bad (_("bad relocation type: 0x%02x"), fixP
->fx_r_type
);
1151 if (fixP
->fx_addsy
== (symbolS
*) NULL
)
1158 tc_coff_fix2rtype (fixP
)
1162 printf ("tc_coff_fix2rtype\n");
1165 switch (fixP
->fx_r_type
)
1175 case RELOC_JUMPTARG
:
1178 printf ("need %d\n", fixP
->fx_r_type
);
1185 #endif /* OBJ_COFF */
1187 /* Should never be called for or32. */
1190 md_create_short_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
1191 char * ptr ATTRIBUTE_UNUSED
;
1192 addressT from_addr ATTRIBUTE_UNUSED
;
1193 addressT to_addr ATTRIBUTE_UNUSED
;
1194 fragS
* frag ATTRIBUTE_UNUSED
;
1195 symbolS
* to_symbol ATTRIBUTE_UNUSED
;
1197 as_fatal ("or32_create_short_jmp\n");
1200 /* Should never be called for or32. */
1202 #ifndef BFD_ASSEMBLER
1204 md_convert_frag (headers
, seg
, fragP
)
1205 object_headers
* headers ATTRIBUTE_UNUSED
;
1206 segT seg ATTRIBUTE_UNUSED
;
1207 register fragS
* fragP ATTRIBUTE_UNUSED
;
1209 as_fatal ("or32_convert_frag\n");
1214 md_convert_frag (headers
, seg
, fragP
)
1215 bfd
* headers ATTRIBUTE_UNUSED
;
1216 segT seg ATTRIBUTE_UNUSED
;
1217 fragS
* fragP ATTRIBUTE_UNUSED
;
1219 as_fatal ("or32_convert_frag\n");
1223 /* Should never be called for or32. */
1226 md_create_long_jump (ptr
, from_addr
, to_addr
, frag
, to_symbol
)
1227 char * ptr ATTRIBUTE_UNUSED
;
1228 addressT from_addr ATTRIBUTE_UNUSED
;
1229 addressT to_addr ATTRIBUTE_UNUSED
;
1230 fragS
* frag ATTRIBUTE_UNUSED
;
1231 symbolS
* to_symbol ATTRIBUTE_UNUSED
;
1233 as_fatal ("or32_create_long_jump\n");
1236 /* Should never be called for or32. */
1239 md_estimate_size_before_relax (fragP
, segtype
)
1240 fragS
* fragP ATTRIBUTE_UNUSED
;
1241 segT segtype ATTRIBUTE_UNUSED
;
1243 as_fatal ("or32_estimate_size_before_relax\n");
1247 /* Translate internal representation of relocation info to target format.
1249 On sparc/29k: first 4 bytes are normal unsigned long address, next three
1250 bytes are index, most sig. byte first. Byte 7 is broken up with
1251 bit 7 as external, bits 6 & 5 unused, and the lower
1252 five bits as relocation type. Next 4 bytes are long addend. */
1253 /* Thanx and a tip of the hat to Michael Bloom, mb@ttidca.tti.com. */
1257 tc_aout_fix_to_chars (where
, fixP
, segment_address_in_file
)
1260 relax_addressT segment_address_in_file
;
1265 printf ("tc_aout_fix_to_chars\n");
1268 know (fixP
->fx_r_type
< BFD_RELOC_NONE
);
1269 know (fixP
->fx_addsy
!= NULL
);
1273 fixP
->fx_frag
->fr_address
+ fixP
->fx_where
- segment_address_in_file
,
1276 r_symbolnum
= (S_IS_DEFINED (fixP
->fx_addsy
)
1277 ? S_GET_TYPE (fixP
->fx_addsy
)
1278 : fixP
->fx_addsy
->sy_number
);
1280 where
[4] = (r_symbolnum
>> 16) & 0x0ff;
1281 where
[5] = (r_symbolnum
>> 8) & 0x0ff;
1282 where
[6] = r_symbolnum
& 0x0ff;
1283 where
[7] = (((!S_IS_DEFINED (fixP
->fx_addsy
)) << 7) & 0x80) | (0 & 0x60) | (fixP
->fx_r_type
& 0x1F);
1286 md_number_to_chars (&where
[8], fixP
->fx_addnumber
, 4);
1289 #endif /* OBJ_AOUT */
1291 const char *md_shortopts
= "";
1293 struct option md_longopts
[] =
1295 { NULL
, no_argument
, NULL
, 0 }
1297 size_t md_longopts_size
= sizeof (md_longopts
);
1300 md_parse_option (c
, arg
)
1301 int c ATTRIBUTE_UNUSED
;
1302 char * arg ATTRIBUTE_UNUSED
;
1308 md_show_usage (stream
)
1309 FILE * stream ATTRIBUTE_UNUSED
;
1313 /* This is called when a line is unrecognized. This is used to handle
1314 definitions of or32 style local labels. */
1317 or32_unrecognized_line (c
)
1324 || ! ISDIGIT ((unsigned char) input_line_pointer
[0]))
1327 s
= input_line_pointer
;
1330 while (ISDIGIT ((unsigned char) *s
))
1332 lab
= lab
* 10 + *s
- '0';
1337 /* Not a label definition. */
1340 if (dollar_label_defined (lab
))
1342 as_bad (_("label \"$%d\" redefined"), lab
);
1346 define_dollar_label (lab
);
1347 colon (dollar_label_name (lab
, 0));
1348 input_line_pointer
= s
+ 1;
1353 #ifndef BFD_ASSEMBLER
1354 /* Record a fixup for a cons expression. */
1357 or32_cons_fix_new (frag, where, nbytes, exp)
1363 fix_new_exp (frag, where, nbytes, exp, 0,
1364 nbytes == 5 ? RELOC_32
1365 : nbytes == 2 ? RELOC_16
1369 tc_aout_pre_write_hook ()
1372 printf ("In tc_aout_pre_write_hook()\n");
1378 /* Default the values of symbols known that should be "predefined". We
1379 don't bother to predefine them unless you actually use one, since there
1380 are a lot of them. */
1383 md_undefined_symbol (name
)
1384 char *name ATTRIBUTE_UNUSED
;
1386 #ifndef BFD_ASSEMBLER
1388 char testbuf
[5 + /*SLOP*/ 5];
1391 printf ("md_undefined_symbol(%s)\n", name
);
1394 /* Register name. */
1395 if (name
[0] == 'r' || name
[0] == 'R' || name
[0] == 'a' || name
[0] == 'b')
1397 /* Parse the number, make sure it has no extra zeroes or
1399 regnum
= atol (& name
[1]);
1402 as_fatal (_("register out of range"));
1404 sprintf (testbuf
, "%ld", regnum
);
1406 if (strcmp (testbuf
, &name
[1]) != 0)
1407 return NULL
; /* gr007 or lr7foo or whatever. */
1409 /* We have a wiener! Define and return a new symbol for it. */
1410 return (symbol_new (name
, SEG_REGISTER
, (valueT
) regnum
,
1411 &zero_address_frag
));
1417 /* Parse an operand that is machine-specific. */
1420 md_operand (expressionP
)
1421 expressionS
*expressionP
;
1424 printf (" md_operand(input_line_pointer = %s)\n", input_line_pointer
);
1427 if (input_line_pointer
[0] == REGISTER_PREFIX
&& input_line_pointer
[1] == 'r')
1429 /* We have a numeric register expression. No biggy. */
1430 input_line_pointer
+= 2; /* Skip %r */
1431 (void) expression (expressionP
);
1433 if (expressionP
->X_op
!= O_constant
1434 || expressionP
->X_add_number
> 255)
1435 as_bad (_("Invalid expression after %%%%\n"));
1436 expressionP
->X_op
= O_register
;
1438 else if (input_line_pointer
[0] == '&')
1440 /* We are taking the 'address' of a register...this one is not
1441 in the manual, but it *is* in traps/fpsymbol.h! What they
1442 seem to want is the register number, as an absolute number. */
1443 input_line_pointer
++; /* Skip & */
1444 (void) expression (expressionP
);
1446 if (expressionP
->X_op
!= O_register
)
1447 as_bad (_("invalid register in & expression"));
1449 expressionP
->X_op
= O_constant
;
1451 else if (input_line_pointer
[0] == '$'
1452 && ISDIGIT ((unsigned char) input_line_pointer
[1]))
1458 /* This is a local label. */
1459 ++input_line_pointer
;
1460 lab
= (long) get_absolute_expression ();
1462 if (dollar_label_defined (lab
))
1464 name
= dollar_label_name (lab
, 0);
1465 sym
= symbol_find (name
);
1469 name
= dollar_label_name (lab
, 1);
1470 sym
= symbol_find_or_make (name
);
1473 expressionP
->X_op
= O_symbol
;
1474 expressionP
->X_add_symbol
= sym
;
1475 expressionP
->X_add_number
= 0;
1477 else if (input_line_pointer
[0] == '$')
1481 int fieldnum
, fieldlimit
;
1482 LITTLENUM_TYPE floatbuf
[8];
1484 /* $float(), $doubleN(), or $extendN() convert floating values
1486 s
= input_line_pointer
;
1491 if (strncmp (s
, "double", sizeof "double" - 1) == 0)
1493 s
+= sizeof "double" - 1;
1497 else if (strncmp (s
, "float", sizeof "float" - 1) == 0)
1499 s
+= sizeof "float" - 1;
1503 else if (strncmp (s
, "extend", sizeof "extend" - 1) == 0)
1505 s
+= sizeof "extend" - 1;
1514 fieldnum
= *s
- '0';
1517 if (fieldnum
>= fieldlimit
)
1526 s
= atof_ieee (s
, type
, floatbuf
);
1537 input_line_pointer
= s
;
1538 expressionP
->X_op
= O_constant
;
1539 expressionP
->X_unsigned
= 1;
1540 expressionP
->X_add_number
= ((floatbuf
[fieldnum
* 2]
1541 << LITTLENUM_NUMBER_OF_BITS
)
1542 + floatbuf
[fieldnum
* 2 + 1]);
1546 /* Round up a section size to the appropriate boundary. */
1549 md_section_align (segment
, size
)
1550 segT segment ATTRIBUTE_UNUSED
;
1551 valueT size ATTRIBUTE_UNUSED
;
1553 return size
; /* Byte alignment is fine. */
1556 /* Exactly what point is a PC-relative offset relative TO?
1557 On the 29000, they're relative to the address of the instruction,
1558 which we have set up as the address of the fixup too. */
1561 md_pcrel_from (fixP
)
1564 return fixP
->fx_where
+ fixP
->fx_frag
->fr_address
;
1567 /* Generate a reloc for a fixup. */
1569 #ifdef BFD_ASSEMBLER
1571 tc_gen_reloc (seg
, fixp
)
1572 asection
*seg ATTRIBUTE_UNUSED
;
1577 reloc
= (arelent
*) xmalloc (sizeof (arelent
));
1578 reloc
->sym_ptr_ptr
= (asymbol
**) xmalloc (sizeof (asymbol
*));
1579 *reloc
->sym_ptr_ptr
= symbol_get_bfdsym (fixp
->fx_addsy
);
1580 reloc
->address
= fixp
->fx_frag
->fr_address
+ fixp
->fx_where
;
1581 /* reloc->address = fixp->fx_frag->fr_address + fixp->fx_where + fixp->fx_addnumber;*/
1582 reloc
->howto
= bfd_reloc_type_lookup (stdoutput
, fixp
->fx_r_type
);
1584 if (reloc
->howto
== (reloc_howto_type
*) NULL
)
1586 as_bad_where (fixp
->fx_file
, fixp
->fx_line
,
1587 _("reloc %d not supported by object file format"),
1588 (int) fixp
->fx_r_type
);
1592 if (fixp
->fx_r_type
== BFD_RELOC_VTABLE_ENTRY
)
1593 reloc
->address
= fixp
->fx_offset
;
1595 reloc
->addend
= fixp
->fx_addnumber
;