src/kernel/trap/trap.c
/*!
 * @note handle the exc(exception request)
 *       after store trap frame.
 *       invoked in file "trap_asm.s".
 *       And the different from exception handling
 *      and interrupt handing is that exception handing
 *       needs to turn off interrupts manually
 * @param cause  scause register
 * @param epc    sepc register
 * @param regs   x0~x31 registers
 * @param fregs  f0~f31 registers
 */
@note handle the exc(exception request)
after store trap frame.
@note handle the exc ( exception request ) after store trap frame .
void exc_handler(trap_frame_t * trap_frame){
    ASSERT(GET_RUNNING_THREAD()->magic == THREADS_MAGIC);
    thread_t * self = GET_RUNNING_THREAD();
    intr_on();
    trap_exc_table[get_cpu_id_raw()][trap_frame->scause](trap_frame);
    if((r_sstatus()&SSTATUS_SPP)==0){
        intr_off();
        preempt_schedule_user_preempt();
        intr_on();
    }
}
void exc_handler ( trap_frame_t * trap_frame ) { ASSERT ( GET_RUNNING_THREAD ( ) -> magic == THREADS_MAGIC ) ; thread_t * self = GET_RUNNING_THREAD ( ) ; intr_on ( ) ; trap_exc_table [ get_cpu_id_raw ( ) ] [ trap_frame -> scause ] ( trap_frame ) ; if ( ( r_sstatus ( ) & SSTATUS_SPP ) == 0 ) { intr_off ( ) ; preempt_schedule_user_preempt ( ) ; intr_on ( ) ; } }
@note handle the exc(exception request)
       after store trap frame.
@note handle the exc ( exception request ) after store trap frame .
//don`t need to get cpu id by per cpu var. //this will disable kernel preempt. //in most cases,different cpu have same exception //handler function. //back to user mode