ppc.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496
  1. /* ppc.h -- Header file for PowerPC opcode table
  2. Copyright (C) 1994-2022 Free Software Foundation, Inc.
  3. Written by Ian Lance Taylor, Cygnus Support
  4. This file is part of GDB, GAS, and the GNU binutils.
  5. GDB, GAS, and the GNU binutils are free software; you can redistribute
  6. them and/or modify them under the terms of the GNU General Public
  7. License as published by the Free Software Foundation; either version 3,
  8. or (at your option) any later version.
  9. GDB, GAS, and the GNU binutils are distributed in the hope that they
  10. will be useful, but WITHOUT ANY WARRANTY; without even the implied
  11. warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
  12. the GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this file; see the file COPYING3. If not, write to the Free
  15. Software Foundation, 51 Franklin Street - Fifth Floor, Boston,
  16. MA 02110-1301, USA. */
  17. #ifndef PPC_H
  18. #define PPC_H
  19. #include <stdint.h>
  20. #ifdef __cplusplus
  21. extern "C" {
  22. #endif
  23. typedef uint64_t ppc_cpu_t;
  24. /* The opcode table is an array of struct powerpc_opcode. */
  25. struct powerpc_opcode
  26. {
  27. /* The opcode name. */
  28. const char *name;
  29. /* The opcode itself. Those bits which will be filled in with
  30. operands are zeroes. */
  31. uint64_t opcode;
  32. /* The opcode mask. This is used by the disassembler. This is a
  33. mask containing ones indicating those bits which must match the
  34. opcode field, and zeroes indicating those bits which need not
  35. match (and are presumably filled in by operands). */
  36. uint64_t mask;
  37. /* One bit flags for the opcode. These are used to indicate which
  38. specific processors support the instructions. The defined values
  39. are listed below. */
  40. ppc_cpu_t flags;
  41. /* One bit flags for the opcode. These are used to indicate which
  42. specific processors no longer support the instructions. The defined
  43. values are listed below. */
  44. ppc_cpu_t deprecated;
  45. /* An array of operand codes. Each code is an index into the
  46. operand table. They appear in the order which the operands must
  47. appear in assembly code, and are terminated by a zero. */
  48. unsigned char operands[8];
  49. };
  50. /* The table itself is sorted by major opcode number, and is otherwise
  51. in the order in which the disassembler should consider
  52. instructions. */
  53. extern const struct powerpc_opcode powerpc_opcodes[];
  54. extern const unsigned int powerpc_num_opcodes;
  55. extern const struct powerpc_opcode prefix_opcodes[];
  56. extern const unsigned int prefix_num_opcodes;
  57. extern const struct powerpc_opcode vle_opcodes[];
  58. extern const unsigned int vle_num_opcodes;
  59. extern const struct powerpc_opcode spe2_opcodes[];
  60. extern const unsigned int spe2_num_opcodes;
  61. /* Values defined for the flags field of a struct powerpc_opcode. */
  62. /* Opcode is defined for the PowerPC architecture. */
  63. #define PPC_OPCODE_PPC 0x1ull
  64. /* Opcode is defined for the POWER (RS/6000) architecture. */
  65. #define PPC_OPCODE_POWER 0x2ull
  66. /* Opcode is defined for the POWER2 (Rios 2) architecture. */
  67. #define PPC_OPCODE_POWER2 0x4ull
  68. /* Opcode is only defined on 64 bit architectures. */
  69. #define PPC_OPCODE_64 0x8ull
  70. /* Opcode is supported by the Motorola PowerPC 601 processor. The 601
  71. is assumed to support all PowerPC (PPC_OPCODE_PPC) instructions,
  72. but it also supports many additional POWER instructions. */
  73. #define PPC_OPCODE_601 0x10ull
  74. /* Opcode is supported in both the Power and PowerPC architectures
  75. (ie, compiler's -mcpu=common or assembler's -mcom). More than just
  76. the intersection of PPC_OPCODE_PPC with the union of PPC_OPCODE_POWER
  77. and PPC_OPCODE_POWER2 because many instructions changed mnemonics
  78. between POWER and POWERPC. */
  79. #define PPC_OPCODE_COMMON 0x20ull
  80. /* Opcode is supported for any Power or PowerPC platform (this is
  81. for the assembler's -many option, and it eliminates duplicates). */
  82. #define PPC_OPCODE_ANY 0x40ull
  83. /* Opcode is supported as part of the 64-bit bridge. */
  84. #define PPC_OPCODE_64_BRIDGE 0x80ull
  85. /* Opcode is supported by Altivec Vector Unit */
  86. #define PPC_OPCODE_ALTIVEC 0x100ull
  87. /* Opcode is supported by PowerPC 403 processor. */
  88. #define PPC_OPCODE_403 0x200ull
  89. /* Opcode is supported by PowerPC BookE processor. */
  90. #define PPC_OPCODE_BOOKE 0x400ull
  91. /* Opcode is only supported by Power4 architecture. */
  92. #define PPC_OPCODE_POWER4 0x800ull
  93. /* Opcode is only supported by e500x2 Core.
  94. This bit, PPC_OPCODE_EFS, PPC_OPCODE_VLE, and all those with APU in
  95. their comment mark opcodes so that when those instructions are used
  96. an APUinfo entry can be generated. */
  97. #define PPC_OPCODE_SPE 0x1000ull
  98. /* Opcode is supported by Integer select APU. */
  99. #define PPC_OPCODE_ISEL 0x2000ull
  100. /* Opcode is an e500 SPE floating point instruction. */
  101. #define PPC_OPCODE_EFS 0x4000ull
  102. /* Opcode is supported by branch locking APU. */
  103. #define PPC_OPCODE_BRLOCK 0x8000ull
  104. /* Opcode is supported by performance monitor APU. */
  105. #define PPC_OPCODE_PMR 0x10000ull
  106. /* Opcode is supported by cache locking APU. */
  107. #define PPC_OPCODE_CACHELCK 0x20000ull
  108. /* Opcode is supported by machine check APU. */
  109. #define PPC_OPCODE_RFMCI 0x40000ull
  110. /* Opcode is supported by PowerPC 440 processor. */
  111. #define PPC_OPCODE_440 0x80000ull
  112. /* Opcode is only supported by Power5 architecture. */
  113. #define PPC_OPCODE_POWER5 0x100000ull
  114. /* Opcode is supported by PowerPC e300 family. */
  115. #define PPC_OPCODE_E300 0x200000ull
  116. /* Opcode is only supported by Power6 architecture. */
  117. #define PPC_OPCODE_POWER6 0x400000ull
  118. /* Opcode is only supported by PowerPC Cell family. */
  119. #define PPC_OPCODE_CELL 0x800000ull
  120. /* Opcode is supported by CPUs with paired singles support. */
  121. #define PPC_OPCODE_PPCPS 0x1000000ull
  122. /* Opcode is supported by Power E500MC */
  123. #define PPC_OPCODE_E500MC 0x2000000ull
  124. /* Opcode is supported by PowerPC 405 processor. */
  125. #define PPC_OPCODE_405 0x4000000ull
  126. /* Opcode is supported by Vector-Scalar (VSX) Unit */
  127. #define PPC_OPCODE_VSX 0x8000000ull
  128. /* Opcode is only supported by Power7 architecture. */
  129. #define PPC_OPCODE_POWER7 0x10000000ull
  130. /* Opcode is supported by A2. */
  131. #define PPC_OPCODE_A2 0x20000000ull
  132. /* Opcode is supported by PowerPC 476 processor. */
  133. #define PPC_OPCODE_476 0x40000000ull
  134. /* Opcode is supported by AppliedMicro Titan core */
  135. #define PPC_OPCODE_TITAN 0x80000000ull
  136. /* Opcode which is supported by the e500 family */
  137. #define PPC_OPCODE_E500 0x100000000ull
  138. /* Opcode is supported by Power E6500 */
  139. #define PPC_OPCODE_E6500 0x200000000ull
  140. /* Opcode is supported by Thread management APU */
  141. #define PPC_OPCODE_TMR 0x400000000ull
  142. /* Opcode which is supported by the VLE extension. */
  143. #define PPC_OPCODE_VLE 0x800000000ull
  144. /* Opcode is only supported by Power8 architecture. */
  145. #define PPC_OPCODE_POWER8 0x1000000000ull
  146. /* Opcode is supported by ppc750cl/Gekko/Broadway. */
  147. #define PPC_OPCODE_750 0x2000000000ull
  148. /* Opcode is supported by ppc7450. */
  149. #define PPC_OPCODE_7450 0x4000000000ull
  150. /* Opcode is supported by ppc821/850/860. */
  151. #define PPC_OPCODE_860 0x8000000000ull
  152. /* Opcode is only supported by Power9 architecture. */
  153. #define PPC_OPCODE_POWER9 0x10000000000ull
  154. /* Opcode is supported by e200z4. */
  155. #define PPC_OPCODE_E200Z4 0x20000000000ull
  156. /* Disassemble to instructions matching later in the opcode table
  157. with fewer "mask" bits set rather than the earlist match. Fewer
  158. "mask" bits set imply a more general form of the opcode, in fact
  159. the underlying machine instruction. */
  160. #define PPC_OPCODE_RAW 0x40000000000ull
  161. /* Opcode is supported by PowerPC LSP */
  162. #define PPC_OPCODE_LSP 0x80000000000ull
  163. /* Opcode is only supported by Freescale SPE2 APU. */
  164. #define PPC_OPCODE_SPE2 0x100000000000ull
  165. /* Opcode is supported by EFS2. */
  166. #define PPC_OPCODE_EFS2 0x200000000000ull
  167. /* Opcode is only supported by power10 architecture. */
  168. #define PPC_OPCODE_POWER10 0x400000000000ull
  169. /* A macro to extract the major opcode from an instruction. */
  170. #define PPC_OP(i) (((i) >> 26) & 0x3f)
  171. /* A macro to determine if the instruction is a 2-byte VLE insn. */
  172. #define PPC_OP_SE_VLE(m) ((m) <= 0xffff)
  173. /* A macro to extract the major opcode from a VLE instruction. */
  174. #define VLE_OP(i,m) (((i) >> ((m) <= 0xffff ? 10 : 26)) & 0x3f)
  175. /* A macro to convert a VLE opcode to a VLE opcode segment. */
  176. #define VLE_OP_TO_SEG(i) ((i) >> 1)
  177. /* A macro to extract the extended opcode from a SPE2 instruction. */
  178. #define SPE2_XOP(i) ((i) & 0x7ff)
  179. /* A macro to convert a SPE2 extended opcode to a SPE2 xopcode segment. */
  180. #define SPE2_XOP_TO_SEG(i) ((i) >> 7)
  181. /* A macro to extract the prefix word from an 8-byte PREFIX instruction. */
  182. #define PPC_GET_PREFIX(i) (((i) >> 32) & ((1LL << 32) - 1))
  183. /* A macro to extract the suffix word from an 8-byte PREFIX instruction. */
  184. #define PPC_GET_SUFFIX(i) ((i) & ((1LL << 32) - 1))
  185. /* A macro to determine whether insn I is an 8-byte prefix instruction. */
  186. #define PPC_PREFIX_P(i) (PPC_OP (PPC_GET_PREFIX (i)) == 0x1)
  187. /* A macro used to hash 8-byte PREFIX instructions. */
  188. #define PPC_PREFIX_SEG(i) (PPC_OP (i) >> 1)
  189. /* The operands table is an array of struct powerpc_operand. */
  190. struct powerpc_operand
  191. {
  192. /* A bitmask of bits in the operand. */
  193. uint64_t bitm;
  194. /* The shift operation to be applied to the operand. No shift
  195. is made if this is zero. For positive values, the operand
  196. is shifted left by SHIFT. For negative values, the operand
  197. is shifted right by -SHIFT. Use PPC_OPSHIFT_INV to indicate
  198. that BITM and SHIFT cannot be used to determine where the
  199. operand goes in the insn. */
  200. int shift;
  201. /* Insertion function. This is used by the assembler. To insert an
  202. operand value into an instruction, check this field.
  203. If it is NULL, execute
  204. if (o->shift >= 0)
  205. i |= (op & o->bitm) << o->shift;
  206. else
  207. i |= (op & o->bitm) >> -o->shift;
  208. (i is the instruction which we are filling in, o is a pointer to
  209. this structure, and op is the operand value).
  210. If this field is not NULL, then simply call it with the
  211. instruction and the operand value. It will return the new value
  212. of the instruction. If the operand value is illegal, *ERRMSG
  213. will be set to a warning string (the operand will be inserted in
  214. any case). If the operand value is legal, *ERRMSG will be
  215. unchanged (most operands can accept any value). */
  216. uint64_t (*insert)
  217. (uint64_t instruction, int64_t op, ppc_cpu_t dialect, const char **errmsg);
  218. /* Extraction function. This is used by the disassembler. To
  219. extract this operand type from an instruction, check this field.
  220. If it is NULL, compute
  221. if (o->shift >= 0)
  222. op = (i >> o->shift) & o->bitm;
  223. else
  224. op = (i << -o->shift) & o->bitm;
  225. if ((o->flags & PPC_OPERAND_SIGNED) != 0)
  226. sign_extend (op);
  227. (i is the instruction, o is a pointer to this structure, and op
  228. is the result).
  229. If this field is not NULL, then simply call it with the
  230. instruction value. It will return the value of the operand.
  231. *INVALID will be set to one by the extraction function if this
  232. operand type can not be extracted from this operand (i.e., the
  233. instruction does not match). If the operand is valid, *INVALID
  234. will not be changed. *INVALID will always be non-negative when
  235. used to extract a field from an instruction.
  236. The extraction function is also called by both the assembler and
  237. disassembler if an operand is optional, in which case the
  238. function should return the default value of the operand.
  239. *INVALID is negative in this case, and is the negative count of
  240. omitted optional operands up to and including this operand. */
  241. int64_t (*extract) (uint64_t instruction, ppc_cpu_t dialect, int *invalid);
  242. /* One bit syntax flags. */
  243. unsigned long flags;
  244. };
  245. /* Elements in the table are retrieved by indexing with values from
  246. the operands field of the powerpc_opcodes table. */
  247. extern const struct powerpc_operand powerpc_operands[];
  248. extern const unsigned int num_powerpc_operands;
  249. /* Use with the shift field of a struct powerpc_operand to indicate
  250. that BITM and SHIFT cannot be used to determine where the operand
  251. goes in the insn. */
  252. #define PPC_OPSHIFT_INV (1U << 30)
  253. /* A special case, 6-bit SH field. */
  254. #define PPC_OPSHIFT_SH6 (2U << 30)
  255. /* Values defined for the flags field of a struct powerpc_operand.
  256. Keep the register bits low: They need to fit in an unsigned short. */
  257. /* This operand names a register. The disassembler uses this to print
  258. register names with a leading 'r'. */
  259. #define PPC_OPERAND_GPR (0x1)
  260. /* Like PPC_OPERAND_GPR, but don't print a leading 'r' for r0. */
  261. #define PPC_OPERAND_GPR_0 (0x2)
  262. /* This operand names a floating point register. The disassembler
  263. prints these with a leading 'f'. */
  264. #define PPC_OPERAND_FPR (0x4)
  265. /* This operand names a vector unit register. The disassembler
  266. prints these with a leading 'v'. */
  267. #define PPC_OPERAND_VR (0x8)
  268. /* This operand names a vector-scalar unit register. The disassembler
  269. prints these with a leading 'vs'. */
  270. #define PPC_OPERAND_VSR (0x10)
  271. /* This operand names a VSX accumulator. */
  272. #define PPC_OPERAND_ACC (0x20)
  273. /* This operand may use the symbolic names for the CR fields (even
  274. without -mregnames), which are
  275. lt 0 gt 1 eq 2 so 3 un 3
  276. cr0 0 cr1 1 cr2 2 cr3 3
  277. cr4 4 cr5 5 cr6 6 cr7 7
  278. These may be combined arithmetically, as in cr2*4+gt. These are
  279. only supported on the PowerPC, not the POWER. */
  280. #define PPC_OPERAND_CR_BIT (0x40)
  281. /* This is a CR FIELD that does not use symbolic names (unless
  282. -mregnames is in effect). If both PPC_OPERAND_CR_BIT and
  283. PPC_OPERAND_CR_REG are set then treat the field as per
  284. PPC_OPERAND_CR_BIT for assembly, but as if neither of these
  285. bits are set for disassembly. */
  286. #define PPC_OPERAND_CR_REG (0x80)
  287. /* This operand names a special purpose register. */
  288. #define PPC_OPERAND_SPR (0x100)
  289. /* This operand names a paired-single graphics quantization register. */
  290. #define PPC_OPERAND_GQR (0x200)
  291. /* This operand is a relative branch displacement. The disassembler
  292. prints these symbolically if possible. */
  293. #define PPC_OPERAND_RELATIVE (0x400)
  294. /* This operand is an absolute branch address. The disassembler
  295. prints these symbolically if possible. */
  296. #define PPC_OPERAND_ABSOLUTE (0x800)
  297. /* This operand takes signed values. */
  298. #define PPC_OPERAND_SIGNED (0x1000)
  299. /* This operand takes signed values, but also accepts a full positive
  300. range of values when running in 32 bit mode. That is, if bits is
  301. 16, it takes any value from -0x8000 to 0xffff. In 64 bit mode,
  302. this flag is ignored. */
  303. #define PPC_OPERAND_SIGNOPT (0x2000)
  304. /* The next operand should be wrapped in parentheses rather than
  305. separated from this one by a comma. This is used for the load and
  306. store instructions which want their operands to look like
  307. reg,displacement(reg)
  308. */
  309. #define PPC_OPERAND_PARENS (0x4000)
  310. /* This operand is for the DS field in a DS form instruction. */
  311. #define PPC_OPERAND_DS (0x8000)
  312. /* This operand is for the DQ field in a DQ form instruction. */
  313. #define PPC_OPERAND_DQ (0x10000)
  314. /* This operand should be regarded as a negative number for the
  315. purposes of overflow checking (i.e., the normal most negative
  316. number is disallowed and one more than the normal most positive
  317. number is allowed). This flag will only be set for a signed
  318. operand. */
  319. #define PPC_OPERAND_NEGATIVE (0x20000)
  320. /* Valid range of operand is 0..n rather than 0..n-1. */
  321. #define PPC_OPERAND_PLUS1 (0x40000)
  322. /* This operand is optional, and is zero if omitted. This is used for
  323. example, in the optional BF field in the comparison instructions. The
  324. assembler must count the number of operands remaining on the line,
  325. and the number of operands remaining for the opcode, and decide
  326. whether this operand is present or not. The disassembler should
  327. print this operand out only if it is not zero. */
  328. #define PPC_OPERAND_OPTIONAL (0x80000)
  329. /* This flag is only used with PPC_OPERAND_OPTIONAL. If this operand
  330. is omitted, then for the next operand use this operand value plus
  331. 1, ignoring the next operand field for the opcode. This wretched
  332. hack is needed because the Power rotate instructions can take
  333. either 4 or 5 operands. The disassembler should print this operand
  334. out regardless of the PPC_OPERAND_OPTIONAL field. */
  335. #define PPC_OPERAND_NEXT (0x100000)
  336. /* This flag is only used with PPC_OPERAND_OPTIONAL. The operand is
  337. only optional when generating 32-bit code. */
  338. #define PPC_OPERAND_OPTIONAL32 (0x400000)
  339. /* Xilinx APU and FSL related operands */
  340. #define PPC_OPERAND_FSL (0x800000)
  341. #define PPC_OPERAND_FCR (0x1000000)
  342. #define PPC_OPERAND_UDI (0x2000000)
  343. extern ppc_cpu_t ppc_parse_cpu (ppc_cpu_t, ppc_cpu_t *, const char *);
  344. static inline int64_t
  345. ppc_optional_operand_value (const struct powerpc_operand *operand,
  346. uint64_t insn,
  347. ppc_cpu_t dialect,
  348. int num_optional)
  349. {
  350. if (operand->extract)
  351. return (*operand->extract) (insn, dialect, &num_optional);
  352. return 0;
  353. }
  354. /* PowerPC VLE insns. */
  355. #define E_OPCODE_MASK 0xfc00f800
  356. /* Form I16L, uses 16A relocs. */
  357. #define E_OR2I_INSN 0x7000C000
  358. #define E_AND2I_DOT_INSN 0x7000C800
  359. #define E_OR2IS_INSN 0x7000D000
  360. #define E_LIS_INSN 0x7000E000
  361. #define E_AND2IS_DOT_INSN 0x7000E800
  362. /* Form I16A, uses 16D relocs. */
  363. #define E_ADD2I_DOT_INSN 0x70008800
  364. #define E_ADD2IS_INSN 0x70009000
  365. #define E_CMP16I_INSN 0x70009800
  366. #define E_MULL2I_INSN 0x7000A000
  367. #define E_CMPL16I_INSN 0x7000A800
  368. #define E_CMPH16I_INSN 0x7000B000
  369. #define E_CMPHL16I_INSN 0x7000B800
  370. #define E_LI_INSN 0x70000000
  371. #define E_LI_MASK 0xfc008000
  372. #ifdef __cplusplus
  373. }
  374. #endif
  375. #endif /* PPC_H */