From 4c048211f19d587133d4d688f5b1045a0bd4cb15 Mon Sep 17 00:00:00 2001 From: Andy Polyakov Date: Tue, 22 Jul 2008 08:47:35 +0000 Subject: [PATCH] Split ms/uplink.pl to corresponding platform versions. --- ms/uplink-common.pl | 22 ++++++++++++++++ ms/uplink-ia64.pl | 50 ++++++++++++++++++++++++++++++++++++ ms/uplink-x86.pl | 33 ++++++++++++++++++++++++ ms/uplink-x86_64.pl | 62 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 167 insertions(+) create mode 100755 ms/uplink-common.pl create mode 100755 ms/uplink-ia64.pl create mode 100755 ms/uplink-x86.pl create mode 100755 ms/uplink-x86_64.pl diff --git a/ms/uplink-common.pl b/ms/uplink-common.pl new file mode 100755 index 0000000000..1d20e6e03e --- /dev/null +++ b/ms/uplink-common.pl @@ -0,0 +1,22 @@ +#!/usr/bin/env perl +# +# pull APPLINK_MAX value from applink.c... +$applink_c=$0; +$applink_c=~s|[^/\\]+$||g; +$applink_c.="applink.c"; +open(INPUT,$applink_c) || die "can't open $applink_c: $!"; +@max=grep {/APPLINK_MAX\s+(\d+)/} ; +close(INPUT); +($#max==0) or die "can't find APPLINK_MAX in $applink_c"; + +$max[0]=~/APPLINK_MAX\s+(\d+)/; +$N=$1; # number of entries in OPENSSL_UplinkTable not including + # OPENSSL_UplinkTable[0], which contains this value... + +1; + +# Idea is to fill the OPENSSL_UplinkTable with pointers to stubs +# which invoke 'void OPENSSL_Uplink (ULONG_PTR *table,int index)'; +# and then dereference themselves. Latter shall result in endless +# loop *unless* OPENSSL_Uplink does not replace 'table[index]' with +# something else, e.g. as 'table[index]=unimplemented;'... diff --git a/ms/uplink-ia64.pl b/ms/uplink-ia64.pl new file mode 100755 index 0000000000..4204c73d58 --- /dev/null +++ b/ms/uplink-ia64.pl @@ -0,0 +1,50 @@ +#!/usr/bin/env perl + +$0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1; +push(@INC,"${dir}."); + +require "uplink-common.pl"; + +local $V=8; # max number of args uplink functions may accept... +my $loc0 = "r".(32+$V); +print <<___; +.text +.global OPENSSL_Uplink# +.type OPENSSL_Uplink#,\@function + +___ +for ($i=1;$i<=$N;$i++) { +print <<___; +.proc lazy$i# +lazy$i: + .prologue +{ .mii; .save ar.pfs,$loc0 + alloc loc0=ar.pfs,$V,3,2,0 + .save b0,loc1 + mov loc1=b0 + addl loc2=\@ltoff(OPENSSL_UplinkTable#),gp };; + .body +{ .mmi; ld8 out0=[loc2] + mov out1=$i };; +{ .mib; add loc2=8*$i,out0 + br.call.sptk.many b0=OPENSSL_Uplink# };; +{ .mmi; ld8 r31=[loc2];; + ld8 r30=[r31],8 };; +{ .mii; ld8 gp=[r31] + mov b6=r30 + mov b0=loc1 };; +{ .mib; mov ar.pfs=loc0 + br.many b6 };; +.endp lazy$i# + +___ +} +print <<___; +.data +.global OPENSSL_UplinkTable# +OPENSSL_UplinkTable: data8 $N // amount of following entries +___ +for ($i=1;$i<=$N;$i++) { print " data8 \@fptr(lazy$i#)\n"; } +print <<___; +.size OPENSSL_UplinkTable,.-OPENSSL_UplinkTable# +___ diff --git a/ms/uplink-x86.pl b/ms/uplink-x86.pl new file mode 100755 index 0000000000..0dffc14fcd --- /dev/null +++ b/ms/uplink-x86.pl @@ -0,0 +1,33 @@ +#!/usr/bin/env perl + +$0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1; +push(@INC, "${dir}.", "${dir}../crypto/perlasm"); +require "x86asm.pl"; + +require "uplink-common.pl"; + +&asm_init($ARGV[0],"uplink-x86"); + +&external_label("OPENSSL_Uplink"); +&public_label("OPENSSL_UplinkTable"); + +for ($i=1;$i<=$N;$i++) { +&function_begin_B("_\$lazy${i}"); + &lea ("eax",&DWP(&label("OPENSSL_UplinkTable"))); + &push ("eax"); + &push ($i); + &call (&label("OPENSSL_Uplink")); + &add ("esp",8); + &pop ("eax"); + &jmp_ptr(&DWP(4*$i,"eax")); +&function_end_B("_\$lazy${i}"); +} + +&dataseg(); +&align(4); +&set_label("OPENSSL_UplinkTable"); +&data_word($N); +for ($i=1;$i<=$N;$i++) { +&data_word(&label("_\$lazy${i}")); +} +&asm_finish(); diff --git a/ms/uplink-x86_64.pl b/ms/uplink-x86_64.pl new file mode 100755 index 0000000000..80807ce05b --- /dev/null +++ b/ms/uplink-x86_64.pl @@ -0,0 +1,62 @@ +#!/usr/bin/env perl + +$output=shift; +$0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1; +open STDOUT,"| $^X ${dir}../crypto/perlasm/x86_64-xlate.pl $output"; +push(@INC,"${dir}."); + +require "uplink-common.pl"; + +$prefix="_lazy"; + +print <<___; +.text +.extern OPENSSL_Uplink +___ +for ($i=1;$i<=$N;$i++) { +print <<___; +.type $prefix${i},\@abi-omnipotent +.align 16 +$prefix${i}: + .byte 0x48,0x83,0xEC,0x28 # sub rsp,40 + mov %rcx,48(%rsp) + mov %rdx,56(%rsp) + mov %r8,64(%rsp) + mov %r9,72(%rsp) + lea OPENSSL_UplinkTable(%rip),%rcx + mov \$$i,%rdx + call OPENSSL_Uplink + mov 48(%rsp),%rcx + mov 56(%rsp),%rdx + mov 64(%rsp),%r8 + mov 72(%rsp),%r9 + add \$40,%rsp + lea OPENSSL_UplinkTable(%rip),%rax + jmp *8*$i(%rax) +$prefix${i}_end: +.size $prefix${i},.-$prefix${i} +___ +} +print <<___; +.data +.globl OPENSSL_UplinkTable +OPENSSL_UplinkTable: + .quad $N +___ +for ($i=1;$i<=$N;$i++) { print " .quad $prefix$i\n"; } +print <<___; +.section .pdata +___ +for ($i=1;$i<=$N;$i++) { +print <<___; + .long $prefix${i} + .long $prefix${i}_end + .long ${prefix}_unwind_info +___ +} +print <<___; +.section .xdata +${prefix}_unwind_info: + .byte 0x01,0x04,0x01,0x00 + .byte 0x04,0x42,0x00,0x00 +___ -- 2.25.1