/* ppc.h -- Header file for PowerPC opcode table1Copyright 1994, 1995, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 20062Free Software Foundation, Inc.3Written by Ian Lance Taylor, Cygnus Support45This file is part of GDB, GAS, and the GNU binutils.67GDB, GAS, and the GNU binutils are free software; you can redistribute8them and/or modify them under the terms of the GNU General Public9License as published by the Free Software Foundation; either version101, or (at your option) any later version.1112GDB, GAS, and the GNU binutils are distributed in the hope that they13will be useful, but WITHOUT ANY WARRANTY; without even the implied14warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See15the GNU General Public License for more details.1617You should have received a copy of the GNU General Public License18along with this file; see the file COPYING. If not, write to the Free19Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA. */2021#ifndef PPC_H22#define PPC_H2324/* The opcode table is an array of struct powerpc_opcode. */2526struct powerpc_opcode27{28/* The opcode name. */29const char *name;3031/* The opcode itself. Those bits which will be filled in with32operands are zeroes. */33unsigned long opcode;3435/* The opcode mask. This is used by the disassembler. This is a36mask containing ones indicating those bits which must match the37opcode field, and zeroes indicating those bits which need not38match (and are presumably filled in by operands). */39unsigned long mask;4041/* One bit flags for the opcode. These are used to indicate which42specific processors support the instructions. The defined values43are listed below. */44unsigned long flags;4546/* An array of operand codes. Each code is an index into the47operand table. They appear in the order which the operands must48appear in assembly code, and are terminated by a zero. */49unsigned char operands[8];50};5152/* The table itself is sorted by major opcode number, and is otherwise53in the order in which the disassembler should consider54instructions. */55extern const struct powerpc_opcode powerpc_opcodes[];56extern const int powerpc_num_opcodes;5758/* Values defined for the flags field of a struct powerpc_opcode. */5960/* Opcode is defined for the PowerPC architecture. */61#define PPC_OPCODE_PPC 16263/* Opcode is defined for the POWER (RS/6000) architecture. */64#define PPC_OPCODE_POWER 26566/* Opcode is defined for the POWER2 (Rios 2) architecture. */67#define PPC_OPCODE_POWER2 46869/* Opcode is only defined on 32 bit architectures. */70#define PPC_OPCODE_32 87172/* Opcode is only defined on 64 bit architectures. */73#define PPC_OPCODE_64 0x107475/* Opcode is supported by the Motorola PowerPC 601 processor. The 60176is assumed to support all PowerPC (PPC_OPCODE_PPC) instructions,77but it also supports many additional POWER instructions. */78#define PPC_OPCODE_601 0x207980/* Opcode is supported in both the Power and PowerPC architectures81(ie, compiler's -mcpu=common or assembler's -mcom). */82#define PPC_OPCODE_COMMON 0x408384/* Opcode is supported for any Power or PowerPC platform (this is85for the assembler's -many option, and it eliminates duplicates). */86#define PPC_OPCODE_ANY 0x808788/* Opcode is supported as part of the 64-bit bridge. */89#define PPC_OPCODE_64_BRIDGE 0x1009091/* Opcode is supported by Altivec Vector Unit */92#define PPC_OPCODE_ALTIVEC 0x2009394/* Opcode is supported by PowerPC 403 processor. */95#define PPC_OPCODE_403 0x4009697/* Opcode is supported by PowerPC BookE processor. */98#define PPC_OPCODE_BOOKE 0x80099100/* Opcode is only supported by 64-bit PowerPC BookE processor. */101#define PPC_OPCODE_BOOKE64 0x1000102103/* Opcode is supported by PowerPC 440 processor. */104#define PPC_OPCODE_440 0x2000105106/* Opcode is only supported by Power4 architecture. */107#define PPC_OPCODE_POWER4 0x4000108109/* Opcode isn't supported by Power4 architecture. */110#define PPC_OPCODE_NOPOWER4 0x8000111112/* Opcode is only supported by POWERPC Classic architecture. */113#define PPC_OPCODE_CLASSIC 0x10000114115/* Opcode is only supported by e500x2 Core. */116#define PPC_OPCODE_SPE 0x20000117118/* Opcode is supported by e500x2 Integer select APU. */119#define PPC_OPCODE_ISEL 0x40000120121/* Opcode is an e500 SPE floating point instruction. */122#define PPC_OPCODE_EFS 0x80000123124/* Opcode is supported by branch locking APU. */125#define PPC_OPCODE_BRLOCK 0x100000126127/* Opcode is supported by performance monitor APU. */128#define PPC_OPCODE_PMR 0x200000129130/* Opcode is supported by cache locking APU. */131#define PPC_OPCODE_CACHELCK 0x400000132133/* Opcode is supported by machine check APU. */134#define PPC_OPCODE_RFMCI 0x800000135136/* Opcode is only supported by Power5 architecture. */137#define PPC_OPCODE_POWER5 0x1000000138139/* Opcode is supported by PowerPC e300 family. */140#define PPC_OPCODE_E300 0x2000000141142/* Opcode is only supported by Power6 architecture. */143#define PPC_OPCODE_POWER6 0x4000000144145/* Opcode is only supported by PowerPC Cell family. */146#define PPC_OPCODE_CELL 0x8000000147148/* A macro to extract the major opcode from an instruction. */149#define PPC_OP(i) (((i) >> 26) & 0x3f)150151/* The operands table is an array of struct powerpc_operand. */152153struct powerpc_operand154{155/* The number of bits in the operand. */156int bits;157158/* How far the operand is left shifted in the instruction. */159int shift;160161/* Insertion function. This is used by the assembler. To insert an162operand value into an instruction, check this field.163164If it is NULL, execute165i |= (op & ((1 << o->bits) - 1)) << o->shift;166(i is the instruction which we are filling in, o is a pointer to167this structure, and op is the opcode value; this assumes twos168complement arithmetic).169170If this field is not NULL, then simply call it with the171instruction and the operand value. It will return the new value172of the instruction. If the ERRMSG argument is not NULL, then if173the operand value is illegal, *ERRMSG will be set to a warning174string (the operand will be inserted in any case). If the175operand value is legal, *ERRMSG will be unchanged (most operands176can accept any value). */177unsigned long (*insert)178(unsigned long instruction, long op, int dialect, const char **errmsg);179180/* Extraction function. This is used by the disassembler. To181extract this operand type from an instruction, check this field.182183If it is NULL, compute184op = ((i) >> o->shift) & ((1 << o->bits) - 1);185if ((o->flags & PPC_OPERAND_SIGNED) != 0186&& (op & (1 << (o->bits - 1))) != 0)187op -= 1 << o->bits;188(i is the instruction, o is a pointer to this structure, and op189is the result; this assumes twos complement arithmetic).190191If this field is not NULL, then simply call it with the192instruction value. It will return the value of the operand. If193the INVALID argument is not NULL, *INVALID will be set to194non-zero if this operand type can not actually be extracted from195this operand (i.e., the instruction does not match). If the196operand is valid, *INVALID will not be changed. */197long (*extract) (unsigned long instruction, int dialect, int *invalid);198199/* One bit syntax flags. */200unsigned long flags;201};202203/* Elements in the table are retrieved by indexing with values from204the operands field of the powerpc_opcodes table. */205206extern const struct powerpc_operand powerpc_operands[];207208/* Values defined for the flags field of a struct powerpc_operand. */209210/* This operand takes signed values. */211#define PPC_OPERAND_SIGNED (01)212213/* This operand takes signed values, but also accepts a full positive214range of values when running in 32 bit mode. That is, if bits is21516, it takes any value from -0x8000 to 0xffff. In 64 bit mode,216this flag is ignored. */217#define PPC_OPERAND_SIGNOPT (02)218219/* This operand does not actually exist in the assembler input. This220is used to support extended mnemonics such as mr, for which two221operands fields are identical. The assembler should call the222insert function with any op value. The disassembler should call223the extract function, ignore the return value, and check the value224placed in the valid argument. */225#define PPC_OPERAND_FAKE (04)226227/* The next operand should be wrapped in parentheses rather than228separated from this one by a comma. This is used for the load and229store instructions which want their operands to look like230reg,displacement(reg)231*/232#define PPC_OPERAND_PARENS (010)233234/* This operand may use the symbolic names for the CR fields, which235are236lt 0 gt 1 eq 2 so 3 un 3237cr0 0 cr1 1 cr2 2 cr3 3238cr4 4 cr5 5 cr6 6 cr7 7239These may be combined arithmetically, as in cr2*4+gt. These are240only supported on the PowerPC, not the POWER. */241#define PPC_OPERAND_CR (020)242243/* This operand names a register. The disassembler uses this to print244register names with a leading 'r'. */245#define PPC_OPERAND_GPR (040)246247/* Like PPC_OPERAND_GPR, but don't print a leading 'r' for r0. */248#define PPC_OPERAND_GPR_0 (0100)249250/* This operand names a floating point register. The disassembler251prints these with a leading 'f'. */252#define PPC_OPERAND_FPR (0200)253254/* This operand is a relative branch displacement. The disassembler255prints these symbolically if possible. */256#define PPC_OPERAND_RELATIVE (0400)257258/* This operand is an absolute branch address. The disassembler259prints these symbolically if possible. */260#define PPC_OPERAND_ABSOLUTE (01000)261262/* This operand is optional, and is zero if omitted. This is used for263example, in the optional BF field in the comparison instructions. The264assembler must count the number of operands remaining on the line,265and the number of operands remaining for the opcode, and decide266whether this operand is present or not. The disassembler should267print this operand out only if it is not zero. */268#define PPC_OPERAND_OPTIONAL (02000)269270/* This flag is only used with PPC_OPERAND_OPTIONAL. If this operand271is omitted, then for the next operand use this operand value plus2721, ignoring the next operand field for the opcode. This wretched273hack is needed because the Power rotate instructions can take274either 4 or 5 operands. The disassembler should print this operand275out regardless of the PPC_OPERAND_OPTIONAL field. */276#define PPC_OPERAND_NEXT (04000)277278/* This operand should be regarded as a negative number for the279purposes of overflow checking (i.e., the normal most negative280number is disallowed and one more than the normal most positive281number is allowed). This flag will only be set for a signed282operand. */283#define PPC_OPERAND_NEGATIVE (010000)284285/* This operand names a vector unit register. The disassembler286prints these with a leading 'v'. */287#define PPC_OPERAND_VR (020000)288289/* This operand is for the DS field in a DS form instruction. */290#define PPC_OPERAND_DS (040000)291292/* This operand is for the DQ field in a DQ form instruction. */293#define PPC_OPERAND_DQ (0100000)294295/* The POWER and PowerPC assemblers use a few macros. We keep them296with the operands table for simplicity. The macro table is an297array of struct powerpc_macro. */298299struct powerpc_macro300{301/* The macro name. */302const char *name;303304/* The number of operands the macro takes. */305unsigned int operands;306307/* One bit flags for the opcode. These are used to indicate which308specific processors support the instructions. The values are the309same as those for the struct powerpc_opcode flags field. */310unsigned long flags;311312/* A format string to turn the macro into a normal instruction.313Each %N in the string is replaced with operand number N (zero314based). */315const char *format;316};317318extern const struct powerpc_macro powerpc_macros[];319extern const int powerpc_num_macros;320321#endif /* PPC_H */322323324