pt-machine.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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, write to the Free
  15. Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
  16. Boston, MA 02110-1301, USA. */
  17. #ifndef _PT_MACHINE_H
  18. #define _PT_MACHINE_H 1
  19. #include <sys/syscall.h>
  20. #include <asm/unistd.h>
  21. #ifndef PT_EI
  22. # define PT_EI extern inline __attribute__ ((gnu_inline))
  23. #endif
  24. #define MEMORY_BARRIER() __asm__ ("memw" : : : "memory")
  25. #define HAS_COMPARE_AND_SWAP
  26. extern long int testandset (int *spinlock);
  27. extern int __compare_and_swap (long int *p, long int oldval, long int newval);
  28. /* Spinlock implementation; required. */
  29. PT_EI long int
  30. testandset (int *spinlock)
  31. {
  32. unsigned long tmp;
  33. __asm__ volatile (
  34. " movi %0, 0 \n"
  35. " wsr %0, SCOMPARE1 \n"
  36. " movi %0, 1 \n"
  37. " s32c1i %0, %1, 0 \n"
  38. : "=&a" (tmp)
  39. : "a" (spinlock)
  40. : "memory"
  41. );
  42. return tmp;
  43. }
  44. PT_EI int
  45. __compare_and_swap (long int *p, long int oldval, long int newval)
  46. {
  47. unsigned long tmp;
  48. unsigned long value;
  49. __asm__ volatile (
  50. "1: l32i %0, %2, 0 \n"
  51. " bne %0, %4, 2f \n"
  52. " wsr %0, SCOMPARE1 \n"
  53. " mov %1, %0 \n"
  54. " mov %0, %3 \n"
  55. " s32c1i %0, %2, 0 \n"
  56. " bne %1, %0, 1b \n"
  57. "2: \n"
  58. : "=&a" (tmp), "=&a" (value)
  59. : "a" (p), "a" (newval), "a" (oldval)
  60. : "memory" );
  61. return tmp == oldval;
  62. }
  63. /* Get some notion of the current stack. Need not be exactly the top
  64. of the stack, just something somewhere in the current frame. */
  65. #define CURRENT_STACK_FRAME __builtin_frame_address (0)
  66. #endif /* _PT_MACHINE_H */