summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/perlasm
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/perlasm')
-rw-r--r--src/lib/libcrypto/perlasm/alpha.pl434
-rw-r--r--src/lib/libcrypto/perlasm/x86masm.pl184
-rw-r--r--src/lib/libcrypto/perlasm/x86ms.pl472
-rw-r--r--src/lib/libcrypto/perlasm/x86unix.pl725
4 files changed, 184 insertions, 1631 deletions
diff --git a/src/lib/libcrypto/perlasm/alpha.pl b/src/lib/libcrypto/perlasm/alpha.pl
deleted file mode 100644
index 3dac571743..0000000000
--- a/src/lib/libcrypto/perlasm/alpha.pl
+++ /dev/null
@@ -1,434 +0,0 @@
1#!/usr/local/bin/perl
2
3package alpha;
4use Carp qw(croak cluck);
5
6$label="100";
7
8$n_debug=0;
9$smear_regs=1;
10$reg_alloc=1;
11
12$align="3";
13$com_start="#";
14
15sub main'asm_init_output { @out=(); }
16sub main'asm_get_output { return(@out); }
17sub main'get_labels { return(@labels); }
18sub main'external_label { push(@labels,@_); }
19
20# General registers
21
22%regs=( 'r0', '$0',
23 'r1', '$1',
24 'r2', '$2',
25 'r3', '$3',
26 'r4', '$4',
27 'r5', '$5',
28 'r6', '$6',
29 'r7', '$7',
30 'r8', '$8',
31 'r9', '$22',
32 'r10', '$23',
33 'r11', '$24',
34 'r12', '$25',
35 'r13', '$27',
36 'r14', '$28',
37 'r15', '$21', # argc == 5
38 'r16', '$20', # argc == 4
39 'r17', '$19', # argc == 3
40 'r18', '$18', # argc == 2
41 'r19', '$17', # argc == 1
42 'r20', '$16', # argc == 0
43 'r21', '$9', # save 0
44 'r22', '$10', # save 1
45 'r23', '$11', # save 2
46 'r24', '$12', # save 3
47 'r25', '$13', # save 4
48 'r26', '$14', # save 5
49
50 'a0', '$16',
51 'a1', '$17',
52 'a2', '$18',
53 'a3', '$19',
54 'a4', '$20',
55 'a5', '$21',
56
57 's0', '$9',
58 's1', '$10',
59 's2', '$11',
60 's3', '$12',
61 's4', '$13',
62 's5', '$14',
63 'zero', '$31',
64 'sp', '$30',
65 );
66
67$main'reg_s0="r21";
68$main'reg_s1="r22";
69$main'reg_s2="r23";
70$main'reg_s3="r24";
71$main'reg_s4="r25";
72$main'reg_s5="r26";
73
74@reg=( '$0', '$1' ,'$2' ,'$3' ,'$4' ,'$5' ,'$6' ,'$7' ,'$8',
75 '$22','$23','$24','$25','$20','$21','$27','$28');
76
77
78sub main'sub { &out3("subq",@_); }
79sub main'add { &out3("addq",@_); }
80sub main'mov { &out3("bis",$_[0],$_[0],$_[1]); }
81sub main'or { &out3("bis",@_); }
82sub main'bis { &out3("bis",@_); }
83sub main'br { &out1("br",@_); }
84sub main'ld { &out2("ldq",@_); }
85sub main'st { &out2("stq",@_); }
86sub main'cmpult { &out3("cmpult",@_); }
87sub main'cmplt { &out3("cmplt",@_); }
88sub main'bgt { &out2("bgt",@_); }
89sub main'ble { &out2("ble",@_); }
90sub main'blt { &out2("blt",@_); }
91sub main'mul { &out3("mulq",@_); }
92sub main'muh { &out3("umulh",@_); }
93
94$main'QWS=8;
95
96sub main'asm_add
97 {
98 push(@out,@_);
99 }
100
101sub main'asm_finish
102 {
103 &main'file_end();
104 print &main'asm_get_output();
105 }
106
107sub main'asm_init
108 {
109 ($type,$fn)=@_;
110 $filename=$fn;
111
112 &main'asm_init_output();
113 &main'comment("Don't even think of reading this code");
114 &main'comment("It was automatically generated by $filename");
115 &main'comment("Which is a perl program used to generate the alpha assember.");
116 &main'comment("eric <eay\@cryptsoft.com>");
117 &main'comment("");
118
119 $filename =~ s/\.pl$//;
120 &main'file($filename);
121 }
122
123sub conv
124 {
125 local($r)=@_;
126 local($v);
127
128 return($regs{$r}) if defined($regs{$r});
129 return($r);
130 }
131
132sub main'QWPw
133 {
134 local($off,$reg)=@_;
135
136 return(&main'QWP($off*8,$reg));
137 }
138
139sub main'QWP
140 {
141 local($off,$reg)=@_;
142
143 $ret="$off(".&conv($reg).")";
144 return($ret);
145 }
146
147sub out3
148 {
149 local($name,$p1,$p2,$p3)=@_;
150
151 $p1=&conv($p1);
152 $p2=&conv($p2);
153 $p3=&conv($p3);
154 push(@out,"\t$name\t");
155 $l=length($p1)+1;
156 push(@out,$p1.",");
157 $ll=3-($l+9)/8;
158 $tmp1=sprintf("\t" x $ll);
159 push(@out,$tmp1);
160
161 $l=length($p2)+1;
162 push(@out,$p2.",");
163 $ll=3-($l+9)/8;
164 $tmp1=sprintf("\t" x $ll);
165 push(@out,$tmp1);
166
167 push(@out,&conv($p3)."\n");
168 }
169
170sub out2
171 {
172 local($name,$p1,$p2,$p3)=@_;
173
174 $p1=&conv($p1);
175 $p2=&conv($p2);
176 push(@out,"\t$name\t");
177 $l=length($p1)+1;
178 push(@out,$p1.",");
179 $ll=3-($l+9)/8;
180 $tmp1=sprintf("\t" x $ll);
181 push(@out,$tmp1);
182
183 push(@out,&conv($p2)."\n");
184 }
185
186sub out1
187 {
188 local($name,$p1)=@_;
189
190 $p1=&conv($p1);
191 push(@out,"\t$name\t".$p1."\n");
192 }
193
194sub out0
195 {
196 push(@out,"\t$_[0]\n");
197 }
198
199sub main'file
200 {
201 local($file)=@_;
202
203 local($tmp)=<<"EOF";
204 # DEC Alpha assember
205 # Generated from perl scripts contains in SSLeay
206 .file 1 "$file.s"
207 .set noat
208EOF
209 push(@out,$tmp);
210 }
211
212sub main'function_begin
213 {
214 local($func)=@_;
215
216print STDERR "$func\n";
217 local($tmp)=<<"EOF";
218 .text
219 .align $align
220 .globl $func
221 .ent $func
222${func}:
223${func}..ng:
224 .frame \$30,0,\$26,0
225 .prologue 0
226EOF
227 push(@out,$tmp);
228 $stack=0;
229 }
230
231sub main'function_end
232 {
233 local($func)=@_;
234
235 local($tmp)=<<"EOF";
236 ret \$31,(\$26),1
237 .end $func
238EOF
239 push(@out,$tmp);
240 $stack=0;
241 %label=();
242 }
243
244sub main'function_end_A
245 {
246 local($func)=@_;
247
248 local($tmp)=<<"EOF";
249 ret \$31,(\$26),1
250EOF
251 push(@out,$tmp);
252 }
253
254sub main'function_end_B
255 {
256 local($func)=@_;
257
258 $func=$under.$func;
259
260 push(@out,"\t.end $func\n");
261 $stack=0;
262 %label=();
263 }
264
265sub main'wparam
266 {
267 local($num)=@_;
268
269 if ($num < 6)
270 {
271 $num=20-$num;
272 return("r$num");
273 }
274 else
275 { return(&main'QWP($stack+$num*8,"sp")); }
276 }
277
278sub main'stack_push
279 {
280 local($num)=@_;
281 $stack+=$num*8;
282 &main'sub("sp",$num*8,"sp");
283 }
284
285sub main'stack_pop
286 {
287 local($num)=@_;
288 $stack-=$num*8;
289 &main'add("sp",$num*8,"sp");
290 }
291
292sub main'swtmp
293 {
294 return(&main'QWP(($_[0])*8,"sp"));
295 }
296
297# Should use swtmp, which is above sp. Linix can trash the stack above esp
298#sub main'wtmp
299# {
300# local($num)=@_;
301#
302# return(&main'QWP(-($num+1)*4,"esp","",0));
303# }
304
305sub main'comment
306 {
307 foreach (@_)
308 {
309 if (/^\s*$/)
310 { push(@out,"\n"); }
311 else
312 { push(@out,"\t$com_start $_ $com_end\n"); }
313 }
314 }
315
316sub main'label
317 {
318 if (!defined($label{$_[0]}))
319 {
320 $label{$_[0]}=$label;
321 $label++;
322 }
323 return('$'.$label{$_[0]});
324 }
325
326sub main'set_label
327 {
328 if (!defined($label{$_[0]}))
329 {
330 $label{$_[0]}=$label;
331 $label++;
332 }
333# push(@out,".align $align\n") if ($_[1] != 0);
334 push(@out,'$'."$label{$_[0]}:\n");
335 }
336
337sub main'file_end
338 {
339 }
340
341sub main'data_word
342 {
343 push(@out,"\t.long $_[0]\n");
344 }
345
346@pool_free=();
347@pool_taken=();
348$curr_num=0;
349$max=0;
350
351sub main'init_pool
352 {
353 local($args)=@_;
354 local($i);
355
356 @pool_free=();
357 for ($i=(14+(6-$args)); $i >= 0; $i--)
358 {
359 push(@pool_free,"r$i");
360 }
361 print STDERR "START :register pool:@pool_free\n";
362 $curr_num=$max=0;
363 }
364
365sub main'fin_pool
366 {
367 printf STDERR "END %2d:register pool:@pool_free\n",$max;
368 }
369
370sub main'GR
371 {
372 local($r)=@_;
373 local($i,@n,$_);
374
375 foreach (@pool_free)
376 {
377 if ($r ne $_)
378 { push(@n,$_); }
379 else
380 {
381 $curr_num++;
382 $max=$curr_num if ($curr_num > $max);
383 }
384 }
385 @pool_free=@n;
386print STDERR "GR:@pool_free\n" if $reg_alloc;
387 return(@_);
388 }
389
390sub main'NR
391 {
392 local($num)=@_;
393 local(@ret);
394
395 $num=1 if $num == 0;
396 ($#pool_free >= ($num-1)) || croak "out of registers: want $num, have @pool_free";
397 while ($num > 0)
398 {
399 push(@ret,pop @pool_free);
400 $curr_num++;
401 $max=$curr_num if ($curr_num > $max);
402 $num--
403 }
404 print STDERR "nr @ret\n" if $n_debug;
405print STDERR "NR:@pool_free\n" if $reg_alloc;
406 return(@ret);
407
408 }
409
410sub main'FR
411 {
412 local(@r)=@_;
413 local(@a,$v,$w);
414
415 print STDERR "fr @r\n" if $n_debug;
416# cluck "fr @r";
417 for $w (@pool_free)
418 {
419 foreach $v (@r)
420 {
421 croak "double register free of $v (@pool_free)" if $w eq $v;
422 }
423 }
424 foreach $v (@r)
425 {
426 croak "bad argument to FR" if ($v !~ /^r\d+$/);
427 if ($smear_regs)
428 { unshift(@pool_free,$v); }
429 else { push(@pool_free,$v); }
430 $curr_num--;
431 }
432print STDERR "FR:@pool_free\n" if $reg_alloc;
433 }
4341;
diff --git a/src/lib/libcrypto/perlasm/x86masm.pl b/src/lib/libcrypto/perlasm/x86masm.pl
new file mode 100644
index 0000000000..3d50e4a786
--- /dev/null
+++ b/src/lib/libcrypto/perlasm/x86masm.pl
@@ -0,0 +1,184 @@
1#!/usr/bin/env perl
2
3package x86masm;
4
5*out=\@::out;
6
7$::lbdecor="\$L"; # local label decoration
8$nmdecor="_"; # external name decoration
9
10$initseg="";
11$segment="";
12
13sub ::generic
14{ my ($opcode,@arg)=@_;
15
16 # fix hexadecimal constants
17 for (@arg) { s/0x([0-9a-f]+)/0$1h/oi; }
18
19 if ($opcode !~ /movq/)
20 { # fix xmm references
21 $arg[0] =~ s/\b[A-Z]+WORD\s+PTR/XMMWORD PTR/i if ($arg[1]=~/\bxmm[0-7]\b/i);
22 $arg[1] =~ s/\b[A-Z]+WORD\s+PTR/XMMWORD PTR/i if ($arg[0]=~/\bxmm[0-7]\b/i);
23 }
24
25 &::emit($opcode,@arg);
26 1;
27}
28#
29# opcodes not covered by ::generic above, mostly inconsistent namings...
30#
31sub ::call { &::emit("call",(&::islabel($_[0]) or "$nmdecor$_[0]")); }
32sub ::call_ptr { &::emit("call",@_); }
33sub ::jmp_ptr { &::emit("jmp",@_); }
34
35sub get_mem
36{ my($size,$addr,$reg1,$reg2,$idx)=@_;
37 my($post,$ret);
38
39 $ret .= "$size PTR " if ($size ne "");
40
41 $addr =~ s/^\s+//;
42 # prepend global references with optional underscore
43 $addr =~ s/^([^\+\-0-9][^\+\-]*)/&::islabel($1) or "$nmdecor$1"/ige;
44 # put address arithmetic expression in parenthesis
45 $addr="($addr)" if ($addr =~ /^.+[\-\+].+$/);
46
47 if (($addr ne "") && ($addr ne 0))
48 { if ($addr !~ /^-/) { $ret .= "$addr"; }
49 else { $post=$addr; }
50 }
51 $ret .= "[";
52
53 if ($reg2 ne "")
54 { $idx!=0 or $idx=1;
55 $ret .= "$reg2*$idx";
56 $ret .= "+$reg1" if ($reg1 ne "");
57 }
58 else
59 { $ret .= "$reg1"; }
60
61 $ret .= "$post]";
62 $ret =~ s/\+\]/]/; # in case $addr was the only argument
63 $ret =~ s/\[\s*\]//;
64
65 $ret;
66}
67sub ::BP { &get_mem("BYTE",@_); }
68sub ::DWP { &get_mem("DWORD",@_); }
69sub ::QWP { &get_mem("QWORD",@_); }
70sub ::BC { "@_"; }
71sub ::DWC { "@_"; }
72
73sub ::file
74{ my $tmp=<<___;
75TITLE $_[0].asm
76IF \@Version LT 800
77ECHO MASM version 8.00 or later is strongly recommended.
78ENDIF
79.486
80.MODEL FLAT
81OPTION DOTNAME
82IF \@Version LT 800
83.text\$ SEGMENT PAGE 'CODE'
84ELSE
85.text\$ SEGMENT ALIGN(64) 'CODE'
86ENDIF
87___
88 push(@out,$tmp);
89 $segment = ".text\$";
90}
91
92sub ::function_begin_B
93{ my $func=shift;
94 my $global=($func !~ /^_/);
95 my $begin="${::lbdecor}_${func}_begin";
96
97 &::LABEL($func,$global?"$begin":"$nmdecor$func");
98 $func="ALIGN\t16\n".$nmdecor.$func."\tPROC";
99
100 if ($global) { $func.=" PUBLIC\n${begin}::\n"; }
101 else { $func.=" PRIVATE\n"; }
102 push(@out,$func);
103 $::stack=4;
104}
105sub ::function_end_B
106{ my $func=shift;
107
108 push(@out,"$nmdecor$func ENDP\n");
109 $::stack=0;
110 &::wipe_labels();
111}
112
113sub ::file_end
114{ my $xmmheader=<<___;
115.686
116.XMM
117IF \@Version LT 800
118XMMWORD STRUCT 16
119DQ 2 dup (?)
120XMMWORD ENDS
121ENDIF
122___
123 if (grep {/\b[x]?mm[0-7]\b/i} @out) {
124 grep {s/\.[3-7]86/$xmmheader/} @out;
125 }
126
127 push(@out,"$segment ENDS\n");
128
129 if (grep {/\b${nmdecor}OPENSSL_ia32cap_P\b/i} @out)
130 { my $comm=<<___;
131.bss SEGMENT 'BSS'
132COMM ${nmdecor}OPENSSL_ia32cap_P:DWORD
133.bss ENDS
134___
135 # comment out OPENSSL_ia32cap_P declarations
136 grep {s/(^EXTERN\s+${nmdecor}OPENSSL_ia32cap_P)/\;$1/} @out;
137 push (@out,$comm);
138 }
139 push (@out,$initseg) if ($initseg);
140 push (@out,"END\n");
141}
142
143sub ::comment { foreach (@_) { push(@out,"\t; $_\n"); } }
144
145*::set_label_B = sub
146{ my $l=shift; push(@out,$l.($l=~/^\Q${::lbdecor}\E[0-9]{3}/?":\n":"::\n")); };
147
148sub ::external_label
149{ foreach(@_)
150 { push(@out, "EXTERN\t".&::LABEL($_,$nmdecor.$_).":NEAR\n"); }
151}
152
153sub ::public_label
154{ push(@out,"PUBLIC\t".&::LABEL($_[0],$nmdecor.$_[0])."\n"); }
155
156sub ::data_byte
157{ push(@out,("DB\t").join(',',@_)."\n"); }
158
159sub ::data_word
160{ push(@out,("DD\t").join(',',@_)."\n"); }
161
162sub ::align
163{ push(@out,"ALIGN\t$_[0]\n"); }
164
165sub ::picmeup
166{ my($dst,$sym)=@_;
167 &::lea($dst,&::DWP($sym));
168}
169
170sub ::initseg
171{ my $f=$nmdecor.shift;
172
173 $initseg.=<<___;
174.CRT\$XCU SEGMENT DWORD PUBLIC 'DATA'
175EXTERN $f:NEAR
176DD $f
177.CRT\$XCU ENDS
178___
179}
180
181sub ::dataseg
182{ push(@out,"$segment\tENDS\n_DATA\tSEGMENT\n"); $segment="_DATA"; }
183
1841;
diff --git a/src/lib/libcrypto/perlasm/x86ms.pl b/src/lib/libcrypto/perlasm/x86ms.pl
deleted file mode 100644
index a0be2934c2..0000000000
--- a/src/lib/libcrypto/perlasm/x86ms.pl
+++ /dev/null
@@ -1,472 +0,0 @@
1#!/usr/local/bin/perl
2
3package x86ms;
4
5$label="L000";
6
7%lb=( 'eax', 'al',
8 'ebx', 'bl',
9 'ecx', 'cl',
10 'edx', 'dl',
11 'ax', 'al',
12 'bx', 'bl',
13 'cx', 'cl',
14 'dx', 'dl',
15 );
16
17%hb=( 'eax', 'ah',
18 'ebx', 'bh',
19 'ecx', 'ch',
20 'edx', 'dh',
21 'ax', 'ah',
22 'bx', 'bh',
23 'cx', 'ch',
24 'dx', 'dh',
25 );
26
27sub main'asm_init_output { @out=(); }
28sub main'asm_get_output { return(@out); }
29sub main'get_labels { return(@labels); }
30sub main'external_label
31{
32 push(@labels,@_);
33 foreach (@_) {
34 push(@out, "EXTRN\t_$_:DWORD\n");
35 }
36}
37
38sub main'LB
39 {
40 (defined($lb{$_[0]})) || die "$_[0] does not have a 'low byte'\n";
41 return($lb{$_[0]});
42 }
43
44sub main'HB
45 {
46 (defined($hb{$_[0]})) || die "$_[0] does not have a 'high byte'\n";
47 return($hb{$_[0]});
48 }
49
50sub main'BP
51 {
52 &get_mem("BYTE",@_);
53 }
54
55sub main'DWP
56 {
57 &get_mem("DWORD",@_);
58 }
59
60sub main'QWP
61 {
62 &get_mem("QWORD",@_);
63 }
64
65sub main'BC
66 {
67 return @_;
68 }
69
70sub main'DWC
71 {
72 return @_;
73 }
74
75sub main'stack_push
76 {
77 local($num)=@_;
78 $stack+=$num*4;
79 &main'sub("esp",$num*4);
80 }
81
82sub main'stack_pop
83 {
84 local($num)=@_;
85 $stack-=$num*4;
86 &main'add("esp",$num*4);
87 }
88
89sub get_mem
90 {
91 local($size,$addr,$reg1,$reg2,$idx)=@_;
92 local($t,$post);
93 local($ret)="$size PTR ";
94
95 $addr =~ s/^\s+//;
96 if ($addr =~ /^(.+)\+(.+)$/)
97 {
98 $reg2=&conv($1);
99 $addr="_$2";
100 }
101 elsif ($addr =~ /^[_a-z][_a-z0-9]*$/i)
102 {
103 $addr="_$addr";
104 }
105
106 if ($addr =~ /^.+\-.+$/) { $addr="($addr)"; }
107
108 $reg1="$regs{$reg1}" if defined($regs{$reg1});
109 $reg2="$regs{$reg2}" if defined($regs{$reg2});
110 if (($addr ne "") && ($addr ne 0))
111 {
112 if ($addr !~ /^-/)
113 { $ret.=$addr; }
114 else { $post=$addr; }
115 }
116 if ($reg2 ne "")
117 {
118 $t="";
119 $t="*$idx" if ($idx != 0);
120 $reg1="+".$reg1 if ("$reg1$post" ne "");
121 $ret.="[$reg2$t$reg1$post]";
122 }
123 else
124 {
125 $ret.="[$reg1$post]"
126 }
127 $ret =~ s/\[\]//; # in case $addr was the only argument
128 return($ret);
129 }
130
131sub main'mov { &out2("mov",@_); }
132sub main'movb { &out2("mov",@_); }
133sub main'and { &out2("and",@_); }
134sub main'or { &out2("or",@_); }
135sub main'shl { &out2("shl",@_); }
136sub main'shr { &out2("shr",@_); }
137sub main'xor { &out2("xor",@_); }
138sub main'xorb { &out2("xor",@_); }
139sub main'add { &out2("add",@_); }
140sub main'adc { &out2("adc",@_); }
141sub main'sub { &out2("sub",@_); }
142sub main'sbb { &out2("sbb",@_); }
143sub main'rotl { &out2("rol",@_); }
144sub main'rotr { &out2("ror",@_); }
145sub main'exch { &out2("xchg",@_); }
146sub main'cmp { &out2("cmp",@_); }
147sub main'lea { &out2("lea",@_); }
148sub main'mul { &out1("mul",@_); }
149sub main'imul { &out2("imul",@_); }
150sub main'div { &out1("div",@_); }
151sub main'dec { &out1("dec",@_); }
152sub main'inc { &out1("inc",@_); }
153sub main'jmp { &out1("jmp",@_); }
154sub main'jmp_ptr { &out1p("jmp",@_); }
155sub main'je { &out1("je",@_); }
156sub main'jle { &out1("jle",@_); }
157sub main'jz { &out1("jz",@_); }
158sub main'jge { &out1("jge",@_); }
159sub main'jl { &out1("jl",@_); }
160sub main'ja { &out1("ja",@_); }
161sub main'jae { &out1("jae",@_); }
162sub main'jb { &out1("jb",@_); }
163sub main'jbe { &out1("jbe",@_); }
164sub main'jc { &out1("jc",@_); }
165sub main'jnc { &out1("jnc",@_); }
166sub main'jnz { &out1("jnz",@_); }
167sub main'jne { &out1("jne",@_); }
168sub main'jno { &out1("jno",@_); }
169sub main'push { &out1("push",@_); $stack+=4; }
170sub main'pop { &out1("pop",@_); $stack-=4; }
171sub main'pushf { &out0("pushfd"); $stack+=4; }
172sub main'popf { &out0("popfd"); $stack-=4; }
173sub main'bswap { &out1("bswap",@_); &using486(); }
174sub main'not { &out1("not",@_); }
175sub main'call { &out1("call",($_[0]=~/^\$L/?'':'_').$_[0]); }
176sub main'call_ptr { &out1p("call",@_); }
177sub main'ret { &out0("ret"); }
178sub main'nop { &out0("nop"); }
179sub main'test { &out2("test",@_); }
180sub main'bt { &out2("bt",@_); }
181sub main'leave { &out0("leave"); }
182sub main'cpuid { &out0("DW\t0A20Fh"); }
183sub main'rdtsc { &out0("DW\t0310Fh"); }
184sub main'halt { &out0("hlt"); }
185sub main'movz { &out2("movzx",@_); }
186sub main'neg { &out1("neg",@_); }
187sub main'cld { &out0("cld"); }
188
189# SSE2
190sub main'emms { &out0("emms"); }
191sub main'movd { &out2("movd",@_); }
192sub main'movq { &out2("movq",@_); }
193sub main'movdqu { &out2("movdqu",@_); }
194sub main'movdqa { &out2("movdqa",@_); }
195sub main'movdq2q{ &out2("movdq2q",@_); }
196sub main'movq2dq{ &out2("movq2dq",@_); }
197sub main'paddq { &out2("paddq",@_); }
198sub main'pmuludq{ &out2("pmuludq",@_); }
199sub main'psrlq { &out2("psrlq",@_); }
200sub main'psllq { &out2("psllq",@_); }
201sub main'pxor { &out2("pxor",@_); }
202sub main'por { &out2("por",@_); }
203sub main'pand { &out2("pand",@_); }
204
205sub out2
206 {
207 local($name,$p1,$p2)=@_;
208 local($l,$t,$line);
209
210 $line="\t$name\t";
211 $t=&conv($p1).",";
212 $l=length($t);
213 $line.="$t";
214 $l=4-($l+9)/8;
215 $line.="\t" x $l;
216 $line.=&conv($p2);
217 if ($line=~/\bxmm[0-7]\b/i) { $line=~s/\b[A-Z]+WORD\s+PTR/XMMWORD PTR/i; }
218 push(@out,$line."\n");
219 }
220
221sub out0
222 {
223 local($name)=@_;
224
225 push(@out,"\t$name\n");
226 }
227
228sub out1
229 {
230 local($name,$p1)=@_;
231 local($l,$t);
232
233 push(@out,"\t$name\t".&conv($p1)."\n");
234 }
235
236sub conv
237 {
238 local($p)=@_;
239
240 $p =~ s/0x([0-9A-Fa-f]+)/0$1h/;
241 return $p;
242 }
243
244sub using486
245 {
246 return if $using486;
247 $using486++;
248 grep(s/\.386/\.486/,@out);
249 }
250
251sub main'file
252 {
253 local($file)=@_;
254
255 local($tmp)=<<"EOF";
256 TITLE $file.asm
257 .386
258.model FLAT
259_TEXT\$ SEGMENT PAGE 'CODE'
260
261EOF
262 push(@out,$tmp);
263 }
264
265sub main'function_begin
266 {
267 local($func,$extra)=@_;
268
269 push(@labels,$func);
270
271 local($tmp)=<<"EOF";
272PUBLIC _$func
273$extra
274_$func PROC NEAR
275 push ebp
276 push ebx
277 push esi
278 push edi
279EOF
280 push(@out,$tmp);
281 $stack=20;
282 }
283
284sub main'function_begin_B
285 {
286 local($func,$extra)=@_;
287
288 local($tmp)=<<"EOF";
289PUBLIC _$func
290$extra
291_$func PROC NEAR
292EOF
293 push(@out,$tmp);
294 $stack=4;
295 }
296
297sub main'function_end
298 {
299 local($func)=@_;
300
301 local($tmp)=<<"EOF";
302 pop edi
303 pop esi
304 pop ebx
305 pop ebp
306 ret
307_$func ENDP
308EOF
309 push(@out,$tmp);
310 $stack=0;
311 %label=();
312 }
313
314sub main'function_end_B
315 {
316 local($func)=@_;
317
318 local($tmp)=<<"EOF";
319_$func ENDP
320EOF
321 push(@out,$tmp);
322 $stack=0;
323 %label=();
324 }
325
326sub main'function_end_A
327 {
328 local($func)=@_;
329
330 local($tmp)=<<"EOF";
331 pop edi
332 pop esi
333 pop ebx
334 pop ebp
335 ret
336EOF
337 push(@out,$tmp);
338 }
339
340sub main'file_end
341 {
342 # try to detect if SSE2 or MMX extensions were used...
343 my $xmmheader=<<___;
344.686
345.XMM
346IF \@Version LT 800
347XMMWORD STRUCT 16
348 DQ 2 dup (?)
349XMMWORD ENDS
350ENDIF
351___
352 if (grep {/\b[x]?mm[0-7]\b/i} @out) {
353 grep {s/\.[3-7]86/$xmmheader/} @out;
354 }
355 push(@out,"_TEXT\$ ENDS\n");
356 push(@out,"END\n");
357 }
358
359sub main'wparam
360 {
361 local($num)=@_;
362
363 return(&main'DWP($stack+$num*4,"esp","",0));
364 }
365
366sub main'swtmp
367 {
368 return(&main'DWP($_[0]*4,"esp","",0));
369 }
370
371# Should use swtmp, which is above esp. Linix can trash the stack above esp
372#sub main'wtmp
373# {
374# local($num)=@_;
375#
376# return(&main'DWP(-(($num+1)*4),"esp","",0));
377# }
378
379sub main'comment
380 {
381 foreach (@_)
382 {
383 push(@out,"\t; $_\n");
384 }
385 }
386
387sub main'public_label
388 {
389 $label{$_[0]}="_$_[0]" if (!defined($label{$_[0]}));
390 push(@out,"PUBLIC\t$label{$_[0]}\n");
391 }
392
393sub main'label
394 {
395 if (!defined($label{$_[0]}))
396 {
397 $label{$_[0]}="\$${label}${_[0]}";
398 $label++;
399 }
400 return($label{$_[0]});
401 }
402
403sub main'set_label
404 {
405 if (!defined($label{$_[0]}))
406 {
407 $label{$_[0]}="\$${label}${_[0]}";
408 $label++;
409 }
410 if ($_[1]!=0 && $_[1]>1)
411 {
412 main'align($_[1]);
413 }
414 if((defined $_[2]) && ($_[2] == 1))
415 {
416 push(@out,"$label{$_[0]}::\n");
417 }
418 elsif ($label{$_[0]} !~ /^\$/)
419 {
420 push(@out,"$label{$_[0]}\tLABEL PTR\n");
421 }
422 else
423 {
424 push(@out,"$label{$_[0]}:\n");
425 }
426 }
427
428sub main'data_byte
429 {
430 push(@out,"\tDB\t".join(',',@_)."\n");
431 }
432
433sub main'data_word
434 {
435 push(@out,"\tDD\t".join(',',@_)."\n");
436 }
437
438sub main'align
439 {
440 push(@out,"\tALIGN\t$_[0]\n");
441 }
442
443sub out1p
444 {
445 local($name,$p1)=@_;
446 local($l,$t);
447
448 push(@out,"\t$name\t".&conv($p1)."\n");
449 }
450
451sub main'picmeup
452 {
453 local($dst,$sym)=@_;
454 &main'lea($dst,&main'DWP($sym));
455 }
456
457sub main'blindpop { &out1("pop",@_); }
458
459sub main'initseg
460 {
461 local($f)=@_;
462 local($tmp)=<<___;
463OPTION DOTNAME
464.CRT\$XCU SEGMENT DWORD PUBLIC 'DATA'
465EXTRN _$f:NEAR
466DD _$f
467.CRT\$XCU ENDS
468___
469 push(@out,$tmp);
470 }
471
4721;
diff --git a/src/lib/libcrypto/perlasm/x86unix.pl b/src/lib/libcrypto/perlasm/x86unix.pl
deleted file mode 100644
index a4c947165e..0000000000
--- a/src/lib/libcrypto/perlasm/x86unix.pl
+++ /dev/null
@@ -1,725 +0,0 @@
1#!/usr/local/bin/perl
2
3package x86unix; # GAS actually...
4
5$label="L000";
6$const="";
7$constl=0;
8
9$align=($main'aout)?"4":"16";
10$under=($main'aout or $main'coff)?"_":"";
11$dot=($main'aout)?"":".";
12$com_start="#" if ($main'aout or $main'coff);
13
14sub main'asm_init_output { @out=(); }
15sub main'asm_get_output { return(@out); }
16sub main'get_labels { return(@labels); }
17sub main'external_label { push(@labels,@_); }
18
19if ($main'cpp)
20 {
21 $align="ALIGN";
22 $under="";
23 $com_start='/*';
24 $com_end='*/';
25 }
26
27%lb=( 'eax', '%al',
28 'ebx', '%bl',
29 'ecx', '%cl',
30 'edx', '%dl',
31 'ax', '%al',
32 'bx', '%bl',
33 'cx', '%cl',
34 'dx', '%dl',
35 );
36
37%hb=( 'eax', '%ah',
38 'ebx', '%bh',
39 'ecx', '%ch',
40 'edx', '%dh',
41 'ax', '%ah',
42 'bx', '%bh',
43 'cx', '%ch',
44 'dx', '%dh',
45 );
46
47%regs=( 'eax', '%eax',
48 'ebx', '%ebx',
49 'ecx', '%ecx',
50 'edx', '%edx',
51 'esi', '%esi',
52 'edi', '%edi',
53 'ebp', '%ebp',
54 'esp', '%esp',
55
56 'mm0', '%mm0',
57 'mm1', '%mm1',
58 'mm2', '%mm2',
59 'mm3', '%mm3',
60 'mm4', '%mm4',
61 'mm5', '%mm5',
62 'mm6', '%mm6',
63 'mm7', '%mm7',
64
65 'xmm0', '%xmm0',
66 'xmm1', '%xmm1',
67 'xmm2', '%xmm2',
68 'xmm3', '%xmm3',
69 'xmm4', '%xmm4',
70 'xmm5', '%xmm5',
71 'xmm6', '%xmm6',
72 'xmm7', '%xmm7',
73 );
74
75%reg_val=(
76 'eax', 0x00,
77 'ebx', 0x03,
78 'ecx', 0x01,
79 'edx', 0x02,
80 'esi', 0x06,
81 'edi', 0x07,
82 'ebp', 0x05,
83 'esp', 0x04,
84 );
85
86sub main'LB
87 {
88 (defined($lb{$_[0]})) || die "$_[0] does not have a 'low byte'\n";
89 return($lb{$_[0]});
90 }
91
92sub main'HB
93 {
94 (defined($hb{$_[0]})) || die "$_[0] does not have a 'high byte'\n";
95 return($hb{$_[0]});
96 }
97
98sub main'DWP
99 {
100 local($addr,$reg1,$reg2,$idx)=@_;
101
102 $ret="";
103 $addr =~ s/(^|[+ \t])([A-Za-z_]+[A-Za-z0-9_]+)($|[+ \t])/$1$under$2$3/;
104 $reg1="$regs{$reg1}" if defined($regs{$reg1});
105 $reg2="$regs{$reg2}" if defined($regs{$reg2});
106 $ret.=$addr if ($addr ne "") && ($addr ne 0);
107 if ($reg2 ne "")
108 {
109 if($idx ne "" && $idx != 0)
110 { $ret.="($reg1,$reg2,$idx)"; }
111 else
112 { $ret.="($reg1,$reg2)"; }
113 }
114 elsif ($reg1 ne "")
115 { $ret.="($reg1)" }
116 return($ret);
117 }
118
119sub main'QWP
120 {
121 return(&main'DWP(@_));
122 }
123
124sub main'BP
125 {
126 return(&main'DWP(@_));
127 }
128
129sub main'BC
130 {
131 return @_;
132 }
133
134sub main'DWC
135 {
136 return @_;
137 }
138
139#sub main'BP
140# {
141# local($addr,$reg1,$reg2,$idx)=@_;
142#
143# $ret="";
144#
145# $addr =~ s/(^|[+ \t])([A-Za-z_]+)($|[+ \t])/$1$under$2$3/;
146# $reg1="$regs{$reg1}" if defined($regs{$reg1});
147# $reg2="$regs{$reg2}" if defined($regs{$reg2});
148# $ret.=$addr if ($addr ne "") && ($addr ne 0);
149# if ($reg2 ne "")
150# { $ret.="($reg1,$reg2,$idx)"; }
151# else
152# { $ret.="($reg1)" }
153# return($ret);
154# }
155
156sub main'mov { &out2("movl",@_); }
157sub main'movb { &out2("movb",@_); }
158sub main'and { &out2("andl",@_); }
159sub main'or { &out2("orl",@_); }
160sub main'shl { &out2("sall",@_); }
161sub main'shr { &out2("shrl",@_); }
162sub main'xor { &out2("xorl",@_); }
163sub main'xorb { &out2("xorb",@_); }
164sub main'add { &out2($_[0]=~/%[a-d][lh]/?"addb":"addl",@_); }
165sub main'adc { &out2("adcl",@_); }
166sub main'sub { &out2("subl",@_); }
167sub main'sbb { &out2("sbbl",@_); }
168sub main'rotl { &out2("roll",@_); }
169sub main'rotr { &out2("rorl",@_); }
170sub main'exch { &out2($_[0]=~/%[a-d][lh]/?"xchgb":"xchgl",@_); }
171sub main'cmp { &out2("cmpl",@_); }
172sub main'lea { &out2("leal",@_); }
173sub main'mul { &out1("mull",@_); }
174sub main'imul { &out2("imull",@_); }
175sub main'div { &out1("divl",@_); }
176sub main'jmp { &out1("jmp",@_); }
177sub main'jmp_ptr { &out1p("jmp",@_); }
178sub main'je { &out1("je",@_); }
179sub main'jle { &out1("jle",@_); }
180sub main'jne { &out1("jne",@_); }
181sub main'jnz { &out1("jnz",@_); }
182sub main'jz { &out1("jz",@_); }
183sub main'jge { &out1("jge",@_); }
184sub main'jl { &out1("jl",@_); }
185sub main'ja { &out1("ja",@_); }
186sub main'jae { &out1("jae",@_); }
187sub main'jb { &out1("jb",@_); }
188sub main'jbe { &out1("jbe",@_); }
189sub main'jc { &out1("jc",@_); }
190sub main'jnc { &out1("jnc",@_); }
191sub main'jno { &out1("jno",@_); }
192sub main'dec { &out1("decl",@_); }
193sub main'inc { &out1($_[0]=~/%[a-d][hl]/?"incb":"incl",@_); }
194sub main'push { &out1("pushl",@_); $stack+=4; }
195sub main'pop { &out1("popl",@_); $stack-=4; }
196sub main'pushf { &out0("pushfl"); $stack+=4; }
197sub main'popf { &out0("popfl"); $stack-=4; }
198sub main'not { &out1("notl",@_); }
199sub main'call { my $pre=$under;
200 foreach $i (%label)
201 { if ($label{$i} eq $_[0]) { $pre=''; last; } }
202 &out1("call",$pre.$_[0]);
203 }
204sub main'call_ptr { &out1p("call",@_); }
205sub main'ret { &out0("ret"); }
206sub main'nop { &out0("nop"); }
207sub main'test { &out2("testl",@_); }
208sub main'bt { &out2("btl",@_); }
209sub main'leave { &out0("leave"); }
210sub main'cpuid { &out0(".byte\t0x0f,0xa2"); }
211sub main'rdtsc { &out0(".byte\t0x0f,0x31"); }
212sub main'halt { &out0("hlt"); }
213sub main'movz { &out2("movzbl",@_); }
214sub main'neg { &out1("negl",@_); }
215sub main'cld { &out0("cld"); }
216
217# SSE2
218sub main'emms { &out0("emms"); }
219sub main'movd { &out2("movd",@_); }
220sub main'movdqu { &out2("movdqu",@_); }
221sub main'movdqa { &out2("movdqa",@_); }
222sub main'movdq2q{ &out2("movdq2q",@_); }
223sub main'movq2dq{ &out2("movq2dq",@_); }
224sub main'paddq { &out2("paddq",@_); }
225sub main'pmuludq{ &out2("pmuludq",@_); }
226sub main'psrlq { &out2("psrlq",@_); }
227sub main'psllq { &out2("psllq",@_); }
228sub main'pxor { &out2("pxor",@_); }
229sub main'por { &out2("por",@_); }
230sub main'pand { &out2("pand",@_); }
231sub main'movq {
232 local($p1,$p2,$optimize)=@_;
233 if ($optimize && $p1=~/^mm[0-7]$/ && $p2=~/^mm[0-7]$/)
234 # movq between mmx registers can sink Intel CPUs
235 { push(@out,"\tpshufw\t\$0xe4,%$p2,%$p1\n"); }
236 else { &out2("movq",@_); }
237 }
238
239# The bswapl instruction is new for the 486. Emulate if i386.
240sub main'bswap
241 {
242 if ($main'i386)
243 {
244 &main'comment("bswapl @_");
245 &main'exch(main'HB(@_),main'LB(@_));
246 &main'rotr(@_,16);
247 &main'exch(main'HB(@_),main'LB(@_));
248 }
249 else
250 {
251 &out1("bswapl",@_);
252 }
253 }
254
255sub out2
256 {
257 local($name,$p1,$p2)=@_;
258 local($l,$ll,$t);
259 local(%special)=( "roll",0xD1C0,"rorl",0xD1C8,
260 "rcll",0xD1D0,"rcrl",0xD1D8,
261 "shll",0xD1E0,"shrl",0xD1E8,
262 "sarl",0xD1F8);
263
264 if ((defined($special{$name})) && defined($regs{$p1}) && ($p2 == 1))
265 {
266 $op=$special{$name}|$reg_val{$p1};
267 $tmp1=sprintf(".byte %d\n",($op>>8)&0xff);
268 $tmp2=sprintf(".byte %d\t",$op &0xff);
269 push(@out,$tmp1);
270 push(@out,$tmp2);
271
272 $p2=&conv($p2);
273 $p1=&conv($p1);
274 &main'comment("$name $p2 $p1");
275 return;
276 }
277
278 push(@out,"\t$name\t");
279 $t=&conv($p2).",";
280 $l=length($t);
281 push(@out,$t);
282 $ll=4-($l+9)/8;
283 $tmp1=sprintf("\t" x $ll);
284 push(@out,$tmp1);
285 push(@out,&conv($p1)."\n");
286 }
287
288sub out1
289 {
290 local($name,$p1)=@_;
291 local($l,$t);
292 local(%special)=("bswapl",0x0FC8);
293
294 if ((defined($special{$name})) && defined($regs{$p1}))
295 {
296 $op=$special{$name}|$reg_val{$p1};
297 $tmp1=sprintf(".byte %d\n",($op>>8)&0xff);
298 $tmp2=sprintf(".byte %d\t",$op &0xff);
299 push(@out,$tmp1);
300 push(@out,$tmp2);
301
302 $p2=&conv($p2);
303 $p1=&conv($p1);
304 &main'comment("$name $p2 $p1");
305 return;
306 }
307
308 push(@out,"\t$name\t".&conv($p1)."\n");
309 }
310
311sub out1p
312 {
313 local($name,$p1)=@_;
314 local($l,$t);
315
316 push(@out,"\t$name\t*".&conv($p1)."\n");
317 }
318
319sub out0
320 {
321 push(@out,"\t$_[0]\n");
322 }
323
324sub conv
325 {
326 local($p)=@_;
327
328# $p =~ s/0x([0-9A-Fa-f]+)/0$1h/;
329
330 $p=$regs{$p} if (defined($regs{$p}));
331
332 $p =~ s/^(-{0,1}[0-9A-Fa-f]+)$/\$$1/;
333 $p =~ s/^(0x[0-9A-Fa-f]+)$/\$$1/;
334 return $p;
335 }
336
337sub main'file
338 {
339 local($file)=@_;
340
341 local($tmp)=<<"EOF";
342 .file "$file.s"
343EOF
344 push(@out,$tmp);
345 }
346
347sub main'function_begin
348 {
349 local($func)=@_;
350
351 &main'external_label($func);
352 $func=$under.$func;
353
354 local($tmp)=<<"EOF";
355.text
356.globl $func
357EOF
358 push(@out,$tmp);
359 if ($main'cpp)
360 { $tmp=push(@out,"TYPE($func,\@function)\n"); }
361 elsif ($main'coff)
362 { $tmp=push(@out,".def\t$func;\t.scl\t2;\t.type\t32;\t.endef\n"); }
363 elsif ($main'aout and !$main'pic)
364 { }
365 else { $tmp=push(@out,".type\t$func,\@function\n"); }
366 push(@out,".align\t$align\n");
367 push(@out,"$func:\n");
368 $tmp=<<"EOF";
369 pushl %ebp
370 pushl %ebx
371 pushl %esi
372 pushl %edi
373
374EOF
375 push(@out,$tmp);
376 $stack=20;
377 }
378
379sub main'function_begin_B
380 {
381 local($func,$extra)=@_;
382
383 &main'external_label($func);
384 $func=$under.$func;
385
386 local($tmp)=<<"EOF";
387.text
388.globl $func
389EOF
390 push(@out,$tmp);
391 if ($main'cpp)
392 { push(@out,"TYPE($func,\@function)\n"); }
393 elsif ($main'coff)
394 { $tmp=push(@out,".def\t$func;\t.scl\t2;\t.type\t32;\t.endef\n"); }
395 elsif ($main'aout and !$main'pic)
396 { }
397 else { push(@out,".type $func,\@function\n"); }
398 push(@out,".align\t$align\n");
399 push(@out,"$func:\n");
400 $stack=4;
401 }
402
403sub main'function_end
404 {
405 local($func)=@_;
406
407 $func=$under.$func;
408
409 local($tmp)=<<"EOF";
410 popl %edi
411 popl %esi
412 popl %ebx
413 popl %ebp
414 ret
415${dot}L_${func}_end:
416EOF
417 push(@out,$tmp);
418
419 if ($main'cpp)
420 { push(@out,"SIZE($func,${dot}L_${func}_end-$func)\n"); }
421 elsif ($main'coff or $main'aout)
422 { }
423 else { push(@out,".size\t$func,${dot}L_${func}_end-$func\n"); }
424 push(@out,".ident \"$func\"\n");
425 $stack=0;
426 %label=();
427 }
428
429sub main'function_end_A
430 {
431 local($func)=@_;
432
433 local($tmp)=<<"EOF";
434 popl %edi
435 popl %esi
436 popl %ebx
437 popl %ebp
438 ret
439EOF
440 push(@out,$tmp);
441 }
442
443sub main'function_end_B
444 {
445 local($func)=@_;
446
447 $func=$under.$func;
448
449 push(@out,"${dot}L_${func}_end:\n");
450 if ($main'cpp)
451 { push(@out,"SIZE($func,${dot}L_${func}_end-$func)\n"); }
452 elsif ($main'coff or $main'aout)
453 { }
454 else { push(@out,".size\t$func,${dot}L_${func}_end-$func\n"); }
455 push(@out,".ident \"$func\"\n");
456 $stack=0;
457 %label=();
458 }
459
460sub main'wparam
461 {
462 local($num)=@_;
463
464 return(&main'DWP($stack+$num*4,"esp","",0));
465 }
466
467sub main'stack_push
468 {
469 local($num)=@_;
470 $stack+=$num*4;
471 &main'sub("esp",$num*4);
472 }
473
474sub main'stack_pop
475 {
476 local($num)=@_;
477 $stack-=$num*4;
478 &main'add("esp",$num*4);
479 }
480
481sub main'swtmp
482 {
483 return(&main'DWP($_[0]*4,"esp","",0));
484 }
485
486# Should use swtmp, which is above esp. Linix can trash the stack above esp
487#sub main'wtmp
488# {
489# local($num)=@_;
490#
491# return(&main'DWP(-($num+1)*4,"esp","",0));
492# }
493
494sub main'comment
495 {
496 if (!defined($com_start) or $main'elf)
497 { # Regarding $main'elf above...
498 # GNU and SVR4 as'es use different comment delimiters,
499 push(@out,"\n"); # so we just skip ELF comments...
500 return;
501 }
502 foreach (@_)
503 {
504 if (/^\s*$/)
505 { push(@out,"\n"); }
506 else
507 { push(@out,"\t$com_start $_ $com_end\n"); }
508 }
509 }
510
511sub main'public_label
512 {
513 $label{$_[0]}="${under}${_[0]}" if (!defined($label{$_[0]}));
514 push(@out,".globl\t$label{$_[0]}\n");
515 }
516
517sub main'label
518 {
519 if (!defined($label{$_[0]}))
520 {
521 $label{$_[0]}="${dot}${label}${_[0]}";
522 $label++;
523 }
524 return($label{$_[0]});
525 }
526
527sub main'set_label
528 {
529 if (!defined($label{$_[0]}))
530 {
531 $label{$_[0]}="${dot}${label}${_[0]}";
532 $label++;
533 }
534 if ($_[1]!=0)
535 {
536 if ($_[1]>1) { main'align($_[1]); }
537 else { push(@out,".align $align\n"); }
538 }
539 push(@out,"$label{$_[0]}:\n");
540 }
541
542sub main'file_end
543 {
544 # try to detect if SSE2 or MMX extensions were used on ELF platform...
545 if ($main'elf && grep {/\b%[x]*mm[0-7]\b|OPENSSL_ia32cap_P\b/i} @out) {
546 local($tmp);
547
548 push (@out,"\n.section\t.bss\n");
549 push (@out,".comm\t${under}OPENSSL_ia32cap_P,4,4\n");
550
551 return;
552 }
553
554 if ($const ne "")
555 {
556 push(@out,".section .rodata\n");
557 push(@out,$const);
558 $const="";
559 }
560 }
561
562sub main'data_byte
563 {
564 push(@out,"\t.byte\t".join(',',@_)."\n");
565 }
566
567sub main'data_word
568 {
569 push(@out,"\t.long\t".join(',',@_)."\n");
570 }
571
572sub main'align
573 {
574 my $val=$_[0],$p2,$i;
575 if ($main'aout) {
576 for ($p2=0;$val!=0;$val>>=1) { $p2++; }
577 $val=$p2-1;
578 $val.=",0x90";
579 }
580 push(@out,".align\t$val\n");
581 }
582
583# debug output functions: puts, putx, printf
584
585sub main'puts
586 {
587 &pushvars();
588 &main'push('$Lstring' . ++$constl);
589 &main'call('puts');
590 $stack-=4;
591 &main'add("esp",4);
592 &popvars();
593
594 $const .= "Lstring$constl:\n\t.string \"@_[0]\"\n";
595 }
596
597sub main'putx
598 {
599 &pushvars();
600 &main'push($_[0]);
601 &main'push('$Lstring' . ++$constl);
602 &main'call('printf');
603 &main'add("esp",8);
604 $stack-=8;
605 &popvars();
606
607 $const .= "Lstring$constl:\n\t.string \"\%X\"\n";
608 }
609
610sub main'printf
611 {
612 $ostack = $stack;
613 &pushvars();
614 for ($i = @_ - 1; $i >= 0; $i--)
615 {
616 if ($i == 0) # change this to support %s format strings
617 {
618 &main'push('$Lstring' . ++$constl);
619 $const .= "Lstring$constl:\n\t.string \"@_[$i]\"\n";
620 }
621 else
622 {
623 if ($_[$i] =~ /([0-9]*)\(%esp\)/)
624 {
625 &main'push(($1 + $stack - $ostack) . '(%esp)');
626 }
627 else
628 {
629 &main'push($_[$i]);
630 }
631 }
632 }
633 &main'call('printf');
634 $stack-=4*@_;
635 &main'add("esp",4*@_);
636 &popvars();
637 }
638
639sub pushvars
640 {
641 &main'pushf();
642 &main'push("edx");
643 &main'push("ecx");
644 &main'push("eax");
645 }
646
647sub popvars
648 {
649 &main'pop("eax");
650 &main'pop("ecx");
651 &main'pop("edx");
652 &main'popf();
653 }
654
655sub main'picmeup
656 {
657 local($dst,$sym)=@_;
658 if ($main'cpp)
659 {
660 local($tmp)=<<___;
661#if (defined(ELF) || defined(SOL)) && defined(PIC)
662 call 1f
6631: popl $regs{$dst}
664 addl \$_GLOBAL_OFFSET_TABLE_+[.-1b],$regs{$dst}
665 movl $sym\@GOT($regs{$dst}),$regs{$dst}
666#else
667 leal $sym,$regs{$dst}
668#endif
669___
670 push(@out,$tmp);
671 }
672 elsif ($main'pic && ($main'elf || $main'aout))
673 {
674 &main'call(&main'label("PIC_me_up"));
675 &main'set_label("PIC_me_up");
676 &main'blindpop($dst);
677 &main'add($dst,"\$${under}_GLOBAL_OFFSET_TABLE_+[.-".
678 &main'label("PIC_me_up") . "]");
679 &main'mov($dst,&main'DWP($under.$sym."\@GOT",$dst));
680 }
681 else
682 {
683 &main'lea($dst,&main'DWP($sym));
684 }
685 }
686
687sub main'blindpop { &out1("popl",@_); }
688
689sub main'initseg
690 {
691 local($f)=@_;
692 local($tmp);
693 if ($main'elf)
694 {
695 $tmp=<<___;
696.section .init
697 call $under$f
698 jmp .Linitalign
699.align $align
700.Linitalign:
701___
702 }
703 elsif ($main'coff)
704 {
705 $tmp=<<___; # applies to both Cygwin and Mingw
706.section .ctors
707.long $under$f
708___
709 }
710 elsif ($main'aout)
711 {
712 local($ctor)="${under}_GLOBAL_\$I\$$f";
713 $tmp=".text\n";
714 $tmp.=".type $ctor,\@function\n" if ($main'pic);
715 $tmp.=<<___; # OpenBSD way...
716.globl $ctor
717.align 2
718$ctor:
719 jmp $under$f
720___
721 }
722 push(@out,$tmp) if ($tmp);
723 }
724
7251;