Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch/xen Move some of the context switching code into a ...



details:   https://anonhg.NetBSD.org/src/rev/95a1d8d28448
branches:  trunk
changeset: 566023:95a1d8d28448
user:      cl <cl%NetBSD.org@localhost>
date:      Sun Apr 25 19:01:27 2004 +0000

description:
Move some of the context switching code into a C function.

diffstat:

 sys/arch/xen/i386/locore.S  |  94 ++++++--------------------------------------
 sys/arch/xen/i386/machdep.c |  18 +++++++-
 sys/arch/xen/include/cpu.h  |   3 +-
 3 files changed, 31 insertions(+), 84 deletions(-)

diffs (198 lines):

diff -r de59a590b4ce -r 95a1d8d28448 sys/arch/xen/i386/locore.S
--- a/sys/arch/xen/i386/locore.S        Sun Apr 25 18:50:44 2004 +0000
+++ b/sys/arch/xen/i386/locore.S        Sun Apr 25 19:01:27 2004 +0000
@@ -1,5 +1,5 @@
-/*     $NetBSD: locore.S,v 1.3 2004/04/06 15:56:32 cl Exp $    */
-/*     NetBSD: locore.S,v 1.25 2004/03/26 19:05:33 drochner Exp        */
+/*     $NetBSD: locore.S,v 1.4 2004/04/25 19:01:27 cl Exp $    */
+/*     NetBSD: locore.S,v 1.26 2004/04/12 13:17:46 yamt Exp    */
 
 /*-
  * Copyright (c) 1998, 2000 The NetBSD Foundation, Inc.
@@ -431,9 +431,6 @@
 
        call    xpmap_init
 
-       movl    $__HYPERVISOR_fpu_taskswitch,%eax
-       TRAP_INSTR
-
        /* cr0 is 0x8005003b */
 
        /* Relocate atdevbase. */
@@ -1564,48 +1561,9 @@
        movl    PCB_ESP(%edi),%esp
        movl    PCB_EBP(%edi),%ebp
 
-#ifdef XENDEBUG_LOW
-       movl    _C_LABEL(xen_once),%ecx
-       testl   %ecx,%ecx
-       jz      1f
-       movl    $2,%ecx
-       movl    %ecx,_C_LABEL(xen_once)
-1:
-       call    _C_LABEL(xen_dbg2)
-#endif
-
-#ifdef XENDEBUG_LOW
-       #call   _C_LABEL(xen_dbg2)
-       movl    %ds,%ecx
-       movl    %cs,%ebx
-       pushl   %ecx
-       pushl   %ebx
-       call    _C_LABEL(xen_dbg3)
-       addl    $8,%esp
-#endif
-
-       /* Switch TSS. */
-       movl    PCB_TSS_ESP0(%edi),%ecx
-       movl    PCB_TSS_SS0(%edi),%ebx
-       movl    $__HYPERVISOR_stack_switch,%eax
-       TRAP_INSTR
-
-#ifdef XENDEBUG_LOW
-       pushl   PCB_TSS_SS0(%edi)
-       pushl   PCB_TSS_ESP0(%edi)
-       call    _C_LABEL(xen_dbg1)
-       addl    $8,%esp
-#endif
-
-       /* Reset FPU state if necessary. */
-       movl    PCB_CR0(%edi),%ecx
-       testl   $CR0_TS,%ecx
-       jz      1f
-       andl    $~CR0_TS,%ecx
-       movl    %ecx,PCB_CR0(%edi)
-       movl    $__HYPERVISOR_fpu_taskswitch,%eax
-       TRAP_INSTR
-1:
+       pushl   %edi
+       call    _C_LABEL(i386_switch_context)
+       addl    $4,%esp
 
        /* Record new pcb. */
        SET_CURPCB(%edi)
@@ -1765,31 +1723,17 @@
 #if 0
        /* Don't bother with the rest if switching to a system process. */
        testl   $P_SYSTEM,L_FLAG(%edi); XXX NJWLWP lwp's don't have P_SYSTEM!
-       jnz     switch_restored
+       jnz     switch_restored ; XXX skip stack_switch+pmap_activate
 #endif
 
-       /* Switch TSS. */
-       movl    PCB_TSS_ESP0(%esi),%ecx
-       movl    PCB_TSS_SS0(%esi),%ebx
-       movl    $__HYPERVISOR_stack_switch,%eax
-       TRAP_INSTR
-
        pushl   %edi
        call    _C_LABEL(pmap_activate)         # pmap_activate(p)
        addl    $4,%esp
 
-#if 0
-switch_restored:
-#endif
-       /* Reset FPU state if necessary. */
-       movl    PCB_CR0(%esi),%ecx
-       testl   $CR0_TS,%ecx
-       jz      1f
-       andl    $~CR0_TS,%ecx
-       movl    %ecx,PCB_CR0(%esi)
-       movl    $__HYPERVISOR_fpu_taskswitch,%eax
-       TRAP_INSTR
-1:
+       pushl   %esi
+       call    _C_LABEL(i386_switch_context)
+       addl    $4,%esp
+
        /* Record new pcb. */
        SET_CURPCB(%esi)
 
@@ -1909,21 +1853,9 @@
        movl    PCB_ESP(%esi),%esp
        movl    PCB_EBP(%esi),%ebp
 
-       /* Switch TSS. */
-       movl    PCB_TSS_ESP0(%esi),%ecx
-       movl    PCB_TSS_SS0(%esi),%ebx
-       movl    $__HYPERVISOR_stack_switch,%eax
-       TRAP_INSTR
-
-       /* Reset FPU state if necessary. */
-       movl    PCB_CR0(%esi),%ecx
-       testl   $CR0_TS,%ecx
-       jz      1f
-       andl    $~CR0_TS,%ecx
-       movl    %ecx,PCB_CR0(%esi)
-       movl    $__HYPERVISOR_fpu_taskswitch,%eax
-       TRAP_INSTR
-1:
+       pushl   %esi
+       call    _C_LABEL(i386_switch_context)
+       addl    $4,%esp
 
        /* Record new pcb. */
        SET_CURPCB(%esi)
diff -r de59a590b4ce -r 95a1d8d28448 sys/arch/xen/i386/machdep.c
--- a/sys/arch/xen/i386/machdep.c       Sun Apr 25 18:50:44 2004 +0000
+++ b/sys/arch/xen/i386/machdep.c       Sun Apr 25 19:01:27 2004 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: machdep.c,v 1.4 2004/04/11 00:44:15 cl Exp $   */
+/*     $NetBSD: machdep.c,v 1.5 2004/04/25 19:01:27 cl Exp $   */
 /*     NetBSD: machdep.c,v 1.552 2004/03/24 15:34:49 atatat Exp        */
 
 /*-
@@ -73,7 +73,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.4 2004/04/11 00:44:15 cl Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.5 2004/04/25 19:01:27 cl Exp $");
 
 #include "opt_beep.h"
 #include "opt_compat_ibcs2.h"
@@ -408,6 +408,7 @@
        ltr(lwp0.l_md.md_tss_sel);
        lldt(pcb->pcb_ldt_sel);
 #else
+       HYPERVISOR_fpu_taskswitch();
        XENPRINTF(("lwp tss sp %p ss %04x/%04x\n",
                      (void *)pcb->pcb_tss.tss_esp0,
                      pcb->pcb_tss.tss_ss0, IDXSEL(pcb->pcb_tss.tss_ss0)));
@@ -437,6 +438,19 @@
 }
 
 /*
+ * Switch context:
+ * - honor CR0_TS in saved CR0 and request DNA exception on FPU use
+ * - switch stack pointer for user->kernel transition
+ */
+void
+i386_switch_context(struct pcb *new)
+{
+       if (new->pcb_cr0 & CR0_TS)
+               HYPERVISOR_fpu_taskswitch();
+       HYPERVISOR_stack_switch(new->pcb_tss.tss_ss0, new->pcb_tss.tss_esp0);
+}
+
+/*
  * sysctl helper routine for machdep.tm* nodes.
  */
 static int
diff -r de59a590b4ce -r 95a1d8d28448 sys/arch/xen/include/cpu.h
--- a/sys/arch/xen/include/cpu.h        Sun Apr 25 18:50:44 2004 +0000
+++ b/sys/arch/xen/include/cpu.h        Sun Apr 25 19:01:27 2004 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cpu.h,v 1.2 2004/04/24 18:55:02 cl Exp $       */
+/*     $NetBSD: cpu.h,v 1.3 2004/04/25 19:01:27 cl Exp $       */
 /*     NetBSD: cpu.h,v 1.113 2004/02/20 17:35:01 yamt Exp      */
 
 /*-
@@ -360,6 +360,7 @@
 void   cpu_reset(void);
 void   i386_init_pcb_tss_ldt(struct cpu_info *);
 void   i386_proc0_tss_ldt_init(void);
+void   i386_switch_context(struct pcb *);
 
 /* identcpu.c */
 extern int tmx86_has_longrun;



Home | Main Index | Thread Index | Old Index