MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / handle_trap

Function handle_trap

libcpu/risc-v/common64/trap.c:295–386  ·  view source on GitHub ↗

Trap entry */

Source from the content-addressed store, hash-verified

293
294/* Trap entry */
295void handle_trap(rt_ubase_t scause, rt_ubase_t stval, rt_ubase_t sepc,
296 struct rt_hw_stack_frame *sp)
297{
298 ENTER_TRAP;
299 rt_ubase_t id = __MASKVALUE(scause, __MASK(63UL));
300 const char *msg;
301
302 /* supervisor external interrupt */
303 if ((SCAUSE_INTERRUPT & scause) &&
304 SCAUSE_S_EXTERNAL_INTR == (scause & 0xff))
305 {
306 rt_interrupt_enter();
307 plic_handle_irq();
308 rt_interrupt_leave();
309 }
310 else if ((SCAUSE_INTERRUPT | SCAUSE_S_TIMER_INTR) == scause)
311 {
312 /* supervisor timer */
313 rt_interrupt_enter();
314 tick_isr();
315 rt_interrupt_leave();
316 }
317 else
318 {
319 if (SCAUSE_INTERRUPT & scause)
320 {
321 if (id < sizeof(Interrupt_Name) / sizeof(const char *))
322 {
323 msg = Interrupt_Name[id];
324 }
325 else
326 {
327 msg = "Unknown Interrupt";
328 }
329
330 LOG_E("Unhandled Interrupt %ld:%s\n", id, msg);
331 }
332 else
333 {
334#ifdef ARCH_RISCV_VECTOR
335 if (scause == 0x2)
336 {
337 if (!(sp->sstatus & SSTATUS_VS) &&
338 illegal_inst_recoverable(stval, sp))
339 goto _exit;
340 }
341#endif /* ARCH_RISCV_VECTOR */
342#ifdef RT_USING_SMART
343 if (!(sp->sstatus & 0x100) || (PAGE_FAULT && IN_USER_SPACE))
344 {
345 handle_user(scause, stval, sepc, sp);
346 // if handle_user() return here, jump to u mode then
347 goto _exit;
348 }
349#endif
350
351 // handle kernel exception:
352 rt_kprintf("Unhandled Exception %ld:%s\n", id,

Callers

nothing calls this directly

Calls 12

illegal_inst_recoverableFunction · 0.85
handle_userFunction · 0.85
rt_kprintfFunction · 0.85
get_exception_msgFunction · 0.85
dump_regsFunction · 0.85
rt_thread_selfFunction · 0.85
lwp_backtrace_frameFunction · 0.85
rt_backtrace_frameFunction · 0.85
tick_isrFunction · 0.70
rt_interrupt_enterFunction · 0.50
plic_handle_irqFunction · 0.50
rt_interrupt_leaveFunction · 0.50

Tested by

no test coverage detected