Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/arch/sparc64/include/atomic.h

    r986c24c r7a0359b  
    2727 */
    2828
    29 /** @addtogroup sparc64 
     29/** @addtogroup sparc64
    3030 * @{
    3131 */
     
    3737
    3838#include <arch/barrier.h>
    39 #include <arch/types.h>
     39#include <typedefs.h>
    4040#include <preemption.h>
     41#include <trace.h>
    4142
    4243/** Atomic add operation.
     
    4546 *
    4647 * @param val Atomic variable.
    47  * @param i Signed value to be added.
     48 * @param i   Signed value to be added.
    4849 *
    4950 * @return Value of the atomic variable as it existed before addition.
     51 *
    5052 */
    51 static inline long atomic_add(atomic_t *val, int i)
     53NO_TRACE static inline atomic_count_t atomic_add(atomic_t *val,
     54    atomic_count_t i)
    5255{
    53         uint64_t a, b;
    54 
     56        atomic_count_t a;
     57        atomic_count_t b;
     58       
    5559        do {
    56                 volatile uintptr_t x = (uint64_t) &val->count;
    57 
    58                 a = *((uint64_t *) x);
     60                volatile uintptr_t ptr = (uintptr_t) &val->count;
     61               
     62                a = *((atomic_count_t *) ptr);
    5963                b = a + i;
    60                 asm volatile ("casx %0, %2, %1\n" : "+m" (*((uint64_t *)x)),
    61                     "+r" (b) : "r" (a));
     64               
     65                asm volatile (
     66                        "casx %0, %2, %1\n"
     67                        : "+m" (*((atomic_count_t *) ptr)),
     68                      "+r" (b)
     69                    : "r" (a)
     70                );
    6271        } while (a != b);
    63 
     72       
    6473        return a;
    6574}
    6675
    67 static inline long atomic_preinc(atomic_t *val)
     76NO_TRACE static inline atomic_count_t atomic_preinc(atomic_t *val)
    6877{
    6978        return atomic_add(val, 1) + 1;
    7079}
    7180
    72 static inline long atomic_postinc(atomic_t *val)
     81NO_TRACE static inline atomic_count_t atomic_postinc(atomic_t *val)
    7382{
    7483        return atomic_add(val, 1);
    7584}
    7685
    77 static inline long atomic_predec(atomic_t *val)
     86NO_TRACE static inline atomic_count_t atomic_predec(atomic_t *val)
    7887{
    7988        return atomic_add(val, -1) - 1;
    8089}
    8190
    82 static inline long atomic_postdec(atomic_t *val)
     91NO_TRACE static inline atomic_count_t atomic_postdec(atomic_t *val)
    8392{
    8493        return atomic_add(val, -1);
    8594}
    8695
    87 static inline void atomic_inc(atomic_t *val)
     96NO_TRACE static inline void atomic_inc(atomic_t *val)
    8897{
    8998        (void) atomic_add(val, 1);
    9099}
    91100
    92 static inline void atomic_dec(atomic_t *val)
     101NO_TRACE static inline void atomic_dec(atomic_t *val)
    93102{
    94103        (void) atomic_add(val, -1);
    95104}
    96105
    97 static inline long test_and_set(atomic_t *val)
     106NO_TRACE static inline atomic_count_t test_and_set(atomic_t *val)
    98107{
    99         uint64_t v = 1;
    100         volatile uintptr_t x = (uint64_t) &val->count;
    101 
    102         asm volatile ("casx %0, %2, %1\n" : "+m" (*((uint64_t *) x)),
    103             "+r" (v) : "r" (0));
    104 
     108        atomic_count_t v = 1;
     109        volatile uintptr_t ptr = (uintptr_t) &val->count;
     110       
     111        asm volatile (
     112                "casx %0, %2, %1\n"
     113                : "+m" (*((atomic_count_t *) ptr)),
     114              "+r" (v)
     115            : "r" (0)
     116        );
     117       
    105118        return v;
    106119}
    107120
    108 static inline void atomic_lock_arch(atomic_t *val)
     121NO_TRACE static inline void atomic_lock_arch(atomic_t *val)
    109122{
    110         uint64_t tmp1 = 1;
    111         uint64_t tmp2 = 0;
    112 
    113         volatile uintptr_t x = (uint64_t) &val->count;
    114 
     123        atomic_count_t tmp1 = 1;
     124        atomic_count_t tmp2 = 0;
     125       
     126        volatile uintptr_t ptr = (uintptr_t) &val->count;
     127       
    115128        preemption_disable();
    116 
     129       
    117130        asm volatile (
    118         "0:\n"
    119                 "casx %0, %3, %1\n"
    120                 "brz %1, 2f\n"
    121                 "nop\n"
    122         "1:\n"
    123                 "ldx %0, %2\n"
    124                 "brz %2, 0b\n"
    125                 "nop\n"
    126                 "ba %%xcc, 1b\n"
    127                 "nop\n"
    128         "2:\n"
    129                 : "+m" (*((uint64_t *) x)), "+r" (tmp1), "+r" (tmp2) : "r" (0)
     131                "0:\n"
     132                        "casx %0, %3, %1\n"
     133                        "brz %1, 2f\n"
     134                        "nop\n"
     135                "1:\n"
     136                        "ldx %0, %2\n"
     137                        "brz %2, 0b\n"
     138                        "nop\n"
     139                        "ba,a %%xcc, 1b\n"
     140                "2:\n"
     141                : "+m" (*((atomic_count_t *) ptr)),
     142                  "+r" (tmp1),
     143                  "+r" (tmp2)
     144                : "r" (0)
    130145        );
    131146       
Note: See TracChangeset for help on using the changeset viewer.