From 7eacd52ff24f41e7fe8806fcdd59d34699302888 Mon Sep 17 00:00:00 2001 From: chuan ran <1414772332@qq.com> Date: Thu, 29 May 2025 03:22:53 +0000 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=B8=80=E4=BA=9B=20los=5Fdi?= =?UTF-8?q?spatch.S=20=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/liteos_m/arch/risc-v/riscv32/gcc/los_dispatch.S | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/kernel/liteos_m/arch/risc-v/riscv32/gcc/los_dispatch.S b/kernel/liteos_m/arch/risc-v/riscv32/gcc/los_dispatch.S index 0f9074fa..70f02d30 100644 --- a/kernel/liteos_m/arch/risc-v/riscv32/gcc/los_dispatch.S +++ b/kernel/liteos_m/arch/risc-v/riscv32/gcc/los_dispatch.S @@ -114,9 +114,12 @@ HalTaskContextSwitch: and a0, a0, a2 // get mie + // a0 中保存着关闭中断之前的mstatus状态,如果中中断中进的这个函数,则mie为0 + // 如果从task中进的这个函数,则mie为1 andi a1, a0, RISCV_MSTATUS_MIE // 0x00000008 // must be in machine mode + // 这里左移4位,把mie的状态保存在mpie中,mret指令将恢复这个状态 ori a1, a1, 0x180 slli a1, a1, 0x4 or a0, a0, a1 @@ -127,7 +130,8 @@ HalTaskContextSwitch: and a0, a0, a2 // a0 清除 mie后的 mstatus SREG a0, 16 * REGBYTES(sp) - // 返回地址 + // 返回地址,把ra地址保存到mepc寄存器中,则mret指令的作用类似于ret + // 区别是mret附带一个是否打开中断的效果 SREG ra, 17 * REGBYTES(sp) la a1, g_losTask @@ -155,7 +159,7 @@ HalStartToRun: // retrieve the registers POP_ALL_REG - + // 如果是从task中调用,这里会打开中断,如果是从中断中调用,这里不会打开中断 mret .section .text