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