Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 25 May 2022 10:38:48 GMT
From:      Andrew Turner <andrew@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: e605b87a9e75 - main - Save only callee-saved registers in pcb
Message-ID:  <202205251038.24PAcmuH042357@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by andrew:

URL: https://cgit.FreeBSD.org/src/commit/?id=e605b87a9e75a7f693527f0aad8189ae9db20f16

commit e605b87a9e75a7f693527f0aad8189ae9db20f16
Author:     Dapeng Gao <peter@dpgao.cc>
AuthorDate: 2022-05-25 10:25:06 +0000
Commit:     Andrew Turner <andrew@FreeBSD.org>
CommitDate: 2022-05-25 10:26:30 +0000

    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.
---
 sys/arm64/arm64/swtch.S      | 76 +++++++++++++++-----------------------------
 sys/arm64/arm64/vm_machdep.c | 12 +++----
 2 files changed, 32 insertions(+), 56 deletions(-)

diff --git a/sys/arm64/arm64/swtch.S b/sys/arm64/arm64/swtch.S
index 081bdfe88126..d7f915a91946 100644
--- a/sys/arm64/arm64/swtch.S
+++ b/sys/arm64/arm64/swtch.S
@@ -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
diff --git a/sys/arm64/arm64/vm_machdep.c b/sys/arm64/arm64/vm_machdep.c
index c52a7e2fc5c1..feb439314f50 100644
--- a/sys/arm64/arm64/vm_machdep.c
+++ b/sys/arm64/arm64/vm_machdep.c
@@ -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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202205251038.24PAcmuH042357>