blob: e81ecffbea729968a86a828aca2a913251458732 [file] [log] [blame]
yuezonghe824eb0c2024-06-27 02:32:26 -07001/* Machine-dependent pthreads configuration and inline functions.
2 Copyright (C) 1996, 1998, 2000, 2002 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Richard Henderson <rth@tamu.edu>.
5
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.
10
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.
15
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. */
20
21#ifndef _PT_MACHINE_H
22#define _PT_MACHINE_H 1
23
24#include <features.h>
25
26#ifndef PT_EI
27# define PT_EI __extern_always_inline
28#endif
29
30#include <asm/fixed_code.h>
31
32/* Spinlock implementation; required. */
33/* The semantics of the TESTSET instruction cannot be guaranteed. We cannot
34 easily move all locks used by linux kernel to non-cacheable memory.
35 EXCPT 0x4 is used to trap into kernel to do the atomic testandset.
36 It's ugly. But it's the only thing we can do now.
37 The handler of EXCPT 0x4 expects the address of the lock is passed through
38 R0. And the result is returned by R0. */
39PT_EI long int
40testandset (int *spinlock)
41{
42 long int res;
43
44 __asm__ __volatile__ (
45 "CALL (%4);"
46 : "=q0" (res), "=m" (*spinlock)
47 : "qA" (spinlock), "m" (*spinlock), "a" (ATOMIC_XCHG32), "q1" (1)
48 : "RETS", "cc", "memory");
49
50 return res;
51}
52
53#define HAS_COMPARE_AND_SWAP
54PT_EI int
55__compare_and_swap (long int *p, long int oldval, long int newval)
56{
57 long int readval;
58 __asm__ __volatile__ (
59 "CALL (%5);"
60 : "=q0" (readval), "=m" (*p)
61 : "qA" (p),
62 "q1" (oldval),
63 "q2" (newval),
64 "a" (ATOMIC_CAS32),
65 "m" (*p)
66 : "RETS", "memory", "cc");
67 return readval == oldval;
68}
69
70#ifdef SHARED
71# define PTHREAD_STATIC_FN_REQUIRE(name)
72#else
73# define PTHREAD_STATIC_FN_REQUIRE(name) __asm__ (".globl " "_"#name);
74#endif
75
76#endif /* pt-machine.h */