From 68567b88ee8f9e395e0c1f0a565affe8a1d4d68b Mon Sep 17 00:00:00 2001 From: Samuel Thibault Date: Sun, 1 Aug 2010 01:05:53 +0200 Subject: Move files to libpthread/ for inclusion along hurd --- libpthread/sysdeps/ia32/bits/atomic.h | 66 +++++++++++++++++ libpthread/sysdeps/ia32/bits/memory.h | 40 ++++++++++ libpthread/sysdeps/ia32/bits/spin-lock-inline.h | 98 +++++++++++++++++++++++++ libpthread/sysdeps/ia32/bits/spin-lock.h | 39 ++++++++++ libpthread/sysdeps/ia32/machine-sp.h | 30 ++++++++ libpthread/sysdeps/ia32/pt-machdep.h | 29 ++++++++ 6 files changed, 302 insertions(+) create mode 100644 libpthread/sysdeps/ia32/bits/atomic.h create mode 100644 libpthread/sysdeps/ia32/bits/memory.h create mode 100644 libpthread/sysdeps/ia32/bits/spin-lock-inline.h create mode 100644 libpthread/sysdeps/ia32/bits/spin-lock.h create mode 100644 libpthread/sysdeps/ia32/machine-sp.h create mode 100644 libpthread/sysdeps/ia32/pt-machdep.h (limited to 'libpthread/sysdeps/ia32') diff --git a/libpthread/sysdeps/ia32/bits/atomic.h b/libpthread/sysdeps/ia32/bits/atomic.h new file mode 100644 index 00000000..0dfc1f60 --- /dev/null +++ b/libpthread/sysdeps/ia32/bits/atomic.h @@ -0,0 +1,66 @@ +/* Atomic operations. i386 version. + Copyright (C) 2000 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 Library General Public License as + published by the Free Software Foundation; either version 2 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the GNU C Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +#ifndef _BITS_ATOMIC_H +#define _BITS_ATOMIC_H 1 + +typedef __volatile int __atomic_t; + +static inline void +__atomic_inc (__atomic_t *__var) +{ + __asm__ __volatile ("lock; incl %0" : "=m" (*__var) : "m" (*__var)); +} + +static inline void +__atomic_dec (__atomic_t *__var) +{ + __asm__ __volatile ("lock; decl %0" : "=m" (*__var) : "m" (*__var)); +} + +static inline int +__atomic_dec_and_test (__atomic_t *__var) +{ + unsigned char __ret; + + __asm__ __volatile ("lock; decl %0; sete %1" + : "=m" (*__var), "=qm" (__ret) : "m" (*__var)); + return __ret != 0; +} + +/* We assume that an __atomicptr_t is only used for pointers to + word-aligned objects, and use the lowest bit for a simple lock. */ +typedef __volatile int * __atomicptr_t; + +/* Actually we don't implement that yet, and assume that we run on + something that has the i486 instruction set. */ +static inline int +__atomicptr_compare_and_swap (__atomicptr_t *__ptr, void *__oldval, + void * __newval) +{ + char __ret; + int __dummy; + + __asm__ __volatile ("lock; cmpxchgl %3, %1; sete %0" + : "=q" (__ret), "=m" (*__ptr), "=a" (__dummy) + : "r" (__newval), "m" (*__ptr), "a" (__oldval)); + return __ret; +} + +#endif diff --git a/libpthread/sysdeps/ia32/bits/memory.h b/libpthread/sysdeps/ia32/bits/memory.h new file mode 100644 index 00000000..932c4086 --- /dev/null +++ b/libpthread/sysdeps/ia32/bits/memory.h @@ -0,0 +1,40 @@ +/* Memory barrier operations. i386 version. + Copyright (C) 2002, 2008 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 Library General Public License as + published by the Free Software Foundation; either version 2 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the GNU C Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +#ifndef _BITS_MEMORY_H +#define _BITS_MEMORY_H 1 + +/* Prevent read and write reordering across this function. */ +static inline void +__memory_barrier (void) +{ + int i; + + /* Any lock'ed instruction will do. We just do a simple + increment. */ + __asm__ __volatile ("lock; incl %0" : "=m" (i) : "m" (i) : "memory"); +} + +/* Prevent read reordering across this function. */ +#define __memory_read_barrier __memory_barrier + +/* Prevent write reordering across this function. */ +#define __memory_write_barrier __memory_barrier + +#endif diff --git a/libpthread/sysdeps/ia32/bits/spin-lock-inline.h b/libpthread/sysdeps/ia32/bits/spin-lock-inline.h new file mode 100644 index 00000000..e5ed3def --- /dev/null +++ b/libpthread/sysdeps/ia32/bits/spin-lock-inline.h @@ -0,0 +1,98 @@ +/* Machine-specific definitions for spin locks. i386 version. + Copyright (C) 2000, 2005, 2008, 2009 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 Library General Public License as + published by the Free Software Foundation; either version 2 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the GNU C Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +/* + * Never include this file directly; use or instead. + */ + +#ifndef _BITS_SPIN_LOCK_INLINE_H +#define _BITS_SPIN_LOCK_INLINE_H 1 + +#include +#include + +__BEGIN_DECLS + +#if defined __USE_EXTERN_INLINES || defined _FORCE_INLINES + +# ifndef __EBUSY +# include +# define __EBUSY EBUSY +# endif + +# ifndef __PT_SPIN_INLINE +# define __PT_SPIN_INLINE __extern_inline +# endif + +__PT_SPIN_INLINE int __pthread_spin_destroy (__pthread_spinlock_t *__lock); + +__PT_SPIN_INLINE int +__pthread_spin_destroy (__pthread_spinlock_t *__lock) +{ + return 0; +} + +__PT_SPIN_INLINE int __pthread_spin_init (__pthread_spinlock_t *__lock, + int __pshared); + +__PT_SPIN_INLINE int +__pthread_spin_init (__pthread_spinlock_t *__lock, int __pshared) +{ + *__lock = __PTHREAD_SPIN_LOCK_INITIALIZER; + return 0; +} + +__PT_SPIN_INLINE int __pthread_spin_trylock (__pthread_spinlock_t *__lock); + +__PT_SPIN_INLINE int +__pthread_spin_trylock (__pthread_spinlock_t *__lock) +{ + int __locked; + __asm__ __volatile ("xchgl %0, %1" + : "=&r" (__locked), "=m" (*__lock) : "0" (1) : "memory"); + return __locked ? __EBUSY : 0; +} + +__extern_inline int __pthread_spin_lock (__pthread_spinlock_t *__lock); +extern int _pthread_spin_lock (__pthread_spinlock_t *__lock); + +__extern_inline int +__pthread_spin_lock (__pthread_spinlock_t *__lock) +{ + if (__pthread_spin_trylock (__lock)) + return _pthread_spin_lock (__lock); + return 0; +} + +__PT_SPIN_INLINE int __pthread_spin_unlock (__pthread_spinlock_t *__lock); + +__PT_SPIN_INLINE int +__pthread_spin_unlock (__pthread_spinlock_t *__lock) +{ + int __unlocked; + __asm__ __volatile ("xchgl %0, %1" + : "=&r" (__unlocked), "=m" (*__lock) : "0" (0) : "memory"); + return 0; +} + +#endif /* Use extern inlines or force inlines. */ + +__END_DECLS + +#endif /* bits/spin-lock.h */ diff --git a/libpthread/sysdeps/ia32/bits/spin-lock.h b/libpthread/sysdeps/ia32/bits/spin-lock.h new file mode 100644 index 00000000..5ae81e18 --- /dev/null +++ b/libpthread/sysdeps/ia32/bits/spin-lock.h @@ -0,0 +1,39 @@ +/* Machine-specific definitions for spin locks. i386 version. + Copyright (C) 2000, 2005, 2008, 2009 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 Library General Public License as + published by the Free Software Foundation; either version 2 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the GNU C Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +/* + * Never include this file directly; use or instead. + */ + +#ifndef _BITS_SPIN_LOCK_H +#define _BITS_SPIN_LOCK_H 1 + +#include + +__BEGIN_DECLS + +/* The type of a spin lock object. */ +typedef __volatile int __pthread_spinlock_t; + +/* Initializer for a spin lock object. */ +# define __PTHREAD_SPIN_LOCK_INITIALIZER ((__pthread_spinlock_t) 0) + +__END_DECLS + +#endif /* bits/spin-lock.h */ diff --git a/libpthread/sysdeps/ia32/machine-sp.h b/libpthread/sysdeps/ia32/machine-sp.h new file mode 100644 index 00000000..cef6ab72 --- /dev/null +++ b/libpthread/sysdeps/ia32/machine-sp.h @@ -0,0 +1,30 @@ +/* Machine-specific function to return the stack pointer. i386 version. + Copyright (C) 1994, 1997, 2001, 2006 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 _MACHINE_SP_H +#define _MACHINE_SP_H + +/* Return the current stack pointer. */ + +#define __thread_stack_pointer() ({ \ + register void *__sp__ asm("esp"); \ + __sp__; \ +}) + +#endif /* machine-sp.h */ diff --git a/libpthread/sysdeps/ia32/pt-machdep.h b/libpthread/sysdeps/ia32/pt-machdep.h new file mode 100644 index 00000000..6d456367 --- /dev/null +++ b/libpthread/sysdeps/ia32/pt-machdep.h @@ -0,0 +1,29 @@ +/* Machine dependent pthreads internal defenitions. i386 version. + Copyright (C) 2000 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 Library General Public License as + published by the Free Software Foundation; either version 2 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with the GNU C Library; see the file COPYING.LIB. If not, + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. */ + +#ifndef _PT_MACHDEP_H +#define _PT_MACHDEP_H 1 + +struct pthread_mcontext +{ + void *pc; + void *sp; +}; + +#endif /* pt-machdep.h */ -- cgit v1.2.3