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, write to the Free Software Foundation, Inc.,
19 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
21 /* These routines are from Appendix G of the 'PowerPC 601 RISC Microprocessor
22 User's Manual', by IBM and Motorola. */
25 #define _PT_MACHINE_H 1
30 # if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)
31 # define PT_EI static inline __attribute__((always_inline))
33 # define PT_EI extern inline __attribute__((always_inline))
37 /* For multiprocessor systems, we want to ensure all memory accesses
38 are completed before we reset a lock. On other systems, we still
39 need to make sure that the compiler has flushed everything to memory. */
40 #define MEMORY_BARRIER() __asm__ __volatile__ ("sync" : : : "memory")
42 /* Get some notion of the current stack. Need not be exactly the top
43 of the stack, just something somewhere in the current frame. */
44 #define CURRENT_STACK_FRAME stack_pointer
45 register char * stack_pointer __asm__ ("r1");
47 /* Register r2 (tp) is reserved by the ABI as "thread pointer". */
48 struct _pthread_descr_struct;
49 register struct _pthread_descr_struct *__thread_self __asm__("r2");
51 /* Return the thread descriptor for the current thread. */
52 #define THREAD_SELF __thread_self
54 /* Initialize the thread-unique value. */
55 #define INIT_THREAD_SELF(descr, nr) (__thread_self = (descr))
57 /* Compare-and-swap for semaphores. */
58 /* note that test-and-set(x) is the same as !compare-and-swap(x, 0, 1) */
60 #define HAS_COMPARE_AND_SWAP_WITH_RELEASE_SEMANTICS
61 #define IMPLEMENT_TAS_WITH_CAS
64 __compare_and_swap (long int *p, long int oldval, long int newval)
68 __asm__ __volatile__ (
76 : "r"(p), "r"(newval), "r"(oldval)
78 /* This version of __compare_and_swap is to be used when acquiring
79 a lock, so we don't need to worry about whether other memory
80 operations have completed, but we do need to be sure that any loads
81 after this point really occur after we have acquired the lock. */
82 __asm__ __volatile__ ("isync" : : : "memory");
87 __compare_and_swap_with_release_semantics (long int *p,
88 long int oldval, long int newval)
93 __asm__ __volatile__ (
101 : "r"(p), "r"(newval), "r"(oldval)
106 #endif /* pt-machine.h */