#!/bin/bash # hawklink -- linker for the Hawk, using the smal assembler # hawklink [parameters] a b c d e ... # hawklink -help -- gives more documentation # Author: Douglas W. Jones, Department of Computer Science, U. of Iowa. # Copyright 2019, all rights released under Creative Commons CC0 license; # -- that is to say, the author wishes to retain no rights to this work. # Warrantee: It seems to work, what more can you ask of free software; # -- this code has been successfully used by hundreds of students, # -- and it would be nice if it worked for you as well. # version 9/15/2019 -- use exit codes so it works in make scripts myname=`basename $0` if [ $# -lt 1 ] then echo "$myname requires parameters" echo "$myname -help is available" exit 1 fi if [ -help = $1 ] then echo "$myname [options] a b c d e ... links SMAL object and library files named a, b, c, d and e into a new loadable file called link.o (by default) no options are required, but the following are allowed:" echo " -r nnnn -- start relocatable code at nnnn (a hex address) -c nnnn -- start commons at nnnn (a hex address) -m -- suppress linking with standard monitor -o ffff -- direct output to file ffff.o instead of link.o -d -- dump the linker symbol table to link.d or ffff.d " exit 1 fi # defaults for linkage origin=1000 # default for -r option common=10000 # default for -c option monitor=monitor.o # -m option undoes this library=~dwjones/lib/hawk # no option overrides this outfile=link # default for -o option dump="" # default for -d option (don't dump) smal="~dwjones/bin/smal32 -L -U ${library}" # parse options -- loop exits on first non-option while [ $# -gt 0 ] do case $1 in -c) if [ $# -gt 1 ] then common=$2 shift shift else echo "$myname -c nnn requires a hex number nnn" echo "$myname -help explains options" exit 1 fi ;; -r) if [ $# -gt 1 ] then origin=$2 shift shift else echo "$myname -r nnn requires a hex number nnn" echo "$myname -help explains options" exit 1 fi ;; -m) monitor="" shift ;; -o) if [ $# -gt 1 ] then outfile=$2 shift shift else echo "$myname -o fff requires a file name fff" echo "$myname -help explains options" exit 1 fi ;; -d) dump="-D" shift ;; -*) echo "$myname $1 option unknown" echo "$myname -help explains options" exit 1 ;; *) break ;; esac done if [ $# -lt 1 ] then echo "$myname found no object files" echo "$myname -help explains options" exit 1 fi # build linker control file header echo TITLE "$myname $*" > ${outfile}.a echo ".=#${origin}" >> ${outfile}.a echo "C=#${common}" >> ${outfile}.a if [ -n "${monitor}" ] then echo "USE \"${monitor}\"" >> ${outfile}.a fi # build linker control file body while [ $# -gt 0 ] do case $1 in -*) rm ${outfile}.a echo "$myname $1 unexpected option" echo "$myname -help explains command format" exit 1 ;; *) if [ -r $1 -o -r ${library}/$1 ] then echo "USE \"$1\"" >> ${outfile}.a shift else echo "$myname $1 unreadable object file" echo "$myname -help is available" exit 1 fi ;; esac done # build linker control file trailer echo RUNUSED=C >> ${outfile}.a echo RUNAVAIL=#20000 >> ${outfile}.a # actually do the linkage eval ${smal} ${dump} ${outfile}.a exitcode=$? rm ${outfile}.a # cleanup if [ -n "${dump}" ] then sort -k2 -o ${outfile}.d ${outfile}.d fi exit ${exitcode}