ppc.h revision 130561
160484Sobrien/* ppc.h -- Header file for PowerPC opcode table
2130561Sobrien   Copyright 1994, 1995, 1999, 2000, 2001, 2002, 2003, 2004
392828Sobrien   Free Software Foundation, Inc.
460484Sobrien   Written by Ian Lance Taylor, Cygnus Support
560484Sobrien
660484SobrienThis file is part of GDB, GAS, and the GNU binutils.
760484Sobrien
860484SobrienGDB, GAS, and the GNU binutils are free software; you can redistribute
960484Sobrienthem and/or modify them under the terms of the GNU General Public
1060484SobrienLicense as published by the Free Software Foundation; either version
1160484Sobrien1, or (at your option) any later version.
1260484Sobrien
1360484SobrienGDB, GAS, and the GNU binutils are distributed in the hope that they
1460484Sobrienwill be useful, but WITHOUT ANY WARRANTY; without even the implied
1560484Sobrienwarranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
1660484Sobrienthe GNU General Public License for more details.
1760484Sobrien
1860484SobrienYou should have received a copy of the GNU General Public License
1960484Sobrienalong with this file; see the file COPYING.  If not, write to the Free
2060484SobrienSoftware Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
2160484Sobrien
2260484Sobrien#ifndef PPC_H
2360484Sobrien#define PPC_H
2460484Sobrien
2560484Sobrien/* The opcode table is an array of struct powerpc_opcode.  */
2660484Sobrien
2760484Sobrienstruct powerpc_opcode
2860484Sobrien{
2960484Sobrien  /* The opcode name.  */
3060484Sobrien  const char *name;
3160484Sobrien
3260484Sobrien  /* The opcode itself.  Those bits which will be filled in with
3360484Sobrien     operands are zeroes.  */
3460484Sobrien  unsigned long opcode;
3560484Sobrien
3660484Sobrien  /* The opcode mask.  This is used by the disassembler.  This is a
3760484Sobrien     mask containing ones indicating those bits which must match the
3860484Sobrien     opcode field, and zeroes indicating those bits which need not
3960484Sobrien     match (and are presumably filled in by operands).  */
4060484Sobrien  unsigned long mask;
4160484Sobrien
4260484Sobrien  /* One bit flags for the opcode.  These are used to indicate which
4360484Sobrien     specific processors support the instructions.  The defined values
4460484Sobrien     are listed below.  */
4560484Sobrien  unsigned long flags;
4660484Sobrien
4760484Sobrien  /* An array of operand codes.  Each code is an index into the
4860484Sobrien     operand table.  They appear in the order which the operands must
4960484Sobrien     appear in assembly code, and are terminated by a zero.  */
5060484Sobrien  unsigned char operands[8];
5160484Sobrien};
5260484Sobrien
5360484Sobrien/* The table itself is sorted by major opcode number, and is otherwise
5460484Sobrien   in the order in which the disassembler should consider
5560484Sobrien   instructions.  */
5660484Sobrienextern const struct powerpc_opcode powerpc_opcodes[];
5760484Sobrienextern const int powerpc_num_opcodes;
5860484Sobrien
5960484Sobrien/* Values defined for the flags field of a struct powerpc_opcode.  */
6060484Sobrien
6160484Sobrien/* Opcode is defined for the PowerPC architecture.  */
62130561Sobrien#define PPC_OPCODE_PPC			 1
6360484Sobrien
6460484Sobrien/* Opcode is defined for the POWER (RS/6000) architecture.  */
65130561Sobrien#define PPC_OPCODE_POWER		 2
6660484Sobrien
6760484Sobrien/* Opcode is defined for the POWER2 (Rios 2) architecture.  */
68130561Sobrien#define PPC_OPCODE_POWER2		 4
6960484Sobrien
7060484Sobrien/* Opcode is only defined on 32 bit architectures.  */
71130561Sobrien#define PPC_OPCODE_32			 8
7260484Sobrien
7360484Sobrien/* Opcode is only defined on 64 bit architectures.  */
74130561Sobrien#define PPC_OPCODE_64		      0x10
7560484Sobrien
7660484Sobrien/* Opcode is supported by the Motorola PowerPC 601 processor.  The 601
7760484Sobrien   is assumed to support all PowerPC (PPC_OPCODE_PPC) instructions,
7860484Sobrien   but it also supports many additional POWER instructions.  */
79130561Sobrien#define PPC_OPCODE_601		      0x20
8060484Sobrien
8160484Sobrien/* Opcode is supported in both the Power and PowerPC architectures
8260484Sobrien   (ie, compiler's -mcpu=common or assembler's -mcom).  */
83130561Sobrien#define PPC_OPCODE_COMMON	      0x40
8460484Sobrien
8560484Sobrien/* Opcode is supported for any Power or PowerPC platform (this is
8660484Sobrien   for the assembler's -many option, and it eliminates duplicates).  */
87130561Sobrien#define PPC_OPCODE_ANY		      0x80
8860484Sobrien
8960484Sobrien/* Opcode is supported as part of the 64-bit bridge.  */
90130561Sobrien#define PPC_OPCODE_64_BRIDGE	     0x100
9160484Sobrien
9277298Sobrien/* Opcode is supported by Altivec Vector Unit */
93130561Sobrien#define PPC_OPCODE_ALTIVEC	     0x200
9477298Sobrien
9589857Sobrien/* Opcode is supported by PowerPC 403 processor.  */
96130561Sobrien#define PPC_OPCODE_403		     0x400
9789857Sobrien
9889857Sobrien/* Opcode is supported by PowerPC BookE processor.  */
99130561Sobrien#define PPC_OPCODE_BOOKE	     0x800
10089857Sobrien
10189857Sobrien/* Opcode is only supported by 64-bit PowerPC BookE processor.  */
102130561Sobrien#define PPC_OPCODE_BOOKE64	    0x1000
10389857Sobrien
104130561Sobrien/* Opcode is supported by PowerPC 440 processor.  */
105130561Sobrien#define PPC_OPCODE_440		    0x2000
106130561Sobrien
10792828Sobrien/* Opcode is only supported by Power4 architecture.  */
108130561Sobrien#define PPC_OPCODE_POWER4	    0x4000
10992828Sobrien
11092828Sobrien/* Opcode isn't supported by Power4 architecture.  */
111130561Sobrien#define PPC_OPCODE_NOPOWER4	    0x8000
11292828Sobrien
113130561Sobrien/* Opcode is only supported by POWERPC Classic architecture.  */
114130561Sobrien#define PPC_OPCODE_CLASSIC	   0x10000
115130561Sobrien
116130561Sobrien/* Opcode is only supported by e500x2 Core.  */
117130561Sobrien#define PPC_OPCODE_SPE		   0x20000
118130561Sobrien
119130561Sobrien/* Opcode is supported by e500x2 Integer select APU.  */
120130561Sobrien#define PPC_OPCODE_ISEL		   0x40000
121130561Sobrien
122130561Sobrien/* Opcode is an e500 SPE floating point instruction.  */
123130561Sobrien#define PPC_OPCODE_EFS		   0x80000
124130561Sobrien
125130561Sobrien/* Opcode is supported by branch locking APU.  */
126130561Sobrien#define PPC_OPCODE_BRLOCK	  0x100000
127130561Sobrien
128130561Sobrien/* Opcode is supported by performance monitor APU.  */
129130561Sobrien#define PPC_OPCODE_PMR		  0x200000
130130561Sobrien
131130561Sobrien/* Opcode is supported by cache locking APU.  */
132130561Sobrien#define PPC_OPCODE_CACHELCK	  0x400000
133130561Sobrien
134130561Sobrien/* Opcode is supported by machine check APU.  */
135130561Sobrien#define PPC_OPCODE_RFMCI	  0x800000
136130561Sobrien
13760484Sobrien/* A macro to extract the major opcode from an instruction.  */
13860484Sobrien#define PPC_OP(i) (((i) >> 26) & 0x3f)
13960484Sobrien
14060484Sobrien/* The operands table is an array of struct powerpc_operand.  */
14160484Sobrien
14260484Sobrienstruct powerpc_operand
14360484Sobrien{
14460484Sobrien  /* The number of bits in the operand.  */
14560484Sobrien  int bits;
14660484Sobrien
14760484Sobrien  /* How far the operand is left shifted in the instruction.  */
14860484Sobrien  int shift;
14960484Sobrien
15060484Sobrien  /* Insertion function.  This is used by the assembler.  To insert an
15160484Sobrien     operand value into an instruction, check this field.
15260484Sobrien
15360484Sobrien     If it is NULL, execute
154130561Sobrien	 i |= (op & ((1 << o->bits) - 1)) << o->shift;
15560484Sobrien     (i is the instruction which we are filling in, o is a pointer to
15660484Sobrien     this structure, and op is the opcode value; this assumes twos
15760484Sobrien     complement arithmetic).
15860484Sobrien
15960484Sobrien     If this field is not NULL, then simply call it with the
16060484Sobrien     instruction and the operand value.  It will return the new value
16160484Sobrien     of the instruction.  If the ERRMSG argument is not NULL, then if
16260484Sobrien     the operand value is illegal, *ERRMSG will be set to a warning
16360484Sobrien     string (the operand will be inserted in any case).  If the
16460484Sobrien     operand value is legal, *ERRMSG will be unchanged (most operands
16560484Sobrien     can accept any value).  */
166130561Sobrien  unsigned long (*insert)
167130561Sobrien    (unsigned long instruction, long op, int dialect, const char **errmsg);
16860484Sobrien
16960484Sobrien  /* Extraction function.  This is used by the disassembler.  To
17060484Sobrien     extract this operand type from an instruction, check this field.
17160484Sobrien
17260484Sobrien     If it is NULL, compute
173130561Sobrien	 op = ((i) >> o->shift) & ((1 << o->bits) - 1);
17460484Sobrien	 if ((o->flags & PPC_OPERAND_SIGNED) != 0
17560484Sobrien	     && (op & (1 << (o->bits - 1))) != 0)
17660484Sobrien	   op -= 1 << o->bits;
17760484Sobrien     (i is the instruction, o is a pointer to this structure, and op
17860484Sobrien     is the result; this assumes twos complement arithmetic).
17960484Sobrien
18060484Sobrien     If this field is not NULL, then simply call it with the
18160484Sobrien     instruction value.  It will return the value of the operand.  If
18260484Sobrien     the INVALID argument is not NULL, *INVALID will be set to
18360484Sobrien     non-zero if this operand type can not actually be extracted from
18460484Sobrien     this operand (i.e., the instruction does not match).  If the
18560484Sobrien     operand is valid, *INVALID will not be changed.  */
186130561Sobrien  long (*extract) (unsigned long instruction, int dialect, int *invalid);
18760484Sobrien
18860484Sobrien  /* One bit syntax flags.  */
18960484Sobrien  unsigned long flags;
19060484Sobrien};
19160484Sobrien
19260484Sobrien/* Elements in the table are retrieved by indexing with values from
19360484Sobrien   the operands field of the powerpc_opcodes table.  */
19460484Sobrien
19560484Sobrienextern const struct powerpc_operand powerpc_operands[];
19660484Sobrien
19760484Sobrien/* Values defined for the flags field of a struct powerpc_operand.  */
19860484Sobrien
19960484Sobrien/* This operand takes signed values.  */
20060484Sobrien#define PPC_OPERAND_SIGNED (01)
20160484Sobrien
20260484Sobrien/* This operand takes signed values, but also accepts a full positive
20360484Sobrien   range of values when running in 32 bit mode.  That is, if bits is
20460484Sobrien   16, it takes any value from -0x8000 to 0xffff.  In 64 bit mode,
20560484Sobrien   this flag is ignored.  */
20660484Sobrien#define PPC_OPERAND_SIGNOPT (02)
20760484Sobrien
20860484Sobrien/* This operand does not actually exist in the assembler input.  This
20960484Sobrien   is used to support extended mnemonics such as mr, for which two
21060484Sobrien   operands fields are identical.  The assembler should call the
21160484Sobrien   insert function with any op value.  The disassembler should call
21260484Sobrien   the extract function, ignore the return value, and check the value
21360484Sobrien   placed in the valid argument.  */
21460484Sobrien#define PPC_OPERAND_FAKE (04)
21560484Sobrien
21660484Sobrien/* The next operand should be wrapped in parentheses rather than
21760484Sobrien   separated from this one by a comma.  This is used for the load and
21860484Sobrien   store instructions which want their operands to look like
21960484Sobrien       reg,displacement(reg)
22060484Sobrien   */
22160484Sobrien#define PPC_OPERAND_PARENS (010)
22260484Sobrien
22360484Sobrien/* This operand may use the symbolic names for the CR fields, which
22460484Sobrien   are
22560484Sobrien       lt  0	gt  1	eq  2	so  3	un  3
22660484Sobrien       cr0 0	cr1 1	cr2 2	cr3 3
22760484Sobrien       cr4 4	cr5 5	cr6 6	cr7 7
22860484Sobrien   These may be combined arithmetically, as in cr2*4+gt.  These are
22960484Sobrien   only supported on the PowerPC, not the POWER.  */
23060484Sobrien#define PPC_OPERAND_CR (020)
23160484Sobrien
23260484Sobrien/* This operand names a register.  The disassembler uses this to print
23360484Sobrien   register names with a leading 'r'.  */
23460484Sobrien#define PPC_OPERAND_GPR (040)
23560484Sobrien
236130561Sobrien/* Like PPC_OPERAND_GPR, but don't print a leading 'r' for r0.  */
237130561Sobrien#define PPC_OPERAND_GPR_0 (0100)
238130561Sobrien
23960484Sobrien/* This operand names a floating point register.  The disassembler
24060484Sobrien   prints these with a leading 'f'.  */
241130561Sobrien#define PPC_OPERAND_FPR (0200)
24260484Sobrien
24360484Sobrien/* This operand is a relative branch displacement.  The disassembler
24460484Sobrien   prints these symbolically if possible.  */
245130561Sobrien#define PPC_OPERAND_RELATIVE (0400)
24660484Sobrien
24760484Sobrien/* This operand is an absolute branch address.  The disassembler
24860484Sobrien   prints these symbolically if possible.  */
249130561Sobrien#define PPC_OPERAND_ABSOLUTE (01000)
25060484Sobrien
25160484Sobrien/* This operand is optional, and is zero if omitted.  This is used for
25260484Sobrien   the optional BF and L fields in the comparison instructions.  The
25360484Sobrien   assembler must count the number of operands remaining on the line,
25460484Sobrien   and the number of operands remaining for the opcode, and decide
25560484Sobrien   whether this operand is present or not.  The disassembler should
25660484Sobrien   print this operand out only if it is not zero.  */
257130561Sobrien#define PPC_OPERAND_OPTIONAL (02000)
25860484Sobrien
25960484Sobrien/* This flag is only used with PPC_OPERAND_OPTIONAL.  If this operand
26060484Sobrien   is omitted, then for the next operand use this operand value plus
26160484Sobrien   1, ignoring the next operand field for the opcode.  This wretched
26260484Sobrien   hack is needed because the Power rotate instructions can take
26360484Sobrien   either 4 or 5 operands.  The disassembler should print this operand
26460484Sobrien   out regardless of the PPC_OPERAND_OPTIONAL field.  */
265130561Sobrien#define PPC_OPERAND_NEXT (04000)
26660484Sobrien
26760484Sobrien/* This operand should be regarded as a negative number for the
26860484Sobrien   purposes of overflow checking (i.e., the normal most negative
26960484Sobrien   number is disallowed and one more than the normal most positive
27060484Sobrien   number is allowed).  This flag will only be set for a signed
27160484Sobrien   operand.  */
272130561Sobrien#define PPC_OPERAND_NEGATIVE (010000)
27377298Sobrien
27477298Sobrien/* This operand names a vector unit register.  The disassembler
27577298Sobrien   prints these with a leading 'v'.  */
276130561Sobrien#define PPC_OPERAND_VR (020000)
27777298Sobrien
27889857Sobrien/* This operand is for the DS field in a DS form instruction.  */
279130561Sobrien#define PPC_OPERAND_DS (040000)
280130561Sobrien
281130561Sobrien/* This operand is for the DQ field in a DQ form instruction.  */
282130561Sobrien#define PPC_OPERAND_DQ (0100000)
28360484Sobrien
28460484Sobrien/* The POWER and PowerPC assemblers use a few macros.  We keep them
28560484Sobrien   with the operands table for simplicity.  The macro table is an
28660484Sobrien   array of struct powerpc_macro.  */
28760484Sobrien
28860484Sobrienstruct powerpc_macro
28960484Sobrien{
29060484Sobrien  /* The macro name.  */
29160484Sobrien  const char *name;
29260484Sobrien
29360484Sobrien  /* The number of operands the macro takes.  */
29460484Sobrien  unsigned int operands;
29560484Sobrien
29660484Sobrien  /* One bit flags for the opcode.  These are used to indicate which
29760484Sobrien     specific processors support the instructions.  The values are the
29860484Sobrien     same as those for the struct powerpc_opcode flags field.  */
29960484Sobrien  unsigned long flags;
30060484Sobrien
30160484Sobrien  /* A format string to turn the macro into a normal instruction.
30260484Sobrien     Each %N in the string is replaced with operand number N (zero
30360484Sobrien     based).  */
30460484Sobrien  const char *format;
30560484Sobrien};
30660484Sobrien
30760484Sobrienextern const struct powerpc_macro powerpc_macros[];
30860484Sobrienextern const int powerpc_num_macros;
30960484Sobrien
31060484Sobrien#endif /* PPC_H */
311