4 # By Richard W.M. Jones.
6 # $Id: dlife_disasm.pl,v 1.1 2002/04/05 14:40:26 rich Exp $
14 GetOptions ("help|?" => \$help);
18 printf STDERR "dlife_disasm.pl [--help] [file.dlo] > file.dla\n";
22 # Read the entire input file into memory so that we can do some
23 # clever stuff with string regexes.
31 # Remove anything which isn't [0-9a-f].
32 $code =~ tr/0-9a-fA-F//cd;
35 # Convert code to <xx>.
36 $code =~ s/(..)/<$1>/g;
38 # NOTE: The order of this substitutions IS important.
40 # CALLB and CALLF macros.
41 $code =~ s/<23>(<08>|<09>)((<00>|<01>)+)<22><27>/convert_call ($1, $2)/ge;
43 # JMPB and JMPF macros.
44 $code =~ s/(<08>|<09>)((<00>|<01>)+)<22><27>/convert_jmp ($1, $2)/ge;
46 # JMPBZ and JMPFZ macros.
47 $code =~ s/(<08>|<09>)((<00>|<01>)+)<22><07><27><26>/convert_jmpz ($1, $2)/ge;
49 # Basic FINDF and FINDB commands.
50 $code =~ s/(<08>|<09>)((<00>|<01>)+)/convert_find ($1, $2)/ge;
52 # Any other patterns are labels.
53 $code =~ s/((<00>|<01>)+)/convert_label ($1)/ge;
56 $code =~ s/(<2[0-3]>)(<2[4-7]>)/convert_move ($1, $2)/ge;
58 # SWAP macro. XXX Difficult ...
70 my $find_code = shift;
73 my $insn = $find_code eq "<08>" ? "CALLB" : "CALLF";
75 $pattern =~ s/<00>/1/g; # Pattern is complemented.
76 $pattern =~ s/<01>/0/g;
78 return "\n\t$insn ~$pattern\n";
83 my $find_code = shift;
86 my $insn = $find_code eq "<08>" ? "JMPB" : "JMPF";
88 $pattern =~ s/<00>/1/g; # Pattern is complemented.
89 $pattern =~ s/<01>/0/g;
91 return "\n\t$insn ~$pattern\n";
96 my $find_code = shift;
99 my $insn = $find_code eq "<08>" ? "JMPBZ" : "JMPFZ";
101 $pattern =~ s/<00>/1/g; # Pattern is complemented.
102 $pattern =~ s/<01>/0/g;
104 return "\n\t$insn ~$pattern\n";
109 my $find_code = shift;
112 my $insn = $find_code eq "<08>" ? "FINDB" : "FINDF";
114 $pattern =~ s/<00>/1/g; # Pattern is complemented.
115 $pattern =~ s/<01>/0/g;
117 return "\n\t$insn ~$pattern\n";
124 $pattern =~ s/<00>/0/g;
125 $pattern =~ s/<01>/1/g;
127 return "\n$pattern:\n";
132 my $push_code = shift;
133 my $pop_code = shift;
136 if ($push_code eq "<20>") { $src = "A" }
137 elsif ($push_code eq "<21>") { $src = "B" }
138 elsif ($push_code eq "<22>") { $src = "I" }
139 elsif ($push_code eq "<23>") { $src = "P" }
140 if ($pop_code eq "<24>") { $dst = "A" }
141 elsif ($pop_code eq "<25>") { $dst = "B" }
142 elsif ($pop_code eq "<26>") { $dst = "I" }
143 elsif ($pop_code eq "<27>") { $dst = "P" }
145 return "\n\tMOVE $src,$dst\n";