As pointed out by naddy, we should be able to read the %ticks register
on sparc64. The code as it is in the !__OpenBSD__ path throws SIGILL
when running regress, so I cribbed some code from sparc64/cpu.c which
appears to work - the regress timings look roughly the same as with the
softclock.
Does this look ok?
Index: Makefile
===================================================================
RCS file: /cvs/ports/security/polarssl/Makefile,v
retrieving revision 1.45
diff -u -p -r1.45 Makefile
--- Makefile 2 Apr 2022 13:52:41 -0000 1.45
+++ Makefile 2 Apr 2022 16:15:22 -0000
@@ -6,6 +6,7 @@ GH_ACCOUNT= ARMmbed
GH_PROJECT= mbedtls
GH_TAGNAME= mbedtls-2.28.0
DISTNAME= ${GH_TAGNAME}
+REVISION= 0
# check SOVERSION
SHARED_LIBS += mbedtls 7.0
Index: patches/patch-library_timing_c
===================================================================
RCS file: patches/patch-library_timing_c
diff -N patches/patch-library_timing_c
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ patches/patch-library_timing_c 2 Apr 2022 16:05:24 -0000
@@ -0,0 +1,29 @@
+Use assembly fragment from sys/arch/sparc64/sparc64/clock.c for the
+hardclock on sparc64
+
+Index: library/timing.c
+--- library/timing.c.orig
++++ library/timing.c
+@@ -137,18 +137,18 @@ unsigned long mbedtls_timing_hardclock( void )
+ #if !defined(HAVE_HARDCLOCK) && defined(MBEDTLS_HAVE_ASM) && \
+ defined(__GNUC__) && defined(__sparc64__)
+
+-#if defined(__OpenBSD__)
+-#warning OpenBSD does not allow access to tick register using software
version instead
+-#else
+ #define HAVE_HARDCLOCK
+
+ unsigned long mbedtls_timing_hardclock( void )
+ {
+ unsigned long tick;
++#ifdef __OpenBSD__
++ asm volatile( "rd %%tick, %0;" : "=r" (tick) );
++#else
+ asm volatile( "rdpr %%tick, %0;" : "=&r" (tick) );
++#endif /* __OpenBSD__ */
+ return( tick );
+ }
+-#endif /* __OpenBSD__ */
+ #endif /* !HAVE_HARDCLOCK && MBEDTLS_HAVE_ASM &&
+ __GNUC__ && __sparc64__ */
+