Fixed MPIE being cleared leading to have interrupts being disable after an mret instruction#522
Fixed MPIE being cleared leading to have interrupts being disable after an mret instruction#522cpdpls wants to merge 2 commits intoeclipse-threadx:devfrom
Conversation
…n returning from machine mode
|
Thank you for the detailed bug report and the fix @cpdpls — the root cause analysis is correct. Clearing MPIE before mret is indeed the culprit: mret copies MPIE→MIE, so with MPIE=0 interrupts are permanently disabled after the first context switch. However, the fix seems to introduce a new logic error in both modified hunks. The problem li t2, 0x1880 // Set MPP(0x1800) | MPIE(0x80)
li t3, ~0x8 // Preserve all bits except MIE ← computed but never read
or t1, t1, t2 // MPP and MPIE are now set ✅
and t1, t1, t2 // Clear MIE ❌ wrong registerThe t3 is loaded but never used — the same dead-register issue the PR description notes about the original code. The same logic appears in both the Suggested fix: Since csrr t1, mstatus
li t2, 0x1880 // MPP(0x1800) | MPIE(0x80)
or t1, t1, t2 // Set MPP and MPIE
andi t1, t1, ~0x8 // Clear only MIE (bit 3); preserve all other mstatus bitsApply the same three-instruction sequence to both hunks. What do you think? |
|
Hello @fdesbiens, Indeed, I somehow reused T2 both inside the AND and the OR instruction. My intention was to use T3 with the AND instruction … I feel a bit ashamed that I let that one through though. Thank you for reviewing though, I totally agree with the provided solution and will update the PR immediately. Sorry again for that embarrassing mistake. |
|
PR has been updated with the new suggestions. Thanks again for the review |
Fixed #517
PR checklist