[Bug 262691] [patch] Save only callee-saved registers in pcb

[email protected]
Newsgroups gmane.os.freebsd.devel.arm
Message-ID <[email protected]/bugzilla/>
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=262691

            Bug ID: 262691
           Summary: [patch] Save only callee-saved registers in pcb
           Product: Base System
           Version: CURRENT
          Hardware: arm64
                OS: Any
            Status: New
          Severity: Affects Some People
          Priority: ---
         Component: arm
          Assignee: [email protected]
          Reporter: [email protected]

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.

It may also be worth it to remove the unused entries in the `pcb_x` field of
`struct pcb`, but this would be a more disruptive change with compatibility
concerns (e.g. `kgdb` would need to be changed to recognise the new layout the
struct).

--- 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,18 +183,12 @@ 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
@@ -258,23 +240,17 @@ ENTRY(fork_trampoline)
         * will be set to the desired value anyway.
         */
        ERET
-       
+
 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 c52a7e2fc5..feb439314f 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

-- 
You are receiving this mail because:
You are the assignee for the bug.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.