aboutsummaryrefslogtreecommitdiff
path: root/mkrelocxex.pl
diff options
context:
space:
mode:
Diffstat (limited to 'mkrelocxex.pl')
-rwxr-xr-xmkrelocxex.pl44
1 files changed, 25 insertions, 19 deletions
diff --git a/mkrelocxex.pl b/mkrelocxex.pl
index a871cd5..a46360b 100755
--- a/mkrelocxex.pl
+++ b/mkrelocxex.pl
@@ -2,6 +2,7 @@
# mkrelocxex prototype in perl (will rewrite in C).
# this version only supports init addresses, not run addresses.
+# *very* ugly code, sorry about that.
use bytes;
@@ -45,17 +46,6 @@ sub read_seg {
return @bytes;
}
-sub print_table {
- my ($name, $t) = @_;
- print "\n$name byte table:\n";
- my $i = 0;
- for(@$t) {
- printf "\$%04x ", $_;
- print "\n" if $i && ($i & 10 == 0);
- }
- print "\n";
-}
-
($start, $end) = read_header($lo);
($hi_start, $hi_end) = read_header($hi);
@@ -77,20 +67,33 @@ if(($hi_start != ($start + 0x0100)) || ($hi_end != ($end + 0x0100))) {
@bytes = read_seg($lo, $start, $end);
@hi_bytes = read_seg($hi, $hi_start, $hi_end);
+@bit_table = ();
for($i = 0; $i < @bytes; $i++) {
my ($a, $b) = ($bytes[$i], $hi_bytes[$i]);
- next if $a == $b;
- if($b == ($a + 1)) {
- push @hi_table, ($i + $start);
+ my $bit;
+
+ if($a == $b) {
+ $bit = 0;
+ } elsif($b == ($a + 1)) {
+ $bit = 1;
} else {
die "invalid difference (not 0 or 1)\n";
}
+
+ my $table_idx = int($i / 8);
+ my $pos = 7 - $i % 8;
+ #warn "$i $table_idx $pos\n";
+ $bit_table[$table_idx] |= ($bit * (1 << $pos));
}
-push(@hi_table, 0);
+$offset = $start;
-print_table("hi", \@hi_table);
-print "table size: " . @hi_table . " bytes\n\n";
+if(0) {
+ for(@bit_table) {
+ printf("\$%04x: %08b \$%04x\n", $offset, $_, $_);
+ $offset += 8;
+ }
+}
($istart, $iend) = read_header($lo);
@@ -127,9 +130,12 @@ $rcode .= chr(0);
$rcode .= chr($init & 0xff);
$rcode .= chr($init >> 8);
-for(@hi_table) {
+printf "bitmap table starts at \$%04x\n", ($rstart + length($rcode));
+
+for(@bit_table) {
+ die "bad relocation" if $_ > 0xff;
$rcode .= chr($_ & 0xff);
- $rcode .= chr($_ >> 8);
+ #$rcode .= chr($_ >> 8);
}
$rend = $rstart + length($rcode) - 1;