xref: /openssl/ms/uplink-x86_64.pl (revision 1aa89a7a)
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;
13open 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;
16push(@INC,"${dir}.");
17
18require "uplink-common.pl";
19
20$prefix="_lazy";
21
22print <<___;
23.text
24.extern	OPENSSL_Uplink
25.globl	OPENSSL_UplinkTable
26___
27for ($i=1;$i<=$N;$i++) {
28print <<___;
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}
51print <<___;
52.data
53OPENSSL_UplinkTable:
54        .quad   $N
55___
56for ($i=1;$i<=$N;$i++) {   print "      .quad   $prefix$i\n";   }
57print <<___;
58.section	.pdata,"r"
59.align		4
60___
61for ($i=1;$i<=$N;$i++) {
62print <<___;
63	.rva	$prefix${i},$prefix${i}_end,${prefix}_unwind_info
64___
65}
66print <<___;
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
74close STDOUT;
75