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

Subversion Repositories open8_urisc

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

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

Line No. Rev Author Line
1 16 khays
/* tc-open8.c -- Assembler code for the Open8/V8/ARClite MCU
2
 
3
   Copyright 1999, 2000, 2001, 2002, 2004, 2005, 2006, 2007, 2008, 2009,
4
   2010, 2011  Free Software Foundation, Inc.
5
 
6
   Contributed by Kirk Hays <khays@hayshaus.com>
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
#include "as.h"
26
#include "safe-ctype.h"
27
#include "subsegs.h"
28
 
29
struct open8_opcodes_s
30
{
31
  char *        name;
32
  char *        constraints;
33
  int           insn_size;              /* In bytes.  */
34
  int           isa;
35
  unsigned long long bin_opcode;
36
};
37
 
38
#define OPEN8_INSN(NAME, CONSTR, OPCODE, SIZE, ISA, BIN, MASK)  \
39
  {#NAME, CONSTR, SIZE, ISA, BIN},
40
 
41
struct open8_opcodes_s open8_opcodes[] =
42
  {
43
#include "opcode/open8.h"
44
    {NULL, NULL, 0, 0, 0}
45
  };
46
 
47
const char comment_chars[] = ";";
48
const char line_comment_chars[] = "#";
49
const char line_separator_chars[] = "$";
50
 
51
const char *md_shortopts = "m:";
52
struct mcu_type_s
53
{
54
  char *name;
55
  int isa;
56
  int mach;
57
};
58
 
59
static struct mcu_type_s mcu_types[] =
60
  {
61
    {"open8",      OPEN8_ISA_OPEN8,      bfd_mach_open8_1},
62
    {NULL, 0, 0}
63
  };
64
 
65
/* Current MCU type.  */
66
static struct mcu_type_s default_mcu = {"open8",
67
                                        OPEN8_ISA_OPEN8,
68
                                        bfd_mach_open8_1};
69
static struct mcu_type_s * open8_mcu = &default_mcu;
70
 
71
/* OPEN8 target-specific switches.  */
72
struct open8_opt_s
73
{
74
  int all_opcodes; /* -mall-opcodes: accept all known OPEN8 opcodes.  */
75
};
76
 
77
static struct open8_opt_s open8_opt = { 0 };
78
 
79
const char EXP_CHARS[] = "eE";
80
const char FLT_CHARS[] = "dD";
81
 
82
static void open8_set_arch (int);
83
 
84
/* The target specific pseudo-ops which we support.  */
85
const pseudo_typeS md_pseudo_table[] =
86
  {
87
    {"arch", open8_set_arch,    0},
88
    { NULL,     NULL,           0}
89
  };
90
 
91
#define EXP_MOD_NAME(i)       (exp_mod[i].name)
92
#define EXP_MOD_RELOC(i)      (exp_mod[i].reloc)
93
#define EXP_MOD_NEG_RELOC(i)  (exp_mod[i].neg_reloc)
94
 
95
struct exp_mod_s
96
{
97
  char *                    name;
98
  bfd_reloc_code_real_type  reloc;
99
  bfd_reloc_code_real_type  neg_reloc;
100
};
101
 
102
static struct exp_mod_s exp_mod[] =
103
  {
104
    {"hi8", BFD_RELOC_OPEN8_HI8_LDI, BFD_RELOC_OPEN8_HI8_LDI_NEG},
105
    {"lo8", BFD_RELOC_OPEN8_LO8_LDI, BFD_RELOC_OPEN8_LO8_LDI_NEG},
106
  };
107
 
108
/* A union used to store indicies into the exp_mod[] array
109
   in a hash table which expects void * data types.  */
110
typedef union
111
{
112
  void * ptr;
113
  int    index;
114
} mod_index;
115
 
116
/* Opcode hash table.  */
117
static struct hash_control *open8_hash;
118
 
119
/* Reloc modifiers hash control (hi8,lo8).  */
120
static struct hash_control *open8_mod_hash;
121
 
122
#define OPTION_MMCU 'm'
123
enum options
124
  {
125
    OPTION_ALL_OPCODES = OPTION_MD_BASE + 1
126
  };
127
 
128
struct option md_longopts[] =
129
  {
130
    { "mmcu",   required_argument, NULL, OPTION_MMCU        },
131
    { "mall-opcodes", no_argument, NULL, OPTION_ALL_OPCODES },
132
    { NULL, no_argument, NULL, 0 }
133
  };
134
 
135
size_t md_longopts_size = sizeof (md_longopts);
136
 
137
/* Display nicely formatted list of known MCU names.  */
138
 
139
static void
140
show_mcu_list (FILE *stream)
141
{
142
  int i, x;
143
 
144
  fprintf (stream, _("Known MCU names:"));
145
  x = 1000;
146
 
147
  for (i = 0; mcu_types[i].name; i++)
148
    {
149
      int len = strlen (mcu_types[i].name);
150
 
151
      x += len + 1;
152
 
153
      if (x < 75)
154
        fprintf (stream, " %s", mcu_types[i].name);
155
      else
156
        {
157
          fprintf (stream, "\n  %s", mcu_types[i].name);
158
          x = len + 2;
159
        }
160
    }
161
 
162
  fprintf (stream, "\n");
163
}
164
 
165
static inline char *
166
skip_space (char *s)
167
{
168
  while (*s == ' ' || *s == '\t')
169
    ++s;
170
  return s;
171
}
172
 
173
/* Extract one word from FROM and copy it to TO.  */
174
 
175
static char *
176
extract_word (char *from, char *to, int limit)
177
{
178
  char *op_end;
179
  int size = 0;
180
 
181
  /* Drop leading whitespace.  */
182
  from = skip_space (from);
183
  *to = 0;
184
 
185
  /* Find the op code end.  */
186
  for (op_end = from; *op_end != 0 && is_part_of_name (*op_end);)
187
    {
188
      to[size++] = *op_end++;
189
      if (size + 1 >= limit)
190
        break;
191
    }
192
 
193
  to[size] = 0;
194
  return op_end;
195
}
196
 
197
int
198
md_estimate_size_before_relax (fragS *fragp ATTRIBUTE_UNUSED,
199
                               asection *seg ATTRIBUTE_UNUSED)
200
{
201
  abort ();
202
  return 0;
203
}
204
 
205
void
206
md_show_usage (FILE *stream)
207
{
208
  fprintf (stream,
209
           _("OPEN8 options:\n"
210
             "  -mmcu=[open8-name] select microcontroller variant\n"
211
             "                [open8-name] can be:\n"
212
             "                    open8   - open8 RISC from `OpenCores.org'.\n"
213
             ""));
214
  fprintf (stream,
215
           _("  -mall-opcodes accept all opcodes\n"
216
             ""));
217
  show_mcu_list (stream);
218
}
219
 
220
static void
221
open8_opcode_hash (void)
222
{
223
 
224
  struct open8_opcodes_s *opcode;
225
 
226
  /* Discard any prior opcode hash table.  */
227
  if (open8_hash)
228
    {
229
      hash_die (open8_hash);
230
    }
231
 
232
  /* Create a new opcode hash table.  */
233
  open8_hash = hash_new ();
234
 
235
  /* Insert unique names into hash table.  This hash table then provides a
236
     quick index to the first opcode with a particular name in the opcode
237
     table.  */
238
  for (opcode = open8_opcodes; opcode->name; opcode++)
239
    {
240
      if (open8_opt.all_opcodes || open8_mcu->isa & opcode->isa)
241
        {
242
          hash_insert (open8_hash, opcode->name, (char *) opcode);
243
        }
244
    }
245
}
246
 
247
static void
248
open8_set_arch (int dummy ATTRIBUTE_UNUSED)
249
{
250
  char str[20];
251
 
252
  input_line_pointer = extract_word (input_line_pointer, str, 20);
253
  md_parse_option (OPTION_MMCU, str);
254
  bfd_set_arch_mach (stdoutput, TARGET_ARCH, open8_mcu->mach);
255
 
256
  /* Rebuild the opcode hash.  */
257
  open8_opcode_hash ();
258
}
259
 
260
int
261
md_parse_option (int c, char *arg)
262
{
263
  switch (c)
264
    {
265
    case OPTION_MMCU:
266
      {
267
        int i;
268
        char *s = alloca (strlen (arg) + 1);
269
 
270
        /* Accept mixed case in options, force to lower case
271
         * to simplify recognition.
272
         */
273
        {
274
          char *t = s;
275
          char *arg1 = arg;
276
 
277
          do
278
            {
279
              *t = TOLOWER (*arg1++);
280
            }
281
          while (*t++);
282
        }
283
 
284
        for (i = 0; mcu_types[i].name; ++i)
285
          {
286
            if (strcmp (mcu_types[i].name, s) == 0)
287
              break;
288
          }
289
 
290
        if (!mcu_types[i].name)
291
          {
292
            show_mcu_list (stderr);
293
            as_fatal (_("unknown MCU: %s\n"), arg);
294
          }
295
 
296
        /* It is OK to redefine mcu type within the same open8 bfd machine
297
           type - this for allows passing -mmcu=... via gcc ASM_SPEC as well
298
           as `.arch' in the asm output at the same time.  */
299
        if (open8_mcu == &default_mcu || open8_mcu->mach == mcu_types[i].mach)
300
          {
301
            open8_mcu = &mcu_types[i];
302
          }
303
        else
304
          {
305
            as_fatal (_("redefinition of mcu type `%s' to `%s'"),
306
                      open8_mcu->name, mcu_types[i].name);
307
          }
308
        return 1;
309
      }
310
    case OPTION_ALL_OPCODES:
311
      {
312
        open8_opt.all_opcodes = 1;
313
        return 1;
314
      }
315
    }
316
 
317
  return 0;
318
}
319
 
320
symbolS *
321
md_undefined_symbol (char *name ATTRIBUTE_UNUSED)
322
{
323
  return NULL;
324
}
325
 
326
char *
327
md_atof (int type, char *litP, int *sizeP)
328
{
329
  return ieee_md_atof (type, litP, sizeP, FALSE);
330
}
331
 
332
void
333
md_convert_frag (bfd *abfd ATTRIBUTE_UNUSED,
334
                 asection *sec ATTRIBUTE_UNUSED,
335
                 fragS *fragP ATTRIBUTE_UNUSED)
336
{
337
  abort ();
338
}
339
 
340
void
341
md_begin (void)
342
{
343
  unsigned int i;
344
 
345
  /* Setup the valid opcodes for this architecture.  */
346
  open8_opcode_hash ();
347
 
348
  open8_mod_hash = hash_new ();
349
 
350
  for (i = 0; i < ARRAY_SIZE (exp_mod); ++i)
351
    {
352
      mod_index m;
353
 
354
      m.index = i + 10;
355
      hash_insert (open8_mod_hash, EXP_MOD_NAME (i), m.ptr);
356
    }
357
 
358
  bfd_set_arch_mach (stdoutput, TARGET_ARCH, open8_mcu->mach);
359
}
360
 
361
/* Resolve STR as an unsigned constant expression and return the result.
362
   If result greater than MAX then error.  */
363
 
364
static unsigned int
365
open8_get_uconstant (char *str, int max)
366
{
367
  expressionS ex;
368
 
369
  str = skip_space (str);
370
  input_line_pointer = str;
371
  expression (& ex);
372
 
373
  if (ex.X_op != O_constant)
374
    as_bad (_("constant value required"));
375
 
376
  if (ex.X_add_number > max || ex.X_add_number < 0)
377
    as_bad (_("number must be positive and less than %d"), max + 1);
378
 
379
  return ex.X_add_number;
380
}
381
 
382
/* Parse ordinary expression.  */
383
 
384
static char *
385
parse_exp (char *s, expressionS *op)
386
{
387
  input_line_pointer = s;
388
  expression (op);
389
  if (op->X_op == O_absent)
390
    as_bad (_("missing operand"));
391
  return input_line_pointer;
392
}
393
 
394
/* Parse special expressions (needed for LDI command):
395
   xx8 (address)
396
   xx8 (-address)
397
   where xx is: hi, lo.  */
398
 
399
static bfd_reloc_code_real_type
400
open8_ldi_expression (expressionS *exp)
401
{
402
  char *str = input_line_pointer;
403
  char *tmp;
404
  char op[8];
405
  int mod;
406
 
407
  tmp = str;
408
 
409
  str = extract_word (str, op, sizeof (op));
410
 
411
  if (op[0])
412
    {
413
      mod_index m;
414
 
415
      m.ptr = hash_find (open8_mod_hash, op);
416
      mod = m.index;
417
 
418
      if (mod)
419
        {
420
          int closes = 0;
421
 
422
          mod -= 10;
423
          str = skip_space (str);
424
 
425
          if (*str == '(')
426
            {
427
              bfd_reloc_code_real_type  reloc_to_return;
428
              int neg_p = 0;
429
 
430
              ++str;
431
 
432
              if (*str == '-' && *(str + 1) == '(')
433
                {
434
                  neg_p ^= 1;
435
                  ++closes;
436
                  str += 2;
437
                }
438
 
439
              input_line_pointer = str;
440
              expression (exp);
441
 
442
              do
443
                {
444
                  if (*input_line_pointer != ')')
445
                    {
446
                      as_bad (_("`)' required"));
447
                      break;
448
                    }
449
                  input_line_pointer++;
450
                }
451
              while (closes--);
452
 
453
              reloc_to_return =
454
                neg_p ? EXP_MOD_NEG_RELOC (mod) : EXP_MOD_RELOC (mod);
455
              return reloc_to_return;
456
            }
457
        }
458
    }
459
 
460
  input_line_pointer = tmp;
461
  expression (exp);
462
 
463
  /* Warn about expressions that fail to use lo8 ().  */
464
  if (exp->X_op == O_constant)
465
    {
466
      int x = exp->X_add_number;
467
 
468
      if (x < -128 || x > 255)
469
        as_warn (_("constant out of 8-bit range: %d"), x);
470
    }
471
 
472
  return BFD_RELOC_OPEN8_LO8_LDI;
473
}
474
 
475
/* Parse one instruction operand.
476
   Return operand bitmask.  Also fixups can be generated.  */
477
 
478
static unsigned long long
479
open8_operand (int where,
480
               char *op,
481
               char **line)
482
{
483
  expressionS op_expr;
484
  unsigned long long op_mask = 0;
485
  char *str = skip_space (*line);
486
 
487
  switch (*op)
488
    {
489
      /* Any register operand.  */
490
    case 'r':
491
    case 'e':
492
      {
493
        if (*str == 'r' || *str == 'R')
494
          {
495
            char r_name[20];
496
            str = extract_word (str, r_name, sizeof (r_name));
497
            op_mask = 0xff;
498
            if (ISDIGIT (r_name[1]))
499
              {
500
                if (r_name[2] == '\0')
501
                  op_mask = r_name[1] - '0';
502
              }
503
          }
504
 
505
        if (op_mask <= 7)
506
          {
507
            switch (*op)
508
              {
509
              case 'e':
510
                /* Enforce even register requirement.  */
511
                if (op_mask & 1)
512
                  as_bad (_("register r0, r2, r4, or r6 required"));
513
                break;
514
 
515
              case 'r':
516
                break;
517
 
518
              }
519
            break;
520
          }
521
 
522
        as_bad (_("register name from r0 to r7 required"));
523
      }
524
    break;
525
 
526
    /* Unsigned offset expression, eight bits, range 0 to 255.  */
527
    case 'u':
528
      {
529
        str = parse_exp (str, &op_expr);
530
        fix_new_exp (frag_now, where + 1, 1,
531
                     &op_expr, FALSE, BFD_RELOC_8);
532
      }
533
      break;
534
 
535
      /* Signed pc-relative offset expression, eight bits,
536
         range -128 to 127.  */
537
    case 's':
538
      {
539
        str = parse_exp (str, &op_expr);
540
        fix_new_exp (frag_now, where + 1, 1,
541
                     &op_expr, FALSE, BFD_RELOC_OPEN8_PCREL);
542
      }
543
      break;
544
 
545
      /* Parse expression for the ldi instruction.  */
546
    case 'i':
547
      {
548
        bfd_reloc_code_real_type r_type;
549
 
550
        input_line_pointer = str;
551
        r_type = open8_ldi_expression (&op_expr);
552
        str = input_line_pointer;
553
        fix_new_exp (frag_now, where+1, 1,
554
                     &op_expr, FALSE, r_type);
555
      }
556
      break;
557
 
558
      /* Unsigned constant in the range 0..7.  */
559
    case 'n':
560
    case 'b':
561
      {
562
        unsigned int x;
563
 
564
        x = open8_get_uconstant (str, 7);
565
        str = input_line_pointer;
566
        op_mask |= x;
567
      }
568
    break;
569
 
570
    /* Unsigned 16 bit address expression for JMP or JSR.  */
571
    case 'h':
572
      {
573
        str = parse_exp (str, &op_expr);
574
        fix_new_exp (frag_now, where + 1, 2,
575
                     &op_expr, FALSE, BFD_RELOC_OPEN8_CALL);
576
      }
577
      break;
578
 
579
    /* Unsigned 16 bit address expression for composed JMP variant.  */
580
    case 'H':
581
      {
582
        str = parse_exp (str, &op_expr);
583
        fix_new_exp (frag_now, where + 3, 2,
584
                     &op_expr, FALSE, BFD_RELOC_OPEN8_CALL);
585
      }
586
      break;
587
 
588
    /* Unsigned 16 bit address expression for load or store instructions.  */
589
    case 'M':
590
      {
591
        str = parse_exp (str, &op_expr);
592
        fix_new_exp (frag_now, where + 1, 2,
593
                     &op_expr, FALSE, BFD_RELOC_16);
594
      }
595
      break;
596
 
597
      /* Autoincrement operator on index.  */
598
    case 'a':
599
      {
600
        if (str[0] == '+' && str[1] == '+')
601
          {
602
            str = skip_space (str + 2);
603
            op_mask = 0x1;
604
          }
605
      }
606
      break;
607
 
608
    default:
609
      as_bad (_("unknown constraint `%c'"), *op);
610
    }
611
 
612
  *line = str;
613
  return op_mask;
614
}
615
 
616
/* Parse instruction operands.
617
   Return binary opcode.  */
618
 
619
static unsigned long long
620
open8_operands (struct open8_opcodes_s *opcode, char **line)
621
{
622
  char *op = opcode->constraints;
623
  unsigned long long bin = opcode->bin_opcode;
624
  unsigned long long reg1 = 0, reg2 = 0, reg3 = 0;
625
  char *frag = frag_more (opcode->insn_size);
626
  char *str = *line;
627
  int where = frag - frag_now->fr_literal;
628
 
629
  /* Opcodes optionally have operands.  */
630
  /* The operand patterns are:
631
     <empty> |
632
     op1 |
633
     op1 op2 |
634
     op1,op2 |
635
     op1 op2,op3
636
  */
637
  if (*op)
638
    {
639
      /* Parse first operand.  */
640
      reg1 = open8_operand (where, op, &str);
641
      ++op;
642
 
643
      /* Parse second operand, if present.  */
644
      if (*op)
645
        {
646
          str = skip_space (str);
647
 
648
          /* require a comma, if present in the pattern.  */
649
          if (*op == ',')
650
            {
651
              ++op;
652
              if (*str++ != ',')
653
                {
654
                  as_bad (_("`,' required"));
655
                }
656
              str = skip_space (str);
657
            }
658
 
659
          reg2 = open8_operand (where, op, &str);
660
          ++op;
661
        }
662
 
663
      /* Parse third operand, if present.  */
664
      if (*op)
665
        {
666
 
667
          str = skip_space (str);
668
 
669
          /* require a comma, if present in the pattern.  */
670
          if (*op == ',')
671
            {
672
              ++op;
673
              if (*str++ != ',')
674
                {
675
                  as_bad (_("`,' required"));
676
                }
677
              str = skip_space (str);
678
            }
679
 
680
          reg3 = open8_operand (where, op, &str);
681
        }
682
    }
683
 
684
  bin |= reg1 | reg2 | reg3;
685
 
686
  unsigned long long scr = bin;
687
 
688
  /* Copy the instruction bytes to the frag, supporting
689
   * only instructions sizes that are defined for the OPEN8.
690
   * NB: note the fallthroughs.  */
691
  switch (opcode->insn_size)
692
    {
693
    case 5:
694
      *frag++ = (unsigned char)scr;
695
      scr >>= 8;
696
      *frag++ = (unsigned char)scr;
697
      scr >>= 8;
698
      /* FALLTHROUGH.  */
699
    case 3:
700
      *frag++ = (unsigned char)scr;
701
      scr >>= 8;
702
      /* FALLTHROUGH.  */
703
    case 2:
704
      *frag++ = (unsigned char)scr;
705
      scr >>= 8;
706
      /* FALLTHROUGH.  */
707
    case 1:
708
      *frag++ = (unsigned char)scr;
709
      break;
710
 
711
    default:
712
      as_fatal (_("unsupported instruction size: %d\n"), opcode->insn_size);
713
    }
714
 
715
  *line = str;
716
  return bin;
717
}
718
 
719
/* GAS will call this function for each section at the end of the assembly,
720
   to permit the CPU backend to adjust the alignment of a section.  */
721
 
722
valueT
723
md_section_align (asection *seg, valueT addr)
724
{
725
  int align = bfd_get_section_alignment (stdoutput, seg);
726
  return ((addr + (1 << align) - 1) & (-1 << align));
727
}
728
 
729
/* If you define this macro, it should return the offset between the
730
   address of a PC relative fixup and the position from which the PC
731
   relative adjustment should be made.  On many processors, the base
732
   of a PC relative instruction is the next instruction, so this
733
   macro would return the length of an instruction.  */
734
 
735
long
736
md_pcrel_from_section (fixS *fixp, segT sec)
737
{
738
  if (fixp->fx_addsy != (symbolS *) NULL
739
      && (!S_IS_DEFINED (fixp->fx_addsy)
740
          || (S_GET_SEGMENT (fixp->fx_addsy) != sec)))
741
    return 0;
742
 
743
  return fixp->fx_frag->fr_address + fixp->fx_where;
744
}
745
 
746
/* GAS will call this for each fixup.  It should store the correct
747
   value in the object file.  */
748
 
749
void
750
md_apply_fix (fixS *fixP, valueT * valP, segT seg)
751
{
752
  unsigned char *where;
753 165 khays
#if 0
754 16 khays
  unsigned long insn;
755 165 khays
#endif
756 16 khays
  long value = *valP;
757
 
758
  if (fixP->fx_addsy == (symbolS *) NULL)
759
    fixP->fx_done = 1;
760
 
761
  else if (fixP->fx_pcrel)
762
    {
763
      segT s = S_GET_SEGMENT (fixP->fx_addsy);
764
 
765
      if (s == seg || s == absolute_section)
766
        {
767
          value += S_GET_VALUE (fixP->fx_addsy);
768
          fixP->fx_done = 1;
769
        }
770
    }
771
 
772
  /* We don't actually support subtracting a symbol.  */
773
  if (fixP->fx_subsy != (symbolS *) NULL)
774
    as_bad_where (fixP->fx_file, fixP->fx_line, _("expression too complex"));
775
 
776
  switch (fixP->fx_r_type)
777
    {
778
    default:
779
      fixP->fx_no_overflow = 1;
780
      break;
781
    case BFD_RELOC_32:
782
    case BFD_RELOC_16:
783
    case BFD_RELOC_OPEN8_CALL:
784
      break;
785
    }
786
 
787
  if (fixP->fx_done)
788
    {
789
      /* Fetch the instruction, insert the fully resolved operand
790
         value, and stuff the instruction back again.  */
791
      where = (unsigned char *) fixP->fx_frag->fr_literal + fixP->fx_where;
792 165 khays
#if 0
793 16 khays
      insn = bfd_getl16 (where);
794 165 khays
#endif
795 16 khays
      switch (fixP->fx_r_type)
796
        {
797
        case BFD_RELOC_32:
798
          bfd_putl16 ((bfd_vma) value, where);
799
          break;
800
 
801
        case BFD_RELOC_16:
802
          if (value > 65535 || value < -32768)
803
            {
804
              as_warn_where (fixP->fx_file, fixP->fx_line,
805
                             _("operand out of range: %ld"), value);
806
            }
807
          bfd_putl16 ((bfd_vma) value, where);
808
          break;
809
 
810
        case BFD_RELOC_8:
811
          if (value > 255 || value < -128)
812
            {
813
              as_warn_where (fixP->fx_file, fixP->fx_line,
814
                             _("operand out of range: %ld"), value);
815
            }
816
          *where = value;
817
          break;
818
 
819
        case BFD_RELOC_OPEN8_LO8_LDI:
820
          *where = value;
821
          break;
822
 
823
        case BFD_RELOC_OPEN8_HI8_LDI:
824
          *where = value >> 8;
825
          break;
826
 
827
        case BFD_RELOC_OPEN8_LO8_LDI_NEG:
828
          *where = -value;
829
          break;
830
 
831
        case BFD_RELOC_OPEN8_HI8_LDI_NEG:
832
          *where = -value >> 8;
833
          break;
834
 
835
        case BFD_RELOC_OPEN8_CALL:
836
          {
837
            if (value > 65535 || value < -32768)
838
              {
839
                as_warn_where (fixP->fx_file, fixP->fx_line,
840
                               _("operand out of range: %ld"), value);
841
              }
842
            bfd_putl16 ((bfd_vma) value, where);
843
          }
844
          break;
845
 
846
        case BFD_RELOC_OPEN8_PCREL:
847
 
848
          if ((value < -128) || (value > 127))
849
            {
850
              as_bad_where (fixP->fx_file, fixP->fx_line,
851
                            _("operand out of range[-128..127]: %ld"), value);
852
            }
853
          *where = value;
854
          break;
855
 
856
        default:
857
          as_fatal (_("line %d: unknown relocation type: 0x%x"),
858
                    fixP->fx_line, fixP->fx_r_type);
859
          break;
860
        }
861
    }
862
  else
863
    {
864
      switch ((int) fixP->fx_r_type)
865
        {
866
        case -BFD_RELOC_OPEN8_HI8_LDI_NEG:
867
        case -BFD_RELOC_OPEN8_HI8_LDI:
868
        case -BFD_RELOC_OPEN8_LO8_LDI_NEG:
869
        case -BFD_RELOC_OPEN8_LO8_LDI:
870
          as_bad_where (fixP->fx_file, fixP->fx_line,
871
                        _("only constant expression allowed"));
872
          fixP->fx_done = 1;
873
          break;
874
        default:
875
          break;
876
        }
877
    }
878
}
879
 
880
/* GAS will call this to generate a reloc, passing the resulting reloc
881
   to `bfd_install_relocation'.  This currently works poorly, as
882
   `bfd_install_relocation' often does the wrong thing, and instances of
883
   `tc_gen_reloc' have been written to work around the problems, which
884
   in turns makes it difficult to fix `bfd_install_relocation'.  */
885
 
886
/* If while processing a fixup, a reloc really needs to be created
887
   then it is done here.  */
888
 
889
arelent *
890
tc_gen_reloc (asection *seg ATTRIBUTE_UNUSED,
891
              fixS *fixp)
892
{
893
  arelent *reloc;
894
 
895
  if (fixp->fx_addsy && fixp->fx_subsy)
896
    {
897
      long value = 0;
898
 
899
      if ((S_GET_SEGMENT (fixp->fx_addsy) != S_GET_SEGMENT (fixp->fx_subsy))
900
          || S_GET_SEGMENT (fixp->fx_addsy) == undefined_section)
901
        {
902
          as_bad_where (fixp->fx_file, fixp->fx_line,
903
                        "Difference of symbols in different sections"
904
                        " is not supported");
905
          return NULL;
906
        }
907
 
908
      /* We are dealing with two symbols defined in the same section.
909
         Let us fix-up them here.  */
910
      value += S_GET_VALUE (fixp->fx_addsy);
911
      value -= S_GET_VALUE (fixp->fx_subsy);
912
 
913
      /* When fx_addsy and fx_subsy both are zero, md_apply_fix
914
         only takes it's second operands for the fixup value.  */
915
      fixp->fx_addsy = NULL;
916
      fixp->fx_subsy = NULL;
917
      md_apply_fix (fixp, (valueT *) &value, NULL);
918
 
919
      return NULL;
920
    }
921
 
922
  reloc = xmalloc (sizeof (arelent));
923
 
924
  reloc->sym_ptr_ptr = xmalloc (sizeof (asymbol *));
925
  *reloc->sym_ptr_ptr = symbol_get_bfdsym (fixp->fx_addsy);
926
 
927
  reloc->address = fixp->fx_frag->fr_address + fixp->fx_where;
928
  reloc->howto = bfd_reloc_type_lookup (stdoutput, fixp->fx_r_type);
929
  if (reloc->howto == (reloc_howto_type *) NULL)
930
    {
931
      as_bad_where (fixp->fx_file, fixp->fx_line,
932
                    _("reloc %d not supported by object file format"),
933
                    (int) fixp->fx_r_type);
934
      return NULL;
935
    }
936
 
937
  if (fixp->fx_r_type == BFD_RELOC_VTABLE_INHERIT
938
      || fixp->fx_r_type == BFD_RELOC_VTABLE_ENTRY)
939
    reloc->address = fixp->fx_offset;
940
 
941
  reloc->addend = fixp->fx_offset;
942
 
943
  return reloc;
944
}
945
 
946
void
947
md_assemble (char *str)
948
{
949
  struct open8_opcodes_s *opcode;
950
  char op[11];
951
 
952
  str = skip_space (extract_word (str, op, sizeof (op)));
953
 
954
  if (!op[0])
955
    as_bad (_("can't find opcode "));
956
 
957
  opcode = (struct open8_opcodes_s *) hash_find (open8_hash, op);
958
 
959
  if (opcode == NULL)
960
    {
961
      as_bad (_("unknown opcode `%s'"), op);
962
      return;
963
    }
964
 
965
  /* Check to see if opcode allowed.  */
966
  if (!open8_opt.all_opcodes
967
      && ((opcode->isa & open8_mcu->isa) != open8_mcu->isa))
968
    {
969
      as_bad (_("illegal opcode \"%s\" for mcu %s"),
970
              opcode->name,
971
              open8_mcu->name);
972
    }
973
 
974
  dwarf2_emit_insn (0);
975
 
976
  /* We used to set input_line_pointer to the result of get_operands,
977
     but that is wrong.  Our caller assumes we don't change it.  */
978
  {
979
    char *t = input_line_pointer;
980
 
981
    open8_operands (opcode, &str);
982
    if (*skip_space (str))
983
      as_bad (_("garbage at end of line"));
984
    input_line_pointer = t;
985
  }
986
}
987
 

powered by: WebSVN 2.1.0

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