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_off(struct task_struct *task,
25 regs->sstatus = (regs->sstatus & ~SR_FS) | SR_FS_OFF;
28 static inline void fstate_save(struct task_struct *task,
31 if ((regs->sstatus & SR_FS) == SR_FS_DIRTY) {
37 static inline void fstate_restore(struct task_struct *task,
40 if ((regs->sstatus & SR_FS) != SR_FS_OFF) {
41 __fstate_restore(task);
46 static inline void __switch_to_aux(struct task_struct *prev,
47 struct task_struct *next)
51 regs = task_pt_regs(prev);
52 if (unlikely(regs->sstatus & SR_SD))
53 fstate_save(prev, regs);
54 fstate_restore(next, task_pt_regs(next));
60 #define fstate_save(task, regs) do { } while (0)
61 #define fstate_restore(task, regs) do { } while (0)
62 #define __switch_to_aux(__prev, __next) do { } while (0)
65 extern struct task_struct *__switch_to(struct task_struct *,
66 struct task_struct *);
68 #define switch_to(prev, next, last) \
70 struct task_struct *__prev = (prev); \
71 struct task_struct *__next = (next); \
73 __switch_to_aux(__prev, __next); \
74 ((last) = __switch_to(__prev, __next)); \
77 #endif /* _ASM_RISCV_SWITCH_TO_H */