1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Copyright (C) 2012 Regents of the University of California
6 #ifndef _ASM_RISCV_SWITCH_TO_H
7 #define _ASM_RISCV_SWITCH_TO_H
9 #include <linux/sched/task_stack.h>
10 #include <asm/processor.h>
11 #include <asm/ptrace.h>
15 extern void __fstate_save(struct task_struct
*save_to
);
16 extern void __fstate_restore(struct task_struct
*restore_from
);
18 static inline void __fstate_clean(struct pt_regs
*regs
)
20 regs
->status
= (regs
->status
& ~SR_FS
) | SR_FS_CLEAN
;
23 static inline void fstate_off(struct task_struct
*task
,
26 regs
->status
= (regs
->status
& ~SR_FS
) | SR_FS_OFF
;
29 static inline void fstate_save(struct task_struct
*task
,
32 if ((regs
->status
& SR_FS
) == SR_FS_DIRTY
) {
38 static inline void fstate_restore(struct task_struct
*task
,
41 if ((regs
->status
& SR_FS
) != SR_FS_OFF
) {
42 __fstate_restore(task
);
47 static inline void __switch_to_aux(struct task_struct
*prev
,
48 struct task_struct
*next
)
52 regs
= task_pt_regs(prev
);
53 if (unlikely(regs
->status
& SR_SD
))
54 fstate_save(prev
, regs
);
55 fstate_restore(next
, task_pt_regs(next
));
61 #define fstate_save(task, regs) do { } while (0)
62 #define fstate_restore(task, regs) do { } while (0)
63 #define __switch_to_aux(__prev, __next) do { } while (0)
66 extern struct task_struct
*__switch_to(struct task_struct
*,
67 struct task_struct
*);
69 #define switch_to(prev, next, last) \
71 struct task_struct *__prev = (prev); \
72 struct task_struct *__next = (next); \
74 __switch_to_aux(__prev, __next); \
75 ((last) = __switch_to(__prev, __next)); \
78 #endif /* _ASM_RISCV_SWITCH_TO_H */