switch_to.h 1.1 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
/*
 * Copyright IBM Corp. 1999, 2009
 *
 * Author(s): Martin Schwidefsky <schwidefsky@de.ibm.com>
 */

#ifndef __ASM_SWITCH_TO_H
#define __ASM_SWITCH_TO_H

#include <linux/thread_info.h>
11
#include <asm/fpu-internal.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 18

static inline void save_access_regs(unsigned int *acrs)
{
19 20 21
	typedef struct { int _[NUM_ACRS]; } acrstype;

	asm volatile("stam 0,15,%0" : "=Q" (*(acrstype *)acrs));
22 23 24 25
}

static inline void restore_access_regs(unsigned int *acrs)
{
26 27 28
	typedef struct { int _[NUM_ACRS]; } acrstype;

	asm volatile("lam 0,15,%0" : : "Q" (*(acrstype *)acrs));
29 30 31 32
}

#define switch_to(prev,next,last) do {					\
	if (prev->mm) {							\
33
		save_fpu_regs();					\
34
		save_access_regs(&prev->thread.acrs[0]);		\
35
		save_ri_cb(prev->thread.ri_cb);				\
36 37
	}								\
	if (next->mm) {							\
38
		update_cr_regs(next);					\
39
		set_cpu_flag(CIF_FPU);					\
40
		restore_access_regs(&next->thread.acrs[0]);		\
41
		restore_ri_cb(next->thread.ri_cb, prev->thread.ri_cb);	\
42 43 44 45 46
	}								\
	prev = __switch_to(prev,next);					\
} while (0)

#endif /* __ASM_SWITCH_TO_H */