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));
121 static char * parse_operand PARAMS ((char *, expressionS *, int));
124 /* Set bits in machine opcode according to insn->encoding
125 description and passed operand. */
128 encode (insn, opcode, param_val, param_ch)
129 const struct machine_opcode *insn;
130 unsigned long *opcode;
131 signed long param_val;
139 printf (" encode: opcode=%.8lx param_val=%.8lx abs=%.8lx param_ch=%c\n",
140 *opcode, param_val, abs (param_val), param_ch);
142 for (enc = insn->encoding; *enc != '\0'; enc++)
143 if (*enc == param_ch)
145 if (enc - 2 >= insn->encoding && (*(enc - 2) == '0') && (*(enc - 1) == 'x'))
153 for (enc = insn->encoding; *enc != '\0';)
155 if ((*enc == '0') && (*(enc + 1) == 'x'))
157 int tmp = strtol (enc, NULL, 16);
160 *opcode |= tmp << opc_pos;
163 else if ((*enc == '0') || (*enc == '-'))
168 else if (*enc == '1')
171 *opcode |= 1 << opc_pos;
174 else if (*enc == param_ch)
178 *opcode |= ((param_val >> param_pos) & 0x1) << opc_pos;
181 else if (ISALPHA (*enc))
191 printf (" opcode=%.8lx\n", *opcode);
195 /* This function is called once, at assembler startup time. It should
196 set up all the tables, etc., that the MD part of the assembler will
202 const char *retval = NULL;
207 /* Hash up all the opcodes for fast use later. */
208 op_hash = hash_new ();
210 for (i = 0; i < or32_num_opcodes; i++)
212 const char *name = machine_opcodes[i].name;
220 retval = hash_insert (op_hash, name, (PTR) &machine_opcodes[i]);
223 fprintf (stderr, "internal error: can't hash `%s': %s\n",
224 machine_opcodes[i].name, retval);
230 as_fatal (_("Broken assembler. No assembly attempted."));
232 encode (&machine_opcodes[insn_index ("l.jalr")], &jalr_r9_opcode, 9, 'B');
235 /* Returs non zero if instruction is to be used. */
238 check_invalid_opcode (opcode)
239 unsigned long opcode;
241 return opcode == jalr_r9_opcode;
244 /* Assemble a single instruction. Its label has already been handled
245 by the generic front end. We just parse opcode and operands, and
246 produce the bytes of data and relocation. */
255 printf ("NEW INSTRUCTION\n");
262 /* Put out the opcode. */
263 md_number_to_chars (toP, the_insn.opcode, 4);
265 /* Put out the symbol-dependent stuff. */
267 if (the_insn.reloc != BFD_RELOC_NONE)
269 if (the_insn.reloc != NO_RELOC)
272 fix_new_exp (frag_now,
273 (toP - frag_now->fr_literal + the_insn.reloc_offset),
281 /* This is true of the we have issued a "lo(" or "hi"(. */
282 static int waiting_for_shift = 0;
284 static int mask_or_shift = 0;
288 parse_operand (s, operandp, opt)
290 expressionS *operandp;
293 char *save = input_line_pointer;
297 printf (" PROCESS NEW OPERAND(%s) == %c (%d)\n", s, opt ? opt : '!', opt);
300 input_line_pointer = s;
302 if (strncasecmp (s, "HI(", 3) == 0)
304 waiting_for_shift = 1;
305 mask_or_shift = BFD_RELOC_HI16;
307 input_line_pointer += 3;
309 else if (strncasecmp (s, "LO(", 3) == 0)
311 mask_or_shift = BFD_RELOC_LO16;
313 input_line_pointer += 3;
318 if ((*s == '(') && (*(s+1) == 'r'))
321 if ((*s == 'r') && ISDIGIT (*(s + 1)))
323 operandp->X_add_number = strtol (s + 1, NULL, 10);
324 operandp->X_op = O_register;
325 for (; (*s != ',') && (*s != '\0');)
327 input_line_pointer = save;
331 expression (operandp);
333 if (operandp->X_op == O_absent)
336 as_bad (_("missing operand"));
339 operandp->X_add_number = 0;
340 operandp->X_op = O_constant;
344 new = input_line_pointer;
345 input_line_pointer = save;
348 printf (" %s=parse_operand(%s): operandp->X_op = %u\n", new, s, operandp->X_op);
356 parse_operand (s, operandp, opt)
358 expressionS *operandp;
361 char *save = input_line_pointer;
365 printf (" PROCESS NEW OPERAND(%s) == %c (%d)\n", s, opt ? opt : '!', opt);
368 input_line_pointer = s;
370 if (strncasecmp (s, "HI(", 3) == 0)
372 waiting_for_shift = 1;
373 mask_or_shift = RELOC_CONSTH;
375 input_line_pointer += 3;
377 else if (strncasecmp (s, "LO(", 3) == 0)
379 mask_or_shift = RELOC_CONST;
381 input_line_pointer += 3;
387 expression (operandp);
389 if (operandp->X_op == O_absent)
392 as_bad (_("missing operand"));
395 operandp->X_add_number = 0;
396 operandp->X_op = O_constant;
400 new = input_line_pointer;
401 input_line_pointer = save;
403 if ((operandp->X_op == O_symbol) && (*s != '_'))
406 printf ("symbol: '%s'\n", save);
409 for (save = s; s < new; s++)
410 if ((*s == REGISTER_PREFIX) && (*(s + 1) == 'r')) /* Register prefix. */
413 if ((*s == 'r') && ISDIGIT (*(s + 1)))
415 operandp->X_add_number = strtol (s + 1, NULL, 10);
416 operandp->X_op = O_register;
422 printf (" %s=parse_operand(%s): operandp->X_op = %u\n", new, s, operandp->X_op);
429 /* Instruction parsing. Takes a string containing the opcode.
430 Operands are at input_line_pointer. Output is in the_insn.
431 Warnings or errors are generated. */
440 const struct machine_opcode *insn;
442 unsigned long opcode;
443 expressionS the_operand;
444 expressionS *operand = &the_operand;
446 int reloc = BFD_RELOC_NONE;
449 printf ("machine_ip(%s)\n", str);
453 for (; ISALNUM (*s) || *s == '.'; ++s)
462 case ' ': /* FIXME-SOMEDAY more whitespace. */
467 as_bad (_("unknown opcode1: `%s'"), str);
471 if ((insn = (struct machine_opcode *) hash_find (op_hash, str)) == NULL)
473 as_bad (_("unknown opcode2 `%s'."), str);
479 memset (&the_insn, '\0', sizeof (the_insn));
480 the_insn.reloc = BFD_RELOC_NONE;
482 reloc = BFD_RELOC_NONE;
484 /* Build the opcode, checking as we go to make sure that the
487 If an operand matches, we modify the_insn or opcode appropriately,
488 and do a "continue". If an operand fails to match, we "break". */
489 if (insn->args[0] != '\0')
491 /* Prime the pump. */
492 s = parse_operand (s, operand, insn->args[0] == 'I');
495 for (args = insn->args;; ++args)
498 printf (" args = %s\n", args);
502 case '\0': /* End of args. */
503 /* We have have 0 args, do the bazoooka! */
504 if (args == insn->args)
505 encode (insn, &opcode, 0, 0);
509 /* We are truly done. */
510 the_insn.opcode = opcode;
511 if (check_invalid_opcode (opcode))
512 as_bad (_("instruction not allowed: %s"), str);
515 as_bad (_("too many operands: %s"), s);
518 case ',': /* Must match a comma. */
521 reloc = BFD_RELOC_NONE;
523 /* Parse next operand. */
524 s = parse_operand (s, operand, args[1] == 'I');
526 printf (" ',' case: operand->X_add_number = %d, *args = %s, *s = %s\n",
527 operand->X_add_number, args, s);
533 case '(': /* Must match a (. */
534 s = parse_operand (s, operand, args[1] == 'I');
537 case ')': /* Must match a ). */
540 case 'r': /* A general register. */
543 if (operand->X_op != O_register)
544 break; /* Only registers. */
546 know (operand->X_add_symbol == 0);
547 know (operand->X_op_symbol == 0);
548 regno = operand->X_add_number;
549 encode (insn, &opcode, regno, *args);
551 printf (" r: operand->X_op = %d\n", operand->X_op);
556 /* if (! ISALPHA (*args))
557 break; */ /* Only immediate values. */
562 printf ("mask_or_shift = %d\n", mask_or_shift);
564 reloc = mask_or_shift;
568 if (strncasecmp (args, "LO(", 3) == 0)
571 printf ("reloc_const\n");
573 reloc = BFD_RELOC_LO16;
575 else if (strncasecmp (args, "HI(", 3) == 0)
578 printf ("reloc_consth\n");
580 reloc = BFD_RELOC_HI16;
585 operand->X_op = O_constant;
587 operand->X_add_number = 0; /* ??? if enabled load/store offsets
594 printf (" default case: operand->X_add_number = %d, *args = %s, *s = %s\n", operand->X_add_number, args, s);
596 if (operand->X_op == O_constant)
598 if (reloc == BFD_RELOC_NONE)
603 v = abs (operand->X_add_number) & ~ mask;
605 as_bad (_("call/jmp target out of range (1)"));
608 if (reloc == BFD_RELOC_HI16)
609 operand->X_add_number = ((operand->X_add_number >> 16) & 0xffff);
612 encode (insn, &opcode, operand->X_add_number, *args);
613 /* the_insn.reloc = BFD_RELOC_NONE; */
617 if (reloc == BFD_RELOC_NONE)
618 the_insn.reloc = BFD_RELOC_32_GOT_PCREL;
620 the_insn.reloc = reloc;
622 /* the_insn.reloc = insn->reloc; */
624 printf (" reloc sym=%d\n", the_insn.reloc);
625 printf (" BFD_RELOC_NONE=%d\n", BFD_RELOC_NONE);
627 the_insn.exp = *operand;
629 /* the_insn.reloc_offset = 1; */
630 the_insn.pcrel = 1; /* Assume PC-relative jump. */
632 /* FIXME-SOON, Do we figure out whether abs later, after
634 if (reloc == BFD_RELOC_LO16 || reloc == BFD_RELOC_HI16)
637 encode (insn, &opcode, operand->X_add_number, *args);
641 /* Types or values of args don't match. */
642 as_bad (_("invalid operands"));
655 const struct machine_opcode *insn;
657 unsigned long opcode;
658 expressionS the_operand;
659 expressionS *operand = &the_operand;
661 int reloc = NO_RELOC;
664 printf ("machine_ip(%s)\n", str);
668 for (; ISALNUM (*s) || *s == '.'; ++s)
677 case ' ': /* FIXME-SOMEDAY more whitespace. */
682 as_bad (_("unknown opcode1: `%s'"), str);
686 if ((insn = (struct machine_opcode *) hash_find (op_hash, str)) == NULL)
688 as_bad (_("unknown opcode2 `%s'."), str);
694 memset (&the_insn, '\0', sizeof (the_insn));
695 the_insn.reloc = NO_RELOC;
699 /* Build the opcode, checking as we go to make sure that the
702 If an operand matches, we modify the_insn or opcode appropriately,
703 and do a "continue". If an operand fails to match, we "break". */
704 if (insn->args[0] != '\0')
705 /* Prime the pump. */
706 s = parse_operand (s, operand,
708 || strcmp (insn->name, "l.nop") == 0);
710 for (args = insn->args;; ++args)
713 printf (" args = %s\n", args);
717 case '\0': /* End of args. */
718 /* We have have 0 args, do the bazoooka! */
719 if (args == insn->args)
720 encode (insn, &opcode, 0, 0);
724 /* We are truly done. */
725 the_insn.opcode = opcode;
726 if (check_invalid_opcode (opcode))
727 as_bad (_("instruction not allowed: %s"), str);
730 as_bad (_("too many operands: %s"), s);
733 case ',': /* Must match a comma. */
738 /* Parse next operand. */
739 s = parse_operand (s, operand, args[1] == 'I');
741 printf (" ',' case: operand->X_add_number = %d, *args = %s, *s = %s\n",
742 operand->X_add_number, args, s);
748 case '(': /* Must match a (. */
749 s = parse_operand (s, operand, args[1] == 'I');
752 case ')': /* Must match a ). */
755 case 'r': /* A general register. */
758 if (operand->X_op != O_register)
759 break; /* Only registers. */
761 know (operand->X_add_symbol == 0);
762 know (operand->X_op_symbol == 0);
763 regno = operand->X_add_number;
764 encode (insn, &opcode, regno, *args);
766 printf (" r: operand->X_op = %d\n", operand->X_op);
771 /* if (! ISALPHA (*args))
772 break; */ /* Only immediate values. */
777 printf ("mask_or_shift = %d\n", mask_or_shift);
779 reloc = mask_or_shift;
783 if (strncasecmp (args, "LO(", 3) == 0)
786 printf ("reloc_const\n");
790 else if (strncasecmp (args, "HI(", 3) == 0)
793 printf ("reloc_consth\n");
795 reloc = RELOC_CONSTH;
800 operand->X_op = O_constant;
802 operand->X_add_number = 0; /* ??? if enabled load/store offsets
809 printf (" default case: operand->X_add_number = %d, *args = %s, *s = %s\n",
810 operand->X_add_number, args, s);
812 if (operand->X_op == O_constant)
814 if (reloc == NO_RELOC)
816 unsigned long v, mask;
819 v = abs (operand->X_add_number) & ~ mask;
821 as_bad (_("call/jmp target out of range (1)"));
824 if (reloc == RELOC_CONSTH)
825 operand->X_add_number = ((operand->X_add_number>>16) & 0xffff);
828 encode (insn, &opcode, operand->X_add_number, *args);
829 /* the_insn.reloc = NO_RELOC; */
833 if (reloc == NO_RELOC)
834 the_insn.reloc = RELOC_JUMPTARG;
836 the_insn.reloc = reloc;
838 printf (" reloc sym=%d\n", the_insn.reloc);
839 printf (" NO_RELOC=%d\n", NO_RELOC);
841 the_insn.exp = *operand;
843 /* the_insn.reloc_offset = 1; */
844 the_insn.pcrel = 1; /* Assume PC-relative jump. */
846 /* FIXME-SOON, Do we figure out whether abs later, after
848 if (reloc == RELOC_CONST || reloc == RELOC_CONSTH)
851 encode (insn, &opcode, operand->X_add_number, *args);
855 /* Types or values of args don't match. */
856 as_bad (_("invalid operands"));
862 /* This is identical to the md_atof in m68k.c. I think this is right,
865 Turn a string in input_line_pointer into a floating point constant
866 of type type, and store the appropriate bytes in *litP. The number
867 of LITTLENUMS emitted is stored in *sizeP . An error message is
868 returned, or NULL on OK. */
870 /* Equal to MAX_PRECISION in atof-ieee.c. */
871 #define MAX_LITTLENUMS 6
874 md_atof (type, litP, sizeP)
880 LITTLENUM_TYPE words[MAX_LITTLENUMS];
881 LITTLENUM_TYPE *wordP;
912 return _("Bad call to MD_ATOF()");
915 t = atof_ieee (input_line_pointer, type, words);
917 input_line_pointer = t;
919 *sizeP = prec * sizeof (LITTLENUM_TYPE);
921 for (wordP = words; prec--;)
923 md_number_to_chars (litP, (valueT) (*wordP++), sizeof (LITTLENUM_TYPE));
924 litP += sizeof (LITTLENUM_TYPE);
930 /* Write out big-endian. */
933 md_number_to_chars (buf, val, n)
938 number_to_chars_bigendian (buf, val, n);
943 md_apply_fix3 (fixP, val, seg)
946 segT seg ATTRIBUTE_UNUSED;
948 char *buf = fixP->fx_where + fixP->fx_frag->fr_literal;
954 printf ("md_apply_fix val:%x\n", t_val);
957 fixP->fx_addnumber = t_val; /* Remember value for emit_reloc. */
959 know (fixP->fx_size == 4);
960 know (fixP->fx_r_type < BFD_RELOC_NONE);
962 switch (fixP->fx_r_type)
964 case BFD_RELOC_32: /* XXXXXXXX pattern in a word. */
966 printf ("reloc_const: val=%x\n", t_val);
968 buf[0] = t_val >> 24;
969 buf[1] = t_val >> 16;
974 case BFD_RELOC_16: /* XXXX0000 pattern in a word. */
976 printf ("reloc_const: val=%x\n", t_val);
982 case BFD_RELOC_8: /* XX000000 pattern in a word. */
984 printf ("reloc_const: val=%x\n", t_val);
989 case BFD_RELOC_LO16: /* 0000XXXX pattern in a word. */
991 printf ("reloc_const: val=%x\n", t_val);
993 buf[2] = t_val >> 8; /* Holds bits 0000XXXX. */
997 case BFD_RELOC_HI16: /* 0000XXXX pattern in a word. */
999 printf ("reloc_consth: val=%x\n", t_val);
1001 buf[2] = t_val >> 24; /* Holds bits XXXX0000. */
1002 buf[3] = t_val >> 16;
1005 case BFD_RELOC_32_GOT_PCREL: /* 0000XXXX pattern in a word. */
1008 /* The linker tries to support both AMD and old GNU style
1009 R_IREL relocs. That means that if the addend is exactly
1010 the negative of the address within the section, the
1011 linker will not handle it correctly. */
1015 && t_val == - (fixP->fx_frag->fr_address + fixP->fx_where))
1017 (fixP->fx_file, fixP->fx_line,
1018 _("the linker will not handle this relocation correctly (1)"));
1021 else if (fixP->fx_pcrel)
1023 long v = t_val >> 28;
1025 if (v != 0 && v != -1)
1026 as_bad_where (fixP->fx_file, fixP->fx_line,
1027 _("call/jmp target out of range (2)"));
1030 /* This case was supposed to be handled in machine_ip. */
1033 buf[0] |= (t_val >> 26) & 0x03; /* Holds bits 0FFFFFFC of address. */
1034 buf[1] = t_val >> 18;
1035 buf[2] = t_val >> 10;
1036 buf[3] = t_val >> 2;
1039 case BFD_RELOC_VTABLE_INHERIT:
1040 case BFD_RELOC_VTABLE_ENTRY:
1044 case BFD_RELOC_NONE:
1046 as_bad (_("bad relocation type: 0x%02x"), fixP->fx_r_type);
1050 if (fixP->fx_addsy == (symbolS *) NULL)
1055 md_apply_fix3 (fixP, valP, seg)
1058 segT seg ATTRIBUTE_UNUSED;
1060 long val = *(long*)valP;
1061 char *buf = fixP->fx_where + fixP->fx_frag->fr_literal;
1064 printf ("md_apply_fix val:%x\n", val);
1067 fixP->fx_addnumber = val; /* Remember value for emit_reloc. */
1069 know (fixP->fx_size == 4);
1070 know (fixP->fx_r_type < NO_RELOC);
1072 /* This is a hack. There should be a better way to handle this. */
1073 if (fixP->fx_r_type == RELOC_WDISP30 && fixP->fx_addsy)
1074 val += fixP->fx_where + fixP->fx_frag->fr_address;
1076 switch (fixP->fx_r_type)
1090 val = (val >>= 2) + 1;
1091 buf[0] |= (val >> 24) & 0x3f;
1092 buf[1] = (val >> 16);
1098 buf[1] |= (val >> 26) & 0x3f;
1104 buf[2] |= (val >> 8) & 0x03;
1109 buf[2] |= (val >> 8) & 0x1f;
1114 val = (val >>= 2) + 1;
1117 buf[1] |= (val >> 16) & 0x3f;
1122 case RELOC_JUMPTARG: /* 0000XXXX pattern in a word. */
1125 /* The linker tries to support both AMD and old GNU style
1126 R_IREL relocs. That means that if the addend is exactly
1127 the negative of the address within the section, the
1128 linker will not handle it correctly. */
1132 && val == - (fixP->fx_frag->fr_address + fixP->fx_where))
1134 (fixP->fx_file, fixP->fx_line,
1135 _("the linker will not handle this relocation correctly (1)"));
1138 else if (fixP->fx_pcrel)
1142 if (v != 0 && v != -1)
1143 as_bad_where (fixP->fx_file, fixP->fx_line,
1144 _("call/jmp target out of range (2)"));
1148 /* This case was supposed to be handled in machine_ip. */
1151 buf[0] |= (val >> 26) & 0x03; /* Holds bits 0FFFFFFC of address. */
1157 case RELOC_CONST: /* 0000XXXX pattern in a word. */
1159 printf ("reloc_const: val=%x\n", val);
1161 buf[2] = val >> 8; /* Holds bits 0000XXXX. */
1165 case RELOC_CONSTH: /* 0000XXXX pattern in a word. */
1167 printf ("reloc_consth: val=%x\n", val);
1169 buf[2] = val >> 24; /* Holds bits XXXX0000. */
1173 case BFD_RELOC_VTABLE_INHERIT:
1174 case BFD_RELOC_VTABLE_ENTRY:
1180 as_bad (_("bad relocation type: 0x%02x"), fixP->fx_r_type);
1184 if (fixP->fx_addsy == (symbolS *) NULL)
1191 tc_coff_fix2rtype (fixP)
1195 printf ("tc_coff_fix2rtype\n");
1198 switch (fixP->fx_r_type)
1208 case RELOC_JUMPTARG:
1211 printf ("need %d\n", fixP->fx_r_type);
1218 #endif /* OBJ_COFF */
1220 /* Should never be called for or32. */
1223 md_create_short_jump (ptr, from_addr, to_addr, frag, to_symbol)
1224 char * ptr ATTRIBUTE_UNUSED;
1225 addressT from_addr ATTRIBUTE_UNUSED;
1226 addressT to_addr ATTRIBUTE_UNUSED;
1227 fragS * frag ATTRIBUTE_UNUSED;
1228 symbolS * to_symbol ATTRIBUTE_UNUSED;
1230 as_fatal ("or32_create_short_jmp\n");
1233 /* Should never be called for or32. */
1235 #ifndef BFD_ASSEMBLER
1237 md_convert_frag (headers, seg, fragP)
1238 object_headers * headers ATTRIBUTE_UNUSED;
1239 segT seg ATTRIBUTE_UNUSED;
1240 register fragS * fragP ATTRIBUTE_UNUSED;
1242 as_fatal ("or32_convert_frag\n");
1247 md_convert_frag (headers, seg, fragP)
1248 bfd * headers ATTRIBUTE_UNUSED;
1249 segT seg ATTRIBUTE_UNUSED;
1250 fragS * fragP ATTRIBUTE_UNUSED;
1252 as_fatal ("or32_convert_frag\n");
1256 /* Should never be called for or32. */
1259 md_create_long_jump (ptr, from_addr, to_addr, frag, to_symbol)
1260 char * ptr ATTRIBUTE_UNUSED;
1261 addressT from_addr ATTRIBUTE_UNUSED;
1262 addressT to_addr ATTRIBUTE_UNUSED;
1263 fragS * frag ATTRIBUTE_UNUSED;
1264 symbolS * to_symbol ATTRIBUTE_UNUSED;
1266 as_fatal ("or32_create_long_jump\n");
1269 /* Should never be called for or32. */
1272 md_estimate_size_before_relax (fragP, segtype)
1273 fragS * fragP ATTRIBUTE_UNUSED;
1274 segT segtype ATTRIBUTE_UNUSED;
1276 as_fatal ("or32_estimate_size_before_relax\n");
1280 /* Translate internal representation of relocation info to target format.
1282 On sparc/29k: first 4 bytes are normal unsigned long address, next three
1283 bytes are index, most sig. byte first. Byte 7 is broken up with
1284 bit 7 as external, bits 6 & 5 unused, and the lower
1285 five bits as relocation type. Next 4 bytes are long addend. */
1286 /* Thanx and a tip of the hat to Michael Bloom, mb@ttidca.tti.com. */
1290 tc_aout_fix_to_chars (where, fixP, segment_address_in_file)
1293 relax_addressT segment_address_in_file;
1298 printf ("tc_aout_fix_to_chars\n");
1301 know (fixP->fx_r_type < BFD_RELOC_NONE);
1302 know (fixP->fx_addsy != NULL);
1306 fixP->fx_frag->fr_address + fixP->fx_where - segment_address_in_file,
1309 r_symbolnum = (S_IS_DEFINED (fixP->fx_addsy)
1310 ? S_GET_TYPE (fixP->fx_addsy)
1311 : fixP->fx_addsy->sy_number);
1313 where[4] = (r_symbolnum >> 16) & 0x0ff;
1314 where[5] = (r_symbolnum >> 8) & 0x0ff;
1315 where[6] = r_symbolnum & 0x0ff;
1316 where[7] = (((!S_IS_DEFINED (fixP->fx_addsy)) << 7) & 0x80) | (0 & 0x60) | (fixP->fx_r_type & 0x1F);
1319 md_number_to_chars (&where[8], fixP->fx_addnumber, 4);
1322 #endif /* OBJ_AOUT */
1324 const char *md_shortopts = "";
1326 struct option md_longopts[] =
1328 { NULL, no_argument, NULL, 0 }
1330 size_t md_longopts_size = sizeof (md_longopts);
1333 md_parse_option (c, arg)
1334 int c ATTRIBUTE_UNUSED;
1335 char * arg ATTRIBUTE_UNUSED;
1341 md_show_usage (stream)
1342 FILE * stream ATTRIBUTE_UNUSED;
1346 /* This is called when a line is unrecognized. This is used to handle
1347 definitions of or32 style local labels. */
1350 or32_unrecognized_line (c)
1357 || ! ISDIGIT ((unsigned char) input_line_pointer[0]))
1360 s = input_line_pointer;
1363 while (ISDIGIT ((unsigned char) *s))
1365 lab = lab * 10 + *s - '0';
1370 /* Not a label definition. */
1373 if (dollar_label_defined (lab))
1375 as_bad (_("label \"$%d\" redefined"), lab);
1379 define_dollar_label (lab);
1380 colon (dollar_label_name (lab, 0));
1381 input_line_pointer = s + 1;
1386 #ifndef BFD_ASSEMBLER
1387 /* Record a fixup for a cons expression. */
1390 or32_cons_fix_new (frag, where, nbytes, exp)
1396 fix_new_exp (frag, where, nbytes, exp, 0,
1397 nbytes == 5 ? RELOC_32
1398 : nbytes == 2 ? RELOC_16
1402 tc_aout_pre_write_hook ()
1405 printf ("In tc_aout_pre_write_hook()\n");
1411 /* Default the values of symbols known that should be "predefined". We
1412 don't bother to predefine them unless you actually use one, since there
1413 are a lot of them. */
1416 md_undefined_symbol (name)
1417 char *name ATTRIBUTE_UNUSED;
1419 #ifndef BFD_ASSEMBLER
1421 char testbuf[5 + /*SLOP*/ 5];
1424 printf ("md_undefined_symbol(%s)\n", name);
1427 /* Register name. */
1428 if (name[0] == 'r' || name[0] == 'R' || name[0] == 'a' || name[0] == 'b')
1432 /* Parse the number, make sure it has no extra zeroes or
1434 regnum = atol (& name[1]);
1437 as_fatal (_("register out of range"));
1439 sprintf (testbuf, "%ld", regnum);
1441 if (strcmp (testbuf, &name[1]) != 0)
1442 return NULL; /* gr007 or lr7foo or whatever. */
1444 /* We have a wiener! Define and return a new symbol for it. */
1445 return (symbol_new (name, SEG_REGISTER, (valueT) regnum,
1446 &zero_address_frag));
1452 /* Parse an operand that is machine-specific. */
1455 md_operand (expressionP)
1456 expressionS *expressionP;
1459 printf (" md_operand(input_line_pointer = %s)\n", input_line_pointer);
1462 if (input_line_pointer[0] == REGISTER_PREFIX && input_line_pointer[1] == 'r')
1464 /* We have a numeric register expression. No biggy. */
1465 input_line_pointer += 2; /* Skip %r */
1466 (void) expression (expressionP);
1468 if (expressionP->X_op != O_constant
1469 || expressionP->X_add_number > 255)
1470 as_bad (_("Invalid expression after %%%%\n"));
1471 expressionP->X_op = O_register;
1473 else if (input_line_pointer[0] == '&')
1475 /* We are taking the 'address' of a register...this one is not
1476 in the manual, but it *is* in traps/fpsymbol.h! What they
1477 seem to want is the register number, as an absolute number. */
1478 input_line_pointer++; /* Skip & */
1479 (void) expression (expressionP);
1481 if (expressionP->X_op != O_register)
1482 as_bad (_("invalid register in & expression"));
1484 expressionP->X_op = O_constant;
1486 else if (input_line_pointer[0] == '$'
1487 && ISDIGIT ((unsigned char) input_line_pointer[1]))
1493 /* This is a local label. */
1494 ++input_line_pointer;
1495 lab = (long) get_absolute_expression ();
1497 if (dollar_label_defined (lab))
1499 name = dollar_label_name (lab, 0);
1500 sym = symbol_find (name);
1504 name = dollar_label_name (lab, 1);
1505 sym = symbol_find_or_make (name);
1508 expressionP->X_op = O_symbol;
1509 expressionP->X_add_symbol = sym;
1510 expressionP->X_add_number = 0;
1512 else if (input_line_pointer[0] == '$')
1516 int fieldnum, fieldlimit;
1517 LITTLENUM_TYPE floatbuf[8];
1519 /* $float(), $doubleN(), or $extendN() convert floating values
1521 s = input_line_pointer;
1526 if (strncmp (s, "double", sizeof "double" - 1) == 0)
1528 s += sizeof "double" - 1;
1532 else if (strncmp (s, "float", sizeof "float" - 1) == 0)
1534 s += sizeof "float" - 1;
1538 else if (strncmp (s, "extend", sizeof "extend" - 1) == 0)
1540 s += sizeof "extend" - 1;
1549 fieldnum = *s - '0';
1552 if (fieldnum >= fieldlimit)
1561 s = atof_ieee (s, type, floatbuf);
1572 input_line_pointer = s;
1573 expressionP->X_op = O_constant;
1574 expressionP->X_unsigned = 1;
1575 expressionP->X_add_number = ((floatbuf[fieldnum * 2]
1576 << LITTLENUM_NUMBER_OF_BITS)
1577 + floatbuf[fieldnum * 2 + 1]);
1581 /* Round up a section size to the appropriate boundary. */
1584 md_section_align (segment, size)
1585 segT segment ATTRIBUTE_UNUSED;
1586 valueT size ATTRIBUTE_UNUSED;
1588 return size; /* Byte alignment is fine. */
1591 /* Exactly what point is a PC-relative offset relative TO?
1592 On the 29000, they're relative to the address of the instruction,
1593 which we have set up as the address of the fixup too. */
1596 md_pcrel_from (fixP)
1599 return fixP->fx_where + fixP->fx_frag->fr_address;
1602 /* Generate a reloc for a fixup. */
1604 #ifdef BFD_ASSEMBLER
1606 tc_gen_reloc (seg, fixp)
1607 asection *seg ATTRIBUTE_UNUSED;
1612 reloc = (arelent *) xmalloc (sizeof (arelent));
1613 reloc->sym_ptr_ptr = (asymbol **) xmalloc (sizeof (asymbol *));
1614 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
1615 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
1616 /* reloc->address = fixp->fx_frag->fr_address + fixp->fx_where + fixp->fx_addnumber;*/
1617 reloc->howto = bfd_reloc_type_lookup (stdoutput, fixp->fx_r_type);
1619 if (reloc->howto == (reloc_howto_type *) NULL)
1621 as_bad_where (fixp->fx_file, fixp->fx_line,
1622 _("reloc %d not supported by object file format"),
1623 (int) fixp->fx_r_type);
1627 if ( fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY
1628 || fixp->fx_r_type == BFD_RELOC_VTABLE_INHERIT)
1629 reloc->addend = fixp->fx_offset;
1631 reloc->addend = fixp->fx_addnumber;