OpenCores
URL https://opencores.org/ocsvn/open8_urisc/open8_urisc/trunk

Subversion Repositories open8_urisc

[/] [open8_urisc/] [trunk/] [gnu/] [binutils/] [gas/] [config/] [tc-or32.c] - Blame information for rev 159

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 16 khays
/* Assembly backend for the OpenRISC 1000.
2
   Copyright (C) 2002, 2003, 2005, 2007, 2009, 2010
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.
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
12
   the Free Software Foundation; either version 3, or (at your option)
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
22
   the Free Software Foundation, 51 Franklin Street - Fifth Floor,
23
   Boston, MA 02110-1301, USA.  */
24
 
25
/* tc-a29k.c used as a template.  */
26
 
27
#include "safe-ctype.h"
28
#include "as.h"
29
#include "opcode/or32.h"
30
#include "elf/or32.h"
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.  */
45
static struct hash_control *op_hash = NULL;
46
 
47
struct machine_it
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
}
57
the_insn;
58
 
59
const pseudo_typeS md_pseudo_table[] =
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
};
71
 
72
int md_short_jump_size  = 4;
73
int md_long_jump_size   = 4;
74
 
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[] = "#";
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.  */
86
const 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.  */
90
const char line_separator_chars[] = ";";
91
 
92
/* Chars that can be used to separate mant from exp in floating point nums.  */
93
const 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.  */
98
const char FLT_CHARS[] = "rRsSfFdDxXpP";
99
 
100
/* "l.jalr r9" precalculated opcode.  */
101
static unsigned long jalr_r9_opcode;
102
 
103
static void machine_ip (char *);
104
 
105
 
106
/* Set bits in machine opcode according to insn->encoding
107
   description and passed operand.  */
108
 
109
static void
110
encode (const struct machine_opcode *insn,
111
        unsigned long *opcode,
112
        signed long param_val,
113
        char param_ch)
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
    {
136
      if ((*enc == '0') && (*(enc + 1) == 'x'))
137
        {
138
          int tmp = strtol (enc, NULL, 16);
139
 
140
          opc_pos -= 4;
141
          *opcode |= tmp << opc_pos;
142
          enc += 3;
143
        }
144
      else if ((*enc == '0') || (*enc == '-'))
145
        {
146
          opc_pos--;
147
          enc++;
148
        }
149
      else if (*enc == '1')
150
        {
151
          opc_pos--;
152
          *opcode |= 1 << opc_pos;
153
          enc++;
154
        }
155
      else if (*enc == param_ch)
156
        {
157
          opc_pos--;
158
          param_pos--;
159
          *opcode |= ((param_val >> param_pos) & 0x1) << opc_pos;
160
          enc++;
161
        }
162
      else if (ISALPHA (*enc))
163
        {
164
          opc_pos--;
165
          enc++;
166
        }
167
      else
168
        enc++;
169
    }
170
 
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
 
180
void
181
md_begin (void)
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
 
201
      retval = hash_insert (op_hash, name, (void *) &machine_opcodes[i]);
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
 
216
/* Returns non zero if instruction is to be used.  */
217
 
218
static int
219
check_invalid_opcode (unsigned long opcode)
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
 
228
void
229
md_assemble (char *str)
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.  */
245
  if (the_insn.reloc != BFD_RELOC_NONE)
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"(.  */
257
static int waiting_for_shift = 0;
258
 
259
static int mask_or_shift = 0;
260
 
261
static char *
262
parse_operand (char *s, expressionS *operandp, int opt)
263
{
264
  char *save = input_line_pointer;
265
  char *new_pointer;
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
 
292
  if ((*s == 'r') && ISDIGIT (*(s + 1)))
293
    {
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;
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
    }
314
 
315
  new_pointer = input_line_pointer;
316
  input_line_pointer = save;
317
 
318
#if DEBUG
319
  printf ("  %s=parse_operand(%s): operandp->X_op = %u\n", new_pointer, s,
320
          operandp->X_op);
321
#endif
322
 
323
  return new_pointer;
324
}
325
 
326
/* Instruction parsing.  Takes a string containing the opcode.
327
   Operands are at input_line_pointer.  Output is in the_insn.
328
   Warnings or errors are generated.  */
329
 
330
static void
331
machine_ip (char *str)
332
{
333
  char *s;
334
  const char *args;
335
  const struct machine_opcode *insn;
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
  opcode = 0;
372
  memset (&the_insn, '\0', sizeof (the_insn));
373
  the_insn.reloc = BFD_RELOC_NONE;
374
 
375
  reloc = BFD_RELOC_NONE;
376
 
377
  /* Build the opcode, checking as we go to make sure that the
378
     operands match.
379
 
380
     If an operand matches, we modify the_insn or opcode appropriately,
381
     and do a "continue".  If an operand fails to match, we "break".  */
382
  if (insn->args[0] != '\0')
383
    /* Prime the pump.  */
384
    s = parse_operand (s, operand, insn->args[0] == 'I');
385
 
386
  for (args = insn->args;; ++args)
387
    {
388
#if DEBUG
389
      printf ("  args = %s\n", args);
390
#endif
391
      switch (*args)
392
        {
393
        case '\0':    /* End of args.  */
394
          /* We have have 0 args, do the bazoooka!  */
395
          if (args == insn->args)
396
            encode (insn, &opcode, 0, 0);
397
 
398
          if (*s == '\0')
399
            {
400
              /* We are truly done.  */
401
              the_insn.opcode = opcode;
402
              if (check_invalid_opcode (opcode))
403
                as_bad (_("instruction not allowed: %s"), str);
404
              return;
405
            }
406
          as_bad (_("too many operands: %s"), s);
407
          break;
408
 
409
        case ',':   /* Must match a comma.  */
410
          if (*s++ == ',')
411
            {
412
              reloc = BFD_RELOC_NONE;
413
 
414
              /* Parse next operand.  */
415
              s = parse_operand (s, operand, args[1] == 'I');
416
#if DEBUG
417
              printf ("    ',' case: operand->X_add_number = %d, *args = %s, *s = %s\n",
418
                      operand->X_add_number, args, s);
419
#endif
420
              continue;
421
            }
422
          break;
423
 
424
        case '(':   /* Must match a (.  */
425
          s = parse_operand (s, operand, args[1] == 'I');
426
          continue;
427
 
428
        case ')':   /* Must match a ).  */
429
          continue;
430
 
431
        case 'r':   /* A general register.  */
432
          args++;
433
 
434
          if (operand->X_op != O_register)
435
            break;    /* Only registers.  */
436
 
437
          know (operand->X_add_symbol == 0);
438
          know (operand->X_op_symbol == 0);
439
          regno = operand->X_add_number;
440
          encode (insn, &opcode, regno, *args);
441
#if DEBUG
442
          printf ("    r: operand->X_op = %d\n", operand->X_op);
443
#endif
444
          continue;
445
 
446
        default:
447
          /* if (! ISALPHA (*args))
448
               break;  */   /* Only immediate values.  */
449
 
450
          if (mask_or_shift)
451
            {
452
#if DEBUG
453
              printf ("mask_or_shift = %d\n", mask_or_shift);
454
#endif
455
              reloc = mask_or_shift;
456
            }
457
          mask_or_shift = 0;
458
 
459
          if (strncasecmp (args, "LO(", 3) == 0)
460
            {
461
#if DEBUG
462
              printf ("reloc_const\n");
463
#endif
464
              reloc = BFD_RELOC_LO16;
465
            }
466
          else if (strncasecmp (args, "HI(", 3) == 0)
467
            {
468
#if DEBUG
469
              printf ("reloc_consth\n");
470
#endif
471
              reloc = BFD_RELOC_HI16;
472
            }
473
 
474
          if (*s == '(')
475
            operand->X_op = O_constant;
476
          else if (*s == ')')
477
            s += 1;
478
#if DEBUG
479
          printf ("    default case: operand->X_add_number = %d, *args = %s, *s = %s\n", operand->X_add_number, args, s);
480
#endif
481
          if (operand->X_op == O_constant)
482
            {
483
              if (reloc == BFD_RELOC_NONE)
484
                {
485
                  bfd_vma v, mask;
486
 
487
                  mask = 0x3ffffff;
488
                  v = abs (operand->X_add_number) & ~ mask;
489
                  if (v)
490
                    as_bad (_("call/jmp target out of range (1)"));
491
                }
492
 
493
              if (reloc == BFD_RELOC_HI16)
494
                operand->X_add_number = ((operand->X_add_number >> 16) & 0xffff);
495
 
496
              the_insn.pcrel = 0;
497
              encode (insn, &opcode, operand->X_add_number, *args);
498
 /*             the_insn.reloc = BFD_RELOC_NONE; */
499
              continue;
500
            }
501
 
502
          if (reloc == BFD_RELOC_NONE)
503
            the_insn.reloc = BFD_RELOC_32_GOT_PCREL;
504
          else
505
            the_insn.reloc = reloc;
506
 
507
          /* the_insn.reloc = insn->reloc;  */
508
#if DEBUG
509
          printf ("    reloc sym=%d\n", the_insn.reloc);
510
          printf ("    BFD_RELOC_NONE=%d\n", BFD_RELOC_NONE);
511
#endif
512
          the_insn.exp = *operand;
513
 
514
          /*  the_insn.reloc_offset = 1;  */
515
          the_insn.pcrel = 1; /* Assume PC-relative jump.  */
516
 
517
          /* FIXME-SOON, Do we figure out whether abs later, after
518
             know sym val?  */
519
          if (reloc == BFD_RELOC_LO16 || reloc == BFD_RELOC_HI16)
520
            the_insn.pcrel = 0;
521
 
522
          encode (insn, &opcode, operand->X_add_number, *args);
523
          continue;
524
        }
525
 
526
      /* Types or values of args don't match.  */
527
      as_bad (_("invalid operands"));
528
      return;
529
    }
530
}
531
 
532
char *
533
md_atof (int type, char * litP, int *  sizeP)
534
{
535
  return ieee_md_atof (type, litP, sizeP, TRUE);
536
}
537
 
538
/* Write out big-endian.  */
539
 
540
void
541
md_number_to_chars (char *buf, valueT val, int n)
542
{
543
  number_to_chars_bigendian (buf, val, n);
544
}
545
 
546
void
547
md_apply_fix (fixS * fixP, valueT * val, segT seg ATTRIBUTE_UNUSED)
548
{
549
  char *buf = fixP->fx_where + fixP->fx_frag->fr_literal;
550
  long t_val;
551
 
552
  t_val = (long) *val;
553
 
554
#if DEBUG
555
  printf ("md_apply_fix val:%x\n", t_val);
556
#endif
557
 
558
  fixP->fx_addnumber = t_val; /* Remember value for emit_reloc.  */
559
 
560
  switch (fixP->fx_r_type)
561
    {
562
    case BFD_RELOC_32:      /* XXXXXXXX pattern in a word.  */
563
#if DEBUG
564
      printf ("reloc_const: val=%x\n", t_val);
565
#endif
566
      buf[0] = t_val >> 24;
567
      buf[1] = t_val >> 16;
568
      buf[2] = t_val >> 8;
569
      buf[3] = t_val;
570
      break;
571
 
572
    case BFD_RELOC_16:      /* XXXX0000 pattern in a word.  */
573
#if DEBUG
574
      printf ("reloc_const: val=%x\n", t_val);
575
#endif
576
      buf[0] = t_val >> 8;
577
      buf[1] = t_val;
578
      break;
579
 
580
    case BFD_RELOC_8:      /* XX000000 pattern in a word.  */
581
#if DEBUG
582
      printf ("reloc_const: val=%x\n", t_val);
583
#endif
584
      buf[0] = t_val;
585
      break;
586
 
587
    case BFD_RELOC_LO16:      /* 0000XXXX pattern in a word.  */
588
#if DEBUG
589
      printf ("reloc_const: val=%x\n", t_val);
590
#endif
591
      buf[2] = t_val >> 8;  /* Holds bits 0000XXXX.  */
592
      buf[3] = t_val;
593
      break;
594
 
595
    case BFD_RELOC_HI16:    /* 0000XXXX pattern in a word.  */
596
#if DEBUG
597
      printf ("reloc_consth: val=%x\n", t_val);
598
#endif
599
      buf[2] = t_val >> 24; /* Holds bits XXXX0000.  */
600
      buf[3] = t_val >> 16;
601
      break;
602
 
603
    case BFD_RELOC_32_GOT_PCREL:  /* 0000XXXX pattern in a word.  */
604
      if (!fixP->fx_done)
605
        ;
606
      else if (fixP->fx_pcrel)
607
        {
608
          long v = t_val >> 28;
609
 
610
          if (v != 0 && v != -1)
611
            as_bad_where (fixP->fx_file, fixP->fx_line,
612
                          _("call/jmp target out of range (2)"));
613
        }
614
      else
615
        /* This case was supposed to be handled in machine_ip.  */
616
        abort ();
617
 
618
      buf[0] |= (t_val >> 26) & 0x03; /* Holds bits 0FFFFFFC of address.  */
619
      buf[1] = t_val >> 18;
620
      buf[2] = t_val >> 10;
621
      buf[3] = t_val >> 2;
622
      break;
623
 
624
    case BFD_RELOC_VTABLE_INHERIT:
625
    case BFD_RELOC_VTABLE_ENTRY:
626
      fixP->fx_done = 0;
627
      break;
628
 
629
    case BFD_RELOC_NONE:
630
    default:
631
      as_bad (_("bad relocation type: 0x%02x"), fixP->fx_r_type);
632
      break;
633
    }
634
 
635
  if (fixP->fx_addsy == (symbolS *) NULL)
636
    fixP->fx_done = 1;
637
}
638
 
639
/* Should never be called for or32.  */
640
 
641
void
642
md_create_short_jump (char *    ptr       ATTRIBUTE_UNUSED,
643
                      addressT  from_addr ATTRIBUTE_UNUSED,
644
                      addressT  to_addr   ATTRIBUTE_UNUSED,
645
                      fragS *   frag      ATTRIBUTE_UNUSED,
646
                      symbolS * to_symbol ATTRIBUTE_UNUSED)
647
{
648
  as_fatal ("or32_create_short_jmp\n");
649
}
650
 
651
/* Should never be called for or32.  */
652
 
653
void
654
md_convert_frag (bfd *   headers ATTRIBUTE_UNUSED,
655
                 segT    seg     ATTRIBUTE_UNUSED,
656
                 fragS * fragP   ATTRIBUTE_UNUSED)
657
{
658
  as_fatal ("or32_convert_frag\n");
659
}
660
 
661
/* Should never be called for or32.  */
662
 
663
void
664
md_create_long_jump (char *    ptr       ATTRIBUTE_UNUSED,
665
                     addressT  from_addr ATTRIBUTE_UNUSED,
666
                     addressT  to_addr   ATTRIBUTE_UNUSED,
667
                     fragS *   frag      ATTRIBUTE_UNUSED,
668
                     symbolS * to_symbol ATTRIBUTE_UNUSED)
669
{
670
  as_fatal ("or32_create_long_jump\n");
671
}
672
 
673
/* Should never be called for or32.  */
674
 
675
int
676
md_estimate_size_before_relax (fragS * fragP   ATTRIBUTE_UNUSED,
677
                               segT    segtype ATTRIBUTE_UNUSED)
678
{
679
  as_fatal ("or32_estimate_size_before_relax\n");
680
  return 0;
681
}
682
 
683
/* Translate internal representation of relocation info to target format.
684
 
685
   On sparc/29k: first 4 bytes are normal unsigned long address, next three
686
   bytes are index, most sig. byte first.  Byte 7 is broken up with
687
   bit 7 as external, bits 6 & 5 unused, and the lower
688
   five bits as relocation type.  Next 4 bytes are long addend.  */
689
/* Thanx and a tip of the hat to Michael Bloom, mb@ttidca.tti.com.  */
690
 
691
#ifdef OBJ_AOUT
692
void
693
tc_aout_fix_to_chars (char *where,
694
                      fixS *fixP,
695
                      relax_addressT segment_address_in_file)
696
{
697
  long r_symbolnum;
698
 
699
#if DEBUG
700
  printf ("tc_aout_fix_to_chars\n");
701
#endif
702
 
703
  know (fixP->fx_r_type < BFD_RELOC_NONE);
704
  know (fixP->fx_addsy != NULL);
705
 
706
  md_number_to_chars
707
    (where,
708
     fixP->fx_frag->fr_address + fixP->fx_where - segment_address_in_file,
709
     4);
710
 
711
  r_symbolnum = (S_IS_DEFINED (fixP->fx_addsy)
712
     ? S_GET_TYPE (fixP->fx_addsy)
713
     : fixP->fx_addsy->sy_number);
714
 
715
  where[4] = (r_symbolnum >> 16) & 0x0ff;
716
  where[5] = (r_symbolnum >> 8) & 0x0ff;
717
  where[6] = r_symbolnum & 0x0ff;
718
  where[7] = (((!S_IS_DEFINED (fixP->fx_addsy)) << 7) & 0x80) | (0 & 0x60) | (fixP->fx_r_type & 0x1F);
719
 
720
  /* Also easy.  */
721
  md_number_to_chars (&where[8], fixP->fx_addnumber, 4);
722
}
723
 
724
#endif /* OBJ_AOUT */
725
 
726
const char *md_shortopts = "";
727
 
728
struct option md_longopts[] =
729
{
730
  { NULL, no_argument, NULL, 0 }
731
};
732
size_t md_longopts_size = sizeof (md_longopts);
733
 
734
int
735
md_parse_option (int c ATTRIBUTE_UNUSED, char * arg ATTRIBUTE_UNUSED)
736
{
737
  return 0;
738
}
739
 
740
void
741
md_show_usage (FILE * stream ATTRIBUTE_UNUSED)
742
{
743
}
744
 
745
/* This is called when a line is unrecognized.  This is used to handle
746
   definitions of or32 style local labels.  */
747
 
748
int
749
or32_unrecognized_line (int c)
750
{
751
  int lab;
752
  char *s;
753
 
754
  if (c != '$'
755
      || ! ISDIGIT ((unsigned char) input_line_pointer[0]))
756
    return 0;
757
 
758
  s = input_line_pointer;
759
 
760
  lab = 0;
761
  while (ISDIGIT ((unsigned char) *s))
762
    {
763
      lab = lab * 10 + *s - '0';
764
      ++s;
765
    }
766
 
767
  if (*s != ':')
768
    /* Not a label definition.  */
769
    return 0;
770
 
771
  if (dollar_label_defined (lab))
772
    {
773
      as_bad (_("label \"$%d\" redefined"), lab);
774
      return 0;
775
    }
776
 
777
  define_dollar_label (lab);
778
  colon (dollar_label_name (lab, 0));
779
  input_line_pointer = s + 1;
780
 
781
  return 1;
782
}
783
 
784
/* Default the values of symbols known that should be "predefined".  We
785
   don't bother to predefine them unless you actually use one, since there
786
   are a lot of them.  */
787
 
788
symbolS *
789
md_undefined_symbol (char *name ATTRIBUTE_UNUSED)
790
{
791
  return NULL;
792
}
793
 
794
/* Parse an operand that is machine-specific.  */
795
 
796
void
797
md_operand (expressionS *expressionP)
798
{
799
#if DEBUG
800
  printf ("  md_operand(input_line_pointer = %s)\n", input_line_pointer);
801
#endif
802
 
803
  if (input_line_pointer[0] == REGISTER_PREFIX && input_line_pointer[1] == 'r')
804
    {
805
      /* We have a numeric register expression.  No biggy.  */
806
      input_line_pointer += 2;  /* Skip %r */
807
      (void) expression (expressionP);
808
 
809
      if (expressionP->X_op != O_constant
810
          || expressionP->X_add_number > 255)
811
        as_bad (_("Invalid expression after %%%%\n"));
812
      expressionP->X_op = O_register;
813
    }
814
  else if (input_line_pointer[0] == '&')
815
    {
816
      /* We are taking the 'address' of a register...this one is not
817
         in the manual, but it *is* in traps/fpsymbol.h!  What they
818
         seem to want is the register number, as an absolute number.  */
819
      input_line_pointer++; /* Skip & */
820
      (void) expression (expressionP);
821
 
822
      if (expressionP->X_op != O_register)
823
        as_bad (_("invalid register in & expression"));
824
      else
825
        expressionP->X_op = O_constant;
826
    }
827
  else if (input_line_pointer[0] == '$'
828
           && ISDIGIT ((unsigned char) input_line_pointer[1]))
829
    {
830
      long lab;
831
      char *name;
832
      symbolS *sym;
833
 
834
      /* This is a local label.  */
835
      ++input_line_pointer;
836
      lab = (long) get_absolute_expression ();
837
 
838
      if (dollar_label_defined (lab))
839
        {
840
          name = dollar_label_name (lab, 0);
841
          sym = symbol_find (name);
842
        }
843
      else
844
        {
845
          name = dollar_label_name (lab, 1);
846
          sym = symbol_find_or_make (name);
847
        }
848
 
849
      expressionP->X_op = O_symbol;
850
      expressionP->X_add_symbol = sym;
851
      expressionP->X_add_number = 0;
852
    }
853
  else if (input_line_pointer[0] == '$')
854
    {
855
      char *s;
856
      char type;
857
      int fieldnum, fieldlimit;
858
      LITTLENUM_TYPE floatbuf[8];
859
 
860
      /* $float(), $doubleN(), or $extendN() convert floating values
861
         to integers.  */
862
      s = input_line_pointer;
863
 
864
      ++s;
865
 
866
      fieldnum = 0;
867
      if (strncmp (s, "double", sizeof "double" - 1) == 0)
868
        {
869
          s += sizeof "double" - 1;
870
          type = 'd';
871
          fieldlimit = 2;
872
        }
873
      else if (strncmp (s, "float", sizeof "float" - 1) == 0)
874
        {
875
          s += sizeof "float" - 1;
876
          type = 'f';
877
          fieldlimit = 1;
878
        }
879
      else if (strncmp (s, "extend", sizeof "extend" - 1) == 0)
880
        {
881
          s += sizeof "extend" - 1;
882
          type = 'x';
883
          fieldlimit = 4;
884
        }
885
      else
886
        return;
887
 
888
      if (ISDIGIT (*s))
889
        {
890
          fieldnum = *s - '0';
891
          ++s;
892
        }
893
      if (fieldnum >= fieldlimit)
894
        return;
895
 
896
      SKIP_WHITESPACE ();
897
      if (*s != '(')
898
        return;
899
      ++s;
900
      SKIP_WHITESPACE ();
901
 
902
      s = atof_ieee (s, type, floatbuf);
903
      if (s == NULL)
904
        return;
905
      s = s;
906
 
907
      SKIP_WHITESPACE ();
908
      if (*s != ')')
909
        return;
910
      ++s;
911
      SKIP_WHITESPACE ();
912
 
913
      input_line_pointer = s;
914
      expressionP->X_op = O_constant;
915
      expressionP->X_unsigned = 1;
916
      expressionP->X_add_number = ((floatbuf[fieldnum * 2]
917
                                    << LITTLENUM_NUMBER_OF_BITS)
918
                                   + floatbuf[fieldnum * 2 + 1]);
919
    }
920
}
921
 
922
/* Round up a section size to the appropriate boundary.  */
923
 
924
valueT
925
md_section_align (segT segment ATTRIBUTE_UNUSED, valueT size ATTRIBUTE_UNUSED)
926
{
927
  return size;      /* Byte alignment is fine.  */
928
}
929
 
930
/* Exactly what point is a PC-relative offset relative TO?
931
   On the 29000, they're relative to the address of the instruction,
932
   which we have set up as the address of the fixup too.  */
933
 
934
long
935
md_pcrel_from (fixS *fixP)
936
{
937
  return fixP->fx_where + fixP->fx_frag->fr_address;
938
}
939
 
940
/* Generate a reloc for a fixup.  */
941
 
942
arelent *
943
tc_gen_reloc (asection *seg ATTRIBUTE_UNUSED, fixS *fixp)
944
{
945
  arelent *reloc;
946
 
947
  reloc = xmalloc (sizeof (arelent));
948
  reloc->sym_ptr_ptr = xmalloc (sizeof (asymbol *));
949
  *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
950
  reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
951
  /*  reloc->address = fixp->fx_frag->fr_address + fixp->fx_where + fixp->fx_addnumber;*/
952
  reloc->howto = bfd_reloc_type_lookup (stdoutput, fixp->fx_r_type);
953
 
954
  if (reloc->howto == (reloc_howto_type *) NULL)
955
    {
956
      as_bad_where (fixp->fx_file, fixp->fx_line,
957
                    _("reloc %d not supported by object file format"),
958
                    (int) fixp->fx_r_type);
959
      return NULL;
960
    }
961
 
962
  if (fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
963
    reloc->address = fixp->fx_offset;
964
 
965
  reloc->addend = fixp->fx_addnumber;
966
  return reloc;
967
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.