Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 14 Apr 2005 03:09:00 GMT
From:      David Xu <davidxu@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 75128 for review
Message-ID:  <200504140309.j3E390bD014975@repoman.freebsd.org>

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

Change 75128 by davidxu@davidxu_celeron on 2005/04/14 03:08:49

	Implement cpu_set_user_tls.

Affected files ...

.. //depot/projects/davidxu_thread/src/sys/i386/i386/vm_machdep.c#7 edit

Differences ...

==== //depot/projects/davidxu_thread/src/sys/i386/i386/vm_machdep.c#7 (text+ko) ====

@@ -469,6 +469,48 @@
 	    (int)arg);
 }
 
+void
+cpu_set_user_tls(struct thread *td, void *tls_base, size_t tls_size,
+	int tls_seg)
+{
+	struct segment_descriptor sd;
+	uint32_t base;
+
+	/*
+	 * Construct a descriptor and store it in the pcb for
+	 * the next context switch.  Also store it in the gdt
+	 * so that the load of tf_fs into %fs will activate it
+	 * at return to userland.
+	 */
+	base = (uint32_t)tls_base;
+	sd.sd_lobase = base & 0xffffff;
+	sd.sd_hibase = (base >> 24) & 0xff;
+	sd.sd_lolimit = 0xffff;	/* 4GB limit, wraps around */
+	sd.sd_hilimit = 0xf;
+	sd.sd_type  = SDT_MEMRWA;
+	sd.sd_dpl   = SEL_UPL;
+	sd.sd_p     = 1;
+	sd.sd_xx    = 0;
+	sd.sd_def32 = 1;
+	sd.sd_gran  = 1;
+	mtx_lock_spin(&sched_lock);
+	if (tls_seg == 0) {
+		/* set %gs */
+		td->td_pcb->pcb_gsd = sd;
+		if (td == curthread) {
+			PCPU_GET(fsgs_gdt)[1] = sd;
+			load_gs(GSEL(GUGS_SEL, SEL_UPL));
+		}
+	} else {
+		/* set %fs */
+		td->td_pcb->pcb_fsd = sd;
+		if (td == curthread)
+			PCPU_GET(fsgs_gdt)[0] = sd;
+		td->td_frame->tf_fs = GSEL(GUFS_SEL, SEL_UPL);
+	}
+	mtx_unlock_spin(&sched_lock);
+}
+
 /*
  * Convert kernel VA to physical address
  */



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