From b2db68b468d761b954a669ab4defe6963903aae7 Mon Sep 17 00:00:00 2001 From: miod Date: Wed, 5 Jun 2024 19:22:04 +0000 Subject: [PATCH] Pass cpu_fork() function to the new process through caller-saved registers in the pcb rather than on the stack. This makes the code simpler and faster and gets rid of one short timeframe where the stack pointer is only aligned to an 8 byte boundary instead of a 16 byte boundary. --- sys/arch/m88k/m88k/eh_common.S | 15 ++++++--------- sys/arch/m88k/m88k/vm_machdep.c | 24 +++++++++--------------- 2 files changed, 15 insertions(+), 24 deletions(-) diff --git a/sys/arch/m88k/m88k/eh_common.S b/sys/arch/m88k/m88k/eh_common.S index aba3d62c098..d1d775eaa59 100644 --- a/sys/arch/m88k/m88k/eh_common.S +++ b/sys/arch/m88k/m88k/eh_common.S @@ -1,4 +1,4 @@ -/* $OpenBSD: eh_common.S,v 1.65 2023/10/24 13:20:10 claudio Exp $ */ +/* $OpenBSD: eh_common.S,v 1.66 2024/06/05 19:22:04 miod Exp $ */ /* * Mach Operating System * Copyright (c) 1993-1991 Carnegie Mellon University @@ -2202,21 +2202,18 @@ ASLOCAL(do_softint) br 1b /* - * void proc_trampoline(void (*func)(void *), void *proc) + * void proc_trampoline() * * When a process setup by cpu_fork() resumes, it will find itself in - * proc_trampoline, with r31 pointing to a ksigframe. proc_trampoline will - * load func and proc values from ksigframe, call the function, and on return - * pop off the ksigframe. Then, it will return to userland. + * proc_trampoline, with r14 and r15 referring to a function and its + * argument. proc_trampoline will call the function, and return to userland. */ ENTRY(proc_trampoline) bsr proc_trampoline_mi - ld %r1, %r31, 0 /* load func */ - ld %r2, %r31, 4 /* load arg */ - jsr.n %r1 - addu %r31, %r31, 8 /* release ksigframe */ + jsr.n %r14 + or %r2, %r15, 0 /* arg */ /* * Load FPTR with a pointer to the trap frame for the current proc and diff --git a/sys/arch/m88k/m88k/vm_machdep.c b/sys/arch/m88k/m88k/vm_machdep.c index edb3c2e95c4..44a645f268b 100644 --- a/sys/arch/m88k/m88k/vm_machdep.c +++ b/sys/arch/m88k/m88k/vm_machdep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vm_machdep.c,v 1.29 2024/05/21 23:16:06 jsg Exp $ */ +/* $OpenBSD: vm_machdep.c,v 1.30 2024/06/05 19:22:04 miod Exp $ */ /* * Copyright (c) 1998 Steve Murphree, Jr. @@ -72,11 +72,8 @@ void cpu_fork(struct proc *p1, struct proc *p2, void *stack, void *tcb, void (*func)(void *), void *arg) { - struct ksigframe { - void (*func)(void *); - void *arg; - } *ksfp; extern void proc_trampoline(void); + struct m88100_pcb *mdpcb = &p2->p_addr->u_pcb.kernel_state; /* Copy pcb from p1 to p2. */ if (p1 == curproc) { @@ -99,19 +96,16 @@ cpu_fork(struct proc *p1, struct proc *p2, void *stack, void *tcb, if (tcb != NULL) USER_REGS(p2)->r[27] = (u_int)tcb; - ksfp = (struct ksigframe *)((char *)p2->p_addr + USPACE) - 1; - ksfp->func = func; - ksfp->arg = arg; - /* - * When this process resumes, r31 will be ksfp and - * the process will be at the beginning of proc_trampoline(). - * proc_trampoline will execute the function func, pop off - * ksfp frame, and resume to userland. + * When this process resumes, the process will be at the beginning + * of proc_trampoline(). proc_trampoline will execute the function + * func and resume to userland. */ - p2->p_addr->u_pcb.kernel_state.pcb_sp = (u_int)ksfp; - p2->p_addr->u_pcb.kernel_state.pcb_pc = (u_int)proc_trampoline; + mdpcb->pcb_r14 = (u_int)func; + mdpcb->pcb_r15 = (u_int)arg; + mdpcb->pcb_sp = (u_int)((char *)p2->p_addr + USPACE); + mdpcb->pcb_pc = (u_int)proc_trampoline; } /* -- 2.20.1