Shanks0224 opened a new pull request, #22604:
URL: https://github.com/apache/nuttx/pull/22604

   *Note: Please adhere to [Contributing 
Guidelines](https://github.com/apache/nuttx/blob/master/CONTRIBUTING.md).*
   
   ## Summary
   
   The boolean register BR and the MAC16 registers (ACCLO, ACCHI, M0-M3)
   do not belong to a coprocessor, so the lazy coprocessor save does not
   cover them, and the Xtensa exception frame did not include them either.
   They are per-thread state like SAR or LBEG/LEND/LCOUNT; the Cadence HAL
   saves them in `xchal_ncp_store` for this reason.
   
   GCC uses BR for floating point comparisons, e.g.
   
   ```
   olt.s   b0, f0, f1
   movt    a2, a8, b0
   ```
   
   so a thread preempted between the compare and the branch/move resumes
   with another thread's BR and can take the wrong branch.  The same
   applies to the MAC16 accumulator of code that uses MAC16 instructions.
   ESP32 and ESP32-S3 have both options (`XCHAL_HAVE_BOOLEANS`,
   `XCHAL_HAVE_MAC16`); ESP32-S2 has neither.
   
   This PR adds the registers to the exception frame when the core has
   them, and saves/restores them in `_xtensa_context_save`,
   `_xtensa_context_restore` and `up_saveusercontext()`.
   
   ## Impact
   
   Xtensa cores with the Boolean or MAC16 option.  The exception frame
   grows by 28 bytes on ESP32 (216 -> 244) and 32 bytes on ESP32-S3
   (432 -> 464, the coprocessor area stays 16-byte aligned).  ESP32-S2 is
   unchanged (120).  All users of the frame use the REG_* macros and
   XCPTCONTEXT_SIZE, so no other change is needed.
   
   ## Testing
   
   Test program: two SCHED_RR threads of the same priority each write
   their own pattern to BR and ACCLO/ACCHI/M0-M3, spin long enough to be
   preempted by the timer, and check the registers.  ESP32 QEMU
   (Espressif qemu esp-develop-9.0.0-20240606), esp32-devkitc:nsh +
   `CONFIG_ESP32_QEMU_IMAGE=y CONFIG_RR_INTERVAL=10`:
   
   master:
   ```
   R1 rounds 200/200 corrupted 66/65
   FAIL
   ```
   
   this PR:
   ```
   R1 rounds 200/200 corrupted 0/0
   TEST DONE
   ```
   
   ostest on the same QEMU (esp32-devkitc:nsh + ostest): exits with
   status 0 on master and with this PR (`strto_test()` skipped on both,
   see note below).
   
   Builds (xtensa-esp-elf 14.2.0): esp32-devkitc:nsh, esp32-devkitc:smp,
   esp32s2-saola-1:nsh, esp32s3-devkit:nsh, esp32s3-devkit:smp.
   
   Note: on ESP32 `strtol()`/`strtoul()` come from the ROM newlib, which
   does not set the NuttX errno, so ostest's `strto_test()` asserts on
   master independently of this change.
   
   Not tested on real hardware.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

  • [PR] arch/xtensa: Save and re... Shanks0224 (via GitHub) via commits

Reply via email to