7 #include <openssl/bn.h>
9 #define SPARCV9_TICK_PRIVILEGED (1<<0)
10 #define SPARCV9_PREFER_FPU (1<<1)
11 #define SPARCV9_VIS1 (1<<2)
12 #define SPARCV9_VIS2 (1<<3) /* reserved */
13 #define SPARCV9_FMADD (1<<4) /* reserved for SPARC64 V */
15 static int OPENSSL_sparcv9cap_P
=SPARCV9_TICK_PRIVILEGED
;
17 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
)
19 int bn_mul_mont_fpu(BN_ULONG
*rp
, const BN_ULONG
*ap
, const BN_ULONG
*bp
, const BN_ULONG
*np
,const BN_ULONG
*n0
, int num
);
20 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
);
22 if ((OPENSSL_sparcv9cap_P
&(SPARCV9_PREFER_FPU
|SPARCV9_VIS1
)) ==
23 (SPARCV9_PREFER_FPU
|SPARCV9_VIS1
))
24 return bn_mul_mont_fpu(rp
,ap
,bp
,np
,n0
,num
);
26 return bn_mul_mont_int(rp
,ap
,bp
,np
,n0
,num
);
29 unsigned long _sparcv9_rdtick(void);
30 void _sparcv9_vis1_probe(void);
32 unsigned long OPENSSL_rdtsc(void)
34 if (OPENSSL_sparcv9cap_P
&SPARCV9_TICK_PRIVILEGED
)
35 #if defined(__sun) && defined(__SVR4)
41 return _sparcv9_rdtick();
44 #if defined(__sun) && defined(__SVR4)
47 #include <libdevinfo.h>
48 #include <sys/systeminfo.h>
50 typedef di_node_t (*di_init_t
)(const char *,uint_t
);
51 typedef void (*di_fini_t
)(di_node_t
);
52 typedef char * (*di_node_name_t
)(di_node_t
);
53 typedef int (*di_walk_node_t
)(di_node_t
,uint_t
,di_node_name_t
,int (*)(di_node_t
,di_node_name_t
));
55 #define DLLINK(h,name) (name=(name##_t)dlsym((h),#name))
57 static int walk_nodename(di_node_t node
, di_node_name_t di_node_name
)
59 char *name
= (*di_node_name
)(node
);
61 /* This is expected to catch all UltraSPARC flavors prior T1 */
62 if (!strcmp (name
,"SUNW,UltraSPARC") ||
63 !strncmp(name
,"SUNW,UltraSPARC-I",17)) /* covers II,III,IV */
65 OPENSSL_sparcv9cap_P
|= SPARCV9_PREFER_FPU
|SPARCV9_VIS1
;
67 /* %tick is privileged only on UltraSPARC-I/II, but not IIe */
68 if (name
[14]!='\0' && name
[17]!='\0' && name
[18]!='\0')
69 OPENSSL_sparcv9cap_P
&= ~SPARCV9_TICK_PRIVILEGED
;
71 return DI_WALK_TERMINATE
;
73 /* This is expected to catch remaining UltraSPARCs, such as T1 */
74 else if (!strncmp(name
,"SUNW,UltraSPARC",15))
76 OPENSSL_sparcv9cap_P
&= ~SPARCV9_TICK_PRIVILEGED
;
78 return DI_WALK_TERMINATE
;
81 return DI_WALK_CONTINUE
;
84 void OPENSSL_cpuid_setup(void)
93 if ((e
=getenv("OPENSSL_sparcv9cap")))
95 OPENSSL_sparcv9cap_P
=strtoul(e
,NULL
,0);
99 if (sysinfo(SI_MACHINE
,si
,sizeof(si
))>0)
101 if (strcmp(si
,"sun4v"))
102 /* FPU is preferred for all CPUs, but US-T1/2 */
103 OPENSSL_sparcv9cap_P
|= SPARCV9_PREFER_FPU
;
106 if (sysinfo(SI_ISALIST
,si
,sizeof(si
))>0)
108 if (strstr(si
,"+vis"))
109 OPENSSL_sparcv9cap_P
|= SPARCV9_VIS1
;
110 if (strstr(si
,"+vis2"))
112 OPENSSL_sparcv9cap_P
|= SPARCV9_VIS2
;
113 OPENSSL_sparcv9cap_P
&= ~SPARCV9_TICK_PRIVILEGED
;
118 if ((h
= dlopen("libdevinfo.so.1",RTLD_LAZY
))) do
122 di_walk_node_t di_walk_node
;
123 di_node_name_t di_node_name
;
126 if (!DLLINK(h
,di_init
)) break;
127 if (!DLLINK(h
,di_fini
)) break;
128 if (!DLLINK(h
,di_walk_node
)) break;
129 if (!DLLINK(h
,di_node_name
)) break;
131 if ((root_node
= (*di_init
)("/",DINFOSUBTREE
))!=DI_NODE_NIL
)
133 (*di_walk_node
)(root_node
,DI_WALK_SIBFIRST
,
134 di_node_name
,walk_nodename
);
135 (*di_fini
)(root_node
);
144 static sigjmp_buf common_jmp
;
145 static void common_handler(int sig
) { siglongjmp(common_jmp
,sig
); }
147 void OPENSSL_cpuid_setup(void)
150 struct sigaction common_act
,ill_oact
,bus_oact
;
151 sigset_t all_masked
,oset
;
154 if ((e
=getenv("OPENSSL_sparcv9cap")))
156 OPENSSL_sparcv9cap_P
=strtoul(e
,NULL
,0);
160 /* For now we assume that the rest supports UltraSPARC-I* only */
161 OPENSSL_sparcv9cap_P
|= SPARCV9_PREFER_FPU
|SPARCV9_VIS1
;
163 sigfillset(&all_masked
);
164 sigdelset(&all_masked
,SIGILL
);
165 sigdelset(&all_masked
,SIGTRAP
);
167 sigdelset(&all_masked
,SIGEMT
);
169 sigdelset(&all_masked
,SIGFPE
);
170 sigdelset(&all_masked
,SIGBUS
);
171 sigdelset(&all_masked
,SIGSEGV
);
172 sigprocmask(SIG_SETMASK
,&all_masked
,&oset
);
174 memset(&common_act
,0,sizeof(common_act
));
175 common_act
.sa_handler
= common_handler
;
176 common_act
.sa_mask
= all_masked
;
178 sigaction(SIGILL
,&common_act
,&ill_oact
);
179 sigaction(SIGBUS
,&common_act
,&bus_oact
);/* T1 fails 16-bit ldda */
180 if ((sig
=sigsetjmp(common_jmp
,0)) == 0)
182 _sparcv9_vis1_probe();
183 OPENSSL_sparcv9cap_P
|= SPARCV9_VIS1
;
185 else if (sig
== SIGBUS
) /* T1 fails 16-bit ldda */
187 OPENSSL_sparcv9cap_P
&= ~SPARCV9_PREFER_FPU
;
191 OPENSSL_sparcv9cap_P
&= ~SPARCV9_VIS1
;
193 sigaction(SIGBUS
,&bus_oact
,NULL
);
194 sigaction(SIGILL
,&ill_oact
,NULL
);
196 sigaction(SIGILL
,&common_act
,&ill_oact
);
197 if (sigsetjmp(common_jmp
,0) == 0)
200 OPENSSL_sparcv9cap_P
&= ~SPARCV9_TICK_PRIVILEGED
;
204 OPENSSL_sparcv9cap_P
|= SPARCV9_TICK_PRIVILEGED
;
206 sigaction(SIGILL
,&ill_oact
,NULL
);
208 sigprocmask(SIG_SETMASK
,&oset
,NULL
);