cmll-x86_64.pl: fix bug in cbc tail processing and comply with Win64 ABI spec.
[openssl.git] / crypto / camellia / asm / cmll-x86_64.pl
index 7d76c82..c683646 100644 (file)
@@ -650,7 +650,7 @@ Camellia_cbc_encrypt:
        neg     %r10
        and     \$0x3C0,%r10
        sub     %r10,%rsp
-       add     \$8,%rsp                # 8 is reserved for callee's ra
+       #add    \$8,%rsp                # 8 is reserved for callee's ra
 
        mov     %rdi,$inp               # inp argument
        mov     %rsi,$out               # out argument
@@ -742,12 +742,14 @@ Camellia_cbc_encrypt:
        mov     %rax,8+$ivec
        mov     %rax,$_res
 
+.Lcbc_enc_pushf:
        pushfq
        cld
        mov     $inp,%rsi
-       lea     $ivec,%rdi
+       lea     8+$ivec,%rdi
        .long   0x9066A4F3              # rep movsb
        popfq
+.Lcbc_enc_popf:
 
        lea     $ivec,$inp
        lea     16+$ivec,%rax
@@ -830,12 +832,14 @@ Camellia_cbc_encrypt:
        mov     @S[2],8+$ivec
        mov     @S[3],12+$ivec
 
+.Lcbc_dec_pushf:
        pushfq
        cld
-       lea     $ivec,%rsi
+       lea     8+$ivec,%rsi
        lea     ($out),%rdi
        .long   0x9066A4F3              # rep movsb
        popfq
+.Lcbc_dec_popf:
 
        mov     %rax,(%rdx)             # write out IV residue
        mov     %rbx,8(%rdx)
@@ -876,11 +880,12 @@ common_se_handler:
        push    %rdi
        push    %rbx
        push    %rbp
+       push    %r12
        push    %r13
        push    %r14
        push    %r15
        pushfq
-       lea     -72(%rsp),%rsp
+       lea     -64(%rsp),%rsp
 
        mov     120($context),%rax      # pull context->Rax
        mov     248($context),%rbx      # pull context->Rip
@@ -919,36 +924,7 @@ common_se_handler:
        mov     %rsi,168($context)      # restore context->Rsi
        mov     %rdi,176($context)      # restore context->Rdi
 
-       mov     40($disp),%rdi          # disp->ContextRecord
-       mov     $context,%rsi
-       mov     \$`1232/8`,%ecx
-       .long   0xa548f3fc              # cld; rep movsq
-
-       mov     $disp,%rsi
-       xor     %rcx,%rcx               # arg1, UNW_FLAG_NHANDLER
-       mov     8(%rsi),%rdx            # arg2, disp->ImageBase
-       mov     0(%rsi),%r8             # arg3, disp->ControlPc
-       mov     16(%rsi),%r9            # arg4, disp->FunctionEntry
-       mov     40(%rsi),%r10           # disp->ContextRecord
-       lea     56(%rsi),%r11           # &disp->HandlerData
-       lea     24(%rsi),%r12           # &disp->EstablisherFrame
-       mov     %r10,32(%rsp)           # arg5
-       mov     %r11,40(%rsp)           # arg6
-       mov     %r12,48(%rsp)           # arg7
-       mov     %rcx,56(%rsp)           # arg8, (NULL)
-       call    *__imp_RtlVirtualUnwind(%rip)
-
-       mov     \$1,%eax                # ExceptionContinueSearch
-       lea     72(%rsp),%rsp
-       popfq
-       pop     %r15
-       pop     %r14
-       pop     %r13
-       pop     %rbp
-       pop     %rbx
-       pop     %rdi
-       pop     %rsi
-       ret
+       jmp     .Lcommon_seh_exit
 .size  common_se_handler,.-common_se_handler
 
 .type  cbc_se_handler,\@abi-omnipotent
@@ -982,6 +958,25 @@ cbc_se_handler:
        cmp     %r10,%rbx               # context->Rip>=.Lcbc_abort
        jae     .Lin_cbc_prologue
 
+       # handle pushf/popf in Camellia_cbc_encrypt
+       lea     .Lcbc_enc_pushf(%rip),%r10
+       cmp     %r10,%rbx               # context->Rip<=.Lcbc_enc_pushf
+       jbe     .Lin_cbc_no_flag
+       lea     8(%rax),%rax
+       lea     .Lcbc_enc_popf(%rip),%r10
+       cmp     %r10,%rbx               # context->Rip<.Lcbc_enc_popf
+       jb      .Lin_cbc_no_flag
+       lea     -8(%rax),%rax
+       lea     .Lcbc_dec_pushf(%rip),%r10
+       cmp     %r10,%rbx               # context->Rip<=.Lcbc_dec_pushf
+       jbe     .Lin_cbc_no_flag
+       lea     8(%rax),%rax
+       lea     .Lcbc_dec_popf(%rip),%r10
+       cmp     %r10,%rbx               # context->Rip<.Lcbc_dec_popf
+       jb      .Lin_cbc_no_flag
+       lea     -8(%rax),%rax
+
+.Lin_cbc_no_flag:
        mov     48(%rax),%rax           # $_rsp
        lea     48(%rax),%rax
 
@@ -1006,6 +1001,9 @@ cbc_se_handler:
        mov     %rsi,168($context)      # restore context->Rsi
        mov     %rdi,176($context)      # restore context->Rdi
 
+.align 4
+.Lcommon_seh_exit:
+
        mov     40($disp),%rdi          # disp->ContextRecord
        mov     $context,%rsi           # context
        mov     \$`1232/8`,%ecx         # sizeof(CONTEXT)