switch_to.h 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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/fpu/api.h>
  10. #include <asm/ptrace.h>
  11. #include <asm/guarded_storage.h>
  12. extern struct task_struct *__switch_to(void *, void *);
  13. extern void update_cr_regs(struct task_struct *task);
  14. static inline void save_access_regs(unsigned int *acrs)
  15. {
  16. typedef struct { int _[NUM_ACRS]; } acrstype;
  17. asm volatile("stam 0,15,%0" : "=Q" (*(acrstype *)acrs));
  18. }
  19. static inline void restore_access_regs(unsigned int *acrs)
  20. {
  21. typedef struct { int _[NUM_ACRS]; } acrstype;
  22. asm volatile("lam 0,15,%0" : : "Q" (*(acrstype *)acrs));
  23. }
  24. #define switch_to(prev,next,last) do { \
  25. if (prev->mm) { \
  26. save_fpu_regs(); \
  27. save_access_regs(&prev->thread.acrs[0]); \
  28. save_ri_cb(prev->thread.ri_cb); \
  29. save_gs_cb(prev->thread.gs_cb); \
  30. } \
  31. if (next->mm) { \
  32. update_cr_regs(next); \
  33. set_cpu_flag(CIF_FPU); \
  34. restore_access_regs(&next->thread.acrs[0]); \
  35. restore_ri_cb(next->thread.ri_cb, prev->thread.ri_cb); \
  36. restore_gs_cb(next->thread.gs_cb); \
  37. } \
  38. prev = __switch_to(prev,next); \
  39. } while (0)
  40. #endif /* __ASM_SWITCH_TO_H */