WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

[Xen-devel] [PATCH] [Mini-OS] Fix x86 arch_switch_thread

To: xen-devel@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-devel] [PATCH] [Mini-OS] Fix x86 arch_switch_thread
From: Samuel Thibault <samuel.thibault@xxxxxxxxxxxxx>
Date: Fri, 23 Nov 2007 16:11:43 +0000
Delivery-date: Fri, 23 Nov 2007 08:12:20 -0800
Envelope-to: www-data@xxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
Mail-followup-to: Samuel Thibault <samuel.thibault@xxxxxxxxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxx
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: Mutt/1.5.12-2006-07-14
Fix x86 arch_switch_thread by making it pure assembly.
There were missing general register clobbers for x86_64, and BP should
theorically be clobbered too, but gcc does not believe that, so the only
simple safe solution is to use pure assembly

Signed-off-by: Samuel Thibault <samuel.thibault@xxxxxxxxxx>

diff -r 2e05a6173be0 extras/mini-os/arch/x86/x86_32.S
--- a/extras/mini-os/arch/x86/x86_32.S  Fri Nov 23 11:58:11 2007 +0000
+++ b/extras/mini-os/arch/x86/x86_32.S  Fri Nov 23 15:58:24 2007 +0000
@@ -283,3 +283,21 @@
     call *%ebx
     call exit_thread 
     
+ENTRY(__arch_switch_threads)
+    movl 4(%esp), %ecx         /* prev */
+    movl 8(%esp), %edx         /* next */
+    pushl %ebp
+    pushl %ebx
+    pushl %esi
+    pushl %edi
+    movl %esp, (%ecx)          /* save ESP */
+    movl (%edx), %esp          /* restore ESP */
+    movl $1f, 4(%ecx)          /* save EIP */
+    pushl 4(%edx)              /* restore EIP */
+    ret
+1:
+    popl %edi
+    popl %esi
+    popl %ebx
+    popl %ebp
+    ret
diff -r 2e05a6173be0 extras/mini-os/arch/x86/x86_64.S
--- a/extras/mini-os/arch/x86/x86_64.S  Fri Nov 23 11:58:11 2007 +0000
+++ b/extras/mini-os/arch/x86/x86_64.S  Fri Nov 23 15:58:24 2007 +0000
@@ -382,3 +378,23 @@
         call exit_thread 
         
 
+ENTRY(__arch_switch_threads)
+       pushq %rbp
+       pushq %rbx
+       pushq %r12
+       pushq %r13
+       pushq %r14
+       pushq %r15
+       movq %rsp, (%rdi)               /* save ESP */
+       movq (%rsi), %rsp               /* restore ESP */
+       movq $1f, 8(%rdi)               /* save EIP */
+       pushq 8(%rsi)                   /* restore EIP */
+       ret
+1:
+       popq %r15
+       popq %r14
+       popq %r13
+       popq %r12
+       popq %rbx
+       popq %rbp
+       ret
diff -r 2e05a6173be0 extras/mini-os/include/x86/arch_sched.h
--- a/extras/mini-os/include/x86/arch_sched.h   Fri Nov 23 11:58:11 2007 +0000
+++ b/extras/mini-os/include/x86/arch_sched.h   Fri Nov 23 15:58:24 2007 +0000
@@ -11,44 +4,9 @@
     return *current;
 }
 
-#ifdef __i386__
-#define arch_switch_threads(prev, next) do {                            \
-    unsigned long esi,edi;                                              \
-    __asm__ __volatile__("pushfl\n\t"                                   \
-                         "pushl %%ebp\n\t"                              \
-                         "movl %%esp,%0\n\t"         /* save ESP */     \
-                         "movl %4,%%esp\n\t"        /* restore ESP */   \
-                         "movl $1f,%1\n\t"          /* save EIP */      \
-                         "pushl %5\n\t"             /* restore EIP */   \
-                         "ret\n\t"                                      \
-                         "1:\t"                                         \
-                         "popl %%ebp\n\t"                               \
-                         "popfl"                                        \
-                         :"=m" (prev->sp),"=m" (prev->ip),            \
-                          "=S" (esi),"=D" (edi)             \
-                         :"m" (next->sp),"m" (next->ip),              \
-                          "2" (prev), "d" (next));                      \
-} while (0)
-#elif __x86_64__
-#define arch_switch_threads(prev, next) do {                                 \
-    unsigned long rsi,rdi;                                              \
-    __asm__ __volatile__("pushfq\n\t"                                   \
-                         "pushq %%rbp\n\t"                              \
-                         "movq %%rsp,%0\n\t"         /* save RSP */     \
-                         "movq %4,%%rsp\n\t"        /* restore RSP */   \
-                         "movq $1f,%1\n\t"          /* save RIP */      \
-                         "pushq %5\n\t"             /* restore RIP */   \
-                         "ret\n\t"                                      \
-                         "1:\t"                                         \
-                         "popq %%rbp\n\t"                               \
-                         "popfq"                                        \
-                         :"=m" (prev->sp),"=m" (prev->ip),            \
-                          "=S" (rsi),"=D" (rdi)             \
-                         :"m" (next->sp),"m" (next->ip),              \
-                          "2" (prev), "d" (next));                      \
-} while (0)
-#endif
+extern void __arch_switch_threads(unsigned long *prevctx, unsigned long 
*nextctx);
 
+#define arch_switch_threads(prev,next) __arch_switch_threads(&(prev)->sp, 
&(next)->sp)
 
 
           
diff -r f2711b7eae95 -r 36bf1e737b87 extras/mini-os/include/sched.h
--- a/extras/mini-os/include/sched.h    Thu Nov 22 19:55:42 2007 +0000
+++ b/extras/mini-os/include/sched.h    Fri Nov 23 13:21:02 2007 +0000
@@ -10,6 +10,7 @@ struct thread
     char *name;
     char *stack;
 #if !defined(__ia64__)
+    /* keep in that order */
     unsigned long sp;  /* Stack pointer */
     unsigned long ip;  /* Instruction pointer */
 #else /* !defined(__ia64__) */

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-devel] [PATCH] [Mini-OS] Fix x86 arch_switch_thread, Samuel Thibault <=