Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 1 Sep 2002 00:23:53 -0700 (PDT)
From:      Jonathan Mini <mini@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 16890 for review
Message-ID:  <200209010723.g817Nrm3024462@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://people.freebsd.org/~peter/p4db/chv.cgi?CH=16890

Change 16890 by mini@mini_stylus on 2002/09/01 00:22:54

	Add cpu_set_upcall() back, which we need to initialize
	the pcb and inital trampoline for a kernel thread.

Affected files ...

.. //depot/projects/kse/sys/i386/i386/vm_machdep.c#63 edit

Differences ...

==== //depot/projects/kse/sys/i386/i386/vm_machdep.c#63 (text+ko) ====

@@ -307,10 +307,66 @@
 	td->td_frame = (struct trapframe *)((caddr_t)td->td_pcb - 16) - 1;
 }
 
-struct md_store {
-	struct pcb mds_pcb;
-	struct trapframe mds_frame;
-};
+/*
+ * Initialize machine state (pcb and trap frame) for a new thread about to
+ * upcall.
+ */
+void
+cpu_set_upcall(struct thread *td, void *pcb)
+{
+	struct pcb *pcb2;
+
+	td->td_flags |= TDF_UPCALLING;
+
+	/* Point the pcb to the top of the stack. */
+	pcb2 = td->td_pcb;
+
+	/*
+	 * Copy the upcall pcb.  This loads kernel regs.
+	 * Those not loaded individually below get their default
+	 * values here.
+	 *
+	 * XXXKSE It might be a good idea to simply skip this as
+	 * the values of the other registers may be unimportant.
+	 * This would remove any requirement for knowing the KSE
+	 * at this time (see the matching comment below for
+	 * more analysis) (need a good safe default).
+	 */
+	bcopy(pcb, pcb2, sizeof(*pcb2));
+
+	/*
+	 * Create a new fresh stack for the new thread.
+	 * The -16 is so we can expand the trapframe if we go to vm86.
+	 * Don't forget to set this stack value into whatever supplies
+	 * the address for the fault handlers.
+	 * The contexts are filled in at the time we actually DO the
+	 * upcall as only then do we know which KSE we got.
+	 */
+	td->td_frame = (struct trapframe *)((caddr_t)pcb2 - 16) - 1;
+
+	/*
+	 * Set registers for trampoline to user mode.  Leave space for the
+	 * return address on stack.  These are the kernel mode register values.
+	 */
+	pcb2->pcb_cr3 = vtophys(vmspace_pmap(td->td_proc->p_vmspace)->pm_pdir);
+	pcb2->pcb_edi = 0;
+	pcb2->pcb_esi = (int)fork_return;		    /* trampoline arg */
+	pcb2->pcb_ebp = 0;
+	pcb2->pcb_esp = (int)td->td_frame - sizeof(void *); /* trampoline arg */
+	pcb2->pcb_ebx = (int)td;			    /* trampoline arg */
+	pcb2->pcb_eip = (int)fork_trampoline;
+	pcb2->pcb_psl &= ~(PSL_I);	/* interrupts must be disabled */
+	/*
+	 * If we didn't copy the pcb, we'd need to do the following registers:
+	 * pcb2->pcb_dr*:	cloned above.
+	 * pcb2->pcb_savefpu:	cloned above.
+	 * pcb2->pcb_flags:	cloned above.
+	 * pcb2->pcb_onfault:	cloned above (always NULL here?).
+	 * pcb2->pcb_gs:	cloned above.  XXXKSE ???
+	 * pcb2->pcb_ext:	cleared below.
+	 */
+	 pcb2->pcb_ext = NULL;
+}
 
 void
 cpu_wait(p)

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe p4-projects" in the body of the message




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