low level mechanism for context switching