pt-machine.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. * Copyright (C) 2016 Andes Technology, Inc.
  3. * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  4. */
  5. /* Machine-dependent pthreads configuration and inline functions.
  6. Copyright (C) 1997, 1998, 2000, 2002, 2003 Free Software Foundation, Inc.
  7. Contributed by Philip Blundell <philb@gnu.org>.
  8. The GNU C Library is free software; you can redistribute it and/or
  9. modify it under the terms of the GNU Lesser General Public License as
  10. published by the Free Software Foundation; either version 2.1 of the
  11. License, or (at your option) any later version.
  12. The GNU C Library is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. Lesser General Public License for more details.
  16. You should have received a copy of the GNU Lesser General Public
  17. License along with the GNU C Library; see the file COPYING.LIB. If not,
  18. write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  19. Boston, MA 02111-1307, USA. */
  20. #ifndef _PT_MACHINE_H
  21. #define _PT_MACHINE_H 1
  22. #include <features.h>
  23. #ifndef PT_EI
  24. # define PT_EI __extern_always_inline
  25. #endif
  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 int val;
  33. unsigned int temp;
  34. unsigned int offset = 0;
  35. __asm__ __volatile__ (
  36. "1:\n\t"
  37. "llw %[val], [%[spinlock] + %[offset] << 0]\n\t"
  38. "move %[temp], #0x1\n\t"
  39. "beq %[val], %[temp], 2f\n\t"
  40. "scw %[temp], [%[spinlock] + %[offset] << 0]\n\t"
  41. "beqz %[temp], 1b\n\t"
  42. "2:\n\t"
  43. : [val] "=&r" (val), [temp] "=&r" (temp)
  44. : [spinlock] "r" (spinlock), [offset] "r" (offset)
  45. : "memory" ) ;
  46. return val ;
  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__ ("$sp");
  52. #endif /* pt-machine.h */