summaryrefslogtreecommitdiff
path: root/cesar/hal/arch/inc/sparc.h
blob: bd501584363871fc2be02e7ecce0c26568a9a38b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#ifndef hal_arch_inc_sparc_h
#define hal_arch_inc_sparc_h
/* Cesar project {{{
 *
 * Copyright (C) 2007 Spidcom
 *
 * <<<Licence>>>
 *
 * }}} */
/**
 * \file    hal/arch/inc/sparc.h
 * \brief   Sparc specific header.
 * \ingroup lib
 */

extern inline int
arch_atomic_add (volatile int *p, int d)
{
    int o, n, t;
    __asm__ ("   ld %[p], %[o]"                 "\n\t"
             "1: add %[o], %[d], %[n]"          "\n\t"
             "   mov %[n], %[t]"                "\n\t"
             "   swap %[p], %[t]"               "\n\t"
             "   subcc %[t], %[o], %[d]"        "\n\t"
             "   bne,a 1b"                      "\n\t"
             "    mov %[n], %[o]"               "\n\t"
             : [p] "=m" (*p), [d] "=r" (d), [o] "=&r" (o), [n] "=&r" (n), [t] "=&r" (t)
             : "1" (d)
            );
    return n;
}

#endif /* hal_arch_inc_sparc_h */