Hacky way to create an executable via aslink's bank feature and an ihx file per bank
authorNick Downing <nick@ndcode.org>
Fri, 12 Aug 2022 05:04:16 +0000 (15:04 +1000)
committerNick Downing <nick@ndcode.org>
Fri, 12 Aug 2022 05:04:40 +0000 (15:04 +1000)
12 files changed:
bin/aslink
bin/aspdp11
usr/src/cmd/a.sh
usr/src/cmd/aout_hex2bin.py [new file with mode: 0755]
usr/src/cmd/c/c11.c
usr/src/libc/a.sh
usr/src/libc/crt/cerror.s
usr/src/libc/crt/mcount.s
usr/src/libc/csu/crt0.s
usr/src/libc/gen/ldexp11.s
usr/src/libc/sys/access.s
usr/src/libc/sys/umount.s

index c4fdbea..1aa1f29 100755 (executable)
Binary files a/bin/aslink and b/bin/aslink differ
index 8eae3a1..4b8124c 100755 (executable)
Binary files a/bin/aspdp11 and b/bin/aspdp11 differ
index 131c4d2..69ceae4 100755 (executable)
@@ -9,4 +9,6 @@ export PATH=`pwd`/../../../bin:`pwd`
 #cc -n -s -o dump dump.o
 cc -O -S dump.c
 as -l -o dump.o dump.s
-ld -L/lib /lib/crt0.o -o dump -n -s -m -u dump.o -lc
+ld -bD=0x2800 -L/lib /lib/crt0.o -o dump -n -s -m1 -u -w dump.o -lc
+/usr/bin/python3 aout_hex2bin.py dumpI.ihx dumpD.ihx dump <dump.map
+chmod a+x dump
diff --git a/usr/src/cmd/aout_hex2bin.py b/usr/src/cmd/aout_hex2bin.py
new file mode 100755 (executable)
index 0000000..8f23ac8
--- /dev/null
@@ -0,0 +1,69 @@
+#!/usr/bin/env python3
+
+import re
+import sys
+from intelhex import IntelHex
+
+EXIT_SUCCESS = 0
+EXIT_FAILURE = 1
+
+NMAGIC = 0o410
+HEADER_SIZE = 0x10
+
+if len(sys.argv) < 4:
+  print(f'usage: {sys.argv[0]:s} inI.ihx inD.ihx a.out <in.map')
+  sys.exit(EXIT_FAILURE)
+inI_ihx = sys.argv[1]
+inD_ihx = sys.argv[2]
+a_out = sys.argv[3]
+
+print('map')
+map = {}
+re_bank = re.compile('          (....)  ([be]_[ID]|[al]_(text|data))$')
+for line in sys.stdin:
+  line = line.rstrip()
+  match = re_bank.match(line)
+  if match is not None:
+    print(match.group(1), match.group(2))
+    map[match.group(2)] = int(match.group(1), 16)
+I_size = map['e_I'] - map['b_I']
+D_size = map['e_D'] - map['b_D']
+
+intelhexI = IntelHex(inI_ihx)
+intelhexD = IntelHex(inD_ihx)
+
+text_size = map['l_text']
+assert text_size == I_size
+text_size = (text_size + 0x3f) & ~0x3f
+
+data_size = map['l_data']
+data_size = (data_size + 1) & ~1
+
+bss_size = D_size - data_size
+bss_size = (bss_size + 1) & ~1
+
+entry_point = intelhexI.start_addr['EIP'] | 1
+
+hdr = [0] * HEADER_SIZE
+hdr[0] = NMAGIC & 0xff
+hdr[1] = (NMAGIC >> 8) & 0xff
+hdr[2] = text_size & 0xff
+hdr[3] = (text_size >> 8) & 0xff
+hdr[4] = data_size & 0xff
+hdr[5] = (data_size >> 8) & 0xff
+hdr[6] = bss_size & 0xff
+hdr[7] = (bss_size >> 8) & 0xff
+# 8, 9 = string size (unsupported)
+hdr[0xa] = entry_point & 0xff
+hdr[0xb] = (entry_point >> 8) & 0xff
+# 0xc, 0xd = pad (unsupported)
+# 0xe, 0xf = relflg (unsupported)
+
+intelhexI.padding = 0
+text = list(intelhexI.tobinstr(0, text_size - 1))
+
+intelhexD.padding = 0
+data = list(intelhexD.tobinstr(0, data_size - 1))
+
+with open(a_out, 'wb') as fout:
+  fout.write(bytes(hdr + text + data))
index aeb829f..8958b88 100644 (file)
@@ -873,7 +873,7 @@ getree()
  fprintf(stderr, "CSPACE\n");
 #endif
                t = outname(s);
-               printf(".area   comm_%.8s (rel,ovr)\n%.8s:.ds   %d\n.area       %s\n", t, t, geti(), area);
+               printf(".bank   D\n.area        comm_%.8s (rel,ovr,bank = D)\n%.8s:.ds  %d\n.area       %s\n", t, t, geti(), area);
                break;
 
        case SSPACE:
index f50a35c..9bf8876 100755 (executable)
@@ -4,3 +4,4 @@ export APOUT_ROOT=`pwd`/../../..
 export PATH=`pwd`/../../../bin:`pwd`
 #cc -c -O csu/crt0.s
 as -l -o crt0.o csu/crt0.s
+cp crt0.* ../../../lib
index 8f08a1d..adf4438 100644 (file)
@@ -3,7 +3,8 @@
 ; sets errno, returns -1.
 
 .globl cerror
-       .area   comm__errno (rel,ovr)
+       .bank   D
+       .area   comm__errno (rel,ovr,bank = D)
 _errno:        .ds     2
        .area   text
 
index 93a9fb2..a7bd41a 100644 (file)
@@ -2,7 +2,8 @@
 ; count subroutine calls during profiling
 
 .globl mcount
-       .area   comm_countbase (rel,ovr)
+       .bank   D
+       .area   comm_countbase (rel,ovr,bank = D)
 countbase:
        .ds     2
        .area   text
index 6fadc42..ea02b2b 100644 (file)
@@ -1,9 +1,12 @@
 ; C runtime startoff
 
-; set segment ordering for aslink
-.area  text
-.area  data
-.area  bss
+; set up banks and areas, assuming pure executable
+; text area will be reset to bank D for impure executable
+.bank  I (fsfx = I)
+.bank  D (fsfx = D)
+.area  text (bank = I)
+.area  data (bank = D)
+.area  bss (bank = D)
 
 .globl _exit, _environ
 .globl start
@@ -40,3 +43,5 @@ _environ:
        .ds     2
 .area  data
        .ds     2               ; loc 0 for I/D; null ptr points here.
+
+.end   start
index 8fe3ea4..608ef11 100644 (file)
@@ -27,7 +27,8 @@ _ldexp:
 0$:
        jmp     cret
 
-       .area   comm__errno (rel,ovr)
+       .bank   D
+       .area   comm__errno (rel,ovr,bank = D)
 _errno:        .ds     2
        .area   data
 huge:  .dw     0o77777
index 2c33979..f712199 100644 (file)
@@ -7,7 +7,8 @@
 
 .globl _access
 .globl csv, cret
-       .area   comm__errno (rel,ovr)
+       .bank   D
+       .area   comm__errno (rel,ovr,bank = D)
 _errno:        .ds     2
        .area   text
 
index 6414158..9b87670 100644 (file)
@@ -5,7 +5,8 @@
 .globl cerror
 indir  = 0
 .umount = 22
-       .area   comm__errno (rel,ovr)
+       .bank   D
+       .area   comm__errno (rel,ovr,bank = D)
 _errno:        .ds     2
        .area   text