OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [uClibc/] [libpthread/] [linuxthreads/] [sysdeps/] [powerpc/] [pt-machine.h] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1325 phoenix
/* Machine-dependent pthreads configuration and inline functions.
2
   powerpc version.
3
   Copyright (C) 1996, 1997, 1998, 2000, 2001, 2002 Free Software Foundation, Inc.
4
   This file is part of the GNU C Library.
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
/* These routines are from Appendix G of the 'PowerPC 601 RISC Microprocessor
22
   User's Manual', by IBM and Motorola.  */
23
 
24
#ifndef _PT_MACHINE_H
25
#define _PT_MACHINE_H   1
26
 
27
#ifndef PT_EI
28
# define PT_EI extern inline
29
#endif
30
 
31
extern long int testandset (int *spinlock);
32
extern int __compare_and_swap (long int *p, long int oldval, long int newval);
33
 
34
/* For multiprocessor systems, we want to ensure all memory accesses
35
   are completed before we reset a lock.  On other systems, we still
36
   need to make sure that the compiler has flushed everything to memory.  */
37
#define MEMORY_BARRIER() __asm__ __volatile__ ("sync" : : : "memory")
38
 
39
/* Get some notion of the current stack.  Need not be exactly the top
40
   of the stack, just something somewhere in the current frame.  */
41
#define CURRENT_STACK_FRAME  stack_pointer
42
register char * stack_pointer __asm__ ("r1");
43
 
44
/* Compare-and-swap for semaphores. */
45
/* note that test-and-set(x) is the same as !compare-and-swap(x, 0, 1) */
46
 
47
#define HAS_COMPARE_AND_SWAP_WITH_RELEASE_SEMANTICS
48
#define IMPLEMENT_TAS_WITH_CAS
49
 
50
PT_EI int
51
__compare_and_swap (long int *p, long int oldval, long int newval)
52
{
53
  int ret;
54
 
55
  __asm__ __volatile__ (
56
           "0:    lwarx %0,0,%1 ;"
57
           "      xor. %0,%3,%0;"
58
           "      bne 1f;"
59
           "      stwcx. %2,0,%1;"
60
           "      bne- 0b;"
61
           "1:    "
62
        : "=&r"(ret)
63
        : "r"(p), "r"(newval), "r"(oldval)
64
        : "cr0", "memory");
65
  /* This version of __compare_and_swap is to be used when acquiring
66
     a lock, so we don't need to worry about whether other memory
67
     operations have completed, but we do need to be sure that any loads
68
     after this point really occur after we have acquired the lock.  */
69
  __asm__ __volatile__ ("isync" : : : "memory");
70
  return ret == 0;
71
}
72
 
73
PT_EI int
74
__compare_and_swap_with_release_semantics (long int *p,
75
                                           long int oldval, long int newval)
76
{
77
  int ret;
78
 
79
  MEMORY_BARRIER ();
80
  __asm__ __volatile__ (
81
           "0:    lwarx %0,0,%1 ;"
82
           "      xor. %0,%3,%0;"
83
           "      bne 1f;"
84
           "      stwcx. %2,0,%1;"
85
           "      bne- 0b;"
86
           "1:    "
87
        : "=&r"(ret)
88
        : "r"(p), "r"(newval), "r"(oldval)
89
        : "cr0", "memory");
90
  return ret == 0;
91
}
92
 
93
#endif /* pt-machine.h */

powered by: WebSVN 2.1.0

© copyright 1999-2025 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.