5 #include <openssl/bn.h>
7 #define SPARCV9_TICK_PRIVILEGED (1<<0)
8 #define SPARCV9_PREFER_FPU (1<<1)
9 #define SPARCV9_VIS1 (1<<2)
10 #define SPARCV9_VIS2 (1<<3) /* reserved */
11 #define SPARCV9_FMADD (1<<4) /* reserved for SPARC64 V */
12 static int OPENSSL_sparcv9cap_P
=SPARCV9_TICK_PRIVILEGED
;
14 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
)
16 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
);
17 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
);
19 if ((OPENSSL_sparcv9cap_P
&(SPARCV9_PREFER_FPU
|SPARCV9_VIS1
)) ==
20 (SPARCV9_PREFER_FPU
|SPARCV9_VIS1
))
21 return bn_mul_mont_fpu(rp
,ap
,bp
,np
,n0
,num
);
23 return bn_mul_mont_int(rp
,ap
,bp
,np
,n0
,num
);
26 unsigned long OPENSSL_rdtsc(void)
28 unsigned long _sparcv9_rdtick(void);
30 if (OPENSSL_sparcv9cap_P
&SPARCV9_TICK_PRIVILEGED
)
31 #if defined(__sun) && defined(__SVR4)
37 return _sparcv9_rdtick();
40 #if defined(__sun) && defined(__SVR4)
43 #include <libdevinfo.h>
45 typedef di_node_t (*di_init_t
)(const char *,uint_t
);
46 typedef void (*di_fini_t
)(di_node_t
);
47 typedef char * (*di_node_name_t
)(di_node_t
);
48 typedef int (*di_walk_node_t
)(di_node_t
,uint_t
,di_node_name_t
,int (*)(di_node_t
,di_node_name_t
));
50 #define DLLINK(h,name) (name=(name##_t)dlsym((h),#name))
52 static int walk_nodename(di_node_t node
, di_node_name_t di_node_name
)
54 char *name
= (*di_node_name
)(node
);
56 /* This is expected to catch all UltraSPARC flavors prior T1 */
57 if (!strcmp (name
,"SUNW,UltraSPARC") ||
58 !strncmp(name
,"SUNW,UltraSPARC-I",17))
60 OPENSSL_sparcv9cap_P
|= SPARCV9_PREFER_FPU
|SPARCV9_VIS1
;
62 /* %tick is privileged only on UltraSPARC-I/II */
63 if (name
[14]!='\0' && name
[17]!='\0' && name
[18]!='\0')
64 OPENSSL_sparcv9cap_P
&= ~SPARCV9_TICK_PRIVILEGED
;
66 return DI_WALK_TERMINATE
;
68 /* This is expected to catch remaining UltraSPARC T1 */
69 else if (!strncmp(name
,"SUNW,UltraSPARC",15))
71 OPENSSL_sparcv9cap_P
|= SPARCV9_VIS1
;
72 OPENSSL_sparcv9cap_P
&= ~SPARCV9_TICK_PRIVILEGED
;
75 return DI_WALK_CONTINUE
;
78 void OPENSSL_cpuid_setup(void)
87 if ((e
=getenv("OPENSSL_sparcv9cap")))
89 OPENSSL_sparcv9cap_P
=strtoul(e
,NULL
,0);
93 if ((h
= dlopen("libdevinfo.so.1",RTLD_LAZY
))) do
97 di_walk_node_t di_walk_node
;
98 di_node_name_t di_node_name
;
101 if (!DLLINK(h
,di_init
)) break;
102 if (!DLLINK(h
,di_fini
)) break;
103 if (!DLLINK(h
,di_walk_node
)) break;
104 if (!DLLINK(h
,di_node_name
)) break;
106 if ((root_node
= (*di_init
)("/",DINFOSUBTREE
))!=DI_NODE_NIL
)
108 (*di_walk_node
)(root_node
,DI_WALK_SIBFIRST
,
109 di_node_name
,walk_nodename
);
110 (*di_fini
)(root_node
);
119 void OPENSSL_cpucap_setup(void)
123 if ((e
=getenv("OPENSSL_sparcv9cap")))
125 OPENSSL_sparcv9cap_P
=strtoul(env
,NULL
,0);
129 /* For now we assume that the rest supports UltraSPARC-I* only */
130 OPENSSL_sparcv9cap_P
|= SPARCV9_PREFER_FPU
|SPARCV9_VIS1
;