[Openmcl-cvs-notifications] r11370 - in /trunk/source/lisp-kernel: thread_manager.c x86-spentry32.s x86-subprims32.s

gb at clozure.com gb at clozure.com
Sun Nov 16 05:58:10 EST 2008


Author: gb
Date: Sun Nov 16 05:58:10 2008
New Revision: 11370

Log:
Using i386_set_ldt() to point %fs at the tcr on 32-bit FreeBSD doesn't work
on a 64-bit kernel.  Using i386_set_fsbase does work on both 32-bit and
64-bit kernels, but doesn't allow writing to %fs: at least by the time
we've called i386_set_fsbase() on thread startup, %fs contains an appropria=
te
selector and it never changes throughout the life of the thread.

Modified:
    trunk/source/lisp-kernel/thread_manager.c
    trunk/source/lisp-kernel/x86-spentry32.s
    trunk/source/lisp-kernel/x86-subprims32.s

Modified: trunk/source/lisp-kernel/thread_manager.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- trunk/source/lisp-kernel/thread_manager.c (original)
+++ trunk/source/lisp-kernel/thread_manager.c Sun Nov 16 05:58:10 2008
@@ -1102,10 +1102,14 @@
 #include <machine/sysarch.h>
 =

 /* It'd be tempting to use i386_set_fsbase() here, but there doesn't
-   seem to be any way to free the GDT entry it creates. */
+   seem to be any way to free the GDT entry it creates.  Actually,
+   it's not clear that that really sets a GDT entry; let's see */
+
+#define FREEBSD_USE_SET_FSBASE 1
 void
 setup_tcr_extra_segment(TCR *tcr)
 {
+#if !FREEBSD_USE_SET_FSBASE
   struct segment_descriptor sd;
   uintptr_t addr =3D (uintptr_t)tcr;
   unsigned int size =3D sizeof(*tcr);
@@ -1115,6 +1119,9 @@
   sd.sd_hilimit =3D ((size - 1) >> 16) & 0xf;
   sd.sd_lobase =3D addr & ((1<<24)-1);
   sd.sd_hibase =3D (addr>>24)&0xff;
+
+
+
   sd.sd_type =3D 18;
   sd.sd_dpl =3D SEL_UPL;
   sd.sd_p =3D 1;
@@ -1129,19 +1136,34 @@
   } else {
     tcr->ldt_selector =3D LSEL(i,SEL_UPL);
   }
+#else
+  if (i386_set_fsbase((void*)tcr)) {
+    perror("i386_set_fsbase");
+    exit(1);
+  }
+  /* Once we've called i386_set_fsbase, we can't write to %fs. */
+  tcr->ldt_selector =3D GSEL(GUFS_SEL, SEL_UPL);
+#endif
 }
 =

 void =

 free_tcr_extra_segment(TCR *tcr)
 {
+#if FREEBSD_USE_SET_FSBASE
+  /* On a 32-bit kernel, this allocates a GDT entry.  It's not clear
+     what it would mean to deallocate that entry. */
+  /* If we're running on a 64-bit kernel, we can't write to %fs */
+#else
   int idx =3D tcr->ldt_selector >> 3;
   /* load %fs with null segment selector */
   __asm__ volatile ("mov %0,%%fs" : : "r"(0));
   if (i386_set_ldt(idx, NULL, 1) < 0)
     perror("i386_set_ldt");
+#endif
   tcr->ldt_selector =3D 0;
 }
 #endif
+
 #ifdef SOLARIS
 #include <sys/sysi86.h>
 =


Modified: trunk/source/lisp-kernel/x86-spentry32.s
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- trunk/source/lisp-kernel/x86-spentry32.s (original)
+++ trunk/source/lisp-kernel/x86-spentry32.s Sun Nov 16 05:58:10 2008
@@ -4262,13 +4262,15 @@
 	__(push %ebx)
 	__(push %ebp)
 	__(box_fixnum(%eax,%esi))	/* put callback index in arg_y */
-	__(ref_global(get_tcr,%eax))
-	__(subl $12,%esp)		/* alignment */
-	__(push $1)			/* stack now 16-byte aligned */
-	__(call *%eax)
-	__(addl $16,%esp)		/* discard arg, alignment words */
-	/* linear TCR addr now in %eax */
-	__(movw tcr.ldt_selector(%eax), %rcontext_reg)
+        __ifndef([FREEBSD])
+	 __(ref_global(get_tcr,%eax))
+	 __(subl $12,%esp)		/* alignment */
+	 __(push $1)			/* stack now 16-byte aligned */
+	 __(call *%eax)
+	 __(addl $16,%esp)		/* discard arg, alignment words */
+	 /* linear TCR addr now in %eax */
+	 __(movw tcr.ldt_selector(%eax), %rcontext_reg)
+        __endif
 =

         /* ebp is 16-byte aligned, and we've pushed 4 words.  Make
           sure that when we push old foreign_sp, %esp will be 16-byte

Modified: trunk/source/lisp-kernel/x86-subprims32.s
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D
--- trunk/source/lisp-kernel/x86-subprims32.s (original)
+++ trunk/source/lisp-kernel/x86-subprims32.s Sun Nov 16 05:58:10 2008
@@ -74,7 +74,9 @@
 	__(push %esi)
 	__(push %ebx)
 	__(mov 8(%ebp), %ebx)	/* get tcr */
-	__(movw tcr.ldt_selector(%ebx), %rcontext_reg)
+        __ifndef([FREEBSD])
+	 __(movw tcr.ldt_selector(%ebx), %rcontext_reg)
+        __endif
         __(movl 8(%ebp),%eax)
         __(cmpl rcontext(tcr.linear),%eax)
         __(je 0f)



More information about the Openmcl-cvs-notifications mailing list