]>
Commit | Line | Data |
---|---|---|
14e21f86 AP |
1 | #!/usr/bin/env perl |
2 | ||
3 | $output=shift; | |
932cc129 | 4 | $masm=1 if ($output =~ /\.asm/); |
14e21f86 AP |
5 | open STDOUT,">$output" || die "can't open $output: $!"; |
6 | ||
932cc129 | 7 | print<<___ if(defined($masm)); |
376729e1 | 8 | _TEXT SEGMENT |
14e21f86 | 9 | PUBLIC OPENSSL_rdtsc |
376729e1 AP |
10 | |
11 | PUBLIC OPENSSL_atomic_add | |
12 | ALIGN 16 | |
13 | OPENSSL_atomic_add PROC | |
14 | mov eax,DWORD PTR[rcx] | |
15 | \$Lspin: lea r8,DWORD PTR[rdx+rax] | |
16 | lock cmpxchg DWORD PTR[rcx],r8d | |
17 | jne \$Lspin | |
18 | mov eax,r8d | |
19 | cdqe | |
20 | ret | |
21 | OPENSSL_atomic_add ENDP | |
22 | ||
23 | PUBLIC OPENSSL_wipe_cpu | |
24 | ALIGN 16 | |
25 | OPENSSL_wipe_cpu PROC | |
26 | pxor xmm0,xmm0 | |
27 | pxor xmm1,xmm1 | |
28 | pxor xmm2,xmm2 | |
29 | pxor xmm3,xmm3 | |
30 | pxor xmm4,xmm4 | |
31 | pxor xmm5,xmm5 | |
32 | xor rcx,rcx | |
33 | xor rdx,rdx | |
34 | xor r8,r8 | |
35 | xor r9,r9 | |
36 | xor r10,r10 | |
37 | xor r11,r11 | |
38 | lea rax,QWORD PTR[rsp+8] | |
39 | ret | |
40 | OPENSSL_wipe_cpu ENDP | |
376729e1 AP |
41 | _TEXT ENDS |
42 | ||
43 | CRT\$XIU SEGMENT | |
44 | EXTRN OPENSSL_cpuid_setup:PROC | |
45 | DQ OPENSSL_cpuid_setup | |
46 | CRT\$XIU ENDS | |
932cc129 | 47 | |
14e21f86 | 48 | ___ |
932cc129 | 49 | print<<___ if(!defined($masm)); |
14e21f86 | 50 | .text |
376729e1 AP |
51 | |
52 | .globl OPENSSL_atomic_add | |
53 | .type OPENSSL_atomic_add,\@function | |
54 | .align 16 | |
55 | OPENSSL_atomic_add: | |
56 | movl (%rdi),%eax | |
e442c362 AP |
57 | .Lspin: leaq (%rsi,%rax),%r8 |
58 | lock; cmpxchgl %r8d,(%rdi) | |
376729e1 | 59 | jne .Lspin |
e442c362 AP |
60 | movl %r8d,%eax |
61 | .byte 0x48,0x98 | |
376729e1 AP |
62 | ret |
63 | .size OPENSSL_atomic_add,.-OPENSSL_atomic_add | |
64 | ||
65 | .globl OPENSSL_wipe_cpu | |
66 | .type OPENSSL_wipe_cpu,\@function | |
67 | .align 16 | |
68 | OPENSSL_wipe_cpu: | |
69 | pxor %xmm0,%xmm0 | |
70 | pxor %xmm1,%xmm1 | |
71 | pxor %xmm2,%xmm2 | |
72 | pxor %xmm3,%xmm3 | |
73 | pxor %xmm4,%xmm4 | |
74 | pxor %xmm5,%xmm5 | |
75 | pxor %xmm6,%xmm6 | |
76 | pxor %xmm7,%xmm7 | |
77 | pxor %xmm8,%xmm8 | |
78 | pxor %xmm9,%xmm9 | |
79 | pxor %xmm10,%xmm10 | |
80 | pxor %xmm11,%xmm11 | |
81 | pxor %xmm12,%xmm12 | |
82 | pxor %xmm13,%xmm13 | |
83 | pxor %xmm14,%xmm14 | |
84 | pxor %xmm15,%xmm15 | |
e442c362 AP |
85 | xorq %rcx,%rcx |
86 | xorq %rdx,%rdx | |
87 | xorq %rsi,%rsi | |
88 | xorq %rdi,%rdi | |
89 | xorq %r8,%r8 | |
90 | xorq %r9,%r9 | |
91 | xorq %r10,%r10 | |
92 | xorq %r11,%r11 | |
93 | leaq 8(%rsp),%rax | |
376729e1 AP |
94 | ret |
95 | .size OPENSSL_wipe_cpu,.-OPENSSL_wipe_cpu | |
96 | ||
932cc129 AP |
97 | .section .init |
98 | call OPENSSL_cpuid_setup | |
99 | ||
100 | ___ | |
101 | ||
abe7f8b4 | 102 | $0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1; |
89778b7f | 103 | open STDOUT,"| $^X ${dir}perlasm/x86_64-xlate.pl $output"; |
abe7f8b4 | 104 | |
932cc129 AP |
105 | print<<___; |
106 | .text | |
107 | ||
108 | .globl OPENSSL_rdtsc | |
109 | .type OPENSSL_rdtsc,\@abi-omnipotent | |
110 | .align 16 | |
111 | OPENSSL_rdtsc: | |
112 | rdtsc | |
113 | shl \$32,%rdx | |
114 | or %rdx,%rax | |
115 | ret | |
116 | .size OPENSSL_rdtsc,.-OPENSSL_rdtsc | |
117 | ||
376729e1 | 118 | .globl OPENSSL_ia32_cpuid |
932cc129 | 119 | .type OPENSSL_ia32_cpuid,\@abi-omnipotent |
376729e1 AP |
120 | .align 16 |
121 | OPENSSL_ia32_cpuid: | |
932cc129 | 122 | mov %rbx,%r8 |
9babf392 AP |
123 | |
124 | xor %eax,%eax | |
125 | cpuid | |
126 | xor %eax,%eax | |
127 | cmp \$0x756e6547,%ebx # "Genu" | |
128 | setne %al | |
129 | mov %eax,%r9d | |
130 | cmp \$0x49656e69,%edx # "ineI" | |
131 | setne %al | |
132 | or %eax,%r9d | |
133 | cmp \$0x6c65746e,%ecx # "ntel" | |
134 | setne %al | |
135 | or %eax,%r9d | |
136 | ||
932cc129 | 137 | mov \$1,%eax |
376729e1 | 138 | cpuid |
932cc129 | 139 | cmp \$0,%r9d |
9babf392 | 140 | jne .Lnotintel |
55eab3b7 | 141 | or \$0x00100000,%edx # use reserved 20th bit to engage RC4_CHAR |
9babf392 AP |
142 | and \$15,%ah |
143 | cmp \$15,%ah # examine Family ID | |
144 | je .Lnotintel | |
55eab3b7 | 145 | or \$0x40000000,%edx # use reserved bit to skip unrolled loop |
9babf392 | 146 | .Lnotintel: |
3df2eff4 AP |
147 | bt \$28,%edx # test hyper-threading bit |
148 | jnc .Ldone | |
9babf392 AP |
149 | shr \$16,%ebx |
150 | cmp \$1,%bl # see if cache is shared | |
151 | ja .Ldone | |
932cc129 | 152 | and \$0xefffffff,%edx # ~(1<<28) |
9babf392 | 153 | .Ldone: |
932cc129 AP |
154 | shl \$32,%rcx |
155 | mov %edx,%eax | |
156 | mov %r8,%rbx | |
157 | or %rcx,%rax | |
376729e1 AP |
158 | ret |
159 | .size OPENSSL_ia32_cpuid,.-OPENSSL_ia32_cpuid | |
b2dba9bf AP |
160 | |
161 | .globl OPENSSL_cleanse | |
162 | .type OPENSSL_cleanse,\@function,2 | |
163 | .align 16 | |
164 | OPENSSL_cleanse: | |
165 | xor %rax,%rax | |
166 | cmp \$15,%rsi | |
167 | jae .Lot | |
168 | .Little: | |
169 | mov %al,(%rdi) | |
170 | sub \$1,%rsi | |
171 | lea 1(%rdi),%rdi | |
172 | jnz .Little | |
173 | ret | |
174 | .align 16 | |
175 | .Lot: | |
176 | test \$7,%rdi | |
177 | jz .Laligned | |
178 | mov %al,(%rdi) | |
179 | lea -1(%rsi),%rsi | |
180 | lea 1(%rdi),%rdi | |
181 | jmp .Lot | |
182 | .Laligned: | |
183 | mov %rax,(%rdi) | |
184 | lea -8(%rsi),%rsi | |
185 | test \$-8,%rsi | |
186 | lea 8(%rdi),%rdi | |
187 | jnz .Laligned | |
188 | cmp \$0,%rsi | |
189 | jne .Little | |
190 | ret | |
191 | .size OPENSSL_cleanse,.-OPENSSL_cleanse | |
14e21f86 | 192 | ___ |
5d863367 | 193 | close STDOUT; # flush |