pt-machine.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * sysdeps/microblaze/pt-machine.h -- microblaze-specific pthread definitions
  3. *
  4. * Copyright (C) 2003 John Williams <jwilliams@itee.uq.edu.au>
  5. * Copyright (C) 2002 NEC Electronics Corporation
  6. * Copyright (C) 2002 Miles Bader <miles@gnu.org>
  7. *
  8. * This file is subject to the terms and conditions of the GNU Lesser
  9. * General Public License. See the file COPYING.LIB in the main
  10. * directory of this archive for more details.
  11. *
  12. */
  13. #ifndef _PT_MACHINE_H
  14. #define _PT_MACHINE_H 1
  15. #include <features.h>
  16. #ifndef PT_EI
  17. # define PT_EI __extern_always_inline
  18. #endif
  19. /* Get some notion of the current stack. Need not be exactly the top
  20. of the stack, just something somewhere in the current frame. */
  21. #define CURRENT_STACK_FRAME __stack_pointer
  22. register char *__stack_pointer __asm__ ("r1");
  23. #define HAS_COMPARE_AND_SWAP
  24. #define HAS_COMPARE_AND_SWAP_WITH_RELEASE_SEMANTICS
  25. #define MEMORY_BARRIER() __asm__ __volatile__("": : :"memory")
  26. /* Atomically: If *PTR == OLD, set *PTR to NEW and return true,
  27. otherwise do nothing and return false. */
  28. PT_EI int __compare_and_swap (long *ptr, long old, long new)
  29. {
  30. long prev, cmp, retval;
  31. __asm__ __volatile__ (" addi %2, r0, 0;"
  32. "1: lwx %0, %3, r0;"
  33. " cmp %1, %0, %4;"
  34. " bnei %1, 2f;"
  35. " swx %5, %3, r0;"
  36. " addic %1, r0, 0;"
  37. " bnei %1, 1b;"
  38. " addi %2, r0, 1;"
  39. "2:"
  40. : "=&r" (prev), "=&r" (cmp), "=&r" (retval)
  41. : "r" (ptr), "r" (old), "r" (new)
  42. : "cc", "memory");
  43. return retval;
  44. }
  45. PT_EI int
  46. __compare_and_swap_with_release_semantics (long *p,
  47. long oldval, long newval)
  48. {
  49. MEMORY_BARRIER();
  50. return __compare_and_swap (p, oldval, newval);
  51. }
  52. /* Spinlock implementation; required. */
  53. PT_EI long int testandset (int *spinlock)
  54. {
  55. long int retval;
  56. __asm__ __volatile__ ("1: lwx %0, %1, r0;"
  57. " bnei %0, 2f;"
  58. " addik %0, r0, 1;"
  59. " swx %0, %1, r0;"
  60. " addic %0, r0, 0;"
  61. " bnei %0, 1b;"
  62. "2:"
  63. : "=&r" (retval)
  64. : "r" (spinlock)
  65. : "cc", "memory");
  66. return retval;
  67. }
  68. #endif /* pt-machine.h */