From: Bin Meng Date: Tue, 13 Nov 2018 00:22:06 -0800 Subject: [U-Boot] [PATCH 18/19] riscv: Refactor handle_trap() a little for future extension In-Reply-To: <1542097327-6629-1-git-send-email-bmeng.cn@gmail.com> References: <1542097327-6629-1-git-send-email-bmeng.cn@gmail.com> Message-ID: <1542097327-6629-19-git-send-email-bmeng.cn@gmail.com> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de Use a variable 'code' to store the exception code to simplify the codes in handle_trap(). Signed-off-by: Bin Meng --- 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