kernel/trap.c
int
devintr()
{
  uint64 scause = r_scause();

  if((scause & 0x8000000000000000L) &&
     (scause & 0xff) == 9){
    // this is a supervisor external interrupt, via PLIC.

    // irq indicates which device interrupted.
    int irq = plic_claim();

    if(irq == UART0_IRQ){
      uartintr();
    } else if(irq == VIRTIO0_IRQ){
      virtio_disk_intr();
    }

    plic_complete(irq);
    return 1;
  } else if(scause == 0x8000000000000001L){
    // software interrupt from a machine-mode timer interrupt,
    // forwarded by timervec in kernelvec.S.

    if(cpuid() == 0){
      clockintr();
    }
    
    // acknowledge the software interrupt by clearing
    // the SSIP bit in sip.
    w_sip(r_sip() & ~2);

    return 2;
  } else {
    return 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 .
int
devintr()
{
  uint64 scause = r_scause();
  if((scause & 0x8000000000000000L) &&
     (scause & 0xff) == 9){
    int irq = plic_claim();
    if(irq == UART0_IRQ){
      uartintr();
    } else if(irq == VIRTIO0_IRQ){
      virtio_disk_intr();
    }
    plic_complete(irq);
    return 1;
  } else if(scause == 0x8000000000000001L){
    if(cpuid() == 0){
      clockintr();
    }
    w_sip(r_sip() & ~2);
    return 2;
  } else {
    return 0;
  }
}
int devintr ( ) { uint64 scause = r_scause ( ) ; if ( ( scause & 0x8000000000000000L ) && ( scause & 0xff ) == 9 ) { int irq = plic_claim ( ) ; if ( irq == UART0_IRQ ) { uartintr ( ) ; } else if ( irq == VIRTIO0_IRQ ) { virtio_disk_intr ( ) ; } plic_complete ( irq ) ; return 1 ; } else if ( scause == 0x8000000000000001L ) { if ( cpuid ( ) == 0 ) { clockintr ( ) ; } w_sip ( r_sip ( ) & ~ 2 ) ; return 2 ; } else { return 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 .
// this is a supervisor external interrupt, via PLIC. // irq indicates which device interrupted. // software interrupt from a machine-mode timer interrupt, // forwarded by timervec in kernelvec.S. // acknowledge the software interrupt by clearing // the SSIP bit in sip.