I have to implement set_bit function which should be a atomic operation. I found assembly code for this in linux source. (I'm using sparc) and want to change it to a function that can be used in C program.
static void set_bit(unsigned int nr, unsigned int *addr)
{
// *vec |= 1<<bit; <== original non-atomic C code
//set_bit: /* %o0=nr, %o1=addr */ <== nr is in %o0, addr in %o1 by sparc rule
__asm__ __volatile__ (
"srlx %o0, 6, %g1"
"mov 1, %o2"
"sllx %g1, 3, %g3"
"and %o0, 63, %g2"
"sllx %o2, %g2, %o2"
"add %o1, %g3, %o1"
"1: ldx [%o1], %g7"
"or %g7, %o2, %g1"
"casx [%o1], %g7, %g1"
"cmp %g7, %g1"
"bne,pn %xcc, 2f"
"nop"
"retl"
"nop"
: "=m"(addr) // output
: "m"(nr) // input
: );
Is this correct? Do I have list up all the clobberd registers at the last line?
I'm see error messages below..
../../../../../rtems-4.10.99-src/c/src/libchip/sdmmc/ald-sd-card.c:135:1: error: invalid 'asm': invalid operand output code
__asm__ __volatile__ (
^
../../../../../rtems-4.10.99-src/c/src/libchip/sdmmc/ald-sd-card.c:135:1: error: invalid 'asm': invalid operand output code
../../../../../rtems-4.10.99-src/c/src/libchip/sdmmc/ald-sd-card.c:135:1: error: invalid 'asm': operand number out of range
^