pt-machine.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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, 0 \n"
  37. : "=&a" (tmp)
  38. : "a" (spinlock)
  39. : "memory"
  40. );
  41. return tmp;
  42. }
  43. PT_EI int
  44. __compare_and_swap (long int *p, long int oldval, long int newval)
  45. {
  46. unsigned long tmp;
  47. unsigned long value;
  48. __asm__ volatile (
  49. "1: l32i %0, %2, 0 \n"
  50. " bne %0, %4, 2f \n"
  51. " wsr %0, SCOMPARE1 \n"
  52. " mov %1, %0 \n"
  53. " mov %0, %3 \n"
  54. " s32c1i %0, %2, 0 \n"
  55. " bne %1, %0, 1b \n"
  56. "2: \n"
  57. : "=&a" (tmp), "=&a" (value)
  58. : "a" (p), "a" (newval), "a" (oldval)
  59. : "memory" );
  60. return tmp == oldval;
  61. }
  62. /* Get some notion of the current stack. Need not be exactly the top
  63. of the stack, just something somewhere in the current frame. */
  64. #define CURRENT_STACK_FRAME __builtin_frame_address (0)
  65. #endif /* _PT_MACHINE_H */