pt-machine.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /* Machine-dependent pthreads configuration and inline functions.
  2. Copyright (C) 1996, 1997, 1998 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. Contributed by Ralf Baechle <ralf@gnu.ai.mit.edu>.
  5. Based on the Alpha version by Richard Henderson <rth@tamu.edu>.
  6. The GNU C Library is free software; you can redistribute it and/or
  7. modify it under the terms of the GNU Library General Public License as
  8. published by the Free Software Foundation; either version 2 of the
  9. License, or (at your option) any later version.
  10. The GNU C Library is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. Library General Public License for more details.
  14. You should have received a copy of the GNU Library General Public
  15. License along with the GNU C Library; see the file COPYING.LIB. If
  16. not, write to the Free Software Foundation, Inc.,
  17. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  18. TODO: This version makes use of MIPS ISA 2 features. It won't
  19. work on ISA 1. These machines will have to take the overhead of
  20. a sysmips(MIPS_ATOMIC_SET, ...) syscall which isn't implemented
  21. yet correctly. There is however a better solution for R3000
  22. uniprocessor machines possible. */
  23. #ifndef PT_EI
  24. # define PT_EI extern inline
  25. #endif
  26. /* Spinlock implementation; required. */
  27. PT_EI long int
  28. testandset (int *spinlock)
  29. {
  30. long int ret, temp;
  31. __asm__ __volatile__(
  32. "# Inline spinlock test & set\n\t"
  33. ".set\tmips2\n"
  34. "1:\tll\t%0,%3\n\t"
  35. "bnez\t%0,2f\n\t"
  36. ".set\tnoreorder\n\t"
  37. "li\t%1,1\n\t"
  38. ".set\treorder\n\t"
  39. "sc\t%1,%2\n\t"
  40. "beqz\t%1,1b\n"
  41. "2:\t.set\tmips0\n\t"
  42. "/* End spinlock test & set */"
  43. : "=&r"(ret), "=&r" (temp), "=m"(*spinlock)
  44. : "m"(*spinlock)
  45. : "memory");
  46. return ret;
  47. }
  48. /* Get some notion of the current stack. Need not be exactly the top
  49. of the stack, just something somewhere in the current frame. */
  50. #define CURRENT_STACK_FRAME stack_pointer
  51. register char * stack_pointer __asm__ ("$29");
  52. /* Compare-and-swap for semaphores. */
  53. #define HAS_COMPARE_AND_SWAP
  54. PT_EI int
  55. __compare_and_swap (long int *p, long int oldval, long int newval)
  56. {
  57. long ret;
  58. __asm__ __volatile__ (
  59. "/* Inline compare & swap */\n\t"
  60. ".set\tmips2\n"
  61. "1:\tll\t%0,%4\n\t"
  62. ".set\tnoreorder\n\t"
  63. "bne\t%0,%2,2f\n\t"
  64. "move\t%0,%3\n\t"
  65. ".set\treorder\n\t"
  66. "sc\t%0,%1\n\t"
  67. "beqz\t%0,1b\n"
  68. "2:\t.set\tmips0\n\t"
  69. "/* End compare & swap */"
  70. : "=&r"(ret), "=m"(*p)
  71. : "r"(oldval), "r"(newval), "m"(*p));
  72. return ret;
  73. }