1#! /usr/bin/env perl
2# Copyright 2008-2016 The OpenSSL Project Authors. All Rights Reserved.
3#
4# Licensed under the OpenSSL license (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=pop;
10$0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1;
11open OUT,"| \"$^X\" \"${dir}../crypto/perlasm/x86_64-xlate.pl\" \"$output\"";
12*STDOUT=*OUT;
13push(@INC,"${dir}.");
14
15require "uplink-common.pl";
16
17$prefix="_lazy";
18
19print <<___;
20.text
21.extern	OPENSSL_Uplink
22.globl	OPENSSL_UplinkTable
23___
24for ($i=1;$i<=$N;$i++) {
25print <<___;
26.type	$prefix${i},\@abi-omnipotent
27.align	16
28$prefix${i}:
29	.byte	0x48,0x83,0xEC,0x28	# sub rsp,40
30	mov	%rcx,48(%rsp)
31	mov	%rdx,56(%rsp)
32	mov	%r8,64(%rsp)
33	mov	%r9,72(%rsp)
34	lea	OPENSSL_UplinkTable(%rip),%rcx
35	mov	\$$i,%rdx
36	call	OPENSSL_Uplink
37	mov	48(%rsp),%rcx
38	mov	56(%rsp),%rdx
39	mov	64(%rsp),%r8
40	mov	72(%rsp),%r9
41	lea	OPENSSL_UplinkTable(%rip),%rax
42	add	\$40,%rsp
43	jmp	*8*$i(%rax)
44$prefix${i}_end:
45.size	$prefix${i},.-$prefix${i}
46___
47}
48print <<___;
49.data
50OPENSSL_UplinkTable:
51        .quad   $N
52___
53for ($i=1;$i<=$N;$i++) {   print "      .quad   $prefix$i\n";   }
54print <<___;
55.section	.pdata,"r"
56.align		4
57___
58for ($i=1;$i<=$N;$i++) {
59print <<___;
60	.rva	$prefix${i},$prefix${i}_end,${prefix}_unwind_info
61___
62}
63print <<___;
64.section	.xdata,"r"
65.align		8
66${prefix}_unwind_info:
67	.byte	0x01,0x04,0x01,0x00
68	.byte	0x04,0x42,0x00,0x00
69___
70
71close STDOUT;
72