unsafe fn dev_intr(self) -> i32 {
        let scause: usize = r_scause();

        if scause & 0x8000000000000000 != 0 && scause & 0xff == 9 {
            // This is a supervisor external interrupt, via PLIC.

            // irq indicates which device interrupted.
            let irq = unsafe { plic_claim() };

            if irq as usize == UART0_IRQ {
                // SAFETY: it's unsafe only when ctrl+p is pressed.
                unsafe { hal().console().intr(self) };
            } else if irq as usize == VIRTIO0_IRQ {
                hal().disk().pinned_lock().get_pin_mut().intr(self);
            } else if irq != 0 {
                // Use `panic!` instead of `println` to prevent stack overflow.
                // https://github.com/kaist-cp/rv6/issues/311
                panic!("unexpected interrupt irq={}\n", irq);
            }

            // The PLIC allows each device to raise at most one
            // interrupt at a time; tell the PLIC the device is
            // now allowed to interrupt again.
            if irq != 0 {
                unsafe { plic_complete(irq) };
            }

            1
        } else if scause == 0x8000000000000001 {
            // Software interrupt from a machine-mode timer interrupt,
            // forwarded by timervec in selfvec.S.

            if cpuid() == 0 {
                self.clock_intr();
            }

            // Acknowledge the software interrupt by clearing
            // the SSIP bit in sip.
            unsafe { w_sip(r_sip() & !2) };

            2
        } else {
            0
        }
    }
/// Check if it's an external interrupt or software interrupt,
/// and handle it.
/// Returns 2 if timer interrupt,
/// 1 if other device,
/// 0 if not recognized.
Check if it's an external interrupt or software interrupt,
and handle it.
Returns 2 if timer interrupt,
1 if other device,
0 if not recognized.
Check if it ' s an external interrupt or software interrupt and handle it . Returns 2 if timer interrupt 1 if other device 0 if not recognized .
unsafe fn dev_intr(self) -> i32 {
        let scause: usize = r_scause();
        if scause & 0x8000000000000000 != 0 && scause & 0xff == 9 {
            // This is a supervisor external interrupt, via PLIC.
            // irq indicates which device interrupted.
            let irq = unsafe { plic_claim() };
            if irq as usize == UART0_IRQ {
                // SAFETY: it's unsafe only when ctrl+p is pressed.
                unsafe { hal().console().intr(self) };
            } else if irq as usize == VIRTIO0_IRQ {
                hal().disk().pinned_lock().get_pin_mut().intr(self);
            } else if irq != 0 {
                // Use `panic!` instead of `println` to prevent stack overflow.
                // https://github.com/kaist-cp/rv6/issues/311
                panic!("unexpected interrupt irq={}\n", irq);
            }
            // The PLIC allows each device to raise at most one
            // interrupt at a time; tell the PLIC the device is
            // now allowed to interrupt again.
            if irq != 0 {
                unsafe { plic_complete(irq) };
            }
            1
        } else if scause == 0x8000000000000001 {
            // Software interrupt from a machine-mode timer interrupt,
            // forwarded by timervec in selfvec.S.
            if cpuid() == 0 {
                self.clock_intr();
            }
            // Acknowledge the software interrupt by clearing
            // the SSIP bit in sip.
            unsafe { w_sip(r_sip() & !2) };
            2
        } else {
            0
        }
    }
unsafe fn dev_intr ( self ) -> i32 { let scause : usize = r_scause ( ) ; if scause & 0x8000000000000000 != 0 && scause & 0xff == 9 { // This is a supervisor external interrupt, via PLIC. // irq indicates which device interrupted. let irq = unsafe { plic_claim ( ) } ; if irq as usize == UART0_IRQ { // SAFETY: it's unsafe only when ctrl+p is pressed. unsafe { hal ( ) . console ( ) . intr ( self ) } ; } else if irq as usize == VIRTIO0_IRQ { hal ( ) . disk ( ) . pinned_lock ( ) . get_pin_mut ( ) . intr ( self ) ; } else if irq != 0 { // Use `panic!` instead of `println` to prevent stack overflow. // https://github.com/kaist-cp/rv6/issues/311 panic ! ( " \n " irq ) ; } // The PLIC allows each device to raise at most one // interrupt at a time; tell the PLIC the device is // now allowed to interrupt again. if irq != 0 { unsafe { plic_complete ( irq ) } ; } 1 } else if scause == 0x8000000000000001 { // Software interrupt from a machine-mode timer interrupt, // forwarded by timervec in selfvec.S. if cpuid ( ) == 0 { self . clock_intr ( ) ; } // Acknowledge the software interrupt by clearing // the SSIP bit in sip. unsafe { w_sip ( r_sip ( ) & ! 2 ) } ; 2 } else { 0 } }
Check if it's an external interrupt or software interrupt,
and handle it.
Check if it ' s an external interrupt or software interrupt and handle it .
self
self