summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiod Vallat <miod@cvs.openbsd.org>2014-05-03 11:39:47 +0000
committerMiod Vallat <miod@cvs.openbsd.org>2014-05-03 11:39:47 +0000
commit803e6c7bb620f2ce10655afb8992e0a3c163b13f (patch)
tree992499d13fa82e44dd83e5282399090c556f6586
parent3b7ad9b31a887d244a7f63ff25cedd71b2ce2a3e (diff)
Detect Altivec support with the machdep.altivec sysctl rather than setmp and
a SIGILL handler. Do not attempt to detect and use a 64-bit FPU yet.
-rw-r--r--lib/libssl/src/crypto/ppccap.c112
-rwxr-xr-xlib/libssl/src/crypto/ppccpuid.pl10
2 files changed, 20 insertions, 102 deletions
diff --git a/lib/libssl/src/crypto/ppccap.c b/lib/libssl/src/crypto/ppccap.c
index 4d7dd38dd11..4cedefed2c3 100644
--- a/lib/libssl/src/crypto/ppccap.c
+++ b/lib/libssl/src/crypto/ppccap.c
@@ -1,124 +1,48 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <setjmp.h>
-#include <signal.h>
#include <unistd.h>
+#include <sys/param.h>
+#include <sys/sysctl.h>
+#include <machine/cpu.h>
+
#include <crypto.h>
#include <openssl/bn.h>
+#ifdef unused
#define PPC_FPU64 (1<<0)
#define PPC_ALTIVEC (1<<1)
static int OPENSSL_ppccap_P = 0;
-
-static sigset_t all_masked;
+#endif
#ifdef OPENSSL_BN_ASM_MONT
+extern int bn_mul_mont_int(BN_ULONG *, const BN_ULONG *, const BN_ULONG *,
+ const BN_ULONG *, const BN_ULONG *, int);
int
bn_mul_mont(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp,
const BN_ULONG *np, const BN_ULONG *n0, int num)
{
- int bn_mul_mont_fpu64(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp, const BN_ULONG *np, const BN_ULONG *n0, int num);
- int bn_mul_mont_int(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *bp, const BN_ULONG *np, const BN_ULONG *n0, int num);
-
- if (sizeof(size_t) == 4) {
-#if (defined(__APPLE__) && defined(__MACH__))
- if (num >= 8 && (num&3) == 0 && (OPENSSL_ppccap_P&PPC_FPU64))
- return bn_mul_mont_fpu64(rp, ap, bp, np, n0, num);
-#else
- /* boundary of 32 was experimentally determined on
- Linux 2.6.22, might have to be adjusted on AIX... */
- if (num >= 32 && (num&3) == 0 && (OPENSSL_ppccap_P&PPC_FPU64)) {
- sigset_t oset;
- int ret;
-
- sigprocmask(SIG_SETMASK, &all_masked, &oset);
- ret = bn_mul_mont_fpu64(rp, ap, bp, np, n0, num);
- sigprocmask(SIG_SETMASK, &oset, NULL);
-
- return ret;
- }
-#endif
- } else if ((OPENSSL_ppccap_P&PPC_FPU64))
- /* this is a "must" on POWER6, but run-time detection
- * is not implemented yet... */
- return bn_mul_mont_fpu64(rp, ap, bp, np, n0, num);
-
return bn_mul_mont_int(rp, ap, bp, np, n0, num);
}
#endif
-static sigjmp_buf ill_jmp;
-static void ill_handler (int sig)
-{
- siglongjmp(ill_jmp, sig);
-}
-
-void OPENSSL_ppc64_probe(void);
-void OPENSSL_altivec_probe(void);
+#ifdef unused
+void OPENSSL_cpuid_setup(void) __attribute__((constructor));
void
OPENSSL_cpuid_setup(void)
{
- char *e;
- struct sigaction ill_oact, ill_act;
- sigset_t oset;
+ static const int mib[2] = { CTL_MACHDEP, CPU_ALTIVEC };
static int trigger = 0;
+ int altivec = 0;
+ size_t size;
if (trigger)
return;
trigger = 1;
- sigfillset(&all_masked);
- sigdelset(&all_masked, SIGILL);
- sigdelset(&all_masked, SIGTRAP);
-#ifdef SIGEMT
- sigdelset(&all_masked, SIGEMT);
-#endif
- sigdelset(&all_masked, SIGFPE);
- sigdelset(&all_masked, SIGBUS);
- sigdelset(&all_masked, SIGSEGV);
-
- if ((e = getenv("OPENSSL_ppccap"))) {
- OPENSSL_ppccap_P = strtoul(e, NULL, 0);
- return;
- }
-
- OPENSSL_ppccap_P = 0;
-
-#if defined(_AIX)
- if (sizeof(size_t) == 4
-# if defined(_SC_AIX_KERNEL_BITMODE)
- && sysconf(_SC_AIX_KERNEL_BITMODE) != 64
-# endif
- )
- return;
-#endif
-
- memset(&ill_act, 0, sizeof(ill_act));
- ill_act.sa_handler = ill_handler;
- ill_act.sa_mask = all_masked;
-
- sigprocmask(SIG_SETMASK, &ill_act.sa_mask, &oset);
- sigaction(SIGILL, &ill_act, &ill_oact);
-
- if (sizeof(size_t) == 4) {
- if (sigsetjmp(ill_jmp, 1) == 0) {
- OPENSSL_ppc64_probe();
- OPENSSL_ppccap_P |= PPC_FPU64;
- }
- } else {
- /*
- * Wanted code detecting POWER6 CPU and setting PPC_FPU64
- */
- }
-
- if (sigsetjmp(ill_jmp, 1) == 0) {
- OPENSSL_altivec_probe();
- OPENSSL_ppccap_P |= PPC_ALTIVEC;
+ size = sizeof altivec;
+ if (sysctl(mib, 2, &altivec, &size, NULL, 0) != -1) {
+ if (altivec != 0)
+ OPENSSL_ppccap_P |= PPC_ALTIVEC;
}
-
- sigaction (SIGILL, &ill_oact, NULL);
- sigprocmask(SIG_SETMASK, &oset, NULL);
}
+#endif
diff --git a/lib/libssl/src/crypto/ppccpuid.pl b/lib/libssl/src/crypto/ppccpuid.pl
index 37c33c051ab..0cef7014b6e 100755
--- a/lib/libssl/src/crypto/ppccpuid.pl
+++ b/lib/libssl/src/crypto/ppccpuid.pl
@@ -23,6 +23,7 @@ $code=<<___;
.machine "any"
.text
+#if 0
.globl .OPENSSL_ppc64_probe
.align 4
.OPENSSL_ppc64_probe:
@@ -31,14 +32,7 @@ $code=<<___;
blr
.long 0
.byte 0,12,0x14,0,0,0,0,0
-
-.globl .OPENSSL_altivec_probe
-.align 4
-.OPENSSL_altivec_probe:
- .long 0x10000484 # vor v0,v0,v0
- blr
- .long 0
- .byte 0,12,0x14,0,0,0,0,0
+#endif
.globl .OPENSSL_wipe_cpu
.align 4