Save only callee-saved registers in pcb

On AArch64, registers x9-x18 are not callee-saved, yet they are
preserved at many placed in swtch.S. This patch removes code that
preserves these registers.
This commit is contained in:
Dapeng Gao 2022-05-25 11:25:06 +01:00 committed by Andrew Turner
parent 9e0716f461
commit e605b87a9e
2 changed files with 32 additions and 56 deletions

View File

@ -94,18 +94,12 @@ ENTRY(cpu_throw)
msr tpidr_el0, x6
ldr x6, [x4, #PCB_TPIDRRO]
msr tpidrro_el0, x6
ldp x8, x9, [x4, #PCB_REGS + 8 * 8]
ldp x10, x11, [x4, #PCB_REGS + 10 * 8]
ldp x12, x13, [x4, #PCB_REGS + 12 * 8]
ldp x14, x15, [x4, #PCB_REGS + 14 * 8]
ldp x16, x17, [x4, #PCB_REGS + 16 * 8]
ldr x19, [x4, #PCB_REGS + 19 * 8]
ldp x20, x21, [x4, #PCB_REGS + 20 * 8]
ldp x22, x23, [x4, #PCB_REGS + 22 * 8]
ldp x24, x25, [x4, #PCB_REGS + 24 * 8]
ldp x26, x27, [x4, #PCB_REGS + 26 * 8]
ldp x28, x29, [x4, #PCB_REGS + 28 * 8]
ldr lr, [x4, #PCB_LR]
ldp x19, x20, [x4, #PCB_REGS + 19 * 8]
ldp x21, x22, [x4, #PCB_REGS + 21 * 8]
ldp x23, x24, [x4, #PCB_REGS + 23 * 8]
ldp x25, x26, [x4, #PCB_REGS + 25 * 8]
ldp x27, x28, [x4, #PCB_REGS + 27 * 8]
ldp x29, lr, [x4, #PCB_REGS + 29 * 8]
ret
END(cpu_throw)
@ -125,18 +119,12 @@ ENTRY(cpu_switch)
ldr x4, [x0, #TD_PCB]
/* Store the callee-saved registers */
stp x8, x9, [x4, #PCB_REGS + 8 * 8]
stp x10, x11, [x4, #PCB_REGS + 10 * 8]
stp x12, x13, [x4, #PCB_REGS + 12 * 8]
stp x14, x15, [x4, #PCB_REGS + 14 * 8]
stp x16, x17, [x4, #PCB_REGS + 16 * 8]
stp x18, x19, [x4, #PCB_REGS + 18 * 8]
stp x20, x21, [x4, #PCB_REGS + 20 * 8]
stp x22, x23, [x4, #PCB_REGS + 22 * 8]
stp x24, x25, [x4, #PCB_REGS + 24 * 8]
stp x26, x27, [x4, #PCB_REGS + 26 * 8]
stp x28, x29, [x4, #PCB_REGS + 28 * 8]
str lr, [x4, #PCB_LR]
stp x19, x20, [x4, #PCB_REGS + 19 * 8]
stp x21, x22, [x4, #PCB_REGS + 21 * 8]
stp x23, x24, [x4, #PCB_REGS + 23 * 8]
stp x25, x26, [x4, #PCB_REGS + 25 * 8]
stp x27, x28, [x4, #PCB_REGS + 27 * 8]
stp x29, lr, [x4, #PCB_REGS + 29 * 8]
/* And the old stack pointer */
mov x5, sp
mrs x6, tpidrro_el0
@ -195,26 +183,20 @@ ENTRY(cpu_switch)
msr tpidr_el0, x6
ldr x6, [x4, #PCB_TPIDRRO]
msr tpidrro_el0, x6
ldp x8, x9, [x4, #PCB_REGS + 8 * 8]
ldp x10, x11, [x4, #PCB_REGS + 10 * 8]
ldp x12, x13, [x4, #PCB_REGS + 12 * 8]
ldp x14, x15, [x4, #PCB_REGS + 14 * 8]
ldp x16, x17, [x4, #PCB_REGS + 16 * 8]
ldr x19, [x4, #PCB_REGS + 19 * 8]
ldp x20, x21, [x4, #PCB_REGS + 20 * 8]
ldp x22, x23, [x4, #PCB_REGS + 22 * 8]
ldp x24, x25, [x4, #PCB_REGS + 24 * 8]
ldp x26, x27, [x4, #PCB_REGS + 26 * 8]
ldp x28, x29, [x4, #PCB_REGS + 28 * 8]
ldr lr, [x4, #PCB_LR]
ldp x19, x20, [x4, #PCB_REGS + 19 * 8]
ldp x21, x22, [x4, #PCB_REGS + 21 * 8]
ldp x23, x24, [x4, #PCB_REGS + 23 * 8]
ldp x25, x26, [x4, #PCB_REGS + 25 * 8]
ldp x27, x28, [x4, #PCB_REGS + 27 * 8]
ldp x29, lr, [x4, #PCB_REGS + 29 * 8]
str xzr, [x4, #PCB_REGS + 18 * 8]
ret
END(cpu_switch)
ENTRY(fork_trampoline)
mov x0, x8
mov x1, x9
mov x0, x19
mov x1, x20
mov x2, sp
mov fp, #0 /* Stack traceback stops here. */
bl _C_LABEL(fork_exit)
@ -263,18 +245,12 @@ END(fork_trampoline)
ENTRY(savectx)
/* Store the callee-saved registers */
stp x8, x9, [x0, #PCB_REGS + 8 * 8]
stp x10, x11, [x0, #PCB_REGS + 10 * 8]
stp x12, x13, [x0, #PCB_REGS + 12 * 8]
stp x14, x15, [x0, #PCB_REGS + 14 * 8]
stp x16, x17, [x0, #PCB_REGS + 16 * 8]
stp x18, x19, [x0, #PCB_REGS + 18 * 8]
stp x20, x21, [x0, #PCB_REGS + 20 * 8]
stp x22, x23, [x0, #PCB_REGS + 22 * 8]
stp x24, x25, [x0, #PCB_REGS + 24 * 8]
stp x26, x27, [x0, #PCB_REGS + 26 * 8]
stp x28, x29, [x0, #PCB_REGS + 28 * 8]
str lr, [x0, #PCB_LR]
stp x19, x20, [x0, #PCB_REGS + 19 * 8]
stp x21, x22, [x0, #PCB_REGS + 21 * 8]
stp x23, x24, [x0, #PCB_REGS + 23 * 8]
stp x25, x26, [x0, #PCB_REGS + 25 * 8]
stp x27, x28, [x0, #PCB_REGS + 27 * 8]
stp x29, lr, [x0, #PCB_REGS + 29 * 8]
/* And the old stack pointer */
mov x5, sp
mrs x6, tpidrro_el0

View File

@ -105,8 +105,8 @@ cpu_fork(struct thread *td1, struct proc *p2, struct thread *td2, int flags)
td2->td_frame = tf;
/* Set the return value registers for fork() */
td2->td_pcb->pcb_x[8] = (uintptr_t)fork_return;
td2->td_pcb->pcb_x[9] = (uintptr_t)td2;
td2->td_pcb->pcb_x[19] = (uintptr_t)fork_return;
td2->td_pcb->pcb_x[20] = (uintptr_t)td2;
td2->td_pcb->pcb_lr = (uintptr_t)fork_trampoline;
td2->td_pcb->pcb_sp = (uintptr_t)td2->td_frame;
td2->td_pcb->pcb_fpusaved = &td2->td_pcb->pcb_fpustate;
@ -183,8 +183,8 @@ cpu_copy_thread(struct thread *td, struct thread *td0)
bcopy(td0->td_frame, td->td_frame, sizeof(struct trapframe));
bcopy(td0->td_pcb, td->td_pcb, sizeof(struct pcb));
td->td_pcb->pcb_x[8] = (uintptr_t)fork_return;
td->td_pcb->pcb_x[9] = (uintptr_t)td;
td->td_pcb->pcb_x[19] = (uintptr_t)fork_return;
td->td_pcb->pcb_x[20] = (uintptr_t)td;
td->td_pcb->pcb_lr = (uintptr_t)fork_trampoline;
td->td_pcb->pcb_sp = (uintptr_t)td->td_frame;
td->td_pcb->pcb_fpflags &= ~(PCB_FP_STARTED | PCB_FP_KERN | PCB_FP_NOSAVE);
@ -287,8 +287,8 @@ void
cpu_fork_kthread_handler(struct thread *td, void (*func)(void *), void *arg)
{
td->td_pcb->pcb_x[8] = (uintptr_t)func;
td->td_pcb->pcb_x[9] = (uintptr_t)arg;
td->td_pcb->pcb_x[19] = (uintptr_t)func;
td->td_pcb->pcb_x[20] = (uintptr_t)arg;
}
void