kernel/trap.c
void 
kerneltrap() {
  int which_dev = 0;
  uint64 sepc = r_sepc();
  uint64 sstatus = r_sstatus();
  uint64 scause = r_scause();
  
  if((sstatus & SSTATUS_SPP) == 0)
    panic("kerneltrap: not from supervisor mode");
  if(intr_get() != 0)
    panic("kerneltrap: interrupts enabled");

  if((which_dev = devintr()) == 0){
    printf("\nscause %p\n", scause);
    printf("sepc=%p stval=%p hart=%d\n", r_sepc(), r_stval(), r_tp());
    struct proc *p = myproc();
    if (p != 0) {
      printf("pid: %d, name: %s\n", p->pid, p->name);
    }
    panic("kerneltrap");
  }
  // printf("which_dev: %d\n", which_dev);
  
  // give up the CPU if this is a timer interrupt.
  if(which_dev == 2 && myproc() != 0 && myproc()->state == RUNNING) {
    yield();
  }
  // the yield() may have caused some traps to occur,
  // so restore trap registers for use by kernelvec.S's sepc instruction.
  w_sepc(sepc);
  w_sstatus(sstatus);
}
// interrupts and exceptions from kernel code go here via kernelvec,
// on whatever the current kernel stack is.
interrupts and exceptions from kernel code go here via kernelvec,
on whatever the current kernel stack is.
interrupts and exceptions from kernel code go here via kernelvec on whatever the current kernel stack is .
void 
kerneltrap() {
  int which_dev = 0;
  uint64 sepc = r_sepc();
  uint64 sstatus = r_sstatus();
  uint64 scause = r_scause();
  if((sstatus & SSTATUS_SPP) == 0)
    panic("kerneltrap: not from supervisor mode");
  if(intr_get() != 0)
    panic("kerneltrap: interrupts enabled");
  if((which_dev = devintr()) == 0){
    printf("\nscause %p\n", scause);
    printf("sepc=%p stval=%p hart=%d\n", r_sepc(), r_stval(), r_tp());
    struct proc *p = myproc();
    if (p != 0) {
      printf("pid: %d, name: %s\n", p->pid, p->name);
    }
    panic("kerneltrap");
  }
  if(which_dev == 2 && myproc() != 0 && myproc()->state == RUNNING) {
    yield();
  }
  w_sepc(sepc);
  w_sstatus(sstatus);
}
void kerneltrap ( ) { int which_dev = 0 ; uint64 sepc = r_sepc ( ) ; uint64 sstatus = r_sstatus ( ) ; uint64 scause = r_scause ( ) ; if ( ( sstatus & SSTATUS_SPP ) == 0 ) panic ( " " ) ; if ( intr_get ( ) != 0 ) panic ( " " ) ; if ( ( which_dev = devintr ( ) ) == 0 ) { printf ( " \n \n " , scause ) ; printf ( " \n " , r_sepc ( ) , r_stval ( ) , r_tp ( ) ) ; struct proc * p = myproc ( ) ; if ( p != 0 ) { printf ( " \n " , p -> pid , p -> name ) ; } panic ( " " ) ; } if ( which_dev == 2 && myproc ( ) != 0 && myproc ( ) -> state == RUNNING ) { yield ( ) ; } w_sepc ( sepc ) ; w_sstatus ( sstatus ) ; }
interrupts and exceptions from kernel code go here via kernelvec,
on whatever the current kernel stack is.
interrupts and exceptions from kernel code go here via kernelvec on whatever the current kernel stack is .
// printf("which_dev: %d\n", which_dev); // give up the CPU if this is a timer interrupt. // the yield() may have caused some traps to occur, // so restore trap registers for use by kernelvec.S's sepc instruction.