Two Saves One Switch

A timer interrupt arrives while process A is running, and the OS decides to switch to process B. Here is the sequence:

# Who acts Action
1 hardware timer interrupt fires
2 hardware save registers, move to kernel mode, jump to the trap handler
3 OS handle the trap, decide to switch, call switch()
4 OS save registers, restore B's, change the stack pointer to B's kernel stack
5 OS execute return-from-trap
6 hardware restore B's registers, move to user mode, jump to B's PC

Steps 2 and 4 both save registers. Which describes them correctly?

A

Step 2 saves into A's process structure and step 4 onto A's kernel stack, so the deeper save happens closer to the switch

B

Step 2 saves A's user registers onto A's kernel stack, implicitly, in hardware. Step 4 saves A's kernel registers into A's process structure, explicitly, in software

C

Both save to A's kernel stack. Step 2 saves the general-purpose registers and step 4 saves the program counter and stack pointer

D

Both save into A's process structure. Step 2 is the fast path and step 4 only runs when the OS actually switches processes