Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 5 Aug 2006 17:07:01 GMT
From:      Oleksandr Tymoshenko <gonzo@FreeBSD.org>
To:        Perforce Change Reviews <perforce@FreeBSD.org>
Subject:   PERFORCE change 103258 for review
Message-ID:  <200608051707.k75H712Z023495@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=103258

Change 103258 by gonzo@gonzo_hq on 2006/08/05 17:06:07

	o Prevent td2 sp register from being overwritten 
	    by td1 one's during pcb copying.
	o Unmask IRQ5 (timer) in cpu_thread_setup. Otherwise
	    we'll get hardclock switched off forever after cpu_throw.

Affected files ...

.. //depot/projects/mips2/src/sys/mips/mips/vm_machdep.c#6 edit

Differences ...

==== //depot/projects/mips2/src/sys/mips/mips/vm_machdep.c#6 (text+ko) ====

@@ -67,10 +67,16 @@
 cpu_fork(register struct thread *td, register struct proc *p2,
     struct thread *td2, int flags)
 {
+	register_t	sp;
+
 	if ((flags & RFPROC) == 0)
 		return;
 
 	cpu_thread_setup(td2);
+	/*
+	 * Preserve SP from beeing overwritten.
+	 */
+	sp = td2->td_pcb->pcb_regs[PCB_REG_SP];
 
 	/* Copy the pcb */
 	bcopy(td->td_pcb, td2->td_pcb, sizeof(struct pcb));
@@ -88,18 +94,24 @@
 	td2->td_pcb->pcb_regs[PCB_REG_S0] = (register_t)fork_return;
 	td2->td_pcb->pcb_regs[PCB_REG_S1] = (register_t)td2;
 	td2->td_pcb->pcb_regs[PCB_REG_S2] = (register_t)td2->td_frame;
+	/*
+	 * Restore original stack.
+       	 */
+	td2->td_pcb->pcb_regs[PCB_REG_SP] = sp;
+
+	/* Setup to release sched_lock in fork_exit(). */
+	td2->td_md.md_spinlock_count = 1;
+	td2->td_md.md_saved_sr = td2->td_pcb->pcb_regs[PCB_REG_SR];
 
 	/*
  	 * Now cpu_switch() can schedule the new process.
 	 */
-
-	/* Setup to release sched_lock in fork_exit(). */
-	td2->td_md.md_spinlock_count = 1;
 }
 
 void
 cpu_switch(struct thread *old, struct thread *new)
 {
+
 	if (!savectx(old->td_pcb)) {
 		pmap_deactivate(old);
 		cpu_throw(old, new);
@@ -171,7 +183,13 @@
 	td->td_pcb =
 	    (struct pcb *)(td->td_kstack + KSTACK_PAGES * PAGE_SIZE) - 1;
 	td->td_frame = (struct trapframe *)td->td_pcb - 1;
-	td->td_pcb->pcb_regs[PCB_REG_SR] = MIPS_SR_INT_IE;
+
+	/*
+	 * Enable interrupts and unmask timer interrupt (HW IRQ5)
+	 */	 
+	td->td_pcb->pcb_regs[PCB_REG_SR] = MIPS_SR_INT_IE | 
+		(((1 << 5) << 8) << 2);
+
 	/* Stack pointer. */
 	td->td_pcb->pcb_regs[PCB_REG_SP] = (register_t)_ALIGN(td->td_frame - 1);
 }



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