1 /* Machine-dependent pthreads configuration and inline functions.
3 Copyright (C) 1996, 1997, 1998, 2000, 2001, 2002 Free Software Foundation, Inc.
4 This file is part of the GNU C Library.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public License as
8 published by the Free Software Foundation; either version 2.1 of the
9 License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; see the file COPYING.LIB. If
18 not, see <http://www.gnu.org/licenses/>. */
20 /* These routines are from Appendix G of the 'PowerPC 601 RISC Microprocessor
21 User's Manual', by IBM and Motorola. */
24 #define _PT_MACHINE_H 1
29 # define PT_EI __extern_always_inline
32 /* For multiprocessor systems, we want to ensure all memory accesses
33 are completed before we reset a lock. On other systems, we still
34 need to make sure that the compiler has flushed everything to memory. */
35 #define MEMORY_BARRIER() __asm__ __volatile__ ("sync" : : : "memory")
37 /* Get some notion of the current stack. Need not be exactly the top
38 of the stack, just something somewhere in the current frame. */
39 #define CURRENT_STACK_FRAME stack_pointer
40 register char * stack_pointer __asm__ ("r1");
42 /* Register r2 (tp) is reserved by the ABI as "thread pointer". */
43 struct _pthread_descr_struct;
44 register struct _pthread_descr_struct *__thread_self __asm__("r2");
46 /* Return the thread descriptor for the current thread. */
47 #define THREAD_SELF __thread_self
49 /* Initialize the thread-unique value. */
50 #define INIT_THREAD_SELF(descr, nr) (__thread_self = (descr))
52 /* Compare-and-swap for semaphores. */
53 /* note that test-and-set(x) is the same as !compare-and-swap(x, 0, 1) */
55 #define HAS_COMPARE_AND_SWAP_WITH_RELEASE_SEMANTICS
56 #define IMPLEMENT_TAS_WITH_CAS
59 __compare_and_swap (long int *p, long int oldval, long int newval)
63 __asm__ __volatile__ (
71 : "r"(p), "r"(newval), "r"(oldval)
73 /* This version of __compare_and_swap is to be used when acquiring
74 a lock, so we don't need to worry about whether other memory
75 operations have completed, but we do need to be sure that any loads
76 after this point really occur after we have acquired the lock. */
77 __asm__ __volatile__ ("isync" : : : "memory");
82 __compare_and_swap_with_release_semantics (long int *p,
83 long int oldval, long int newval)
88 __asm__ __volatile__ (
96 : "r"(p), "r"(newval), "r"(oldval)
101 #endif /* pt-machine.h */