switch_to.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * Copyright (C) 2001 Hiroyuki Kondo, Hirokazu Takata, and Hitoshi Yamamoto
  7. * Copyright (C) 2004, 2006 Hirokazu Takata <takata at linux-m32r.org>
  8. */
  9. #ifndef _ASM_M32R_SWITCH_TO_H
  10. #define _ASM_M32R_SWITCH_TO_H
  11. /*
  12. * switch_to(prev, next) should switch from task `prev' to `next'
  13. * `prev' will never be the same as `next'.
  14. *
  15. * `next' and `prev' should be struct task_struct, but it isn't always defined
  16. */
  17. #if defined(CONFIG_FRAME_POINTER) || \
  18. !defined(CONFIG_SCHED_OMIT_FRAME_POINTER)
  19. #define M32R_PUSH_FP " push fp\n"
  20. #define M32R_POP_FP " pop fp\n"
  21. #else
  22. #define M32R_PUSH_FP ""
  23. #define M32R_POP_FP ""
  24. #endif
  25. #define switch_to(prev, next, last) do { \
  26. __asm__ __volatile__ ( \
  27. " seth lr, #high(1f) \n" \
  28. " or3 lr, lr, #low(1f) \n" \
  29. " st lr, @%4 ; store old LR \n" \
  30. " ld lr, @%5 ; load new LR \n" \
  31. M32R_PUSH_FP \
  32. " st sp, @%2 ; store old SP \n" \
  33. " ld sp, @%3 ; load new SP \n" \
  34. " push %1 ; store `prev' on new stack \n" \
  35. " jmp lr \n" \
  36. " .fillinsn \n" \
  37. "1: \n" \
  38. " pop %0 ; restore `__last' from new stack \n" \
  39. M32R_POP_FP \
  40. : "=r" (last) \
  41. : "0" (prev), \
  42. "r" (&(prev->thread.sp)), "r" (&(next->thread.sp)), \
  43. "r" (&(prev->thread.lr)), "r" (&(next->thread.lr)) \
  44. : "memory", "lr" \
  45. ); \
  46. } while(0)
  47. #endif /* _ASM_M32R_SWITCH_TO_H */