[U-Boot] [PATCH 18/19] riscv: Refactor handle_trap() a little for future extension

Bin Meng bmeng.cn at gmail.com
Tue Nov 13 08:22:06 UTC 2018


Use a variable 'code' to store the exception code to simplify the
codes in handle_trap().

Signed-off-by: Bin Meng <bmeng.cn at gmail.com>
---

 arch/riscv/lib/interrupts.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/arch/riscv/lib/interrupts.c b/arch/riscv/lib/interrupts.c
index 5e09196..0c13588 100644
--- a/arch/riscv/lib/interrupts.c
+++ b/arch/riscv/lib/interrupts.c
@@ -66,14 +66,18 @@ int disable_interrupts(void)
 ulong handle_trap(ulong mcause, ulong epc, struct pt_regs *regs)
 {
 	ulong is_int;
+	ulong code;
 
 	is_int = (mcause & MCAUSE_INT);
-	if ((is_int) && ((mcause & MCAUSE_CAUSE)  == IRQ_M_EXT))
-		external_interrupt(0);	/* handle_m_ext_interrupt */
-	else if ((is_int) && ((mcause & MCAUSE_CAUSE)  == IRQ_M_TIMER))
-		timer_interrupt(0);	/* handle_m_timer_interrupt */
-	else
-		_exit_trap(mcause & MCAUSE_CAUSE, epc, regs);
+	code = mcause & MCAUSE_CAUSE;
+	if (is_int) {
+		if (code == IRQ_M_EXT)
+			external_interrupt(0);	/* handle_m_ext_interrupt */
+		else if (code == IRQ_M_TIMER)
+			timer_interrupt(0);	/* handle_m_timer_interrupt */
+	} else {
+		_exit_trap(code, epc, regs);
+	}
 
 	return epc;
 }
-- 
2.7.4



More information about the U-Boot mailing list