2015-11-14  Juan Manuel Guerrero  <juan.guerrero@gmx.de>

	* watt/bin/djgpp.mak: -march=i386 -mtune=i586 added to CFLAGS to generate
	i386 compatible code.

	* watt/bin/ping.c (main):  Use USE_RS232_DBG to select call of trace2com_init.

	* watt/src/makefile.all: -march=i386 -mtune=i586 added to CFLAGS to generate
	i386 compatible code.
	-gcoff flag removed when building DXE module.

	* watt/src/zlib/makefile.all: -march=i386 -mtune=i586 added to CFLAGS
	to generate i386 compatible code.
	-gcoff flag removed when building DXE module.

	* watt/inc/sys/cdefs.h [__GNUC__, __GNUC_MINOR__]:  Replace macro
	_W32_EXTERN_INLINE with __EXTERN_INLINE__.

	* watt/inc/sys/swap.h:  Use macro __EXTERN_INLINE__ instead of macro
	_W32_EXTERN_INLINE.

	* watt/src/cpumodel.h:  Use macro __EXTERN_INLINE__ instead of macro
	_W32_EXTERN_INLINE.

	* watt/src/djimport.c (open_module):  Keep access instead of replacing
	it by _chmod.

	* watt/src/dxe_sym.h:  Keep access instead of replacing it by _chmod.

	* watt/src/ioport.h:  Use macro __EXTERN_INLINE__ instead of macro
	_W32_EXTERN_INLINE.
 
	* watt/src/misc.c:  Use macro __EXTERN_INLINE__ instead of macro
	_W32_EXTERN_INLINE.

	* watt/src/misc.h:  Use macro __EXTERN_INLINE__ instead of macro
	_W32_EXTERN_INLINE.

	* watt/src/pcconfig.c (do_include_file, tcp_config_name, tcp_config):
	Use macro access instead of calling function _chmod directly.

	* watt/src/portability.h [__DJGPP__]:  Define macro access to hide the
	DOS/DJGPP specific non-posix function call of _chmod.

	* watt/src/pcdhcp.c (std_write_config):  Use macro access instead of
	calling function _chmod directly.

	* watt/src/pcsarp.c (sarp_init):  Use macro access instead of calling
	function _chmod directly.







diff -aprNU5 wattcp.q2dos/bin/djgpp.mak watt/bin/djgpp.mak
--- wattcp.q2dos/bin/djgpp.mak	2015-11-14 17:20:06 +0100
+++ watt/bin/djgpp.mak	2015-11-15 18:53:06 +0100
@@ -48,11 +48,11 @@ else
   WATTLIB = ../lib/libwatt.a
   EXTRAS  = tiny.c
 endif
 
 CC      = gcc
-CFLAGS += -Wall -W -g -gcoff -O2 -I$(INC_DIR) #-s # strip symbols from .exe
+CFLAGS += -Wall -W -g -O2 -I$(INC_DIR) -march=i386 -mtune=i586 #-s # strip symbols from .exe
 
 ifeq ($(USE_EXCEPT),1)
   CFLAGS += -DUSE_EXCEPT
   EXTRAS += d:/prog/mw/except/lib/libexc.a
 endif
diff -aprNU5 wattcp.q2dos/bin/ping.c watt/bin/ping.c
--- wattcp.q2dos/bin/ping.c	2015-11-14 17:20:06 +0100
+++ watt/bin/ping.c	2015-11-15 18:53:06 +0100
@@ -199,11 +199,11 @@ int main (int argc, char **argv)
        case 'c': count = atol (optarg);
                  if (count < 1)
                     Usage ("illegal count argument\n");
                  break;
        case 'C':
-#ifdef __DJGPP__
+#if defined(__DJGPP__) && defined(USE_RS232_DBG)
                  if (!trace2com_init (optarg[0]-'0',115200UL))
                  {
                    printf ("Failed to initialise COM%d\n", optarg[0]-'0');
                    return (-1);
                  }
diff -aprNU5 wattcp.q2dos/inc/sys/cdefs.h watt/inc/sys/cdefs.h
--- wattcp.q2dos/inc/sys/cdefs.h	2015-11-14 22:32:52 +0100
+++ watt/inc/sys/cdefs.h	2015-11-15 18:53:06 +0100
@@ -189,15 +189,15 @@ struct mbuf {
 
 #if defined(__GNUC__)  /* from djgpp-2.04 sys/cdefs.h : */
 /* Ensure that always traditional GNU extern inline semantics are used
    (aka -fgnu89-inline) even if ISO C99 semantics have been specified.  */
 #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 2)
-# define _W32_EXTERN_INLINE  extern __inline__ __attribute__ ((__gnu_inline__))
+# define __EXTERN_INLINE__  extern __inline__ __attribute__ ((__gnu_inline__))
 #else
-# define _W32_EXTERN_INLINE  extern __inline__
+# define __EXTERN_INLINE__  extern __inline__
 #endif
-#endif /* _W32_EXTERN_INLINE */
+#endif /* __EXTERN_INLINE__ */
 
 /*
  * Delete pseudo-keywords wherever they are not available or needed.
  * This seems to break MingW in mysterious ways, so leave it,
  */
diff -aprNU5 wattcp.q2dos/inc/sys/swap.h watt/inc/sys/swap.h
--- wattcp.q2dos/inc/sys/swap.h	2015-11-14 22:32:52 +0100
+++ watt/inc/sys/swap.h	2015-11-15 18:53:06 +0100
@@ -56,21 +56,21 @@ __BEGIN_DECLS
   #define intel16(x) __ntohs(x)
 
   /*
    * Ripped (and adapted) from <linux/include/asm-386/byteorder.h>
    */
-  /*@unused@*/ _W32_EXTERN_INLINE unsigned long __ntohl (unsigned long x)
+  /*@unused@*/ __EXTERN_INLINE__ unsigned long __ntohl (unsigned long x)
   {
     __asm__ __volatile (
              "xchgb %b0, %h0\n\t"   /* swap lower bytes  */
              "rorl  $16, %0\n\t"    /* swap words        */
              "xchgb %b0, %h0"       /* swap higher bytes */
             : "=q" (x) : "0" (x));
     return (x);
   }
 
-  /*@unused@*/ _W32_EXTERN_INLINE unsigned short __ntohs (unsigned short x)
+  /*@unused@*/ __EXTERN_INLINE__ unsigned short __ntohs (unsigned short x)
   {
     __asm__ __volatile__ (
               "xchgb %b0, %h0"       /* swap bytes */
             : "=q" (x) : "0" (x));
     return (x);
diff -aprNU5 wattcp.q2dos/src/cpumodel.h watt/src/cpumodel.h
--- wattcp.q2dos/src/cpumodel.h	2015-11-14 22:32:52 +0100
+++ watt/src/cpumodel.h	2015-11-15 18:53:06 +0100
@@ -154,11 +154,11 @@ extern CONST char  DATA_DECL x86_vendor_
 
 #if defined(__GNUC__)
   /*
    * Call this only if x86_have_cpuid == TRUE.
    */
-  /*@unused@*/ _W32_EXTERN_INLINE void get_cpuid(DWORD val, DWORD *eax,
+  /*@unused@*/ __EXTERN_INLINE__ void get_cpuid(DWORD val, DWORD *eax,
                                                 DWORD *ebx,DWORD *ecx,
                                                 DWORD *edx)
   {
     __asm__ __volatile__ (
               ".byte 0x0F,0xA2;"   /* cpuid opcode */
@@ -175,20 +175,20 @@ extern CONST char  DATA_DECL x86_vendor_
    * Return CPU timestamp value. Don't call unless 'has_rdtsc'
    * is TRUE. This code is originally by
    *   Tom Burgess <Tom_Burgess@bc.sympatico.ca> and
    *   Douglas Eleveld <deleveld@dds.nl>
    */
-  _W32_EXTERN_INLINE uint64 get_rdtsc (void)
+  __EXTERN_INLINE__ uint64 get_rdtsc (void)
   {
     register uint64 tsc;
     __asm__ __volatile__ (
               ".byte 0x0F, 0x31;"   /* rdtsc opcode */
             : "=A" (tsc) );
     return (tsc);
   }
 
-  _W32_EXTERN_INLINE void get_rdtsc2 (struct ulong_long *tsc)
+  __EXTERN_INLINE__ void get_rdtsc2 (struct ulong_long *tsc)
   {
     __asm__ __volatile__ (
               ".byte 0x0F, 0x31;"
             : "=a" (tsc->lo), "=d" (tsc->hi) : );
   }
@@ -289,11 +289,11 @@ static void pkt_restore_fpu (char far *s
 /*
  * Check if a CPUID instruction is available on this CPU.
  * Note used at the moment. See cpumodel.asm instead.
  */
 #if defined(__GNUC__)
-_W32_EXTERN_INLINE BOOL have_cpuid (void)
+__EXTERN_INLINE__ BOOL have_cpuid (void)
 {
   int result = -1;
 
   /* We're checking if the bit #21 of EFLAGS
    * can be toggled. If yes = CPUID is available.
diff -aprNU5 wattcp.q2dos/src/djimport.c watt/src/djimport.c
--- wattcp.q2dos/src/djimport.c	2015-11-14 22:32:52 +0100
+++ watt/src/djimport.c	2015-11-15 18:53:06 +0100
@@ -422,11 +422,15 @@ static void *open_module (const char *mo
   sym->_go32_dpmi_lock_code                        = _go32_dpmi_lock_code;
   sym->_go32_dpmi_lock_data                        = _go32_dpmi_lock_data;
   sym->_go32_info_block                            = _go32_info_block;
   sym->_go32_want_ctrl_break                       = _go32_want_ctrl_break;
   sym->_write                                      = _write;
+#if 0
+  sym->access                                      = access;
+#else
   sym->_chmod                                      = _chmod;
+#endif
   sym->atexit                                      = atexit;
   sym->atoi                                        = atoi;
   sym->atol                                        = atol;
   sym->bsearch                                     = bsearch;
   sym->calloc                                      = calloc;
diff -aprNU5 wattcp.q2dos/src/dxe_sym.h watt/src/dxe_sym.h
--- wattcp.q2dos/src/dxe_sym.h	2015-11-14 22:32:52 +0100
+++ watt/src/dxe_sym.h	2015-11-15 18:53:06 +0100
@@ -120,11 +120,15 @@ struct st_symbol
   int            (*_go32_dpmi_free_real_mode_callback) (_go32_dpmi_seginfo *);
   int            (*_go32_dpmi_lock_code) (void *, unsigned long);
   int            (*_go32_dpmi_lock_data) (void *, unsigned long);
   void           (*_go32_want_ctrl_break) (int);
   ssize_t        (*_write) (int, const void *, size_t);
+#if 0
+  int            (*access) (const char *, int);
+#else
   int            (*_chmod) (const char *, int, ...);
+#endif
   int            (*atexit) (void (*func)(void));
   int            (*atoi) (const char *);
   long           (*atol) (const char *);
   void          *(*bsearch) (const void *, const void *, size_t, size_t, int (*)(const void *, const void *));
   void          *(*calloc) (size_t, size_t);
@@ -284,11 +288,15 @@ extern struct st_symbol_t import_export;
 #define _go32_dpmi_lock_code                        import_export._go32_dpmi_lock_code
 #define _go32_dpmi_lock_data                        import_export._go32_dpmi_lock_data
 #define _go32_info_block                            import_export._go32_info_block
 #define _go32_want_ctrl_break                       import_export._go32_want_ctrl_break
 #define _write                                      import_export._write
+#if 0
+#define access                                      import_export.access
+#else
 #define _chmod                                      import_export._chmod
+#endif
 #define atexit                                      import_export.atexit
 #define atoi                                        import_export.atoi
 #define atol                                        import_export.atol
 #define bsearch                                     import_export.bsearch
 #define calloc                                      import_export.calloc
diff -aprNU5 wattcp.q2dos/src/ioport.h watt/src/ioport.h
--- wattcp.q2dos/src/ioport.h	2015-11-14 22:32:52 +0100
+++ watt/src/ioport.h	2015-11-15 18:53:06 +0100
@@ -59,39 +59,39 @@
 
 #if defined (__EMX__)
 
 /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
 
-_W32_EXTERN_INLINE unsigned char inportb (unsigned short port)
+__EXTERN_INLINE__ unsigned char inportb (unsigned short port)
 {
   unsigned char rc;
   __asm__ __volatile__ (
             "inb %1, %0"
           : "=a" (rc)
           : "dN" (port));
   return (rc);
 }
 
-_W32_EXTERN_INLINE unsigned short inportw (unsigned short port)
+__EXTERN_INLINE__ unsigned short inportw (unsigned short port)
 {
   unsigned short rc;
   __asm__ __volatile__ (
             "inw %1, %0"
           : "=a" (rc)
           : "dN" (port));
   return (rc);
 }
 
-_W32_EXTERN_INLINE void outportb (unsigned short port, unsigned char data)
+__EXTERN_INLINE__ void outportb (unsigned short port, unsigned char data)
 {
   __asm__ __volatile__ (
              "outb %1, %0"
           :: "dN" (port),
              "a" (data));
 }
 
-_W32_EXTERN_INLINE void outportw (unsigned short port, unsigned short data)
+__EXTERN_INLINE__ void outportw (unsigned short port, unsigned short data)
 {
   __asm__ __volatile__ (
              "outw %1, %0"
           :: "dN" (port),
              "a" (data));
diff -aprNU5 wattcp.q2dos/src/makefile.all watt/src/makefile.all
--- wattcp.q2dos/src/makefile.all	2006-01-15 02:53:46 +0100
+++ watt/src/makefile.all	2015-11-15 18:53:06 +0100
@@ -148,12 +148,12 @@ PKT_STUB = pkt_stub.h
 ########################################################################
 
 @ifdef DJGPP
 
 CC     = gcc
-CFLAGS = -O2 -g -gcoff -I. -I../inc -W -Wall -fno-strength-reduce \
-         -ffast-math #-ffunction-sections -fomit-frame-pointer
+CFLAGS = -O2 -g -I. -I../inc -W -Wall -falign-loops=2 -falign-jumps=2 -falign-functions=2 \
+         -ffast-math -march=i386 -mtune=i586 #-ffunction-sections -fomit-frame-pointer
 
 AS     = as --gdwarf2
 TARGET = ../lib/libwatt.a
 OBJDIR = djgpp
 
@@ -196,12 +196,12 @@ clean:
 @elifdef DJGPP_DXE
 #
 # Not working yet.
 #
 CC     = gcc
-CFLAGS = -O2 -g -gcoff -I. -I../inc -Id:/prog/mw/except \
-         -DWATT32_DOS_DLL -W -Wall -fno-strength-reduce -ffast-math
+CFLAGS = -O2 -g -I. -I../inc -Id:/prog/mw/except \
+         -DWATT32_DOS_DLL -W -Wall -fno-strength-reduce -ffast-math -march=i386 -mtune=i586
 
 WARNING = -Wbad-function-cast -Wcast-qual -Wmissing-declarations \
           -Wmissing-prototypes -Wpointer-arith -Wshadow -Wstrict-prototypes \
           -Wwrite-strings -Wundef -Wcast-align -Wsign-compare
 
diff -aprNU5 wattcp.q2dos/src/misc.c watt/src/misc.c
--- wattcp.q2dos/src/misc.c	2015-11-14 22:32:52 +0100
+++ watt/src/misc.c	2015-11-15 18:53:06 +0100
@@ -1638,16 +1638,16 @@ static void stk_overflow (void _far *whe
 #undef _w32_CPUMODEL_H
 #undef _w32_MISC_H
 #undef _w32_IOPORT_H
 #undef BEEP
 #undef WIN_ASSERT
-#undef _W32_EXTERN_INLINE
+#undef __EXTERN_INLINE__
 
 #define extern
 #define __inline__
 #define __inline
-#define _W32_EXTERN_INLINE
+#define __EXTERN_INLINE__
 
 #if defined(__MINGW32__) || defined(__CYGWIN__)
   #undef intel
   #undef intel16
   #define __NO_INLINE__  /* emulate -O0 */
diff -aprNU5 wattcp.q2dos/src/misc.h watt/src/misc.h
--- wattcp.q2dos/src/misc.h	2015-11-14 22:32:52 +0100
+++ watt/src/misc.h	2015-11-15 18:53:06 +0100
@@ -728,33 +728,33 @@ extern const char *short_strerror (int e
   /* Borrowed from djgpp's <sys/farptr.h>
    * Needed in pkt_receiver_pm() because djgpp 2.03 doesn't
    * save/restore FS/GS registers in the rmode callback stub.
    * Not needed if 'USE_FAST_PKT' is used.
    */
-  _W32_EXTERN_INLINE WORD get_fs_reg (void)
+  __EXTERN_INLINE__ WORD get_fs_reg (void)
   {
      WORD sel;
      __asm__ __volatile__ (
              "movw %%fs, %w0"
            : "=r" (sel) : );
      return (sel);
   }
-  _W32_EXTERN_INLINE WORD get_gs_reg (void)
+  __EXTERN_INLINE__ WORD get_gs_reg (void)
   {
      WORD sel;
      __asm__ __volatile__ (
              "movw %%gs, %w0"
            : "=r" (sel) : );
      return (sel);
   }
-  _W32_EXTERN_INLINE void set_fs_reg (WORD sel)
+  __EXTERN_INLINE__ void set_fs_reg (WORD sel)
   {
     __asm__ __volatile__ (
             "movw %w0, %%fs"
          :: "rm" (sel));
   }
-  _W32_EXTERN_INLINE void set_gs_reg (WORD sel)
+  __EXTERN_INLINE__ void set_gs_reg (WORD sel)
   {
     __asm__ __volatile__ (
             "movw %w0, %%gs"
          :: "rm" (sel));
   }
diff -aprNU5 wattcp.q2dos/src/pcconfig.c watt/src/pcconfig.c
--- wattcp.q2dos/src/pcconfig.c	2015-11-14 22:32:52 +0100
+++ watt/src/pcconfig.c	2015-11-15 19:01:14 +0100
@@ -43,10 +43,12 @@
 #if defined(USE_IPV6)
 #include "pcicmp6.h"
 #include "teredo64.h"
 #endif
 
+#include "portability.h"
+
 #if (DOSX & PHARLAP)
   #include <hw386.h>
 #endif
 
 #if defined(__BORLANDC__)
@@ -582,15 +584,11 @@ static long do_include_file (const char
   {
     CONFIG_DBG_MSG (2, ("Skipping include file `%s'\n", p));
     return (0);
   }
 
-#ifdef __DJGPP__
-  if (_chmod(p, 0) != -1)
-#else
   if (access(p, 0) == 0)
-#endif
   {
     /* Recursion, but we're reentrant.
      * !!Fix-me: recursion depth should be limited.
      */
     UINT  tmp_line = current_line;
@@ -1067,16 +1065,12 @@ int tcp_config_name (char *name, int max
     {
       *temp++ = '\\';
       *temp = '\0';
     }
   }
-#ifdef __DJGPP__
-  else if (_chmod(config_name,0) != -1)
-#else
-  else if (access(config_name,0) == 0)
-#endif
-  { /* found in current directory */
+  else if (access(config_name,0) == 0)  /* found in current directory */
+  {
     strcpy (name, ".\\");
     path = name;
   }
   else if (_watt_os_ver >= 0x300)  /* not found, get path from argv[0] */
   {
@@ -1139,15 +1133,11 @@ long tcp_config (const char *path)
   }
   else
   {
     fname = name;
     StrLcpy (name, path, sizeof(name));
-#ifdef __DJGPP__
-    if (_chmod(fname,0) == -1)
-#else
     if (access(fname,0) != 0)
-#endif
        goto not_found;
   }
 
   if (!FOPEN(file,fname))  /* shouldn't happen */
      goto not_found;
diff -aprNU5 wattcp.q2dos/src/pcdhcp.c watt/src/pcdhcp.c
--- wattcp.q2dos/src/pcdhcp.c	2015-11-14 22:32:52 +0100
+++ watt/src/pcdhcp.c	2015-11-15 19:01:14 +0100
@@ -98,10 +98,13 @@
 #include "pcpkt.h"
 #include "pcconfig.h"
 #include "pcbootp.h"
 #include "pcdhcp.h"
 
+#include "portability.h"
+
+
 #if defined(USE_DHCP)
 
 #define BROADCAST_FLAG  intel16 (0x8000) /* network order (LSB=1) */
 
 BOOL dhcp_did_gratuitous_arp = FALSE;
@@ -1573,16 +1576,12 @@ static int std_write_config (void)
   FILE  *file;
   time_t tim, now = time (NULL);
   int    rc  = 0;
   const  char *fname = get_config_file();
 
-#ifdef __DJGPP__
-  if (_chmod(fname,0) == -1)
-#else
-  if (access(fname,0) != 0)
-#endif
-  { /* file not found, create */
+  if (access(fname,0))  /* file not found, create */
+  {
     file = fopen (fname, "w+t");
     if (!file)
        goto fail;
 
     rc = fprintf (file,
diff -aprNU5 wattcp.q2dos/src/pcsarp.c watt/src/pcsarp.c
--- wattcp.q2dos/src/pcsarp.c	2015-11-14 22:32:52 +0100
+++ watt/src/pcsarp.c	2015-11-15 19:01:14 +0100
@@ -27,10 +27,12 @@
 #include "pcsed.h"
 #include "pcpkt.h"
 #include "pcarp.h"
 #include "pcsarp.h"
 
+#include "portability.h"
+
 
 #if defined(USE_SECURE_ARP)
 /*
  * OpenSSL include path should be in %INCLUDE% and %C_INCLUDE_PATH%.
  */
@@ -83,15 +85,11 @@ int sarp_init (void)
   prev_cfg_hook   = usr_init;
   usr_init        = sarp_parse;
   _sarp_recv_hook = sarp_receive;
   _sarp_xmit_hook = sarp_transmit;
 
-#ifdef __DJGPP__
-  if (rand && _chmod(rand,0) !=-1)
-#else
   if (rand && access(rand,0) == 0)
-#endif
        RAND_load_file (rand, -1);
   else SARP_DEBUG (0, ("Warning: No random seed file found\n"));
   return (0);
 }
 
diff -aprNU5 wattcp.q2dos/src/portability.h watt/src/portability.h
--- wattcp.q2dos/src/portability.h	1970-01-01 01:00:00 +0100
+++ watt/src/portability.h	2015-11-15 19:01:14 +0100
@@ -0,0 +1,20 @@
+/*!\file portability.h
+ *
+ * Defines macros to hide the call of OS specific functions instead of posix functions.
+ *
+ *  Must always be included as last!!!
+ */
+
+#ifndef _w32_PORTABILITY_H
+#define _w32_PORTABILITY_H
+
+
+/*
+ *  For DJGPP allow to use _chmod instead of access.
+ */
+#ifdef __DJGPP__
+# undef  access
+# define access(filename, flags)  (_chmod((filename), (flags)) == -1 ? -1 : 0)
+#endif
+
+#endif /* _w32_CONFIG_H */
diff -aprNU5 wattcp.q2dos/src/zlib/makefile.all watt/src/zlib/makefile.all
--- wattcp.q2dos/src/zlib/makefile.all	2006-01-12 23:26:46 +0100
+++ watt/src/zlib/makefile.all	2015-11-15 18:53:06 +0100
@@ -41,11 +41,11 @@ OBJS = $(OBJDIR)\adler32.obj  $(OBJDIR)\
 ########################################################################
 
 @ifdef DJGPP
 
 CC     = gcc
-CFLAGS = -O2 -g -gcoff -W -Wall -I../../inc
+CFLAGS = -O2 -g -W -Wall -I../../inc -march=i386 -mtune=i586
 OBJDIR = ../djgpp
 
 OBJS := $(subst \,/,$(OBJS))
 OBJS := $(OBJS:.obj=.o)
 
@@ -62,11 +62,11 @@ clean:
 ########################################################################
 
 @elifdef DJGPP_DXE
 
 CC     = gcc
-CFLAGS = -O2 -g -gcoff -I../../inc -D_DLL -W -Wall
+CFLAGS = -O2 -g -I../../inc -D_DLL -W -Wall -march=i386 -mtune=i586
 OBJDIR = ../djgpp/dxe
 
 OBJS := $(subst \,/,$(OBJS))
 OBJS := $(OBJS:.obj=.o)
 
