pt-machine.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /* Machine-dependent pthreads configuration and inline functions.
  2. powerpc version.
  3. Copyright (C) 1996, 1997, 1998 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 Library General Public License as
  7. published by the Free Software Foundation; either version 2 of the
  8. 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. Library General Public License for more details.
  13. You should have received a copy of the GNU Library General Public
  14. License along with the GNU C Library; see the file COPYING.LIB. If
  15. not, write to the Free Software Foundation, Inc.,
  16. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
  17. /* These routines are from Appendix G of the 'PowerPC 601 RISC Microprocessor
  18. User's Manual', by IBM and Motorola. */
  19. #ifndef PT_EI
  20. # define PT_EI extern inline
  21. #endif
  22. /* For multiprocessor systems, we want to ensure all memory accesses
  23. are completed before we reset a lock. */
  24. #if 0
  25. /* on non multiprocessor systems, you can just: */
  26. #define sync() /* nothing */
  27. #else
  28. #define sync() __asm__ __volatile__ ("sync")
  29. #endif
  30. /* Get some notion of the current stack. Need not be exactly the top
  31. of the stack, just something somewhere in the current frame. */
  32. #define CURRENT_STACK_FRAME stack_pointer
  33. register char * stack_pointer __asm__ ("r1");
  34. /* Compare-and-swap for semaphores. */
  35. /* note that test-and-set(x) is the same as compare-and-swap(x, 0, 1) */
  36. #define HAS_COMPARE_AND_SWAP
  37. #if BROKEN_PPC_ASM_CR0
  38. static
  39. #else
  40. PT_EI
  41. #endif
  42. int
  43. __compare_and_swap (long int *p, long int oldval, long int newval)
  44. {
  45. int ret;
  46. sync();
  47. __asm__ __volatile__(
  48. "0: lwarx %0,0,%1 ;"
  49. " xor. %0,%3,%0;"
  50. " bne 1f;"
  51. " stwcx. %2,0,%1;"
  52. " bne- 0b;"
  53. "1: "
  54. : "=&r"(ret)
  55. : "r"(p), "r"(newval), "r"(oldval)
  56. : "cr0", "memory");
  57. sync();
  58. return ret == 0;
  59. }