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