summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2016-10-12 03:39:56 (GMT)
committerH. Peter Anvin <hpa@zytor.com>2016-10-12 03:39:56 (GMT)
commitcc2a3de1a2fc0deec265902de2838740b2d894a6 (patch)
tree02399831cd0be52bf4c4b5d4c548147bca272bf6
parentc07de56eb72f7bfe313d3dddd1ccfce87a0de209 (diff)
downloadabc80-cc2a3de1a2fc0deec265902de2838740b2d894a6.zip
abc80-cc2a3de1a2fc0deec265902de2838740b2d894a6.tar.gz
abc80-cc2a3de1a2fc0deec265902de2838740b2d894a6.tar.bz2
abc80-cc2a3de1a2fc0deec265902de2838740b2d894a6.tar.xz
bin2bac: actually make the relocatable loader work
Now it will actually load and process relocations.
-rw-r--r--data/bacldrr.asm4
-rwxr-xr-xdata/bin2bac.pl26
2 files changed, 19 insertions, 11 deletions
diff --git a/data/bacldrr.asm b/data/bacldrr.asm
index 0944c0e..0d8cc46 100644
--- a/data/bacldrr.asm
+++ b/data/bacldrr.asm
@@ -46,8 +46,8 @@ reloc:
reloc_loop:
ld a,(de)
inc de
- cp 7fh ; JR doesn't support testing the sign bit
- jr c,reloc_large
+ cp 80h ; JR doesn't support testing the sign bit
+ jr nc,reloc_large
ld c,a
ld b,0
diff --git a/data/bin2bac.pl b/data/bin2bac.pl
index 0d00c7c..2fab8a4 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,25 @@ sub makebac($$$$) {
return $q;
}
-($file, $org, $entry, $relocfile) = @ARGV;
+($file, $org, $entry) = @ARGV;
+
+if (!defined($file)) {
+ die "Usage: $0 inputfile {load_addr|relocfile} [entrypoint]\n";
+}
+
+if ($org !~ /^[0-9]/) {
+ $relocfile = $org;
+ undef $org;
+} else {
+ $org = oct $org if ( $org =~ /^0/ );
+}
-$org = oct $org if ( $org =~ /^0/ );
$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";