diff options
Diffstat (limited to 'nptl/sysdeps/s390')
-rw-r--r-- | nptl/sysdeps/s390/Makefile | 25 | ||||
-rw-r--r-- | nptl/sysdeps/s390/bits/atomic.h | 78 | ||||
-rw-r--r-- | nptl/sysdeps/s390/pthread_spin_init.c | 20 | ||||
-rw-r--r-- | nptl/sysdeps/s390/pthread_spin_lock.c | 34 | ||||
-rw-r--r-- | nptl/sysdeps/s390/pthread_spin_trylock.c | 34 | ||||
-rw-r--r-- | nptl/sysdeps/s390/pthread_spin_unlock.c | 33 | ||||
-rw-r--r-- | nptl/sysdeps/s390/pthreaddef.h | 44 | ||||
-rw-r--r-- | nptl/sysdeps/s390/tcb-offsets.sym | 4 | ||||
-rw-r--r-- | nptl/sysdeps/s390/td_ta_map_lwp2thr.c | 47 | ||||
-rw-r--r-- | nptl/sysdeps/s390/tls.h | 149 |
10 files changed, 468 insertions, 0 deletions
diff --git a/nptl/sysdeps/s390/Makefile b/nptl/sysdeps/s390/Makefile new file mode 100644 index 0000000000..fff17dbd19 --- /dev/null +++ b/nptl/sysdeps/s390/Makefile @@ -0,0 +1,25 @@ +# Copyright (C) 2003 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. + +ifeq ($(subdir),csu) +gen-as-const-headers += tcb-offsets.sym +endif + +ifeq ($(subdir),nptl) +libpthread-routines += ptw-sysdep +endif diff --git a/nptl/sysdeps/s390/bits/atomic.h b/nptl/sysdeps/s390/bits/atomic.h new file mode 100644 index 0000000000..375ae0d5e7 --- /dev/null +++ b/nptl/sysdeps/s390/bits/atomic.h @@ -0,0 +1,78 @@ +/* Copyright (C) 2003 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Martin Schwidefsky <schwidefsky@de.ibm.com>, 2003. + + 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. */ + +#include <stdint.h> + +typedef int8_t atomic8_t; +typedef uint8_t uatomic8_t; +typedef int_fast8_t atomic_fast8_t; +typedef uint_fast8_t uatomic_fast8_t; + +typedef int16_t atomic16_t; +typedef uint16_t uatomic16_t; +typedef int_fast16_t atomic_fast16_t; +typedef uint_fast16_t uatomic_fast16_t; + +typedef int32_t atomic32_t; +typedef uint32_t uatomic32_t; +typedef int_fast32_t atomic_fast32_t; +typedef uint_fast32_t uatomic_fast32_t; + +typedef int64_t atomic64_t; +typedef uint64_t uatomic64_t; +typedef int_fast64_t atomic_fast64_t; +typedef uint_fast64_t uatomic_fast64_t; + +typedef intptr_t atomicptr_t; +typedef uintptr_t uatomicptr_t; +typedef intmax_t atomic_max_t; +typedef uintmax_t uatomic_max_t; + + +#define __arch_compare_and_exchange_8_acq(mem, newval, oldval) \ + (abort (), 0) + +#define __arch_compare_and_exchange_16_acq(mem, newval, oldval) \ + (abort (), 0) + +#define __arch_compare_and_exchange_32_acq(mem, newval, oldval) \ + ({ unsigned int *__mem = (unsigned int *) (mem); \ + unsigned int __old = (unsigned int) (oldval); \ + unsigned int __cmp = __old; \ + __asm __volatile ("cs %0,%2,%1" \ + : "+d" (__old), "=Q" (*__mem) \ + : "d" (newval), "m" (*__mem) : "cc" ); \ + __cmp != __old; }) + +#ifdef __s390x__ +# define __arch_compare_and_exchange_64_acq(mem, newval, oldval) \ + ({ unsigned long int *__mem = (unsigned long int *) (mem); \ + unsigned long int __old = (unsigned long int) (oldval); \ + unsigned long int __cmp = __old; \ + __asm __volatile ("csg %0,%2,%1" \ + : "+d" (__old), "=Q" (*__mem) \ + : "d" (newval), "m" (*__mem) : "cc" ); \ + __cmp != __old; }) +#else +/* For 31 bit we do not really need 64-bit compare-and-exchange. We can + implement them by use of the csd instruction. The straightforward + implementation causes warnings so we skip the definition for now. */ +# define __arch_compare_and_exchange_64_acq(mem, newval, oldval) \ + (abort (), 0) +#endif diff --git a/nptl/sysdeps/s390/pthread_spin_init.c b/nptl/sysdeps/s390/pthread_spin_init.c new file mode 100644 index 0000000000..814bb484e7 --- /dev/null +++ b/nptl/sysdeps/s390/pthread_spin_init.c @@ -0,0 +1,20 @@ +/* Copyright (C) 2003 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Martin Schwidefsky <schwidefsky@de.ibm.com>, 2003. + + 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. */ + +/* Not needed. pthread_spin_init is an alias for pthread_spin_unlock. */ diff --git a/nptl/sysdeps/s390/pthread_spin_lock.c b/nptl/sysdeps/s390/pthread_spin_lock.c new file mode 100644 index 0000000000..7d0067b0e9 --- /dev/null +++ b/nptl/sysdeps/s390/pthread_spin_lock.c @@ -0,0 +1,34 @@ +/* Copyright (C) 2003 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Martin Schwidefsky <schwidefsky@de.ibm.com>, 2003. + + 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. */ + +#include "pthreadP.h" + +int +pthread_spin_lock (lock) + pthread_spinlock_t *lock; +{ + unsigned long int oldval; + + __asm __volatile ("0: lhi %0,0\n" + " cs %0,%2,%1\n" + " jl 0b" + : "=d" (oldval), "=Q" (*lock) + : "d" (1), "m" (*lock) : "cc" ); + return 0; +} diff --git a/nptl/sysdeps/s390/pthread_spin_trylock.c b/nptl/sysdeps/s390/pthread_spin_trylock.c new file mode 100644 index 0000000000..8ed0a36647 --- /dev/null +++ b/nptl/sysdeps/s390/pthread_spin_trylock.c @@ -0,0 +1,34 @@ +/* Copyright (C) 2003 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Martin Schwidefsky <schwidefsky@de.ibm.com>, 2003. + + 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. */ + +#include <errno.h> +#include "pthreadP.h" + +int +pthread_spin_trylock (lock) + pthread_spinlock_t *lock; +{ + unsigned long int old; + + __asm __volatile ("cs %0,%3,%1" + : "=d" (old), "=Q" (*lock) + : "0" (0), "d" (1), "m" (*lock) : "cc" ); + + return old != 0 ? EBUSY : 0; +} diff --git a/nptl/sysdeps/s390/pthread_spin_unlock.c b/nptl/sysdeps/s390/pthread_spin_unlock.c new file mode 100644 index 0000000000..a59c945293 --- /dev/null +++ b/nptl/sysdeps/s390/pthread_spin_unlock.c @@ -0,0 +1,33 @@ +/* Copyright (C) 2003 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Martin Schwidefsky <schwidefsky@de.ibm.com>, 2003. + + 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. */ + +/* Ugly hack to avoid the declaration of pthread_spin_init. */ +#define pthread_spin_init pthread_spin_init_XXX +#include "pthreadP.h" +#undef pthread_spin_init + +int +pthread_spin_unlock (pthread_spinlock_t *lock) +{ + __asm __volatile (" xc %O0(4,%R0),%0\n" + " bcr 15,0" + : "=Q" (*lock) : "m" (*lock) : "cc" ); + return 0; +} +strong_alias (pthread_spin_unlock, pthread_spin_init) diff --git a/nptl/sysdeps/s390/pthreaddef.h b/nptl/sysdeps/s390/pthreaddef.h new file mode 100644 index 0000000000..17ef4dc378 --- /dev/null +++ b/nptl/sysdeps/s390/pthreaddef.h @@ -0,0 +1,44 @@ +/* Copyright (C) 2003 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. */ + +/* Default stack size. */ +#define ARCH_STACK_DEFAULT_SIZE (2 * 1024 * 1024) + +/* Required stack pointer alignment at beginning. SSE requires 16 + bytes. */ +#define STACK_ALIGN 16 + +/* Minimal stack size after allocating thread descriptor and guard size. */ +#define MINIMAL_REST_STACK 2048 + +/* Alignment requirement for TCB. */ +#define TCB_ALIGNMENT 16 + +/* The signal used for asynchronous cancelation. */ +#define SIGCANCEL __SIGRTMIN + + +/* Location of current stack frame. */ +#define CURRENT_STACK_FRAME __builtin_frame_address (0) + + +/* XXX Until we have a better place keep the definitions here. */ + +/* While there is no such syscall. */ +#define __exit_thread_inline(val) \ + INLINE_SYSCALL (exit, 0) diff --git a/nptl/sysdeps/s390/tcb-offsets.sym b/nptl/sysdeps/s390/tcb-offsets.sym new file mode 100644 index 0000000000..aee6be2570 --- /dev/null +++ b/nptl/sysdeps/s390/tcb-offsets.sym @@ -0,0 +1,4 @@ +#include <sysdep.h> +#include <tls.h> + +MULTIPLE_THREADS_OFFSET offsetof (tcbhead_t, multiple_threads) diff --git a/nptl/sysdeps/s390/td_ta_map_lwp2thr.c b/nptl/sysdeps/s390/td_ta_map_lwp2thr.c new file mode 100644 index 0000000000..d12328f116 --- /dev/null +++ b/nptl/sysdeps/s390/td_ta_map_lwp2thr.c @@ -0,0 +1,47 @@ +/* Which thread is running on an LWP? i386 version. + Copyright (C) 2003 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Martin Schwidefsky <schwidefsky@de.ibm.com>, 2003. + + 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. */ + +#include "thread_dbP.h" +#include <tls.h> + + +td_err_e +td_ta_map_lwp2thr (const td_thragent_t *ta, lwpid_t lwpid, td_thrhandle_t *th) +{ + LOG ("td_ta_map_lwp2thr"); + + /* Test whether the TA parameter is ok. */ + if (! ta_ok (ta)) + return TD_BADTA; + + prgregset_t regs; + if (ps_lgetregs (ta->ph, lwpid, regs) != PS_OK) + return TD_ERR; + + /* Get the thread area for the addressed thread. */ + if (ps_get_thread_area (ta->ph, lwpid, regs[18] >> 3, &th->th_unique) + != PS_OK) + return TD_ERR; /* XXX Other error value? */ + + /* Found it. Now complete the `td_thrhandle_t' object. */ + th->th_ta_p = (td_thragent_t *) ta; + + return TD_OK; +} diff --git a/nptl/sysdeps/s390/tls.h b/nptl/sysdeps/s390/tls.h new file mode 100644 index 0000000000..fd43564762 --- /dev/null +++ b/nptl/sysdeps/s390/tls.h @@ -0,0 +1,149 @@ +/* Definition for thread-local data handling. nptl/s390 version. + Copyright (C) 2003 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 _TLS_H +#define _TLS_H 1 + +#include <dl-sysdep.h> +#ifndef __ASSEMBLER__ +# include <stddef.h> +# include <stdint.h> +# include <stdlib.h> +# include <list.h> + + +/* Type for the dtv. */ +typedef union dtv +{ + size_t counter; + void *pointer; +} dtv_t; + + +typedef struct +{ + void *tcb; /* Pointer to the TCB. Not necessary the + thread descriptor used by libpthread. */ + dtv_t *dtv; + void *self; /* Pointer to the thread descriptor. */ + int multiple_threads; +#ifdef NEED_DL_SYSINFO + uintptr_t sysinfo; +#endif + list_t list; +} tcbhead_t; + +#else /* __ASSEMBLER__ */ +# include <tcb-offsets.h> +#endif + + +/* We require TLS support in the tools. */ +#ifndef HAVE_TLS_SUPPORT +# error "TLS support is required." +#endif + +/* Signal that TLS support is available. */ +#define USE_TLS 1 + +/* Alignment requirement for the stack. For IA-32 this is governed by + the SSE memory functions. */ +#define STACK_ALIGN 16 + +#ifndef __ASSEMBLER__ +/* Get system call information. */ +# include <sysdep.h> + +/* Get the thread descriptor definition. */ +# include <nptl/descr.h> + +/* This is the size of the initial TCB. */ +# define TLS_INIT_TCB_SIZE sizeof (tcbhead_t) + +/* Alignment requirements for the initial TCB. */ +# define TLS_INIT_TCB_ALIGN __alignof__ (tcbhead_t) + +/* This is the size of the TCB. */ +# define TLS_TCB_SIZE sizeof (struct pthread) + +/* Alignment requirements for the TCB. */ +# define TLS_TCB_ALIGN __alignof__ (struct pthread) + +/* The TCB can have any size and the memory following the address the + thread pointer points to is unspecified. Allocate the TCB there. */ +# define TLS_TCB_AT_TP 1 + + +/* Install the dtv pointer. The pointer passed is to the element with + index -1 which contain the length. */ +# define INSTALL_DTV(descr, dtvp) \ + ((tcbhead_t *) (descr))->dtv = (dtvp) + 1 + +/* Install new dtv for current thread. */ +# define INSTALL_NEW_DTV(dtv) \ + (((tcbhead_t *) __builtin_thread_pointer ())->dtv = (dtv)) + +/* Return dtv of given thread descriptor. */ +# define GET_DTV(descr) \ + (((tcbhead_t *) (descr))->dtv) + +#if defined NEED_DL_SYSINFO && defined SHARED +# define INIT_SYSINFO \ + _head->sysinfo = GL(dl_sysinfo) +#else +# define INIT_SYSINFO +#endif + +/* Code to initially initialize the thread pointer. This might need + special attention since 'errno' is not yet available and if the + operation can cause a failure 'errno' must not be touched. */ +# define TLS_INIT_TP(thrdescr, secondcall) \ + ({ void *_thrdescr = (thrdescr); \ + tcbhead_t *_head = _thrdescr; \ + \ + _head->tcb = _thrdescr; \ + /* For now the thread descriptor is at the same address. */ \ + _head->self = _thrdescr; \ + /* New syscall handling support. */ \ + INIT_SYSINFO; \ + \ + __builtin_set_thread_pointer (_thrdescr); \ + NULL; \ + }) + +/* Return the address of the dtv for the current thread. */ +# define THREAD_DTV() \ + (((tcbhead_t *) __builtin_thread_pointer ())->dtv) + +/* Return the thread descriptor for the current thread. */ +# define THREAD_SELF ((struct pthread *) __builtin_thread_pointer ()) + +/* Access to data in the thread descriptor is easy. */ +#define THREAD_GETMEM(descr, member) \ + THREAD_SELF->member +#define THREAD_GETMEM_NC(descr, member, idx) \ + THREAD_SELF->member[idx] +#define THREAD_SETMEM(descr, member, value) \ + THREAD_SELF->member = (value) +#define THREAD_SETMEM_NC(descr, member, idx, value) \ + THREAD_SELF->member[idx] = (value) + +#endif /* __ASSEMBLER__ */ + +#endif /* tls.h */ |