I am studying about Linux Context Switch on the ARMv8
Below is the codes
ENTRY(cpu_switch_to)
mov x10, #THREAD_CPU_CONTEXT
add x8, x0, x10
mov x9, sp
stp x19, x20, [x8], #16 // store callee-saved registers
stp x21, x22, [x8], #16
stp x23, x24, [x8], #16
stp x25, x26, [x8], #16
stp x27, x28, [x8], #16
stp x29, x9, [x8], #16
str lr, [x8]
add x8, x1, x10
ldp x19, x20, [x8], #16 // restore callee-saved registers
ldp x21, x22, [x8], #16
ldp x23, x24, [x8], #16
ldp x25, x26, [x8], #16
ldp x27, x28, [x8], #16
ldp x29, x9, [x8], #16
ldr lr, [x8]
mov sp, x9
msr sp_el0, x1
ret
ENDPROC(cpu_switch_to)
Question 1: Just Callee Registers (X19 ~ X29, Link Register, SP) are enough for Context Switch. Why the rest of registers (X0 ~ X18) are not involved in Strong and Restoring of context using stack? The task context is kind of sequence of function. So, Callee Registers are enough for context switch?
Question 2: PC (Program Counter) Register is not involved in Strong and Restoring of context using stack. This is because the pc is restored when this callee function has return? At that time link register is copied into PC?
Question 3: PSTATE Register is not involved in Strong and Restoring of context using stack. Is there any reason to do like this? I think that task context should contain PSTATE Register.
If somebody answers my question. I would be grateful.