ppc.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. /* ppc.h -- Header file for PowerPC opcode table
  2. Copyright 1994, 1995, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006
  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, 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, 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. /* Opcode is only supported by Power5 architecture. */
  100. #define PPC_OPCODE_POWER5 0x1000000
  101. /* Opcode is supported by PowerPC e300 family. */
  102. #define PPC_OPCODE_E300 0x2000000
  103. /* Opcode is only supported by Power6 architecture. */
  104. #define PPC_OPCODE_POWER6 0x4000000
  105. /* Opcode is only supported by PowerPC Cell family. */
  106. #define PPC_OPCODE_CELL 0x8000000
  107. /* A macro to extract the major opcode from an instruction. */
  108. #define PPC_OP(i) (((i) >> 26) & 0x3f)
  109. /* The operands table is an array of struct powerpc_operand. */
  110. struct powerpc_operand
  111. {
  112. /* The number of bits in the operand. */
  113. int bits;
  114. /* How far the operand is left shifted in the instruction. */
  115. int shift;
  116. /* Insertion function. This is used by the assembler. To insert an
  117. operand value into an instruction, check this field.
  118. If it is NULL, execute
  119. i |= (op & ((1 << o->bits) - 1)) << o->shift;
  120. (i is the instruction which we are filling in, o is a pointer to
  121. this structure, and op is the opcode value; this assumes twos
  122. complement arithmetic).
  123. If this field is not NULL, then simply call it with the
  124. instruction and the operand value. It will return the new value
  125. of the instruction. If the ERRMSG argument is not NULL, then if
  126. the operand value is illegal, *ERRMSG will be set to a warning
  127. string (the operand will be inserted in any case). If the
  128. operand value is legal, *ERRMSG will be unchanged (most operands
  129. can accept any value). */
  130. unsigned long (*insert)
  131. (unsigned long instruction, long op, int dialect, const char **errmsg);
  132. /* Extraction function. This is used by the disassembler. To
  133. extract this operand type from an instruction, check this field.
  134. If it is NULL, compute
  135. op = ((i) >> o->shift) & ((1 << o->bits) - 1);
  136. if ((o->flags & PPC_OPERAND_SIGNED) != 0
  137. && (op & (1 << (o->bits - 1))) != 0)
  138. op -= 1 << o->bits;
  139. (i is the instruction, o is a pointer to this structure, and op
  140. is the result; this assumes twos complement arithmetic).
  141. If this field is not NULL, then simply call it with the
  142. instruction value. It will return the value of the operand. If
  143. the INVALID argument is not NULL, *INVALID will be set to
  144. non-zero if this operand type can not actually be extracted from
  145. this operand (i.e., the instruction does not match). If the
  146. operand is valid, *INVALID will not be changed. */
  147. long (*extract) (unsigned long instruction, int dialect, int *invalid);
  148. /* One bit syntax flags. */
  149. unsigned long flags;
  150. };
  151. /* Elements in the table are retrieved by indexing with values from
  152. the operands field of the powerpc_opcodes table. */
  153. extern const struct powerpc_operand powerpc_operands[];
  154. /* Values defined for the flags field of a struct powerpc_operand. */
  155. /* This operand takes signed values. */
  156. #define PPC_OPERAND_SIGNED (01)
  157. /* This operand takes signed values, but also accepts a full positive
  158. range of values when running in 32 bit mode. That is, if bits is
  159. 16, it takes any value from -0x8000 to 0xffff. In 64 bit mode,
  160. this flag is ignored. */
  161. #define PPC_OPERAND_SIGNOPT (02)
  162. /* This operand does not actually exist in the assembler input. This
  163. is used to support extended mnemonics such as mr, for which two
  164. operands fields are identical. The assembler should call the
  165. insert function with any op value. The disassembler should call
  166. the extract function, ignore the return value, and check the value
  167. placed in the valid argument. */
  168. #define PPC_OPERAND_FAKE (04)
  169. /* The next operand should be wrapped in parentheses rather than
  170. separated from this one by a comma. This is used for the load and
  171. store instructions which want their operands to look like
  172. reg,displacement(reg)
  173. */
  174. #define PPC_OPERAND_PARENS (010)
  175. /* This operand may use the symbolic names for the CR fields, which
  176. are
  177. lt 0 gt 1 eq 2 so 3 un 3
  178. cr0 0 cr1 1 cr2 2 cr3 3
  179. cr4 4 cr5 5 cr6 6 cr7 7
  180. These may be combined arithmetically, as in cr2*4+gt. These are
  181. only supported on the PowerPC, not the POWER. */
  182. #define PPC_OPERAND_CR (020)
  183. /* This operand names a register. The disassembler uses this to print
  184. register names with a leading 'r'. */
  185. #define PPC_OPERAND_GPR (040)
  186. /* Like PPC_OPERAND_GPR, but don't print a leading 'r' for r0. */
  187. #define PPC_OPERAND_GPR_0 (0100)
  188. /* This operand names a floating point register. The disassembler
  189. prints these with a leading 'f'. */
  190. #define PPC_OPERAND_FPR (0200)
  191. /* This operand is a relative branch displacement. The disassembler
  192. prints these symbolically if possible. */
  193. #define PPC_OPERAND_RELATIVE (0400)
  194. /* This operand is an absolute branch address. The disassembler
  195. prints these symbolically if possible. */
  196. #define PPC_OPERAND_ABSOLUTE (01000)
  197. /* This operand is optional, and is zero if omitted. This is used for
  198. example, in the optional BF field in the comparison instructions. The
  199. assembler must count the number of operands remaining on the line,
  200. and the number of operands remaining for the opcode, and decide
  201. whether this operand is present or not. The disassembler should
  202. print this operand out only if it is not zero. */
  203. #define PPC_OPERAND_OPTIONAL (02000)
  204. /* This flag is only used with PPC_OPERAND_OPTIONAL. If this operand
  205. is omitted, then for the next operand use this operand value plus
  206. 1, ignoring the next operand field for the opcode. This wretched
  207. hack is needed because the Power rotate instructions can take
  208. either 4 or 5 operands. The disassembler should print this operand
  209. out regardless of the PPC_OPERAND_OPTIONAL field. */
  210. #define PPC_OPERAND_NEXT (04000)
  211. /* This operand should be regarded as a negative number for the
  212. purposes of overflow checking (i.e., the normal most negative
  213. number is disallowed and one more than the normal most positive
  214. number is allowed). This flag will only be set for a signed
  215. operand. */
  216. #define PPC_OPERAND_NEGATIVE (010000)
  217. /* This operand names a vector unit register. The disassembler
  218. prints these with a leading 'v'. */
  219. #define PPC_OPERAND_VR (020000)
  220. /* This operand is for the DS field in a DS form instruction. */
  221. #define PPC_OPERAND_DS (040000)
  222. /* This operand is for the DQ field in a DQ form instruction. */
  223. #define PPC_OPERAND_DQ (0100000)
  224. /* The POWER and PowerPC assemblers use a few macros. We keep them
  225. with the operands table for simplicity. The macro table is an
  226. array of struct powerpc_macro. */
  227. struct powerpc_macro
  228. {
  229. /* The macro name. */
  230. const char *name;
  231. /* The number of operands the macro takes. */
  232. unsigned int operands;
  233. /* One bit flags for the opcode. These are used to indicate which
  234. specific processors support the instructions. The values are the
  235. same as those for the struct powerpc_opcode flags field. */
  236. unsigned long flags;
  237. /* A format string to turn the macro into a normal instruction.
  238. Each %N in the string is replaced with operand number N (zero
  239. based). */
  240. const char *format;
  241. };
  242. extern const struct powerpc_macro powerpc_macros[];
  243. extern const int powerpc_num_macros;
  244. #endif /* PPC_H */