doreti was improperly clearing the entire gd_reqflags field when, in
[dragonfly.git] / sys / i386 / i386 / trap.c
1 /*-
2  * Copyright (C) 1994, David Greenman
3  * Copyright (c) 1990, 1993
4  *      The Regents of the University of California.  All rights reserved.
5  *
6  * This code is derived from software contributed to Berkeley by
7  * the University of Utah, and William Jolitz.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  * 3. All advertising materials mentioning features or use of this software
18  *    must display the following acknowledgement:
19  *      This product includes software developed by the University of
20  *      California, Berkeley and its contributors.
21  * 4. Neither the name of the University nor the names of its contributors
22  *    may be used to endorse or promote products derived from this software
23  *    without specific prior written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35  * SUCH DAMAGE.
36  *
37  *      from: @(#)trap.c        7.4 (Berkeley) 5/13/91
38  * $FreeBSD: src/sys/i386/i386/trap.c,v 1.147.2.11 2003/02/27 19:09:59 luoqi Exp $
39  * $DragonFly: src/sys/i386/i386/Attic/trap.c,v 1.25 2003/07/20 07:14:23 dillon Exp $
40  */
41
42 /*
43  * 386 Trap and System call handling
44  */
45
46 #include "opt_cpu.h"
47 #include "opt_ddb.h"
48 #include "opt_ktrace.h"
49 #include "opt_clock.h"
50 #include "opt_trap.h"
51
52 #include <sys/param.h>
53 #include <sys/systm.h>
54 #include <sys/proc.h>
55 #include <sys/pioctl.h>
56 #include <sys/kernel.h>
57 #include <sys/resourcevar.h>
58 #include <sys/signalvar.h>
59 #include <sys/syscall.h>
60 #include <sys/sysctl.h>
61 #include <sys/sysent.h>
62 #include <sys/uio.h>
63 #include <sys/vmmeter.h>
64 #ifdef KTRACE
65 #include <sys/ktrace.h>
66 #endif
67
68 #include <vm/vm.h>
69 #include <vm/vm_param.h>
70 #include <sys/lock.h>
71 #include <vm/pmap.h>
72 #include <vm/vm_kern.h>
73 #include <vm/vm_map.h>
74 #include <vm/vm_page.h>
75 #include <vm/vm_extern.h>
76
77 #include <machine/cpu.h>
78 #include <machine/ipl.h>
79 #include <machine/md_var.h>
80 #include <machine/pcb.h>
81 #ifdef SMP
82 #include <machine/smp.h>
83 #endif
84 #include <machine/tss.h>
85 #include <machine/globaldata.h>
86
87 #include <i386/isa/intr_machdep.h>
88
89 #ifdef POWERFAIL_NMI
90 #include <sys/syslog.h>
91 #include <machine/clock.h>
92 #endif
93
94 #include <machine/vm86.h>
95
96 #include <ddb/ddb.h>
97 #include <sys/thread2.h>
98
99 #include "isa.h"
100 #include "npx.h"
101
102 int (*pmath_emulate) __P((struct trapframe *));
103
104 extern void trap __P((struct trapframe frame));
105 extern int trapwrite __P((unsigned addr));
106 extern void syscall2 __P((struct trapframe frame));
107
108 static int trap_pfault __P((struct trapframe *, int, vm_offset_t));
109 static void trap_fatal __P((struct trapframe *, vm_offset_t));
110 void dblfault_handler __P((void));
111
112 extern inthand_t IDTVEC(syscall);
113
114 #define MAX_TRAP_MSG            28
115 static char *trap_msg[] = {
116         "",                                     /*  0 unused */
117         "privileged instruction fault",         /*  1 T_PRIVINFLT */
118         "",                                     /*  2 unused */
119         "breakpoint instruction fault",         /*  3 T_BPTFLT */
120         "",                                     /*  4 unused */
121         "",                                     /*  5 unused */
122         "arithmetic trap",                      /*  6 T_ARITHTRAP */
123         "system forced exception",              /*  7 T_ASTFLT */
124         "",                                     /*  8 unused */
125         "general protection fault",             /*  9 T_PROTFLT */
126         "trace trap",                           /* 10 T_TRCTRAP */
127         "",                                     /* 11 unused */
128         "page fault",                           /* 12 T_PAGEFLT */
129         "",                                     /* 13 unused */
130         "alignment fault",                      /* 14 T_ALIGNFLT */
131         "",                                     /* 15 unused */
132         "",                                     /* 16 unused */
133         "",                                     /* 17 unused */
134         "integer divide fault",                 /* 18 T_DIVIDE */
135         "non-maskable interrupt trap",          /* 19 T_NMI */
136         "overflow trap",                        /* 20 T_OFLOW */
137         "FPU bounds check fault",               /* 21 T_BOUND */
138         "FPU device not available",             /* 22 T_DNA */
139         "double fault",                         /* 23 T_DOUBLEFLT */
140         "FPU operand fetch fault",              /* 24 T_FPOPFLT */
141         "invalid TSS fault",                    /* 25 T_TSSFLT */
142         "segment not present fault",            /* 26 T_SEGNPFLT */
143         "stack fault",                          /* 27 T_STKFLT */
144         "machine check trap",                   /* 28 T_MCHK */
145 };
146
147 #if defined(I586_CPU) && !defined(NO_F00F_HACK)
148 extern int has_f00f_bug;
149 #endif
150
151 #ifdef DDB
152 static int ddb_on_nmi = 1;
153 SYSCTL_INT(_machdep, OID_AUTO, ddb_on_nmi, CTLFLAG_RW,
154         &ddb_on_nmi, 0, "Go to DDB on NMI");
155 #endif
156 static int panic_on_nmi = 1;
157 SYSCTL_INT(_machdep, OID_AUTO, panic_on_nmi, CTLFLAG_RW,
158         &panic_on_nmi, 0, "Panic on NMI");
159 static int fast_release;
160 SYSCTL_INT(_machdep, OID_AUTO, fast_release, CTLFLAG_RW,
161         &fast_release, 0, "Passive Release was optimal");
162 static int slow_release;
163 SYSCTL_INT(_machdep, OID_AUTO, slow_release, CTLFLAG_RW,
164         &slow_release, 0, "Passive Release was nonoptimal");
165
166 /*
167  * USER->KERNEL transition.  Do not transition us out of userland from the
168  * point of view of the userland scheduler unless we actually have to
169  * switch.
170  *
171  * usertdsw is called from within a critical section and the BGL will still
172  * be held.  This function is NOT called for preemptions, only for switchouts.
173  */
174 static void
175 passive_release(struct thread *td)
176 {
177         struct proc *p = td->td_proc;
178
179         td->td_release = NULL;
180         lwkt_setpri_self(TDPRI_KERN_USER);
181         if (p->p_flag & P_CURPROC) {
182                 release_curproc(p);
183         }
184 }
185
186 /*
187  * userenter() passively intercepts the thread switch function to increase
188  * the thread priority from a user priority to a kernel priority, reducing
189  * syscall and trap overhead for the case where no switch occurs.
190  */
191
192 static __inline void
193 userenter(void)
194 {
195         struct thread *td = curthread;
196
197         td->td_release = passive_release;
198 }
199
200 static __inline void
201 userexit(struct proc *p)
202 {
203         struct thread *td = p->p_thread;
204
205         /*
206          * If we did not have to release we should already be P_CURPROC.  If
207          * we did have to release we must acquire P_CURPROC again and then
208          * restore our priority for user return.
209          *
210          * Lowering our priority may make other higher priority threads
211          * runnable. lwkt_setpri_self() does not switch away, so call
212          * lwkt_maybe_switch() to deal with it.
213          */
214         if (td->td_release) {
215                 ++fast_release;
216                 td->td_release = NULL;
217                 KKASSERT(p->p_flag & P_CURPROC);
218         } else {
219                 ++slow_release;
220                 acquire_curproc(p);
221                 switch(p->p_rtprio.type) {
222                 case RTP_PRIO_IDLE:
223                         lwkt_setpri_self(TDPRI_USER_IDLE);
224                         break;
225                 case RTP_PRIO_REALTIME:
226                 case RTP_PRIO_FIFO:
227                         lwkt_setpri_self(TDPRI_USER_REAL);
228                         break;
229                 default:
230                         lwkt_setpri_self(TDPRI_USER_NORM);
231                         break;
232                 }
233                 lwkt_maybe_switch();
234         }
235 }
236
237
238 static void
239 userret(struct proc *p, struct trapframe *frame, u_quad_t oticks)
240 {
241         int sig;
242
243         /*
244          * Post any pending signals
245          */
246         while ((sig = CURSIG(p)) != 0) {
247                 postsig(sig);
248         }
249
250         /*
251          * If a reschedule has been requested then the easiest solution
252          * is to run our passive release function which will possibly
253          * shift our P_CURPROC designation to another user process.
254          * We don't actually switch here because that would be a waste
255          * of cycles (the newly scheduled user process would just switch
256          * back to us since we might be running at a kernel priority).
257          * Instead we fall through and will switch away when we attempt
258          * to reacquire our P_CURPROC designation.
259          */
260         if (resched_wanted()) {
261                 if (curthread->td_release)
262                         passive_release(curthread);
263         }
264
265         /*
266          * Charge system time if profiling.  Note: times are in microseconds.
267          */
268         if (p->p_flag & P_PROFIL) {
269                 addupc_task(p, frame->tf_eip, 
270                     (u_int)(curthread->td_sticks - oticks));
271         }
272
273         /*
274          * Post any pending signals XXX
275          */
276         while ((sig = CURSIG(p)) != 0)
277                 postsig(sig);
278 }
279
280 #ifdef DEVICE_POLLING
281 extern u_int32_t poll_in_trap;
282 extern int ether_poll __P((int count));
283 #endif /* DEVICE_POLLING */
284
285 /*
286  * Exception, fault, and trap interface to the FreeBSD kernel.
287  * This common code is called from assembly language IDT gate entry
288  * routines that prepare a suitable stack frame, and restore this
289  * frame after the exception has been processed.
290  *
291  * This function is also called from doreti in an interlock to handle ASTs.
292  * For example:  hardwareint->INTROUTINE->(set ast)->doreti->trap
293  *
294  * NOTE!  We have to retrieve the fault address prior to obtaining the
295  * MP lock because get_mplock() may switch out.  YYY cr2 really ought
296  * to be retrieved by the assembly code, not here.
297  */
298 void
299 trap(frame)
300         struct trapframe frame;
301 {
302         struct proc *p = curproc;
303         u_quad_t sticks = 0;
304         int i = 0, ucode = 0, type, code;
305         vm_offset_t eva;
306
307 #ifdef DDB
308         if (db_active) {
309                 eva = (frame.tf_trapno == T_PAGEFLT ? rcr2() : 0);
310                 get_mplock();
311                 trap_fatal(&frame, eva);
312                 goto out2;
313         }
314 #endif
315
316         eva = 0;
317         if (frame.tf_trapno == T_PAGEFLT) {
318                 /*
319                  * For some Cyrix CPUs, %cr2 is clobbered by interrupts.
320                  * This problem is worked around by using an interrupt
321                  * gate for the pagefault handler.  We are finally ready
322                  * to read %cr2 and then must reenable interrupts.
323                  *
324                  * XXX this should be in the switch statement, but the
325                  * NO_FOOF_HACK and VM86 goto and ifdefs obfuscate the
326                  * flow of control too much for this to be obviously
327                  * correct.
328                  */
329                 eva = rcr2();
330                 get_mplock();
331                 cpu_enable_intr();
332         } else {
333                 get_mplock();
334         }
335         /*
336          * MP lock is held at this point
337          */
338
339         if (!(frame.tf_eflags & PSL_I)) {
340                 /*
341                  * Buggy application or kernel code has disabled interrupts
342                  * and then trapped.  Enabling interrupts now is wrong, but
343                  * it is better than running with interrupts disabled until
344                  * they are accidentally enabled later.
345                  */
346                 type = frame.tf_trapno;
347                 if (ISPL(frame.tf_cs)==SEL_UPL || (frame.tf_eflags & PSL_VM)) {
348                         printf(
349                             "pid %ld (%s): trap %d with interrupts disabled\n",
350                             (long)curproc->p_pid, curproc->p_comm, type);
351                 } else if (type != T_BPTFLT && type != T_TRCTRAP) {
352                         /*
353                          * XXX not quite right, since this may be for a
354                          * multiple fault in user mode.
355                          */
356                         printf("kernel trap %d with interrupts disabled\n",
357                             type);
358                 }
359                 cpu_enable_intr();
360         }
361
362
363 #ifdef DEVICE_POLLING
364         if (poll_in_trap)
365                 ether_poll(poll_in_trap);
366 #endif /* DEVICE_POLLING */
367
368 #if defined(I586_CPU) && !defined(NO_F00F_HACK)
369 restart:
370 #endif
371         type = frame.tf_trapno;
372         code = frame.tf_err;
373
374         if (in_vm86call) {
375                 if (frame.tf_eflags & PSL_VM &&
376                     (type == T_PROTFLT || type == T_STKFLT)) {
377 #ifdef SMP
378                         KKASSERT(curthread->td_mpcount > 0);
379 #endif
380                         i = vm86_emulate((struct vm86frame *)&frame);
381 #ifdef SMP
382                         KKASSERT(curthread->td_mpcount > 0);
383 #endif
384                         if (i != 0) {
385                                 /*
386                                  * returns to original process
387                                  */
388                                 vm86_trap((struct vm86frame *)&frame);
389                                 KKASSERT(0);
390                         }
391                         goto out2;
392                 }
393                 switch (type) {
394                         /*
395                          * these traps want either a process context, or
396                          * assume a normal userspace trap.
397                          */
398                 case T_PROTFLT:
399                 case T_SEGNPFLT:
400                         trap_fatal(&frame, eva);
401                         goto out2;
402                 case T_TRCTRAP:
403                         type = T_BPTFLT;        /* kernel breakpoint */
404                         /* FALL THROUGH */
405                 }
406                 goto kernel_trap;       /* normal kernel trap handling */
407         }
408
409         if ((ISPL(frame.tf_cs) == SEL_UPL) || (frame.tf_eflags & PSL_VM)) {
410                 /* user trap */
411
412                 userenter();
413
414                 sticks = curthread->td_sticks;
415                 p->p_md.md_regs = &frame;
416
417                 switch (type) {
418                 case T_PRIVINFLT:       /* privileged instruction fault */
419                         ucode = type;
420                         i = SIGILL;
421                         break;
422
423                 case T_BPTFLT:          /* bpt instruction fault */
424                 case T_TRCTRAP:         /* trace trap */
425                         frame.tf_eflags &= ~PSL_T;
426                         i = SIGTRAP;
427                         break;
428
429                 case T_ARITHTRAP:       /* arithmetic trap */
430                         ucode = code;
431                         i = SIGFPE;
432                         break;
433
434                 case T_ASTFLT:          /* Allow process switch */
435                         mycpu->gd_cnt.v_soft++;
436                         if (mycpu->gd_reqflags & RQF_AST_OWEUPC) {
437                                 atomic_clear_int_nonlocked(&mycpu->gd_reqflags,
438                                             RQF_AST_OWEUPC);
439                                 addupc_task(p, p->p_stats->p_prof.pr_addr,
440                                             p->p_stats->p_prof.pr_ticks);
441                         }
442                         goto out;
443
444                         /*
445                          * The following two traps can happen in
446                          * vm86 mode, and, if so, we want to handle
447                          * them specially.
448                          */
449                 case T_PROTFLT:         /* general protection fault */
450                 case T_STKFLT:          /* stack fault */
451                         if (frame.tf_eflags & PSL_VM) {
452                                 i = vm86_emulate((struct vm86frame *)&frame);
453                                 if (i == 0)
454                                         goto out;
455                                 break;
456                         }
457                         /* FALL THROUGH */
458
459                 case T_SEGNPFLT:        /* segment not present fault */
460                 case T_TSSFLT:          /* invalid TSS fault */
461                 case T_DOUBLEFLT:       /* double fault */
462                 default:
463                         ucode = code + BUS_SEGM_FAULT ;
464                         i = SIGBUS;
465                         break;
466
467                 case T_PAGEFLT:         /* page fault */
468                         i = trap_pfault(&frame, TRUE, eva);
469                         if (i == -1)
470                                 goto out;
471 #if defined(I586_CPU) && !defined(NO_F00F_HACK)
472                         if (i == -2)
473                                 goto restart;
474 #endif
475                         if (i == 0)
476                                 goto out;
477
478                         ucode = T_PAGEFLT;
479                         break;
480
481                 case T_DIVIDE:          /* integer divide fault */
482                         ucode = FPE_INTDIV;
483                         i = SIGFPE;
484                         break;
485
486 #if NISA > 0
487                 case T_NMI:
488 #ifdef POWERFAIL_NMI
489                         goto handle_powerfail;
490 #else /* !POWERFAIL_NMI */
491                         /* machine/parity/power fail/"kitchen sink" faults */
492                         if (isa_nmi(code) == 0) {
493 #ifdef DDB
494                                 /*
495                                  * NMI can be hooked up to a pushbutton
496                                  * for debugging.
497                                  */
498                                 if (ddb_on_nmi) {
499                                         printf ("NMI ... going to debugger\n");
500                                         kdb_trap (type, 0, &frame);
501                                 }
502 #endif /* DDB */
503                                 goto out2;
504                         } else if (panic_on_nmi)
505                                 panic("NMI indicates hardware failure");
506                         break;
507 #endif /* POWERFAIL_NMI */
508 #endif /* NISA > 0 */
509
510                 case T_OFLOW:           /* integer overflow fault */
511                         ucode = FPE_INTOVF;
512                         i = SIGFPE;
513                         break;
514
515                 case T_BOUND:           /* bounds check fault */
516                         ucode = FPE_FLTSUB;
517                         i = SIGFPE;
518                         break;
519
520                 case T_DNA:
521 #if NNPX > 0
522                         /* if a transparent fault (due to context switch "late") */
523                         if (npxdna())
524                                 goto out;
525 #endif
526                         if (!pmath_emulate) {
527                                 i = SIGFPE;
528                                 ucode = FPE_FPU_NP_TRAP;
529                                 break;
530                         }
531                         i = (*pmath_emulate)(&frame);
532                         if (i == 0) {
533                                 if (!(frame.tf_eflags & PSL_T))
534                                         goto out2;
535                                 frame.tf_eflags &= ~PSL_T;
536                                 i = SIGTRAP;
537                         }
538                         /* else ucode = emulator_only_knows() XXX */
539                         break;
540
541                 case T_FPOPFLT:         /* FPU operand fetch fault */
542                         ucode = T_FPOPFLT;
543                         i = SIGILL;
544                         break;
545
546                 case T_XMMFLT:          /* SIMD floating-point exception */
547                         ucode = 0; /* XXX */
548                         i = SIGFPE;
549                         break;
550                 }
551         } else {
552 kernel_trap:
553                 /* kernel trap */
554
555                 switch (type) {
556                 case T_PAGEFLT:                 /* page fault */
557                         (void) trap_pfault(&frame, FALSE, eva);
558                         goto out2;
559
560                 case T_DNA:
561 #if NNPX > 0
562                         /*
563                          * The kernel is apparently using npx for copying.
564                          * XXX this should be fatal unless the kernel has
565                          * registered such use.
566                          */
567                         if (npxdna())
568                                 goto out2;
569 #endif
570                         break;
571
572                 case T_PROTFLT:         /* general protection fault */
573                 case T_SEGNPFLT:        /* segment not present fault */
574                         /*
575                          * Invalid segment selectors and out of bounds
576                          * %eip's and %esp's can be set up in user mode.
577                          * This causes a fault in kernel mode when the
578                          * kernel tries to return to user mode.  We want
579                          * to get this fault so that we can fix the
580                          * problem here and not have to check all the
581                          * selectors and pointers when the user changes
582                          * them.
583                          */
584 #define MAYBE_DORETI_FAULT(where, whereto)                              \
585         do {                                                            \
586                 if (frame.tf_eip == (int)where) {                       \
587                         frame.tf_eip = (int)whereto;                    \
588                         goto out2;                                      \
589                 }                                                       \
590         } while (0)
591
592                         if (mycpu->gd_intr_nesting_level == 0) {
593                                 /*
594                                  * Invalid %fs's and %gs's can be created using
595                                  * procfs or PT_SETREGS or by invalidating the
596                                  * underlying LDT entry.  This causes a fault
597                                  * in kernel mode when the kernel attempts to
598                                  * switch contexts.  Lose the bad context
599                                  * (XXX) so that we can continue, and generate
600                                  * a signal.
601                                  */
602                                 if (frame.tf_eip == (int)cpu_switch_load_gs) {
603                                         curthread->td_pcb->pcb_gs = 0;
604                                         psignal(p, SIGBUS);
605                                         goto out2;
606                                 }
607                                 MAYBE_DORETI_FAULT(doreti_iret,
608                                                    doreti_iret_fault);
609                                 MAYBE_DORETI_FAULT(doreti_popl_ds,
610                                                    doreti_popl_ds_fault);
611                                 MAYBE_DORETI_FAULT(doreti_popl_es,
612                                                    doreti_popl_es_fault);
613                                 MAYBE_DORETI_FAULT(doreti_popl_fs,
614                                                    doreti_popl_fs_fault);
615                                 if (curthread->td_pcb->pcb_onfault) {
616                                         frame.tf_eip = (int)curthread->td_pcb->pcb_onfault;
617                                         goto out2;
618                                 }
619                         }
620                         break;
621
622                 case T_TSSFLT:
623                         /*
624                          * PSL_NT can be set in user mode and isn't cleared
625                          * automatically when the kernel is entered.  This
626                          * causes a TSS fault when the kernel attempts to
627                          * `iret' because the TSS link is uninitialized.  We
628                          * want to get this fault so that we can fix the
629                          * problem here and not every time the kernel is
630                          * entered.
631                          */
632                         if (frame.tf_eflags & PSL_NT) {
633                                 frame.tf_eflags &= ~PSL_NT;
634                                 goto out2;
635                         }
636                         break;
637
638                 case T_TRCTRAP:  /* trace trap */
639                         if (frame.tf_eip == (int)IDTVEC(syscall)) {
640                                 /*
641                                  * We've just entered system mode via the
642                                  * syscall lcall.  Continue single stepping
643                                  * silently until the syscall handler has
644                                  * saved the flags.
645                                  */
646                                 goto out2;
647                         }
648                         if (frame.tf_eip == (int)IDTVEC(syscall) + 1) {
649                                 /*
650                                  * The syscall handler has now saved the
651                                  * flags.  Stop single stepping it.
652                                  */
653                                 frame.tf_eflags &= ~PSL_T;
654                                 goto out2;
655                         }
656                         /*
657                          * Ignore debug register trace traps due to
658                          * accesses in the user's address space, which
659                          * can happen under several conditions such as
660                          * if a user sets a watchpoint on a buffer and
661                          * then passes that buffer to a system call.
662                          * We still want to get TRCTRAPS for addresses
663                          * in kernel space because that is useful when
664                          * debugging the kernel.
665                          */
666                         if (user_dbreg_trap()) {
667                                 /*
668                                  * Reset breakpoint bits because the
669                                  * processor doesn't
670                                  */
671                                 load_dr6(rdr6() & 0xfffffff0);
672                                 goto out2;
673                         }
674                         /*
675                          * Fall through (TRCTRAP kernel mode, kernel address)
676                          */
677                 case T_BPTFLT:
678                         /*
679                          * If DDB is enabled, let it handle the debugger trap.
680                          * Otherwise, debugger traps "can't happen".
681                          */
682 #ifdef DDB
683                         if (kdb_trap (type, 0, &frame))
684                                 goto out2;
685 #endif
686                         break;
687
688 #if NISA > 0
689                 case T_NMI:
690 #ifdef POWERFAIL_NMI
691 #ifndef TIMER_FREQ
692 #  define TIMER_FREQ 1193182
693 #endif
694         handle_powerfail:
695                 {
696                   static unsigned lastalert = 0;
697
698                   if(time_second - lastalert > 10)
699                     {
700                       log(LOG_WARNING, "NMI: power fail\n");
701                       sysbeep(TIMER_FREQ/880, hz);
702                       lastalert = time_second;
703                     }
704                     /* YYY mp count */
705                   goto out2;
706                 }
707 #else /* !POWERFAIL_NMI */
708                         /* machine/parity/power fail/"kitchen sink" faults */
709                         if (isa_nmi(code) == 0) {
710 #ifdef DDB
711                                 /*
712                                  * NMI can be hooked up to a pushbutton
713                                  * for debugging.
714                                  */
715                                 if (ddb_on_nmi) {
716                                         printf ("NMI ... going to debugger\n");
717                                         kdb_trap (type, 0, &frame);
718                                 }
719 #endif /* DDB */
720                                 goto out2;
721                         } else if (panic_on_nmi == 0)
722                                 goto out2;
723                         /* FALL THROUGH */
724 #endif /* POWERFAIL_NMI */
725 #endif /* NISA > 0 */
726                 }
727
728                 trap_fatal(&frame, eva);
729                 goto out2;
730         }
731
732         /* Translate fault for emulators (e.g. Linux) */
733         if (*p->p_sysent->sv_transtrap)
734                 i = (*p->p_sysent->sv_transtrap)(i, type);
735
736         trapsignal(p, i, ucode);
737
738 #ifdef DEBUG
739         if (type <= MAX_TRAP_MSG) {
740                 uprintf("fatal process exception: %s",
741                         trap_msg[type]);
742                 if ((type == T_PAGEFLT) || (type == T_PROTFLT))
743                         uprintf(", fault VA = 0x%lx", (u_long)eva);
744                 uprintf("\n");
745         }
746 #endif
747
748 out:
749 #ifdef SMP
750         if (ISPL(frame.tf_cs) == SEL_UPL)
751                 KASSERT(curthread->td_mpcount == 1, ("badmpcount trap from %p", (void *)frame.tf_eip));
752 #endif
753         userret(p, &frame, sticks);
754         userexit(p);
755 out2:
756 #ifdef SMP
757         KKASSERT(curthread->td_mpcount > 0);
758 #endif
759         rel_mplock();
760 }
761
762 #ifdef notyet
763 /*
764  * This version doesn't allow a page fault to user space while
765  * in the kernel. The rest of the kernel needs to be made "safe"
766  * before this can be used. I think the only things remaining
767  * to be made safe are the iBCS2 code and the process tracing/
768  * debugging code.
769  */
770 static int
771 trap_pfault(frame, usermode, eva)
772         struct trapframe *frame;
773         int usermode;
774         vm_offset_t eva;
775 {
776         vm_offset_t va;
777         struct vmspace *vm = NULL;
778         vm_map_t map = 0;
779         int rv = 0;
780         vm_prot_t ftype;
781         struct proc *p = curproc;
782
783         if (frame->tf_err & PGEX_W)
784                 ftype = VM_PROT_WRITE;
785         else
786                 ftype = VM_PROT_READ;
787
788         va = trunc_page(eva);
789         if (va < VM_MIN_KERNEL_ADDRESS) {
790                 vm_offset_t v;
791                 vm_page_t mpte;
792
793                 if (p == NULL ||
794                     (!usermode && va < VM_MAXUSER_ADDRESS &&
795                      (mycpu->gd_intr_nesting_level != 0 || 
796                       curthread->td_pcb->pcb_onfault == NULL))) {
797                         trap_fatal(frame, eva);
798                         return (-1);
799                 }
800
801                 /*
802                  * This is a fault on non-kernel virtual memory.
803                  * vm is initialized above to NULL. If curproc is NULL
804                  * or curproc->p_vmspace is NULL the fault is fatal.
805                  */
806                 vm = p->p_vmspace;
807                 if (vm == NULL)
808                         goto nogo;
809
810                 map = &vm->vm_map;
811
812                 /*
813                  * Keep swapout from messing with us during this
814                  *      critical time.
815                  */
816                 ++p->p_lock;
817
818                 /*
819                  * Grow the stack if necessary
820                  */
821                 /* grow_stack returns false only if va falls into
822                  * a growable stack region and the stack growth
823                  * fails.  It returns true if va was not within
824                  * a growable stack region, or if the stack 
825                  * growth succeeded.
826                  */
827                 if (!grow_stack (p, va)) {
828                         rv = KERN_FAILURE;
829                         --p->p_lock;
830                         goto nogo;
831                 }
832                 
833                 /* Fault in the user page: */
834                 rv = vm_fault(map, va, ftype,
835                               (ftype & VM_PROT_WRITE) ? VM_FAULT_DIRTY
836                                                       : VM_FAULT_NORMAL);
837
838                 --p->p_lock;
839         } else {
840                 /*
841                  * Don't allow user-mode faults in kernel address space.
842                  */
843                 if (usermode)
844                         goto nogo;
845
846                 /*
847                  * Since we know that kernel virtual address addresses
848                  * always have pte pages mapped, we just have to fault
849                  * the page.
850                  */
851                 rv = vm_fault(kernel_map, va, ftype, VM_FAULT_NORMAL);
852         }
853
854         if (rv == KERN_SUCCESS)
855                 return (0);
856 nogo:
857         if (!usermode) {
858                 if (mycpu->gd_intr_nesting_level == 0 && curthread->td_pcb->pcb_onfault) {
859                         frame->tf_eip = (int)curthread->td_pcb->pcb_onfault;
860                         return (0);
861                 }
862                 trap_fatal(frame, eva);
863                 return (-1);
864         }
865
866         /* kludge to pass faulting virtual address to sendsig */
867         frame->tf_err = eva;
868
869         return((rv == KERN_PROTECTION_FAILURE) ? SIGBUS : SIGSEGV);
870 }
871 #endif
872
873 int
874 trap_pfault(frame, usermode, eva)
875         struct trapframe *frame;
876         int usermode;
877         vm_offset_t eva;
878 {
879         vm_offset_t va;
880         struct vmspace *vm = NULL;
881         vm_map_t map = 0;
882         int rv = 0;
883         vm_prot_t ftype;
884         struct proc *p = curproc;
885
886         va = trunc_page(eva);
887         if (va >= KERNBASE) {
888                 /*
889                  * Don't allow user-mode faults in kernel address space.
890                  * An exception:  if the faulting address is the invalid
891                  * instruction entry in the IDT, then the Intel Pentium
892                  * F00F bug workaround was triggered, and we need to
893                  * treat it is as an illegal instruction, and not a page
894                  * fault.
895                  */
896 #if defined(I586_CPU) && !defined(NO_F00F_HACK)
897                 if ((eva == (unsigned int)&idt[6]) && has_f00f_bug) {
898                         frame->tf_trapno = T_PRIVINFLT;
899                         return -2;
900                 }
901 #endif
902                 if (usermode)
903                         goto nogo;
904
905                 map = kernel_map;
906         } else {
907                 /*
908                  * This is a fault on non-kernel virtual memory.
909                  * vm is initialized above to NULL. If curproc is NULL
910                  * or curproc->p_vmspace is NULL the fault is fatal.
911                  */
912                 if (p != NULL)
913                         vm = p->p_vmspace;
914
915                 if (vm == NULL)
916                         goto nogo;
917
918                 map = &vm->vm_map;
919         }
920
921         if (frame->tf_err & PGEX_W)
922                 ftype = VM_PROT_WRITE;
923         else
924                 ftype = VM_PROT_READ;
925
926         if (map != kernel_map) {
927                 /*
928                  * Keep swapout from messing with us during this
929                  *      critical time.
930                  */
931                 ++p->p_lock;
932
933                 /*
934                  * Grow the stack if necessary
935                  */
936                 /* grow_stack returns false only if va falls into
937                  * a growable stack region and the stack growth
938                  * fails.  It returns true if va was not within
939                  * a growable stack region, or if the stack 
940                  * growth succeeded.
941                  */
942                 if (!grow_stack (p, va)) {
943                         rv = KERN_FAILURE;
944                         --p->p_lock;
945                         goto nogo;
946                 }
947
948                 /* Fault in the user page: */
949                 rv = vm_fault(map, va, ftype,
950                               (ftype & VM_PROT_WRITE) ? VM_FAULT_DIRTY
951                                                       : VM_FAULT_NORMAL);
952
953                 --p->p_lock;
954         } else {
955                 /*
956                  * Don't have to worry about process locking or stacks in the kernel.
957                  */
958                 rv = vm_fault(map, va, ftype, VM_FAULT_NORMAL);
959         }
960
961         if (rv == KERN_SUCCESS)
962                 return (0);
963 nogo:
964         if (!usermode) {
965                 if (mycpu->gd_intr_nesting_level == 0 && curthread->td_pcb->pcb_onfault) {
966                         frame->tf_eip = (int)curthread->td_pcb->pcb_onfault;
967                         return (0);
968                 }
969                 trap_fatal(frame, eva);
970                 return (-1);
971         }
972
973         /* kludge to pass faulting virtual address to sendsig */
974         frame->tf_err = eva;
975
976         return((rv == KERN_PROTECTION_FAILURE) ? SIGBUS : SIGSEGV);
977 }
978
979 static void
980 trap_fatal(frame, eva)
981         struct trapframe *frame;
982         vm_offset_t eva;
983 {
984         int code, type, ss, esp;
985         struct soft_segment_descriptor softseg;
986
987         code = frame->tf_err;
988         type = frame->tf_trapno;
989         sdtossd(&gdt[IDXSEL(frame->tf_cs & 0xffff)].sd, &softseg);
990
991         if (type <= MAX_TRAP_MSG)
992                 printf("\n\nFatal trap %d: %s while in %s mode\n",
993                         type, trap_msg[type],
994                         frame->tf_eflags & PSL_VM ? "vm86" :
995                         ISPL(frame->tf_cs) == SEL_UPL ? "user" : "kernel");
996 #ifdef SMP
997         /* three seperate prints in case of a trap on an unmapped page */
998         printf("mp_lock = %08x; ", mp_lock);
999         printf("cpuid = %d; ", mycpu->gd_cpuid);
1000         printf("lapic.id = %08x\n", lapic.id);
1001 #endif
1002         if (type == T_PAGEFLT) {
1003                 printf("fault virtual address   = 0x%x\n", eva);
1004                 printf("fault code              = %s %s, %s\n",
1005                         code & PGEX_U ? "user" : "supervisor",
1006                         code & PGEX_W ? "write" : "read",
1007                         code & PGEX_P ? "protection violation" : "page not present");
1008         }
1009         printf("instruction pointer     = 0x%x:0x%x\n",
1010                frame->tf_cs & 0xffff, frame->tf_eip);
1011         if ((ISPL(frame->tf_cs) == SEL_UPL) || (frame->tf_eflags & PSL_VM)) {
1012                 ss = frame->tf_ss & 0xffff;
1013                 esp = frame->tf_esp;
1014         } else {
1015                 ss = GSEL(GDATA_SEL, SEL_KPL);
1016                 esp = (int)&frame->tf_esp;
1017         }
1018         printf("stack pointer           = 0x%x:0x%x\n", ss, esp);
1019         printf("frame pointer           = 0x%x:0x%x\n", ss, frame->tf_ebp);
1020         printf("code segment            = base 0x%x, limit 0x%x, type 0x%x\n",
1021                softseg.ssd_base, softseg.ssd_limit, softseg.ssd_type);
1022         printf("                        = DPL %d, pres %d, def32 %d, gran %d\n",
1023                softseg.ssd_dpl, softseg.ssd_p, softseg.ssd_def32,
1024                softseg.ssd_gran);
1025         printf("processor eflags        = ");
1026         if (frame->tf_eflags & PSL_T)
1027                 printf("trace trap, ");
1028         if (frame->tf_eflags & PSL_I)
1029                 printf("interrupt enabled, ");
1030         if (frame->tf_eflags & PSL_NT)
1031                 printf("nested task, ");
1032         if (frame->tf_eflags & PSL_RF)
1033                 printf("resume, ");
1034         if (frame->tf_eflags & PSL_VM)
1035                 printf("vm86, ");
1036         printf("IOPL = %d\n", (frame->tf_eflags & PSL_IOPL) >> 12);
1037         printf("current process         = ");
1038         if (curproc) {
1039                 printf("%lu (%s)\n",
1040                     (u_long)curproc->p_pid, curproc->p_comm ?
1041                     curproc->p_comm : "");
1042         } else {
1043                 printf("Idle\n");
1044         }
1045         printf("current thread          = pri %d ", curthread->td_pri);
1046         if (curthread->td_pri >= TDPRI_CRIT)
1047                 printf("(CRIT)");
1048         printf("\n");
1049         printf("interrupt mask          = ");
1050         if ((curthread->td_cpl & net_imask) == net_imask)
1051                 printf("net ");
1052         if ((curthread->td_cpl & tty_imask) == tty_imask)
1053                 printf("tty ");
1054         if ((curthread->td_cpl & bio_imask) == bio_imask)
1055                 printf("bio ");
1056         if ((curthread->td_cpl & cam_imask) == cam_imask)
1057                 printf("cam ");
1058         if (curthread->td_cpl == 0)
1059                 printf("none");
1060 #ifdef SMP
1061 /**
1062  *  XXX FIXME:
1063  *      we probably SHOULD have stopped the other CPUs before now!
1064  *      another CPU COULD have been touching cpl at this moment...
1065  */
1066         printf(" <- SMP: XXX");
1067 #endif
1068         printf("\n");
1069
1070 #ifdef KDB
1071         if (kdb_trap(&psl))
1072                 return;
1073 #endif
1074 #ifdef DDB
1075         if ((debugger_on_panic || db_active) && kdb_trap(type, 0, frame))
1076                 return;
1077 #endif
1078         printf("trap number             = %d\n", type);
1079         if (type <= MAX_TRAP_MSG)
1080                 panic("%s", trap_msg[type]);
1081         else
1082                 panic("unknown/reserved trap");
1083 }
1084
1085 /*
1086  * Double fault handler. Called when a fault occurs while writing
1087  * a frame for a trap/exception onto the stack. This usually occurs
1088  * when the stack overflows (such is the case with infinite recursion,
1089  * for example).
1090  *
1091  * XXX Note that the current PTD gets replaced by IdlePTD when the
1092  * task switch occurs. This means that the stack that was active at
1093  * the time of the double fault is not available at <kstack> unless
1094  * the machine was idle when the double fault occurred. The downside
1095  * of this is that "trace <ebp>" in ddb won't work.
1096  */
1097 void
1098 dblfault_handler()
1099 {
1100         struct mdglobaldata *gd = mdcpu;
1101
1102         printf("\nFatal double fault:\n");
1103         printf("eip = 0x%x\n", gd->gd_common_tss.tss_eip);
1104         printf("esp = 0x%x\n", gd->gd_common_tss.tss_esp);
1105         printf("ebp = 0x%x\n", gd->gd_common_tss.tss_ebp);
1106 #ifdef SMP
1107         /* three seperate prints in case of a trap on an unmapped page */
1108         printf("mp_lock = %08x; ", mp_lock);
1109         printf("cpuid = %d; ", mycpu->gd_cpuid);
1110         printf("lapic.id = %08x\n", lapic.id);
1111 #endif
1112         panic("double fault");
1113 }
1114
1115 /*
1116  * Compensate for 386 brain damage (missing URKR).
1117  * This is a little simpler than the pagefault handler in trap() because
1118  * it the page tables have already been faulted in and high addresses
1119  * are thrown out early for other reasons.
1120  */
1121 int trapwrite(addr)
1122         unsigned addr;
1123 {
1124         struct proc *p;
1125         vm_offset_t va;
1126         struct vmspace *vm;
1127         int rv;
1128
1129         va = trunc_page((vm_offset_t)addr);
1130         /*
1131          * XXX - MAX is END.  Changed > to >= for temp. fix.
1132          */
1133         if (va >= VM_MAXUSER_ADDRESS)
1134                 return (1);
1135
1136         p = curproc;
1137         vm = p->p_vmspace;
1138
1139         ++p->p_lock;
1140
1141         if (!grow_stack (p, va)) {
1142                 --p->p_lock;
1143                 return (1);
1144         }
1145
1146         /*
1147          * fault the data page
1148          */
1149         rv = vm_fault(&vm->vm_map, va, VM_PROT_WRITE, VM_FAULT_DIRTY);
1150
1151         --p->p_lock;
1152
1153         if (rv != KERN_SUCCESS)
1154                 return 1;
1155
1156         return (0);
1157 }
1158
1159 /*
1160  *      syscall2 -      MP aware system call request C handler
1161  *
1162  *      A system call is essentially treated as a trap except that the
1163  *      MP lock is not held on entry or return.  We are responsible for
1164  *      obtaining the MP lock if necessary and for handling ASTs
1165  *      (e.g. a task switch) prior to return.
1166  *
1167  *      In general, only simple access and manipulation of curproc and
1168  *      the current stack is allowed without having to hold MP lock.
1169  */
1170 void
1171 syscall2(frame)
1172         struct trapframe frame;
1173 {
1174         struct thread *td = curthread;
1175         struct proc *p = td->td_proc;
1176         caddr_t params;
1177         int i;
1178         struct sysent *callp;
1179         register_t orig_tf_eflags;
1180         u_quad_t sticks;
1181         int error;
1182         int narg;
1183         int args[8];
1184         u_int code;
1185
1186 #ifdef DIAGNOSTIC
1187         if (ISPL(frame.tf_cs) != SEL_UPL) {
1188                 get_mplock();
1189                 panic("syscall");
1190                 /* NOT REACHED */
1191         }
1192 #endif
1193
1194 #ifdef SMP
1195         KASSERT(curthread->td_mpcount == 0, ("badmpcount syscall from %p", (void *)frame.tf_eip));
1196         get_mplock();
1197 #endif
1198         /*
1199          * access non-atomic field from critical section.  p_sticks is
1200          * updated by the clock interrupt.  Also use this opportunity
1201          * to lazy-raise our LWKT priority.
1202          */
1203         crit_enter();
1204         userenter();
1205         sticks = curthread->td_sticks;
1206         crit_exit();
1207
1208         p->p_md.md_regs = &frame;
1209         params = (caddr_t)frame.tf_esp + sizeof(int);
1210         code = frame.tf_eax;
1211         orig_tf_eflags = frame.tf_eflags;
1212
1213         if (p->p_sysent->sv_prepsyscall) {
1214                 /*
1215                  * The prep code is not MP aware.
1216                  */
1217                 (*p->p_sysent->sv_prepsyscall)(&frame, args, &code, &params);
1218         } else {
1219                 /*
1220                  * Need to check if this is a 32 bit or 64 bit syscall.
1221                  * fuword is MP aware.
1222                  */
1223                 if (code == SYS_syscall) {
1224                         /*
1225                          * Code is first argument, followed by actual args.
1226                          */
1227                         code = fuword(params);
1228                         params += sizeof(int);
1229                 } else if (code == SYS___syscall) {
1230                         /*
1231                          * Like syscall, but code is a quad, so as to maintain
1232                          * quad alignment for the rest of the arguments.
1233                          */
1234                         code = fuword(params);
1235                         params += sizeof(quad_t);
1236                 }
1237         }
1238
1239         if (p->p_sysent->sv_mask)
1240                 code &= p->p_sysent->sv_mask;
1241
1242         if (code >= p->p_sysent->sv_size)
1243                 callp = &p->p_sysent->sv_table[0];
1244         else
1245                 callp = &p->p_sysent->sv_table[code];
1246
1247         narg = callp->sy_narg & SYF_ARGMASK;
1248
1249         /*
1250          * copyin is MP aware, but the tracing code is not
1251          */
1252         if (params && (i = narg * sizeof(int)) &&
1253             (error = copyin(params, (caddr_t)args, (u_int)i))) {
1254 #ifdef KTRACE
1255                 if (KTRPOINT(td, KTR_SYSCALL))
1256                         ktrsyscall(p->p_tracep, code, narg, args);
1257 #endif
1258                 goto bad;
1259         }
1260
1261 #if 0
1262         /*
1263          * Try to run the syscall without the MP lock if the syscall
1264          * is MP safe.  We have to obtain the MP lock no matter what if 
1265          * we are ktracing
1266          */
1267         if ((callp->sy_narg & SYF_MPSAFE) == 0) {
1268                 get_mplock();
1269                 have_mplock = 1;
1270         }
1271 #endif
1272
1273 #ifdef KTRACE
1274         if (KTRPOINT(td, KTR_SYSCALL)) {
1275                 ktrsyscall(p->p_tracep, code, narg, args);
1276         }
1277 #endif
1278         p->p_retval[0] = 0;
1279         p->p_retval[1] = frame.tf_edx;
1280
1281         STOPEVENT(p, S_SCE, narg);      /* MP aware */
1282
1283         error = (*callp->sy_call)(args);
1284
1285         /*
1286          * MP SAFE (we may or may not have the MP lock at this point)
1287          */
1288         switch (error) {
1289         case 0:
1290                 /*
1291                  * Reinitialize proc pointer `p' as it may be different
1292                  * if this is a child returning from fork syscall.
1293                  */
1294                 p = curproc;
1295                 frame.tf_eax = p->p_retval[0];
1296                 frame.tf_edx = p->p_retval[1];
1297                 frame.tf_eflags &= ~PSL_C;
1298                 break;
1299
1300         case ERESTART:
1301                 /*
1302                  * Reconstruct pc, assuming lcall $X,y is 7 bytes,
1303                  * int 0x80 is 2 bytes. We saved this in tf_err.
1304                  */
1305                 frame.tf_eip -= frame.tf_err;
1306                 break;
1307
1308         case EJUSTRETURN:
1309                 break;
1310
1311         default:
1312 bad:
1313                 if (p->p_sysent->sv_errsize) {
1314                         if (error >= p->p_sysent->sv_errsize)
1315                                 error = -1;     /* XXX */
1316                         else
1317                                 error = p->p_sysent->sv_errtbl[error];
1318                 }
1319                 frame.tf_eax = error;
1320                 frame.tf_eflags |= PSL_C;
1321                 break;
1322         }
1323
1324         /*
1325          * Traced syscall.  trapsignal() is not MP aware.
1326          */
1327         if ((orig_tf_eflags & PSL_T) && !(orig_tf_eflags & PSL_VM)) {
1328                 frame.tf_eflags &= ~PSL_T;
1329                 trapsignal(p, SIGTRAP, 0);
1330         }
1331
1332         /*
1333          * Handle reschedule and other end-of-syscall issues
1334          */
1335         userret(p, &frame, sticks);
1336
1337 #ifdef KTRACE
1338         if (KTRPOINT(td, KTR_SYSRET)) {
1339                 ktrsysret(p->p_tracep, code, error, p->p_retval[0]);
1340         }
1341 #endif
1342
1343         /*
1344          * This works because errno is findable through the
1345          * register set.  If we ever support an emulation where this
1346          * is not the case, this code will need to be revisited.
1347          */
1348         STOPEVENT(p, S_SCX, code);
1349
1350         userexit(p);
1351 #ifdef SMP
1352         /*
1353          * Release the MP lock if we had to get it
1354          */
1355         KASSERT(curthread->td_mpcount == 1, ("badmpcount syscall from %p", (void *)frame.tf_eip));
1356         rel_mplock();
1357 #endif
1358 }
1359
1360 /*
1361  * Simplified back end of syscall(), used when returning from fork()
1362  * directly into user mode.  MP lock is held on entry and should be
1363  * released on return.  This code will return back into the fork
1364  * trampoline code which then runs doreti.
1365  */
1366 void
1367 fork_return(p, frame)
1368         struct proc *p;
1369         struct trapframe frame;
1370 {
1371         frame.tf_eax = 0;               /* Child returns zero */
1372         frame.tf_eflags &= ~PSL_C;      /* success */
1373         frame.tf_edx = 1;
1374
1375         userret(p, &frame, 0);
1376 #ifdef KTRACE
1377         if (KTRPOINT(p->p_thread, KTR_SYSRET))
1378                 ktrsysret(p->p_tracep, SYS_fork, 0, 0);
1379 #endif
1380         p->p_flag |= P_PASSIVE_ACQ;
1381         userexit(p);
1382         p->p_flag &= ~P_PASSIVE_ACQ;
1383 #ifdef SMP
1384         KKASSERT(curthread->td_mpcount == 1);
1385         rel_mplock();
1386 #endif
1387 }
1388