xref: /netbsd-src/crypto/external/bsd/openssl/lib/libcrypto/arch/i386/x86cpuid.S (revision b757af438b42b93f8c6571f026d8b8ef3eaf5fc9)
1#include <machine/asm.h>
2
3.file	"x86cpuid.s"
4.text
5.globl	OPENSSL_ia32_cpuid
6.type	OPENSSL_ia32_cpuid,@function
7.align	16
8OPENSSL_ia32_cpuid:
9.L_OPENSSL_ia32_cpuid_begin:
10	pushl	%ebp
11	pushl	%ebx
12	pushl	%esi
13	pushl	%edi
14	xorl	%edx,%edx
15	pushfl
16	popl	%eax
17	movl	%eax,%ecx
18	xorl	$2097152,%eax
19	pushl	%eax
20	popfl
21	pushfl
22	popl	%eax
23	xorl	%eax,%ecx
24	btl	$21,%ecx
25	jnc	.L000done
26	xorl	%eax,%eax
27	.byte	0x0f,0xa2
28	movl	%eax,%edi
29	xorl	%eax,%eax
30	cmpl	$1970169159,%ebx
31	setne	%al
32	movl	%eax,%ebp
33	cmpl	$1231384169,%edx
34	setne	%al
35	orl	%eax,%ebp
36	cmpl	$1818588270,%ecx
37	setne	%al
38	orl	%eax,%ebp
39	jz	.L001intel
40	cmpl	$1752462657,%ebx
41	setne	%al
42	movl	%eax,%esi
43	cmpl	$1769238117,%edx
44	setne	%al
45	orl	%eax,%esi
46	cmpl	$1145913699,%ecx
47	setne	%al
48	orl	%eax,%esi
49	jnz	.L001intel
50	movl	$2147483648,%eax
51	.byte	0x0f,0xa2
52	cmpl	$2147483656,%eax
53	jb	.L001intel
54	movl	$2147483656,%eax
55	.byte	0x0f,0xa2
56	movzbl	%cl,%esi
57	incl	%esi
58	movl	$1,%eax
59	.byte	0x0f,0xa2
60	btl	$28,%edx
61	jnc	.L000done
62	shrl	$16,%ebx
63	andl	$255,%ebx
64	cmpl	%esi,%ebx
65	ja	.L000done
66	andl	$4026531839,%edx
67	jmp	.L000done
68.L001intel:
69	cmpl	$4,%edi
70	movl	$-1,%edi
71	jb	.L002nocacheinfo
72	movl	$4,%eax
73	movl	$0,%ecx
74	.byte	0x0f,0xa2
75	movl	%eax,%edi
76	shrl	$14,%edi
77	andl	$4095,%edi
78.L002nocacheinfo:
79	movl	$1,%eax
80	.byte	0x0f,0xa2
81	cmpl	$0,%ebp
82	jne	.L003notP4
83	andb	$15,%ah
84	cmpb	$15,%ah
85	jne	.L003notP4
86	orl	$1048576,%edx
87.L003notP4:
88	btl	$28,%edx
89	jnc	.L000done
90	andl	$4026531839,%edx
91	cmpl	$0,%edi
92	je	.L000done
93	orl	$268435456,%edx
94	shrl	$16,%ebx
95	cmpb	$1,%bl
96	ja	.L000done
97	andl	$4026531839,%edx
98.L000done:
99	movl	%edx,%eax
100	movl	%ecx,%edx
101	popl	%edi
102	popl	%esi
103	popl	%ebx
104	popl	%ebp
105	ret
106.size	OPENSSL_ia32_cpuid,.-.L_OPENSSL_ia32_cpuid_begin
107.globl	OPENSSL_rdtsc
108.type	OPENSSL_rdtsc,@function
109.align	16
110OPENSSL_rdtsc:
111.L_OPENSSL_rdtsc_begin:
112	xorl	%eax,%eax
113	xorl	%edx,%edx
114	call	.L004PIC_me_up
115.L004PIC_me_up:
116	popl	%ecx
117	leal	_GLOBAL_OFFSET_TABLE_+[.-.L004PIC_me_up](%ecx),%ecx
118	movl	OPENSSL_ia32cap_P@GOT(%ecx),%ecx
119	btl	$4,(%ecx)
120	jnc	.L005notsc
121	.byte	0x0f,0x31
122.L005notsc:
123	ret
124.size	OPENSSL_rdtsc,.-.L_OPENSSL_rdtsc_begin
125.globl	OPENSSL_instrument_halt
126.type	OPENSSL_instrument_halt,@function
127.align	16
128OPENSSL_instrument_halt:
129.L_OPENSSL_instrument_halt_begin:
130	call	.L006PIC_me_up
131.L006PIC_me_up:
132	popl	%ecx
133	leal	_GLOBAL_OFFSET_TABLE_+[.-.L006PIC_me_up](%ecx),%ecx
134	movl	OPENSSL_ia32cap_P@GOT(%ecx),%ecx
135	btl	$4,(%ecx)
136	jnc	.L007nohalt
137.long	2421723150
138	andl	$3,%eax
139	jnz	.L007nohalt
140	pushfl
141	popl	%eax
142	btl	$9,%eax
143	jnc	.L007nohalt
144	.byte	0x0f,0x31
145	pushl	%edx
146	pushl	%eax
147	hlt
148	.byte	0x0f,0x31
149	subl	(%esp),%eax
150	sbbl	4(%esp),%edx
151	addl	$8,%esp
152	ret
153.L007nohalt:
154	xorl	%eax,%eax
155	xorl	%edx,%edx
156	ret
157.size	OPENSSL_instrument_halt,.-.L_OPENSSL_instrument_halt_begin
158.globl	OPENSSL_far_spin
159.type	OPENSSL_far_spin,@function
160.align	16
161OPENSSL_far_spin:
162.L_OPENSSL_far_spin_begin:
163	pushfl
164	popl	%eax
165	btl	$9,%eax
166	jnc	.L008nospin
167	movl	4(%esp),%eax
168	movl	8(%esp),%ecx
169.long	2430111262
170	xorl	%eax,%eax
171	movl	(%ecx),%edx
172	jmp	.L009spin
173.align	16
174.L009spin:
175	incl	%eax
176	cmpl	(%ecx),%edx
177	je	.L009spin
178.long	529567888
179	ret
180.L008nospin:
181	xorl	%eax,%eax
182	xorl	%edx,%edx
183	ret
184.size	OPENSSL_far_spin,.-.L_OPENSSL_far_spin_begin
185.globl	OPENSSL_wipe_cpu
186.type	OPENSSL_wipe_cpu,@function
187.align	16
188OPENSSL_wipe_cpu:
189.L_OPENSSL_wipe_cpu_begin:
190	xorl	%eax,%eax
191	xorl	%edx,%edx
192	call	.L010PIC_me_up
193.L010PIC_me_up:
194	popl	%ecx
195	leal	_GLOBAL_OFFSET_TABLE_+[.-.L010PIC_me_up](%ecx),%ecx
196	movl	OPENSSL_ia32cap_P@GOT(%ecx),%ecx
197	movl	(%ecx),%ecx
198	btl	$1,(%ecx)
199	jnc	.L011no_x87
200.long	4007259865,4007259865,4007259865,4007259865,2430851995
201.L011no_x87:
202	leal	4(%esp),%eax
203	ret
204.size	OPENSSL_wipe_cpu,.-.L_OPENSSL_wipe_cpu_begin
205.globl	OPENSSL_atomic_add
206.type	OPENSSL_atomic_add,@function
207.align	16
208OPENSSL_atomic_add:
209.L_OPENSSL_atomic_add_begin:
210	movl	4(%esp),%edx
211	movl	8(%esp),%ecx
212	pushl	%ebx
213	nop
214	movl	(%edx),%eax
215.L012spin:
216	leal	(%eax,%ecx,1),%ebx
217	nop
218.long	447811568
219	jne	.L012spin
220	movl	%ebx,%eax
221	popl	%ebx
222	ret
223.size	OPENSSL_atomic_add,.-.L_OPENSSL_atomic_add_begin
224.globl	OPENSSL_indirect_call
225.type	OPENSSL_indirect_call,@function
226.align	16
227OPENSSL_indirect_call:
228.L_OPENSSL_indirect_call_begin:
229	pushl	%ebp
230	movl	%esp,%ebp
231	subl	$28,%esp
232	movl	12(%ebp),%ecx
233	movl	%ecx,(%esp)
234	movl	16(%ebp),%edx
235	movl	%edx,4(%esp)
236	movl	20(%ebp),%eax
237	movl	%eax,8(%esp)
238	movl	24(%ebp),%eax
239	movl	%eax,12(%esp)
240	movl	28(%ebp),%eax
241	movl	%eax,16(%esp)
242	movl	32(%ebp),%eax
243	movl	%eax,20(%esp)
244	movl	36(%ebp),%eax
245	movl	%eax,24(%esp)
246	call	*8(%ebp)
247	movl	%ebp,%esp
248	popl	%ebp
249	ret
250.size	OPENSSL_indirect_call,.-.L_OPENSSL_indirect_call_begin
251.globl	OPENSSL_cleanse
252.type	OPENSSL_cleanse,@function
253.align	16
254OPENSSL_cleanse:
255.L_OPENSSL_cleanse_begin:
256	movl	4(%esp),%edx
257	movl	8(%esp),%ecx
258	xorl	%eax,%eax
259	cmpl	$7,%ecx
260	jae	.L013lot
261	cmpl	$0,%ecx
262	je	.L014ret
263.L015little:
264	movb	%al,(%edx)
265	subl	$1,%ecx
266	leal	1(%edx),%edx
267	jnz	.L015little
268.L014ret:
269	ret
270.align	16
271.L013lot:
272	testl	$3,%edx
273	jz	.L016aligned
274	movb	%al,(%edx)
275	leal	-1(%ecx),%ecx
276	leal	1(%edx),%edx
277	jmp	.L013lot
278.L016aligned:
279	movl	%eax,(%edx)
280	leal	-4(%ecx),%ecx
281	testl	$-4,%ecx
282	leal	4(%edx),%edx
283	jnz	.L016aligned
284	cmpl	$0,%ecx
285	jne	.L015little
286	ret
287.size	OPENSSL_cleanse,.-.L_OPENSSL_cleanse_begin
288.comm	OPENSSL_ia32cap_P,4,4
289.section	.init
290#ifdef PIC
291	PIC_PROLOGUE
292	call	PIC_PLT(_C_LABEL(OPENSSL_cpuid_setup))
293	PIC_EPILOGUE
294#else
295	call	_C_LABEL(OPENSSL_cpuid_setup)
296#endif
297	jmp	.Linitalign
298.align	16
299.Linitalign:
300