diff -Nurd linux86.old/Changes linux86/Changes --- linux86.old/Changes Sat Sep 20 18:43:23 2003 +++ linux86/Changes Sun Nov 2 08:16:51 2003 @@ -3,6 +3,11 @@ > 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 -Nurd linux86.old/Makefile linux86/Makefile --- linux86.old/Makefile Thu Jul 31 21:33:54 2003 +++ linux86/Makefile Sat Sep 20 18:47:54 2003 @@ -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 -Nurd linux86.old/ar/alloca.c linux86/ar/alloca.c --- linux86.old/ar/alloca.c Mon Aug 18 08:13:58 2003 +++ linux86/ar/alloca.c Tue Oct 7 22:31:03 2003 @@ -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 -Nurd linux86.old/ar/ar.c linux86/ar/ar.c --- linux86.old/ar/ar.c Sun Aug 31 09:09:29 2003 +++ linux86/ar/ar.c Tue Oct 7 22:31:59 2003 @@ -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 -Nurd linux86.old/bcc/bcc.c linux86/bcc/bcc.c --- linux86.old/bcc/bcc.c Sun Aug 31 14:30:18 2003 +++ linux86/bcc/bcc.c Tue Oct 7 20:37:41 2003 @@ -21,10 +21,11 @@ #ifndef MSDOS #include #endif +#else +#include #endif #include #include -#include #include #include #include diff -Nurd linux86.old/copt/copt.c linux86/copt/copt.c --- linux86.old/copt/copt.c Sat Aug 3 14:05:25 2002 +++ linux86/copt/copt.c Tue Oct 7 20:46:35 2003 @@ -36,7 +36,6 @@ #include #include -#include #include #include diff -Nurd linux86.old/cpp/cc.h linux86/cpp/cc.h --- linux86.old/cpp/cc.h Sun Aug 31 09:24:55 2003 +++ linux86/cpp/cc.h Sun Nov 2 08:10:32 2003 @@ -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 @@ #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 @@ #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 -Nurd linux86.old/cpp/cpp.c linux86/cpp/cpp.c --- linux86.old/cpp/cpp.c Tue Aug 13 22:15:44 2002 +++ linux86/cpp/cpp.c Sun Nov 2 08:10:42 2003 @@ -1,9 +1,10 @@ #include #include -#include #ifdef __STDC__ #include +#else +#include #endif #include "cc.h" @@ -92,26 +93,26 @@ 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 -Nurd linux86.old/cpp/cygwin.c linux86/cpp/cygwin.c --- linux86.old/cpp/cygwin.c Sun Aug 31 08:10:05 2003 +++ linux86/cpp/cygwin.c Thu Jan 1 01:00:00 1970 @@ -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 -Nurd linux86.old/cpp/hash.c linux86/cpp/hash.c --- linux86.old/cpp/hash.c Sat Aug 3 07:26:07 2002 +++ linux86/cpp/hash.c Sun Nov 2 08:11:10 2003 @@ -1,6 +1,10 @@ #include +#ifdef __STDC__ +#include +#else #include +#endif #include "cc.h" /* @@ -23,7 +27,7 @@ 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 -Nurd linux86.old/cpp/main.c linux86/cpp/main.c --- linux86.old/cpp/main.c Sun Aug 31 08:13:22 2003 +++ linux86/cpp/main.c Sun Nov 2 08:12:14 2003 @@ -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 -Nurd linux86.old/cpp/token1.c linux86/cpp/token1.c --- linux86.old/cpp/token1.c Sat Aug 3 07:25:20 2002 +++ linux86/cpp/token1.c Sun Nov 2 08:11:22 2003 @@ -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 -Nurd linux86.old/cpp/token2.c linux86/cpp/token2.c --- linux86.old/cpp/token2.c Sat Aug 3 07:25:40 2002 +++ linux86/cpp/token2.c Sun Nov 2 08:11:39 2003 @@ -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 -Nurd linux86.old/ifdef.c linux86/ifdef.c --- linux86.old/ifdef.c Sun Aug 31 07:12:58 2003 +++ linux86/ifdef.c Thu Oct 9 23:43:23 2003 @@ -5,7 +5,7 @@ #include #ifdef __STDC__ /* == Not braindead compiler (hopefully!) */ -#include +#include #define P(x) x #else @@ -441,7 +441,7 @@ #ifdef __linux__ save_name("__linux__", 'D'); #ifdef __i386__ - save_name("__linux____i386__", 'D'); + save_name("__linux_i386__", 'D'); #endif #endif #ifdef __unix__ @@ -498,5 +498,8 @@ /* This isn't much nicer */ #ifdef __CYGWIN__ save_name("__CYGWIN__", 'D'); +#endif +#ifdef __APPLE__ + save_name("__APPLE__", 'D'); #endif } diff -Nurd linux86.old/ld/Makefile linux86/ld/Makefile --- linux86.old/ld/Makefile Sun Aug 31 15:19:52 2003 +++ linux86/ld/Makefile Mon Oct 6 18:14:16 2003 @@ -3,20 +3,22 @@ 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 -Nurd linux86.old/ld/bindef.h linux86/ld/bindef.h --- linux86.old/ld/bindef.h Sun Aug 31 13:06:09 2003 +++ linux86/ld/bindef.h Tue Oct 7 20:22:02 2003 @@ -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 -Nurd linux86.old/ld/dumps.c linux86/ld/dumps.c --- linux86.old/ld/dumps.c Wed Jan 28 20:24:26 1998 +++ linux86/ld/dumps.c Tue Oct 7 09:02:28 2003 @@ -83,4 +83,12 @@ putbyte('\n'); } } + + putstr("Total memory used: "); +#ifdef LONG_OFFSETS + put08lx(memory_used()); +#else + put08x(memory_used()); +#endif + putbyte('\n'); } diff -Nurd linux86.old/ld/io.c linux86/ld/io.c --- linux86.old/ld/io.c Sun Aug 31 14:32:57 2003 +++ linux86/ld/io.c Mon Oct 6 17:27:43 2003 @@ -615,11 +615,11 @@ #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 -Nurd linux86.old/ld/ld.c linux86/ld/ld.c --- linux86.old/ld/ld.c Wed Dec 4 21:12:02 2002 +++ linux86/ld/ld.c Tue Oct 7 07:53:36 2003 @@ -105,16 +105,10 @@ 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 @@ 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 @@ 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 @@ 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 @@ 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 -Nurd linux86.old/ld/ld86r.c linux86/ld/ld86r.c --- linux86.old/ld/ld86r.c Sun Oct 5 12:39:35 1997 +++ linux86/ld/ld86r.c Mon Oct 6 11:51:58 2003 @@ -1,8 +1,13 @@ #include +#include #include #include -#include +#ifdef __STDC__ +#include +#include +#else #include +#endif #define ARMAG "!\n" #define SARMAG 8 diff -Nurd linux86.old/ld/mkar.c linux86/ld/mkar.c --- linux86.old/ld/mkar.c Thu Jan 1 01:00:00 1970 +++ linux86/ld/mkar.c Sun Nov 2 08:30:36 2003 @@ -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 @@ 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 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 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 @@ 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 @@ 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 @@ 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 @@ break; } - if( symtab ) free(symtab); + if( strtab ) free(strtab); if( symnames ) free(symnames); - symtab = 0; + strtab = 0; symnames = 0; } @@ -306,32 +314,16 @@ 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(); - - symtab = malloc((unsigned int)str_len+1); - if( symtab == 0 ) return error("Out of memory"); - - cpos = ftell(ifd); - fseek(ifd, filepos+str_off, 0); - fread(symtab, 1, (unsigned int)str_len, ifd); - fseek(ifd, cpos, 0); + long ssenc; + int i; - 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); - } + 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 */ - (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 @@ 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 @@ } printf(" %s\n", symnames[i]); } - - if( symtype == 0x43 || symtype == 0x2003 ) - size_bss += offset; } if( !display_mode ) printf("\n"); @@ -439,16 +472,18 @@ 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 @@ 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 @@ 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,7 +200,25 @@ 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 */ diff -Nurd linux86.old/ld/type.h linux86/ld/type.h --- linux86.old/ld/type.h Wed Mar 20 22:17:42 2002 +++ linux86/ld/type.h Tue Oct 7 20:35:51 2003 @@ -144,6 +144,7 @@ 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 @@ 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 -Nurd linux86.old/ld/writebin.c linux86/ld/writebin.c --- linux86.old/ld/writebin.c Sun Aug 31 13:15:51 2003 +++ linux86/ld/writebin.c Tue Oct 7 20:21:02 2003 @@ -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 -Nurd linux86.old/ld/writeemu.c linux86/ld/writeemu.c --- linux86.old/ld/writeemu.c Thu Jan 1 01:00:00 1970 +++ linux86/ld/writeemu.c Tue Oct 7 20:19:36 2003 @@ -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 -Nurd linux86.old/ld/writerel.c linux86/ld/writerel.c --- linux86.old/ld/writerel.c Wed Apr 23 22:05:51 1997 +++ linux86/ld/writerel.c Thu Jan 1 01:00:00 1970 @@ -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 -Nurd linux86.old/makefile.in linux86/makefile.in --- linux86.old/makefile.in Sun Aug 31 14:45:08 2003 +++ linux86/makefile.in Thu Oct 9 23:44:57 2003 @@ -27,7 +27,7 @@ # 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 @@ #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 @@ 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,8 +202,10 @@ 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 @@ # 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 @@ #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 -Nurd linux86.old/unproto/Makefile linux86/unproto/Makefile --- linux86.old/unproto/Makefile Sun Aug 31 13:48:15 2003 +++ linux86/unproto/Makefile Mon Oct 6 18:01:45 2003 @@ -83,7 +83,7 @@ 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