2 * Copyright (C) 2012 Regents of the University of California
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation, version 2.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
14 #ifndef _ASM_RISCV_SWITCH_TO_H
15 #define _ASM_RISCV_SWITCH_TO_H
17 #include <asm/processor.h>
18 #include <asm/ptrace.h>
21 extern void __fstate_save(struct task_struct
*save_to
);
22 extern void __fstate_restore(struct task_struct
*restore_from
);
24 static inline void __fstate_clean(struct pt_regs
*regs
)
26 regs
->sstatus
|= (regs
->sstatus
& ~(SR_FS
)) | SR_FS_CLEAN
;
29 static inline void fstate_save(struct task_struct
*task
,
32 if ((regs
->sstatus
& SR_FS
) == SR_FS_DIRTY
) {
38 static inline void fstate_restore(struct task_struct
*task
,
41 if ((regs
->sstatus
& 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
->sstatus
& SR_SD
))
54 fstate_save(prev
, regs
);
55 fstate_restore(next
, task_pt_regs(next
));
58 extern struct task_struct
*__switch_to(struct task_struct
*,
59 struct task_struct
*);
61 #define switch_to(prev, next, last) \
63 struct task_struct *__prev = (prev); \
64 struct task_struct *__next = (next); \
65 __switch_to_aux(__prev, __next); \
66 ((last) = __switch_to(__prev, __next)); \
69 #endif /* _ASM_RISCV_SWITCH_TO_H */