switch_to.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright IBM Corp. 1999, 2009
  4. *
  5. * Author(s): Martin Schwidefsky <[email protected]>
  6. */
  7. #ifndef __ASM_SWITCH_TO_H
  8. #define __ASM_SWITCH_TO_H
  9. #include <linux/thread_info.h>
  10. #include <asm/fpu/api.h>
  11. #include <asm/ptrace.h>
  12. #include <asm/guarded_storage.h>
  13. extern struct task_struct *__switch_to(void *, void *);
  14. extern void update_cr_regs(struct task_struct *task);
  15. static inline void save_access_regs(unsigned int *acrs)
  16. {
  17. typedef struct { int _[NUM_ACRS]; } acrstype;
  18. asm volatile("stam 0,15,%0" : "=Q" (*(acrstype *)acrs));
  19. }
  20. static inline void restore_access_regs(unsigned int *acrs)
  21. {
  22. typedef struct { int _[NUM_ACRS]; } acrstype;
  23. asm volatile("lam 0,15,%0" : : "Q" (*(acrstype *)acrs));
  24. }
  25. #define switch_to(prev, next, last) do { \
  26. /* save_fpu_regs() sets the CIF_FPU flag, which enforces \
  27. * a restore of the floating point / vector registers as \
  28. * soon as the next task returns to user space \
  29. */ \
  30. save_fpu_regs(); \
  31. save_access_regs(&prev->thread.acrs[0]); \
  32. save_ri_cb(prev->thread.ri_cb); \
  33. save_gs_cb(prev->thread.gs_cb); \
  34. update_cr_regs(next); \
  35. restore_access_regs(&next->thread.acrs[0]); \
  36. restore_ri_cb(next->thread.ri_cb, prev->thread.ri_cb); \
  37. restore_gs_cb(next->thread.gs_cb); \
  38. prev = __switch_to(prev, next); \
  39. } while (0)
  40. #endif /* __ASM_SWITCH_TO_H */