411-libpthread-avr32.patch 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. Subject: [PATCH] libpthread: AVR32 support
  2. Implement pt-machine.h for AVR32.
  3. ---
  4. libpthread/linuxthreads/sysdeps/avr32/pt-machine.h | 92 +++++++++++++++++++++
  5. 1 file changed, 92 insertions(+)
  6. Index: uClibc-0.9.28/libpthread/linuxthreads/sysdeps/avr32/pt-machine.h
  7. ===================================================================
  8. --- /dev/null 1970-01-01 00:00:00.000000000 +0000
  9. +++ uClibc-0.9.28/libpthread/linuxthreads/sysdeps/avr32/pt-machine.h 2006-02-07 17:14:47.000000000 +0100
  10. @@ -0,0 +1,92 @@
  11. +/* Machine-dependent pthreads configuration and inline functions.
  12. +
  13. + Copyright (C) 2005 Atmel Norway
  14. + This file is part of the GNU C Library.
  15. +
  16. + The GNU C Library is free software; you can redistribute it and/or
  17. + modify it under the terms of the GNU Lesser General Public License as
  18. + published by the Free Software Foundation; either version 2.1 of the
  19. + License, or (at your option) any later version.
  20. +
  21. + The GNU C Library is distributed in the hope that it will be useful,
  22. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  24. + Lesser General Public License for more details.
  25. +
  26. + You should have received a copy of the GNU Lesser General Public
  27. + License along with the GNU C Library; see the file COPYING.LIB. If not,
  28. + write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  29. + Boston, MA 02111-1307, USA. */
  30. +
  31. +#ifndef _PT_MACHINE_H
  32. +#define _PT_MACHINE_H 1
  33. +
  34. +#include <features.h>
  35. +
  36. +static inline int
  37. +_test_and_set (int *p, int v) __THROW
  38. +{
  39. + int result;
  40. +
  41. + __asm__ __volatile__(
  42. + "/* Inline test and set */\n"
  43. + "1: ssrf 5\n"
  44. + " ld.w %0, %2\n"
  45. + " tst %0, %3\n"
  46. + " breq 2f\n"
  47. + " stcond %1, %3\n"
  48. + " brne 1b\n"
  49. + "2:"
  50. + : "=&r"(result), "=m"(*p)
  51. + : "m"(*p), "r"(v)
  52. + : "memory", "cc");
  53. +
  54. + return result;
  55. +}
  56. +
  57. +#ifndef PT_EI
  58. +# define PT_EI extern inline
  59. +#endif
  60. +
  61. +extern long int testandset (int *spinlock);
  62. +extern int __compare_and_swap (long int *p, long int oldval, long int newval);
  63. +
  64. +/* Spinlock implementation; required. */
  65. +PT_EI long int
  66. +testandset (int *spinlock)
  67. +{
  68. + return _test_and_set(spinlock, 1);
  69. +}
  70. +
  71. +
  72. +/* Get some notion of the current stack. Need not be exactly the top
  73. + of the stack, just something somewhere in the current frame. */
  74. +#define CURRENT_STACK_FRAME stack_pointer
  75. +register char * stack_pointer __asm__ ("sp");
  76. +
  77. +/* Compare-and-swap for semaphores. */
  78. +
  79. +#define HAS_COMPARE_AND_SWAP
  80. +PT_EI int
  81. +__compare_and_swap(long int *p, long int oldval, long int newval)
  82. +{
  83. + long int result, tmp;
  84. +
  85. + __asm__ __volatile__(
  86. + "/* Inline compare and swap */\n"
  87. + "1: ssrf 5\n"
  88. + " ld.w %1, %3\n"
  89. + " cp.w %1, %5\n"
  90. + " sreq %0\n"
  91. + " brne 2f\n"
  92. + " stcond %2, %4\n"
  93. + " brne 1b\n"
  94. + "2:"
  95. + : "=&r"(result), "=&r"(tmp), "=m"(*p)
  96. + : "m"(*p), "r"(newval), "r"(oldval)
  97. + : "cc", "memory");
  98. +
  99. + return result;
  100. +}
  101. +
  102. +#endif /* pt-machine.h */