renamed asm directories.
[gnutls:gnutls.git] / lib / accelerated / x86 / elf / padlock-x86.s
1 # Copyright (c) 2011, Andy Polyakov by <appro@openssl.org>
2 # All rights reserved.
3 #
4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions
6 # are met:
7
8 #     * Redistributions of source code must retain copyright notices,
9 #      this list of conditions and the following disclaimer.
10 #
11 #     * Redistributions in binary form must reproduce the above
12 #      copyright notice, this list of conditions and the following
13 #      disclaimer in the documentation and/or other materials
14 #      provided with the distribution.
15 #
16 #     * Neither the name of the Andy Polyakov nor the names of its
17 #      copyright holder and contributors may be used to endorse or
18 #      promote products derived from this software without specific
19 #      prior written permission.
20 #
21 # ALTERNATIVELY, provided that this notice is retained in full, this
22 # product may be distributed under the terms of the GNU General Public
23 # License (GPL), in which case the provisions of the GPL apply INSTEAD OF
24 # those given above.
25 #
26 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS
27 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
29 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
30 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
31 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
32 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
33 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
34 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37
38 .file   "devel/perlasm/e_padlock-x86.s"
39 .text
40 .globl  padlock_capability
41 .type   padlock_capability,@function
42 .align  16
43 padlock_capability:
44 .L_padlock_capability_begin:
45         pushl   %ebx
46         pushfl
47         popl    %eax
48         movl    %eax,%ecx
49         xorl    $2097152,%eax
50         pushl   %eax
51         popfl
52         pushfl
53         popl    %eax
54         xorl    %eax,%ecx
55         xorl    %eax,%eax
56         btl     $21,%ecx
57         jnc     .L000noluck
58         .byte   0x0f,0xa2
59         xorl    %eax,%eax
60         cmpl    $0x746e6543,%ebx
61         jne     .L000noluck
62         cmpl    $0x48727561,%edx
63         jne     .L000noluck
64         cmpl    $0x736c7561,%ecx
65         jne     .L000noluck
66         movl    $3221225472,%eax
67         .byte   0x0f,0xa2
68         movl    %eax,%edx
69         xorl    %eax,%eax
70         cmpl    $3221225473,%edx
71         jb      .L000noluck
72         movl    $1,%eax
73         .byte   0x0f,0xa2
74         orl     $15,%eax
75         xorl    %ebx,%ebx
76         andl    $4095,%eax
77         cmpl    $1791,%eax
78         sete    %bl
79         movl    $3221225473,%eax
80         pushl   %ebx
81         .byte   0x0f,0xa2
82         popl    %ebx
83         movl    %edx,%eax
84         shll    $4,%ebx
85         andl    $4294967279,%eax
86         orl     %ebx,%eax
87 .L000noluck:
88         popl    %ebx
89         ret
90 .size   padlock_capability,.-.L_padlock_capability_begin
91 .globl  padlock_key_bswap
92 .type   padlock_key_bswap,@function
93 .align  16
94 padlock_key_bswap:
95 .L_padlock_key_bswap_begin:
96         movl    4(%esp),%edx
97         movl    240(%edx),%ecx
98 .L001bswap_loop:
99         movl    (%edx),%eax
100         bswap   %eax
101         movl    %eax,(%edx)
102         leal    4(%edx),%edx
103         subl    $1,%ecx
104         jnz     .L001bswap_loop
105         ret
106 .size   padlock_key_bswap,.-.L_padlock_key_bswap_begin
107 .globl  padlock_verify_context
108 .type   padlock_verify_context,@function
109 .align  16
110 padlock_verify_context:
111 .L_padlock_verify_context_begin:
112         movl    4(%esp),%edx
113         leal    .Lpadlock_saved_context-.L002verify_pic_point,%eax
114         pushfl
115         call    _padlock_verify_ctx
116 .L002verify_pic_point:
117         leal    4(%esp),%esp
118         ret
119 .size   padlock_verify_context,.-.L_padlock_verify_context_begin
120 .type   _padlock_verify_ctx,@function
121 .align  16
122 _padlock_verify_ctx:
123         addl    (%esp),%eax
124         btl     $30,4(%esp)
125         jnc     .L003verified
126         cmpl    (%eax),%edx
127         je      .L003verified
128         pushfl
129         popfl
130 .L003verified:
131         movl    %edx,(%eax)
132         ret
133 .size   _padlock_verify_ctx,.-_padlock_verify_ctx
134 .globl  padlock_reload_key
135 .type   padlock_reload_key,@function
136 .align  16
137 padlock_reload_key:
138 .L_padlock_reload_key_begin:
139         pushfl
140         popfl
141         ret
142 .size   padlock_reload_key,.-.L_padlock_reload_key_begin
143 .globl  padlock_aes_block
144 .type   padlock_aes_block,@function
145 .align  16
146 padlock_aes_block:
147 .L_padlock_aes_block_begin:
148         pushl   %edi
149         pushl   %esi
150         pushl   %ebx
151         movl    16(%esp),%edi
152         movl    20(%esp),%esi
153         movl    24(%esp),%edx
154         movl    $1,%ecx
155         leal    32(%edx),%ebx
156         leal    16(%edx),%edx
157 .byte   243,15,167,200
158         popl    %ebx
159         popl    %esi
160         popl    %edi
161         ret
162 .size   padlock_aes_block,.-.L_padlock_aes_block_begin
163 .globl  padlock_ecb_encrypt
164 .type   padlock_ecb_encrypt,@function
165 .align  16
166 padlock_ecb_encrypt:
167 .L_padlock_ecb_encrypt_begin:
168         pushl   %ebp
169         pushl   %ebx
170         pushl   %esi
171         pushl   %edi
172         movl    20(%esp),%edi
173         movl    24(%esp),%esi
174         movl    28(%esp),%edx
175         movl    32(%esp),%ecx
176         testl   $15,%edx
177         jnz     .L004ecb_abort
178         testl   $15,%ecx
179         jnz     .L004ecb_abort
180         leal    .Lpadlock_saved_context-.L005ecb_pic_point,%eax
181         pushfl
182         cld
183         call    _padlock_verify_ctx
184 .L005ecb_pic_point:
185         leal    16(%edx),%edx
186         xorl    %eax,%eax
187         xorl    %ebx,%ebx
188         cmpl    $128,%ecx
189         jbe     .L006ecb_short
190         testl   $32,(%edx)
191         jnz     .L007ecb_aligned
192         testl   $15,%edi
193         setz    %al
194         testl   $15,%esi
195         setz    %bl
196         testl   %ebx,%eax
197         jnz     .L007ecb_aligned
198         negl    %eax
199         movl    $512,%ebx
200         notl    %eax
201         leal    -24(%esp),%ebp
202         cmpl    %ebx,%ecx
203         cmovcl  %ecx,%ebx
204         andl    %ebx,%eax
205         movl    %ecx,%ebx
206         negl    %eax
207         andl    $511,%ebx
208         leal    (%eax,%ebp,1),%esp
209         andl    $-16,%esp
210         jmp     .L008ecb_loop
211 .align  16
212 .L008ecb_loop:
213         movl    %edi,(%ebp)
214         movl    %esi,4(%ebp)
215         movl    %ecx,8(%ebp)
216         movl    %ebx,%ecx
217         movl    %ebx,12(%ebp)
218         testl   $15,%edi
219         cmovnzl %esp,%edi
220         testl   $15,%esi
221         jz      .L009ecb_inp_aligned
222         shrl    $2,%ecx
223 .byte   243,165
224         subl    %ebx,%edi
225         movl    %ebx,%ecx
226         movl    %edi,%esi
227 .L009ecb_inp_aligned:
228         leal    -16(%edx),%eax
229         leal    16(%edx),%ebx
230         shrl    $4,%ecx
231 .byte   243,15,167,200
232         movl    (%ebp),%edi
233         movl    12(%ebp),%ebx
234         testl   $15,%edi
235         jz      .L010ecb_out_aligned
236         movl    %ebx,%ecx
237         shrl    $2,%ecx
238         leal    (%esp),%esi
239 .byte   243,165
240         subl    %ebx,%edi
241 .L010ecb_out_aligned:
242         movl    4(%ebp),%esi
243         movl    8(%ebp),%ecx
244         addl    %ebx,%edi
245         addl    %ebx,%esi
246         subl    %ebx,%ecx
247         movl    $512,%ebx
248         jnz     .L008ecb_loop
249         cmpl    %ebp,%esp
250         je      .L011ecb_done
251         pxor    %xmm0,%xmm0
252         leal    (%esp),%eax
253 .L012ecb_bzero:
254         movaps  %xmm0,(%eax)
255         leal    16(%eax),%eax
256         cmpl    %eax,%ebp
257         ja      .L012ecb_bzero
258 .L011ecb_done:
259         leal    24(%ebp),%esp
260         jmp     .L013ecb_exit
261 .align  16
262 .L006ecb_short:
263         xorl    %eax,%eax
264         leal    -24(%esp),%ebp
265         subl    %ecx,%eax
266         leal    (%eax,%ebp,1),%esp
267         andl    $-16,%esp
268         xorl    %ebx,%ebx
269 .L014ecb_short_copy:
270         movups  (%esi,%ebx,1),%xmm0
271         leal    16(%ebx),%ebx
272         cmpl    %ebx,%ecx
273         movaps  %xmm0,-16(%esp,%ebx,1)
274         ja      .L014ecb_short_copy
275         movl    %esp,%esi
276         movl    %ecx,%ebx
277         jmp     .L008ecb_loop
278 .align  16
279 .L007ecb_aligned:
280         leal    -16(%edx),%eax
281         leal    16(%edx),%ebx
282         shrl    $4,%ecx
283 .byte   243,15,167,200
284 .L013ecb_exit:
285         movl    $1,%eax
286         leal    4(%esp),%esp
287 .L004ecb_abort:
288         popl    %edi
289         popl    %esi
290         popl    %ebx
291         popl    %ebp
292         ret
293 .size   padlock_ecb_encrypt,.-.L_padlock_ecb_encrypt_begin
294 .globl  padlock_cbc_encrypt
295 .type   padlock_cbc_encrypt,@function
296 .align  16
297 padlock_cbc_encrypt:
298 .L_padlock_cbc_encrypt_begin:
299         pushl   %ebp
300         pushl   %ebx
301         pushl   %esi
302         pushl   %edi
303         movl    20(%esp),%edi
304         movl    24(%esp),%esi
305         movl    28(%esp),%edx
306         movl    32(%esp),%ecx
307         testl   $15,%edx
308         jnz     .L015cbc_abort
309         testl   $15,%ecx
310         jnz     .L015cbc_abort
311         leal    .Lpadlock_saved_context-.L016cbc_pic_point,%eax
312         pushfl
313         cld
314         call    _padlock_verify_ctx
315 .L016cbc_pic_point:
316         leal    16(%edx),%edx
317         xorl    %eax,%eax
318         xorl    %ebx,%ebx
319         cmpl    $64,%ecx
320         jbe     .L017cbc_short
321         testl   $32,(%edx)
322         jnz     .L018cbc_aligned
323         testl   $15,%edi
324         setz    %al
325         testl   $15,%esi
326         setz    %bl
327         testl   %ebx,%eax
328         jnz     .L018cbc_aligned
329         negl    %eax
330         movl    $512,%ebx
331         notl    %eax
332         leal    -24(%esp),%ebp
333         cmpl    %ebx,%ecx
334         cmovcl  %ecx,%ebx
335         andl    %ebx,%eax
336         movl    %ecx,%ebx
337         negl    %eax
338         andl    $511,%ebx
339         leal    (%eax,%ebp,1),%esp
340         andl    $-16,%esp
341         jmp     .L019cbc_loop
342 .align  16
343 .L019cbc_loop:
344         movl    %edi,(%ebp)
345         movl    %esi,4(%ebp)
346         movl    %ecx,8(%ebp)
347         movl    %ebx,%ecx
348         movl    %ebx,12(%ebp)
349         testl   $15,%edi
350         cmovnzl %esp,%edi
351         testl   $15,%esi
352         jz      .L020cbc_inp_aligned
353         shrl    $2,%ecx
354 .byte   243,165
355         subl    %ebx,%edi
356         movl    %ebx,%ecx
357         movl    %edi,%esi
358 .L020cbc_inp_aligned:
359         leal    -16(%edx),%eax
360         leal    16(%edx),%ebx
361         shrl    $4,%ecx
362 .byte   243,15,167,208
363         movaps  (%eax),%xmm0
364         movaps  %xmm0,-16(%edx)
365         movl    (%ebp),%edi
366         movl    12(%ebp),%ebx
367         testl   $15,%edi
368         jz      .L021cbc_out_aligned
369         movl    %ebx,%ecx
370         shrl    $2,%ecx
371         leal    (%esp),%esi
372 .byte   243,165
373         subl    %ebx,%edi
374 .L021cbc_out_aligned:
375         movl    4(%ebp),%esi
376         movl    8(%ebp),%ecx
377         addl    %ebx,%edi
378         addl    %ebx,%esi
379         subl    %ebx,%ecx
380         movl    $512,%ebx
381         jnz     .L019cbc_loop
382         cmpl    %ebp,%esp
383         je      .L022cbc_done
384         pxor    %xmm0,%xmm0
385         leal    (%esp),%eax
386 .L023cbc_bzero:
387         movaps  %xmm0,(%eax)
388         leal    16(%eax),%eax
389         cmpl    %eax,%ebp
390         ja      .L023cbc_bzero
391 .L022cbc_done:
392         leal    24(%ebp),%esp
393         jmp     .L024cbc_exit
394 .align  16
395 .L017cbc_short:
396         xorl    %eax,%eax
397         leal    -24(%esp),%ebp
398         subl    %ecx,%eax
399         leal    (%eax,%ebp,1),%esp
400         andl    $-16,%esp
401         xorl    %ebx,%ebx
402 .L025cbc_short_copy:
403         movups  (%esi,%ebx,1),%xmm0
404         leal    16(%ebx),%ebx
405         cmpl    %ebx,%ecx
406         movaps  %xmm0,-16(%esp,%ebx,1)
407         ja      .L025cbc_short_copy
408         movl    %esp,%esi
409         movl    %ecx,%ebx
410         jmp     .L019cbc_loop
411 .align  16
412 .L018cbc_aligned:
413         leal    -16(%edx),%eax
414         leal    16(%edx),%ebx
415         shrl    $4,%ecx
416 .byte   243,15,167,208
417         movaps  (%eax),%xmm0
418         movaps  %xmm0,-16(%edx)
419 .L024cbc_exit:
420         movl    $1,%eax
421         leal    4(%esp),%esp
422 .L015cbc_abort:
423         popl    %edi
424         popl    %esi
425         popl    %ebx
426         popl    %ebp
427         ret
428 .size   padlock_cbc_encrypt,.-.L_padlock_cbc_encrypt_begin
429 .globl  padlock_xstore
430 .type   padlock_xstore,@function
431 .align  16
432 padlock_xstore:
433 .L_padlock_xstore_begin:
434         pushl   %edi
435         movl    8(%esp),%edi
436         movl    12(%esp),%edx
437 .byte   15,167,192
438         popl    %edi
439         ret
440 .size   padlock_xstore,.-.L_padlock_xstore_begin
441 .type   _win32_segv_handler,@function
442 .align  16
443 _win32_segv_handler:
444         movl    $1,%eax
445         movl    4(%esp),%edx
446         movl    12(%esp),%ecx
447         cmpl    $3221225477,(%edx)
448         jne     .L026ret
449         addl    $4,184(%ecx)
450         movl    $0,%eax
451 .L026ret:
452         ret
453 .size   _win32_segv_handler,.-_win32_segv_handler
454 .globl  padlock_sha1_oneshot
455 .type   padlock_sha1_oneshot,@function
456 .align  16
457 padlock_sha1_oneshot:
458 .L_padlock_sha1_oneshot_begin:
459         pushl   %edi
460         pushl   %esi
461         xorl    %eax,%eax
462         movl    12(%esp),%edi
463         movl    16(%esp),%esi
464         movl    20(%esp),%ecx
465         movl    %esp,%edx
466         addl    $-128,%esp
467         movups  (%edi),%xmm0
468         andl    $-16,%esp
469         movl    16(%edi),%eax
470         movaps  %xmm0,(%esp)
471         movl    %esp,%edi
472         movl    %eax,16(%esp)
473         xorl    %eax,%eax
474 .byte   243,15,166,200
475         movaps  (%esp),%xmm0
476         movl    16(%esp),%eax
477         movl    %edx,%esp
478         movl    12(%esp),%edi
479         movups  %xmm0,(%edi)
480         movl    %eax,16(%edi)
481         popl    %esi
482         popl    %edi
483         ret
484 .size   padlock_sha1_oneshot,.-.L_padlock_sha1_oneshot_begin
485 .globl  padlock_sha1_blocks
486 .type   padlock_sha1_blocks,@function
487 .align  16
488 padlock_sha1_blocks:
489 .L_padlock_sha1_blocks_begin:
490         pushl   %edi
491         pushl   %esi
492         movl    12(%esp),%edi
493         movl    16(%esp),%esi
494         movl    %esp,%edx
495         movl    20(%esp),%ecx
496         addl    $-128,%esp
497         movups  (%edi),%xmm0
498         andl    $-16,%esp
499         movl    16(%edi),%eax
500         movaps  %xmm0,(%esp)
501         movl    %esp,%edi
502         movl    %eax,16(%esp)
503         movl    $-1,%eax
504 .byte   243,15,166,200
505         movaps  (%esp),%xmm0
506         movl    16(%esp),%eax
507         movl    %edx,%esp
508         movl    12(%esp),%edi
509         movups  %xmm0,(%edi)
510         movl    %eax,16(%edi)
511         popl    %esi
512         popl    %edi
513         ret
514 .size   padlock_sha1_blocks,.-.L_padlock_sha1_blocks_begin
515 .globl  padlock_sha256_oneshot
516 .type   padlock_sha256_oneshot,@function
517 .align  16
518 padlock_sha256_oneshot:
519 .L_padlock_sha256_oneshot_begin:
520         pushl   %edi
521         pushl   %esi
522         xorl    %eax,%eax
523         movl    12(%esp),%edi
524         movl    16(%esp),%esi
525         movl    20(%esp),%ecx
526         movl    %esp,%edx
527         addl    $-128,%esp
528         movups  (%edi),%xmm0
529         andl    $-16,%esp
530         movups  16(%edi),%xmm1
531         movaps  %xmm0,(%esp)
532         movl    %esp,%edi
533         movaps  %xmm1,16(%esp)
534         xorl    %eax,%eax
535 .byte   243,15,166,208
536         movaps  (%esp),%xmm0
537         movaps  16(%esp),%xmm1
538         movl    %edx,%esp
539         movl    12(%esp),%edi
540         movups  %xmm0,(%edi)
541         movups  %xmm1,16(%edi)
542         popl    %esi
543         popl    %edi
544         ret
545 .size   padlock_sha256_oneshot,.-.L_padlock_sha256_oneshot_begin
546 .globl  padlock_sha256_blocks
547 .type   padlock_sha256_blocks,@function
548 .align  16
549 padlock_sha256_blocks:
550 .L_padlock_sha256_blocks_begin:
551         pushl   %edi
552         pushl   %esi
553         movl    12(%esp),%edi
554         movl    16(%esp),%esi
555         movl    20(%esp),%ecx
556         movl    %esp,%edx
557         addl    $-128,%esp
558         movups  (%edi),%xmm0
559         andl    $-16,%esp
560         movups  16(%edi),%xmm1
561         movaps  %xmm0,(%esp)
562         movl    %esp,%edi
563         movaps  %xmm1,16(%esp)
564         movl    $-1,%eax
565 .byte   243,15,166,208
566         movaps  (%esp),%xmm0
567         movaps  16(%esp),%xmm1
568         movl    %edx,%esp
569         movl    12(%esp),%edi
570         movups  %xmm0,(%edi)
571         movups  %xmm1,16(%edi)
572         popl    %esi
573         popl    %edi
574         ret
575 .size   padlock_sha256_blocks,.-.L_padlock_sha256_blocks_begin
576 .globl  padlock_sha512_blocks
577 .type   padlock_sha512_blocks,@function
578 .align  16
579 padlock_sha512_blocks:
580 .L_padlock_sha512_blocks_begin:
581         pushl   %edi
582         pushl   %esi
583         movl    12(%esp),%edi
584         movl    16(%esp),%esi
585         movl    20(%esp),%ecx
586         movl    %esp,%edx
587         addl    $-128,%esp
588         movups  (%edi),%xmm0
589         andl    $-16,%esp
590         movups  16(%edi),%xmm1
591         movups  32(%edi),%xmm2
592         movups  48(%edi),%xmm3
593         movaps  %xmm0,(%esp)
594         movl    %esp,%edi
595         movaps  %xmm1,16(%esp)
596         movaps  %xmm2,32(%esp)
597         movaps  %xmm3,48(%esp)
598 .byte   243,15,166,224
599         movaps  (%esp),%xmm0
600         movaps  16(%esp),%xmm1
601         movaps  32(%esp),%xmm2
602         movaps  48(%esp),%xmm3
603         movl    %edx,%esp
604         movl    12(%esp),%edi
605         movups  %xmm0,(%edi)
606         movups  %xmm1,16(%edi)
607         movups  %xmm2,32(%edi)
608         movups  %xmm3,48(%edi)
609         popl    %esi
610         popl    %edi
611         ret
612 .size   padlock_sha512_blocks,.-.L_padlock_sha512_blocks_begin
613 .byte   86,73,65,32,80,97,100,108,111,99,107,32,120,56,54,32
614 .byte   109,111,100,117,108,101,44,32,67,82,89,80,84,79,71,65
615 .byte   77,83,32,98,121,32,60,97,112,112,114,111,64,111,112,101
616 .byte   110,115,115,108,46,111,114,103,62,0
617 .align  16
618 .data
619 .align  4
620 .Lpadlock_saved_context:
621 .long   0
622
623 .section .note.GNU-stack,"",%progbits