]> git.ipfire.org Git - thirdparty/openssl.git/blame - ms/uplink.pl
Disclaim 16-bit support.
[thirdparty/openssl.git] / ms / uplink.pl
CommitLineData
3fc378aa
AP
1#!/usr/bin/env perl
2#
3# For Microsoft CL this is implemented as inline assembler. So that
4# even though this script can generate even Win32 code, we'll be
5# using it primarily to generate Win64 modules. Both IA-64 and AMD64
6# are supported...
7
8# pull APPLINK_MAX value from applink.c...
9$applink_c=$0;
10$applink_c=~s|[^/\\]+$||g;
11$applink_c.="applink.c";
12open(INPUT,$applink_c) || die "can't open $applink_c: $!";
13@max=grep {/APPLINK_MAX\s+(\d+)/} <INPUT>;
14close(INPUT);
15($#max==0) or die "can't find APPLINK_MAX in $applink_c";
16
17$max[0]=~/APPLINK_MAX\s+(\d+)/;
18$N=$1; # number of entries in OPENSSL_UplinkTable not including
19 # OPENSSL_UplinkTable[0], which contains this value...
20
21# Idea is to fill the OPENSSL_UplinkTable with pointers to stubs
22# which invoke 'void OPENSSL_Uplink (ULONG_PTR *table,int index)';
23# and then dereference themselves. Latter shall result in endless
24# loop *unless* OPENSSL_Uplink does not replace 'table[index]' with
25# something else, e.g. as 'table[index]=unimplemented;'...
26
27$arg = shift;
28#( defined shift || open STDOUT,">$arg" ) || die "can't open $arg: $!";
29
30if ($arg =~ /win32n/) { ia32nasm(); }
31elsif ($arg =~ /win32/) { ia32masm(); }
32elsif ($arg =~ /ia64/) { ia64ias(); }
33elsif ($arg =~ /amd64/) { amd64masm(); }
34else { die "nonsense $arg"; }
35
36sub ia32masm() {
37print <<___;
38.386P
39.model FLAT
40
41_DATA SEGMENT
42PUBLIC _OPENSSL_UplinkTable
43_OPENSSL_UplinkTable DD $N ; amount of following entries
44___
45for ($i=1;$i<=$N;$i++) { print " DD FLAT:\$lazy$i\n"; }
46print <<___;
47_DATA ENDS
48
49_TEXT SEGMENT
50EXTRN _OPENSSL_Uplink:NEAR
51___
52for ($i=1;$i<=$N;$i++) {
53print <<___;
54ALIGN 4
55\$lazy$i PROC NEAR
56 push $i
57 push OFFSET FLAT:_OPENSSL_UplinkTable
58 call _OPENSSL_Uplink
59 add esp,8
60 jmp DWORD PTR _OPENSSL_UplinkTable+4*$i
61\$lazy$i ENDP
62___
63}
64print <<___;
65ALIGN 4
66_TEXT ENDS
67END
68___
69}
70
71sub ia32nasm() {
72print <<___;
73SEGMENT .data
74GLOBAL _OPENSSL_UplinkTable
75_OPENSSL_UplinkTable DD $N ; amount of following entries
76___
77for ($i=1;$i<=$N;$i++) { print " DD \$lazy$i\n"; }
78print <<___;
79
80SEGMENT .text
81EXTERN _OPENSSL_Uplink
82___
83for ($i=1;$i<=$N;$i++) {
84print <<___;
85ALIGN 4
86\$lazy$i:
87 push $i
88 push _OPENSSL_UplinkTable
89 call _OPENSSL_Uplink
90 add esp,8
91 jmp [_OPENSSL_UplinkTable+4*$i]
92___
93}
94print <<___;
95ALIGN 4
96END
97___
98}
99
100sub ia64ias () {
101local $V=8; # max number of args uplink functions may accept...
102print <<___;
103.data
104.global OPENSSL_UplinkTable#
105OPENSSL_UplinkTable: data8 $N // amount of following entries
106___
107for ($i=1;$i<=$N;$i++) { print " data8 \@fptr(lazy$i#)\n"; }
108print <<___;
109.size OPENSSL_UplinkTable,.-OPENSSL_UplinkTable#
110
111.text
112.global OPENSSL_Uplink#
113.type OPENSSL_Uplink#,\@function
114___
115for ($i=1;$i<=$N;$i++) {
116print <<___;
117.proc lazy$i
118lazy$i:
119{ .mii; alloc loc0=ar.pfs,$V,3,2,0
120 mov loc1=b0
121 addl loc2=\@ltoff(OPENSSL_UplinkTable#),gp };;
122{ .mmi; ld8 out0=[loc2]
123 mov out1=$i };;
124{ .mib; adds loc2=8*$i,out0
125 br.call.sptk.many b0=OPENSSL_Uplink# };;
126{ .mmi; ld8 r31=[loc2];;
127 ld8 r30=[r31],8 };;
128{ .mii; ld8 gp=[r31]
129 mov b6=r30
130 mov b0=loc1 };;
131{ .mib; mov ar.pfs=loc0
132 br.many b6 };;
133.endp lazy$i#
134___
135}
136}
137
138sub amd64masm() {
139print <<___;
140_DATA SEGMENT
141PUBLIC OPENSSL_UplinkTable
142OPENSSL_UplinkTable DQ $N
143___
144for ($i=1;$i<=$N;$i++) { print " DQ FLAT:\$lazy$i\n"; }
145print <<___;
146_DATA ENDS
147
148TEXT SEGMENT
149EXTERN OPENSSL_Uplink:NEAR
150___
151for ($i=1;$i<=$N;$i++) {
152print <<___;
153ALIGN 4
154\$lazy$i PROC NEAR
155 push r9
156 push r8
157 push rdx
158 push rcx
159 sub rsp,40
160 mov rcx,OFFSET FLAT:OPENSSL_UplinkTable
161 mov rdx,$i
162 call OPENSSL_Uplink
163 add rsp,40
164 pop rcx
165 pop rdx
166 pop r8
167 pop r9
168 jmp QWORD PTR OPENSSL_UplinkTable+8*$i
169\$lazy$i ENDP
170___
171}
172print <<___;
173TEXT ENDS
174END
175___
176}
177