lj_target_mips.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. /*
  2. ** Definitions for MIPS CPUs.
  3. ** Copyright (C) 2005-2014 Mike Pall. See Copyright Notice in luajit.h
  4. */
  5. #ifndef _LJ_TARGET_MIPS_H
  6. #define _LJ_TARGET_MIPS_H
  7. /* -- Registers IDs ------------------------------------------------------- */
  8. #define GPRDEF(_) \
  9. _(R0) _(R1) _(R2) _(R3) _(R4) _(R5) _(R6) _(R7) \
  10. _(R8) _(R9) _(R10) _(R11) _(R12) _(R13) _(R14) _(R15) \
  11. _(R16) _(R17) _(R18) _(R19) _(R20) _(R21) _(R22) _(R23) \
  12. _(R24) _(R25) _(SYS1) _(SYS2) _(R28) _(SP) _(R30) _(RA)
  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_ZERO = RID_R0,
  25. RID_TMP = RID_RA,
  26. /* Calling conventions. */
  27. RID_RET = RID_R2,
  28. #if LJ_LE
  29. RID_RETHI = RID_R3,
  30. RID_RETLO = RID_R2,
  31. #else
  32. RID_RETHI = RID_R2,
  33. RID_RETLO = RID_R3,
  34. #endif
  35. RID_FPRET = RID_F0,
  36. RID_CFUNCADDR = RID_R25,
  37. /* These definitions must match with the *.dasc file(s): */
  38. RID_BASE = RID_R16, /* Interpreter BASE. */
  39. RID_LPC = RID_R18, /* Interpreter PC. */
  40. RID_DISPATCH = RID_R19, /* Interpreter DISPATCH table. */
  41. RID_LREG = RID_R20, /* Interpreter L. */
  42. RID_JGL = RID_R30, /* On-trace: global_State + 32768. */
  43. /* Register ranges [min, max) and number of registers. */
  44. RID_MIN_GPR = RID_R0,
  45. RID_MAX_GPR = RID_RA+1,
  46. RID_MIN_FPR = RID_F0,
  47. RID_MAX_FPR = RID_F31+1,
  48. RID_NUM_GPR = RID_MAX_GPR - RID_MIN_GPR,
  49. RID_NUM_FPR = RID_MAX_FPR - RID_MIN_FPR /* Only even regs are used. */
  50. };
  51. #define RID_NUM_KREF RID_NUM_GPR
  52. #define RID_MIN_KREF RID_R0
  53. /* -- Register sets ------------------------------------------------------- */
  54. /* Make use of all registers, except ZERO, TMP, SP, SYS1, SYS2 and JGL. */
  55. #define RSET_FIXED \
  56. (RID2RSET(RID_ZERO)|RID2RSET(RID_TMP)|RID2RSET(RID_SP)|\
  57. RID2RSET(RID_SYS1)|RID2RSET(RID_SYS2)|RID2RSET(RID_JGL))
  58. #define RSET_GPR (RSET_RANGE(RID_MIN_GPR, RID_MAX_GPR) - RSET_FIXED)
  59. #define RSET_FPR \
  60. (RID2RSET(RID_F0)|RID2RSET(RID_F2)|RID2RSET(RID_F4)|RID2RSET(RID_F6)|\
  61. RID2RSET(RID_F8)|RID2RSET(RID_F10)|RID2RSET(RID_F12)|RID2RSET(RID_F14)|\
  62. RID2RSET(RID_F16)|RID2RSET(RID_F18)|RID2RSET(RID_F20)|RID2RSET(RID_F22)|\
  63. RID2RSET(RID_F24)|RID2RSET(RID_F26)|RID2RSET(RID_F28)|RID2RSET(RID_F30))
  64. #define RSET_ALL (RSET_GPR|RSET_FPR)
  65. #define RSET_INIT RSET_ALL
  66. #define RSET_SCRATCH_GPR \
  67. (RSET_RANGE(RID_R1, RID_R15+1)|\
  68. RID2RSET(RID_R24)|RID2RSET(RID_R25)|RID2RSET(RID_R28))
  69. #define RSET_SCRATCH_FPR \
  70. (RID2RSET(RID_F0)|RID2RSET(RID_F2)|RID2RSET(RID_F4)|RID2RSET(RID_F6)|\
  71. RID2RSET(RID_F8)|RID2RSET(RID_F10)|RID2RSET(RID_F12)|RID2RSET(RID_F14)|\
  72. RID2RSET(RID_F16)|RID2RSET(RID_F18))
  73. #define RSET_SCRATCH (RSET_SCRATCH_GPR|RSET_SCRATCH_FPR)
  74. #define REGARG_FIRSTGPR RID_R4
  75. #define REGARG_LASTGPR RID_R7
  76. #define REGARG_NUMGPR 4
  77. #define REGARG_FIRSTFPR RID_F12
  78. #define REGARG_LASTFPR RID_F14
  79. #define REGARG_NUMFPR 2
  80. /* -- Spill slots --------------------------------------------------------- */
  81. /* Spill slots are 32 bit wide. An even/odd pair is used for FPRs.
  82. **
  83. ** SPS_FIXED: Available fixed spill slots in interpreter frame.
  84. ** This definition must match with the *.dasc file(s).
  85. **
  86. ** SPS_FIRST: First spill slot for general use.
  87. */
  88. #define SPS_FIXED 5
  89. #define SPS_FIRST 4
  90. #define SPOFS_TMP 0
  91. #define sps_scale(slot) (4 * (int32_t)(slot))
  92. #define sps_align(slot) (((slot) - SPS_FIXED + 1) & ~1)
  93. /* -- Exit state ---------------------------------------------------------- */
  94. /* This definition must match with the *.dasc file(s). */
  95. typedef struct {
  96. lua_Number fpr[RID_NUM_FPR]; /* Floating-point registers. */
  97. int32_t gpr[RID_NUM_GPR]; /* General-purpose registers. */
  98. int32_t spill[256]; /* Spill slots. */
  99. } ExitState;
  100. /* Highest exit + 1 indicates stack check. */
  101. #define EXITSTATE_CHECKEXIT 1
  102. /* Return the address of a per-trace exit stub. */
  103. static LJ_AINLINE uint32_t *exitstub_trace_addr_(uint32_t *p)
  104. {
  105. while (*p == 0x00000000) p++; /* Skip MIPSI_NOP. */
  106. return p;
  107. }
  108. /* Avoid dependence on lj_jit.h if only including lj_target.h. */
  109. #define exitstub_trace_addr(T, exitno) \
  110. exitstub_trace_addr_((MCode *)((char *)(T)->mcode + (T)->szmcode))
  111. /* -- Instructions -------------------------------------------------------- */
  112. /* Instruction fields. */
  113. #define MIPSF_S(r) ((r) << 21)
  114. #define MIPSF_T(r) ((r) << 16)
  115. #define MIPSF_D(r) ((r) << 11)
  116. #define MIPSF_R(r) ((r) << 21)
  117. #define MIPSF_H(r) ((r) << 16)
  118. #define MIPSF_G(r) ((r) << 11)
  119. #define MIPSF_F(r) ((r) << 6)
  120. #define MIPSF_A(n) ((n) << 6)
  121. #define MIPSF_M(n) ((n) << 11)
  122. typedef enum MIPSIns {
  123. /* Integer instructions. */
  124. MIPSI_MOVE = 0x00000021,
  125. MIPSI_NOP = 0x00000000,
  126. MIPSI_LI = 0x24000000,
  127. MIPSI_LU = 0x34000000,
  128. MIPSI_LUI = 0x3c000000,
  129. MIPSI_ADDIU = 0x24000000,
  130. MIPSI_ANDI = 0x30000000,
  131. MIPSI_ORI = 0x34000000,
  132. MIPSI_XORI = 0x38000000,
  133. MIPSI_SLTI = 0x28000000,
  134. MIPSI_SLTIU = 0x2c000000,
  135. MIPSI_ADDU = 0x00000021,
  136. MIPSI_SUBU = 0x00000023,
  137. MIPSI_MUL = 0x70000002,
  138. MIPSI_AND = 0x00000024,
  139. MIPSI_OR = 0x00000025,
  140. MIPSI_XOR = 0x00000026,
  141. MIPSI_NOR = 0x00000027,
  142. MIPSI_SLT = 0x0000002a,
  143. MIPSI_SLTU = 0x0000002b,
  144. MIPSI_MOVZ = 0x0000000a,
  145. MIPSI_MOVN = 0x0000000b,
  146. MIPSI_SLL = 0x00000000,
  147. MIPSI_SRL = 0x00000002,
  148. MIPSI_SRA = 0x00000003,
  149. MIPSI_ROTR = 0x00200002, /* MIPS32R2 */
  150. MIPSI_SLLV = 0x00000004,
  151. MIPSI_SRLV = 0x00000006,
  152. MIPSI_SRAV = 0x00000007,
  153. MIPSI_ROTRV = 0x00000046, /* MIPS32R2 */
  154. MIPSI_SEB = 0x7c000420, /* MIPS32R2 */
  155. MIPSI_SEH = 0x7c000620, /* MIPS32R2 */
  156. MIPSI_WSBH = 0x7c0000a0, /* MIPS32R2 */
  157. MIPSI_B = 0x10000000,
  158. MIPSI_J = 0x08000000,
  159. MIPSI_JAL = 0x0c000000,
  160. MIPSI_JR = 0x00000008,
  161. MIPSI_JALR = 0x0000f809,
  162. MIPSI_BEQ = 0x10000000,
  163. MIPSI_BNE = 0x14000000,
  164. MIPSI_BLEZ = 0x18000000,
  165. MIPSI_BGTZ = 0x1c000000,
  166. MIPSI_BLTZ = 0x04000000,
  167. MIPSI_BGEZ = 0x04010000,
  168. /* Load/store instructions. */
  169. MIPSI_LW = 0x8c000000,
  170. MIPSI_SW = 0xac000000,
  171. MIPSI_LB = 0x80000000,
  172. MIPSI_SB = 0xa0000000,
  173. MIPSI_LH = 0x84000000,
  174. MIPSI_SH = 0xa4000000,
  175. MIPSI_LBU = 0x90000000,
  176. MIPSI_LHU = 0x94000000,
  177. MIPSI_LWC1 = 0xc4000000,
  178. MIPSI_SWC1 = 0xe4000000,
  179. MIPSI_LDC1 = 0xd4000000,
  180. MIPSI_SDC1 = 0xf4000000,
  181. /* FP instructions. */
  182. MIPSI_MOV_S = 0x46000006,
  183. MIPSI_MOV_D = 0x46200006,
  184. MIPSI_MOVT_D = 0x46210011,
  185. MIPSI_MOVF_D = 0x46200011,
  186. MIPSI_ABS_D = 0x46200005,
  187. MIPSI_NEG_D = 0x46200007,
  188. MIPSI_ADD_D = 0x46200000,
  189. MIPSI_SUB_D = 0x46200001,
  190. MIPSI_MUL_D = 0x46200002,
  191. MIPSI_DIV_D = 0x46200003,
  192. MIPSI_SQRT_D = 0x46200004,
  193. MIPSI_ADD_S = 0x46000000,
  194. MIPSI_SUB_S = 0x46000001,
  195. MIPSI_CVT_D_S = 0x46000021,
  196. MIPSI_CVT_W_S = 0x46000024,
  197. MIPSI_CVT_S_D = 0x46200020,
  198. MIPSI_CVT_W_D = 0x46200024,
  199. MIPSI_CVT_S_W = 0x46800020,
  200. MIPSI_CVT_D_W = 0x46800021,
  201. MIPSI_TRUNC_W_S = 0x4600000d,
  202. MIPSI_TRUNC_W_D = 0x4620000d,
  203. MIPSI_FLOOR_W_S = 0x4600000f,
  204. MIPSI_FLOOR_W_D = 0x4620000f,
  205. MIPSI_MFC1 = 0x44000000,
  206. MIPSI_MTC1 = 0x44800000,
  207. MIPSI_BC1F = 0x45000000,
  208. MIPSI_BC1T = 0x45010000,
  209. MIPSI_C_EQ_D = 0x46200032,
  210. MIPSI_C_OLT_D = 0x46200034,
  211. MIPSI_C_ULT_D = 0x46200035,
  212. MIPSI_C_OLE_D = 0x46200036,
  213. MIPSI_C_ULE_D = 0x46200037,
  214. } MIPSIns;
  215. #endif