x86unix.pl 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725
  1. #!/usr/local/bin/perl
  2. package x86unix; # GAS actually...
  3. $label="L000";
  4. $const="";
  5. $constl=0;
  6. $align=($main'aout)?"4":"16";
  7. $under=($main'aout or $main'coff)?"_":"";
  8. $dot=($main'aout)?"":".";
  9. $com_start="#" if ($main'aout or $main'coff);
  10. sub main'asm_init_output { @out=(); }
  11. sub main'asm_get_output { return(@out); }
  12. sub main'get_labels { return(@labels); }
  13. sub main'external_label { push(@labels,@_); }
  14. if ($main'cpp)
  15. {
  16. $align="ALIGN";
  17. $under="";
  18. $com_start='/*';
  19. $com_end='*/';
  20. }
  21. %lb=( 'eax', '%al',
  22. 'ebx', '%bl',
  23. 'ecx', '%cl',
  24. 'edx', '%dl',
  25. 'ax', '%al',
  26. 'bx', '%bl',
  27. 'cx', '%cl',
  28. 'dx', '%dl',
  29. );
  30. %hb=( 'eax', '%ah',
  31. 'ebx', '%bh',
  32. 'ecx', '%ch',
  33. 'edx', '%dh',
  34. 'ax', '%ah',
  35. 'bx', '%bh',
  36. 'cx', '%ch',
  37. 'dx', '%dh',
  38. );
  39. %regs=( 'eax', '%eax',
  40. 'ebx', '%ebx',
  41. 'ecx', '%ecx',
  42. 'edx', '%edx',
  43. 'esi', '%esi',
  44. 'edi', '%edi',
  45. 'ebp', '%ebp',
  46. 'esp', '%esp',
  47. 'mm0', '%mm0',
  48. 'mm1', '%mm1',
  49. 'mm2', '%mm2',
  50. 'mm3', '%mm3',
  51. 'mm4', '%mm4',
  52. 'mm5', '%mm5',
  53. 'mm6', '%mm6',
  54. 'mm7', '%mm7',
  55. 'xmm0', '%xmm0',
  56. 'xmm1', '%xmm1',
  57. 'xmm2', '%xmm2',
  58. 'xmm3', '%xmm3',
  59. 'xmm4', '%xmm4',
  60. 'xmm5', '%xmm5',
  61. 'xmm6', '%xmm6',
  62. 'xmm7', '%xmm7',
  63. );
  64. %reg_val=(
  65. 'eax', 0x00,
  66. 'ebx', 0x03,
  67. 'ecx', 0x01,
  68. 'edx', 0x02,
  69. 'esi', 0x06,
  70. 'edi', 0x07,
  71. 'ebp', 0x05,
  72. 'esp', 0x04,
  73. );
  74. sub main'LB
  75. {
  76. (defined($lb{$_[0]})) || die "$_[0] does not have a 'low byte'\n";
  77. return($lb{$_[0]});
  78. }
  79. sub main'HB
  80. {
  81. (defined($hb{$_[0]})) || die "$_[0] does not have a 'high byte'\n";
  82. return($hb{$_[0]});
  83. }
  84. sub main'DWP
  85. {
  86. local($addr,$reg1,$reg2,$idx)=@_;
  87. $ret="";
  88. $addr =~ s/(^|[+ \t])([A-Za-z_]+[A-Za-z0-9_]+)($|[+ \t])/$1$under$2$3/;
  89. $reg1="$regs{$reg1}" if defined($regs{$reg1});
  90. $reg2="$regs{$reg2}" if defined($regs{$reg2});
  91. $ret.=$addr if ($addr ne "") && ($addr ne 0);
  92. if ($reg2 ne "")
  93. {
  94. if($idx ne "" && $idx != 0)
  95. { $ret.="($reg1,$reg2,$idx)"; }
  96. else
  97. { $ret.="($reg1,$reg2)"; }
  98. }
  99. elsif ($reg1 ne "")
  100. { $ret.="($reg1)" }
  101. return($ret);
  102. }
  103. sub main'QWP
  104. {
  105. return(&main'DWP(@_));
  106. }
  107. sub main'BP
  108. {
  109. return(&main'DWP(@_));
  110. }
  111. sub main'BC
  112. {
  113. return @_;
  114. }
  115. sub main'DWC
  116. {
  117. return @_;
  118. }
  119. #sub main'BP
  120. # {
  121. # local($addr,$reg1,$reg2,$idx)=@_;
  122. #
  123. # $ret="";
  124. #
  125. # $addr =~ s/(^|[+ \t])([A-Za-z_]+)($|[+ \t])/$1$under$2$3/;
  126. # $reg1="$regs{$reg1}" if defined($regs{$reg1});
  127. # $reg2="$regs{$reg2}" if defined($regs{$reg2});
  128. # $ret.=$addr if ($addr ne "") && ($addr ne 0);
  129. # if ($reg2 ne "")
  130. # { $ret.="($reg1,$reg2,$idx)"; }
  131. # else
  132. # { $ret.="($reg1)" }
  133. # return($ret);
  134. # }
  135. sub main'mov { &out2("movl",@_); }
  136. sub main'movb { &out2("movb",@_); }
  137. sub main'and { &out2("andl",@_); }
  138. sub main'or { &out2("orl",@_); }
  139. sub main'shl { &out2("sall",@_); }
  140. sub main'shr { &out2("shrl",@_); }
  141. sub main'xor { &out2("xorl",@_); }
  142. sub main'xorb { &out2("xorb",@_); }
  143. sub main'add { &out2($_[0]=~/%[a-d][lh]/?"addb":"addl",@_); }
  144. sub main'adc { &out2("adcl",@_); }
  145. sub main'sub { &out2("subl",@_); }
  146. sub main'sbb { &out2("sbbl",@_); }
  147. sub main'rotl { &out2("roll",@_); }
  148. sub main'rotr { &out2("rorl",@_); }
  149. sub main'exch { &out2($_[0]=~/%[a-d][lh]/?"xchgb":"xchgl",@_); }
  150. sub main'cmp { &out2("cmpl",@_); }
  151. sub main'lea { &out2("leal",@_); }
  152. sub main'mul { &out1("mull",@_); }
  153. sub main'imul { &out2("imull",@_); }
  154. sub main'div { &out1("divl",@_); }
  155. sub main'jmp { &out1("jmp",@_); }
  156. sub main'jmp_ptr { &out1p("jmp",@_); }
  157. sub main'je { &out1("je",@_); }
  158. sub main'jle { &out1("jle",@_); }
  159. sub main'jne { &out1("jne",@_); }
  160. sub main'jnz { &out1("jnz",@_); }
  161. sub main'jz { &out1("jz",@_); }
  162. sub main'jge { &out1("jge",@_); }
  163. sub main'jl { &out1("jl",@_); }
  164. sub main'ja { &out1("ja",@_); }
  165. sub main'jae { &out1("jae",@_); }
  166. sub main'jb { &out1("jb",@_); }
  167. sub main'jbe { &out1("jbe",@_); }
  168. sub main'jc { &out1("jc",@_); }
  169. sub main'jnc { &out1("jnc",@_); }
  170. sub main'jno { &out1("jno",@_); }
  171. sub main'dec { &out1("decl",@_); }
  172. sub main'inc { &out1($_[0]=~/%[a-d][hl]/?"incb":"incl",@_); }
  173. sub main'push { &out1("pushl",@_); $stack+=4; }
  174. sub main'pop { &out1("popl",@_); $stack-=4; }
  175. sub main'pushf { &out0("pushfl"); $stack+=4; }
  176. sub main'popf { &out0("popfl"); $stack-=4; }
  177. sub main'not { &out1("notl",@_); }
  178. sub main'call { my $pre=$under;
  179. foreach $i (%label)
  180. { if ($label{$i} eq $_[0]) { $pre=''; last; } }
  181. &out1("call",$pre.$_[0]);
  182. }
  183. sub main'call_ptr { &out1p("call",@_); }
  184. sub main'ret { &out0("ret"); }
  185. sub main'nop { &out0("nop"); }
  186. sub main'test { &out2("testl",@_); }
  187. sub main'bt { &out2("btl",@_); }
  188. sub main'leave { &out0("leave"); }
  189. sub main'cpuid { &out0(".byte\t0x0f,0xa2"); }
  190. sub main'rdtsc { &out0(".byte\t0x0f,0x31"); }
  191. sub main'halt { &out0("hlt"); }
  192. sub main'movz { &out2("movzbl",@_); }
  193. sub main'neg { &out1("negl",@_); }
  194. sub main'cld { &out0("cld"); }
  195. # SSE2
  196. sub main'emms { &out0("emms"); }
  197. sub main'movd { &out2("movd",@_); }
  198. sub main'movdqu { &out2("movdqu",@_); }
  199. sub main'movdqa { &out2("movdqa",@_); }
  200. sub main'movdq2q{ &out2("movdq2q",@_); }
  201. sub main'movq2dq{ &out2("movq2dq",@_); }
  202. sub main'paddq { &out2("paddq",@_); }
  203. sub main'pmuludq{ &out2("pmuludq",@_); }
  204. sub main'psrlq { &out2("psrlq",@_); }
  205. sub main'psllq { &out2("psllq",@_); }
  206. sub main'pxor { &out2("pxor",@_); }
  207. sub main'por { &out2("por",@_); }
  208. sub main'pand { &out2("pand",@_); }
  209. sub main'movq {
  210. local($p1,$p2,$optimize)=@_;
  211. if ($optimize && $p1=~/^mm[0-7]$/ && $p2=~/^mm[0-7]$/)
  212. # movq between mmx registers can sink Intel CPUs
  213. { push(@out,"\tpshufw\t\$0xe4,%$p2,%$p1\n"); }
  214. else { &out2("movq",@_); }
  215. }
  216. # The bswapl instruction is new for the 486. Emulate if i386.
  217. sub main'bswap
  218. {
  219. if ($main'i386)
  220. {
  221. &main'comment("bswapl @_");
  222. &main'exch(main'HB(@_),main'LB(@_));
  223. &main'rotr(@_,16);
  224. &main'exch(main'HB(@_),main'LB(@_));
  225. }
  226. else
  227. {
  228. &out1("bswapl",@_);
  229. }
  230. }
  231. sub out2
  232. {
  233. local($name,$p1,$p2)=@_;
  234. local($l,$ll,$t);
  235. local(%special)=( "roll",0xD1C0,"rorl",0xD1C8,
  236. "rcll",0xD1D0,"rcrl",0xD1D8,
  237. "shll",0xD1E0,"shrl",0xD1E8,
  238. "sarl",0xD1F8);
  239. if ((defined($special{$name})) && defined($regs{$p1}) && ($p2 == 1))
  240. {
  241. $op=$special{$name}|$reg_val{$p1};
  242. $tmp1=sprintf(".byte %d\n",($op>>8)&0xff);
  243. $tmp2=sprintf(".byte %d\t",$op &0xff);
  244. push(@out,$tmp1);
  245. push(@out,$tmp2);
  246. $p2=&conv($p2);
  247. $p1=&conv($p1);
  248. &main'comment("$name $p2 $p1");
  249. return;
  250. }
  251. push(@out,"\t$name\t");
  252. $t=&conv($p2).",";
  253. $l=length($t);
  254. push(@out,$t);
  255. $ll=4-($l+9)/8;
  256. $tmp1=sprintf("\t" x $ll);
  257. push(@out,$tmp1);
  258. push(@out,&conv($p1)."\n");
  259. }
  260. sub out1
  261. {
  262. local($name,$p1)=@_;
  263. local($l,$t);
  264. local(%special)=("bswapl",0x0FC8);
  265. if ((defined($special{$name})) && defined($regs{$p1}))
  266. {
  267. $op=$special{$name}|$reg_val{$p1};
  268. $tmp1=sprintf(".byte %d\n",($op>>8)&0xff);
  269. $tmp2=sprintf(".byte %d\t",$op &0xff);
  270. push(@out,$tmp1);
  271. push(@out,$tmp2);
  272. $p2=&conv($p2);
  273. $p1=&conv($p1);
  274. &main'comment("$name $p2 $p1");
  275. return;
  276. }
  277. push(@out,"\t$name\t".&conv($p1)."\n");
  278. }
  279. sub out1p
  280. {
  281. local($name,$p1)=@_;
  282. local($l,$t);
  283. push(@out,"\t$name\t*".&conv($p1)."\n");
  284. }
  285. sub out0
  286. {
  287. push(@out,"\t$_[0]\n");
  288. }
  289. sub conv
  290. {
  291. local($p)=@_;
  292. # $p =~ s/0x([0-9A-Fa-f]+)/0$1h/;
  293. $p=$regs{$p} if (defined($regs{$p}));
  294. $p =~ s/^(-{0,1}[0-9A-Fa-f]+)$/\$$1/;
  295. $p =~ s/^(0x[0-9A-Fa-f]+)$/\$$1/;
  296. return $p;
  297. }
  298. sub main'file
  299. {
  300. local($file)=@_;
  301. local($tmp)=<<"EOF";
  302. .file "$file.s"
  303. EOF
  304. push(@out,$tmp);
  305. }
  306. sub main'function_begin
  307. {
  308. local($func)=@_;
  309. &main'external_label($func);
  310. $func=$under.$func;
  311. local($tmp)=<<"EOF";
  312. .text
  313. .globl $func
  314. EOF
  315. push(@out,$tmp);
  316. if ($main'cpp)
  317. { $tmp=push(@out,"TYPE($func,\@function)\n"); }
  318. elsif ($main'coff)
  319. { $tmp=push(@out,".def\t$func;\t.scl\t2;\t.type\t32;\t.endef\n"); }
  320. elsif ($main'aout and !$main'pic)
  321. { }
  322. else { $tmp=push(@out,".type\t$func,\@function\n"); }
  323. push(@out,".align\t$align\n");
  324. push(@out,"$func:\n");
  325. $tmp=<<"EOF";
  326. pushl %ebp
  327. pushl %ebx
  328. pushl %esi
  329. pushl %edi
  330. EOF
  331. push(@out,$tmp);
  332. $stack=20;
  333. }
  334. sub main'function_begin_B
  335. {
  336. local($func,$extra)=@_;
  337. &main'external_label($func);
  338. $func=$under.$func;
  339. local($tmp)=<<"EOF";
  340. .text
  341. .globl $func
  342. EOF
  343. push(@out,$tmp);
  344. if ($main'cpp)
  345. { push(@out,"TYPE($func,\@function)\n"); }
  346. elsif ($main'coff)
  347. { $tmp=push(@out,".def\t$func;\t.scl\t2;\t.type\t32;\t.endef\n"); }
  348. elsif ($main'aout and !$main'pic)
  349. { }
  350. else { push(@out,".type $func,\@function\n"); }
  351. push(@out,".align\t$align\n");
  352. push(@out,"$func:\n");
  353. $stack=4;
  354. }
  355. sub main'function_end
  356. {
  357. local($func)=@_;
  358. $func=$under.$func;
  359. local($tmp)=<<"EOF";
  360. popl %edi
  361. popl %esi
  362. popl %ebx
  363. popl %ebp
  364. ret
  365. ${dot}L_${func}_end:
  366. EOF
  367. push(@out,$tmp);
  368. if ($main'cpp)
  369. { push(@out,"SIZE($func,${dot}L_${func}_end-$func)\n"); }
  370. elsif ($main'coff or $main'aout)
  371. { }
  372. else { push(@out,".size\t$func,${dot}L_${func}_end-$func\n"); }
  373. push(@out,".ident \"$func\"\n");
  374. $stack=0;
  375. %label=();
  376. }
  377. sub main'function_end_A
  378. {
  379. local($func)=@_;
  380. local($tmp)=<<"EOF";
  381. popl %edi
  382. popl %esi
  383. popl %ebx
  384. popl %ebp
  385. ret
  386. EOF
  387. push(@out,$tmp);
  388. }
  389. sub main'function_end_B
  390. {
  391. local($func)=@_;
  392. $func=$under.$func;
  393. push(@out,"${dot}L_${func}_end:\n");
  394. if ($main'cpp)
  395. { push(@out,"SIZE($func,${dot}L_${func}_end-$func)\n"); }
  396. elsif ($main'coff or $main'aout)
  397. { }
  398. else { push(@out,".size\t$func,${dot}L_${func}_end-$func\n"); }
  399. push(@out,".ident \"$func\"\n");
  400. $stack=0;
  401. %label=();
  402. }
  403. sub main'wparam
  404. {
  405. local($num)=@_;
  406. return(&main'DWP($stack+$num*4,"esp","",0));
  407. }
  408. sub main'stack_push
  409. {
  410. local($num)=@_;
  411. $stack+=$num*4;
  412. &main'sub("esp",$num*4);
  413. }
  414. sub main'stack_pop
  415. {
  416. local($num)=@_;
  417. $stack-=$num*4;
  418. &main'add("esp",$num*4);
  419. }
  420. sub main'swtmp
  421. {
  422. return(&main'DWP($_[0]*4,"esp","",0));
  423. }
  424. # Should use swtmp, which is above esp. Linix can trash the stack above esp
  425. #sub main'wtmp
  426. # {
  427. # local($num)=@_;
  428. #
  429. # return(&main'DWP(-($num+1)*4,"esp","",0));
  430. # }
  431. sub main'comment
  432. {
  433. if (!defined($com_start) or $main'elf)
  434. { # Regarding $main'elf above...
  435. # GNU and SVR4 as'es use different comment delimiters,
  436. push(@out,"\n"); # so we just skip ELF comments...
  437. return;
  438. }
  439. foreach (@_)
  440. {
  441. if (/^\s*$/)
  442. { push(@out,"\n"); }
  443. else
  444. { push(@out,"\t$com_start $_ $com_end\n"); }
  445. }
  446. }
  447. sub main'public_label
  448. {
  449. $label{$_[0]}="${under}${_[0]}" if (!defined($label{$_[0]}));
  450. push(@out,".globl\t$label{$_[0]}\n");
  451. }
  452. sub main'label
  453. {
  454. if (!defined($label{$_[0]}))
  455. {
  456. $label{$_[0]}="${dot}${label}${_[0]}";
  457. $label++;
  458. }
  459. return($label{$_[0]});
  460. }
  461. sub main'set_label
  462. {
  463. if (!defined($label{$_[0]}))
  464. {
  465. $label{$_[0]}="${dot}${label}${_[0]}";
  466. $label++;
  467. }
  468. if ($_[1]!=0)
  469. {
  470. if ($_[1]>1) { main'align($_[1]); }
  471. else { push(@out,".align $align\n"); }
  472. }
  473. push(@out,"$label{$_[0]}:\n");
  474. }
  475. sub main'file_end
  476. {
  477. # try to detect if SSE2 or MMX extensions were used on ELF platform...
  478. if ($main'elf && grep {/\b%[x]*mm[0-7]\b|OPENSSL_ia32cap_P\b/i} @out) {
  479. local($tmp);
  480. push (@out,"\n.section\t.bss\n");
  481. push (@out,".comm\t${under}OPENSSL_ia32cap_P,4,4\n");
  482. return;
  483. }
  484. if ($const ne "")
  485. {
  486. push(@out,".section .rodata\n");
  487. push(@out,$const);
  488. $const="";
  489. }
  490. }
  491. sub main'data_byte
  492. {
  493. push(@out,"\t.byte\t".join(',',@_)."\n");
  494. }
  495. sub main'data_word
  496. {
  497. push(@out,"\t.long\t".join(',',@_)."\n");
  498. }
  499. sub main'align
  500. {
  501. my $val=$_[0],$p2,$i;
  502. if ($main'aout) {
  503. for ($p2=0;$val!=0;$val>>=1) { $p2++; }
  504. $val=$p2-1;
  505. $val.=",0x90";
  506. }
  507. push(@out,".align\t$val\n");
  508. }
  509. # debug output functions: puts, putx, printf
  510. sub main'puts
  511. {
  512. &pushvars();
  513. &main'push('$Lstring' . ++$constl);
  514. &main'call('puts');
  515. $stack-=4;
  516. &main'add("esp",4);
  517. &popvars();
  518. $const .= "Lstring$constl:\n\t.string \"@_[0]\"\n";
  519. }
  520. sub main'putx
  521. {
  522. &pushvars();
  523. &main'push($_[0]);
  524. &main'push('$Lstring' . ++$constl);
  525. &main'call('printf');
  526. &main'add("esp",8);
  527. $stack-=8;
  528. &popvars();
  529. $const .= "Lstring$constl:\n\t.string \"\%X\"\n";
  530. }
  531. sub main'printf
  532. {
  533. $ostack = $stack;
  534. &pushvars();
  535. for ($i = @_ - 1; $i >= 0; $i--)
  536. {
  537. if ($i == 0) # change this to support %s format strings
  538. {
  539. &main'push('$Lstring' . ++$constl);
  540. $const .= "Lstring$constl:\n\t.string \"@_[$i]\"\n";
  541. }
  542. else
  543. {
  544. if ($_[$i] =~ /([0-9]*)\(%esp\)/)
  545. {
  546. &main'push(($1 + $stack - $ostack) . '(%esp)');
  547. }
  548. else
  549. {
  550. &main'push($_[$i]);
  551. }
  552. }
  553. }
  554. &main'call('printf');
  555. $stack-=4*@_;
  556. &main'add("esp",4*@_);
  557. &popvars();
  558. }
  559. sub pushvars
  560. {
  561. &main'pushf();
  562. &main'push("edx");
  563. &main'push("ecx");
  564. &main'push("eax");
  565. }
  566. sub popvars
  567. {
  568. &main'pop("eax");
  569. &main'pop("ecx");
  570. &main'pop("edx");
  571. &main'popf();
  572. }
  573. sub main'picmeup
  574. {
  575. local($dst,$sym)=@_;
  576. if ($main'cpp)
  577. {
  578. local($tmp)=<<___;
  579. #if (defined(ELF) || defined(SOL)) && defined(PIC)
  580. call 1f
  581. 1: popl $regs{$dst}
  582. addl \$_GLOBAL_OFFSET_TABLE_+[.-1b],$regs{$dst}
  583. movl $sym\@GOT($regs{$dst}),$regs{$dst}
  584. #else
  585. leal $sym,$regs{$dst}
  586. #endif
  587. ___
  588. push(@out,$tmp);
  589. }
  590. elsif ($main'pic && ($main'elf || $main'aout))
  591. {
  592. &main'call(&main'label("PIC_me_up"));
  593. &main'set_label("PIC_me_up");
  594. &main'blindpop($dst);
  595. &main'add($dst,"\$${under}_GLOBAL_OFFSET_TABLE_+[.-".
  596. &main'label("PIC_me_up") . "]");
  597. &main'mov($dst,&main'DWP($under.$sym."\@GOT",$dst));
  598. }
  599. else
  600. {
  601. &main'lea($dst,&main'DWP($sym));
  602. }
  603. }
  604. sub main'blindpop { &out1("popl",@_); }
  605. sub main'initseg
  606. {
  607. local($f)=@_;
  608. local($tmp);
  609. if ($main'elf)
  610. {
  611. $tmp=<<___;
  612. .section .init
  613. call $under$f
  614. jmp .Linitalign
  615. .align $align
  616. .Linitalign:
  617. ___
  618. }
  619. elsif ($main'coff)
  620. {
  621. $tmp=<<___; # applies to both Cygwin and Mingw
  622. .section .ctors
  623. .long $under$f
  624. ___
  625. }
  626. elsif ($main'aout)
  627. {
  628. local($ctor)="${under}_GLOBAL_\$I\$$f";
  629. $tmp=".text\n";
  630. $tmp.=".type $ctor,\@function\n" if ($main'pic);
  631. $tmp.=<<___; # OpenBSD way...
  632. .globl $ctor
  633. .align 2
  634. $ctor:
  635. jmp $under$f
  636. ___
  637. }
  638. push(@out,$tmp) if ($tmp);
  639. }
  640. 1;