0005-add-riscv-support.patch 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. From 64ad80e6d95871f17be4cd01da15581f41ac0b2b Mon Sep 17 00:00:00 2001
  2. From: Stefan O'Rear <sorear2@gmail.com>
  3. Date: Fri, 11 Nov 2016 21:10:34 -0700
  4. Subject: [PATCH] Add RISC-V support
  5. These changes allow spidermonkey to cross-compile for riscv64 and riscv32.
  6. Upstream-status: Submitted
  7. See: https://bugzilla.mozilla.org/show_bug.cgi?id=1318905
  8. Signed-off-by: Stefan O'Rear <sorear2@gmail.com>
  9. Signed-off-by: Ricardo Salveti <ricardo@foundries.io>
  10. Signed-off-by: Adam Duskett <aduskett@gmail.com>
  11. ---
  12. build/autoconf/config.guess | 3 +++
  13. build/moz.configure/init.configure | 3 +++
  14. js/src/jit/AtomicOperations.h | 2 ++
  15. js/src/jit/none/AtomicOperations-feeling-lucky.h | 8 ++++++++
  16. mfbt/tests/TestPoisonArea.cpp | 3 +++
  17. python/mozbuild/mozbuild/configure/constants.py | 4 ++++
  18. 6 files changed, 23 insertions(+)
  19. diff --git a/build/autoconf/config.guess b/build/autoconf/config.guess
  20. index d5d667d4..1277a862 100755
  21. --- a/build/autoconf/config.guess
  22. +++ b/build/autoconf/config.guess
  23. @@ -1029,6 +1029,9 @@ EOF
  24. ppcle:Linux:*:*)
  25. echo powerpcle-unknown-linux-${LIBC}
  26. exit ;;
  27. + riscv32:Linux:*:* | riscv64:Linux:*:*)
  28. + echo ${UNAME_MACHINE}-unknown-linux-${LIBC}
  29. + exit ;;
  30. s390:Linux:*:* | s390x:Linux:*:*)
  31. echo ${UNAME_MACHINE}-ibm-linux-${LIBC}
  32. exit ;;
  33. diff --git a/build/moz.configure/init.configure b/build/moz.configure/init.configure
  34. index 83b8d705..ef33db50 100644
  35. --- a/build/moz.configure/init.configure
  36. +++ b/build/moz.configure/init.configure
  37. @@ -676,6 +676,9 @@ def split_triplet(triplet, allow_unknown=False):
  38. elif cpu == 'sh4':
  39. canonical_cpu = 'sh4'
  40. endianness = 'little'
  41. + elif cpu in ('riscv32', 'riscv64'):
  42. + canonical_cpu = cpu
  43. + endianness = 'little'
  44. elif allow_unknown:
  45. canonical_cpu = cpu
  46. endianness = 'unknown'
  47. diff --git a/js/src/jit/AtomicOperations.h b/js/src/jit/AtomicOperations.h
  48. index 3501e65b..fda0b148 100644
  49. --- a/js/src/jit/AtomicOperations.h
  50. +++ b/js/src/jit/AtomicOperations.h
  51. @@ -393,6 +393,8 @@ inline bool AtomicOperations::isLockfreeJS(int32_t size) {
  52. #include "jit/none/AtomicOperations-feeling-lucky.h"
  53. #elif defined(__s390__) || defined(__s390x__)
  54. #include "jit/none/AtomicOperations-feeling-lucky.h"
  55. +#elif defined(__riscv)
  56. +#include "jit/none/AtomicOperations-feeling-lucky.h"
  57. #else
  58. #error "No AtomicOperations support provided for this platform"
  59. #endif
  60. diff --git a/js/src/jit/none/AtomicOperations-feeling-lucky.h b/js/src/jit/none/AtomicOperations-feeling-lucky.h
  61. index c0b43699..42b1f3e0 100644
  62. --- a/js/src/jit/none/AtomicOperations-feeling-lucky.h
  63. +++ b/js/src/jit/none/AtomicOperations-feeling-lucky.h
  64. @@ -80,6 +80,14 @@
  65. #define GNUC_COMPATIBLE
  66. #endif
  67. +#ifdef __riscv
  68. +#define GNUC_COMPATIBLE
  69. +#ifdef __riscv_xlen == 64
  70. +#define HAS_64BIT_ATOMICS
  71. +#define HAS_64BIT_LOCKFREE
  72. +#endif
  73. +#endif
  74. +
  75. // The default implementation tactic for gcc/clang is to use the newer
  76. // __atomic intrinsics added for use in C++11 <atomic>. Where that
  77. // isn't available, we use GCC's older __sync functions instead.
  78. diff --git a/mfbt/tests/TestPoisonArea.cpp b/mfbt/tests/TestPoisonArea.cpp
  79. index 06c24ed0..fba9263c 100644
  80. --- a/mfbt/tests/TestPoisonArea.cpp
  81. +++ b/mfbt/tests/TestPoisonArea.cpp
  82. @@ -168,6 +168,9 @@ static const ia64_instr _return_instr =
  83. #define RETURN_INSTR _return_instr
  84. #define RETURN_INSTR_TYPE ia64_instr
  85. +#elif defined __riscv
  86. +#define RETURN_INSTR 0x80828082 /* ret; ret */
  87. +
  88. #else
  89. #error "Need return instruction for this architecture"
  90. #endif
  91. diff --git a/python/mozbuild/mozbuild/configure/constants.py b/python/mozbuild/mozbuild/configure/constants.py
  92. index 33ae5a45..1067b6a4 100644
  93. --- a/python/mozbuild/mozbuild/configure/constants.py
  94. +++ b/python/mozbuild/mozbuild/configure/constants.py
  95. @@ -50,6 +50,8 @@ CPU_bitness = {
  96. 'mips64': 64,
  97. 'ppc': 32,
  98. 'ppc64': 64,
  99. + 'riscv32': 32,
  100. + 'riscv64': 64,
  101. 's390': 32,
  102. 's390x': 64,
  103. 'sh4': 32,
  104. @@ -82,6 +84,8 @@ CPU_preprocessor_checks = OrderedDict((
  105. ('s390', '__s390__'),
  106. ('ppc64', '__powerpc64__'),
  107. ('ppc', '__powerpc__'),
  108. + ('riscv32', '__riscv && __SIZEOF_POINTER__ == 4'),
  109. + ('riscv64', '__riscv && __SIZEOF_POINTER__ == 8'),
  110. ('Alpha', '__alpha__'),
  111. ('hppa', '__hppa__'),
  112. ('sparc64', '__sparc__ && __arch64__'),
  113. --
  114. 2.23.0