Embedded operating system issue


If you are new to RTOS, as you say, why then are you starting with a "dual-core, PowerPC"? I recommend starting with something easier and mainstream, like single-core ARM Cortex-M. For a good intro into traditional RTOS, I recommend my RTOS video playlist.

I agree with starting simple, but since the OP may not have the freedom to choose the processor, I’ll give an answer a try.
I am assuming you are working with FreeRTOS based on the function naming and behavior you’re describing? If so, I should mention that while I can help clarify some concepts, my experience is primarily with other RTOS implementations, so I may not catch all the FreeRTOS-specific nuances.
That said, what you’re observing is typical RTOS behavior - the PreTaskHook and PostTaskHook don’t guarantee that the same task context will be restored, and other tasks can indeed execute between these hooks depending on scheduling decisions and interrupts. The register changes you’re seeing are expected since the scheduler may switch contexts.

PreTaskHook and PostTaskHook aren’t responsible for saving or restoring registers. They’re just notifications around a context switch.
The RTOS itself saves the full CPU context into the task’s control block (TCB), not your hook. That’s why the registers you see in PreTaskHook don’t match what you see in PostTaskHook.
Interrupts and even other task switches can legally occur in between.
So don’t try to compare or restore registers between the hooks. Instead, use them for logging which task is coming in/out, timestamps, or profiling. If you actually need register contents, read them from the saved context in the TCB, not the live CPU registers.







