Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 3 Jun 2002 14:42:08 -0700 (PDT)
From:      Julian Elischer <julian@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 12336 for review
Message-ID:  <200206032142.g53Lg8q52366@freefall.freebsd.org>

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

Change 12336 by julian@julian_ref on 2002/06/03 14:41:50

	Additions to Alpha support
	from: Bernd Walter <ticso@cicely5.cicely.de>

Affected files ...

... //depot/projects/kse/sys/alpha/alpha/vm_machdep.c#23 edit

Differences ...

==== //depot/projects/kse/sys/alpha/alpha/vm_machdep.c#23 (text+ko) ====

@@ -242,23 +242,26 @@
 void
 cpu_exit(struct thread *td)
 {
-	/* KSEXXX */
+
 	alpha_fpstate_drop(td);
 }
 
 void
 cpu_thread_exit(struct thread *td)
 {
-	/* KSEXXX */
+
+	return;
 }
 
 void
 cpu_thread_setup(struct thread *td)
 {
-	/* KSEXXX */
+
+	td->td_pcb =
+	     (struct pcb *)(td->td_kstack + KSTACK_PAGES * PAGE_SIZE) - 1;
+	td->td_frame = (struct trapframe *)((caddr_t)td->td_pcb) - 1;
 }
 
-/* KSEXXX */
 struct md_store {
 	struct pcb mds_pcb;
 	struct trapframe mds_frame;
@@ -267,13 +270,72 @@
 void
 cpu_save_upcall(struct thread *td, struct kse *newkse)
 {
-	/* KSEXXX */
+
+	newkse->ke_mdstorage = malloc(sizeof(struct md_store), M_TEMP,
+	    M_WAITOK);
+	/* Note: use of M_WAITOK means it won't fail. */
+	/* set up shortcuts in MI section */
+	newkse->ke_pcb =
+	    &(((struct md_store *)(newkse->ke_mdstorage))->mds_pcb);
+	newkse->ke_frame =
+	    &(((struct md_store *)(newkse->ke_mdstorage))->mds_frame);
+
+	/* Copy the upcall pcb. Kernel mode & fp regs are here. */
+	/* XXXKSE this may be un-needed */
+	bcopy(td->td_pcb, newkse->ke_pcb, sizeof(struct pcb));
+
+	/* This copies most of the user mode register values. */
+	bcopy(td->td_frame, newkse->ke_frame, sizeof(struct trapframe));
 }
 
 void
 cpu_set_upcall(struct thread *td, void *pcb)
 {
-	/* KSEXXX */
+	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.
+	 * 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) - 1;
+
+	/*
+	 * Arrange for continuation at fork_return(), which
+	 * will return to exception_return().  Note that the child
+	 * process doesn't stay in the kernel for long!
+	 */
+	pcb2->pcb_hw.apcb_ksp = (u_int64_t)td->td_frame;
+	pcb2->pcb_context[0] = (u_int64_t)fork_return;	 	/* s0: a0 */
+	pcb2->pcb_context[1] = (u_int64_t)exception_return;	/* s1: ra */
+	pcb2->pcb_context[2] = (u_long)td;			/* s2: a1 */
+	pcb2->pcb_context[7] = (u_int64_t)fork_trampoline;	/* ra: magic*/
+#ifdef SMP
+	/*
+	 * We start off at a nesting level of 1 within the kernel.
+	 */
+	td->td_md.md_kernnest = 1;
+#endif
 }
 
 /*
@@ -284,19 +346,46 @@
 void
 cpu_set_retval(struct thread *td, int retval, int aux, int success)
 {
-	/* KSEXXX */
+	struct trapframe *frame;
+
+	frame = td->td_frame;
+	frame->tf_regs[FRAME_V0] = (u_int64_t)retval;
+	frame->tf_regs[FRAME_A3] = (success) ? 0 : ~0;
+	frame->tf_regs[FRAME_A4] = (u_int64_t)aux;
 }
 
 void
 cpu_free_kse_mdstorage(struct kse *kse)
 {
-	/* KSEXXX */
+
+	free(kse->ke_mdstorage, M_TEMP);
+	kse->ke_mdstorage = NULL;
+	kse->ke_pcb = NULL;
+	kse->ke_frame = NULL;
 }
 
 int
 cpu_export_context(struct thread *td)
 {
-	/* KSEXXX */
+	/* XXXKSE */
+#if 0
+	struct trapframe *frame;
+	struct thread_mailbox *tm;
+	struct trapframe *uframe;
+	int error;
+
+	frame = td->td_frame;
+	tm = td->td_mailbox;
+	uframe = &tm->ctx.tfrm.tf_tf;
+	error = copyout(frame, uframe, sizeof(*frame));
+	/*
+	 * "What about the fp regs?" I hear you ask.... XXXKSE
+	 * Don't know where gs and "onstack" come from.
+	 * May need to fiddle a few other values too.
+	 */
+	return (error);
+#endif
+	return (0);
 }
 
 void

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?200206032142.g53Lg8q52366>