[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[microblaze-uclinux] [PATCH] update uClibc for generic headers



I have checked out uClibc from petalinux and updated it to compile
with the generic ABI headers that I posted to lkml. This is the
patch I used, for reference.

The respective kernel tree can be found at
git://git.kernel.org:/pub/scm/linux/kernel/git/arnd/playground.git
in the generic-microblaze branch.

Signed-off-by: Arnd Bergmann <arnd@xxxxxxxx>

 libc/sysdeps/linux/microblaze/bits/fcntl.h              |   12 -
 libc/sysdeps/linux/microblaze/bits/kernel_stat.h        |   58 -----
 libc/sysdeps/linux/microblaze/bits/kernel_types.h       |   36 ---
 libc/sysdeps/linux/microblaze/bits/mman.h               |    4
 libc/sysdeps/linux/microblaze/bits/poll.h               |   11 -
 libc/sysdeps/linux/microblaze/bits/syscalls.h           |  165 ++++++++++++++++
 libc/sysdeps/linux/microblaze/clinkage.h                |    9
 libc/sysdeps/linux/microblaze/mmap.c                    |   49 ++++
 libc/sysdeps/linux/microblaze/sys/ucontext.h            |    2
 libpthread/linuxthreads/sysdeps/microblaze/pt-machine.h |    2
 10 files changed, 246 insertions(+), 102 deletions(-)


Index: libc/sysdeps/linux/microblaze/bits/kernel_stat.h
===================================================================
--- libc/sysdeps/linux/microblaze/bits/kernel_stat.h	(revision 5238)
+++ libc/sysdeps/linux/microblaze/bits/kernel_stat.h	(working copy)
@@ -3,60 +3,12 @@
 #ifndef _BITS_STAT_STRUCT_H
 #define _BITS_STAT_STRUCT_H
 
-struct kernel_stat
-{
-  __kernel_dev_t	st_dev;
-  __kernel_ino_t	st_ino;
-  __kernel_mode_t	st_mode;
-  __kernel_nlink_t 	st_nlink;
-  __kernel_uid_t 	st_uid;
-  __kernel_gid_t 	st_gid;
-  __kernel_dev_t	st_rdev;
-  __kernel_off_t	st_size;
-	unsigned long  st_blksize;
-	unsigned long  st_blocks;
-	unsigned long  st_atime;
-	unsigned long  __unused1;
-	unsigned long  st_mtime;
-	unsigned long  __unused2;
-	unsigned long  st_ctime;
-	unsigned long  __unused3;
-	unsigned long  __unused4;
-	unsigned long  __unused5;
-};
+#define stat kernel_stat
+#define stat64 kernel_stat64
 
-struct kernel_stat64
-{
-  __kernel_dev_t	st_dev;
-  unsigned long		__unused0;
-  unsigned long		__unused1;
+#include <asm-generic/stat.h>
 
-  __kernel_ino64_t	st_ino;
+#undef stat
+#undef stat64
 
-  __kernel_mode_t	st_mode;
-  __kernel_nlink_t 	st_nlink;
-
-  __kernel_uid_t	st_uid;
-  __kernel_gid_t	st_gid;
-
-  __kernel_dev_t	st_rdev;
-  unsigned long		__unused2;
-  unsigned long		__unused3;
-
-  __kernel_loff_t	st_size;
-	unsigned long	st_blksize;
-
-  unsigned long		__unused4; /* future possible st_blocks high bits */
-	unsigned long	st_blocks;	/* Number 512-byte blocks allocated. */
-
-	unsigned long	st_atime;
-  unsigned long		__unused5;
-
-	unsigned long	st_mtime;
-  unsigned long		__unused6;
-
-	unsigned long	st_ctime;
-  unsigned long		__unused7; /* high 32 bits of ctime someday */
-};
-
 #endif	/*  _BITS_STAT_STRUCT_H */
Index: libc/sysdeps/linux/microblaze/bits/syscalls.h
===================================================================
--- libc/sysdeps/linux/microblaze/bits/syscalls.h	(revision 5238)
+++ libc/sysdeps/linux/microblaze/bits/syscalls.h	(working copy)
@@ -6,6 +6,171 @@
 
 #include <features.h>
 
+/*
+ * user-visible error numbers are in the range -1 - -128: see
+ * <asm-generic/errno.h>
+ *
+ * both i386 and microblaze use generic version * of errno.h. the
+ * generic version of errno.h has more than 128 of * numbers. not
+ * sure what the comment means.
+ *
+ * following code is taken from mb 2.4
+ */
+#define __syscall_return(type, res)					\
+do {									\
+	/* user-visible error numbers are in the range -1 - -124:	\
+	 see <asm-microblaze/errno.h> */				\
+	if ((unsigned long)(res) >= (unsigned long)(-125)) {		\
+		errno = -(res);						\
+		res = -1;						\
+	}								\
+	return (type) (res);						\
+} while (0)
+
+#define _syscall0(type, name)						\
+type name(void)								\
+{									\
+	long __ret;							\
+	asm volatile ("addik	r12, r0, %1	\n\t"			\
+			"brki	r14, 0x8	\n\t"			\
+			"addk	%0, r3, r0	\n\t"			\
+			: "=r" (__ret)					\
+			: "i" (__NR_##name)				\
+			: "r3", "r4", "r5", "r6", "r7", "r8", "r9",	\
+				"r10", "r12", "r14", "cc");		\
+	__syscall_return(type, __ret);					\
+}
+
+#define _syscall1(type, name, type1, arg1)				\
+type name(type1 arg1)							\
+{									\
+	long __ret;							\
+	asm volatile ("addk	r5, r0, %2	\n\t"			\
+			"addik	r12, r0, %1	\n\t"			\
+			"brki	r14, 0x8	\n\t"			\
+			"addk	%0, r3, r0	\n\t"			\
+			: "=r" (__ret)					\
+			: "i" (__NR_##name),				\
+			"r" ((long)arg1)				\
+			: "r3", "r4", "r5", "r6", "r7", "r8", "r9",	\
+				"r10", "r12", "r14", "cc");		\
+	__syscall_return(type, __ret);					\
+}
+
+#define _syscall2(type, name, type1, arg1, type2, arg2)			\
+type name(type1 arg1, type2 arg2)					\
+{									\
+	long __ret;							\
+	asm volatile ("addk	r5, r0, %2	\n\t"			\
+			"addk	r6, r0, %3	\n\t"			\
+			"addik	r12, r0, %1	\n\t"			\
+			"brki	r14, 0x8	\n\t"			\
+			"addk	%0, r3, r0	\n\t"			\
+			: "=r" (__ret)					\
+			: "i" (__NR_##name),				\
+			"r" ((long)arg1),				\
+			"r" ((long)arg2)				\
+			: "r3", "r4", "r5", "r6", "r7", "r8", "r9",	\
+				"r10", "r12", "r14", "cc");		\
+	__syscall_return(type, __ret);					\
+}
+
+#define _syscall3(type, name, type1, arg1, type2, arg2, type3, arg3)	\
+type name(type1 arg1, type2 arg2, type3 arg3)				\
+{									\
+	long __ret;							\
+	asm volatile ("addk	r5, r0, %2	\n\t"			\
+			"addk	r6, r0, %3	\n\t"			\
+			"addk	r7, r0, %4	\n\t"			\
+			"addik	r12, r0, %1	\n\t"			\
+			"brki	r14, 0x8	\n\t"			\
+			"addk	%0, r3, r0	\n\t"			\
+			: "=r" (__ret)					\
+			: "i" (__NR_##name),				\
+			"r" ((long)arg1),				\
+			"r" ((long)arg2),				\
+			"r" ((long)arg3)				\
+			: "r3", "r4", "r5", "r6", "r7", "r8", "r9",	\
+				"r10", "r12", "r14", "cc");		\
+	__syscall_return(type, __ret);					\
+}
+
+#define _syscall4(type, name, type1, arg1, type2, arg2, type3, arg3,	\
+			type4, arg4)					\
+type name(type1 arg1, type2 arg2, type3 arg3, type4 arg4)		\
+{									\
+	long __ret;							\
+	asm volatile ("addk	r5, r0, %2	\n\t"			\
+			"addk	r6, r0, %3	\n\t"			\
+			"addk	r7, r0, %4	\n\t"			\
+			"addk	r8, r0, %5	\n\t"			\
+			"addik	r12, r0, %1	\n\t"			\
+			"brki	r14, 0x8	\n\t"			\
+			"addk	%0, r3, r0	\n\t"			\
+			: "=r" (__ret)					\
+			: "i" (__NR_##name),				\
+			"r" ((long)arg1),				\
+			"r" ((long)arg2),				\
+			"r" ((long)arg3),				\
+			"r" ((long)arg4)				\
+			: "r3", "r4", "r5", "r6", "r7", "r8", "r9",	\
+				"r10", "r12", "r14", "cc");		\
+	__syscall_return(type, __ret);					\
+}
+
+#define _syscall5(type, name, type1, arg1, type2, arg2, type3, arg3,	\
+			type4, arg4, type5, arg5)			\
+type name(type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5)	\
+{									\
+	long __ret;							\
+	asm volatile ("addk	r5, r0, %2	\n\t"			\
+			"addk	r6, r0, %3	\n\t"			\
+			"addk	r7, r0, %4	\n\t"			\
+			"addk	r8, r0, %5	\n\t"			\
+			"addk	r9, r0, %6	\n\t"			\
+			"addik	r12, r0, %1	\n\t"			\
+			"brki	r14, 0x8	\n\t"			\
+			"addk	%0, r3, r0	\n\t"			\
+			: "=r" (__ret)					\
+			: "i" (__NR_##name),				\
+			"r" ((long)arg1),				\
+			"r" ((long)arg2),				\
+			"r" ((long)arg3),				\
+			"r" ((long)arg4),				\
+			"r" ((long)arg5)				\
+			: "r3", "r4", "r5", "r6", "r7", "r8", "r9",	\
+				"r10", "r12", "r14", "cc");		\
+	__syscall_return(type, __ret);					\
+}
+
+#define _syscall6(type, name, type1, arg1, type2, arg2, type3, arg3,	\
+			type4, arg4, type5, arg5, type6, arg6)		\
+type name(type1 arg1, type2 arg2, type3 arg3, type4 arg4, type5 arg5,	\
+			type6 arg6)					\
+{									\
+	long __ret;							\
+	asm volatile ("addk	r5, r0, %2	\n\t"			\
+			"addk	r6, r0, %3	\n\t"			\
+			"addk	r7, r0, %4	\n\t"			\
+			"addk	r8, r0, %5	\n\t"			\
+			"addk	r9, r0, %6	\n\t"			\
+			"addk	r10, r0, %7	\n\t"			\
+			"addik	r12, r0, %1	\n\t"			\
+			"brki	r14, 0x8	\n\t"			\
+			"addk	%0, r3, r0	\n\t"			\
+			: "=r" (__ret)					\
+			: "i" (__NR_##name),				\
+			"r" ((long)arg1),				\
+			"r" ((long)arg2),				\
+			"r" ((long)arg3),				\
+			"r" ((long)arg4),				\
+			"r" ((long)arg5),				\
+			"r" ((long)arg6)				\
+			: "r3", "r4", "r5", "r6", "r7", "r8", "r9",	\
+				"r10", "r12", "r14", "cc");		\
+	__syscall_return(type, __ret);					\
+}
+
 /* Do something very evil for now.  Until we create our own syscall
  * macros, short circuit bits/sysnum.h  and use asm/unistd.h instead */
 #include <asm/unistd.h>
Index: libc/sysdeps/linux/microblaze/bits/kernel_types.h
===================================================================
--- libc/sysdeps/linux/microblaze/bits/kernel_types.h	(revision 5238)
+++ libc/sysdeps/linux/microblaze/bits/kernel_types.h	(working copy)
@@ -16,40 +16,8 @@
 #ifndef __MICROBLAZE_POSIX_TYPES_H__
 #define __MICROBLAZE_POSIX_TYPES_H__
 
-typedef unsigned int	__kernel_dev_t;
-typedef unsigned long	__kernel_ino_t;
-typedef unsigned long long __kernel_ino64_t;
-typedef unsigned int	__kernel_mode_t;
-typedef unsigned int	__kernel_nlink_t;
-typedef long		__kernel_off_t;
-typedef long long	__kernel_loff_t;
-typedef int		__kernel_pid_t;
-typedef unsigned short	__kernel_ipc_pid_t;
-typedef unsigned int	__kernel_uid_t;
-typedef unsigned int	__kernel_gid_t;
-typedef unsigned int	__kernel_size_t;
-typedef int		__kernel_ssize_t;
-typedef int		__kernel_ptrdiff_t;
-typedef long		__kernel_time_t;
-typedef long		__kernel_suseconds_t;
-typedef long		__kernel_clock_t;
-typedef int		__kernel_daddr_t;
-typedef char *		__kernel_caddr_t;
-typedef unsigned short	__kernel_uid16_t;
-typedef unsigned short	__kernel_gid16_t;
-typedef unsigned int	__kernel_uid32_t;
-typedef unsigned int	__kernel_gid32_t;
+#include <asm/posix_types.h>
 
-typedef unsigned short	__kernel_old_uid_t;
-typedef unsigned short	__kernel_old_gid_t;
-typedef __kernel_dev_t	__kernel_old_dev_t;
+typedef unsigned int __kernel_dev_t;
 
-typedef struct {
-#ifdef __USE_ALL
-	int val[2];
-#else
-	int __val[2];
-#endif
-} __kernel_fsid_t;
-
 #endif /* __MICROBLAZE_POSIX_TYPES_H__ */
Index: libc/sysdeps/linux/microblaze/bits/fcntl.h
===================================================================
--- libc/sysdeps/linux/microblaze/bits/fcntl.h	(revision 5238)
+++ libc/sysdeps/linux/microblaze/bits/fcntl.h	(working copy)
@@ -42,10 +42,12 @@
 #define O_ASYNC		 020000
 
 #ifdef __USE_GNU
-# define O_DIRECTORY	 040000	/* Must be a directory.	 */
-# define O_NOFOLLOW	0100000	/* Do not follow links.	 */
-# define O_DIRECT	0200000	/* Direct disk access.	*/
-# define O_STREAMING	04000000/* streaming access */
+# define O_DIRECT       00040000 /* direct disk access hint */
+# define O_DIRECTORY    00200000 /* must be a directory */
+# define O_NOFOLLOW     00400000 /* don't follow links */
+# define O_NOATIME      01000000
+# define O_CLOEXEC      02000000 /* set close_on_exec */
+# define O_STREAMING 	04000000 /* streaming access */
 #endif
 
 /* For now Linux has synchronisity options for data and read operations.
@@ -57,7 +59,7 @@
 #endif
 
 #ifdef __USE_LARGEFILE64
-# define O_LARGEFILE	0400000
+# define O_LARGEFILE	00100000
 #endif
 
 /* Values for the second argument to `fcntl'.  */
Index: libc/sysdeps/linux/microblaze/bits/poll.h
===================================================================
--- libc/sysdeps/linux/microblaze/bits/poll.h	(revision 5238)
+++ libc/sysdeps/linux/microblaze/bits/poll.h	(working copy)
@@ -31,10 +31,17 @@
 /* These values are defined in XPG4.2.  */
 # define POLLRDNORM	0x040		/* Normal data may be read.  */
 # define POLLRDBAND	0x080		/* Priority data may be read.  */
-# define POLLWRNORM	POLLOUT		/* Writing now will not block.  */
-# define POLLWRBAND	0x100		/* Priority data may be written.  */
+# define POLLWRNORM	0x100		/* Writing now will not block.  */
+# define POLLWRBAND	0x200		/* Priority data may be written.  */
 #endif
 
+#ifdef __USE_GNU
+/* These are extensions for Linux.  */
+# define POLLMSG        0x400
+# define POLLREMOVE     0x1000
+# define POLLRDHUP      0x2000
+#endif
+
 /* Event types always implicitly polled for.  These bits need not be set in
    `events', but they will appear in `revents' to indicate the status of
    the file descriptor.  */
Index: libc/sysdeps/linux/microblaze/bits/mman.h
===================================================================
--- libc/sysdeps/linux/microblaze/bits/mman.h	(revision 5238)
+++ libc/sysdeps/linux/microblaze/bits/mman.h	(working copy)
@@ -61,6 +61,10 @@
 # define MAP_EXECUTABLE	0x1000		/* Mark it as an executable.  */
 # define MAP_LOCKED	0x2000		/* Lock the mapping.  */
 # define MAP_NORESERVE	0x4000		/* Don't check for reservations.  */
+# define MAP_POPULATE   0x8000		/* populate (prefault) pagetables */
+# define MAP_NONBLOCK   0x10000		/* do not block on IO */
+# define MAP_STACK      0x20000		/* give out an address that is best
+					   suited for process/threadstacks */
 #endif
 
 /* Flags to `msync'.  */
Index: libc/sysdeps/linux/microblaze/clinkage.h
===================================================================
--- libc/sysdeps/linux/microblaze/clinkage.h	(revision 5238)
+++ libc/sysdeps/linux/microblaze/clinkage.h	(working copy)
@@ -12,4 +12,11 @@
  * Written by Miles Bader <miles@xxxxxxx>
  */
 
-#include <asm/clinkage.h>
+#ifndef __C_LINKAGE_H
+#define __C_LINKAGE_H
+
+#define C_SYMBOL_NAME(name)	name
+#define C_ENTRY(name)		.globl name; .align 4; name
+#define C_END(name)
+
+#endif /* __C_LINKAGE_H */
Index: libc/sysdeps/linux/microblaze/mmap.c
===================================================================
--- libc/sysdeps/linux/microblaze/mmap.c	(revision 5238)
+++ libc/sysdeps/linux/microblaze/mmap.c	(working copy)
@@ -1,9 +1,48 @@
-/* Use new style mmap for microblaze */
+/* Copyright (C) 1997, 1998, 1999, 2002, 2003 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Daniel Jacobowitz <dan@xxxxxxxxxx>, 1999.
 
+   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.  */
+
+/* Massivly hacked up for uClibc by Erik Andersen */
+
+/* Extracted from ../common/mmap64.c by Alexandre Oliva <aoliva@xxxxxxxxxx>
+
+   We don't want to use the old mmap interface.  */
+
+#include <features.h>
+#include <errno.h>
 #include <unistd.h>
-#include <errno.h>
+#include <sys/syscall.h>
 #include <sys/mman.h>
-#include <sys/syscall.h>
 
-_syscall6 (__ptr_t, mmap, __ptr_t, addr, size_t, len, int, prot,
-	   int, flags, int, fd, __off_t, offset);
+#define __NR___syscall_mmap2	    __NR_mmap2
+static inline _syscall6(__ptr_t, __syscall_mmap2, __ptr_t, addr, 
+	size_t, len, int, prot, int, flags, int, fd, off_t, offset);
+
+/* This is always 12, even on architectures where PAGE_SHIFT != 12.  */
+# ifndef MMAP2_PAGE_SHIFT
+#  define MMAP2_PAGE_SHIFT 12
+# endif
+
+__ptr_t mmap(__ptr_t addr, size_t len, int prot, int flags, int fd, __off_t offset)
+{
+    if (offset & ((1 << MMAP2_PAGE_SHIFT) - 1)) {
+	__set_errno (EINVAL);
+	return MAP_FAILED;
+    }
+    return(__syscall_mmap2(addr, len, prot, flags, fd, (off_t) (offset >> MMAP2_PAGE_SHIFT)));
+}
Index: libc/sysdeps/linux/microblaze/sys/ucontext.h
===================================================================
--- libc/sysdeps/linux/microblaze/sys/ucontext.h	(revision 5238)
+++ libc/sysdeps/linux/microblaze/sys/ucontext.h	(working copy)
@@ -34,7 +34,7 @@
     unsigned long int uc_flags;
     struct ucontext *uc_link;
     stack_t uc_stack;
-    mcontext_t uc_mcontext;
+    struct sigcontext uc_mcontext;
     __sigset_t uc_sigmask;
   } ucontext_t;
 
Index: libpthread/linuxthreads/sysdeps/microblaze/pt-machine.h
===================================================================
--- libpthread/linuxthreads/sysdeps/microblaze/pt-machine.h	(revision 5238)
+++ libpthread/linuxthreads/sysdeps/microblaze/pt-machine.h	(working copy)
@@ -43,7 +43,7 @@
 			:
 			: "r3");
 
-  if (likely (*ptr == old))
+  if (__builtin_expect (*ptr == old, 1))
     {
       *ptr = new;
       __asm__ __volatile__ ("mts rmsr, %0;" :: "r" (psw)); /* re-enable */
___________________________
microblaze-uclinux mailing list
microblaze-uclinux@xxxxxxxxxxxxxx
Project Home Page : http://www.itee.uq.edu.au/~jwilliams/mblaze-uclinux
Mailing List Archive : http://www.itee.uq.edu.au/~listarch/microblaze-uclinux/