#!/usr/local/bin/perl
-package x86unix;
+package x86unix; # GAS actually...
$label="L000";
$const="";
$constl=0;
$align=($main'aout)?"4":"16";
-$under=($main'aout)?"_":"";
-$com_start=($main'sol)?"/":"#";
+$under=($main'aout or $main'coff)?"_":"";
+$dot=($main'aout)?"":".";
+$com_start="#" if ($main'aout or $main'coff);
sub main'asm_init_output { @out=(); }
sub main'asm_get_output { return(@out); }
sub main'add { &out2("addl",@_); }
sub main'adc { &out2("adcl",@_); }
sub main'sub { &out2("subl",@_); }
+sub main'sbb { &out2("sbbl",@_); }
sub main'rotl { &out2("roll",@_); }
sub main'rotr { &out2("rorl",@_); }
sub main'exch { &out2("xchg",@_); }
sub main'inc { &out1("incl",@_); }
sub main'push { &out1("pushl",@_); $stack+=4; }
sub main'pop { &out1("popl",@_); $stack-=4; }
-sub main'pushf { &out0("pushf"); $stack+=4; }
-sub main'popf { &out0("popf"); $stack-=4; }
+sub main'pushf { &out0("pushfl"); $stack+=4; }
+sub main'popf { &out0("popfl"); $stack-=4; }
sub main'not { &out1("notl",@_); }
-sub main'call { &out1("call",($_[0]=~/^\.L/?'':$under).$_[0]); }
+sub main'call { my $pre=$under;
+ foreach $i (%label)
+ { if ($label{$i} eq $_[0]) { $pre=''; last; } }
+ &out1("call",$pre.$_[0]);
+ }
sub main'ret { &out0("ret"); }
sub main'nop { &out0("nop"); }
sub main'test { &out2("testl",@_); }
sub main'bt { &out2("btl",@_); }
sub main'leave { &out0("leave"); }
-sub main'cpuid { &out0(".word\t0xa20f"); }
-sub main'rdtsc { &out0(".word\t0x310f"); }
+sub main'cpuid { &out0(".byte 0x0f; .byte 0xa2"); }
+sub main'rdtsc { &out0(".byte 0x0f; .byte 0x31"); }
+sub main'halt { &out0("hlt"); }
# SSE2
sub main'emms { &out0("emms"); }
local($tmp)=<<"EOF";
.file "$file.s"
- .version "01.01"
-gcc2_compiled.:
EOF
push(@out,$tmp);
}
local($tmp)=<<"EOF";
.text
- .align $align
-.globl $func
+.globl $func
EOF
push(@out,$tmp);
if ($main'cpp)
- { $tmp=push(@out,"\tTYPE($func,\@function)\n"); }
- elsif ($main'gaswin)
- { $tmp=push(@out,"\t.def\t$func;\t.scl\t2;\t.type\t32;\t.endef\n"); }
- else { $tmp=push(@out,"\t.type\t$func,\@function\n"); }
+ { $tmp=push(@out,"TYPE($func,\@function)\n"); }
+ elsif ($main'coff)
+ { $tmp=push(@out,".def\t$func;\t.scl\t2;\t.type\t32;\t.endef\n"); }
+ elsif ($main'aout and !$main'pic)
+ { }
+ else { $tmp=push(@out,".type\t$func,\@function\n"); }
+ push(@out,".align\t$align\n");
push(@out,"$func:\n");
$tmp=<<"EOF";
pushl %ebp
local($tmp)=<<"EOF";
.text
- .align $align
-.globl $func
+.globl $func
EOF
push(@out,$tmp);
if ($main'cpp)
- { push(@out,"\tTYPE($func,\@function)\n"); }
- elsif ($main'gaswin)
- { $tmp=push(@out,"\t.def\t$func;\t.scl\t2;\t.type\t32;\t.endef\n"); }
- else { push(@out,"\t.type $func,\@function\n"); }
+ { push(@out,"TYPE($func,\@function)\n"); }
+ elsif ($main'coff)
+ { $tmp=push(@out,".def\t$func;\t.scl\t2;\t.type\t32;\t.endef\n"); }
+ elsif ($main'aout and !$main'pic)
+ { }
+ else { push(@out,".type $func,\@function\n"); }
+ push(@out,".align\t$align\n");
push(@out,"$func:\n");
$stack=4;
}
popl %ebx
popl %ebp
ret
-.L_${func}_end:
+${dot}L_${func}_end:
EOF
push(@out,$tmp);
if ($main'cpp)
- { push(@out,"\tSIZE($func,.L_${func}_end-$func)\n"); }
- elsif ($main'gaswin)
- { $tmp=push(@out,"\t.align 4\n"); }
- else { push(@out,"\t.size\t$func,.L_${func}_end-$func\n"); }
+ { push(@out,"SIZE($func,${dot}L_${func}_end-$func)\n"); }
+ elsif ($main'coff or $main'aout)
+ { }
+ else { push(@out,".size\t$func,${dot}L_${func}_end-$func\n"); }
push(@out,".ident \"$func\"\n");
$stack=0;
%label=();
$func=$under.$func;
- push(@out,".L_${func}_end:\n");
+ push(@out,"${dot}L_${func}_end:\n");
if ($main'cpp)
- { push(@out,"\tSIZE($func,.L_${func}_end-$func)\n"); }
- elsif ($main'gaswin)
- { push(@out,"\t.align 4\n"); }
- else { push(@out,"\t.size\t$func,.L_${func}_end-$func\n"); }
+ { push(@out,"SIZE($func,${dot}L_${func}_end-$func)\n"); }
+ elsif ($main'coff or $main'aout)
+ { }
+ else { push(@out,".size\t$func,${dot}L_${func}_end-$func\n"); }
push(@out,".ident \"$func\"\n");
$stack=0;
%label=();
sub main'comment
{
- if ($main'elf) # GNU and SVR4 as'es use different comment delimiters,
- { # so we just skip comments...
- push(@out,"\n");
+ if (!defined($com_start) or $main'elf)
+ { # Regarding $main'elf above...
+ # GNU and SVR4 as'es use different comment delimiters,
+ push(@out,"\n"); # so we just skip ELF comments...
return;
}
foreach (@_)
{
if (!defined($label{$_[0]}))
{
- $label{$_[0]}=".${label}${_[0]}";
+ $label{$_[0]}="${dot}${label}${_[0]}";
$label++;
}
return($label{$_[0]});
{
if (!defined($label{$_[0]}))
{
- $label{$_[0]}=".${label}${_[0]}";
+ $label{$_[0]}="${dot}${label}${_[0]}";
$label++;
}
- push(@out,".align $align\n") if ($_[1] != 0);
+ if ($_[1]!=0)
+ {
+ if ($_[1]>1) { main'align($_[1]); }
+ else { push(@out,".align $align\n"); }
+ }
push(@out,"$label{$_[0]}:\n");
}
if ($main'elf && grep {/%[x]*mm[0-7]/i} @out) {
local($tmp);
- push (@out,"\n.comm\t".$under."OPENSSL_ia32cap,8,4\n");
+ push (@out,"\n.comm\t${under}OPENSSL_ia32cap_P,4,4\n");
push (@out,".section\t.init\n");
# One can argue that it's wasteful to craft every
#
# $1<<10 sets a reserved bit to signal that variable
# was initialized already...
- &main'picmeup("edx","OPENSSL_ia32cap");
+ &main'picmeup("edx","OPENSSL_ia32cap_P");
$tmp=<<___;
cmpl \$0,(%edx)
jne 1f
pushf
popl %eax
xorl %ecx,%eax
- bt \$21,%eax
+ btl \$21,%eax
jnc 1f
pushl %edi
pushl %ebx
movl %edx,%edi
movl \$1,%eax
- .word 0xa20f
+ .byte 0x0f; .byte 0xa2
orl \$1<<10,%edx
movl %edx,0(%edi)
- movl %ecx,4(%edi)
popl %ebx
popl %edi
- .align 4
+ .align $align
1:
___
push (@out,$tmp);
sub main'align
{
- push(@out,".align $_[0]\n");
+ my $val=$_[0],$p2,$i;
+ if ($main'aout) {
+ for ($p2=0;$val!=0;$val>>=1) { $p2++; }
+ $val=$p2-1;
+ $val.=",0x90";
+ }
+ push(@out,".align\t$val\n");
}
# debug output functions: puts, putx, printf
{
local($tmp)=<<___;
#if (defined(ELF) || defined(SOL)) && defined(PIC)
- .align 4
call 1f
1: popl $regs{$dst}
addl \$_GLOBAL_OFFSET_TABLE_+[.-1b],$regs{$dst}
}
elsif ($main'pic && ($main'elf || $main'aout))
{
- push(@out,"\t.align\t4\n");
&main'call(&main'label("PIC_me_up"));
&main'set_label("PIC_me_up");
&main'blindpop($dst);
- &main'add($dst,"\$$under"."_GLOBAL_OFFSET_TABLE_+[.-".
+ &main'add($dst,"\$${under}_GLOBAL_OFFSET_TABLE_+[.-".
&main'label("PIC_me_up") . "]");
- &main'mov($dst,&main'DWP($sym."\@GOT",$dst));
+ &main'mov($dst,&main'DWP($under.$sym."\@GOT",$dst));
}
else
{
sub main'initseg
{
local($f)=@_;
+ local($tmp);
if ($main'elf)
{
- local($tmp)=<<___;
-.pushsection .init
+ $tmp=<<___;
+.section .init
call $under$f
-.popsection
+ .align $align
___
- push(@out,$tmp);
}
+ elsif ($main'coff)
+ {
+ $tmp=<<___; # applies to both Cygwin and Mingw
+.section .ctors
+.long $under$f
+___
+ }
+ elsif ($main'aout)
+ {
+ local($ctor)="${under}_GLOBAL_\$I\$$f";
+ $tmp=".text\n";
+ $tmp.=".type $ctor,\@function\n" if ($main'pic);
+ $tmp.=<<___; # OpenBSD way...
+.globl $ctor
+.align 2
+$ctor:
+ jmp $under$f
+___
+ }
+ push(@out,$tmp) if ($tmp);
}
+
+1;