SPARC Context Switch Code

Ahlendorf, Falk Falk.Ahlendorf at
Thu Feb 6 12:31:19 UTC 2014

> > I understand that the _CPU_Context_switch can be
> > invoked at arbitrary places within a user program (at least
> when using
> > preemptive scheduling), so it must make sure that *all*
> registers are
> > saved and restored. Otherwise it would render %g1 pretty much
> useless
> > as (from a user POV) its content might change in an
> unpredictable way
> > in the middle of a sequence of instructions.
> Why do you think that _CPU_Context_switch() is invoked at
> arbitrary places?
> The only valid invocation places for _CPU_Context_switch() are
> _Thread_Dispatch() and _Thread_Start_multitasking().

_Thread_Dispatch() can also be called by a clock interrupt, 
which can just happen anywhere in your program and not necessarily 
at the point of a function call. 

So the call to _Thread_Dispatch happens at a random location and 
therefore also the call to _CPU_Context_switch.

That's why it is essential that also the volatile registers are 
saved in the task context.

Kind regards
 Falk Ahlendorf

More information about the users mailing list