7 #if defined(__linux) || defined(_AIX)
8 #include <sys/utsname.h>
11 #include <openssl/bn.h>
15 unsigned int OPENSSL_ppccap_P = 0;
17 static sigset_t all_masked;
19 #ifdef OPENSSL_BN_ASM_MONT
20 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)
22 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);
23 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);
25 if (sizeof(size_t)==4)
27 #if 1 || (defined(__APPLE__) && defined(__MACH__))
28 if (num>=8 && (num&3)==0 && (OPENSSL_ppccap_P&PPC_FPU64))
29 return bn_mul_mont_fpu64(rp,ap,bp,np,n0,num);
31 /* boundary of 32 was experimentally determined on
32 Linux 2.6.22, might have to be adjusted on AIX... */
33 if (num>=32 && (num&3)==0 && (OPENSSL_ppccap_P&PPC_FPU64))
38 sigprocmask(SIG_SETMASK,&all_masked,&oset);
39 ret=bn_mul_mont_fpu64(rp,ap,bp,np,n0,num);
40 sigprocmask(SIG_SETMASK,&oset,NULL);
46 else if ((OPENSSL_ppccap_P&PPC_FPU64))
47 /* this is a "must" on POWER6, but run-time detection
48 * is not implemented yet... */
49 return bn_mul_mont_fpu64(rp,ap,bp,np,n0,num);
51 return bn_mul_mont_int(rp,ap,bp,np,n0,num);
55 void sha256_block_p8(void *ctx,const void *inp,size_t len);
56 void sha256_block_ppc(void *ctx,const void *inp,size_t len);
57 void sha256_block_data_order(void *ctx,const void *inp,size_t len)
59 OPENSSL_ppccap_P&PPC_CRYPTO207? sha256_block_p8(ctx,inp,len):
60 sha256_block_ppc(ctx,inp,len);
63 void sha512_block_p8(void *ctx,const void *inp,size_t len);
64 void sha512_block_ppc(void *ctx,const void *inp,size_t len);
65 void sha512_block_data_order(void *ctx,const void *inp,size_t len)
67 OPENSSL_ppccap_P&PPC_CRYPTO207? sha512_block_p8(ctx,inp,len):
68 sha512_block_ppc(ctx,inp,len);
71 static sigjmp_buf ill_jmp;
72 static void ill_handler (int sig) { siglongjmp(ill_jmp,sig); }
74 void OPENSSL_ppc64_probe(void);
75 void OPENSSL_altivec_probe(void);
76 void OPENSSL_crypto207_probe(void);
78 void OPENSSL_cpuid_setup(void)
81 struct sigaction ill_oact,ill_act;
88 sigfillset(&all_masked);
89 sigdelset(&all_masked,SIGILL);
90 sigdelset(&all_masked,SIGTRAP);
92 sigdelset(&all_masked,SIGEMT);
94 sigdelset(&all_masked,SIGFPE);
95 sigdelset(&all_masked,SIGBUS);
96 sigdelset(&all_masked,SIGSEGV);
98 if ((e=getenv("OPENSSL_ppccap")))
100 OPENSSL_ppccap_P=strtoul(e,NULL,0);
104 OPENSSL_ppccap_P = 0;
107 if (sizeof(size_t)==4)
110 # if defined(_SC_AIX_KERNEL_BITMODE)
111 if (sysconf(_SC_AIX_KERNEL_BITMODE)!=64) return;
113 if (uname(&uts)!=0 || atoi(uts.version)<6) return;
117 memset(&ill_act,0,sizeof(ill_act));
118 ill_act.sa_handler = ill_handler;
119 ill_act.sa_mask = all_masked;
121 sigprocmask(SIG_SETMASK,&ill_act.sa_mask,&oset);
122 sigaction(SIGILL,&ill_act,&ill_oact);
124 if (sizeof(size_t)==4)
128 if (uname(&uts)==0 && strcmp(uts.machine,"ppc64")==0)
130 if (sigsetjmp(ill_jmp,1) == 0)
132 OPENSSL_ppc64_probe();
133 OPENSSL_ppccap_P |= PPC_FPU64;
139 * Wanted code detecting POWER6 CPU and setting PPC_FPU64
143 if (sigsetjmp(ill_jmp,1) == 0)
145 OPENSSL_altivec_probe();
146 OPENSSL_ppccap_P |= PPC_ALTIVEC;
147 if (sigsetjmp(ill_jmp,1) == 0)
149 OPENSSL_crypto207_probe();
150 OPENSSL_ppccap_P |= PPC_CRYPTO207;
154 sigaction (SIGILL,&ill_oact,NULL);
155 sigprocmask(SIG_SETMASK,&oset,NULL);