switch_to.h 2.4 KB

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