1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- #ifndef _PT_MACHINE_H
- #define _PT_MACHINE_H 1
- #include <features.h>
- #ifndef PT_EI
- # define PT_EI __extern_always_inline
- #endif
- #define CURRENT_STACK_FRAME __stack_pointer
- register char *__stack_pointer __asm__ ("r1");
- #define HAS_COMPARE_AND_SWAP
- #define HAS_COMPARE_AND_SWAP_WITH_RELEASE_SEMANTICS
- #define MEMORY_BARRIER() __asm__ __volatile__("": : :"memory")
- PT_EI int __compare_and_swap (long *ptr, long old, long new)
- {
- long prev, cmp, retval;
- __asm__ __volatile__ (" addi %2, r0, 0;"
- "1: lwx %0, %3, r0;"
- " cmp %1, %0, %4;"
- " bnei %1, 2f;"
- " swx %5, %3, r0;"
- " addic %1, r0, 0;"
- " bnei %1, 1b;"
- " addi %2, r0, 1;"
- "2:"
- : "=&r" (prev), "=&r" (cmp), "=&r" (retval)
- : "r" (ptr), "r" (old), "r" (new)
- : "cc", "memory");
- return retval;
- }
- PT_EI int
- __compare_and_swap_with_release_semantics (long *p,
- long oldval, long newval)
- {
- MEMORY_BARRIER();
- return __compare_and_swap (p, oldval, newval);
- }
-
- PT_EI long int testandset (int *spinlock)
- {
- long int retval;
- __asm__ __volatile__ ("1: lwx %0, %1, r0;"
- " bnei %0, 2f;"
- " addik %0, r0, 1;"
- " swx %0, %1, r0;"
- " addic %0, r0, 0;"
- " bnei %0, 1b;"
- "2:"
- : "=&r" (retval)
- : "r" (spinlock)
- : "cc", "memory");
- return retval;
- }
- #endif
|