2 * sysdeps/microblaze/pt-machine.h -- microblaze-specific pthread definitions
4 * Copyright (C) 2003 John Williams <jwilliams@itee.uq.edu.au>
5 * Copyright (C) 2002 NEC Electronics Corporation
6 * Copyright (C) 2002 Miles Bader <miles@gnu.org>
8 * This file is subject to the terms and conditions of the GNU Lesser
9 * General Public License. See the file COPYING.LIB in the main
10 * directory of this archive for more details.
12 * Written by Miles Bader <miles@gnu.org>
16 #define _PT_MACHINE_H 1
21 # define PT_EI extern inline
24 extern long int testandset (int *spinlock);
25 extern int __compare_and_swap (long *ptr, long old, long new);
27 /* Get some notion of the current stack. Need not be exactly the top
28 of the stack, just something somewhere in the current frame. */
29 #define CURRENT_STACK_FRAME __stack_pointer
30 register char *__stack_pointer __asm__ ("r1");
32 #define HAS_COMPARE_AND_SWAP
33 #define HAS_COMPARE_AND_SWAP_WITH_RELEASE_SEMANTICS
34 #define IMPLEMENT_TAS_WITH_CAS
36 /* Atomically: If *PTR == OLD, set *PTR to NEW and return true,
37 otherwise do nothing and return false. */
38 PT_EI int __compare_and_swap (long *ptr, long old, long new)
42 /* disable interrupts */
43 /* This is ugly ugly ugly! */
44 __asm__ __volatile__ ("mfs %0, rmsr;"
51 if (likely (*ptr == old))
54 __asm__ __volatile__ ("mts rmsr, %0;" :: "r" (psw)); /* re-enable */
59 __asm__ __volatile__ ("mts rmsr, %0;" :: "r" (psw)); /* re-enable */
64 /* like above's __compare_and_swap() but it first syncs the memory
65 (This is also the difference between both functions in e.g.
66 ../powerpc/pt-machine.h)
67 Doing this additional sync fixes a hang of __pthread_alt_unlock()
68 (Falk Brettschneider <fbrettschneider@baumeroptronic.de>) */
70 __compare_and_swap_with_release_semantics (long *p,
71 long oldval, long newval)
73 __asm__ __volatile__ ("" : : : "memory"); /*MEMORY_BARRIER ();*/
74 return __compare_and_swap (p, oldval, newval);
78 #ifndef IMPLEMENT_TAS_WITH_CAS
79 /* Spinlock implementation; required. */
80 PT_EI long int testandset (int *spinlock)
84 /* disable interrupts */
85 __asm__ __volatile__ ("mfs %0, rmsr;"
95 __asm__ __volatile__ ("mts rmsr, %0;" :: "r" (psw));
100 __asm__ __volatile__ ("mts rmsr, %0;" :: "r" (psw));
106 #endif /* pt-machine.h */