12159047fSniklas /* Definitions for opcode table for the sparc. 2*007c2a45Smiod Copyright 1989, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 2000, 2002, 3*007c2a45Smiod 2003 Free Software Foundation, Inc. 42159047fSniklas 52159047fSniklas This file is part of GAS, the GNU Assembler, GDB, the GNU debugger, and 62159047fSniklas the GNU Binutils. 72159047fSniklas 82159047fSniklas GAS/GDB is free software; you can redistribute it and/or modify 92159047fSniklas it under the terms of the GNU General Public License as published by 102159047fSniklas the Free Software Foundation; either version 2, or (at your option) 112159047fSniklas any later version. 122159047fSniklas 132159047fSniklas GAS/GDB is distributed in the hope that it will be useful, 142159047fSniklas but WITHOUT ANY WARRANTY; without even the implied warranty of 152159047fSniklas MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 162159047fSniklas GNU General Public License for more details. 172159047fSniklas 182159047fSniklas You should have received a copy of the GNU General Public License 192159047fSniklas along with GAS or GDB; see the file COPYING. If not, write to 202159047fSniklas the Free Software Foundation, 59 Temple Place - Suite 330, 212159047fSniklas Boston, MA 02111-1307, USA. */ 222159047fSniklas 23c074d1c9Sdrahn #include "ansidecl.h" 246a4c786fSespie 252159047fSniklas /* The SPARC opcode table (and other related data) is defined in 262159047fSniklas the opcodes library in sparc-opc.c. If you change anything here, make 272159047fSniklas sure you fix up that file, and vice versa. */ 282159047fSniklas 292159047fSniklas /* FIXME-someday: perhaps the ,a's and such should be embedded in the 302159047fSniklas instruction's name rather than the args. This would make gas faster, pinsn 312159047fSniklas slower, but would mess up some macros a bit. xoxorich. */ 322159047fSniklas 33c88b1d6cSniklas /* List of instruction sets variations. 34c88b1d6cSniklas These values are such that each element is either a superset of a 35c88b1d6cSniklas preceding each one or they conflict in which case SPARC_OPCODE_CONFLICT_P 36c88b1d6cSniklas returns non-zero. 37c88b1d6cSniklas The values are indices into `sparc_opcode_archs' defined in sparc-opc.c. 38c88b1d6cSniklas Don't change this without updating sparc-opc.c. */ 392159047fSniklas 40c88b1d6cSniklas enum sparc_opcode_arch_val { 41c88b1d6cSniklas SPARC_OPCODE_ARCH_V6 = 0, 42c88b1d6cSniklas SPARC_OPCODE_ARCH_V7, 43c88b1d6cSniklas SPARC_OPCODE_ARCH_V8, 44c88b1d6cSniklas SPARC_OPCODE_ARCH_SPARCLET, 45c88b1d6cSniklas SPARC_OPCODE_ARCH_SPARCLITE, 46c88b1d6cSniklas /* v9 variants must appear last */ 47c88b1d6cSniklas SPARC_OPCODE_ARCH_V9, 48c88b1d6cSniklas SPARC_OPCODE_ARCH_V9A, /* v9 with ultrasparc additions */ 49b55d4692Sfgsch SPARC_OPCODE_ARCH_V9B, /* v9 with ultrasparc and cheetah additions */ 50c88b1d6cSniklas SPARC_OPCODE_ARCH_BAD /* error return from sparc_opcode_lookup_arch */ 512159047fSniklas }; 522159047fSniklas 53c88b1d6cSniklas /* The highest architecture in the table. */ 54c88b1d6cSniklas #define SPARC_OPCODE_ARCH_MAX (SPARC_OPCODE_ARCH_BAD - 1) 552159047fSniklas 56c88b1d6cSniklas /* Given an enum sparc_opcode_arch_val, return the bitmask to use in 57c88b1d6cSniklas insn encoding/decoding. */ 58c88b1d6cSniklas #define SPARC_OPCODE_ARCH_MASK(arch) (1 << (arch)) 592159047fSniklas 60c88b1d6cSniklas /* Given a valid sparc_opcode_arch_val, return non-zero if it's v9. */ 61c88b1d6cSniklas #define SPARC_OPCODE_ARCH_V9_P(arch) ((arch) >= SPARC_OPCODE_ARCH_V9) 62c88b1d6cSniklas 63c88b1d6cSniklas /* Table of cpu variants. */ 64c88b1d6cSniklas 65c88b1d6cSniklas struct sparc_opcode_arch { 66c88b1d6cSniklas const char *name; 67c88b1d6cSniklas /* Mask of sparc_opcode_arch_val's supported. 68c88b1d6cSniklas EG: For v7 this would be 69c88b1d6cSniklas (SPARC_OPCODE_ARCH_MASK (..._V6) | SPARC_OPCODE_ARCH_MASK (..._V7)). 70c88b1d6cSniklas These are short's because sparc_opcode.architecture is. */ 71c88b1d6cSniklas short supported; 72c88b1d6cSniklas }; 73c88b1d6cSniklas 74c88b1d6cSniklas extern const struct sparc_opcode_arch sparc_opcode_archs[]; 75c88b1d6cSniklas 76c88b1d6cSniklas /* Given architecture name, look up it's sparc_opcode_arch_val value. */ 77*007c2a45Smiod extern enum sparc_opcode_arch_val sparc_opcode_lookup_arch (const char *); 78c88b1d6cSniklas 79c88b1d6cSniklas /* Return the bitmask of supported architectures for ARCH. */ 80c88b1d6cSniklas #define SPARC_OPCODE_SUPPORTED(ARCH) (sparc_opcode_archs[ARCH].supported) 81c88b1d6cSniklas 82c88b1d6cSniklas /* Non-zero if ARCH1 conflicts with ARCH2. 83c88b1d6cSniklas IE: ARCH1 as a supported bit set that ARCH2 doesn't, and vice versa. */ 84c88b1d6cSniklas #define SPARC_OPCODE_CONFLICT_P(ARCH1, ARCH2) \ 85c88b1d6cSniklas (((SPARC_OPCODE_SUPPORTED (ARCH1) & SPARC_OPCODE_SUPPORTED (ARCH2)) \ 86c88b1d6cSniklas != SPARC_OPCODE_SUPPORTED (ARCH1)) \ 87c88b1d6cSniklas && ((SPARC_OPCODE_SUPPORTED (ARCH1) & SPARC_OPCODE_SUPPORTED (ARCH2)) \ 88c88b1d6cSniklas != SPARC_OPCODE_SUPPORTED (ARCH2))) 89c88b1d6cSniklas 90c88b1d6cSniklas /* Structure of an opcode table entry. */ 912159047fSniklas 922159047fSniklas struct sparc_opcode { 932159047fSniklas const char *name; 942159047fSniklas unsigned long match; /* Bits that must be set. */ 952159047fSniklas unsigned long lose; /* Bits that must not be set. */ 962159047fSniklas const char *args; 972159047fSniklas /* This was called "delayed" in versions before the flags. */ 982159047fSniklas char flags; 99c88b1d6cSniklas short architecture; /* Bitmask of sparc_opcode_arch_val's. */ 1002159047fSniklas }; 1012159047fSniklas 1022159047fSniklas #define F_DELAYED 1 /* Delayed branch */ 1032159047fSniklas #define F_ALIAS 2 /* Alias for a "real" instruction */ 1042159047fSniklas #define F_UNBR 4 /* Unconditional branch */ 1052159047fSniklas #define F_CONDBR 8 /* Conditional branch */ 1062159047fSniklas #define F_JSR 16 /* Subroutine call */ 107c88b1d6cSniklas #define F_FLOAT 32 /* Floating point instruction (not a branch) */ 108c88b1d6cSniklas #define F_FBR 64 /* Floating point branch */ 1092159047fSniklas /* FIXME: Add F_ANACHRONISTIC flag for v9. */ 1102159047fSniklas 1112159047fSniklas /* 1122159047fSniklas 1132159047fSniklas All sparc opcodes are 32 bits, except for the `set' instruction (really a 1142159047fSniklas macro), which is 64 bits. It is handled as a special case. 1152159047fSniklas 1162159047fSniklas The match component is a mask saying which bits must match a particular 1172159047fSniklas opcode in order for an instruction to be an instance of that opcode. 1182159047fSniklas 1192159047fSniklas The args component is a string containing one character for each operand of the 1202159047fSniklas instruction. 1212159047fSniklas 1222159047fSniklas Kinds of operands: 1232159047fSniklas # Number used by optimizer. It is ignored. 1242159047fSniklas 1 rs1 register. 1252159047fSniklas 2 rs2 register. 1262159047fSniklas d rd register. 1272159047fSniklas e frs1 floating point register. 1282159047fSniklas v frs1 floating point register (double/even). 1292159047fSniklas V frs1 floating point register (quad/multiple of 4). 1302159047fSniklas f frs2 floating point register. 1312159047fSniklas B frs2 floating point register (double/even). 1322159047fSniklas R frs2 floating point register (quad/multiple of 4). 1332159047fSniklas g frsd floating point register. 1342159047fSniklas H frsd floating point register (double/even). 1352159047fSniklas J frsd floating point register (quad/multiple of 4). 1362159047fSniklas b crs1 coprocessor register 1372159047fSniklas c crs2 coprocessor register 1382159047fSniklas D crsd coprocessor register 1392159047fSniklas m alternate space register (asr) in rd 1402159047fSniklas M alternate space register (asr) in rs1 1412159047fSniklas h 22 high bits. 142c88b1d6cSniklas X 5 bit unsigned immediate 143c88b1d6cSniklas Y 6 bit unsigned immediate 144b55d4692Sfgsch 3 SIAM mode (3 bits). (v9b) 1452159047fSniklas K MEMBAR mask (7 bits). (v9) 1462159047fSniklas j 10 bit Immediate. (v9) 1472159047fSniklas I 11 bit Immediate. (v9) 1482159047fSniklas i 13 bit Immediate. 1492159047fSniklas n 22 bit immediate. 1502159047fSniklas k 2+14 bit PC relative immediate. (v9) 1512159047fSniklas G 19 bit PC relative immediate. (v9) 1522159047fSniklas l 22 bit PC relative immediate. 1532159047fSniklas L 30 bit PC relative immediate. 1542159047fSniklas a Annul. The annul bit is set. 1552159047fSniklas A Alternate address space. Stored as 8 bits. 1562159047fSniklas C Coprocessor state register. 1572159047fSniklas F floating point state register. 1582159047fSniklas p Processor state register. 1592159047fSniklas N Branch predict clear ",pn" (v9) 1602159047fSniklas T Branch predict set ",pt" (v9) 1612159047fSniklas z %icc. (v9) 1622159047fSniklas Z %xcc. (v9) 1632159047fSniklas q Floating point queue. 164c88b1d6cSniklas r Single register that is both rs1 and rd. 165c88b1d6cSniklas O Single register that is both rs2 and rd. 1662159047fSniklas Q Coprocessor queue. 1672159047fSniklas S Special case. 1682159047fSniklas t Trap base register. 1692159047fSniklas w Window invalid mask register. 1702159047fSniklas y Y register. 171c88b1d6cSniklas u sparclet coprocessor registers in rd position 172c88b1d6cSniklas U sparclet coprocessor registers in rs1 position 1732159047fSniklas E %ccr. (v9) 1742159047fSniklas s %fprs. (v9) 1752159047fSniklas P %pc. (v9) 1762159047fSniklas W %tick. (v9) 1772159047fSniklas o %asi. (v9) 1782159047fSniklas 6 %fcc0. (v9) 1792159047fSniklas 7 %fcc1. (v9) 1802159047fSniklas 8 %fcc2. (v9) 1812159047fSniklas 9 %fcc3. (v9) 1822159047fSniklas ! Privileged Register in rd (v9) 1832159047fSniklas ? Privileged Register in rs1 (v9) 1842159047fSniklas * Prefetch function constant. (v9) 1852159047fSniklas x OPF field (v9 impdep). 1860c6d0228Sniklas 0 32/64 bit immediate for set or setx (v9) insns 187b305b0f1Sespie _ Ancillary state register in rd (v9a) 188b305b0f1Sespie / Ancillary state register in rs1 (v9a) 1892159047fSniklas 1902159047fSniklas The following chars are unused: (note: ,[] are used as punctuation) 191b55d4692Sfgsch [45] 1922159047fSniklas 1932159047fSniklas */ 1942159047fSniklas 1952159047fSniklas #define OP2(x) (((x)&0x7) << 22) /* op2 field of format2 insns */ 1962159047fSniklas #define OP3(x) (((x)&0x3f) << 19) /* op3 field of format3 insns */ 1972159047fSniklas #define OP(x) ((unsigned)((x)&0x3) << 30) /* op field of all insns */ 1982159047fSniklas #define OPF(x) (((x)&0x1ff) << 5) /* opf field of float insns */ 1992159047fSniklas #define OPF_LOW5(x) OPF((x)&0x1f) /* v9 */ 2002159047fSniklas #define F3F(x, y, z) (OP(x) | OP3(y) | OPF(z)) /* format3 float insns */ 2012159047fSniklas #define F3I(x) (((x)&0x1) << 13) /* immediate field of format 3 insns */ 2022159047fSniklas #define F2(x, y) (OP(x) | OP2(y)) /* format 2 insns */ 2032159047fSniklas #define F3(x, y, z) (OP(x) | OP3(y) | F3I(z)) /* format3 insns */ 2042159047fSniklas #define F1(x) (OP(x)) 2052159047fSniklas #define DISP30(x) ((x)&0x3fffffff) 2062159047fSniklas #define ASI(x) (((x)&0xff) << 5) /* asi field of format3 insns */ 2072159047fSniklas #define RS2(x) ((x)&0x1f) /* rs2 field */ 2082159047fSniklas #define SIMM13(x) ((x)&0x1fff) /* simm13 field */ 2092159047fSniklas #define RD(x) (((x)&0x1f) << 25) /* destination register field */ 2102159047fSniklas #define RS1(x) (((x)&0x1f) << 14) /* rs1 field */ 2112159047fSniklas #define ASI_RS2(x) (SIMM13(x)) 2122159047fSniklas #define MEMBAR(x) ((x)&0x7f) 213c88b1d6cSniklas #define SLCPOP(x) (((x)&0x7f) << 6) /* sparclet cpop */ 2142159047fSniklas 2152159047fSniklas #define ANNUL (1<<29) 2162159047fSniklas #define BPRED (1<<19) /* v9 */ 2172159047fSniklas #define IMMED F3I(1) 2182159047fSniklas #define RD_G0 RD(~0) 2192159047fSniklas #define RS1_G0 RS1(~0) 2202159047fSniklas #define RS2_G0 RS2(~0) 2212159047fSniklas 222b305b0f1Sespie extern const struct sparc_opcode sparc_opcodes[]; 223c88b1d6cSniklas extern const int sparc_num_opcodes; 2242159047fSniklas 225*007c2a45Smiod extern int sparc_encode_asi (const char *); 226*007c2a45Smiod extern const char *sparc_decode_asi (int); 227*007c2a45Smiod extern int sparc_encode_membar (const char *); 228*007c2a45Smiod extern const char *sparc_decode_membar (int); 229*007c2a45Smiod extern int sparc_encode_prefetch (const char *); 230*007c2a45Smiod extern const char *sparc_decode_prefetch (int); 231*007c2a45Smiod extern int sparc_encode_sparclet_cpreg (const char *); 232*007c2a45Smiod extern const char *sparc_decode_sparclet_cpreg (int); 2332159047fSniklas 2342159047fSniklas /* 2352159047fSniklas * Local Variables: 2362159047fSniklas * fill-column: 131 2372159047fSniklas * comment-column: 0 2382159047fSniklas * End: 2392159047fSniklas */ 2402159047fSniklas 2412159047fSniklas /* end of sparc.h */ 242