comment added

This commit is contained in:
2025-06-23 11:18:49 +08:00
parent c7c962ffef
commit 70ee668b9b
6 changed files with 34 additions and 8 deletions

View File

@@ -76,13 +76,18 @@ usertrap(void)
if(killed(p))
exit(-1);
// give up the CPU if this is a timer interrupt.
// 如果这是一个定时器中断则让出CPU。
if(which_dev == 2){
// 当前进程的中断计数器加一。
p->inter_cnt++;
// 如果中断计数器达到设定的报警计数并且报警计数大于0。
if (p->inter_cnt == p->alarm_cnt && 0 < p->alarm_cnt) {
// 备份当前trapframe到pre_trapframe用于后续恢复。
*p->pre_trapframe = *p->trapframe;
// 将epc设置为用户定义的handler函数地址返回用户态时会跳转到handler执行。
p->trapframe->epc = p->handler;
} else {
// 否则让出CPU进行进程调度。
yield();
}
}