Question about disabling interrupts in the demo_gpio program


(岩倉 澪) #1

reset_demo begins with the following:

  // Disable the machine & timer interrupts until setup is done.

  clear_csr(mie, MIP_MEIP);
  clear_csr(mie, MIP_MTIP);

I understand what clear_csr is doing, and that MIP_MEIP and MIP_MTIP are being used in place of having symbols defined for MIE_MEIE and MIE_MTIE as the locations in the registers are identical.

Why do we disable the machine and timer interrupts vs just disabling interrupts globally with the MIE bit in mstatus? My understanding is that by turning off MEIE and MTIE bits in mie we are leaving the possibility for software interrupts to still be handled (MSIE). Is there a specific reason why we would want that behaviour, or am I misunderstanding the relationship between mie/mstatus/the plic?

Here is the episode from my show where we encountered this question:


(Megan A. Wachs) #2

Good question! Those lines of code don’t make a lot of sense anymore. They are left over from an earlier version of the code, which allowed “reset_demo()” to be called from other functions (we simplified the demo before we released it).

And, you’re right that the same could be achieved by just disabling interrupts globally. There is no special desire to keep the MSIP interrupt enabled, we just know in this demo we never enabled it.