summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/perlasm/x86unix.pl
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/perlasm/x86unix.pl')
-rw-r--r--src/lib/libcrypto/perlasm/x86unix.pl251
1 files changed, 77 insertions, 174 deletions
diff --git a/src/lib/libcrypto/perlasm/x86unix.pl b/src/lib/libcrypto/perlasm/x86unix.pl
index a4c947165e..b61425e951 100644
--- a/src/lib/libcrypto/perlasm/x86unix.pl
+++ b/src/lib/libcrypto/perlasm/x86unix.pl
@@ -1,21 +1,26 @@
1#!/usr/local/bin/perl 1#!/usr/local/bin/perl
2 2
3package x86unix; # GAS actually... 3package x86unix;
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 or $main'coff)?"_":""; 10$under=($main'aout)?"_":"";
11$dot=($main'aout)?"":"."; 11$com_start=($main'sol)?"/":"#";
12$com_start="#" if ($main'aout or $main'coff);
13 12
14sub main'asm_init_output { @out=(); } 13sub main'asm_init_output { @out=(); }
15sub main'asm_get_output { return(@out); } 14sub main'asm_get_output { return(@out); }
16sub main'get_labels { return(@labels); } 15sub main'get_labels { return(@labels); }
17sub main'external_label { push(@labels,@_); } 16sub main'external_label { push(@labels,@_); }
18 17
18if ($main'openbsd)
19 {
20 $com_start='/*';
21 $com_end='*/';
22 }
23
19if ($main'cpp) 24if ($main'cpp)
20 { 25 {
21 $align="ALIGN"; 26 $align="ALIGN";
@@ -52,24 +57,6 @@ if ($main'cpp)
52 'edi', '%edi', 57 'edi', '%edi',
53 'ebp', '%ebp', 58 'ebp', '%ebp',
54 'esp', '%esp', 59 '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 ); 60 );
74 61
75%reg_val=( 62%reg_val=(
@@ -116,11 +103,6 @@ sub main'DWP
116 return($ret); 103 return($ret);
117 } 104 }
118 105
119sub main'QWP
120 {
121 return(&main'DWP(@_));
122 }
123
124sub main'BP 106sub main'BP
125 { 107 {
126 return(&main'DWP(@_)); 108 return(&main'DWP(@_));
@@ -164,14 +146,12 @@ sub main'xorb { &out2("xorb",@_); }
164sub main'add { &out2($_[0]=~/%[a-d][lh]/?"addb":"addl",@_); } 146sub main'add { &out2($_[0]=~/%[a-d][lh]/?"addb":"addl",@_); }
165sub main'adc { &out2("adcl",@_); } 147sub main'adc { &out2("adcl",@_); }
166sub main'sub { &out2("subl",@_); } 148sub main'sub { &out2("subl",@_); }
167sub main'sbb { &out2("sbbl",@_); }
168sub main'rotl { &out2("roll",@_); } 149sub main'rotl { &out2("roll",@_); }
169sub main'rotr { &out2("rorl",@_); } 150sub main'rotr { &out2("rorl",@_); }
170sub main'exch { &out2($_[0]=~/%[a-d][lh]/?"xchgb":"xchgl",@_); } 151sub main'exch { &out2($_[0]=~/%[a-d][lh]/?"xchgb":"xchgl",@_); }
171sub main'cmp { &out2("cmpl",@_); } 152sub main'cmp { &out2("cmpl",@_); }
172sub main'lea { &out2("leal",@_); } 153sub main'lea { &out2("leal",@_); }
173sub main'mul { &out1("mull",@_); } 154sub main'mul { &out1("mull",@_); }
174sub main'imul { &out2("imull",@_); }
175sub main'div { &out1("divl",@_); } 155sub main'div { &out1("divl",@_); }
176sub main'jmp { &out1("jmp",@_); } 156sub main'jmp { &out1("jmp",@_); }
177sub main'jmp_ptr { &out1p("jmp",@_); } 157sub main'jmp_ptr { &out1p("jmp",@_); }
@@ -193,48 +173,15 @@ sub main'dec { &out1("decl",@_); }
193sub main'inc { &out1($_[0]=~/%[a-d][hl]/?"incb":"incl",@_); } 173sub main'inc { &out1($_[0]=~/%[a-d][hl]/?"incb":"incl",@_); }
194sub main'push { &out1("pushl",@_); $stack+=4; } 174sub main'push { &out1("pushl",@_); $stack+=4; }
195sub main'pop { &out1("popl",@_); $stack-=4; } 175sub main'pop { &out1("popl",@_); $stack-=4; }
196sub main'pushf { &out0("pushfl"); $stack+=4; } 176sub main'pushf { &out0("pushf"); $stack+=4; }
197sub main'popf { &out0("popfl"); $stack-=4; } 177sub main'popf { &out0("popf"); $stack-=4; }
198sub main'not { &out1("notl",@_); } 178sub main'not { &out1("notl",@_); }
199sub main'call { my $pre=$under; 179sub main'call { &out1("call",($_[0]=~/^\.L/?'':$under).$_[0]); }
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"); } 180sub main'ret { &out0("ret"); }
206sub main'nop { &out0("nop"); } 181sub main'nop { &out0("nop"); }
207sub main'test { &out2("testl",@_); } 182sub 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",@_); } 183sub main'movz { &out2("movzbl",@_); }
214sub main'neg { &out1("negl",@_); } 184sub 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 185
239# The bswapl instruction is new for the 486. Emulate if i386. 186# The bswapl instruction is new for the 486. Emulate if i386.
240sub main'bswap 187sub main'bswap
@@ -338,8 +285,13 @@ sub main'file
338 { 285 {
339 local($file)=@_; 286 local($file)=@_;
340 287
288 if ($main'openbsd)
289 { push(@out,"#include <machine/asm.h>\n"); return; }
290
341 local($tmp)=<<"EOF"; 291 local($tmp)=<<"EOF";
342 .file "$file.s" 292 .file "$file.s"
293 .version "01.01"
294gcc2_compiled.:
343EOF 295EOF
344 push(@out,$tmp); 296 push(@out,$tmp);
345 } 297 }
@@ -351,20 +303,22 @@ sub main'function_begin
351 &main'external_label($func); 303 &main'external_label($func);
352 $func=$under.$func; 304 $func=$under.$func;
353 305
306 if ($main'openbsd)
307 { push (@out, "\nENTRY($func)\n"); goto skip; }
308
354 local($tmp)=<<"EOF"; 309 local($tmp)=<<"EOF";
355.text 310.text
356.globl $func 311 .align $align
312.globl $func
357EOF 313EOF
358 push(@out,$tmp); 314 push(@out,$tmp);
359 if ($main'cpp) 315 if ($main'cpp)
360 { $tmp=push(@out,"TYPE($func,\@function)\n"); } 316 { $tmp=push(@out,"\tTYPE($func,\@function)\n"); }
361 elsif ($main'coff) 317 elsif ($main'gaswin)
362 { $tmp=push(@out,".def\t$func;\t.scl\t2;\t.type\t32;\t.endef\n"); } 318 { $tmp=push(@out,"\t.def\t$func;\t.scl\t2;\t.type\t32;\t.endef\n"); }
363 elsif ($main'aout and !$main'pic) 319 else { $tmp=push(@out,"\t.type\t$func,\@function\n"); }
364 { }
365 else { $tmp=push(@out,".type\t$func,\@function\n"); }
366 push(@out,".align\t$align\n");
367 push(@out,"$func:\n"); 320 push(@out,"$func:\n");
321skip:
368 $tmp=<<"EOF"; 322 $tmp=<<"EOF";
369 pushl %ebp 323 pushl %ebp
370 pushl %ebx 324 pushl %ebx
@@ -383,20 +337,22 @@ sub main'function_begin_B
383 &main'external_label($func); 337 &main'external_label($func);
384 $func=$under.$func; 338 $func=$under.$func;
385 339
340 if ($main'openbsd)
341 { push(@out, "\nENTRY($func)\n"); goto skip; }
342
386 local($tmp)=<<"EOF"; 343 local($tmp)=<<"EOF";
387.text 344.text
388.globl $func 345 .align $align
346.globl $func
389EOF 347EOF
390 push(@out,$tmp); 348 push(@out,$tmp);
391 if ($main'cpp) 349 if ($main'cpp)
392 { push(@out,"TYPE($func,\@function)\n"); } 350 { push(@out,"\tTYPE($func,\@function)\n"); }
393 elsif ($main'coff) 351 elsif ($main'gaswin)
394 { $tmp=push(@out,".def\t$func;\t.scl\t2;\t.type\t32;\t.endef\n"); } 352 { $tmp=push(@out,"\t.def\t$func;\t.scl\t2;\t.type\t32;\t.endef\n"); }
395 elsif ($main'aout and !$main'pic) 353 else { push(@out,"\t.type $func,\@function\n"); }
396 { }
397 else { push(@out,".type $func,\@function\n"); }
398 push(@out,".align\t$align\n");
399 push(@out,"$func:\n"); 354 push(@out,"$func:\n");
355skip:
400 $stack=4; 356 $stack=4;
401 } 357 }
402 358
@@ -412,15 +368,15 @@ sub main'function_end
412 popl %ebx 368 popl %ebx
413 popl %ebp 369 popl %ebp
414 ret 370 ret
415${dot}L_${func}_end: 371.L_${func}_end:
416EOF 372EOF
417 push(@out,$tmp); 373 push(@out,$tmp);
418 374
419 if ($main'cpp) 375 if ($main'cpp)
420 { push(@out,"SIZE($func,${dot}L_${func}_end-$func)\n"); } 376 { push(@out,"\tSIZE($func,.L_${func}_end-$func)\n"); }
421 elsif ($main'coff or $main'aout) 377 elsif ($main'gaswin)
422 { } 378 { $tmp=push(@out,"\t.align 4\n"); }
423 else { push(@out,".size\t$func,${dot}L_${func}_end-$func\n"); } 379 else { push(@out,"\t.size\t$func,.L_${func}_end-$func\n"); }
424 push(@out,".ident \"$func\"\n"); 380 push(@out,".ident \"$func\"\n");
425 $stack=0; 381 $stack=0;
426 %label=(); 382 %label=();
@@ -446,13 +402,13 @@ sub main'function_end_B
446 402
447 $func=$under.$func; 403 $func=$under.$func;
448 404
449 push(@out,"${dot}L_${func}_end:\n"); 405 push(@out,".L_${func}_end:\n");
450 if ($main'cpp) 406 if ($main'cpp)
451 { push(@out,"SIZE($func,${dot}L_${func}_end-$func)\n"); } 407 { push(@out,"\tSIZE($func,.L_${func}_end-$func)\n"); }
452 elsif ($main'coff or $main'aout) 408 elsif ($main'gaswin)
453 { } 409 { push(@out,"\t.align 4\n"); }
454 else { push(@out,".size\t$func,${dot}L_${func}_end-$func\n"); } 410 else { push(@out,"\t.size\t$func,.L_${func}_end-$func\n"); }
455 push(@out,".ident \"$func\"\n"); 411 push(@out,".ident \"desasm.pl\"\n");
456 $stack=0; 412 $stack=0;
457 %label=(); 413 %label=();
458 } 414 }
@@ -493,10 +449,10 @@ sub main'swtmp
493 449
494sub main'comment 450sub main'comment
495 { 451 {
496 if (!defined($com_start) or $main'elf) 452 if (!$main'openbsd && $main'elf)
497 { # Regarding $main'elf above...
498 # GNU and SVR4 as'es use different comment delimiters, 453 # GNU and SVR4 as'es use different comment delimiters,
499 push(@out,"\n"); # so we just skip ELF comments... 454 { # so we just skip comments...
455 push(@out,"\n");
500 return; 456 return;
501 } 457 }
502 foreach (@_) 458 foreach (@_)
@@ -509,16 +465,16 @@ sub main'comment
509 } 465 }
510 466
511sub main'public_label 467sub main'public_label
512 { 468 {
513 $label{$_[0]}="${under}${_[0]}" if (!defined($label{$_[0]})); 469 $label{$_[0]}="${under}${_[0]}" if (!defined($label{$_[0]}));
514 push(@out,".globl\t$label{$_[0]}\n"); 470 push(@out,".globl\t$label{$_[0]}\n");
515 } 471 }
516 472
517sub main'label 473sub main'label
518 { 474 {
519 if (!defined($label{$_[0]})) 475 if (!defined($label{$_[0]}))
520 { 476 {
521 $label{$_[0]}="${dot}${label}${_[0]}"; 477 $label{$_[0]}=".${label}${_[0]}";
522 $label++; 478 $label++;
523 } 479 }
524 return($label{$_[0]}); 480 return($label{$_[0]});
@@ -528,29 +484,18 @@ sub main'set_label
528 { 484 {
529 if (!defined($label{$_[0]})) 485 if (!defined($label{$_[0]}))
530 { 486 {
531 $label{$_[0]}="${dot}${label}${_[0]}"; 487 $label{$_[0]}=".${label}${_[0]}";
532 $label++; 488 $label++;
533 } 489 }
534 if ($_[1]!=0) 490 if ($main'openbsd)
535 { 491 { push(@out,"_ALIGN_TEXT\n") if ($_[1] != 0); }
536 if ($_[1]>1) { main'align($_[1]); } 492 else
537 else { push(@out,".align $align\n"); } 493 { push(@out,".align $align\n") if ($_[1] != 0); }
538 }
539 push(@out,"$label{$_[0]}:\n"); 494 push(@out,"$label{$_[0]}:\n");
540 } 495 }
541 496
542sub main'file_end 497sub main'file_end
543 { 498 {
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 "") 499 if ($const ne "")
555 { 500 {
556 push(@out,".section .rodata\n"); 501 push(@out,".section .rodata\n");
@@ -559,27 +504,11 @@ sub main'file_end
559 } 504 }
560 } 505 }
561 506
562sub main'data_byte
563 {
564 push(@out,"\t.byte\t".join(',',@_)."\n");
565 }
566
567sub main'data_word 507sub main'data_word
568 { 508 {
569 push(@out,"\t.long\t".join(',',@_)."\n"); 509 push(@out,"\t.long\t".join(',',@_)."\n");
570 } 510 }
571 511
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 512# debug output functions: puts, putx, printf
584 513
585sub main'puts 514sub main'puts
@@ -659,6 +588,7 @@ sub main'picmeup
659 { 588 {
660 local($tmp)=<<___; 589 local($tmp)=<<___;
661#if (defined(ELF) || defined(SOL)) && defined(PIC) 590#if (defined(ELF) || defined(SOL)) && defined(PIC)
591 .align 8
662 call 1f 592 call 1f
6631: popl $regs{$dst} 5931: popl $regs{$dst}
664 addl \$_GLOBAL_OFFSET_TABLE_+[.-1b],$regs{$dst} 594 addl \$_GLOBAL_OFFSET_TABLE_+[.-1b],$regs{$dst}
@@ -669,14 +599,25 @@ sub main'picmeup
669___ 599___
670 push(@out,$tmp); 600 push(@out,$tmp);
671 } 601 }
602 elsif ($main'openbsd)
603 {
604 push(@out, "#ifdef PIC\n");
605 push(@out, "\tPIC_PROLOGUE\n");
606 &main'mov($dst,"PIC_GOT($sym)");
607 push(@out, "\tPIC_EPILOGUE\n");
608 push(@out, "#else\n");
609 &main'lea($dst,&main'DWP($sym));
610 push(@out, "#endif\n");
611 }
672 elsif ($main'pic && ($main'elf || $main'aout)) 612 elsif ($main'pic && ($main'elf || $main'aout))
673 { 613 {
614 push(@out,"\t.align\t8\n");
674 &main'call(&main'label("PIC_me_up")); 615 &main'call(&main'label("PIC_me_up"));
675 &main'set_label("PIC_me_up"); 616 &main'set_label("PIC_me_up");
676 &main'blindpop($dst); 617 &main'blindpop($dst);
677 &main'add($dst,"\$${under}_GLOBAL_OFFSET_TABLE_+[.-". 618 &main'add($dst,"\$$under"."_GLOBAL_OFFSET_TABLE_+[.-".
678 &main'label("PIC_me_up") . "]"); 619 &main'label("PIC_me_up") . "]");
679 &main'mov($dst,&main'DWP($under.$sym."\@GOT",$dst)); 620 &main'mov($dst,&main'DWP($sym."\@GOT",$dst));
680 } 621 }
681 else 622 else
682 { 623 {
@@ -685,41 +626,3 @@ ___
685 } 626 }
686 627
687sub main'blindpop { &out1("popl",@_); } 628sub 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;