lj_target_ppc.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. /*
  2. ** Definitions for PPC CPUs.
  3. ** Copyright (C) 2005-2023 Mike Pall. See Copyright Notice in luajit.h
  4. */
  5. #ifndef _LJ_TARGET_PPC_H
  6. #define _LJ_TARGET_PPC_H
  7. /* -- Registers IDs ------------------------------------------------------- */
  8. #define GPRDEF(_) \
  9. _(R0) _(SP) _(SYS1) _(R3) _(R4) _(R5) _(R6) _(R7) \
  10. _(R8) _(R9) _(R10) _(R11) _(R12) _(SYS2) _(R14) _(R15) \
  11. _(R16) _(R17) _(R18) _(R19) _(R20) _(R21) _(R22) _(R23) \
  12. _(R24) _(R25) _(R26) _(R27) _(R28) _(R29) _(R30) _(R31)
  13. #define FPRDEF(_) \
  14. _(F0) _(F1) _(F2) _(F3) _(F4) _(F5) _(F6) _(F7) \
  15. _(F8) _(F9) _(F10) _(F11) _(F12) _(F13) _(F14) _(F15) \
  16. _(F16) _(F17) _(F18) _(F19) _(F20) _(F21) _(F22) _(F23) \
  17. _(F24) _(F25) _(F26) _(F27) _(F28) _(F29) _(F30) _(F31)
  18. #define VRIDDEF(_)
  19. #define RIDENUM(name) RID_##name,
  20. enum {
  21. GPRDEF(RIDENUM) /* General-purpose registers (GPRs). */
  22. FPRDEF(RIDENUM) /* Floating-point registers (FPRs). */
  23. RID_MAX,
  24. RID_TMP = RID_R0,
  25. /* Calling conventions. */
  26. RID_RET = RID_R3,
  27. RID_RETHI = RID_R3,
  28. RID_RETLO = RID_R4,
  29. RID_FPRET = RID_F1,
  30. /* These definitions must match with the *.dasc file(s): */
  31. RID_BASE = RID_R14, /* Interpreter BASE. */
  32. RID_LPC = RID_R16, /* Interpreter PC. */
  33. RID_DISPATCH = RID_R17, /* Interpreter DISPATCH table. */
  34. RID_LREG = RID_R18, /* Interpreter L. */
  35. RID_JGL = RID_R31, /* On-trace: global_State + 32768. */
  36. /* Register ranges [min, max) and number of registers. */
  37. RID_MIN_GPR = RID_R0,
  38. RID_MAX_GPR = RID_R31+1,
  39. RID_MIN_FPR = RID_F0,
  40. RID_MAX_FPR = RID_F31+1,
  41. RID_NUM_GPR = RID_MAX_GPR - RID_MIN_GPR,
  42. RID_NUM_FPR = RID_MAX_FPR - RID_MIN_FPR
  43. };
  44. #define RID_NUM_KREF RID_NUM_GPR
  45. #define RID_MIN_KREF RID_R0
  46. /* -- Register sets ------------------------------------------------------- */
  47. /* Make use of all registers, except TMP, SP, SYS1, SYS2 and JGL. */
  48. #define RSET_FIXED \
  49. (RID2RSET(RID_TMP)|RID2RSET(RID_SP)|RID2RSET(RID_SYS1)|\
  50. RID2RSET(RID_SYS2)|RID2RSET(RID_JGL))
  51. #define RSET_GPR (RSET_RANGE(RID_MIN_GPR, RID_MAX_GPR) - RSET_FIXED)
  52. #define RSET_FPR RSET_RANGE(RID_MIN_FPR, RID_MAX_FPR)
  53. #define RSET_ALL (RSET_GPR|RSET_FPR)
  54. #define RSET_INIT RSET_ALL
  55. #define RSET_SCRATCH_GPR (RSET_RANGE(RID_R3, RID_R12+1))
  56. #define RSET_SCRATCH_FPR (RSET_RANGE(RID_F0, RID_F13+1))
  57. #define RSET_SCRATCH (RSET_SCRATCH_GPR|RSET_SCRATCH_FPR)
  58. #define REGARG_FIRSTGPR RID_R3
  59. #define REGARG_LASTGPR RID_R10
  60. #define REGARG_NUMGPR 8
  61. #define REGARG_FIRSTFPR RID_F1
  62. #define REGARG_LASTFPR RID_F8
  63. #define REGARG_NUMFPR 8
  64. /* -- Spill slots --------------------------------------------------------- */
  65. /* Spill slots are 32 bit wide. An even/odd pair is used for FPRs.
  66. **
  67. ** SPS_FIXED: Available fixed spill slots in interpreter frame.
  68. ** This definition must match with the *.dasc file(s).
  69. **
  70. ** SPS_FIRST: First spill slot for general use.
  71. ** [sp+12] tmplo word \
  72. ** [sp+ 8] tmphi word / tmp dword, parameter area for callee
  73. ** [sp+ 4] tmpw, LR of callee
  74. ** [sp+ 0] stack chain
  75. */
  76. #define SPS_FIXED 7
  77. #define SPS_FIRST 4
  78. /* Stack offsets for temporary slots. Used for FP<->int conversions etc. */
  79. #define SPOFS_TMPW 4
  80. #define SPOFS_TMP 8
  81. #define SPOFS_TMPHI 8
  82. #define SPOFS_TMPLO 12
  83. #define sps_scale(slot) (4 * (int32_t)(slot))
  84. #define sps_align(slot) (((slot) - SPS_FIXED + 3) & ~3)
  85. /* -- Exit state ---------------------------------------------------------- */
  86. /* This definition must match with the *.dasc file(s). */
  87. typedef struct {
  88. lua_Number fpr[RID_NUM_FPR]; /* Floating-point registers. */
  89. intptr_t gpr[RID_NUM_GPR]; /* General-purpose registers. */
  90. int32_t spill[256]; /* Spill slots. */
  91. } ExitState;
  92. /* Highest exit + 1 indicates stack check. */
  93. #define EXITSTATE_CHECKEXIT 1
  94. /* Return the address of a per-trace exit stub. */
  95. static LJ_AINLINE uint32_t *exitstub_trace_addr_(uint32_t *p, uint32_t exitno)
  96. {
  97. while (*p == 0x60000000) p++; /* Skip PPCI_NOP. */
  98. return p + 3 + exitno;
  99. }
  100. /* Avoid dependence on lj_jit.h if only including lj_target.h. */
  101. #define exitstub_trace_addr(T, exitno) \
  102. exitstub_trace_addr_((MCode *)((char *)(T)->mcode + (T)->szmcode), (exitno))
  103. /* -- Instructions -------------------------------------------------------- */
  104. /* Instruction fields. */
  105. #define PPCF_CC(cc) ((((cc) & 3) << 16) | (((cc) & 4) << 22))
  106. #define PPCF_T(r) ((r) << 21)
  107. #define PPCF_A(r) ((r) << 16)
  108. #define PPCF_B(r) ((r) << 11)
  109. #define PPCF_C(r) ((r) << 6)
  110. #define PPCF_MB(n) ((n) << 6)
  111. #define PPCF_ME(n) ((n) << 1)
  112. #define PPCF_Y 0x00200000
  113. #define PPCF_DOT 0x00000001
  114. typedef enum PPCIns {
  115. /* Integer instructions. */
  116. PPCI_MR = 0x7c000378,
  117. PPCI_NOP = 0x60000000,
  118. PPCI_LI = 0x38000000,
  119. PPCI_LIS = 0x3c000000,
  120. PPCI_ADD = 0x7c000214,
  121. PPCI_ADDC = 0x7c000014,
  122. PPCI_ADDO = 0x7c000614,
  123. PPCI_ADDE = 0x7c000114,
  124. PPCI_ADDZE = 0x7c000194,
  125. PPCI_ADDME = 0x7c0001d4,
  126. PPCI_ADDI = 0x38000000,
  127. PPCI_ADDIS = 0x3c000000,
  128. PPCI_ADDIC = 0x30000000,
  129. PPCI_ADDICDOT = 0x34000000,
  130. PPCI_SUBF = 0x7c000050,
  131. PPCI_SUBFC = 0x7c000010,
  132. PPCI_SUBFO = 0x7c000450,
  133. PPCI_SUBFE = 0x7c000110,
  134. PPCI_SUBFZE = 0x7c000190,
  135. PPCI_SUBFME = 0x7c0001d0,
  136. PPCI_SUBFIC = 0x20000000,
  137. PPCI_NEG = 0x7c0000d0,
  138. PPCI_AND = 0x7c000038,
  139. PPCI_ANDC = 0x7c000078,
  140. PPCI_NAND = 0x7c0003b8,
  141. PPCI_ANDIDOT = 0x70000000,
  142. PPCI_ANDISDOT = 0x74000000,
  143. PPCI_OR = 0x7c000378,
  144. PPCI_NOR = 0x7c0000f8,
  145. PPCI_ORI = 0x60000000,
  146. PPCI_ORIS = 0x64000000,
  147. PPCI_XOR = 0x7c000278,
  148. PPCI_EQV = 0x7c000238,
  149. PPCI_XORI = 0x68000000,
  150. PPCI_XORIS = 0x6c000000,
  151. PPCI_CMPW = 0x7c000000,
  152. PPCI_CMPLW = 0x7c000040,
  153. PPCI_CMPWI = 0x2c000000,
  154. PPCI_CMPLWI = 0x28000000,
  155. PPCI_MULLW = 0x7c0001d6,
  156. PPCI_MULLI = 0x1c000000,
  157. PPCI_MULLWO = 0x7c0005d6,
  158. PPCI_EXTSB = 0x7c000774,
  159. PPCI_EXTSH = 0x7c000734,
  160. PPCI_SLW = 0x7c000030,
  161. PPCI_SRW = 0x7c000430,
  162. PPCI_SRAW = 0x7c000630,
  163. PPCI_SRAWI = 0x7c000670,
  164. PPCI_RLWNM = 0x5c000000,
  165. PPCI_RLWINM = 0x54000000,
  166. PPCI_RLWIMI = 0x50000000,
  167. PPCI_B = 0x48000000,
  168. PPCI_BL = 0x48000001,
  169. PPCI_BC = 0x40800000,
  170. PPCI_BCL = 0x40800001,
  171. PPCI_BCTR = 0x4e800420,
  172. PPCI_BCTRL = 0x4e800421,
  173. PPCI_CRANDC = 0x4c000102,
  174. PPCI_CRXOR = 0x4c000182,
  175. PPCI_CRAND = 0x4c000202,
  176. PPCI_CREQV = 0x4c000242,
  177. PPCI_CRORC = 0x4c000342,
  178. PPCI_CROR = 0x4c000382,
  179. PPCI_MFLR = 0x7c0802a6,
  180. PPCI_MTCTR = 0x7c0903a6,
  181. PPCI_MCRXR = 0x7c000400,
  182. /* Load/store instructions. */
  183. PPCI_LWZ = 0x80000000,
  184. PPCI_LBZ = 0x88000000,
  185. PPCI_STW = 0x90000000,
  186. PPCI_STB = 0x98000000,
  187. PPCI_LHZ = 0xa0000000,
  188. PPCI_LHA = 0xa8000000,
  189. PPCI_STH = 0xb0000000,
  190. PPCI_STWU = 0x94000000,
  191. PPCI_LFS = 0xc0000000,
  192. PPCI_LFD = 0xc8000000,
  193. PPCI_STFS = 0xd0000000,
  194. PPCI_STFD = 0xd8000000,
  195. PPCI_LWZX = 0x7c00002e,
  196. PPCI_LBZX = 0x7c0000ae,
  197. PPCI_STWX = 0x7c00012e,
  198. PPCI_STBX = 0x7c0001ae,
  199. PPCI_LHZX = 0x7c00022e,
  200. PPCI_LHAX = 0x7c0002ae,
  201. PPCI_STHX = 0x7c00032e,
  202. PPCI_LWBRX = 0x7c00042c,
  203. PPCI_STWBRX = 0x7c00052c,
  204. PPCI_LFSX = 0x7c00042e,
  205. PPCI_LFDX = 0x7c0004ae,
  206. PPCI_STFSX = 0x7c00052e,
  207. PPCI_STFDX = 0x7c0005ae,
  208. /* FP instructions. */
  209. PPCI_FMR = 0xfc000090,
  210. PPCI_FNEG = 0xfc000050,
  211. PPCI_FABS = 0xfc000210,
  212. PPCI_FRSP = 0xfc000018,
  213. PPCI_FCTIWZ = 0xfc00001e,
  214. PPCI_FADD = 0xfc00002a,
  215. PPCI_FSUB = 0xfc000028,
  216. PPCI_FMUL = 0xfc000032,
  217. PPCI_FDIV = 0xfc000024,
  218. PPCI_FSQRT = 0xfc00002c,
  219. PPCI_FMADD = 0xfc00003a,
  220. PPCI_FMSUB = 0xfc000038,
  221. PPCI_FNMSUB = 0xfc00003c,
  222. PPCI_FCMPU = 0xfc000000,
  223. PPCI_FSEL = 0xfc00002e,
  224. } PPCIns;
  225. typedef enum PPCCC {
  226. CC_GE, CC_LE, CC_NE, CC_NS, CC_LT, CC_GT, CC_EQ, CC_SO
  227. } PPCCC;
  228. #endif