summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert de Bath <rdebath@poboxes.com>1997-05-09 19:36:29 +0200
committerLubomir Rintel <lkundrak@v3.sk>2013-10-23 23:39:48 +0200
commite63c244cb22bf48ca1d2695784a072269d19ea96 (patch)
tree45b9018259f43db629b27395783cf48e55a85eee
parent4c36e9a0c125ccfff37aa440dab2cf58c4152fff (diff)
downloaddev86-e63c244cb22bf48ca1d2695784a072269d19ea96.tar.gz
Import Dev86src-0.12.0.tar.gzv0.12.0
-rw-r--r--Changes43
-rw-r--r--GNUmakefile13
-rw-r--r--Libc_version2
-rw-r--r--Makefile12
-rw-r--r--README10
-rw-r--r--as/Makefile2
-rw-r--r--as/align.h23
-rw-r--r--as/as.c2
-rw-r--r--as/as86_encap.sh1
-rw-r--r--as/byteord.h6
-rw-r--r--as/const.h14
-rw-r--r--as/express.c10
-rw-r--r--as/table.c2
-rw-r--r--as/typeconv.c578
-rw-r--r--as/typeconv.c.old537
-rw-r--r--bcc/Makefile15
-rw-r--r--bcc/align.h7
-rw-r--r--bcc/assign.c7
-rw-r--r--bcc/bcc-cc1.c3
-rw-r--r--bcc/bcc.c8
-rw-r--r--bcc/bcc.h28
-rw-r--r--bcc/byteord.h4
-rw-r--r--bcc/codefrag.c3
-rw-r--r--bcc/const.h17
-rw-r--r--bcc/debug.c4
-rw-r--r--bcc/declare.c5
-rw-r--r--bcc/express.c3
-rw-r--r--bcc/exptree.c10
-rw-r--r--bcc/floatop.c3
-rw-r--r--bcc/function.c3
-rw-r--r--bcc/gencode.c3
-rw-r--r--bcc/genloads.c3
-rw-r--r--bcc/glogcode.c3
-rw-r--r--bcc/hardop.c9
-rw-r--r--bcc/input.c3
-rw-r--r--bcc/label.c3
-rw-r--r--bcc/loadexp.c3
-rw-r--r--bcc/longop.c3
-rw-r--r--bcc/output.c3
-rw-r--r--bcc/preproc.c3
-rw-r--r--bcc/preserve.c3
-rw-r--r--bcc/proto.h31
-rw-r--r--bcc/scan.c3
-rw-r--r--bcc/softop.c3
-rw-r--r--bcc/state.c3
-rw-r--r--bcc/sysproto.h27
-rw-r--r--bcc/table.c5
-rw-r--r--bcc/type.c3
-rw-r--r--bcc/types.h2
-rw-r--r--bootblocks/Makefile11
-rw-r--r--bootblocks/README12
-rw-r--r--bootblocks/dosfs.c1
-rw-r--r--bootblocks/makeboot.c2
-rw-r--r--bootblocks/mbr.s10
-rw-r--r--bootblocks/minix.c299
-rw-r--r--bootblocks/monitor.c27
-rw-r--r--bootblocks/sysboot.s29
-rw-r--r--copt/copt.diff72
-rw-r--r--copt/rules.8621
-rw-r--r--elksemu/Makefile3
-rw-r--r--elksemu/elks.c2
-rw-r--r--elksemu/elks_sys.c11
-rw-r--r--ifdef.c36
-rw-r--r--ld/Makefile19
-rw-r--r--ld/align.h13
-rw-r--r--ld/bindef.h6
-rw-r--r--ld/bugs14
-rw-r--r--ld/byteord.h6
-rw-r--r--ld/ld.c10
-rw-r--r--ld/rel_aout.h383
-rw-r--r--ld/type.h3
-rw-r--r--ld/typeconv.c579
-rw-r--r--ld/typeconv.c.old536
-rw-r--r--ld/writebin.c34
-rw-r--r--ld/writerel.c22
-rw-r--r--ld/x86_aout.h44
-rw-r--r--libc/Config_sh2
-rw-r--r--libc/Makefile4
-rw-r--r--libc/bcc/Makefile7
-rw-r--r--libc/bios/Makefile4
-rw-r--r--libc/error/Makefile2
-rw-r--r--libc/getent/Makefile2
-rw-r--r--libc/gtermcap/Makefile2
-rw-r--r--libc/i386fp/Makefile2
-rw-r--r--libc/i386sys/Makefile5
-rw-r--r--libc/i386sys/mksyscall3
-rw-r--r--libc/malloc1/Makefile3
-rw-r--r--libc/malloc2/Makefile3
-rw-r--r--libc/misc/Makefile7
-rw-r--r--libc/msdos/Makefile4
-rw-r--r--libc/regexp/Makefile4
-rw-r--r--libc/stdio2/Makefile5
-rw-r--r--libc/stdio2/stdio.c51
-rw-r--r--libc/string/Makefile3
-rw-r--r--libc/syscall/Makefile6
-rw-r--r--libc/syscall/mksyscall3
-rw-r--r--libc/termios/Makefile3
-rw-r--r--libc/time/Makefile2
-rw-r--r--makefile.in39
-rw-r--r--man/as86.14
-rw-r--r--man/bcc.112
-rw-r--r--man/ld86.111
-rw-r--r--mkcompile2
-rw-r--r--mkcompile22
-rw-r--r--tests/compr.c6
-rw-r--r--unproto/unproto.c4
106 files changed, 2624 insertions, 1279 deletions
diff --git a/Changes b/Changes
index ddcb414..59f13ca 100644
--- a/Changes
+++ b/Changes
@@ -1,3 +1,46 @@
+For version 0.12.0.
+
+> Notice the change in the version numbers, as long as I'm releasing the
+ upto the minute patches I thought I'd better give everyone a way of
+ keeping track. So now the 0.X.0 are the main releases, the 0.X.Y are
+ interim patches.
+
+> I've added a new output binary for ld86, it can now do the broken
+ relocatable a.out that bin86 produces. I don't like this but it
+ does let me move ld86 back to /usr/bin without breaking DOSEMU.
+ Note! If you've installed vsn 0.0.11 or earlier you will need to
+ uninstall it before installing this one.
+
+> Altered makefiles for GNU-make 3.74, GNU-make no longer generates
+ automatic 'rm' commands so I have to do it manually.
+
+> Altered makefiles again, starting to get non GNU makefile working.
+
+> Added some cleanups to ifdef.c. (voids etc)
+
+> Assembler now understands monadic '-' and '+' operations (for copt).
+
+> Improved the type conversion functions, they should now work on most
+ machines. There may still be some problems with sizeof(long) == 8 tho,
+ added some warnings/traps.
+
+> Improved the auto-detection and auto-rejection of <a.out.h> ld is more
+ likely to compile even if a.out.h is completely incompatible (leaving
+ out native support).
+
+> Fix for stdio, there was a problem if the OS only did a partial write.
+
+> Alter align() macros to use ssize_t iff both __STDC__ and _POSIX_SOURCE
+ are defined.
+
+> Add some changes for compiling under AIX. Assember and BCC appear to work,
+ ld has problems with AIX's 'ar' command - problem: AIX's make and gmake
+ won't like the smell of a standard following ar86 command ... hmmm.
+
+> Changes in bootblocks, minix.c can now be compiled for a hard disk (works
+ on dosemu, dunno about the real thing tho), fixes for mbr.s re preboot
+ facility. Addition to minix.c to fix number of sectors in bpb for floppy.
+
For version 0.0.11.
> New, most recent, version of unproto inserted.
diff --git a/GNUmakefile b/GNUmakefile
new file mode 100644
index 0000000..ab2c284
--- /dev/null
+++ b/GNUmakefile
@@ -0,0 +1,13 @@
+#
+# Flag that we're using GNU make.
+#
+
+all: phony
+ @$(MAKE) -f Makefile IFDEFFLAGS=-DGNUMAKE $@
+
+%: phony
+ @$(MAKE) -f Makefile IFDEFFLAGS=-DGNUMAKE $@
+
+phony: ;
+
+GNUmakefile: ;
diff --git a/Libc_version b/Libc_version
index 2cfabea..ac454c6 100644
--- a/Libc_version
+++ b/Libc_version
@@ -1 +1 @@
-0.0.11
+0.12.0
diff --git a/Makefile b/Makefile
index 8866f91..c04c366 100644
--- a/Makefile
+++ b/Makefile
@@ -2,10 +2,14 @@
# This file is part of the Linux-8086 Development environment and is
# distributed under the GNU General Public License.
-TARGETS=all bcc unproto copt as86 ld86 \
+TARGETS=bcc unproto copt as86 ld86 \
install install-all install-lib install-lib2 install-other \
clean tests alt-libs library config other
+# Some makes take the last of a list as the default ...
+all: make.fil
+ PATH="`pwd`/bin:$$PATH" $(MAKE) -f make.fil TOPDIR=`pwd` $@
+
$(TARGETS): make.fil
PATH="`pwd`/bin:$$PATH" $(MAKE) -f make.fil TOPDIR=`pwd` $@
@@ -14,7 +18,7 @@ phony:
realclean:
[ ! -f make.fil ] || $(MAKE) -f make.fil TOPDIR=`pwd` $@
- rm -f make.fil ifdef
+ rm -f make.fil ifdef ifdef.o
make.fil: ifdef makefile.in
./ifdef -MU makefile.in >tmp.mak
@@ -23,11 +27,15 @@ make.fil: ifdef makefile.in
ifdef: ifdef.o
$(CC) -o ifdef ifdef.o
+ifdef.o: ifdef.c
+ $(CC) $(CFLAGS) $(IFDEFFLAGS) -c ifdef.c
+
Uninstall: phony
@echo 'Are you really sure... have you checked this... ^C to interrupt'
@read line
rm -rf /usr/bcc
rm -f /usr/bin/bcc /usr/bin/as86_encap /usr/bin/dis88
+ rm -f /usr/bin/as86 /usr/bin/ld86
rm -f /lib/elksemu
rm -f /usr/lib/liberror.txt
rm -f /usr/man/man1/elks.1* /usr/man/man1/elksemu.1*
diff --git a/README b/README
index d7a17cf..acc38b4 100644
--- a/README
+++ b/README
@@ -45,16 +45,6 @@ The as86 and ld86 with this are _different_ from the ones needed for the
linux-i386 kernel but can replace them, the kernel-i386 ones _will_ _not_
work correctly here!
-Unfortunatly, the DOSEMU folks have been using the '-r' option of ld86
-This version does accept '-r' (with -N) but it generates _LINUX_ a.out
-object files. I think they should really be using 'as86_encap' but in
-the short term DOSEMU is being changed to be able to use the new ld86.
-
-Neverthless this ld86 will call a program called /usr/bin/ld86r if it's
-given -r without -N, this can be the old ld86 renamed. For simplicity
-Dev86 doesn't yet overwrite /usr/bin/ld86 but stores the linker in
-/usr/bcc/lib.
-
I _strongly_ suggest you install the kernel patch or load the module in
the elksemu directory in your Linux-i386 kernel, it makes things _much_
easier. (They both need the elksemu executable installed correctly)
diff --git a/as/Makefile b/as/Makefile
index 4319371..04a0d98 100644
--- a/as/Makefile
+++ b/as/Makefile
@@ -23,7 +23,7 @@ install: all
install -d $(LIBDIR)
install -m 755 as86 $(LIBDIR)
install -d $(BINDIR)
- install -m 755 tmp $(BINDIR)/as86_encap
+ install -m 755 as86_encap $(BINDIR)/as86_encap
-@rm -f tmp
clean realclean:
diff --git a/as/align.h b/as/align.h
new file mode 100644
index 0000000..52b1e89
--- /dev/null
+++ b/as/align.h
@@ -0,0 +1,23 @@
+/* align.h - memory alignment requirements for linker */
+
+/* Copyright (C) 1994 Bruce Evans */
+
+#ifndef S_ALIGNMENT
+# define align(x)
+#else
+
+#if defined(__STDC__) && defined(_POSIX_SOURCE)
+# define align(x) ((x)=(void *) \
+ (((ssize_t)(x) + (S_ALIGNMENT-1)) & ~(S_ALIGNMENT-1)))
+#else
+# define align(x) ((x)=(void *) \
+ ((char *)(x) + ((S_ALIGNMENT-(char)(x)) & (S_ALIGNMENT-1))))
+#endif
+#endif
+
+
+
+
+
+
+
diff --git a/as/as.c b/as/as.c
index 234fe18..9d3f371 100644
--- a/as/as.c
+++ b/as/as.c
@@ -62,7 +62,7 @@ char **argv;
initbin();
initobj();
initsource(); /* only nec to init for unsupported mem file */
- typeconv_init(BIG_ENDIAN, LONG_BIG_ENDIAN);
+ typeconv_init(INT_BIG_ENDIAN, LONG_BIG_ENDIAN);
as_warn.global = TRUE; /* constant */
last_pass=1;
process_args(argc, argv);
diff --git a/as/as86_encap.sh b/as/as86_encap.sh
index 0ba4e71..5dea514 100644
--- a/as/as86_encap.sh
+++ b/as/as86_encap.sh
@@ -21,6 +21,7 @@ trap "rm -f _$$.* ; exit 99" 1 2 3 15
LIBDIR='%%LIBDIR%%' # Set by make install
# If the one set by install fails then try a couple of others.
+[ -x "$LIBDIR/as86" ] || LIBDIR="`dirname $0`"
[ -x "$LIBDIR/as86" ] || LIBDIR="`dirname $0`/../lib"
[ -x "$LIBDIR/as86" ] || LIBDIR=/usr/bin
diff --git a/as/byteord.h b/as/byteord.h
index a0d14e1..baf02d0 100644
--- a/as/byteord.h
+++ b/as/byteord.h
@@ -3,16 +3,16 @@
/* These are for the targets of everything and for linker source too. */
#ifdef I8086
-# define BIG_ENDIAN 0
+# define INT_BIG_ENDIAN 0
# define LONG_BIG_ENDIAN 0 /* except longs are back to front for Xenix */
#endif
#ifdef I80386
-# define BIG_ENDIAN 0
+# define INT_BIG_ENDIAN 0
# define LONG_BIG_ENDIAN 0
#endif
#ifdef MC6809
-# define BIG_ENDIAN 1 /* byte order in words is high-low */
+# define INT_BIG_ENDIAN 1 /* byte order in words is high-low */
# define LONG_BIG_ENDIAN 1 /* byte order in longs is high-low */
#endif
diff --git a/as/const.h b/as/const.h
index 2265795..25ae996 100644
--- a/as/const.h
+++ b/as/const.h
@@ -2,20 +2,12 @@
/* Speed and space hacks for BCC */
#ifdef __AS386_16__
#define LOW_BYTE 0 /* must be changed for big-endian */
-#define align(x) /* Don't bother */
+#else
+#define S_ALIGNMENT sizeof(long)
#endif
-#ifndef align
-#ifdef MSDOS
-#define align(x)
-#endif
-#endif
-
-#ifndef align /* Normal ... */
-#define align(x) ((x) = (void*)(((long) (x) + (4-1)) & ~(4-1)))
-#endif
-
+#include "align.h"
/* const.h - constants for assembler */
diff --git a/as/express.c b/as/express.c
index 0bcd8b4..023e2dd 100644
--- a/as/express.c
+++ b/as/express.c
@@ -330,6 +330,16 @@ PUBLIC void factor()
chkabs();
lastexp.offset = ~lastexp.offset;
return;
+ case ADDOP:
+ getsym();
+ factor();
+ return;
+ case SUBOP:
+ getsym();
+ factor();
+ chkabs();
+ lastexp.offset = -lastexp.offset;
+ return;
case STAR:
/* context-sensitive, STAR means location counter here */
lastexp.offset = lc;
diff --git a/as/table.c b/as/table.c
index 389ec9c..6cb5e8b 100644
--- a/as/table.c
+++ b/as/table.c
@@ -180,7 +180,7 @@ PUBLIC struct sym_s *lookup()
symptr->type = 0;
symptr->data = inidata;
symptr->length = length;
- symptr->value_reg_or_op.value = (unsigned) (symptr->next = NUL_PTR);
+ symptr->value_reg_or_op.value = (offset_t) (symptr->next = NUL_PTR);
heapptr = symptr->name;
do
*heapptr++ = *nameptr++;
diff --git a/as/typeconv.c b/as/typeconv.c
index c51b991..6cc4a20 100644
--- a/as/typeconv.c
+++ b/as/typeconv.c
@@ -1,537 +1,187 @@
-/* typeconv.c - convert between char arrays and unsigneds */
-
-/* Copyright (C) 1994 Bruce Evans */
/*
- c2u2(): 2 byte array to 2 byte unsigned
- c4u4(): 4 byte array to 4 byte unsigned
- cnu2(): n byte array to 2 byte unsigned
- cnu4(): n byte array to 4 byte unsigned
- u2c2(): 2 byte unsigned to 2 byte array
- u2cn(): 2 byte unsigned to n byte array
- u4c4(): 4 byte unsigned to 4 byte array
- u4cn(): 4 byte unsigned to n byte array
- typeconv_init: (re)initialise for given byte order.
- Default is no swapping, but the initialisation should be done
- anyway to provide some validity checks (returns FALSE if error).
-
- Not provided:
- c2u4(), c4u2(), u2c4(), u4c2().
- Each of these is best done by truncating or extending a return value
- or argument to the appropiate fixed-count function.
- c4u2() has too many cases to do in-line conveniently, and the others
- are hardly more efficient when done in-line.
-
- 4 byte orderings for both char arrays and unsigneds are supported:
- 0123 - little-endian
- 3210 - big-endian
- 2301 - little-endian with long words big-endian (pdp11)
- 1032 - big-endian with long words little_endian (who knows?)
-
- The unsigned's byte order is that of the machine on which these
- routines are running.
- It is determined at run time initialisation since the compiler/
- preprocessor is too dumb to tell us at compile time.
-*/
+ * Type conversion routines, these have been rewritten for portability.
+ *
+ * The only requirement is now that the u2_t and u4_t must be big enough.
+ */
#include "syshead.h"
#include "const.h"
#include "type.h"
#include "globvar.h"
-FORWARD u2_pt c2u2_00 P((char *buf));
-FORWARD u4_pt c4u4_00 P((char *buf));
-FORWARD u2_pt c2u2_ss P((char *buf));
-FORWARD u4_pt c4u4_ss P((char *buf));
-FORWARD u4_pt c4u4_s0 P((char *buf));
-FORWARD u4_pt c4u4_0s P((char *buf));
-FORWARD void u2c2_00 P((char *buf, u2_pt offset));
-FORWARD void u4c4_00 P((char *buf, u4_t offset));
-FORWARD void u2c2_ss P((char *buf, u2_pt offset));
-FORWARD void u4c4_ss P((char *buf, u4_t offset));
-FORWARD void u4c4_s0 P((char *buf, u4_t offset));
-FORWARD void u4c4_0s P((char *buf, u4_t offset));
-
-PRIVATE u2_pt (*pc2u2) P((char *buf)) = c2u2_00;
-PRIVATE u4_pt (*pc4u4) P((char *buf)) = c4u4_00;
-PRIVATE void (*pu2c2) P((char *buf, u2_pt offset)) = u2c2_00;
-PRIVATE void (*pu4c4) P((char *buf, u4_t offset)) = u4c4_00;
-
-/* === char arrays to unsigneds === */
-
-/* no bytes swapped, longwinded to avoid alignment problems */
-
-PRIVATE u2_pt c2u2_00(buf)
-register char *buf;
-{
- u2_t offset;
-
- ((char *) &offset)[0] = buf[0];
- ((char *) &offset)[1] = buf[1];
- return offset;
-}
-
-PRIVATE u4_pt c4u4_00(buf)
-register char *buf;
-{
- u4_t offset;
+void xxerr P((char *));
+void xxerr(x) char * x; { write(2, x, strlen(x)); }
- ((char *) &offset)[0] = buf[0];
- ((char *) &offset)[1] = buf[1];
- ((char *) &offset)[2] = buf[2];
- ((char *) &offset)[3] = buf[3];
- return offset;
-}
-
-/* straight swapping for little-endian to big-endian and vice versa */
-
-PRIVATE u2_pt c2u2_ss(buf)
-register char *buf;
-{
- u2_t offset;
-
- ((char *) &offset)[0] = buf[1];
- ((char *) &offset)[1] = buf[0];
- return offset;
-}
-
-PRIVATE u4_pt c4u4_ss(buf)
-register char *buf;
-{
- u4_t offset;
-
- ((char *) &offset)[0] = buf[3];
- ((char *) &offset)[1] = buf[2];
- ((char *) &offset)[2] = buf[1];
- ((char *) &offset)[3] = buf[0];
- return offset;
-}
+static int no_swap = 1;
-/* wierd swapping for different-endian u2's, same-endian u4's */
+static long_off[4] = {0,1,2,3};
+static int_off[2] = {0,1};
-PRIVATE u4_pt c4u4_s0(buf)
-register char *buf;
+PUBLIC bool_pt typeconv_init(big_endian, long_big_endian)
+bool_pt big_endian;
+bool_pt long_big_endian;
{
- u4_t offset;
+ int i;
+ no_swap = (!big_endian && !long_big_endian);
- ((char *) &offset)[0] = buf[1];
- ((char *) &offset)[1] = buf[0];
- ((char *) &offset)[2] = buf[3];
- ((char *) &offset)[3] = buf[2];
- return offset;
-}
-
-/* very wierd swapping for same-endian u2's, different-endian u4's */
+ for(i=0; i<4; i++) long_off[i] = i;
+ for(i=0; i<2; i++) int_off[i] = i;
-PRIVATE u4_pt c4u4_0s(buf)
-register char *buf;
-{
- u4_t offset;
+ if( long_big_endian )
+ {
+ i = long_off[0]; long_off[0] = long_off[2]; long_off[2] = i;
+ i = long_off[1]; long_off[1] = long_off[3]; long_off[3] = i;
+ }
+ if( big_endian )
+ {
+ i = long_off[2]; long_off[2] = long_off[3]; long_off[3] = i;
+ i = long_off[0]; long_off[0] = long_off[1]; long_off[1] = i;
- ((char *) &offset)[0] = buf[2];
- ((char *) &offset)[1] = buf[3];
- ((char *) &offset)[2] = buf[0];
- ((char *) &offset)[3] = buf[1];
- return offset;
+ i = int_off[0]; int_off[0] = int_off[1]; int_off[1] = i;
+ }
+ return 1;
}
-/* === entry points === */
-
-PUBLIC u2_pt c2u2(buf)
+PUBLIC void u2c2(buf, offset)
char *buf;
+u2_pt offset;
{
- return (*pc2u2) (buf);
+#ifdef __AS386_16__
+ if( no_swap )
+ {
+ *((unsigned short*)buf) = offset; /* UNALIGNED ACCESS! */
+ return;
+ }
+#endif
+ buf[int_off[0]] = offset;
+ buf[int_off[1]] = (offset>>8);
}
-PUBLIC u4_t c4u4(buf)
+PUBLIC void u4c4(buf, offset)
char *buf;
+u4_t offset;
{
- return (*pc4u4) (buf);
+ int i;
+#ifdef __AS386_16__
+ if( no_swap )
+ {
+ *((unsigned long*)buf) = offset; /* UNALIGNED ACCESS! */
+ return;
+ }
+#endif
+ for(i=0; i<4; i++)
+ {
+ buf[long_off[i]] = offset;
+ offset >>= 8;
+ }
}
-PUBLIC u2_pt cnu2(buf, count)
+PUBLIC void u4cn(buf, offset, count)
char *buf;
+u4_t offset;
unsigned count;
{
- switch (count)
+ switch(count)
{
case 1:
- return buf[0] & 0xFF;
+ buf[0] = (char) offset;
+ return;
case 2:
- return (*pc2u2) (buf);
+ u2c2(buf, (u2_pt) offset);
+ return;
case 4:
- return (u2_pt) (*pc4u4) (buf);
+ u4c4(buf, (u4_t) offset);
+ return;
default:
- return 0;
+ xxerr("WARNING: typeconv.c(u4cn) illegal count\n");
+ return;
}
}
-PUBLIC u4_t cnu4(buf, count)
+PUBLIC void u2cn(buf, offset, count)
char *buf;
+u2_pt offset;
unsigned count;
{
- switch (count)
+ switch(count)
{
case 1:
- return buf[0] & 0xFF;
+ buf[0] = (char) offset;
+ return;
case 2:
- return (*pc2u2) (buf);
+ u2c2(buf, (u2_pt) offset);
+ return;
case 4:
- return (*pc4u4) (buf);
+ u4c4(buf, (u4_t) offset);
+ return;
default:
- return 0;
+ xxerr("WARNING: typeconv.c(u2cn) illegal count\n");
+ return;
}
}
-/* === unsigneds to char arrays === */
-
-/* no bytes swapped, longwinded to avoid alignment problems */
-
-PRIVATE void u2c2_00(buf, offset)
-register char *buf;
-u2_pt offset;
-{
-
- buf[0] = ((char *) &offset)[0];
- buf[1] = ((char *) &offset)[1];
-}
-
-PRIVATE void u4c4_00(buf, offset)
-register char *buf;
-u4_t offset;
-{
- buf[0] = ((char *) &offset)[0];
- buf[1] = ((char *) &offset)[1];
- buf[2] = ((char *) &offset)[2];
- buf[3] = ((char *) &offset)[3];
-}
-
-/* straight swapping for little-endian to big-endian and vice versa */
-
-PRIVATE void u2c2_ss(buf, offset)
-register char *buf;
-u2_pt offset;
-{
- u2_t offset2;
-
- offset2 = offset;
- buf[0] = ((char *) &offset2)[1];
- buf[1] = ((char *) &offset2)[0];
-}
-
-PRIVATE void u4c4_ss(buf, offset)
-register char *buf;
-u4_t offset;
-{
- buf[0] = ((char *) &offset)[3];
- buf[1] = ((char *) &offset)[2];
- buf[2] = ((char *) &offset)[1];
- buf[3] = ((char *) &offset)[0];
-}
-
-/* wierd swapping for different-endian u2's, same-endian u4's */
-
-PRIVATE void u4c4_s0(buf, offset)
-register char *buf;
-u4_t offset;
-{
- buf[0] = ((char *) &offset)[1];
- buf[1] = ((char *) &offset)[0];
- buf[2] = ((char *) &offset)[3];
- buf[3] = ((char *) &offset)[2];
-}
-
-/* very wierd swapping for same-endian u2's, different-endian u4's */
-
-PRIVATE void u4c4_0s(buf, offset)
-register char *buf;
-u4_t offset;
+PUBLIC u2_pt c2u2(buf)
+char *buf;
{
- buf[0] = ((char *) &offset)[2];
- buf[1] = ((char *) &offset)[3];
- buf[2] = ((char *) &offset)[0];
- buf[3] = ((char *) &offset)[1];
-}
-
-/* === entry points === */
+ u2_pt res;
+#ifdef __AS386_16__
+ if( no_swap ) return *((u2_pt *)buf); /* UNALIGNED ACCESS! */
+#endif
-PUBLIC void u2c2(buf, offset)
-register char *buf;
-u2_pt offset;
-{
- (*pu2c2) (buf, offset);
+ res = ((unsigned char *)buf) [int_off[0]]
+ + ((((unsigned char *)buf) [int_off[1]]) << 8);
+ return res;
}
-PUBLIC void u4c4(buf, offset)
-register char *buf;
-u4_t offset;
+PUBLIC u4_t c4u4(buf)
+char *buf;
{
- (*pu4c4) (buf, offset);
+ u4_t res;
+ int i;
+#ifdef __AS386_16__
+ if( no_swap ) return *((u4_t *)buf); /* UNALIGNED ACCESS! */
+#endif
+ res = 0;
+ for(i=3; i>=0; i--)
+ {
+ res = (res<<8) + ((unsigned char *)buf) [long_off[i]];
+ }
+ return res;
}
-PUBLIC void u2cn(buf, offset, count)
-register char *buf;
-u2_pt offset;
+PUBLIC u4_t cnu4(buf, count)
+char *buf;
unsigned count;
{
switch (count)
{
case 1:
- buf[0] = (char) offset;
- return;
+ return buf[0] & 0xFF;
case 2:
- (*pu2c2) (buf, offset);
- return;
+ return c2u2(buf);
case 4:
- (*pu4c4) (buf, (u4_t) offset);
- return;
+ return c4u4(buf);
+ default:
+ xxerr("WARNING: typeconv.c(cnu4) illegal count\n");
+ return 0;
}
}
-PUBLIC void u4cn(buf, offset, count)
-register char *buf;
-u4_t offset;
+PUBLIC u2_pt cnu2(buf, count)
+char *buf;
unsigned count;
{
switch (count)
{
case 1:
- buf[0] = (char) offset;
- return;
+ return buf[0] & 0xFF;
case 2:
- (*pu2c2) (buf, (u2_pt) (u2_t) offset);
- return;
+ return c2u2(buf);
case 4:
- (*pu4c4) (buf, offset);
- return;
- }
-}
-
-/* initialise type conversion, return FALSE if it cannot be handled */
-
-PUBLIC bool_pt typeconv_init(big_endian, long_big_endian)
-bool_pt big_endian;
-bool_pt long_big_endian;
-{
- u2_pt conv2;
- u4_pt conv4;
- char *conv2ptr;
- char *conv4ptr;
-
- if (sizeof(u2_t) != 2 || sizeof(u4_t) != 4)
- /* dumb preprocessor's don't accept sizeof in #if expressions */
- return FALSE;
-
- if (big_endian)
- {
- conv2ptr = (conv4ptr = "\1\2\3\4") + 2;
- if (!long_big_endian)
- conv4ptr = "\3\4\1\2";
- }
- else
- {
- conv2ptr = conv4ptr = "\4\3\2\1";
- if (long_big_endian)
- conv4ptr = "\2\1\4\3";
- }
- conv2 = c2u2_00(conv2ptr);
- conv4 = c4u4_00(conv4ptr);
- if (conv2 == 0x0304)
- {
- pc2u2 = c2u2_00;
- pc4u4 = c4u4_00;
- pu2c2 = u2c2_00;
- pu4c4 = u4c4_00;
- if (conv4 == 0x03040102L)
- {
- pc4u4 = c4u4_0s;
- pu4c4 = u4c4_0s;
- }
- else if (conv4 != 0x01020304L)
- return FALSE;
- }
- else if (conv2 == 0x0403)
- {
- pc2u2 = c2u2_ss;
- pc4u4 = c4u4_ss;
- pu2c2 = u2c2_ss;
- pu4c4 = u4c4_ss;
- if (conv4 == 0x02010403L)
- {
- pc4u4 = c4u4_s0;
- pu4c4 = u4c4_s0;
- }
- else if (conv4 != 0x04030201L)
- return FALSE;
+ return (u2_pt) c4u4(buf);
+ default:
+ xxerr("WARNING: typeconv.c(cnu2) illegal count\n");
+ return 0;
}
- else
- return FALSE;
- return TRUE;
}
-
-#ifdef DEBUG_TYPECONV
-
-main()
-{
- char *source;
- char target[4];
- u2_t u2;
- u2_t u2a;
- u4_t u4;
- u4_t u4a;
-
- printf("%u\n", typeconv_init(FALSE, FALSE));
- printf("%u\n", typeconv_init(FALSE, TRUE));
- printf("%u\n", typeconv_init(TRUE, FALSE));
- printf("%u\n", typeconv_init(TRUE, TRUE));
-
- typeconv_init(FALSE, FALSE);
- source = "\4\3\2\1";
-
- target[0] = 0;
- target[1] = 0;
- u2 = cnu2(source, 2);
- u2cn(target, u2, 2);
- if (strncmp(source, target, 2))
- printf("oops9\n");
-
- target[0] = 0;
- target[1] = 0;
- u4a = cnu4(source, 2);
- u4cn(target, u4a, 2);
- if (strncmp(source, target, 2))
- printf("oops10\n");
-
- target[0] = 0;
- target[1] = 0;
- target[2] = 0;
- target[3] = 0;
- u2a = cnu2(source, 4);
- u2cn(target, u2a, 4);
- if (strncmp(target, "\4\3\0\0", 4))
- printf("oops11\n");
-
- target[0] = 0;
- target[1] = 0;
- target[2] = 0;
- target[3] = 0;
- u4 = cnu4(source, 4);
- u4cn(target, u4, 4);
- if (strncmp(source, target, 4))
- printf("oops12\n");
-
- printf("%04x %04x %08lx %08lx\n", u2, u2a, u4, u4a);
-
- typeconv_init(FALSE, TRUE);
- source = "\2\1\4\3";
-
- target[0] = 0;
- target[1] = 0;
- u2 = cnu2(source + 2, 2);
- u2cn(target, u2, 2);
- if (strncmp(source + 2, target, 2))
- printf("oops13\n");
-
- target[0] = 0;
- target[1] = 0;
- u4a = cnu4(source + 2, 2);
- u4cn(target, u4a, 2);
- if (strncmp(source + 2, target, 2))
- printf("oops14\n");
-
- target[0] = 0;
- target[1] = 0;
- target[2] = 0;
- target[3] = 0;
- u2a = cnu2(source, 4);
- u2cn(target, u2a, 4);
- if (strncmp(target, "\0\0\4\3", 4))
- printf("oops15\n");
-
- target[0] = 0;
- target[1] = 0;
- target[2] = 0;
- target[3] = 0;
- u4 = cnu4(source, 4);
- u4cn(target, u4, 4);
- if (strncmp(source, target, 4))
- printf("oops16\n");
-
- printf("%04x %04x %08lx %08lx\n", u2, u2a, u4, u4a);
-
- typeconv_init(TRUE, FALSE);
- source = "\3\4\1\2";
-
- target[0] = 0;
- target[1] = 0;
- u2 = cnu2(source, 2);
- u2cn(target, u2, 2);
- if (strncmp(source, target, 2))
- printf("oops5\n");
-
- target[0] = 0;
- target[1] = 0;
- u4a = cnu4(source, 2);
- u4cn(target, u4a, 2);
- if (strncmp(source, target, 2))
- printf("oops6\n");
-
- target[0] = 0;
- target[1] = 0;
- target[2] = 0;
- target[3] = 0;
- u2a = cnu2(source, 4);
- u2cn(target, u2a, 4);
- if (strncmp(target, "\3\4\0\0", 4))
- printf("oops7\n");
-
- target[0] = 0;
- target[1] = 0;
- target[2] = 0;
- target[3] = 0;
- u4 = cnu4(source, 4);
- u4cn(target, u4, 4);
- if (strncmp(source, target, 4))
- printf("oops8\n");
-
- printf("%04x %04x %08lx %08lx\n", u2, u2a, u4, u4a);
-
- typeconv_init(TRUE, TRUE);
- source = "\1\2\3\4";
-
- target[0] = 0;
- target[1] = 0;
- u2 = cnu2(source + 2, 2);
- u2cn(target, u2, 2);
- if (strncmp(source + 2, target, 2))
- printf("oops1\n");
-
- target[0] = 0;
- target[1] = 0;
- u4a = cnu4(source + 2, 2);
- u4cn(target, u4a, 2);
- if (strncmp(source + 2, target, 2))
- printf("oops2\n");
-
- target[0] = 0;
- target[1] = 0;
- target[2] = 0;
- target[3] = 0;
- u2a = cnu2(source, 4);
- u2cn(target, u2a, 4);
- if (strncmp(target, "\0\0\3\4", 4))
- printf("oops3\n");
-
- target[0] = 0;
- target[1] = 0;
- target[2] = 0;
- target[3] = 0;
- u4 = cnu4(source, 4);
- u4cn(target, u4, 4);
- if (strncmp(source, target, 4))
- printf("oops4\n");
-
- printf("%04x %04x %08lx %08lx\n", u2, u2a, u4, u4a);
-}
-
-#endif /* DEBUG_TYPECONV */
diff --git a/as/typeconv.c.old b/as/typeconv.c.old
new file mode 100644
index 0000000..c51b991
--- /dev/null
+++ b/as/typeconv.c.old
@@ -0,0 +1,537 @@
+/* typeconv.c - convert between char arrays and unsigneds */
+
+/* Copyright (C) 1994 Bruce Evans */
+
+/*
+ c2u2(): 2 byte array to 2 byte unsigned
+ c4u4(): 4 byte array to 4 byte unsigned
+ cnu2(): n byte array to 2 byte unsigned
+ cnu4(): n byte array to 4 byte unsigned
+ u2c2(): 2 byte unsigned to 2 byte array
+ u2cn(): 2 byte unsigned to n byte array
+ u4c4(): 4 byte unsigned to 4 byte array
+ u4cn(): 4 byte unsigned to n byte array
+ typeconv_init: (re)initialise for given byte order.
+ Default is no swapping, but the initialisation should be done
+ anyway to provide some validity checks (returns FALSE if error).
+
+ Not provided:
+ c2u4(), c4u2(), u2c4(), u4c2().
+ Each of these is best done by truncating or extending a return value
+ or argument to the appropiate fixed-count function.
+ c4u2() has too many cases to do in-line conveniently, and the others
+ are hardly more efficient when done in-line.
+
+ 4 byte orderings for both char arrays and unsigneds are supported:
+ 0123 - little-endian
+ 3210 - big-endian
+ 2301 - little-endian with long words big-endian (pdp11)
+ 1032 - big-endian with long words little_endian (who knows?)
+
+ The unsigned's byte order is that of the machine on which these
+ routines are running.
+ It is determined at run time initialisation since the compiler/
+ preprocessor is too dumb to tell us at compile time.
+*/
+
+#include "syshead.h"
+#include "const.h"
+#include "type.h"
+#include "globvar.h"
+
+FORWARD u2_pt c2u2_00 P((char *buf));
+FORWARD u4_pt c4u4_00 P((char *buf));
+FORWARD u2_pt c2u2_ss P((char *buf));
+FORWARD u4_pt c4u4_ss P((char *buf));
+FORWARD u4_pt c4u4_s0 P((char *buf));
+FORWARD u4_pt c4u4_0s P((char *buf));
+FORWARD void u2c2_00 P((char *buf, u2_pt offset));
+FORWARD void u4c4_00 P((char *buf, u4_t offset));
+FORWARD void u2c2_ss P((char *buf, u2_pt offset));
+FORWARD void u4c4_ss P((char *buf, u4_t offset));
+FORWARD void u4c4_s0 P((char *buf, u4_t offset));
+FORWARD void u4c4_0s P((char *buf, u4_t offset));
+
+PRIVATE u2_pt (*pc2u2) P((char *buf)) = c2u2_00;
+PRIVATE u4_pt (*pc4u4) P((char *buf)) = c4u4_00;
+PRIVATE void (*pu2c2) P((char *buf, u2_pt offset)) = u2c2_00;
+PRIVATE void (*pu4c4) P((char *buf, u4_t offset)) = u4c4_00;
+
+/* === char arrays to unsigneds === */
+
+/* no bytes swapped, longwinded to avoid alignment problems */
+
+PRIVATE u2_pt c2u2_00(buf)
+register char *buf;
+{
+ u2_t offset;
+
+ ((char *) &offset)[0] = buf[0];
+ ((char *) &offset)[1] = buf[1];
+ return offset;
+}
+
+PRIVATE u4_pt c4u4_00(buf)
+register char *buf;
+{
+ u4_t offset;
+
+ ((char *) &offset)[0] = buf[0];
+ ((char *) &offset)[1] = buf[1];
+ ((char *) &offset)[2] = buf[2];
+ ((char *) &offset)[3] = buf[3];
+ return offset;
+}
+
+/* straight swapping for little-endian to big-endian and vice versa */
+
+PRIVATE u2_pt c2u2_ss(buf)
+register char *buf;
+{
+ u2_t offset;
+
+ ((char *) &offset)[0] = buf[1];
+ ((char *) &offset)[1] = buf[0];
+ return offset;
+}
+
+PRIVATE u4_pt c4u4_ss(buf)
+register char *buf;
+{
+ u4_t offset;
+
+ ((char *) &offset)[0] = buf[3];
+ ((char *) &offset)[1] = buf[2];
+ ((char *) &offset)[2] = buf[1];
+ ((char *) &offset)[3] = buf[0];
+ return offset;
+}
+
+/* wierd swapping for different-endian u2's, same-endian u4's */
+
+PRIVATE u4_pt c4u4_s0(buf)
+register char *buf;
+{
+ u4_t offset;
+
+ ((char *) &offset)[0] = buf[1];
+ ((char *) &offset)[1] = buf[0];
+ ((char *) &offset)[2] = buf[3];
+ ((char *) &offset)[3] = buf[2];
+ return offset;
+}
+
+/* very wierd swapping for same-endian u2's, different-endian u4's */
+
+PRIVATE u4_pt c4u4_0s(buf)
+register char *buf;
+{
+ u4_t offset;
+
+ ((char *) &offset)[0] = buf[2];
+ ((char *) &offset)[1] = buf[3];
+ ((char *) &offset)[2] = buf[0];
+ ((char *) &offset)[3] = buf[1];
+ return offset;
+}
+
+/* === entry points === */
+
+PUBLIC u2_pt c2u2(buf)
+char *buf;
+{
+ return (*pc2u2) (buf);
+}
+
+PUBLIC u4_t c4u4(buf)
+char *buf;
+{
+ return (*pc4u4) (buf);
+}
+
+PUBLIC u2_pt cnu2(buf, count)
+char *buf;
+unsigned count;
+{
+ switch (count)
+ {
+ case 1:
+ return buf[0] & 0xFF;
+ case 2:
+ return (*pc2u2) (buf);
+ case 4:
+ return (u2_pt) (*pc4u4) (buf);
+ default:
+ return 0;
+ }
+}
+
+PUBLIC u4_t cnu4(buf, count)
+char *buf;
+unsigned count;
+{
+ switch (count)
+ {
+ case 1:
+ return buf[0] & 0xFF;
+ case 2:
+ return (*pc2u2) (buf);
+ case 4:
+ return (*pc4u4) (buf);
+ default:
+ return 0;
+ }
+}
+
+/* === unsigneds to char arrays === */
+
+/* no bytes swapped, longwinded to avoid alignment problems */
+
+PRIVATE void u2c2_00(buf, offset)
+register char *buf;
+u2_pt offset;
+{
+
+ buf[0] = ((char *) &offset)[0];
+ buf[1] = ((char *) &offset)[1];
+}
+
+PRIVATE void u4c4_00(buf, offset)
+register char *buf;
+u4_t offset;
+{
+ buf[0] = ((char *) &offset)[0];
+ buf[1] = ((char *) &offset)[1];
+ buf[2] = ((char *) &offset)[2];
+ buf[3] = ((char *) &offset)[3];
+}
+
+/* straight swapping for little-endian to big-endian and vice versa */
+
+PRIVATE void u2c2_ss(buf, offset)
+register char *buf;
+u2_pt offset;
+{
+ u2_t offset2;
+
+ offset2 = offset;
+ buf[0] = ((char *) &offset2)[1];
+ buf[1] = ((char *) &offset2)[0];
+}
+
+PRIVATE void u4c4_ss(buf, offset)
+register char *buf;
+u4_t offset;
+{
+ buf[0] = ((char *) &offset)[3];
+ buf[1] = ((char *) &offset)[2];
+ buf[2] = ((char *) &offset)[1];
+ buf[3] = ((char *) &offset)[0];
+}
+
+/* wierd swapping for different-endian u2's, same-endian u4's */
+
+PRIVATE void u4c4_s0(buf, offset)
+register char *buf;
+u4_t offset;
+{
+ buf[0] = ((char *) &offset)[1];
+ buf[1] = ((char *) &offset)[0];
+ buf[2] = ((char *) &offset)[3];
+ buf[3] = ((char *) &offset)[2];
+}
+
+/* very wierd swapping for same-endian u2's, different-endian u4's */
+
+PRIVATE void u4c4_0s(buf, offset)
+register char *buf;
+u4_t offset;
+{
+ buf[0] = ((char *) &offset)[2];
+ buf[1] = ((char *) &offset)[3];
+ buf[2] = ((char *) &offset)[0];
+ buf[3] = ((char *) &offset)[1];
+}
+
+/* === entry points === */
+
+PUBLIC void u2c2(buf, offset)
+register char *buf;
+u2_pt offset;
+{
+ (*pu2c2) (buf, offset);
+}
+
+PUBLIC void u4c4(buf, offset)
+register char *buf;
+u4_t offset;
+{
+ (*pu4c4) (buf, offset);
+}
+
+PUBLIC void u2cn(buf, offset, count)
+register char *buf;
+u2_pt offset;
+unsigned count;
+{
+ switch (count)
+ {
+ case 1:
+ buf[0] = (char) offset;
+ return;
+ case 2:
+ (*pu2c2) (buf, offset);
+ return;
+ case 4:
+ (*pu4c4) (buf, (u4_t) offset);
+ return;
+ }
+}
+
+PUBLIC void u4cn(buf, offset, count)
+register char *buf;
+u4_t offset;
+unsigned count;
+{
+ switch (count)
+ {
+ case 1:
+ buf[0] = (char) offset;
+ return;
+ case 2:
+ (*pu2c2) (buf, (u2_pt) (u2_t) offset);
+ return;
+ case 4:
+ (*pu4c4) (buf, offset);
+ return;
+ }
+}
+
+/* initialise type conversion, return FALSE if it cannot be handled */
+
+PUBLIC bool_pt typeconv_init(big_endian, long_big_endian)
+bool_pt big_endian;
+bool_pt long_big_endian;
+{
+ u2_pt conv2;
+ u4_pt conv4;
+ char *conv2ptr;
+ char *conv4ptr;
+
+ if (sizeof(u2_t) != 2 || sizeof(u4_t) != 4)
+ /* dumb preprocessor's don't accept sizeof in #if expressions */
+ return FALSE;
+
+ if (big_endian)
+ {
+ conv2ptr = (conv4ptr = "\1\2\3\4") + 2;
+ if (!long_big_endian)
+ conv4ptr = "\3\4\1\2";
+ }
+ else
+ {
+ conv2ptr = conv4ptr = "\4\3\2\1";
+ if (long_big_endian)
+ conv4ptr = "\2\1\4\3";
+ }
+ conv2 = c2u2_00(conv2ptr);
+ conv4 = c4u4_00(conv4ptr);
+ if (conv2 == 0x0304)
+ {
+ pc2u2 = c2u2_00;
+ pc4u4 = c4u4_00;
+ pu2c2 = u2c2_00;
+ pu4c4 = u4c4_00;
+ if (conv4 == 0x03040102L)
+ {
+ pc4u4 = c4u4_0s;
+ pu4c4 = u4c4_0s;
+ }
+ else if (conv4 != 0x01020304L)
+ return FALSE;
+ }
+ else if (conv2 == 0x0403)
+ {
+ pc2u2 = c2u2_ss;
+ pc4u4 = c4u4_ss;
+ pu2c2 = u2c2_ss;
+ pu4c4 = u4c4_ss;
+ if (conv4 == 0x02010403L)
+ {
+ pc4u4 = c4u4_s0;
+ pu4c4 = u4c4_s0;
+ }
+ else if (conv4 != 0x04030201L)
+ return FALSE;
+ }
+ else
+ return FALSE;
+ return TRUE;
+}
+
+#ifdef DEBUG_TYPECONV
+
+main()
+{
+ char *source;
+ char target[4];
+ u2_t u2;
+ u2_t u2a;
+ u4_t u4;
+ u4_t u4a;
+
+ printf("%u\n", typeconv_init(FALSE, FALSE));
+ printf("%u\n", typeconv_init(FALSE, TRUE));
+ printf("%u\n", typeconv_init(TRUE, FALSE));
+ printf("%u\n", typeconv_init(TRUE, TRUE));
+
+ typeconv_init(FALSE, FALSE);
+ source = "\4\3\2\1";
+
+ target[0] = 0;
+ target[1] = 0;
+ u2 = cnu2(source, 2);
+ u2cn(target, u2, 2);
+ if (strncmp(source, target, 2))
+ printf("oops9\n");
+
+ target[0] = 0;
+ target[1] = 0;
+ u4a = cnu4(source, 2);
+ u4cn(target, u4a, 2);
+ if (strncmp(source, target, 2))
+ printf("oops10\n");
+
+ target[0] = 0;
+ target[1] = 0;
+ target[2] = 0;
+ target[3] = 0;
+ u2a = cnu2(source, 4);
+ u2cn(target, u2a, 4);
+ if (strncmp(target, "\4\3\0\0", 4))
+ printf("oops11\n");
+
+ target[0] = 0;
+ target[1] = 0;
+ target[2] = 0;
+ target[3] = 0;
+ u4 = cnu4(source, 4);
+ u4cn(target, u4, 4);
+ if (strncmp(source, target, 4))
+ printf("oops12\n");
+
+ printf("%04x %04x %08lx %08lx\n", u2, u2a, u4, u4a);
+
+ typeconv_init(FALSE, TRUE);
+ source = "\2\1\4\3";
+
+ target[0] = 0;
+ target[1] = 0;
+ u2 = cnu2(source + 2, 2);
+ u2cn(target, u2, 2);
+ if (strncmp(source + 2, target, 2))
+ printf("oops13\n");
+
+ target[0] = 0;
+ target[1] = 0;
+ u4a = cnu4(source + 2, 2);
+ u4cn(target, u4a, 2);
+ if (strncmp(source + 2, target, 2))
+ printf("oops14\n");
+
+ target[0] = 0;
+ target[1] = 0;
+ target[2] = 0;
+ target[3] = 0;
+ u2a = cnu2(source, 4);
+ u2cn(target, u2a, 4);
+ if (strncmp(target, "\0\0\4\3", 4))
+ printf("oops15\n");
+
+ target[0] = 0;
+ target[1] = 0;
+ target[2] = 0;
+ target[3] = 0;
+ u4 = cnu4(source, 4);
+ u4cn(target, u4, 4);
+ if (strncmp(source, target, 4))
+ printf("oops16\n");
+
+ printf("%04x %04x %08lx %08lx\n", u2, u2a, u4, u4a);
+
+ typeconv_init(TRUE, FALSE);
+ source = "\3\4\1\2";
+
+ target[0] = 0;
+ target[1] = 0;
+ u2 = cnu2(source, 2);
+ u2cn(target, u2, 2);
+ if (strncmp(source, target, 2))
+ printf("oops5\n");
+
+ target[0] = 0;
+ target[1] = 0;
+ u4a = cnu4(source, 2);
+ u4cn(target, u4a, 2);
+ if (strncmp(source, target, 2))
+ printf("oops6\n");
+
+ target[0] = 0;
+ target[1] = 0;
+ target[2] = 0;
+ target[3] = 0;
+ u2a = cnu2(source, 4);
+ u2cn(target, u2a, 4);
+ if (strncmp(target, "\3\4\0\0", 4))
+ printf("oops7\n");
+
+ target[0] = 0;
+ target[1] = 0;
+ target[2] = 0;
+ target[3] = 0;
+ u4 = cnu4(source, 4);
+ u4cn(target, u4, 4);
+ if (strncmp(source, target, 4))
+ printf("oops8\n");
+
+ printf("%04x %04x %08lx %08lx\n", u2, u2a, u4, u4a);
+
+ typeconv_init(TRUE, TRUE);
+ source = "\1\2\3\4";
+
+ target[0] = 0;
+ target[1] = 0;
+ u2 = cnu2(source + 2, 2);
+ u2cn(target, u2, 2);
+ if (strncmp(source + 2, target, 2))
+ printf("oops1\n");
+
+ target[0] = 0;
+ target[1] = 0;
+ u4a = cnu4(source + 2, 2);
+ u4cn(target, u4a, 2);
+ if (strncmp(source + 2, target, 2))
+ printf("oops2\n");
+
+ target[0] = 0;
+ target[1] = 0;
+ target[2] = 0;
+ target[3] = 0;
+ u2a = cnu2(source, 4);
+ u2cn(target, u2a, 4);
+ if (strncmp(target, "\0\0\3\4", 4))
+ printf("oops3\n");
+
+ target[0] = 0;
+ target[1] = 0;
+ target[2] = 0;
+ target[3] = 0;
+ u4 = cnu4(source, 4);
+ u4cn(target, u4, 4);
+ if (strncmp(source, target, 4))
+ printf("oops4\n");
+
+ printf("%04x %04x %08lx %08lx\n", u2, u2a, u4, u4a);
+}
+
+#endif /* DEBUG_TYPECONV */
diff --git a/bcc/Makefile b/bcc/Makefile
index 512c013..8812c38 100644
--- a/bcc/Makefile
+++ b/bcc/Makefile
@@ -25,16 +25,16 @@ install: all
install -m 755 bcc-cc1 $(LIBDIR)/bcc-cc1
bcc: bcc.c
- $(CC) -ansi $(CFLAGS) $(BCCDEFS) $(LDFLAGS) bcc.c -o $@
+ $(CC) $(ANSI) $(CFLAGS) $(BCCDEFS) $(LDFLAGS) bcc.c -o $@
ncc: bcc.c
- $(CC) -ansi $(CFLAGS) -DL_TREE -DDEFARCH=0 $(LDFLAGS) bcc.c -o $@
+ $(CC) $(ANSI) $(CFLAGS) -DL_TREE -DDEFARCH=0 $(LDFLAGS) bcc.c -o $@
bcc09: bcc.c
- $(CC) -ansi $(CFLAGS) -DMC6809 $(BCCDEFS) $(LDFLAGS) bcc.c -o $@
+ $(CC) $(ANSI) $(CFLAGS) -DMC6809 $(BCCDEFS) $(LDFLAGS) bcc.c -o $@
ccc: bcc.c
- $(CC) -ansi $(CFLAGS) -DCCC $(BCCDEFS) $(LDFLAGS) bcc.c -o $@
+ $(CC) $(ANSI) $(CFLAGS) -DCCC $(BCCDEFS) $(LDFLAGS) bcc.c -o $@
bcc-cc1: $(OBJS)
$(CC) $(LDFLAGS) $(OBJS) -o bcc-cc1
@@ -43,5 +43,8 @@ clean realclean:
rm -f bcc bcc-cc1 ncc bcc09 ccc bcc.o $(OBJS)
-$(OBJS): align.h byteord.h condcode.h const.h gencode.h input.h label.h os.h \
- output.h parse.h proto.h reg.h sc.h scan.h sizes.h table.h type.h types.h
+$(OBJS): bcc.h align.h const.h types.h \
+ byteord.h condcode.h gencode.h \
+ input.h label.h os.h output.h \
+ parse.h proto.h reg.h sc.h scan.h \
+ sizes.h table.h type.h
diff --git a/bcc/align.h b/bcc/align.h
index 3c8971b..2fce75d 100644
--- a/bcc/align.h
+++ b/bcc/align.h
@@ -5,11 +5,10 @@
#ifndef S_ALIGNMENT
# define align(x) (x)
#else
-# ifdef UNPORTABLE_ALIGNMENT
-typedef unsigned pointerint_t;
-# define align(x) (((pointerint_t) (x) + (S_ALIGNMENT-1)) & ~(S_ALIGNMENT-1))
+# if defined(__STDC__) && defined(_POSIX_SOURCE)
+# define align(x) (((ssize_t) (x) + (S_ALIGNMENT-1)) & ~(S_ALIGNMENT-1))
# else
-# define align(x) ((char *) (x) + (- (int) (x) & (S_ALIGNMENT-1)))
+# define align(x) ((char *) (x) + (- (char) (x) & (S_ALIGNMENT-1)))
# endif
#endif
diff --git a/bcc/assign.c b/bcc/assign.c
index ebbc1fc..977d23e 100644
--- a/bcc/assign.c
+++ b/bcc/assign.c
@@ -2,8 +2,7 @@
/* Copyright (C) 1992 Bruce Evans */
-#include "const.h"
-#include "types.h"
+#include "bcc.h"
#include "byteord.h"
#include "gencode.h"
#include "reg.h"
@@ -236,7 +235,7 @@ struct symstruct *target;
if (long_big_endian)
#endif
#if DYNAMIC_LONG_ORDER || LONG_BIG_ENDIAN
-# if BIG_ENDIAN
+# if INT_BIG_ENDIAN
target->offset.offi += oldsize - ctypesize;
# else
{
@@ -249,7 +248,7 @@ struct symstruct *target;
else
#endif
#if DYNAMIC_LONG_ORDER || LONG_BIG_ENDIAN == 0
-# if BIG_ENDIAN
+# if INT_BIG_ENDIAN
target->offset.offi += ctypesize;
# else
;
diff --git a/bcc/bcc-cc1.c b/bcc/bcc-cc1.c
index d6fece3..6f545be 100644
--- a/bcc/bcc-cc1.c
+++ b/bcc/bcc-cc1.c
@@ -2,8 +2,7 @@
/* Copyright (C) 1992 Bruce Evans */
-#include "const.h"
-#include "types.h"
+#include "bcc.h"
PUBLIC int main(argc, argv)
int argc;
diff --git a/bcc/bcc.c b/bcc/bcc.c
index 9f7474d..4dc16b1 100644
--- a/bcc/bcc.c
+++ b/bcc/bcc.c
@@ -45,7 +45,7 @@
#define EXESUF
#endif
-#ifdef __minix
+#if defined(__minix) || defined(_AIX)
#define realpath(x,y) 0
#endif
@@ -531,10 +531,14 @@ char **argv;
addarg(&cppargs, "-D__linux__");
addarg(&ldargs, "-N"); /* Make OMAGIC */
break;
+ case 0:
+ break;
+ default:
+ fatal("Fatal error: illegal -M option given");
}
#endif
-if( !aswarn )
+ if( !aswarn )
addarg(&asargs, "-w");
if( patch_exe )
addarg(&ldargs, "-s");
diff --git a/bcc/bcc.h b/bcc/bcc.h
new file mode 100644
index 0000000..275c100
--- /dev/null
+++ b/bcc/bcc.h
@@ -0,0 +1,28 @@
+/* Copyright (C) 1997 Robert de Bath <robert@mayday.cix.co.uk>
+ * This file is part of the Linux-8086 Development environment and is
+ * distributed under the GNU General Public License. */
+
+/* Ansi C has certain guarentees ... except under MSdross :-( */
+
+#ifdef __STDC__
+#ifndef MSDOS
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <fcntl.h>
+#endif
+
+#define P(x) x
+
+#else
+#define P(x) ()
+#endif
+
+#include "const.h"
+#include "types.h"
+#include "proto.h"
+
+#if !defined(__STDC__) || defined(MSDOS)
+#include "sysproto.h"
+#endif
+
diff --git a/bcc/byteord.h b/bcc/byteord.h
index e7b19e0..00cfd42 100644
--- a/bcc/byteord.h
+++ b/bcc/byteord.h
@@ -3,11 +3,11 @@
/* Copyright (C) 1992 Bruce Evans */
#ifdef I8088
-# define BIG_ENDIAN 0
+# define INT_BIG_ENDIAN 0
# define LONG_BIG_ENDIAN 1 /* longs are back to front for Xenix */
#endif
#ifdef MC6809
-# define BIG_ENDIAN 1 /* byte order in words is high-low */
+# define INT_BIG_ENDIAN 1 /* byte order in words is high-low */
# define LONG_BIG_ENDIAN 1 /* byte order in longs is high-low */
#endif
diff --git a/bcc/codefrag.c b/bcc/codefrag.c
index 5d3aa82..750c837 100644
--- a/bcc/codefrag.c
+++ b/bcc/codefrag.c
@@ -2,8 +2,7 @@
/* Copyright (C) 1992 Bruce Evans */
-#include "const.h"
-#include "types.h"
+#include "bcc.h"
#include "byteord.h"
#include "condcode.h"
#include "gencode.h"
diff --git a/bcc/const.h b/bcc/const.h
index f8fd692..cd1f16e 100644
--- a/bcc/const.h
+++ b/bcc/const.h
@@ -17,9 +17,13 @@
#endif
+#ifdef __AS386_16__
+#define VERY_SMALL_MEMORY
+#endif
+
#define SELFTYPECHECK /* check calculated type = runtime type */
-#ifndef __AS386_16__
+#ifndef VERY_SMALL_MEMORY
#define DEBUG /* generate compiler-debugging code */
#endif
@@ -29,7 +33,7 @@
* since assembler has only 1 data seg */
# define DYNAMIC_LONG_ORDER 1 /* long word order spec. at compile time */
-#ifdef __AS386_16__
+#ifdef VERY_SMALL_MEMORY
/* Humm, now this is nasty :-) */
#define float no_hope
@@ -61,12 +65,9 @@ typedef long no_hope;
/* switches for source machine dependencies */
-#ifndef SOS_EDOS
-# define S_ALIGNMENT (sizeof(int)) /* source memory alignment, power of 2 */
-#endif
-
-#ifndef SOS_MSDOS /* need portable alignment for large model */
-# define UNPORTABLE_ALIGNMENT
+/* Unportable alignment needed for specific compilers */
+#ifndef VERY_SMALL_MEMORY
+# define S_ALIGNMENT (sizeof(long)) /* A little safer */
#endif
/* local style */
diff --git a/bcc/debug.c b/bcc/debug.c
index 26f7bf8..9e97ae7 100644
--- a/bcc/debug.c
+++ b/bcc/debug.c
@@ -2,11 +2,9 @@
/* Copyright (C) 1992 Bruce Evans */
-#include "const.h"
+#include "bcc.h"
#ifdef DEBUG
-
-#include "types.h"
#include "gencode.h"
#include "reg.h"
#include "sc.h"
diff --git a/bcc/declare.c b/bcc/declare.c
index accd663..1c9b43a 100644
--- a/bcc/declare.c
+++ b/bcc/declare.c
@@ -2,8 +2,7 @@
/* Copyright (C) 1992 Bruce Evans */
-#include "const.h"
-#include "types.h"
+#include "bcc.h"
#include "align.h"
#include "byteord.h"
#include "gencode.h"
@@ -644,7 +643,7 @@ PRIVATE void declfunc()
arg1size = itypesize;
argsp = softsp -= arg1size;
}
-#if BIG_ENDIAN
+#if INT_BIG_ENDIAN
if (argsize < itypesize)
argsp += itypesize - argsize;
symptr->offset.offi = argsp;
diff --git a/bcc/express.c b/bcc/express.c
index e6ee64c..22d5bed 100644
--- a/bcc/express.c
+++ b/bcc/express.c
@@ -2,8 +2,7 @@
/* Copyright (C) 1992 Bruce Evans */
-#include "const.h"
-#include "types.h"
+#include "bcc.h"
#include "gencode.h"
#include "parse.h"
#include "reg.h"
diff --git a/bcc/exptree.c b/bcc/exptree.c
index 6b24eff..1a079e7 100644
--- a/bcc/exptree.c
+++ b/bcc/exptree.c
@@ -2,8 +2,7 @@
/* Copyright (C) 1992 Bruce Evans */
-#include "const.h"
-#include "types.h"
+#include "bcc.h"
#include "byteord.h"
#include "gencode.h"
#include "parse.h"
@@ -13,7 +12,7 @@
#include "sizes.h"
#include "type.h"
-#ifdef __AS386_16__
+#ifdef VERY_SMALL_MEMORY
#define ETREESIZE 300
#else
#define ETREESIZE 1200
@@ -375,6 +374,7 @@ struct nodestruct *p2;
if (lscalar & RSCALAR && !(rscalar & RSCALAR))
{
double val;
+ /* XXX: Gcc warns about ansi vs k&r problem with this */
static double MAXULONG = (double)0xFFFFFFFFL +1;
val = *target->offset.offd;
@@ -425,7 +425,7 @@ struct nodestruct *p2;
if (long_big_endian)
#endif
#if DYNAMIC_LONG_ORDER || LONG_BIG_ENDIAN
-# if BIG_ENDIAN
+# if INT_BIG_ENDIAN
target->offset.offi += targszdelta;
# else
{
@@ -438,7 +438,7 @@ struct nodestruct *p2;
else
#endif
#if DYNAMIC_LONG_ORDER || LONG_BIG_ENDIAN == 0
-# if BIG_ENDIAN
+# if INT_BIG_ENDIAN
{
if (rscalar & CHAR)
target->offset.offi += ctypesize;
diff --git a/bcc/floatop.c b/bcc/floatop.c
index fb9c54d..38b0e52 100644
--- a/bcc/floatop.c
+++ b/bcc/floatop.c
@@ -2,8 +2,7 @@
/* Copyright (C) 1992 Bruce Evans */
-#include "const.h"
-#include "types.h"
+#include "bcc.h"
#include "gencode.h"
#include "reg.h"
#include "sc.h"
diff --git a/bcc/function.c b/bcc/function.c
index 7beaa14..5d30a40 100644
--- a/bcc/function.c
+++ b/bcc/function.c
@@ -2,8 +2,7 @@
/* Copyright (C) 1992 Bruce Evans */
-#include "const.h"
-#include "types.h"
+#include "bcc.h"
#include "align.h"
#include "byteord.h"
#include "gencode.h"
diff --git a/bcc/gencode.c b/bcc/gencode.c
index 2f7ce5f..a16ff74 100644
--- a/bcc/gencode.c
+++ b/bcc/gencode.c
@@ -5,8 +5,7 @@
#define islvalop(op) \
(((op) >= ASSIGNOP && (op) <= SUBABOP) || (op) == PTRADDABOP)
-#include "const.h"
-#include "types.h"
+#include "bcc.h"
#include "align.h"
#include "condcode.h"
#include "reg.h"
diff --git a/bcc/genloads.c b/bcc/genloads.c
index 9c77032..26933f8 100644
--- a/bcc/genloads.c
+++ b/bcc/genloads.c
@@ -2,8 +2,7 @@
/* Copyright (C) 1992 Bruce Evans */
-#include "const.h"
-#include "types.h"
+#include "bcc.h"
#include "byteord.h"
#include "condcode.h"
#include "gencode.h"
diff --git a/bcc/glogcode.c b/bcc/glogcode.c
index 2f39080..7aac27c 100644
--- a/bcc/glogcode.c
+++ b/bcc/glogcode.c
@@ -2,8 +2,7 @@
/* Copyright (C) 1992 Bruce Evans */
-#include "const.h"
-#include "types.h"
+#include "bcc.h"
#include "condcode.h"
#include "gencode.h"
#include "reg.h"
diff --git a/bcc/hardop.c b/bcc/hardop.c
index 51f9616..c6adb87 100644
--- a/bcc/hardop.c
+++ b/bcc/hardop.c
@@ -2,8 +2,7 @@
/* Copyright (C) 1992 Bruce Evans */
-#include "const.h"
-#include "types.h"
+#include "bcc.h"
#include "byteord.h"
#include "condcode.h"
#include "gencode.h"
@@ -380,11 +379,11 @@ struct symstruct *target;
indcount = source->indcount;
# endif
outopsep();
-# if BIG_ENDIAN == 0
+# if INT_BIG_ENDIAN == 0
++source->offset.offi;
# endif
outadr(source);
-# if BIG_ENDIAN == 0
+# if INT_BIG_ENDIAN == 0
--source->offset.offi;
# endif
# if MAXINDIRECT > 1
@@ -396,7 +395,7 @@ struct symstruct *target;
}
outregname(BREG);
outopsep();
-# if BIG_ENDIAN
+# if INT_BIG_ENDIAN
++source->offset.offi;
# endif
outadr(source);
diff --git a/bcc/input.c b/bcc/input.c
index f905416..1adedda 100644
--- a/bcc/input.c
+++ b/bcc/input.c
@@ -5,8 +5,7 @@
#define ARBITRARY_BACKSLASH_NEWLINES_NOT
#define INSERT_BACKSLASH_NEWLINES_NOT
-#include "const.h"
-#include "types.h"
+#include "bcc.h"
#include "gencode.h"
#include "output.h"
#include "os.h"
diff --git a/bcc/label.c b/bcc/label.c
index 394a47c..635a5bd 100644
--- a/bcc/label.c
+++ b/bcc/label.c
@@ -2,8 +2,7 @@
/* Copyright (C) 1992 Bruce Evans */
-#include "const.h"
-#include "types.h"
+#include "bcc.h"
#include "condcode.h"
#include "gencode.h"
#include "label.h"
diff --git a/bcc/loadexp.c b/bcc/loadexp.c
index 632c2ad..6ecb82f 100644
--- a/bcc/loadexp.c
+++ b/bcc/loadexp.c
@@ -2,8 +2,7 @@
/* Copyright (C) 1992 Bruce Evans */
-#include "const.h"
-#include "types.h"
+#include "bcc.h"
#include "byteord.h"
#include "gencode.h"
#include "parse.h"
diff --git a/bcc/longop.c b/bcc/longop.c
index f678e11..412ac25 100644
--- a/bcc/longop.c
+++ b/bcc/longop.c
@@ -2,8 +2,7 @@
/* Copyright (C) 1992 Bruce Evans */
-#include "const.h"
-#include "types.h"
+#include "bcc.h"
#include "byteord.h"
#include "gencode.h"
#include "reg.h"
diff --git a/bcc/output.c b/bcc/output.c
index fb7f1bf..6bc4d04 100644
--- a/bcc/output.c
+++ b/bcc/output.c
@@ -2,8 +2,7 @@
/* Copyright (C) 1992 Bruce Evans */
-#include "const.h"
-#include "types.h"
+#include "bcc.h"
#include "input.h"
#include "os.h"
#include "sizes.h"
diff --git a/bcc/preproc.c b/bcc/preproc.c
index b9aed0e..37ca1d5 100644
--- a/bcc/preproc.c
+++ b/bcc/preproc.c
@@ -2,8 +2,7 @@
/* Copyright (C) 1992 Bruce Evans */
-#include "const.h"
-#include "types.h"
+#include "bcc.h"
#include "input.h"
#include "os.h"
#include "output.h"
diff --git a/bcc/preserve.c b/bcc/preserve.c
index 74b0f34..17ded07 100644
--- a/bcc/preserve.c
+++ b/bcc/preserve.c
@@ -2,8 +2,7 @@
/* Copyright (C) 1992 Bruce Evans */
-#include "const.h"
-#include "types.h"
+#include "bcc.h"
#include "gencode.h"
#include "reg.h"
#include "type.h"
diff --git a/bcc/proto.h b/bcc/proto.h
index e45cf0e..b3e7151 100644
--- a/bcc/proto.h
+++ b/bcc/proto.h
@@ -2,12 +2,6 @@
/* Copyright (C) 1992 Bruce Evans */
-#ifdef __STDC__
-#define P(x) x
-#else
-#define P(x) ()
-#endif
-
/* assign.c */
void assign P((struct symstruct *source, struct symstruct *target));
void cast P((struct typestruct *type, struct symstruct *target));
@@ -371,28 +365,3 @@ struct typestruct *promote P((struct typestruct *type));
struct typestruct *tounsigned P((struct typestruct *type));
void typeinit P((void));
-/* library - fcntl.h */
-int creat P((const char *_path, int _mode));
-int open P((const char *_path, int _oflag, ...));
-
-/* library - stdlib.h */
-double atof P((const char *_str));
-void exit P((int _status));
-
-/* library - string.h */
-void *memcpy P((void *_t, const void *_s, unsigned _length));
-void *memset P((void *_s, int _c, unsigned _nbytes));
-char *strcat P((char *_target, const char *_source));
-char *strchr P((const char *_s, int _ch));
-int strcmp P((const char *_s1, const char *_s2));
-char *strcpy P((char *_target, const char *_source));
-unsigned strlen P((const char *_s));
-char *strncpy P((char *_target, const char *_source, unsigned _maxlength));
-char *strrchr P((const char *_s, int _ch));
-
-/* library - unistd.h */
-int close P((int _fd));
-int isatty P((int _fd));
-long lseek P((int _fd, long _offset, int _whence));
-int read P((int _fd, char *_buf, unsigned _nbytes));
-int write P((int _fd, char *_buf, unsigned _nbytes));
diff --git a/bcc/scan.c b/bcc/scan.c
index 2254e4a..3aad1a2 100644
--- a/bcc/scan.c
+++ b/bcc/scan.c
@@ -4,8 +4,7 @@
#define GCH1() do { if (SYMOFCHAR(ch = *++lineptr) == SPECIALCHAR) specialchar(); } while (0)
-#include "const.h"
-#include "types.h"
+#include "bcc.h"
#include "input.h"
#include "os.h"
#include "output.h"
diff --git a/bcc/softop.c b/bcc/softop.c
index 369ad96..6f2dbce 100644
--- a/bcc/softop.c
+++ b/bcc/softop.c
@@ -2,8 +2,7 @@
/* Copyright (C) 1992 Bruce Evans */
-#include "const.h"
-#include "types.h"
+#include "bcc.h"
#include "gencode.h"
#include "reg.h"
#include "scan.h"
diff --git a/bcc/state.c b/bcc/state.c
index 1d0dd04..7a1faef 100644
--- a/bcc/state.c
+++ b/bcc/state.c
@@ -2,8 +2,7 @@
/* Copyright (C) 1992 Bruce Evans */
-#include "const.h"
-#include "types.h"
+#include "bcc.h"
#include "align.h"
#include "condcode.h"
#include "gencode.h"
diff --git a/bcc/sysproto.h b/bcc/sysproto.h
new file mode 100644
index 0000000..b1d19fb
--- /dev/null
+++ b/bcc/sysproto.h
@@ -0,0 +1,27 @@
+
+/* library - fcntl.h */
+int creat P((const char *_path, int _mode));
+int open P((const char *_path, int _oflag, ...));
+
+/* library - stdlib.h */
+double atof P((const char *_str));
+void exit P((int _status));
+
+/* library - string.h */
+void *memcpy P((void *_t, const void *_s, unsigned _length));
+void *memset P((void *_s, int _c, unsigned _nbytes));
+char *strcat P((char *_target, const char *_source));
+char *strchr P((const char *_s, int _ch));
+int strcmp P((const char *_s1, const char *_s2));
+char *strcpy P((char *_target, const char *_source));
+unsigned strlen P((const char *_s));
+char *strncpy P((char *_target, const char *_source, unsigned _maxlength));
+char *strrchr P((const char *_s, int _ch));
+
+/* library - unistd.h */
+int close P((int _fd));
+int isatty P((int _fd));
+long lseek P((int _fd, long _offset, int _whence));
+int read P((int _fd, char *_buf, unsigned _nbytes));
+int write P((int _fd, char *_buf, unsigned _nbytes));
+
diff --git a/bcc/table.c b/bcc/table.c
index 7f4a1ac..19e1528 100644
--- a/bcc/table.c
+++ b/bcc/table.c
@@ -6,8 +6,7 @@
* usually be set to some level different from OFFKLUDGELEVEL.
*/
-#include "const.h"
-#include "types.h"
+#include "bcc.h"
#include "align.h"
#include "gencode.h"
#include "os.h"
@@ -25,7 +24,7 @@
#define GOLDEN 157 /* GOLDEN/HASHTABSIZE approx golden ratio */
#define HASHTABSIZE 256
#define MARKER ((unsigned) 0x18C396A5L) /* lint everywhere it is used */
-#ifdef __AS386_16__
+#ifdef VERY_SMALL_MEMORY
#define MAXEXPR 125
#else
#define MAXEXPR 500
diff --git a/bcc/type.c b/bcc/type.c
index 7e40f93..fe66b33 100644
--- a/bcc/type.c
+++ b/bcc/type.c
@@ -2,8 +2,7 @@
/* Copyright (C) 1992 Bruce Evans */
-#include "const.h"
-#include "types.h"
+#include "bcc.h"
#include "align.h"
#include "gencode.h" /* s.b. switches.h */
#include "sc.h"
diff --git a/bcc/types.h b/bcc/types.h
index 755b8b1..79ff836 100644
--- a/bcc/types.h
+++ b/bcc/types.h
@@ -202,5 +202,3 @@ struct typelist
#define NULLNODE ((struct nodestruct *) NULL)
#define NULLTYPE ((struct typestruct *) NULL)
-
-#include "proto.h"
diff --git a/bootblocks/Makefile b/bootblocks/Makefile
index 85393a7..707179f 100644
--- a/bootblocks/Makefile
+++ b/bootblocks/Makefile
@@ -15,8 +15,8 @@ all: default tgz bin
CSRC=minix.c
SSRC=tarboot.s skip.s com_bcc.s tich.s sysboot.s bootlist.s mbr.s msdos.s
-encap: $(SSRC:s=v) $(CSRC:c=v)
-bin: $(SSRC:s=bin) $(CSRC:c=bin)
+encap: $(SSRC:s=v) $(CSRC:c=v) minixhd.v
+bin: $(SSRC:s=bin) $(CSRC:c=bin) minixhd.bin
MOBJ=monitor.o i86_funcs.o relocate.o help.o bzimage.o dosfs.o nofs.o
MSRC=monitor.c i86_funcs.c relocate.c help.c bzimage.c dosfs.c nofs.c
@@ -35,6 +35,9 @@ monitor: $(MSRC)
minix.s: minix.c
$(BCC) -Mc -S minix.c
+minixhd.s: minix.c
+ $(BCC) -Mc -DHARDDISK -S minix.c -o minixhd.s
+
makeboot: makeboot.c sysboot.v skip.v msdos.v tarboot.v
$(HOSTCC) $(HOSTCCFLAGS) -o makeboot makeboot.c
@@ -62,7 +65,9 @@ distribution:
.SUFFIXES: .bin .v
.s.bin:
- $(BCC) -c $*.s -A-b -A$*.bin -A-s -A$*.sym -A-l -A$*.lst
+ $(BCC) -c $*.s -A-u- -A-b -A/tmp/$*.bin -A-s -A$*.sym -A-l -A$*.lst
+ -@mv /tmp/$*.bin $*.bin
+ -@rm $*.o
.s.v:
as86_encap $*.s $*.v $*_ $(ASFLAGS) $(LST)
diff --git a/bootblocks/README b/bootblocks/README
index 5d2344b..e78097d 100644
--- a/bootblocks/README
+++ b/bootblocks/README
@@ -30,9 +30,7 @@ C:\> makeboot dos a:
Place a Linux-8086 executable in the root directory of the floppy.
$ make monitor.out
-$ mount -t msdos /dev/fd0 /mnt
-$ cp monitor.out /mnt/bootfile.sys
-$ umount /dev/fd0
+$ mcopy monitor.out a:BOOTFILE.SYS
or
C:\> copy monitor.out a:\bootfile.sys
@@ -80,10 +78,10 @@ Take 1 msdos floppy.
$ makeboot dos /dev/fd0
$ mount -t msdos /dev/fd0 /mnt
$ cp monitor.out /mnt/bootfile.sys
-$ umount /dev/fd0
-$ cp /usr/src/linux/arch/i386/boot/bzImage /mnt/fd0/vmlinuz
-$ echo 'root=/dev/ram ramdisk_file=ramdisk.gz mem=80M' > /mnt/fd0/vmlinuz.cmd
-$ cp /archive/ramdisk.gz /mnt/fd0/ramdisk.gz
+
+$ cp /usr/src/linux/arch/i386/boot/bzImage /mnt/vmlinuz
+$ echo 'root=/dev/ram ramdisk_file=ramdisk.gz mem=80M' > /mnt/vmlinuz.cmd
+$ cp /archive/ramdisk.gz /mnt/ramdisk.gz
$ umount /dev/fd0
The stuff about ramdisk is only if you want an init ramdisk. You can also use:
diff --git a/bootblocks/dosfs.c b/bootblocks/dosfs.c
index a545b28..9dba0af 100644
--- a/bootblocks/dosfs.c
+++ b/bootblocks/dosfs.c
@@ -54,6 +54,7 @@ struct filestatus {
open_file(fname)
char * fname;
{
+ extern union REGS __argr;
char conv_name[12];
char *s, *d;
int i;
diff --git a/bootblocks/makeboot.c b/bootblocks/makeboot.c
index 28d7ded..0f07735 100644
--- a/bootblocks/makeboot.c
+++ b/bootblocks/makeboot.c
@@ -24,7 +24,7 @@ struct bblist {
} bblocks[] = {
{ "tar", tarboot_data, FS_TAR, "Bootable GNU tar volume lable" },
{ "dosfs", msdos_data, FS_ADOS, "Boots file BOOTFILE.SYS from dosfs" },
- { "bare", sysboot_data, FS_DOS, "Bare bootblock, lockup if booted" },
+ { "none", sysboot_data, FS_DOS, "No OS bookblock, just message" },
{ "skip", skip_data, FS_DOS, "Bypasses floppy boot with message" },
{ "stat", 0, FS_STAT, "Display dosfs superblock" },
{ "copy", 0, FS_STAT, "Copy boot block to makeboot.sav" },
diff --git a/bootblocks/mbr.s b/bootblocks/mbr.s
index dd4cb27..f6a8048 100644
--- a/bootblocks/mbr.s
+++ b/bootblocks/mbr.s
@@ -8,7 +8,7 @@
! Lowest available is $0500, MSDOS appears to use $0600 ... I wonder why?
ORGADDR=$0500
-preboot=1 ! Include the pre-boot loader ?
+preboot=0 ! Include the pre-boot loader ?
! Include standard layout
org ORGADDR
@@ -58,7 +58,7 @@ more_boot:
jnc more_boot ! This doesn't retry, with a HD it shouldn't be bad.
jc disk_error
load_done:
- call [di]
+ call di
exec_done:
pop bx
endif
@@ -70,6 +70,7 @@ exec_done:
check_active:
cmp byte [si],#$80 ! Flag for activated partition
jz found_active
+bad_boot:
add si,#partition_2-partition_1
cmp si,#bootblock_magic
jnz check_active
@@ -83,6 +84,7 @@ found_active:
mov cx,[si+2] ! cx = Sector & head encoded for int $13
! bx is correct
retry:
+ movb [$7DFE],#0 ! Clear magic for dosemu
mov ax,#$0201 ! Read 1 sector
int $13 ! Disk read.
jnc sector_loaded
@@ -101,7 +103,7 @@ disk_error:
sector_loaded:
mov di,#$7DFE ! End of sector loaded
cmp [di],#$AA55 ! Check for magic
- jnz check_active ! No? Try next partition.
+ jnz bad_boot ! No? Try next partition.
mov bp,si ! LILO says some BBs use bp rather than si
jmpi #$7C00,#0 ! Go!
@@ -141,6 +143,8 @@ return:
export pre_boot_table
pre_boot_table:
+ ! Example: Load rest of H0,C0 into mem at $7C00 (8k).
+ ! .word $7C00, $7C00,$0002,$0000,$0210, $0000
.word return
.word 0
endif
diff --git a/bootblocks/minix.c b/bootblocks/minix.c
index f6ba7b4..8242707 100644
--- a/bootblocks/minix.c
+++ b/bootblocks/minix.c
@@ -2,7 +2,7 @@
* This bootblock loads the linux-8086 executable in the file 'linux'
* from the root directory of a minix filesystem.
*
- * Copyright (C) 1990-1996 Robert de Bath, distributed under the GPL Version 2
+ * Copyright (C) 1990-1997 Robert de Bath, distributed under the GPL Version 2
* Based on minix filesystem definitions.
*/
@@ -16,36 +16,72 @@
#define BOOTSEG (0x07c0)
#define LOADSEG (0x1000)
+#ifdef HARDDISK
+#define get_now()
+#endif
+
#asm
-BOOTSEG = 0x07c0
+! BOOTSEG = 0x07c0
+! LOADSEG = 0x1000 ! This must be sector aligned
+
BOOTADDR = 0x7c00
-LOADSEG = 0x1000 ! This must be sector aligned
+ORGADDR = $0500
.text
! Apparently on startup the only things we can assume are that we start at
-! `start` (ABS addr $07C00) ...
+! `start` (ABS addr $07C00) and the boot sector is in the segment.
! So first set CS=DS=ES=SS=0
! The we move this to $0500 and put the stack at the top of the first 64k.
! The directory 'file' is loaded $1500 and scanned there.
! The final executable will be loaded in the 2nd 64k chunk.
!
-org $0500 ! The lowest available address.
+org ORGADDR ! The lowest available address.
start:
include sysboot.s
+
+org dos_sysid
+ .ascii "MINIXFS BOOT (C) 1990-1997, Robert de Bath"
+
org codestart
+#ifdef HARDDISK
+ mov bx,[si+8] ! Fetch the linear address of part from DS:SI
+ mov dh,[si+10] ! DL is drive number
+#endif
+
xor ax,ax
mov ds,ax
mov es,ax
mov ss,ax
mov sp,ax
+#ifndef HARDDISK
mov ax,#$0204 ! Read 4 sectors, code + superblock.
mov bx,#start ! Where this _should_ be
mov cx,#$0001 ! From sector 1
xor dx,dx ! Of the floppy drive head zero
int $13
+#else
+
+ mov cx,#$100 ! Move 256 words
+ mov si,#BOOTADDR ! From default BB
+ mov di,#ORGADDR ! To the correct address.
+ rep
+ movsw
+
+ xchg dl,dh
+ mov [bootpart],bx ! Save the partition sector offset (and drive)
+ mov [bootpart+2],dx
+
+ ! Read first 3 sectors of hd.
+ xor dx,dx
+ mov cx,#1
+ mov bx,#ORGADDR+$200
+ mov al,#3
+
+ call load_sect
+#endif
jmpi code,#0
@@ -214,15 +250,213 @@ _bootfile: ! 'boot' is good too.
.ascii "linux"
.byte 0,0,0,0,0,0,0,0,0
+#ifdef HARDDISK
+bootpart: .long 0
+#else
_loadcount: .word 0
_firstsect: .word 0
_loadaddr: .word 0
_lastsect: .word 0
+#endif
code:
call _loadprog
call _runprog
br _nogood
+
+#endasm
+
+#ifdef HARDDISK
+
+#asm
+_load_block:
+ push bp
+ mov bp,sp
+
+ ! Fetch load location
+ mov ax,[bp+4]
+ mov es,ax
+
+ ! Test for block zero
+ mov ax,6[bp]
+ test ax,ax
+ jne real_block
+
+ ! Iff block zero, zap memory
+ push di
+ mov cx,#512
+ xor ax,ax
+ mov di,ax
+ rep
+ stosw
+ pop di
+
+func_exit:
+ mov sp,bp
+ pop bp
+ ret
+
+real_block:
+#ifdef DOTS
+ mov ax,#$2E
+ push ax
+ call _bios_putc
+ inc sp
+ inc sp
+#endif
+
+! Load a real block.
+ mov cx,ax
+ xor dx,dx
+ shl cx,#1
+ rcl dx,#1
+
+ xor bx,bx
+ mov al,#2
+ call load_sect
+
+ j func_exit
+
+!
+! Load AL sectors from linear sector DX:CX into location ES:BX
+! Linear sector zero is a [bootpart]
+! This loads one sector at a time, but that's OK cause even in the _very_
+! worst case it'll take no more that 5 seconds to load a 16 bit executable.
+!
+load_sect:
+ add cx,[bootpart]
+ adc dx,[bootpart+2]
+moresect:
+ cmp al,#0
+ jnz onesect
+ clc
+ ret
+
+! Load one sector...
+onesect:
+ push ax ! Save lots
+ push di
+ push si
+ push cx ! Drive and sector.
+ push dx
+
+ push es ! Load location
+ push bx
+
+ push cx ! Drive and sector.
+ push dx
+
+ ! Fetch drive 'shape'
+ mov ah,#8
+ mov dl,dh
+ int $13 ! DX:CX = drive specification
+ jc _nogood
+
+ and cx,#$3F ! Get sector count => DI
+ mov di,cx
+
+ xor dl,dl ! Get head count => SI
+ xchg dl,dh
+ inc dx
+ mov si,dx
+
+ pop dx ! Get back drive and sector
+ pop ax
+
+ mov bl,dh ! Save drive
+ xor dh,dh
+
+ div di ! DX=sector, AX=track number
+ mov cx,dx
+ inc cl ! CL=sector number
+
+ xor dx,dx
+ div si ! DX=head, AX=cylinder
+
+ mov dh,dl
+ mov dl,bl ! DX for int 1302
+
+ xchg al,ah
+ ror al,#1
+ ror al,#1
+ or cx,ax ! CX for int 1302
+
+ pop bx ! ES:BX for int 1302
+ pop es
+
+ mov ax,#$0201
+ int $13
+ jc _nogood
+
+ pop dx
+ pop cx
+ pop si
+ pop di
+ pop ax
+
+ dec al
+ add cx,#1
+ adc dh,#0
+ add bh,#2
+ jmp moresect
+#endasm
+
+#else
+#asm
+_set_bpb:
+bios_tabl=dosfs_stat ! Temp space.
+bios_disk=dosfs_stat+4 !
+
+#ifndef __CALLER_SAVES__
+ push si
+ push di
+#endif
+
+ mov di,#bios_disk
+ mov bx,#0x78
+! 0:bx is parameter table address
+
+ push ds
+ push di
+
+ mov si,[bx]
+ mov ax,[bx+2]
+ mov [bios_tabl],si
+ mov [bios_tabl+2],ax
+ push ax
+
+ pop ds
+! ds:si is source
+
+! copy 12 bytes
+ mov cl,#6
+ cld
+ rep
+ movsw
+
+ pop di
+ pop ds
+ mov ax,[_n_sectors]
+ movb 4[di],al ! patch sector count
+
+ mov [bx],di
+ mov 2[bx],es
+
+#ifndef __CALLER_SAVES__
+ pop si
+ pop di
+#endif
+ ret
+
+_unset_bpb:
+! 0:0x78 is parameter table address
+
+ mov ax,[bios_tabl]
+ mov [0x78],ax
+ mov ax,[bios_tabl+2]
+ mov [0x78+2],ax
+ ret
+
#endasm
static
@@ -314,11 +548,7 @@ zero_block(address)
#endasm
}
-#ifndef load_zone
-NOT_DEFINED_load_zone(address, zoneno)
-{
-}
-#endif
+#endif /* !HARDDISK */
#ifdef DOTS
static
@@ -339,6 +569,27 @@ bios_putc(c)
static
nogood()
{
+#ifdef HARDDISK
+#asm
+ mov si,#fail_fs
+min_nextc:
+ lodsb
+ cmp al,#0
+ jz min_eos
+ mov bx,#7
+ mov ah,#$E ! Can't use $13 cause that's AT+ only!
+ int $10
+ jmp min_nextc
+min_eos: ! Wait for a key then reboot
+ xor ax,ax
+ int $16
+ !int $19 ! This should be OK as we haven't touched anything.
+ jmpi $0,$FFFF ! Wam! Try or die!
+
+fail_fs:
+ .asciz "Inital boot failed, press return to reboot\r\n"
+#endasm
+#else
/* This didn't work, chain the boot sector of the HD */
#asm
push cs
@@ -352,16 +603,20 @@ hcode:
jc hcode ! Keep trying forever!
jmpi BOOTADDR,0
#endasm
+#endif
}
+/****************************************************************************/
#asm
end_of_part1:
if *>start+0x200
- fail
+ fail! Part 1 too large!
endif
.blkb 0x200+start-*
#endasm
+/****************************************************************************/
+
static
loadprog()
{
@@ -372,6 +627,10 @@ loadprog()
n_sectors = b_super.s_nzones / 80;
if( n_sectors < 5 ) n_sectors = b_super.s_nzones / 40;
+#ifndef HARDDISK
+ set_bpb();
+#endif
+
try_again:;
#ifdef zone_shift
if( zone_shift != b_super.s_log_zone_size) nogood();
@@ -459,6 +718,9 @@ register char * p = dirptr->d_name;
}
nogood();
}
+#ifndef HARDDISK
+ unset_bpb();
+#endif
}
static
@@ -466,8 +728,14 @@ runprog()
{
/* This did work, run the loaded executable */
#asm
+#ifdef HARDDISK
+ mov dx,[bootpart+2]
+ xchg dh,dl ! DX => hard drive
+ push [bootpart] ! CX => partition offset
+#else
xor dx,dx ! DX=0 => floppy drive
push dx ! CX=0 => partition offset = 0
+#endif
mov si,[_n_sectors] ! Save for monitor.out
mov bx,#LOADSEG
@@ -477,7 +745,7 @@ runprog()
xor di,di ! Zero
mov ax,[di]
cmp ax,#0x0301 ! Right magic ?
- bne nogood ! Yuk ...
+ bne _nogood ! Yuk ...
mov ax,[di+2]
and ax,#$20 ! Is it split I/D ?
jz impure ! No ...
@@ -509,6 +777,13 @@ idiv_u:
xor dx,dx
div bx
ret
+#ifndef zone_shift
+isl:
+islu:
+ mov cl,bl
+ shl ax,cl
+ ret
+#endif
libend:
vars:
diff --git a/bootblocks/monitor.c b/bootblocks/monitor.c
index b9cc751..dbf2d64 100644
--- a/bootblocks/monitor.c
+++ b/bootblocks/monitor.c
@@ -9,7 +9,7 @@
#include "readfs.h"
#ifdef __STANDALONE__
-#define VT52COLOUR
+#define NOT_VT52COLOUR
#define NOT_ANSICOLOUR
#endif
@@ -27,6 +27,9 @@ extern struct t_cmd_list {
static unsigned int current_address;
static int number_base = 16;
+#ifdef __STANDALONE__
+ extern union REGS __argr;
+#endif
#ifdef __STANDALONE__
main()
@@ -48,22 +51,17 @@ static char minibuf[2] = " ";
#endif
init_prog();
-
-#if 0
#ifdef __STANDALONE__
- reg_line();
-#endif
-#ifdef VT52COLOUR
- colour_line();
-#endif
+ if( (__argr.x.dx & 0xFF) == 0 )
#endif
+ {
+ display_help(0);
- display_help(0);
-
- if(1) /* ( x86 > 2 && !x86_emu ) /* Check some basics */
- cmd_bzimage((void*)0);
- else
- printf("System appears incompatible use '=' <return> to try anyway\n");
+ if( x86 > 2 && !x86_emu ) /* Check some basics */
+ cmd_bzimage((void*)0);
+ else
+ printf("System is not a 386+ in real mode, load aborted.\nUse 'bzimage' command toattempt load.\n");
+ }
for (;;)
{
@@ -175,7 +173,6 @@ void init_prog()
#ifdef __STANDALONE__
reg_line()
{
- extern union REGS __argr;
printf("REGS: AX=%04x BX=%04x CX=%04x DX=%04x SI=%04x DI=%04x\n",
__argr.x.ax, __argr.x.bx, __argr.x.cx, __argr.x.dx,
__argr.x.si, __argr.x.di);
diff --git a/bootblocks/sysboot.s b/bootblocks/sysboot.s
index 54b0fb2..3bc7c57 100644
--- a/bootblocks/sysboot.s
+++ b/bootblocks/sysboot.s
@@ -45,10 +45,37 @@ dos4_serial: .blkw 2 ! Serial number
dos4_label: .blkb 11 ! Disk Label (DOS 4+)
dos4_fattype: .blkb 8 ! FAT type
+!
+! This is where the code will be overlaid, the default is an 'oops'
.blkb sysboot_start+0x3E-*
public codestart
codestart:
- jmp codestart
+ xor ax,ax
+ mov ds,ax
+ mov es,ax
+ mov ss,ax
+ mov sp,ax
+ jmpi sys_code+$7C00-sysboot_start,#0
+
+sys_code: ! SI now has pointer to error message
+ mov si,#sys_no_os+$7C00-sysboot_start
+sys_nextc:
+ lodsb
+ cmp al,#0
+ jz sys_eos
+ mov bx,#7
+ mov ah,#$E ! Can't use $13 cause that's AT+ only!
+ int $10
+ jmp sys_nextc
+sys_eos: ! Wait for a key then reboot
+ xor ax,ax
+ int $16
+ !int $19 ! This should be OK as we haven't touched anything.
+ jmpi $0,$FFFF ! Wam! Try or die!
+
+sys_no_os:
+ .asciz "PANIC! NO OS Found!\r\n"
+
! Partition table
public partition_1
diff --git a/copt/copt.diff b/copt/copt.diff
new file mode 100644
index 0000000..89d3686
--- /dev/null
+++ b/copt/copt.diff
@@ -0,0 +1,72 @@
+diff -rc linux-86.orig/copt/copt.c linux-86/copt/copt.c
+*** linux-86.orig/copt/copt.c Tue Feb 18 21:31:34 1997
+--- linux-86/copt/copt.c Tue Apr 22 14:11:05 1997
+***************
+*** 303,314 ****
+ }
+
+
+-
+- /*
+- * Eval an expression into an integer number
+- */
+- static long eval(char *str, int len)
+- {
+ #define NO_OP 0
+ #define ADD_OP 1
+ #define SUB_OP 2
+--- 303,308 ----
+***************
+*** 317,330 ****
+ #define SHL_OP 5
+ #define SHR_OP 6
+
+! char *oldcp, *cp, c;
+! long retval = 0;
+! long num = 0;
+! int sign = 1;
+! int base = 10;
+! int state = 0;
+! int op = NO_OP;
+! int i, varnum;
+
+ /* Apply operation to current numeric value */
+ static void doretval(void)
+--- 311,321 ----
+ #define SHL_OP 5
+ #define SHR_OP 6
+
+! static int op = NO_OP;
+! static long retval = 0;
+! static long num = 0;
+! static int sign = 1;
+! static int base = 10;
+
+ /* Apply operation to current numeric value */
+ static void doretval(void)
+***************
+*** 350,355 ****
+--- 341,363 ----
+ sign = 1;
+ base = 10;
+ }
++
++
++ /*
++ * Eval an expression into an integer number
++ */
++ static long eval(char *str, int len)
++ {
++
++ char *oldcp, *cp, c;
++ int state = 0;
++ int i, varnum;
++
++ op = NO_OP;
++ retval = 0;
++ num = 0;
++ sign = 1;
++ base = 10;
+
+ /* Scan through whole string and decode it */
+ for (cp = str, i = 0; *cp && i < len; cp++, i++) {
diff --git a/copt/rules.86 b/copt/rules.86
index d4fe131..b4030cd 100644
--- a/copt/rules.86
+++ b/copt/rules.86
@@ -2,10 +2,9 @@
# Rules for loading short variables
-# Chad says this one (I think) is broken
-# mov %0$0[%2],%3
-# =
-# mov %0[%2],%3
+mov %0$0[%2],%3
+=
+mov %0[%2],%3
mov %2,%[ax|bx|cx|dx]1
mov %[ax|bx|cx|dx]1,%2
@@ -131,12 +130,14 @@ stosb
# Rules for manipulating short values
-mov %[ax|bx]2,%1
-%[add|and|xor|sub|or]4 %[ax|bx]2,%3
-mov %1,%[ax|bx]2
-=
-mov %2,%3
-%4 %1,%2
+# This is the broken rule - Chad
+
+#mov %[ax|bx]2,%1
+#%[add|and|xor|sub|or]4 %[ax|bx]2,%3
+#mov %1,%[ax|bx]2
+#=
+#mov %2,%3
+#%4 %1,%2
mov %[ax|bx]2,%1
%[add|and|xor|or]4 %[ax|bx]2,%3
diff --git a/elksemu/Makefile b/elksemu/Makefile
index 5964353..2de8673 100644
--- a/elksemu/Makefile
+++ b/elksemu/Makefile
@@ -10,6 +10,9 @@ else
CFLAGS=-O2 -fno-strength-reduce -Wall -idirafter . $(DEFS)
endif
+# Turn on elkemu's strace like facility.
+# DEFS=-DDEBUG
+
# For gcc making a.out with a basically ELF compiler
# CFLAGS=-O2 -fno-strength-reduce -b i486-linuxaout -N -s -static
diff --git a/elksemu/elks.c b/elksemu/elks.c
index 2c58f8e..c31e94f 100644
--- a/elksemu/elks.c
+++ b/elksemu/elks.c
@@ -234,7 +234,7 @@ void main(int argc, char *argv[], char *envp[])
setregid(rgid, egid);
setreuid(ruid, euid);
- dbprintf(("ELKSEMU 0.0.6 Alpha\n"));
+ dbprintf(("ELKSEMU 0.12.0\n"));
elks_init();
/* The Linux vm will deal with not allocating the unused pages */
diff --git a/elksemu/elks_sys.c b/elksemu/elks_sys.c
index 74afbf9..4cc4368 100644
--- a/elksemu/elks_sys.c
+++ b/elksemu/elks_sys.c
@@ -110,13 +110,22 @@ static int elks_read(int bx,int cx,int dx,int di,int si)
bx,cx,dx));
if( bx >= 10000 && bx < 10000+DIRCOUNT)
return elks_readdir(bx, cx, dx);
+ if( dx < 0 || dx > 1024 ) dx = 1024;
return read(bx, ELKS_PTR(void, cx), dx);
}
#define sys_write elks_write
static int elks_write(int bx,int cx,int dx,int di,int si)
{
- dbprintf(("write(%d, %d, %d)\n",bx,cx,dx));
+ if( dx > 1024 || dx < 0 )
+ {
+ dx = 1024;
+ dbprintf(("write(%d, %d, >%d)\n",bx,cx,dx));
+ }
+ else
+ {
+ dbprintf(("write(%d, %d, %d)\n",bx,cx,dx));
+ }
return write(bx,ELKS_PTR(void, cx),dx);
}
diff --git a/ifdef.c b/ifdef.c
index f856157..0837864 100644
--- a/ifdef.c
+++ b/ifdef.c
@@ -2,6 +2,16 @@
#include <stdio.h>
#include <ctype.h>
+#include <string.h>
+
+#ifdef __STDC__ /* == Not braindead compiler (hopefully!) */
+#include <malloc.h>
+
+#define P(x) x
+#else
+#define P(x) ()
+#define void char
+#endif
struct varrec
{
@@ -32,6 +42,18 @@ char * commentstr = "#";
char names[16][32];
char state[16];
+int main P((int argc, char ** argv));
+void Usage P((char * prog));
+void save_name P((char * varname, int state));
+void do_file P((char * fname));
+void set_line P((int lineno));
+int do_hashcom P((void));
+int do_ifdef P((char * p, int which));
+void check_name P((char * nm));
+void fatal P((char * msg));
+void manifest_constant P((void));
+
+int
main(argc, argv)
int argc;
char ** argv;
@@ -77,7 +99,7 @@ char ** argv;
exit(0);
}
-Usage(prog)
+void Usage(prog)
char * prog;
{
fprintf(stderr, "Usage: %s [-DFLAG] [-UFLAG] [-blcrMDU] [-C##] files\n",
@@ -85,6 +107,7 @@ char * prog;
exit(1);
}
+void
save_name(varname, state)
char * varname;
int state;
@@ -110,7 +133,7 @@ int state;
curr->state = state;
}
-
+void
do_file(fname)
char * fname;
{
@@ -146,6 +169,7 @@ char * fname;
fclose(fd);
}
+void
set_line(lineno)
int lineno;
{
@@ -156,6 +180,7 @@ int lineno;
prline = lineno;
}
+int
do_hashcom()
{
char * p = linebuf+1;
@@ -202,6 +227,7 @@ do_hashcom()
return 0;
}
+int
do_ifdef(p, which)
char * p;
int which;
@@ -245,6 +271,7 @@ int which;
return 1;
}
+void
check_name(nm)
char * nm;
{
@@ -270,6 +297,7 @@ x_error:
fputc('\n', stderr);
}
+void
fatal(msg)
char * msg;
{
@@ -281,6 +309,7 @@ char * msg;
*
* Unfortunatly I can find no way of discovering the variables automatically
*/
+void
manifest_constant()
{
/* General */
@@ -290,6 +319,9 @@ manifest_constant()
#ifdef __GNUC__
save_name("__GNUC__", 'D');
#endif
+#ifdef GNUMAKE
+ save_name("GNUMAKE", 'D');
+#endif
/* MSDOS */
#ifdef MSDOS
diff --git a/ld/Makefile b/ld/Makefile
index da7b268..2e30d96 100644
--- a/ld/Makefile
+++ b/ld/Makefile
@@ -4,11 +4,19 @@ CFLAGS =-O
LDFLAGS =-s
# May need some of these if the auto-sense fails.
-# -DV7_A_OUT -DBSD_A_OUT -DSTANDARD_GNU_A_OUT
-DEFS =-DREL_OUTPUT
+# -DV7_A_OUT # a.out.h is like V7
+# -DBSD_A_OUT # a.out.h is like BSD
+# -DSTANDARD_GNU_A_OUT # a.out.h is like GNU normal.
+# -DNO_AOUT # a.out.h is like nothing known!
+#
+DEFS =-DREL_OUTPUT -DBUGCOMPAT
+
+# An alternative file for a non-standard a.out.h (eg i386 linux on an Alpha)
+#
+# NATIVE= -DA_OUT_INCL='"a_out_local.h"'
OBJS= dumps.o io.o ld.o readobj.o table.o typeconv.o linksyms.o \
- writex86.o writebin.o
+ writex86.o writebin.o writerel.o
all: ld86
@@ -29,5 +37,10 @@ ar.h:
ln -s ../libc/include/ar.h . || \
ln ../libc/include/ar.h .
+writebin.o: writebin.c
+ $(CC) $(CFLAGS) $(DEFS) $(NATIVE) -c writebin.c
+
+writerel.o: writebin.c
+
.c.o:
$(CC) $(CFLAGS) $(DEFS) -c $< -o $@
diff --git a/ld/align.h b/ld/align.h
index 02bbe43..52b1e89 100644
--- a/ld/align.h
+++ b/ld/align.h
@@ -5,8 +5,14 @@
#ifndef S_ALIGNMENT
# define align(x)
#else
-# define align(x) ((x)=(void*) \
- ((char *)(x) + ((S_ALIGNMENT-(int)(x)) & (S_ALIGNMENT-1))))
+
+#if defined(__STDC__) && defined(_POSIX_SOURCE)
+# define align(x) ((x)=(void *) \
+ (((ssize_t)(x) + (S_ALIGNMENT-1)) & ~(S_ALIGNMENT-1)))
+#else
+# define align(x) ((x)=(void *) \
+ ((char *)(x) + ((S_ALIGNMENT-(char)(x)) & (S_ALIGNMENT-1))))
+#endif
#endif
@@ -14,7 +20,4 @@
-/* * assumes sizeof(int) == sizeof(char *) *
-# define align(x) ((x) = (void *)(((int) (x) + (S_ALIGNMENT-1)) & ~(S_ALIGNMENT-1)))
-*/
diff --git a/ld/bindef.h b/ld/bindef.h
index 2a2d8d8..dbacfcd 100644
--- a/ld/bindef.h
+++ b/ld/bindef.h
@@ -66,8 +66,12 @@
# endif /* BSD_A_OUT */
/* And finally make sure it worked */
-#ifdef C_EXT
+#if defined(A_MINHDR) || defined(BSD_A_OUT)
+#if defined(C_EXT) && defined(C_STAT) && !defined(SCNHSZ)
+
#define AOUT_DETECTED 1
+
+#endif
#endif
#endif /* NO_AOUT */
diff --git a/ld/bugs b/ld/bugs
deleted file mode 100644
index 9444281..0000000
--- a/ld/bugs
+++ /dev/null
@@ -1,14 +0,0 @@
-1. Should cause error when an address which requires > 16 bits is referenced
- using 16 bits.
-
-TODO:
- integrate byteord.h with compiler as well as assembler
-
-TODO:
- integrate align.h with compiler and assembler
- use alignment for *86 like compiler - use more portable macro
- ((x) + (-(int) (x) & MASK)) when it is either necessary or
- faster
-
-TODO:
- do malloc stuff better, as in compiler
diff --git a/ld/byteord.h b/ld/byteord.h
index 57d17b9..c854979 100644
--- a/ld/byteord.h
+++ b/ld/byteord.h
@@ -5,16 +5,16 @@
/* These are for the targets of everything and for linker source too. */
#ifdef I8086
-# define BIG_ENDIAN 0
+# define INT_BIG_ENDIAN 0
# define LONG_BIG_ENDIAN 0 /* except longs are back to front for Xenix */
#endif
#ifdef I80386
-# define BIG_ENDIAN 0
+# define INT_BIG_ENDIAN 0
# define LONG_BIG_ENDIAN 0
#endif
#ifdef MC6809
-# define BIG_ENDIAN 1 /* byte order in words is high-low */
+# define INT_BIG_ENDIAN 1 /* byte order in words is high-low */
# define LONG_BIG_ENDIAN 1 /* byte order in longs is high-low */
#endif
diff --git a/ld/ld.c b/ld/ld.c
index 1de55ce..0a307e9 100644
--- a/ld/ld.c
+++ b/ld/ld.c
@@ -83,7 +83,7 @@ char **argv;
ioinit(argv[0]);
objinit();
syminit();
- typeconv_init(BIG_ENDIAN, LONG_BIG_ENDIAN);
+ typeconv_init(INT_BIG_ENDIAN, LONG_BIG_ENDIAN);
#ifndef MC6809
flag['3'] = sizeof(char *) >= 4;
#endif
@@ -205,6 +205,7 @@ char **argv;
#ifdef REL_OUTPUT
#ifndef MSDOS
+#ifndef BUGCOMPAT
if( flag['r'] && !flag['N'] )
{
/* Ok, try for an alternate linker */
@@ -217,6 +218,7 @@ char **argv;
}
#endif
#endif
+#endif
#ifdef MSDOS
/* MSDOS Native is special, we make a COM file */
@@ -241,6 +243,12 @@ char **argv;
flag['z'] & flag['3']);
else
#endif
+#ifdef BUGCOMPAT
+ if( flag['r'] )
+ write_rel(outfilename, flag['i'], flag['3'], flag['s'],
+ flag['z'] & flag['3']);
+ else
+#endif
write_elks(outfilename, flag['i'], flag['3'], flag['s'],
flag['z'] & flag['3']);
if (flag['m'])
diff --git a/ld/rel_aout.h b/ld/rel_aout.h
new file mode 100644
index 0000000..9316a72
--- /dev/null
+++ b/ld/rel_aout.h
@@ -0,0 +1,383 @@
+#ifndef _BSD_A_OUT_H
+#define _BSD_A_OUT_H
+
+struct exec { /* a.out header */
+ unsigned char a_magic[2]; /* magic number */
+ unsigned char a_flags; /* flags, see below */
+ unsigned char a_cpu; /* cpu id */
+ unsigned char a_hdrlen; /* length of header */
+ unsigned char a_unused; /* reserved for future use */
+ unsigned short a_version; /* version stamp (not used at present) */
+ long a_text; /* size of text segement in bytes */
+ long a_data; /* size of data segment in bytes */
+ long a_bss; /* size of bss segment in bytes */
+ long a_entry; /* entry point */
+ long a_total; /* total memory allocated */
+ long a_syms; /* size of symbol table */
+ /* SHORT FORM ENDS HERE */
+
+ long a_trsize; /* text relocation size */
+ long a_drsize; /* data relocation size */
+ long a_tbase; /* text relocation base */
+ long a_dbase; /* data relocation base */
+};
+
+#define A_MAGIC0 ((unsigned char) 0x01)
+#define A_MAGIC1 ((unsigned char) 0x03)
+#define BADMAG(X) ((X).a_magic[0] != A_MAGIC0 || (X).a_magic[1] != A_MAGIC1)
+
+/* CPU Id of TARGET machine (byte order coded in low order two bits) */
+#define A_NONE 0x00 /* unknown */
+#define A_I8086 0x04 /* intel i8086/8088 */
+#define A_M68K 0x0B /* motorola m68000 */
+#define A_NS16K 0x0C /* national semiconductor 16032 */
+#define A_I80386 0x10 /* intel i80386 */
+#define A_SPARC 0x17 /* Sun SPARC */
+
+#define A_BLR(cputype) ((cputype&0x01)!=0) /* TRUE if bytes left-to-right */
+#define A_WLR(cputype) ((cputype&0x02)!=0) /* TRUE if words left-to-right */
+
+/* Flags. */
+#define A_UZP 0x01 /* unmapped zero page (pages) */
+#define A_EXEC 0x10 /* executable */
+#define A_SEP 0x20 /* separate I/D */
+#define A_PURE 0x40 /* pure text */ /* not used */
+#define A_TOVLY 0x80 /* text overlay */ /* not used */
+
+/* Tell a.out.gnu.h not to define `struct exec'. */
+#define __STRUCT_EXEC_OVERRIDE__
+
+/* Hide M_386 from enum declaration in a.out.h. */
+#define M_386 HIDE_M_386
+
+#ifndef __A_OUT_GNU_H__
+#define __A_OUT_GNU_H__
+
+#if defined(sequent) && defined(i386)
+#define a_magic a_info
+#include <a.out.h>
+#undef a_magic
+#define __STRUCT_EXEC_OVERRIDE__
+#define N_NLIST_DECLARED
+#define N_RELOCATION_INFO_DECLARED
+#endif
+
+#define __GNU_EXEC_MACROS__
+
+#ifndef __STRUCT_EXEC_OVERRIDE__
+
+struct exec
+{
+ unsigned long a_info; /* Use macros N_MAGIC, etc for access */
+ unsigned long a_text; /* length of text, in bytes */
+ unsigned long a_data; /* length of data, in bytes */
+ unsigned long a_bss; /* length of uninitialized data area for file, in bytes */
+ unsigned long a_syms; /* length of symbol table data in file, in bytes */
+ unsigned long a_entry; /* start address */
+ unsigned long a_trsize; /* length of relocation info for text, in bytes */
+ unsigned long a_drsize; /* length of relocation info for data, in bytes */
+};
+
+#endif /* __STRUCT_EXEC_OVERRIDE__ */
+
+/* these go in the N_MACHTYPE field */
+enum machine_type {
+#if defined (M_OLDSUN2)
+ M__OLDSUN2 = M_OLDSUN2,
+#else
+ M_OLDSUN2 = 0,
+#endif
+#if defined (M_68010)
+ M__68010 = M_68010,
+#else
+ M_68010 = 1,
+#endif
+#if defined (M_68020)
+ M__68020 = M_68020,
+#else
+ M_68020 = 2,
+#endif
+#if defined (M_SPARC)
+ M__SPARC = M_SPARC,
+#else
+ M_SPARC = 3,
+#endif
+ /* skip a bunch so we don't run into any of sun's numbers */
+ M_386 = 100,
+};
+
+#if !defined (N_MAGIC)
+#define N_MAGIC(exec) ((exec).a_info & 0xffff)
+#endif
+#define N_MACHTYPE(exec) ((enum machine_type)(((exec).a_info >> 16) & 0xff))
+#define N_FLAGS(exec) (((exec).a_info >> 24) & 0xff)
+#define N_SET_INFO(exec, magic, type, flags) \
+ ((exec).a_info = ((magic) & 0xffff) \
+ | (((int)(type) & 0xff) << 16) \
+ | (((flags) & 0xff) << 24))
+#define N_SET_MAGIC(exec, magic) \
+ ((exec).a_info = (((exec).a_info & 0xffff0000) | ((magic) & 0xffff)))
+
+#define N_SET_MACHTYPE(exec, machtype) \
+ ((exec).a_info = \
+ ((exec).a_info&0xff00ffff) | ((((int)(machtype))&0xff) << 16))
+
+#define N_SET_FLAGS(exec, flags) \
+ ((exec).a_info = \
+ ((exec).a_info&0x00ffffff) | (((flags) & 0xff) << 24))
+
+#ifndef OMAGIC
+/* Code indicating object file or impure executable. */
+#define OMAGIC 0407
+/* Code indicating pure executable. */
+#define NMAGIC 0410
+/* Code indicating demand-paged executable. */
+#define ZMAGIC 0413
+#endif /* not OMAGIC */
+
+#if !defined (N_BADMAG)
+#define N_BADMAG(x) \
+ (N_MAGIC(x) != OMAGIC && N_MAGIC(x) != NMAGIC \
+ && N_MAGIC(x) != ZMAGIC)
+#endif
+
+#define _N_BADMAG(x) \
+ (N_MAGIC(x) != OMAGIC && N_MAGIC(x) != NMAGIC \
+ && N_MAGIC(x) != ZMAGIC)
+
+#define _N_HDROFF(x) (SEGMENT_SIZE - sizeof (struct exec))
+
+#if !defined (N_TXTOFF)
+#define N_TXTOFF(x) \
+ (N_MAGIC(x) == ZMAGIC ? _N_HDROFF((x)) + sizeof (struct exec) : sizeof (struct exec))
+#endif
+
+#if !defined (N_DATOFF)
+#define N_DATOFF(x) (N_TXTOFF(x) + (x).a_text)
+#endif
+
+#if !defined (N_TRELOFF)
+#define N_TRELOFF(x) (N_DATOFF(x) + (x).a_data)
+#endif
+
+#if !defined (N_DRELOFF)
+#define N_DRELOFF(x) (N_TRELOFF(x) + (x).a_trsize)
+#endif
+
+#if !defined (N_SYMOFF)
+#define N_SYMOFF(x) (N_DRELOFF(x) + (x).a_drsize)
+#endif
+
+#if !defined (N_STROFF)
+#define N_STROFF(x) (N_SYMOFF(x) + (x).a_syms)
+#endif
+
+/* Address of text segment in memory after it is loaded. */
+#if !defined (N_TXTADDR)
+#define N_TXTADDR(x) 0
+#endif
+
+/* Address of data segment in memory after it is loaded.
+ Note that it is up to you to define SEGMENT_SIZE
+ on machines not listed here. */
+#if defined(vax) || defined(hp300) || defined(pyr)
+#define SEGMENT_SIZE PAGE_SIZE
+#endif
+#ifdef hp300
+#define PAGE_SIZE 4096
+#endif
+#ifdef sony
+#define SEGMENT_SIZE 0x2000
+#endif /* Sony. */
+#ifdef is68k
+#define SEGMENT_SIZE 0x20000
+#endif
+#if defined(m68k) && defined(PORTAR)
+#define PAGE_SIZE 0x400
+#define SEGMENT_SIZE PAGE_SIZE
+#endif
+
+#define _N_SEGMENT_ROUND(x) (((x) + SEGMENT_SIZE - 1) & ~(SEGMENT_SIZE - 1))
+
+#define _N_TXTENDADDR(x) (N_TXTADDR(x)+(x).a_text)
+
+#ifndef N_DATADDR
+#define N_DATADDR(x) \
+ (N_MAGIC(x)==OMAGIC? (_N_TXTENDADDR(x)) \
+ : (_N_SEGMENT_ROUND (_N_TXTENDADDR(x))))
+#endif
+
+/* Address of bss segment in memory after it is loaded. */
+#if !defined (N_BSSADDR)
+#define N_BSSADDR(x) (N_DATADDR(x) + (x).a_data)
+#endif
+
+#if !defined (N_NLIST_DECLARED)
+struct nlist {
+ union {
+ char *n_name;
+ struct nlist *n_next;
+ long n_strx;
+ } n_un;
+ unsigned char n_type;
+ char n_other;
+ short n_desc;
+ unsigned long n_value;
+};
+#endif /* no N_NLIST_DECLARED. */
+
+#if !defined (N_UNDF)
+#define N_UNDF 0
+#endif
+#if !defined (N_ABS)
+#define N_ABS 2
+#endif
+#if !defined (N_TEXT)
+#define N_TEXT 4
+#endif
+#if !defined (N_DATA)
+#define N_DATA 6
+#endif
+#if !defined (N_BSS)
+#define N_BSS 8
+#endif
+#if !defined (N_COMM)
+#define N_COMM 18
+#endif
+#if !defined (N_FN)
+#define N_FN 15
+#endif
+
+#if !defined (N_EXT)
+#define N_EXT 1
+#endif
+#if !defined (N_TYPE)
+#define N_TYPE 036
+#endif
+#if !defined (N_STAB)
+#define N_STAB 0340
+#endif
+
+/* The following type indicates the definition of a symbol as being
+ an indirect reference to another symbol. The other symbol
+ appears as an undefined reference, immediately following this symbol.
+
+ Indirection is asymmetrical. The other symbol's value will be used
+ to satisfy requests for the indirect symbol, but not vice versa.
+ If the other symbol does not have a definition, libraries will
+ be searched to find a definition. */
+#define N_INDR 0xa
+
+/* The following symbols refer to set elements.
+ All the N_SET[ATDB] symbols with the same name form one set.
+ Space is allocated for the set in the text section, and each set
+ element's value is stored into one word of the space.
+ The first word of the space is the length of the set (number of elements).
+
+ The address of the set is made into an N_SETV symbol
+ whose name is the same as the name of the set.
+ This symbol acts like a N_DATA global symbol
+ in that it can satisfy undefined external references. */
+
+/* These appear as input to LD, in a .o file. */
+#define N_SETA 0x14 /* Absolute set element symbol */
+#define N_SETT 0x16 /* Text set element symbol */
+#define N_SETD 0x18 /* Data set element symbol */
+#define N_SETB 0x1A /* Bss set element symbol */
+
+/* This is output from LD. */
+#define N_SETV 0x1C /* Pointer to set vector in data area. */
+
+#if !defined (N_RELOCATION_INFO_DECLARED)
+/* This structure describes a single relocation to be performed.
+ The text-relocation section of the file is a vector of these structures,
+ all of which apply to the text section.
+ Likewise, the data-relocation section applies to the data section. */
+
+struct relocation_info
+{
+ /* Address (within segment) to be relocated. */
+ unsigned long r_address;
+#if 0
+ /* The meaning of r_symbolnum depends on r_extern. */
+ unsigned int r_symbolnum:24;
+ /* Nonzero means value is a pc-relative offset
+ and it should be relocated for changes in its own address
+ as well as for changes in the symbol or section specified. */
+ unsigned int r_pcrel:1;
+ /* Length (as exponent of 2) of the field to be relocated.
+ Thus, a value of 2 indicates 1<<2 bytes. */
+ unsigned int r_length:2;
+ /* 1 => relocate with value of symbol.
+ r_symbolnum is the index of the symbol
+ in file's the symbol table.
+ 0 => relocate with the address of a segment.
+ r_symbolnum is N_TEXT, N_DATA, N_BSS or N_ABS
+ (the N_EXT bit may be set also, but signifies nothing). */
+ unsigned int r_extern:1;
+ /* Four bits that aren't used, but when writing an object file
+ it is desirable to clear them. */
+ unsigned int r_pad:4;
+#else
+ unsigned long foo;
+#endif
+};
+#endif /* no N_RELOCATION_INFO_DECLARED. */
+
+
+#endif /* __A_OUT_GNU_H__ */
+
+#undef M_386
+#define M_386 A_I80386
+
+#undef N_MAGIC
+#define N_MAGIC3(magic0, magic1, type) \
+ ((magic0) | ((magic1) << 8) | ((type) << 16))
+#define N_MAGIC(exec) \
+ N_MAGIC3((exec).a_magic[0], (exec).a_magic[1], (exec).a_flags)
+
+#undef N_MACHTYPE
+#define N_MACHTYPE(exec) ((enum machine_type)((exec).a_cpu))
+
+#undef N_FLAGS
+#define N_FLAGS(exec) 0
+
+#undef N_SET_INFO
+#define N_SET_INFO(exec, magic, type, flags) \
+ ((exec).a_magic[0] = (magic) & 0xff, \
+ (exec).a_magic[1] = ((magic) >> 8) & 0xff, \
+ (exec).a_flags = ((magic) >> 16) & 0xff, \
+ (exec).a_cpu = (type) & 0xff)
+
+#undef N_SET_MAGIC
+#define N_SET_MAGIC(exec, magic) \
+ ((exec).a_magic[0] = (magic) & 0xff, \
+ (exec).a_magic[1] = ((magic) >> 8) & 0xff, \
+ (exec).a_flags = ((magic) >> 16) & 0xff)
+
+#undef N_SET_MACHTYPE
+#define N_SET_MACHTYPE(exec, machtype) \
+ ((exec).a_cpu = (machtype) & 0xff, \
+ (exec).a_hdrlen = sizeof (exec))
+
+#undef N_SET_FLAGS
+#define N_SET_FLAGS(exec, flags) /* nothing */
+
+#undef OMAGIC
+#define OMAGIC N_MAGIC3(A_MAGIC0, A_MAGIC1, 0)
+
+#undef NMAGIC
+#define NMAGIC N_MAGIC3(A_MAGIC0, A_MAGIC1, A_EXEC)
+
+#undef ZMAGIC
+#define ZMAGIC N_MAGIC3(A_MAGIC0, A_MAGIC1, A_EXEC)
+
+#undef _N_HDROFF
+#define _N_HDROFF(x) 0
+
+#undef PAGE_SIZE
+#define PAGE_SIZE 16
+#define SEGMENT_SIZE PAGE_SIZE
+#define getpagesize() PAGE_SIZE
+
+#endif /* _BSD_A_OUT_H */
diff --git a/ld/type.h b/ld/type.h
index 12758e3..217d6a9 100644
--- a/ld/type.h
+++ b/ld/type.h
@@ -159,6 +159,9 @@ bool_pt typeconv_init P((bool_pt big_endian, bool_pt long_big_endian));
void writebin P((char *outfilename, bool_pt argsepid, bool_pt argbits32,
bool_pt argstripflag, bool_pt arguzp));
+void write_rel P((char *outfilename, bool_pt argsepid, bool_pt argbits32,
+ bool_pt argstripflag, bool_pt arguzp));
+
/* write_elks.c */
void write_elks P((char *outfilename, bool_pt argsepid, bool_pt argbits32,
bool_pt argstripflag, bool_pt arguzp));
diff --git a/ld/typeconv.c b/ld/typeconv.c
index 82dafdd..6cc4a20 100644
--- a/ld/typeconv.c
+++ b/ld/typeconv.c
@@ -1,536 +1,187 @@
-/* typeconv.c - convert between char arrays and unsigneds */
-
-/* Copyright (C) 1994 Bruce Evans */
/*
- c2u2(): 2 byte array to 2 byte unsigned
- c4u4(): 4 byte array to 4 byte unsigned
- cnu2(): n byte array to 2 byte unsigned
- cnu4(): n byte array to 4 byte unsigned
- u2c2(): 2 byte unsigned to 2 byte array
- u2cn(): 2 byte unsigned to n byte array
- u4c4(): 4 byte unsigned to 4 byte array
- u4cn(): 4 byte unsigned to n byte array
- typeconv_init: (re)initialise for given byte order.
- Default is no swapping, but the initialisation should be done
- anyway to provide some validity checks (returns FALSE if error).
-
- Not provided:
- c2u4(), c4u2(), u2c4(), u4c2().
- Each of these is best done by truncating or extending a return value
- or argument to the appropiate fixed-count function.
- c4u2() has too many cases to do in-line conveniently, and the others
- are hardly more efficient when done in-line.
-
- 4 byte orderings for both char arrays and unsigneds are supported:
- 0123 - little-endian
- 3210 - big-endian
- 2301 - little-endian with long words big-endian (pdp11)
- 1032 - big-endian with long words little_endian (who knows?)
-
- The unsigned's byte order is that of the machine on which these
- routines are running.
- It is determined at run time initialisation since the compiler/
- preprocessor is too dumb to tell us at compile time.
-*/
+ * Type conversion routines, these have been rewritten for portability.
+ *
+ * The only requirement is now that the u2_t and u4_t must be big enough.
+ */
+#include "syshead.h"
#include "const.h"
#include "type.h"
#include "globvar.h"
-FORWARD u2_pt c2u2_00 P((char *buf));
-FORWARD u4_pt c4u4_00 P((char *buf));
-FORWARD u2_pt c2u2_ss P((char *buf));
-FORWARD u4_pt c4u4_ss P((char *buf));
-FORWARD u4_pt c4u4_s0 P((char *buf));
-FORWARD u4_pt c4u4_0s P((char *buf));
-FORWARD void u2c2_00 P((char *buf, u2_pt offset));
-FORWARD void u4c4_00 P((char *buf, u4_t offset));
-FORWARD void u2c2_ss P((char *buf, u2_pt offset));
-FORWARD void u4c4_ss P((char *buf, u4_t offset));
-FORWARD void u4c4_s0 P((char *buf, u4_t offset));
-FORWARD void u4c4_0s P((char *buf, u4_t offset));
-
-PRIVATE u2_pt (*pc2u2) P((char *buf)) = c2u2_00;
-PRIVATE u4_pt (*pc4u4) P((char *buf)) = c4u4_00;
-PRIVATE void (*pu2c2) P((char *buf, u2_pt offset)) = u2c2_00;
-PRIVATE void (*pu4c4) P((char *buf, u4_t offset)) = u4c4_00;
-
-/* === char arrays to unsigneds === */
-
-/* no bytes swapped, longwinded to avoid alignment problems */
-
-PRIVATE u2_pt c2u2_00(buf)
-register char *buf;
-{
- u2_t offset;
-
- ((char *) &offset)[0] = buf[0];
- ((char *) &offset)[1] = buf[1];
- return offset;
-}
-
-PRIVATE u4_pt c4u4_00(buf)
-register char *buf;
-{
- u4_t offset;
+void xxerr P((char *));
+void xxerr(x) char * x; { write(2, x, strlen(x)); }
- ((char *) &offset)[0] = buf[0];
- ((char *) &offset)[1] = buf[1];
- ((char *) &offset)[2] = buf[2];
- ((char *) &offset)[3] = buf[3];
- return offset;
-}
-
-/* straight swapping for little-endian to big-endian and vice versa */
-
-PRIVATE u2_pt c2u2_ss(buf)
-register char *buf;
-{
- u2_t offset;
-
- ((char *) &offset)[0] = buf[1];
- ((char *) &offset)[1] = buf[0];
- return offset;
-}
-
-PRIVATE u4_pt c4u4_ss(buf)
-register char *buf;
-{
- u4_t offset;
-
- ((char *) &offset)[0] = buf[3];
- ((char *) &offset)[1] = buf[2];
- ((char *) &offset)[2] = buf[1];
- ((char *) &offset)[3] = buf[0];
- return offset;
-}
+static int no_swap = 1;
-/* wierd swapping for different-endian u2's, same-endian u4's */
+static long_off[4] = {0,1,2,3};
+static int_off[2] = {0,1};
-PRIVATE u4_pt c4u4_s0(buf)
-register char *buf;
+PUBLIC bool_pt typeconv_init(big_endian, long_big_endian)
+bool_pt big_endian;
+bool_pt long_big_endian;
{
- u4_t offset;
+ int i;
+ no_swap = (!big_endian && !long_big_endian);
- ((char *) &offset)[0] = buf[1];
- ((char *) &offset)[1] = buf[0];
- ((char *) &offset)[2] = buf[3];
- ((char *) &offset)[3] = buf[2];
- return offset;
-}
-
-/* very wierd swapping for same-endian u2's, different-endian u4's */
+ for(i=0; i<4; i++) long_off[i] = i;
+ for(i=0; i<2; i++) int_off[i] = i;
-PRIVATE u4_pt c4u4_0s(buf)
-register char *buf;
-{
- u4_t offset;
+ if( long_big_endian )
+ {
+ i = long_off[0]; long_off[0] = long_off[2]; long_off[2] = i;
+ i = long_off[1]; long_off[1] = long_off[3]; long_off[3] = i;
+ }
+ if( big_endian )
+ {
+ i = long_off[2]; long_off[2] = long_off[3]; long_off[3] = i;
+ i = long_off[0]; long_off[0] = long_off[1]; long_off[1] = i;
- ((char *) &offset)[0] = buf[2];
- ((char *) &offset)[1] = buf[3];
- ((char *) &offset)[2] = buf[0];
- ((char *) &offset)[3] = buf[1];
- return offset;
+ i = int_off[0]; int_off[0] = int_off[1]; int_off[1] = i;
+ }
+ return 1;
}
-/* === entry points === */
-
-PUBLIC u2_pt c2u2(buf)
+PUBLIC void u2c2(buf, offset)
char *buf;
+u2_pt offset;
{
- return (*pc2u2) (buf);
+#ifdef __AS386_16__
+ if( no_swap )
+ {
+ *((unsigned short*)buf) = offset; /* UNALIGNED ACCESS! */
+ return;
+ }
+#endif
+ buf[int_off[0]] = offset;
+ buf[int_off[1]] = (offset>>8);
}
-PUBLIC u4_t c4u4(buf)
+PUBLIC void u4c4(buf, offset)
char *buf;
+u4_t offset;
{
- return (*pc4u4) (buf);
+ int i;
+#ifdef __AS386_16__
+ if( no_swap )
+ {
+ *((unsigned long*)buf) = offset; /* UNALIGNED ACCESS! */
+ return;
+ }
+#endif
+ for(i=0; i<4; i++)
+ {
+ buf[long_off[i]] = offset;
+ offset >>= 8;
+ }
}
-PUBLIC u2_pt cnu2(buf, count)
+PUBLIC void u4cn(buf, offset, count)
char *buf;
+u4_t offset;
unsigned count;
{
- switch (count)
+ switch(count)
{
case 1:
- return buf[0] & 0xFF;
+ buf[0] = (char) offset;
+ return;
case 2:
- return (*pc2u2) (buf);
+ u2c2(buf, (u2_pt) offset);
+ return;
case 4:
- return (u2_pt) (*pc4u4) (buf);
+ u4c4(buf, (u4_t) offset);
+ return;
default:
- return 0;
+ xxerr("WARNING: typeconv.c(u4cn) illegal count\n");
+ return;
}
}
-PUBLIC u4_t cnu4(buf, count)
+PUBLIC void u2cn(buf, offset, count)
char *buf;
+u2_pt offset;
unsigned count;
{
- switch (count)
+ switch(count)
{
case 1:
- return buf[0] & 0xFF;
+ buf[0] = (char) offset;
+ return;
case 2:
- return (*pc2u2) (buf);
+ u2c2(buf, (u2_pt) offset);
+ return;
case 4:
- return (*pc4u4) (buf);
+ u4c4(buf, (u4_t) offset);
+ return;
default:
- return 0;
+ xxerr("WARNING: typeconv.c(u2cn) illegal count\n");
+ return;
}
}
-/* === unsigneds to char arrays === */
-
-/* no bytes swapped, longwinded to avoid alignment problems */
-
-PRIVATE void u2c2_00(buf, offset)
-register char *buf;
-u2_pt offset;
-{
-
- buf[0] = ((char *) &offset)[0];
- buf[1] = ((char *) &offset)[1];
-}
-
-PRIVATE void u4c4_00(buf, offset)
-register char *buf;
-u4_t offset;
-{
- buf[0] = ((char *) &offset)[0];
- buf[1] = ((char *) &offset)[1];
- buf[2] = ((char *) &offset)[2];
- buf[3] = ((char *) &offset)[3];
-}
-
-/* straight swapping for little-endian to big-endian and vice versa */
-
-PRIVATE void u2c2_ss(buf, offset)
-register char *buf;
-u2_pt offset;
-{
- u2_t offset2;
-
- offset2 = offset;
- buf[0] = ((char *) &offset2)[1];
- buf[1] = ((char *) &offset2)[0];
-}
-
-PRIVATE void u4c4_ss(buf, offset)
-register char *buf;
-u4_t offset;
-{
- buf[0] = ((char *) &offset)[3];
- buf[1] = ((char *) &offset)[2];
- buf[2] = ((char *) &offset)[1];
- buf[3] = ((char *) &offset)[0];
-}
-
-/* wierd swapping for different-endian u2's, same-endian u4's */
-
-PRIVATE void u4c4_s0(buf, offset)
-register char *buf;
-u4_t offset;
-{
- buf[0] = ((char *) &offset)[1];
- buf[1] = ((char *) &offset)[0];
- buf[2] = ((char *) &offset)[3];
- buf[3] = ((char *) &offset)[2];
-}
-
-/* very wierd swapping for same-endian u2's, different-endian u4's */
-
-PRIVATE void u4c4_0s(buf, offset)
-register char *buf;
-u4_t offset;
+PUBLIC u2_pt c2u2(buf)
+char *buf;
{
- buf[0] = ((char *) &offset)[2];
- buf[1] = ((char *) &offset)[3];
- buf[2] = ((char *) &offset)[0];
- buf[3] = ((char *) &offset)[1];
-}
-
-/* === entry points === */
+ u2_pt res;
+#ifdef __AS386_16__
+ if( no_swap ) return *((u2_pt *)buf); /* UNALIGNED ACCESS! */
+#endif
-PUBLIC void u2c2(buf, offset)
-register char *buf;
-u2_pt offset;
-{
- (*pu2c2) (buf, offset);
+ res = ((unsigned char *)buf) [int_off[0]]
+ + ((((unsigned char *)buf) [int_off[1]]) << 8);
+ return res;
}
-PUBLIC void u4c4(buf, offset)
-register char *buf;
-u4_t offset;
+PUBLIC u4_t c4u4(buf)
+char *buf;
{
- (*pu4c4) (buf, offset);
+ u4_t res;
+ int i;
+#ifdef __AS386_16__
+ if( no_swap ) return *((u4_t *)buf); /* UNALIGNED ACCESS! */
+#endif
+ res = 0;
+ for(i=3; i>=0; i--)
+ {
+ res = (res<<8) + ((unsigned char *)buf) [long_off[i]];
+ }
+ return res;
}
-PUBLIC void u2cn(buf, offset, count)
-register char *buf;
-u2_pt offset;
+PUBLIC u4_t cnu4(buf, count)
+char *buf;
unsigned count;
{
switch (count)
{
case 1:
- buf[0] = (char) offset;
- return;
+ return buf[0] & 0xFF;
case 2:
- (*pu2c2) (buf, offset);
- return;
+ return c2u2(buf);
case 4:
- (*pu4c4) (buf, (u4_t) offset);
- return;
+ return c4u4(buf);
+ default:
+ xxerr("WARNING: typeconv.c(cnu4) illegal count\n");
+ return 0;
}
}
-PUBLIC void u4cn(buf, offset, count)
-register char *buf;
-u4_t offset;
+PUBLIC u2_pt cnu2(buf, count)
+char *buf;
unsigned count;
{
switch (count)
{
case 1:
- buf[0] = (char) offset;
- return;
+ return buf[0] & 0xFF;
case 2:
- (*pu2c2) (buf, (u2_pt) (u2_t) offset);
- return;
+ return c2u2(buf);
case 4:
- (*pu4c4) (buf, offset);
- return;
- }
-}
-
-/* initialise type conversion, return FALSE if it cannot be handled */
-
-PUBLIC bool_pt typeconv_init(big_endian, long_big_endian)
-bool_pt big_endian;
-bool_pt long_big_endian;
-{
- u2_pt conv2;
- u4_pt conv4;
- char *conv2ptr;
- char *conv4ptr;
-
- if (sizeof(u2_t) != 2 || sizeof(u4_t) != 4)
- /* dumb preprocessor's don't accept sizeof in #if expressions */
- return FALSE;
-
- if (big_endian)
- {
- conv2ptr = (conv4ptr = "\1\2\3\4") + 2;
- if (!long_big_endian)
- conv4ptr = "\3\4\1\2";
- }
- else
- {
- conv2ptr = conv4ptr = "\4\3\2\1";
- if (long_big_endian)
- conv4ptr = "\2\1\4\3";
- }
- conv2 = c2u2_00(conv2ptr);
- conv4 = c4u4_00(conv4ptr);
- if (conv2 == 0x0304)
- {
- pc2u2 = c2u2_00;
- pc4u4 = c4u4_00;
- pu2c2 = u2c2_00;
- pu4c4 = u4c4_00;
- if (conv4 == 0x03040102L)
- {
- pc4u4 = c4u4_0s;
- pu4c4 = u4c4_0s;
- }
- else if (conv4 != 0x01020304L)
- return FALSE;
- }
- else if (conv2 == 0x0403)
- {
- pc2u2 = c2u2_ss;
- pc4u4 = c4u4_ss;
- pu2c2 = u2c2_ss;
- pu4c4 = u4c4_ss;
- if (conv4 == 0x02010403L)
- {
- pc4u4 = c4u4_s0;
- pu4c4 = u4c4_s0;
- }
- else if (conv4 != 0x04030201L)
- return FALSE;
+ return (u2_pt) c4u4(buf);
+ default:
+ xxerr("WARNING: typeconv.c(cnu2) illegal count\n");
+ return 0;
}
- else
- return FALSE;
- return TRUE;
}
-
-#ifdef DEBUG_TYPECONV
-
-main()
-{
- char *source;
- char target[4];
- u2_t u2;
- u2_t u2a;
- u4_t u4;
- u4_t u4a;
-
- printf("%u\n", typeconv_init(FALSE, FALSE));
- printf("%u\n", typeconv_init(FALSE, TRUE));
- printf("%u\n", typeconv_init(TRUE, FALSE));
- printf("%u\n", typeconv_init(TRUE, TRUE));
-
- typeconv_init(FALSE, FALSE);
- source = "\4\3\2\1";
-
- target[0] = 0;
- target[1] = 0;
- u2 = cnu2(source, 2);
- u2cn(target, u2, 2);
- if (strncmp(source, target, 2))
- printf("oops9\n");
-
- target[0] = 0;
- target[1] = 0;
- u4a = cnu4(source, 2);
- u4cn(target, u4a, 2);
- if (strncmp(source, target, 2))
- printf("oops10\n");
-
- target[0] = 0;
- target[1] = 0;
- target[2] = 0;
- target[3] = 0;
- u2a = cnu2(source, 4);
- u2cn(target, u2a, 4);
- if (strncmp(target, "\4\3\0\0", 4))
- printf("oops11\n");
-
- target[0] = 0;
- target[1] = 0;
- target[2] = 0;
- target[3] = 0;
- u4 = cnu4(source, 4);
- u4cn(target, u4, 4);
- if (strncmp(source, target, 4))
- printf("oops12\n");
-
- printf("%04x %04x %08lx %08lx\n", u2, u2a, u4, u4a);
-
- typeconv_init(FALSE, TRUE);
- source = "\2\1\4\3";
-
- target[0] = 0;
- target[1] = 0;
- u2 = cnu2(source + 2, 2);
- u2cn(target, u2, 2);
- if (strncmp(source + 2, target, 2))
- printf("oops13\n");
-
- target[0] = 0;
- target[1] = 0;
- u4a = cnu4(source + 2, 2);
- u4cn(target, u4a, 2);
- if (strncmp(source + 2, target, 2))
- printf("oops14\n");
-
- target[0] = 0;
- target[1] = 0;
- target[2] = 0;
- target[3] = 0;
- u2a = cnu2(source, 4);
- u2cn(target, u2a, 4);
- if (strncmp(target, "\0\0\4\3", 4))
- printf("oops15\n");
-
- target[0] = 0;
- target[1] = 0;
- target[2] = 0;
- target[3] = 0;
- u4 = cnu4(source, 4);
- u4cn(target, u4, 4);
- if (strncmp(source, target, 4))
- printf("oops16\n");
-
- printf("%04x %04x %08lx %08lx\n", u2, u2a, u4, u4a);
-
- typeconv_init(TRUE, FALSE);
- source = "\3\4\1\2";
-
- target[0] = 0;
- target[1] = 0;
- u2 = cnu2(source, 2);
- u2cn(target, u2, 2);
- if (strncmp(source, target, 2))
- printf("oops5\n");
-
- target[0] = 0;
- target[1] = 0;
- u4a = cnu4(source, 2);
- u4cn(target, u4a, 2);
- if (strncmp(source, target, 2))
- printf("oops6\n");
-
- target[0] = 0;
- target[1] = 0;
- target[2] = 0;
- target[3] = 0;
- u2a = cnu2(source, 4);
- u2cn(target, u2a, 4);
- if (strncmp(target, "\3\4\0\0", 4))
- printf("oops7\n");
-
- target[0] = 0;
- target[1] = 0;
- target[2] = 0;
- target[3] = 0;
- u4 = cnu4(source, 4);
- u4cn(target, u4, 4);
- if (strncmp(source, target, 4))
- printf("oops8\n");
-
- printf("%04x %04x %08lx %08lx\n", u2, u2a, u4, u4a);
-
- typeconv_init(TRUE, TRUE);
- source = "\1\2\3\4";
-
- target[0] = 0;
- target[1] = 0;
- u2 = cnu2(source + 2, 2);
- u2cn(target, u2, 2);
- if (strncmp(source + 2, target, 2))
- printf("oops1\n");
-
- target[0] = 0;
- target[1] = 0;
- u4a = cnu4(source + 2, 2);
- u4cn(target, u4a, 2);
- if (strncmp(source + 2, target, 2))
- printf("oops2\n");
-
- target[0] = 0;
- target[1] = 0;
- target[2] = 0;
- target[3] = 0;
- u2a = cnu2(source, 4);
- u2cn(target, u2a, 4);
- if (strncmp(target, "\0\0\3\4", 4))
- printf("oops3\n");
-
- target[0] = 0;
- target[1] = 0;
- target[2] = 0;
- target[3] = 0;
- u4 = cnu4(source, 4);
- u4cn(target, u4, 4);
- if (strncmp(source, target, 4))
- printf("oops4\n");
-
- printf("%04x %04x %08lx %08lx\n", u2, u2a, u4, u4a);
-}
-
-#endif /* DEBUG_TYPECONV */
diff --git a/ld/typeconv.c.old b/ld/typeconv.c.old
new file mode 100644
index 0000000..82dafdd
--- /dev/null
+++ b/ld/typeconv.c.old
@@ -0,0 +1,536 @@
+/* typeconv.c - convert between char arrays and unsigneds */
+
+/* Copyright (C) 1994 Bruce Evans */
+
+/*
+ c2u2(): 2 byte array to 2 byte unsigned
+ c4u4(): 4 byte array to 4 byte unsigned
+ cnu2(): n byte array to 2 byte unsigned
+ cnu4(): n byte array to 4 byte unsigned
+ u2c2(): 2 byte unsigned to 2 byte array
+ u2cn(): 2 byte unsigned to n byte array
+ u4c4(): 4 byte unsigned to 4 byte array
+ u4cn(): 4 byte unsigned to n byte array
+ typeconv_init: (re)initialise for given byte order.
+ Default is no swapping, but the initialisation should be done
+ anyway to provide some validity checks (returns FALSE if error).
+
+ Not provided:
+ c2u4(), c4u2(), u2c4(), u4c2().
+ Each of these is best done by truncating or extending a return value
+ or argument to the appropiate fixed-count function.
+ c4u2() has too many cases to do in-line conveniently, and the others
+ are hardly more efficient when done in-line.
+
+ 4 byte orderings for both char arrays and unsigneds are supported:
+ 0123 - little-endian
+ 3210 - big-endian
+ 2301 - little-endian with long words big-endian (pdp11)
+ 1032 - big-endian with long words little_endian (who knows?)
+
+ The unsigned's byte order is that of the machine on which these
+ routines are running.
+ It is determined at run time initialisation since the compiler/
+ preprocessor is too dumb to tell us at compile time.
+*/
+
+#include "const.h"
+#include "type.h"
+#include "globvar.h"
+
+FORWARD u2_pt c2u2_00 P((char *buf));
+FORWARD u4_pt c4u4_00 P((char *buf));
+FORWARD u2_pt c2u2_ss P((char *buf));
+FORWARD u4_pt c4u4_ss P((char *buf));
+FORWARD u4_pt c4u4_s0 P((char *buf));
+FORWARD u4_pt c4u4_0s P((char *buf));
+FORWARD void u2c2_00 P((char *buf, u2_pt offset));
+FORWARD void u4c4_00 P((char *buf, u4_t offset));
+FORWARD void u2c2_ss P((char *buf, u2_pt offset));
+FORWARD void u4c4_ss P((char *buf, u4_t offset));
+FORWARD void u4c4_s0 P((char *buf, u4_t offset));
+FORWARD void u4c4_0s P((char *buf, u4_t offset));
+
+PRIVATE u2_pt (*pc2u2) P((char *buf)) = c2u2_00;
+PRIVATE u4_pt (*pc4u4) P((char *buf)) = c4u4_00;
+PRIVATE void (*pu2c2) P((char *buf, u2_pt offset)) = u2c2_00;
+PRIVATE void (*pu4c4) P((char *buf, u4_t offset)) = u4c4_00;
+
+/* === char arrays to unsigneds === */
+
+/* no bytes swapped, longwinded to avoid alignment problems */
+
+PRIVATE u2_pt c2u2_00(buf)
+register char *buf;
+{
+ u2_t offset;
+
+ ((char *) &offset)[0] = buf[0];
+ ((char *) &offset)[1] = buf[1];
+ return offset;
+}
+
+PRIVATE u4_pt c4u4_00(buf)
+register char *buf;
+{
+ u4_t offset;
+
+ ((char *) &offset)[0] = buf[0];
+ ((char *) &offset)[1] = buf[1];
+ ((char *) &offset)[2] = buf[2];
+ ((char *) &offset)[3] = buf[3];
+ return offset;
+}
+
+/* straight swapping for little-endian to big-endian and vice versa */
+
+PRIVATE u2_pt c2u2_ss(buf)
+register char *buf;
+{
+ u2_t offset;
+
+ ((char *) &offset)[0] = buf[1];
+ ((char *) &offset)[1] = buf[0];
+ return offset;
+}
+
+PRIVATE u4_pt c4u4_ss(buf)
+register char *buf;
+{
+ u4_t offset;
+
+ ((char *) &offset)[0] = buf[3];
+ ((char *) &offset)[1] = buf[2];
+ ((char *) &offset)[2] = buf[1];
+ ((char *) &offset)[3] = buf[0];
+ return offset;
+}
+
+/* wierd swapping for different-endian u2's, same-endian u4's */
+
+PRIVATE u4_pt c4u4_s0(buf)
+register char *buf;
+{
+ u4_t offset;
+
+ ((char *) &offset)[0] = buf[1];
+ ((char *) &offset)[1] = buf[0];
+ ((char *) &offset)[2] = buf[3];
+ ((char *) &offset)[3] = buf[2];
+ return offset;
+}
+
+/* very wierd swapping for same-endian u2's, different-endian u4's */
+
+PRIVATE u4_pt c4u4_0s(buf)
+register char *buf;
+{
+ u4_t offset;
+
+ ((char *) &offset)[0] = buf[2];
+ ((char *) &offset)[1] = buf[3];
+ ((char *) &offset)[2] = buf[0];
+ ((char *) &offset)[3] = buf[1];
+ return offset;
+}
+
+/* === entry points === */
+
+PUBLIC u2_pt c2u2(buf)
+char *buf;
+{
+ return (*pc2u2) (buf);
+}
+
+PUBLIC u4_t c4u4(buf)
+char *buf;
+{
+ return (*pc4u4) (buf);
+}
+
+PUBLIC u2_pt cnu2(buf, count)
+char *buf;
+unsigned count;
+{
+ switch (count)
+ {
+ case 1:
+ return buf[0] & 0xFF;
+ case 2:
+ return (*pc2u2) (buf);
+ case 4:
+ return (u2_pt) (*pc4u4) (buf);
+ default:
+ return 0;
+ }
+}
+
+PUBLIC u4_t cnu4(buf, count)
+char *buf;
+unsigned count;
+{
+ switch (count)
+ {
+ case 1:
+ return buf[0] & 0xFF;
+ case 2:
+ return (*pc2u2) (buf);
+ case 4:
+ return (*pc4u4) (buf);
+ default:
+ return 0;
+ }
+}
+
+/* === unsigneds to char arrays === */
+
+/* no bytes swapped, longwinded to avoid alignment problems */
+
+PRIVATE void u2c2_00(buf, offset)
+register char *buf;
+u2_pt offset;
+{
+
+ buf[0] = ((char *) &offset)[0];
+ buf[1] = ((char *) &offset)[1];
+}
+
+PRIVATE void u4c4_00(buf, offset)
+register char *buf;
+u4_t offset;
+{
+ buf[0] = ((char *) &offset)[0];
+ buf[1] = ((char *) &offset)[1];
+ buf[2] = ((char *) &offset)[2];
+ buf[3] = ((char *) &offset)[3];
+}
+
+/* straight swapping for little-endian to big-endian and vice versa */
+
+PRIVATE void u2c2_ss(buf, offset)
+register char *buf;
+u2_pt offset;
+{
+ u2_t offset2;
+
+ offset2 = offset;
+ buf[0] = ((char *) &offset2)[1];
+ buf[1] = ((char *) &offset2)[0];
+}
+
+PRIVATE void u4c4_ss(buf, offset)
+register char *buf;
+u4_t offset;
+{
+ buf[0] = ((char *) &offset)[3];
+ buf[1] = ((char *) &offset)[2];
+ buf[2] = ((char *) &offset)[1];
+ buf[3] = ((char *) &offset)[0];
+}
+
+/* wierd swapping for different-endian u2's, same-endian u4's */
+
+PRIVATE void u4c4_s0(buf, offset)
+register char *buf;
+u4_t offset;
+{
+ buf[0] = ((char *) &offset)[1];
+ buf[1] = ((char *) &offset)[0];
+ buf[2] = ((char *) &offset)[3];
+ buf[3] = ((char *) &offset)[2];
+}
+
+/* very wierd swapping for same-endian u2's, different-endian u4's */
+
+PRIVATE void u4c4_0s(buf, offset)
+register char *buf;
+u4_t offset;
+{
+ buf[0] = ((char *) &offset)[2];
+ buf[1] = ((char *) &offset)[3];
+ buf[2] = ((char *) &offset)[0];
+ buf[3] = ((char *) &offset)[1];
+}
+
+/* === entry points === */
+
+PUBLIC void u2c2(buf, offset)
+register char *buf;
+u2_pt offset;
+{
+ (*pu2c2) (buf, offset);
+}
+
+PUBLIC void u4c4(buf, offset)
+register char *buf;
+u4_t offset;
+{
+ (*pu4c4) (buf, offset);
+}
+
+PUBLIC void u2cn(buf, offset, count)
+register char *buf;
+u2_pt offset;
+unsigned count;
+{
+ switch (count)
+ {
+ case 1:
+ buf[0] = (char) offset;
+ return;
+ case 2:
+ (*pu2c2) (buf, offset);
+ return;
+ case 4:
+ (*pu4c4) (buf, (u4_t) offset);
+ return;
+ }
+}
+
+PUBLIC void u4cn(buf, offset, count)
+register char *buf;
+u4_t offset;
+unsigned count;
+{
+ switch (count)
+ {
+ case 1:
+ buf[0] = (char) offset;
+ return;
+ case 2:
+ (*pu2c2) (buf, (u2_pt) (u2_t) offset);
+ return;
+ case 4:
+ (*pu4c4) (buf, offset);
+ return;
+ }
+}
+
+/* initialise type conversion, return FALSE if it cannot be handled */
+
+PUBLIC bool_pt typeconv_init(big_endian, long_big_endian)
+bool_pt big_endian;
+bool_pt long_big_endian;
+{
+ u2_pt conv2;
+ u4_pt conv4;
+ char *conv2ptr;
+ char *conv4ptr;
+
+ if (sizeof(u2_t) != 2 || sizeof(u4_t) != 4)
+ /* dumb preprocessor's don't accept sizeof in #if expressions */
+ return FALSE;
+
+ if (big_endian)
+ {
+ conv2ptr = (conv4ptr = "\1\2\3\4") + 2;
+ if (!long_big_endian)
+ conv4ptr = "\3\4\1\2";
+ }
+ else
+ {
+ conv2ptr = conv4ptr = "\4\3\2\1";
+ if (long_big_endian)
+ conv4ptr = "\2\1\4\3";
+ }
+ conv2 = c2u2_00(conv2ptr);
+ conv4 = c4u4_00(conv4ptr);
+ if (conv2 == 0x0304)
+ {
+ pc2u2 = c2u2_00;
+ pc4u4 = c4u4_00;
+ pu2c2 = u2c2_00;
+ pu4c4 = u4c4_00;
+ if (conv4 == 0x03040102L)
+ {
+ pc4u4 = c4u4_0s;
+ pu4c4 = u4c4_0s;
+ }
+ else if (conv4 != 0x01020304L)
+ return FALSE;
+ }
+ else if (conv2 == 0x0403)
+ {
+ pc2u2 = c2u2_ss;
+ pc4u4 = c4u4_ss;
+ pu2c2 = u2c2_ss;
+ pu4c4 = u4c4_ss;
+ if (conv4 == 0x02010403L)
+ {
+ pc4u4 = c4u4_s0;
+ pu4c4 = u4c4_s0;
+ }
+ else if (conv4 != 0x04030201L)
+ return FALSE;
+ }
+ else
+ return FALSE;
+ return TRUE;
+}
+
+#ifdef DEBUG_TYPECONV
+
+main()
+{
+ char *source;
+ char target[4];
+ u2_t u2;
+ u2_t u2a;
+ u4_t u4;
+ u4_t u4a;
+
+ printf("%u\n", typeconv_init(FALSE, FALSE));
+ printf("%u\n", typeconv_init(FALSE, TRUE));
+ printf("%u\n", typeconv_init(TRUE, FALSE));
+ printf("%u\n", typeconv_init(TRUE, TRUE));
+
+ typeconv_init(FALSE, FALSE);
+ source = "\4\3\2\1";
+
+ target[0] = 0;
+ target[1] = 0;
+ u2 = cnu2(source, 2);
+ u2cn(target, u2, 2);
+ if (strncmp(source, target, 2))
+ printf("oops9\n");
+
+ target[0] = 0;
+ target[1] = 0;
+ u4a = cnu4(source, 2);
+ u4cn(target, u4a, 2);
+ if (strncmp(source, target, 2))
+ printf("oops10\n");
+
+ target[0] = 0;
+ target[1] = 0;
+ target[2] = 0;
+ target[3] = 0;
+ u2a = cnu2(source, 4);
+ u2cn(target, u2a, 4);
+ if (strncmp(target, "\4\3\0\0", 4))
+ printf("oops11\n");
+
+ target[0] = 0;
+ target[1] = 0;
+ target[2] = 0;
+ target[3] = 0;
+ u4 = cnu4(source, 4);
+ u4cn(target, u4, 4);
+ if (strncmp(source, target, 4))
+ printf("oops12\n");
+
+ printf("%04x %04x %08lx %08lx\n", u2, u2a, u4, u4a);
+
+ typeconv_init(FALSE, TRUE);
+ source = "\2\1\4\3";
+
+ target[0] = 0;
+ target[1] = 0;
+ u2 = cnu2(source + 2, 2);
+ u2cn(target, u2, 2);
+ if (strncmp(source + 2, target, 2))
+ printf("oops13\n");
+
+ target[0] = 0;
+ target[1] = 0;
+ u4a = cnu4(source + 2, 2);
+ u4cn(target, u4a, 2);
+ if (strncmp(source + 2, target, 2))
+ printf("oops14\n");
+
+ target[0] = 0;
+ target[1] = 0;
+ target[2] = 0;
+ target[3] = 0;
+ u2a = cnu2(source, 4);
+ u2cn(target, u2a, 4);
+ if (strncmp(target, "\0\0\4\3", 4))
+ printf("oops15\n");
+
+ target[0] = 0;
+ target[1] = 0;
+ target[2] = 0;
+ target[3] = 0;
+ u4 = cnu4(source, 4);
+ u4cn(target, u4, 4);
+ if (strncmp(source, target, 4))
+ printf("oops16\n");
+
+ printf("%04x %04x %08lx %08lx\n", u2, u2a, u4, u4a);
+
+ typeconv_init(TRUE, FALSE);
+ source = "\3\4\1\2";
+
+ target[0] = 0;
+ target[1] = 0;
+ u2 = cnu2(source, 2);
+ u2cn(target, u2, 2);
+ if (strncmp(source, target, 2))
+ printf("oops5\n");
+
+ target[0] = 0;
+ target[1] = 0;
+ u4a = cnu4(source, 2);
+ u4cn(target, u4a, 2);
+ if (strncmp(source, target, 2))
+ printf("oops6\n");
+
+ target[0] = 0;
+ target[1] = 0;
+ target[2] = 0;
+ target[3] = 0;
+ u2a = cnu2(source, 4);
+ u2cn(target, u2a, 4);
+ if (strncmp(target, "\3\4\0\0", 4))
+ printf("oops7\n");
+
+ target[0] = 0;
+ target[1] = 0;
+ target[2] = 0;
+ target[3] = 0;
+ u4 = cnu4(source, 4);
+ u4cn(target, u4, 4);
+ if (strncmp(source, target, 4))
+ printf("oops8\n");
+
+ printf("%04x %04x %08lx %08lx\n", u2, u2a, u4, u4a);
+
+ typeconv_init(TRUE, TRUE);
+ source = "\1\2\3\4";
+
+ target[0] = 0;
+ target[1] = 0;
+ u2 = cnu2(source + 2, 2);
+ u2cn(target, u2, 2);
+ if (strncmp(source + 2, target, 2))
+ printf("oops1\n");
+
+ target[0] = 0;
+ target[1] = 0;
+ u4a = cnu4(source + 2, 2);
+ u4cn(target, u4a, 2);
+ if (strncmp(source + 2, target, 2))
+ printf("oops2\n");
+
+ target[0] = 0;
+ target[1] = 0;
+ target[2] = 0;
+ target[3] = 0;
+ u2a = cnu2(source, 4);
+ u2cn(target, u2a, 4);
+ if (strncmp(target, "\0\0\3\4", 4))
+ printf("oops3\n");
+
+ target[0] = 0;
+ target[1] = 0;
+ target[2] = 0;
+ target[3] = 0;
+ u4 = cnu4(source, 4);
+ u4cn(target, u4, 4);
+ if (strncmp(source, target, 4))
+ printf("oops4\n");
+
+ printf("%04x %04x %08lx %08lx\n", u2, u2a, u4, u4a);
+}
+
+#endif /* DEBUG_TYPECONV */
diff --git a/ld/writebin.c b/ld/writebin.c
index a001b5d..3b31649 100644
--- a/ld/writebin.c
+++ b/ld/writebin.c
@@ -4,8 +4,10 @@
/* Copyright (C) 1994 Bruce Evans */
#ifndef NO_AOUT
+#ifndef A_OUT_INCL
#define A_OUT_INCL <a.out.h>
#endif
+#endif
#include "syshead.h"
#include "bindef.h"
@@ -43,7 +45,9 @@
# define HEADERLEN (A_MINHDR)
# endif
# endif
-# define FILEHEADERLENGTH (headerless?0:HEADERLEN)
+# ifndef FILEHEADERLENGTH
+# define FILEHEADERLENGTH (headerless?0:HEADERLEN)
+# endif
#endif
#define DPSEG 2
@@ -119,8 +123,11 @@ FORWARD void writeheader P((void));
FORWARD void writenulls P((bin_off_t count));
/* write binary file */
+#ifndef FUNCNAME
+#define FUNCNAME writebin
+#endif
-PUBLIC void writebin(outfilename, argsepid, argbits32, argstripflag, arguzp)
+PUBLIC void FUNCNAME(outfilename, argsepid, argbits32, argstripflag, arguzp)
char *outfilename;
bool_pt argsepid;
bool_pt argbits32;
@@ -422,11 +429,11 @@ bool_pt arguzp;
extsym.n_was_sclass = C_EXT;
else
extsym.n_was_sclass = C_STAT;
- if (!(flags & I_MASK) ||
+ if (!(flags & I_MASK) || (
#ifdef REL_OUTPUT
!reloc_output &&
#endif
- flags & C_MASK)
+ (flags & C_MASK)))
switch (flags & (A_MASK | SEGM_MASK))
{
case 0:
@@ -485,14 +492,17 @@ bool_pt arguzp;
memsizeof(struct exec, a_syms));
writeout(buf4, memsizeof(struct exec, a_syms));
#ifdef REL_OUTPUT
- seekout((unsigned long) offsetof(struct exec, a_trsize));
- u4cn(buf4, (u4_t) ntreloc * RELOC_INFO_SIZE,
- memsizeof(struct exec, a_trsize));
- writeout(buf4, memsizeof(struct exec, a_trsize));
- seekout((unsigned long) offsetof(struct exec, a_drsize));
- u4cn(buf4, (u4_t) ndreloc * RELOC_INFO_SIZE,
- memsizeof(struct exec, a_drsize));
- writeout(buf4, memsizeof(struct exec, a_drsize));
+ if( FILEHEADERLENGTH >= offsetof(struct exec, a_trsize)+8)
+ {
+ seekout((unsigned long) offsetof(struct exec, a_trsize));
+ u4cn(buf4, (u4_t) ntreloc * RELOC_INFO_SIZE,
+ memsizeof(struct exec, a_trsize));
+ writeout(buf4, memsizeof(struct exec, a_trsize));
+ seekout((unsigned long) offsetof(struct exec, a_drsize));
+ u4cn(buf4, (u4_t) ndreloc * RELOC_INFO_SIZE,
+ memsizeof(struct exec, a_drsize));
+ writeout(buf4, memsizeof(struct exec, a_drsize));
+ }
#endif
}
#endif /* MINIX */
diff --git a/ld/writerel.c b/ld/writerel.c
new file mode 100644
index 0000000..a0294f5
--- /dev/null
+++ b/ld/writerel.c
@@ -0,0 +1,22 @@
+/*
+ * This uses a special version of writebin for bug compatibility with
+ * the old bin86 package.
+ *
+ * This _should_ be replaced by a function that writes out a as86 object
+ * but then it would completely **** up dosemu compiles.
+ *
+ * NOTE: A some time I intend to replace this with a routine that generates
+ * an as86 object file.
+ */
+
+#ifdef BUGCOMPAT
+#define A_OUT_INCL "rel_aout.h"
+#define BSD_A_OUT 1
+#define FILEHEADERLENGTH 32
+#define ELF_SYMS 0
+
+#define FUNCNAME write_rel
+#undef NO_AOUT
+
+#include "writebin.c"
+#endif
diff --git a/ld/x86_aout.h b/ld/x86_aout.h
index bd58346..af2c537 100644
--- a/ld/x86_aout.h
+++ b/ld/x86_aout.h
@@ -8,25 +8,33 @@
#ifndef __AOUT_H
#define __AOUT_H
+/* If the host isn't an x86 all bets are off, use chars. */
+#if defined(i386) || defined(__BCC__)
+typedef long Long;
+#define __OUT_OK 1
+#else
+typedef char Long[4];
+#endif
+
struct exec { /* a.out header */
unsigned char a_magic[2]; /* magic number */
unsigned char a_flags; /* flags, see below */
unsigned char a_cpu; /* cpu id */
unsigned char a_hdrlen; /* length of header */
unsigned char a_unused; /* reserved for future use */
- unsigned short a_version; /* version stamp (not used at present) */
- long a_text; /* size of text segement in bytes */
- long a_data; /* size of data segment in bytes */
- long a_bss; /* size of bss segment in bytes */
- long a_entry; /* entry point */
- long a_total; /* total memory allocated */
- long a_syms; /* size of symbol table */
+ unsigned char a_version[2]; /* version stamp (not used at present) */
+ Long a_text; /* size of text segement in bytes */
+ Long a_data; /* size of data segment in bytes */
+ Long a_bss; /* size of bss segment in bytes */
+ Long a_entry; /* entry point */
+ Long a_total; /* total memory allocated */
+ Long a_syms; /* size of symbol table */
/* SHORT FORM ENDS HERE */
- long a_trsize; /* text relocation size */
- long a_drsize; /* data relocation size */
- long a_tbase; /* text relocation base */
- long a_dbase; /* data relocation base */
+ Long a_trsize; /* text relocation size */
+ Long a_drsize; /* data relocation size */
+ Long a_tbase; /* text relocation base */
+ Long a_dbase; /* data relocation base */
};
#define A_MAGIC0 (unsigned char) 0x01
@@ -34,12 +42,12 @@ struct exec { /* a.out header */
#define BADMAG(X) ((X).a_magic[0] != A_MAGIC0 ||(X).a_magic[1] != A_MAGIC1)
/* CPU Id of TARGET machine (byte order coded in low order two bits) */
-#define A_NONE 0x00 /* unknown */
-#define A_I8086 0x04 /* intel i8086/8088 */
-#define A_M68K 0x0B /* motorola m68000 */
-#define A_NS16K 0x0C /* national semiconductor 16032 */
+#define A_NONE 0x00 /* unknown */
+#define A_I8086 0x04 /* intel i8086/8088 */
+#define A_M68K 0x0B /* motorola m68000 */
+#define A_NS16K 0x0C /* national semiconductor 16032 */
#define A_I80386 0x10 /* intel i80386 */
-#define A_SPARC 0x17 /* Sun SPARC */
+#define A_SPARC 0x17 /* Sun SPARC */
#define A_BLR(cputype) ((cputype&0x01)!=0) /* TRUE if bytes left-to-right */
#define A_WLR(cputype) ((cputype&0x02)!=0) /* TRUE if words left-to-right */
@@ -56,15 +64,17 @@ struct exec { /* a.out header */
/* Offsets of various things. */
#define A_MINHDR 32
#define A_TEXTPOS(X) ((long)(X).a_hdrlen)
-#define A_DATAPOS(X) (A_TEXTPOS(X) + (X).a_text)
#define A_HASRELS(X) ((X).a_hdrlen > (unsigned char) A_MINHDR)
#define A_HASEXT(X) ((X).a_hdrlen > (unsigned char) (A_MINHDR + 8))
#define A_HASLNS(X) ((X).a_hdrlen > (unsigned char) (A_MINHDR + 16))
#define A_HASTOFF(X) ((X).a_hdrlen > (unsigned char) (A_MINHDR + 24))
+#ifdef __OUT_OK
+#define A_DATAPOS(X) (A_TEXTPOS(X) + (X).a_text)
#define A_TRELPOS(X) (A_DATAPOS(X) + (X).a_data)
#define A_DRELPOS(X) (A_TRELPOS(X) + (X).a_trsize)
#define A_SYMPOS(X) (A_TRELPOS(X) + (A_HASRELS(X) ? \
((X).a_trsize + (X).a_drsize) : 0))
+#endif
struct reloc {
long r_vaddr; /* virtual address of reference */
diff --git a/libc/Config_sh b/libc/Config_sh
index 6c93784..4beff3e 100644
--- a/libc/Config_sh
+++ b/libc/Config_sh
@@ -30,7 +30,7 @@ main()
CHANGED=0
RUNNING=1
- [ "$DIST" != "" ] && {
+ [ "$DIST" != "" -o ! -t 1 -o ! -t 0 ] && {
RUNNING=0
echo 'Using default configuration'
}
diff --git a/libc/Makefile b/libc/Makefile
index 83aded9..593eaab 100644
--- a/libc/Makefile
+++ b/libc/Makefile
@@ -10,8 +10,8 @@ TOP=$(TOPDIR)/libc
endif
VERMAJOR=0
-VERMINOR=0
-VERPATCH=11
+VERMINOR=12
+VERPATCH=0
VER=$(VERMAJOR).$(VERMINOR).$(VERPATCH)
CC=bcc
diff --git a/libc/bcc/Makefile b/libc/bcc/Makefile
index f4cce3d..9f0627a 100644
--- a/libc/bcc/Makefile
+++ b/libc/bcc/Makefile
@@ -50,34 +50,29 @@ CFLAGS=$(ARCH) $(CCFLAGS) $(DEFS)
ifneq ($(OBJ),)
all: $(LIBC)
- @:
+ @$(RM) $(OBJ)
$(LIBC): $(LIBC)($(OBJ))
$(LIBC)($(IOBJ)): $(ISRC)
$(CC) $(CFLAGS) -DL_$* $< -c -o $*.o
$(AR) $(ARFLAGS) $@ $*.o
- $(RM) $*.o
$(LIBC)($(LOBJ)): $(LSRC)
$(CC) $(CFLAGS) -DL_$* $< -c -o $*.o
$(AR) $(ARFLAGS) $@ $*.o
- $(RM) $*.o
$(LIBC)($(AOBJ)): $(ASRC)
$(CC) $(CFLAGS) -DL_$* $< -c -o $*.o
$(AR) $(ARFLAGS) $@ $*.o
- $(RM) $*.o
$(LIBC)($(ROBJ)): $(RSRC)
$(CC) $(CFLAGS) -DL_$* $< -c -o $*.o
$(AR) $(ARFLAGS) $@ $*.o
- $(RM) $*.o
$(LIBC)($(POBJ)): $(PSRC)
$(CC) $(CFLAGS) -DL_$* $< -c -o $*.o
$(AR) $(ARFLAGS) $@ $*.o
- $(RM) $*.o
else
all:
@:
diff --git a/libc/bios/Makefile b/libc/bios/Makefile
index 5fcc964..57128e0 100644
--- a/libc/bios/Makefile
+++ b/libc/bios/Makefile
@@ -15,17 +15,15 @@ OBJ=$(AOBJ) $(BOBJ)
CFLAGS=$(ARCH) $(CCFLAGS) $(DEFS)
all: $(LIBC)($(OBJ))
- @:
+ @$(RM) $(OBJ)
$(LIBC)($(AOBJ)): $(ASRC)
$(CC) $(CFLAGS) -DL_$* $< -c -o $*.o
$(AR) $(ARFLAGS) $@ $*.o
- $(RM) $*.o
$(LIBC)($(BOBJ)): $(BSRC)
$(CC) $(CFLAGS) -DL_$* $< -c -o $*.o
$(AR) $(ARFLAGS) $@ $*.o
- $(RM) $*.o
else
all:
@:
diff --git a/libc/error/Makefile b/libc/error/Makefile
index ae3d1c0..8ec26dc 100644
--- a/libc/error/Makefile
+++ b/libc/error/Makefile
@@ -8,7 +8,7 @@ ifeq ($(LIB_OS),ELKS)
OBJ=error.o sys_errlist.o perror.o sys_siglist.o __assert.o
all: $(LIBC)($(OBJ))
- @:
+ @$(RM) $(OBJ)
else
all:
@:
diff --git a/libc/getent/Makefile b/libc/getent/Makefile
index 9321ced..d2623bc 100644
--- a/libc/getent/Makefile
+++ b/libc/getent/Makefile
@@ -22,7 +22,7 @@ ifeq ($(LIB_OS),ELKS)
OBJ=$(POBJ) $(GOBJ) $(UOBJ)
all: $(LIBC)($(OBJ))
- @:
+ @$(RM) $(OBJ)
$(LIBC)($(GOBJ)): config-grp.h
diff --git a/libc/gtermcap/Makefile b/libc/gtermcap/Makefile
index 44e21da..51eb1f3 100644
--- a/libc/gtermcap/Makefile
+++ b/libc/gtermcap/Makefile
@@ -8,7 +8,7 @@ ifeq ($(LIB_OS),ELKS)
OBJ=termcap.o tparam.o
all: $(LIBC)($(OBJ))
- @:
+ @$(RM) $(OBJ)
else
all:
@:
diff --git a/libc/i386fp/Makefile b/libc/i386fp/Makefile
index 55d06da..46c28a9 100644
--- a/libc/i386fp/Makefile
+++ b/libc/i386fp/Makefile
@@ -24,7 +24,7 @@ CFLAGS=$(ARCH) $(CCFLAGS) $(DEFS)
ifeq ($(LIB_CPU),i386)
all: $(LIBC)($(FPOBJ))
- rm -f $(JUNK)
+ rm -f $(JUNK) $(FPOBJ)
else
all:
@:
diff --git a/libc/i386sys/Makefile b/libc/i386sys/Makefile
index ef01ac9..5110871 100644
--- a/libc/i386sys/Makefile
+++ b/libc/i386sys/Makefile
@@ -19,7 +19,7 @@ SYSCALLS=syscalls
CFLAGS=$(ARCH) $(CCFLAGS) $(DEFS)
all: $(SYSCALLS) $(LIBC)($(OBJ))
- @:
+ @$(RM) $(OBJ)
syscalls: syscall.mak
$(MAKE) -f syscall.mak LIBC="$(LIBC)" CFLAGS="$(CFLAGS)"
@@ -30,17 +30,14 @@ syscall.mak: mksyscall syscall.dat
$(LIBC)($(LOBJ)): $(LSRC)
$(CC) $(CFLAGS) -DL_$* $< -c -o $*.o
$(AR) $(ARFLAGS) $@ $*.o
- $(RM) $*.o
$(LIBC)($(DOBJ)): $(DSRC)
$(CC) $(CFLAGS) -DL_$* $< -c -o $*.o
$(AR) $(ARFLAGS) $@ $*.o
- $(RM) $*.o
$(LIBC)($(EOBJ)): $(ESRC)
$(CC) $(CFLAGS) -DL_$* $< -c -o $*.o
$(AR) $(ARFLAGS) $@ $*.o
- $(RM) $*.o
else
all:
@:
diff --git a/libc/i386sys/mksyscall b/libc/i386sys/mksyscall
index d9b7f3a..f3b5a00 100644
--- a/libc/i386sys/mksyscall
+++ b/libc/i386sys/mksyscall
@@ -132,12 +132,11 @@ cat >> syscall.mak <<\!
CFLAGS=$(ARCH) $(CCFLAGS) $(DEFS)
all: $(LIBC)($(OBJ))
- @:
+ @$(RM) $(OBJ)
$(LIBC)($(OBJ)): syscall.dat
$(CC) $(CFLAGS) -DL_$* syscall.c -c -o $*.o
$(AR) $(ARFLAGS) $@ $*.o
- $(RM) $*.o
!
exit $?
diff --git a/libc/malloc1/Makefile b/libc/malloc1/Makefile
index a4107b8..e762582 100644
--- a/libc/malloc1/Makefile
+++ b/libc/malloc1/Makefile
@@ -8,12 +8,11 @@ AOBJ=malloc.o alloca.o free.o calloc.o realloc.o
CFLAGS=$(ARCH) $(CCFLAGS) $(DEFS)
all: $(LIBC)($(AOBJ))
- @:
+ @$(RM) $(OBJ)
$(LIBC)($(AOBJ)): $(ASRC)
$(CC) $(CFLAGS) -DL_$* $< -c -o $*.o
$(AR) $(ARFLAGS) $@ $*.o
- $(RM) $*.o
clean:
rm -f *.o libc.a
diff --git a/libc/malloc2/Makefile b/libc/malloc2/Makefile
index ea944db..edfc8f5 100644
--- a/libc/malloc2/Makefile
+++ b/libc/malloc2/Makefile
@@ -4,7 +4,8 @@ OBJ=malloc.o stack.o
CFLAGS=$(ARCH) $(CCFLAGS) $(DEFS)
all: $(LIBC)($(OBJ))
- @:
+ @$(RM) $(OBJ)
+
clean:
rm -f *.o libc.a
diff --git a/libc/misc/Makefile b/libc/misc/Makefile
index 9bb579c..56fe043 100644
--- a/libc/misc/Makefile
+++ b/libc/misc/Makefile
@@ -29,19 +29,17 @@ endif
CFLAGS=$(ARCH) $(CCFLAGS) $(DEFS)
all: $(LIBC)
- @:
+ @$(RM) $(OBJ)
$(LIBC): $(LIBC)($(OBJ))
$(LIBC)($(MOBJ)): $(MSRC)
$(CC) $(CFLAGS) -DL_$* $< -c -o $*.o
$(AR) $(ARFLAGS) $@ $*.o
- $(RM) $*.o
$(LIBC)($(EOBJ)): $(ESRC)
$(CC) $(CFLAGS) -DL_$* $< -c -o $*.o
$(AR) $(ARFLAGS) $@ $*.o
- $(RM) $*.o
clean:
rm -f *.o libc.a
@@ -49,14 +47,11 @@ clean:
$(LIBC)(strtol.o): strtol.c
$(CC) -c -ansi $(ARCH) $(CCFLAGS) $(DEFS) $*.c
$(AR) $(ARFLAGS) $@ $*.o
- $(RM) $*.o
$(LIBC)(strtod.o): strtod.c
$(CC) -c -ansi $(ARCH) $(CCFLAGS) $(DEFS) $*.c
$(AR) $(ARFLAGS) $@ $*.o
- $(RM) $*.o
$(LIBC)(crypt.o): crypt.c
$(CC) -c -ansi $(ARCH) $(CCFLAGS) $(DEFS) $*.c
$(AR) $(ARFLAGS) $@ $*.o
- $(RM) $*.o
diff --git a/libc/msdos/Makefile b/libc/msdos/Makefile
index 7a5eaa6..d929ee8 100644
--- a/libc/msdos/Makefile
+++ b/libc/msdos/Makefile
@@ -22,19 +22,17 @@ endif
CFLAGS=$(ARCH) $(CCFLAGS) $(DEFS)
all: $(LIBC)
- @:
+ @$(RM) $(OBJ)
$(LIBC): $(LIBC)($(OBJ))
$(LIBC)($(AOBJ)): $(ASRC)
$(CC) $(CFLAGS) -DL_$* $< -c -o $*.o
$(AR) $(ARFLAGS) $@ $*.o
- $(RM) $*.o
$(LIBC)($(BOBJ)): $(BSRC)
$(CC) $(CFLAGS) -DL_$* $< -c -o $*.o
$(AR) $(ARFLAGS) $@ $*.o
- $(RM) $*.o
else
all:
@:
diff --git a/libc/regexp/Makefile b/libc/regexp/Makefile
index 0276aba..c99c22e 100644
--- a/libc/regexp/Makefile
+++ b/libc/regexp/Makefile
@@ -5,7 +5,7 @@ LSRC=regexp.c regsub.c regerror.c
CFLAGS=$(ARCH) $(CCFLAGS) $(DEFS)
all: $(LIBC)
- @:
+ @$(RM) $(OBJ)
$(LIBC): $(LIBC)($(OBJ))
@@ -16,12 +16,10 @@ transfer:
$(LIBC)(regexp.o): regexp.c regexp.h regmagic.h
$(CC) $(CFLAGS) -DL_$* $< -c -o $*.o
$(AR) $(ARFLAGS) $@ $*.o
- $(RM) $*.o
$(LIBC)(regsub.o): regsub.c regexp.h regmagic.h
$(CC) $(CFLAGS) -DL_$* $< -c -o $*.o
$(AR) $(ARFLAGS) $@ $*.o
- $(RM) $*.o
clean:
rm -f libc.a *.o core mon.out timer.t.h dMakefile dtr try timer
diff --git a/libc/stdio2/Makefile b/libc/stdio2/Makefile
index 80f2e3b..0fd8d97 100644
--- a/libc/stdio2/Makefile
+++ b/libc/stdio2/Makefile
@@ -22,24 +22,21 @@ OBJ= $(AOBJ) $(POBJ) $(SOBJ)
CFLAGS=$(ARCH) $(CCFLAGS) $(DEFS)
all: $(LIBC)
- @:
+ @$(RM) $(OBJ)
$(LIBC): $(LIBC)($(OBJ))
$(LIBC)($(AOBJ)): $(ASRC)
$(CC) $(CFLAGS) -DL_$* $< -c -o $*.o
$(AR) $(ARFLAGS) $@ $*.o
- $(RM) $*.o
$(LIBC)($(POBJ)): $(PSRC)
$(CC) $(CFLAGS) -DL_$* $< -c -o $*.o
$(AR) $(ARFLAGS) $@ $*.o
- $(RM) $*.o
$(LIBC)($(SOBJ)): $(SSRC)
$(CC) $(CFLAGS) -DL_$* $< -c -o $*.o
$(AR) $(ARFLAGS) $@ $*.o
- $(RM) $*.o
transfer:
-@rm -f ../include/stdio.h
diff --git a/libc/stdio2/stdio.c b/libc/stdio2/stdio.c
index 156d3e3..210c41f 100644
--- a/libc/stdio2/stdio.c
+++ b/libc/stdio2/stdio.c
@@ -207,7 +207,8 @@ int
fflush(fp)
FILE *fp;
{
- int len, cc;
+ int len, cc, rv=0;
+ char * bstart;
if (fp == NULL) /* On NULL flush the lot. */
{
if (fflush(stdin))
@@ -231,24 +232,29 @@ FILE *fp;
if (len)
{
+ bstart = fp->bufstart;
/*
- * The loop is so we don't get upset by signals
+ * The loop is so we don't get upset by signals or partial writes.
*/
do
{
- cc = write(fp->fd, fp->bufstart, len);
+ cc = write(fp->fd, bstart, len);
+ if( cc > 0 )
+ {
+ bstart+=cc; len-=cc;
+ }
}
- while (cc == -1 && errno == EINTR);
+ while ( cc>0 || (cc == -1 && errno == EINTR));
/*
- * I think the following test is _too_ stringent, but it's not
- * serious If it is found to be a problem then if cc>0 we can do
- * a memcpy to put the buffer in a state for a retry. Or even do
- * the retry ourselves.
+ * If we get here with len!=0 there was an error, exactly what to
+ * do about it is another matter ...
+ *
+ * I'll just clear the buffer.
*/
- if (cc != len)
+ if (len)
{
fp->mode |= __MODE_ERR;
- return EOF;
+ rv = EOF;
}
}
}
@@ -260,7 +266,7 @@ FILE *fp;
len = fp->bufread - fp->bufpos; /* Bytes buffered but unread */
/* If it's a file, make it good */
- if (len > 0 && lseek(fp->fd, -len, 1) < 0)
+ if (len > 0 && lseek(fp->fd, (long)-len, 1) < 0)
{
/* Hummm - Not certain here, I don't think this is reported */
/*
@@ -272,7 +278,7 @@ FILE *fp;
/* All done, no problem */
fp->mode &= (~(__MODE_READING|__MODE_WRITING|__MODE_EOF|__MODE_UNGOT));
fp->bufread = fp->bufwrite = fp->bufpos = fp->bufstart;
- return 0;
+ return rv;
}
#endif
@@ -475,12 +481,21 @@ FILE *fp;
else
/* Too big for the buffer */
{
- put = write(fp->fd, buf, bytes);
- if (put < 0)
+ put = bytes;
+ do
{
- fp->mode |= __MODE_ERR;
- put = 0;
+ len = write(fp->fd, buf, bytes);
+ if( len > 0 )
+ {
+ buf+=len; bytes-=len;
+ }
}
+ while (len > 0 || (len == -1 && errno == EINTR));
+
+ if (len < 0)
+ fp->mode |= __MODE_ERR;
+
+ put -= bytes;
}
return put / size;
@@ -504,8 +519,6 @@ FILE *fp;
long offset;
int ref;
{
- /* Use fflush to sync the pointers */
-
#if 1
/* if __MODE_READING and no ungetc ever done can just move pointer */
/* This needs testing! */
@@ -532,6 +545,8 @@ int ref;
}
#endif
+ /* Use fflush to sync the pointers */
+
if (fflush(fp) == EOF)
return EOF;
if (lseek(fp->fd, offset, ref) < 0)
diff --git a/libc/string/Makefile b/libc/string/Makefile
index 61fad41..0f47b40 100644
--- a/libc/string/Makefile
+++ b/libc/string/Makefile
@@ -13,14 +13,13 @@ OBJ=$(SOBJ) strpbrk.o strsep.o strstr.o strtok.o strcspn.o \
CFLAGS=$(ARCH) $(CCFLAGS) $(DEFS)
all: $(LIBC)
- @:
+ @$(RM) $(OBJ)
$(LIBC): $(LIBC)($(OBJ))
$(LIBC)($(SOBJ)): $(SSRC)
$(CC) $(CFLAGS) -DL_$* $< -c -o $*.o
$(AR) $(ARFLAGS) $@ $*.o
- $(RM) $*.o
transfer:
-@rm -f ../include/string.h
diff --git a/libc/syscall/Makefile b/libc/syscall/Makefile
index fd1b187..a064c3f 100644
--- a/libc/syscall/Makefile
+++ b/libc/syscall/Makefile
@@ -28,7 +28,7 @@ endif
CFLAGS=$(ARCH) $(CCFLAGS) $(DEFS)
all: $(SYSCALLS) $(LIBC)
- @:
+ @$(RM) $(OBJ)
call_i86: syscall.mak
$(MAKE) -f syscall.mak LIBC="$(LIBC)" CFLAGS="$(CFLAGS)"
@@ -41,22 +41,18 @@ $(LIBC): $(LIBC)($(OBJ))
$(LIBC)($(LOBJ)): $(LSRC)
$(CC) $(CFLAGS) -DL_$* $< -c -o $*.o
$(AR) $(ARFLAGS) $@ $*.o
- $(RM) $*.o
$(LIBC)($(DOBJ)): $(DSRC)
$(CC) $(CFLAGS) -DL_$* $< -c -o $*.o
$(AR) $(ARFLAGS) $@ $*.o
- $(RM) $*.o
$(LIBC)($(EOBJ)): $(ESRC)
$(CC) $(CFLAGS) -DL_$* $< -c -o $*.o
$(AR) $(ARFLAGS) $@ $*.o
- $(RM) $*.o
$(LIBC)($(LOBJ0)): $(LSRC0)
$(CC) $(CFLAGS) -DL_$* $< -c -o $*.o
$(AR) $(ARFLAGS) $@ $*.o
- $(RM) $*.o
clean:
rm -f *.o libc.a
diff --git a/libc/syscall/mksyscall b/libc/syscall/mksyscall
index 2005029..f7b91a6 100644
--- a/libc/syscall/mksyscall
+++ b/libc/syscall/mksyscall
@@ -278,12 +278,11 @@ END{
cat >> syscall.mak <<\!
all: $(LIBC)($(OBJ))
- @:
+ @$(RM) $(OBJ)
$(LIBC)($(OBJ)): syscall.dat
$(CC) $(CFLAGS) -DL_$* syscall.c -c -o $*.o
$(AR) $(ARFLAGS) $@ $*.o
- $(RM) $*.o
!
exit $?
diff --git a/libc/termios/Makefile b/libc/termios/Makefile
index cfc3baa..7e87a81 100644
--- a/libc/termios/Makefile
+++ b/libc/termios/Makefile
@@ -13,14 +13,13 @@ OBJ=$(TOBJ) ttyname.o
CFLAGS=$(ARCH) $(CCFLAGS) $(DEFS)
all: $(LIBC)
- @:
+ @$(RM) $(OBJ)
$(LIBC): $(LIBC)($(OBJ))
$(LIBC)($(TOBJ)): $(TSRC)
$(CC) $(CFLAGS) -DL_$* $< -c -o $*.o
$(AR) $(ARFLAGS) $@ $*.o
- $(RM) $*.o
else
all:
@:
diff --git a/libc/time/Makefile b/libc/time/Makefile
index 6e95444..2abb745 100644
--- a/libc/time/Makefile
+++ b/libc/time/Makefile
@@ -7,7 +7,7 @@ OBJ=localtime.o gmtime.o asctime.o ctime.o asc_conv.o tm_conv.o
CFLAGS=$(ARCH) $(CCFLAGS) $(DEFS)
all: $(LIBC)
- @:
+ @$(RM) $(OBJ)
$(LIBC): $(LIBC)($(OBJ))
diff --git a/makefile.in b/makefile.in
index a382e30..423b154 100644
--- a/makefile.in
+++ b/makefile.in
@@ -21,24 +21,34 @@ MAKEC=$(MAKE) -C
MAKEX=
#ifdef __GNUC__
+# unproto is yukky, I've included '-w' in the local makefile.
+
WALL =-Wtraditional -Wshadow -Wid-clash-14 -Wpointer-arith \
-Wcast-qual -Wcast-align -Wconversion -Waggregate-return \
-Wstrict-prototypes -Wmissing-prototypes -Wredundant-decls \
-Wnested-externs -Winline
-# unproto is yukky, I've included '-w' in the local makefile.
WALL =-Wstrict-prototypes
CC =gcc $(GCCFLAG)
+#ifdef __i386__
+CFLAGS =-Wall $(WALL) -O2 -m486 -fno-strength-reduce
+#else
CFLAGS =-Wall $(WALL) -O2 -fno-strength-reduce
+#endf
LDFLAGS =-s
#endif
+#ifndef GNUMAKE
+MAKEC=sh makec
+MAKEX=makec
+#endif
+
#ifdef __minix
# Minix make doesn't understand -C, cc runs out of memory with the headers.
MAKEC=ash makec
MAKEX=makec
-CFLAGS=-O -m -w -DPOSIX_HEADERS_MISSING
+CFLAGS=-O -m -w -DPOSIX_HEADERS_MISSING -DVERY_SMALL_MEMORY
#endif
#ifdef __BCC__
@@ -106,12 +116,12 @@ copt: bindir
as86: bindir
$(MAKEC) as $(MAKEARG) all
- cp -p as/as86 lib/as86
+ cp -p as/as86 bin/as86
cp -p as/as86_encap bin/as86_encap
ld86: bindir
$(MAKEC) ld $(MAKEARG) ld86
- cp -p ld/ld86 lib/ld86
+ cp -p ld/ld86 bin/ld86
elksemu: bindir
$(MAKEC) elksemu $(MAKEARG) elksemu
@@ -120,13 +130,15 @@ elksemu: bindir
install-bcc: bcc unproto copt as86 ld86
install -d $(DISTBIN) $(DISTLIB) $(DISTLIB)/i86
install $(INEXE) bin/bcc $(DISTBIN)/bcc
+ install $(INEXE) bin/as86_encap $(DISTBIN)/as86_encap
+ install $(INEXE) bin/as86 $(DISTBIN)/as86
+ install $(INEXE) bin/ld86 $(DISTBIN)/ld86
install $(INEXE) lib/bcc-cc1 $(DISTLIB)/bcc-cc1
install $(INEXE) lib/unproto $(DISTLIB)/unproto
- install $(INEXE) lib/as86 $(DISTLIB)/as86
- install $(INEXE) bin/as86_encap $(DISTBIN)/as86_encap
- install $(INEXE) lib/ld86 $(DISTLIB)/ld86
install $(INEXE) lib/copt $(DISTLIB)/copt
install $(INDAT) lib/rules.* $(DISTLIB)/i86
+ @test ! -f $(DISTLIB)/as86 || rm -f $(DISTLIB)/as86
+ @test ! -f $(DISTLIB)/ld86 || rm -f $(DISTLIB)/ld86
install-emu: elksemu
install -d $(DIST)/lib
@@ -191,12 +203,20 @@ lib-386: bindir
##############################################################################
-check_config:
+#ifdef GNUMAKE
+
+check_config: $(MAKEX)
$(MAKEC) libc .config.dir
-config:
+config: $(MAKEX)
$(MAKEC) libc config
+#else
+check_config: $(MAKEX) ;
+
+config: ;
+#endif
+
makec:
echo 'cd $$1 ; shift ; make "$$@"' > makec
chmod +x makec
@@ -222,5 +242,6 @@ realclean:
-@for i in $(CLEANLIST) ; do $(MAKEC) $$i $@ ; true ; done
rm -rf bin lib
rm -f include
+ rm -f makec
##############################################################################
diff --git a/man/as86.1 b/man/as86.1
index 8edbdc7..990c263 100644
--- a/man/as86.1
+++ b/man/as86.1
@@ -73,7 +73,9 @@ start with 32-bit code segment, don't warn for any instructions. (not even
486 or 586)
.TP
.B -a
-enable partial compatibility with Minix asld
+enable partial compatibility with Minix asld. This swaps the interpretation
+of round brackets and square brackets as well as making alterations to the
+code generation for 16bit jumps and calls.
.TP
.B -g
only put global symbols in object or symbol file
diff --git a/man/bcc.1 b/man/bcc.1
index 84234e2..9cf4188 100644
--- a/man/bcc.1
+++ b/man/bcc.1
@@ -325,14 +325,11 @@ this path is hardcoded into the C library.
The
.B bcc
-executable itself is in /usr/bin and the
+executable itself,
.B as86
and
.B ld86
-executables can be placed there also, but be aware that some programs
-will require the old operation of the
-.B -r
-argument to ld86 (eg compiling DOSEMU)
+are in /usr/bin.
.SH SEE ALSO
unprotoize(1), as86(1), ld86(1), elksemu(1)
@@ -342,3 +339,8 @@ try it produces a nasty mixture of 8086 and 80386 code that really
upsets the assembler.
The bcc.c compiler driver source is very untidy.
+
+The linker, ld86, produces a broken a.out object file if given one input and
+the
+.B -r
+option this is so it is compatible with pre-dev86 versions.
diff --git a/man/ld86.1 b/man/ld86.1
index de762dd..1349969 100644
--- a/man/ld86.1
+++ b/man/ld86.1
@@ -83,8 +83,9 @@ output file name follows
strip symbols
.TP
.B -r
-Generate a relocatable object from one source object, note this only works
-when creating native (-N) binaries.
+Generate a relocatable object from one source object, if the linker is
+given the -N option also the output format will be the hosts native format
+if possible.
.TP
.B -t
trace modules being looked at on stdout
@@ -102,10 +103,12 @@ The previous versions of the linker could produce an 8086 executable with
segments of a size >64k, now only i386 executables may have segments
this large.
-The output format for the -r option has changed.
-
.SH BUGS
The linker cannot deal with reverse seeks caused by
.B org
instructions in the object file. Unlike previous versions the current one
traps the error rather than trying to fill up the hard disk.
+
+The linker produces a broken a.out object file if given one input and the
+.B -r
+option this is so it is compatible with pre-dev86 versions.
diff --git a/mkcompile b/mkcompile
index 493574e..6adf313 100644
--- a/mkcompile
+++ b/mkcompile
@@ -35,7 +35,7 @@ main() {
ARCH=-Ml
build bcc bcc-cc1 lib "$HDR_CC1" $SRC_CC1
build as as86 bin "$HDR_AS" $SRC_AS
- build ld ld86 lib "$HDR_LD" $SRC_LD
+ build ld ld86 bin "$HDR_LD" $SRC_LD
echo ":exit_now"
}
diff --git a/mkcompile2 b/mkcompile2
index f61be39..87c0df6 100644
--- a/mkcompile2
+++ b/mkcompile2
@@ -35,7 +35,7 @@ main() {
ARCH=-ml
build bcc bcc-cc1 lib "$HDR_CC1" $SRC_CC1
build as as86 bin "$HDR_AS" $SRC_AS
- build ld ld86 lib "$HDR_LD" $SRC_LD
+ build ld ld86 bin "$HDR_LD" $SRC_LD
echo ":exit_now"
}
diff --git a/tests/compr.c b/tests/compr.c
index 8e53443..b52609d 100644
--- a/tests/compr.c
+++ b/tests/compr.c
@@ -22,8 +22,12 @@ FILE * fd;
int * itb;
int size;
-int maxno= 8000;
long cnt=0;
+#ifdef __GNUC__
+int maxno= 16384;
+#else
+int maxno= 8000;
+#endif
long icount = 0;
long ocount = 0;
diff --git a/unproto/unproto.c b/unproto/unproto.c
index f7c03f7..945e066 100644
--- a/unproto/unproto.c
+++ b/unproto/unproto.c
@@ -147,7 +147,11 @@ extern int getopt();
/* Application-specific stuff */
#include "vstring.h"
+#ifdef _AIX
+#include <stdarg.h>
+#else
#include "stdarg.h"
+#endif
#include "token.h"
#include "error.h"
#include "symbol.h"