ppc.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. /* ppc.h -- Header file for PowerPC opcode table
  2. Copyright 1994, 1995, 1999, 2000, 2001, 2002, 2003
  3. Free Software Foundation, Inc.
  4. Written by Ian Lance Taylor, Cygnus Support
  5. This file is part of GDB, GAS, and the GNU binutils.
  6. GDB, GAS, and the GNU binutils are free software; you can redistribute
  7. them and/or modify them under the terms of the GNU General Public
  8. License as published by the Free Software Foundation; either version
  9. 1, or (at your option) any later version.
  10. GDB, GAS, and the GNU binutils are distributed in the hope that they
  11. will be useful, but WITHOUT ANY WARRANTY; without even the implied
  12. warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
  13. the GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with this file; see the file COPYING. If not, write to the Free
  16. Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
  17. #ifndef PPC_H
  18. #define PPC_H
  19. /* The opcode table is an array of struct powerpc_opcode. */
  20. struct powerpc_opcode
  21. {
  22. /* The opcode name. */
  23. const char *name;
  24. /* The opcode itself. Those bits which will be filled in with
  25. operands are zeroes. */
  26. unsigned long opcode;
  27. /* The opcode mask. This is used by the disassembler. This is a
  28. mask containing ones indicating those bits which must match the
  29. opcode field, and zeroes indicating those bits which need not
  30. match (and are presumably filled in by operands). */
  31. unsigned long mask;
  32. /* One bit flags for the opcode. These are used to indicate which
  33. specific processors support the instructions. The defined values
  34. are listed below. */
  35. unsigned long flags;
  36. /* An array of operand codes. Each code is an index into the
  37. operand table. They appear in the order which the operands must
  38. appear in assembly code, and are terminated by a zero. */
  39. unsigned char operands[8];
  40. };
  41. /* The table itself is sorted by major opcode number, and is otherwise
  42. in the order in which the disassembler should consider
  43. instructions. */
  44. extern const struct powerpc_opcode powerpc_opcodes[];
  45. extern const int powerpc_num_opcodes;
  46. /* Values defined for the flags field of a struct powerpc_opcode. */
  47. /* Opcode is defined for the PowerPC architecture. */
  48. #define PPC_OPCODE_PPC 1
  49. /* Opcode is defined for the POWER (RS/6000) architecture. */
  50. #define PPC_OPCODE_POWER 2
  51. /* Opcode is defined for the POWER2 (Rios 2) architecture. */
  52. #define PPC_OPCODE_POWER2 4
  53. /* Opcode is only defined on 32 bit architectures. */
  54. #define PPC_OPCODE_32 8
  55. /* Opcode is only defined on 64 bit architectures. */
  56. #define PPC_OPCODE_64 0x10
  57. /* Opcode is supported by the Motorola PowerPC 601 processor. The 601
  58. is assumed to support all PowerPC (PPC_OPCODE_PPC) instructions,
  59. but it also supports many additional POWER instructions. */
  60. #define PPC_OPCODE_601 0x20
  61. /* Opcode is supported in both the Power and PowerPC architectures
  62. (ie, compiler's -mcpu=common or assembler's -mcom). */
  63. #define PPC_OPCODE_COMMON 0x40
  64. /* Opcode is supported for any Power or PowerPC platform (this is
  65. for the assembler's -many option, and it eliminates duplicates). */
  66. #define PPC_OPCODE_ANY 0x80
  67. /* Opcode is supported as part of the 64-bit bridge. */
  68. #define PPC_OPCODE_64_BRIDGE 0x100
  69. /* Opcode is supported by Altivec Vector Unit */
  70. #define PPC_OPCODE_ALTIVEC 0x200
  71. /* Opcode is supported by PowerPC 403 processor. */
  72. #define PPC_OPCODE_403 0x400
  73. /* Opcode is supported by PowerPC BookE processor. */
  74. #define PPC_OPCODE_BOOKE 0x800
  75. /* Opcode is only supported by 64-bit PowerPC BookE processor. */
  76. #define PPC_OPCODE_BOOKE64 0x1000
  77. /* Opcode is supported by PowerPC 440 processor. */
  78. #define PPC_OPCODE_440 0x2000
  79. /* Opcode is only supported by Power4 architecture. */
  80. #define PPC_OPCODE_POWER4 0x4000
  81. /* Opcode isn't supported by Power4 architecture. */
  82. #define PPC_OPCODE_NOPOWER4 0x8000
  83. /* Opcode is only supported by POWERPC Classic architecture. */
  84. #define PPC_OPCODE_CLASSIC 0x10000
  85. /* Opcode is only supported by e500x2 Core. */
  86. #define PPC_OPCODE_SPE 0x20000
  87. /* Opcode is supported by e500x2 Integer select APU. */
  88. #define PPC_OPCODE_ISEL 0x40000
  89. /* Opcode is an e500 SPE floating point instruction. */
  90. #define PPC_OPCODE_EFS 0x80000
  91. /* Opcode is supported by branch locking APU. */
  92. #define PPC_OPCODE_BRLOCK 0x100000
  93. /* Opcode is supported by performance monitor APU. */
  94. #define PPC_OPCODE_PMR 0x200000
  95. /* Opcode is supported by cache locking APU. */
  96. #define PPC_OPCODE_CACHELCK 0x400000
  97. /* Opcode is supported by machine check APU. */
  98. #define PPC_OPCODE_RFMCI 0x800000
  99. /* A macro to extract the major opcode from an instruction. */
  100. #define PPC_OP(i) (((i) >> 26) & 0x3f)
  101. /* The operands table is an array of struct powerpc_operand. */
  102. struct powerpc_operand
  103. {
  104. /* The number of bits in the operand. */
  105. int bits;
  106. /* How far the operand is left shifted in the instruction. */
  107. int shift;
  108. /* Insertion function. This is used by the assembler. To insert an
  109. operand value into an instruction, check this field.
  110. If it is NULL, execute
  111. i |= (op & ((1 << o->bits) - 1)) << o->shift;
  112. (i is the instruction which we are filling in, o is a pointer to
  113. this structure, and op is the opcode value; this assumes twos
  114. complement arithmetic).
  115. If this field is not NULL, then simply call it with the
  116. instruction and the operand value. It will return the new value
  117. of the instruction. If the ERRMSG argument is not NULL, then if
  118. the operand value is illegal, *ERRMSG will be set to a warning
  119. string (the operand will be inserted in any case). If the
  120. operand value is legal, *ERRMSG will be unchanged (most operands
  121. can accept any value). */
  122. unsigned long (*insert)
  123. (unsigned long instruction, long op, int dialect, const char **errmsg);
  124. /* Extraction function. This is used by the disassembler. To
  125. extract this operand type from an instruction, check this field.
  126. If it is NULL, compute
  127. op = ((i) >> o->shift) & ((1 << o->bits) - 1);
  128. if ((o->flags & PPC_OPERAND_SIGNED) != 0
  129. && (op & (1 << (o->bits - 1))) != 0)
  130. op -= 1 << o->bits;
  131. (i is the instruction, o is a pointer to this structure, and op
  132. is the result; this assumes twos complement arithmetic).
  133. If this field is not NULL, then simply call it with the
  134. instruction value. It will return the value of the operand. If
  135. the INVALID argument is not NULL, *INVALID will be set to
  136. non-zero if this operand type can not actually be extracted from
  137. this operand (i.e., the instruction does not match). If the
  138. operand is valid, *INVALID will not be changed. */
  139. long (*extract) (unsigned long instruction, int dialect, int *invalid);
  140. /* One bit syntax flags. */
  141. unsigned long flags;
  142. };
  143. /* Elements in the table are retrieved by indexing with values from
  144. the operands field of the powerpc_opcodes table. */
  145. extern const struct powerpc_operand powerpc_operands[];
  146. /* Values defined for the flags field of a struct powerpc_operand. */
  147. /* This operand takes signed values. */
  148. #define PPC_OPERAND_SIGNED (01)
  149. /* This operand takes signed values, but also accepts a full positive
  150. range of values when running in 32 bit mode. That is, if bits is
  151. 16, it takes any value from -0x8000 to 0xffff. In 64 bit mode,
  152. this flag is ignored. */
  153. #define PPC_OPERAND_SIGNOPT (02)
  154. /* This operand does not actually exist in the assembler input. This
  155. is used to support extended mnemonics such as mr, for which two
  156. operands fields are identical. The assembler should call the
  157. insert function with any op value. The disassembler should call
  158. the extract function, ignore the return value, and check the value
  159. placed in the valid argument. */
  160. #define PPC_OPERAND_FAKE (04)
  161. /* The next operand should be wrapped in parentheses rather than
  162. separated from this one by a comma. This is used for the load and
  163. store instructions which want their operands to look like
  164. reg,displacement(reg)
  165. */
  166. #define PPC_OPERAND_PARENS (010)
  167. /* This operand may use the symbolic names for the CR fields, which
  168. are
  169. lt 0 gt 1 eq 2 so 3 un 3
  170. cr0 0 cr1 1 cr2 2 cr3 3
  171. cr4 4 cr5 5 cr6 6 cr7 7
  172. These may be combined arithmetically, as in cr2*4+gt. These are
  173. only supported on the PowerPC, not the POWER. */
  174. #define PPC_OPERAND_CR (020)
  175. /* This operand names a register. The disassembler uses this to print
  176. register names with a leading 'r'. */
  177. #define PPC_OPERAND_GPR (040)
  178. /* This operand names a floating point register. The disassembler
  179. prints these with a leading 'f'. */
  180. #define PPC_OPERAND_FPR (0100)
  181. /* This operand is a relative branch displacement. The disassembler
  182. prints these symbolically if possible. */
  183. #define PPC_OPERAND_RELATIVE (0200)
  184. /* This operand is an absolute branch address. The disassembler
  185. prints these symbolically if possible. */
  186. #define PPC_OPERAND_ABSOLUTE (0400)
  187. /* This operand is optional, and is zero if omitted. This is used for
  188. the optional BF and L fields in the comparison instructions. The
  189. assembler must count the number of operands remaining on the line,
  190. and the number of operands remaining for the opcode, and decide
  191. whether this operand is present or not. The disassembler should
  192. print this operand out only if it is not zero. */
  193. #define PPC_OPERAND_OPTIONAL (01000)
  194. /* This flag is only used with PPC_OPERAND_OPTIONAL. If this operand
  195. is omitted, then for the next operand use this operand value plus
  196. 1, ignoring the next operand field for the opcode. This wretched
  197. hack is needed because the Power rotate instructions can take
  198. either 4 or 5 operands. The disassembler should print this operand
  199. out regardless of the PPC_OPERAND_OPTIONAL field. */
  200. #define PPC_OPERAND_NEXT (02000)
  201. /* This operand should be regarded as a negative number for the
  202. purposes of overflow checking (i.e., the normal most negative
  203. number is disallowed and one more than the normal most positive
  204. number is allowed). This flag will only be set for a signed
  205. operand. */
  206. #define PPC_OPERAND_NEGATIVE (04000)
  207. /* This operand names a vector unit register. The disassembler
  208. prints these with a leading 'v'. */
  209. #define PPC_OPERAND_VR (010000)
  210. /* This operand is for the DS field in a DS form instruction. */
  211. #define PPC_OPERAND_DS (020000)
  212. /* This operand is for the DQ field in a DQ form instruction. */
  213. #define PPC_OPERAND_DQ (040000)
  214. /* The POWER and PowerPC assemblers use a few macros. We keep them
  215. with the operands table for simplicity. The macro table is an
  216. array of struct powerpc_macro. */
  217. struct powerpc_macro
  218. {
  219. /* The macro name. */
  220. const char *name;
  221. /* The number of operands the macro takes. */
  222. unsigned int operands;
  223. /* One bit flags for the opcode. These are used to indicate which
  224. specific processors support the instructions. The values are the
  225. same as those for the struct powerpc_opcode flags field. */
  226. unsigned long flags;
  227. /* A format string to turn the macro into a normal instruction.
  228. Each %N in the string is replaced with operand number N (zero
  229. based). */
  230. const char *format;
  231. };
  232. extern const struct powerpc_macro powerpc_macros[];
  233. extern const int powerpc_num_macros;
  234. #endif /* PPC_H */