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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [uClibc/] [libc/] [sysdeps/] [linux/] [arm/] [bits/] [atomicity.h] - Blame information for rev 1779

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

Line No. Rev Author Line
1 1325 phoenix
/* Low-level functions for atomic operations.  ARM version.
2
   Copyright (C) 1997, 1998, 1999, 2000 Free Software Foundation, Inc.
3
   This file is part of the GNU C Library.
4
 
5
   The GNU C Library is free software; you can redistribute it and/or
6
   modify it under the terms of the GNU Lesser General Public
7
   License as published by the Free Software Foundation; either
8
   version 2.1 of the License, or (at your option) any later version.
9
 
10
   The GNU C Library is distributed in the hope that it will be useful,
11
   but WITHOUT ANY WARRANTY; without even the implied warranty of
12
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
   Lesser General Public License for more details.
14
 
15
   You should have received a copy of the GNU Lesser General Public
16
   License along with the GNU C Library; if not, write to the Free
17
   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18
   02111-1307 USA.  */
19
 
20
#ifndef _ATOMICITY_H
21
#define _ATOMICITY_H    1
22
 
23
#include <inttypes.h>
24
 
25
 
26
static inline int
27
__attribute__ ((unused))
28
exchange_and_add (volatile uint32_t *mem, int val)
29
{
30
  int tmp1;
31
  int tmp2;
32
  int result;
33
  __asm__ ("\n"
34
           "0:\tldr\t%0,[%3]\n\t"
35
           "add\t%1,%0,%4\n\t"
36
           "swp\t%2,%1,[%3]\n\t"
37
           "cmp\t%0,%2\n\t"
38
           "swpne\t%1,%2,[%3]\n\t"
39
           "bne\t0b"
40
           : "=&r" (result), "=&r" (tmp1), "=&r" (tmp2)
41
           : "r" (mem), "r"(val)
42
           : "cc", "memory");
43
  return result;
44
}
45
 
46
static inline void
47
__attribute__ ((unused))
48
atomic_add (volatile uint32_t *mem, int val)
49
{
50
  int tmp1;
51
  int tmp2;
52
  int tmp3;
53
  __asm__ ("\n"
54
           "0:\tldr\t%0,[%3]\n\t"
55
           "add\t%1,%0,%4\n\t"
56
           "swp\t%2,%1,[%3]\n\t"
57
           "cmp\t%0,%2\n\t"
58
           "swpne\t%1,%2,[%3]\n\t"
59
           "bne\t0b"
60
           : "=&r" (tmp1), "=&r" (tmp2), "=&r" (tmp3)
61
           : "r" (mem), "r"(val)
62
           : "cc", "memory");
63
}
64
 
65
static inline int
66
__attribute__ ((unused))
67
compare_and_swap (volatile long int *p, long int oldval, long int newval)
68
{
69
  int result, tmp;
70
  __asm__ ("\n"
71
           "0:\tldr\t%1,[%2]\n\t"
72
           "mov\t%0,#0\n\t"
73
           "cmp\t%1,%4\n\t"
74
           "bne\t1f\n\t"
75
           "swp\t%0,%3,[%2]\n\t"
76
           "cmp\t%1,%0\n\t"
77
           "swpne\t%1,%0,[%2]\n\t"
78
           "bne\t0b\n\t"
79
           "mov\t%0,#1\n"
80
           "1:"
81
           : "=&r" (result), "=&r" (tmp)
82
           : "r" (p), "r" (newval), "r" (oldval)
83
           : "cc", "memory");
84
  return result;
85
}
86
 
87
#endif /* atomicity.h */

powered by: WebSVN 2.1.0

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