Skip to content

Commit 2285afc

Browse files
Andy Rossnashif
authored andcommitted
xtensa: Disable interrupts on entry to _Cstart
Zephyr isn't ready to handle interrupts yet, until the threading/scheduler are set up and we make our first context switch. This was a semi-hidden bug: only the timer interrupt would actually get unmasked before the system was ready, and obviously would never have time to fire a tick before the system completed initialization. But a combination of system load and a new version of Qemu (which seems to be more sensitive to non-deterministic timing glitchery) has made this visible. About 2-3% of the time when run under a full sanitycheck, the qemu process will get swapped away for long enough that the tick timer expires before _Cstart() has reached enable_multithreading(). It looks like the original code was cut and pasted from another implementation, which was expected to call into an "application" main() routine that wanted interrupts ready. Fixes #11182 (Note also that this code is not used for ESP-32, which has its own startup path) Signed-off-by: Andy Ross <[email protected]>
1 parent 82e6a4e commit 2285afc

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

arch/xtensa/core/crt1.S

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,7 @@ _start:
5656
*
5757
* Assumptions on entry to _start:
5858
* - low (level-one) and medium priority interrupts are disabled
59-
* via PS.INTLEVEL and/or INTENABLE (PS.INTLEVEL is expected to
60-
* be zeroed, to potentially enable them, before calling main)
59+
* via PS.INTLEVEL and/or INTENABLE
6160
* - C calling context not initialized:
6261
* - PS not initialized
6362
* - SP not initialized
@@ -88,16 +87,16 @@ _start:
8887

8988
/*
9089
* Now that sp (a1) is set, we can set PS as per the application (user
91-
* vector mode, enable interrupts, enable window exceptions if
90+
* vector mode, disable interrupts, enable window exceptions if
9291
* applicable).
9392
*/
9493
#if XCHAL_HAVE_EXCEPTIONS
9594
# ifdef __XTENSA_CALL0_ABI__
96-
/* PS.WOE = 0, PS.UM = 1, PS.EXCM = 0, PS.INTLEVEL = 0 */
97-
movi a3, PS_UM
95+
/* PS.WOE = 0, PS.UM = 1, PS.EXCM = 0, PS.INTLEVEL = 15 */
96+
movi a3, PS_UM|PS_INTLEVEL(15)
9897
# else
99-
/* PS.WOE = 1, PS.UM = 1, PS.EXCM = 0, PS.INTLEVEL = 0 */
100-
movi a3, PS_UM|PS_WOE
98+
/* PS.WOE = 1, PS.UM = 1, PS.EXCM = 0, PS.INTLEVEL = 15 */
99+
movi a3, PS_UM|PS_WOE|PS_INTLEVEL(15)
101100
# endif
102101
wsr a3, PS
103102
rsync

0 commit comments

Comments
 (0)