Added COFF versions of assembly files.
[gnutls:gnutls.git] / lib / accelerated / x86 / coff / padlock-x86-coff.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   "./engines/asm/e_padlock-x86.s"
39 .text
40 .globl  _padlock_capability
41 .def    _padlock_capability;    .scl    2;      .type   32;     .endef
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 .globl  _padlock_key_bswap
91 .def    _padlock_key_bswap;     .scl    2;      .type   32;     .endef
92 .align  16
93 _padlock_key_bswap:
94 .L_padlock_key_bswap_begin:
95         movl    4(%esp),%edx
96         movl    240(%edx),%ecx
97 .L001bswap_loop:
98         movl    (%edx),%eax
99         bswap   %eax
100         movl    %eax,(%edx)
101         leal    4(%edx),%edx
102         subl    $1,%ecx
103         jnz     .L001bswap_loop
104         ret
105 .globl  _padlock_verify_context
106 .def    _padlock_verify_context;        .scl    2;      .type   32;     .endef
107 .align  16
108 _padlock_verify_context:
109 .L_padlock_verify_context_begin:
110         movl    4(%esp),%edx
111         leal    .Lpadlock_saved_context,%eax
112         pushfl
113         call    __padlock_verify_ctx
114 .L002verify_pic_point:
115         leal    4(%esp),%esp
116         ret
117 .def    __padlock_verify_ctx;   .scl    3;      .type   32;     .endef
118 .align  16
119 __padlock_verify_ctx:
120         btl     $30,4(%esp)
121         jnc     .L003verified
122         cmpl    (%eax),%edx
123         je      .L003verified
124         pushfl
125         popfl
126 .L003verified:
127         movl    %edx,(%eax)
128         ret
129 .globl  _padlock_reload_key
130 .def    _padlock_reload_key;    .scl    2;      .type   32;     .endef
131 .align  16
132 _padlock_reload_key:
133 .L_padlock_reload_key_begin:
134         pushfl
135         popfl
136         ret
137 .globl  _padlock_aes_block
138 .def    _padlock_aes_block;     .scl    2;      .type   32;     .endef
139 .align  16
140 _padlock_aes_block:
141 .L_padlock_aes_block_begin:
142         pushl   %edi
143         pushl   %esi
144         pushl   %ebx
145         movl    16(%esp),%edi
146         movl    20(%esp),%esi
147         movl    24(%esp),%edx
148         movl    $1,%ecx
149         leal    32(%edx),%ebx
150         leal    16(%edx),%edx
151 .byte   243,15,167,200
152         popl    %ebx
153         popl    %esi
154         popl    %edi
155         ret
156 .globl  _padlock_ecb_encrypt
157 .def    _padlock_ecb_encrypt;   .scl    2;      .type   32;     .endef
158 .align  16
159 _padlock_ecb_encrypt:
160 .L_padlock_ecb_encrypt_begin:
161         pushl   %ebp
162         pushl   %ebx
163         pushl   %esi
164         pushl   %edi
165         movl    20(%esp),%edi
166         movl    24(%esp),%esi
167         movl    28(%esp),%edx
168         movl    32(%esp),%ecx
169         testl   $15,%edx
170         jnz     .L004ecb_abort
171         testl   $15,%ecx
172         jnz     .L004ecb_abort
173         leal    .Lpadlock_saved_context,%eax
174         pushfl
175         cld
176         call    __padlock_verify_ctx
177 .L005ecb_pic_point:
178         leal    16(%edx),%edx
179         xorl    %eax,%eax
180         xorl    %ebx,%ebx
181         cmpl    $128,%ecx
182         jbe     .L006ecb_short
183         testl   $32,(%edx)
184         jnz     .L007ecb_aligned
185         testl   $15,%edi
186         setz    %al
187         testl   $15,%esi
188         setz    %bl
189         testl   %ebx,%eax
190         jnz     .L007ecb_aligned
191         negl    %eax
192         movl    $512,%ebx
193         notl    %eax
194         leal    -24(%esp),%ebp
195         cmpl    %ebx,%ecx
196         cmovcl  %ecx,%ebx
197         andl    %ebx,%eax
198         movl    %ecx,%ebx
199         negl    %eax
200         andl    $511,%ebx
201         leal    (%eax,%ebp,1),%esp
202         andl    $-16,%esp
203         jmp     .L008ecb_loop
204 .align  16
205 .L008ecb_loop:
206         movl    %edi,(%ebp)
207         movl    %esi,4(%ebp)
208         movl    %ecx,8(%ebp)
209         movl    %ebx,%ecx
210         movl    %ebx,12(%ebp)
211         testl   $15,%edi
212         cmovnzl %esp,%edi
213         testl   $15,%esi
214         jz      .L009ecb_inp_aligned
215         shrl    $2,%ecx
216 .byte   243,165
217         subl    %ebx,%edi
218         movl    %ebx,%ecx
219         movl    %edi,%esi
220 .L009ecb_inp_aligned:
221         leal    -16(%edx),%eax
222         leal    16(%edx),%ebx
223         shrl    $4,%ecx
224 .byte   243,15,167,200
225         movl    (%ebp),%edi
226         movl    12(%ebp),%ebx
227         testl   $15,%edi
228         jz      .L010ecb_out_aligned
229         movl    %ebx,%ecx
230         shrl    $2,%ecx
231         leal    (%esp),%esi
232 .byte   243,165
233         subl    %ebx,%edi
234 .L010ecb_out_aligned:
235         movl    4(%ebp),%esi
236         movl    8(%ebp),%ecx
237         addl    %ebx,%edi
238         addl    %ebx,%esi
239         subl    %ebx,%ecx
240         movl    $512,%ebx
241         jnz     .L008ecb_loop
242         cmpl    %ebp,%esp
243         je      .L011ecb_done
244         pxor    %xmm0,%xmm0
245         leal    (%esp),%eax
246 .L012ecb_bzero:
247         movaps  %xmm0,(%eax)
248         leal    16(%eax),%eax
249         cmpl    %eax,%ebp
250         ja      .L012ecb_bzero
251 .L011ecb_done:
252         leal    24(%ebp),%esp
253         jmp     .L013ecb_exit
254 .align  16
255 .L006ecb_short:
256         xorl    %eax,%eax
257         leal    -24(%esp),%ebp
258         subl    %ecx,%eax
259         leal    (%eax,%ebp,1),%esp
260         andl    $-16,%esp
261         xorl    %ebx,%ebx
262 .L014ecb_short_copy:
263         movups  (%esi,%ebx,1),%xmm0
264         leal    16(%ebx),%ebx
265         cmpl    %ebx,%ecx
266         movaps  %xmm0,-16(%esp,%ebx,1)
267         ja      .L014ecb_short_copy
268         movl    %esp,%esi
269         movl    %ecx,%ebx
270         jmp     .L008ecb_loop
271 .align  16
272 .L007ecb_aligned:
273         leal    -16(%edx),%eax
274         leal    16(%edx),%ebx
275         shrl    $4,%ecx
276 .byte   243,15,167,200
277 .L013ecb_exit:
278         movl    $1,%eax
279         leal    4(%esp),%esp
280 .L004ecb_abort:
281         popl    %edi
282         popl    %esi
283         popl    %ebx
284         popl    %ebp
285         ret
286 .globl  _padlock_cbc_encrypt
287 .def    _padlock_cbc_encrypt;   .scl    2;      .type   32;     .endef
288 .align  16
289 _padlock_cbc_encrypt:
290 .L_padlock_cbc_encrypt_begin:
291         pushl   %ebp
292         pushl   %ebx
293         pushl   %esi
294         pushl   %edi
295         movl    20(%esp),%edi
296         movl    24(%esp),%esi
297         movl    28(%esp),%edx
298         movl    32(%esp),%ecx
299         testl   $15,%edx
300         jnz     .L015cbc_abort
301         testl   $15,%ecx
302         jnz     .L015cbc_abort
303         leal    .Lpadlock_saved_context,%eax
304         pushfl
305         cld
306         call    __padlock_verify_ctx
307 .L016cbc_pic_point:
308         leal    16(%edx),%edx
309         xorl    %eax,%eax
310         xorl    %ebx,%ebx
311         cmpl    $64,%ecx
312         jbe     .L017cbc_short
313         testl   $32,(%edx)
314         jnz     .L018cbc_aligned
315         testl   $15,%edi
316         setz    %al
317         testl   $15,%esi
318         setz    %bl
319         testl   %ebx,%eax
320         jnz     .L018cbc_aligned
321         negl    %eax
322         movl    $512,%ebx
323         notl    %eax
324         leal    -24(%esp),%ebp
325         cmpl    %ebx,%ecx
326         cmovcl  %ecx,%ebx
327         andl    %ebx,%eax
328         movl    %ecx,%ebx
329         negl    %eax
330         andl    $511,%ebx
331         leal    (%eax,%ebp,1),%esp
332         andl    $-16,%esp
333         jmp     .L019cbc_loop
334 .align  16
335 .L019cbc_loop:
336         movl    %edi,(%ebp)
337         movl    %esi,4(%ebp)
338         movl    %ecx,8(%ebp)
339         movl    %ebx,%ecx
340         movl    %ebx,12(%ebp)
341         testl   $15,%edi
342         cmovnzl %esp,%edi
343         testl   $15,%esi
344         jz      .L020cbc_inp_aligned
345         shrl    $2,%ecx
346 .byte   243,165
347         subl    %ebx,%edi
348         movl    %ebx,%ecx
349         movl    %edi,%esi
350 .L020cbc_inp_aligned:
351         leal    -16(%edx),%eax
352         leal    16(%edx),%ebx
353         shrl    $4,%ecx
354 .byte   243,15,167,208
355         movaps  (%eax),%xmm0
356         movaps  %xmm0,-16(%edx)
357         movl    (%ebp),%edi
358         movl    12(%ebp),%ebx
359         testl   $15,%edi
360         jz      .L021cbc_out_aligned
361         movl    %ebx,%ecx
362         shrl    $2,%ecx
363         leal    (%esp),%esi
364 .byte   243,165
365         subl    %ebx,%edi
366 .L021cbc_out_aligned:
367         movl    4(%ebp),%esi
368         movl    8(%ebp),%ecx
369         addl    %ebx,%edi
370         addl    %ebx,%esi
371         subl    %ebx,%ecx
372         movl    $512,%ebx
373         jnz     .L019cbc_loop
374         cmpl    %ebp,%esp
375         je      .L022cbc_done
376         pxor    %xmm0,%xmm0
377         leal    (%esp),%eax
378 .L023cbc_bzero:
379         movaps  %xmm0,(%eax)
380         leal    16(%eax),%eax
381         cmpl    %eax,%ebp
382         ja      .L023cbc_bzero
383 .L022cbc_done:
384         leal    24(%ebp),%esp
385         jmp     .L024cbc_exit
386 .align  16
387 .L017cbc_short:
388         xorl    %eax,%eax
389         leal    -24(%esp),%ebp
390         subl    %ecx,%eax
391         leal    (%eax,%ebp,1),%esp
392         andl    $-16,%esp
393         xorl    %ebx,%ebx
394 .L025cbc_short_copy:
395         movups  (%esi,%ebx,1),%xmm0
396         leal    16(%ebx),%ebx
397         cmpl    %ebx,%ecx
398         movaps  %xmm0,-16(%esp,%ebx,1)
399         ja      .L025cbc_short_copy
400         movl    %esp,%esi
401         movl    %ecx,%ebx
402         jmp     .L019cbc_loop
403 .align  16
404 .L018cbc_aligned:
405         leal    -16(%edx),%eax
406         leal    16(%edx),%ebx
407         shrl    $4,%ecx
408 .byte   243,15,167,208
409         movaps  (%eax),%xmm0
410         movaps  %xmm0,-16(%edx)
411 .L024cbc_exit:
412         movl    $1,%eax
413         leal    4(%esp),%esp
414 .L015cbc_abort:
415         popl    %edi
416         popl    %esi
417         popl    %ebx
418         popl    %ebp
419         ret
420 .globl  _padlock_xstore
421 .def    _padlock_xstore;        .scl    2;      .type   32;     .endef
422 .align  16
423 _padlock_xstore:
424 .L_padlock_xstore_begin:
425         pushl   %edi
426         movl    8(%esp),%edi
427         movl    12(%esp),%edx
428 .byte   15,167,192
429         popl    %edi
430         ret
431 .def    __win32_segv_handler;   .scl    3;      .type   32;     .endef
432 .align  16
433 __win32_segv_handler:
434         movl    $1,%eax
435         movl    4(%esp),%edx
436         movl    12(%esp),%ecx
437         cmpl    $3221225477,(%edx)
438         jne     .L026ret
439         addl    $4,184(%ecx)
440         movl    $0,%eax
441 .L026ret:
442         ret
443 .globl  _padlock_sha1_oneshot
444 .def    _padlock_sha1_oneshot;  .scl    2;      .type   32;     .endef
445 .align  16
446 _padlock_sha1_oneshot:
447 .L_padlock_sha1_oneshot_begin:
448         pushl   %edi
449         pushl   %esi
450         xorl    %eax,%eax
451         movl    12(%esp),%edi
452         movl    16(%esp),%esi
453         movl    20(%esp),%ecx
454         pushl   __win32_segv_handler
455 .byte   100,255,48
456 .byte   100,137,32
457         movl    %esp,%edx
458         addl    $-128,%esp
459         movups  (%edi),%xmm0
460         andl    $-16,%esp
461         movl    16(%edi),%eax
462         movaps  %xmm0,(%esp)
463         movl    %esp,%edi
464         movl    %eax,16(%esp)
465         xorl    %eax,%eax
466 .byte   243,15,166,200
467         movaps  (%esp),%xmm0
468         movl    16(%esp),%eax
469         movl    %edx,%esp
470 .byte   100,143,5,0,0,0,0
471         leal    4(%esp),%esp
472         movl    16(%esp),%edi
473         movups  %xmm0,(%edi)
474         movl    %eax,16(%edi)
475         popl    %esi
476         popl    %edi
477         ret
478 .globl  _padlock_sha1_blocks
479 .def    _padlock_sha1_blocks;   .scl    2;      .type   32;     .endef
480 .align  16
481 _padlock_sha1_blocks:
482 .L_padlock_sha1_blocks_begin:
483         pushl   %edi
484         pushl   %esi
485         movl    12(%esp),%edi
486         movl    16(%esp),%esi
487         movl    %esp,%edx
488         movl    20(%esp),%ecx
489         addl    $-128,%esp
490         movups  (%edi),%xmm0
491         andl    $-16,%esp
492         movl    16(%edi),%eax
493         movaps  %xmm0,(%esp)
494         movl    %esp,%edi
495         movl    %eax,16(%esp)
496         movl    $-1,%eax
497 .byte   243,15,166,200
498         movaps  (%esp),%xmm0
499         movl    16(%esp),%eax
500         movl    %edx,%esp
501         movl    12(%esp),%edi
502         movups  %xmm0,(%edi)
503         movl    %eax,16(%edi)
504         popl    %esi
505         popl    %edi
506         ret
507 .globl  _padlock_sha256_oneshot
508 .def    _padlock_sha256_oneshot;        .scl    2;      .type   32;     .endef
509 .align  16
510 _padlock_sha256_oneshot:
511 .L_padlock_sha256_oneshot_begin:
512         pushl   %edi
513         pushl   %esi
514         xorl    %eax,%eax
515         movl    12(%esp),%edi
516         movl    16(%esp),%esi
517         movl    20(%esp),%ecx
518         pushl   __win32_segv_handler
519 .byte   100,255,48
520 .byte   100,137,32
521         movl    %esp,%edx
522         addl    $-128,%esp
523         movups  (%edi),%xmm0
524         andl    $-16,%esp
525         movups  16(%edi),%xmm1
526         movaps  %xmm0,(%esp)
527         movl    %esp,%edi
528         movaps  %xmm1,16(%esp)
529         xorl    %eax,%eax
530 .byte   243,15,166,208
531         movaps  (%esp),%xmm0
532         movaps  16(%esp),%xmm1
533         movl    %edx,%esp
534 .byte   100,143,5,0,0,0,0
535         leal    4(%esp),%esp
536         movl    16(%esp),%edi
537         movups  %xmm0,(%edi)
538         movups  %xmm1,16(%edi)
539         popl    %esi
540         popl    %edi
541         ret
542 .globl  _padlock_sha256_blocks
543 .def    _padlock_sha256_blocks; .scl    2;      .type   32;     .endef
544 .align  16
545 _padlock_sha256_blocks:
546 .L_padlock_sha256_blocks_begin:
547         pushl   %edi
548         pushl   %esi
549         movl    12(%esp),%edi
550         movl    16(%esp),%esi
551         movl    20(%esp),%ecx
552         movl    %esp,%edx
553         addl    $-128,%esp
554         movups  (%edi),%xmm0
555         andl    $-16,%esp
556         movups  16(%edi),%xmm1
557         movaps  %xmm0,(%esp)
558         movl    %esp,%edi
559         movaps  %xmm1,16(%esp)
560         movl    $-1,%eax
561 .byte   243,15,166,208
562         movaps  (%esp),%xmm0
563         movaps  16(%esp),%xmm1
564         movl    %edx,%esp
565         movl    12(%esp),%edi
566         movups  %xmm0,(%edi)
567         movups  %xmm1,16(%edi)
568         popl    %esi
569         popl    %edi
570         ret
571 .globl  _padlock_sha512_blocks
572 .def    _padlock_sha512_blocks; .scl    2;      .type   32;     .endef
573 .align  16
574 _padlock_sha512_blocks:
575 .L_padlock_sha512_blocks_begin:
576         pushl   %edi
577         pushl   %esi
578         movl    12(%esp),%edi
579         movl    16(%esp),%esi
580         movl    20(%esp),%ecx
581         movl    %esp,%edx
582         addl    $-128,%esp
583         movups  (%edi),%xmm0
584         andl    $-16,%esp
585         movups  16(%edi),%xmm1
586         movups  32(%edi),%xmm2
587         movups  48(%edi),%xmm3
588         movaps  %xmm0,(%esp)
589         movl    %esp,%edi
590         movaps  %xmm1,16(%esp)
591         movaps  %xmm2,32(%esp)
592         movaps  %xmm3,48(%esp)
593 .byte   243,15,166,224
594         movaps  (%esp),%xmm0
595         movaps  16(%esp),%xmm1
596         movaps  32(%esp),%xmm2
597         movaps  48(%esp),%xmm3
598         movl    %edx,%esp
599         movl    12(%esp),%edi
600         movups  %xmm0,(%edi)
601         movups  %xmm1,16(%edi)
602         movups  %xmm2,32(%edi)
603         movups  %xmm3,48(%edi)
604         popl    %esi
605         popl    %edi
606         ret
607 .byte   86,73,65,32,80,97,100,108,111,99,107,32,120,56,54,32
608 .byte   109,111,100,117,108,101,44,32,67,82,89,80,84,79,71,65
609 .byte   77,83,32,98,121,32,60,97,112,112,114,111,64,111,112,101
610 .byte   110,115,115,108,46,111,114,103,62,0
611 .align  16
612 .data
613 .align  4
614 .Lpadlock_saved_context:
615 .long   0