Ignore:
File:
1 edited

Legend:

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

    r7a0359b r986c24c  
    2727 */
    2828
    29 /** @addtogroup sparc64
     29/** @addtogroup sparc64 
    3030 * @{
    3131 */
     
    3737
    3838#include <arch/barrier.h>
    39 #include <typedefs.h>
     39#include <arch/types.h>
    4040#include <preemption.h>
    41 #include <trace.h>
    4241
    4342/** Atomic add operation.
     
    4645 *
    4746 * @param val Atomic variable.
    48  * @param i   Signed value to be added.
     47 * @param i Signed value to be added.
    4948 *
    5049 * @return Value of the atomic variable as it existed before addition.
    51  *
    5250 */
    53 NO_TRACE static inline atomic_count_t atomic_add(atomic_t *val,
    54     atomic_count_t i)
     51static inline long atomic_add(atomic_t *val, int i)
    5552{
    56         atomic_count_t a;
    57         atomic_count_t b;
    58        
     53        uint64_t a, b;
     54
    5955        do {
    60                 volatile uintptr_t ptr = (uintptr_t) &val->count;
    61                
    62                 a = *((atomic_count_t *) ptr);
     56                volatile uintptr_t x = (uint64_t) &val->count;
     57
     58                a = *((uint64_t *) x);
    6359                b = a + i;
    64                
    65                 asm volatile (
    66                         "casx %0, %2, %1\n"
    67                         : "+m" (*((atomic_count_t *) ptr)),
    68                       "+r" (b)
    69                     : "r" (a)
    70                 );
     60                asm volatile ("casx %0, %2, %1\n" : "+m" (*((uint64_t *)x)),
     61                    "+r" (b) : "r" (a));
    7162        } while (a != b);
    72        
     63
    7364        return a;
    7465}
    7566
    76 NO_TRACE static inline atomic_count_t atomic_preinc(atomic_t *val)
     67static inline long atomic_preinc(atomic_t *val)
    7768{
    7869        return atomic_add(val, 1) + 1;
    7970}
    8071
    81 NO_TRACE static inline atomic_count_t atomic_postinc(atomic_t *val)
     72static inline long atomic_postinc(atomic_t *val)
    8273{
    8374        return atomic_add(val, 1);
    8475}
    8576
    86 NO_TRACE static inline atomic_count_t atomic_predec(atomic_t *val)
     77static inline long atomic_predec(atomic_t *val)
    8778{
    8879        return atomic_add(val, -1) - 1;
    8980}
    9081
    91 NO_TRACE static inline atomic_count_t atomic_postdec(atomic_t *val)
     82static inline long atomic_postdec(atomic_t *val)
    9283{
    9384        return atomic_add(val, -1);
    9485}
    9586
    96 NO_TRACE static inline void atomic_inc(atomic_t *val)
     87static inline void atomic_inc(atomic_t *val)
    9788{
    9889        (void) atomic_add(val, 1);
    9990}
    10091
    101 NO_TRACE static inline void atomic_dec(atomic_t *val)
     92static inline void atomic_dec(atomic_t *val)
    10293{
    10394        (void) atomic_add(val, -1);
    10495}
    10596
    106 NO_TRACE static inline atomic_count_t test_and_set(atomic_t *val)
     97static inline long test_and_set(atomic_t *val)
    10798{
    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        
     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
    118105        return v;
    119106}
    120107
    121 NO_TRACE static inline void atomic_lock_arch(atomic_t *val)
     108static inline void atomic_lock_arch(atomic_t *val)
    122109{
    123         atomic_count_t tmp1 = 1;
    124         atomic_count_t tmp2 = 0;
    125        
    126         volatile uintptr_t ptr = (uintptr_t) &val->count;
    127        
     110        uint64_t tmp1 = 1;
     111        uint64_t tmp2 = 0;
     112
     113        volatile uintptr_t x = (uint64_t) &val->count;
     114
    128115        preemption_disable();
    129        
     116
    130117        asm volatile (
    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)
     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)
    145130        );
    146131       
Note: See TracChangeset for help on using the changeset viewer.