Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Register RA will be modified when TX_ENABLE_EXECUTION_CHANGE_NOTIFY is enabled #348

Open
xuzihan351 opened this issue Jan 25, 2024 · 1 comment
Labels
bug Something isn't working hardware New hardware or architecture support request

Comments

@xuzihan351
Copy link

Let us discuss the code below(ports/risc-v32/iar/src/tx_thread_context_save.s and others asm code)

#ifdef TX_ENABLE_EXECUTION_CHANGE_NOTIFY
    /* _tx_execution_isr_enter is called with thread stack pointer */
    call    _tx_execution_isr_enter                     ; Call the ISR execution enter function
#endif
...
...
   ret
   END

The function tx_thread_context_save is called from ISR or another function, and tx_thread_context_save will return to it by ret.
Register RA stored the return address of the caller function.
When TX_ENABLE_EXECUTION_CHANGE_NOTIFY is enabled, function _tx_execution_isr_enter will be called, and register RA will store the return address of the next line of call _tx_execution_isr_enter . Without saving register RA before call _tx_execution_isr_enter, the return address of tx_thread_context_save's caller function will be replaced. Resulting in function tx_thread_context_save will never return to the right address.

@xuzihan351 xuzihan351 added bug Something isn't working hardware New hardware or architecture support request labels Jan 25, 2024
@williamelamie
Copy link

This is definitely a problem. A solution is to move RA into a compiler-preserved register (like S0) before the call. After the call returns, RA can be restored from the same register. Another option is to move the call to _tx_execution_isr_enter to AFTER _tx_thread_context_save returns. The downside of this is that it would need to be done in all ISRs that use _tx_thread_context_save. So that's more of a quick patch rather than a solution.

As for the other assembly files that have a _tx_execution* call, these look okay since RA is either saved prior to the call or restored subsequent to the call.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working hardware New hardware or architecture support request
Projects
None yet
Development

No branches or pull requests

2 participants