Skip to content

Commit

Permalink
[AVR32] Don't use __builtin_xchg()
Browse files Browse the repository at this point in the history
The implementation of __builtin_xchg() in at least some versions of
avr32 gcc is buggy. Rather than find out exactly which versions that
have this bug, let's just avoid the problem altogether by implementing
xchg() in inline assembly.

Also, in most architectures, xchg() seems to imply a memory barrier,
while the existing avr32 implementation did not. This patch also fixes
that discrepancy.

Signed-off-by: Haavard Skinnemoen <hskinnemoen@atmel.com>
  • Loading branch information
Haavard Skinnemoen committed Oct 11, 2007
1 parent 82c54f8 commit bb7aa6d
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions include/asm-avr32/system.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,16 @@ extern struct task_struct *__switch_to(struct task_struct *,

extern void __xchg_called_with_bad_pointer(void);

#ifdef __CHECKER__
extern unsigned long __builtin_xchg(void *ptr, unsigned long x);
#endif
static inline unsigned long xchg_u32(u32 val, volatile u32 *m)
{
u32 ret;

#define xchg_u32(val, m) __builtin_xchg((void *)m, val)
asm volatile("xchg %[ret], %[m], %[val]"
: [ret] "=&r"(ret), "=m"(*m)
: "m"(*m), [m] "r"(m), [val] "r"(val)
: "memory");
return ret;
}

static inline unsigned long __xchg(unsigned long x,
volatile void *ptr,
Expand Down

0 comments on commit bb7aa6d

Please sign in to comment.