diff options
Diffstat (limited to 'data/bin2bac.pl')
-rwxr-xr-x | data/bin2bac.pl | 49 |
1 files changed, 39 insertions, 10 deletions
diff --git a/data/bin2bac.pl b/data/bin2bac.pl index 0d00c7c..edc67bd 100755 --- a/data/bin2bac.pl +++ b/data/bin2bac.pl @@ -91,22 +91,22 @@ sub makebac($$$$) { $entrypt = 0 unless(defined($entrypt)); # Raw data length, must be recorded before pack_relocs() - my $data_len = = length($data); + my $data_len = length($data); my $relptr; ($data, $relptr) = pack_relocs($data, $relocs); $bld = "\x01\xc9\x00\xc5\x2a\x1c\xfe\xe5\x5d\x54\x4e\x09"; - $bld .= "\x7e\xd6\x08\x38\x0a\x0e\x06\x09\x4f\xed\x80"; + $bld .= "\x7e\xd6\x08\x38\x0a\x0e\x06\x09\x4f\xed\xb0"; $bld .= "\x23\x23\x18\xf1\x21"; # 16-bit length of data not including relocations $bld .= pack('v', $data_len); - $bld .= "\xd1\x19\xeb\x1a\x13\xfe\x7f\x38\x0e\x4f\x06\x00"; + $bld .= "\xd1\x19\xeb\x1a\x13\xfe\x80\x30\x0e\x4f\x06\x00"; $bld .= "\x09\x7d\x86\x77\x7c\x23\x8e\x77\x23\x18\xec"; $bld .= "\xd6\x81\x38\x06\x47\x1a\x13\x4f\x18\xeb\x01"; # 16-bit offset from final relocation to entry point $bld .= pack('v', $entrypt - $relptr); - $bld[2] = "\x09\xe9"; + $bld .= "\x09\xe9"; } my $q = "\x82"; # Output (program start marker) @@ -118,7 +118,7 @@ sub makebac($$$$) { $q .= bacstmt(++$r, \$left, "\x83\xc1\xf1\x5a\x00\xbb\xc7\x1e\xfe\xce\x36\xc7". "\x1f\xfe\xce\x36\xce\x34\xf5\xc7". - pack("v", length($bld)). + pack("v", length($bld)+2). # +2 for statement trailer "\xf8\xce\x3a\xb7"); my $i = 0; @@ -156,17 +156,46 @@ sub makebac($$$$) { return $q; } -($file, $org, $entry, $relocfile) = @ARGV; +($file, $org, $entry, $entryname) = @ARGV; -$org = oct $org if ( $org =~ /^0/ ); -$entry = oct $entry if ( $entry =~ /^0/ ); +if (!defined($file)) { + die "Usage: $0 inputfile {load_addr|relocfile} [entrypoint|deffile [entryname]]\n"; +} + +if ($org !~ /^[0-9]/) { + $relocfile = $org; + undef $org; +} else { + $org = oct $org if ( $org =~ /^0/ ); +} + +if ($entry !~ /^[0-9]/) { + $entryfile = $entry; + $entryname = '_start' unless(defined($entryname)); + undef $entry; + + open(DEF, '<', $entryfile) or die "$0: $entryfile: $!\n"; + while ($line = <DEF>) { + chomp $line; + @l = split(/\s+/, $line); + if ($l[0] =~ /^DEFC$/i && $l[1] eq $entryname && $l[2] eq '=' && + $l[3] =~ /^\$([0-9a-f]+)$/i) { + $entry = hex $1; + last; + } + } + close(DEF); + if (!defined($entry)) { + die "$0: symbol $entryname not found in file $entryfile\n"; + } +} else { + $entry = oct $entry if ( $entry =~ /^0/ ); +} open(FILE, '<:raw', $file) or die "$0: $file: $!\n"; read(FILE, $dd, 65536); close(FILE); -undef $org if ($org =~ /^(bofa|reloc|\-)$/i); - if (defined($relocfile)) { if (defined($org)) { die "$0: cannot specify load address and relocation file both\n"; |