* config/tc-ppc.c (ppc_setup_opcodes): Tidy. Add code to test
[deliverable/binutils-gdb.git] / gas / config / tc-or32.c
CommitLineData
3b16e843 1/* Assembly backend for the OpenRISC 1000.
541d2ffd
AM
2 Copyright (C) 2002, 2003, 2005, 2007
3 Free Software Foundation, Inc.
3b16e843
NC
4 Contributed by Damjan Lampret <lampret@opencores.org>.
5 Modified bu Johan Rydberg, <johan.rydberg@netinsight.se>.
6 Based upon a29k port.
7
8 This file is part of GAS, the GNU Assembler.
9
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
ec2655a6 12 the Free Software Foundation; either version 3, or (at your option)
3b16e843
NC
13 any later version.
14
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.
19
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
4b4da160
NC
22 the Free Software Foundation, 51 Franklin Street - Fifth Floor,
23 Boston, MA 02110-1301, USA. */
3b16e843
NC
24
25/* tc-a29k.c used as a template. */
26
27#include "safe-ctype.h"
28#include "as.h"
29#include "opcode/or32.h"
5d6255fe 30#include "elf/or32.h"
3b16e843
NC
31
32#define DEBUG 0
33
34#ifndef REGISTER_PREFIX
35#define REGISTER_PREFIX '%'
36#endif
37
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
43
44/* Handle of the OPCODE hash table. */
45static struct hash_control *op_hash = NULL;
46
47struct machine_it
ea1562b3
NC
48{
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;
56}
3b16e843
NC
57the_insn;
58
3b16e843 59const pseudo_typeS md_pseudo_table[] =
ea1562b3
NC
60{
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 },
70};
3b16e843
NC
71
72int md_short_jump_size = 4;
73int md_long_jump_size = 4;
74
3b16e843
NC
75/* This array holds the chars that always start a comment.
76 If the pre-processor is disabled, these aren't very useful. */
77const char comment_chars[] = "#";
78
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. */
86const char line_comment_chars[] = "#";
87
88/* We needed an unused char for line separation to work around the
89 lack of macros, using sed and such. */
90const char line_separator_chars[] = ";";
91
92/* Chars that can be used to separate mant from exp in floating point nums. */
93const char EXP_CHARS[] = "eE";
94
95/* Chars that mean this number is a floating point constant.
96 As in 0f12.456
97 or 0d1.2345e12. */
98const char FLT_CHARS[] = "rRsSfFdDxXpP";
99
100/* "l.jalr r9" precalculated opcode. */
101static unsigned long jalr_r9_opcode;
102
ea1562b3 103static void machine_ip (char *);
3b16e843 104
3b16e843
NC
105
106/* Set bits in machine opcode according to insn->encoding
5d6255fe 107 description and passed operand. */
3b16e843 108
5d6255fe 109static void
ea1562b3
NC
110encode (const struct machine_opcode *insn,
111 unsigned long *opcode,
112 signed long param_val,
113 char param_ch)
3b16e843
NC
114{
115 int opc_pos = 0;
116 int param_pos = 0;
117 char *enc;
118
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)
125 {
126 if (enc - 2 >= insn->encoding && (*(enc - 2) == '0') && (*(enc - 1) == 'x'))
127 continue;
128 else
129 param_pos ++;
130 }
131
132 opc_pos = 32;
133
134 for (enc = insn->encoding; *enc != '\0';)
135 {
5d6255fe 136 if ((*enc == '0') && (*(enc + 1) == 'x'))
3b16e843
NC
137 {
138 int tmp = strtol (enc, NULL, 16);
139
140 opc_pos -= 4;
141 *opcode |= tmp << opc_pos;
142 enc += 3;
143 }
5d6255fe 144 else if ((*enc == '0') || (*enc == '-'))
3b16e843
NC
145 {
146 opc_pos--;
147 enc++;
148 }
5d6255fe 149 else if (*enc == '1')
3b16e843
NC
150 {
151 opc_pos--;
152 *opcode |= 1 << opc_pos;
153 enc++;
154 }
5d6255fe 155 else if (*enc == param_ch)
3b16e843
NC
156 {
157 opc_pos--;
158 param_pos--;
159 *opcode |= ((param_val >> param_pos) & 0x1) << opc_pos;
160 enc++;
161 }
5d6255fe 162 else if (ISALPHA (*enc))
3b16e843
NC
163 {
164 opc_pos--;
165 enc++;
166 }
167 else
168 enc++;
169 }
5d6255fe 170
3b16e843
NC
171#if DEBUG
172 printf (" opcode=%.8lx\n", *opcode);
173#endif
174}
175
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. */
179
180void
ea1562b3 181md_begin (void)
3b16e843
NC
182{
183 const char *retval = NULL;
184 int lose = 0;
185 int skipnext = 0;
186 unsigned int i;
187
188 /* Hash up all the opcodes for fast use later. */
189 op_hash = hash_new ();
190
191 for (i = 0; i < or32_num_opcodes; i++)
192 {
193 const char *name = machine_opcodes[i].name;
194
195 if (skipnext)
196 {
197 skipnext = 0;
198 continue;
199 }
200
ea1562b3 201 retval = hash_insert (op_hash, name, (void *) &machine_opcodes[i]);
3b16e843
NC
202 if (retval != NULL)
203 {
204 fprintf (stderr, "internal error: can't hash `%s': %s\n",
205 machine_opcodes[i].name, retval);
206 lose = 1;
207 }
208 }
209
210 if (lose)
211 as_fatal (_("Broken assembler. No assembly attempted."));
212
213 encode (&machine_opcodes[insn_index ("l.jalr")], &jalr_r9_opcode, 9, 'B');
214}
215
67c1ffbe 216/* Returns non zero if instruction is to be used. */
3b16e843
NC
217
218static int
ea1562b3 219check_invalid_opcode (unsigned long opcode)
3b16e843
NC
220{
221 return opcode == jalr_r9_opcode;
222}
223
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. */
227
228void
ea1562b3 229md_assemble (char *str)
3b16e843
NC
230{
231 char *toP;
232
233#if DEBUG
234 printf ("NEW INSTRUCTION\n");
235#endif
236
237 know (str);
238 machine_ip (str);
239 toP = frag_more (4);
240
241 /* Put out the opcode. */
242 md_number_to_chars (toP, the_insn.opcode, 4);
243
244 /* Put out the symbol-dependent stuff. */
3b16e843 245 if (the_insn.reloc != BFD_RELOC_NONE)
3b16e843
NC
246 {
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);
253 }
254}
255
256/* This is true of the we have issued a "lo(" or "hi"(. */
257static int waiting_for_shift = 0;
258
259static int mask_or_shift = 0;
260
3b16e843 261static char *
ea1562b3 262parse_operand (char *s, expressionS *operandp, int opt)
3b16e843
NC
263{
264 char *save = input_line_pointer;
265 char *new;
266
267#if DEBUG
268 printf (" PROCESS NEW OPERAND(%s) == %c (%d)\n", s, opt ? opt : '!', opt);
269#endif
270
271 input_line_pointer = s;
272
273 if (strncasecmp (s, "HI(", 3) == 0)
274 {
275 waiting_for_shift = 1;
276 mask_or_shift = BFD_RELOC_HI16;
277
278 input_line_pointer += 3;
279 }
280 else if (strncasecmp (s, "LO(", 3) == 0)
281 {
282 mask_or_shift = BFD_RELOC_LO16;
283
284 input_line_pointer += 3;
285 }
286 else
287 mask_or_shift = 0;
288
289 if ((*s == '(') && (*(s+1) == 'r'))
290 s++;
291
5d6255fe 292 if ((*s == 'r') && ISDIGIT (*(s + 1)))
3b16e843
NC
293 {
294 operandp->X_add_number = strtol (s + 1, NULL, 10);
295 operandp->X_op = O_register;
296 for (; (*s != ',') && (*s != '\0');)
5d6255fe 297 s++;
3b16e843 298 input_line_pointer = save;
5d6255fe 299 return s;
3b16e843
NC
300 }
301
302 expression (operandp);
303
304 if (operandp->X_op == O_absent)
305 {
306 if (! opt)
307 as_bad (_("missing operand"));
308 else
309 {
310 operandp->X_add_number = 0;
311 operandp->X_op = O_constant;
312 }
313 }
5d6255fe 314
3b16e843
NC
315 new = input_line_pointer;
316 input_line_pointer = save;
5d6255fe 317
3b16e843
NC
318#if DEBUG
319 printf (" %s=parse_operand(%s): operandp->X_op = %u\n", new, s, operandp->X_op);
320#endif
321
322 return new;
323}
3b16e843
NC
324
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. */
328
3b16e843 329static void
ea1562b3 330machine_ip (char *str)
3b16e843
NC
331{
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;
341
342#if DEBUG
343 printf ("machine_ip(%s)\n", str);
344#endif
345
346 s = str;
347 for (; ISALNUM (*s) || *s == '.'; ++s)
348 if (ISUPPER (*s))
349 *s = TOLOWER (*s);
350
351 switch (*s)
352 {
353 case '\0':
354 break;
355
356 case ' ': /* FIXME-SOMEDAY more whitespace. */
357 *s++ = '\0';
358 break;
359
360 default:
361 as_bad (_("unknown opcode1: `%s'"), str);
362 return;
363 }
364
365 if ((insn = (struct machine_opcode *) hash_find (op_hash, str)) == NULL)
366 {
367 as_bad (_("unknown opcode2 `%s'."), str);
368 return;
369 }
370
371 argsStart = s;
372 opcode = 0;
373 memset (&the_insn, '\0', sizeof (the_insn));
374 the_insn.reloc = BFD_RELOC_NONE;
375
376 reloc = BFD_RELOC_NONE;
377
378 /* Build the opcode, checking as we go to make sure that the
379 operands match.
5d6255fe 380
3b16e843
NC
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')
ea1562b3
NC
384 /* Prime the pump. */
385 s = parse_operand (s, operand, insn->args[0] == 'I');
3b16e843
NC
386
387 for (args = insn->args;; ++args)
388 {
389#if DEBUG
390 printf (" args = %s\n", args);
391#endif
392 switch (*args)
393 {
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);
398
399 if (*s == '\0')
400 {
401 /* We are truly done. */
402 the_insn.opcode = opcode;
403 if (check_invalid_opcode (opcode))
5d6255fe 404 as_bad (_("instruction not allowed: %s"), str);
3b16e843
NC
405 return;
406 }
407 as_bad (_("too many operands: %s"), s);
408 break;
409
410 case ',': /* Must match a comma. */
411 if (*s++ == ',')
412 {
413 reloc = BFD_RELOC_NONE;
414
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);
5d6255fe 420#endif
3b16e843
NC
421 continue;
422 }
423 break;
424
425 case '(': /* Must match a (. */
426 s = parse_operand (s, operand, args[1] == 'I');
427 continue;
5d6255fe 428
3b16e843
NC
429 case ')': /* Must match a ). */
430 continue;
431
432 case 'r': /* A general register. */
433 args++;
434
435 if (operand->X_op != O_register)
436 break; /* Only registers. */
5d6255fe 437
3b16e843
NC
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;
446
447 default:
448 /* if (! ISALPHA (*args))
449 break; */ /* Only immediate values. */
5d6255fe 450
3b16e843
NC
451 if (mask_or_shift)
452 {
453#if DEBUG
454 printf ("mask_or_shift = %d\n", mask_or_shift);
455#endif
456 reloc = mask_or_shift;
457 }
458 mask_or_shift = 0;
5d6255fe
KH
459
460 if (strncasecmp (args, "LO(", 3) == 0)
3b16e843
NC
461 {
462#if DEBUG
463 printf ("reloc_const\n");
464#endif
465 reloc = BFD_RELOC_LO16;
466 }
5d6255fe 467 else if (strncasecmp (args, "HI(", 3) == 0)
3b16e843
NC
468 {
469#if DEBUG
470 printf ("reloc_consth\n");
471#endif
472 reloc = BFD_RELOC_HI16;
473 }
5d6255fe
KH
474
475 if (*s == '(')
ea1562b3 476 operand->X_op = O_constant;
3b16e843
NC
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)
483 {
484 if (reloc == BFD_RELOC_NONE)
485 {
486 bfd_vma v, mask;
487
488 mask = 0x3ffffff;
489 v = abs (operand->X_add_number) & ~ mask;
490 if (v)
491 as_bad (_("call/jmp target out of range (1)"));
492 }
493
494 if (reloc == BFD_RELOC_HI16)
495 operand->X_add_number = ((operand->X_add_number >> 16) & 0xffff);
496
497 the_insn.pcrel = 0;
498 encode (insn, &opcode, operand->X_add_number, *args);
499 /* the_insn.reloc = BFD_RELOC_NONE; */
5d6255fe 500 continue;
3b16e843
NC
501 }
502
503 if (reloc == BFD_RELOC_NONE)
504 the_insn.reloc = BFD_RELOC_32_GOT_PCREL;
505 else
506 the_insn.reloc = reloc;
507
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;
5d6255fe 514
3b16e843
NC
515 /* the_insn.reloc_offset = 1; */
516 the_insn.pcrel = 1; /* Assume PC-relative jump. */
517
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;
522
523 encode (insn, &opcode, operand->X_add_number, *args);
524 continue;
525 }
5d6255fe 526
3b16e843
NC
527 /* Types or values of args don't match. */
528 as_bad (_("invalid operands"));
529 return;
530 }
531}
532
3b16e843 533char *
ea1562b3 534md_atof (int type, char * litP, int * sizeP)
3b16e843 535{
499ac353 536 return ieee_md_atof (type, litP, sizeP, TRUE);
3b16e843
NC
537}
538
539/* Write out big-endian. */
540
541void
ea1562b3 542md_number_to_chars (char *buf, valueT val, int n)
3b16e843
NC
543{
544 number_to_chars_bigendian (buf, val, n);
545}
546
3b16e843 547void
55cf6793 548md_apply_fix (fixS * fixP, valueT * val, segT seg ATTRIBUTE_UNUSED)
3b16e843
NC
549{
550 char *buf = fixP->fx_where + fixP->fx_frag->fr_literal;
551 long t_val;
552
553 t_val = (long) *val;
554
555#if DEBUG
556 printf ("md_apply_fix val:%x\n", t_val);
557#endif
558
559 fixP->fx_addnumber = t_val; /* Remember value for emit_reloc. */
560
3b16e843
NC
561 switch (fixP->fx_r_type)
562 {
563 case BFD_RELOC_32: /* XXXXXXXX pattern in a word. */
564#if DEBUG
565 printf ("reloc_const: val=%x\n", t_val);
566#endif
567 buf[0] = t_val >> 24;
568 buf[1] = t_val >> 16;
569 buf[2] = t_val >> 8;
570 buf[3] = t_val;
571 break;
572
573 case BFD_RELOC_16: /* XXXX0000 pattern in a word. */
574#if DEBUG
575 printf ("reloc_const: val=%x\n", t_val);
576#endif
577 buf[0] = t_val >> 8;
578 buf[1] = t_val;
579 break;
580
581 case BFD_RELOC_8: /* XX000000 pattern in a word. */
582#if DEBUG
583 printf ("reloc_const: val=%x\n", t_val);
584#endif
585 buf[0] = t_val;
586 break;
587
588 case BFD_RELOC_LO16: /* 0000XXXX pattern in a word. */
589#if DEBUG
590 printf ("reloc_const: val=%x\n", t_val);
591#endif
592 buf[2] = t_val >> 8; /* Holds bits 0000XXXX. */
593 buf[3] = t_val;
594 break;
595
596 case BFD_RELOC_HI16: /* 0000XXXX pattern in a word. */
597#if DEBUG
598 printf ("reloc_consth: val=%x\n", t_val);
599#endif
600 buf[2] = t_val >> 24; /* Holds bits XXXX0000. */
601 buf[3] = t_val >> 16;
602 break;
603
604 case BFD_RELOC_32_GOT_PCREL: /* 0000XXXX pattern in a word. */
605 if (!fixP->fx_done)
65ec77d2 606 ;
3b16e843
NC
607 else if (fixP->fx_pcrel)
608 {
609 long v = t_val >> 28;
610
611 if (v != 0 && v != -1)
612 as_bad_where (fixP->fx_file, fixP->fx_line,
613 _("call/jmp target out of range (2)"));
614 }
615 else
616 /* This case was supposed to be handled in machine_ip. */
617 abort ();
618
619 buf[0] |= (t_val >> 26) & 0x03; /* Holds bits 0FFFFFFC of address. */
620 buf[1] = t_val >> 18;
621 buf[2] = t_val >> 10;
622 buf[3] = t_val >> 2;
623 break;
624
625 case BFD_RELOC_VTABLE_INHERIT:
626 case BFD_RELOC_VTABLE_ENTRY:
627 fixP->fx_done = 0;
628 break;
629
630 case BFD_RELOC_NONE:
631 default:
632 as_bad (_("bad relocation type: 0x%02x"), fixP->fx_r_type);
633 break;
634 }
635
636 if (fixP->fx_addsy == (symbolS *) NULL)
637 fixP->fx_done = 1;
638}
3b16e843
NC
639
640/* Should never be called for or32. */
641
642void
ea1562b3
NC
643md_create_short_jump (char * ptr ATTRIBUTE_UNUSED,
644 addressT from_addr ATTRIBUTE_UNUSED,
645 addressT to_addr ATTRIBUTE_UNUSED,
646 fragS * frag ATTRIBUTE_UNUSED,
647 symbolS * to_symbol ATTRIBUTE_UNUSED)
3b16e843
NC
648{
649 as_fatal ("or32_create_short_jmp\n");
650}
651
652/* Should never be called for or32. */
653
3b16e843 654void
ea1562b3
NC
655md_convert_frag (bfd * headers ATTRIBUTE_UNUSED,
656 segT seg ATTRIBUTE_UNUSED,
657 fragS * fragP ATTRIBUTE_UNUSED)
3b16e843
NC
658{
659 as_fatal ("or32_convert_frag\n");
5d6255fe 660}
3b16e843
NC
661
662/* Should never be called for or32. */
663
664void
ea1562b3
NC
665md_create_long_jump (char * ptr ATTRIBUTE_UNUSED,
666 addressT from_addr ATTRIBUTE_UNUSED,
667 addressT to_addr ATTRIBUTE_UNUSED,
668 fragS * frag ATTRIBUTE_UNUSED,
669 symbolS * to_symbol ATTRIBUTE_UNUSED)
3b16e843
NC
670{
671 as_fatal ("or32_create_long_jump\n");
672}
673
674/* Should never be called for or32. */
675
676int
ea1562b3
NC
677md_estimate_size_before_relax (fragS * fragP ATTRIBUTE_UNUSED,
678 segT segtype ATTRIBUTE_UNUSED)
3b16e843
NC
679{
680 as_fatal ("or32_estimate_size_before_relax\n");
681 return 0;
682}
683
684/* Translate internal representation of relocation info to target format.
685
686 On sparc/29k: first 4 bytes are normal unsigned long address, next three
687 bytes are index, most sig. byte first. Byte 7 is broken up with
688 bit 7 as external, bits 6 & 5 unused, and the lower
689 five bits as relocation type. Next 4 bytes are long addend. */
690/* Thanx and a tip of the hat to Michael Bloom, mb@ttidca.tti.com. */
691
692#ifdef OBJ_AOUT
693void
ea1562b3
NC
694tc_aout_fix_to_chars (char *where,
695 fixS *fixP,
696 relax_addressT segment_address_in_file)
3b16e843
NC
697{
698 long r_symbolnum;
699
700#if DEBUG
701 printf ("tc_aout_fix_to_chars\n");
5d6255fe 702#endif
3b16e843
NC
703
704 know (fixP->fx_r_type < BFD_RELOC_NONE);
705 know (fixP->fx_addsy != NULL);
706
707 md_number_to_chars
708 (where,
709 fixP->fx_frag->fr_address + fixP->fx_where - segment_address_in_file,
710 4);
711
712 r_symbolnum = (S_IS_DEFINED (fixP->fx_addsy)
713 ? S_GET_TYPE (fixP->fx_addsy)
714 : fixP->fx_addsy->sy_number);
715
716 where[4] = (r_symbolnum >> 16) & 0x0ff;
717 where[5] = (r_symbolnum >> 8) & 0x0ff;
718 where[6] = r_symbolnum & 0x0ff;
719 where[7] = (((!S_IS_DEFINED (fixP->fx_addsy)) << 7) & 0x80) | (0 & 0x60) | (fixP->fx_r_type & 0x1F);
720
721 /* Also easy. */
722 md_number_to_chars (&where[8], fixP->fx_addnumber, 4);
723}
724
725#endif /* OBJ_AOUT */
726\f
727const char *md_shortopts = "";
728
729struct option md_longopts[] =
ea1562b3
NC
730{
731 { NULL, no_argument, NULL, 0 }
732};
3b16e843
NC
733size_t md_longopts_size = sizeof (md_longopts);
734
735int
ea1562b3 736md_parse_option (int c ATTRIBUTE_UNUSED, char * arg ATTRIBUTE_UNUSED)
3b16e843
NC
737{
738 return 0;
739}
740
741void
ea1562b3 742md_show_usage (FILE * stream ATTRIBUTE_UNUSED)
3b16e843
NC
743{
744}
745\f
746/* This is called when a line is unrecognized. This is used to handle
747 definitions of or32 style local labels. */
748
749int
ea1562b3 750or32_unrecognized_line (int c)
3b16e843
NC
751{
752 int lab;
753 char *s;
754
755 if (c != '$'
756 || ! ISDIGIT ((unsigned char) input_line_pointer[0]))
757 return 0;
758
759 s = input_line_pointer;
760
761 lab = 0;
762 while (ISDIGIT ((unsigned char) *s))
763 {
764 lab = lab * 10 + *s - '0';
765 ++s;
766 }
767
768 if (*s != ':')
769 /* Not a label definition. */
770 return 0;
771
772 if (dollar_label_defined (lab))
773 {
774 as_bad (_("label \"$%d\" redefined"), lab);
775 return 0;
776 }
777
778 define_dollar_label (lab);
779 colon (dollar_label_name (lab, 0));
780 input_line_pointer = s + 1;
781
782 return 1;
783}
784
3b16e843
NC
785/* Default the values of symbols known that should be "predefined". We
786 don't bother to predefine them unless you actually use one, since there
787 are a lot of them. */
788
789symbolS *
ea1562b3 790md_undefined_symbol (char *name ATTRIBUTE_UNUSED)
3b16e843 791{
3b16e843
NC
792 return NULL;
793}
794
795/* Parse an operand that is machine-specific. */
796
797void
ea1562b3 798md_operand (expressionS *expressionP)
3b16e843
NC
799{
800#if DEBUG
801 printf (" md_operand(input_line_pointer = %s)\n", input_line_pointer);
802#endif
803
804 if (input_line_pointer[0] == REGISTER_PREFIX && input_line_pointer[1] == 'r')
805 {
806 /* We have a numeric register expression. No biggy. */
807 input_line_pointer += 2; /* Skip %r */
808 (void) expression (expressionP);
809
810 if (expressionP->X_op != O_constant
811 || expressionP->X_add_number > 255)
812 as_bad (_("Invalid expression after %%%%\n"));
813 expressionP->X_op = O_register;
814 }
815 else if (input_line_pointer[0] == '&')
816 {
817 /* We are taking the 'address' of a register...this one is not
818 in the manual, but it *is* in traps/fpsymbol.h! What they
819 seem to want is the register number, as an absolute number. */
820 input_line_pointer++; /* Skip & */
821 (void) expression (expressionP);
822
823 if (expressionP->X_op != O_register)
824 as_bad (_("invalid register in & expression"));
825 else
826 expressionP->X_op = O_constant;
827 }
828 else if (input_line_pointer[0] == '$'
829 && ISDIGIT ((unsigned char) input_line_pointer[1]))
830 {
831 long lab;
832 char *name;
833 symbolS *sym;
5d6255fe 834
3b16e843
NC
835 /* This is a local label. */
836 ++input_line_pointer;
837 lab = (long) get_absolute_expression ();
838
839 if (dollar_label_defined (lab))
840 {
841 name = dollar_label_name (lab, 0);
842 sym = symbol_find (name);
843 }
844 else
845 {
846 name = dollar_label_name (lab, 1);
847 sym = symbol_find_or_make (name);
848 }
849
850 expressionP->X_op = O_symbol;
851 expressionP->X_add_symbol = sym;
852 expressionP->X_add_number = 0;
853 }
854 else if (input_line_pointer[0] == '$')
855 {
856 char *s;
857 char type;
858 int fieldnum, fieldlimit;
859 LITTLENUM_TYPE floatbuf[8];
860
861 /* $float(), $doubleN(), or $extendN() convert floating values
862 to integers. */
863 s = input_line_pointer;
864
865 ++s;
866
867 fieldnum = 0;
868 if (strncmp (s, "double", sizeof "double" - 1) == 0)
869 {
870 s += sizeof "double" - 1;
871 type = 'd';
872 fieldlimit = 2;
873 }
874 else if (strncmp (s, "float", sizeof "float" - 1) == 0)
875 {
876 s += sizeof "float" - 1;
877 type = 'f';
878 fieldlimit = 1;
879 }
880 else if (strncmp (s, "extend", sizeof "extend" - 1) == 0)
881 {
882 s += sizeof "extend" - 1;
883 type = 'x';
884 fieldlimit = 4;
885 }
5d6255fe 886 else
3b16e843
NC
887 return;
888
889 if (ISDIGIT (*s))
890 {
891 fieldnum = *s - '0';
892 ++s;
893 }
894 if (fieldnum >= fieldlimit)
895 return;
896
897 SKIP_WHITESPACE ();
898 if (*s != '(')
899 return;
900 ++s;
901 SKIP_WHITESPACE ();
902
903 s = atof_ieee (s, type, floatbuf);
904 if (s == NULL)
905 return;
906 s = s;
907
908 SKIP_WHITESPACE ();
909 if (*s != ')')
910 return;
911 ++s;
912 SKIP_WHITESPACE ();
913
914 input_line_pointer = s;
5d6255fe 915 expressionP->X_op = O_constant;
3b16e843
NC
916 expressionP->X_unsigned = 1;
917 expressionP->X_add_number = ((floatbuf[fieldnum * 2]
918 << LITTLENUM_NUMBER_OF_BITS)
919 + floatbuf[fieldnum * 2 + 1]);
920 }
921}
922
923/* Round up a section size to the appropriate boundary. */
924
925valueT
ea1562b3 926md_section_align (segT segment ATTRIBUTE_UNUSED, valueT size ATTRIBUTE_UNUSED)
3b16e843
NC
927{
928 return size; /* Byte alignment is fine. */
929}
930
931/* Exactly what point is a PC-relative offset relative TO?
932 On the 29000, they're relative to the address of the instruction,
933 which we have set up as the address of the fixup too. */
934
935long
ea1562b3 936md_pcrel_from (fixS *fixP)
3b16e843
NC
937{
938 return fixP->fx_where + fixP->fx_frag->fr_address;
939}
940
941/* Generate a reloc for a fixup. */
942
3b16e843 943arelent *
ea1562b3 944tc_gen_reloc (asection *seg ATTRIBUTE_UNUSED, fixS *fixp)
3b16e843
NC
945{
946 arelent *reloc;
947
ea1562b3
NC
948 reloc = xmalloc (sizeof (arelent));
949 reloc->sym_ptr_ptr = xmalloc (sizeof (asymbol *));
3b16e843
NC
950 *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
951 reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
952 /* reloc->address = fixp->fx_frag->fr_address + fixp->fx_where + fixp->fx_addnumber;*/
953 reloc->howto = bfd_reloc_type_lookup (stdoutput, fixp->fx_r_type);
954
955 if (reloc->howto == (reloc_howto_type *) NULL)
956 {
957 as_bad_where (fixp->fx_file, fixp->fx_line,
958 _("reloc %d not supported by object file format"),
959 (int) fixp->fx_r_type);
960 return NULL;
961 }
962
a161fe53
AM
963 if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
964 reloc->address = fixp->fx_offset;
3b16e843 965
a161fe53 966 reloc->addend = fixp->fx_addnumber;
3b16e843
NC
967 return reloc;
968}
This page took 0.316973 seconds and 4 git commands to generate.