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

Subversion Repositories scarts

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

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 6 jlechner
/* SPARC opcode support.  -*- C -*-
2
   Copyright (C) 2000, 2005 Red Hat, Inc.
3
   This file is part of CGEN.
4
   This file is copyrighted with the GNU General Public License.
5
   See file COPYING for details.  */
6
 
7
/* This file is an addendum to sparc.cpu.  Heavy use of C code isn't
8
   appropriate in .cpu files, so it resides here.  This especially applies
9
   to assembly/disassembly where parsing/printing can be quite involved.
10
   Such things aren't really part of the specification of the cpu, per se,
11
   so .cpu files provide the general framework and .opc files handle the
12
   nitty-gritty details as necessary.
13
 
14
   Each section is delimited with start and end markers.
15
 
16
   -opc.h additions use: "-- opc.h"
17
   -opc.c additions use: "-- opc.c"
18
   -asm.c additions use: "-- asm.c"
19
   -dis.c additions use: "-- dis.c"  */
20
 
21
/* -- opc.h */
22
 
23
#undef  CGEN_DIS_HASH_SIZE
24
#define CGEN_DIS_HASH_SIZE 256
25
#undef  CGEN_DIS_HASH
26
extern const unsigned int sparc_cgen_opcode_bits[];
27
#define CGEN_DIS_HASH(buffer, insn) \
28
  ((((insn) >> 24) & 0xc0) \
29
   | (((insn) & sparc_cgen_opcode_bits[((insn) >> 30) & 3]) >> 19))
30
 
31
/* -- */
32
 
33
/* -- asm.c */
34
 
35
static const char * MISSING_CLOSING_PARENTHESIS = N("missing `)'");
36
 
37
/* It is important that we only look at insn code bits as that is how the
38
   opcode table is hashed.  OPCODE_BITS is a table of valid bits for each
39
   of the main types (0,1,2,3).  */
40
const unsigned int sparc_cgen_opcode_bits[4] =
41
{
42
  0x01c00000, 0x0, 0x01f80000, 0x01f80000
43
};
44
 
45
/* Handle %lo().  */
46
 
47
static const char *
48
parse_lo10 (CGEN_CPU_DESC cd,
49
            const char **strp,
50
            int opindex,
51
            long *valuep)
52
{
53
  const char *errmsg;
54
  enum cgen_parse_operand_result result_type;
55
  bfd_vma value;
56
 
57
  if (strncasecmp (*strp, "%lo(", 4) == 0)
58
    {
59
      *strp += 4;
60
      errmsg = cgen_parse_address (od, strp, opindex, BFD_RELOC_LO10,
61
                                   & result_type, & value);
62
      if (**strp != ')')
63
        return MISSING_CLOSING_PARENTHESIS;
64
      ++*strp;
65
      value &= 0x3ff;
66
      *valuep = value;
67
      return errmsg;
68
    }
69
 
70
  return cgen_parse_unsigned_integer (od, strp, opindex, valuep);
71
}
72
 
73
static const char *
74
parse_lo13 (CGEN_CPU_DESC cd,
75
            const char **strp,
76
            int opindex,
77
            long *valuep)
78
{
79
  const char *errmsg;
80
  enum cgen_parse_operand_result result_type;
81
  bfd_vma value;
82
 
83
  if (strncasecmp (*strp, "%lo(", 4) == 0)
84
    {
85
      *strp += 4;
86
      errmsg = cgen_parse_address (od, strp, opindex, BFD_RELOC_LO10,
87
                                   & result_type, & value);
88
      if (**strp != ')')
89
        return MISSING_CLOSING_PARENTHESIS;
90
      ++*strp;
91
      value &= 0x3ff;
92
      *valuep = value;
93
      return errmsg;
94
    }
95
 
96
  return cgen_parse_unsigned_integer (od, strp, opindex, valuep);
97
}
98
 
99
/* Handle %hi().  */
100
 
101
static const char *
102
parse_hi22 (CGEN_CPU_DESC cd,
103
            const char **strp,
104
            int opindex,
105
            unsigned long *valuep)
106
{
107
  const char *errmsg;
108
  enum cgen_parse_operand_result result_type;
109
  bfd_vma value;
110
 
111
  if (strncasecmp (*strp, "%hi(", 4) == 0)
112
    {
113
      *strp += 4;
114
      errmsg = cgen_parse_address (od, strp, opindex, BFD_RELOC_HI22,
115
                                   & result_type, & value);
116
      if (**strp != ')')
117
        return MISSING_CLOSING_PARENTHESIS;
118
      ++*strp;
119
      if (result_type == CGEN_PARSE_OPERAND_RESULT_NUMBER)
120
        value >>= 10;
121
      *valuep = value;
122
      return errmsg;
123
    }
124
 
125
  return cgen_parse_unsigned_integer (od, strp, opindex, valuep);
126
}
127
 
128
/* -- */
129
 
130
/* -- dis.c */
131
 
132
/* Include "%hi(foo)" in sethi output.  */
133
 
134
static void
135
print_hi22 (CGEN_CPU_DESC cd,
136
            void * dis_info,
137
            long value,
138
            unsigned int attrs,
139
            bfd_vma pc,
140
            int length)
141
{
142
  disassemble_info *info = (disassemble_info *) dis_info;
143
 
144
  (*info->fprintf_func) (info->stream, "%%hi(0x%lx)", value << 10);
145
}
146
 
147
#undef  CGEN_PRINT_INSN
148
#define CGEN_PRINT_INSN sparc_print_insn
149
 
150
static int
151
sparc_print_insn (CGEN_CPU_DESC cd,
152
                  bfd_vma pc,
153
                  disassemble_info *info)
154
{
155
  char buffer[CGEN_MAX_INSN_SIZE];
156
  char *buf = buffer;
157
  int status;
158
  unsigned long insn_value;
159
  int len;
160
 
161
  /* Read the base part of the insn.  */
162
  status = (*info->read_memory_func) (pc, buf, 4, info);
163
  if (status != 0)
164
    {
165
      (*info->memory_error_func) (status, pc, info);
166
      return -1;
167
    }
168
 
169
  len = print_insn (od, pc, info, buf, 4);
170
  if (len != 0)
171
    return len;
172
 
173
  /* CGEN doesn't handle this insn yet.  Fall back on old way.  */
174
  return old_print_insn_sparc (pc, info);
175
}
176
 
177
/* -- */

powered by: WebSVN 2.1.0

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