summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert de Bath <rdebath@poboxes.com>2002-01-12 20:42:42 +0100
committerLubomir Rintel <lkundrak@v3.sk>2013-10-23 23:48:46 +0200
commitd91fa39567f5659e3931cf61517d62fddcd87570 (patch)
tree20583acd4f345a4f5c9a7772870ef972cb8a3b14
parentbff547eabb6678ec8e71ffbcfbf9a4f05c94d949 (diff)
downloaddev86-d91fa39567f5659e3931cf61517d62fddcd87570.tar.gz
Import Dev86src-0.16.1.tar.gzv0.16.1
-rw-r--r--Libc_version2
-rw-r--r--MAGIC23
-rw-r--r--Mk_dist5
-rw-r--r--as/Makefile4
-rw-r--r--as/alloc.c100
-rw-r--r--as/as.c28
-rw-r--r--as/assemble.c2
-rw-r--r--as/const.h119
-rw-r--r--as/error.c102
-rw-r--r--as/errors.c107
-rw-r--r--as/errors.h105
-rw-r--r--as/express.c12
-rw-r--r--as/genbin.c6
-rw-r--r--as/genlist.c57
-rw-r--r--as/genobj.c27
-rw-r--r--as/gensym.c25
-rw-r--r--as/globvar.h4
-rw-r--r--as/keywords.c8
-rw-r--r--as/macro.c44
-rw-r--r--as/mops.c26
-rw-r--r--as/opcode.h2
-rw-r--r--as/pops.c12
-rw-r--r--as/proto.h19
-rw-r--r--as/readsrc.c9
-rw-r--r--as/scan.c4
-rw-r--r--as/scan.h2
-rw-r--r--as/table.c14
-rw-r--r--as/type.h1
-rw-r--r--as/typeconv.c4
-rw-r--r--bcc/bcc.c2179
-rw-r--r--bcc/const.h1
-rw-r--r--bcc/function.c7
-rw-r--r--bcc/gencode.h1
-rwxr-xr-xbcc/idcc328
-rw-r--r--bcc/input.c6
-rw-r--r--bcc/preproc.c29
-rw-r--r--bcc/scan.c20
-rw-r--r--bcc/scan.h3
-rw-r--r--bcc/state.c28
-rw-r--r--bootblocks/Makefile10
-rw-r--r--bootblocks/mbr.s2
-rw-r--r--bootblocks/monitor.h2
-rw-r--r--bootblocks/tarboot.s14
-rw-r--r--later.c38
-rw-r--r--libc/Config.dflt1
-rw-r--r--libc/Makefile2
-rw-r--r--libc/bios/bios.c22
-rw-r--r--libc/bios/cprintf.c132
-rw-r--r--libc/conio/Config1
-rw-r--r--libc/conio/Makefile36
-rw-r--r--libc/conio/conio.c (renamed from libc/msdos/conio.c)28
-rw-r--r--libc/conio/cprintf.c (renamed from bootblocks/cprintf.c)125
-rw-r--r--libc/include/conio.h26
-rw-r--r--libc/syscall/syscall.dev8626
-rw-r--r--libc/syscall/syscall.dev86.old160
-rw-r--r--makefile.in10
-rw-r--r--man/bcc.110
-rw-r--r--mkcompile64
-rw-r--r--mkcompile2103
59 files changed, 1965 insertions, 2322 deletions
diff --git a/Libc_version b/Libc_version
index 04a373e..2a0970c 100644
--- a/Libc_version
+++ b/Libc_version
@@ -1 +1 @@
-0.16.0
+0.16.1
diff --git a/MAGIC b/MAGIC
deleted file mode 100644
index 42710b3..0000000
--- a/MAGIC
+++ /dev/null
@@ -1,23 +0,0 @@
-Useful bits for /etc/magic:
-
-#------------------------------------------------------------------------------
-# Localstuff: file(1) magic for locally observed files
-#
-# $Id: Localstuff,v 1.3 1995/01/21 21:09:00 christos Exp $
-# Add any locally observed files here. Remember:
-# text if readable, executable if runnable binary, data if unreadable.
-#
-0 string \01\03\020\04 Linux-8086 impure executable
->28 long !0 not stripped
-0 string \01\03\040\04 Linux-8086 executable
->28 long !0 not stripped
-#
-0 string \243\206\001\0 Linux-8086 object file
-# There is _no_ difference between 16 and 32 bit .o files that file can see.
-#
-0 string \01\03\020\20 Minix-386 impure executable
->28 long !0 not stripped
-0 string \01\03\040\20 Minix-386 executable
->28 long !0 not stripped
-#
-#------------------------------------------------------------------------------
diff --git a/Mk_dist b/Mk_dist
index 88a372d..aeb87ac 100644
--- a/Mk_dist
+++ b/Mk_dist
@@ -13,9 +13,8 @@ TMPSRC=linux86
ARCDIR="$DIR"/dev86arc
SRCDIRS='bcc unproto as ar ld copt man elksemu dis88 tests libbsd bin86'
-DISTFILES='Libc_version Makefile README COPYING MAGIC Changes Contributors
- mkcompile mkcompile2 later.c GNUmakefile libcompat
- ifdef.c makefile.in Mk_dist'
+DISTFILES='Libc_version Makefile README COPYING Changes Contributors
+ mkcompile GNUmakefile libcompat ifdef.c makefile.in Mk_dist'
TMPDIST=$TMPDIR/$TMPSRC
rm -rf ${TMPDIR}
diff --git a/as/Makefile b/as/Makefile
index bc62091..4dedc8d 100644
--- a/as/Makefile
+++ b/as/Makefile
@@ -4,10 +4,10 @@ LDFLAGS=-s
LIBDIR=/usr/bin
BINDIR=/usr/bin
-OBJS =as.o assemble.o error.o express.o \
+OBJS =as.o assemble.o errors.o express.o \
genbin.o genlist.o genobj.o gensym.o \
keywords.o macro.o mops.o pops.o readsrc.o \
- scan.o table.o typeconv.o
+ scan.o table.o typeconv.o alloc.o
all: as86 as86_encap
diff --git a/as/alloc.c b/as/alloc.c
new file mode 100644
index 0000000..6f64ccc
--- /dev/null
+++ b/as/alloc.c
@@ -0,0 +1,100 @@
+
+#include "syshead.h"
+#include "const.h"
+#include "type.h"
+#include "align.h"
+
+PRIVATE char NOMEMEORY[] = "Cannot allocate sufficient memory";
+
+#ifdef USE_FIXED_HEAP
+PRIVATE char *heapend; /* end of free space for symbol list */
+PRIVATE char *heapptr; /* next free space in symbol list */
+#endif
+
+#ifndef USE_FIXED_HEAP
+PRIVATE char tempbuf[2048];
+#endif
+
+void
+init_heap()
+{
+#ifdef USE_FIXED_HEAP
+#ifndef USERMEM
+#define USERMEM (unsigned) 0xAC00U
+#endif
+
+#ifdef __AS386_16__
+ heapptr = sbrk(0);
+ heapend = ((char*)&argc) - STAKSIZ - 16;
+ brk(heapend);
+ if(sbrk(0) != heapend)
+ as_abort(NOMEMEORY);
+#else
+#ifdef SOS_EDOS
+ heapend = stackreg() - STAKSIZ;
+#else
+ heapptr = malloc(USERMEM);
+ heapend = heapptr + USERMEM;
+ if (heapptr == 0)
+ as_abort(NOMEMEORY);
+#endif
+#endif
+#endif
+}
+
+void * temp_buf()
+{
+#ifdef USE_FIXED_HEAP
+ return heapptr;
+#else
+ return tempbuf;
+#endif
+}
+
+void *
+asalloc(size)
+unsigned int size;
+{
+ void * rv;
+#ifdef USE_FIXED_HEAP
+ align(heapptr);
+ if (heapptr+size < heapend)
+ {
+ rv = heapptr;
+ heapptr += size;
+ }
+ else
+ rv = 0;
+#else
+ rv = malloc(size);
+#endif
+
+ if (rv == 0) as_abort(NOMEMEORY);
+ return rv;
+}
+
+
+void *
+asrealloc(oldptr, size)
+void * oldptr;
+unsigned int size;
+{
+ void * rv;
+#ifdef USE_FIXED_HEAP
+ if (oldptr == 0) return asalloc(size);
+
+ if ((char*)oldptr+size < heapend)
+ {
+ heapptr = oldptr + size;
+ rv = oldptr;
+ }
+ else
+ rv = 0;
+#else
+ rv = realloc(oldptr, size);
+#endif
+
+ if (rv == 0) as_abort(NOMEMEORY);
+ return rv;
+}
+
diff --git a/as/as.c b/as/as.c
index 64f1e42..ef19d2c 100644
--- a/as/as.c
+++ b/as/as.c
@@ -32,30 +32,11 @@ FORWARD void summary P((fd_t fd));
FORWARD void summ_number P((unsigned num));
FORWARD void usage P((void));
-#ifndef USERMEM
-#define USERMEM (sizeof(int) <= 2 ? (unsigned) 0xAC00 : (unsigned) 0x28000L)
-#endif
-
PUBLIC int main(argc, argv)
int argc;
char **argv;
{
-#ifdef __AS386_16__
- heapptr = sbrk(0);
- heapend = ((char*)&argc) - STAKSIZ - 16;
- brk(heapend);
- if(sbrk(0) != heapend)
- as_abort("Cannot allocate memory");
-#else
-#ifdef SOS_EDOS
- heapend = stackreg() - STAKSIZ;
-#else
- heapptr = malloc(USERMEM);
- heapend = heapptr + USERMEM;
- if (heapptr == 0)
- as_abort("cannot allocate memory");
-#endif
-#endif
+ init_heap();
initp1();
initp1p2();
inst_keywords();
@@ -321,9 +302,10 @@ int fd;
PRIVATE void summ_number(num)
unsigned num;
{
- /* format number like line numbers, build it at free spot heapptr */
- *build_number(num, LINUM_LEN, heapptr) = 0;
- writes(heapptr);
+ /* format number like line numbers */
+ char buf[16];
+ *build_number(num, LINUM_LEN, buf) = 0;
+ writes(buf);
}
PRIVATE void usage()
diff --git a/as/assemble.c b/as/assemble.c
index 175d5cc..5af954e 100644
--- a/as/assemble.c
+++ b/as/assemble.c
@@ -38,7 +38,9 @@ PRIVATE pfv rout_table[] =
pfcb,
pfcc,
pfdb,
+#if SIZEOF_OFFSET_T > 2
pfqb,
+#endif
pget,
pglobl,
pident,
diff --git a/as/const.h b/as/const.h
index 25ae996..1b98a8b 100644
--- a/as/const.h
+++ b/as/const.h
@@ -7,14 +7,14 @@
#define S_ALIGNMENT sizeof(long)
#endif
-#include "align.h"
-
/* const.h - constants for assembler */
/* major switches */
+/* #define MC6809 */ /* generate 6809 code */
+#ifndef MC6809
#define I80386 /* generate 80386 code */
-#undef MC6809 /* generate 6809 code */
+#endif
#define MNSIZE /* allow byte size in mnemonic, e.g. "movb" */
#undef SOS_EDOS /* source OS is EDOS */
@@ -215,116 +215,6 @@ enum
COLON
};
-enum
-{
-/* Error codes. */
-
-/* Syntax errors. */
- COMEXP,
- DELEXP,
- FACEXP,
- IREGEXP,
- LABEXP,
- LPEXP,
- OPEXP,
- RBEXP,
- REGEXP,
- RPEXP,
- SPEXP,
-
-/* Expression errors. */
- ABSREQ,
- NONIMPREQ,
- RELBAD,
-
-/* Label errors. */
- ILLAB,
- MACUID,
- MISLAB,
- MNUID,
- REGUID,
- RELAB,
- UNBLAB,
- UNLAB,
- VARLAB,
-
-/* Addressing errors. */
- ABOUNDS,
- DBOUNDS,
- ILLMOD,
- ILLREG,
-
-/* Control structure errors. */
- ELSEBAD,
-#define ELSEIFBAD ELSEBAD
- ENDBBAD,
-#define ENDIFBAD ELSEBAD
- EOFBLOCK,
- EOFIF,
- EOFLC,
- EOFMAC,
- FAILERR,
-
-/* Overflow errors. */
- BLOCKOV,
- BWRAP,
- COUNTOV,
- COUNTUN,
- GETOV,
- IFOV,
-
- LINLONG,
- MACOV,
- OBJSYMOV,
- OWRITE,
- PAROV,
- SYMOV,
- SYMOUTOV,
-
-/* I/O errors. */
- OBJOUT,
-
-/* Miscellaneous errors. */
- AL_AX_EAX_EXP,
- CTLINS,
- FURTHER,
- ILL_IMM_MODE,
- ILL_IND_TO_IND,
- ILL_IND,
- ILL_IND_PTR,
- ILL_SCALE,
- ILL_SECTION,
- ILL_SEG_REG,
- ILL_SOURCE_EA,
- ILL_SIZE,
- IMM_REQ,
- INDEX_REG_EXP,
- IND_REQ,
- MISMATCHED_SIZE,
- NOIMPORT,
- REENTER,
- REL_REQ,
- REPEATED_DISPL,
- SEGREL,
- SEG_REG_REQ,
- SIZE_UNK,
- UNKNOWN_ESCAPE_SEQUENCE,
-
- FP_REG_REQ,
- FP_REG_NOT_ALLOWED,
- ILL_FP_REG,
- ILL_FP_REG_PAIR,
- JUNK_AFTER_OPERANDS,
-
- ALREADY,
- UNSTABLE_LABEL,
-
-/* Warnings. */
-#define MINWARN CPUCLASH
- CPUCLASH,
- SHORTB
-};
-
/* symbol table entry */
/* type entry contains following flags */
@@ -423,3 +313,6 @@ oops - ENTBIT misplaced
#define DPLOC 2
#define STRLOC 1
#define TEXTLOC 0
+
+#include "errors.h"
+
diff --git a/as/error.c b/as/error.c
deleted file mode 100644
index 3088ec4..0000000
--- a/as/error.c
+++ /dev/null
@@ -1,102 +0,0 @@
-/* error.c - error routines for assembler */
-
-#include "syshead.h"
-#include "const.h"
-#include "type.h"
-
-PRIVATE char *errormessage[] =
-{
- "comma expected",
- "delimiter expected",
- "factor expected",
- "index register expected",
- "label expected",
- "left parentheses expected",
- "opcode expected",
- "right bracket expected",
- "register expected",
- "right parentheses expected",
- "space expected",
- "absolute expression required",
- "non-imported expression required",
- "relocation impossible",
- "illegal label",
- "MACRO used as identifier",
- "missing label",
- "opcode used as identifier",
- "register used as identifier",
- "redefined label",
- "unbound label",
- "undefined label",
- "variable used as label",
- "address out of bounds",
- "data out of bounds",
- "illegal address mode",
- "illegal register",
- "no matching IF",
- "no matching BLOCK",
- "end of file in BLOCK",
- "end of file in IF",
- "location counter was undefined at end",
- "end of file in MACRO",
- "user-generated error",
- "BLOCK stack overflow",
- "binary file wrap-around",
- "counter overflow",
- "counter underflow",
- "GET stack overflow",
- "IF stack overflow",
- "line too long",
- "MACRO stack overflow",
- "object symbol table overflow",
- "program overwrite",
- "parameter table overflow",
- "symbol table overflow",
- "output symbol table overflow",
- "error writing object file",
- "al, ax or eax expected",
- "control character in string",
- "futher errors suppressed",
- "illegal immediate mode",
- "illegal indirect to indirect",
- "illegal indirection",
- "illegal indirection from previous 'ptr'",
- "illegal scale",
- "illegal section",
- "illegal segment register",
- "illegal source effective address",
- "illegal size",
- "immediate expression expected",
- "index register expected",
- "indirect expression required",
- "mismatched size",
- "no imports with binary file output",
- "multiple ENTER pseudo-ops",
- "relative expression required",
- "repeated displacement",
- "segment or relocatability redefined",
- "segment register required",
- "size unknown",
- "unknown escape sequence",
- "FP register required",
- "FP register not allowed",
- "illegal FP register",
- "illegal FP register pair",
- "junk after operands",
- "already defined",
- "label moved in last pass, add -O?",
- "instruction illegal for current cpu",
- "short branch would do",
- "unknown error",
-};
-
-/* build null-terminated error message for given error at given spot */
-
-PUBLIC char *build_error_message(errnum, buf)
-error_pt errnum;
-char *buf;
-{
- if (errnum >= sizeof errormessage / sizeof errormessage[0])
- errnum = sizeof errormessage / sizeof errormessage[0] - 1;
- return strcpy(buf, errormessage[errnum]);
-}
diff --git a/as/errors.c b/as/errors.c
new file mode 100644
index 0000000..0f2558a
--- /dev/null
+++ b/as/errors.c
@@ -0,0 +1,107 @@
+
+#include "syshead.h"
+#include "const.h"
+
+/* Error codes. */
+
+/* Syntax errors. */
+PUBLIC char * COMEXP = "comma expected";
+PUBLIC char * DELEXP = "delimiter expected";
+PUBLIC char * FACEXP = "factor expected";
+PUBLIC char * IREGEXP = "index register expected";
+PUBLIC char * LABEXP = "label expected";
+PUBLIC char * LPEXP = "left parentheses expected";
+PUBLIC char * OPEXP = "opcode expected";
+PUBLIC char * RBEXP = "right bracket expected";
+PUBLIC char * REGEXP = "register expected";
+PUBLIC char * RPEXP = "right parentheses expected";
+PUBLIC char * SPEXP = "space expected";
+
+/* Expression errors. */
+PUBLIC char * ABSREQ = "absolute expression required";
+PUBLIC char * NONIMPREQ = "non-imported expression required";
+PUBLIC char * RELBAD = "relocation impossible";
+
+/* Label errors. */
+PUBLIC char * ILLAB = "illegal label";
+PUBLIC char * MACUID = "MACRO used as identifier";
+PUBLIC char * MISLAB = "missing label";
+PUBLIC char * MNUID = "opcode used as identifier";
+PUBLIC char * REGUID = "register used as identifier";
+PUBLIC char * RELAB = "redefined label";
+PUBLIC char * UNBLAB = "unbound label";
+PUBLIC char * UNLAB = "undefined label";
+PUBLIC char * VARLAB = "variable used as label";
+
+/* Addressing errors. */
+PUBLIC char * ABOUNDS = "address out of bounds";
+PUBLIC char * DBOUNDS = "data out of bounds";
+PUBLIC char * ILLMOD = "illegal address mode";
+PUBLIC char * ILLREG = "illegal register";
+
+/* Control structure errors. */
+PUBLIC char * ELSEBAD = "no matching IF";
+PUBLIC char * ENDBBAD = "no matching BLOCK";
+PUBLIC char * EOFBLOCK = "end of file in BLOCK";
+PUBLIC char * EOFIF = "end of file in IF";
+PUBLIC char * EOFLC = "location counter was undefined at end";
+PUBLIC char * EOFMAC = "end of file in MACRO";
+PUBLIC char * FAILERR = "user-generated error";
+
+/* Overflow errors. */
+PUBLIC char * BLOCKOV = "BLOCK stack overflow";
+PUBLIC char * BWRAP = "binary file wrap-around";
+PUBLIC char * COUNTOV = "counter overflow";
+PUBLIC char * COUNTUN = "counter underflow";
+PUBLIC char * GETOV = "GET stack overflow";
+PUBLIC char * IFOV = "IF stack overflow";
+
+PUBLIC char * LINLONG = "line too long";
+PUBLIC char * MACOV = "MACRO stack overflow";
+PUBLIC char * OBJSYMOV = "object symbol table overflow";
+PUBLIC char * OWRITE = "program overwrite";
+PUBLIC char * PAROV = "parameter table overflow";
+PUBLIC char * SYMOV = "symbol table overflow";
+PUBLIC char * SYMOUTOV = "output symbol table overflow";
+
+/* I/O errors. */
+PUBLIC char * OBJOUT = "error writing object file";
+
+/* Miscellaneous errors. */
+PUBLIC char * AL_AX_EAX_EXP = "al ax or eax expected";
+PUBLIC char * CTLINS = "control character in string";
+PUBLIC char * FURTHER = "futher errors suppressed";
+PUBLIC char * ILL_IMM_MODE = "illegal immediate mode";
+PUBLIC char * ILL_IND_TO_IND = "illegal indirect to indirect";
+PUBLIC char * ILL_IND = "illegal indirection";
+PUBLIC char * ILL_IND_PTR = "illegal indirection from previous 'ptr'";
+PUBLIC char * ILL_SCALE = "illegal scale";
+PUBLIC char * ILL_SECTION = "illegal section";
+PUBLIC char * ILL_SEG_REG = "illegal segment register";
+PUBLIC char * ILL_SOURCE_EA = "illegal source effective address";
+PUBLIC char * ILL_SIZE = "illegal size";
+PUBLIC char * IMM_REQ = "immediate expression expected";
+PUBLIC char * INDEX_REG_EXP = "index register expected";
+PUBLIC char * IND_REQ = "indirect expression required";
+PUBLIC char * MISMATCHED_SIZE = "mismatched size";
+PUBLIC char * NOIMPORT = "no imports with binary file output";
+PUBLIC char * REENTER = "multiple ENTER pseudo-ops";
+PUBLIC char * REL_REQ = "relative expression required";
+PUBLIC char * REPEATED_DISPL = "repeated displacement";
+PUBLIC char * SEGREL = "segment or relocatability redefined";
+PUBLIC char * SEG_REG_REQ = "segment register required";
+PUBLIC char * SIZE_UNK = "size unknown";
+PUBLIC char * UNKNOWN_ESCAPE_SEQUENCE = "unknown escape sequence";
+
+PUBLIC char * FP_REG_REQ = "FP register required";
+PUBLIC char * FP_REG_NOT_ALLOWED = "FP register not allowed";
+PUBLIC char * ILL_FP_REG = "illegal FP register";
+PUBLIC char * ILL_FP_REG_PAIR = "illegal FP register pair";
+PUBLIC char * JUNK_AFTER_OPERANDS = "junk after operands";
+
+PUBLIC char * ALREADY = "already defined";
+PUBLIC char * UNSTABLE_LABEL = "label moved in last pass add -O?";
+
+/* Warnings. */
+PUBLIC char * CPUCLASH = "instruction illegal for current cpu";
+PUBLIC char * SHORTB = "short branch would do";
diff --git a/as/errors.h b/as/errors.h
new file mode 100644
index 0000000..28e1a58
--- /dev/null
+++ b/as/errors.h
@@ -0,0 +1,105 @@
+/* Error codes. */
+
+/* Syntax errors. */
+EXTERN char * COMEXP; /* "comma expected" */
+EXTERN char * DELEXP; /* "delimiter expected" */
+EXTERN char * FACEXP; /* "factor expected" */
+EXTERN char * IREGEXP; /* "index register expected" */
+EXTERN char * LABEXP; /* "label expected" */
+EXTERN char * LPEXP; /* "left parentheses expected" */
+EXTERN char * OPEXP; /* "opcode expected" */
+EXTERN char * RBEXP; /* "right bracket expected" */
+EXTERN char * REGEXP; /* "register expected" */
+EXTERN char * RPEXP; /* "right parentheses expected" */
+EXTERN char * SPEXP; /* "space expected" */
+
+/* Expression errors. */
+EXTERN char * ABSREQ; /* "absolute expression required" */
+EXTERN char * NONIMPREQ; /* "non-imported expression required" */
+EXTERN char * RELBAD; /* "relocation impossible" */
+
+/* Label errors. */
+EXTERN char * ILLAB; /* "illegal label" */
+EXTERN char * MACUID; /* "MACRO used as identifier" */
+EXTERN char * MISLAB; /* "missing label" */
+EXTERN char * MNUID; /* "opcode used as identifier" */
+EXTERN char * REGUID; /* "register used as identifier" */
+EXTERN char * RELAB; /* "redefined label" */
+EXTERN char * UNBLAB; /* "unbound label" */
+EXTERN char * UNLAB; /* "undefined label" */
+EXTERN char * VARLAB; /* "variable used as label" */
+
+/* Addressing errors. */
+EXTERN char * ABOUNDS; /* "address out of bounds" */
+EXTERN char * DBOUNDS; /* "data out of bounds" */
+EXTERN char * ILLMOD; /* "illegal address mode" */
+EXTERN char * ILLREG; /* "illegal register" */
+
+/* Control structure errors. */
+EXTERN char * ELSEBAD; /* "no matching IF" */
+#define ELSEIFBAD ELSEBAD
+EXTERN char * ENDBBAD; /* "no matching BLOCK" */
+#define ENDIFBAD ELSEBAD
+EXTERN char * EOFBLOCK; /* "end of file in BLOCK" */
+EXTERN char * EOFIF; /* "end of file in IF" */
+EXTERN char * EOFLC; /* "location counter was undefined at end" */
+EXTERN char * EOFMAC; /* "end of file in MACRO" */
+EXTERN char * FAILERR; /* "user-generated error" */
+
+/* Overflow errors. */
+EXTERN char * BLOCKOV; /* "BLOCK stack overflow" */
+EXTERN char * BWRAP; /* "binary file wrap-around" */
+EXTERN char * COUNTOV; /* "counter overflow" */
+EXTERN char * COUNTUN; /* "counter underflow" */
+EXTERN char * GETOV; /* "GET stack overflow" */
+EXTERN char * IFOV; /* "IF stack overflow" */
+
+EXTERN char * LINLONG; /* "line too long" */
+EXTERN char * MACOV; /* "MACRO stack overflow" */
+EXTERN char * OBJSYMOV; /* "object symbol table overflow" */
+EXTERN char * OWRITE; /* "program overwrite" */
+EXTERN char * PAROV; /* "parameter table overflow" */
+EXTERN char * SYMOV; /* "symbol table overflow" */
+EXTERN char * SYMOUTOV; /* "output symbol table overflow" */
+
+/* I/O errors. */
+EXTERN char * OBJOUT; /* "error writing object file" */
+
+/* Miscellaneous errors. */
+EXTERN char * AL_AX_EAX_EXP; /* "al ax or eax expected" */
+EXTERN char * CTLINS; /* "control character in string" */
+EXTERN char * FURTHER; /* "futher errors suppressed" */
+EXTERN char * ILL_IMM_MODE; /* "illegal immediate mode" */
+EXTERN char * ILL_IND_TO_IND; /* "illegal indirect to indirect" */
+EXTERN char * ILL_IND; /* "illegal indirection" */
+EXTERN char * ILL_IND_PTR; /* "illegal indirection from previous 'ptr'" */
+EXTERN char * ILL_SCALE; /* "illegal scale" */
+EXTERN char * ILL_SECTION; /* "illegal section" */
+EXTERN char * ILL_SEG_REG; /* "illegal segment register" */
+EXTERN char * ILL_SOURCE_EA; /* "illegal source effective address" */
+EXTERN char * ILL_SIZE; /* "illegal size" */
+EXTERN char * IMM_REQ; /* "immediate expression expected" */
+EXTERN char * INDEX_REG_EXP; /* "index register expected" */
+EXTERN char * IND_REQ; /* "indirect expression required" */
+EXTERN char * MISMATCHED_SIZE; /* "mismatched size" */
+EXTERN char * NOIMPORT; /* "no imports with binary file output" */
+EXTERN char * REENTER; /* "multiple ENTER pseudo-ops" */
+EXTERN char * REL_REQ; /* "relative expression required" */
+EXTERN char * REPEATED_DISPL; /* "repeated displacement" */
+EXTERN char * SEGREL; /* "segment or relocatability redefined" */
+EXTERN char * SEG_REG_REQ; /* "segment register required" */
+EXTERN char * SIZE_UNK; /* "size unknown" */
+EXTERN char * UNKNOWN_ESCAPE_SEQUENCE; /* "unknown escape sequence" */
+
+EXTERN char * FP_REG_REQ; /* "FP register required" */
+EXTERN char * FP_REG_NOT_ALLOWED; /* "FP register not allowed" */
+EXTERN char * ILL_FP_REG; /* "illegal FP register" */
+EXTERN char * ILL_FP_REG_PAIR; /* "illegal FP register pair" */
+EXTERN char * JUNK_AFTER_OPERANDS; /* "junk after operands" */
+
+EXTERN char * ALREADY; /* "already defined" */
+EXTERN char * UNSTABLE_LABEL; /* "label moved in last pass add -O?" */
+
+/* Warnings. */
+EXTERN char * CPUCLASH; /* "instruction illegal for current cpu" */
+EXTERN char * SHORTB; /* "short branch would do" */
diff --git a/as/express.c b/as/express.c
index 65923b5..51537c3 100644
--- a/as/express.c
+++ b/as/express.c
@@ -8,7 +8,7 @@
#include "scan.h"
#include "source.h"
-FORWARD void experror P((error_pt errnum));
+FORWARD void experror P((char * err_str));
FORWARD void expundefined P((void));
FORWARD void simple2 P((void));
FORWARD void simple P((void));
@@ -33,10 +33,10 @@ PUBLIC void chkabs()
}
}
-PRIVATE void experror(errnum)
-error_pt errnum;
+PRIVATE void experror(err_str)
+char * err_str;
{
- error(errnum);
+ error(err_str);
expundefined();
}
@@ -312,6 +312,7 @@ PUBLIC void factor()
getsym();
return;
}
+#ifndef MC6809
case LBRACKET:
if (!asld_compatible)
break; /* error, LPAREN is the grouping symbol */
@@ -322,9 +323,12 @@ PUBLIC void factor()
else
getsym();
return;
+#endif
case LPAREN:
+#ifndef MC6809
if (asld_compatible)
break; /* error, LBRACKET is the grouping symbol */
+#endif
getsym();
expres();
if (sym != RPAREN)
diff --git a/as/genbin.c b/as/genbin.c
index 887c921..6b4b42a 100644
--- a/as/genbin.c
+++ b/as/genbin.c
@@ -7,9 +7,11 @@
#include "file.h"
#include "globvar.h"
+#ifdef USE_FIXED_HEAP
PRIVATE char *asmbeg; /* beginning of assembler code */
/* for overwrite check */
/* bss-init to zero = NULL and not changed */
+#endif
/* Sneaky stuff, the start of a binary file can be _negative_ for the I80386
assembler. The -ve addresses are ones over 2GB (or "org -32") */
@@ -234,17 +236,19 @@ static PT zapptr = 0;
}
}
}
+#ifdef USE_FIXED_HEAP
else if (binaryc && !(lcdata & UNDBIT))
/* memory output, and enabled */
{
register char *bufptr;
- if ((bufptr = (char *) binmbuf) >= asmbeg && bufptr < heapptr)
+ if ((bufptr = (char *) binmbuf) >= asmbeg && bufptr < temp_buf())
error(OWRITE);
else
*bufptr = ch;
++binmbuf;
}
+#endif
}
/* write sized offset to binary file or directly to memory */
diff --git a/as/genlist.c b/as/genlist.c
index b0db41c..edeefff 100644
--- a/as/genlist.c
+++ b/as/genlist.c
@@ -17,7 +17,7 @@
struct error_s /* to record error info */
{
- unsigned char errnum;
+ char * err_str;
unsigned char position;
};
@@ -131,36 +131,39 @@ register char *where;
/* record number and position of error (or error buffer overflow) */
-PUBLIC void error(errnum)
-error_pt errnum;
+PUBLIC void warning(err_str)
+char * err_str;
+{
+ if (!as_warn.current) return;
+ ++totwarn;
+ --toterr;
+ error(err_str);
+}
+
+PUBLIC void error(err_str)
+char * err_str;
{
register struct error_s *errptr;
register struct error_s *errptrlow;
unsigned char position;
- if ((unsigned) errnum < MINWARN || as_warn.current)
+ if (errcount >= MAXERR)
+ erroverflow = TRUE;
+ else
{
- if (errcount >= MAXERR)
- erroverflow = TRUE;
- else
+ position = symname - linebuf;
+ for (errptr = errbuf + errcount;
+ errptr > errbuf && errptr->position > position;
+ errptr = errptrlow)
{
- position = symname - linebuf;
- for (errptr = errbuf + errcount;
- errptr > errbuf && errptr->position > position;
- errptr = errptrlow)
- {
- errptrlow = errptr - 1;
- errptr->errnum = errptrlow->errnum;
- errptr->position = errptrlow->position;
- }
- errptr->errnum = errnum;
- errptr->position = position;
- ++errcount;
- if ((unsigned)errnum >= MINWARN)
- ++totwarn;
- else
- ++toterr;
+ errptrlow = errptr - 1;
+ errptr->err_str = errptrlow->err_str;
+ errptr->position = errptrlow->position;
}
+ errptr->err_str = err_str;
+ errptr->position = position;
+ ++errcount;
+ ++toterr;
}
}
@@ -208,7 +211,7 @@ PRIVATE void listcode()
unsigned numlength;
char *numptr;
- listptr = (struct code_listing_s *) heapptr;
+ listptr = (struct code_listing_s *) temp_buf();
memset((char *) listptr, ' ', sizeof *listptr);
listptr->nullterm = 0;
if (macflag)
@@ -354,7 +357,7 @@ PRIVATE void listerrors()
{
writenl(); paderrorline(1);
}
- writes(errmsg = build_error_message(errptr->errnum, heapptr));
+ writes(errmsg = errptr->err_str);
errcol = strlen(errmsg)+LINUM_LEN+1;
column = 0; linep = linebuf;
errcolw = CODE_LIST_LENGTH;
@@ -390,7 +393,7 @@ PRIVATE void listerrors()
paderrorline((unsigned) errcolw - LINUM_LEN);
}
writec('^');
- writes(errmsg = build_error_message(errptr->errnum, heapptr));
+ writes(errmsg = errptr->err_str);
errcol += strlen(errmsg);
#endif
++errptr;
@@ -404,7 +407,7 @@ PRIVATE void listerrors()
#else
paderrorline(CODE_LIST_LENGTH - LINUM_LEN);
#endif
- writesn(build_error_message(FURTHER, heapptr));
+ writesn(FURTHER);
}
}
diff --git a/as/genobj.c b/as/genobj.c
index abe140a..588f41b 100644
--- a/as/genobj.c
+++ b/as/genobj.c
@@ -345,6 +345,7 @@ PUBLIC void objheader()
unsigned symosiz; /* size of object symbol table */
register struct sym_s *symptr;
u32_T textlength;
+ int symcount = 0;
if ((objectc = objectg) == 0)
return;
@@ -362,9 +363,22 @@ PUBLIC void objheader()
if ((nameptr = strrchr(module_name, '.')) != NUL_PTR)
*nameptr = 0;
strsiz = strlen(module_name) + 1;
- align(heapptr);
- for (hashptr = spt, arrext = copyptr = (struct sym_s **) heapptr;
- hashptr < spt_top;)
+
+ for (hashptr = spt; hashptr < spt_top;)
+ if ((symptr = *hashptr++) != NUL_PTR)
+ do
+ {
+ if ((symptr->type & EXPBIT || symptr->data & IMPBIT) ||
+ (!globals_only_in_obj && symptr->name[0] != '.' &&
+ !(symptr->type & (MNREGBIT | MACBIT | VARBIT))))
+ {
+ symcount ++;
+ }
+ }
+ while ((symptr = symptr->next) != NUL_PTR);
+ arrext = copyptr = asalloc( sizeof(struct sym_s *) * symcount);
+
+ for (hashptr = spt; hashptr < spt_top;)
if ((symptr = *hashptr++) != NUL_PTR)
do
{
@@ -372,11 +386,6 @@ PUBLIC void objheader()
(!globals_only_in_obj && symptr->name[0] != '.' &&
!(symptr->type & (MNREGBIT | MACBIT | VARBIT))))
{
- if (copyptr >= (struct sym_s **) heapend)
- {
- heapptr = (char *) copyptr;
- fatalerror(OBJSYMOV);
- }
*copyptr++ = symptr;
strsiz += symptr->length + 1;
if (textseg>=0 && (symptr->data & SEGM) == textseg)
@@ -399,7 +408,7 @@ PUBLIC void objheader()
}
}
while ((symptr = symptr->next) != NUL_PTR);
- heapptr = (char *) (copytop = copyptr);
+ copytop = copyptr;
/* calculate length of text, and number of seg size bytes in header */
diff --git a/as/gensym.c b/as/gensym.c
index db9dec4..646c5cd 100644
--- a/as/gensym.c
+++ b/as/gensym.c
@@ -29,35 +29,34 @@ PUBLIC void gensym()
#ifdef BINSYM
unsigned label_stringptr; /* offset of label str from start of file */
#endif
+ int symcount = 0;
labels_length = label_count = 0;
/* make copy of all relavant symbol ptrs on heap */
/* original ptrs can now be modified, but need to be an array for sort */
- align(heapptr);
- for (hashptr = spt, symlptr = copyptr = (struct sym_s **) heapptr;
- hashptr < spt_top;)
+ for (hashptr = spt; hashptr < spt_top;)
+ if ((symptr = *hashptr++) != NUL_PTR)
+ do
+ if (!(symptr->type & (MACBIT | MNREGBIT | VARBIT)))
+ symcount++;
+ while ((symptr = symptr->next) != NUL_PTR);
+ symlptr = copyptr = asalloc( sizeof(struct sym_s *) * symcount);
+
+ for (hashptr = spt; hashptr < spt_top;)
if ((symptr = *hashptr++) != NUL_PTR)
do
if (!(symptr->type & (MACBIT | MNREGBIT | VARBIT)))
{
- if (copyptr >= (struct sym_s **) heapend)
- {
- heapptr = (char *) copyptr;
- error(SYMOUTOV); /* avoid recursive fatalerror */
- listline(); /* the main job is OK if here */
- goto sort_symbols;
- }
*copyptr++ = symptr;
++label_count;
labels_length += symptr->length + 3; /* 3 for type, value */
}
while ((symptr = symptr->next) != NUL_PTR);
-sort_symbols:
sort(symlptr, copyptr, TRUE); /* sort on name */
- heapptr = (char *) (copytop = copyptr);
+ copytop = copyptr;
if (list.global)
{
outfd = lstfil;
@@ -147,7 +146,7 @@ unsigned column;
char *outname;
char *symname;
- listptr = (struct sym_listing_s *) heapptr;
+ listptr = (struct sym_listing_s *) temp_buf();
memset((char *) listptr, ' ', SYMLIS_LEN);
listptr->nullterm = 0;
if ((length = symptr->length) > SYMLIS_NAMELEN)
diff --git a/as/globvar.h b/as/globvar.h
index 1ea385e..edd9419 100644
--- a/as/globvar.h
+++ b/as/globvar.h
@@ -35,8 +35,6 @@ EXTERN char *linebuf; /* buffer */
/* for symbol table routines */
-EXTERN char *heapend; /* end of free space for symbol list */
-EXTERN char *heapptr; /* next free space in symbol list */
EXTERN unsigned char inidata; /* init sym entry data governed by "u" flag */
EXTERN struct sym_s **spt; /* symbol pointer table */
EXTERN struct sym_s **spt_top; /* top of symbol ptr table */
@@ -112,7 +110,7 @@ extern char hexdigit[];
#ifdef I80386
#ifndef __AS386_16__
#define iscpu(x) (cpuid>=(x))
-#define needcpu(x) do{ if(cpuid<(x)) {error(CPUCLASH); cpuid|=0x10;} }while(0)
+#define needcpu(x) do{ if(cpuid<(x)) {warning(CPUCLASH); cpuid|=0x10;} }while(0)
#define setcpu(x) (cpuid=(x))
#define cpuwarn() (cpuid&=0xF)
#endif
diff --git a/as/keywords.c b/as/keywords.c
index b3c1615..0db0636 100644
--- a/as/keywords.c
+++ b/as/keywords.c
@@ -135,9 +135,13 @@ PUBLIC char ops[] =
5, '.', 'D', 'A', 'T', 'A', DATAOP, 0,
6, '.', 'D', 'A', 'T', 'A', '1', FCBOP, 0,
6, '.', 'D', 'A', 'T', 'A', '2', FDBOP, 0,
+#if SIZEOF_OFFSET_T > 2
6, '.', 'D', 'A', 'T', 'A', '4', FQBOP, 0,
+#endif
2, 'D', 'B', FCBOP, 0,
+#if SIZEOF_OFFSET_T > 2
2, 'D', 'D', FQBOP, 0,
+#endif
7, '.', 'D', 'E', 'F', 'I', 'N', 'E', EXPORTOP, 0,
2, 'D', 'W', FDBOP, 0,
3, 'E', 'N', 'D', PROCEOFOP, 0,
@@ -165,7 +169,9 @@ PUBLIC char ops[] =
6, '.', 'L', 'C', 'O', 'M', 'M', LCOMMOP1, 0,
5, '.', 'L', 'I', 'S', 'T', LISTOP, 0,
3, 'L', 'O', 'C', LOCOP, 0,
+#if SIZEOF_OFFSET_T > 2
5, '.', 'L', 'O', 'N', 'G', FQBOP, 0,
+#endif
8, '.', 'M', 'A', 'C', 'L', 'I', 'S', 'T', MACLISTOP, 0,
5, 'M', 'A', 'C', 'R', 'O', MACROOP, 0,
4, '.', 'M', 'A', 'P', MAPOP, 0,
@@ -180,8 +186,10 @@ PUBLIC char ops[] =
6, '.', 'S', 'H', 'O', 'R', 'T', FDBOP, 0,
6, '.', 'S', 'P', 'A', 'C', 'E', RMBOP, 0,
5, '.', 'T', 'E', 'X', 'T', TEXTOP, 0,
+#ifndef MC6809
5, 'U', 'S', 'E', '1', '6', USE16OP, 0,
5, 'U', 'S', 'E', '3', '2', USE32OP, 0,
+#endif
5, '.', 'W', 'A', 'R', 'N', WARNOP, 0,
5, '.', 'W', 'O', 'R', 'D', FDBOP, 0,
6, '.', 'Z', 'E', 'R', 'O', 'W', BLKWOP, 0,
diff --git a/as/macro.c b/as/macro.c
index 566c086..a858141 100644
--- a/as/macro.c
+++ b/as/macro.c
@@ -38,9 +38,12 @@ struct sym_s *symptr;
macpar = (struct schain_s *) (stringptr + 1);
/* TODO: alignment */
getsym();
- if (sym != LPAREN)
+ if (sym == EOLSYM)
return; /* no other params */
- reglineptr = lineptr;
+ if (sym != LPAREN)
+ reglineptr = symname;
+ else
+ reglineptr = lineptr;
stringptr = macpar->string;
while (TRUE)
{
@@ -51,10 +54,11 @@ struct sym_s *symptr;
return;
}
ch = *reglineptr++;
- if (ch == '/')
+ if (ch == '\\')
/* escaped means no special meaning for slash, comma, paren */
ch = *reglineptr++;
- else if (ch == ',' || ch == ')')
+ else if (ch == ',' || ch == ')' || ch == '!' || ch == ';'
+ || ch == '\n' || ch == 0)
{
if (stringptr >= (char *) macptop)
{
@@ -69,7 +73,7 @@ struct sym_s *symptr;
macpar = (struct schain_s *) (stringptr + 1);
/* but is finished OK - TODO align */
stringptr = macpar->string;
- if (ch == ')')
+ if (ch != ',')
return;
continue;
}
@@ -90,6 +94,9 @@ PUBLIC void pmacro()
bool_t saving;
bool_t savingc;
struct sym_s *symptr=0;
+ int maclen = 8;
+ int macoff = 0;
+ char * macbuf = asalloc(8);
saving = /* prepare for bad macro */
savingc = FALSE; /* normally don't save comments */
@@ -114,9 +121,7 @@ PUBLIC void pmacro()
else
symptr->type |= MACBIT;
symptr->data = UNDBIT; /* undefined till end */
- symptr->value_reg_or_op.value = (offset_t) heapptr;
- /* beginning of store for macro */
- /* value s.b. (char *) */
+ symptr->value_reg_or_op.value = (offset_t) macbuf;
getsym_nolookup(); /* test for "C" */
if (sym == IDENT && lineptr == symname + 1 && *symname == 'C')
savingc = TRUE;
@@ -147,27 +152,24 @@ PUBLIC void pmacro()
if (!saving)
continue;
{
- register char *reglineptr;
- register char *regheapptr;
+ char * p = strchr(linebuf, EOLCHAR);
+ int len = (p-linebuf+1);
- reglineptr = linebuf;
- regheapptr = heapptr;
- do
+ if ( macoff + len > maclen-4 )
{
- if (regheapptr >= heapend)
- {
- heapptr = regheapptr;
- fatalerror(SYMOV); /* won't fit */
- }
+ maclen = maclen * 2 + len;
+ macbuf = asrealloc(macbuf, maclen);
}
- while ((*regheapptr++ = *reglineptr++) != EOLCHAR);
- heapptr = regheapptr;
+ memcpy(macbuf+macoff, linebuf, len);
+ macoff += len;
+
}
}
macload = FALSE;
if (saving)
{
- *heapptr++ = ETB;
+ macbuf[macoff] = ETB;
+ symptr->value_reg_or_op.value = (offset_t) macbuf;
symptr->data = 0;
}
}
diff --git a/as/mops.c b/as/mops.c
index f711708..d18510d 100644
--- a/as/mops.c
+++ b/as/mops.c
@@ -409,7 +409,7 @@ FORWARD void getimmed P((struct ea_s *eap, count_t immed_count));
FORWARD void getindirect P((struct ea_s *eap));
FORWARD void getshift P((struct ea_s *eap));
FORWARD reg_pt indregchk P((reg_pt matchreg));
-FORWARD void kgerror P((error_pt errnum));
+FORWARD void kgerror P((char * err_str));
FORWARD void lbranch P((int backamount));
FORWARD void notbytesize P((struct ea_s *eap));
FORWARD void notimmed P((struct ea_s *eap));
@@ -1050,10 +1050,10 @@ reg_pt matchreg;
return reg;
}
-PRIVATE void kgerror(errnum)
-error_pt errnum;
+PRIVATE void kgerror(err_str)
+char * err_str;
{
- error(errnum);
+ error(err_str);
sprefix = oprefix = aprefix = mcount = 0x0;
}
@@ -1071,7 +1071,7 @@ int backamount;
if ( last_pass<2 && backamount != 0x0 &&
!(lastexp.data & IMPBIT) &&
lastexp.offset + backamount < 0x80 + backamount)
- error(SHORTB); /* -0x8? to 0x7F, warning */
+ warning(SHORTB); /* -0x8? to 0x7F, warning */
}
}
}
@@ -2427,7 +2427,7 @@ FORWARD void doaltind P((void));
FORWARD void do1altind P((void));
FORWARD void fixupind P((void));
FORWARD void getindexnopost P((void));
-FORWARD void inderror P((error_pt errnum));
+FORWARD void inderror P((char * err_str));
FORWARD reg_pt indreg P((reg_pt maxindex));
FORWARD void predec1 P((void));
FORWARD void sustack P((reg_pt stackreg));
@@ -2617,8 +2617,8 @@ PRIVATE void do1altind()
inderror(ILLMOD); /* e.g. LEAX $10 */
else
{
- if (byteflag || !wordflag && !(lastexp.data & (FORBIT | RELBIT)) &&
- (lastexp.offset >> 0x8) == dirpag)
+ if (byteflag || (!wordflag && !(lastexp.data & (FORBIT | RELBIT)) &&
+ (lastexp.offset >> 0x8) == dirpag))
{ /* direct addressing */
if (opcode >= 0x80)
opcode |= 0x10;
@@ -2634,7 +2634,7 @@ PRIVATE void do1altind()
!(lastexp.data & IMPBIT) &&
lastexp.offset + (0x81 - 0x3) < 0x101)
/* JSR or JMP could be done with BSR or BRA */
- error(SHORTB);
+ warning(SHORTB);
}
}
}
@@ -2657,10 +2657,10 @@ PRIVATE void getindexnopost()
fixupind();
}
-PRIVATE void inderror(errnum)
-error_pt errnum;
+PRIVATE void inderror(err_str)
+char * err_str;
{
- error(errnum);
+ error(err_str);
if (postb & INDIRECTBIT)
sym = RBRACKET; /* fake right bracket to kill further errors */
fixupind();
@@ -2754,7 +2754,7 @@ PUBLIC void mlong()
lastexp.offset = lastexp.offset - lc - lcjump;
if ( last_pass<2 && !(lastexp.data & IMPBIT) &&
lastexp.offset + 0x81 < 0x101)
- error(SHORTB); /* -0x81 to 0x7F, warning */
+ warning(SHORTB); /* -0x81 to 0x7F, warning */
}
}
}
diff --git a/as/opcode.h b/as/opcode.h
index 385c096..1d91dc2 100644
--- a/as/opcode.h
+++ b/as/opcode.h
@@ -31,7 +31,9 @@ enum
FCBOP,
FCCOP,
FDBOP,
+#if SIZEOF_OFFSET_T > 2
FQBOP,
+#endif
GETOP,
GLOBLOP,
IDENTOP,
diff --git a/as/pops.c b/as/pops.c
index eb617f2..68e7f45 100644
--- a/as/pops.c
+++ b/as/pops.c
@@ -420,10 +420,10 @@ pfv func;
}
}
-PUBLIC void fatalerror(errnum)
-error_pt errnum;
+PUBLIC void fatalerror(err_str)
+char * err_str;
{
- error(errnum);
+ error(err_str);
skipline();
listline();
finishup();
@@ -432,8 +432,8 @@ error_pt errnum;
/* swap position with label position, do error, put back posn */
/* also clear label ptr */
-PUBLIC void labelerror(errnum)
-error_pt errnum;
+PUBLIC void labelerror(err_str)
+char * err_str;
{
struct sym_s *oldgsymptr;
char *oldlineptr;
@@ -447,7 +447,7 @@ error_pt errnum;
lineptr = linebuf;
getsym(); /* 1st symbol is label or symbol after
* missing one */
- error(errnum);
+ error(err_str);
gsymptr = oldgsymptr;
lineptr = oldlineptr;
sym = oldsym;
diff --git a/as/proto.h b/as/proto.h
index 9cc6446..bf96a70 100644
--- a/as/proto.h
+++ b/as/proto.h
@@ -10,9 +10,6 @@ void line_zero P((void));
/* assemble.c */
void assemble P((void));
-/* error.c */
-char *build_error_message P((error_pt errnum, char *buf));
-
/* express.c */
void absexpres P((void));
void chkabs P((void));
@@ -34,7 +31,8 @@ void putbin P((int ch));
/* genlist.c */
char *build_2hex_number P((unsigned num, char *where));
char *build_number P((unsigned num, unsigned width, char *where));
-void error P((error_pt errnum));
+void warning P((char * errorstr));
+void error P((char * errorstr));
void listline P((void));
void writec P((int ch));
void writenl P((void));
@@ -139,8 +137,8 @@ void mshort P((void));
bool_pt checksegrel P((struct sym_s *symptr));
void checkdatabounds P((void));
void datatoobig P((void));
-void fatalerror P((error_pt errnum));
-void labelerror P((error_pt errnum));
+void fatalerror P((char * errorstr));
+void labelerror P((char * errorstr));
void palign P((void));
void pasciz P((void));
void pblkw P((void));
@@ -163,7 +161,9 @@ void pfail P((void));
void pfcb P((void));
void pfcc P((void));
void pfdb P((void));
+#if SIZEOF_OFFSET_T > 2
void pfqb P((void));
+#endif
void pglobl P((void));
void pident P((void));
void pif P((void));
@@ -216,3 +216,10 @@ void u4c4 P((char *buf, u32_T offset));
void u2cn P((char *buf, u16_pt offset, unsigned count));
void u4cn P((char *buf, u32_T offset, unsigned count));
bool_pt typeconv_init P((bool_pt big_endian, bool_pt long_big_endian));
+
+/* alloc.c */
+void * asalloc P((unsigned int size));
+void * asrealloc P((void * oldptr, unsigned int size));
+void * temp_buf P((void));
+void init_heap P((void));
+
diff --git a/as/readsrc.c b/as/readsrc.c
index 819efb8..df69756 100644
--- a/as/readsrc.c
+++ b/as/readsrc.c
@@ -138,9 +138,12 @@ char *name;
for(;;)
{
if( filelength >= memsize )
- mem_start = realloc(mem_start, (memsize+=16000)+4);
- if(mem_start == 0)
- as_abort("Cannot allocate memory for BIG buffer");
+ {
+ if (memsize > 16000)
+ mem_start = asrealloc(mem_start, (memsize+=16384)+4);
+ else
+ mem_start = asrealloc(mem_start, (memsize+=memsize+32)+4);
+ }
cc = read(fd, mem_start+filelength,
(size_t)(memsize-filelength));
if( cc <= 0 ) break;
diff --git a/as/scan.c b/as/scan.c
index d40eabd..97be265 100644
--- a/as/scan.c
+++ b/as/scan.c
@@ -233,6 +233,7 @@ PRIVATE void intconst()
PUBLIC void initscan()
{
+#ifndef MC6809
if (asld_compatible)
{
lindirect = LPAREN;
@@ -241,8 +242,11 @@ PUBLIC void initscan()
}
else
{
+#endif
lindirect = LBRACKET;
rindexp = RBEXP;
rindirect = RBRACKET;
+#ifndef MC6809
}
+#endif
}
diff --git a/as/scan.h b/as/scan.h
index 43a328c..baffefb 100644
--- a/as/scan.h
+++ b/as/scan.h
@@ -6,7 +6,7 @@ EXTERN struct sym_s *gsymptr; /* global symbol ptr */
EXTERN char lindirect; /* left symbol for indirect addressing */
EXTERN char *lineptr; /* current line position */
EXTERN offset_t number; /* constant number */
-EXTERN int rindexp; /* error code for missing rindirect */
+EXTERN char * rindexp; /* error code for missing rindirect */
EXTERN char rindirect; /* right symbol for indirect addressing */
EXTERN char sym; /* current symbol */
EXTERN char *symname; /* current symbol name */
diff --git a/as/table.c b/as/table.c
index 6cb5e8b..3d39d0b 100644
--- a/as/table.c
+++ b/as/table.c
@@ -168,24 +168,18 @@ PUBLIC struct sym_s *lookup()
}
if (!ifflag)
return NUL_PTR;
- align(heapptr);
- if (heapptr >= heapend)
- fatalerror(SYMOV);
#ifdef DEBUG
++nsym;
if (hashptr >= spt && hashptr < spt + SPTSIZ)
++nhash;
#endif
- *hashptr = symptr = (struct sym_s *) heapptr;
+ *hashptr = symptr = asalloc(sizeof(struct sym_s) + length);
symptr->type = 0;
symptr->data = inidata;
symptr->length = length;
symptr->value_reg_or_op.value = (offset_t) (symptr->next = NUL_PTR);
- heapptr = symptr->name;
- do
- *heapptr++ = *nameptr++;
- while (--length != 0);
- *heapptr++ = 0;
+ memcpy(symptr->name, nameptr, length);
+ symptr->name[length] = 0;
return symptr;
}
@@ -220,6 +214,6 @@ PUBLIC void statistics()
weight += nx[i] * i;
}
printf("\n");
- printf("weight = %d%d\n", w;
+ printf("weight = %d%d\n", w);
#endif
}
diff --git a/as/type.h b/as/type.h
index c66266d..171790e 100644
--- a/as/type.h
+++ b/as/type.h
@@ -22,7 +22,6 @@ typedef unsigned long u4_pt;
typedef unsigned char bool_t;
typedef int bool_pt;
typedef unsigned count_t;
-typedef int error_pt;
typedef int fd_t;
typedef unsigned char indcount_t;
#ifdef I80386
diff --git a/as/typeconv.c b/as/typeconv.c
index 708d92b..d8c0c89 100644
--- a/as/typeconv.c
+++ b/as/typeconv.c
@@ -15,8 +15,8 @@ void xxerr(x) char * x; { write(2, x, strlen(x)); }
static int no_swap = 1;
-static long_off[4] = {0,1,2,3};
-static int_off[2] = {0,1};
+static int long_off[4] = {0,1,2,3};
+static int int_off[2] = {0,1};
PUBLIC bool_pt typeconv_init(big_endian, long_big_endian)
bool_pt big_endian;
diff --git a/bcc/bcc.c b/bcc/bcc.c
index 3de0006..abac5a9 100644
--- a/bcc/bcc.c
+++ b/bcc/bcc.c
@@ -1,26 +1,67 @@
-/* bcc.c - driver for Bruce's C compiler (bcc) and for CvW's C compiler */
-
-/* Copyright (C) 1992 Bruce Evans */
-
-#define _POSIX_SOURCE 1
-
+/*
+ * bcc.c Version 2001.1
+ * Complete rewrite because the old one was just too confusing!
+ *
+ * There are no significant compile time options (MC6809 and CCC
+ * just change defaults) but you should set LOCALPREFIX.
+ *
+ * Personality flags are:
+ *
+ * -Mn Normal ELKS
+ * -Md MSDOS
+ * -Ms PC Standalone.
+ * -Ml i386 Linux
+ * -M8 CvW's c386
+ * -M9 MC6809 with bcc
+ */
+#include <stdio.h>
+#ifdef __STDC__
+#include <stdlib.h>
+#include <unistd.h>
+#endif
+#include <string.h>
+#include <memory.h>
+#include <malloc.h>
+#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#ifndef MSDOS
#include <sys/wait.h>
-#include <unistd.h>
-#endif
#include <signal.h>
-#include <stdlib.h>
-#include <string.h>
-#include <fcntl.h>
+#endif
+
+#ifdef MSDOS
+#define LOCALPREFIX /linux86
+#define EXESUF ".exe"
+#define R_OK 4 /* Test for read permission. */
+#define W_OK 2 /* Test for write permission. */
+#define X_OK 1 /* Test for execute permission. */
+#define F_OK 0 /* Test for existence. */
+#define L_TREE 1 /* Use different tree style */
+#define DEFARCH 0 /* Default to 8086 code */
+#else
+#define EXESUF
+#endif
+
+#define AS "as" EXESUF
+#define LD "ld" EXESUF
+#define CPP "cpp" EXESUF
+#define CC1 "cc1" EXESUF
+#define OPT "opt" EXESUF
+
+#define CC1C386 "c386" EXESUF
+
+#define AS09 "as09" EXESUF
+#define LD09 "ld09" EXESUF
-#define FALSE 0
-#define FORWARD static
-#define NUL_PTR ((void*)0)
-#define PRIVATE static
-#define PUBLIC
-#define TRUE 1
+#define CPPBCC "bcc-cc1" EXESUF
+#define CC1BCC "bcc-cc1" EXESUF
+#define AS86 "as86" EXESUF
+#define LD86 "ld86" EXESUF
+
+#define GCC "gcc"
+#define UNPROTO "unproto" EXESUF
+#define OPTIM "copt" EXESUF
#if __STDC__ == 1
#define P(x) x
@@ -32,932 +73,951 @@
#define QUOT(x) "x"
#endif
+struct command {
+ char * cmd;
+ char * fullpath;
+ int numargs;
+ int maxargs;
+ char ** arglist;
+} command = { 0,0,0,0,0 };
+
+struct file_list {
+ struct file_list * next;
+ char * file;
+ char * oldfile;
+ char * name;
+ int filetype; /* Char, notional extention of file. */
+} * files;
+
+struct opt_list {
+ struct opt_list * next;
+ char * opt;
+ int opttype; /* Where the option should go */
+} * options;
+
+int opt_v, opt_V, opt_e, opt_x, opt_I, opt_L, opt_W, opt_i,
+ opt_O, opt_M;
+
+#ifdef DEFARCH
+int opt_arch = (DEFARCH != 0);
+#else
+int opt_arch = sizeof (char *) >= 4;
+#endif
+
+int do_preproc = 1; /* c -> i */
+int do_unproto = 0; /* i -> i */
+int do_compile = 1; /* i -> s */
+int do_optim = 0; /* s -> s */
+int do_as = 1; /* s -> o */
+int do_link = 1; /* o -> done */
+char * executable_name = 0;
+
+int file_count = 0;
+int dyn_count = 0;
+int error_count = 0;
+char * progname = "C";
#ifdef MSDOS
-#define LOCALPREFIX /linux86
-#define EXESUF ".exe"
-#define R_OK 4 /* Test for read permission. */
-#define W_OK 2 /* Test for write permission. */
-#define X_OK 1 /* Test for execute permission. */
-#define F_OK 0 /* Test for existence. */
-#define L_TREE 1 /* Use different tree style */
-#define DEFARCH 0 /* Default to 8086 code */
+char * tmpdir = "";
#else
-#define EXESUF
+char * tmpdir = "/tmp/";
+#endif
+
+int main P((int argc, char **argv));
+void getargs P((int argc, char **argv));
+void add_prefix P((char * path));
+void run_aspreproc P((struct file_list * file));
+void run_preproc P((struct file_list * file));
+void run_unproto P((struct file_list * file));
+void run_compile P((struct file_list * file));
+void run_optim P((struct file_list * file));
+void run_as P((struct file_list * file));
+void run_link P((void));
+void command_reset P((void));
+void command_opt P((char * option));
+void command_arch P((void));
+void command_opts P((int opykey));
+void newfilename P((struct file_list * file, int last_stage, int new_extn, int use_o));
+void run_unlink P((void));
+void append_file P((char * filename, int ftype));
+void append_option P((char * option, int otype));
+char * expand_tilde P((char * str));
+void * xalloc P((int size));
+void Usage P((void));
+void fatal P((char * why));
+char * copystr P((char * str));
+char * catstr P((char * str, char * str2));
+#ifdef L_TREE
+void reset_localprefix P((void));
#endif
+void run_command P((struct file_list * file));
-#if defined(__minix) || defined(__BCC__)
-#define realpath(x,y) 0
+#ifndef LOCALPREFIX
+#define LOCALPREFIX /usr
+#endif
+char * localprefix = QUOT(LOCALPREFIX);
+#ifndef L_TREE
+char * default_include = "-I~/include";
+char * default_libdir0 = "-L~/lib/bcc/i86/";
+char * default_libdir3 = "-L~/lib/bcc/i386/";
+char * optim_rules = "-d~/lib/bcc/i86";
+#else
+char * default_include = "-I~/include";
+char * default_libdir0 = "-L~/lib/";
+char * default_libdir3 = "-L~/lib/i386/";
+char * optim_rules = "-d~/lib";
#endif
-#define BAS86
-#define BCC86
+char devnull[] = "/dev/null";
+char * exec_prefixs[] = {
-#define AS "as86" EXESUF
-#define CC1 "bcc-cc1" EXESUF
-#define CC1_MINUS_O_BROKEN FALSE
-#define CPP "bcc-cc1" EXESUF
-#define CPPFLAGS "-E"
-#define GCC "gcc"
-#define LD "ld86" EXESUF
-#define UNPROTO "unproto" EXESUF
-#define OPTIM "copt" EXESUF
+ /* Place fillers for dynamic fill */
+ devnull, devnull, devnull, devnull, devnull,
-#ifdef L_TREE
-#define STANDARD_CRT0_0_PREFIX "~/lib/"
-#define STANDARD_CRT0_3_PREFIX "~/lib/i386/"
-#define STANDARD_EXEC_PREFIX "~/lib/"
-#define STANDARD_EXEC_PREFIX_2 "~/bin/"
-#define DEFAULT_INCLUDE "-I~/include"
-#define DEFAULT_LIBDIR0 "-L~/lib/"
-#define DEFAULT_LIBDIR3 "-L~/lib/i386/"
-#define OPTIM_RULES "-d~/lib"
-#else
-#define STANDARD_CRT0_0_PREFIX "~/lib/bcc/i86/"
-#define STANDARD_CRT0_3_PREFIX "~/lib/bcc/i386/"
-#define STANDARD_EXEC_PREFIX "~/lib/bcc/"
+ "~/lib/bcc/",
#ifdef BINDIR
-#define STANDARD_EXEC_PREFIX_2 QUOT(BINDIR) "/"
-#else
-#define STANDARD_EXEC_PREFIX_2 "/usr/bin/"
+ QUOT(BINDIR) "/",
#endif
-#define DEFAULT_INCLUDE "-I~/include"
-#define DEFAULT_LIBDIR0 "-L~/lib/bcc/i86/"
-#define DEFAULT_LIBDIR3 "-L~/lib/bcc/i386/"
-#define OPTIM_RULES "-d~/lib/bcc/i86"
+ "~/lib/",
+ "~/bin/",
+ "/usr/bin/",
+ 0
+};
+
+char * libc = "-lc";
+
+int
+main(argc, argv)
+int argc;
+char ** argv;
+{
+ struct file_list * next_file;
+
+ progname = argv[0];
+#ifdef L_TREE
+ reset_localprefix();
#endif
+ getargs(argc, argv);
-#ifdef CCC
-#undef BCC86
-#undef CC1
-#define CC1 "c386"
-#undef CC1_MINUS_O_BROKEN
-#define CC1_MINUS_O_BROKEN TRUE
-#undef STANDARD_CRT0_0_PREFIX
-#undef STANDARD_CRT0_3_PREFIX
-#define STANDARD_CRT0_PREFIX "~/lib/i386/"
-#endif /* CCC */
+ default_include = expand_tilde(default_include);
+ default_libdir0 = expand_tilde(default_libdir0);
+ default_libdir3 = expand_tilde(default_libdir3);
+ optim_rules = expand_tilde(optim_rules);
-#ifdef MC6809
-#undef BAS86
-#undef BCC86
-#undef CRT0
-#undef GCC
-#undef STANDARD_CRT0_0_PREFIX
-#undef STANDARD_CRT0_3_PREFIX
-#undef STANDARD_EXEC_PREFIX
-#define STANDARD_EXEC_PREFIX "~/lib/bcc/m09/"
-#endif /* MC6809 */
-
-#define ALLOC_UNIT 16 /* allocation unit for arg arrays */
-#define DIRCHAR '/'
-#define START_ARGS 4 /* number of reserved args */
-
-typedef unsigned char bool_T; /* boolean: TRUE if nonzero */
-
-struct arg_s
+ if (opt_v>1) { command.cmd = ""; command_reset(); }
+
+ for(next_file = files; next_file && !error_count; next_file = next_file->next)
+ {
+ if (next_file->filetype == 'o') continue;
+
+ if (opt_V)
+ fprintf(stderr, "%s:\n", next_file->file);
+
+ /* Assembler that's not to be optimised. */
+ if (do_preproc && next_file->filetype == 'S') run_aspreproc(next_file);
+ if (do_as && next_file->filetype == 's') run_as(next_file);
+
+ /* C source */
+ if (do_preproc && next_file->filetype == 'c') run_preproc(next_file);
+ if (do_unproto && next_file->filetype == 'i') run_unproto(next_file);
+ if (do_compile && next_file->filetype == 'i') run_compile(next_file);
+ if (do_optim && next_file->filetype == 's') run_optim(next_file);
+ if (do_as && next_file->filetype == 's') run_as(next_file);
+
+ if (next_file->filetype == '~') error_count++;
+ }
+
+ if (do_link && !error_count)
+ run_link();
+
+ run_unlink();
+ exit(error_count>0);
+}
+
+char *
+copystr(str)
+char * str;
{
- char *prog;
- bool_T minus_O_broken;
- int argc;
- char **argv;
- unsigned nr_allocated;
-};
+ return strcpy(xalloc(strlen(str)+1), str);
+}
-struct prefix_s
+char *
+catstr(str, str2)
+char * str, * str2;
{
- char *name;
- struct prefix_s *next;
-};
+ return strcat(strcpy(xalloc(strlen(str)+strlen(str2)+1), str), str2);
+}
-PRIVATE struct arg_s asargs = { AS, };
-PRIVATE struct arg_s ccargs = { CC1, CC1_MINUS_O_BROKEN, };
-PRIVATE struct arg_s cppargs = { CPP, };
-PRIVATE struct arg_s unprotoargs = { UNPROTO, TRUE };
-PRIVATE struct arg_s optargs = { OPTIM };
-PRIVATE struct prefix_s exec_prefix;
-PRIVATE struct arg_s ldargs = { LD, };
-#ifdef BAS86
-PRIVATE struct arg_s ldrargs = { LD, };
-#endif
-PRIVATE char *progname;
-PRIVATE bool_T runerror; /* = FALSE */
-PRIVATE struct arg_s tmpargs; /* = empty */
-PRIVATE char *tmpdir;
-PRIVATE unsigned verbosity; /* = 0 */
-
-PRIVATE char * localprefix = QUOT(LOCALPREFIX);
-
-#ifdef REDECLARE_STDC_FUNCTIONS
-void exit P((int status));
-char *getenv P((const char *name));
-void *malloc P((size_t size));
-void *realloc P((void *ptr, size_t size));
-void (*signal P((int sig, void (*func) P((int sig))))) P((int sig));
-char *strcpy P((char *dest, const char *src));
-size_t strlen P((const char *s));
-char *strrchr P((const char *s, int c));
+void
+run_aspreproc(file)
+struct file_list * file;
+{
+ if (opt_arch<5) command.cmd = CPPBCC;
+ else command.cmd = CPP;
+ command_reset();
+ newfilename(file, !do_as, 's', (opt_arch<5));
+ if (opt_arch<5)
+ command_opt("-E");
+ command_opts('p');
+ command_opt("-D__ASSEMBLER__");
+#if 0
+ if (!opt_I)
+ command_opt(default_include);
#endif
+ command_arch();
+ run_command(file);
+}
-#ifdef REDECLARE_POSIX_FUNCTIONS
-int access P((const char *path, int amode));
-int execv P((const char *path, char * const *argv));
-int execve P((const char *path, char * const *argv, char * const envp));
-pid_t fork P((void));
-pid_t getpid P((void));
-int unlink P((const char *path));
-pid_t wait P((int *status));
-ssize_t write P((int fd, const void *buf, size_t nbytes));
-#endif
+void
+run_preproc(file)
+struct file_list * file;
+{
+ int last_stage = 0;;
-int main P((int argc, char **argv));
+ if (opt_arch<5) command.cmd = CPPBCC;
+ else command.cmd = CPP;
+ command_reset();
-FORWARD void addarg P((struct arg_s *argp, char *arg));
-FORWARD void adddefine P((char *arg));
-FORWARD void addprefix P((struct prefix_s *prefix, char *name));
-FORWARD char *expand_tilde P((char * str, int canfree));
-FORWARD void fatal P((char *message));
-FORWARD char *fixpath P((char *path, struct prefix_s *prefix, int mode));
-FORWARD void killtemps P((void));
-FORWARD void *my_malloc P((unsigned size, char *where));
-FORWARD char *my_mktemp P((void));
-FORWARD void my_unlink P((char *name));
-FORWARD void outofmemory P((char *where));
-FORWARD int run P((char *in_name, char *out_name, struct arg_s *argp));
-#ifdef L_TREE
-FORWARD void reset_localprefix P((void));
-#endif
-FORWARD void set_trap P((void));
-FORWARD void show_who P((char *message));
-FORWARD void startarg P((struct arg_s *argp));
-FORWARD char *stralloc P((char *s));
-FORWARD char *stralloc2 P((char *s1, char *s2));
-FORWARD void trap P((int signum));
-FORWARD void writen P((void));
-FORWARD void writes P((char *s));
-FORWARD void writesn P((char *s));
-FORWARD void linux_patch P((char * fname));
+ if (!opt_e && !do_optim && !do_as ) last_stage =1;
+ if (opt_e && !do_unproto && !do_compile ) last_stage =1;
-#ifdef __BCC__
-char ** minienviron[] = {
- "PATH=/bin:/usr/bin",
- "SHELL=/bin/sh",
- 0
-};
-#endif
+ newfilename(file, last_stage, (opt_e?'i':'s'), (opt_arch<5));
-PUBLIC int main(argc, argv)
-int argc;
-char **argv;
+ if (opt_e && opt_arch<5) command_opt("-E");
+
+ command_opts('p');
+ if (!opt_e)
+ {
+ command_opts('c');
+ if (opt_arch<5 && !do_as)
+ command_opt("-t");
+ }
+
+ if (!opt_I)
+ command_opt(default_include);
+
+ command_arch();
+
+ run_command(file);
+}
+
+void
+run_unproto(file)
+struct file_list * file;
{
- char *arg;
- int add_default_inc = 1;
- int add_default_lib = 1;
- int argcount = argc;
- bool_T *argdone = my_malloc((unsigned) argc * sizeof *argdone, "argdone");
- bool_T as_only = FALSE;
- char *basename;
-#ifdef BCC86
-#ifdef DEFARCH
- bool_T bits32 = (DEFARCH != 0);
-#else
- bool_T bits32 = sizeof (char *) >= 4;
-#endif
- char *bits_arg;
+ command.cmd = UNPROTO;
+ command_reset();
+ newfilename(file, !do_compile, 'i', 0);
+ command_opts('u');
+
+ run_command(file);
+}
+
+void
+run_compile(file)
+struct file_list * file;
+{
+ if (opt_arch == 3) command.cmd = CC1C386;
+ else if (opt_arch<5) command.cmd = CC1BCC;
+ else command.cmd = CC1;
+ command_reset();
+ newfilename(file, !(do_optim || do_as), 's', (opt_arch != 3 && opt_arch<5));
+
+ command_opts('c');
+
+ command_arch();
+
+ run_command(file);
+}
+
+void
+run_optim(file)
+struct file_list * file;
+{
+ char buf[32];
+ if (opt_arch<5) command.cmd = OPTIM;
+ else command.cmd = OPT;
+ command_reset();
+ newfilename(file, !do_as, 's', 1);
+ command_opt("-c!");
+ if (opt_O)
+ {
+ sprintf(buf, "-huse16 %c86", opt_O);
+ command_opt(buf);
+ }
+ command_opt(optim_rules);
+
+ command_opt("rules.start");
+ command_opts('o');
+ if (opt_O)
+ {
+ sprintf(buf, "rules.%c86", opt_O);
+ command_opt(buf);
+ }
+ command_opt("rules.86");
+ command_opt("rules.end");
+
+ run_command(file);
+}
+
+void
+run_as(file)
+struct file_list * file;
+{
+ char * buf;
+ switch(opt_arch)
+ {
+ case 0: case 1: case 2:
+ command.cmd = AS86; break;
+ case 4: command.cmd = AS09; break;
+ default: command.cmd = AS; break;
+ }
+ command_reset();
+ newfilename(file, (!do_link && opt_arch!=2), 'o', 1);
+ if (opt_arch==3)
+ command_opt("-j");
+ if (opt_arch<5)
+ command_opt("-u");
+ command_opts('a');
+ if (opt_W)
+ command_opt("-w-");
+ else
+ command_opt("-w");
+ command_arch();
+ command_opt("-n");
+ buf = catstr(file->name, ".s");
+ command_opt(buf);
+ free(buf);
+
+ run_command(file);
+
+ if (opt_arch == 2)
+ {
+ command.cmd = LD86;
+ command_reset();
+ newfilename(file, !do_link, 'o', 1);
+ command_opt("-r");
+ run_command(file);
+ }
+}
+
+void
+run_link()
+{
+ struct file_list * next_file;
+
+ switch(opt_arch)
+ {
+ case 0: case 1:
+ command.cmd = LD86; break;
+ case 2: command.cmd = GCC; break;
+ case 4: command.cmd = LD09; break;
+ default: command.cmd = LD; break;
+ }
+ command_reset();
+ if (executable_name == 0) executable_name = "a.out";
+
+ command_opt("-o");
+ command_opt(executable_name);
+
+ command_opts('l');
+ if (opt_arch != 2)
+ {
+ if (opt_arch == 0 && !opt_i)
+ command_opt("-i");
+
+ if (!opt_L)
+ {
+ if (opt_arch==1) command_opt(default_libdir3);
+ else command_opt(default_libdir0);
+ }
+ command_arch();
+
+ if (!opt_x)
+ command_opt("-C0");
+ }
+
+ for(next_file = files; next_file; next_file = next_file->next)
+ command_opt(next_file->file);
+
+ if (opt_arch != 2)
+ command_opt(libc);
+ run_command(0);
+}
+
+void
+command_reset()
+{
+#ifndef MAXPATHLEN
+#define MAXPATHLEN 1024
#endif
- bool_T cc_only = FALSE;
- bool_T ansi_pass = FALSE;
-#ifdef CCC
- bool_T cpp_pass = TRUE;
+ char buf[MAXPATHLEN];
+ char ** prefix;
+
+ if (command.arglist)
+ {
+ int i;
+ for(i=0; i<command.maxargs; i++)
+ if(command.arglist[i])
+ free(command.arglist[i]);
+ free(command.arglist);
+ }
+ command.arglist = 0;
+ command.numargs = 1;
+ command.maxargs = 20;
+
+ command.arglist = xalloc(command.maxargs*sizeof(char**));
+ command.arglist[0] = copystr(command.cmd);
+
+ if (command.fullpath) free(command.fullpath);
+ command.fullpath = 0;
+
+ /* Search for the exe, nb as this will probably be called from 'make'
+ * there's not much point saving this.
+ */
+ for(prefix=exec_prefixs; *prefix; prefix++)
+ {
+ char * p;
+ if (*prefix == devnull) continue;
+
+ p = strchr(*prefix, '~');
+ if (!p) strcpy(buf, *prefix);
+ else
+ {
+ memcpy(buf, *prefix, p-*prefix);
+ buf[p-*prefix] = 0;
+
+ strcat(buf, localprefix);
+ strcat(buf, p+1);
+ }
+ strcat(buf, command.cmd);
+
+ if (!*command.cmd)
+ fprintf(stderr, "PATH+=%s\n", buf);
+ else if (access(buf, X_OK) == 0)
+ {
+ command.fullpath = copystr(buf);
+ break;
+ }
+ }
+ if (!command.fullpath)
+ command.fullpath = copystr(command.cmd);
+}
+
+void
+command_opt(option)
+char * option;
+{
+ if (command.maxargs <= command.numargs+1) {
+ char ** newbuf = xalloc(command.maxargs*2*sizeof(char**));
+ memcpy(newbuf, command.arglist, command.maxargs*sizeof(char**));
+ command.maxargs *= 2;
+ free(command.arglist);
+ command.arglist = newbuf;
+ }
+
+ command.arglist[command.numargs++] = copystr(option);
+}
+
+void
+command_arch()
+{
+ if (opt_arch==0) command_opt("-0");
+ if (opt_arch==1) command_opt("-3");
+ if (opt_arch==2) command_opt("-3");
+}
+
+void
+command_opts(optkey)
+int optkey;
+{
+ struct opt_list * ol;
+ for(ol=options; ol; ol=ol->next)
+ if (ol->opttype == optkey)
+ command_opt(ol->opt);
+}
+
+void newfilename(file, last_stage, new_extn, use_o)
+struct file_list * file;
+int last_stage;
+int new_extn;
+int use_o;
+{
+ file->filetype = new_extn;
+ if (file->oldfile) free(file->oldfile);
+ file->oldfile = file->file;
+ file->file = 0;
+
+ if (last_stage) {
+ if (executable_name)
+ file->file = copystr(executable_name);
+ else
+ {
+ char buf[4];
+ buf[0] = '.';
+ buf[1] = file->filetype;
+ buf[2] = 0;
+ file->file = catstr(file->name, buf);
+ }
+ }
+ else
+ {
+ char buf[16];
+#ifdef MSDOS
+ sprintf(buf, "$$%05d$", dyn_count++);
#else
- bool_T cpp_pass = FALSE;
+ sprintf(buf, "$$%04d%05d", dyn_count++, getpid());
#endif
- char *libc = "-lc";
+ file->file = catstr(tmpdir, buf);
+ }
+
+ command_opt(file->oldfile);
+ /* *.i files go to the stdout */
+ if (last_stage && file->filetype == 'i') return;
+ if (use_o) command_opt("-o");
+ command_opt(file->file);
+}
+
+void
+run_unlink()
+{
+ int i;
+ for(i=0; i<dyn_count; i++)
+ {
+ char buf[16];
+ char * p;
#ifdef MSDOS
- char major_mode = 'd';
+ sprintf(buf, "$$%05d$", i);
#else
- char major_mode = 0;
-#endif
- bool_T has_crt0 = TRUE;
- bool_T debug = FALSE;
- bool_T echo = FALSE;
- unsigned errcount = 0;
- char ext;
- char *f_out = NUL_PTR;
-#ifdef BAS86
- bool_T gnu_objects = FALSE;
-#endif
- bool_T aswarn = FALSE;
- char *in_name;
- int length;
- unsigned ncisfiles = 0;
- unsigned nifiles = 0;
- unsigned npass_specs;
- bool_T optimize = FALSE;
- char *optflags = 0;
- char *out_name;
- bool_T profile = FALSE;
- bool_T prep_only = FALSE;
- bool_T prep_line_numbers = FALSE;
- bool_T compiler_warnings = TRUE;
- int status;
- char *temp;
- bool_T patch_exe = FALSE; /* Hackish patch to convert minix i386->OMAGIC */
-
- progname = argv[0];
- addarg(&cppargs, CPPFLAGS);
-#ifdef CCC
- addarg(&asargs, "-j");
-#endif
- addarg(&asargs, "-u");
-#ifdef BAS86
- addarg(&ldrargs, "-r");
- addarg(&ldrargs, "-N"); /* GCC uses native objects */
- /* GCC also uses 386 how to add -3 too ? */
- addarg(&optargs, "-c!");
- optflags = stralloc("start");
+ sprintf(buf, "$$%04d%05d", i, getpid());
#endif
+ p = catstr(tmpdir, buf);
+ if (opt_v>1)
+ fprintf(stderr, "rm %s\n", p);
+ if (opt_v>2)
+ continue;
+ if (unlink(p) < 0)
+ {
+ if (error_count==0 || opt_v>1)
+ fprintf(stderr, "Error unlinking %s\n", p);
+ error_count++;
+ }
+ free(p);
+ }
+}
-#ifdef L_TREE
- reset_localprefix();
-#endif
- /* Pass 1 over argv to gather compile options. */
- for (; --argc != 0;)
- {
- arg = *++argv;
- *++argdone = TRUE;
- if (arg[0] == '-' && arg[1] != 0 && arg[2] == 0)
- switch (arg[1])
- {
-#ifdef BCC86
- case '0':
- bits32 = FALSE;
- break;
- case '3':
- bits32 = TRUE;
- break;
-#endif
- case 'E':
- prep_only = prep_line_numbers = cpp_pass = TRUE;
- break;
-#ifdef BAS86
- case 'G':
- gnu_objects = TRUE;
- add_default_lib = 0;
- break;
-#endif
- case 'P':
- prep_only = cpp_pass = TRUE;
- prep_line_numbers = FALSE;
- break;
- case 'O':
- optimize = TRUE;
- temp = optflags;
- optflags=stralloc2(optflags,",86");
- free(temp);
- break;
- case 'S':
- cc_only = TRUE;
-#ifndef CCC
- addarg(&ccargs, "-t");
-#endif
- break;
- case 'V':
- echo = TRUE;
- break;
- case 'c':
- as_only = TRUE;
- break;
- case 'e':
- cpp_pass = TRUE;
- break;
- case 'g':
- debug = TRUE; /* unsupported */
- break;
- case 'o':
- if (argc <= 1)
- {
- ++errcount;
- show_who("output file missing after -o\n");
- }
- else
- {
- argc--;
- if (f_out != NUL_PTR)
- show_who("more than one output file\n");
- f_out = *++argv;
- *++argdone = TRUE;
- }
- break;
- case 'p':
- profile = TRUE;
- break;
- case 'v':
- ++verbosity;
- break;
- case 'w':
- compiler_warnings = FALSE;
- aswarn = FALSE;
- break;
- case 'W':
- aswarn = TRUE;
- break;
- case 'x':
- has_crt0 = FALSE;
- break;
- case 'I':
- add_default_inc = 0;
- break;
- case 'L':
- add_default_lib = 0;
- break;
-
- default:
- *argdone = FALSE;
- break;
- }
- else if (arg[0] == '-')
- switch (arg[1])
- {
- case 'a':
- if (!strcmp(arg, "-ansi"))
- {
- ansi_pass=TRUE;
- cpp_pass=TRUE;
- /* NOTE I'm setting this to zero, this isn't a _real_ STDC */
- adddefine("-D__STDC__=0");
- }
- break;
- case 't':
- addarg(&asargs, "-t");
- addarg(&asargs, arg+2);
- break;
- case 'A':
- addarg(&asargs, arg + 2);
- break;
- case 'B':
- addprefix(&exec_prefix, arg + 2);
- break;
- case 'C':
- addarg(&ccargs, arg + 2);
- break;
- case 'D':
- case 'I':
- case 'U':
- adddefine(arg);
- break;
- case 'X':
- addarg(&ldargs, arg + 2);
- break;
- case 'L':
- addarg(&ldargs, arg);
- break;
- case 'M':
- major_mode=arg[2];
- break;
-
- case 'O':
- optimize = TRUE;
- temp=optflags; optflags=stralloc2(optflags,","); free(temp);
- temp=optflags; optflags=stralloc2(optflags,arg+2); free(temp);
- if( arg[3] == 0 && ( arg[2] >= '1' && arg[2] <= '3' ))
- {
- temp=optflags;
- optflags=stralloc2(optflags,"86,86");
- free(temp);
- switch(arg[2])
- {
- case '1': addarg(&optargs, "-huse16 186"); break;
- case '2': addarg(&optargs, "-huse16 286"); break;
- case '3': addarg(&optargs, "-huse16 386"); break;
- }
- }
- break;
- case 'P':
- addarg(&cppargs, arg + 2);
- break;
- case 'Q':
- addarg(&ccargs, arg);
- break;
- case 'T':
- tmpdir = arg + 2;
- break;
- default:
- *argdone = FALSE;
- break;
- }
- else
- {
- ++nifiles;
- *argdone = FALSE;
- length = strlen(arg);
- if (length >= 2 && arg[length - 2] == '.'
- && ((ext = arg[length - 1]) == 'c' || ext == 'i' || ext == 'S'
- || ext == 's'))
- ++ncisfiles;
- }
- }
- npass_specs = prep_only + cc_only + as_only;
- if (npass_specs != 0)
- {
- if (npass_specs > 1)
- {
- ++errcount;
- show_who("more than 1 option from -E -P -S -c\n");
- }
- if (f_out != NUL_PTR && ncisfiles > 1)
- {
- ++errcount;
- show_who("cannot have more than 1 input with non-linked output\n");
+void
+getargs(argc, argv)
+int argc;
+char ** argv;
+{
+ int ar;
+ char * pflag = 0;
+ int control_count = 0;
+ int exe_count = 0;
+
+ for(ar=1; ar<argc; ) if (argv[ar][0] != '-')
+ {
+ append_file(argv[ar++], 0);
+ file_count++;
+ }
+ else
+ {
+ int opt;
+ int used_arg = 1, inc_ar=0;
+ char * opt_arg;
+
+ if (argv[ar][2]) opt_arg = argv[ar]+2;
+ else
+ {
+ inc_ar++;
+ if (argv[ar+1]) opt_arg = argv[ar+1];
+ else
+ {
+ inc_ar++;
+ opt_arg = "ERROR";
+ }
+ }
+ /* Special case -? is different from -?abcdef */
+ if(!pflag && argv[ar][2] == 0) switch(argv[ar][1])
+ {
+ case 'a': case 'L': case 'M': case 'O': case 'P': case 'Q':
+ pflag = argv[ar]+1;
+ used_arg = 0;
+ break;
+ }
+ /* Options that need an argument */
+ if(!pflag) switch(argv[ar][1])
+ {
+ case 'a':
+ if(strcmp(argv[ar], "-ansi") == 0) {
+ do_unproto = 1;
+ opt_e = 1;
+ /* NOTE I'm setting this to zero, this isn't a _real_ STDC */
+ append_option("-D__STDC__=0", 'p');
+ }
+ else
+ Usage();
+ break;
+
+ case 't':
+ append_option("-t", 'a');
+ /*FALLTHROUGH*/
+ case 'A':
+ append_option(opt_arg, 'a');
+ break;
+ case 'C':
+ append_option(opt_arg, 'c');
+ break;
+ case 'P':
+ append_option(opt_arg, 'p');
+ break;
+ case 'X':
+ append_option(opt_arg, 'l');
+ break;
+
+ case 'L':
+ append_option(argv[ar], 'l');
+ break;
+
+ case 'Q':
+ append_option(argv[ar], 'c');
+ break;
+
+ case 'O':
+ do_optim=1;
+ if (!opt_arg[1] && ( opt_arg[0] >= '1' && opt_arg[0] <= '3' ))
+ opt_O = opt_arg[0];
+ else
+ {
+ char * p = xalloc(strlen(opt_arg)+8);
+ strcpy(p, "rules.");
+ strcat(p, opt_arg);
+ append_option(p, 'o');
+ free(p);
+ }
+ break;
+
+ case 'o':
+ exe_count++;
+ executable_name = opt_arg;
+ break;
+
+ case 'B':
+ add_prefix(opt_arg);
+ break;
+
+ case 'I':
+ case 'D':
+ case 'U':
+ append_option(argv[ar], 'p');
+ break;
+
+ case 'T':
+ tmpdir = catstr(opt_arg, "/");
+ break;
+
+ case 'M':
+ if (opt_arg[1]) Usage();
+ opt_M = *opt_arg;
+ break;
+
+ default:
+ pflag = argv[ar]+1;
+ used_arg = 0;
+ break;
+ }
+ /* Singleton flags */
+ if(pflag) switch(opt = *pflag++)
+ {
+ case 'P':
+ append_option("-P", 'p');
+ /*FALLTHROUGH*/
+ case 'E':
+ control_count++;
+ do_compile = do_link = do_as = 0;
+ opt_e = 1;
+ break;
+ case 'S':
+ control_count++;
+ do_as = do_link = 0;
+ break;
+ case 'c':
+ control_count++;
+ do_link = 0;
+ break;
+ case 'O':
+ do_optim=1;
+ break;
+
+ case 'G': opt_M = 'G'; break;
+
+ case 'v': opt_v++; break;
+ case 'V': opt_V++; break;
+ case 'e': opt_e++; break;
+ case 'x': opt_x++; break;
+ case 'I': opt_I++; break;
+ case 'L': opt_L++; break;
+ case 'i': opt_i++; break;
+
+ case 'W': opt_W++; break;
+
+ case '0': opt_arch=0; opt_M='x'; break;
+ case '3': opt_arch=1; opt_M='x'; break;
+
+ case 'w': /*IGNORED*/ break;
+ case 'g': /*IGNORED*/ break;
+ case 'f': /*IGNORED*/ break;
+ case 'p': /*IGNORED*/ break;
+
+ default:
+ if (pflag == argv[ar]+2) {
+ /* Special; unknown options saved as flags for the linker */
+ append_file(argv[ar], 'o');
+ pflag = 0;
}
- }
- if (nifiles == 0)
- {
- ++errcount;
- show_who("no input files\n");
- }
- if (errcount != 0)
- exit(1);
-
-#ifdef BCC86
- if(!major_mode && !bits32) major_mode='n';
- switch(major_mode)
- {
- case 'd': /* DOS compile */
- bits32 = FALSE;
- libc= "-ldos";
- adddefine("-D__MSDOS__");
- addarg(&ldargs, "-d");
- addarg(&ldargs, "-T100");
- break;
-
- case 'n': /* Normal Linux-86 */
- bits32 = FALSE;
- libc= "-lc";
- adddefine("-D__ELKS__");
- adddefine("-D__unix__");
- break;
-
- case 'f': /* Caller saves+ax is first arg */
- bits32 = FALSE;
- libc= "-lc_f";
- adddefine("-D__ELKS__");
- adddefine("-D__unix__");
- addarg(&ccargs, "-f");
- addarg(&ccargs, "-c");
- break;
-
- case 'c': /* Just caller saves, normal C-lib is ok */
- bits32 = FALSE;
- libc= "-lc";
- adddefine("-D__ELKS__");
- adddefine("-D__unix__");
- addarg(&ccargs, "-c");
- break;
-
- case 's': /* Standalone executable */
- bits32 = FALSE;
- libc= "-lc_s";
- adddefine("-D__STANDALONE__");
- break;
-
- case 'l': /* Large Linux compile */
- bits32 = TRUE;
- libc= "-lc";
- adddefine("-D__linux__");
- adddefine("-D__unix__");
-#ifdef __linux__
- addarg(&ldargs, "-N"); /* Make OMAGIC */
-#else
- patch_exe = TRUE;
-#endif
- break;
+ else
+ Usage();
+ }
+ if (!pflag || !*pflag) { ar++; pflag = 0; }
+ if (used_arg && inc_ar) ar++;
+ if (used_arg && inc_ar==2)
+ fatal("Last option requires an argument");
+ }
- case '?':
- case 0:
- break;
+ if (control_count>1)
+ fatal("only one option from -E -P -S -c allowed");
+ if (exe_count>1)
+ fatal("only one -o option allowed");
- default:
- fatal("Fatal error: illegal -M option given");
- }
-#endif
+ if (file_count==0) Usage();
- if( aswarn )
- addarg(&asargs, "-w-");
- else
- addarg(&asargs, "-w");
- if( patch_exe )
- addarg(&ldargs, "-s");
-#ifdef BCC86
- else if( !bits32 )
- addarg(&ldargs, "-i");
-#endif
- if (verbosity > 2)
- {
- show_who("localprefix set to ");
- writesn(localprefix);
- }
- if ((temp = getenv("BCC_EXEC_PREFIX")) != NUL_PTR)
- addprefix(&exec_prefix, temp);
- if( add_default_inc )
- adddefine(DEFAULT_INCLUDE);
- if( add_default_lib )
- {
-#ifdef BCC86
-#ifdef DEFAULT_LIBDIR3
- if( bits32 )
- addarg(&ldargs, DEFAULT_LIBDIR3);
- else
-#endif
+ if (exe_count && file_count != 1 && !do_link)
+ fatal("only one input file for each non-linked output");
+
+ add_prefix(getenv("BCC_EXEC_PREFIX"));
+
+#ifdef MC6809
+ if (opt_M==0) opt_M = '9';
#endif
- addarg(&ldargs, DEFAULT_LIBDIR0);
- }
-
- if (optimize)
- addarg(&asargs, "-O");
- addarg(&optargs, OPTIM_RULES);
- temp=optflags; optflags=stralloc2(optflags,",end"); free(temp);
- for(temp=strtok(optflags,","); temp; temp=strtok((char*)0,","))
- {
- temp = stralloc2("rules.", temp);
- addarg(&optargs, temp);
- }
- addprefix(&exec_prefix, STANDARD_EXEC_PREFIX);
- addprefix(&exec_prefix, STANDARD_EXEC_PREFIX_2);
- cppargs.prog = fixpath(cppargs.prog, &exec_prefix, X_OK);
- ccargs.prog = fixpath(ccargs.prog, &exec_prefix, X_OK);
- asargs.prog = fixpath(asargs.prog, &exec_prefix, X_OK);
- ldargs.prog = fixpath(ldargs.prog, &exec_prefix, X_OK);
-#ifdef BAS86
- ldrargs.prog = fixpath(ldrargs.prog, &exec_prefix, X_OK);
+#ifdef CCC
+ if (opt_M==0) opt_M = '8';
#endif
- unprotoargs.prog=fixpath(unprotoargs.prog, &exec_prefix, X_OK);
- optargs.prog = fixpath(optargs.prog, &exec_prefix, X_OK);
- if (tmpdir == NUL_PTR && (tmpdir = getenv("TMPDIR")) == NUL_PTR)
#ifdef MSDOS
- tmpdir = ".";
-#else
- tmpdir = "/tmp";
+ if (opt_M==0) opt_M = 'd';
#endif
+ if (opt_M==0) opt_M = (opt_arch==1 ?'l':'n');
+ switch(opt_M)
+ {
+ case 'n':
+ append_option("-D__ELKS__", 'p');
+ append_option("-D__unix__", 'p');
+ libc="-lc";
+ break;
+ case 'f':
+ append_option("-D__ELKS__", 'p');
+ append_option("-D__unix__", 'p');
+ append_option("-c", 'p');
+ append_option("-f", 'p');
+ libc="-lc_f";
+ break;
+ case 'c':
+ append_option("-D__ELKS__", 'p');
+ append_option("-D__unix__", 'p');
+ append_option("-c", 'p');
+ libc="-lc";
+ break;
+ case 's':
+ append_option("-D__STANDALONE__", 'p');
+ libc="-lc_s";
+ break;
+ case 'd':
+ append_option("-D__MSDOS__", 'p');
+ libc="-ldos";
+ append_option("-d", 'l');
+ append_option("-T100", 'l');
+ break;
+ case 'l':
+ opt_arch=1;
+ append_option("-D__linux__", 'p');
+ append_option("-D__unix__", 'p');
+ libc="-lc";
+ append_option("-N", 'l');
+ break;
+ case 'G':
+ opt_arch = 2;
+ break;
+ case '8':
+ opt_arch = 3;
+ opt_e = 1;
+ break;
+ case '9':
+ opt_arch = 4;
+ default_libdir0 = "-L~/lib/bcc/m09/";
+ optim_rules = "-d~/lib/bcc/m09";
+ add_prefix("~/lib/bcc/m09/");
+ break;
+ case '0':
+ opt_arch = 5;
+ opt_e = 1;
+ opt_I = 1;
+ opt_L = 1;
+ opt_x = 1;
+ append_option("/lib/crt0.o", 'l');
+ break;
+ }
- if (prep_only && !prep_line_numbers)
- addarg(&cppargs, "-P");
-#ifdef BCC86
-#ifdef STANDARD_CRT0_3_PREFIX
- if (bits32)
- bits_arg = "-3";
- else
-#endif
- bits_arg = "-0";
- addarg(&ccargs, bits_arg);
- addarg(&cppargs, bits_arg);
- addarg(&asargs, bits_arg);
-#ifdef BAS86
- if (!gnu_objects)
- {
- addarg(&ldargs, bits_arg);
- addarg(&ldrargs, bits_arg);
- if( has_crt0 )
- addarg(&ldargs, "-C0");
- }
-#endif /* BAS86 */
-#endif /* BCC86 */
- set_trap();
-
- /* Pass 2 over argv to compile and assemble .c, .i, .S and .s files and
- * gather arguments for linker.
- */
- for (argv -= (argc = argcount) - 1, argdone -= argcount - 1; --argc != 0;)
- {
- arg = *++argv;
- if (!*++argdone)
- {
- length = strlen(arg);
- if (length >= 2 && arg[length - 2] == '.'
- && ((ext = arg[length - 1]) == 'c' || ext == 'i' || ext == 'S'
- || ext == 's'))
- {
- if (echo || verbosity != 0)
- {
- writes(arg);
- writesn(":");
- }
- if ((basename = strrchr(arg, DIRCHAR)) == NUL_PTR)
- basename = arg;
- else
- ++basename;
- in_name = arg;
- if (ext == 'c')
- {
- if (cpp_pass)
- {
- if (prep_only && !ansi_pass)
- out_name = f_out;
- else
- out_name = my_mktemp();
- if (run(in_name, out_name, &cppargs) != 0)
- continue;
- in_name = out_name;
- if (ansi_pass)
- {
- if (prep_only)
- out_name = f_out;
- else
- out_name = my_mktemp();
-
- if (run(in_name, out_name, &unprotoargs) != 0)
- continue;
- in_name=out_name;
- }
- }
- ext = 'i';
- }
- if (ext == 'i')
- {
- if (prep_only)
- continue;
- if (cc_only && !optimize)
- {
- if (f_out != NUL_PTR)
- out_name = f_out;
- else
- {
- out_name = stralloc(basename);
- out_name[strlen(out_name) - 1] = 's';
- }
- }
- else
- out_name = my_mktemp();
- if (run(in_name, out_name, &ccargs) != 0)
- continue;
- in_name = out_name;
- if( optimize )
- {
- if (cc_only)
- {
- if (f_out != NUL_PTR)
- out_name = f_out;
- else
- {
- out_name = stralloc(basename);
- out_name[strlen(out_name) - 1] = 's';
- }
- }
- else
- out_name = my_mktemp();
-
- if (run(in_name, out_name, &optargs) != 0)
- continue;
- in_name = out_name;
- }
- ext = 's';
- }
- if (ext == 'S')
- {
- if (prep_only)
- out_name = f_out;
- else if (cc_only)
- {
- if (f_out != NUL_PTR)
- out_name = f_out;
- else
- {
- out_name = stralloc(basename);
- out_name[strlen(out_name) - 1] = 's';
- }
- }
- else
- out_name = my_mktemp();
- if (run(in_name, out_name, &cppargs) != 0)
- continue;
- in_name = out_name;
- ext = 's';
- }
- if (ext == 's')
- {
- if (prep_only || cc_only)
- continue;
- out_name = stralloc(basename);
- out_name[strlen(out_name) - 1] = 'o';
- if (as_only)
- {
- if (f_out != NUL_PTR)
- out_name = f_out;
- else
- {
- out_name = stralloc(basename);
- out_name[strlen(out_name) - 1] = 'o';
- }
- }
- else
- out_name = my_mktemp();
- addarg(&asargs, "-n");
- arg[length - 1] = 's';
- addarg(&asargs, arg);
-#ifdef BAS86
- if (gnu_objects)
- {
- char *tmp_out_name;
-
- tmp_out_name = my_mktemp();
- status = run(in_name, tmp_out_name, &asargs);
- asargs.argc -= 2;
- if (status != 0)
- continue;
- if (run(tmp_out_name, out_name, &ldrargs) != 0)
- continue;
- }
- else
-#endif
- {
- status = run(in_name, out_name, &asargs);
- asargs.argc -= 2;
- if (status != 0)
- continue;
- }
- ext = 'o';
- in_name = out_name;
- }
- if (ext == 'o')
- {
- if (prep_only || cc_only || as_only)
- continue;
- addarg(&ldargs, in_name);
- }
- }
- else
- addarg(&ldargs, arg);
- }
- }
-
- if (!prep_only && !cc_only && !as_only && !runerror)
- {
- int link_st;
-
- if (f_out == NUL_PTR)
- f_out = "a.out";
-#ifdef BAS86
- if (gnu_objects)
- {
- /* Remove -i and -i-. */
- for (argc = ldargs.argc - 1; argc >= START_ARGS; --argc)
- {
- arg = ldargs.argv[argc];
- if (arg[0] == '-' && arg[1] == 'i'
- && (arg[2] == 0 || (arg[2] == '-' && arg[3] == 0)))
- {
- --ldargs.argc;
- memmove(ldargs.argv + argc, ldargs.argv + argc + 1,
- (ldargs.argc - argc) * sizeof ldargs.argv[0]);
- ldargs.argv[ldargs.argc] = NUL_PTR;
- }
- }
-
- ldargs.prog = fixpath(GCC, &exec_prefix, X_OK);
- link_st = run((char *) NUL_PTR, f_out, &ldargs);
- }
- else
-#endif
- {
- addarg(&ldargs, libc);
- link_st = run((char *) NUL_PTR, f_out, &ldargs);
- }
- if( patch_exe && link_st == 0 )
- linux_patch(f_out);
- }
- if( runerror && f_out != NUL_PTR )
- my_unlink(f_out);
- killtemps();
- return runerror ? 1 : 0;
+ if (do_optim)
+ {
+ if (opt_e)
+ append_option("-O", 'c');
+ append_option("-O", 'p');
+ append_option("-O", 'a');
+ }
}
-PRIVATE void linux_patch(fname)
-char * fname;
+void
+add_prefix(path)
+char * path;
{
-/* OMAGIC */
-
-#define AOUT_MAG "\x07\x01\x64\x00" /* 0x640107L */
-#define ELKS_MAG1 0x10
-#define ELKS_MAG2 0x11 /* -z */
-#define ELKS_MAG3 0x20 /* -i */
-#define ELKS_MAG4 0x21 /* -i -z */
-
-static struct ELKS_exec { /* ELKS a.out header */
- char a_magic1; /* magic number */
- char a_magic2; /* magic number */
- char a_magic3; /* magic number */
- char a_magic4; /* magic number */
- char a_hdrlen; /* length, etc of header */
- char a_hdrlen3[3];
- 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 */
-} instr;
-
-
-static struct aout_exec {
- char a_info[4]; /* Use macros N_MAGIC, etc for access */
- unsigned a_text; /* length of text, in bytes */
- unsigned a_data; /* length of data, in bytes */
- unsigned a_bss; /* length of uninitialized data area, in bytes */
- unsigned a_syms; /* length of symbol table data in file, in bytes */
- unsigned a_entry; /* start address */
- unsigned a_trsize; /* length of relocation info for text, in bytes */
- unsigned a_drsize; /* length of relocation info for data, in bytes */
-} outstr;
-
- int fd;
-
- fd = open(fname, O_RDWR);
- if( fd<0 ) return;
-
- if( read(fd, &instr, sizeof(instr)) != sizeof(instr) )
- {
- writesn("Cannot re-read executable header");
- return;
+ char ** p;
+ if (!path || !*path) return;
+
+ for(p=exec_prefixs; *p; p++) {
+ if( *p == devnull )
+ {
+ *p = path;
+ break;
+ }
}
+ if (!*p) fatal("Too many -B options");
+}
- if( instr.a_hdrlen != 0x20 || instr.a_magic1 != 0x01 ||
- instr.a_magic2 != 0x03 || instr.a_magic4 != 0x10 )
+void append_file (filename, ftype)
+char * filename;
+int ftype;
+{
+ struct file_list * newfile = xalloc(sizeof(struct file_list));
+ char * s;
+ char * name;
+
+ newfile->file = copystr(filename);
+ name = copystr(filename);
+
+ s = strrchr(name, '.');
+
+ if (ftype)
{
- writesn("Executable cannot be converted to OMAGIC - bad magics");
- return;
+ newfile->name = copystr(name);
+ newfile->filetype = ftype;
+ }
+ else if (s && s == name + strlen(name) - 2) {
+ newfile->filetype = s[1];
+ *s = 0;
+ newfile->name = copystr(name);
}
+ else
+ newfile->name = copystr(name);
+ free(name);
- switch((int)(instr.a_magic3))
+ if (newfile->filetype == 0) newfile->filetype = 'o'; /* Objects */
+
+ if (files==0)
+ files = newfile;
+ else
{
- case ELKS_MAG1:
- break;
- case ELKS_MAG2:
- writesn("Executable cannot be converted to OMAGIC (compiled with -z)");
- return;
- case ELKS_MAG3:
- case ELKS_MAG4:
- writesn("Executable file is split I/D, data overlaps text");
- return;
- default:
- writesn("Executable cannot be converted to OMAGIC (unknown type)");
- return;
+ struct file_list * fptr;
+ for(fptr=files; fptr->next; fptr=fptr->next);
+ fptr->next = newfile;
}
+}
- if( instr.a_syms != 0 )
- writesn("Warning: executable file isn't stripped");
-
- memcpy(outstr.a_info, AOUT_MAG, 4);
- outstr.a_text = instr.a_text;
- outstr.a_data = instr.a_data;
- outstr.a_bss = instr.a_bss;
- outstr.a_entry= instr.a_entry;
+void
+append_option (option, otype)
+char * option;
+int otype;
+{
+ struct opt_list * newopt = xalloc(sizeof(struct opt_list));
- lseek(fd, 0L, 0);
+ newopt->opt = copystr(option);
+ newopt->opttype = otype;
- if( write(fd, &outstr, sizeof(outstr)) != sizeof(outstr) )
+ if (options==0)
+ options = newopt;
+ else
{
- writesn("Cannot re-write executable header");
- return;
+ struct opt_list * optr;
+ for(optr=options; optr->next; optr=optr->next);
+ optr->next = newopt;
}
+}
+
+char * expand_tilde(str)
+char * str;
+{
+ char * newstr;
+ char * ptr = strchr(str, '~');
+ if( ptr == 0 ) return copystr(str);
+
+ newstr = xalloc(strlen(str)+strlen(localprefix));
+ if( ptr!=str ) memcpy(newstr, str, ptr-str);
+ strcpy(newstr+(ptr-str), localprefix);
+ strcat(newstr, ptr+1);
+ return newstr;
+}
+
+void *
+xalloc (size)
+int size;
+{
+ void * p = malloc(size);
+ if (!p) fatal("Out of memory");
+ memset(p, '\0', size);
+ return p;
+}
+
+void Usage()
+{
+ fatal("Usage: bcc [-ansi] [-options] [-o output] file [files]");
+}
- close(fd);
+void fatal(str)
+char * str;
+{
+ fprintf(stderr, "%s: Fatal error: %s.\n", progname, str);
+ exit(1);
}
#ifdef L_TREE
#ifdef MSDOS
-PRIVATE void reset_localprefix()
+void reset_localprefix()
{
char *ptr, *temp;
- temp = stralloc(progname);
+ temp = copystr(progname);
if( (ptr = strrchr(temp, '\\')) != 0
&& temp<ptr-4 && strncmp(ptr-4, "\\BIN", 4) == 0 )
{
ptr[-4] = 0;
localprefix = temp;
- if (verbosity > 2)
- {
- show_who("localprefix is now ");
- writesn(localprefix);
- }
}
else
free(temp);
}
#else
-PRIVATE void reset_localprefix()
+void reset_localprefix()
{
char *ptr, *temp;
if( *progname == '/' )
- temp = stralloc(progname);
+ temp = copystr(progname);
else
{
char * s, * d;
ptr = getenv("PATH");
if( ptr==0 || *ptr == 0 ) return;
- ptr = stralloc(ptr);
- temp = stralloc("");
+ ptr = copystr(ptr);
+ temp = copystr("");
for(d=s=ptr; d && *s; s=d)
{
@@ -970,14 +1030,14 @@ PRIVATE void reset_localprefix()
free(temp);
d=strchr(s, ':');
if( d ) *d='\0';
- temp = my_malloc(strlen(progname)+strlen(s)+2, "prefixing");
+ temp = xalloc(strlen(progname)+strlen(s)+2);
strcpy(temp, s);
strcat(temp, "/");
strcat(temp, progname);
if( realpath(temp, buf) != 0 )
{
free(temp);
- temp = stralloc(buf);
+ temp = copystr(buf);
}
if( access(temp, X_OK) == 0 ) break;
d++;
@@ -985,7 +1045,7 @@ PRIVATE void reset_localprefix()
if( s == 0 )
{
free(temp);
- temp = stralloc(progname);
+ temp = copystr(progname);
}
free(ptr);
}
@@ -995,11 +1055,6 @@ PRIVATE void reset_localprefix()
{
ptr[-4] = 0;
localprefix = temp;
- if (verbosity > 2)
- {
- show_who("localprefix is now ");
- writesn(localprefix);
- }
}
else
free(temp);
@@ -1007,355 +1062,71 @@ PRIVATE void reset_localprefix()
#endif
#endif
-PRIVATE char * expand_tilde(str, canfree)
-char * str;
-int canfree;
-{
- char * newstr;
- char * ptr = strchr(str, '~');
- if( ptr == 0 ) return str;
-
- newstr = my_malloc(strlen(str)+strlen(localprefix), "expand tilde");
- if( ptr!=str ) memcpy(newstr, str, ptr-str);
- strcpy(newstr+(ptr-str), localprefix);
- strcat(newstr, ptr+1);
- if( canfree ) free(str);
- return newstr;
-}
-PRIVATE void adddefine(arg)
-char *arg;
+void
+run_command(file)
+struct file_list * file;
{
-#ifndef CCC
- addarg(&ccargs, arg);
+#ifdef __BCC__
+static char ** minienviron[] = {
+ "PATH=/bin:/usr/bin",
+ "SHELL=/bin/sh",
+ 0
+};
#endif
- addarg(&cppargs, arg);
-}
-
-PRIVATE void addarg(argp, arg)
-register struct arg_s *argp;
-char *arg;
-{
- int new_argc;
- char **new_argv;
-
- if (argp->nr_allocated == 0)
- startarg(argp);
- new_argc = argp->argc + 1;
- if (new_argc >= argp->nr_allocated)
- {
- argp->nr_allocated += ALLOC_UNIT;
- new_argv = realloc(argp->argv, argp->nr_allocated * sizeof *argp->argv);
- if (new_argv == NUL_PTR)
- outofmemory("addarg");
- argp->argv = new_argv;
- }
- argp->argv[argp->argc] = expand_tilde(arg, 0);
- argp->argv[argp->argc = new_argc] = NUL_PTR;
-}
-
-PRIVATE void addprefix(prefix, name)
-struct prefix_s *prefix;
-char *name;
-{
- struct prefix_s *new_prefix;
-
- if (prefix->name == NUL_PTR)
- prefix->name = name;
- else
- {
- new_prefix = my_malloc(sizeof *new_prefix, "addprefix");
- new_prefix->name = expand_tilde(name, 0);
- new_prefix->next = NUL_PTR;
- while (prefix->next != NUL_PTR)
- prefix = prefix->next;
- prefix->next = new_prefix;
- }
-}
-
-PRIVATE void fatal(message)
-char *message;
-{
- writesn(message);
- killtemps();
- exit(1);
-}
-
-PRIVATE char *fixpath(path, prefix, mode)
-char *path;
-struct prefix_s *prefix;
-int mode;
-{
- char *ppath;
-
- for (; prefix != NUL_PTR; prefix = prefix->next)
- {
- if (verbosity > 2)
- {
- show_who("searching for ");
- if (mode == R_OK)
- writes("readable file ");
- else
- writes("executable file ");
- }
- ppath = expand_tilde(stralloc2(prefix->name, path), 1);
- if (verbosity > 2)
- writes(ppath);
- if (access(ppath, mode) == 0)
- {
- if (verbosity > 2)
- writesn(" - found.");
- return ppath;
- }
- if (verbosity > 2)
- writesn(" - nope.");
- free(ppath);
- }
- return path;
-}
-
-PRIVATE void killtemps()
-{
- while (tmpargs.argc > START_ARGS)
- my_unlink(tmpargs.argv[--tmpargs.argc]);
-}
-
-PRIVATE void *my_malloc(size, where)
-unsigned size;
-char *where;
-{
- void *block;
-
- if ((block = malloc(size)) == NUL_PTR)
- outofmemory(where);
- return block;
-}
-
-PRIVATE char *my_mktemp()
-{
- char *p;
- unsigned digit;
- unsigned digits;
- char *template;
- static unsigned tmpnum;
-
-#ifdef MSDOS
- digits = 42;
- p = template = stralloc2(tmpdir, "/$$YYYYXX");
-#else
- digits = getpid();
- p = template = stralloc2(tmpdir, "/bccYYYYXXXX");
+ int i, status;
+#ifndef MSDOS
+ void *oqsig, *oisig, *otsig, *ocsig;
#endif
- p += strlen(p);
-
- while (*--p == 'X')
- {
- if ((digit = digits % 16) > 9)
- digit += 'A' - ('9' + 1);
- *p = digit + '0';
- digits /= 16;
- }
- digits = tmpnum;
- while (*p == 'Y')
- {
- if ((digit = digits % 16) > 9)
- digit += 'A' - ('9' + 1);
- *p-- = digit + '0';
- digits /= 16;
- }
- ++tmpnum;
- addarg(&tmpargs, template);
- return template;
-}
-PRIVATE void my_unlink(name)
-char *name;
-{
- if (verbosity > 1)
- {
- show_who("unlinking ");
- writesn(name);
- }
- if (verbosity > 4) return;
- if (unlink(name) < 0)
- {
- if( !runerror || verbosity > 1)
- {
- show_who("error unlinking ");
- writesn(name);
- runerror = TRUE;
- }
- }
-}
-PRIVATE void outofmemory(where)
-char *where;
-{
- show_who("out of memory in ");
- fatal(where);
-}
+ if (opt_v)
+ {
+ fprintf(stderr, "%s", command.fullpath);
+ for(i=1; command.arglist[i]; i++)
+ fprintf(stderr, " %s", command.arglist[i]);
+ fprintf(stderr, "\n");
+ if (opt_v>2) return;
+ }
-PRIVATE int run(in_name, out_name, argp)
-char *in_name;
-char *out_name;
-struct arg_s *argp;
-{
- int arg0;
- int i;
- int status;
-
- arg0 = 0;
- if (in_name == NUL_PTR)
- ++arg0;
- if (out_name == NUL_PTR)
- arg0 += 2;
- else if (argp->minus_O_broken)
- ++arg0;
- if (argp->nr_allocated == 0)
- startarg(argp);
- argp->argv[arg0] = argp->prog;
- i = arg0 + 1;
- if (in_name != NUL_PTR)
- argp->argv[i++] = in_name;
- if (out_name != NUL_PTR)
- {
- if (!argp->minus_O_broken)
- argp->argv[i++] = "-o";
- argp->argv[i++] = out_name;
- }
- if (verbosity != 0)
- {
- for (i = arg0; i < argp->argc; ++i)
- {
- writes(argp->argv[i]);
- writes(" ");
- }
- writen();
- }
- if (verbosity > 4 ) return 0;
#ifdef MSDOS
- status = spawnv(0, argp->prog, argp->argv+arg0);
- if( status<0 )
- {
- show_who("spawn of ");
- writes(argp->prog);
- writesn(" failed");
- }
+ status = spawnv(0, command.fullpath, command.arglist);
+ if (status<0)
+ {
+ fprintf(stderr, "Unable to execute %s\n", command.fullpath);
+ }
#else
- switch (fork())
- {
- case -1:
- show_who("fork failed");
- fatal("");
- case 0:
+ oqsig = signal(SIGQUIT, SIG_IGN);
+ oisig = signal(SIGINT, SIG_IGN);
+ otsig = signal(SIGTERM, SIG_IGN);
+ ocsig = signal(SIGCHLD, SIG_DFL);
+
+ switch(fork())
+ {
+ case -1:
+ fatal("Forking failure");
+ case 0:
#ifdef __BCC__
- execve(argp->prog, argp->argv + arg0, minienviron);
+ execve(command.fullpath, command.arglist, minienviron);
#else
- execv(argp->prog, argp->argv + arg0);
-#endif
- show_who("exec of ");
- writes(argp->prog);
- fatal(" failed");
- default:
- wait(&status);
- if (status & 0xFF)
- {
- writes(argp->prog);
- writesn(": killed by fatal signal");
- }
- }
+ execv(command.fullpath, command.arglist);
#endif
- for (i = tmpargs.argc - 1; i >= START_ARGS; --i)
- if (in_name == tmpargs.argv[i])
- {
- my_unlink(in_name);
- --tmpargs.argc;
- memmove(tmpargs.argv + i, tmpargs.argv + i + 1,
- (tmpargs.argc - i) * sizeof tmpargs.argv[0]);
- tmpargs.argv[tmpargs.argc] = NUL_PTR;
- break;
- }
- if (status != 0)
- {
- runerror = TRUE;
- killtemps();
- }
- return status;
-}
+ fprintf(stderr, "Unable to execute %s.\n", command.fullpath);
+ exit(1);
+ default:
+ wait(&status);
+ if (status&0xFF)
+ {
+ fprintf(stderr, "%s: killed by signal %d\n", command.fullpath, (status&0xFF));
+ }
+ }
-PRIVATE void set_trap()
-{
-#ifdef SIGINT
- signal(SIGINT, trap);
-#endif
-#ifdef SIGQUIT
- signal(SIGQUIT, trap);
-#endif
-#ifdef SIGTERM
- signal(SIGTERM, trap);
+ (void) signal(SIGQUIT, oqsig);
+ (void) signal(SIGINT, oisig);
+ (void) signal(SIGTERM, otsig);
+ (void) signal(SIGCHLD, ocsig);
#endif
+ if (status)
+ file->filetype = '~';
}
-PRIVATE void show_who(message)
-char *message;
-{
-#ifdef MSDOS
- char * ptr;
- ptr = strrchr(progname, '\\');
- if(ptr) ptr++; else ptr = progname;
- writes(ptr);
-#else
- writes(progname);
-#endif
- writes(": ");
- writes(message);
-}
-
-PRIVATE void startarg(argp)
-struct arg_s *argp;
-{
- argp->argv = my_malloc((argp->nr_allocated = ALLOC_UNIT)
- * sizeof *argp->argv, "startarg");
- argp->argc = START_ARGS;
- argp->argv[START_ARGS] = NUL_PTR;
-}
-
-PRIVATE char *stralloc(s)
-char *s;
-{
- return strcpy(my_malloc(strlen(s) + 1, "stralloc"), s);
-}
-
-PRIVATE char *stralloc2(s1, s2)
-char *s1;
-char *s2;
-{
- return strcat(strcpy(my_malloc(
- strlen(s1) + strlen(s2) + 1, "stralloc2"), s1), s2);
-}
-
-PRIVATE void trap(signum)
-int signum;
-{
- signal(signum, SIG_IGN);
- show_who("caught signal");
- fatal("");
-}
-
-PRIVATE void writen()
-{
- writes("\n");
-}
-
-PRIVATE void writes(s)
-char *s;
-{
- write(2, s, strlen(s));
-}
-
-PRIVATE void writesn(s)
-char *s;
-{
- writes(s);
- writen();
-}
diff --git a/bcc/const.h b/bcc/const.h
index 2383a30..a854685 100644
--- a/bcc/const.h
+++ b/bcc/const.h
@@ -25,6 +25,7 @@
#ifndef VERY_SMALL_MEMORY
#define DEBUG /* generate compiler-debugging code */
+#define OPTIMISE /* include optimisation code */
#endif
#ifdef I8088
diff --git a/bcc/function.c b/bcc/function.c
index 6c84975..e3dcd61 100644
--- a/bcc/function.c
+++ b/bcc/function.c
@@ -270,7 +270,12 @@ PRIVATE void out_callstring()
PUBLIC void popframe()
{
+#ifdef STUPIDFRAME
+ poplist(callee1mask); /*XXX: Add if round this */
+ poplist(FRAMEREG);
+#else
poplist(frame1list);
+#endif
}
#endif
@@ -308,7 +313,7 @@ PUBLIC void reslocals()
pushreg(FRAMEREG);
regtransfer(STACKREG, FRAMEREG);
framep = sp;
- pushlist(callee1mask);
+ pushlist(callee1mask); /*XXX: Add if round this */
# else /* not STUPIDFRAME */
# ifdef CANHANDLENOFRAME
if (stackarg || softsp != -frameregsize) /* args or locals */
diff --git a/bcc/gencode.h b/bcc/gencode.h
index 03de445..6c3908b 100644
--- a/bcc/gencode.h
+++ b/bcc/gencode.h
@@ -52,6 +52,7 @@ EXTERN bool_t stackarg; /* nonzero to show function has arg on stack */
#endif
EXTERN struct switchstruct *switchnow; /* currently active switch */
/* depends on NULL init */
+EXTERN bool_t optimise; /* nonzero to add optimisation code */
/* variables to be initialised to nonzero */
diff --git a/bcc/idcc b/bcc/idcc
deleted file mode 100755
index 1dc25b9..0000000
--- a/bcc/idcc
+++ /dev/null
@@ -1,328 +0,0 @@
-#!/bin/ash
-#
-# This is a shell version of the bcc compiler driver. It's a little slower
-# than a C version but overall seems to be a lot cleaner, perhaps a C version
-# based on this might be a good idea ...
-#
-# The compiler works on a 'modal' basis certain flags given to it put the
-# compiler into specific modes, it can only be in one mode for a run.
-#
-# The mode defines the basic passes and specific options that are available
-#
-# To define a mode see the functions 'run_0' and 'run_3' for examples. The
-# variable assignments just above the definitions enable the functions.
-#
-# This script is specifically designed so the there is as little interaction
-# between the modes as is possible.
-#
-# It's run using ash because this appears to be _much_ faster than bash, it's
-# also reasonable with ksh.
-# (On other interpreters I think perl would be too big, but awk might work...)
-#
-
-TMPFIL="/tmp/cc$$"
-trap "rm -f $TMPFIL.* ; exit 1" 1 2 3 15
-TMPCNT=0
-
-FILES=
-OPTS=
-RESEXTN=
-VERBOSE=no
-MULTISRC=no
-
-LDOPTS=
-DESTDEF=no
-LDDEST=a.out
-DEFMODE=0
-
-ccmode=
-LIBPATH="/lib:/usr/lib:/usr/bin"
-
-main() {
- scanargs "$@"
-
- PATH="$LIBPATH:$PATH"
- [ "$EXEC_PREFIX" != "" ] && PATH="$EXEC_PREFIX:$PATH"
-
- rv=0
- LDFILES=
- [ "$MULTISRC" = yes -o "$RESEXTN" = "" ] && DESTDEF=no
-
- for FILE in $FILES
- do
- case "$FILE" in
- *.c ) PASS=cpp ; BASE="`basename $FILE .c`" ;;
- *.s ) PASS=as ; BASE="`basename $FILE .s`" ;;
- * ) PASS=lnk ;;
- esac
-
- NAME="`basename $FILE`"
- DEST="`dirname $FILE`/"
- [ "$DEST" = "./" ] && DEST=
- DEST="$DEST$BASE.$RESEXTN"
- [ "$DESTDEF" = yes ] && DEST="$LDDEST"
-
- STEMP=0 INTEMP=0
- [ "$PASS" = "cpp" ] && { compile $FILE || rv=$? ; }
- [ "$PASS" = "as" ] && { assem $FILE || rv=$? ; }
- if [ "$PASS" = "lnk" ]
- then
- LDFILES="$LDFILES $FILE"
- else
- # If there's a fail can't link - still assembling to temps tho.
- [ "$RESEXTN" = "" ] && RESEXTN=O
- fi
- [ "$STEMP" = 1 ] && rm -f "$SFILE"
- done
-
- [ "$RESEXTN" != "" ] && {
- rm -f $TMPFIL.*
- exit $rv
- }
-
- [ "$VERBOSE" = yes ] && eval "echo \"$LINK\"" 1>&2
- eval "$LINK"
- rv=$?
- rm -f $TMPFIL.*
- exit "$rv"
-}
-
-scanargs() {
- WILDOPT=no
-
- while [ "$#" -gt 0 ]
- do
- case "$1" in
- -[DU]* ) CPPDEFS="$CPPDEFS $1" ;;
- -B?* ) PATH="`echo '.$1:$PATH' | sed 's/...//'`" ;;
- -I?* ) CPPFLAGS="$CPPFLAGS $1" ;;
- -L?* ) LDOPTS="$LDOPTS $1" ;;
- -o ) LDDEST="$2"; DESTDEF=yes ; shift ;;
- -b ) . /usr/lib/idcc/opts_$2 || exit 1; shift ;;
- -E ) RESEXTN=i ;;
- -S ) RESEXTN=s ;;
- -c ) RESEXTN=o ;;
- -v ) VERBOSE=yes ;;
- -l?* ) FILES="$FILES $1" ; MULTISRC=yes ;;
- -* ) OPTS="$OPTS `echo .$1 | sed 's/..//'`" ;;
- * ) [ "$FILES" != "" ] && MULTISRC=yes ; FILES="$FILES $1" ;;
- esac
- shift
- done
-
- while [ "$OPTS" != "" -o "$DEFMODE" != "" ]
- do
- # So they can try again ... with DEFMODE if needed
- MOPTS="$OPTS"
- OPTS=
-
- for opt in $MOPTS
- do
- # Option can be defined only for specific mode so if we haven't seen
- # the mode yet save the opt. If we have check for conflicts too.
- [ "$ccmode" = "" -a "$DEFMODE" != "" ] && {
- eval "[ \"\$opt_$opt\" = yes ]" || { OPTS="$OPTS $opt" ; opt= ; }
- }
- [ "$opt" != "" ] && {
- [ "$ccmode" = "" ] || {
- eval "[ \"\$mode_$opt\" = yes ]" && {
- echo Option "-$opt incompatible with -$ccmode" 1>&2
- exit 2
- }
- }
-
- eval "[ \"\$opt_$opt\" = yes ]" || {
- { eval "[ \"$WILDOPT\" = yes ]" && wild_opt "-$opt" ; } || {
- echo Option '-'$opt unknown for this mode 1>&2
- exit 3
- }
- }
-
- eval "[ \"\$opt_$opt\" = yes ]" && run_$opt
- eval "[ \"\$mode_$opt\" = yes ]" && ccmode="$opt"
- }
- done
- [ "$ccmode" = "" -a "$DEFMODE" != "" ] && OPTS="$DEFMODE $OPTS"
- DEFMODE=
- done
-}
-
-compile() {
- [ -r "$FILE" ] || { echo "Cannot open $FILE" 1>&2 ; return 1 ; }
-
- # Loop for the pass list
- # The CCX variables _are_ expanded again.
-
- ret=1
- for pass in $PASSLIST
- do
- for extn in '' res opt
- do eval "CCX$extn=\"\$CC$pass$extn\""
- done
-
- [ "$CCX" = "" ] && continue;
-
- shuffel "$RESEXTN" $CCXres
- [ "$VERBOSE" = yes ] && eval "echo \"$CCX\"" 1>&2
- eval "$CCX" || return 1
- ret=0
- [ "$CCXres" = "$RESEXTN" ] && break
- done
- [ "$ret" = 1 ] && { echo 'CC configuration error' 1>&2 ; return $ret ; }
-
- [ "$RESEXTN" != "$CCXres" ] && PASS=as
- return 0
-}
-
-assem() {
- [ -r "$FILE" ] || { echo "Cannot open $FILE" 1>&2 ; return 1 ; }
-
- shuffel "$RESEXTN" o
-
- n=
- [ "$ASNAME" != "" ] && n="$ASNAME$NAME"
-
- [ "$VERBOSE" = yes ] && echo "$AS $ASFLAGS $n $SFILE -o $FILE" 1>&2
- $AS $ASFLAGS $n $SFILE -o $FILE || return
-
- [ "$RESEXTN" != "o" ] && PASS=lnk
- return 0
-}
-
-if [ "2" = "$[1+1]" ] ; then inc_tmpcnt() { TMPCNT="$[$TMPCNT+1]" ; }
-else inc_tmpcnt() { TMPCNT="`expr $TMPCNT + 1`" ; }
-fi
-
-shuffel() {
- [ "$STEMP" = 1 ] && rm -f "$SFILE"
-
- SFILE="$FILE"
- STEMP="$INTEMP"
-
- if [ "$1" = "$2" ]
- then
- FILE="$DEST"
- INTEMP=0
- else
- inc_tmpcnt
- FILE="$TMPFIL.$TMPCNT.$2"
- INTEMP=1
- fi
-}
-
-mode_0=yes opt_0=yes
-run_0()
-{
- SYSINC="-I/usr/bcc/include"
- SYSLIB="-L/usr/bcc/lib/bcc/i86/"
- LIBPATH="/usr/bcc/lib/bcc"
- CRT0="-C0"
- LIBS="-lc"
- CGEN='-0'
- DEFS=
-
- CPP="cpp"
-
- PASSLIST=2
- CC2='bcc-cc1 $SYSINC $DEFS $CPPDEFS $CPPFLAGS $CGEN $SFILE -o $FILE'
- CC2res=s
- AS="as86" ASFLAGS='-u -w -0' ASNAME='-n '
- LINK='ld86 $SYSLIB $LDOPTS $LDFLAGS -o $LDDEST $CRT0 $LDFILES $LIBS'
- LDFLAGS='-i -0'
-
- [ "$RESEXTN" = "i" ] && {
- PASSLIST="0"
- CC0='bcc-cc1 $SYSINC $DEFS $CPPDEFS $CPPFLAGS $CGEN $SFILE -E'
- CC0res=i
- }
-
- opt_ansi=yes
- run_ansi()
- {
- PASSLIST="0 1 2"
- CC0='bcc-cc1 $SYSINC $DEFS $CPPDEFS $CPPFLAGS $CGEN $SFILE -o $FILE -E'
- CC0res=k
- CC1res=i CC1='unproto $SFILE $FILE'
- CC2res=s CC2='bcc-cc1 $CGEN $SFILE -o $FILE'
- DEFS='-D__STDC__=0'
- }
- opt_I=yes; run_I() { SYSINC= ; }
- opt_L=yes; run_L() { SYSLIB= ; }
- opt_O=yes; run_O() { echo Warning -O ignored 1>&2 ; }
- opt_Mf=yes; run_Mf() { LIBS=-lc_f ; CGEN='-0 -f -c' ;}
- opt_Md=yes;
- run_Md() { LIBS=-ldos ; DEFS=$DEFS' -D__MSDOS__' LDFLAGS='-i -0 -d' ;}
-
- WILDOPT=yes
- wild_opt()
- {
- case "$1" in
- # For normal CC operation unknowns go to the linker. ie:
- # * ) LDFLAGS="$LDFLAGS $1" ; return 0 ;;
- # But do this instead.
- -[dMizmts] ) LDFLAGS="$LDFLAGS $1" ; return 0 ;;
- -[dMizmt]- ) LDFLAGS="$LDFLAGS $1" ; return 0 ;;
- -T* ) LDFLAGS="$LDFLAGS $1" ; return 0 ;;
- * ) return 1 ;;
- esac
- return 0
- }
-}
-
-mode_3=yes opt_3=yes
-run_3()
-{
- SYSINC="-I/usr/bcc/include"
- SYSLIB="-L/usr/bcc/lib/bcc/i386/"
- LIBPATH="/usr/bcc/lib/bcc"
- CRT0="-C0"
- LIBS="-lc"
- CGEN='-3'
- DEFS=
-
- CPP="cpp"
-
- PASSLIST=2
- CC2='bcc-cc1 $SYSINC $DEFS $CPPDEFS $CPPFLAGS $CGEN $SFILE -o $FILE'
- CC2res=s
- AS="as86" ASFLAGS='-u -w -3' ASNAME='-n '
- LINK='ld86 $SYSLIB $LDOPTS $LDFLAGS -o $LDDEST $CRT0 $LDFILES $LIBS'
- LDFLAGS='-3'
-
- [ "$RESEXTN" = "i" ] && {
- PASSLIST="0"
- CC0='bcc-cc1 $SYSINC $DEFS $CPPDEFS $CPPFLAGS $CGEN $SFILE -E'
- CC0res=i
- }
-
- opt_ansi=yes
- run_ansi()
- {
- PASSLIST="0 1 2"
- CC0='bcc-cc1 $SYSINC $DEFS $CPPDEFS $CPPFLAGS $CGEN $SFILE -o $FILE -E'
- CC0res=k
- CC1res=i CC1='unproto $SFILE $FILE'
- CC2res=s CC2='bcc-cc1 $CGEN $SFILE -o $FILE'
- DEFS='-D__STDC__=0'
- }
- opt_I=yes; run_I() { SYSINC= ; }
- opt_L=yes; run_L() { SYSLIB= ; }
- opt_O=yes; run_O() { echo Warning -O ignored 1>&2 ; }
-
- WILDOPT=yes
- wild_opt()
- {
- case "$1" in
- # For normal CC operation unknowns go to the linker. ie:
- # * ) LDFLAGS="$LDFLAGS $1" ; return 0 ;;
- # But do this instead.
- -[dMizmts] ) LDFLAGS="$LDFLAGS $1" ; return 0 ;;
- -[dMizmt]- ) LDFLAGS="$LDFLAGS $1" ; return 0 ;;
- -T* ) LDFLAGS="$LDFLAGS $1" ; return 0 ;;
- * ) return 1 ;;
- esac
- return 0
- }
-}
-
-main "$@"
diff --git a/bcc/input.c b/bcc/input.c
index 5084663..080c7bc 100644
--- a/bcc/input.c
+++ b/bcc/input.c
@@ -509,6 +509,7 @@ char *argv[];
#endif
case 't': /* print source code in asm output */
case 'w': /* watch location counter */
+ case 'O': /* Optimisation. */
if (arg[2] == 0)
flag[(int)arg[1]] = TRUE;
else if (arg[2] == '-' && arg[3] == 0)
@@ -597,6 +598,11 @@ ts_s_includelist += sizeof *incnew;
definestring("__POS_INDEPENDENT__");
}
#endif
+ if (flag['O'])
+ {
+ optimise = TRUE;
+ definestring("__OPTIMISED__");
+ }
#ifdef NOFLOAT
definestring("__HAS_NO_FLOATS__");
#endif
diff --git a/bcc/preproc.c b/bcc/preproc.c
index 84262e6..62302e8 100644
--- a/bcc/preproc.c
+++ b/bcc/preproc.c
@@ -68,8 +68,11 @@ PRIVATE void asmcontrol()
#endif
asmmode = TRUE;
+ if (expect_statement)
+ return;
+
if (orig_cppmode)
- outstr("#asm\n");
+ outnstr("#asm");
else
{
outnstr("!BCC_ASM");
@@ -126,9 +129,9 @@ PRIVATE void asmcontrol()
}
#endif
if (orig_cppmode)
- outstr("#endasm"); /* nl is done by skipeol */
+ outnstr("#endasm");
else
- outstr("!BCC_ENDASM\n");
+ outnstr("!BCC_ENDASM");
}
/* blanksident() - return nonzero if at blanks followed by an identifier */
@@ -158,6 +161,13 @@ PRIVATE void control()
char sname[NAMESIZE + 1];
sym_t ctlcase;
struct symstruct *symptr;
+ if (ctext && asmmode)
+ {
+ comment();
+ outudec(input.linenumber);
+ outbyte(' ');
+ outline(lineptr);
+ }
sname[0] = '#'; /* prepare for bad control */
sname[1] = 0;
@@ -188,7 +198,13 @@ PRIVATE void control()
switch (ctlcase)
{
case ASMCNTL:
- asmcontrol();
+ if (asmmode)
+ {
+ if (ifstate.ifflag)
+ error(" bad control");
+ }
+ else
+ asmcontrol();
break;
case DEFINECNTL:
define();
@@ -197,6 +213,11 @@ PRIVATE void control()
elsecontrol();
break;
case ENDASMCNTL:
+ if (!asmmode)
+ {
+ if (ifstate.ifflag)
+ error(" bad control");
+ }
asmmode = FALSE;
break;
case ENDIFCNTL:
diff --git a/bcc/scan.c b/bcc/scan.c
index 973bcab..b96093d 100644
--- a/bcc/scan.c
+++ b/bcc/scan.c
@@ -182,7 +182,10 @@ int asm_only;
else
{
docontrol();
- break;
+#ifndef ASM_BARE
+ virtual_nl = 1;
+#endif
+ continue;
}
case SLASH:
gch1();
@@ -431,7 +434,14 @@ PUBLIC void nextsym()
static char lastch;
register char *reglineptr;
- while (TRUE) /* exit with short, fast returns */
+ if (expect_statement && asmmode)
+ {
+ outnstr("!BCC_ASM");
+ dumplocs();
+ cppscan(1);
+ outnstr("!BCC_ENDASM");
+ }
+ else while (TRUE) /* exit with short, fast returns */
{
reglineptr = lineptr;
while ((sym = SYMOFCHAR(*reglineptr)) == WHITESPACE)
@@ -470,7 +480,13 @@ PUBLIC void nextsym()
}
else
{
+ int old_asmmode = asmmode;
docontrol();
+ if (asmmode && !old_asmmode)
+ {
+ sym = SEMICOLON;
+ return;
+ }
break;
}
case FLOATCONST:
diff --git a/bcc/scan.h b/bcc/scan.h
index 98db208..e318e9e 100644
--- a/bcc/scan.h
+++ b/bcc/scan.h
@@ -200,3 +200,6 @@ EXTERN struct symstruct *gsymptr; /* symbol ptr for last identifier */
EXTERN bool_t incppexpr; /* nonzero while scanning cpp expression */
EXTERN sym_t sym; /* current symbol */
extern sym_t symofchar[]; /* table to convert chars to their symbols */
+EXTERN bool_t expect_statement; /* If set #asm needs to clear the recursive
+ * pending operations. ie: if stmts. */
+
diff --git a/bcc/state.c b/bcc/state.c
index 620b553..c14ff7b 100644
--- a/bcc/state.c
+++ b/bcc/state.c
@@ -188,6 +188,7 @@ PUBLIC void compound() /* have just seen "{" */
#endif
spmark = sp;
newlevel();
+ expect_statement++;
decllist();
softsp &= alignmask;
if (sym != RBRACE) /* no need for locals if empty compound */
@@ -195,6 +196,7 @@ PUBLIC void compound() /* have just seen "{" */
returnflag = FALSE;
while (sym != RBRACE && sym != EOFSYM)
statement();
+ expect_statement--;
oldlevel();
if (!returnflag)
{
@@ -233,17 +235,27 @@ PUBLIC void compound() /* have just seen "{" */
PRIVATE void doasm()
{
- lparen();
+ if (sym == LPAREN) nextsym();
if (sym!=STRINGCONST)
error("string const expected");
else {
- nextsym();
- constant.value.s[charptr-constant.value.s]='\0';
outnstr("!BCC_ASM");
- outbyte('\t');
- outnstr(constant.value.s);
+ for(;;)
+ {
+ constant.value.s[charptr-constant.value.s]='\0';
+ outbyte('\t');
+ outnstr(constant.value.s);
+ /* XXX: Need to investigate: wasting memory?
+ *
+ * charptr = constant.value.s;
+ */
+
+ nextsym();
+ if (sym == COMMA) nextsym();
+ if (sym!=STRINGCONST) break;
+ }
outnstr("!BCC_ENDASM");
- rparen();
+ if (sym == RPAREN) nextsym();
semicolon();
}
}
@@ -718,6 +730,10 @@ more:
nextsym();
doif();
break;
+ case ELSESYM:
+ error("unexpected else");
+ nextsym();
+ break;
case WHILESYM:
nextsym();
dowhile();
diff --git a/bootblocks/Makefile b/bootblocks/Makefile
index f54305d..66a87c4 100644
--- a/bootblocks/Makefile
+++ b/bootblocks/Makefile
@@ -25,9 +25,9 @@ encap: $(SSRC:s=v) $(CSRC:c=v) minixhd.v msdos16.v
bootbin: $(SSRC:s=bin) $(CSRC:c=bin) minixhd.bin msdos16.bin minix_elks.bin
MOBJ=monitor.o commands.o i86_funcs.o relocate.o help.o bzimage.o \
- trk_buf.o min_buf.o unix.o fs.o fs_tar.o fs_min.o fs_dos.o cprintf.o
+ trk_buf.o min_buf.o unix.o fs.o fs_tar.o fs_min.o fs_dos.o
MSRC=monitor.c commands.c i86_funcs.c relocate.c help.c bzimage.c \
- trk_buf.c min_buf.c unix.c fs.c fs_tar.c fs_min.c fs_dos.c cprintf.c
+ trk_buf.c min_buf.c unix.c fs.c fs_tar.c fs_min.c fs_dos.c
MINC=i86_funcs.h readfs.h monitor.h
BOOTBLOCKS=sysboot.v noboot.v skip.v msdos.v msdos16.v \
@@ -46,19 +46,19 @@ fs_min.o: minix.h
bootfile.sys: $(MSRC) $(MINC)
@rm -f $(MOBJ)
- make 'CFLAGS=$(CFLAGS) -DDOSFLOPPY -i-' monitor.out
+ make 'CFLAGS=$(CFLAGS) -DDOSFLOPPY -i' monitor.out
mv monitor.out bootfile.sys
@rm -f $(MOBJ)
boottar.sys: $(MSRC) $(MINC) tarboot.bin
@rm -f $(MOBJ)
- make 'CFLAGS=$(CFLAGS) -DTARFLOPPY -i-' monitor.out
+ make 'CFLAGS=$(CFLAGS) -DTARFLOPPY -i' monitor.out
mv monitor.out boottar.sys
@rm -f $(MOBJ)
bootminix.sys: $(MSRC) $(MINC) tarboot.bin
@rm -f $(MOBJ)
- make 'CFLAGS=$(CFLAGS) -DMINFLOPPY -i-' monitor.out
+ make 'CFLAGS=$(CFLAGS) -DMINFLOPPY -i' monitor.out
mv monitor.out bootminix.sys
@rm -f $(MOBJ)
diff --git a/bootblocks/mbr.s b/bootblocks/mbr.s
index 113bb51..d071a8b 100644
--- a/bootblocks/mbr.s
+++ b/bootblocks/mbr.s
@@ -16,7 +16,7 @@
ORGADDR=$0500
preboot=0 ! Include the pre-boot loader.
mbrkey=0 ! Option to choose the boot record base on keystroke
-message=0 ! Display boot message
+message=1 ! Display boot message
diskman=0 ! Disk manager partitions, allows 16 partitions but
! don't overwrite this with a LILO BB.
diff --git a/bootblocks/monitor.h b/bootblocks/monitor.h
index 7283c10..9d66f95 100644
--- a/bootblocks/monitor.h
+++ b/bootblocks/monitor.h
@@ -59,7 +59,7 @@ extern union REGS __argr;
#ifdef __STANDALONE__
#undef putchar
-#define putchar cputchar
+#define putchar putch
#define printf cprintf
#define fflush(x)
#endif
diff --git a/bootblocks/tarboot.s b/bootblocks/tarboot.s
index f872ad0..a8e56fa 100644
--- a/bootblocks/tarboot.s
+++ b/bootblocks/tarboot.s
@@ -463,28 +463,20 @@ bad_rt: xor ah,ah
if DEBUG
pboot:
- mov si,#mesg
+ mov si,#blk_load
nextc:
lodsb
call putc
cmp al,#0
jnz nextc
ret
-
-locn(512-16)
-mesg:
-.ascii "Tarboot loading "
endif
!-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
-! This isn't a hard disk boot sector so don't give it an HD magic
-! locn(510)
-! .word 0xAA55
-if DEBUG = 0
+! This isn't a hard disk boot sector but give it an HD magic anyway.
locn(510)
- .word 0
-endif
+ .word 0xAA55
! From here down is where we load stuff.
locn(512)
diff --git a/later.c b/later.c
deleted file mode 100644
index 8b407da..0000000
--- a/later.c
+++ /dev/null
@@ -1,38 +0,0 @@
-
-#include <stdio.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-
-main(argc, argv)
-int argc;
-char ** argv;
-{
- struct stat st;
- long exe_mtime = 0;
- int verbose = 0;
- int ar;
-
- if( strcmp(argv[1], "+") == 0 ) { verbose++; argc--; argv++; }
-
- if( stat(argv[1], &st) < 0 )
- {
- if( verbose ) printf("%s not found\n", argv[1]);
- exit(2);
- }
- exe_mtime = st.st_mtime;
-
- for(ar=2; ar<argc; ar++)
- {
- if( stat(argv[ar], &st) < 0 )
- {
- printf("ERROR: dependent %d not found\n", argv[ar]);
- exit(3);
- }
- if( exe_mtime < st.st_mtime )
- {
- if( verbose ) printf("%s out of dat wrt %s \n", argv[1], argv[ar]);
- exit(1);
- }
- }
- exit(0);
-}
diff --git a/libc/Config.dflt b/libc/Config.dflt
index 1927f1e..5056bf7 100644
--- a/libc/Config.dflt
+++ b/libc/Config.dflt
@@ -1,5 +1,6 @@
bcc:+:
bios:+:
+conio:+:
error:+:
getent:+:
gtermcap:+:
diff --git a/libc/Makefile b/libc/Makefile
index 21c3a30..6d6c5bb 100644
--- a/libc/Makefile
+++ b/libc/Makefile
@@ -11,7 +11,7 @@ endif
VERMAJOR=0
VERMINOR=16
-VERPATCH=0
+VERPATCH=1
VER=$(VERMAJOR).$(VERMINOR).$(VERPATCH)
CC=bcc
diff --git a/libc/bios/bios.c b/libc/bios/bios.c
index 402f689..e0e5c23 100644
--- a/libc/bios/bios.c
+++ b/libc/bios/bios.c
@@ -33,12 +33,22 @@ loop_save:
.text
export ___cstartup ! Crt0 startup
___cstartup:
- mov ___argr+0,ax
- mov ___argr+2,bx
- mov ___argr+4,cx
- mov ___argr+6,dx
- mov ___argr+8,si
- mov ___argr+10,di
+ cli
+ mov sp,cs
+ add sp,#__segoff
+ mov ds,sp
+ mov ss,sp
+ mov sp,#___argr+12
+ push di
+ push si
+ push dx
+ push cx
+ push bx
+ push ax
+ xor bp,bp
+ mov sp,bp
+ push bp
+ sti
zap_bss: ! Clear the BSS
mov ax,ds
diff --git a/libc/bios/cprintf.c b/libc/bios/cprintf.c
deleted file mode 100644
index cd5f62b..0000000
--- a/libc/bios/cprintf.c
+++ /dev/null
@@ -1,132 +0,0 @@
-
-#include <stdarg.h>
-#define wchar(ch) putch(ch)
-
-cprintf(char * fmt, va_list ap)
-{
- register int c;
- int count = 0;
- int type, base;
- long val;
- char * cp;
- char padch=' ';
- int minsize = 0;
-
- while(c=*fmt++)
- {
- if(c!='%')
- {
- wchar(c);
- count++;
- }
- else
- {
- type=1;
- do { c=*fmt++; } while( c>='0' && c<='9');
-
- padch = *fmt;
- minsize=0;
- if(padch == '-') fmt++;
-
- for(;;)
- {
- c=*fmt++;
- if( c<'0' || c>'9' ) break;
- minsize*=10; minsize+=c-'0';
- }
-
- while( c=='.' || (c>='0' && c<='9')) { c=*fmt++; }
-
- if( padch == '-' ) minsize = -minsize;
- else
- if( padch == '0' ) padch='0'; else padch=' ';
-
- if( c == 0 ) break;
- if(c=='h')
- {
- c=*fmt++;
- type = 0;
- }
- else if(c=='l')
- {
- c=*fmt++;
- type = 2;
- }
-
- switch(c)
- {
- case 'x': base=16; type|=4; if(0) {
- case 'o': base= 8; type|=4; } if(0) {
- case 'u': base=10; type|=4; } if(0) {
- case 'd': base=10; }
- val=0;
- switch(type)
- {
- case 0: val=va_arg(ap, short); break;
- case 1: val=va_arg(ap, int); break;
- case 2: val=va_arg(ap, long); break;
- case 4: val=va_arg(ap, unsigned short); break;
- case 5: val=va_arg(ap, unsigned int); break;
- case 6: val=va_arg(ap, unsigned long); break;
- }
- cp = __numout(val,base);
- if(0) {
- case 's':
- cp=va_arg(ap, char *);
- }
- if( minsize > 0 )
- {
- minsize -= strlen(cp);
- while(minsize>0) { wchar(padch); minsize--; }
- minsize=0;
- }
- if( minsize < 0 ) minsize= -minsize-strlen(cp);
- while(*cp)
- wchar(*cp++);
- while(minsize>0) { wchar(' '); minsize--; }
- break;
- case 'c':
- wchar(va_arg(ap, int));
- break;
- default:
- wchar(c);
- break;
- }
- }
- }
- return count;
-}
-
-
-
-static char nstring[]="0123456789ABCDEF";
-
-static unsigned char *
-__numout(long i, int base)
-{
- static unsigned char out[16];
- int n;
- int flg = 0;
- unsigned long val;
-
- if (i<0 && base==10)
- {
- flg = 1;
- i = -i;
- }
- val = i;
-
- for (n = 0; n < 15; n++)
- out[n] = ' ';
- out[15] = '\0';
- n = 14;
- do
- {
- out[n] = nstring[val % base];
- n--;
- val /= base;
- }
- while(val);
- if(flg) out[n--] = '-';
- return &out[n+1];
-}
diff --git a/libc/conio/Config b/libc/conio/Config
new file mode 100644
index 0000000..76765c8
--- /dev/null
+++ b/libc/conio/Config
@@ -0,0 +1 @@
+conio: Console io functions for BIOS and DOS.
diff --git a/libc/conio/Makefile b/libc/conio/Makefile
new file mode 100644
index 0000000..bd86b2c
--- /dev/null
+++ b/libc/conio/Makefile
@@ -0,0 +1,36 @@
+# Copyright (C) 1996 Robert de Bath <robert@mayday.compulink.co.uk>
+# This file is part of the Linux-8086 C library and is distributed
+# under the GNU Library General Public License.
+
+ASRC=conio.c
+AOBJ=getch.o getche.o kbhit.o putch.o cputs.o
+
+OBJ=$(AOBJ) cprintf.o
+
+CFLAGS=$(ARCH) $(CCFLAGS) $(DEFS)
+
+ifeq ($(LIB_CPU)-$(LIB_OS),i86-BIOS)
+all: $(LIBC)($(OBJ))
+ @$(RM) $(OBJ)
+else
+ifeq ($(LIB_CPU)-$(LIB_OS),i86-DOS)
+all: $(LIBC)($(OBJ))
+ @$(RM) $(OBJ)
+else
+all:
+ @:
+endif
+endif
+
+$(LIBC)($(AOBJ)): $(ASRC)
+ $(CC) $(CFLAGS) -DL_$* $< -c -o $*.o
+ $(AR) $(ARFLAGS) $@ $*.o
+
+$(LIBC)(cprintf.o): cprintf.c
+ $(CC) -c -ansi $(ARCH) $(CCFLAGS) $(DEFS) $*.c
+ $(AR) $(ARFLAGS) $@ $*.o
+
+
+
+clean:
+ rm -f *.o libc.a
diff --git a/libc/msdos/conio.c b/libc/conio/conio.c
index f6f9105..c0e9cbb 100644
--- a/libc/msdos/conio.c
+++ b/libc/conio/conio.c
@@ -3,11 +3,17 @@
* under the GNU Library General Public License.
*/
+#include <conio.h>
+
/*
* I'm not sure if these should be BIOS or dos calls, so I'll assume they're
* BIOS calls but I may have to do something about Ctrl-C.
+ *
+ * These functions are also compiled for __STANDALONE__ so if ^C or DOS
+ * versions are made this will have to be addressed.
*/
+#ifdef L_getch
getch()
{
#asm
@@ -15,14 +21,18 @@ getch()
int $16
#endasm
}
+#endif
+#ifdef L_getche
getche()
{
int i = getch();
- if( i & 0xFF) putch(i);
+ if( i & 0xFF ) putch(i);
return i;
}
+#endif
+#ifdef L_kbhit
kbhit()
{
#asm
@@ -38,7 +48,9 @@ nokey:
xor ax,ax
#endasm
}
+#endif
+#ifdef L_putch
putch()
{
#asm
@@ -46,17 +58,27 @@ putch()
mov bx,sp
mov ax,[bx+2]
#endif
+ cmp al,#$0A
+ jne not_nl
+ mov ax,#$0E0D
+ mov bx,#7
+ int $10
+ mov al,#$0A
+not_nl:
mov ah,#$0E
mov bx,#7
int $10
#endasm
}
+#endif
+#ifdef L_cputs
cputs(str)
char * str;
{
while(*str) putch(*str++);
}
+#endif
#if 0
@@ -64,10 +86,6 @@ cgets()
{
}
-cprintf()
-{
-}
-
cscanf()
{
}
diff --git a/bootblocks/cprintf.c b/libc/conio/cprintf.c
index e6c0ea7..4bc3bac 100644
--- a/bootblocks/cprintf.c
+++ b/libc/conio/cprintf.c
@@ -1,16 +1,9 @@
-
#include <stdarg.h>
+#include <conio.h>
static unsigned char * __numout(long i, int base);
-cputchar(ch)
-int ch;
-{
- if(ch == '\n') bios_putc('\r');
- return bios_putc(ch);
-}
-
-cprintf(char * fmt, ...)
+int cprintf(char * fmt, ...)
{
register int c;
int count = 0;
@@ -27,7 +20,7 @@ cprintf(char * fmt, ...)
{
count++;
if(c!='%')
- cputchar(c);
+ putch(c);
else
{
type=1;
@@ -52,7 +45,7 @@ cprintf(char * fmt, ...)
if( padch == '-' ) minsize = -minsize;
else
- if( padch == '0' ) padch='0'; else padch=' ';
+ if( padch != '0' ) padch=' ';
if( c == 0 ) break;
if(c=='h')
@@ -71,7 +64,7 @@ cprintf(char * fmt, ...)
case 'x': base=16; type |= 4; if(0) {
case 'o': base= 8; type |= 4; } if(0) {
case 'u': base=10; type |= 4; } if(0) {
- case 'd': base=10; }
+ case 'd': base=-10; }
switch(type)
{
case 0: val=va_arg(ap, short); break;
@@ -93,22 +86,22 @@ cprintf(char * fmt, ...)
if( minsize > 0 )
{
minsize -= c;
- while(minsize>0) { cputchar(padch); count++; minsize--; }
+ while(minsize>0) { putch(padch); count++; minsize--; }
minsize=0;
}
if( minsize < 0 ) minsize= -minsize-c;
while(*cp && maxsize-->0 )
{
- cputchar(*cp++);
+ putch(*cp++);
count++;
}
- while(minsize>0) { cputchar(' '); count++; minsize--; }
+ while(minsize>0) { putch(' '); count++; minsize--; }
break;
case 'c':
- cputchar(va_arg(ap, int));
+ putch(va_arg(ap, int));
break;
default:
- cputchar(c);
+ putch(c);
break;
}
}
@@ -119,32 +112,110 @@ cprintf(char * fmt, ...)
static char nstring[]="0123456789ABCDEF";
+#ifndef __AS386_16__
+#define NUMLTH 11
+
static unsigned char *
__numout(long i, int base)
{
- static unsigned char out[16];
+ static unsigned char out[NUMLTH+1];
int n;
int flg = 0;
unsigned long val;
- if (i<0 && base==10)
+ if (base<0)
{
- flg = 1;
- i = -i;
+ base = -base;
+ if (i<0)
+ {
+ flg = 1;
+ i = -i;
+ }
}
val = i;
- for (n = 0; n < 15; n++)
- out[n] = ' ';
- out[15] = '\0';
- n = 14;
+ out[NUMLTH] = '\0';
+ n = NUMLTH-1;
do
{
- out[n] = nstring[val % base];
- n--;
+ out[n--] = nstring[val % base];
val /= base;
}
while(val);
if(flg) out[n--] = '-';
return &out[n+1];
}
+
+#else
+
+#asm
+! numout.s
+!
+.bss
+___out lcomm $C
+
+.text
+___numout:
+push bp
+mov bp,sp
+push di
+push si
+add sp,*-4
+mov byte ptr -8[bp],*$0 ! flg = 0
+mov si,4[bp] ; i or val.lo
+mov di,6[bp] ; i or val.hi
+mov cx,8[bp] ; base
+test cx,cx ! base < 0 ?
+jge .3num
+neg cx ! base = -base
+or di,di ! i < 0 ?
+jns .5num
+mov byte ptr -8[bp],*1 ! flg = 1
+neg di ! i = -i
+neg si
+sbb di,0
+.5num:
+.3num:
+mov byte ptr [___out+$B],*$0 ! out[11] = nul
+mov -6[bp],*$A ! n = 10
+
+.9num:
+!!! out[n--] = nstring[val % base];
+xor dx,dx
+xchg ax,di
+div cx
+xchg ax,di
+xchg ax,si
+div cx
+xchg ax,si ! val(new) = val / base
+
+mov bx,dx ! dx = val % base
+
+mov al,_nstring[bx]
+mov bx,-6[bp]
+dec word ptr -6[bp]
+mov ___out[bx],al
+
+mov ax,si
+or ax,di ! while (val)
+jne .9num
+
+cmp byte ptr -8[bp],*$0 ! flg == 0 ?
+je .Dnum
+
+mov bx,-6[bp]
+dec word ptr -6[bp]
+mov byte ptr ___out[bx],*$2D ! out[n--] = minus
+
+.Dnum:
+mov ax,-6[bp]
+add ax,#___out+1
+
+add sp,*4
+pop si
+pop di
+pop bp
+ret
+#endasm
+
+#endif
diff --git a/libc/include/conio.h b/libc/include/conio.h
new file mode 100644
index 0000000..7219a8f
--- /dev/null
+++ b/libc/include/conio.h
@@ -0,0 +1,26 @@
+
+#ifndef __CONIO_H
+#define __CONIO_H
+#include <features.h>
+
+int cprintf __P((char *, ...));
+int cputs __P((char *));
+int getch __P((void));
+int getche __P((void));
+int kbhit __P((void));
+int putch __P((int));
+
+#if 0 /* Unimplemented as yet */
+char * cgets __P((char *));
+int ungetch __P((int));
+int cscanf __P((char *, ...));
+#endif
+
+#if 0 /* Hummm */
+unsigned outpw __P((unsigned int, unsigned int));
+unsigned inpw __P((unsigned int));
+int outp __P((unsigned int, int));
+int inp __P((unsigned int));
+#endif
+
+#endif
diff --git a/libc/syscall/syscall.dev86 b/libc/syscall/syscall.dev86
index 29e7b5e..2c5384c 100644
--- a/libc/syscall/syscall.dev86
+++ b/libc/syscall/syscall.dev86
@@ -47,25 +47,25 @@ ptrace 26 4 @ adb/sdb/dbx need this.
alarm 27 2
fstat +28 2
pause 29 0
-utime 30 2
+utime +30 2
chroot +31 1
-vfork 32 0
+vfork +32 0
access +33 2
nice 34 1
sleep 35 1
sync +36 0
-kill 37 2
+kill +37 2
rename +38 2
mkdir +39 2
rmdir +40 1
dup +41 1 . There is a fcntl lib function too.
-pipe 42 1
+pipe +42 1
times 43 2 * 2nd arg is pointer for long ret val.
profil 44 4 @
dup2 +45 2
setgid +46 1
getgid 47 1 * this gets both gid and egid
-signal 48 2 * have put the despatch table in user space.
+signal +48 2 * have put the despatch table in user space.
getinfo 49 1 @ possible? gets pid,ppid,uid,euid etc
fcntl +50 3
acct 51 1 @ Accounting to named file (off if null)
@@ -78,11 +78,19 @@ lstat +57 2
symlink +58 2
readlink +59 3
umask +60 1
-settimeofday 61 2
-gettimeofday 62 2
-select 63 5 *
+settimeofday +61 2
+gettimeofday +62 2
+select +63 5 . 5 paramaters is possible
readdir +64 3 *
-
+insmod +65 1
+fchown +66 3
+dlload +67 2
+setsid +68 0
+socket +69 3
+bind +70 3
+listen +71 2
+accept +72 3
+connect +73 3
#
# Name No Args Flag&comment
#
diff --git a/libc/syscall/syscall.dev86.old b/libc/syscall/syscall.dev86.old
new file mode 100644
index 0000000..29e7b5e
--- /dev/null
+++ b/libc/syscall/syscall.dev86.old
@@ -0,0 +1,160 @@
+#
+# WARNING!
+# This file is used to generate the system call lists for Dev86(elks)
+# ELKSemu and elks itself. Changes to this may require changes in
+# all three of those packages.
+#
+# . = Ok, with comment
+# * = Needs libc code (Prefix __)
+# - = Obsolete/not required
+# @ = May be required later
+#
+# An initial plus on the call number specifies that this call is
+# implemented in the kernel.
+#
+# Package versions are matched.
+# Dev86/Elksemu version - 0.13.1
+# Elks version - 0.0.66
+#
+# Name No Args Flag, comment
+#
+exit +1 1 * c exit does stdio, _exit in crt0
+fork +2 0
+read +3 3
+write +4 3
+open +5 3
+close +6 1
+wait4 +7 4
+creat 8 0 - Not needed alias for open
+link +9 2
+unlink +10 1
+execve +11 3 * execve minix style
+chdir +12 1
+time 13 1 - Use settimeofday
+mknod +14 3
+chmod +15 2
+chown +16 3
+brk +17 1 * This is only to tell the system
+stat +18 2
+lseek +19 3 * nb 2nd arg is an io ptr to long not a long.
+getpid +20 1 * this gets both pid & ppid
+mount +21 5
+umount +22 1
+setuid +23 1
+getuid +24 1 * this gets both uid and euid
+stime 25 2 - this must not exist - even as a libc.
+ptrace 26 4 @ adb/sdb/dbx need this.
+alarm 27 2
+fstat +28 2
+pause 29 0
+utime 30 2
+chroot +31 1
+vfork 32 0
+access +33 2
+nice 34 1
+sleep 35 1
+sync +36 0
+kill 37 2
+rename +38 2
+mkdir +39 2
+rmdir +40 1
+dup +41 1 . There is a fcntl lib function too.
+pipe 42 1
+times 43 2 * 2nd arg is pointer for long ret val.
+profil 44 4 @
+dup2 +45 2
+setgid +46 1
+getgid 47 1 * this gets both gid and egid
+signal 48 2 * have put the despatch table in user space.
+getinfo 49 1 @ possible? gets pid,ppid,uid,euid etc
+fcntl +50 3
+acct 51 1 @ Accounting to named file (off if null)
+phys 52 3 - Replaced my mmap()
+lock 53 1 @ Prevent swapping for this proc if flg!=0
+ioctl +54 3 . make this and fcntl the same ?
+reboot +55 3 . the magic number is 0xfee1,0xdead,...
+mpx 56 2 - Replaced by fifos and select.
+lstat +57 2
+symlink +58 2
+readlink +59 3
+umask +60 1
+settimeofday 61 2
+gettimeofday 62 2
+select 63 5 *
+readdir +64 3 *
+
+#
+# Name No Args Flag&comment
+#
+# ( awk '{$2=NR+500;OFS="\t";print ;}'| expand -24,32,40 | unexpand ) <<!
+#
+ADJTIMEX 501 X @
+FCHDIR 502 1 @
+FCHMOD 503 2 @
+FCHOWN 504 3 @
+FDATASYNC 505 X @
+FLOCK 506 2 - Use fcntl
+FSTATFS 507 2 @
+FSYNC 508 1 @
+FTIME 509 1 - Use gettimeofday
+FTRUNCATE 510 3 @
+GETDENTS 511 X @
+GETGROUPS 512 2 @
+GETITIMER 513 2 @
+GETPGID 514 1 @
+GETPGRP 515 0 - Use getpgid(0)
+GETPRIORITY 516 2 @
+GETRLIMIT 517 2 @
+GETRUSAGE 518 2 @
+GETSID 519 X @
+IPC 520 5 @ This is for all SYSV IPC (c/f mpx)
+LLSEEK 521 3 @ 2nd arg is ptr to two longs
+MPROTECT 522 X @
+MSYNC 523 X @
+MUNLOCK 524 X @
+MUNLOCKALL 525 X @
+MUNMAP 526 X @
+PERSONALITY 527 X @
+QUOTACTL 528 X @
+READV 529 3 @
+SCHED_GETPARAM 530 X @
+SCHED_GETSCHEDULER 531 X @
+SCHED_GET_PRIORITY_MAX 532 X @
+SCHED_GET_PRIORITY_MIN 533 X @
+SCHED_RR_GET_INTERVAL 534 X @
+SCHED_SETPARAM 535 X @
+SCHED_SETSCHEDULER 536 X @
+SCHED_YIELD 537 X @
+SETDOMAINNAME 538 X @
+SETFSGID 539 1 @
+SETFSUID 540 1 @
+SETGROUPS 541 2 @
+SETHOSTNAME 542 2 @
+SETITIMER 543 3 @
+SETPGID 544 2 @
+SETPRIORITY 545 3 @
+SETREGID 546 2 @
+SETREUID 547 2 @
+SETRLIMIT 548 2 @
+SETSID 549 0 @
+SGETMASK 550 X @
+SIGACTION 551 X @
+SIGPENDING 552 X @
+SIGPROCMASK 553 X @
+SIGRETURN 554 X @
+SIGSUSPEND 555 X @
+SOCKETCALL 556 X @
+SSETMASK 557 X @
+STATFS 558 2 @
+SWAPOFF 559 X @
+SWAPON 560 X @
+SYSCTL 561 X @
+SYSFS 562 X @
+SYSINFO 563 X - Use /proc
+SYSLOG 564 X @ Poss fifo & libc implementation.
+TRUNCATE 565 3 @
+ULIMIT 566 2 @
+UNAME 567 1 @
+USTAT 568 2 @
+VHANGUP 569 0 @
+WRITEV 570 3 @
diff --git a/makefile.in b/makefile.in
index 25ea4d4..3cf85c7 100644
--- a/makefile.in
+++ b/makefile.in
@@ -39,7 +39,7 @@ WALL =-Wtraditional -Wshadow -Wid-clash-14 -Wpointer-arith \
WALL =-Wstrict-prototypes
CC =gcc
-CFLAGS =$(GCCFLAG) -Wall $(WALL) -O6 -g
+CFLAGS =$(GCCFLAG) -Wall $(WALL) -O2 -g
#endif
#ifndef GNUMAKE
@@ -324,10 +324,10 @@ install-other:
$(MAKEC) $$i BCC=ncc DIST=$(DIST) PREFIX=$(PREFIX) install || exit 1 ; \
done
-other: $(OTHERS)
-
-$(OTHERS):
- $(MAKEC) $@ BCC=ncc
+other:
+ @for i in $(OTHERS) ; do \
+ $(MAKEC) $$i BCC=ncc DIST=$(DIST) PREFIX=$(PREFIX) || exit 1; \
+ done
clean:
-@for i in $(CLEANLIST) ; do $(MAKEC) $$i $@ ; true ; done
diff --git a/man/bcc.1 b/man/bcc.1
index 1050cc9..fb88ac8 100644
--- a/man/bcc.1
+++ b/man/bcc.1
@@ -88,7 +88,7 @@ don't add default library to search list
.B -Md
alters the arguments for all passes to produce MSDOS executable COM files.
These are small model executables, use
-.B -i-
+.B -i
to get tiny model.
.TP
.B -Mf
@@ -189,9 +189,13 @@ assembler warning messages.
.TP
.B -x
don't include crt0.o in the link.
+.TP
+.B -i
+don't pass
+.B -i
+to the linker so that it will create an impure executable.
.P
-Other options are passed to the linker, in particular -i-, -lx, -M, -m, -s, -H.
-The -i option is always passed to the linker but can be cancelled using -i-.
+Other options are passed to the linker, in particular -lx, -M, -m, -s, -H.
.SH CODE GENERATOR OPTIONS
These are all options that the code generator pass
diff --git a/mkcompile b/mkcompile
index 6adf313..1c7ee85 100644
--- a/mkcompile
+++ b/mkcompile
@@ -10,32 +10,27 @@ SRC_AS=' as.c assemble.c error.c express.c genbin.c genlist.c genobj.c gensym.c
SRC_LD=' ld.c dumps.c io.c linksyms.c readobj.c table.c typeconv.c
writebin.c writex86.c'
-HDR_BCC=''
-HDR_CC1='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'
-HDR_AS=' address.h byteord.h const.h file.h flag.h globvar.h macro.h opcode.h
- proto.h scan.h source.h syshead.h type.h'
-HDR_LD=' align.h ar.h bindef.h byteord.h config.h const.h globvar.h obj.h
- syshead.h type.h x86_aout.h'
+SRC_UP=' unproto.c tok_io.c tok_class.c tok_pool.c vstring.c symbol.c error.c
+ hash.c strsave.c'
main() {
echo '@echo off'
- echo -n 'if not exist later.exe '
- echo 'cl -nologo -O later.c %LIB%\setargv.obj -link /NOE'
- echo
CFLAGS='-nologo -O'
LDFLAGS='%LIB%\setargv.obj -link /NOE'
ARCH=-Ms
- build bcc bcc bin "$HDR_BCC" $SRC_BCC
+ build bcc bcc bin $SRC_BCC
CFLAGS='-nologo -O -DPOSIX_HEADERS_MISSING'
LDFLAGS=
ARCH=-Ml
- build bcc bcc-cc1 lib "$HDR_CC1" $SRC_CC1
- build as as86 bin "$HDR_AS" $SRC_AS
- build ld ld86 bin "$HDR_LD" $SRC_LD
+
+ build bcc bcc-cc1 lib $SRC_CC1
+ build as as86 bin $SRC_AS
+ build ld ld86 bin $SRC_LD
+ # build unproto unproto bin $SRC_UP
+
+ echo "echo Compile complete."
echo ":exit_now"
}
@@ -43,7 +38,6 @@ build() {
DIR="$1" ; shift
PRG="$1" ; shift
BIN="$1" ; shift
- HDR="$1" ; shift
OBJ=
BOBJ=
COBJ=
@@ -53,51 +47,35 @@ build() {
for i in $SRC
do
j=`basename $i .c`
- check_time $DIR/$j.obj $i $HDR
- echo -n "if errorlevel 1 "
- echo "cl $ARCH $CFLAGS -c -Fo$DIR\\$j.obj $DIR\\$i"
+ echo "cl $ARCH $CFLAGS -c -Fo%TMP%\\$j.obj $DIR\\$i"
if [ "$BOBJ" = "" ]
- then BOBJ="$DIR\\$j.obj"
- else LOBJ="$LOBJ +$DIR\\$j.obj"
+ then BOBJ="%TMP%\\$j.obj"
+ else LOBJ="$LOBJ +%TMP%\\$j.obj"
fi
- COBJ="$COBJ $DIR\\$j.obj"
+ COBJ="$COBJ %TMP%\\$j.obj"
OBJ="$OBJ $j.obj"
echo "if errorlevel 1 goto exit_now"
done
+ echo
if [ `echo $COBJ | wc -c` -lt 50 ]
then
- check_time $BIN/$PRG.exe $OBJ
- echo -n "if errorlevel 1 "
echo "cl $ARCH -o $BIN\\$PRG.exe$COBJ $LDFLAGS"
echo "if errorlevel 1 goto exit_now"
else
- check_time $BIN/$PRG.exe $OBJ
- echo "if not errorlevel 1 goto done_$PRG"
- echo "if exist doslib.lib del doslib.lib"
+ echo "if exist %TMP%\\doslib.lib del %TMP%\\doslib.lib"
echo $LOBJ | fmt -62 | \
- sed 's/\(.*\)/lib doslib.lib \1; >NUL/'
- echo "cl $ARCH -o $BIN\\$PRG.exe $BOBJ doslib.lib $LDFLAGS"
+ sed "s/\(.*\)/lib %TMP%\\\\doslib.lib \1; /" |
+ sed 's/$/@if errorlevel 1 goto exit_now/' |
+ tr '@' '\012'
+ echo
+ echo "cl $ARCH -o $BIN\\$PRG.exe $BOBJ %TMP%\\doslib.lib $LDFLAGS"
echo "if errorlevel 1 goto exit_now"
- echo "if exist doslib.lib del doslib.lib"
- echo "if exist doslib.bak del doslib.bak"
- echo ":done_$PRG"
fi
echo
}
-check_time() {
- TARG="$1" ; shift
-
- for i
- do echo "$DIR/$i"
- done | fmt -70 | \
- sed -e "s;\(.*\);later $TARG \1@if errorlevel 3 goto exit_now;" \
- -e '2,$s/^/if not errorlevel 1 /' | \
- tr '@' '\012'
-}
-
main "$@" | sed 's/$/ /' > compile.bat
diff --git a/mkcompile2 b/mkcompile2
deleted file mode 100644
index 87c0df6..0000000
--- a/mkcompile2
+++ /dev/null
@@ -1,103 +0,0 @@
-#!/bin/sh
-
-SRC_BCC='bcc.c'
-SRC_CC1='bcc-cc1.c assign.c codefrag.c debug.c declare.c express.c exptree.c
- floatop.c function.c gencode.c genloads.c glogcode.c hardop.c input.c
- label.c loadexp.c longop.c output.c preproc.c preserve.c scan.c
- softop.c state.c table.c type.c'
-SRC_AS=' as.c assemble.c error.c express.c genbin.c genlist.c genobj.c gensym.c
- keywords.c macro.c mops.c pops.c readsrc.c scan.c table.c typeconv.c'
-SRC_LD=' ld.c dumps.c io.c linksyms.c readobj.c table.c typeconv.c
- writebin.c writex86.c'
-
-HDR_BCC=''
-HDR_CC1='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'
-HDR_AS=' address.h byteord.h const.h file.h flag.h globvar.h macro.h opcode.h
- proto.h scan.h source.h syshead.h type.h'
-HDR_LD=' align.h ar.h bindef.h byteord.h config.h const.h globvar.h obj.h
- syshead.h type.h x86_aout.h'
-
-main() {
- echo '@echo off'
- echo -n 'if not exist later.exe '
- echo 'bcc -O later.c'
- echo
-
- CFLAGS='-O -D__STDC__=1 -DMSDOS'
- LDFLAGS=''
- ARCH=
- build bcc bcc bin "$HDR_BCC" $SRC_BCC
-
- CFLAGS='-O -D__STDC__=1 -DMSDOS -DPOSIX_HEADERS_MISSING'
- LDFLAGS=
- ARCH=-ml
- build bcc bcc-cc1 lib "$HDR_CC1" $SRC_CC1
- build as as86 bin "$HDR_AS" $SRC_AS
- build ld ld86 bin "$HDR_LD" $SRC_LD
- echo ":exit_now"
-}
-
-build() {
- DIR="$1" ; shift
- PRG="$1" ; shift
- BIN="$1" ; shift
- HDR="$1" ; shift
- OBJ=
- BOBJ=
- COBJ=
- LOBJ=
- SRC="$*"
-
- for i in $SRC
- do
- j=`basename $i .c`
- check_time $DIR/$j.obj $i $HDR
- echo -n "if errorlevel 1 "
-
- echo "bcc $ARCH $CFLAGS -c -I$DIR -o$DIR\\$j.obj $DIR\\$i"
- if [ "$BOBJ" = "" ]
- then BOBJ="$DIR\\$j.obj"
- else LOBJ="$LOBJ +$DIR\\$j.obj"
- fi
- COBJ="$COBJ $DIR\\$j.obj"
- OBJ="$OBJ $j.obj"
-
- echo "if errorlevel 1 goto exit_now"
- done
-
- if [ `echo $COBJ | wc -c` -lt 50 ]
- then
- check_time $BIN/$PRG.exe $OBJ
- echo -n "if errorlevel 1 "
- echo "bcc $ARCH -e$BIN\\$PRG.exe$COBJ $LDFLAGS"
- echo "if errorlevel 1 goto exit_now"
- else
- check_time $BIN/$PRG.exe $OBJ
- echo "if not errorlevel 1 goto done_$PRG"
- echo "if exist doslib.lib del doslib.lib"
- echo $LOBJ | fmt -62 | \
- sed 's/\(.*\)/tlib doslib.lib \1/'
- echo "bcc $ARCH -e$BIN\\$PRG.exe $BOBJ doslib.lib $LDFLAGS"
- echo "if errorlevel 1 goto exit_now"
- echo "if exist doslib.lib del doslib.lib"
- echo "if exist doslib.bak del doslib.bak"
- echo ":done_$PRG"
- fi
- echo
-}
-
-check_time() {
- TARG="$1" ; shift
-
- for i
- do echo "$DIR/$i"
- done | fmt -70 | \
- sed -e "s;\(.*\);later $TARG \1@if errorlevel 3 goto exit_now;" \
- -e '2,$s/^/if not errorlevel 1 /' | \
- tr '@' '\012'
-}
-
-main "$@" | sed 's/$/ /' > compile.bat
-