Rizin
unix-like reverse engineering framework and cli tools
sparc.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 1989, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 2000, 2002, 2003, 2005, 2010 Free Software Foundation, Inc.
2 // SPDX-License-Identifier: GPL-3.0-or-later
3 
4 /* Definitions for opcode table for the sparc.
5  Copyright 1989, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 2000, 2002,
6  2003, 2005, 2010 Free Software Foundation, Inc.
7 
8  This file is part of GAS, the GNU Assembler, GDB, the GNU debugger, and
9  the GNU Binutils.
10 
11  GAS/GDB is free software; you can redistribute it and/or modify
12  it under the terms of the GNU General Public License as published by
13  the Free Software Foundation; either version 3, or (at your option)
14  any later version.
15 
16  GAS/GDB is distributed in the hope that it will be useful,
17  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  GNU General Public License for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with GAS or GDB; see the file COPYING3. If not, write to
23  the Free Software Foundation, 51 Franklin Street - Fifth Floor,
24  Boston, MA 02110-1301, USA. */
25 
26 #include "ansidecl.h"
27 
28 /* The SPARC opcode table (and other related data) is defined in
29  the opcodes library in sparc-opc.c. If you change anything here, make
30  sure you fix up that file, and vice versa. */
31 
32 /* FIXME-someday: perhaps the ,a's and such should be embedded in the
33  instruction's name rather than the args. This would make gas faster, pinsn
34  slower, but would mess up some macros a bit. xoxorich. */
35 
36 /* List of instruction sets variations.
37  These values are such that each element is either a superset of a
38  preceding each one or they conflict in which case SPARC_OPCODE_CONFLICT_P
39  returns non-zero.
40  The values are indices into `sparc_opcode_archs' defined in sparc-opc.c.
41  Don't change this without updating sparc-opc.c. */
42 
49  /* V9 variants must appear last. */
51  SPARC_OPCODE_ARCH_V9A, /* V9 with ultrasparc additions. */
52  SPARC_OPCODE_ARCH_V9B, /* V9 with ultrasparc and cheetah additions. */
53  SPARC_OPCODE_ARCH_BAD /* Error return from sparc_opcode_lookup_arch. */
54 };
55 
56 /* The highest architecture in the table. */
57 #define SPARC_OPCODE_ARCH_MAX (SPARC_OPCODE_ARCH_BAD - 1)
58 
59 /* Given an enum sparc_opcode_arch_val, return the bitmask to use in
60  insn encoding/decoding. */
61 #define SPARC_OPCODE_ARCH_MASK(arch) (1 << (arch))
62 
63 /* Given a valid sparc_opcode_arch_val, return non-zero if it's v9. */
64 #define SPARC_OPCODE_ARCH_V9_P(arch) ((arch) >= SPARC_OPCODE_ARCH_V9)
65 
66 /* Table of cpu variants. */
67 
68 typedef struct sparc_opcode_arch {
69  const char *name;
70  /* Mask of sparc_opcode_arch_val's supported.
71  EG: For v7 this would be
72  (SPARC_OPCODE_ARCH_MASK (..._V6) | SPARC_OPCODE_ARCH_MASK (..._V7)).
73  These are short's because sparc_opcode.architecture is. */
74  short supported;
76 
77 extern const struct sparc_opcode_arch sparc_opcode_archs[];
78 
79 /* Given architecture name, look up it's sparc_opcode_arch_val value. */
80 extern enum sparc_opcode_arch_val sparc_opcode_lookup_arch(const char *);
81 
82 /* Return the bitmask of supported architectures for ARCH. */
83 #define SPARC_OPCODE_SUPPORTED(ARCH) (sparc_opcode_archs[ARCH].supported)
84 
85 /* Non-zero if ARCH1 conflicts with ARCH2.
86  IE: ARCH1 as a supported bit set that ARCH2 doesn't, and vice versa. */
87 #define SPARC_OPCODE_CONFLICT_P(ARCH1, ARCH2) \
88  (((SPARC_OPCODE_SUPPORTED(ARCH1) & SPARC_OPCODE_SUPPORTED(ARCH2)) != SPARC_OPCODE_SUPPORTED(ARCH1)) && ((SPARC_OPCODE_SUPPORTED(ARCH1) & SPARC_OPCODE_SUPPORTED(ARCH2)) != SPARC_OPCODE_SUPPORTED(ARCH2)))
89 
90 /* Structure of an opcode table entry. */
91 
92 typedef struct sparc_opcode {
93  const char *name;
94  unsigned long match; /* Bits that must be set. */
95  unsigned long lose; /* Bits that must not be set. */
96  const char *args;
97  /* This was called "delayed" in versions before the flags. */
98  char flags;
99  short architecture; /* Bitmask of sparc_opcode_arch_val's. */
101 
102 #define F_DELAYED 1 /* Delayed branch. */
103 #define F_ALIAS 2 /* Alias for a "real" instruction. */
104 #define F_UNBR 4 /* Unconditional branch. */
105 #define F_CONDBR 8 /* Conditional branch. */
106 #define F_JSR 16 /* Subroutine call. */
107 #define F_FLOAT 32 /* Floating point instruction (not a branch). */
108 #define F_FBR 64 /* Floating point branch. */
109 /* FIXME: Add F_ANACHRONISTIC flag for v9. */
110 
111 /* All sparc opcodes are 32 bits, except for the `set' instruction (really a
112  macro), which is 64 bits. It is handled as a special case.
113 
114  The match component is a mask saying which bits must match a particular
115  opcode in order for an instruction to be an instance of that opcode.
116 
117  The args component is a string containing one character for each operand of the
118  instruction.
119 
120  Kinds of operands:
121  # Number used by optimizer. It is ignored.
122  1 rs1 register.
123  2 rs2 register.
124  d rd register.
125  e frs1 floating point register.
126  v frs1 floating point register (double/even).
127  V frs1 floating point register (quad/multiple of 4).
128  f frs2 floating point register.
129  B frs2 floating point register (double/even).
130  R frs2 floating point register (quad/multiple of 4).
131  g frsd floating point register.
132  H frsd floating point register (double/even).
133  J frsd floating point register (quad/multiple of 4).
134  b crs1 coprocessor register
135  c crs2 coprocessor register
136  D crsd coprocessor register
137  m alternate space register (asr) in rd
138  M alternate space register (asr) in rs1
139  h 22 high bits.
140  X 5 bit unsigned immediate
141  Y 6 bit unsigned immediate
142  3 SIAM mode (3 bits). (v9b)
143  K MEMBAR mask (7 bits). (v9)
144  j 10 bit Immediate. (v9)
145  I 11 bit Immediate. (v9)
146  i 13 bit Immediate.
147  n 22 bit immediate.
148  k 2+14 bit PC relative immediate. (v9)
149  G 19 bit PC relative immediate. (v9)
150  l 22 bit PC relative immediate.
151  L 30 bit PC relative immediate.
152  a Annul. The annul bit is set.
153  A Alternate address space. Stored as 8 bits.
154  C Coprocessor state register.
155  F floating point state register.
156  p Processor state register.
157  N Branch predict clear ",pn" (v9)
158  T Branch predict set ",pt" (v9)
159  z %icc. (v9)
160  Z %xcc. (v9)
161  q Floating point queue.
162  r Single register that is both rs1 and rd.
163  O Single register that is both rs2 and rd.
164  Q Coprocessor queue.
165  S Special case.
166  t Trap base register.
167  w Window invalid mask register.
168  y Y register.
169  u sparclet coprocessor registers in rd position
170  U sparclet coprocessor registers in rs1 position
171  E %ccr. (v9)
172  s %fprs. (v9)
173  P %pc. (v9)
174  W %tick. (v9)
175  o %asi. (v9)
176  6 %fcc0. (v9)
177  7 %fcc1. (v9)
178  8 %fcc2. (v9)
179  9 %fcc3. (v9)
180  ! Privileged Register in rd (v9)
181  ? Privileged Register in rs1 (v9)
182  * Prefetch function constant. (v9)
183  x OPF field (v9 impdep).
184  0 32/64 bit immediate for set or setx (v9) insns
185  _ Ancillary state register in rd (v9a)
186  / Ancillary state register in rs1 (v9a)
187 
188  The following chars are unused: (note: ,[] are used as punctuation)
189  [45]. */
190 
191 #define OP2(x) (((x)&0x7) << 22) /* Op2 field of format2 insns. */
192 #define OP3(x) (((x)&0x3f) << 19) /* Op3 field of format3 insns. */
193 #define OP(x) ((unsigned)((x)&0x3) << 30) /* Op field of all insns. */
194 #define OPF(x) (((x)&0x1ff) << 5) /* Opf field of float insns. */
195 #define OPF_LOW5(x) OPF((x)&0x1f) /* V9. */
196 #define F3F(x, y, z) (OP(x) | OP3(y) | OPF(z)) /* Format3 float insns. */
197 #define F3I(x) (((x)&0x1) << 13) /* Immediate field of format 3 insns. */
198 #define F2(x, y) (OP(x) | OP2(y)) /* Format 2 insns. */
199 #define F3(x, y, z) (OP(x) | OP3(y) | F3I(z)) /* Format3 insns. */
200 #define F1(x) (OP(x))
201 #define DISP30(x) ((x)&0x3fffffff)
202 #define ASI(x) (((x)&0xff) << 5) /* Asi field of format3 insns. */
203 #define RS2(x) ((x)&0x1f) /* Rs2 field. */
204 #define SIMM13(x) ((x)&0x1fff) /* Simm13 field. */
205 #define RD(x) (((x)&0x1f) << 25) /* Destination register field. */
206 #define RS1(x) (((x)&0x1f) << 14) /* Rs1 field. */
207 #define ASI_RS2(x) (SIMM13(x))
208 #define MEMBAR(x) ((x)&0x7f)
209 #define SLCPOP(x) (((x)&0x7f) << 6) /* Sparclet cpop. */
210 
211 #define ANNUL (1 << 29)
212 #define BPRED (1 << 19) /* V9. */
213 #define IMMED F3I(1)
214 #define RD_G0 RD(~0)
215 #define RS1_G0 RS1(~0)
216 #define RS2_G0 RS2(~0)
217 
218 extern const struct sparc_opcode sparc_opcodes[];
219 extern const int sparc_num_opcodes;
220 
221 extern int sparc_encode_asi(const char *);
222 extern const char *sparc_decode_asi(int);
223 extern int sparc_encode_membar(const char *);
224 extern const char *sparc_decode_membar(int);
225 extern int sparc_encode_prefetch(const char *);
226 extern const char *sparc_decode_prefetch(int);
227 extern int sparc_encode_sparclet_cpreg(const char *);
228 extern const char *sparc_decode_sparclet_cpreg(int);
229 
230 /* Local Variables:
231  fill-column: 131
232  comment-column: 0
233  End: */
sparc_opcode_arch_val
Definition: sparc.h:43
@ SPARC_OPCODE_ARCH_BAD
Definition: sparc.h:53
@ SPARC_OPCODE_ARCH_V9B
Definition: sparc.h:52
@ SPARC_OPCODE_ARCH_V6
Definition: sparc.h:44
@ SPARC_OPCODE_ARCH_V9
Definition: sparc.h:50
@ SPARC_OPCODE_ARCH_SPARCLITE
Definition: sparc.h:48
@ SPARC_OPCODE_ARCH_V8
Definition: sparc.h:46
@ SPARC_OPCODE_ARCH_V7
Definition: sparc.h:45
@ SPARC_OPCODE_ARCH_V9A
Definition: sparc.h:51
@ SPARC_OPCODE_ARCH_SPARCLET
Definition: sparc.h:47
const struct sparc_opcode_arch sparc_opcode_archs[]
Definition: sparc-opc.c:75
const int sparc_num_opcodes
Definition: sparc-opc.c:1831
const char * sparc_decode_asi(int)
Definition: sparc-opc.c:2051
int sparc_encode_sparclet_cpreg(const char *)
Definition: sparc-opc.c:2137
struct sparc_opcode_arch sparc_opcode_arch
int sparc_encode_membar(const char *)
Definition: sparc-opc.c:2073
enum sparc_opcode_arch_val sparc_opcode_lookup_arch(const char *)
Definition: sparc-opc.c:94
const struct sparc_opcode sparc_opcodes[]
Definition: sparc-opc.c:177
struct sparc_opcode sparc_opcode
const char * sparc_decode_membar(int)
Definition: sparc-opc.c:2081
const char * sparc_decode_prefetch(int)
Definition: sparc-opc.c:2115
const char * sparc_decode_sparclet_cpreg(int)
Definition: sparc-opc.c:2145
int sparc_encode_prefetch(const char *)
Definition: sparc-opc.c:2107
int sparc_encode_asi(const char *)
Definition: sparc-opc.c:2043
short supported
Definition: sparc.h:74
const char * name
Definition: sparc.h:69
short architecture
Definition: sparc.h:99
const char * name
Definition: sparc.h:93
unsigned long lose
Definition: sparc.h:95
unsigned long match
Definition: sparc.h:94
const char * args
Definition: sparc.h:96
char flags
Definition: sparc.h:98