Fix DSA to skip EOL test when parsing mod line.
[openssl.git] / crypto / armcap.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <setjmp.h>
5 #include <signal.h>
6 #include <crypto.h>
7
8 #include "arm_arch.h"
9
10 unsigned int OPENSSL_armcap_P;
11
12 static sigset_t all_masked;
13
14 static sigjmp_buf ill_jmp;
15 static void ill_handler (int sig) { siglongjmp(ill_jmp,sig); }
16
17 /*
18  * Following subroutines could have been inlined, but it's not all
19  * ARM compilers support inline assembler...
20  */
21 void _armv7_neon_probe(void);
22 unsigned int _armv7_tick(void);
23
24 unsigned int OPENSSL_rdtsc(void)
25         {
26         if (OPENSSL_armcap_P|ARMV7_TICK)
27                 return _armv7_tick();
28         else
29                 return 0;
30         }
31
32 void OPENSSL_cpuid_setup(void)
33         {
34         char *e;
35         struct sigaction        ill_oact,ill_act;
36         sigset_t                oset;
37         static int trigger=0;
38
39         if (trigger) return;
40         trigger=1;
41  
42         if ((e=getenv("OPENSSL_armcap")))
43                 {
44                 OPENSSL_armcap_P=strtoul(e,NULL,0);
45                 return;
46                 }
47
48         sigfillset(&all_masked);
49         sigdelset(&all_masked,SIGILL);
50         sigdelset(&all_masked,SIGTRAP);
51         sigdelset(&all_masked,SIGFPE);
52         sigdelset(&all_masked,SIGBUS);
53         sigdelset(&all_masked,SIGSEGV);
54
55         OPENSSL_armcap_P = 0;
56
57         memset(&ill_act,0,sizeof(ill_act));
58         ill_act.sa_handler = ill_handler;
59         ill_act.sa_mask    = all_masked;
60
61         sigprocmask(SIG_SETMASK,&ill_act.sa_mask,&oset);
62         sigaction(SIGILL,&ill_act,&ill_oact);
63
64         if (sigsetjmp(ill_jmp,1) == 0)
65                 {
66                 _armv7_neon_probe();
67                 OPENSSL_armcap_P |= ARMV7_NEON;
68                 }
69         if (sigsetjmp(ill_jmp,1) == 0)
70                 {
71                 _armv7_tick();
72                 OPENSSL_armcap_P |= ARMV7_TICK;
73                 }
74
75         sigaction (SIGILL,&ill_oact,NULL);
76         sigprocmask(SIG_SETMASK,&oset,NULL);
77         }