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 <asm/processor.h>
10 #include <asm/ptrace.h>
14 extern void __fstate_save(struct task_struct *save_to);
15 extern void __fstate_restore(struct task_struct *restore_from);
17 static inline void __fstate_clean(struct pt_regs *regs)
19 regs->sstatus |= (regs->sstatus & ~(SR_FS)) | SR_FS_CLEAN;
22 static inline void fstate_save(struct task_struct *task,
25 if ((regs->sstatus & SR_FS) == SR_FS_DIRTY) {
31 static inline void fstate_restore(struct task_struct *task,
34 if ((regs->sstatus & SR_FS) != SR_FS_OFF) {
35 __fstate_restore(task);
40 static inline void __switch_to_aux(struct task_struct *prev,
41 struct task_struct *next)
45 regs = task_pt_regs(prev);
46 if (unlikely(regs->sstatus & SR_SD))
47 fstate_save(prev, regs);
48 fstate_restore(next, task_pt_regs(next));
54 #define fstate_save(task, regs) do { } while (0)
55 #define fstate_restore(task, regs) do { } while (0)
56 #define __switch_to_aux(__prev, __next) do { } while (0)
59 extern struct task_struct *__switch_to(struct task_struct *,
60 struct task_struct *);
62 #define switch_to(prev, next, last) \
64 struct task_struct *__prev = (prev); \
65 struct task_struct *__next = (next); \
67 __switch_to_aux(__prev, __next); \
68 ((last) = __switch_to(__prev, __next)); \
71 #endif /* _ASM_RISCV_SWITCH_TO_H */