Import of openssl-0.9.8, a feature release.
[dragonfly.git] / crypto / openssl-0.9 / crypto / x86_64cpuid.pl
1 #!/usr/bin/env perl
2
3 $output=shift;
4 $win64a=1 if ($output =~ /win64a\.[s|asm]/);
5 open STDOUT,">$output" || die "can't open $output: $!";
6
7 print<<___ if(defined($win64a));
8 _TEXT   SEGMENT
9 PUBLIC  OPENSSL_rdtsc
10 ALIGN   16
11 OPENSSL_rdtsc   PROC
12         rdtsc
13         shl     rdx,32
14         or      rax,rdx
15         ret
16 OPENSSL_rdtsc   ENDP
17
18 PUBLIC  OPENSSL_atomic_add
19 ALIGN   16
20 OPENSSL_atomic_add      PROC
21         mov     eax,DWORD PTR[rcx]
22 \$Lspin:        lea     r8,DWORD PTR[rdx+rax]
23 lock    cmpxchg DWORD PTR[rcx],r8d
24         jne     \$Lspin
25         mov     eax,r8d
26         cdqe    
27         ret
28 OPENSSL_atomic_add      ENDP
29
30 PUBLIC  OPENSSL_wipe_cpu
31 ALIGN   16
32 OPENSSL_wipe_cpu        PROC
33         pxor    xmm0,xmm0
34         pxor    xmm1,xmm1
35         pxor    xmm2,xmm2
36         pxor    xmm3,xmm3
37         pxor    xmm4,xmm4
38         pxor    xmm5,xmm5
39         xor     rcx,rcx
40         xor     rdx,rdx
41         xor     r8,r8
42         xor     r9,r9
43         xor     r10,r10
44         xor     r11,r11
45         lea     rax,QWORD PTR[rsp+8]
46         ret
47 OPENSSL_wipe_cpu        ENDP
48
49 OPENSSL_ia32_cpuid      PROC
50         mov     r8,rbx
51         mov     eax,1
52         cpuid
53         shl     rcx,32
54         mov     eax,edx
55         mov     rbx,r8
56         or      rax,rcx
57         ret
58 OPENSSL_ia32_cpuid      ENDP
59 _TEXT   ENDS
60
61 CRT\$XIU        SEGMENT
62 EXTRN   OPENSSL_cpuid_setup:PROC
63 DQ      OPENSSL_cpuid_setup
64 CRT\$XIU        ENDS
65 END
66 ___
67 print<<___ if(!defined($win64a));
68 .text
69 .globl  OPENSSL_rdtsc
70 .align  16
71 OPENSSL_rdtsc:
72         rdtsc
73         shlq    \$32,%rdx
74         orq     %rdx,%rax
75         ret
76 .size   OPENSSL_rdtsc,.-OPENSSL_rdtsc
77
78 .globl  OPENSSL_atomic_add
79 .type   OPENSSL_atomic_add,\@function
80 .align  16
81 OPENSSL_atomic_add:
82         movl    (%rdi),%eax
83 .Lspin: leaq    (%rsi,%rax),%r8
84 lock;   cmpxchgl        %r8d,(%rdi)
85         jne     .Lspin
86         movl    %r8d,%eax
87         .byte   0x48,0x98
88         ret
89 .size   OPENSSL_atomic_add,.-OPENSSL_atomic_add
90
91 .globl  OPENSSL_wipe_cpu
92 .type   OPENSSL_wipe_cpu,\@function
93 .align  16
94 OPENSSL_wipe_cpu:
95         pxor    %xmm0,%xmm0
96         pxor    %xmm1,%xmm1
97         pxor    %xmm2,%xmm2
98         pxor    %xmm3,%xmm3
99         pxor    %xmm4,%xmm4
100         pxor    %xmm5,%xmm5
101         pxor    %xmm6,%xmm6
102         pxor    %xmm7,%xmm7
103         pxor    %xmm8,%xmm8
104         pxor    %xmm9,%xmm9
105         pxor    %xmm10,%xmm10
106         pxor    %xmm11,%xmm11
107         pxor    %xmm12,%xmm12
108         pxor    %xmm13,%xmm13
109         pxor    %xmm14,%xmm14
110         pxor    %xmm15,%xmm15
111         xorq    %rcx,%rcx
112         xorq    %rdx,%rdx
113         xorq    %rsi,%rsi
114         xorq    %rdi,%rdi
115         xorq    %r8,%r8
116         xorq    %r9,%r9
117         xorq    %r10,%r10
118         xorq    %r11,%r11
119         leaq    8(%rsp),%rax
120         ret
121 .size   OPENSSL_wipe_cpu,.-OPENSSL_wipe_cpu
122
123 .globl  OPENSSL_ia32_cpuid
124 .align  16
125 OPENSSL_ia32_cpuid:
126         movq    %rbx,%r8
127         movl    \$1,%eax
128         cpuid
129         shlq    \$32,%rcx
130         movl    %edx,%eax
131         movq    %r8,%rbx
132         orq     %rcx,%rax
133         ret
134 .size   OPENSSL_ia32_cpuid,.-OPENSSL_ia32_cpuid
135
136 .section        .init
137         call    OPENSSL_cpuid_setup
138 ___