switch_to.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. * Copyright IBM Corp. 1999, 2009
  3. *
  4. * Author(s): Martin Schwidefsky <schwidefsky@de.ibm.com>
  5. */
  6. #ifndef __ASM_SWITCH_TO_H
  7. #define __ASM_SWITCH_TO_H
  8. #include <linux/thread_info.h>
  9. extern struct task_struct *__switch_to(void *, void *);
  10. extern void update_per_regs(struct task_struct *task);
  11. static inline void save_fp_regs(s390_fp_regs *fpregs)
  12. {
  13. asm volatile(
  14. " std 0,%O0+8(%R0)\n"
  15. " std 2,%O0+24(%R0)\n"
  16. " std 4,%O0+40(%R0)\n"
  17. " std 6,%O0+56(%R0)"
  18. : "=Q" (*fpregs) : "Q" (*fpregs));
  19. if (!MACHINE_HAS_IEEE)
  20. return;
  21. asm volatile(
  22. " stfpc %0\n"
  23. " std 1,%O0+16(%R0)\n"
  24. " std 3,%O0+32(%R0)\n"
  25. " std 5,%O0+48(%R0)\n"
  26. " std 7,%O0+64(%R0)\n"
  27. " std 8,%O0+72(%R0)\n"
  28. " std 9,%O0+80(%R0)\n"
  29. " std 10,%O0+88(%R0)\n"
  30. " std 11,%O0+96(%R0)\n"
  31. " std 12,%O0+104(%R0)\n"
  32. " std 13,%O0+112(%R0)\n"
  33. " std 14,%O0+120(%R0)\n"
  34. " std 15,%O0+128(%R0)\n"
  35. : "=Q" (*fpregs) : "Q" (*fpregs));
  36. }
  37. static inline void restore_fp_regs(s390_fp_regs *fpregs)
  38. {
  39. asm volatile(
  40. " ld 0,%O0+8(%R0)\n"
  41. " ld 2,%O0+24(%R0)\n"
  42. " ld 4,%O0+40(%R0)\n"
  43. " ld 6,%O0+56(%R0)"
  44. : : "Q" (*fpregs));
  45. if (!MACHINE_HAS_IEEE)
  46. return;
  47. asm volatile(
  48. " lfpc %0\n"
  49. " ld 1,%O0+16(%R0)\n"
  50. " ld 3,%O0+32(%R0)\n"
  51. " ld 5,%O0+48(%R0)\n"
  52. " ld 7,%O0+64(%R0)\n"
  53. " ld 8,%O0+72(%R0)\n"
  54. " ld 9,%O0+80(%R0)\n"
  55. " ld 10,%O0+88(%R0)\n"
  56. " ld 11,%O0+96(%R0)\n"
  57. " ld 12,%O0+104(%R0)\n"
  58. " ld 13,%O0+112(%R0)\n"
  59. " ld 14,%O0+120(%R0)\n"
  60. " ld 15,%O0+128(%R0)\n"
  61. : : "Q" (*fpregs));
  62. }
  63. static inline void save_access_regs(unsigned int *acrs)
  64. {
  65. asm volatile("stam 0,15,%0" : "=Q" (*acrs));
  66. }
  67. static inline void restore_access_regs(unsigned int *acrs)
  68. {
  69. asm volatile("lam 0,15,%0" : : "Q" (*acrs));
  70. }
  71. #define switch_to(prev,next,last) do { \
  72. if (prev->mm) { \
  73. save_fp_regs(&prev->thread.fp_regs); \
  74. save_access_regs(&prev->thread.acrs[0]); \
  75. } \
  76. if (next->mm) { \
  77. restore_fp_regs(&next->thread.fp_regs); \
  78. restore_access_regs(&next->thread.acrs[0]); \
  79. update_per_regs(next); \
  80. } \
  81. prev = __switch_to(prev,next); \
  82. } while (0)
  83. extern void account_vtime(struct task_struct *, struct task_struct *);
  84. extern void account_tick_vtime(struct task_struct *);
  85. #define finish_arch_switch(prev) do { \
  86. set_fs(current->thread.mm_segment); \
  87. account_vtime(prev, current); \
  88. } while (0)
  89. #endif /* __ASM_SWITCH_TO_H */