2 * Copyright IBM Corp. 1999, 2009
4 * Author(s): Martin Schwidefsky <schwidefsky@de.ibm.com>
7 #ifndef __ASM_SWITCH_TO_H
8 #define __ASM_SWITCH_TO_H
10 #include <linux/thread_info.h>
11 #include <asm/ptrace.h>
13 extern struct task_struct
*__switch_to(void *, void *);
14 extern void update_cr_regs(struct task_struct
*task
);
16 static inline int test_fp_ctl(u32 fpc
)
21 if (!MACHINE_HAS_IEEE
)
31 : "=d" (rc
), "=d" (orig_fpc
)
32 : "d" (fpc
), "0" (-EINVAL
));
36 static inline void save_fp_ctl(u32
*fpc
)
38 if (!MACHINE_HAS_IEEE
)
46 static inline int restore_fp_ctl(u32
*fpc
)
50 if (!MACHINE_HAS_IEEE
)
58 : "=d" (rc
) : "Q" (*fpc
), "0" (-EINVAL
));
62 static inline void save_fp_regs(freg_t
*fprs
)
64 asm volatile("std 0,%0" : "=Q" (fprs
[0]));
65 asm volatile("std 2,%0" : "=Q" (fprs
[2]));
66 asm volatile("std 4,%0" : "=Q" (fprs
[4]));
67 asm volatile("std 6,%0" : "=Q" (fprs
[6]));
68 if (!MACHINE_HAS_IEEE
)
70 asm volatile("std 1,%0" : "=Q" (fprs
[1]));
71 asm volatile("std 3,%0" : "=Q" (fprs
[3]));
72 asm volatile("std 5,%0" : "=Q" (fprs
[5]));
73 asm volatile("std 7,%0" : "=Q" (fprs
[7]));
74 asm volatile("std 8,%0" : "=Q" (fprs
[8]));
75 asm volatile("std 9,%0" : "=Q" (fprs
[9]));
76 asm volatile("std 10,%0" : "=Q" (fprs
[10]));
77 asm volatile("std 11,%0" : "=Q" (fprs
[11]));
78 asm volatile("std 12,%0" : "=Q" (fprs
[12]));
79 asm volatile("std 13,%0" : "=Q" (fprs
[13]));
80 asm volatile("std 14,%0" : "=Q" (fprs
[14]));
81 asm volatile("std 15,%0" : "=Q" (fprs
[15]));
84 static inline void restore_fp_regs(freg_t
*fprs
)
86 asm volatile("ld 0,%0" : : "Q" (fprs
[0]));
87 asm volatile("ld 2,%0" : : "Q" (fprs
[2]));
88 asm volatile("ld 4,%0" : : "Q" (fprs
[4]));
89 asm volatile("ld 6,%0" : : "Q" (fprs
[6]));
90 if (!MACHINE_HAS_IEEE
)
92 asm volatile("ld 1,%0" : : "Q" (fprs
[1]));
93 asm volatile("ld 3,%0" : : "Q" (fprs
[3]));
94 asm volatile("ld 5,%0" : : "Q" (fprs
[5]));
95 asm volatile("ld 7,%0" : : "Q" (fprs
[7]));
96 asm volatile("ld 8,%0" : : "Q" (fprs
[8]));
97 asm volatile("ld 9,%0" : : "Q" (fprs
[9]));
98 asm volatile("ld 10,%0" : : "Q" (fprs
[10]));
99 asm volatile("ld 11,%0" : : "Q" (fprs
[11]));
100 asm volatile("ld 12,%0" : : "Q" (fprs
[12]));
101 asm volatile("ld 13,%0" : : "Q" (fprs
[13]));
102 asm volatile("ld 14,%0" : : "Q" (fprs
[14]));
103 asm volatile("ld 15,%0" : : "Q" (fprs
[15]));
106 static inline void save_vx_regs(__vector128
*vxrs
)
108 typedef struct { __vector128 _
[__NUM_VXRS
]; } addrtype
;
112 " .word 0xe70f,0x1000,0x003e\n" /* vstm 0,15,0(1) */
113 " .word 0xe70f,0x1100,0x0c3e\n" /* vstm 16,31,256(1) */
114 : "=Q" (*(addrtype
*) vxrs
) : : "1");
117 static inline void save_vx_regs_safe(__vector128
*vxrs
)
119 unsigned long cr0
, flags
;
121 flags
= arch_local_irq_save();
122 __ctl_store(cr0
, 0, 0);
123 __ctl_set_bit(0, 17);
124 __ctl_set_bit(0, 18);
126 __ctl_load(cr0
, 0, 0);
127 arch_local_irq_restore(flags
);
130 static inline void restore_vx_regs(__vector128
*vxrs
)
132 typedef struct { __vector128 _
[__NUM_VXRS
]; } addrtype
;
136 " .word 0xe70f,0x1000,0x0036\n" /* vlm 0,15,0(1) */
137 " .word 0xe70f,0x1100,0x0c36\n" /* vlm 16,31,256(1) */
138 : : "Q" (*(addrtype
*) vxrs
) : "1");
141 static inline void save_fp_vx_regs(struct task_struct
*task
)
144 if (task
->thread
.vxrs
)
145 save_vx_regs(task
->thread
.vxrs
);
148 save_fp_regs(task
->thread
.fp_regs
.fprs
);
151 static inline void restore_fp_vx_regs(struct task_struct
*task
)
154 if (task
->thread
.vxrs
)
155 restore_vx_regs(task
->thread
.vxrs
);
158 restore_fp_regs(task
->thread
.fp_regs
.fprs
);
161 static inline void save_access_regs(unsigned int *acrs
)
163 typedef struct { int _
[NUM_ACRS
]; } acrstype
;
165 asm volatile("stam 0,15,%0" : "=Q" (*(acrstype
*)acrs
));
168 static inline void restore_access_regs(unsigned int *acrs
)
170 typedef struct { int _
[NUM_ACRS
]; } acrstype
;
172 asm volatile("lam 0,15,%0" : : "Q" (*(acrstype
*)acrs
));
175 #define switch_to(prev,next,last) do { \
177 save_fp_ctl(&prev->thread.fp_regs.fpc); \
178 save_fp_vx_regs(prev); \
179 save_access_regs(&prev->thread.acrs[0]); \
180 save_ri_cb(prev->thread.ri_cb); \
183 update_cr_regs(next); \
184 restore_fp_ctl(&next->thread.fp_regs.fpc); \
185 restore_fp_vx_regs(next); \
186 restore_access_regs(&next->thread.acrs[0]); \
187 restore_ri_cb(next->thread.ri_cb, prev->thread.ri_cb); \
189 prev = __switch_to(prev,next); \
192 #endif /* __ASM_SWITCH_TO_H */