diff options
Diffstat (limited to 'linuxthreads/sysdeps')
27 files changed, 1672 insertions, 0 deletions
diff --git a/linuxthreads/sysdeps/alpha/bits/semaphore.h b/linuxthreads/sysdeps/alpha/bits/semaphore.h new file mode 100644 index 0000000000..323fea159e --- /dev/null +++ b/linuxthreads/sysdeps/alpha/bits/semaphore.h @@ -0,0 +1,31 @@ +/* Copyright (C) 1996, 1997 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 _SEMAPHORE_H +# error "Never include <bits/semaphore.h> directly; use <semaphore.h> instead." +#endif + + +/* Due to the implementation of the load-locked/store-conditional + instructions, we cannot pack semaphores closer than a cache line + or risk threads deadlocking on unrelated semaphores. */ + +typedef struct { + long int sem_status; + long int sem_reserved[3]; +} sem_t; diff --git a/linuxthreads/sysdeps/alpha/pt-machine.h b/linuxthreads/sysdeps/alpha/pt-machine.h new file mode 100644 index 0000000000..a0c7cc77e2 --- /dev/null +++ b/linuxthreads/sysdeps/alpha/pt-machine.h @@ -0,0 +1,102 @@ +/* Machine-dependent pthreads configuration and inline functions. + Alpha version. + Copyright (C) 1996, 1997 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Richard Henderson <rth@tamu.edu>. + + 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. */ + +#include <asm/pal.h> + + +/* Spinlock implementation; required. */ +extern inline long testandset(int *spinlock) +{ + long ret, temp; + + __asm__ __volatile__( + "/* Inline spinlock test & set */\n" + "1:\t" + "ldl_l %0,%3\n\t" + "bne %0,2f\n\t" + "or $31,1,%1\n\t" + "stl_c %1,%2\n\t" + "beq %1,1b\n" + "2:\tmb\n" + "/* End spinlock test & set */" + : "=&r"(ret), "=&r"(temp), "=m"(*spinlock) + : "m"(*spinlock) + : "memory"); + + return ret; +} + +/* Spinlock release; default is just set to zero. */ +#define RELEASE(spinlock) \ + __asm__ __volatile__("mb" : : : "memory"); \ + *spinlock = 0 + + +/* Begin allocating thread stacks at this address. Default is to allocate + them just below the initial program stack. */ +#define THREAD_STACK_START_ADDRESS 0x40000000000 + + +/* Get some notion of the current stack. Need not be exactly the top + of the stack, just something somewhere in the current frame. */ +#define CURRENT_STACK_FRAME stack_pointer +register char *stack_pointer __asm__("$30"); + + +/* Return the thread descriptor for the current thread. */ +#define THREAD_SELF \ +({ \ + register pthread_descr __self __asm__("$0"); \ + __asm__ ("call_pal %1" : "=r"(__self) : "i"(PAL_rduniq) : "$0"); \ + __self; \ +}) + +/* Initialize the thread-unique value. */ +#define INIT_THREAD_SELF(descr) \ +{ \ + register pthread_descr __self __asm__("$16") = (descr); \ + __asm__ __volatile__ ("call_pal %1" : : "r"(__self), "i"(PAL_wruniq)); \ +} + + +/* Compare-and-swap for semaphores. */ + +#define HAS_COMPARE_AND_SWAP +extern inline int __compare_and_swap(long * p, long oldval, long newval) +{ + long ret; + + __asm__ __volatile__ ( + "/* Inline compare & swap */\n" + "1:\t" + "ldq_l %0,%4\n\t" + "cmpeq %0,%2,%0\n\t" + "beq %0,2f\n\t" + "mov %3,%0\n\t" + "stq_c %0,%1\n\t" + "beq %0,1b\n\t" + "2:\tmb\n" + "/* End compare & swap */" + : "=&r"(ret), "=m"(*p) + : "r"(oldval), "r"(newval), "m"(*p)); + + return ret; +} diff --git a/linuxthreads/sysdeps/arm/Implies b/linuxthreads/sysdeps/arm/Implies new file mode 100644 index 0000000000..7edcd7e757 --- /dev/null +++ b/linuxthreads/sysdeps/arm/Implies @@ -0,0 +1 @@ +pthread/no-cmpxchg diff --git a/linuxthreads/sysdeps/arm/pt-machine.h b/linuxthreads/sysdeps/arm/pt-machine.h new file mode 100644 index 0000000000..0b9bc01fc1 --- /dev/null +++ b/linuxthreads/sysdeps/arm/pt-machine.h @@ -0,0 +1,44 @@ +/* Machine-dependent pthreads configuration and inline functions. + ARM version. + Copyright (C) 1997 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Philip Blundell <philb@gnu.org>. + + 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. */ + + +/* This will not work on ARM1 or ARM2 because SWP is lacking on those + machines. Unfortunately we have no way to detect this at compile + time; let's hope nobody tries to use one. */ + +/* Spinlock implementation; required. */ +extern inline int +testandset (int *spinlock) +{ + register unsigned int ret; + + __asm__ __volatile__("swp %0, %1, [%2]" + : "=r"(ret) + : "0"(1), "r"(spinlock)); + + return ret; +} + + +/* Get some notion of the current stack. Need not be exactly the top + of the stack, just something somewhere in the current frame. */ +#define CURRENT_STACK_FRAME stack_pointer +register char * stack_pointer __asm__ ("sp"); diff --git a/linuxthreads/sysdeps/i386/Implies b/linuxthreads/sysdeps/i386/Implies new file mode 100644 index 0000000000..7edcd7e757 --- /dev/null +++ b/linuxthreads/sysdeps/i386/Implies @@ -0,0 +1 @@ +pthread/no-cmpxchg diff --git a/linuxthreads/sysdeps/i386/pt-machine.h b/linuxthreads/sysdeps/i386/pt-machine.h new file mode 100644 index 0000000000..ef4df2a1a3 --- /dev/null +++ b/linuxthreads/sysdeps/i386/pt-machine.h @@ -0,0 +1,93 @@ +/* Machine-dependent pthreads configuration and inline functions. + i386 version. + Copyright (C) 1996, 1997 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Richard Henderson <rth@tamu.edu>. + + 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. */ + + +/* Spinlock implementation; required. */ +extern inline int +testandset (int *spinlock) +{ + int ret; + + __asm__ __volatile__("xchgl %0, %1" + : "=r"(ret), "=m"(*spinlock) + : "0"(1), "m"(*spinlock)); + + return ret; +} + + +/* Get some notion of the current stack. Need not be exactly the top + of the stack, just something somewhere in the current frame. */ +#define CURRENT_STACK_FRAME stack_pointer +register char * stack_pointer __asm__ ("%esp"); + + +/* Compare-and-swap for semaphores. + Available on the 486 and above, but not on the 386. + We test dynamically whether it's available or not. */ + +#define HAS_COMPARE_AND_SWAP +#define TEST_FOR_COMPARE_AND_SWAP + +extern inline int +__compare_and_swap (long int *p, long int oldval, long int newval) +{ + char ret; + long int readval; + + __asm__ __volatile__ ("lock; cmpxchgl %3, %1; sete %0" + : "=q" (ret), "=m" (*p), "=a" (readval) + : "r" (newval), "m" (*p), "a" (oldval)); + return ret; +} + + +extern inline int +get_eflags (void) +{ + int res; + __asm__ __volatile__ ("pushfl; popl %0" : "=r" (res) : ); + return res; +} + + +extern inline void +set_eflags (int newflags) +{ + __asm__ __volatile__ ("pushl %0; popfl" : : "r" (newflags) : "cc"); +} + + +extern inline int +compare_and_swap_is_available (void) +{ + int oldflags = get_eflags (); + int changed; + /* Flip AC bit in EFLAGS. */ + set_eflags (oldflags ^ 0x40000); + /* See if bit changed. */ + changed = (get_eflags () ^ oldflags) & 0x40000; + /* Restore EFLAGS. */ + set_eflags (oldflags); + /* If the AC flag did not change, it's a 386 and it lacks cmpxchg. + Otherwise, it's a 486 or above and it has cmpxchg. */ + return changed != 0; +} diff --git a/linuxthreads/sysdeps/m68k/Implies b/linuxthreads/sysdeps/m68k/Implies new file mode 100644 index 0000000000..81e93666c4 --- /dev/null +++ b/linuxthreads/sysdeps/m68k/Implies @@ -0,0 +1 @@ +pthread/cmpxchg diff --git a/linuxthreads/sysdeps/m68k/pt-machine.h b/linuxthreads/sysdeps/m68k/pt-machine.h new file mode 100644 index 0000000000..c5c6cabe35 --- /dev/null +++ b/linuxthreads/sysdeps/m68k/pt-machine.h @@ -0,0 +1,58 @@ +/* Machine-dependent pthreads configuration and inline functions. + m68k version. + Copyright (C) 1996 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Richard Henderson <rth@tamu.edu>. + + 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. */ + + +/* Spinlock implementation; required. */ +extern inline int +testandset (int *spinlock) +{ + char ret; + + __asm__ __volatile__("tas %1; sne %0" + : "=dm"(ret), "=m"(*spinlock) + : "m"(*spinlock) + : "cc"); + + return ret; +} + + +/* Get some notion of the current stack. Need not be exactly the top + of the stack, just something somewhere in the current frame. */ +#define CURRENT_STACK_FRAME stack_pointer +register char * stack_pointer __asm__ ("%sp"); + + +/* Compare-and-swap for semaphores. */ + +#define HAS_COMPARE_AND_SWAP +extern inline int +__compare_and_swap (long int *p, long int oldval, long int newval) +{ + char ret; + long int readval; + + __asm__ __volatile__ ("casl %2, %3, %1; seq %0" + : "=dm" (ret), "=m" (*p), "=d" (readval) + : "d" (newval), "m" (*p), "2" (oldval)); + + return ret; +} diff --git a/linuxthreads/sysdeps/mips/Implies b/linuxthreads/sysdeps/mips/Implies new file mode 100644 index 0000000000..81e93666c4 --- /dev/null +++ b/linuxthreads/sysdeps/mips/Implies @@ -0,0 +1 @@ +pthread/cmpxchg diff --git a/linuxthreads/sysdeps/mips/pt-machine.h b/linuxthreads/sysdeps/mips/pt-machine.h new file mode 100644 index 0000000000..d15da7535b --- /dev/null +++ b/linuxthreads/sysdeps/mips/pt-machine.h @@ -0,0 +1,84 @@ +/* Machine-dependent pthreads configuration and inline functions. + + Copyright (C) 1996, 1997 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Ralf Baechle <ralf@gnu.ai.mit.edu>. + Based on the Alpha version by Richard Henderson <rth@tamu.edu>. + + 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. + + TODO: This version makes use of MIPS ISA 2 features. It won't + work on ISA 1. These machines will have to take the overhead of + a sysmips(MIPS_ATOMIC_SET, ...) syscall which isn't implemented + yet correctly. There is however a better solution for R3000 + uniprocessor machines possible. */ + + +/* Spinlock implementation; required. */ +extern inline long testandset(int *spinlock) +{ + long ret, temp; + + __asm__ __volatile__( + "# Inline spinlock test & set\n\t" + ".set\tmips2\n" + "1:\tll\t%0,%3\n\t" + "bnez\t%0,2f\n\t" + ".set\tnoreorder\n\t" + "li\t%1,1\n\t" + ".set\treorder\n\t" + "sc\t%1,%2\n\t" + "beqz\t%1,1b\n" + "2:\t.set\tmips0\n\t" + "/* End spinlock test & set */" + : "=&r"(ret), "=&r" (temp), "=m"(*spinlock) + : "m"(*spinlock) + : "memory"); + + return ret; +} + + +/* Get some notion of the current stack. Need not be exactly the top + of the stack, just something somewhere in the current frame. */ +#define CURRENT_STACK_FRAME stack_pointer +register char * stack_pointer __asm__ ("$29"); + + +/* Compare-and-swap for semaphores. */ + +#define HAS_COMPARE_AND_SWAP +extern inline int __compare_and_swap(long * p, long oldval, long newval) +{ + long ret; + + __asm__ __volatile__ ( + "/* Inline compare & swap */\n\t" + ".set\tmips2\n" + "1:\tll\t%0,%4\n\t" + ".set\tnoreorder\n\t" + "bne\t%0,%2,2f\n\t" + "move\t%0,%3\n\t" + ".set\treorder\n\t" + "sc\t%0,%1\n\t" + "beqz\t%0,1b\n" + "2:\t.set\tmips0\n\t" + "/* End compare & swap */" + : "=&r"(ret), "=m"(*p) + : "r"(oldval), "r"(newval), "m"(*p)); + + return ret; +} diff --git a/linuxthreads/sysdeps/powerpc/Implies b/linuxthreads/sysdeps/powerpc/Implies new file mode 100644 index 0000000000..81e93666c4 --- /dev/null +++ b/linuxthreads/sysdeps/powerpc/Implies @@ -0,0 +1 @@ +pthread/cmpxchg diff --git a/linuxthreads/sysdeps/powerpc/bits/semaphore.h b/linuxthreads/sysdeps/powerpc/bits/semaphore.h new file mode 100644 index 0000000000..3770eedf15 --- /dev/null +++ b/linuxthreads/sysdeps/powerpc/bits/semaphore.h @@ -0,0 +1,32 @@ +/* Copyright (C) 1996, 1997 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 _SEMAPHORE_H +# error "Never include <bits/semaphore.h> directly; use <semaphore.h> instead." +#endif |
