ICU/APIC cleanup part 2/many.
[dragonfly.git] / sys / platform / pc32 / i386 / swtch.s
1 /*
2  * Copyright (c) 2003,2004 The DragonFly Project.  All rights reserved.
3  * 
4  * This code is derived from software contributed to The DragonFly Project
5  * by Matthew Dillon <dillon@backplane.com>
6  * 
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in
15  *    the documentation and/or other materials provided with the
16  *    distribution.
17  * 3. Neither the name of The DragonFly Project nor the names of its
18  *    contributors may be used to endorse or promote products derived
19  *    from this software without specific, prior written permission.
20  * 
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
25  * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
31  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32  * SUCH DAMAGE.
33  * 
34  * Copyright (c) 1990 The Regents of the University of California.
35  * All rights reserved.
36  *
37  * This code is derived from software contributed to Berkeley by
38  * William Jolitz.
39  *
40  * Redistribution and use in source and binary forms, with or without
41  * modification, are permitted provided that the following conditions
42  * are met:
43  * 1. Redistributions of source code must retain the above copyright
44  *    notice, this list of conditions and the following disclaimer.
45  * 2. Redistributions in binary form must reproduce the above copyright
46  *    notice, this list of conditions and the following disclaimer in the
47  *    documentation and/or other materials provided with the distribution.
48  * 3. All advertising materials mentioning features or use of this software
49  *    must display the following acknowledgement:
50  *      This product includes software developed by the University of
51  *      California, Berkeley and its contributors.
52  * 4. Neither the name of the University nor the names of its contributors
53  *    may be used to endorse or promote products derived from this software
54  *    without specific prior written permission.
55  *
56  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
57  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
58  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
59  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
60  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
61  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
62  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
63  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
64  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
65  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
66  * SUCH DAMAGE.
67  *
68  * $FreeBSD: src/sys/i386/i386/swtch.s,v 1.89.2.10 2003/01/23 03:36:24 ps Exp $
69  * $DragonFly: src/sys/platform/pc32/i386/swtch.s,v 1.39 2005/11/02 09:14:58 dillon Exp $
70  */
71
72 #include "use_npx.h"
73
74 #include <sys/rtprio.h>
75
76 #include <machine/asmacros.h>
77 #include <machine/segments.h>
78 #include <machine/ipl.h>
79
80 #include <machine/pmap.h>
81 #include <machine/smptests.h>           /** GRAB_LOPRIO */
82 #include <arch/apic/apicreg.h>
83 #include <machine/lock.h>
84
85 #include "assym.s"
86
87 #if defined(SMP)
88 #define MPLOCKED        lock ;
89 #else
90 #define MPLOCKED
91 #endif
92
93         .data
94
95         .globl  panic
96
97 #if defined(SWTCH_OPTIM_STATS)
98         .globl  swtch_optim_stats, tlb_flush_count
99 swtch_optim_stats:      .long   0               /* number of _swtch_optims */
100 tlb_flush_count:        .long   0
101 #endif
102
103         .text
104
105
106 /*
107  * cpu_heavy_switch(next_thread)
108  *
109  *      Switch from the current thread to a new thread.  This entry
110  *      is normally called via the thread->td_switch function, and will
111  *      only be called when the current thread is a heavy weight process.
112  *
113  *      Some instructions have been reordered to reduce pipeline stalls.
114  *
115  *      YYY disable interrupts once giant is removed.
116  */
117 ENTRY(cpu_heavy_switch)
118         /*
119          * Save general regs
120          */
121         movl    PCPU(curthread),%ecx
122         movl    (%esp),%eax                     /* (reorder optimization) */
123         movl    TD_PCB(%ecx),%edx               /* EDX = PCB */
124         movl    %eax,PCB_EIP(%edx)              /* return PC may be modified */
125         movl    %ebx,PCB_EBX(%edx)
126         movl    %esp,PCB_ESP(%edx)
127         movl    %ebp,PCB_EBP(%edx)
128         movl    %esi,PCB_ESI(%edx)
129         movl    %edi,PCB_EDI(%edx)
130         movl    %gs,PCB_GS(%edx)
131
132         movl    %ecx,%ebx                       /* EBX = curthread */
133         movl    TD_PROC(%ecx),%ecx
134         movl    PCPU(cpuid), %eax
135         movl    P_VMSPACE(%ecx), %ecx           /* ECX = vmspace */
136         MPLOCKED btrl   %eax, VM_PMAP+PM_ACTIVE(%ecx)
137
138         /*
139          * Push the LWKT switch restore function, which resumes a heavy
140          * weight process.  Note that the LWKT switcher is based on
141          * TD_SP, while the heavy weight process switcher is based on
142          * PCB_ESP.  TD_SP is usually two ints pushed relative to
143          * PCB_ESP.  We push the flags for later restore by cpu_heavy_restore.
144          */
145         pushfl
146         pushl   $cpu_heavy_restore
147         movl    %esp,TD_SP(%ebx)
148
149         /*
150          * Save debug regs if necessary
151          */
152         movb    PCB_FLAGS(%edx),%al
153         andb    $PCB_DBREGS,%al
154         jz      1f                              /* no, skip over */
155         movl    %dr7,%eax                       /* yes, do the save */
156         movl    %eax,PCB_DR7(%edx)
157         andl    $0x0000fc00, %eax               /* disable all watchpoints */
158         movl    %eax,%dr7
159         movl    %dr6,%eax
160         movl    %eax,PCB_DR6(%edx)
161         movl    %dr3,%eax
162         movl    %eax,PCB_DR3(%edx)
163         movl    %dr2,%eax
164         movl    %eax,PCB_DR2(%edx)
165         movl    %dr1,%eax
166         movl    %eax,PCB_DR1(%edx)
167         movl    %dr0,%eax
168         movl    %eax,PCB_DR0(%edx)
169 1:
170  
171 #if NNPX > 0
172         /*
173          * Save the FP state if we have used the FP.  Note that calling
174          * npxsave will NULL out PCPU(npxthread).
175          */
176         cmpl    %ebx,PCPU(npxthread)
177         jne     1f
178         pushl   TD_SAVEFPU(%ebx)
179         call    npxsave                 /* do it in a big C function */
180         addl    $4,%esp                 /* EAX, ECX, EDX trashed */
181 1:
182 #endif  /* NNPX > 0 */
183
184         /*
185          * Switch to the next thread, which was passed as an argument
186          * to cpu_heavy_switch().  Due to the eflags and switch-restore
187          * function we pushed, the argument is at 12(%esp).  Set the current
188          * thread, load the stack pointer, and 'ret' into the switch-restore
189          * function.
190          *
191          * The switch restore function expects the new thread to be in %eax
192          * and the old one to be in %ebx.
193          *
194          * There is a one-instruction window where curthread is the new
195          * thread but %esp still points to the old thread's stack, but
196          * we are protected by a critical section so it is ok.
197          */
198         movl    12(%esp),%eax           /* EAX = newtd, EBX = oldtd */
199         movl    %eax,PCPU(curthread)
200         movl    TD_SP(%eax),%esp
201         ret
202
203 /*
204  *  cpu_exit_switch()
205  *
206  *      The switch function is changed to this when a thread is going away
207  *      for good.  We have to ensure that the MMU state is not cached, and
208  *      we don't bother saving the existing thread state before switching.
209  *
210  *      At this point we are in a critical section and this cpu owns the
211  *      thread's token, which serves as an interlock until the switchout is
212  *      complete.
213  */
214 ENTRY(cpu_exit_switch)
215         /*
216          * Get us out of the vmspace
217          */
218         movl    IdlePTD,%ecx
219         movl    %cr3,%eax
220         cmpl    %ecx,%eax
221         je      1f
222         movl    %ecx,%cr3
223 1:
224         movl    PCPU(curthread),%ebx
225         /*
226          * Switch to the next thread.  RET into the restore function, which
227          * expects the new thread in EAX and the old in EBX.
228          *
229          * There is a one-instruction window where curthread is the new
230          * thread but %esp still points to the old thread's stack, but
231          * we are protected by a critical section so it is ok.
232          */
233         movl    4(%esp),%eax
234         movl    %eax,PCPU(curthread)
235         movl    TD_SP(%eax),%esp
236         ret
237
238 /*
239  * cpu_heavy_restore()  (current thread in %eax on entry)
240  *
241  *      Restore the thread after an LWKT switch.  This entry is normally
242  *      called via the LWKT switch restore function, which was pulled 
243  *      off the thread stack and jumped to.
244  *
245  *      This entry is only called if the thread was previously saved
246  *      using cpu_heavy_switch() (the heavy weight process thread switcher),
247  *      or when a new process is initially scheduled.  The first thing we
248  *      do is clear the TDF_RUNNING bit in the old thread and set it in the
249  *      new thread.
250  *
251  *      NOTE: The process may be in any state, not necessarily SRUN, because
252  *      a preemption switch may interrupt the process and then return via 
253  *      cpu_heavy_restore.
254  *
255  *      YYY theoretically we do not have to restore everything here, a lot
256  *      of this junk can wait until we return to usermode.  But for now
257  *      we restore everything.
258  *
259  *      YYY the PCB crap is really crap, it makes startup a bitch because
260  *      we can't switch away.
261  *
262  *      YYY note: spl check is done in mi_switch when it splx()'s.
263  */
264
265 ENTRY(cpu_heavy_restore)
266         popfl
267         movl    TD_PCB(%eax),%edx               /* EDX = PCB */
268         movl    TD_PROC(%eax),%ecx
269
270 #if defined(SWTCH_OPTIM_STATS)
271         incl    _swtch_optim_stats
272 #endif
273         /*
274          * Tell the pmap that our cpu is using the VMSPACE now.  We cannot
275          * safely test/reload %cr3 until after we have set the bit in the
276          * pmap (remember, we do not hold the MP lock in the switch code).
277          */
278         movl    P_VMSPACE(%ecx), %ecx           /* ECX = vmspace */
279         movl    PCPU(cpuid), %esi
280         MPLOCKED btsl   %esi, VM_PMAP+PM_ACTIVE(%ecx)
281
282         /*
283          * Restore the MMU address space.  If it is the same as the last
284          * thread we don't have to invalidate the tlb (i.e. reload cr3).
285          * YYY which naturally also means that the PM_ACTIVE bit had better
286          * already have been set before we set it above, check? YYY
287          */
288         movl    %cr3,%esi
289         movl    PCB_CR3(%edx),%ecx
290         cmpl    %esi,%ecx
291         je      4f
292 #if defined(SWTCH_OPTIM_STATS)
293         decl    _swtch_optim_stats
294         incl    _tlb_flush_count
295 #endif
296         movl    %ecx,%cr3
297 4:
298         /*
299          * Clear TDF_RUNNING flag in old thread only after cleaning up
300          * %cr3.  The target thread is already protected by being TDF_RUNQ
301          * so setting TDF_RUNNING isn't as big a deal.
302          */
303         andl    $~TDF_RUNNING,TD_FLAGS(%ebx)
304         orl     $TDF_RUNNING,TD_FLAGS(%eax)
305
306         /*
307          * Deal with the PCB extension, restore the private tss
308          */
309         movl    PCB_EXT(%edx),%edi      /* check for a PCB extension */
310         movl    $1,%ebx                 /* maybe mark use of a private tss */
311         testl   %edi,%edi
312         jnz     2f
313
314         /*
315          * Going back to the common_tss.  We may need to update TSS_ESP0
316          * which sets the top of the supervisor stack when entering from
317          * usermode.  The PCB is at the top of the stack but we need another
318          * 16 bytes to take vm86 into account.
319          */
320         leal    -16(%edx),%ebx
321         movl    %ebx, PCPU(common_tss) + TSS_ESP0
322
323         cmpl    $0,PCPU(private_tss)    /* don't have to reload if      */
324         je      3f                      /* already using the common TSS */
325
326         subl    %ebx,%ebx               /* unmark use of private tss */
327
328         /*
329          * Get the address of the common TSS descriptor for the ltr.
330          * There is no way to get the address of a segment-accessed variable
331          * so we store a self-referential pointer at the base of the per-cpu
332          * data area and add the appropriate offset.
333          */
334         movl    $gd_common_tssd, %edi
335         addl    %fs:0, %edi
336
337         /*
338          * Move the correct TSS descriptor into the GDT slot, then reload
339          * ltr.
340          */
341 2:
342         movl    %ebx,PCPU(private_tss)          /* mark/unmark private tss */
343         movl    PCPU(tss_gdt), %ebx             /* entry in GDT */
344         movl    0(%edi), %eax
345         movl    %eax, 0(%ebx)
346         movl    4(%edi), %eax
347         movl    %eax, 4(%ebx)
348         movl    $GPROC0_SEL*8, %esi             /* GSEL(entry, SEL_KPL) */
349         ltr     %si
350
351 3:
352         /*
353          * Restore general registers.
354          */
355         movl    PCB_EBX(%edx),%ebx
356         movl    PCB_ESP(%edx),%esp
357         movl    PCB_EBP(%edx),%ebp
358         movl    PCB_ESI(%edx),%esi
359         movl    PCB_EDI(%edx),%edi
360         movl    PCB_EIP(%edx),%eax
361         movl    %eax,(%esp)
362
363         /*
364          * Restore the user LDT if we have one
365          */
366         cmpl    $0, PCB_USERLDT(%edx)
367         jnz     1f
368         movl    _default_ldt,%eax
369         cmpl    PCPU(currentldt),%eax
370         je      2f
371         lldt    _default_ldt
372         movl    %eax,PCPU(currentldt)
373         jmp     2f
374 1:      pushl   %edx
375         call    set_user_ldt
376         popl    %edx
377 2:
378         /*
379          * Restore the user TLS if we have one
380          */
381         pushl   %edx
382         call    set_user_TLS
383         popl    %edx
384         /*
385          * Restore the %gs segment register, which must be done after
386          * loading the user LDT.  Since user processes can modify the
387          * register via procfs, this may result in a fault which is
388          * detected by checking the fault address against cpu_switch_load_gs
389          * in i386/i386/trap.c
390          */
391         .globl  cpu_switch_load_gs
392 cpu_switch_load_gs:
393         movl    PCB_GS(%edx),%gs
394
395         /*
396          * Restore the DEBUG register state if necessary.
397          */
398         movb    PCB_FLAGS(%edx),%al
399         andb    $PCB_DBREGS,%al
400         jz      1f                              /* no, skip over */
401         movl    PCB_DR6(%edx),%eax              /* yes, do the restore */
402         movl    %eax,%dr6
403         movl    PCB_DR3(%edx),%eax
404         movl    %eax,%dr3
405         movl    PCB_DR2(%edx),%eax
406         movl    %eax,%dr2
407         movl    PCB_DR1(%edx),%eax
408         movl    %eax,%dr1
409         movl    PCB_DR0(%edx),%eax
410         movl    %eax,%dr0
411         movl    %dr7,%eax                /* load dr7 so as not to disturb */
412         andl    $0x0000fc00,%eax         /*   reserved bits               */
413         pushl   %ebx
414         movl    PCB_DR7(%edx),%ebx
415         andl    $~0x0000fc00,%ebx
416         orl     %ebx,%eax
417         popl    %ebx
418         movl    %eax,%dr7
419 1:
420
421         ret
422
423 /*
424  * savectx(pcb)
425  *
426  * Update pcb, saving current processor state.
427  */
428 ENTRY(savectx)
429         /* fetch PCB */
430         movl    4(%esp),%ecx
431
432         /* caller's return address - child won't execute this routine */
433         movl    (%esp),%eax
434         movl    %eax,PCB_EIP(%ecx)
435
436         movl    %cr3,%eax
437         movl    %eax,PCB_CR3(%ecx)
438
439         movl    %ebx,PCB_EBX(%ecx)
440         movl    %esp,PCB_ESP(%ecx)
441         movl    %ebp,PCB_EBP(%ecx)
442         movl    %esi,PCB_ESI(%ecx)
443         movl    %edi,PCB_EDI(%ecx)
444         movl    %gs,PCB_GS(%ecx)
445
446 #if NNPX > 0
447         /*
448          * If npxthread == NULL, then the npx h/w state is irrelevant and the
449          * state had better already be in the pcb.  This is true for forks
450          * but not for dumps (the old book-keeping with FP flags in the pcb
451          * always lost for dumps because the dump pcb has 0 flags).
452          *
453          * If npxthread != NULL, then we have to save the npx h/w state to
454          * npxthread's pcb and copy it to the requested pcb, or save to the
455          * requested pcb and reload.  Copying is easier because we would
456          * have to handle h/w bugs for reloading.  We used to lose the
457          * parent's npx state for forks by forgetting to reload.
458          */
459         movl    PCPU(npxthread),%eax
460         testl   %eax,%eax
461         je      1f
462
463         pushl   %ecx                    /* target pcb */
464         movl    TD_SAVEFPU(%eax),%eax   /* originating savefpu area */
465         pushl   %eax
466
467         pushl   %eax
468         call    npxsave
469         addl    $4,%esp
470
471         popl    %eax
472         popl    %ecx
473
474         pushl   $PCB_SAVEFPU_SIZE
475         leal    PCB_SAVEFPU(%ecx),%ecx
476         pushl   %ecx
477         pushl   %eax
478         call    bcopy
479         addl    $12,%esp
480 #endif  /* NNPX > 0 */
481
482 1:
483         ret
484
485 /*
486  * cpu_idle_restore()   (current thread in %eax on entry) (one-time execution)
487  *
488  *      Don't bother setting up any regs other then %ebp so backtraces
489  *      don't die.  This restore function is used to bootstrap into the
490  *      cpu_idle() LWKT only, after that cpu_lwkt_*() will be used for
491  *      switching.
492  *
493  *      Clear TDF_RUNNING in old thread only after we've cleaned up %cr3.
494  *
495  *      If we are an AP we have to call ap_init() before jumping to
496  *      cpu_idle().  ap_init() will synchronize with the BP and finish
497  *      setting up various ncpu-dependant globaldata fields.  This may
498  *      happen on UP as well as SMP if we happen to be simulating multiple
499  *      cpus.
500  */
501 ENTRY(cpu_idle_restore)
502         /* cli */
503         movl    IdlePTD,%ecx
504         movl    $0,%ebp
505         pushl   $0
506         movl    %ecx,%cr3
507         andl    $~TDF_RUNNING,TD_FLAGS(%ebx)
508         orl     $TDF_RUNNING,TD_FLAGS(%eax)
509 #ifdef SMP
510         cmpl    $0,PCPU(cpuid)
511         je      1f
512         call    ap_init
513 1:
514 #endif
515         sti
516         jmp     cpu_idle
517
518 /*
519  * cpu_kthread_restore() (current thread is %eax on entry) (one-time execution)
520  *
521  *      Don't bother setting up any regs other then %ebp so backtraces
522  *      don't die.  This restore function is used to bootstrap into an
523  *      LWKT based kernel thread only.  cpu_lwkt_switch() will be used
524  *      after this.
525  *
526  *      Since all of our context is on the stack we are reentrant and
527  *      we can release our critical section and enable interrupts early.
528  */
529 ENTRY(cpu_kthread_restore)
530         sti
531         movl    IdlePTD,%ecx
532         movl    TD_PCB(%eax),%edx
533         movl    $0,%ebp
534         movl    %ecx,%cr3
535         andl    $~TDF_RUNNING,TD_FLAGS(%ebx)
536         orl     $TDF_RUNNING,TD_FLAGS(%eax)
537         subl    $TDPRI_CRIT,TD_PRI(%eax)
538         popl    %eax            /* kthread exit function */
539         pushl   PCB_EBX(%edx)   /* argument to ESI function */
540         pushl   %eax            /* set exit func as return address */
541         movl    PCB_ESI(%edx),%eax
542         jmp     *%eax
543
544 /*
545  * cpu_lwkt_switch()
546  *
547  *      Standard LWKT switching function.  Only non-scratch registers are
548  *      saved and we don't bother with the MMU state or anything else.
549  *
550  *      This function is always called while in a critical section.
551  *
552  *      There is a one-instruction window where curthread is the new
553  *      thread but %esp still points to the old thread's stack, but
554  *      we are protected by a critical section so it is ok.
555  *
556  *      YYY BGL, SPL
557  */
558 ENTRY(cpu_lwkt_switch)
559         pushl   %ebp    /* note: GDB hacked to locate ebp relative to td_sp */
560         pushl   %ebx
561         movl    PCPU(curthread),%ebx
562         pushl   %esi
563         pushl   %edi
564         pushfl
565         /* warning: adjust movl into %eax below if you change the pushes */
566
567 #if NNPX > 0
568         /*
569          * Save the FP state if we have used the FP.  Note that calling
570          * npxsave will NULL out PCPU(npxthread).
571          *
572          * We have to deal with the FP state for LWKT threads in case they
573          * happen to get preempted or block while doing an optimized
574          * bzero/bcopy/memcpy.
575          */
576         cmpl    %ebx,PCPU(npxthread)
577         jne     1f
578         pushl   TD_SAVEFPU(%ebx)
579         call    npxsave                 /* do it in a big C function */
580         addl    $4,%esp                 /* EAX, ECX, EDX trashed */
581 1:
582 #endif  /* NNPX > 0 */
583
584         movl    4+20(%esp),%eax         /* switch to this thread */
585         pushl   $cpu_lwkt_restore
586         movl    %esp,TD_SP(%ebx)
587         movl    %eax,PCPU(curthread)
588         movl    TD_SP(%eax),%esp
589
590         /*
591          * eax contains new thread, ebx contains old thread.
592          */
593         ret
594
595 /*
596  * cpu_lwkt_restore()   (current thread in %eax on entry)
597  *
598  *      Standard LWKT restore function.  This function is always called
599  *      while in a critical section.
600  *      
601  *      Warning: due to preemption the restore function can be used to 
602  *      'return' to the original thread.  Interrupt disablement must be
603  *      protected through the switch so we cannot run splz here.
604  *
605  *      YYY we theoretically do not need to load IdlePTD into cr3, but if
606  *      so we need a way to detect when the PTD we are using is being 
607  *      deleted due to a process exiting.
608  */
609 ENTRY(cpu_lwkt_restore)
610         movl    IdlePTD,%ecx    /* YYY borrow but beware desched/cpuchg/exit */
611         movl    %cr3,%edx
612         cmpl    %ecx,%edx
613         je      1f
614         movl    %ecx,%cr3
615 1:
616         andl    $~TDF_RUNNING,TD_FLAGS(%ebx)
617         orl     $TDF_RUNNING,TD_FLAGS(%eax)
618         popfl
619         popl    %edi
620         popl    %esi
621         popl    %ebx
622         popl    %ebp
623         ret
624