X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=ghc%2Fdriver%2Fmangler%2Fghc-asm.lprl;h=10b928f829649650c2aa168bcdb55a591915b448;hb=8c0b2b04054478f82cfa72e57d0dc315ffb9e6f9;hp=6d492199bd41ec4407e2f2290e0c545168ba3e52;hpb=c625c85f1921c26df7a0752204ae84b47c5bacaa;p=ghc-hetmet.git diff --git a/ghc/driver/mangler/ghc-asm.lprl b/ghc/driver/mangler/ghc-asm.lprl index 6d49219..10b928f 100644 --- a/ghc/driver/mangler/ghc-asm.lprl +++ b/ghc/driver/mangler/ghc-asm.lprl @@ -42,6 +42,28 @@ for the same reason. Advantage: No more ridiculous call sequences. %************************************************************************ %* * +\subsection{Top-level code} +%* * +%************************************************************************ + +\begin{code} +$TargetPlatform = $TARGETPLATFORM; + +($Pgm = $0) =~ s|.*/||; +$ifile = $ARGV[0]; +$ofile = $ARGV[1]; + +if ( $TargetPlatform =~ /^i386-/ ) { + $StolenX86Regs = $ARGV[2]; +} + +&mangle_asm($ifile,$ofile); + +exit(0); +\end{code} + +%************************************************************************ +%* * \subsection{Constants for various architectures} %* * %************************************************************************ @@ -69,7 +91,7 @@ sub init_TARGET_STUFF { $T_HDR_data = "\.data\n\t\.align 3\n"; $T_HDR_consist = "\.text\n"; $T_HDR_closure = "\.data\n\t\.align 3\n"; - $T_HDR_srt = "\.data\n\t\.align 3\n"; + $T_HDR_srt = "\.text\n\t\.align 3\n"; $T_HDR_info = "\.text\n\t\.align 3\n"; $T_HDR_entry = "\.text\n\t\.align 3\n"; $T_HDR_fast = "\.text\n\t\.align 3\n"; @@ -89,7 +111,7 @@ sub init_TARGET_STUFF { $T_COPY_DIRVS = '^\s+\.(IMPORT|EXPORT)'; $T_hsc_cc_PAT = '\.STRING.*\)(hsc|cc) (.*)\\\\x09(.*)\\\\x00"'; - $T_DOT_WORD = '\.word'; + $T_DOT_WORD = '\.(blockz|word|half|byte)'; $T_DOT_GLOBAL = '^\s+\.EXPORT'; $T_HDR_literal = "\t.SPACE \$TEXT\$\n\t.SUBSPA \$LIT\$\n"; $T_HDR_misc = "\t.SPACE \$TEXT\$\n\t.SUBSPA \$CODE\$\n\t\.align 4\n"; @@ -104,7 +126,7 @@ sub init_TARGET_STUFF { $T_HDR_direct = "\t.SPACE \$TEXT\$\n\t.SUBSPA \$CODE\$\n\t\.align 4\n"; #--------------------------------------------------------# - } elsif ( $TargetPlatform =~ /^i386-.*-(linuxaout|freebsd2|nextstep3|cygwin32|mingw32)$/ ) { + } elsif ( $TargetPlatform =~ /^i386-.*-(linuxaout|freebsd2|netbsd|nextstep3|cygwin32|mingw32)$/ ) { # NeXT added but not tested. CaS $T_STABBY = 1; # 1 iff .stab things (usually if a.out format) @@ -126,7 +148,8 @@ sub init_TARGET_STUFF { $T_HDR_data = "\.data\n\t\.align 2\n"; $T_HDR_consist = "\.text\n"; $T_HDR_closure = "\.data\n\t\.align 2\n"; - $T_HDR_srt = "\.data\n\t\.align 2\n"; + $T_HDR_closure = "\.data\n\t\.align 2\n\t.long 0\n" if ( $TargetPlatform =~ /.*-mingw32$/ ); + $T_HDR_srt = "\.text\n\t\.align 2\n"; $T_HDR_info = "\.text\n\t\.align 2\n"; # NB: requires padding $T_HDR_entry = "\.text\n"; # no .align so we're right next to _info (arguably wrong...?) $T_HDR_fast = "\.text\n\t\.align 2,0x90\n"; @@ -134,12 +157,12 @@ sub init_TARGET_STUFF { $T_HDR_direct = "\.text\n\t\.align 2,0x90\n"; #--------------------------------------------------------# - } elsif ( $TargetPlatform =~ /^i386-.*-(solaris2|linux|freebsd3)$/ ) { + } elsif ( $TargetPlatform =~ /^i386-.*-(solaris2|linux|freebsd|netbsd_elf)$/ ) { $T_STABBY = 0; # 1 iff .stab things (usually if a.out format) $T_US = ''; # _ if symbols have an underscore on the front $T_PRE_APP = # regexp that says what comes before APP/NO_APP - ($TargetPlatform =~ /-(linux|freebsd3)$/) ? '#' : '/' ; + ($TargetPlatform =~ /-(linux|freebsd|netbsd_elf)$/) ? '#' : '/' ; $T_CONST_LBL = '^\.LC(\d+):$'; # regexp for what such a lbl looks like $T_POST_LBL = ':'; $T_X86_PRE_LLBL_PAT = '\.L'; @@ -149,7 +172,7 @@ sub init_TARGET_STUFF { $T_MOVE_DIRVS = '^(\s*(\.(p2)?align\s+\d+(,0x90)?|\.globl\s+\S+|\.text|\.data|\.section\s+.*|\.type\s+.*|\.Lfe.*\n\t\.size\s+.*|\.size\s+.*|\.ident.*)\n)'; $T_COPY_DIRVS = '\.(globl)'; - if ( $TargetPlatform =~ /freebsd3/ ) { + if ( $TargetPlatform =~ /freebsd|netbsd_elf/ ) { $T_hsc_cc_PAT = '\.ascii.*\)(hsc|cc) (.*)\\\\11"\n\t\.ascii\s+"(.*)\\\\0"'; } else { $T_hsc_cc_PAT = '\.string.*\)(hsc|cc) (.*)\\\\t(.*)"'; @@ -162,12 +185,12 @@ sub init_TARGET_STUFF { $T_HDR_data = "\.data\n\t\.align 4\n"; # ToDo: change align?? $T_HDR_consist = "\.text\n"; $T_HDR_closure = "\.data\n\t\.align 4\n"; # ToDo: change align? - $T_HDR_srt = "\.data\n\t\.align 4\n"; # ToDo: change align? - $T_HDR_info = "\.text\n\t\.align 16\n"; # NB: requires padding + $T_HDR_srt = "\.text\n\t\.align 4\n"; # ToDo: change align? + $T_HDR_info = "\.text\n\t\.align 4\n"; # NB: requires padding $T_HDR_entry = "\.text\n"; # no .align so we're right next to _info (arguably wrong...?) - $T_HDR_fast = "\.text\n\t\.align 16\n"; - $T_HDR_vector = "\.text\n\t\.align 16\n"; # NB: requires padding - $T_HDR_direct = "\.text\n\t\.align 16\n"; + $T_HDR_fast = "\.text\n\t\.align 4\n"; + $T_HDR_vector = "\.text\n\t\.align 4\n"; # NB: requires padding + $T_HDR_direct = "\.text\n\t\.align 4\n"; #--------------------------------------------------------# } elsif ( $TargetPlatform =~ /^m68k-.*-sunos4/ ) { @@ -189,7 +212,7 @@ sub init_TARGET_STUFF { $T_HDR_data = "\.data\n\t\.even\n"; $T_HDR_consist = "\.text\n"; $T_HDR_closure = "\.data\n\t\.even\n"; - $T_HDR_srt = "\.data\n\t\.even\n"; + $T_HDR_srt = "\.text\n\t\.even\n"; $T_HDR_info = "\.text\n\t\.even\n"; $T_HDR_entry = "\.text\n\t\.even\n"; $T_HDR_fast = "\.text\n\t\.even\n"; @@ -216,7 +239,7 @@ sub init_TARGET_STUFF { $T_HDR_data = "\t\.data\n\t\.align 2\n"; $T_HDR_consist = 'TOO LAZY TO DO THIS TOO'; $T_HDR_closure = "\t\.data\n\t\.align 2\n"; - $T_HDR_srt = "\t\.data\n\t\.align 2\n"; + $T_HDR_srt = "\t\.text\n\t\.align 2\n"; $T_HDR_info = "\t\.text\n\t\.align 2\n"; $T_HDR_entry = "\t\.text\n\t\.align 2\n"; $T_HDR_fast = "\t\.text\n\t\.align 2\n"; @@ -264,7 +287,7 @@ sub init_TARGET_STUFF { $T_COPY_DIRVS = '\.(global|proc|stab)'; $T_hsc_cc_PAT = '\.asciz.*\)(hsc|cc) (.*)\\\\t(.*)"'; - $T_DOT_WORD = '\.(word|byte|half|skip)'; + $T_DOT_WORD = '\.(word|byte|half|skip|uahalf|uaword)'; $T_DOT_GLOBAL = '^\t\.global'; $T_HDR_literal = "\.text\n\t\.align 8\n"; $T_HDR_misc = "\.text\n\t\.align 4\n"; @@ -434,7 +457,7 @@ sub mangle_asm { $chkcat[$i] = 'literal'; $chksymb[$i] = $1; - } elsif ( /^$TUS[@]?__stg_split_marker(\d+)$TPOSTLBL[@]?$/o ) { + } elsif ( /^$TUS[@]?__stg_split_marker(\d*)$TPOSTLBL[@]?$/o ) { $chk[++$i] = $_; $chkcat[$i] = 'splitmarker'; $chksymb[$i] = $1; @@ -477,6 +500,11 @@ sub mangle_asm { $srtchk{$1} = $i; + } elsif ( /^$TUS[@]?([A-Za-z0-9_]+)_ct$TPOSTLBL[@]?$/o ) { + $chk[++$i] = $_; + $chkcat[$i] = 'data'; + $chksymb[$i] = ''; + } elsif ( /^$TUS[@]?ghc.*c_ID$TPOSTLBL/o ) { $chk[++$i] = $_; $chkcat[$i] = 'consist'; @@ -486,7 +514,6 @@ sub mangle_asm { } elsif ( /^$TUS[A-Za-z0-9_]+\.\d+$TPOSTLBL[@]?$/o || /^$TUS[@]?.*_CAT$TPOSTLBL[@]?$/o # PROF: _entryname_CAT - || /^$TUS[@]?CC_.*_struct$TPOSTLBL[@]?$/o # PROF: _CC_ccident_struct || /^$TUS[@]?.*_done$TPOSTLBL[@]?$/o # PROF: _module_done || /^$TUS[@]?_module_registered$TPOSTLBL[@]?$/o # PROF: _module_registered ) { @@ -504,7 +531,7 @@ sub mangle_asm { $chkcat[$i] = 'toc'; $chksymb[$i] = $1; - } elsif ( /^$TUS[@]?CC(S)?_.*$/ ) { + } elsif ( /^$TUS[@]?([A-Za-z0-9_]+)_cc(s)?$TPOSTLBL[@]?$/o ) { # all CC_ symbols go in the data section... $chk[++$i] = $_; $chkcat[$i] = 'data'; @@ -559,7 +586,7 @@ sub mangle_asm { unless $KNOWN_FUNNY_THING{$thing} || /^$TUS[@]?stg_.*$TPOSTLBL[@]?$/o # RTS internals || /^$TUS[@]__fexp_.*$TPOSTLBL$/o # foreign export - || /^$TUS[@]?_reg.*$TPOSTLBL$/o # PROF: __reg + || /^$TUS[@]?__init.*$TPOSTLBL$/o # __init || /^$TUS[@]?.*_btm$TPOSTLBL$/o # large bitmaps || /^$TUS[@]?.*_closure_tbl$TPOSTLBL$/o; # closure tables $chk[++$i] = $_; @@ -643,6 +670,7 @@ sub mangle_asm { if ($TargetPlatform =~ /^i386-/) { $p =~ s/^\tpushl \%edi\n//; $p =~ s/^\tpushl \%esi\n//; + $p =~ s/^\tpushl \%ebx\n//; $p =~ s/^\tsubl \$\d+,\%esp\n//; $p =~ s/^\tmovl \$\d+,\%eax\n\tcall __alloca\n// if ($TargetPlatform =~ /^.*-cygwin32/); } elsif ($TargetPlatform =~ /^m68k-/) { @@ -681,6 +709,9 @@ sub mangle_asm { print STDERR "$Pgm: unknown prologue mangling? $TargetPlatform\n"; } + # HWL HACK: dont die, just print a warning + #print stderr "HWL: this should die! Prologue junk?: $p\n" if $p =~ /^\t[^\.]/ + # && $TargetPlatform !~ /^powerpc-/; #ToDo: remove test die "Prologue junk?: $p\n" if $p =~ /^\t[^\.]/ && $TargetPlatform !~ /^powerpc-/; #ToDo: remove test @@ -702,7 +733,10 @@ sub mangle_asm { $e =~ s/^\tret\n//; $e =~ s/^\tpopl \%edi\n//; $e =~ s/^\tpopl \%esi\n//; + $e =~ s/^\tpopl \%edx\n//; + $e =~ s/^\tpopl \%ecx\n//; $e =~ s/^\taddl \$\d+,\%esp\n//; + $e =~ s/^\tsubl \$-\d+,\%esp\n//; } elsif ($TargetPlatform =~ /^m68k-/) { $e =~ s/^\tunlk a6\n//; $e =~ s/^\trts\n//; @@ -720,7 +754,10 @@ sub mangle_asm { } else { print STDERR "$Pgm: unknown epilogue mangling? $TargetPlatform\n"; } - die "Epilogue junk?: $e\n" if $e =~ /^\t[^\.]/ + # HWL HACK: dont die, just print a warning + #print stderr "HWL: this should die! Epilogue junk?: $e\n" if $e =~ /^\t[^\.]/ + # && $TargetPlatform !~ /^powerpc-/; #ToDo: remove test + die "Epilogue junk?: $e\n" if $e =~ /^\t[^\.\n]/ && $TargetPlatform !~ /^powerpc-/; #ToDo: remove test # glue together what's left @@ -733,7 +770,7 @@ sub mangle_asm { # toss the register-windowing save/restore/ret* instructions # directly: if ( $TargetPlatform =~ /^sparc-/ ) { - $c =~ s/^\t(save .*|restore|ret|retl)\n//g; + $c =~ s/^\t(save.*|restore|ret|retl)\n//g; # throw away PROLOGUE comments $c =~ s/^\t!#PROLOGUE# 0\n\t!#PROLOGUE# 1\n//; } @@ -768,7 +805,28 @@ sub mangle_asm { # (this SEGVs perl4 on alphas, you see) $to_move = $1; - if ( $i < ($numchks - 1) + + # on x86 we try not to copy any directives into a literal + # chunk, rather we keep looking for the next real chunk. This + # is because we get things like + # + # .globl blah_closure + # .LC32 + # .string "..." + # blah_closure: + # ... + # + if ( $TargetPlatform =~ /^(i386|sparc)/ && $to_move =~ /$TCOPYDIRVS/ ) { + $j = $i + 1; + while ( $j < $numchks && $chk[$j] =~ /$T_CONST_LBL/) { + $j++; + } + if ( $j < $numchks ) { + $chk[$j] = $to_move . $chk[$j]; + } + } + + elsif ( $i < ($numchks - 1) && ( $to_move =~ /$TCOPYDIRVS/ || ($TargetPlatform =~ /^hppa/ && $to_move =~ /align/ && $chkcat[$i+1] eq 'literal') )) { $chk[$i + 1] = $to_move . $chk[$i + 1]; @@ -874,7 +932,7 @@ sub mangle_asm { }; &print_doctored($chk[$i], 0); if ($TargetPlatform =~ /^powerpc-|^rs6000-/ && $printDS) { -#ok if ($chksymb[$i] !~ /\_regMain/) { +#ok if ($chksymb[$i] !~ /\__init_Main/) { print OUTASM "\.csect ${chksymb[$i]}[DS]\n"; print OUTASM "${p}TOC[tc0], 0\n"; #ok } @@ -967,7 +1025,7 @@ sub mangle_asm { $chk[$infochk{$symb}] =~ s/\.long ([A-Za-z]\S+_upd)/\.long \.\1/; print OUTASM $chk[$infochk{$symb}]; } else { - print OUTASM &rev_tbl($symb, $chk[$infochk{$symb}], 1); + print OUTASM &rev_tbl($symb, $chk[$infochk{$symb}], 1); } # entry code will be put here! @@ -1014,8 +1072,8 @@ sub mangle_asm { } elsif ( $TargetPlatform =~ /^powerpc-|^rs6000-/ ) { $c =~ s/^\tb \.${T_US}${symb}_fast\d+\n//; } elsif ( $TargetPlatform =~ /^sparc-/ ) { - $c =~ s/^\tcall ${T_US}${symb}_fast\d+,.*\n\tnop\n//; - $c =~ s/^\tcall ${T_US}${symb}_fast\d+,.*\n(\t[a-z].*\n)/$1/; + $c =~ s/^\tcall\s+${T_US}${symb}_fast\d+,.*\n\t\s*nop\n//; + $c =~ s/^\tcall\s+${T_US}${symb}_fast\d+,.*\n(\t\s*[a-z].*\n)/$1/; } else { print STDERR "$Pgm: mystery slow-fast dropthrough: $TargetPlatform\n"; } @@ -1154,7 +1212,8 @@ sub print_doctored { local($_, $need_fallthru_patch) = @_; if ( $TargetPlatform !~ /^i386-/ - || ! /^\t[a-z]/ ) { # no instructions in here, apparently + || ! /^\t[a-z]/ # no instructions in here, apparently + || /^${T_US}__init_[A-Za-z0-9_]+${T_POST_LBL}/) { print OUTASM $_; return; } @@ -1213,7 +1272,7 @@ sub print_doctored { } if ($StolenX86Regs <= 3 ) { # spurious uses of edi? s/^\tmovl (.*),\%edi\n\tjmp \*%edi\n/\tmovl $1,\%eax\n\tjmp \*\%eax\n/g; - s/^\tjmp \*(-?\d*)\((.*\%edi.*)\)\n/\tmovl $2,\%eax\n\tjmp \*$1\(\%eax\)\n/g; + s/^\tjmp \*(-?\d*\(.*\%edi.*\))\n/\tmovl $1,\%eax\n\tjmp \*\%eax\n/g; s/^\tjmp \*\%edi\n/\tmovl \%edi,\%eax\n\tjmp \*\%eax\n/g; die "$Pgm: (mangler) still have jump involving \%edi!\n$_" if /(jmp|call) .*\%edi/; @@ -1332,7 +1391,7 @@ sub rev_tbl { push(@words, $lines[$i]); } } else { # hppa weirdness - for ( ; $i <= $#lines && $lines[$i] =~ /^\s+\.(word|IMPORT)/; $i++) { + for ( ; $i <= $#lines && $lines[$i] =~ /^\s+($TDOTWORD|\.IMPORT)/; $i++) { if ($lines[$i] =~ /^\s+\.IMPORT/) { push(@imports, $lines[$i]); } else { @@ -1347,7 +1406,8 @@ sub rev_tbl { # now throw away the first word (SRT) iff it is empty. # The .zero business is for Linux/ELF. # The .skip business is for Sparc/Solaris/ELF. - if ($discard1 && $words[0] =~ /^\t?($TDOTWORD\s+0|\.zero\s+4|\.skip\s+4)/) { + # The .blockz business is for HPPA. + if ($discard1 && $words[0] =~ /^\t?($TDOTWORD\s+0|\.zero\s+4|\.skip\s+4|\.blockz\s+4)/) { shift(@words) } @@ -1458,7 +1518,12 @@ sub mangle_powerpc_tailjump { }; $c; } +\end{code} -# make "require"r happy... -1; +\begin{code} +sub tidy_up_and_die { + local($return_val, $msg) = @_; + print STDERR $msg; + exit (($return_val == 0) ? 0 : 1); +} \end{code}