From 2dd63606af3e20ed5a4eb1674624783eecd80a93 Mon Sep 17 00:00:00 2001 From: David CARLIER Date: Tue, 5 Jan 2021 16:28:22 +0000 Subject: [PATCH] Sparc support proposal. (#264) * Sparc support proposal. * Tweaks from feedback. Shift to integer/pointers cast like other archs. Assembly reworks. Note apparently reading the register once is sufficient to provoke a pause in the cpu adding a clobber tough. --- src/aal/aal.h | 7 +++++ src/aal/aal_sparc.h | 62 ++++++++++++++++++++++++++++++++++++++ src/pal/pal_linux.h | 2 +- src/pal/pal_open_enclave.h | 2 +- src/pal/pal_posix.h | 2 +- 5 files changed, 72 insertions(+), 3 deletions(-) create mode 100644 src/aal/aal_sparc.h diff --git a/src/aal/aal.h b/src/aal/aal.h index ce5e6c1..9e3fbaf 100644 --- a/src/aal/aal.h +++ b/src/aal/aal.h @@ -23,6 +23,10 @@ # define PLATFORM_IS_POWERPC #endif +#if defined(__sparc__) +# define PLATFORM_IS_SPARC +#endif + namespace snmalloc { /** @@ -54,6 +58,7 @@ namespace snmalloc PowerPC, X86, X86_SGX, + Sparc, }; /** @@ -147,6 +152,8 @@ namespace snmalloc # include "aal_arm.h" #elif defined(PLATFORM_IS_POWERPC) # include "aal_powerpc.h" +#elif defined(PLATFORM_IS_SPARC) +# include "aal_sparc.h" #endif namespace snmalloc diff --git a/src/aal/aal_sparc.h b/src/aal/aal_sparc.h new file mode 100644 index 0000000..3bbf840 --- /dev/null +++ b/src/aal/aal_sparc.h @@ -0,0 +1,62 @@ +#pragma once + +#if defined(__arch64__) // More reliable than __sparc64__ +# define SNMALLOC_VA_BITS_64 +#else +# define SNMALLOC_VA_BITS_32 +#endif + +namespace snmalloc +{ + /** + * Sparc architecture abstraction layer. + */ + class AAL_Sparc + { + public: + /** + * Bitmap of AalFeature flags + */ + static constexpr uint64_t aal_features = IntegerPointers; + + static constexpr enum AalName aal_name = Sparc; + +#ifdef SNMALLOC_VA_BITS_64 + /** + * Even Ultra-Sparc I supports 8192 and onwards + */ + static constexpr size_t smallest_page_size = 0x2000; +#else + static constexpr size_t smallest_page_size = 0x1000; +#endif + + /** + * On Sparc ideally pause instructions ought to be + * optimised per Sparc processor but here a version + * as least common denominator to avoid numerous ifdef, + * reading Conditions Code Register here + */ + static inline void pause() + { + __asm__ volatile("rd %%ccr, %%g0" ::: "memory"); + } + + static inline void prefetch(void* ptr) + { +#ifdef SNMALLOC_VA_BITS_64 + __asm__ volatile("prefetch [%0], 0" ::"r"(ptr)); +#else + UNUSED(ptr); +#endif + } + + static inline uint64_t tick() + { + uint64_t tick; + __asm__ volatile("rd %%asr4, %0" : "=r"(tick)); + return tick; + } + }; + + using AAL_Arch = AAL_Sparc; +} // namespace snmalloc diff --git a/src/pal/pal_linux.h b/src/pal/pal_linux.h index 74999af..f9ad8b2 100644 --- a/src/pal/pal_linux.h +++ b/src/pal/pal_linux.h @@ -26,7 +26,7 @@ namespace snmalloc static constexpr uint64_t pal_features = PALPOSIX::pal_features; static constexpr size_t page_size = - Aal::aal_name == PowerPC ? 0x10000 : 0x1000; + Aal::aal_name == PowerPC ? 0x10000 : PALPOSIX::page_size; /** * OS specific function for zeroing memory. diff --git a/src/pal/pal_open_enclave.h b/src/pal/pal_open_enclave.h index 420c49d..a9d926c 100644 --- a/src/pal/pal_open_enclave.h +++ b/src/pal/pal_open_enclave.h @@ -39,7 +39,7 @@ namespace snmalloc */ static constexpr uint64_t pal_features = 0; - static constexpr size_t page_size = 0x1000; + static constexpr size_t page_size = Aal::smallest_page_size; [[noreturn]] static void error(const char* const str) { diff --git a/src/pal/pal_posix.h b/src/pal/pal_posix.h index ba1f489..db9981f 100644 --- a/src/pal/pal_posix.h +++ b/src/pal/pal_posix.h @@ -98,7 +98,7 @@ namespace snmalloc */ static constexpr uint64_t pal_features = LazyCommit; - static constexpr size_t page_size = 0x1000; + static constexpr size_t page_size = Aal::smallest_page_size; static void print_stack_trace() {