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

Subversion Repositories or1k

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

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1325 phoenix
/* Machine-dependent pthreads configuration and inline functions.
2
 
3
   Copyright (C) 1996, 1997, 1998, 2000, 2002 Free Software Foundation, Inc.
4
   This file is part of the GNU C Library.
5
   Contributed by Ralf Baechle <ralf@gnu.org>.
6
   Based on the Alpha version by Richard Henderson <rth@tamu.edu>.
7
 
8
   The GNU C Library is free software; you can redistribute it and/or
9
   modify it under the terms of the GNU Lesser General Public License as
10
   published by the Free Software Foundation; either version 2.1 of the
11
   License, or (at your option) any later version.
12
 
13
   The GNU C Library is distributed in the hope that it will be useful,
14
   but WITHOUT ANY WARRANTY; without even the implied warranty of
15
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16
   Lesser General Public License for more details.
17
 
18
   You should have received a copy of the GNU Lesser General Public
19
   License along with the GNU C Library; see the file COPYING.LIB.  If
20
   not, write to the Free Software Foundation, Inc.,
21
   59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
22
 
23
#ifndef _PT_MACHINE_H
24
#define _PT_MACHINE_H   1
25
 
26
#include <features.h>
27
 
28
/* Copyright (C) 2000, 2002 Free Software Foundation, Inc.
29
   This file is part of the GNU C Library.
30
   Contributed by Maciej W. Rozycki <macro@ds2.pg.gda.pl>, 2000.  */
31
static inline int
32
_test_and_set (int *p, int v) __THROW
33
{
34
  int r, t;
35
 
36
  __asm__ __volatile__
37
    ("/* Inline test and set */\n"
38
     "1:\n\t"
39
     ".set      push\n\t"
40
     ".set      mips2\n\t"
41
     "ll        %0,%3\n\t"
42
     "move      %1,%4\n\t"
43
     "beq       %0,%4,2f\n\t"
44
     "sc        %1,%2\n\t"
45
     ".set      pop\n\t"
46
     "beqz      %1,1b\n"
47
     "2:\n\t"
48
     "/* End test and set */"
49
     : "=&r" (r), "=&r" (t), "=m" (*p)
50
     : "m" (*p), "r" (v)
51
     : "memory");
52
 
53
  return r;
54
}
55
 
56
 
57
#ifndef PT_EI
58
# define PT_EI extern inline
59
#endif
60
 
61
extern long int testandset (int *spinlock);
62
extern int __compare_and_swap (long int *p, long int oldval, long int newval);
63
 
64
 
65
/* Spinlock implementation; required.  */
66
 
67
PT_EI long int
68
testandset (int *spinlock)
69
{
70
  return _test_and_set (spinlock, 1);
71
}
72
 
73
 
74
/* Get some notion of the current stack.  Need not be exactly the top
75
   of the stack, just something somewhere in the current frame.  */
76
#define CURRENT_STACK_FRAME  stack_pointer
77
register char * stack_pointer __asm__ ("$29");
78
 
79
 
80
/* Compare-and-swap for semaphores. */
81
 
82
#define HAS_COMPARE_AND_SWAP
83
PT_EI int
84
__compare_and_swap (long int *p, long int oldval, long int newval)
85
{
86
  long int ret, temp;
87
 
88
  __asm__ __volatile__
89
    ("/* Inline compare & swap */\n"
90
     "1:\n\t"
91
     ".set      push\n\t"
92
     ".set      mips2\n\t"
93
     "ll        %1,%5\n\t"
94
     "move      %0,$0\n\t"
95
     "bne       %1,%3,2f\n\t"
96
     "move      %0,%4\n\t"
97
     "sc        %0,%2\n\t"
98
     ".set      pop\n\t"
99
     "beqz      %0,1b\n"
100
     "2:\n\t"
101
     "/* End compare & swap */"
102
     : "=&r" (ret), "=&r" (temp), "=m" (*p)
103
     : "r" (oldval), "r" (newval), "m" (*p)
104
     : "memory");
105
 
106
  return ret;
107
}
108
 
109
#endif /* pt-machine.h */

powered by: WebSVN 2.1.0

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