[kaffe] CVS kaffe (guilhem): Fixed PIC on x86. Changed how FPU mode is set. Added new replacement for getifad

Kaffe CVS cvs-commits at kaffe.org
Sun Jul 17 09:57:33 PDT 2005


PatchSet 6744 
Date: 2005/07/17 16:46:09
Author: guilhem
Branch: HEAD
Tag: (none) 
Log:
Fixed PIC on x86. Changed how FPU mode is set. Added new replacement for getifaddrs.

        * config/i386/trampolines.S: Fixed PIC usage for x86.

        * config/i386/fpu-set.h: New file.

        * config/i386/linux/md.c: Do not use fpu_control.h but the new
        function in fpu-set.h

        * config/i386/solaris2/md.h
        (INIT_MD): Call fpu_set_precision.

        * configure.ac: Removed fpu_control.h

        * config/Makefile.am: Added i386/fpu-set.h

        * replace/Makefile.am: Added ifaddrs_bsd.c

        * replace/ifaddrs_bsd.c: New file.

        * configure,
        config/config.h.in,
        config/Makefile.in,
        replace/Makefile.in: Regenerated.

Members: 
	ChangeLog:1.4268->1.4269 
	configure.ac:1.152->1.153 
	config/Makefile.am:1.61->1.62 
	config/Makefile.in:1.185->1.186 
	config/config.h.in:1.145->1.146 
	config/i386/fpu-set.h:INITIAL->1.1 
	config/i386/trampolines.S:1.3->1.4 
	config/i386/linux/md.c:1.6->1.7 
	config/i386/solaris2/md.h:1.11->1.12 
	replace/Makefile.am:1.14->1.15 
	replace/Makefile.in:1.88->1.89 
	replace/getifaddrs.c:1.2->1.3 
	replace/ifaddrs.h:INITIAL->1.1 
	replace/ifaddrs_bsd.c:INITIAL->1.1 

Index: kaffe/ChangeLog
diff -u kaffe/ChangeLog:1.4268 kaffe/ChangeLog:1.4269
--- kaffe/ChangeLog:1.4268	Sun Jul 17 16:40:05 2005
+++ kaffe/ChangeLog	Sun Jul 17 16:46:09 2005
@@ -1,3 +1,28 @@
+2005-07-17  Guilhem Lavaux  <guilhem at kaffe.org>
+
+	* config/i386/trampolines.S: Fixed PIC usage for x86.
+
+	* config/i386/fpu-set.h: New file.
+
+	* config/i386/linux/md.c: Do not use fpu_control.h but the new
+	function in fpu-set.h
+
+	* config/i386/solaris2/md.h
+	(INIT_MD): Call fpu_set_precision.
+
+	* configure.ac: Removed fpu_control.h
+
+	* config/Makefile.am: Added i386/fpu-set.h
+	
+	* replace/Makefile.am: Added ifaddrs_bsd.c
+
+	* replace/ifaddrs_bsd.c: New file.
+
+	* configure,
+	config/config.h.in,
+	config/Makefile.in,
+	replace/Makefile.in: Regenerated.
+
 2005-07-17  Dalibor Topic  <robilad at kaffe.org>
 
 	Resynced with GNU Classpath.
Index: kaffe/configure.ac
diff -u kaffe/configure.ac:1.152 kaffe/configure.ac:1.153
--- kaffe/configure.ac:1.152	Sun Jul 10 13:49:26 2005
+++ kaffe/configure.ac	Sun Jul 17 16:46:21 2005
@@ -1019,6 +1019,7 @@
 memory.h \
 mips/cachectl.h \
 netdb.h \
+net/if.h \
 netinet/in.h \
 netinet/in_systm.h \
 netinet/tcp.h \
@@ -1046,14 +1047,14 @@
 sys/param.h \
 sys/signal.h \
 sys/ucontext.h \
+sys/sockio.h \
 syslog.h \
 time.h \
 unistd.h \
 utime.h \
 wintypes.h \
 wtypes.h \
-zlib.h \
-fpu_control.h])
+zlib.h])
 
 dnl GNU/Linux sigcontext headers
 AC_CHECK_HEADERS([asm/sigcontext.h])
Index: kaffe/config/Makefile.am
diff -u kaffe/config/Makefile.am:1.61 kaffe/config/Makefile.am:1.62
--- kaffe/config/Makefile.am:1.61	Mon Jul  4 01:12:38 2005
+++ kaffe/config/Makefile.am	Sun Jul 17 16:46:24 2005
@@ -126,6 +126,7 @@
 	x86_64/threads.h \
 	x86_64/sysdepCallMethod.h \
 	i386/atomic.h \
+	i386/fpu_set.h \
 	i386/beos/config.frag \
 	i386/beos/jit-md.h \
 	i386/beos/jit3-md.h \
@@ -204,6 +205,7 @@
 	i386/sco3.2v5/md.h \
 	i386/solaris2/config.frag \
 	i386/solaris2/jit-md.h \
+	i386/solaris2/jit3-md.h \
 	i386/solaris2/md.c \
 	i386/solaris2/md.h \
 	i386/sysdepCallMethod.h \
Index: kaffe/config/Makefile.in
diff -u kaffe/config/Makefile.in:1.185 kaffe/config/Makefile.in:1.186
--- kaffe/config/Makefile.in:1.185	Mon Jul  4 01:12:38 2005
+++ kaffe/config/Makefile.in	Sun Jul 17 16:46:25 2005
@@ -468,6 +468,7 @@
 	x86_64/threads.h \
 	x86_64/sysdepCallMethod.h \
 	i386/atomic.h \
+	i386/fpu_set.h \
 	i386/beos/config.frag \
 	i386/beos/jit-md.h \
 	i386/beos/jit3-md.h \
@@ -546,6 +547,7 @@
 	i386/sco3.2v5/md.h \
 	i386/solaris2/config.frag \
 	i386/solaris2/jit-md.h \
+	i386/solaris2/jit3-md.h \
 	i386/solaris2/md.c \
 	i386/solaris2/md.h \
 	i386/sysdepCallMethod.h \
Index: kaffe/config/config.h.in
diff -u kaffe/config/config.h.in:1.145 kaffe/config/config.h.in:1.146
--- kaffe/config/config.h.in:1.145	Sun Jul 10 13:49:34 2005
+++ kaffe/config/config.h.in	Sun Jul 17 16:46:27 2005
@@ -132,9 +132,6 @@
 /* Define to 1 if you have the `fork' function. */
 #undef HAVE_FORK
 
-/* Define to 1 if you have the <fpu_control.h> header file. */
-#undef HAVE_FPU_CONTROL_H
-
 /* Define to 1 if you have the `fsync' function. */
 #undef HAVE_FSYNC
 
@@ -386,6 +383,9 @@
 /* Define to 1 if you have the <netpacket/packet.h> header file. */
 #undef HAVE_NETPACKET_PACKET_H
 
+/* Define to 1 if you have the <net/if.h> header file. */
+#undef HAVE_NET_IF_H
+
 /* Define to 1 if you have the `on_exit' function. */
 #undef HAVE_ON_EXIT
 
@@ -606,6 +606,9 @@
 
 /* Define to 1 if you have the <sys/socket.h> header file. */
 #undef HAVE_SYS_SOCKET_H
+
+/* Define to 1 if you have the <sys/sockio.h> header file. */
+#undef HAVE_SYS_SOCKIO_H
 
 /* Define to 1 if you have the <sys/stat.h> header file. */
 #undef HAVE_SYS_STAT_H
===================================================================
Checking out kaffe/config/i386/fpu-set.h
RCS:  /home/cvs/kaffe/kaffe/config/i386/fpu-set.h,v
VERS: 1.1
***************
--- /dev/null	Sun Aug  4 19:57:58 2002
+++ kaffe/config/i386/fpu-set.h	Sun Jul 17 16:57:33 2005
@@ -0,0 +1,33 @@
+/*
+ * config/i386/fpu-set.h
+ * Setup the CPU in double mode.
+ *
+ * Copyright(c) 2005
+ *    The Kaffe.org's developers. All rights reserved.
+ *    See ChangeLog for details.
+ *
+ * See the file "license.terms" for information on usage and redistribution
+ * of this file.
+ */
+#ifndef __FPU_SET_H
+#define __FPU_SET_H
+
+static inline void
+set_fpu_precision(void)
+{
+  unsigned int fpu_control;
+
+  __asm__ __volatile__
+    (
+     "fnstcw %0\n\t"           /* Get the FPU state */
+     "mov %0, %%ax\n\t"
+     "and $0xfc, %%ah\n\t"     /* Remove the extended mode flag */
+     "or $0x2, %%ah\n\t"       /* Put the double mode flag */
+     "mov %%ax, %0\n\t"        /* Put back the new flag in memory */
+     "fldcw %0\n\t"            /* and setup the FPU */
+     : "+m" (fpu_control)
+     : 
+     : "eax");
+}
+
+#endif
Index: kaffe/config/i386/trampolines.S
diff -u kaffe/config/i386/trampolines.S:1.3 kaffe/config/i386/trampolines.S:1.4
--- kaffe/config/i386/trampolines.S:1.3	Wed Jun 29 17:23:38 2005
+++ kaffe/config/i386/trampolines.S	Sun Jul 17 16:46:29 2005
@@ -25,13 +25,26 @@
      .text
      .align 4
      .globl C_FUNC_NAME(i386_do_fixup_trampoline)
+     .type C_FUNC_NAME(i386_do_fixup_trampoline), @function
 
      C_FUNC_NAME(i386_do_fixup_trampoline) :
         popl	%eax
 	push	%ebp
 	mov	%esp,%ebp
+#if defined(PIC)
+	pushl	%ebx
+	call	.L2
+     .L2:
+	popl	%ebx
+	addl	$_GLOBAL_OFFSET_TABLE_+[.-.L2], %ebx
+	subl	$4, %esp
+	push	%eax
+	call	C_FUNC_NAME(soft_fixup_trampoline at PLT)
+	movl	-4(%ebp), %ebx
+#else
 	push	%eax
 	call	C_FUNC_NAME(soft_fixup_trampoline)
+#endif
 	leave
 	jmp	*%eax
 
Index: kaffe/config/i386/linux/md.c
diff -u kaffe/config/i386/linux/md.c:1.6 kaffe/config/i386/linux/md.c:1.7
--- kaffe/config/i386/linux/md.c:1.6	Wed Jun 15 09:56:29 2005
+++ kaffe/config/i386/linux/md.c	Sun Jul 17 16:46:32 2005
@@ -20,9 +20,7 @@
 #include <features.h>
 #endif
 
-#if defined(HAVE_FPU_CONTROL_H)
-#include <fpu_control.h>
-#endif
+#include "i386/fpu-set.h"
 
 void
 init_md(void)
@@ -31,7 +29,6 @@
 	mallopt(M_MMAP_MAX, 0);
 #endif
 
-#if defined(HAVE_FPU_CONTROL_H)
 	/* See http://www.srware.com/linux_numerics.txt */
         /*
 	  This puts the X86 FPU in 64-bit precision mode.  The default
@@ -40,12 +37,7 @@
 	  (int)(1000*atof("0.3")) is 300 in 64-bit mode, 299 in 80-bit
 	  mode.
         */
-        fpu_control_t cw;
-        _FPU_GETCW(cw);
-        cw &= ~_FPU_EXTENDED;
-        cw |= _FPU_DOUBLE;
-        _FPU_SETCW(cw);
-#endif
+	set_fpu_precision();
 }
 
 #if defined(__GLIBC__)
Index: kaffe/config/i386/solaris2/md.h
diff -u kaffe/config/i386/solaris2/md.h:1.11 kaffe/config/i386/solaris2/md.h:1.12
--- kaffe/config/i386/solaris2/md.h:1.11	Fri Jul 15 15:37:25 2005
+++ kaffe/config/i386/solaris2/md.h	Sun Jul 17 16:46:33 2005
@@ -40,6 +40,9 @@
 #include "jit-md.h"
 #endif
 
+#include "i386/fpu-set.h"
+#define INIT_MD fpu_set_precision
+
 #include "kaffe-unix-stack.h"
 
 #endif
Index: kaffe/replace/Makefile.am
diff -u kaffe/replace/Makefile.am:1.14 kaffe/replace/Makefile.am:1.15
--- kaffe/replace/Makefile.am:1.14	Wed Jun 29 09:42:48 2005
+++ kaffe/replace/Makefile.am	Sun Jul 17 16:46:34 2005
@@ -27,9 +27,11 @@
 	memset.c \
 	repsemaphore.h \
 	semaphores.c
+	ifaddrs.h
 
 libreplace_la_LIBADD = \
         $(LTLIBINTL)
 
 EXTRA_DIST = \
-	ifaddrs_linux.c
+	ifaddrs_linux.c \
+	ifaddrs_bsd.c
Index: kaffe/replace/Makefile.in
diff -u kaffe/replace/Makefile.in:1.88 kaffe/replace/Makefile.in:1.89
--- kaffe/replace/Makefile.in:1.88	Wed Jun 29 09:42:48 2005
+++ kaffe/replace/Makefile.in	Sun Jul 17 16:46:34 2005
@@ -396,7 +396,8 @@
         $(LTLIBINTL)
 
 EXTRA_DIST = \
-	ifaddrs_linux.c
+	ifaddrs_linux.c \
+	ifaddrs_bsd.c
 
 all: all-am
 
@@ -654,6 +655,7 @@
 	pdf pdf-am ps ps-am tags uninstall uninstall-am \
 	uninstall-info-am
 
+	ifaddrs.h
 # Tell versions [3.59,3.63) of GNU make to not export all variables.
 # Otherwise a system limit (for SysV at least) may be exceeded.
 .NOEXPORT:
Index: kaffe/replace/getifaddrs.c
diff -u kaffe/replace/getifaddrs.c:1.2 kaffe/replace/getifaddrs.c:1.3
--- kaffe/replace/getifaddrs.c:1.2	Thu Jun 12 08:47:02 2003
+++ kaffe/replace/getifaddrs.c	Sun Jul 17 16:46:34 2005
@@ -14,6 +14,15 @@
  */
 
 #include "config.h"
+#include "config-net.h"
+
+#if defined(HAVE_SYS_SOCKIO_H)
+#include <sys/sockio.h>
+#endif
+
+#if defined(HAVE_NET_IF_H)
+#include <net/if.h>
+#endif
 
 #if defined(HAVE_GETIFADDRS)
 
@@ -27,13 +36,15 @@
 #define __close(x) close(x)
 #endif
 
-#include "ifaddrs_linux.c"
+#elif defined(SIOCGIFINFO)
+
+#include "ifaddrs_bsd.c"
 
 #else
 
 #include <errno.h>
 #include <sys/types.h>
-#include <ifaddrs.h>
+#include "ifaddrs.h"
 
 int getifaddrs(struct ifaddrs **ifap)
 {
===================================================================
Checking out kaffe/replace/ifaddrs.h
RCS:  /home/cvs/kaffe/kaffe/replace/ifaddrs.h,v
VERS: 1.1
***************
--- /dev/null	Sun Aug  4 19:57:58 2002
+++ kaffe/replace/ifaddrs.h	Sun Jul 17 16:57:33 2005
@@ -0,0 +1,79 @@
+/* ifaddrs.h -- declarations for getting network interface addresses
+   Copyright (C) 2002 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, write to the Free
+   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+   02111-1307 USA.  */
+
+#ifndef _IFADDRS_H
+#define _IFADDRS_H	1
+
+#include <sys/socket.h>
+
+#define __THROW
+
+#if defined(__cplusplus)
+extern "C" {
+#endif
+
+/* The `getifaddrs' function generates a linked list of these structures.
+   Each element of the list describes one network interface.  */
+struct ifaddrs
+{
+  struct ifaddrs *ifa_next;	/* Pointer to the next structure.  */
+
+  char *ifa_name;		/* Name of this network interface.  */
+  unsigned int ifa_flags;	/* Flags as from SIOCGIFFLAGS ioctl.  */
+
+  struct sockaddr *ifa_addr;	/* Network address of this interface.  */
+  struct sockaddr *ifa_netmask; /* Netmask of this interface.  */
+  union
+  {
+    /* At most one of the following two is valid.  If the IFF_BROADCAST
+       bit is set in `ifa_flags', then `ifa_broadaddr' is valid.  If the
+       IFF_POINTOPOINT bit is set, then `ifa_dstaddr' is valid.
+       It is never the case that both these bits are set at once.  */
+    struct sockaddr *ifu_broadaddr; /* Broadcast address of this interface. */
+    struct sockaddr *ifu_dstaddr; /* Point-to-point destination address.  */
+  } ifa_ifu;
+  /* These very same macros are defined by <net/if.h> for `struct ifaddr'.
+     So if they are defined already, the existing definitions will be fine.  */
+# ifndef ifa_broadaddr
+#  define ifa_broadaddr	ifa_ifu.ifu_broadaddr
+# endif
+# ifndef ifa_dstaddr
+#  define ifa_dstaddr	ifa_ifu.ifu_dstaddr
+# endif
+
+  void *ifa_data;		/* Address-specific data (may be unused).  */
+};
+
+
+/* Create a linked list of `struct ifaddrs' structures, one for each
+   network interface on the host machine.  If successful, store the
+   list in *IFAP and return 0.  On errors, return -1 and set `errno'.
+
+   The storage returned in *IFAP is allocated dynamically and can
+   only be properly freed by passing it to `freeifaddrs'.  */
+extern int getifaddrs (struct ifaddrs **__ifap) __THROW;
+
+/* Reclaim the storage allocated by a previous `getifaddrs' call.  */
+extern void freeifaddrs (struct ifaddrs *__ifa)  __THROW;
+
+#if defined(__cplusplus)
+}
+#endif
+
+#endif /* ifaddrs.h */
===================================================================
Checking out kaffe/replace/ifaddrs_bsd.c
RCS:  /home/cvs/kaffe/kaffe/replace/ifaddrs_bsd.c,v
VERS: 1.1
***************
--- /dev/null	Sun Aug  4 19:57:58 2002
+++ kaffe/replace/ifaddrs_bsd.c	Sun Jul 17 16:57:33 2005
@@ -0,0 +1,130 @@
+/*
+ * ifaddrs_bsd.c
+ *
+ * Replacement of getifaddrs() function using BSD syscalls (SIOC*)
+ *
+ * Copyright(c) 2005 The kaffe.org's developpers.
+ *   All Rights reserved.
+ *
+ * This file is licensed under the terms of the GNU Public License.
+ * See the file "license.terms" for information on usage and redistribution
+ * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
+ */
+#include "config.h"
+#include "config-std.h"
+#include "config-net.h"
+#include "config-io.h"
+#include "ifaddrs.h"
+
+#if defined(HAVE_SYS_SOCKIO_H)
+#include <sys/sockio.h>
+#endif
+
+#if defined(HAVE_NET_IF_H)
+#include <net/if.h>
+#endif
+
+static int
+getSockAddrLen(struct sockaddr* addr)
+{
+  switch (addr->sa_family)
+    {
+    case AF_INET:
+      return sizeof(struct sockaddr_in);
+#if defined(HAVE_STRUCT_SOCKADDR_IN6)
+    case AF_INET6:
+      return sizeof(struct sockaddr_in6);
+#endif
+    default:
+      return sizeof(struct sockaddr);
+    }
+}
+
+int getifaddrs(struct ifaddrs **ifap)
+{
+  int sockfd;
+  int bufSize = 1024;
+  char *buf = NULL;
+  char *ptr;
+  int isFull;
+  int i;
+  int numberOfIfaces;
+  size_t len;
+  struct ifaddrs *allIfaces;
+  struct ifconf ifc;
+  struct ifreq *ifr;
+
+  sockfd = socket(AF_INET, SOCK_DGRAM, 0);
+
+  memset(&ifc, 0, sizeof(struct ifconf));
+  do
+    {
+      if (buf != NULL)
+	free(buf);
+      else
+	bufSize *= 2;
+
+      buf = (char *)malloc(bufSize);
+      memset(buf, 0, bufSize);
+      
+      ifc.ifc_len = bufSize;
+      ifc.ifc_req = (struct ifreq *)buf;
+
+      if (ioctl (sockfd, SIOCGIFCONF, &ifc) <  0)
+	{
+	  free(buf);
+	  return -1;
+	}
+
+      isFull = (ifc.ifc_len == bufSize);
+    }
+  while (isFull);
+
+  numberOfIfaces = ifc.ifc_len / (sizeof(struct sockaddr) + sizeof(ifr->ifr_name));
+  
+  allIfaces = (struct ifaddrs *)malloc(numberOfIfaces * sizeof(struct ifaddrs));
+
+  for (ptr = buf, i = 0; ptr < buf + ifc.ifc_len; i++)
+  {
+    ifr = (struct ifreq *) ptr;
+    
+    allIfaces[i].ifa_name = strdup(ifr->ifr_name);
+#if defined(HAVE_SOCKADDR_SA_LEN) || defined(__FreeBSD__)
+    if (ifr->ifr_addr.sa_len > len)
+      len = ifr->ifr_addr.sa_len;	/* length > 16 */
+    else
+#endif
+      len = getSockAddrLen(&ifr->ifr_addr);
+
+    allIfaces[i].ifa_addr = (struct sockaddr *)malloc(len);
+    allIfaces[i].ifa_next = &allIfaces[i+1];
+    
+    memcpy(allIfaces[i].ifa_addr, &ifr->ifr_addr, len);
+    
+    ptr += sizeof(ifr->ifr_name) + len;
+  }
+  allIfaces[i-1].ifa_next = NULL;
+  
+  free(ptr);
+  close(sockfd);
+
+  *ifap = allIfaces;
+
+  return 0;
+}
+
+void freeifaddrs(struct ifaddrs *ifp)
+{
+  struct ifaddrs *allIfaces = ifp;
+
+  while (allIfaces != NULL)
+    {
+      free(allIfaces->ifa_name);
+      free(allIfaces->ifa_addr);
+      allIfaces = allIfaces->ifa_next;
+    }
+
+  if (ifp != NULL)
+    free(ifp);
+}
+




More information about the kaffe mailing list