1/*
2 * Copyright (c) 2021 Andes Technology Corporation
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7#include "soc_v5.h"
8
9#include <zephyr/offsets.h>
10#include <zephyr/toolchain.h>
11
12#ifdef CONFIG_RISCV_SOC_CONTEXT_SAVE
13
14/* Exports */
15GTEXT(__soc_save_context)
16GTEXT(__soc_restore_context)
17
18SECTION_FUNC(exception.other, __soc_save_context)
19
20#ifdef CONFIG_SOC_ANDES_V5_PFT
21	csrr t0, NDS_MXSTATUS
22#endif
23#ifdef CONFIG_SOC_ANDES_V5_HWDSP
24	csrr t1, NDS_UCODE
25#endif
26
27#ifdef CONFIG_SOC_ANDES_V5_PFT
28	sw t0, __soc_esf_t_mxstatus_OFFSET(a0)
29#endif
30#ifdef CONFIG_SOC_ANDES_V5_HWDSP
31	sw t1, __soc_esf_t_ucode_OFFSET(a0)
32#endif
33	ret
34
35SECTION_FUNC(exception.other, __soc_restore_context)
36
37#ifdef CONFIG_SOC_ANDES_V5_PFT
38	lw t0, __soc_esf_t_mxstatus_OFFSET(a0)
39#endif
40#ifdef CONFIG_SOC_ANDES_V5_HWDSP
41	lw t1, __soc_esf_t_ucode_OFFSET(a0)
42#endif
43
44#ifdef CONFIG_SOC_ANDES_V5_PFT
45	csrw NDS_MXSTATUS, t0
46#endif
47#ifdef CONFIG_SOC_ANDES_V5_HWDSP
48	csrw NDS_UCODE, t1
49#endif
50	ret
51
52#endif /* CONFIG_RISCV_SOC_CONTEXT_SAVE */
53