Suppose there is two task running TASK_A and TASK_B. While TASK_A is running an interrupt occurred and a context switch to TASK_B is needed.
While inside ISR, TASK_B should not be directly jumped since it is still in ISR and have'nt returned yet (for eg: RETI is not executed). If normally returned from ISR it will as usual go back to the TASK_A's last program counter. So the RTOS has to get out of the ISR and as soon as it is out of the ISR it has to do a context switch to TASK_B. Instead of going back to TASK_A how does a RTOS get back control as soon as it exit ISR.
In case of switching from a RTOS function such as while unlocking a mutex a direct switch can be made by backing up the registers.
How does an RTOS handle this situation
Pardon me if this is a generalized question...