xv6 - switch 语句中的“+”是什么意思

xv6 - what does '+' mean in a switch sentence

我正在修改 XV6,我想了解一些关于 trap.c

的事情
switch(tf->trapno){
  case T_IRQ0 + IRQ_TIMER:
    if(cpu->id == 0){
      acquire(&tickslock);
      ticks++;
      wakeup(&ticks);
      release(&tickslock);
    }
    lapiceoi();
    break;
  case T_IRQ0 + IRQ_IDE:
    ideintr();
    lapiceoi();
    break;
  case T_IRQ0 + IRQ_IDE+1:
    // Bochs generates spurious IDE1 interrupts.
    break;
  case T_IRQ0 + IRQ_KBD:
    kbdintr();
    lapiceoi();
    break;
  case T_IRQ0 + IRQ_COM1:
    uartintr();
    lapiceoi();
    break;
  case T_IRQ0 + 7:
  case T_IRQ0 + IRQ_SPURIOUS:
    cprintf("cpu%d: spurious interrupt at %x:%x\n",
            cpu->id, tf->cs, tf->eip);
    lapiceoi();
    break;

  //PAGEBREAK: 13
  default:
    if(proc == 0 || (tf->cs&3) == 0){
      // In kernel, it must be our mistake.
      cprintf("unexpected trap %d from cpu %d eip %x (cr2=0x%x)\n",
              tf->trapno, cpu->id, tf->eip, rcr2());
      panic("trap");
    }
    // In user space, assume process misbehaved.
    cprintf("pid %d %s: trap %d err %d on cpu %d "
            "eip 0x%x addr 0x%x--kill proc\n",
            proc->pid, proc->name, tf->trapno, tf->err, cpu->id, tf->eip, 
            rcr2());
    proc->killed = 1;
  }

当它说 "case T_IRQ0 + IRQ_IDE" 时是否意味着这两种情况都必须发生?

一个进程是否可以进入多个case?

“+”是正常加法。结果加法将决定是否输入相应的 case 块。

does that mean both of those must happen?

没有。 case: 之间的东西必须是数字。数字指定为总和并不重要,重要的是总和的值。

can a single process enter more than one case?

大多数情况下,没有。请注意,所有代码段在每个 case 关键字之后,末尾都包含 break。这将导致只有一个这样的部分被执行。一个小例外:

  case T_IRQ0 + 7:  // ***** Here *****
  case T_IRQ0 + IRQ_SPURIOUS:
    ...
    break;

代码...将在两种情况下执行:当tf->trapno等于T_IRQ0 + 7或等于T_IRQ0 + IRQ_SPURIOUS时。从技术上讲,它进入第一个 case,什么都不做,然后立即进入第二个 case.