pt-machine.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /* Machine-dependent pthreads configuration and inline functions.
  2. Xtensa version.
  3. Copyright (C) 2007 Free Software Foundation, Inc.
  4. This file is part of the GNU C Library.
  5. The GNU C Library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Lesser General Public
  7. License as published by the Free Software Foundation; either
  8. version 2.1 of the License, or (at your option) any later version.
  9. The GNU C Library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public
  14. License along with the GNU C Library; if not, see
  15. <http://www.gnu.org/licenses/>. */
  16. #ifndef _PT_MACHINE_H
  17. #define _PT_MACHINE_H 1
  18. #include <sys/syscall.h>
  19. #include <asm/unistd.h>
  20. #ifndef PT_EI
  21. # define PT_EI extern inline __attribute__ ((gnu_inline))
  22. #endif
  23. #define MEMORY_BARRIER() __asm__ ("memw" : : : "memory")
  24. #define HAS_COMPARE_AND_SWAP
  25. extern long int testandset (int *spinlock);
  26. extern int __compare_and_swap (long int *p, long int oldval, long int newval);
  27. /* Spinlock implementation; required. */
  28. PT_EI long int
  29. testandset (int *spinlock)
  30. {
  31. unsigned long tmp;
  32. __asm__ volatile (
  33. " movi %0, 0 \n"
  34. " wsr %0, SCOMPARE1 \n"
  35. " movi %0, 1 \n"
  36. " s32c1i %0, %1 \n"
  37. : "=&a" (tmp), "+m" (*spinlock)
  38. :: "memory"
  39. );
  40. return tmp;
  41. }
  42. PT_EI int
  43. __compare_and_swap (long int *p, long int oldval, long int newval)
  44. {
  45. unsigned long tmp;
  46. unsigned long value;
  47. __asm__ volatile (
  48. "1: l32i %0, %2 \n"
  49. " bne %0, %4, 2f \n"
  50. " wsr %0, SCOMPARE1 \n"
  51. " mov %1, %0 \n"
  52. " mov %0, %3 \n"
  53. " s32c1i %0, %2 \n"
  54. " bne %1, %0, 1b \n"
  55. "2: \n"
  56. : "=&a" (tmp), "=&a" (value), "+m" (*p)
  57. : "a" (newval), "a" (oldval)
  58. : "memory" );
  59. return tmp == oldval;
  60. }
  61. /* Get some notion of the current stack. Need not be exactly the top
  62. of the stack, just something somewhere in the current frame. */
  63. #define CURRENT_STACK_FRAME __builtin_frame_address (0)
  64. #endif /* _PT_MACHINE_H */