]> begriffs open source - freertos/commit
Fix/clear MIE bit in initial RISC-V mstatus register. (#57)
authorRichardBarry <3073890+RichardBarry@users.noreply.github.com>
Sat, 2 May 2020 05:35:42 +0000 (22:35 -0700)
committerGitHub <noreply@github.com>
Sat, 2 May 2020 05:35:42 +0000 (22:35 -0700)
commitbac101c98869c7716700d1549f064e02a892cd78
tree9c783bf6952fa8f3a1689573ccaafed918291e15
parenteac2b9a271be1526efddcde3f22533c3205ded2a
Fix/clear MIE bit in initial RISC-V mstatus register. (#57)

* fix: CLEAR MIE BIT IN INITIAL RISC-V MSTATUS VALUE
The MIE bit in the RISC-V MSTATUS register is used to globally enable
or disable interrupts.  It is copied into the MPIE bit and cleared
on entry to an interrupt, and then copied back from the MPIE bit on
exit from an interrupt.

When a task is created it is given an initial MSTATUS value that is
derived from the current MSTATUS value with the MPIE bit force to 1,
but the MIE bit is not forced into any state.  This change forces
the MIE bit to 0 (interrupts disabled).

Why:
If a task is created before the scheduler is started the MIE bit
will happen to be 0 (interrupts disabled), which is fine.  If a
task is created after the scheduler has been started the MIE bit
is set (interrupts enabled), causing interrupts to unintentionally
become enabled inside the interrupt in which the task is first
moved to the running state - effectively breaking a critical
section which in turn could cause a crash if enabling interrupts
causes interrupts to nest.  It is only an issue when starting a
newly created task that was created after the scheduler was started.

Related Issues:
https://forums.freertos.org/t/risc-v-port-pxportinitialisestack-issue-about-mstatus-value-onto-the-stack/9622
Co-authored-by: Cobus van Eeden <35851496+cobusve@users.noreply.github.com>
portable/GCC/RISC-V/portASM.S
portable/IAR/RISC-V/portASM.s