Import of openssl-0.9.8, a feature release.
[dragonfly.git] / crypto / openssl-0.9 / crypto / x86_64cpuid.pl
CommitLineData
56276539
SS
1#!/usr/bin/env perl
2
3$output=shift;
4$win64a=1 if ($output =~ /win64a\.[s|asm]/);
5open STDOUT,">$output" || die "can't open $output: $!";
6
7print<<___ if(defined($win64a));
8_TEXT SEGMENT
9PUBLIC OPENSSL_rdtsc
10ALIGN 16
11OPENSSL_rdtsc PROC
12 rdtsc
13 shl rdx,32
14 or rax,rdx
15 ret
16OPENSSL_rdtsc ENDP
17
18PUBLIC OPENSSL_atomic_add
19ALIGN 16
20OPENSSL_atomic_add PROC
21 mov eax,DWORD PTR[rcx]
22\$Lspin: lea r8,DWORD PTR[rdx+rax]
23lock cmpxchg DWORD PTR[rcx],r8d
24 jne \$Lspin
25 mov eax,r8d
26 cdqe
27 ret
28OPENSSL_atomic_add ENDP
29
30PUBLIC OPENSSL_wipe_cpu
31ALIGN 16
32OPENSSL_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
47OPENSSL_wipe_cpu ENDP
48
49OPENSSL_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
58OPENSSL_ia32_cpuid ENDP
59_TEXT ENDS
60
61CRT\$XIU SEGMENT
62EXTRN OPENSSL_cpuid_setup:PROC
63DQ OPENSSL_cpuid_setup
64CRT\$XIU ENDS
65END
66___
67print<<___ if(!defined($win64a));
68.text
69.globl OPENSSL_rdtsc
70.align 16
71OPENSSL_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
81OPENSSL_atomic_add:
82 movl (%rdi),%eax
83.Lspin: leaq (%rsi,%rax),%r8
84lock; 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
94OPENSSL_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
125OPENSSL_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___