Use callee-saved registers to pass args through fork_trampoline().

This commit is contained in:
br 2016-02-17 13:43:43 +00:00
parent 13e5393598
commit 97821f014d
2 changed files with 9 additions and 17 deletions

View File

@ -109,14 +109,10 @@ ENTRY(cpu_switch)
/* Save the old context. */
ld x13, TD_PCB(a0)
/* Store the callee-saved registers */
/* Store ra, sp and the callee-saved registers */
sd ra, (PCB_RA)(x13)
sd sp, (PCB_SP)(x13)
/* We use these in fork_trampoline */
sd t0, (PCB_T + 0 * 8)(x13)
sd t1, (PCB_T + 1 * 8)(x13)
/* s[0-11] */
sd s0, (PCB_S + 0 * 8)(x13)
sd s1, (PCB_S + 1 * 8)(x13)
@ -167,10 +163,6 @@ ENTRY(cpu_switch)
ld ra, (PCB_RA)(x13)
ld sp, (PCB_SP)(x13)
/* We use these in fork_trampoline */
ld t0, (PCB_T + 0 * 8)(x13)
ld t1, (PCB_T + 1 * 8)(x13)
/* s[0-11] */
ld s0, (PCB_S + 0 * 8)(x13)
ld s1, (PCB_S + 1 * 8)(x13)
@ -195,8 +187,8 @@ END(cpu_switch)
*/
ENTRY(fork_trampoline)
mv a0, x5
mv a1, x6
mv a0, s0
mv a1, s1
mv a2, sp
call _C_LABEL(fork_exit)

View File

@ -97,8 +97,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_t[0] = (uintptr_t)fork_return;
td2->td_pcb->pcb_t[1] = (uintptr_t)td2;
td2->td_pcb->pcb_s[0] = (uintptr_t)fork_return;
td2->td_pcb->pcb_s[1] = (uintptr_t)td2;
td2->td_pcb->pcb_ra = (uintptr_t)fork_trampoline;
td2->td_pcb->pcb_sp = (uintptr_t)td2->td_frame;
@ -165,8 +165,8 @@ cpu_set_upcall(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_t[0] = (uintptr_t)fork_return;
td->td_pcb->pcb_t[1] = (uintptr_t)td;
td->td_pcb->pcb_s[0] = (uintptr_t)fork_return;
td->td_pcb->pcb_s[1] = (uintptr_t)td;
td->td_pcb->pcb_ra = (uintptr_t)fork_trampoline;
td->td_pcb->pcb_sp = (uintptr_t)td->td_frame;
@ -240,8 +240,8 @@ void
cpu_set_fork_handler(struct thread *td, void (*func)(void *), void *arg)
{
td->td_pcb->pcb_t[0] = (uintptr_t)func;
td->td_pcb->pcb_t[1] = (uintptr_t)arg;
td->td_pcb->pcb_s[0] = (uintptr_t)func;
td->td_pcb->pcb_s[1] = (uintptr_t)arg;
td->td_pcb->pcb_ra = (uintptr_t)fork_trampoline;
td->td_pcb->pcb_sp = (uintptr_t)td->td_frame;
}