lj_arch.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742
  1. /*
  2. ** Target architecture selection.
  3. ** Copyright (C) 2005-2023 Mike Pall. See Copyright Notice in luajit.h
  4. */
  5. #ifndef _LJ_ARCH_H
  6. #define _LJ_ARCH_H
  7. #include "lua.h"
  8. /* -- Target definitions -------------------------------------------------- */
  9. /* Target endianess. */
  10. #define LUAJIT_LE 0
  11. #define LUAJIT_BE 1
  12. /* Target architectures. */
  13. #define LUAJIT_ARCH_X86 1
  14. #define LUAJIT_ARCH_x86 1
  15. #define LUAJIT_ARCH_X64 2
  16. #define LUAJIT_ARCH_x64 2
  17. #define LUAJIT_ARCH_ARM 3
  18. #define LUAJIT_ARCH_arm 3
  19. #define LUAJIT_ARCH_ARM64 4
  20. #define LUAJIT_ARCH_arm64 4
  21. #define LUAJIT_ARCH_PPC 5
  22. #define LUAJIT_ARCH_ppc 5
  23. #define LUAJIT_ARCH_MIPS 6
  24. #define LUAJIT_ARCH_mips 6
  25. #define LUAJIT_ARCH_MIPS32 6
  26. #define LUAJIT_ARCH_mips32 6
  27. #define LUAJIT_ARCH_MIPS64 7
  28. #define LUAJIT_ARCH_mips64 7
  29. /* Target OS. */
  30. #define LUAJIT_OS_OTHER 0
  31. #define LUAJIT_OS_WINDOWS 1
  32. #define LUAJIT_OS_LINUX 2
  33. #define LUAJIT_OS_OSX 3
  34. #define LUAJIT_OS_BSD 4
  35. #define LUAJIT_OS_POSIX 5
  36. /* Number mode. */
  37. #define LJ_NUMMODE_SINGLE 0 /* Single-number mode only. */
  38. #define LJ_NUMMODE_SINGLE_DUAL 1 /* Default to single-number mode. */
  39. #define LJ_NUMMODE_DUAL 2 /* Dual-number mode only. */
  40. #define LJ_NUMMODE_DUAL_SINGLE 3 /* Default to dual-number mode. */
  41. /* -- Target detection ---------------------------------------------------- */
  42. /* Select native target if no target defined. */
  43. #ifndef LUAJIT_TARGET
  44. #if defined(__i386) || defined(__i386__) || defined(_M_IX86)
  45. #define LUAJIT_TARGET LUAJIT_ARCH_X86
  46. #elif defined(__x86_64__) || defined(__x86_64) || defined(_M_X64) || defined(_M_AMD64)
  47. #define LUAJIT_TARGET LUAJIT_ARCH_X64
  48. #elif defined(__arm__) || defined(__arm) || defined(__ARM__) || defined(__ARM)
  49. #define LUAJIT_TARGET LUAJIT_ARCH_ARM
  50. #elif defined(__aarch64__) || defined(_M_ARM64)
  51. #define LUAJIT_TARGET LUAJIT_ARCH_ARM64
  52. #elif defined(__ppc__) || defined(__ppc) || defined(__PPC__) || defined(__PPC) || defined(__powerpc__) || defined(__powerpc) || defined(__POWERPC__) || defined(__POWERPC) || defined(_M_PPC)
  53. #define LUAJIT_TARGET LUAJIT_ARCH_PPC
  54. #elif defined(__mips64__) || defined(__mips64) || defined(__MIPS64__) || defined(__MIPS64)
  55. #define LUAJIT_TARGET LUAJIT_ARCH_MIPS64
  56. #elif defined(__mips__) || defined(__mips) || defined(__MIPS__) || defined(__MIPS)
  57. #define LUAJIT_TARGET LUAJIT_ARCH_MIPS32
  58. #else
  59. #error "Architecture not supported (in this version), see: https://luajit.org/status.html#architectures"
  60. #endif
  61. #endif
  62. /* Select native OS if no target OS defined. */
  63. #ifndef LUAJIT_OS
  64. #if defined(_WIN32) && !defined(_XBOX_VER)
  65. #define LUAJIT_OS LUAJIT_OS_WINDOWS
  66. #elif defined(__linux__)
  67. #define LUAJIT_OS LUAJIT_OS_LINUX
  68. #elif defined(__MACH__) && defined(__APPLE__)
  69. #include "TargetConditionals.h"
  70. #define LUAJIT_OS LUAJIT_OS_OSX
  71. #elif (defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || \
  72. defined(__NetBSD__) || defined(__OpenBSD__) || \
  73. defined(__DragonFly__)) && !defined(__ORBIS__) && !defined(__PROSPERO__)
  74. #define LUAJIT_OS LUAJIT_OS_BSD
  75. #elif (defined(__sun__) && defined(__svr4__))
  76. #define LJ_TARGET_SOLARIS 1
  77. #define LUAJIT_OS LUAJIT_OS_POSIX
  78. #elif defined(__HAIKU__)
  79. #define LUAJIT_OS LUAJIT_OS_POSIX
  80. #elif defined(__CYGWIN__)
  81. #define LJ_TARGET_CYGWIN 1
  82. #define LUAJIT_OS LUAJIT_OS_POSIX
  83. #elif defined(__QNX__)
  84. #define LJ_TARGET_QNX 1
  85. #define LUAJIT_OS LUAJIT_OS_POSIX
  86. #else
  87. #define LUAJIT_OS LUAJIT_OS_OTHER
  88. #endif
  89. #endif
  90. /* Set target OS properties. */
  91. #if LUAJIT_OS == LUAJIT_OS_WINDOWS
  92. #define LJ_OS_NAME "Windows"
  93. #elif LUAJIT_OS == LUAJIT_OS_LINUX
  94. #define LJ_OS_NAME "Linux"
  95. #elif LUAJIT_OS == LUAJIT_OS_OSX
  96. #define LJ_OS_NAME "OSX"
  97. #elif LUAJIT_OS == LUAJIT_OS_BSD
  98. #define LJ_OS_NAME "BSD"
  99. #elif LUAJIT_OS == LUAJIT_OS_POSIX
  100. #define LJ_OS_NAME "POSIX"
  101. #else
  102. #define LJ_OS_NAME "Other"
  103. #endif
  104. #define LJ_TARGET_WINDOWS (LUAJIT_OS == LUAJIT_OS_WINDOWS)
  105. #define LJ_TARGET_LINUX (LUAJIT_OS == LUAJIT_OS_LINUX)
  106. #define LJ_TARGET_OSX (LUAJIT_OS == LUAJIT_OS_OSX)
  107. #define LJ_TARGET_BSD (LUAJIT_OS == LUAJIT_OS_BSD)
  108. #define LJ_TARGET_POSIX (LUAJIT_OS > LUAJIT_OS_WINDOWS)
  109. #define LJ_TARGET_DLOPEN LJ_TARGET_POSIX
  110. #if TARGET_OS_IPHONE
  111. #define LJ_TARGET_IOS 1
  112. #else
  113. #define LJ_TARGET_IOS 0
  114. #endif
  115. #ifdef __CELLOS_LV2__
  116. #define LJ_TARGET_PS3 1
  117. #define LJ_TARGET_CONSOLE 1
  118. #endif
  119. #ifdef __ORBIS__
  120. #define LJ_TARGET_PS4 1
  121. #define LJ_TARGET_CONSOLE 1
  122. #undef NULL
  123. #define NULL ((void*)0)
  124. #endif
  125. #ifdef __PROSPERO__
  126. #define LJ_TARGET_PS5 1
  127. #define LJ_TARGET_CONSOLE 1
  128. #undef NULL
  129. #define NULL ((void*)0)
  130. #endif
  131. #ifdef __psp2__
  132. #define LJ_TARGET_PSVITA 1
  133. #define LJ_TARGET_CONSOLE 1
  134. #endif
  135. #if _XBOX_VER >= 200
  136. #define LJ_TARGET_XBOX360 1
  137. #define LJ_TARGET_CONSOLE 1
  138. #endif
  139. #ifdef _DURANGO
  140. #define LJ_TARGET_XBOXONE 1
  141. #define LJ_TARGET_CONSOLE 1
  142. #define LJ_TARGET_GC64 1
  143. #endif
  144. #ifdef __NX__
  145. #define LJ_TARGET_NX 1
  146. #define LJ_TARGET_CONSOLE 1
  147. #undef NULL
  148. #define NULL ((void*)0)
  149. #endif
  150. #ifdef _UWP
  151. #define LJ_TARGET_UWP 1
  152. #if LUAJIT_TARGET == LUAJIT_ARCH_X64
  153. #define LJ_TARGET_GC64 1
  154. #endif
  155. #endif
  156. /* -- Arch-specific settings ---------------------------------------------- */
  157. /* Set target architecture properties. */
  158. #if LUAJIT_TARGET == LUAJIT_ARCH_X86
  159. #define LJ_ARCH_NAME "x86"
  160. #define LJ_ARCH_BITS 32
  161. #define LJ_ARCH_ENDIAN LUAJIT_LE
  162. #define LJ_TARGET_X86 1
  163. #define LJ_TARGET_X86ORX64 1
  164. #define LJ_TARGET_EHRETREG 0
  165. #define LJ_TARGET_EHRAREG 8
  166. #define LJ_TARGET_MASKSHIFT 1
  167. #define LJ_TARGET_MASKROT 1
  168. #define LJ_TARGET_UNALIGNED 1
  169. #define LJ_ARCH_NUMMODE LJ_NUMMODE_SINGLE_DUAL
  170. #elif LUAJIT_TARGET == LUAJIT_ARCH_X64
  171. #define LJ_ARCH_NAME "x64"
  172. #define LJ_ARCH_BITS 64
  173. #define LJ_ARCH_ENDIAN LUAJIT_LE
  174. #define LJ_TARGET_X64 1
  175. #define LJ_TARGET_X86ORX64 1
  176. #define LJ_TARGET_EHRETREG 0
  177. #define LJ_TARGET_EHRAREG 16
  178. #define LJ_TARGET_JUMPRANGE 31 /* +-2^31 = +-2GB */
  179. #define LJ_TARGET_MASKSHIFT 1
  180. #define LJ_TARGET_MASKROT 1
  181. #define LJ_TARGET_UNALIGNED 1
  182. #define LJ_ARCH_NUMMODE LJ_NUMMODE_SINGLE_DUAL
  183. #ifndef LUAJIT_DISABLE_GC64
  184. #define LJ_TARGET_GC64 1
  185. #elif LJ_TARGET_OSX
  186. #error "macOS requires GC64 -- don't disable it"
  187. #endif
  188. #elif LUAJIT_TARGET == LUAJIT_ARCH_ARM
  189. #define LJ_ARCH_NAME "arm"
  190. #define LJ_ARCH_BITS 32
  191. #define LJ_ARCH_ENDIAN LUAJIT_LE
  192. #if !defined(LJ_ARCH_HASFPU) && __SOFTFP__
  193. #define LJ_ARCH_HASFPU 0
  194. #endif
  195. #if !defined(LJ_ABI_SOFTFP) && !__ARM_PCS_VFP
  196. #define LJ_ABI_SOFTFP 1
  197. #endif
  198. #define LJ_ABI_EABI 1
  199. #define LJ_TARGET_ARM 1
  200. #define LJ_TARGET_EHRETREG 0
  201. #define LJ_TARGET_EHRAREG 14
  202. #define LJ_TARGET_JUMPRANGE 25 /* +-2^25 = +-32MB */
  203. #define LJ_TARGET_MASKSHIFT 0
  204. #define LJ_TARGET_MASKROT 1
  205. #define LJ_TARGET_UNIFYROT 2 /* Want only IR_BROR. */
  206. #define LJ_ARCH_NUMMODE LJ_NUMMODE_DUAL
  207. #if __ARM_ARCH >= 8 || __ARM_ARCH_8__ || __ARM_ARCH_8A__
  208. #define LJ_ARCH_VERSION 80
  209. #elif __ARM_ARCH == 7 || __ARM_ARCH_7__ || __ARM_ARCH_7A__ || __ARM_ARCH_7R__ || __ARM_ARCH_7S__ || __ARM_ARCH_7VE__
  210. #define LJ_ARCH_VERSION 70
  211. #elif __ARM_ARCH_6T2__
  212. #define LJ_ARCH_VERSION 61
  213. #elif __ARM_ARCH == 6 || __ARM_ARCH_6__ || __ARM_ARCH_6J__ || __ARM_ARCH_6K__ || __ARM_ARCH_6Z__ || __ARM_ARCH_6ZK__
  214. #define LJ_ARCH_VERSION 60
  215. #else
  216. #define LJ_ARCH_VERSION 50
  217. #endif
  218. #elif LUAJIT_TARGET == LUAJIT_ARCH_ARM64
  219. #define LJ_ARCH_BITS 64
  220. #if defined(__AARCH64EB__)
  221. #define LJ_ARCH_NAME "arm64be"
  222. #define LJ_ARCH_ENDIAN LUAJIT_BE
  223. #else
  224. #define LJ_ARCH_NAME "arm64"
  225. #define LJ_ARCH_ENDIAN LUAJIT_LE
  226. #endif
  227. #if !defined(LJ_ABI_PAUTH) && defined(__arm64e__)
  228. #define LJ_ABI_PAUTH 1
  229. #endif
  230. #define LJ_TARGET_ARM64 1
  231. #define LJ_TARGET_EHRETREG 0
  232. #define LJ_TARGET_EHRAREG 30
  233. #define LJ_TARGET_JUMPRANGE 27 /* +-2^27 = +-128MB */
  234. #define LJ_TARGET_MASKSHIFT 1
  235. #define LJ_TARGET_MASKROT 1
  236. #define LJ_TARGET_UNIFYROT 2 /* Want only IR_BROR. */
  237. #define LJ_TARGET_GC64 1
  238. #define LJ_ARCH_NUMMODE LJ_NUMMODE_DUAL
  239. #define LJ_ARCH_VERSION 80
  240. #elif LUAJIT_TARGET == LUAJIT_ARCH_PPC
  241. #ifndef LJ_ARCH_ENDIAN
  242. #if __BYTE_ORDER__ != __ORDER_BIG_ENDIAN__
  243. #define LJ_ARCH_ENDIAN LUAJIT_LE
  244. #else
  245. #define LJ_ARCH_ENDIAN LUAJIT_BE
  246. #endif
  247. #endif
  248. #if _LP64
  249. #define LJ_ARCH_BITS 64
  250. #if LJ_ARCH_ENDIAN == LUAJIT_LE
  251. #define LJ_ARCH_NAME "ppc64le"
  252. #else
  253. #define LJ_ARCH_NAME "ppc64"
  254. #endif
  255. #else
  256. #define LJ_ARCH_BITS 32
  257. #define LJ_ARCH_NAME "ppc"
  258. #if !defined(LJ_ARCH_HASFPU)
  259. #if defined(_SOFT_FLOAT) || defined(_SOFT_DOUBLE)
  260. #define LJ_ARCH_HASFPU 0
  261. #else
  262. #define LJ_ARCH_HASFPU 1
  263. #endif
  264. #endif
  265. #if !defined(LJ_ABI_SOFTFP)
  266. #if defined(_SOFT_FLOAT) || defined(_SOFT_DOUBLE)
  267. #define LJ_ABI_SOFTFP 1
  268. #else
  269. #define LJ_ABI_SOFTFP 0
  270. #endif
  271. #endif
  272. #endif
  273. #if LJ_ABI_SOFTFP
  274. #define LJ_ARCH_NUMMODE LJ_NUMMODE_DUAL
  275. #else
  276. #define LJ_ARCH_NUMMODE LJ_NUMMODE_DUAL_SINGLE
  277. #endif
  278. #define LJ_TARGET_PPC 1
  279. #define LJ_TARGET_EHRETREG 3
  280. #define LJ_TARGET_EHRAREG 65
  281. #define LJ_TARGET_JUMPRANGE 25 /* +-2^25 = +-32MB */
  282. #define LJ_TARGET_MASKSHIFT 0
  283. #define LJ_TARGET_MASKROT 1
  284. #define LJ_TARGET_UNIFYROT 1 /* Want only IR_BROL. */
  285. #if LJ_TARGET_CONSOLE
  286. #define LJ_ARCH_PPC32ON64 1
  287. #define LJ_ARCH_NOFFI 1
  288. #elif LJ_ARCH_BITS == 64
  289. #error "No support for PPC64"
  290. #undef LJ_TARGET_PPC
  291. #endif
  292. #if _ARCH_PWR7
  293. #define LJ_ARCH_VERSION 70
  294. #elif _ARCH_PWR6
  295. #define LJ_ARCH_VERSION 60
  296. #elif _ARCH_PWR5X
  297. #define LJ_ARCH_VERSION 51
  298. #elif _ARCH_PWR5
  299. #define LJ_ARCH_VERSION 50
  300. #elif _ARCH_PWR4
  301. #define LJ_ARCH_VERSION 40
  302. #else
  303. #define LJ_ARCH_VERSION 0
  304. #endif
  305. #if _ARCH_PPCSQ
  306. #define LJ_ARCH_SQRT 1
  307. #endif
  308. #if _ARCH_PWR5X
  309. #define LJ_ARCH_ROUND 1
  310. #endif
  311. #if __PPU__
  312. #define LJ_ARCH_CELL 1
  313. #endif
  314. #if LJ_TARGET_XBOX360
  315. #define LJ_ARCH_XENON 1
  316. #endif
  317. #elif LUAJIT_TARGET == LUAJIT_ARCH_MIPS32 || LUAJIT_TARGET == LUAJIT_ARCH_MIPS64
  318. #if defined(__MIPSEL__) || defined(__MIPSEL) || defined(_MIPSEL)
  319. #if __mips_isa_rev >= 6
  320. #define LJ_TARGET_MIPSR6 1
  321. #define LJ_TARGET_UNALIGNED 1
  322. #endif
  323. #if LUAJIT_TARGET == LUAJIT_ARCH_MIPS32
  324. #if LJ_TARGET_MIPSR6
  325. #define LJ_ARCH_NAME "mips32r6el"
  326. #else
  327. #define LJ_ARCH_NAME "mipsel"
  328. #endif
  329. #else
  330. #if LJ_TARGET_MIPSR6
  331. #define LJ_ARCH_NAME "mips64r6el"
  332. #else
  333. #define LJ_ARCH_NAME "mips64el"
  334. #endif
  335. #endif
  336. #define LJ_ARCH_ENDIAN LUAJIT_LE
  337. #else
  338. #if LUAJIT_TARGET == LUAJIT_ARCH_MIPS32
  339. #if LJ_TARGET_MIPSR6
  340. #define LJ_ARCH_NAME "mips32r6"
  341. #else
  342. #define LJ_ARCH_NAME "mips"
  343. #endif
  344. #else
  345. #if LJ_TARGET_MIPSR6
  346. #define LJ_ARCH_NAME "mips64r6"
  347. #else
  348. #define LJ_ARCH_NAME "mips64"
  349. #endif
  350. #endif
  351. #define LJ_ARCH_ENDIAN LUAJIT_BE
  352. #endif
  353. #if !defined(LJ_ARCH_HASFPU)
  354. #ifdef __mips_soft_float
  355. #define LJ_ARCH_HASFPU 0
  356. #else
  357. #define LJ_ARCH_HASFPU 1
  358. #endif
  359. #endif
  360. #if !defined(LJ_ABI_SOFTFP)
  361. #ifdef __mips_soft_float
  362. #define LJ_ABI_SOFTFP 1
  363. #else
  364. #define LJ_ABI_SOFTFP 0
  365. #endif
  366. #endif
  367. #if LUAJIT_TARGET == LUAJIT_ARCH_MIPS32
  368. #define LJ_ARCH_BITS 32
  369. #define LJ_TARGET_MIPS32 1
  370. #else
  371. #define LJ_ARCH_BITS 64
  372. #define LJ_TARGET_MIPS64 1
  373. #define LJ_TARGET_GC64 1
  374. #endif
  375. #define LJ_TARGET_MIPS 1
  376. #define LJ_TARGET_EHRETREG 4
  377. #define LJ_TARGET_EHRAREG 31
  378. #define LJ_TARGET_JUMPRANGE 27 /* 2*2^27 = 256MB-aligned region */
  379. #define LJ_TARGET_MASKSHIFT 1
  380. #define LJ_TARGET_MASKROT 1
  381. #define LJ_TARGET_UNIFYROT 2 /* Want only IR_BROR. */
  382. #define LJ_ARCH_NUMMODE LJ_NUMMODE_DUAL
  383. #if LJ_TARGET_MIPSR6
  384. #define LJ_ARCH_VERSION 60
  385. #elif _MIPS_ARCH_MIPS32R2 || _MIPS_ARCH_MIPS64R2
  386. #define LJ_ARCH_VERSION 20
  387. #else
  388. #define LJ_ARCH_VERSION 10
  389. #endif
  390. #else
  391. #error "No target architecture defined"
  392. #endif
  393. /* -- Checks for requirements --------------------------------------------- */
  394. /* Check for minimum required compiler versions. */
  395. #if defined(__GNUC__)
  396. #if LJ_TARGET_X86
  397. #if (__GNUC__ < 3) || ((__GNUC__ == 3) && __GNUC_MINOR__ < 4)
  398. #error "Need at least GCC 3.4 or newer"
  399. #endif
  400. #elif LJ_TARGET_X64
  401. #if __GNUC__ < 4
  402. #error "Need at least GCC 4.0 or newer"
  403. #endif
  404. #elif LJ_TARGET_ARM
  405. #if (__GNUC__ < 4) || ((__GNUC__ == 4) && __GNUC_MINOR__ < 2)
  406. #error "Need at least GCC 4.2 or newer"
  407. #endif
  408. #elif LJ_TARGET_ARM64
  409. #if __clang__
  410. #if ((__clang_major__ < 3) || ((__clang_major__ == 3) && __clang_minor__ < 5)) && !defined(__NX_TOOLCHAIN_MAJOR__)
  411. #error "Need at least Clang 3.5 or newer"
  412. #endif
  413. #else
  414. #if (__GNUC__ < 4) || ((__GNUC__ == 4) && __GNUC_MINOR__ < 8)
  415. #error "Need at least GCC 4.8 or newer"
  416. #endif
  417. #endif
  418. #elif !LJ_TARGET_PS3
  419. #if __clang__
  420. #if ((__clang_major__ < 3) || ((__clang_major__ == 3) && __clang_minor__ < 5))
  421. #error "Need at least Clang 3.5 or newer"
  422. #endif
  423. #else
  424. #if (__GNUC__ < 4) || ((__GNUC__ == 4) && __GNUC_MINOR__ < 3)
  425. #error "Need at least GCC 4.3 or newer"
  426. #endif
  427. #endif
  428. #endif
  429. #endif
  430. /* Check target-specific constraints. */
  431. #ifndef _BUILDVM_H
  432. #if LJ_TARGET_X64
  433. #if __USING_SJLJ_EXCEPTIONS__
  434. #error "Need a C compiler with native exception handling on x64"
  435. #endif
  436. #elif LJ_TARGET_ARM
  437. #if defined(__ARMEB__)
  438. #error "No support for big-endian ARM"
  439. #undef LJ_TARGET_ARM
  440. #endif
  441. #if __ARM_ARCH_6M__ || __ARM_ARCH_7M__ || __ARM_ARCH_7EM__
  442. #error "No support for Cortex-M CPUs"
  443. #undef LJ_TARGET_ARM
  444. #endif
  445. #if !(__ARM_EABI__ || LJ_TARGET_IOS)
  446. #error "Only ARM EABI or iOS 3.0+ ABI is supported"
  447. #undef LJ_TARGET_ARM
  448. #endif
  449. #elif LJ_TARGET_ARM64
  450. #if defined(_ILP32)
  451. #error "No support for ILP32 model on ARM64"
  452. #undef LJ_TARGET_ARM64
  453. #endif
  454. #elif LJ_TARGET_PPC
  455. #if defined(_LITTLE_ENDIAN) && (!defined(_BYTE_ORDER) || (_BYTE_ORDER == _LITTLE_ENDIAN))
  456. #error "No support for little-endian PPC32"
  457. #undef LJ_TARGET_PPC
  458. #endif
  459. #if defined(__NO_FPRS__) && !defined(_SOFT_FLOAT)
  460. #error "No support for PPC/e500, use LuaJIT 2.0"
  461. #undef LJ_TARGET_PPC
  462. #endif
  463. #elif LJ_TARGET_MIPS32
  464. #if !((defined(_MIPS_SIM_ABI32) && _MIPS_SIM == _MIPS_SIM_ABI32) || (defined(_ABIO32) && _MIPS_SIM == _ABIO32))
  465. #error "Only o32 ABI supported for MIPS32"
  466. #undef LJ_TARGET_MIPS
  467. #endif
  468. #if LJ_TARGET_MIPSR6
  469. /* Not that useful, since most available r6 CPUs are 64 bit. */
  470. #error "No support for MIPS32R6"
  471. #undef LJ_TARGET_MIPS
  472. #endif
  473. #elif LJ_TARGET_MIPS64
  474. #if !((defined(_MIPS_SIM_ABI64) && _MIPS_SIM == _MIPS_SIM_ABI64) || (defined(_ABI64) && _MIPS_SIM == _ABI64))
  475. /* MIPS32ON64 aka n32 ABI support might be desirable, but difficult. */
  476. #error "Only n64 ABI supported for MIPS64"
  477. #undef LJ_TARGET_MIPS
  478. #endif
  479. #endif
  480. #endif
  481. /* -- Derived defines ----------------------------------------------------- */
  482. /* Enable or disable the dual-number mode for the VM. */
  483. #if (LJ_ARCH_NUMMODE == LJ_NUMMODE_SINGLE && LUAJIT_NUMMODE == 2) || \
  484. (LJ_ARCH_NUMMODE == LJ_NUMMODE_DUAL && LUAJIT_NUMMODE == 1)
  485. #error "No support for this number mode on this architecture"
  486. #endif
  487. #if LJ_ARCH_NUMMODE == LJ_NUMMODE_DUAL || \
  488. (LJ_ARCH_NUMMODE == LJ_NUMMODE_DUAL_SINGLE && LUAJIT_NUMMODE != 1) || \
  489. (LJ_ARCH_NUMMODE == LJ_NUMMODE_SINGLE_DUAL && LUAJIT_NUMMODE == 2)
  490. #define LJ_DUALNUM 1
  491. #else
  492. #define LJ_DUALNUM 0
  493. #endif
  494. #if LJ_TARGET_IOS || LJ_TARGET_CONSOLE
  495. /* Runtime code generation is restricted on iOS. Complain to Apple, not me. */
  496. /* Ditto for the consoles. Complain to Sony or MS, not me. */
  497. #ifndef LUAJIT_ENABLE_JIT
  498. #define LJ_OS_NOJIT 1
  499. #endif
  500. #endif
  501. /* 64 bit GC references. */
  502. #if LJ_TARGET_GC64
  503. #define LJ_GC64 1
  504. #else
  505. #define LJ_GC64 0
  506. #endif
  507. /* 2-slot frame info. */
  508. #if LJ_GC64
  509. #define LJ_FR2 1
  510. #else
  511. #define LJ_FR2 0
  512. #endif
  513. /* Disable or enable the JIT compiler. */
  514. #if defined(LUAJIT_DISABLE_JIT) || defined(LJ_ARCH_NOJIT) || defined(LJ_OS_NOJIT)
  515. #define LJ_HASJIT 0
  516. #else
  517. #define LJ_HASJIT 1
  518. #endif
  519. /* Disable or enable the FFI extension. */
  520. #if defined(LUAJIT_DISABLE_FFI) || defined(LJ_ARCH_NOFFI)
  521. #define LJ_HASFFI 0
  522. #else
  523. #define LJ_HASFFI 1
  524. #endif
  525. /* Disable or enable the string buffer extension. */
  526. #if defined(LUAJIT_DISABLE_BUFFER)
  527. #define LJ_HASBUFFER 0
  528. #else
  529. #define LJ_HASBUFFER 1
  530. #endif
  531. #if defined(LUAJIT_DISABLE_PROFILE)
  532. #define LJ_HASPROFILE 0
  533. #elif LJ_TARGET_POSIX
  534. #define LJ_HASPROFILE 1
  535. #define LJ_PROFILE_SIGPROF 1
  536. #elif LJ_TARGET_PS3
  537. #define LJ_HASPROFILE 1
  538. #define LJ_PROFILE_PTHREAD 1
  539. #elif LJ_TARGET_WINDOWS || LJ_TARGET_XBOX360
  540. #define LJ_HASPROFILE 1
  541. #define LJ_PROFILE_WTHREAD 1
  542. #else
  543. #define LJ_HASPROFILE 0
  544. #endif
  545. #ifndef LJ_ARCH_HASFPU
  546. #define LJ_ARCH_HASFPU 1
  547. #endif
  548. #ifndef LJ_ABI_SOFTFP
  549. #define LJ_ABI_SOFTFP 0
  550. #endif
  551. #define LJ_SOFTFP (!LJ_ARCH_HASFPU)
  552. #define LJ_SOFTFP32 (LJ_SOFTFP && LJ_32)
  553. #ifndef LJ_ABI_PAUTH
  554. #define LJ_ABI_PAUTH 0
  555. #endif
  556. #if LJ_ARCH_ENDIAN == LUAJIT_BE
  557. #define LJ_LE 0
  558. #define LJ_BE 1
  559. #define LJ_ENDIAN_SELECT(le, be) be
  560. #define LJ_ENDIAN_LOHI(lo, hi) hi lo
  561. #else
  562. #define LJ_LE 1
  563. #define LJ_BE 0
  564. #define LJ_ENDIAN_SELECT(le, be) le
  565. #define LJ_ENDIAN_LOHI(lo, hi) lo hi
  566. #endif
  567. #if LJ_ARCH_BITS == 32
  568. #define LJ_32 1
  569. #define LJ_64 0
  570. #else
  571. #define LJ_32 0
  572. #define LJ_64 1
  573. #endif
  574. #ifndef LJ_TARGET_UNALIGNED
  575. #define LJ_TARGET_UNALIGNED 0
  576. #endif
  577. #ifndef LJ_PAGESIZE
  578. #define LJ_PAGESIZE 4096
  579. #endif
  580. /* Various workarounds for embedded operating systems or weak C runtimes. */
  581. #if defined(__ANDROID__) || defined(__symbian__) || LJ_TARGET_XBOX360 || LJ_TARGET_WINDOWS
  582. #define LUAJIT_NO_LOG2
  583. #endif
  584. #if LJ_TARGET_CONSOLE || (LJ_TARGET_IOS && __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_8_0)
  585. #define LJ_NO_SYSTEM 1
  586. #endif
  587. #if LJ_TARGET_WINDOWS || LJ_TARGET_CYGWIN
  588. #define LJ_ABI_WIN 1
  589. #else
  590. #define LJ_ABI_WIN 0
  591. #endif
  592. #if LJ_TARGET_WINDOWS
  593. #if LJ_TARGET_UWP
  594. #define LJ_WIN_VALLOC VirtualAllocFromApp
  595. #define LJ_WIN_VPROTECT VirtualProtectFromApp
  596. extern void *LJ_WIN_LOADLIBA(const char *path);
  597. #else
  598. #define LJ_WIN_VALLOC VirtualAlloc
  599. #define LJ_WIN_VPROTECT VirtualProtect
  600. #define LJ_WIN_LOADLIBA(path) LoadLibraryExA((path), NULL, 0)
  601. #endif
  602. #endif
  603. #if defined(LUAJIT_NO_UNWIND) || __GNU_COMPACT_EH__ || defined(__symbian__) || LJ_TARGET_IOS || LJ_TARGET_PS3 || LJ_TARGET_PS4 || LJ_TARGET_PS5
  604. #define LJ_NO_UNWIND 1
  605. #endif
  606. #if !LJ_NO_UNWIND && !defined(LUAJIT_UNWIND_INTERNAL) && (LJ_ABI_WIN || (defined(LUAJIT_UNWIND_EXTERNAL) && (defined(__GNUC__) || defined(__clang__))))
  607. #define LJ_UNWIND_EXT 1
  608. #else
  609. #define LJ_UNWIND_EXT 0
  610. #endif
  611. #if LJ_UNWIND_EXT && LJ_HASJIT && !LJ_TARGET_ARM && !(LJ_ABI_WIN && LJ_TARGET_X86)
  612. #define LJ_UNWIND_JIT 1
  613. #else
  614. #define LJ_UNWIND_JIT 0
  615. #endif
  616. /* Compatibility with Lua 5.1 vs. 5.2. */
  617. #ifdef LUAJIT_ENABLE_LUA52COMPAT
  618. #define LJ_52 1
  619. #else
  620. #define LJ_52 0
  621. #endif
  622. /* -- VM security --------------------------------------------------------- */
  623. /* Don't make any changes here. Instead build with:
  624. ** make "XCFLAGS=-DLUAJIT_SECURITY_flag=value"
  625. **
  626. ** Important note to distro maintainers: DO NOT change the defaults for a
  627. ** regular distro build -- neither upwards, nor downwards!
  628. ** These build-time configurable security flags are intended for embedders
  629. ** who may have specific needs wrt. security vs. performance.
  630. */
  631. /* Security defaults. */
  632. #ifndef LUAJIT_SECURITY_PRNG
  633. /* PRNG init: 0 = fixed/insecure, 1 = secure from OS. */
  634. #define LUAJIT_SECURITY_PRNG 1
  635. #endif
  636. #ifndef LUAJIT_SECURITY_STRHASH
  637. /* String hash: 0 = sparse only, 1 = sparse + dense. */
  638. #define LUAJIT_SECURITY_STRHASH 1
  639. #endif
  640. #ifndef LUAJIT_SECURITY_STRID
  641. /* String IDs: 0 = linear, 1 = reseed < 255, 2 = reseed < 15, 3 = random. */
  642. #define LUAJIT_SECURITY_STRID 1
  643. #endif
  644. #ifndef LUAJIT_SECURITY_MCODE
  645. /* Machine code page protection: 0 = insecure RWX, 1 = secure RW^X. */
  646. #define LUAJIT_SECURITY_MCODE 1
  647. #endif
  648. #define LJ_SECURITY_MODE \
  649. ( 0u \
  650. | ((LUAJIT_SECURITY_PRNG & 3) << 0) \
  651. | ((LUAJIT_SECURITY_STRHASH & 3) << 2) \
  652. | ((LUAJIT_SECURITY_STRID & 3) << 4) \
  653. | ((LUAJIT_SECURITY_MCODE & 3) << 6) \
  654. )
  655. #define LJ_SECURITY_MODESTRING \
  656. "\004prng\007strhash\005strid\005mcode"
  657. #endif