Set OSABI field back to 0 (SysV), to avoid interoperability problems
[nacl-binutils.git] / gas / config / tc-or32.c
blob3d8d39c0e0746c9a424aabec64295e1c367bcb3b
1 /* Assembly backend for the OpenRISC 1000.
2 Copyright (C) 2002, 2003, 2005, 2007
3 Free Software Foundation, Inc.
4 Contributed by Damjan Lampret <lampret@opencores.org>.
5 Modified bu Johan Rydberg, <johan.rydberg@netinsight.se>.
6 Based upon a29k port.
8 This file is part of GAS, the GNU Assembler.
10 GAS is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 3, or (at your option)
13 any later version.
15 GAS is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with GAS; see the file COPYING. If not, write to
22 the Free Software Foundation, 51 Franklin Street - Fifth Floor,
23 Boston, MA 02110-1301, USA. */
25 /* tc-a29k.c used as a template. */
27 #include "safe-ctype.h"
28 #include "as.h"
29 #include "opcode/or32.h"
30 #include "elf/or32.h"
32 #define DEBUG 0
34 #ifndef REGISTER_PREFIX
35 #define REGISTER_PREFIX '%'
36 #endif
38 /* Make it easier to clone this machine desc into another one. */
39 #define machine_opcode or32_opcode
40 #define machine_opcodes or32_opcodes
41 #define machine_ip or32_ip
42 #define machine_it or32_it
44 /* Handle of the OPCODE hash table. */
45 static struct hash_control *op_hash = NULL;
47 struct machine_it
49 char * error;
50 unsigned long opcode;
51 struct nlist * nlistp;
52 expressionS exp;
53 int pcrel;
54 int reloc_offset; /* Offset of reloc within insn. */
55 int reloc;
57 the_insn;
59 const pseudo_typeS md_pseudo_table[] =
61 {"align", s_align_bytes, 4 },
62 {"space", s_space, 0 },
63 {"cputype", s_ignore, 0 },
64 {"reg", s_lsym, 0 }, /* Register equate, same as equ. */
65 {"sect", s_ignore, 0 }, /* Creation of coff sections. */
66 {"proc", s_ignore, 0 }, /* Start of a function. */
67 {"endproc", s_ignore, 0 }, /* Function end. */
68 {"word", cons, 4 },
69 {NULL, 0, 0 },
72 int md_short_jump_size = 4;
73 int md_long_jump_size = 4;
75 /* This array holds the chars that always start a comment.
76 If the pre-processor is disabled, these aren't very useful. */
77 const char comment_chars[] = "#";
79 /* This array holds the chars that only start a comment at the beginning of
80 a line. If the line seems to have the form '# 123 filename'
81 .line and .file directives will appear in the pre-processed output. */
82 /* Note that input_file.c hand checks for '#' at the beginning of the
83 first line of the input file. This is because the compiler outputs
84 #NO_APP at the beginning of its output. */
85 /* Also note that comments like this one will always work. */
86 const char line_comment_chars[] = "#";
88 /* We needed an unused char for line separation to work around the
89 lack of macros, using sed and such. */
90 const char line_separator_chars[] = ";";
92 /* Chars that can be used to separate mant from exp in floating point nums. */
93 const char EXP_CHARS[] = "eE";
95 /* Chars that mean this number is a floating point constant.
96 As in 0f12.456
97 or 0d1.2345e12. */
98 const char FLT_CHARS[] = "rRsSfFdDxXpP";
100 /* "l.jalr r9" precalculated opcode. */
101 static unsigned long jalr_r9_opcode;
103 static void machine_ip (char *);
106 /* Set bits in machine opcode according to insn->encoding
107 description and passed operand. */
109 static void
110 encode (const struct machine_opcode *insn,
111 unsigned long *opcode,
112 signed long param_val,
113 char param_ch)
115 int opc_pos = 0;
116 int param_pos = 0;
117 char *enc;
119 #if DEBUG
120 printf (" encode: opcode=%.8lx param_val=%.8lx abs=%.8lx param_ch=%c\n",
121 *opcode, param_val, abs (param_val), param_ch);
122 #endif
123 for (enc = insn->encoding; *enc != '\0'; enc++)
124 if (*enc == param_ch)
126 if (enc - 2 >= insn->encoding && (*(enc - 2) == '0') && (*(enc - 1) == 'x'))
127 continue;
128 else
129 param_pos ++;
132 opc_pos = 32;
134 for (enc = insn->encoding; *enc != '\0';)
136 if ((*enc == '0') && (*(enc + 1) == 'x'))
138 int tmp = strtol (enc, NULL, 16);
140 opc_pos -= 4;
141 *opcode |= tmp << opc_pos;
142 enc += 3;
144 else if ((*enc == '0') || (*enc == '-'))
146 opc_pos--;
147 enc++;
149 else if (*enc == '1')
151 opc_pos--;
152 *opcode |= 1 << opc_pos;
153 enc++;
155 else if (*enc == param_ch)
157 opc_pos--;
158 param_pos--;
159 *opcode |= ((param_val >> param_pos) & 0x1) << opc_pos;
160 enc++;
162 else if (ISALPHA (*enc))
164 opc_pos--;
165 enc++;
167 else
168 enc++;
171 #if DEBUG
172 printf (" opcode=%.8lx\n", *opcode);
173 #endif
176 /* This function is called once, at assembler startup time. It should
177 set up all the tables, etc., that the MD part of the assembler will
178 need. */
180 void
181 md_begin (void)
183 const char *retval = NULL;
184 int lose = 0;
185 int skipnext = 0;
186 unsigned int i;
188 /* Hash up all the opcodes for fast use later. */
189 op_hash = hash_new ();
191 for (i = 0; i < or32_num_opcodes; i++)
193 const char *name = machine_opcodes[i].name;
195 if (skipnext)
197 skipnext = 0;
198 continue;
201 retval = hash_insert (op_hash, name, (void *) &machine_opcodes[i]);
202 if (retval != NULL)
204 fprintf (stderr, "internal error: can't hash `%s': %s\n",
205 machine_opcodes[i].name, retval);
206 lose = 1;
210 if (lose)
211 as_fatal (_("Broken assembler. No assembly attempted."));
213 encode (&machine_opcodes[insn_index ("l.jalr")], &jalr_r9_opcode, 9, 'B');
216 /* Returns non zero if instruction is to be used. */
218 static int
219 check_invalid_opcode (unsigned long opcode)
221 return opcode == jalr_r9_opcode;
224 /* Assemble a single instruction. Its label has already been handled
225 by the generic front end. We just parse opcode and operands, and
226 produce the bytes of data and relocation. */
228 void
229 md_assemble (char *str)
231 char *toP;
233 #if DEBUG
234 printf ("NEW INSTRUCTION\n");
235 #endif
237 know (str);
238 machine_ip (str);
239 toP = frag_more (4);
241 /* Put out the opcode. */
242 md_number_to_chars (toP, the_insn.opcode, 4);
244 /* Put out the symbol-dependent stuff. */
245 if (the_insn.reloc != BFD_RELOC_NONE)
247 fix_new_exp (frag_now,
248 (toP - frag_now->fr_literal + the_insn.reloc_offset),
249 4, /* size */
250 &the_insn.exp,
251 the_insn.pcrel,
252 the_insn.reloc);
256 /* This is true of the we have issued a "lo(" or "hi"(. */
257 static int waiting_for_shift = 0;
259 static int mask_or_shift = 0;
261 static char *
262 parse_operand (char *s, expressionS *operandp, int opt)
264 char *save = input_line_pointer;
265 char *new;
267 #if DEBUG
268 printf (" PROCESS NEW OPERAND(%s) == %c (%d)\n", s, opt ? opt : '!', opt);
269 #endif
271 input_line_pointer = s;
273 if (strncasecmp (s, "HI(", 3) == 0)
275 waiting_for_shift = 1;
276 mask_or_shift = BFD_RELOC_HI16;
278 input_line_pointer += 3;
280 else if (strncasecmp (s, "LO(", 3) == 0)
282 mask_or_shift = BFD_RELOC_LO16;
284 input_line_pointer += 3;
286 else
287 mask_or_shift = 0;
289 if ((*s == '(') && (*(s+1) == 'r'))
290 s++;
292 if ((*s == 'r') && ISDIGIT (*(s + 1)))
294 operandp->X_add_number = strtol (s + 1, NULL, 10);
295 operandp->X_op = O_register;
296 for (; (*s != ',') && (*s != '\0');)
297 s++;
298 input_line_pointer = save;
299 return s;
302 expression (operandp);
304 if (operandp->X_op == O_absent)
306 if (! opt)
307 as_bad (_("missing operand"));
308 else
310 operandp->X_add_number = 0;
311 operandp->X_op = O_constant;
315 new = input_line_pointer;
316 input_line_pointer = save;
318 #if DEBUG
319 printf (" %s=parse_operand(%s): operandp->X_op = %u\n", new, s, operandp->X_op);
320 #endif
322 return new;
325 /* Instruction parsing. Takes a string containing the opcode.
326 Operands are at input_line_pointer. Output is in the_insn.
327 Warnings or errors are generated. */
329 static void
330 machine_ip (char *str)
332 char *s;
333 const char *args;
334 const struct machine_opcode *insn;
335 char *argsStart;
336 unsigned long opcode;
337 expressionS the_operand;
338 expressionS *operand = &the_operand;
339 unsigned int regno;
340 int reloc = BFD_RELOC_NONE;
342 #if DEBUG
343 printf ("machine_ip(%s)\n", str);
344 #endif
346 s = str;
347 for (; ISALNUM (*s) || *s == '.'; ++s)
348 if (ISUPPER (*s))
349 *s = TOLOWER (*s);
351 switch (*s)
353 case '\0':
354 break;
356 case ' ': /* FIXME-SOMEDAY more whitespace. */
357 *s++ = '\0';
358 break;
360 default:
361 as_bad (_("unknown opcode1: `%s'"), str);
362 return;
365 if ((insn = (struct machine_opcode *) hash_find (op_hash, str)) == NULL)
367 as_bad (_("unknown opcode2 `%s'."), str);
368 return;
371 argsStart = s;
372 opcode = 0;
373 memset (&the_insn, '\0', sizeof (the_insn));
374 the_insn.reloc = BFD_RELOC_NONE;
376 reloc = BFD_RELOC_NONE;
378 /* Build the opcode, checking as we go to make sure that the
379 operands match.
381 If an operand matches, we modify the_insn or opcode appropriately,
382 and do a "continue". If an operand fails to match, we "break". */
383 if (insn->args[0] != '\0')
384 /* Prime the pump. */
385 s = parse_operand (s, operand, insn->args[0] == 'I');
387 for (args = insn->args;; ++args)
389 #if DEBUG
390 printf (" args = %s\n", args);
391 #endif
392 switch (*args)
394 case '\0': /* End of args. */
395 /* We have have 0 args, do the bazoooka! */
396 if (args == insn->args)
397 encode (insn, &opcode, 0, 0);
399 if (*s == '\0')
401 /* We are truly done. */
402 the_insn.opcode = opcode;
403 if (check_invalid_opcode (opcode))
404 as_bad (_("instruction not allowed: %s"), str);
405 return;
407 as_bad (_("too many operands: %s"), s);
408 break;
410 case ',': /* Must match a comma. */
411 if (*s++ == ',')
413 reloc = BFD_RELOC_NONE;
415 /* Parse next operand. */
416 s = parse_operand (s, operand, args[1] == 'I');
417 #if DEBUG
418 printf (" ',' case: operand->X_add_number = %d, *args = %s, *s = %s\n",
419 operand->X_add_number, args, s);
420 #endif
421 continue;
423 break;
425 case '(': /* Must match a (. */
426 s = parse_operand (s, operand, args[1] == 'I');
427 continue;
429 case ')': /* Must match a ). */
430 continue;
432 case 'r': /* A general register. */
433 args++;
435 if (operand->X_op != O_register)
436 break; /* Only registers. */
438 know (operand->X_add_symbol == 0);
439 know (operand->X_op_symbol == 0);
440 regno = operand->X_add_number;
441 encode (insn, &opcode, regno, *args);
442 #if DEBUG
443 printf (" r: operand->X_op = %d\n", operand->X_op);
444 #endif
445 continue;
447 default:
448 /* if (! ISALPHA (*args))
449 break; */ /* Only immediate values. */
451 if (mask_or_shift)
453 #if DEBUG
454 printf ("mask_or_shift = %d\n", mask_or_shift);
455 #endif
456 reloc = mask_or_shift;
458 mask_or_shift = 0;
460 if (strncasecmp (args, "LO(", 3) == 0)
462 #if DEBUG
463 printf ("reloc_const\n");
464 #endif
465 reloc = BFD_RELOC_LO16;
467 else if (strncasecmp (args, "HI(", 3) == 0)
469 #if DEBUG
470 printf ("reloc_consth\n");
471 #endif
472 reloc = BFD_RELOC_HI16;
475 if (*s == '(')
476 operand->X_op = O_constant;
477 else if (*s == ')')
478 s += 1;
479 #if DEBUG
480 printf (" default case: operand->X_add_number = %d, *args = %s, *s = %s\n", operand->X_add_number, args, s);
481 #endif
482 if (operand->X_op == O_constant)
484 if (reloc == BFD_RELOC_NONE)
486 bfd_vma v, mask;
488 mask = 0x3ffffff;
489 v = abs (operand->X_add_number) & ~ mask;
490 if (v)
491 as_bad (_("call/jmp target out of range (1)"));
494 if (reloc == BFD_RELOC_HI16)
495 operand->X_add_number = ((operand->X_add_number >> 16) & 0xffff);
497 the_insn.pcrel = 0;
498 encode (insn, &opcode, operand->X_add_number, *args);
499 /* the_insn.reloc = BFD_RELOC_NONE; */
500 continue;
503 if (reloc == BFD_RELOC_NONE)
504 the_insn.reloc = BFD_RELOC_32_GOT_PCREL;
505 else
506 the_insn.reloc = reloc;
508 /* the_insn.reloc = insn->reloc; */
509 #if DEBUG
510 printf (" reloc sym=%d\n", the_insn.reloc);
511 printf (" BFD_RELOC_NONE=%d\n", BFD_RELOC_NONE);
512 #endif
513 the_insn.exp = *operand;
515 /* the_insn.reloc_offset = 1; */
516 the_insn.pcrel = 1; /* Assume PC-relative jump. */
518 /* FIXME-SOON, Do we figure out whether abs later, after
519 know sym val? */
520 if (reloc == BFD_RELOC_LO16 || reloc == BFD_RELOC_HI16)
521 the_insn.pcrel = 0;
523 encode (insn, &opcode, operand->X_add_number, *args);
524 continue;
527 /* Types or values of args don't match. */
528 as_bad (_("invalid operands"));
529 return;
533 /* This is identical to the md_atof in m68k.c. I think this is right,
534 but I'm not sure.
536 Turn a string in input_line_pointer into a floating point constant
537 of type type, and store the appropriate bytes in *litP. The number
538 of LITTLENUMS emitted is stored in *sizeP . An error message is
539 returned, or NULL on OK. */
541 /* Equal to MAX_PRECISION in atof-ieee.c. */
542 #define MAX_LITTLENUMS 6
544 char *
545 md_atof (int type, char * litP, int * sizeP)
547 int prec;
548 LITTLENUM_TYPE words[MAX_LITTLENUMS];
549 LITTLENUM_TYPE *wordP;
550 char *t;
552 switch (type)
554 case 'f':
555 case 'F':
556 case 's':
557 case 'S':
558 prec = 2;
559 break;
561 case 'd':
562 case 'D':
563 case 'r':
564 case 'R':
565 prec = 4;
566 break;
568 case 'x':
569 case 'X':
570 prec = 6;
571 break;
573 case 'p':
574 case 'P':
575 prec = 6;
576 break;
578 default:
579 *sizeP = 0;
580 return _("Bad call to MD_ATOF()");
583 t = atof_ieee (input_line_pointer, type, words);
584 if (t)
585 input_line_pointer = t;
587 *sizeP = prec * sizeof (LITTLENUM_TYPE);
589 for (wordP = words; prec--;)
591 md_number_to_chars (litP, (valueT) (*wordP++), sizeof (LITTLENUM_TYPE));
592 litP += sizeof (LITTLENUM_TYPE);
595 return NULL;
598 /* Write out big-endian. */
600 void
601 md_number_to_chars (char *buf, valueT val, int n)
603 number_to_chars_bigendian (buf, val, n);
606 void
607 md_apply_fix (fixS * fixP, valueT * val, segT seg ATTRIBUTE_UNUSED)
609 char *buf = fixP->fx_where + fixP->fx_frag->fr_literal;
610 long t_val;
612 t_val = (long) *val;
614 #if DEBUG
615 printf ("md_apply_fix val:%x\n", t_val);
616 #endif
618 fixP->fx_addnumber = t_val; /* Remember value for emit_reloc. */
620 switch (fixP->fx_r_type)
622 case BFD_RELOC_32: /* XXXXXXXX pattern in a word. */
623 #if DEBUG
624 printf ("reloc_const: val=%x\n", t_val);
625 #endif
626 buf[0] = t_val >> 24;
627 buf[1] = t_val >> 16;
628 buf[2] = t_val >> 8;
629 buf[3] = t_val;
630 break;
632 case BFD_RELOC_16: /* XXXX0000 pattern in a word. */
633 #if DEBUG
634 printf ("reloc_const: val=%x\n", t_val);
635 #endif
636 buf[0] = t_val >> 8;
637 buf[1] = t_val;
638 break;
640 case BFD_RELOC_8: /* XX000000 pattern in a word. */
641 #if DEBUG
642 printf ("reloc_const: val=%x\n", t_val);
643 #endif
644 buf[0] = t_val;
645 break;
647 case BFD_RELOC_LO16: /* 0000XXXX pattern in a word. */
648 #if DEBUG
649 printf ("reloc_const: val=%x\n", t_val);
650 #endif
651 buf[2] = t_val >> 8; /* Holds bits 0000XXXX. */
652 buf[3] = t_val;
653 break;
655 case BFD_RELOC_HI16: /* 0000XXXX pattern in a word. */
656 #if DEBUG
657 printf ("reloc_consth: val=%x\n", t_val);
658 #endif
659 buf[2] = t_val >> 24; /* Holds bits XXXX0000. */
660 buf[3] = t_val >> 16;
661 break;
663 case BFD_RELOC_32_GOT_PCREL: /* 0000XXXX pattern in a word. */
664 if (!fixP->fx_done)
666 else if (fixP->fx_pcrel)
668 long v = t_val >> 28;
670 if (v != 0 && v != -1)
671 as_bad_where (fixP->fx_file, fixP->fx_line,
672 _("call/jmp target out of range (2)"));
674 else
675 /* This case was supposed to be handled in machine_ip. */
676 abort ();
678 buf[0] |= (t_val >> 26) & 0x03; /* Holds bits 0FFFFFFC of address. */
679 buf[1] = t_val >> 18;
680 buf[2] = t_val >> 10;
681 buf[3] = t_val >> 2;
682 break;
684 case BFD_RELOC_VTABLE_INHERIT:
685 case BFD_RELOC_VTABLE_ENTRY:
686 fixP->fx_done = 0;
687 break;
689 case BFD_RELOC_NONE:
690 default:
691 as_bad (_("bad relocation type: 0x%02x"), fixP->fx_r_type);
692 break;
695 if (fixP->fx_addsy == (symbolS *) NULL)
696 fixP->fx_done = 1;
699 /* Should never be called for or32. */
701 void
702 md_create_short_jump (char * ptr ATTRIBUTE_UNUSED,
703 addressT from_addr ATTRIBUTE_UNUSED,
704 addressT to_addr ATTRIBUTE_UNUSED,
705 fragS * frag ATTRIBUTE_UNUSED,
706 symbolS * to_symbol ATTRIBUTE_UNUSED)
708 as_fatal ("or32_create_short_jmp\n");
711 /* Should never be called for or32. */
713 void
714 md_convert_frag (bfd * headers ATTRIBUTE_UNUSED,
715 segT seg ATTRIBUTE_UNUSED,
716 fragS * fragP ATTRIBUTE_UNUSED)
718 as_fatal ("or32_convert_frag\n");
721 /* Should never be called for or32. */
723 void
724 md_create_long_jump (char * ptr ATTRIBUTE_UNUSED,
725 addressT from_addr ATTRIBUTE_UNUSED,
726 addressT to_addr ATTRIBUTE_UNUSED,
727 fragS * frag ATTRIBUTE_UNUSED,
728 symbolS * to_symbol ATTRIBUTE_UNUSED)
730 as_fatal ("or32_create_long_jump\n");
733 /* Should never be called for or32. */
736 md_estimate_size_before_relax (fragS * fragP ATTRIBUTE_UNUSED,
737 segT segtype ATTRIBUTE_UNUSED)
739 as_fatal ("or32_estimate_size_before_relax\n");
740 return 0;
743 /* Translate internal representation of relocation info to target format.
745 On sparc/29k: first 4 bytes are normal unsigned long address, next three
746 bytes are index, most sig. byte first. Byte 7 is broken up with
747 bit 7 as external, bits 6 & 5 unused, and the lower
748 five bits as relocation type. Next 4 bytes are long addend. */
749 /* Thanx and a tip of the hat to Michael Bloom, mb@ttidca.tti.com. */
751 #ifdef OBJ_AOUT
752 void
753 tc_aout_fix_to_chars (char *where,
754 fixS *fixP,
755 relax_addressT segment_address_in_file)
757 long r_symbolnum;
759 #if DEBUG
760 printf ("tc_aout_fix_to_chars\n");
761 #endif
763 know (fixP->fx_r_type < BFD_RELOC_NONE);
764 know (fixP->fx_addsy != NULL);
766 md_number_to_chars
767 (where,
768 fixP->fx_frag->fr_address + fixP->fx_where - segment_address_in_file,
771 r_symbolnum = (S_IS_DEFINED (fixP->fx_addsy)
772 ? S_GET_TYPE (fixP->fx_addsy)
773 : fixP->fx_addsy->sy_number);
775 where[4] = (r_symbolnum >> 16) & 0x0ff;
776 where[5] = (r_symbolnum >> 8) & 0x0ff;
777 where[6] = r_symbolnum & 0x0ff;
778 where[7] = (((!S_IS_DEFINED (fixP->fx_addsy)) << 7) & 0x80) | (0 & 0x60) | (fixP->fx_r_type & 0x1F);
780 /* Also easy. */
781 md_number_to_chars (&where[8], fixP->fx_addnumber, 4);
784 #endif /* OBJ_AOUT */
786 const char *md_shortopts = "";
788 struct option md_longopts[] =
790 { NULL, no_argument, NULL, 0 }
792 size_t md_longopts_size = sizeof (md_longopts);
795 md_parse_option (int c ATTRIBUTE_UNUSED, char * arg ATTRIBUTE_UNUSED)
797 return 0;
800 void
801 md_show_usage (FILE * stream ATTRIBUTE_UNUSED)
805 /* This is called when a line is unrecognized. This is used to handle
806 definitions of or32 style local labels. */
809 or32_unrecognized_line (int c)
811 int lab;
812 char *s;
814 if (c != '$'
815 || ! ISDIGIT ((unsigned char) input_line_pointer[0]))
816 return 0;
818 s = input_line_pointer;
820 lab = 0;
821 while (ISDIGIT ((unsigned char) *s))
823 lab = lab * 10 + *s - '0';
824 ++s;
827 if (*s != ':')
828 /* Not a label definition. */
829 return 0;
831 if (dollar_label_defined (lab))
833 as_bad (_("label \"$%d\" redefined"), lab);
834 return 0;
837 define_dollar_label (lab);
838 colon (dollar_label_name (lab, 0));
839 input_line_pointer = s + 1;
841 return 1;
844 /* Default the values of symbols known that should be "predefined". We
845 don't bother to predefine them unless you actually use one, since there
846 are a lot of them. */
848 symbolS *
849 md_undefined_symbol (char *name ATTRIBUTE_UNUSED)
851 return NULL;
854 /* Parse an operand that is machine-specific. */
856 void
857 md_operand (expressionS *expressionP)
859 #if DEBUG
860 printf (" md_operand(input_line_pointer = %s)\n", input_line_pointer);
861 #endif
863 if (input_line_pointer[0] == REGISTER_PREFIX && input_line_pointer[1] == 'r')
865 /* We have a numeric register expression. No biggy. */
866 input_line_pointer += 2; /* Skip %r */
867 (void) expression (expressionP);
869 if (expressionP->X_op != O_constant
870 || expressionP->X_add_number > 255)
871 as_bad (_("Invalid expression after %%%%\n"));
872 expressionP->X_op = O_register;
874 else if (input_line_pointer[0] == '&')
876 /* We are taking the 'address' of a register...this one is not
877 in the manual, but it *is* in traps/fpsymbol.h! What they
878 seem to want is the register number, as an absolute number. */
879 input_line_pointer++; /* Skip & */
880 (void) expression (expressionP);
882 if (expressionP->X_op != O_register)
883 as_bad (_("invalid register in & expression"));
884 else
885 expressionP->X_op = O_constant;
887 else if (input_line_pointer[0] == '$'
888 && ISDIGIT ((unsigned char) input_line_pointer[1]))
890 long lab;
891 char *name;
892 symbolS *sym;
894 /* This is a local label. */
895 ++input_line_pointer;
896 lab = (long) get_absolute_expression ();
898 if (dollar_label_defined (lab))
900 name = dollar_label_name (lab, 0);
901 sym = symbol_find (name);
903 else
905 name = dollar_label_name (lab, 1);
906 sym = symbol_find_or_make (name);
909 expressionP->X_op = O_symbol;
910 expressionP->X_add_symbol = sym;
911 expressionP->X_add_number = 0;
913 else if (input_line_pointer[0] == '$')
915 char *s;
916 char type;
917 int fieldnum, fieldlimit;
918 LITTLENUM_TYPE floatbuf[8];
920 /* $float(), $doubleN(), or $extendN() convert floating values
921 to integers. */
922 s = input_line_pointer;
924 ++s;
926 fieldnum = 0;
927 if (strncmp (s, "double", sizeof "double" - 1) == 0)
929 s += sizeof "double" - 1;
930 type = 'd';
931 fieldlimit = 2;
933 else if (strncmp (s, "float", sizeof "float" - 1) == 0)
935 s += sizeof "float" - 1;
936 type = 'f';
937 fieldlimit = 1;
939 else if (strncmp (s, "extend", sizeof "extend" - 1) == 0)
941 s += sizeof "extend" - 1;
942 type = 'x';
943 fieldlimit = 4;
945 else
946 return;
948 if (ISDIGIT (*s))
950 fieldnum = *s - '0';
951 ++s;
953 if (fieldnum >= fieldlimit)
954 return;
956 SKIP_WHITESPACE ();
957 if (*s != '(')
958 return;
959 ++s;
960 SKIP_WHITESPACE ();
962 s = atof_ieee (s, type, floatbuf);
963 if (s == NULL)
964 return;
965 s = s;
967 SKIP_WHITESPACE ();
968 if (*s != ')')
969 return;
970 ++s;
971 SKIP_WHITESPACE ();
973 input_line_pointer = s;
974 expressionP->X_op = O_constant;
975 expressionP->X_unsigned = 1;
976 expressionP->X_add_number = ((floatbuf[fieldnum * 2]
977 << LITTLENUM_NUMBER_OF_BITS)
978 + floatbuf[fieldnum * 2 + 1]);
982 /* Round up a section size to the appropriate boundary. */
984 valueT
985 md_section_align (segT segment ATTRIBUTE_UNUSED, valueT size ATTRIBUTE_UNUSED)
987 return size; /* Byte alignment is fine. */
990 /* Exactly what point is a PC-relative offset relative TO?
991 On the 29000, they're relative to the address of the instruction,
992 which we have set up as the address of the fixup too. */
994 long
995 md_pcrel_from (fixS *fixP)
997 return fixP->fx_where + fixP->fx_frag->fr_address;
1000 /* Generate a reloc for a fixup. */
1002 arelent *
1003 tc_gen_reloc (asection *seg ATTRIBUTE_UNUSED, fixS *fixp)
1005 arelent *reloc;
1007 reloc = xmalloc (sizeof (arelent));
1008 reloc->sym_ptr_ptr = xmalloc (sizeof (asymbol *));
1009 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
1010 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
1011 /* reloc->address = fixp->fx_frag->fr_address + fixp->fx_where + fixp->fx_addnumber;*/
1012 reloc->howto = bfd_reloc_type_lookup (stdoutput, fixp->fx_r_type);
1014 if (reloc->howto == (reloc_howto_type *) NULL)
1016 as_bad_where (fixp->fx_file, fixp->fx_line,
1017 _("reloc %d not supported by object file format"),
1018 (int) fixp->fx_r_type);
1019 return NULL;
1022 if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
1023 reloc->address = fixp->fx_offset;
1025 reloc->addend = fixp->fx_addnumber;
1026 return reloc;