Unify all assembler file generators
[openssl.git] / ms / uplink-x86_64.pl
1 #! /usr/bin/env perl
2 # Copyright 2008-2016 The OpenSSL Project Authors. All Rights Reserved.
3 #
4 # Licensed under the Apache License 2.0 (the "License").  You may not use
5 # this file except in compliance with the License.  You can obtain a copy
6 # in the file LICENSE in the source distribution or at
7 # https://www.openssl.org/source/license.html
8
9 # $output is the last argument if it looks like a file (it has an extension)
10 $output = $#ARGV >= 0 && $ARGV[$#ARGV] =~ m|\.\w+$| ? pop : undef;
11
12 $0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1;
13 open OUT,"| \"$^X\" \"${dir}../crypto/perlasm/x86_64-xlate.pl\" \"$output\""
14     or die "can't call ${dir}../crypto/perlasm/x86_64-xlate.pl: $!";
15 *STDOUT=*OUT;
16 push(@INC,"${dir}.");
17
18 require "uplink-common.pl";
19
20 $prefix="_lazy";
21
22 print <<___;
23 .text
24 .extern OPENSSL_Uplink
25 .globl  OPENSSL_UplinkTable
26 ___
27 for ($i=1;$i<=$N;$i++) {
28 print <<___;
29 .type   $prefix${i},\@abi-omnipotent
30 .align  16
31 $prefix${i}:
32         .byte   0x48,0x83,0xEC,0x28     # sub rsp,40
33         mov     %rcx,48(%rsp)
34         mov     %rdx,56(%rsp)
35         mov     %r8,64(%rsp)
36         mov     %r9,72(%rsp)
37         lea     OPENSSL_UplinkTable(%rip),%rcx
38         mov     \$$i,%rdx
39         call    OPENSSL_Uplink
40         mov     48(%rsp),%rcx
41         mov     56(%rsp),%rdx
42         mov     64(%rsp),%r8
43         mov     72(%rsp),%r9
44         lea     OPENSSL_UplinkTable(%rip),%rax
45         add     \$40,%rsp
46         jmp     *8*$i(%rax)
47 $prefix${i}_end:
48 .size   $prefix${i},.-$prefix${i}
49 ___
50 }
51 print <<___;
52 .data
53 OPENSSL_UplinkTable:
54         .quad   $N
55 ___
56 for ($i=1;$i<=$N;$i++) {   print "      .quad   $prefix$i\n";   }
57 print <<___;
58 .section        .pdata,"r"
59 .align          4
60 ___
61 for ($i=1;$i<=$N;$i++) {
62 print <<___;
63         .rva    $prefix${i},$prefix${i}_end,${prefix}_unwind_info
64 ___
65 }
66 print <<___;
67 .section        .xdata,"r"
68 .align          8
69 ${prefix}_unwind_info:
70         .byte   0x01,0x04,0x01,0x00
71         .byte   0x04,0x42,0x00,0x00
72 ___
73
74 close STDOUT;