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

Subversion Repositories scarts

[/] [scarts/] [trunk/] [toolchain/] [scarts-binutils/] [binutils-2.19.1/] [cgen/] [cpu/] [xstormy16.opc] - Blame information for rev 6

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 6 jlechner
/* XSTORMY16 opcode support.  -*- C -*-
2
   Copyright (C) 2001, 2002, 2005 Red Hat, Inc.
3
   This file is part of CGEN.  */
4
 
5
/* This file is an addendum to xstormy16.cpu.  Heavy use of C code isn't
6
   appropriate in .cpu files, so it resides here.  This especially applies
7
   to assembly/disassembly where parsing/printing can be quite involved.
8
   Such things aren't really part of the specification of the cpu, per se,
9
   so .cpu files provide the general framework and .opc files handle the
10
   nitty-gritty details as necessary.
11
 
12
   Each section is delimited with start and end markers.
13
 
14
   -opc.h additions use: "-- opc.h"
15
   -opc.c additions use: "-- opc.c"
16
   -asm.c additions use: "-- asm.c"
17
   -dis.c additions use: "-- dis.c"
18
   -ibd.h additions use: "-- ibd.h".  */
19
 
20
/* -- opc.h */
21
 
22
/* Allows reason codes to be output when assembler errors occur.  */
23
#define CGEN_VERBOSE_ASSEMBLER_ERRORS
24
 
25
/* We can't use the default hash size because many bits are used by
26
   operands.  */
27
#define CGEN_DIS_HASH_SIZE 1
28
#define CGEN_DIS_HASH(buf, value) 0
29
/* -- */
30
 
31
/* -- asm.c */
32
 
33
/* The machine-independent code doesn't know how to disambiguate
34
     mov (foo),r3
35
   and
36
     mov (r2),r3
37
   where 'foo' is a label.  This helps it out. */
38
 
39
static const char *
40
parse_mem8 (CGEN_CPU_DESC cd,
41
            const char **strp,
42
            int opindex,
43
            unsigned long *valuep)
44
{
45
  if (**strp == '(')
46
    {
47
      const char *s = *strp;
48
 
49
      if (s[1] == '-' && s[2] == '-')
50
        return _("Bad register in preincrement");
51
 
52
      while (ISALNUM (*++s))
53
        ;
54
      if (s[0] == '+' && s[1] == '+' && (s[2] == ')' || s[2] == ','))
55
        return _("Bad register in postincrement");
56
      if (s[0] == ',' || s[0] == ')')
57
        return _("Bad register name");
58
    }
59
  else if (cgen_parse_keyword (cd, strp, & xstormy16_cgen_opval_gr_names,
60
                               (long *) valuep) == NULL)
61
    return _("Label conflicts with register name");
62
  else if (strncasecmp (*strp, "rx,", 3) == 0
63
           || strncasecmp (*strp, "rxl,", 3) == 0
64
           || strncasecmp (*strp, "rxh,", 3) == 0)
65
    return _("Label conflicts with `Rx'");
66
  else if (**strp == '#')
67
    return _("Bad immediate expression");
68
 
69
  return cgen_parse_unsigned_integer (cd, strp, opindex, valuep);
70
}
71
 
72
/* For the add and subtract instructions, there are two immediate forms,
73
   one for small operands and one for large ones.  We want to use
74
   the small one when possible, but we do not want to generate relocs
75
   of the small size.  This is somewhat tricky.  */
76
 
77
static const char *
78
parse_small_immediate (CGEN_CPU_DESC cd,
79
                       const char **strp,
80
                       int opindex,
81
                       unsigned long *valuep)
82
{
83
  bfd_vma value;
84
  enum cgen_parse_operand_result result;
85
  const char *errmsg;
86
 
87
  if (**strp == '@')
88
    return _("No relocation for small immediate");
89
 
90
  errmsg = (* cd->parse_operand_fn)
91
    (cd, CGEN_PARSE_OPERAND_INTEGER, strp, opindex, BFD_RELOC_NONE,
92
     & result, & value);
93
 
94
  if (errmsg)
95
    return errmsg;
96
 
97
  if (result != CGEN_PARSE_OPERAND_RESULT_NUMBER)
98
    return _("Small operand was not an immediate number");
99
 
100
  *valuep = value;
101
  return NULL;
102
}
103
 
104
/* Literal scan be either a normal literal, a @hi() or @lo relocation.  */
105
 
106
static const char *
107
parse_immediate16 (CGEN_CPU_DESC cd,
108
                   const char **strp,
109
                   int opindex,
110
                   unsigned long *valuep)
111
{
112
  const char *errmsg;
113
  enum cgen_parse_operand_result result;
114
  bfd_reloc_code_real_type code = BFD_RELOC_NONE;
115
  bfd_vma value;
116
 
117
  if (strncmp (*strp, "@hi(", 4) == 0)
118
    {
119
      *strp += 4;
120
      code = BFD_RELOC_HI16;
121
    }
122
  else
123
  if (strncmp (*strp, "@lo(", 4) == 0)
124
    {
125
      *strp += 4;
126
      code = BFD_RELOC_LO16;
127
    }
128
 
129
  if (code == BFD_RELOC_NONE)
130
    errmsg = cgen_parse_unsigned_integer (cd, strp, opindex, valuep);
131
  else
132
    {
133
      errmsg = cgen_parse_address (cd, strp, opindex, code, &result, &value);
134
      if ((errmsg == NULL) &&
135
          (result != CGEN_PARSE_OPERAND_RESULT_QUEUED))
136
        errmsg = _("Operand is not a symbol");
137
 
138
      *valuep = value;
139
      if ((code == BFD_RELOC_HI16 || code == BFD_RELOC_LO16)
140
          && **strp == ')')
141
        *strp += 1;
142
      else
143
        {
144
          errmsg = _("Syntax error: No trailing ')'");
145
          return errmsg;
146
        }
147
    }
148
  return errmsg;
149
}
150
/* -- */

powered by: WebSVN 2.1.0

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