x86cpuid.s revision 279264
1	# $FreeBSD: releng/10.0/secure/lib/libcrypto/i386/x86cpuid.s 279264 2015-02-25 05:56:16Z delphij $
2.file	"x86cpuid.s"
3.text
4.globl	OPENSSL_ia32_cpuid
5.type	OPENSSL_ia32_cpuid,@function
6.align	16
7OPENSSL_ia32_cpuid:
8.L_OPENSSL_ia32_cpuid_begin:
9	pushl	%ebp
10	pushl	%ebx
11	pushl	%esi
12	pushl	%edi
13	xorl	%edx,%edx
14	pushfl
15	popl	%eax
16	movl	%eax,%ecx
17	xorl	$2097152,%eax
18	pushl	%eax
19	popfl
20	pushfl
21	popl	%eax
22	xorl	%eax,%ecx
23	xorl	%eax,%eax
24	btl	$21,%ecx
25	jnc	.L000nocpuid
26	.byte	0x0f,0xa2
27	movl	%eax,%edi
28	xorl	%eax,%eax
29	cmpl	$1970169159,%ebx
30	setne	%al
31	movl	%eax,%ebp
32	cmpl	$1231384169,%edx
33	setne	%al
34	orl	%eax,%ebp
35	cmpl	$1818588270,%ecx
36	setne	%al
37	orl	%eax,%ebp
38	jz	.L001intel
39	cmpl	$1752462657,%ebx
40	setne	%al
41	movl	%eax,%esi
42	cmpl	$1769238117,%edx
43	setne	%al
44	orl	%eax,%esi
45	cmpl	$1145913699,%ecx
46	setne	%al
47	orl	%eax,%esi
48	jnz	.L001intel
49	movl	$2147483648,%eax
50	.byte	0x0f,0xa2
51	cmpl	$2147483649,%eax
52	jb	.L001intel
53	movl	%eax,%esi
54	movl	$2147483649,%eax
55	.byte	0x0f,0xa2
56	orl	%ecx,%ebp
57	andl	$2049,%ebp
58	cmpl	$2147483656,%esi
59	jb	.L001intel
60	movl	$2147483656,%eax
61	.byte	0x0f,0xa2
62	movzbl	%cl,%esi
63	incl	%esi
64	movl	$1,%eax
65	xorl	%ecx,%ecx
66	.byte	0x0f,0xa2
67	btl	$28,%edx
68	jnc	.L002generic
69	shrl	$16,%ebx
70	andl	$255,%ebx
71	cmpl	%esi,%ebx
72	ja	.L002generic
73	andl	$4026531839,%edx
74	jmp	.L002generic
75.L001intel:
76	cmpl	$4,%edi
77	movl	$-1,%edi
78	jb	.L003nocacheinfo
79	movl	$4,%eax
80	movl	$0,%ecx
81	.byte	0x0f,0xa2
82	movl	%eax,%edi
83	shrl	$14,%edi
84	andl	$4095,%edi
85.L003nocacheinfo:
86	movl	$1,%eax
87	xorl	%ecx,%ecx
88	.byte	0x0f,0xa2
89	andl	$3220176895,%edx
90	cmpl	$0,%ebp
91	jne	.L004notintel
92	orl	$1073741824,%edx
93	andb	$15,%ah
94	cmpb	$15,%ah
95	jne	.L004notintel
96	orl	$1048576,%edx
97.L004notintel:
98	btl	$28,%edx
99	jnc	.L002generic
100	andl	$4026531839,%edx
101	cmpl	$0,%edi
102	je	.L002generic
103	orl	$268435456,%edx
104	shrl	$16,%ebx
105	cmpb	$1,%bl
106	ja	.L002generic
107	andl	$4026531839,%edx
108.L002generic:
109	andl	$2048,%ebp
110	andl	$4294965247,%ecx
111	movl	%edx,%esi
112	orl	%ecx,%ebp
113	btl	$27,%ecx
114	jnc	.L005clear_avx
115	xorl	%ecx,%ecx
116.byte	15,1,208
117	andl	$6,%eax
118	cmpl	$6,%eax
119	je	.L006done
120	cmpl	$2,%eax
121	je	.L005clear_avx
122.L007clear_xmm:
123	andl	$4261412861,%ebp
124	andl	$4278190079,%esi
125.L005clear_avx:
126	andl	$4026525695,%ebp
127.L006done:
128	movl	%esi,%eax
129	movl	%ebp,%edx
130.L000nocpuid:
131	popl	%edi
132	popl	%esi
133	popl	%ebx
134	popl	%ebp
135	ret
136.size	OPENSSL_ia32_cpuid,.-.L_OPENSSL_ia32_cpuid_begin
137.globl	OPENSSL_rdtsc
138.type	OPENSSL_rdtsc,@function
139.align	16
140OPENSSL_rdtsc:
141.L_OPENSSL_rdtsc_begin:
142	xorl	%eax,%eax
143	xorl	%edx,%edx
144	leal	OPENSSL_ia32cap_P,%ecx
145	btl	$4,(%ecx)
146	jnc	.L008notsc
147	.byte	0x0f,0x31
148.L008notsc:
149	ret
150.size	OPENSSL_rdtsc,.-.L_OPENSSL_rdtsc_begin
151.globl	OPENSSL_instrument_halt
152.type	OPENSSL_instrument_halt,@function
153.align	16
154OPENSSL_instrument_halt:
155.L_OPENSSL_instrument_halt_begin:
156	leal	OPENSSL_ia32cap_P,%ecx
157	btl	$4,(%ecx)
158	jnc	.L009nohalt
159.long	2421723150
160	andl	$3,%eax
161	jnz	.L009nohalt
162	pushfl
163	popl	%eax
164	btl	$9,%eax
165	jnc	.L009nohalt
166	.byte	0x0f,0x31
167	pushl	%edx
168	pushl	%eax
169	hlt
170	.byte	0x0f,0x31
171	subl	(%esp),%eax
172	sbbl	4(%esp),%edx
173	addl	$8,%esp
174	ret
175.L009nohalt:
176	xorl	%eax,%eax
177	xorl	%edx,%edx
178	ret
179.size	OPENSSL_instrument_halt,.-.L_OPENSSL_instrument_halt_begin
180.globl	OPENSSL_far_spin
181.type	OPENSSL_far_spin,@function
182.align	16
183OPENSSL_far_spin:
184.L_OPENSSL_far_spin_begin:
185	pushfl
186	popl	%eax
187	btl	$9,%eax
188	jnc	.L010nospin
189	movl	4(%esp),%eax
190	movl	8(%esp),%ecx
191.long	2430111262
192	xorl	%eax,%eax
193	movl	(%ecx),%edx
194	jmp	.L011spin
195.align	16
196.L011spin:
197	incl	%eax
198	cmpl	(%ecx),%edx
199	je	.L011spin
200.long	529567888
201	ret
202.L010nospin:
203	xorl	%eax,%eax
204	xorl	%edx,%edx
205	ret
206.size	OPENSSL_far_spin,.-.L_OPENSSL_far_spin_begin
207.globl	OPENSSL_wipe_cpu
208.type	OPENSSL_wipe_cpu,@function
209.align	16
210OPENSSL_wipe_cpu:
211.L_OPENSSL_wipe_cpu_begin:
212	xorl	%eax,%eax
213	xorl	%edx,%edx
214	leal	OPENSSL_ia32cap_P,%ecx
215	movl	(%ecx),%ecx
216	btl	$1,(%ecx)
217	jnc	.L012no_x87
218	andl	$83886080,%ecx
219	cmpl	$83886080,%ecx
220	jne	.L013no_sse2
221	pxor	%xmm0,%xmm0
222	pxor	%xmm1,%xmm1
223	pxor	%xmm2,%xmm2
224	pxor	%xmm3,%xmm3
225	pxor	%xmm4,%xmm4
226	pxor	%xmm5,%xmm5
227	pxor	%xmm6,%xmm6
228	pxor	%xmm7,%xmm7
229.L013no_sse2:
230.long	4007259865,4007259865,4007259865,4007259865,2430851995
231.L012no_x87:
232	leal	4(%esp),%eax
233	ret
234.size	OPENSSL_wipe_cpu,.-.L_OPENSSL_wipe_cpu_begin
235.globl	OPENSSL_atomic_add
236.type	OPENSSL_atomic_add,@function
237.align	16
238OPENSSL_atomic_add:
239.L_OPENSSL_atomic_add_begin:
240	movl	4(%esp),%edx
241	movl	8(%esp),%ecx
242	pushl	%ebx
243	nop
244	movl	(%edx),%eax
245.L014spin:
246	leal	(%eax,%ecx,1),%ebx
247	nop
248.long	447811568
249	jne	.L014spin
250	movl	%ebx,%eax
251	popl	%ebx
252	ret
253.size	OPENSSL_atomic_add,.-.L_OPENSSL_atomic_add_begin
254.globl	OPENSSL_indirect_call
255.type	OPENSSL_indirect_call,@function
256.align	16
257OPENSSL_indirect_call:
258.L_OPENSSL_indirect_call_begin:
259	pushl	%ebp
260	movl	%esp,%ebp
261	subl	$28,%esp
262	movl	12(%ebp),%ecx
263	movl	%ecx,(%esp)
264	movl	16(%ebp),%edx
265	movl	%edx,4(%esp)
266	movl	20(%ebp),%eax
267	movl	%eax,8(%esp)
268	movl	24(%ebp),%eax
269	movl	%eax,12(%esp)
270	movl	28(%ebp),%eax
271	movl	%eax,16(%esp)
272	movl	32(%ebp),%eax
273	movl	%eax,20(%esp)
274	movl	36(%ebp),%eax
275	movl	%eax,24(%esp)
276	call	*8(%ebp)
277	movl	%ebp,%esp
278	popl	%ebp
279	ret
280.size	OPENSSL_indirect_call,.-.L_OPENSSL_indirect_call_begin
281.globl	OPENSSL_cleanse
282.type	OPENSSL_cleanse,@function
283.align	16
284OPENSSL_cleanse:
285.L_OPENSSL_cleanse_begin:
286	movl	4(%esp),%edx
287	movl	8(%esp),%ecx
288	xorl	%eax,%eax
289	cmpl	$7,%ecx
290	jae	.L015lot
291	cmpl	$0,%ecx
292	je	.L016ret
293.L017little:
294	movb	%al,(%edx)
295	subl	$1,%ecx
296	leal	1(%edx),%edx
297	jnz	.L017little
298.L016ret:
299	ret
300.align	16
301.L015lot:
302	testl	$3,%edx
303	jz	.L018aligned
304	movb	%al,(%edx)
305	leal	-1(%ecx),%ecx
306	leal	1(%edx),%edx
307	jmp	.L015lot
308.L018aligned:
309	movl	%eax,(%edx)
310	leal	-4(%ecx),%ecx
311	testl	$-4,%ecx
312	leal	4(%edx),%edx
313	jnz	.L018aligned
314	cmpl	$0,%ecx
315	jne	.L017little
316	ret
317.size	OPENSSL_cleanse,.-.L_OPENSSL_cleanse_begin
318.globl	OPENSSL_ia32_rdrand
319.type	OPENSSL_ia32_rdrand,@function
320.align	16
321OPENSSL_ia32_rdrand:
322.L_OPENSSL_ia32_rdrand_begin:
323	movl	$8,%ecx
324.L019loop:
325.byte	15,199,240
326	jc	.L020break
327	loop	.L019loop
328.L020break:
329	cmpl	$0,%eax
330	cmovel	%ecx,%eax
331	ret
332.size	OPENSSL_ia32_rdrand,.-.L_OPENSSL_ia32_rdrand_begin
333.comm	OPENSSL_ia32cap_P,8,4
334.section	.init
335	call	OPENSSL_cpuid_setup
336