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>
15 #define SCR_REG_WIDTH 8
17 .macro EX insn, reg, src, offs
18 .ex\@: \insn \reg, \src, \offs
19 _asm_extable .ex\@, .L_lbt_fault
23 * Save a thread's lbt context.
25 SYM_FUNC_START(_save_lbt)
26 movscr2gr t1, $scr0 # save scr
27 stptr.d t1, a0, THREAD_SCR0
29 stptr.d t1, a0, THREAD_SCR1
31 stptr.d t1, a0, THREAD_SCR2
33 stptr.d t1, a0, THREAD_SCR3
35 x86mfflag t1, 0x3f # save eflags
36 stptr.d t1, a0, THREAD_EFLAGS
38 SYM_FUNC_END(_save_lbt)
39 EXPORT_SYMBOL(_save_lbt)
42 * Restore a thread's lbt context.
44 SYM_FUNC_START(_restore_lbt)
45 ldptr.d t1, a0, THREAD_SCR0 # restore scr
47 ldptr.d t1, a0, THREAD_SCR1
49 ldptr.d t1, a0, THREAD_SCR2
51 ldptr.d t1, a0, THREAD_SCR3
54 ldptr.d t1, a0, THREAD_EFLAGS # restore eflags
57 SYM_FUNC_END(_restore_lbt)
58 EXPORT_SYMBOL(_restore_lbt)
61 * Load scr/eflag with zero.
63 SYM_FUNC_START(_init_lbt)
71 SYM_FUNC_END(_init_lbt)
77 SYM_FUNC_START(_save_lbt_context)
78 movscr2gr t1, $scr0 # save scr
79 EX st.d t1, a0, (0 * SCR_REG_WIDTH)
81 EX st.d t1, a0, (1 * SCR_REG_WIDTH)
83 EX st.d t1, a0, (2 * SCR_REG_WIDTH)
85 EX st.d t1, a0, (3 * SCR_REG_WIDTH)
87 x86mfflag t1, 0x3f # save eflags
91 SYM_FUNC_END(_save_lbt_context)
97 SYM_FUNC_START(_restore_lbt_context)
98 EX ld.d t1, a0, (0 * SCR_REG_WIDTH) # restore scr
100 EX ld.d t1, a0, (1 * SCR_REG_WIDTH)
102 EX ld.d t1, a0, (2 * SCR_REG_WIDTH)
104 EX ld.d t1, a0, (3 * SCR_REG_WIDTH)
107 EX ld.w t1, a1, 0 # restore eflags
111 SYM_FUNC_END(_restore_lbt_context)
116 SYM_FUNC_START(_save_ftop_context)
121 SYM_FUNC_END(_save_ftop_context)
126 SYM_FUNC_START(_restore_ftop_context)
151 SYM_FUNC_END(_restore_ftop_context)
154 li.w a0, -EFAULT # failure