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>
22 extern void __fstate_save(struct task_struct
*save_to
);
23 extern void __fstate_restore(struct task_struct
*restore_from
);
25 static inline void __fstate_clean(struct pt_regs
*regs
)
27 regs
->sstatus
|= (regs
->sstatus
& ~(SR_FS
)) | SR_FS_CLEAN
;
30 static inline void fstate_save(struct task_struct
*task
,
33 if ((regs
->sstatus
& SR_FS
) == SR_FS_DIRTY
) {
39 static inline void fstate_restore(struct task_struct
*task
,
42 if ((regs
->sstatus
& SR_FS
) != SR_FS_OFF
) {
43 __fstate_restore(task
);
48 static inline void __switch_to_aux(struct task_struct
*prev
,
49 struct task_struct
*next
)
53 regs
= task_pt_regs(prev
);
54 if (unlikely(regs
->sstatus
& SR_SD
))
55 fstate_save(prev
, regs
);
56 fstate_restore(next
, task_pt_regs(next
));
62 #define fstate_save(task, regs) do { } while (0)
63 #define fstate_restore(task, regs) do { } while (0)
64 #define __switch_to_aux(__prev, __next) do { } while (0)
67 extern struct task_struct
*__switch_to(struct task_struct
*,
68 struct task_struct
*);
70 #define switch_to(prev, next, last) \
72 struct task_struct *__prev = (prev); \
73 struct task_struct *__next = (next); \
75 __switch_to_aux(__prev, __next); \
76 ((last) = __switch_to(__prev, __next)); \
79 #endif /* _ASM_RISCV_SWITCH_TO_H */