You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

112 lines
3.3 KiB

  1. From 195e0be62c0aa0f6aaf63a93ee322bb0a630576c Mon Sep 17 00:00:00 2001
  2. From: Clint Bland <bland.cr@gmail.com>
  3. Date: Wed, 13 Mar 2019 19:19:16 -0700
  4. Subject: [PATCH] Have powerpc use fake GOT like MIPS
  5. ---
  6. src/lj_dispatch.c | 15 +++++++++++++++
  7. src/lj_dispatch.h | 29 ++++++++++++++++++++++++++++-
  8. src/vm_ppc.dasc | 9 ++++++++-
  9. 3 files changed, 51 insertions(+), 2 deletions(-)
  10. --- a/src/lj_dispatch.c
  11. +++ b/src/lj_dispatch.c
  12. @@ -56,6 +56,18 @@ static const ASMFunction dispatch_got[]
  13. #undef GOTFUNC
  14. #endif
  15. +#if LJ_TARGET_PPC
  16. +#include <math.h>
  17. +LJ_FUNCA_NORET void LJ_FASTCALL lj_ffh_coroutine_wrap_err(lua_State *L,
  18. + lua_State *co);
  19. +
  20. +#define GOTFUNC(name) (ASMFunction)name,
  21. +static const ASMFunction dispatch_got[] = {
  22. + GOTDEF(GOTFUNC)
  23. +};
  24. +#undef GOTFUNC
  25. +#endif
  26. +
  27. /* Initialize instruction dispatch table and hot counters. */
  28. void lj_dispatch_init(GG_State *GG)
  29. {
  30. @@ -77,6 +89,9 @@ void lj_dispatch_init(GG_State *GG)
  31. #if LJ_TARGET_MIPS
  32. memcpy(GG->got, dispatch_got, LJ_GOT__MAX*sizeof(ASMFunction *));
  33. #endif
  34. +#if LJ_TARGET_PPC
  35. + memcpy(GG->got, dispatch_got, LJ_GOT__MAX*4);
  36. +#endif
  37. }
  38. #if LJ_HASJIT
  39. --- a/src/lj_dispatch.h
  40. +++ b/src/lj_dispatch.h
  41. @@ -66,6 +66,33 @@ GOTDEF(GOTENUM)
  42. };
  43. #endif
  44. +#if LJ_TARGET_PPC
  45. +/* Need our own global offset table for the dreaded MIPS calling conventions. */
  46. +#if LJ_SOFTFP
  47. +#ifndef _LJ_IRCALL_H
  48. +extern double __ledf2(double a, double b);
  49. +extern double __adddf3(double a, double b);
  50. +extern double __subdf3(double a, double b);
  51. +extern double __muldf3(double a, double b);
  52. +extern double __divdf3(double a, double b);
  53. +#endif
  54. +#define SFGOTDEF(_) _(__ledf2) _(__adddf3) _(__subdf3) _(__muldf3) _(__divdf3)
  55. +#else
  56. +#define SFGOTDEF(_)
  57. +#endif
  58. +#define GOTDEF(_) \
  59. + _(floor) _(ceil) _(trunc) _(log) _(log10) _(exp) _(sin) _(cos) _(tan) \
  60. + _(asin) _(acos) _(atan) _(sinh) _(cosh) _(tanh) _(frexp) _(modf) _(atan2) \
  61. + _(pow) _(fmod) _(ldexp) _(sqrt) SFGOTDEF(_)
  62. +
  63. +enum {
  64. +#define GOTENUM(name) LJ_GOT_##name,
  65. +GOTDEF(GOTENUM)
  66. +#undef GOTENUM
  67. + LJ_GOT__MAX
  68. +};
  69. +#endif
  70. +
  71. /* Type of hot counter. Must match the code in the assembler VM. */
  72. /* 16 bits are sufficient. Only 0.0015% overhead with maximum slot penalty. */
  73. typedef uint16_t HotCount;
  74. @@ -89,7 +116,7 @@ typedef uint16_t HotCount;
  75. typedef struct GG_State {
  76. lua_State L; /* Main thread. */
  77. global_State g; /* Global state. */
  78. -#if LJ_TARGET_MIPS
  79. +#if LJ_TARGET_MIPS || LJ_TARGET_PPC
  80. ASMFunction got[LJ_GOT__MAX]; /* Global offset table. */
  81. #endif
  82. #if LJ_HASJIT
  83. --- a/src/vm_ppc.dasc
  84. +++ b/src/vm_ppc.dasc
  85. @@ -59,7 +59,12 @@
  86. |.define ENV_OFS, 8
  87. |.endif
  88. |.else // No TOC.
  89. -|.macro blex, target; bl extern target@plt; .endmacro
  90. +|.macro blex, target
  91. +| lwz TMP0, DISPATCH_GOT(target)(DISPATCH)
  92. +| mtctr TMP0
  93. +| bctrl
  94. +| //bl extern target@plt
  95. +|.endmacro
  96. |.macro .toc, a, b; .endmacro
  97. |.endif
  98. |.macro .tocenv, a, b; .if TOCENV; a, b; .endif; .endmacro
  99. @@ -482,6 +487,8 @@
  100. |// Assumes DISPATCH is relative to GL.
  101. #define DISPATCH_GL(field) (GG_DISP2G + (int)offsetof(global_State, field))
  102. #define DISPATCH_J(field) (GG_DISP2J + (int)offsetof(jit_State, field))
  103. +#define GG_DISP2GOT (GG_OFS(got) - GG_OFS(dispatch))
  104. +#define DISPATCH_GOT(name) (GG_DISP2GOT + 4*LJ_GOT_##name)
  105. |
  106. #define PC2PROTO(field) ((int)offsetof(GCproto, field)-(int)sizeof(GCproto))
  107. |