diff options
author | Robert de Bath <rdebath@poboxes.com> | 1996-11-03 22:33:35 +0100 |
---|---|---|
committer | Lubomir Rintel <lkundrak@v3.sk> | 2013-10-23 23:33:35 +0200 |
commit | c218c617b5be443b7968308506969ad2b726d73c (patch) | |
tree | 0051f396af56133d24fcf2ab757fabc78c1a09bf /as | |
parent | 0936b9aeab611665645a4e6bafaded7ca76dd189 (diff) | |
parent | 0d2fbe9b1bd284ce2cad55be17e8f2c896031a25 (diff) | |
download | dev86-c218c617b5be443b7968308506969ad2b726d73c.tar.gz |
Import Dev86src-0.0.8.tar.gzv0.0.8
Diffstat (limited to 'as')
-rw-r--r-- | as/Makefile | 7 | ||||
-rw-r--r--[-rwxr-xr-x] | as/as86_encap | 105 | ||||
-rw-r--r-- | as/genbin.c | 28 |
3 files changed, 110 insertions, 30 deletions
diff --git a/as/Makefile b/as/Makefile index 392b8e6..736d144 100644 --- a/as/Makefile +++ b/as/Makefile @@ -6,6 +6,9 @@ CC=bcc LDFLAGS=-s endif +# Temp needed for libc-5.4.7 +CFLAGS+=-Dwarn=as_warn + OBJS =as.o assemble.o error.o express.o \ genbin.o genlist.o genobj.o gensym.o \ keywords.o macro.o mops.o pops.o readsrc.o \ @@ -19,6 +22,10 @@ as86: $(OBJS) install: all install -d $(LIBDIR) install -m 755 as86 $(LIBDIR) + sed "s:%%LIBDIR%%:$(LIBDIR):" < as86_encap > tmp + install -d $(BINDIR) + install -m 755 tmp $(BINDIR)/as86_encap + -@rm -f tmp # typeconv.o: dummy # -cp -p ../ld/typeconv.o . diff --git a/as/as86_encap b/as/as86_encap index 45db468..8e5d4ab 100755..100644 --- a/as/as86_encap +++ b/as/as86_encap @@ -1,14 +1,65 @@ -#!/usr/bin/awk -f -BEGIN{ - started = 0; - prefix=ARGV[1] "_"; - if( 2 in ARGV ) prefix=ARGV[2]; - - sname = prefix "start"; - cmd = ARGV[1] ".sym"; - while(getline < cmd) - { - if(NF == 0) break; +#!/bin/sh - +# +# This file is simply an example of what can be done using the new binary +# and symbol table output functions. As shown it can be used to produce +# a C file containing the encapsulated binary of the assembly, plus any +# public symbols in the source are accessable to the C program. +# +# Use it in a makefile: +# +# .s.v: +# as86_encap $*.s $*.v $*_ $(AS86FLAGS) +# + +[ $# -lt 2 ] && { + echo "Usage: `basename $0` infile outfile prefix [as86 opts]" 1>&2 + exit 1 +} + +trap "rm -f _$$.* ; exit 99" 1 2 3 15 + +LIBDIR='%%LIBDIR%%' # Set by make install + +IFILE="$1" +OFILE="$2" +PREFIX="`basename $IFILE .s`_" + +shift ; shift +if [ $# -ge 1 ] +then case "$1" in + -* ) ;; + [A-Za-z_]* ) PREFIX="$1" + shift + ;; + esac +fi +RV=0 + +$LIBDIR/as86 "$@" "$IFILE" -b _$$.bin -s _$$.sym || RV=$? + +[ "$RV" = 0 ] && { + ( + cat _$$.sym + echo %%%% + od -v -t uC _$$.bin + ) | \ + awk > _$$.v -v prefix=$PREFIX ' BEGIN{ + sname = prefix "start"; + } + /^%%%%$/ { flg++; + if( flg == 1 ) + { + if( !started ) + printf "int %s = 0;\n", sname; + + printf "\n"; + printf "char %sdata[] = {\n", prefix; + bincount=0; + } + next; + } + flg==0 { + if(NF == 0) next; if( substr($2,1,4) == "0000" ) $2=substr($2,5); if( $1 == "+" && $4 == "$start" ) { @@ -19,22 +70,28 @@ BEGIN{ { printf "int %s%s = 0x%s;\n", prefix, $4, $2; } + next; } - - if( !started ) - printf "int %s = 0;\n", sname; - - printf "\n"; - printf "char %sdata[] = {\n", prefix; - cmd = "od " ARGV[1] ".bin -v -t uC"; - bincount=0; - while(cmd | getline) - { - if(NF == 0) break; + flg==1 { + if(NF == 0) next; printf " "; for(i=2;i<=NF;i++) { printf("%3d,", $i); bincount++; } printf "\n"; } - printf "};\n\n"; - printf "int %ssize = %d;\n", prefix, bincount; + END { + printf "};\n\n"; + printf "int %ssize = %d;\n", prefix, bincount; + } + ' + RV=$? +} + +[ "$RV" = 0 ] && { + if [ "X$OFILE" = "X-" ] + then cat _$$.v + else mv -f _$$.v "$OFILE" || RV=$? + fi } + +rm -f _$$.* +exit $RV diff --git a/as/genbin.c b/as/genbin.c index a36e6a2..377c6bf 100644 --- a/as/genbin.c +++ b/as/genbin.c @@ -10,9 +10,20 @@ PRIVATE char *asmbeg; /* beginning of assembler code */ /* for overwrite check */ /* bss-init to zero = NULL and not changed */ + +/* Sneaky stuff, the start of a binary file can be _negative_ for the I80386 + assembler. The -ve addresses are ones over 2GB (or "org -32") */ +#ifdef I80386 +PRIVATE soffset_t binfbuf; /* binary code buffer for file (counter) */ +PRIVATE soffset_t binmax; /* maximum value of binmbuf for pass 1 */ +PRIVATE soffset_t binmin; /* minimum value of binmbuf for pass 1 */ +#define PT soffset_t +#else PRIVATE offset_t binfbuf; /* binary code buffer for file (counter) */ PRIVATE offset_t binmax; /* maximum value of binmbuf for pass 1 */ PRIVATE offset_t binmin; /* minimum value of binmbuf for pass 1 */ +#define PT offset_t +#endif FORWARD void putbinoffset P((offset_t offset, count_t size)); @@ -170,7 +181,11 @@ PUBLIC void genbin() PUBLIC void initbin() { +#ifdef I80386 + binmin = ((offset_t)-1 >>1); /* greater than anything */ +#else binmin = -1; /* greater than anything */ +#endif } /* write char to binary file or directly to memory */ @@ -182,15 +197,16 @@ opcode_pt ch; { if (!binaryc) /* pass 1, just record limits */ { - if (binmbuf < binmin) + if ((PT)binmbuf < binmin) binmin = binmbuf; - if (++binmbuf > binmax) + binmbuf++; + if ((PT)binmbuf > binmax) binmax = binmbuf; } else { #if 0 - if (binfbuf > binmbuf) + if (binfbuf > (PT)binmbuf) { error(BWRAP); /* file buffer ahead of memory buffer */ } @@ -198,12 +214,12 @@ opcode_pt ch; #endif { outfd = binfil; - if( binfbuf != binmbuf) - if( lseek(binfil, (long)(binmbuf-binfbuf), 1) < 0 ) + if( binfbuf != (PT)binmbuf) + if( lseek(binfil, (long)((PT)binmbuf-binfbuf), 1) < 0 ) error(BWRAP); binfbuf = binmbuf; #if 0 - while (binfbuf < binmbuf) + while (binfbuf < (PT)binmbuf) { writec(0x0);/* pad with nulls if file buffer behind */ ++binfbuf; |