1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Author: Qi Hu <huqi@loongson.cn>
4 * Huacai Chen <chenhuacai@loongson.cn>
6 * Copyright (C) 2020-2023 Loongson Technology Corporation Limited
9 #include <asm/asmmacro.h>
10 #include <asm/asm-extable.h>
11 #include <asm/asm-offsets.h>
12 #include <asm/errno.h>
13 #include <asm/regdef.h>
14 #include <asm/unwind_hints.h>
16 #define SCR_REG_WIDTH 8
18 .macro EX insn, reg, src, offs
19 .ex\@: \insn \reg, \src, \offs
20 _asm_extable .ex\@, .L_lbt_fault
24 * Save a thread's lbt context.
26 SYM_FUNC_START(_save_lbt)
27 movscr2gr t1, $scr0 # save scr
28 stptr.d t1, a0, THREAD_SCR0
30 stptr.d t1, a0, THREAD_SCR1
32 stptr.d t1, a0, THREAD_SCR2
34 stptr.d t1, a0, THREAD_SCR3
36 x86mfflag t1, 0x3f # save eflags
37 stptr.d t1, a0, THREAD_EFLAGS
39 SYM_FUNC_END(_save_lbt)
40 EXPORT_SYMBOL(_save_lbt)
43 * Restore a thread's lbt context.
45 SYM_FUNC_START(_restore_lbt)
46 ldptr.d t1, a0, THREAD_SCR0 # restore scr
48 ldptr.d t1, a0, THREAD_SCR1
50 ldptr.d t1, a0, THREAD_SCR2
52 ldptr.d t1, a0, THREAD_SCR3
55 ldptr.d t1, a0, THREAD_EFLAGS # restore eflags
58 SYM_FUNC_END(_restore_lbt)
59 EXPORT_SYMBOL(_restore_lbt)
62 * Load scr/eflag with zero.
64 SYM_FUNC_START(_init_lbt)
72 SYM_FUNC_END(_init_lbt)
78 SYM_FUNC_START(_save_lbt_context)
79 movscr2gr t1, $scr0 # save scr
80 EX st.d t1, a0, (0 * SCR_REG_WIDTH)
82 EX st.d t1, a0, (1 * SCR_REG_WIDTH)
84 EX st.d t1, a0, (2 * SCR_REG_WIDTH)
86 EX st.d t1, a0, (3 * SCR_REG_WIDTH)
88 x86mfflag t1, 0x3f # save eflags
92 SYM_FUNC_END(_save_lbt_context)
98 SYM_FUNC_START(_restore_lbt_context)
99 EX ld.d t1, a0, (0 * SCR_REG_WIDTH) # restore scr
101 EX ld.d t1, a0, (1 * SCR_REG_WIDTH)
103 EX ld.d t1, a0, (2 * SCR_REG_WIDTH)
105 EX ld.d t1, a0, (3 * SCR_REG_WIDTH)
108 EX ld.w t1, a1, 0 # restore eflags
112 SYM_FUNC_END(_restore_lbt_context)
117 SYM_FUNC_START(_save_ftop_context)
122 SYM_FUNC_END(_save_ftop_context)
127 SYM_FUNC_START(_restore_ftop_context)
152 SYM_FUNC_END(_restore_ftop_context)
155 li.w a0, -EFAULT # failure
158 STACK_FRAME_NON_STANDARD _restore_ftop_context