From b5dac1e3bdd01a2ce105df747a9073ff0d6a94e2 Mon Sep 17 00:00:00 2001 From: Robert de Bath Date: Sun, 2 Nov 2003 09:31:19 +0100 Subject: Import Dev86src-0.16.14.tar.gz --- Changes | 5 ++ Makefile | 2 +- ar/alloca.c | 2 +- ar/ar.c | 6 +- bcc/bcc.c | 3 +- copt/copt.c | 1 - cpp/cc.h | 24 +++---- cpp/cpp.c | 43 ++++++------ cpp/cygwin.c | 99 --------------------------- cpp/hash.c | 6 +- cpp/main.c | 29 ++++---- cpp/token1.c | 2 +- cpp/token2.c | 2 +- ifdef.c | 7 +- ld/Makefile | 12 ++-- ld/bindef.h | 29 ++++---- ld/dumps.c | 8 +++ ld/io.c | 4 +- ld/ld.c | 46 +++++-------- ld/ld86r.c | 7 +- ld/mkar.c | 74 ++++++++++++++++++++ ld/objdump86.c | 202 ++++++++++++++++++++++++++++++++++--------------------- ld/table.c | 31 +++++++++ ld/type.h | 3 +- ld/writebin.c | 6 -- ld/writeemu.c | 20 ++++++ ld/writerel.c | 22 ------ makefile.in | 40 +++++------ unproto/Makefile | 2 +- 29 files changed, 398 insertions(+), 339 deletions(-) delete mode 100644 cpp/cygwin.c create mode 100644 ld/mkar.c create mode 100644 ld/writeemu.c delete mode 100644 ld/writerel.c diff --git a/Changes b/Changes index 88a23d8..680d76d 100644 --- a/Changes +++ b/Changes @@ -3,6 +3,11 @@ For version 0.16.*. > More changes so it compiles better on 'other' machines. Removed some GNU-Make'isms in the top header file. +> It seems that CYGWin's problem with _P is inherited from BSD. It also + seems most of my problems come from BSD recently, haven't they realised + that they down own the 'Unix Standard' anymore and haven't since SYSV + got popular. + > Some changes for cygwin, it isn't quite as nasty as compiling for minix but it doesn't miss by much! diff --git a/Makefile b/Makefile index 429ce8e..704c9d2 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ # This file is part of the Linux-8086 Development environment and is # distributed under the GNU General Public License. -VERSION=0.16.13 +VERSION=0.16.14 TARGETS= \ clean bcc unproto copt as86 ld86 elksemu \ diff --git a/ar/alloca.c b/ar/alloca.c index 880c100..80c95e2 100644 --- a/ar/alloca.c +++ b/ar/alloca.c @@ -6,7 +6,7 @@ #include #endif -#ifdef __TINYC__ +#if defined(__TINYC__) || defined(__HP_cc) typedef union mem_cell { union mem_cell *next; /* A pointer to the next mem */ diff --git a/ar/ar.c b/ar/ar.c index 1753293..b0694ac 100644 --- a/ar/ar.c +++ b/ar/ar.c @@ -15,7 +15,7 @@ You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ - + #include #include @@ -29,11 +29,11 @@ #include #include #include -#include +#include #include "ar.h" #include "rel_aout.h" -#ifdef __BCC__ +#if defined(__BCC__) || defined(__HP_cc) #define HAVE_RENAME #undef HAVE_FSYNC #define SHORT_FILENAME diff --git a/bcc/bcc.c b/bcc/bcc.c index 9b053e5..67e5469 100644 --- a/bcc/bcc.c +++ b/bcc/bcc.c @@ -21,10 +21,11 @@ #ifndef MSDOS #include #endif +#else +#include #endif #include #include -#include #include #include #include diff --git a/copt/copt.c b/copt/copt.c index 350c163..d744da8 100644 --- a/copt/copt.c +++ b/copt/copt.c @@ -36,7 +36,6 @@ #include #include -#include #include #include diff --git a/cpp/cc.h b/cpp/cc.h index 5781f05..9bb7ebd 100644 --- a/cpp/cc.h +++ b/cpp/cc.h @@ -1,16 +1,16 @@ -#ifndef _P +#ifndef P #if __STDC__ -#define _P(x) x +#define P(x) x #else -#define _P(x) () +#define P(x) () #endif #endif -extern void cfatal _P((char*)); -extern void cerror _P((char*)); -extern void cwarn _P((char*)); -extern FILE * open_include _P((char*, char*, int)); +extern void cfatal P((char*)); +extern void cerror P((char*)); +extern void cwarn P((char*)); +extern FILE * open_include P((char*, char*, int)); extern FILE * curfile; extern char curword[]; @@ -22,11 +22,11 @@ extern int dialect; #define DI_KNR 1 #define DI_ANSI 2 -extern int gettok _P((void)); +extern int gettok P((void)); struct token_trans { char * name; int token; }; -struct token_trans * is_ctok _P((const char *str, unsigned int len)); -struct token_trans * is_ckey _P((const char *str, unsigned int len)); +struct token_trans * is_ctok P((const char *str, unsigned int len)); +struct token_trans * is_ckey P((const char *str, unsigned int len)); #define WORDSIZE 128 #define TK_WSPACE 256 @@ -101,8 +101,8 @@ struct token_trans * is_ckey _P((const char *str, unsigned int len)); #define MAX_INCLUDE 64 /* Nested includes */ #define MAX_DEFINE 64 /* Nested defines */ -extern char * set_entry _P((int,char*,void*)); -extern void * read_entry _P((int,char*)); +extern char * set_entry P((int,char*,void*)); +extern void * read_entry P((int,char*)); struct define_item { diff --git a/cpp/cpp.c b/cpp/cpp.c index 231760b..7fcc4b5 100644 --- a/cpp/cpp.c +++ b/cpp/cpp.c @@ -1,9 +1,10 @@ #include #include -#include #ifdef __STDC__ #include +#else +#include #endif #include "cc.h" @@ -92,26 +93,26 @@ struct arg_store { int in_define; }; -static int chget _P((void)); -static int chget_raw _P((void)); -static void unchget _P((int)); -static int gettok_nosub _P((void)); -static int get_onetok _P((int)); -static int pgetc _P((void)); -static int do_preproc _P((void)); -static int do_proc_copy_hashline _P((void)); -static int do_proc_if _P((int)); -static void do_proc_include _P((void)); -static void do_proc_define _P((void)); -static void do_proc_undef _P((void)); -static void do_proc_else _P((void)); -static void do_proc_endif _P((void)); -static void do_proc_tail _P((void)); -static int get_if_expression _P((void)); -static int_type get_expression _P((int)); -static int_type get_exp_value _P((void)); -static void gen_substrings _P((char *, char *, int)); -static char * insert_substrings _P((char *, struct arg_store *, int)); +static int chget P((void)); +static int chget_raw P((void)); +static void unchget P((int)); +static int gettok_nosub P((void)); +static int get_onetok P((int)); +static int pgetc P((void)); +static int do_preproc P((void)); +static int do_proc_copy_hashline P((void)); +static int do_proc_if P((int)); +static void do_proc_include P((void)); +static void do_proc_define P((void)); +static void do_proc_undef P((void)); +static void do_proc_else P((void)); +static void do_proc_endif P((void)); +static void do_proc_tail P((void)); +static int get_if_expression P((void)); +static int_type get_expression P((int)); +static int_type get_exp_value P((void)); +static void gen_substrings P((char *, char *, int)); +static char * insert_substrings P((char *, struct arg_store *, int)); int gettok() diff --git a/cpp/cygwin.c b/cpp/cygwin.c deleted file mode 100644 index 5cb6e39..0000000 --- a/cpp/cygwin.c +++ /dev/null @@ -1,99 +0,0 @@ -/* Copyright (C) 1995,1996 Robert de Bath - * This file is part of the Linux-8086 C library and is distributed - * under the GNU Library General Public License. - */ - -/* - * CTYPE Character classification and conversion - */ - -/* - * I've copied this here from the bcc libs because cygwin's version has - * the _very_ silly feature of using _P as a private library constant. - * - * Single underscore variables are generally used for private variables - * in user libraries; the few stdio ones being 'leftovers' from version7 - * where user and system libraries were one and the same. - * - */ -#ifndef __CTYPE_H -#define __CTYPE_H - -static unsigned char __ctype[]; - -#define __CT_d 0x01 /* numeric digit */ -#define __CT_u 0x02 /* upper case */ -#define __CT_l 0x04 /* lower case */ -#define __CT_c 0x08 /* control character */ -#define __CT_s 0x10 /* whitespace */ -#define __CT_p 0x20 /* punctuation */ -#define __CT_x 0x40 /* hexadecimal */ - -/* Define these as simple old style ascii versions */ -#define toupper(c) (((c)>='a'&&(c)<='z') ? (c)^0x20 : (c)) -#define tolower(c) (((c)>='A'&&(c)<='Z') ? (c)^0x20 : (c)) -#define _toupper(c) ((c)^0x20) -#define _tolower(c) ((c)^0x20) -#define toascii(c) ((c)&0x7F) - -#define __CT(c) (__ctype[1+(unsigned char)c]) - -/* Note the '!!' is a cast to 'bool' and even BCC deletes it in an if() */ -#define isalnum(c) (!!(__CT(c)&(__CT_u|__CT_l|__CT_d))) -#define isalpha(c) (!!(__CT(c)&(__CT_u|__CT_l))) -#define isascii(c) (!((c)&~0x7F)) -#define iscntrl(c) (!!(__CT(c)&__CT_c)) -#define isdigit(c) (!!(__CT(c)&__CT_d)) -#define isgraph(c) (!(__CT(c)&(__CT_c|__CT_s))) -#define islower(c) (!!(__CT(c)&__CT_l)) -#define isprint(c) (!(__CT(c)&__CT_c)) -#define ispunct(c) (!!(__CT(c)&__CT_p)) -#define isspace(c) (!!(__CT(c)&__CT_s)) -#define isupper(c) (!!(__CT(c)&__CT_u)) -#define isxdigit(c) (!!(__CT(c)&__CT_x)) - -static unsigned char __ctype[257] = -{ - 0, /* -1 */ - __CT_c, __CT_c, __CT_c, __CT_c, /* 0x00..0x03 */ - __CT_c, __CT_c, __CT_c, __CT_c, /* 0x04..0x07 */ - __CT_c, __CT_c|__CT_s, __CT_c|__CT_s, __CT_c|__CT_s, /* 0x08..0x0B */ - __CT_c|__CT_s, __CT_c|__CT_s, __CT_c, __CT_c, /* 0x0C..0x0F */ - - __CT_c, __CT_c, __CT_c, __CT_c, /* 0x10..0x13 */ - __CT_c, __CT_c, __CT_c, __CT_c, /* 0x14..0x17 */ - __CT_c, __CT_c, __CT_c, __CT_c, /* 0x18..0x1B */ - __CT_c, __CT_c, __CT_c, __CT_c, /* 0x1C..0x1F */ - - __CT_s, __CT_p, __CT_p, __CT_p, /* 0x20..0x23 */ - __CT_p, __CT_p, __CT_p, __CT_p, /* 0x24..0x27 */ - __CT_p, __CT_p, __CT_p, __CT_p, /* 0x28..0x2B */ - __CT_p, __CT_p, __CT_p, __CT_p, /* 0x2C..0x2F */ - - __CT_d|__CT_x, __CT_d|__CT_x, __CT_d|__CT_x, __CT_d|__CT_x,/* 0x30..0x33 */ - __CT_d|__CT_x, __CT_d|__CT_x, __CT_d|__CT_x, __CT_d|__CT_x,/* 0x34..0x37 */ - __CT_d|__CT_x, __CT_d|__CT_x, __CT_p, __CT_p, /* 0x38..0x3B */ - __CT_p, __CT_p, __CT_p, __CT_p, /* 0x3C..0x3F */ - - __CT_p, __CT_u|__CT_x, __CT_u|__CT_x, __CT_u|__CT_x, /* 0x40..0x43 */ - __CT_u|__CT_x, __CT_u|__CT_x, __CT_u|__CT_x, __CT_u, /* 0x44..0x47 */ - __CT_u, __CT_u, __CT_u, __CT_u, /* 0x48..0x4B */ - __CT_u, __CT_u, __CT_u, __CT_u, /* 0x4C..0x4F */ - - __CT_u, __CT_u, __CT_u, __CT_u, /* 0x50..0x53 */ - __CT_u, __CT_u, __CT_u, __CT_u, /* 0x54..0x57 */ - __CT_u, __CT_u, __CT_u, __CT_p, /* 0x58..0x5B */ - __CT_p, __CT_p, __CT_p, __CT_p, /* 0x5C..0x5F */ - - __CT_p, __CT_l|__CT_x, __CT_l|__CT_x, __CT_l|__CT_x, /* 0x60..0x63 */ - __CT_l|__CT_x, __CT_l|__CT_x, __CT_l|__CT_x, __CT_l, /* 0x64..0x67 */ - __CT_l, __CT_l, __CT_l, __CT_l, /* 0x68..0x6B */ - __CT_l, __CT_l, __CT_l, __CT_l, /* 0x6C..0x6F */ - - __CT_l, __CT_l, __CT_l, __CT_l, /* 0x70..0x73 */ - __CT_l, __CT_l, __CT_l, __CT_l, /* 0x74..0x77 */ - __CT_l, __CT_l, __CT_l, __CT_p, /* 0x78..0x7B */ - __CT_p, __CT_p, __CT_p, __CT_c /* 0x7C..0x7F */ -}; - -#endif /* __CTYPE_H */ diff --git a/cpp/hash.c b/cpp/hash.c index 11c32da..7cab819 100644 --- a/cpp/hash.c +++ b/cpp/hash.c @@ -1,6 +1,10 @@ #include +#ifdef __STDC__ +#include +#else #include +#endif #include "cc.h" /* @@ -23,7 +27,7 @@ struct hashentry struct hashentry ** hashtable; int hashsize = 0xFF; /* 2^X -1 */ int hashcount = 0; -static int hashvalue _P((int namespace, char * word)); +static int hashvalue P((int namespace, char * word)); void * read_entry(namespace, word) diff --git a/cpp/main.c b/cpp/main.c index b7cf0ee..78db160 100644 --- a/cpp/main.c +++ b/cpp/main.c @@ -3,31 +3,28 @@ #if __STDC__ #include #include -#endif -#ifndef __CYGWIN__ -#include #else -#include "cygwin.c" +#include #endif +#include #include -#include #include #include "cc.h" #define MAXINCPATH 5 -int main _P((int argc, char ** argv)); -void undefine_macro _P((char * name)); -void define_macro _P((char * name)); -void print_toks_cpp _P((void)); -void print_toks_raw _P((void)); -void define_macro _P((char *)); -void undefine_macro _P((char *)); -void cmsg _P((char * mtype, char * str)); -char * token_txn _P((int)); -void pr_indent _P((int)); -void hash_line _P((void)); +int main P((int argc, char ** argv)); +void undefine_macro P((char * name)); +void define_macro P((char * name)); +void print_toks_cpp P((void)); +void print_toks_raw P((void)); +void define_macro P((char *)); +void undefine_macro P((char *)); +void cmsg P((char * mtype, char * str)); +char * token_txn P((int)); +void pr_indent P((int)); +void hash_line P((void)); char * include_paths[MAXINCPATH]; diff --git a/cpp/token1.c b/cpp/token1.c index 4b966f7..f3aa420 100644 --- a/cpp/token1.c +++ b/cpp/token1.c @@ -6,6 +6,6 @@ #ifdef __GNUC__ __inline #endif -static unsigned int hash1 _P((register const char *, register unsigned int)); +static unsigned int hash1 P((register const char *, register unsigned int)); #include "token1.h" diff --git a/cpp/token2.c b/cpp/token2.c index c535746..b4d22b1 100644 --- a/cpp/token2.c +++ b/cpp/token2.c @@ -6,6 +6,6 @@ #ifdef __GNUC__ __inline #endif -static unsigned int hash2 _P((register const char *, register unsigned int)); +static unsigned int hash2 P((register const char *, register unsigned int)); #include "token2.h" diff --git a/ifdef.c b/ifdef.c index 0d7fcdd..7289dc1 100644 --- a/ifdef.c +++ b/ifdef.c @@ -5,7 +5,7 @@ #include #ifdef __STDC__ /* == Not braindead compiler (hopefully!) */ -#include +#include #define P(x) x #else @@ -441,7 +441,7 @@ manifest_constant() #ifdef __linux__ save_name("__linux__", 'D'); #ifdef __i386__ - save_name("__linux____i386__", 'D'); + save_name("__linux_i386__", 'D'); #endif #endif #ifdef __unix__ @@ -499,4 +499,7 @@ manifest_constant() #ifdef __CYGWIN__ save_name("__CYGWIN__", 'D'); #endif +#ifdef __APPLE__ + save_name("__APPLE__", 'D'); +#endif } diff --git a/ld/Makefile b/ld/Makefile index 69170bd..b4aed62 100644 --- a/ld/Makefile +++ b/ld/Makefile @@ -3,20 +3,22 @@ LIBDIR =/usr/bin CFLAGS =-O LDFLAGS = -# May need some of these if the auto-sense fails. +# Will need some of these if you want native executables on non-Linux/i386 +# -DDETECTAOUT # Turn on detection. # -DV7_A_OUT # a.out.h is like V7 # -DBSD_A_OUT # a.out.h is like BSD # -DSTANDARD_GNU_A_OUT # a.out.h is like GNU normal. -# -DNO_AOUT # a.out.h is like nothing known! # -DEFS =-DREL_OUTPUT -DBUGCOMPAT +# -DREL_OUTPUT -DBUGCOMPAT # -r Produces weird *.o files. +# +DEFS =-DREL_OUTPUT # An alternative file for a non-standard a.out.h (eg i386 linux on an Alpha) # # NATIVE=-DA_OUT_INCL='"a_out_local.h"' -OBJS= dumps.o io.o ld.o readobj.o table.o typeconv.o linksyms.o \ - writex86.o writebin.o writerel.o +OBJS= dumps.o io.o ld.o readobj.o table.o typeconv.o linksyms.o mkar.o \ + writex86.o writebin.o writeemu.o all: ld86 objchop catimage objdump86 diff --git a/ld/bindef.h b/ld/bindef.h index 1c8dc49..c359509 100644 --- a/ld/bindef.h +++ b/ld/bindef.h @@ -1,22 +1,19 @@ -#if defined(__i386__) || defined(__8086__) || defined(__i386) -#ifndef MSDOS -#ifndef NO_AOUT -/* Ok, I'm just gonna make it simple ... override this if you like. */ -#ifndef A_OUT_INCL -#define A_OUT_INCL "a.out.h" +/* Only do native on Linux/i386 by default -- it's safer. */ +#ifndef DETECTAOUT +#if defined(__i386__) && defined(__linux__) +#define DETECTAOUT +#else +# ifdef A_OUT_INCL +# define DETECTAOUT +# endif +#endif #endif -/* This is how it used to be ... */ +#ifdef DETECTAOUT +/* Ok, I'm just gonna make it simple ... override this if you like. */ #ifndef A_OUT_INCL -# ifdef BSD_A_OUT -# ifdef STANDARD_GNU_A_OUT -# define A_OUT_INCL -# else -# define A_OUT_INCL "bsd-a.out.h" -# endif -# define A_OUT_INCL "a.out.h" /* maybe local copy of for X-link */ -# endif /* BSD_A_OUT */ +#define A_OUT_INCL #endif #include A_OUT_INCL @@ -76,5 +73,3 @@ #endif #endif /* NO_AOUT */ -#endif /* MSDOS */ -#endif /* CPU type */ diff --git a/ld/dumps.c b/ld/dumps.c index a969123..4732017 100644 --- a/ld/dumps.c +++ b/ld/dumps.c @@ -83,4 +83,12 @@ PUBLIC void dumpsyms() putbyte('\n'); } } + + putstr("Total memory used: "); +#ifdef LONG_OFFSETS + put08lx(memory_used()); +#else + put08x(memory_used()); +#endif + putbyte('\n'); } diff --git a/ld/io.c b/ld/io.c index 743fa94..bc8e73c 100644 --- a/ld/io.c +++ b/ld/io.c @@ -615,11 +615,11 @@ PUBLIC void usage() #ifdef REL_OUTPUT errexit("\ [-03NMdimrstz[-]] [-llib_extension] [-o outfile] [-Ccrtfile]\n\ - [-Llibdir] [-Olibfile] [-T textaddr] [-D dataaddr] [-H heapsize] infile..."); + [-Llibdir] [-Olibfile] [-Ttextaddr] [-Ddataaddr] [-Hheapsize] infile..."); #else errexit("\ [-03NMdimstz[-]] [-llib_extension] [-o outfile] [-Ccrtfile]\n\ - [-Llibdir] [-Olibfile] [-T textaddr] [-D dataaddr] [-H heapsize] infile..."); + [-Llibdir] [-Olibfile] [-Ttextaddr] [-Ddataaddr] [-Hheapsize] infile..."); #endif } diff --git a/ld/ld.c b/ld/ld.c index 403bdfb..cc95fb7 100644 --- a/ld/ld.c +++ b/ld/ld.c @@ -105,16 +105,10 @@ char **argv; case 'v': version_msg(); case 'r': /* relocatable output */ -#ifndef REL_OUTPUT -#ifndef MSDOS - /* Ok, try for an alternate linker */ - if( strcmp(argv[0], "ld86r") != 0 ) - { - argv[0] = "ld86r"; - execv("/usr/bin/ld86r", argv); - } -#endif - usage(); + case 't': /* trace modules linked */ + if (icount > 0) usage(); +#ifdef REL_OUTPUT + case 'B': /* Broken -r for dosemu. */ #endif case '0': /* use 16-bit libraries */ case '3': /* use 32-bit libraries */ @@ -122,7 +116,6 @@ char **argv; case 'i': /* separate I & D output */ case 'm': /* print modules linked */ case 's': /* strip symbols */ - case 't': /* trace modules linked */ case 'z': /* unmapped zero page */ case 'N': /* Native format a.out */ case 'd': /* Make a headerless outfile */ @@ -209,22 +202,21 @@ char **argv; usage(); } } - if(icount==0) fatalerror("no input files"); + if(icount==0) usage(); + +#ifdef BUGCOMPAT + if( icount==1 && ( flag['r'] && !flag['N'] ) ) { + flag['r'] = 0; + flag['B'] = 1; + } +#endif #ifdef REL_OUTPUT #ifndef MSDOS -#ifdef BUGCOMPAT - if( icount>1 && ( flag['r'] && !flag['N'] ) ) -#else if( flag['r'] && !flag['N'] ) -#endif { - /* Ok, try for an alternate linker */ - if( strcmp(argv[0], "ld86r") != 0 ) - { - argv[0] = "ld86r"; - execv("/usr/bin/ld86r", argv); - } + /* Do a relocatable link -- actually fake it with 'ar.c' */ + ld86r(argc, argv); } #endif #endif @@ -249,7 +241,7 @@ char **argv; if ( cpm86 ) flag['s'] = 1; #endif - linksyms(flag['r']); + linksyms(flag['r'] | flag['B']); if (outfilename == NUL_PTR) outfilename = "a.out"; #ifndef MSDOS @@ -258,12 +250,10 @@ char **argv; flag['z'] & flag['3']); else #endif -#ifdef BUGCOMPAT - if( flag['r'] ) - write_rel(outfilename, flag['i'], flag['3'], flag['s'], - flag['z'] & flag['3']); + if( flag['B'] ) + write_dosemu(outfilename, flag['i'], flag['3'], flag['s'], + flag['z'] & flag['3']); else -#endif write_elks(outfilename, flag['i'], flag['3'], flag['s'], flag['z'], flag['y']); if (flag['m']) diff --git a/ld/ld86r.c b/ld/ld86r.c index c8c0631..dfc876d 100644 --- a/ld/ld86r.c +++ b/ld/ld86r.c @@ -1,8 +1,13 @@ #include +#include #include #include -#include +#ifdef __STDC__ +#include +#include +#else #include +#endif #define ARMAG "!\n" #define SARMAG 8 diff --git a/ld/mkar.c b/ld/mkar.c new file mode 100644 index 0000000..96163b7 --- /dev/null +++ b/ld/mkar.c @@ -0,0 +1,74 @@ + +#include +#include +#include +#include +#ifdef __STDC__ +#include +#include +#else +#include +#endif + +#include "ar.h" + +static struct ar_hdr arbuf; + +void +ld86r(int argc, char ** argv) +{ +char buf[128]; + FILE * fd, * ifd; + struct stat st; + int ar, libarg=0, need_o = 0, got_o = 0; + + for(ar=1; ar 1 || need_o > got_o ) + fatalerror("-o option required for -r"); + + if( (fd =fopen(argv[libarg], "wb")) == 0 ) fatalerror("Cannot open archive"); + if( fwrite(ARMAG, 1, SARMAG, fd) != SARMAG) fatalerror("Cannot write magic"); + + for(ar=1; ar -#include -#include #ifdef __STDC__ #include +#else +#include #endif +#include #include "ar.h" #include "obj.h" @@ -36,6 +37,7 @@ char * ifname; long get_long _((void)); long get_sized _((int sz)); unsigned int get_word _((void)); +int get_byte _((void)); int main _((int argc, char**argv)); void do_file _((char * fname)); long read_arheader _((char *archentry)); @@ -44,6 +46,8 @@ int error _((char * str)); int read_objheader _((void)); int read_sectheader _((void)); int read_syms _((void)); +void disp_sectheader _((void)); +int disp_syms _((void)); void read_databytes _((void)); void hex_output _((int ch)); void fetch_aout_hdr _((void)); @@ -51,14 +55,24 @@ void dump_aout _((void)); void size_aout _((void)); void nm_aout _((void)); +int obj_ver; int sections; long segsizes[16]; -long textoff, textlen; -long str_off, str_len; +long textoff; +long textlen; +long str_off; +long str_len; long filepos; +int num_syms; +long code_bytes; char ** symnames; -char * symtab; +char * strtab; + +struct { + unsigned int nameoff, symtype; + long offset; +} *symtab; int display_mode = 0; int multiple_files = 0; @@ -177,7 +191,7 @@ do_module(fname, archive) char * fname; char * archive; { - int modno, i, ch; + int modno, i; size_text = size_data = size_bss = 0; byte_order = 0; @@ -209,6 +223,14 @@ char * archive; if( read_syms() < 0 ) break; + strtab = malloc((unsigned int)str_len+1); + if( strtab == 0 ) { error("Out of memory"); break; } + str_off = ftell(ifd); + fread(strtab, 1, (unsigned int)str_len, ifd); + + disp_sectheader(); + disp_syms(); + if( display_mode == 0 ) printf("text\tdata\tbss\tdec\thex\tfilename\n"); if( display_mode != 2 ) @@ -227,20 +249,6 @@ char * archive; read_databytes(); } - if( !archive && !display_mode ) - { - i=0; - while( (ch=getc(ifd)) != EOF ) - { - if( i == 0 ) - { - printf("TRAILER\n"); - i=1; - } - hex_output(ch); - } - hex_output(EOF); - } break; case 1: /* ELKS executable */ @@ -256,9 +264,9 @@ char * archive; break; } - if( symtab ) free(symtab); + if( strtab ) free(strtab); if( symnames ) free(symnames); - symtab = 0; + strtab = 0; symnames = 0; } @@ -306,32 +314,16 @@ read_objheader() int read_sectheader() { - long ssenc, cpos; - int i, ver; - - textoff = get_long(); textlen = get_long(); - str_len=get_word(); str_off=textoff-str_len; - ver = get_word(); + long ssenc; + int i; - symtab = malloc((unsigned int)str_len+1); - if( symtab == 0 ) return error("Out of memory"); + textoff = get_long(); /* Offset of bytecode in file */ + textlen = get_long(); /* Length of text+data (no bss) in memory */ + str_len = get_word(); /* Length of string table in file */ + obj_ver = get_word(); /* 0.0 */ - cpos = ftell(ifd); - fseek(ifd, filepos+str_off, 0); - fread(symtab, 1, (unsigned int)str_len, ifd); - fseek(ifd, cpos, 0); - - if( !display_mode ) - { - printf("MODULE '%s'\n", symtab); - printf("BYTEPOS %08lx\n", textoff); - printf("BINLEN %08lx\n", textlen); - printf("STRINGS %04lx +%04lx\n", str_off, str_len); - printf("VERSION %d.%d\n", ver/256, ver%256); - } - - (void)get_long(); /* Ignore fives */ - ssenc=get_long(); + (void)get_long(); /* Ignore fives */ + ssenc = get_long(); /* Sixteen segment size sizes */ for(i=0; i<16; i++) { @@ -339,48 +331,92 @@ read_sectheader() ss = (i^3); ss = ((ssenc>>(2*(15-ss)))&3); segsizes[i] = get_sized(ss); - if( segsizes[i] && !display_mode ) - printf("SEG%x %08lx\n", i, segsizes[i]); } - if( !display_mode ) - printf("\n"); + + num_syms = get_word(); /* Number of symbol codes */ return 0; } +void +disp_sectheader() +{ + int i; + if( display_mode ) return; + + printf("MODULE '%s'\n", strtab); + printf("BYTEPOS %08lx\n", textoff); + printf("BINLEN %08lx\n", textlen); + printf("STRINGS %04lx +%04lx\n", str_off, str_len); + printf("VERSION %d.%d\n", obj_ver/256, obj_ver%256); + + for(i=0; i<16; i++) + if( segsizes[i] ) + printf("SEG%x %08lx\n", i, segsizes[i]); + + printf("\n"); + printf("SYMS %u\n", num_syms); +} + int read_syms() { - int syms, i; - - syms=get_word(); + int i; - if( !display_mode ) printf("SYMS %u\n", syms); - if( syms < 0 ) return error("Bad symbol table"); + if( num_syms < 0 ) return error("Bad symbol table"); - symnames = malloc(syms*sizeof(char*)+1); + symnames = malloc(num_syms*sizeof(char*)+1); if( symnames == 0 ) return error("Out of memory"); + symtab = calloc(num_syms, sizeof(*symtab)); + if( symtab == 0 ) return error("Out of memory"); + if(display_mode == 2 && multiple_files) printf("\n%s:\n", ifname); - for(i=0; i>14)&3); + symtab[i].offset = get_sized((symtab[i].symtype>>14)&3); + + if( symtype == 0x43 || symtype == 0x2003 ) + size_bss += symtab[i].offset; + } + + return 0; +} + +int +disp_syms() +{ + int i; + + if(display_mode == 2 && multiple_files) + printf("\n%s:\n", ifname); + + for(i=0; i str_len || nameoff < 0) - symnames[i] = symtab + str_len; + symnames[i] = strtab + str_len; else - symnames[i] = symtab+nameoff; + symnames[i] = strtab+nameoff; if( !display_mode ) { @@ -425,9 +461,6 @@ read_syms() } printf(" %s\n", symnames[i]); } - - if( symtype == 0x43 || symtype == 0x2003 ) - size_bss += offset; } if( !display_mode ) printf("\n"); @@ -439,16 +472,18 @@ void read_databytes() { static char * relstr[] = {"ERR", "DB", "DW", "DD"}; - long l; + long l, cpos; int ch, i; int curseg = 0; int relsize = 0; + + cpos = ftell(ifd); fseek(ifd, filepos+textoff, 0); printf("\nBYTECODE\n"); for(;;) { - if( (ch=getc(ifd)) == EOF ) break; + if( (ch=get_byte()) == -1 ) break; if( ch == 0 ) break; @@ -467,7 +502,7 @@ static char * relstr[] = {"ERR", "DB", "DW", "DD"}; printf("SEG %x\n", curseg= (ch&0xF)); break; default: printf("CODE %02x - unknown\n", ch); - return ; + goto break_break ; } break; case 0x40: /* Raw bytes */ @@ -476,12 +511,12 @@ static char * relstr[] = {"ERR", "DB", "DW", "DD"}; if( abscnt == 0 ) abscnt = 64; for( i=0; iname; while (TRUE) { + /* Stats: need a checkused against 's', maybe. */ if (s >= tableend) outofmemory(); if ((c = readchar()) < 0) @@ -187,9 +200,27 @@ PUBLIC char *readstring() PUBLIC void release(cptr) char *cptr; { + check_used(); + mainavail += cptr - tableend; + usedtop -= cptr - tableend; + tableend = cptr; } +PRIVATE void check_used() +{ + int used; + + used = usedtop + mainavail - (tableend - tableptr); + if (used > maxused) maxused = used; +} + +PUBLIC int memory_used() +{ + check_used(); + return maxused; +} + /* allocate space for string */ PUBLIC char *stralloc(s) diff --git a/ld/type.h b/ld/type.h index 8d4390f..950446f 100644 --- a/ld/type.h +++ b/ld/type.h @@ -144,6 +144,7 @@ char *ourmalloc P((unsigned nbytes)); void ourfree P((char *cptr)); char *readstring P((void)); void release P((char *cptr)); +int memory_used P((void)); char *stralloc P((char *s)); /* typeconvert.c */ @@ -161,7 +162,7 @@ bool_pt typeconv_init P((bool_pt big_endian, bool_pt long_big_endian)); void writebin P((char *outfilename, bool_pt argsepid, bool_pt argbits32, bool_pt argstripflag, bool_pt arguzp)); -void write_rel P((char *outfilename, bool_pt argsepid, bool_pt argbits32, +void write_dosemu P((char *outfilename, bool_pt argsepid, bool_pt argbits32, bool_pt argstripflag, bool_pt arguzp)); /* write_elks.c */ diff --git a/ld/writebin.c b/ld/writebin.c index e833f6c..d3032e3 100644 --- a/ld/writebin.c +++ b/ld/writebin.c @@ -3,12 +3,6 @@ /* Copyright (C) 1994 Bruce Evans */ -#ifndef NO_AOUT -#ifndef A_OUT_INCL -#define A_OUT_INCL -#endif -#endif - #include "syshead.h" #include "bindef.h" #include "const.h" diff --git a/ld/writeemu.c b/ld/writeemu.c new file mode 100644 index 0000000..b0438fc --- /dev/null +++ b/ld/writeemu.c @@ -0,0 +1,20 @@ +/* + * This uses a special version of writebin for bug compatibility with + * the old bin86 package. + * + * This _should_ be replaced by a function that writes out a as86 object + * but then it would completely **** up dosemu compiles. + * + * NOTE: A some time I intend to replace this with a routine that generates + * an as86 object file. + */ + +#undef A_OUT_INCL +#define A_OUT_INCL "rel_aout.h" +#define BSD_A_OUT 1 +#define FILEHEADERLENGTH 32 +#define ELF_SYMS 0 + +#define FUNCNAME write_dosemu + +#include "writebin.c" diff --git a/ld/writerel.c b/ld/writerel.c deleted file mode 100644 index a0294f5..0000000 --- a/ld/writerel.c +++ /dev/null @@ -1,22 +0,0 @@ -/* - * This uses a special version of writebin for bug compatibility with - * the old bin86 package. - * - * This _should_ be replaced by a function that writes out a as86 object - * but then it would completely **** up dosemu compiles. - * - * NOTE: A some time I intend to replace this with a routine that generates - * an as86 object file. - */ - -#ifdef BUGCOMPAT -#define A_OUT_INCL "rel_aout.h" -#define BSD_A_OUT 1 -#define FILEHEADERLENGTH 32 -#define ELF_SYMS 0 - -#define FUNCNAME write_rel -#undef NO_AOUT - -#include "writebin.c" -#endif diff --git a/makefile.in b/makefile.in index ac4c989..c026376 100644 --- a/makefile.in +++ b/makefile.in @@ -27,7 +27,7 @@ MAKEX= # files. This should be fine for Linux, but it won't be for AIX etc. # Unfortunatly it's even _required_ for linux because some versions # of Redhat have a broken standard ar command. -#ifdef __linux__ +#ifdef __linux_i386__ AR=ar86 #endif @@ -68,21 +68,22 @@ BCCARCH =-Mf -O #endif #endif -# Alter these if for some reason you don't want this done as root. -#ifdef __CYGWIN__ -INDAT=-m 644 -INEXE=-m 755 -INSCR=-m 755 -#else -#ifdef __BCC__ -INDAT=-o root -g root -m 644 -INEXE=-o root -g root -m 755 -INSCR=-o root -g root -m 755 -#else +# Apple cpp-precomp 6.14 (devkit-213/devkit_tools-214) cannot +# handle the QUOT macro in bcc. It puts a space in /usr so that +# it becomes / usr +#ifdef __APPLE__ +CFLAGS += -no-cpp-precomp +#endif + +# Yet again other systems have general weirdness here. +#ifdef __linux__ INDAT=-o root -g root -m 644 INEXE=-o root -g root -m 755 -s INSCR=-o root -g root -m 755 -#endif +#else +INDAT=-m 644 +INEXE=-m 755 +INSCR=-m 755 #endif #ifdef __CYGWIN__ @@ -188,14 +189,10 @@ objdump86: bindir elksemu: bindir #ifndef __AS386_16__ #ifdef __linux_i386__ - $(MAKEC) elksemu \ - CC='$(CC)' PREFIX=$(PREFIX) LIBPRE='$(LIBPRE)' LIBDIR='$(LIBDIR)' BINDIR='$(BINDIR)' \ - elksemu -#else $(MAKEC) elksemu CC='ncc' elksemu -#endif cp -p elksemu/elksemu bin/elksemu #endif +#endif install-ln: bcc cpp unproto copt as86 ar86 ld86 elksemu install -d $(DISTBIN) @@ -205,7 +202,9 @@ install-ln: bcc cpp unproto copt as86 ar86 ld86 elksemu ln -fs `pwd`/bin/ar86 $(DISTBIN)/ar86 ln -fs `pwd`/bin/ld86 $(DISTBIN)/ld86 #ifndef __AS386_16__ +#ifdef __linux_i386__ ln -fs `pwd`/bin/elksemu $(DIST)/lib/elksemu +#endif #endif -install -d $(DIST)/usr/lib -install $(INDAT) libc/error/liberror.txt $(DIST)/usr/lib/liberror.txt @@ -231,9 +230,11 @@ install-bcc: bcc cpp unproto copt as86 ar86 ld86 objdump86 # NB: This doesn't install as a suid root, that's ok though. install-emu: elksemu #ifndef __AS386_16__ +#ifdef __linux_i386__ install -d $(DIST)/lib install $(INEXE) bin/elksemu $(DIST)/lib/elksemu #endif +#endif install-man: -$(MAKEC) man MANDIR=$(DIST)$(PREFIX)/man install @@ -287,10 +288,11 @@ lib-bsd: bindir #ifdef __AS386_16__ alt-libs: lib-stand lib-dos lib-fast + @touch lib/lib1-done #else alt-libs: lib-stand lib-dos lib-386 lib-fast -#endif @touch lib/lib1-done +#endif lib-fast: bindir test -f bin/ncc diff --git a/unproto/Makefile b/unproto/Makefile index 42fb1d9..55b8a9d 100644 --- a/unproto/Makefile +++ b/unproto/Makefile @@ -83,7 +83,7 @@ OBJECTS = tok_io.o tok_class.o tok_pool.o unproto.o vstring.o symbol.o error.o \ CFLAGS = -O LDFLAGS = -CCFLAGS = $(CFLAGS) $(PIPE) $(SKIP) $(BELL) $(MAP) $(ALIAS) -DREOPEN +CCFLAGS = $(CFLAGS) -w $(PIPE) $(SKIP) $(BELL) $(MAP) $(ALIAS) -DREOPEN #CFLAGS = -O $(PIPE) $(SKIP) $(BELL) $(MAP) $(ALIAS) -p -Dstatic= #CFLAGS = -g $(PIPE) $(SKIP) $(BELL) $(MAP) $(ALIAS) -DDEBUG -- cgit v1.2.1