blob: dcadfde32265ad705a3899ef1584f858ae3af704 [file] [log] [blame]
David Howellsa0616cd2012-03-28 18:30:02 +01001/*
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>
Hendrik Brueckner904818e2015-06-11 15:33:54 +020011#include <asm/fpu-internal.h>
Heiko Carstensbee5c282013-08-20 10:24:12 +020012#include <asm/ptrace.h>
David Howellsa0616cd2012-03-28 18:30:02 +010013
14extern struct task_struct *__switch_to(void *, void *);
Michael Mueller64597f92013-07-02 22:58:26 +020015extern void update_cr_regs(struct task_struct *task);
David Howellsa0616cd2012-03-28 18:30:02 +010016
David Howellsa0616cd2012-03-28 18:30:02 +010017static inline void save_access_regs(unsigned int *acrs)
18{
Heiko Carstensbee5c282013-08-20 10:24:12 +020019 typedef struct { int _[NUM_ACRS]; } acrstype;
20
21 asm volatile("stam 0,15,%0" : "=Q" (*(acrstype *)acrs));
David Howellsa0616cd2012-03-28 18:30:02 +010022}
23
24static inline void restore_access_regs(unsigned int *acrs)
25{
Heiko Carstensbee5c282013-08-20 10:24:12 +020026 typedef struct { int _[NUM_ACRS]; } acrstype;
27
28 asm volatile("lam 0,15,%0" : : "Q" (*(acrstype *)acrs));
David Howellsa0616cd2012-03-28 18:30:02 +010029}
30
31#define switch_to(prev,next,last) do { \
32 if (prev->mm) { \
Hendrik Bruecknerd0164ee2015-06-29 16:43:06 +020033 save_fpu_regs(); \
David Howellsa0616cd2012-03-28 18:30:02 +010034 save_access_regs(&prev->thread.acrs[0]); \
Jan Glaubere4b8b3f2012-07-31 10:52:05 +020035 save_ri_cb(prev->thread.ri_cb); \
David Howellsa0616cd2012-03-28 18:30:02 +010036 } \
37 if (next->mm) { \
Martin Schwidefsky80703612014-10-06 17:53:53 +020038 update_cr_regs(next); \
Hendrik Brueckner9977e882015-06-10 12:53:42 +020039 set_cpu_flag(CIF_FPU); \
David Howellsa0616cd2012-03-28 18:30:02 +010040 restore_access_regs(&next->thread.acrs[0]); \
Jan Glaubere4b8b3f2012-07-31 10:52:05 +020041 restore_ri_cb(next->thread.ri_cb, prev->thread.ri_cb); \
David Howellsa0616cd2012-03-28 18:30:02 +010042 } \
43 prev = __switch_to(prev,next); \
44} while (0)
45
David Howellsa0616cd2012-03-28 18:30:02 +010046#endif /* __ASM_SWITCH_TO_H */