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/x86ms.pl122
-rw-r--r--src/lib/libcrypto/perlasm/x86nasm.pl153
-rw-r--r--src/lib/libcrypto/perlasm/x86unix.pl220
3 files changed, 404 insertions, 91 deletions
diff --git a/src/lib/libcrypto/perlasm/x86ms.pl b/src/lib/libcrypto/perlasm/x86ms.pl
index b6bd744057..a0be2934c2 100644
--- a/src/lib/libcrypto/perlasm/x86ms.pl
+++ b/src/lib/libcrypto/perlasm/x86ms.pl
@@ -27,7 +27,13 @@ $label="L000";
27sub main'asm_init_output { @out=(); } 27sub main'asm_init_output { @out=(); }
28sub main'asm_get_output { return(@out); } 28sub main'asm_get_output { return(@out); }
29sub main'get_labels { return(@labels); } 29sub main'get_labels { return(@labels); }
30sub main'external_label { push(@labels,@_); } 30sub main'external_label
31{
32 push(@labels,@_);
33 foreach (@_) {
34 push(@out, "EXTRN\t_$_:DWORD\n");
35 }
36}
31 37
32sub main'LB 38sub main'LB
33 { 39 {
@@ -51,6 +57,11 @@ sub main'DWP
51 &get_mem("DWORD",@_); 57 &get_mem("DWORD",@_);
52 } 58 }
53 59
60sub main'QWP
61 {
62 &get_mem("QWORD",@_);
63 }
64
54sub main'BC 65sub main'BC
55 { 66 {
56 return @_; 67 return @_;
@@ -87,7 +98,7 @@ sub get_mem
87 $reg2=&conv($1); 98 $reg2=&conv($1);
88 $addr="_$2"; 99 $addr="_$2";
89 } 100 }
90 elsif ($addr =~ /^[_a-zA-Z]/) 101 elsif ($addr =~ /^[_a-z][_a-z0-9]*$/i)
91 { 102 {
92 $addr="_$addr"; 103 $addr="_$addr";
93 } 104 }
@@ -128,12 +139,14 @@ sub main'xorb { &out2("xor",@_); }
128sub main'add { &out2("add",@_); } 139sub main'add { &out2("add",@_); }
129sub main'adc { &out2("adc",@_); } 140sub main'adc { &out2("adc",@_); }
130sub main'sub { &out2("sub",@_); } 141sub main'sub { &out2("sub",@_); }
142sub main'sbb { &out2("sbb",@_); }
131sub main'rotl { &out2("rol",@_); } 143sub main'rotl { &out2("rol",@_); }
132sub main'rotr { &out2("ror",@_); } 144sub main'rotr { &out2("ror",@_); }
133sub main'exch { &out2("xchg",@_); } 145sub main'exch { &out2("xchg",@_); }
134sub main'cmp { &out2("cmp",@_); } 146sub main'cmp { &out2("cmp",@_); }
135sub main'lea { &out2("lea",@_); } 147sub main'lea { &out2("lea",@_); }
136sub main'mul { &out1("mul",@_); } 148sub main'mul { &out1("mul",@_); }
149sub main'imul { &out2("imul",@_); }
137sub main'div { &out1("div",@_); } 150sub main'div { &out1("div",@_); }
138sub main'dec { &out1("dec",@_); } 151sub main'dec { &out1("dec",@_); }
139sub main'inc { &out1("inc",@_); } 152sub main'inc { &out1("inc",@_); }
@@ -155,26 +168,54 @@ sub main'jne { &out1("jne",@_); }
155sub main'jno { &out1("jno",@_); } 168sub main'jno { &out1("jno",@_); }
156sub main'push { &out1("push",@_); $stack+=4; } 169sub main'push { &out1("push",@_); $stack+=4; }
157sub main'pop { &out1("pop",@_); $stack-=4; } 170sub main'pop { &out1("pop",@_); $stack-=4; }
171sub main'pushf { &out0("pushfd"); $stack+=4; }
172sub main'popf { &out0("popfd"); $stack-=4; }
158sub main'bswap { &out1("bswap",@_); &using486(); } 173sub main'bswap { &out1("bswap",@_); &using486(); }
159sub main'not { &out1("not",@_); } 174sub main'not { &out1("not",@_); }
160sub main'call { &out1("call",($_[0]=~/^\$L/?'':'_').$_[0]); } 175sub main'call { &out1("call",($_[0]=~/^\$L/?'':'_').$_[0]); }
176sub main'call_ptr { &out1p("call",@_); }
161sub main'ret { &out0("ret"); } 177sub main'ret { &out0("ret"); }
162sub main'nop { &out0("nop"); } 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"); }
163sub main'movz { &out2("movzx",@_); } 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",@_); }
164 204
165sub out2 205sub out2
166 { 206 {
167 local($name,$p1,$p2)=@_; 207 local($name,$p1,$p2)=@_;
168 local($l,$t); 208 local($l,$t,$line);
169 209
170 push(@out,"\t$name\t"); 210 $line="\t$name\t";
171 $t=&conv($p1).","; 211 $t=&conv($p1).",";
172 $l=length($t); 212 $l=length($t);
173 push(@out,$t); 213 $line.="$t";
174 $l=4-($l+9)/8; 214 $l=4-($l+9)/8;
175 push(@out,"\t" x $l); 215 $line.="\t" x $l;
176 push(@out,&conv($p2)); 216 $line.=&conv($p2);
177 push(@out,"\n"); 217 if ($line=~/\bxmm[0-7]\b/i) { $line=~s/\b[A-Z]+WORD\s+PTR/XMMWORD PTR/i; }
218 push(@out,$line."\n");
178 } 219 }
179 220
180sub out0 221sub out0
@@ -214,7 +255,9 @@ sub main'file
214 local($tmp)=<<"EOF"; 255 local($tmp)=<<"EOF";
215 TITLE $file.asm 256 TITLE $file.asm
216 .386 257 .386
217.model FLAT 258.model FLAT
259_TEXT\$ SEGMENT PAGE 'CODE'
260
218EOF 261EOF
219 push(@out,$tmp); 262 push(@out,$tmp);
220 } 263 }
@@ -226,7 +269,6 @@ sub main'function_begin
226 push(@labels,$func); 269 push(@labels,$func);
227 270
228 local($tmp)=<<"EOF"; 271 local($tmp)=<<"EOF";
229_TEXT SEGMENT
230PUBLIC _$func 272PUBLIC _$func
231$extra 273$extra
232_$func PROC NEAR 274_$func PROC NEAR
@@ -244,7 +286,6 @@ sub main'function_begin_B
244 local($func,$extra)=@_; 286 local($func,$extra)=@_;
245 287
246 local($tmp)=<<"EOF"; 288 local($tmp)=<<"EOF";
247_TEXT SEGMENT
248PUBLIC _$func 289PUBLIC _$func
249$extra 290$extra
250_$func PROC NEAR 291_$func PROC NEAR
@@ -264,7 +305,6 @@ sub main'function_end
264 pop ebp 305 pop ebp
265 ret 306 ret
266_$func ENDP 307_$func ENDP
267_TEXT ENDS
268EOF 308EOF
269 push(@out,$tmp); 309 push(@out,$tmp);
270 $stack=0; 310 $stack=0;
@@ -277,7 +317,6 @@ sub main'function_end_B
277 317
278 local($tmp)=<<"EOF"; 318 local($tmp)=<<"EOF";
279_$func ENDP 319_$func ENDP
280_TEXT ENDS
281EOF 320EOF
282 push(@out,$tmp); 321 push(@out,$tmp);
283 $stack=0; 322 $stack=0;
@@ -300,6 +339,20 @@ EOF
300 339
301sub main'file_end 340sub main'file_end
302 { 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");
303 push(@out,"END\n"); 356 push(@out,"END\n");
304 } 357 }
305 358
@@ -331,6 +384,12 @@ sub main'comment
331 } 384 }
332 } 385 }
333 386
387sub main'public_label
388 {
389 $label{$_[0]}="_$_[0]" if (!defined($label{$_[0]}));
390 push(@out,"PUBLIC\t$label{$_[0]}\n");
391 }
392
334sub main'label 393sub main'label
335 { 394 {
336 if (!defined($label{$_[0]})) 395 if (!defined($label{$_[0]}))
@@ -348,19 +407,37 @@ sub main'set_label
348 $label{$_[0]}="\$${label}${_[0]}"; 407 $label{$_[0]}="\$${label}${_[0]}";
349 $label++; 408 $label++;
350 } 409 }
410 if ($_[1]!=0 && $_[1]>1)
411 {
412 main'align($_[1]);
413 }
351 if((defined $_[2]) && ($_[2] == 1)) 414 if((defined $_[2]) && ($_[2] == 1))
352 { 415 {
353 push(@out,"$label{$_[0]}::\n"); 416 push(@out,"$label{$_[0]}::\n");
354 } 417 }
418 elsif ($label{$_[0]} !~ /^\$/)
419 {
420 push(@out,"$label{$_[0]}\tLABEL PTR\n");
421 }
355 else 422 else
356 { 423 {
357 push(@out,"$label{$_[0]}:\n"); 424 push(@out,"$label{$_[0]}:\n");
358 } 425 }
359 } 426 }
360 427
428sub main'data_byte
429 {
430 push(@out,"\tDB\t".join(',',@_)."\n");
431 }
432
361sub main'data_word 433sub main'data_word
362 { 434 {
363 push(@out,"\tDD\t$_[0]\n"); 435 push(@out,"\tDD\t".join(',',@_)."\n");
436 }
437
438sub main'align
439 {
440 push(@out,"\tALIGN\t$_[0]\n");
364 } 441 }
365 442
366sub out1p 443sub out1p
@@ -368,7 +445,7 @@ sub out1p
368 local($name,$p1)=@_; 445 local($name,$p1)=@_;
369 local($l,$t); 446 local($l,$t);
370 447
371 push(@out,"\t$name\t ".&conv($p1)."\n"); 448 push(@out,"\t$name\t".&conv($p1)."\n");
372 } 449 }
373 450
374sub main'picmeup 451sub main'picmeup
@@ -378,3 +455,18 @@ sub main'picmeup
378 } 455 }
379 456
380sub main'blindpop { &out1("pop",@_); } 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/x86nasm.pl b/src/lib/libcrypto/perlasm/x86nasm.pl
index 4bdb3fe180..fa38f89c09 100644
--- a/src/lib/libcrypto/perlasm/x86nasm.pl
+++ b/src/lib/libcrypto/perlasm/x86nasm.pl
@@ -3,6 +3,7 @@
3package x86nasm; 3package x86nasm;
4 4
5$label="L000"; 5$label="L000";
6$under=($main'netware)?'':'_';
6 7
7%lb=( 'eax', 'al', 8%lb=( 'eax', 'al',
8 'ebx', 'bl', 9 'ebx', 'bl',
@@ -32,7 +33,8 @@ sub main'external_label
32{ 33{
33 push(@labels,@_); 34 push(@labels,@_);
34 foreach (@_) { 35 foreach (@_) {
35 push(@out, "extern\t_$_\n"); 36 push(@out,".") if ($main'mwerks);
37 push(@out, "extern\t${under}$_\n");
36 } 38 }
37} 39}
38 40
@@ -58,14 +60,19 @@ sub main'DWP
58 &get_mem("DWORD",@_); 60 &get_mem("DWORD",@_);
59 } 61 }
60 62
63sub main'QWP
64 {
65 &get_mem("",@_);
66 }
67
61sub main'BC 68sub main'BC
62 { 69 {
63 return "BYTE @_"; 70 return (($main'mwerks)?"":"BYTE ")."@_";
64 } 71 }
65 72
66sub main'DWC 73sub main'DWC
67 { 74 {
68 return "DWORD @_"; 75 return (($main'mwerks)?"":"DWORD ")."@_";
69 } 76 }
70 77
71sub main'stack_push 78sub main'stack_push
@@ -86,16 +93,22 @@ sub get_mem
86 { 93 {
87 my($size,$addr,$reg1,$reg2,$idx)=@_; 94 my($size,$addr,$reg1,$reg2,$idx)=@_;
88 my($t,$post); 95 my($t,$post);
89 my($ret)="$size ["; 96 my($ret)=$size;
97 if ($ret ne "")
98 {
99 $ret .= " PTR" if ($main'mwerks);
100 $ret .= " ";
101 }
102 $ret .= "[";
90 $addr =~ s/^\s+//; 103 $addr =~ s/^\s+//;
91 if ($addr =~ /^(.+)\+(.+)$/) 104 if ($addr =~ /^(.+)\+(.+)$/)
92 { 105 {
93 $reg2=&conv($1); 106 $reg2=&conv($1);
94 $addr="_$2"; 107 $addr="$under$2";
95 } 108 }
96 elsif ($addr =~ /^[_a-zA-Z]/) 109 elsif ($addr =~ /^[_a-z][_a-z0-9]*$/i)
97 { 110 {
98 $addr="_$addr"; 111 $addr="$under$addr";
99 } 112 }
100 113
101 if ($addr =~ /^.+\-.+$/) { $addr="($addr)"; } 114 if ($addr =~ /^.+\-.+$/) { $addr="($addr)"; }
@@ -134,12 +147,14 @@ sub main'xorb { &out2("xor",@_); }
134sub main'add { &out2("add",@_); } 147sub main'add { &out2("add",@_); }
135sub main'adc { &out2("adc",@_); } 148sub main'adc { &out2("adc",@_); }
136sub main'sub { &out2("sub",@_); } 149sub main'sub { &out2("sub",@_); }
150sub main'sbb { &out2("sbb",@_); }
137sub main'rotl { &out2("rol",@_); } 151sub main'rotl { &out2("rol",@_); }
138sub main'rotr { &out2("ror",@_); } 152sub main'rotr { &out2("ror",@_); }
139sub main'exch { &out2("xchg",@_); } 153sub main'exch { &out2("xchg",@_); }
140sub main'cmp { &out2("cmp",@_); } 154sub main'cmp { &out2("cmp",@_); }
141sub main'lea { &out2("lea",@_); } 155sub main'lea { &out2("lea",@_); }
142sub main'mul { &out1("mul",@_); } 156sub main'mul { &out1("mul",@_); }
157sub main'imul { &out2("imul",@_); }
143sub main'div { &out1("div",@_); } 158sub main'div { &out1("div",@_); }
144sub main'dec { &out1("dec",@_); } 159sub main'dec { &out1("dec",@_); }
145sub main'inc { &out1("inc",@_); } 160sub main'inc { &out1("inc",@_); }
@@ -147,29 +162,57 @@ sub main'jmp { &out1("jmp",@_); }
147sub main'jmp_ptr { &out1p("jmp",@_); } 162sub main'jmp_ptr { &out1p("jmp",@_); }
148 163
149# This is a bit of a kludge: declare all branches as NEAR. 164# This is a bit of a kludge: declare all branches as NEAR.
150sub main'je { &out1("je NEAR",@_); } 165$near=($main'mwerks)?'':'NEAR';
151sub main'jle { &out1("jle NEAR",@_); } 166sub main'je { &out1("je $near",@_); }
152sub main'jz { &out1("jz NEAR",@_); } 167sub main'jle { &out1("jle $near",@_); }
153sub main'jge { &out1("jge NEAR",@_); } 168sub main'jz { &out1("jz $near",@_); }
154sub main'jl { &out1("jl NEAR",@_); } 169sub main'jge { &out1("jge $near",@_); }
155sub main'ja { &out1("ja NEAR",@_); } 170sub main'jl { &out1("jl $near",@_); }
156sub main'jae { &out1("jae NEAR",@_); } 171sub main'ja { &out1("ja $near",@_); }
157sub main'jb { &out1("jb NEAR",@_); } 172sub main'jae { &out1("jae $near",@_); }
158sub main'jbe { &out1("jbe NEAR",@_); } 173sub main'jb { &out1("jb $near",@_); }
159sub main'jc { &out1("jc NEAR",@_); } 174sub main'jbe { &out1("jbe $near",@_); }
160sub main'jnc { &out1("jnc NEAR",@_); } 175sub main'jc { &out1("jc $near",@_); }
161sub main'jnz { &out1("jnz NEAR",@_); } 176sub main'jnc { &out1("jnc $near",@_); }
162sub main'jne { &out1("jne NEAR",@_); } 177sub main'jnz { &out1("jnz $near",@_); }
163sub main'jno { &out1("jno NEAR",@_); } 178sub main'jne { &out1("jne $near",@_); }
179sub main'jno { &out1("jno $near",@_); }
164 180
165sub main'push { &out1("push",@_); $stack+=4; } 181sub main'push { &out1("push",@_); $stack+=4; }
166sub main'pop { &out1("pop",@_); $stack-=4; } 182sub main'pop { &out1("pop",@_); $stack-=4; }
183sub main'pushf { &out0("pushfd"); $stack+=4; }
184sub main'popf { &out0("popfd"); $stack-=4; }
167sub main'bswap { &out1("bswap",@_); &using486(); } 185sub main'bswap { &out1("bswap",@_); &using486(); }
168sub main'not { &out1("not",@_); } 186sub main'not { &out1("not",@_); }
169sub main'call { &out1("call",($_[0]=~/^\$L/?'':'_').$_[0]); } 187sub main'call { &out1("call",($_[0]=~/^\@L/?'':$under).$_[0]); }
188sub main'call_ptr { &out1p("call",@_); }
170sub main'ret { &out0("ret"); } 189sub main'ret { &out0("ret"); }
171sub main'nop { &out0("nop"); } 190sub main'nop { &out0("nop"); }
191sub main'test { &out2("test",@_); }
192sub main'bt { &out2("bt",@_); }
193sub main'leave { &out0("leave"); }
194sub main'cpuid { &out0("cpuid"); }
195sub main'rdtsc { &out0("rdtsc"); }
196sub main'halt { &out0("hlt"); }
172sub main'movz { &out2("movzx",@_); } 197sub main'movz { &out2("movzx",@_); }
198sub main'neg { &out1("neg",@_); }
199sub main'cld { &out0("cld"); }
200
201# SSE2
202sub main'emms { &out0("emms"); }
203sub main'movd { &out2("movd",@_); }
204sub main'movq { &out2("movq",@_); }
205sub main'movdqu { &out2("movdqu",@_); }
206sub main'movdqa { &out2("movdqa",@_); }
207sub main'movdq2q{ &out2("movdq2q",@_); }
208sub main'movq2dq{ &out2("movq2dq",@_); }
209sub main'paddq { &out2("paddq",@_); }
210sub main'pmuludq{ &out2("pmuludq",@_); }
211sub main'psrlq { &out2("psrlq",@_); }
212sub main'psllq { &out2("psllq",@_); }
213sub main'pxor { &out2("pxor",@_); }
214sub main'por { &out2("por",@_); }
215sub main'pand { &out2("pand",@_); }
173 216
174sub out2 217sub out2
175 { 218 {
@@ -177,7 +220,7 @@ sub out2
177 my($l,$t); 220 my($l,$t);
178 221
179 push(@out,"\t$name\t"); 222 push(@out,"\t$name\t");
180 if ($name eq "lea") 223 if (!$main'mwerks and $name eq "lea")
181 { 224 {
182 $p1 =~ s/^[^\[]*\[/\[/; 225 $p1 =~ s/^[^\[]*\[/\[/;
183 $p2 =~ s/^[^\[]*\[/\[/; 226 $p2 =~ s/^[^\[]*\[/\[/;
@@ -221,15 +264,17 @@ sub using486
221 264
222sub main'file 265sub main'file
223 { 266 {
224 local $tmp; 267 if ($main'mwerks) { push(@out,".section\t.text\n"); }
225 $tmp=<<___; 268 else {
269 local $tmp=<<___;
226%ifdef __omf__ 270%ifdef __omf__
227section code use32 class=code 271section code use32 class=code
228%else 272%else
229section .text 273section .text
230%endif 274%endif
231___ 275___
232 push(@out,$tmp); 276 push(@out,$tmp);
277 }
233 } 278 }
234 279
235sub main'function_begin 280sub main'function_begin
@@ -237,9 +282,10 @@ sub main'function_begin
237 my($func,$extra)=@_; 282 my($func,$extra)=@_;
238 283
239 push(@labels,$func); 284 push(@labels,$func);
285 push(@out,".") if ($main'mwerks);
240 my($tmp)=<<"EOF"; 286 my($tmp)=<<"EOF";
241global _$func 287global $under$func
242_$func: 288$under$func:
243 push ebp 289 push ebp
244 push ebx 290 push ebx
245 push esi 291 push esi
@@ -252,9 +298,10 @@ EOF
252sub main'function_begin_B 298sub main'function_begin_B
253 { 299 {
254 my($func,$extra)=@_; 300 my($func,$extra)=@_;
301 push(@out,".") if ($main'mwerks);
255 my($tmp)=<<"EOF"; 302 my($tmp)=<<"EOF";
256global _$func 303global $under$func
257_$func: 304$under$func:
258EOF 305EOF
259 push(@out,$tmp); 306 push(@out,$tmp);
260 $stack=4; 307 $stack=4;
@@ -328,11 +375,18 @@ sub main'comment
328 } 375 }
329 } 376 }
330 377
378sub main'public_label
379 {
380 $label{$_[0]}="${under}${_[0]}" if (!defined($label{$_[0]}));
381 push(@out,".") if ($main'mwerks);
382 push(@out,"global\t$label{$_[0]}\n");
383 }
384
331sub main'label 385sub main'label
332 { 386 {
333 if (!defined($label{$_[0]})) 387 if (!defined($label{$_[0]}))
334 { 388 {
335 $label{$_[0]}="\$${label}${_[0]}"; 389 $label{$_[0]}="\@${label}${_[0]}";
336 $label++; 390 $label++;
337 } 391 }
338 return($label{$_[0]}); 392 return($label{$_[0]});
@@ -342,15 +396,30 @@ sub main'set_label
342 { 396 {
343 if (!defined($label{$_[0]})) 397 if (!defined($label{$_[0]}))
344 { 398 {
345 $label{$_[0]}="\$${label}${_[0]}"; 399 $label{$_[0]}="\@${label}${_[0]}";
346 $label++; 400 $label++;
347 } 401 }
402 if ($_[1]!=0 && $_[1]>1)
403 {
404 main'align($_[1]);
405 }
348 push(@out,"$label{$_[0]}:\n"); 406 push(@out,"$label{$_[0]}:\n");
349 } 407 }
350 408
409sub main'data_byte
410 {
411 push(@out,(($main'mwerks)?".byte\t":"DB\t").join(',',@_)."\n");
412 }
413
351sub main'data_word 414sub main'data_word
352 { 415 {
353 push(@out,"\tDD\t$_[0]\n"); 416 push(@out,(($main'mwerks)?".long\t":"DD\t").join(',',@_)."\n");
417 }
418
419sub main'align
420 {
421 push(@out,".") if ($main'mwerks);
422 push(@out,"align\t$_[0]\n");
354 } 423 }
355 424
356sub out1p 425sub out1p
@@ -358,7 +427,7 @@ sub out1p
358 my($name,$p1)=@_; 427 my($name,$p1)=@_;
359 my($l,$t); 428 my($l,$t);
360 429
361 push(@out,"\t$name\t ".&conv($p1)."\n"); 430 push(@out,"\t$name\t".&conv($p1)."\n");
362 } 431 }
363 432
364sub main'picmeup 433sub main'picmeup
@@ -368,3 +437,19 @@ sub main'picmeup
368 } 437 }
369 438
370sub main'blindpop { &out1("pop",@_); } 439sub main'blindpop { &out1("pop",@_); }
440
441sub main'initseg
442 {
443 local($f)=@_;
444 if ($main'win32)
445 {
446 local($tmp)=<<___;
447segment .CRT\$XCU data
448extern $under$f
449DD $under$f
450___
451 push(@out,$tmp);
452 }
453 }
454
4551;
diff --git a/src/lib/libcrypto/perlasm/x86unix.pl b/src/lib/libcrypto/perlasm/x86unix.pl
index a31a25c12b..a4c947165e 100644
--- a/src/lib/libcrypto/perlasm/x86unix.pl
+++ b/src/lib/libcrypto/perlasm/x86unix.pl
@@ -1,14 +1,15 @@
1#!/usr/local/bin/perl 1#!/usr/local/bin/perl
2 2
3package x86unix; 3package x86unix; # GAS actually...
4 4
5$label="L000"; 5$label="L000";
6$const=""; 6$const="";
7$constl=0; 7$constl=0;
8 8
9$align=($main'aout)?"4":"16"; 9$align=($main'aout)?"4":"16";
10$under=($main'aout)?"_":""; 10$under=($main'aout or $main'coff)?"_":"";
11$com_start=($main'sol)?"/":"#"; 11$dot=($main'aout)?"":".";
12$com_start="#" if ($main'aout or $main'coff);
12 13
13sub main'asm_init_output { @out=(); } 14sub main'asm_init_output { @out=(); }
14sub main'asm_get_output { return(@out); } 15sub main'asm_get_output { return(@out); }
@@ -51,6 +52,24 @@ if ($main'cpp)
51 'edi', '%edi', 52 'edi', '%edi',
52 'ebp', '%ebp', 53 'ebp', '%ebp',
53 'esp', '%esp', 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',
54 ); 73 );
55 74
56%reg_val=( 75%reg_val=(
@@ -97,6 +116,11 @@ sub main'DWP
97 return($ret); 116 return($ret);
98 } 117 }
99 118
119sub main'QWP
120 {
121 return(&main'DWP(@_));
122 }
123
100sub main'BP 124sub main'BP
101 { 125 {
102 return(&main'DWP(@_)); 126 return(&main'DWP(@_));
@@ -140,12 +164,14 @@ sub main'xorb { &out2("xorb",@_); }
140sub main'add { &out2($_[0]=~/%[a-d][lh]/?"addb":"addl",@_); } 164sub main'add { &out2($_[0]=~/%[a-d][lh]/?"addb":"addl",@_); }
141sub main'adc { &out2("adcl",@_); } 165sub main'adc { &out2("adcl",@_); }
142sub main'sub { &out2("subl",@_); } 166sub main'sub { &out2("subl",@_); }
167sub main'sbb { &out2("sbbl",@_); }
143sub main'rotl { &out2("roll",@_); } 168sub main'rotl { &out2("roll",@_); }
144sub main'rotr { &out2("rorl",@_); } 169sub main'rotr { &out2("rorl",@_); }
145sub main'exch { &out2($_[0]=~/%[a-d][lh]/?"xchgb":"xchgl",@_); } 170sub main'exch { &out2($_[0]=~/%[a-d][lh]/?"xchgb":"xchgl",@_); }
146sub main'cmp { &out2("cmpl",@_); } 171sub main'cmp { &out2("cmpl",@_); }
147sub main'lea { &out2("leal",@_); } 172sub main'lea { &out2("leal",@_); }
148sub main'mul { &out1("mull",@_); } 173sub main'mul { &out1("mull",@_); }
174sub main'imul { &out2("imull",@_); }
149sub main'div { &out1("divl",@_); } 175sub main'div { &out1("divl",@_); }
150sub main'jmp { &out1("jmp",@_); } 176sub main'jmp { &out1("jmp",@_); }
151sub main'jmp_ptr { &out1p("jmp",@_); } 177sub main'jmp_ptr { &out1p("jmp",@_); }
@@ -167,13 +193,48 @@ sub main'dec { &out1("decl",@_); }
167sub main'inc { &out1($_[0]=~/%[a-d][hl]/?"incb":"incl",@_); } 193sub main'inc { &out1($_[0]=~/%[a-d][hl]/?"incb":"incl",@_); }
168sub main'push { &out1("pushl",@_); $stack+=4; } 194sub main'push { &out1("pushl",@_); $stack+=4; }
169sub main'pop { &out1("popl",@_); $stack-=4; } 195sub main'pop { &out1("popl",@_); $stack-=4; }
170sub main'pushf { &out0("pushf"); $stack+=4; } 196sub main'pushf { &out0("pushfl"); $stack+=4; }
171sub main'popf { &out0("popf"); $stack-=4; } 197sub main'popf { &out0("popfl"); $stack-=4; }
172sub main'not { &out1("notl",@_); } 198sub main'not { &out1("notl",@_); }
173sub main'call { &out1("call",($_[0]=~/^\.L/?'':$under).$_[0]); } 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",@_); }
174sub main'ret { &out0("ret"); } 205sub main'ret { &out0("ret"); }
175sub main'nop { &out0("nop"); } 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"); }
176sub main'movz { &out2("movzbl",@_); } 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 }
177 238
178# The bswapl instruction is new for the 486. Emulate if i386. 239# The bswapl instruction is new for the 486. Emulate if i386.
179sub main'bswap 240sub main'bswap
@@ -279,8 +340,6 @@ sub main'file
279 340
280 local($tmp)=<<"EOF"; 341 local($tmp)=<<"EOF";
281 .file "$file.s" 342 .file "$file.s"
282 .version "01.01"
283gcc2_compiled.:
284EOF 343EOF
285 push(@out,$tmp); 344 push(@out,$tmp);
286 } 345 }
@@ -294,15 +353,17 @@ sub main'function_begin
294 353
295 local($tmp)=<<"EOF"; 354 local($tmp)=<<"EOF";
296.text 355.text
297 .align $align 356.globl $func
298.globl $func
299EOF 357EOF
300 push(@out,$tmp); 358 push(@out,$tmp);
301 if ($main'cpp) 359 if ($main'cpp)
302 { $tmp=push(@out,"\tTYPE($func,\@function)\n"); } 360 { $tmp=push(@out,"TYPE($func,\@function)\n"); }
303 elsif ($main'gaswin) 361 elsif ($main'coff)
304 { $tmp=push(@out,"\t.def\t$func;\t.scl\t2;\t.type\t32;\t.endef\n"); } 362 { $tmp=push(@out,".def\t$func;\t.scl\t2;\t.type\t32;\t.endef\n"); }
305 else { $tmp=push(@out,"\t.type\t$func,\@function\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");
306 push(@out,"$func:\n"); 367 push(@out,"$func:\n");
307 $tmp=<<"EOF"; 368 $tmp=<<"EOF";
308 pushl %ebp 369 pushl %ebp
@@ -324,15 +385,17 @@ sub main'function_begin_B
324 385
325 local($tmp)=<<"EOF"; 386 local($tmp)=<<"EOF";
326.text 387.text
327 .align $align 388.globl $func
328.globl $func
329EOF 389EOF
330 push(@out,$tmp); 390 push(@out,$tmp);
331 if ($main'cpp) 391 if ($main'cpp)
332 { push(@out,"\tTYPE($func,\@function)\n"); } 392 { push(@out,"TYPE($func,\@function)\n"); }
333 elsif ($main'gaswin) 393 elsif ($main'coff)
334 { $tmp=push(@out,"\t.def\t$func;\t.scl\t2;\t.type\t32;\t.endef\n"); } 394 { $tmp=push(@out,".def\t$func;\t.scl\t2;\t.type\t32;\t.endef\n"); }
335 else { push(@out,"\t.type $func,\@function\n"); } 395 elsif ($main'aout and !$main'pic)
396 { }
397 else { push(@out,".type $func,\@function\n"); }
398 push(@out,".align\t$align\n");
336 push(@out,"$func:\n"); 399 push(@out,"$func:\n");
337 $stack=4; 400 $stack=4;
338 } 401 }
@@ -349,15 +412,15 @@ sub main'function_end
349 popl %ebx 412 popl %ebx
350 popl %ebp 413 popl %ebp
351 ret 414 ret
352.L_${func}_end: 415${dot}L_${func}_end:
353EOF 416EOF
354 push(@out,$tmp); 417 push(@out,$tmp);
355 418
356 if ($main'cpp) 419 if ($main'cpp)
357 { push(@out,"\tSIZE($func,.L_${func}_end-$func)\n"); } 420 { push(@out,"SIZE($func,${dot}L_${func}_end-$func)\n"); }
358 elsif ($main'gaswin) 421 elsif ($main'coff or $main'aout)
359 { $tmp=push(@out,"\t.align 4\n"); } 422 { }
360 else { push(@out,"\t.size\t$func,.L_${func}_end-$func\n"); } 423 else { push(@out,".size\t$func,${dot}L_${func}_end-$func\n"); }
361 push(@out,".ident \"$func\"\n"); 424 push(@out,".ident \"$func\"\n");
362 $stack=0; 425 $stack=0;
363 %label=(); 426 %label=();
@@ -383,13 +446,13 @@ sub main'function_end_B
383 446
384 $func=$under.$func; 447 $func=$under.$func;
385 448
386 push(@out,".L_${func}_end:\n"); 449 push(@out,"${dot}L_${func}_end:\n");
387 if ($main'cpp) 450 if ($main'cpp)
388 { push(@out,"\tSIZE($func,.L_${func}_end-$func)\n"); } 451 { push(@out,"SIZE($func,${dot}L_${func}_end-$func)\n"); }
389 elsif ($main'gaswin) 452 elsif ($main'coff or $main'aout)
390 { push(@out,"\t.align 4\n"); } 453 { }
391 else { push(@out,"\t.size\t$func,.L_${func}_end-$func\n"); } 454 else { push(@out,".size\t$func,${dot}L_${func}_end-$func\n"); }
392 push(@out,".ident \"desasm.pl\"\n"); 455 push(@out,".ident \"$func\"\n");
393 $stack=0; 456 $stack=0;
394 %label=(); 457 %label=();
395 } 458 }
@@ -430,9 +493,10 @@ sub main'swtmp
430 493
431sub main'comment 494sub main'comment
432 { 495 {
433 if ($main'elf) # GNU and SVR4 as'es use different comment delimiters, 496 if (!defined($com_start) or $main'elf)
434 { # so we just skip comments... 497 { # Regarding $main'elf above...
435 push(@out,"\n"); 498 # GNU and SVR4 as'es use different comment delimiters,
499 push(@out,"\n"); # so we just skip ELF comments...
436 return; 500 return;
437 } 501 }
438 foreach (@_) 502 foreach (@_)
@@ -444,11 +508,17 @@ sub main'comment
444 } 508 }
445 } 509 }
446 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
447sub main'label 517sub main'label
448 { 518 {
449 if (!defined($label{$_[0]})) 519 if (!defined($label{$_[0]}))
450 { 520 {
451 $label{$_[0]}=".${label}${_[0]}"; 521 $label{$_[0]}="${dot}${label}${_[0]}";
452 $label++; 522 $label++;
453 } 523 }
454 return($label{$_[0]}); 524 return($label{$_[0]});
@@ -458,15 +528,29 @@ sub main'set_label
458 { 528 {
459 if (!defined($label{$_[0]})) 529 if (!defined($label{$_[0]}))
460 { 530 {
461 $label{$_[0]}=".${label}${_[0]}"; 531 $label{$_[0]}="${dot}${label}${_[0]}";
462 $label++; 532 $label++;
463 } 533 }
464 push(@out,".align $align\n") if ($_[1] != 0); 534 if ($_[1]!=0)
535 {
536 if ($_[1]>1) { main'align($_[1]); }
537 else { push(@out,".align $align\n"); }
538 }
465 push(@out,"$label{$_[0]}:\n"); 539 push(@out,"$label{$_[0]}:\n");
466 } 540 }
467 541
468sub main'file_end 542sub main'file_end
469 { 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
470 if ($const ne "") 554 if ($const ne "")
471 { 555 {
472 push(@out,".section .rodata\n"); 556 push(@out,".section .rodata\n");
@@ -475,9 +559,25 @@ sub main'file_end
475 } 559 }
476 } 560 }
477 561
562sub main'data_byte
563 {
564 push(@out,"\t.byte\t".join(',',@_)."\n");
565 }
566
478sub main'data_word 567sub main'data_word
479 { 568 {
480 push(@out,"\t.long $_[0]\n"); 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");
481 } 581 }
482 582
483# debug output functions: puts, putx, printf 583# debug output functions: puts, putx, printf
@@ -559,7 +659,6 @@ sub main'picmeup
559 { 659 {
560 local($tmp)=<<___; 660 local($tmp)=<<___;
561#if (defined(ELF) || defined(SOL)) && defined(PIC) 661#if (defined(ELF) || defined(SOL)) && defined(PIC)
562 .align 8
563 call 1f 662 call 1f
5641: popl $regs{$dst} 6631: popl $regs{$dst}
565 addl \$_GLOBAL_OFFSET_TABLE_+[.-1b],$regs{$dst} 664 addl \$_GLOBAL_OFFSET_TABLE_+[.-1b],$regs{$dst}
@@ -572,13 +671,12 @@ ___
572 } 671 }
573 elsif ($main'pic && ($main'elf || $main'aout)) 672 elsif ($main'pic && ($main'elf || $main'aout))
574 { 673 {
575 push(@out,"\t.align\t8\n");
576 &main'call(&main'label("PIC_me_up")); 674 &main'call(&main'label("PIC_me_up"));
577 &main'set_label("PIC_me_up"); 675 &main'set_label("PIC_me_up");
578 &main'blindpop($dst); 676 &main'blindpop($dst);
579 &main'add($dst,"\$$under"."_GLOBAL_OFFSET_TABLE_+[.-". 677 &main'add($dst,"\$${under}_GLOBAL_OFFSET_TABLE_+[.-".
580 &main'label("PIC_me_up") . "]"); 678 &main'label("PIC_me_up") . "]");
581 &main'mov($dst,&main'DWP($sym."\@GOT",$dst)); 679 &main'mov($dst,&main'DWP($under.$sym."\@GOT",$dst));
582 } 680 }
583 else 681 else
584 { 682 {
@@ -587,3 +685,41 @@ ___
587 } 685 }
588 686
589sub main'blindpop { &out1("popl",@_); } 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;