7 $align=($main'aout)?"4":"16";
8 $under=($main'aout)?"_":"";
9 $com_start=($main'sol)?"/":"#";
11 sub main'asm_init_output { @out=(); }
12 sub main'asm_get_output { return(@out); }
13 sub main'get_labels { return(@labels); }
14 sub main'external_label { push(@labels,@_); }
44 %regs=( 'eax', '%eax',
67 (defined($lb{$_[0]})) || die "$_[0] does not have a 'low byte'\n";
73 (defined($hb{$_[0]})) || die "$_[0] does not have a 'high byte'\n";
79 local($addr,$reg1,$reg2,$idx)=@_;
82 $addr =~ s/(^|[+ \t])([A-Za-z_]+)($|[+ \t])/$1$under$2$3/;
83 $reg1="$regs{$reg1}" if defined($regs{$reg1});
84 $reg2="$regs{$reg2}" if defined($regs{$reg2});
85 $ret.=$addr if ($addr ne "") && ($addr ne 0);
89 { $ret.="($reg1,$reg2,$idx)"; }
91 { $ret.="($reg1,$reg2)"; }
100 return(&main'DWP(@_));
115 # local($addr,$reg1,$reg2,$idx)=@_;
119 # $addr =~ s/(^|[+ \t])([A-Za-z_]+)($|[+ \t])/$1$under$2$3/;
120 # $reg1="$regs{$reg1}" if defined($regs{$reg1});
121 # $reg2="$regs{$reg2}" if defined($regs{$reg2});
122 # $ret.=$addr if ($addr ne "") && ($addr ne 0);
124 # { $ret.="($reg1,$reg2,$idx)"; }
126 # { $ret.="($reg1)" }
130 sub main'mov { &out2("movl",@_); }
131 sub main'movb { &out2("movb",@_); }
132 sub main'and { &out2("andl",@_); }
133 sub main'or { &out2("orl",@_); }
134 sub main'shl { &out2("sall",@_); }
135 sub main'shr { &out2("shrl",@_); }
136 sub main'xor { &out2("xorl",@_); }
137 sub main'xorb { &out2("xorb",@_); }
138 sub main'add { &out2("addl",@_); }
139 sub main'adc { &out2("adcl",@_); }
140 sub main'sub { &out2("subl",@_); }
141 sub main'rotl { &out2("roll",@_); }
142 sub main'rotr { &out2("rorl",@_); }
143 sub main'exch { &out2("xchg",@_); }
144 sub main'cmp { &out2("cmpl",@_); }
145 sub main'lea { &out2("leal",@_); }
146 sub main'mul { &out1("mull",@_); }
147 sub main'div { &out1("divl",@_); }
148 sub main'jmp { &out1("jmp",@_); }
149 sub main'jmp_ptr { &out1p("jmp",@_); }
150 sub main'je { &out1("je",@_); }
151 sub main'jle { &out1("jle",@_); }
152 sub main'jne { &out1("jne",@_); }
153 sub main'jnz { &out1("jnz",@_); }
154 sub main'jz { &out1("jz",@_); }
155 sub main'jge { &out1("jge",@_); }
156 sub main'jl { &out1("jl",@_); }
157 sub main'jb { &out1("jb",@_); }
158 sub main'jc { &out1("jc",@_); }
159 sub main'jnc { &out1("jnc",@_); }
160 sub main'jno { &out1("jno",@_); }
161 sub main'dec { &out1("decl",@_); }
162 sub main'inc { &out1("incl",@_); }
163 sub main'push { &out1("pushl",@_); $stack+=4; }
164 sub main'pop { &out1("popl",@_); $stack-=4; }
165 sub main'not { &out1("notl",@_); }
166 sub main'call { &out1("call",$under.$_[0]); }
167 sub main'ret { &out0("ret"); }
168 sub main'nop { &out0("nop"); }
170 # The bswapl instruction is new for the 486. Emulate if i386.
175 &main'comment("bswapl @_");
176 &main'exch(main'HB(@_),main'LB(@_));
178 &main'exch(main'HB(@_),main'LB(@_));
188 local($name,$p1,$p2)=@_;
190 local(%special)=( "roll",0xD1C0,"rorl",0xD1C8,
191 "rcll",0xD1D0,"rcrl",0xD1D8,
192 "shll",0xD1E0,"shrl",0xD1E8,
195 if ((defined($special{$name})) && defined($regs{$p1}) && ($p2 == 1))
197 $op=$special{$name}|$reg_val{$p1};
198 $tmp1=sprintf(".byte %d\n",($op>>8)&0xff);
199 $tmp2=sprintf(".byte %d\t",$op &0xff);
205 &main'comment("$name $p2 $p1");
209 push(@out,"\t$name\t");
214 $tmp1=sprintf("\t" x $ll);
216 push(@out,&conv($p1)."\n");
223 local(%special)=("bswapl",0x0FC8);
225 if ((defined($special{$name})) && defined($regs{$p1}))
227 $op=$special{$name}|$reg_val{$p1};
228 $tmp1=sprintf(".byte %d\n",($op>>8)&0xff);
229 $tmp2=sprintf(".byte %d\t",$op &0xff);
235 &main'comment("$name $p2 $p1");
239 push(@out,"\t$name\t".&conv($p1)."\n");
247 push(@out,"\t$name\t*".&conv($p1)."\n");
252 push(@out,"\t$_[0]\n");
259 # $p =~ s/0x([0-9A-Fa-f]+)/0$1h/;
261 $p=$regs{$p} if (defined($regs{$p}));
263 $p =~ s/^(-{0,1}[0-9A-Fa-f]+)$/\$$1/;
264 $p =~ s/^(0x[0-9A-Fa-f]+)$/\$$1/;
280 sub main'function_begin
284 &main'external_label($func);
294 { $tmp=push(@out,"\tTYPE($func,\@function)\n"); }
295 else { $tmp=push(@out,"\t.type\t$func,\@function\n"); }
296 push(@out,"$func:\n");
308 sub main'function_begin_B
310 local($func,$extra)=@_;
312 &main'external_label($func);
322 { push(@out,"\tTYPE($func,\@function)\n"); }
323 else { push(@out,"\t.type $func,\@function\n"); }
324 push(@out,"$func:\n");
328 sub main'function_end
344 { push(@out,"\tSIZE($func,.${func}_end-$func)\n"); }
345 else { push(@out,"\t.size\t$func,.${func}_end-$func\n"); }
346 push(@out,".ident \"$func\"\n");
351 sub main'function_end_A
365 sub main'function_end_B
371 push(@out,".${func}_end:\n");
373 { push(@out,"\tSIZE($func,.${func}_end-$func)\n"); }
374 else { push(@out,"\t.size\t$func,.${func}_end-$func\n"); }
375 push(@out,".ident \"desasm.pl\"\n");
384 return(&main'DWP($stack+$num*4,"esp","",0));
391 &main'sub("esp",$num*4);
398 &main'add("esp",$num*4);
403 return(&main'DWP($_[0]*4,"esp","",0));
406 # Should use swtmp, which is above esp. Linix can trash the stack above esp
411 # return(&main'DWP(-($num+1)*4,"esp","",0));
421 { push(@out,"\t$com_start $_ $com_end\n"); }
427 if (!defined($label{$_[0]}))
429 $label{$_[0]}=".${label}${_[0]}";
432 return($label{$_[0]});
437 if (!defined($label{$_[0]}))
439 $label{$_[0]}=".${label}${_[0]}";
442 push(@out,".align $align\n") if ($_[1] != 0);
443 push(@out,"$label{$_[0]}:\n");
452 push(@out,"\t.long $_[0]\n");