/* ppc.h -- Header file for PowerPC opcode table1Copyright (C) 1994-2016 Free Software Foundation, Inc.2Written by Ian Lance Taylor, Cygnus Support34This file is part of GDB, GAS, and the GNU binutils.56GDB, GAS, and the GNU binutils are free software; you can redistribute7them and/or modify them under the terms of the GNU General Public8License as published by the Free Software Foundation; either version91, or (at your option) any later version.1011GDB, GAS, and the GNU binutils are distributed in the hope that they12will be useful, but WITHOUT ANY WARRANTY; without even the implied13warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See14the GNU General Public License for more details.1516You should have received a copy of the GNU General Public License17along with this file; see the file COPYING. If not, write to the Free18Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */1920#ifndef PPC_H21#define PPC_H2223#ifdef __cplusplus24extern "C" {25#endif2627typedef uint64_t ppc_cpu_t;2829/* The opcode table is an array of struct powerpc_opcode. */3031struct powerpc_opcode32{33/* The opcode name. */34const char *name;3536/* The opcode itself. Those bits which will be filled in with37operands are zeroes. */38unsigned long opcode;3940/* The opcode mask. This is used by the disassembler. This is a41mask containing ones indicating those bits which must match the42opcode field, and zeroes indicating those bits which need not43match (and are presumably filled in by operands). */44unsigned long mask;4546/* One bit flags for the opcode. These are used to indicate which47specific processors support the instructions. The defined values48are listed below. */49ppc_cpu_t flags;5051/* One bit flags for the opcode. These are used to indicate which52specific processors no longer support the instructions. The defined53values are listed below. */54ppc_cpu_t deprecated;5556/* An array of operand codes. Each code is an index into the57operand table. They appear in the order which the operands must58appear in assembly code, and are terminated by a zero. */59unsigned char operands[8];60};6162/* The table itself is sorted by major opcode number, and is otherwise63in the order in which the disassembler should consider64instructions. */65extern const struct powerpc_opcode powerpc_opcodes[];66extern const int powerpc_num_opcodes;67extern const struct powerpc_opcode vle_opcodes[];68extern const int vle_num_opcodes;6970/* Values defined for the flags field of a struct powerpc_opcode. */7172/* Opcode is defined for the PowerPC architecture. */73#define PPC_OPCODE_PPC 17475/* Opcode is defined for the POWER (RS/6000) architecture. */76#define PPC_OPCODE_POWER 27778/* Opcode is defined for the POWER2 (Rios 2) architecture. */79#define PPC_OPCODE_POWER2 48081/* Opcode is supported by the Motorola PowerPC 601 processor. The 60182is assumed to support all PowerPC (PPC_OPCODE_PPC) instructions,83but it also supports many additional POWER instructions. */84#define PPC_OPCODE_601 88586/* Opcode is supported in both the Power and PowerPC architectures87(ie, compiler's -mcpu=common or assembler's -mcom). More than just88the intersection of PPC_OPCODE_PPC with the union of PPC_OPCODE_POWER89and PPC_OPCODE_POWER2 because many instructions changed mnemonics90between POWER and POWERPC. */91#define PPC_OPCODE_COMMON 0x109293/* Opcode is supported for any Power or PowerPC platform (this is94for the assembler's -many option, and it eliminates duplicates). */95#define PPC_OPCODE_ANY 0x209697/* Opcode is only defined on 64 bit architectures. */98#define PPC_OPCODE_64 0x4099100/* Opcode is supported as part of the 64-bit bridge. */101#define PPC_OPCODE_64_BRIDGE 0x80102103/* Opcode is supported by Altivec Vector Unit */104#define PPC_OPCODE_ALTIVEC 0x100105106/* Opcode is supported by PowerPC 403 processor. */107#define PPC_OPCODE_403 0x200108109/* Opcode is supported by PowerPC BookE processor. */110#define PPC_OPCODE_BOOKE 0x400111112/* Opcode is supported by PowerPC 440 processor. */113#define PPC_OPCODE_440 0x800114115/* Opcode is only supported by Power4 architecture. */116#define PPC_OPCODE_POWER4 0x1000117118/* Opcode is only supported by Power7 architecture. */119#define PPC_OPCODE_POWER7 0x2000120121/* Opcode is only supported by e500x2 Core. */122#define PPC_OPCODE_SPE 0x4000123124/* Opcode is supported by e500x2 Integer select APU. */125#define PPC_OPCODE_ISEL 0x8000126127/* Opcode is an e500 SPE floating point instruction. */128#define PPC_OPCODE_EFS 0x10000129130/* Opcode is supported by branch locking APU. */131#define PPC_OPCODE_BRLOCK 0x20000132133/* Opcode is supported by performance monitor APU. */134#define PPC_OPCODE_PMR 0x40000135136/* Opcode is supported by cache locking APU. */137#define PPC_OPCODE_CACHELCK 0x80000138139/* Opcode is supported by machine check APU. */140#define PPC_OPCODE_RFMCI 0x100000141142/* Opcode is only supported by Power5 architecture. */143#define PPC_OPCODE_POWER5 0x200000144145/* Opcode is supported by PowerPC e300 family. */146#define PPC_OPCODE_E300 0x400000147148/* Opcode is only supported by Power6 architecture. */149#define PPC_OPCODE_POWER6 0x800000150151/* Opcode is only supported by PowerPC Cell family. */152#define PPC_OPCODE_CELL 0x1000000153154/* Opcode is supported by CPUs with paired singles support. */155#define PPC_OPCODE_PPCPS 0x2000000156157/* Opcode is supported by Power E500MC */158#define PPC_OPCODE_E500MC 0x4000000159160/* Opcode is supported by PowerPC 405 processor. */161#define PPC_OPCODE_405 0x8000000162163/* Opcode is supported by Vector-Scalar (VSX) Unit */164#define PPC_OPCODE_VSX 0x10000000165166/* Opcode is supported by A2. */167#define PPC_OPCODE_A2 0x20000000168169/* Opcode is supported by PowerPC 476 processor. */170#define PPC_OPCODE_476 0x40000000171172/* Opcode is supported by AppliedMicro Titan core */173#define PPC_OPCODE_TITAN 0x80000000174175/* Opcode which is supported by the e500 family */176#define PPC_OPCODE_E500 0x100000000ull177178/* Opcode is supported by Extended Altivec Vector Unit */179#define PPC_OPCODE_ALTIVEC2 0x200000000ull180181/* Opcode is supported by Power E6500 */182#define PPC_OPCODE_E6500 0x400000000ull183184/* Opcode is supported by Thread management APU */185#define PPC_OPCODE_TMR 0x800000000ull186187/* Opcode which is supported by the VLE extension. */188#define PPC_OPCODE_VLE 0x1000000000ull189190/* Opcode is only supported by Power8 architecture. */191#define PPC_OPCODE_POWER8 0x2000000000ull192193/* Opcode which is supported by the Hardware Transactional Memory extension. */194/* Currently, this is the same as the POWER8 mask. If another cpu comes out195that isn't a superset of POWER8, we can define this to its own mask. */196#define PPC_OPCODE_HTM PPC_OPCODE_POWER8197198/* Opcode is supported by ppc750cl. */199#define PPC_OPCODE_750 0x4000000000ull200201/* Opcode is supported by ppc7450. */202#define PPC_OPCODE_7450 0x8000000000ull203204/* Opcode is supported by ppc821/850/860. */205#define PPC_OPCODE_860 0x10000000000ull206207/* Opcode is only supported by Power9 architecture. */208#define PPC_OPCODE_POWER9 0x20000000000ull209210/* Opcode is supported by Vector-Scalar (VSX) Unit from ISA 2.08. */211#define PPC_OPCODE_VSX3 0x40000000000ull212213/* Opcode is supported by e200z4. */214#define PPC_OPCODE_E200Z4 0x80000000000ull215216/* A macro to extract the major opcode from an instruction. */217#define PPC_OP(i) (((i) >> 26) & 0x3f)218219/* A macro to determine if the instruction is a 2-byte VLE insn. */220#define PPC_OP_SE_VLE(m) ((m) <= 0xffff)221222/* A macro to extract the major opcode from a VLE instruction. */223#define VLE_OP(i,m) (((i) >> ((m) <= 0xffff ? 10 : 26)) & 0x3f)224225/* A macro to convert a VLE opcode to a VLE opcode segment. */226#define VLE_OP_TO_SEG(i) ((i) >> 1)227228/* The operands table is an array of struct powerpc_operand. */229230struct powerpc_operand231{232/* A bitmask of bits in the operand. */233unsigned int bitm;234235/* The shift operation to be applied to the operand. No shift236is made if this is zero. For positive values, the operand237is shifted left by SHIFT. For negative values, the operand238is shifted right by -SHIFT. Use PPC_OPSHIFT_INV to indicate239that BITM and SHIFT cannot be used to determine where the240operand goes in the insn. */241int shift;242243/* Insertion function. This is used by the assembler. To insert an244operand value into an instruction, check this field.245246If it is NULL, execute247if (o->shift >= 0)248i |= (op & o->bitm) << o->shift;249else250i |= (op & o->bitm) >> -o->shift;251(i is the instruction which we are filling in, o is a pointer to252this structure, and op is the operand value).253254If this field is not NULL, then simply call it with the255instruction and the operand value. It will return the new value256of the instruction. If the ERRMSG argument is not NULL, then if257the operand value is illegal, *ERRMSG will be set to a warning258string (the operand will be inserted in any case). If the259operand value is legal, *ERRMSG will be unchanged (most operands260can accept any value). */261unsigned long (*insert)262(unsigned long instruction, long op, ppc_cpu_t dialect, const char **errmsg);263264/* Extraction function. This is used by the disassembler. To265extract this operand type from an instruction, check this field.266267If it is NULL, compute268if (o->shift >= 0)269op = (i >> o->shift) & o->bitm;270else271op = (i << -o->shift) & o->bitm;272if ((o->flags & PPC_OPERAND_SIGNED) != 0)273sign_extend (op);274(i is the instruction, o is a pointer to this structure, and op275is the result).276277If this field is not NULL, then simply call it with the278instruction value. It will return the value of the operand. If279the INVALID argument is not NULL, *INVALID will be set to280non-zero if this operand type can not actually be extracted from281this operand (i.e., the instruction does not match). If the282operand is valid, *INVALID will not be changed. */283long (*extract) (unsigned long instruction, ppc_cpu_t dialect, int *invalid);284285/* One bit syntax flags. */286unsigned long flags;287};288289/* Elements in the table are retrieved by indexing with values from290the operands field of the powerpc_opcodes table. */291292extern const struct powerpc_operand powerpc_operands[];293extern const unsigned int num_powerpc_operands;294295/* Use with the shift field of a struct powerpc_operand to indicate296that BITM and SHIFT cannot be used to determine where the operand297goes in the insn. */298#define PPC_OPSHIFT_INV (-1U << 31)299300/* Values defined for the flags field of a struct powerpc_operand. */301302/* This operand takes signed values. */303#define PPC_OPERAND_SIGNED (0x1)304305/* This operand takes signed values, but also accepts a full positive306range of values when running in 32 bit mode. That is, if bits is30716, it takes any value from -0x8000 to 0xffff. In 64 bit mode,308this flag is ignored. */309#define PPC_OPERAND_SIGNOPT (0x2)310311/* This operand does not actually exist in the assembler input. This312is used to support extended mnemonics such as mr, for which two313operands fields are identical. The assembler should call the314insert function with any op value. The disassembler should call315the extract function, ignore the return value, and check the value316placed in the valid argument. */317#define PPC_OPERAND_FAKE (0x4)318319/* The next operand should be wrapped in parentheses rather than320separated from this one by a comma. This is used for the load and321store instructions which want their operands to look like322reg,displacement(reg)323*/324#define PPC_OPERAND_PARENS (0x8)325326/* This operand may use the symbolic names for the CR fields, which327are328lt 0 gt 1 eq 2 so 3 un 3329cr0 0 cr1 1 cr2 2 cr3 3330cr4 4 cr5 5 cr6 6 cr7 7331These may be combined arithmetically, as in cr2*4+gt. These are332only supported on the PowerPC, not the POWER. */333#define PPC_OPERAND_CR_BIT (0x10)334335/* This operand names a register. The disassembler uses this to print336register names with a leading 'r'. */337#define PPC_OPERAND_GPR (0x20)338339/* Like PPC_OPERAND_GPR, but don't print a leading 'r' for r0. */340#define PPC_OPERAND_GPR_0 (0x40)341342/* This operand names a floating point register. The disassembler343prints these with a leading 'f'. */344#define PPC_OPERAND_FPR (0x80)345346/* This operand is a relative branch displacement. The disassembler347prints these symbolically if possible. */348#define PPC_OPERAND_RELATIVE (0x100)349350/* This operand is an absolute branch address. The disassembler351prints these symbolically if possible. */352#define PPC_OPERAND_ABSOLUTE (0x200)353354/* This operand is optional, and is zero if omitted. This is used for355example, in the optional BF field in the comparison instructions. The356assembler must count the number of operands remaining on the line,357and the number of operands remaining for the opcode, and decide358whether this operand is present or not. The disassembler should359print this operand out only if it is not zero. */360#define PPC_OPERAND_OPTIONAL (0x400)361362/* This flag is only used with PPC_OPERAND_OPTIONAL. If this operand363is omitted, then for the next operand use this operand value plus3641, ignoring the next operand field for the opcode. This wretched365hack is needed because the Power rotate instructions can take366either 4 or 5 operands. The disassembler should print this operand367out regardless of the PPC_OPERAND_OPTIONAL field. */368#define PPC_OPERAND_NEXT (0x800)369370/* This operand should be regarded as a negative number for the371purposes of overflow checking (i.e., the normal most negative372number is disallowed and one more than the normal most positive373number is allowed). This flag will only be set for a signed374operand. */375#define PPC_OPERAND_NEGATIVE (0x1000)376377/* This operand names a vector unit register. The disassembler378prints these with a leading 'v'. */379#define PPC_OPERAND_VR (0x2000)380381/* This operand is for the DS field in a DS form instruction. */382#define PPC_OPERAND_DS (0x4000)383384/* This operand is for the DQ field in a DQ form instruction. */385#define PPC_OPERAND_DQ (0x8000)386387/* Valid range of operand is 0..n rather than 0..n-1. */388#define PPC_OPERAND_PLUS1 (0x10000)389390/* Xilinx APU and FSL related operands */391#define PPC_OPERAND_FSL (0x20000)392#define PPC_OPERAND_FCR (0x40000)393#define PPC_OPERAND_UDI (0x80000)394395/* This operand names a vector-scalar unit register. The disassembler396prints these with a leading 'vs'. */397#define PPC_OPERAND_VSR (0x100000)398399/* This is a CR FIELD that does not use symbolic names. */400#define PPC_OPERAND_CR_REG (0x200000)401402/* This flag is only used with PPC_OPERAND_OPTIONAL. If this operand403is omitted, then the value it should use for the operand is stored404in the SHIFT field of the immediatly following operand field. */405#define PPC_OPERAND_OPTIONAL_VALUE (0x400000)406407/* This flag is only used with PPC_OPERAND_OPTIONAL. The operand is408only optional when generating 32-bit code. */409#define PPC_OPERAND_OPTIONAL32 (0x800000)410411/* The POWER and PowerPC assemblers use a few macros. We keep them412with the operands table for simplicity. The macro table is an413array of struct powerpc_macro. */414415struct powerpc_macro416{417/* The macro name. */418const char *name;419420/* The number of operands the macro takes. */421unsigned int operands;422423/* One bit flags for the opcode. These are used to indicate which424specific processors support the instructions. The values are the425same as those for the struct powerpc_opcode flags field. */426ppc_cpu_t flags;427428/* A format string to turn the macro into a normal instruction.429Each %N in the string is replaced with operand number N (zero430based). */431const char *format;432};433434extern const struct powerpc_macro powerpc_macros[];435extern const int powerpc_num_macros;436437static inline long438ppc_optional_operand_value (const struct powerpc_operand *operand)439{440if ((operand->flags & PPC_OPERAND_OPTIONAL_VALUE) != 0)441return (operand+1)->shift;442return 0;443}444445#ifdef __cplusplus446}447#endif448449#endif /* PPC_H */450451452