Open maxkunes opened 6 months ago
Not manually, For Armv7-M ISA based CPU like Cortex-M7, caller save registers (r0-r3,r12,LR(r14),PC(r15), xPSR) would be saved into stack by hardware, and r4-r9, r10,r11,SP would be saved by callee functions, save and restore instructions would be generated by compilers, so for C programmers, no manual procedure is required to save/restore contexts.
Hi @rayc345 Threadx context save/restore not only saves register, but also manages the option that while the interrupt happened something that requires context switch. For this case stuff needed to be stored on the stack and context restore returns from the interrupt to the scheduler instead of to the original point where the interrupt was called from. And hence I think the answer to @maxkunes is that indeed it should be called from assembly code.
@amgross Thank you for the reply.
Honestly, I've been working with ThreadX for 3 years now without doing this, and I've yet to see anything that is obviously wrong. Can you explain what behavior might be seen in theory without these calls? Maybe I have some intermittent bugs due to this that I haven't connected to anything else.
Hi @maxkunes , By 'without doing it' you mean you call it from C code or not calling it at all?
I do not call it at all.
On Sat, May 18, 2024 at 10:21 PM amgross @.***> wrote:
Hi @maxkunes https://github.com/maxkunes , By 'without doing it' you mean you call it from C code or not calling it at all?
— Reply to this email directly, view it on GitHub https://github.com/eclipse-threadx/threadx/issues/381#issuecomment-2119105921, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACZP7FF5RTLLH6BSHYQGAODZDAZFLAVCNFSM6AAAAABFTVTCPGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMJZGEYDKOJSGE . You are receiving this because you were mentioned.Message ID: @.***>
Surprisingly (for me), it seems like I was mistaken and there is no need for cortex M to use save/restore
So @rayc345 is correct
But that seems to depend on the compiler used?
Which says on GNU you have to use assembly to save r0 and lr and then you can bl to your C function.
Im using arm-none-eabi-gcc, which presumably is AC5 or 6? If so, that explains why I don't have issues.
On Sun, May 19, 2024 at 2:33 AM amgross @.***> wrote:
Surprisingly (for me), it seems like I was mistaken and there is no need for cortex M to use save/restore
So @rayc345 https://github.com/rayc345 is correct
— Reply to this email directly, view it on GitHub https://github.com/eclipse-threadx/threadx/issues/381#issuecomment-2119169327, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACZP7FCLY7PRHJKSIQERW5DZDBWYFAVCNFSM6AAAAABFTVTCPGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMJZGE3DSMZSG4 . You are receiving this because you were mentioned.Message ID: @.***>
The ThreadX docs under Chapter 3 - Functional Components: ISR Template suggest that context saving and restoring must be done in assembly before executing any ThreadX code (i.e. notifying semaphores) or calling user code.
Is this required on Cortex-M7? Or is this only needed on specific architectures?