xref: /netbsd-src/external/gpl3/gdb/dist/include/opcode/ppc.h (revision 889f3bb010ad20d396fb291b89f202288dac2c87)
198b9484cSchristos /* ppc.h -- Header file for PowerPC opcode table
2*889f3bb0Schristos    Copyright (C) 1994-2024 Free Software Foundation, Inc.
398b9484cSchristos    Written by Ian Lance Taylor, Cygnus Support
498b9484cSchristos 
598b9484cSchristos    This file is part of GDB, GAS, and the GNU binutils.
698b9484cSchristos 
798b9484cSchristos    GDB, GAS, and the GNU binutils are free software; you can redistribute
898b9484cSchristos    them and/or modify them under the terms of the GNU General Public
998b9484cSchristos    License as published by the Free Software Foundation; either version 3,
1098b9484cSchristos    or (at your option) any later version.
1198b9484cSchristos 
1298b9484cSchristos    GDB, GAS, and the GNU binutils are distributed in the hope that they
1398b9484cSchristos    will be useful, but WITHOUT ANY WARRANTY; without even the implied
1498b9484cSchristos    warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
1598b9484cSchristos    the GNU General Public License for more details.
1698b9484cSchristos 
1798b9484cSchristos    You should have received a copy of the GNU General Public License
1898b9484cSchristos    along with this file; see the file COPYING3.  If not, write to the Free
1998b9484cSchristos    Software Foundation, 51 Franklin Street - Fifth Floor, Boston,
2098b9484cSchristos    MA 02110-1301, USA.  */
2198b9484cSchristos 
2298b9484cSchristos #ifndef PPC_H
2398b9484cSchristos #define PPC_H
2498b9484cSchristos 
25924795e6Schristos #include <stdint.h>
2698b9484cSchristos 
27c358683dSchristos #ifdef __cplusplus
28c358683dSchristos extern "C" {
29c358683dSchristos #endif
30c358683dSchristos 
3198b9484cSchristos typedef uint64_t ppc_cpu_t;
32924795e6Schristos typedef uint16_t ppc_opindex_t;
33924795e6Schristos 
34924795e6Schristos /* Smaller of ppc_opindex_t and fx_pcrel_adjust maximum.  Note that
35924795e6Schristos    values extracted from fx_pcrel_adjust are masked with this constant,
36924795e6Schristos    effectively making the field unsigned.  */
37924795e6Schristos #define PPC_OPINDEX_MAX 0xffff
3898b9484cSchristos 
3998b9484cSchristos /* The opcode table is an array of struct powerpc_opcode.  */
4098b9484cSchristos 
4198b9484cSchristos struct powerpc_opcode
4298b9484cSchristos {
4398b9484cSchristos   /* The opcode name.  */
4498b9484cSchristos   const char *name;
4598b9484cSchristos 
4698b9484cSchristos   /* The opcode itself.  Those bits which will be filled in with
4798b9484cSchristos      operands are zeroes.  */
48314094e7Schristos   uint64_t opcode;
4998b9484cSchristos 
5098b9484cSchristos   /* The opcode mask.  This is used by the disassembler.  This is a
5198b9484cSchristos      mask containing ones indicating those bits which must match the
5298b9484cSchristos      opcode field, and zeroes indicating those bits which need not
5398b9484cSchristos      match (and are presumably filled in by operands).  */
54314094e7Schristos   uint64_t mask;
5598b9484cSchristos 
5698b9484cSchristos   /* One bit flags for the opcode.  These are used to indicate which
5798b9484cSchristos      specific processors support the instructions.  The defined values
5898b9484cSchristos      are listed below.  */
5998b9484cSchristos   ppc_cpu_t flags;
6098b9484cSchristos 
6198b9484cSchristos   /* One bit flags for the opcode.  These are used to indicate which
6298b9484cSchristos      specific processors no longer support the instructions.  The defined
6398b9484cSchristos      values are listed below.  */
6498b9484cSchristos   ppc_cpu_t deprecated;
6598b9484cSchristos 
6698b9484cSchristos   /* An array of operand codes.  Each code is an index into the
6798b9484cSchristos      operand table.  They appear in the order which the operands must
6898b9484cSchristos      appear in assembly code, and are terminated by a zero.  */
69924795e6Schristos   ppc_opindex_t operands[8];
7098b9484cSchristos };
7198b9484cSchristos 
7298b9484cSchristos /* The table itself is sorted by major opcode number, and is otherwise
7398b9484cSchristos    in the order in which the disassembler should consider
7498b9484cSchristos    instructions.  */
7598b9484cSchristos extern const struct powerpc_opcode powerpc_opcodes[];
76314094e7Schristos extern const unsigned int powerpc_num_opcodes;
77db9b8011Schristos extern const struct powerpc_opcode prefix_opcodes[];
78db9b8011Schristos extern const unsigned int prefix_num_opcodes;
79a2e2270fSchristos extern const struct powerpc_opcode vle_opcodes[];
80314094e7Schristos extern const unsigned int vle_num_opcodes;
81924795e6Schristos extern const struct powerpc_opcode lsp_opcodes[];
82924795e6Schristos extern const unsigned int lsp_num_opcodes;
83314094e7Schristos extern const struct powerpc_opcode spe2_opcodes[];
84314094e7Schristos extern const unsigned int spe2_num_opcodes;
8598b9484cSchristos 
8698b9484cSchristos /* Values defined for the flags field of a struct powerpc_opcode.  */
8798b9484cSchristos 
8898b9484cSchristos /* Opcode is defined for the PowerPC architecture.  */
893b99ba0fSchristos #define PPC_OPCODE_PPC		       0x1ull
9098b9484cSchristos 
9198b9484cSchristos /* Opcode is defined for the POWER (RS/6000) architecture.  */
923b99ba0fSchristos #define PPC_OPCODE_POWER	       0x2ull
9398b9484cSchristos 
9498b9484cSchristos /* Opcode is defined for the POWER2 (Rios 2) architecture.  */
953b99ba0fSchristos #define PPC_OPCODE_POWER2	       0x4ull
963b99ba0fSchristos 
973b99ba0fSchristos /* Opcode is only defined on 64 bit architectures.  */
983b99ba0fSchristos #define PPC_OPCODE_64		       0x8ull
9998b9484cSchristos 
10098b9484cSchristos /* Opcode is supported by the Motorola PowerPC 601 processor.  The 601
10198b9484cSchristos    is assumed to support all PowerPC (PPC_OPCODE_PPC) instructions,
10298b9484cSchristos    but it also supports many additional POWER instructions.  */
1033b99ba0fSchristos #define PPC_OPCODE_601		      0x10ull
10498b9484cSchristos 
10598b9484cSchristos /* Opcode is supported in both the Power and PowerPC architectures
10698b9484cSchristos    (ie, compiler's -mcpu=common or assembler's -mcom).  More than just
10798b9484cSchristos    the intersection of PPC_OPCODE_PPC with the union of PPC_OPCODE_POWER
10898b9484cSchristos    and PPC_OPCODE_POWER2 because many instructions changed mnemonics
10998b9484cSchristos    between POWER and POWERPC.  */
1103b99ba0fSchristos #define PPC_OPCODE_COMMON	      0x20ull
11198b9484cSchristos 
11298b9484cSchristos /* Opcode is supported for any Power or PowerPC platform (this is
11398b9484cSchristos    for the assembler's -many option, and it eliminates duplicates).  */
1143b99ba0fSchristos #define PPC_OPCODE_ANY		      0x40ull
11598b9484cSchristos 
11698b9484cSchristos /* Opcode is supported as part of the 64-bit bridge.  */
1173b99ba0fSchristos #define PPC_OPCODE_64_BRIDGE	      0x80ull
11898b9484cSchristos 
11998b9484cSchristos /* Opcode is supported by Altivec Vector Unit */
1203b99ba0fSchristos #define PPC_OPCODE_ALTIVEC	     0x100ull
12198b9484cSchristos 
12298b9484cSchristos /* Opcode is supported by PowerPC 403 processor.  */
1233b99ba0fSchristos #define PPC_OPCODE_403		     0x200ull
12498b9484cSchristos 
12598b9484cSchristos /* Opcode is supported by PowerPC BookE processor.  */
1263b99ba0fSchristos #define PPC_OPCODE_BOOKE	     0x400ull
12798b9484cSchristos 
12898b9484cSchristos /* Opcode is only supported by Power4 architecture.  */
1293b99ba0fSchristos #define PPC_OPCODE_POWER4	     0x800ull
13098b9484cSchristos 
1313b99ba0fSchristos /* Opcode is only supported by e500x2 Core.
1323b99ba0fSchristos    This bit, PPC_OPCODE_EFS, PPC_OPCODE_VLE, and all those with APU in
1333b99ba0fSchristos    their comment mark opcodes so that when those instructions are used
1343b99ba0fSchristos    an APUinfo entry can be generated.  */
1353b99ba0fSchristos #define PPC_OPCODE_SPE		    0x1000ull
13698b9484cSchristos 
1373b99ba0fSchristos /* Opcode is supported by Integer select APU.  */
1383b99ba0fSchristos #define PPC_OPCODE_ISEL		    0x2000ull
13998b9484cSchristos 
14098b9484cSchristos /* Opcode is an e500 SPE floating point instruction.  */
1413b99ba0fSchristos #define PPC_OPCODE_EFS		    0x4000ull
14298b9484cSchristos 
14398b9484cSchristos /* Opcode is supported by branch locking APU.  */
1443b99ba0fSchristos #define PPC_OPCODE_BRLOCK	    0x8000ull
14598b9484cSchristos 
14698b9484cSchristos /* Opcode is supported by performance monitor APU.  */
1473b99ba0fSchristos #define PPC_OPCODE_PMR		   0x10000ull
14898b9484cSchristos 
14998b9484cSchristos /* Opcode is supported by cache locking APU.  */
1503b99ba0fSchristos #define PPC_OPCODE_CACHELCK	   0x20000ull
15198b9484cSchristos 
15298b9484cSchristos /* Opcode is supported by machine check APU.  */
1533b99ba0fSchristos #define PPC_OPCODE_RFMCI	   0x40000ull
1543b99ba0fSchristos 
1553b99ba0fSchristos /* Opcode is supported by PowerPC 440 processor.  */
1563b99ba0fSchristos #define PPC_OPCODE_440		   0x80000ull
15798b9484cSchristos 
15898b9484cSchristos /* Opcode is only supported by Power5 architecture.  */
1593b99ba0fSchristos #define PPC_OPCODE_POWER5	  0x100000ull
16098b9484cSchristos 
16198b9484cSchristos /* Opcode is supported by PowerPC e300 family.  */
1623b99ba0fSchristos #define PPC_OPCODE_E300		  0x200000ull
16398b9484cSchristos 
16498b9484cSchristos /* Opcode is only supported by Power6 architecture.  */
1653b99ba0fSchristos #define PPC_OPCODE_POWER6	  0x400000ull
16698b9484cSchristos 
16798b9484cSchristos /* Opcode is only supported by PowerPC Cell family.  */
1683b99ba0fSchristos #define PPC_OPCODE_CELL		  0x800000ull
16998b9484cSchristos 
17098b9484cSchristos /* Opcode is supported by CPUs with paired singles support.  */
1713b99ba0fSchristos #define PPC_OPCODE_PPCPS	 0x1000000ull
17298b9484cSchristos 
17398b9484cSchristos /* Opcode is supported by Power E500MC */
1743b99ba0fSchristos #define PPC_OPCODE_E500MC	 0x2000000ull
17598b9484cSchristos 
17698b9484cSchristos /* Opcode is supported by PowerPC 405 processor.  */
1773b99ba0fSchristos #define PPC_OPCODE_405		 0x4000000ull
17898b9484cSchristos 
17998b9484cSchristos /* Opcode is supported by Vector-Scalar (VSX) Unit */
1803b99ba0fSchristos #define PPC_OPCODE_VSX		 0x8000000ull
1813b99ba0fSchristos 
1823b99ba0fSchristos /* Opcode is only supported by Power7 architecture.  */
1833b99ba0fSchristos #define PPC_OPCODE_POWER7	0x10000000ull
18498b9484cSchristos 
18598b9484cSchristos /* Opcode is supported by A2.  */
1863b99ba0fSchristos #define PPC_OPCODE_A2		0x20000000ull
18798b9484cSchristos 
18898b9484cSchristos /* Opcode is supported by PowerPC 476 processor.  */
1893b99ba0fSchristos #define PPC_OPCODE_476		0x40000000ull
19098b9484cSchristos 
19198b9484cSchristos /* Opcode is supported by AppliedMicro Titan core */
1923b99ba0fSchristos #define PPC_OPCODE_TITAN	0x80000000ull
19398b9484cSchristos 
19498b9484cSchristos /* Opcode which is supported by the e500 family */
19598b9484cSchristos #define PPC_OPCODE_E500        0x100000000ull
19698b9484cSchristos 
197a2e2270fSchristos /* Opcode is supported by Power E6500 */
1983b99ba0fSchristos #define PPC_OPCODE_E6500       0x200000000ull
199a2e2270fSchristos 
200a2e2270fSchristos /* Opcode is supported by Thread management APU */
2013b99ba0fSchristos #define PPC_OPCODE_TMR	       0x400000000ull
202a2e2270fSchristos 
203a2e2270fSchristos /* Opcode which is supported by the VLE extension.  */
2043b99ba0fSchristos #define PPC_OPCODE_VLE	       0x800000000ull
205a2e2270fSchristos 
206a2e2270fSchristos /* Opcode is only supported by Power8 architecture.  */
2073b99ba0fSchristos #define PPC_OPCODE_POWER8     0x1000000000ull
208a2e2270fSchristos 
209314094e7Schristos /* Opcode is supported by ppc750cl/Gekko/Broadway.  */
2103b99ba0fSchristos #define PPC_OPCODE_750	      0x2000000000ull
2117a93e43bSchristos 
2127a93e43bSchristos /* Opcode is supported by ppc7450.  */
2133b99ba0fSchristos #define PPC_OPCODE_7450       0x4000000000ull
2147a93e43bSchristos 
2157a93e43bSchristos /* Opcode is supported by ppc821/850/860.  */
2163b99ba0fSchristos #define PPC_OPCODE_860	      0x8000000000ull
2177a93e43bSchristos 
218c358683dSchristos /* Opcode is only supported by Power9 architecture.  */
2193b99ba0fSchristos #define PPC_OPCODE_POWER9    0x10000000000ull
220c358683dSchristos 
2213b99ba0fSchristos /* Opcode is supported by e200z4.  */
2223b99ba0fSchristos #define PPC_OPCODE_E200Z4    0x20000000000ull
2233b99ba0fSchristos 
2243b99ba0fSchristos /* Disassemble to instructions matching later in the opcode table
2253b99ba0fSchristos    with fewer "mask" bits set rather than the earlist match.  Fewer
2263b99ba0fSchristos    "mask" bits set imply a more general form of the opcode, in fact
2273b99ba0fSchristos    the underlying machine instruction.  */
2283b99ba0fSchristos #define PPC_OPCODE_RAW	     0x40000000000ull
229c358683dSchristos 
230314094e7Schristos /* Opcode is supported by PowerPC LSP */
231314094e7Schristos #define PPC_OPCODE_LSP	     0x80000000000ull
232314094e7Schristos 
233314094e7Schristos /* Opcode is only supported by Freescale SPE2 APU.  */
234314094e7Schristos #define PPC_OPCODE_SPE2	    0x100000000000ull
235314094e7Schristos 
236314094e7Schristos /* Opcode is supported by EFS2.  */
237314094e7Schristos #define PPC_OPCODE_EFS2	    0x200000000000ull
238314094e7Schristos 
239db9b8011Schristos /* Opcode is only supported by power10 architecture.  */
240db9b8011Schristos #define PPC_OPCODE_POWER10  0x400000000000ull
241db9b8011Schristos 
242924795e6Schristos /* Opcode is only supported by SVP64 extensions (LibreSOC architecture).  */
243924795e6Schristos #define PPC_OPCODE_SVP64    0x800000000000ull
244924795e6Schristos 
245924795e6Schristos /* Opcode is only supported by 'future' architecture.  */
246924795e6Schristos #define PPC_OPCODE_FUTURE  0x1000000000000ull
247924795e6Schristos 
24898b9484cSchristos /* A macro to extract the major opcode from an instruction.  */
24998b9484cSchristos #define PPC_OP(i) (((i) >> 26) & 0x3f)
250a2e2270fSchristos 
251a2e2270fSchristos /* A macro to determine if the instruction is a 2-byte VLE insn.  */
252a2e2270fSchristos #define PPC_OP_SE_VLE(m) ((m) <= 0xffff)
253a2e2270fSchristos 
254a2e2270fSchristos /* A macro to extract the major opcode from a VLE instruction.  */
255a2e2270fSchristos #define VLE_OP(i,m) (((i) >> ((m) <= 0xffff ? 10 : 26)) & 0x3f)
256a2e2270fSchristos 
257a2e2270fSchristos /* A macro to convert a VLE opcode to a VLE opcode segment.  */
258a2e2270fSchristos #define VLE_OP_TO_SEG(i) ((i) >> 1)
259314094e7Schristos 
260924795e6Schristos /* Map LSP insn to lookup segment for disassembly.  */
261924795e6Schristos #define LSP_OP_TO_SEG(i) (((i) & 0x7ff) >> 6)
262924795e6Schristos 
263314094e7Schristos /* A macro to extract the extended opcode from a SPE2 instruction.  */
264314094e7Schristos #define SPE2_XOP(i) ((i) & 0x7ff)
265314094e7Schristos 
266314094e7Schristos /* A macro to convert a SPE2 extended opcode to a SPE2 xopcode segment.  */
267314094e7Schristos #define SPE2_XOP_TO_SEG(i) ((i) >> 7)
268db9b8011Schristos 
269db9b8011Schristos /* A macro to extract the prefix word from an 8-byte PREFIX instruction.  */
270db9b8011Schristos #define PPC_GET_PREFIX(i) (((i) >> 32) & ((1LL << 32) - 1))
271db9b8011Schristos 
272db9b8011Schristos /* A macro to extract the suffix word from an 8-byte PREFIX instruction.  */
273db9b8011Schristos #define PPC_GET_SUFFIX(i) ((i) & ((1LL << 32) - 1))
274db9b8011Schristos 
275db9b8011Schristos /* A macro to determine whether insn I is an 8-byte prefix instruction.  */
276db9b8011Schristos #define PPC_PREFIX_P(i) (PPC_OP (PPC_GET_PREFIX (i)) == 0x1)
277db9b8011Schristos 
278db9b8011Schristos /* A macro used to hash 8-byte PREFIX instructions.  */
279db9b8011Schristos #define PPC_PREFIX_SEG(i) (PPC_OP (i) >> 1)
280db9b8011Schristos 
28198b9484cSchristos 
28298b9484cSchristos /* The operands table is an array of struct powerpc_operand.  */
28398b9484cSchristos 
28498b9484cSchristos struct powerpc_operand
28598b9484cSchristos {
28698b9484cSchristos   /* A bitmask of bits in the operand.  */
287314094e7Schristos   uint64_t bitm;
28898b9484cSchristos 
289a2e2270fSchristos   /* The shift operation to be applied to the operand.  No shift
290a2e2270fSchristos      is made if this is zero.  For positive values, the operand
291a2e2270fSchristos      is shifted left by SHIFT.  For negative values, the operand
292a2e2270fSchristos      is shifted right by -SHIFT.  Use PPC_OPSHIFT_INV to indicate
293a2e2270fSchristos      that BITM and SHIFT cannot be used to determine where the
294a2e2270fSchristos      operand goes in the insn.  */
29598b9484cSchristos   int shift;
29698b9484cSchristos 
29798b9484cSchristos   /* Insertion function.  This is used by the assembler.  To insert an
29898b9484cSchristos      operand value into an instruction, check this field.
29998b9484cSchristos 
30098b9484cSchristos      If it is NULL, execute
301a2e2270fSchristos 	 if (o->shift >= 0)
30298b9484cSchristos 	   i |= (op & o->bitm) << o->shift;
303a2e2270fSchristos 	 else
304a2e2270fSchristos 	   i |= (op & o->bitm) >> -o->shift;
30598b9484cSchristos      (i is the instruction which we are filling in, o is a pointer to
30698b9484cSchristos      this structure, and op is the operand value).
30798b9484cSchristos 
30898b9484cSchristos      If this field is not NULL, then simply call it with the
30998b9484cSchristos      instruction and the operand value.  It will return the new value
310314094e7Schristos      of the instruction.  If the operand value is illegal, *ERRMSG
311314094e7Schristos      will be set to a warning string (the operand will be inserted in
312314094e7Schristos      any case).  If the operand value is legal, *ERRMSG will be
313314094e7Schristos      unchanged (most operands can accept any value).  */
314314094e7Schristos   uint64_t (*insert)
315314094e7Schristos     (uint64_t instruction, int64_t op, ppc_cpu_t dialect, const char **errmsg);
31698b9484cSchristos 
31798b9484cSchristos   /* Extraction function.  This is used by the disassembler.  To
31898b9484cSchristos      extract this operand type from an instruction, check this field.
31998b9484cSchristos 
32098b9484cSchristos      If it is NULL, compute
321a2e2270fSchristos 	 if (o->shift >= 0)
32298b9484cSchristos 	   op = (i >> o->shift) & o->bitm;
323a2e2270fSchristos 	 else
324a2e2270fSchristos 	   op = (i << -o->shift) & o->bitm;
32598b9484cSchristos 	 if ((o->flags & PPC_OPERAND_SIGNED) != 0)
32698b9484cSchristos 	   sign_extend (op);
32798b9484cSchristos      (i is the instruction, o is a pointer to this structure, and op
32898b9484cSchristos      is the result).
32998b9484cSchristos 
33098b9484cSchristos      If this field is not NULL, then simply call it with the
331314094e7Schristos      instruction value.  It will return the value of the operand.
332314094e7Schristos      *INVALID will be set to one by the extraction function if this
333314094e7Schristos      operand type can not be extracted from this operand (i.e., the
334314094e7Schristos      instruction does not match).  If the operand is valid, *INVALID
335314094e7Schristos      will not be changed.  *INVALID will always be non-negative when
336314094e7Schristos      used to extract a field from an instruction.
337314094e7Schristos 
338314094e7Schristos      The extraction function is also called by both the assembler and
339314094e7Schristos      disassembler if an operand is optional, in which case the
340314094e7Schristos      function should return the default value of the operand.
341314094e7Schristos      *INVALID is negative in this case, and is the negative count of
342314094e7Schristos      omitted optional operands up to and including this operand.  */
343314094e7Schristos   int64_t (*extract) (uint64_t instruction, ppc_cpu_t dialect, int *invalid);
34498b9484cSchristos 
34598b9484cSchristos   /* One bit syntax flags.  */
34698b9484cSchristos   unsigned long flags;
34798b9484cSchristos };
34898b9484cSchristos 
34998b9484cSchristos /* Elements in the table are retrieved by indexing with values from
35098b9484cSchristos    the operands field of the powerpc_opcodes table.  */
35198b9484cSchristos 
35298b9484cSchristos extern const struct powerpc_operand powerpc_operands[];
35398b9484cSchristos extern const unsigned int num_powerpc_operands;
35498b9484cSchristos 
355a2e2270fSchristos /* Use with the shift field of a struct powerpc_operand to indicate
356a2e2270fSchristos    that BITM and SHIFT cannot be used to determine where the operand
357a2e2270fSchristos    goes in the insn.  */
358924795e6Schristos #define PPC_OPSHIFT_INV (1U << 30)
359924795e6Schristos /* A special case, 6-bit SH field.  */
360924795e6Schristos #define PPC_OPSHIFT_SH6 (2U << 30)
361a2e2270fSchristos 
3623b99ba0fSchristos /* Values defined for the flags field of a struct powerpc_operand.
3633b99ba0fSchristos    Keep the register bits low:  They need to fit in an unsigned short.  */
3643b99ba0fSchristos 
3653b99ba0fSchristos /* This operand names a register.  The disassembler uses this to print
3663b99ba0fSchristos    register names with a leading 'r'.  */
3673b99ba0fSchristos #define PPC_OPERAND_GPR (0x1)
3683b99ba0fSchristos 
3693b99ba0fSchristos /* Like PPC_OPERAND_GPR, but don't print a leading 'r' for r0.  */
3703b99ba0fSchristos #define PPC_OPERAND_GPR_0 (0x2)
3713b99ba0fSchristos 
3723b99ba0fSchristos /* This operand names a floating point register.  The disassembler
3733b99ba0fSchristos    prints these with a leading 'f'.  */
3743b99ba0fSchristos #define PPC_OPERAND_FPR (0x4)
3753b99ba0fSchristos 
3763b99ba0fSchristos /* This operand names a vector unit register.  The disassembler
3773b99ba0fSchristos    prints these with a leading 'v'.  */
3783b99ba0fSchristos #define PPC_OPERAND_VR (0x8)
3793b99ba0fSchristos 
3803b99ba0fSchristos /* This operand names a vector-scalar unit register.  The disassembler
3813b99ba0fSchristos    prints these with a leading 'vs'.  */
3823b99ba0fSchristos #define PPC_OPERAND_VSR (0x10)
3833b99ba0fSchristos 
384db9b8011Schristos /* This operand names a VSX accumulator.  */
385db9b8011Schristos #define PPC_OPERAND_ACC (0x20)
386db9b8011Schristos 
387924795e6Schristos /* This operand names a dense math register.  */
388924795e6Schristos #define PPC_OPERAND_DMR (0x40)
389924795e6Schristos 
3903b99ba0fSchristos /* This operand may use the symbolic names for the CR fields (even
3913b99ba0fSchristos    without -mregnames), which are
3923b99ba0fSchristos        lt  0	gt  1	eq  2	so  3	un  3
3933b99ba0fSchristos        cr0 0	cr1 1	cr2 2	cr3 3
3943b99ba0fSchristos        cr4 4	cr5 5	cr6 6	cr7 7
3953b99ba0fSchristos    These may be combined arithmetically, as in cr2*4+gt.  These are
3963b99ba0fSchristos    only supported on the PowerPC, not the POWER.  */
397924795e6Schristos #define PPC_OPERAND_CR_BIT (0x80)
3983b99ba0fSchristos 
3993b99ba0fSchristos /* This is a CR FIELD that does not use symbolic names (unless
400db9b8011Schristos    -mregnames is in effect).  If both PPC_OPERAND_CR_BIT and
401db9b8011Schristos    PPC_OPERAND_CR_REG are set then treat the field as per
402db9b8011Schristos    PPC_OPERAND_CR_BIT for assembly, but as if neither of these
403db9b8011Schristos    bits are set for disassembly.  */
404924795e6Schristos #define PPC_OPERAND_CR_REG (0x100)
4053b99ba0fSchristos 
4063b99ba0fSchristos /* This operand names a special purpose register.  */
407924795e6Schristos #define PPC_OPERAND_SPR (0x200)
4083b99ba0fSchristos 
4093b99ba0fSchristos /* This operand names a paired-single graphics quantization register.  */
410924795e6Schristos #define PPC_OPERAND_GQR (0x400)
4113b99ba0fSchristos 
4123b99ba0fSchristos /* This operand is a relative branch displacement.  The disassembler
4133b99ba0fSchristos    prints these symbolically if possible.  */
414924795e6Schristos #define PPC_OPERAND_RELATIVE (0x800)
4153b99ba0fSchristos 
4163b99ba0fSchristos /* This operand is an absolute branch address.  The disassembler
4173b99ba0fSchristos    prints these symbolically if possible.  */
418924795e6Schristos #define PPC_OPERAND_ABSOLUTE (0x1000)
41998b9484cSchristos 
42098b9484cSchristos /* This operand takes signed values.  */
421924795e6Schristos #define PPC_OPERAND_SIGNED (0x2000)
42298b9484cSchristos 
42398b9484cSchristos /* This operand takes signed values, but also accepts a full positive
42498b9484cSchristos    range of values when running in 32 bit mode.  That is, if bits is
42598b9484cSchristos    16, it takes any value from -0x8000 to 0xffff.  In 64 bit mode,
42698b9484cSchristos    this flag is ignored.  */
427924795e6Schristos #define PPC_OPERAND_SIGNOPT (0x4000)
42898b9484cSchristos 
42998b9484cSchristos /* The next operand should be wrapped in parentheses rather than
43098b9484cSchristos    separated from this one by a comma.  This is used for the load and
43198b9484cSchristos    store instructions which want their operands to look like
43298b9484cSchristos        reg,displacement(reg)
43398b9484cSchristos    */
434924795e6Schristos #define PPC_OPERAND_PARENS (0x8000)
43598b9484cSchristos 
43698b9484cSchristos /* This operand is for the DS field in a DS form instruction.  */
437924795e6Schristos #define PPC_OPERAND_DS (0x10000)
43898b9484cSchristos 
43998b9484cSchristos /* This operand is for the DQ field in a DQ form instruction.  */
440924795e6Schristos #define PPC_OPERAND_DQ (0x20000)
44198b9484cSchristos 
4423b99ba0fSchristos /* This operand should be regarded as a negative number for the
4433b99ba0fSchristos    purposes of overflow checking (i.e., the normal most negative
4443b99ba0fSchristos    number is disallowed and one more than the normal most positive
4453b99ba0fSchristos    number is allowed).  This flag will only be set for a signed
4463b99ba0fSchristos    operand.  */
447924795e6Schristos #define PPC_OPERAND_NEGATIVE (0x40000)
4483b99ba0fSchristos 
44998b9484cSchristos /* Valid range of operand is 0..n rather than 0..n-1.  */
450924795e6Schristos #define PPC_OPERAND_PLUS1 (0x80000)
45198b9484cSchristos 
4523b99ba0fSchristos /* This operand is optional, and is zero if omitted.  This is used for
4533b99ba0fSchristos    example, in the optional BF field in the comparison instructions.  The
4543b99ba0fSchristos    assembler must count the number of operands remaining on the line,
4553b99ba0fSchristos    and the number of operands remaining for the opcode, and decide
4563b99ba0fSchristos    whether this operand is present or not.  The disassembler should
4573b99ba0fSchristos    print this operand out only if it is not zero.  */
458924795e6Schristos #define PPC_OPERAND_OPTIONAL (0x100000)
459a2e2270fSchristos 
4603b99ba0fSchristos /* This flag is only used with PPC_OPERAND_OPTIONAL.  If this operand
4613b99ba0fSchristos    is omitted, then for the next operand use this operand value plus
4623b99ba0fSchristos    1, ignoring the next operand field for the opcode.  This wretched
4633b99ba0fSchristos    hack is needed because the Power rotate instructions can take
4643b99ba0fSchristos    either 4 or 5 operands.  The disassembler should print this operand
4653b99ba0fSchristos    out regardless of the PPC_OPERAND_OPTIONAL field.  */
466924795e6Schristos #define PPC_OPERAND_NEXT (0x200000)
4677a93e43bSchristos 
4683b99ba0fSchristos /* This flag is only used with PPC_OPERAND_OPTIONAL.  The operand is
4693b99ba0fSchristos    only optional when generating 32-bit code.  */
4703b99ba0fSchristos #define PPC_OPERAND_OPTIONAL32 (0x400000)
4713b99ba0fSchristos 
4723b99ba0fSchristos /* Xilinx APU and FSL related operands */
4733b99ba0fSchristos #define PPC_OPERAND_FSL (0x800000)
4743b99ba0fSchristos #define PPC_OPERAND_FCR (0x1000000)
4753b99ba0fSchristos #define PPC_OPERAND_UDI (0x2000000)
47698b9484cSchristos 
477924795e6Schristos /* Valid range of operand is 1..n rather than 0..n-1.
478924795e6Schristos    Before encoding, the operand value is decremented.
479924795e6Schristos    After decoding, the operand value is incremented.  */
480924795e6Schristos #define PPC_OPERAND_NONZERO (0x4000000)
48198b9484cSchristos 
482a2e2270fSchristos extern ppc_cpu_t ppc_parse_cpu (ppc_cpu_t, ppc_cpu_t *, const char *);
48398b9484cSchristos 
484314094e7Schristos static inline int64_t
485314094e7Schristos ppc_optional_operand_value (const struct powerpc_operand *operand,
486314094e7Schristos 			    uint64_t insn,
487314094e7Schristos 			    ppc_cpu_t dialect,
488314094e7Schristos 			    int num_optional)
4897a93e43bSchristos {
490314094e7Schristos   if (operand->extract)
491314094e7Schristos     return (*operand->extract) (insn, dialect, &num_optional);
4927a93e43bSchristos   return 0;
4937a93e43bSchristos }
4947a93e43bSchristos 
4953b99ba0fSchristos /* PowerPC VLE insns.  */
496314094e7Schristos #define E_OPCODE_MASK		0xfc00f800
497314094e7Schristos 
4983b99ba0fSchristos /* Form I16L, uses 16A relocs.  */
4993b99ba0fSchristos #define E_OR2I_INSN		0x7000C000
5003b99ba0fSchristos #define E_AND2I_DOT_INSN	0x7000C800
5013b99ba0fSchristos #define E_OR2IS_INSN		0x7000D000
5023b99ba0fSchristos #define E_LIS_INSN		0x7000E000
5033b99ba0fSchristos #define	E_AND2IS_DOT_INSN	0x7000E800
5043b99ba0fSchristos 
5053b99ba0fSchristos /* Form I16A, uses 16D relocs.  */
5063b99ba0fSchristos #define E_ADD2I_DOT_INSN	0x70008800
5073b99ba0fSchristos #define E_ADD2IS_INSN		0x70009000
5083b99ba0fSchristos #define E_CMP16I_INSN		0x70009800
5093b99ba0fSchristos #define E_MULL2I_INSN		0x7000A000
5103b99ba0fSchristos #define E_CMPL16I_INSN		0x7000A800
5113b99ba0fSchristos #define E_CMPH16I_INSN		0x7000B000
5123b99ba0fSchristos #define E_CMPHL16I_INSN		0x7000B800
5133b99ba0fSchristos 
514314094e7Schristos #define E_LI_INSN		0x70000000
515314094e7Schristos #define E_LI_MASK		0xfc008000
516314094e7Schristos 
517c358683dSchristos #ifdef __cplusplus
518c358683dSchristos }
519c358683dSchristos #endif
520c358683dSchristos 
52198b9484cSchristos #endif /* PPC_H */
522