pt-machine.h 999 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /*
  2. * Copyright (C) 2013 Synopsys, Inc. (www.synopsys.com)
  3. *
  4. * Licensed under the LGPL v2.1 or later, see the file COPYING.LIB in this tarball.
  5. */
  6. #ifndef _PT_MACHINE_H
  7. #define _PT_MACHINE_H 1
  8. #include <features.h>
  9. #ifndef PT_EI
  10. # define PT_EI __extern_always_inline
  11. #endif
  12. extern long int testandset (int *spinlock);
  13. extern int __compare_and_swap (long int *p, long int oldval, long int newval);
  14. PT_EI long int
  15. testandset (int *spinlock)
  16. {
  17. unsigned int old = 1;
  18. /* Atomically exchange @spinlock with 1 */
  19. __asm__ __volatile__(
  20. "ex %0, [%1]"
  21. : "+r" (old)
  22. : "r" (spinlock)
  23. : "memory");
  24. return old;
  25. }
  26. /* Get some notion of the current stack. Need not be exactly the top
  27. of the stack, just something somewhere in the current frame.
  28. I don't trust register variables, so let's do this the safe way. */
  29. #define CURRENT_STACK_FRAME \
  30. __extension__ ({ char *__sp; __asm__ ("mov %0,sp" : "=r" (__sp)); __sp; })
  31. #else
  32. #error PT_MACHINE already defined
  33. #endif /* pt-machine.h */