11/*
22 * Copyright (c) 2006-2018, RT-Thread Development Team
3+ * Copyright (c) 2021, Alibaba Group Holding Limited
34 *
45 * SPDX-License-Identifier: Apache-2.0
56 *
67 * Change Logs:
78 * Date Author Notes
89 * 2020/08/20 zx.chen The T-HEAD RISC-V CPU E906 porting implementation
10+ * 2021/08/13 zx.chen update T-HEAD E9xx-series(E906/7/F/D/P) CPU porting code.
911 */
1012
1113#include "cpuport.h"
@@ -29,8 +31,6 @@ vPortYield:
2931
3032 ret
3133
32-
33-
3434/*
3535 * #ifdef RT_USING_SMP
3636 * void rt_hw_context_switch_to(rt_ubase_t to, stuct rt_thread *to_thread);
@@ -56,12 +56,10 @@ rt_hw_context_switch_to:
5656 li t1, 1
5757 STORE t1, (t0)
5858
59- /* enable mexstatus SPUSHEN and SPSWAPEN */
60- #if ((CONFIG_CPU_E906 ==1 ) || (CONFIG_CPU_E906F ==1 ) || (CONFIG_CPU_E906FD ==1 ))
61- uint32_t mexstatus;
62- mexstatus = __get_MEXSTATUS();
63- mexstatus |= (0x2 << 16 );
64- __set_MEXSTATUS(mexstatus);
59+ /* enable mexstatus SPUSHEN */
60+ #ifdef CONFIG_THEAD_EXT_SPUSHEN
61+ li t0, 0x10000
62+ csrs mexstatus, t0
6563#endif
6664
6765 csrw mscratch, sp
@@ -140,7 +138,7 @@ PendSV_Handler:
140138 lw t1, (t0)
141139 beqz t1, .switch_to_thead
142140
143- /* save from thread context */
141+ /* restore from thread context t0,t1 */
144142 lw t0, (-4 )(sp)
145143 lw t1, (-8 )(sp)
146144
@@ -191,10 +189,6 @@ PendSV_Handler:
191189 csrr x1, mepc
192190 STORE x1, 0 * REGBYTES(sp)
193191 csrr x1, mstatus
194- andi x1, x1, 8
195- beqz x1, .save_mpie
196- li x1, 0x80
197- .save_mpie:
198192 STORE x1, 2 * REGBYTES(sp)
199193 /* x3 don't need save */
200194 STORE x4, 4 * REGBYTES(sp)
@@ -256,11 +250,9 @@ PendSV_Handler:
256250 csrw mepc, a1
257251 LOAD x1, 1 * REGBYTES(sp)
258252
259- /* force to machin mode(MPP=11) */
260- li a1, 0x1880
261- csrs mstatus, a1
253+ /* force to machine mode(MPP=11) */
262254 LOAD a1, 2 * REGBYTES(sp)
263- csrs mstatus, a1
255+ csrw mstatus, a1
264256 /* x3 don't need restore */
265257 LOAD x4, 4 * REGBYTES(sp)
266258 LOAD x5, 5 * REGBYTES(sp)
0 commit comments