]> CyberLeo.Net >> Repos - FreeBSD/stable/8.git/blob - sys/amd64/amd64/vm_machdep.c
MFC r362623:
[FreeBSD/stable/8.git] / sys / amd64 / amd64 / vm_machdep.c
1 /*-
2  * Copyright (c) 1982, 1986 The Regents of the University of California.
3  * Copyright (c) 1989, 1990 William Jolitz
4  * Copyright (c) 1994 John Dyson
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to Berkeley by
8  * the Systems Programming Group of the University of Utah Computer
9  * Science Department, and William Jolitz.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  * 1. Redistributions of source code must retain the above copyright
15  *    notice, this list of conditions and the following disclaimer.
16  * 2. Redistributions in binary form must reproduce the above copyright
17  *    notice, this list of conditions and the following disclaimer in the
18  *    documentation and/or other materials provided with the distribution.
19  * 3. All advertising materials mentioning features or use of this software
20  *    must display the following acknowledgement:
21  *      This product includes software developed by the University of
22  *      California, Berkeley and its contributors.
23  * 4. Neither the name of the University nor the names of its contributors
24  *    may be used to endorse or promote products derived from this software
25  *    without specific prior written permission.
26  *
27  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
28  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
31  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
36  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37  * SUCH DAMAGE.
38  *
39  *      from: @(#)vm_machdep.c  7.3 (Berkeley) 5/13/91
40  *      Utah $Hdr: vm_machdep.c 1.16.1.1 89/06/23$
41  */
42
43 #include <sys/cdefs.h>
44 __FBSDID("$FreeBSD$");
45
46 #include "opt_isa.h"
47 #include "opt_cpu.h"
48 #include "opt_compat.h"
49
50 #include <sys/param.h>
51 #include <sys/systm.h>
52 #include <sys/bio.h>
53 #include <sys/buf.h>
54 #include <sys/kernel.h>
55 #include <sys/ktr.h>
56 #include <sys/lock.h>
57 #include <sys/malloc.h>
58 #include <sys/mbuf.h>
59 #include <sys/mutex.h>
60 #include <sys/pioctl.h>
61 #include <sys/proc.h>
62 #include <sys/sf_buf.h>
63 #include <sys/smp.h>
64 #include <sys/sysctl.h>
65 #include <sys/sysent.h>
66 #include <sys/unistd.h>
67 #include <sys/vnode.h>
68 #include <sys/vmmeter.h>
69
70 #include <machine/cpu.h>
71 #include <machine/md_var.h>
72 #include <machine/pcb.h>
73 #include <machine/specialreg.h>
74 #include <machine/tss.h>
75
76 #include <vm/vm.h>
77 #include <vm/vm_extern.h>
78 #include <vm/vm_kern.h>
79 #include <vm/vm_page.h>
80 #include <vm/vm_map.h>
81 #include <vm/vm_param.h>
82
83 #include <amd64/isa/isa.h>
84
85 static void     cpu_reset_real(void);
86 #ifdef SMP
87 static void     cpu_reset_proxy(void);
88 static u_int    cpu_reset_proxyid;
89 static volatile u_int   cpu_reset_proxy_active;
90 #endif
91
92 struct savefpu *
93 get_pcb_user_save_td(struct thread *td)
94 {
95         vm_offset_t p;
96
97         p = td->td_kstack + td->td_kstack_pages * PAGE_SIZE -
98             cpu_max_ext_state_size;
99         KASSERT((p % 64) == 0, ("Unaligned pcb_user_save area"));
100         return ((struct savefpu *)p);
101 }
102
103 struct savefpu *
104 get_pcb_user_save_pcb(struct pcb *pcb)
105 {
106         vm_offset_t p;
107
108         p = (vm_offset_t)(pcb + 1);
109         return ((struct savefpu *)p);
110 }
111
112 struct pcb *
113 get_pcb_td(struct thread *td)
114 {
115         vm_offset_t p;
116
117         p = td->td_kstack + td->td_kstack_pages * PAGE_SIZE -
118             cpu_max_ext_state_size - sizeof(struct pcb);
119         return ((struct pcb *)p);
120 }
121
122 void *
123 alloc_fpusave(int flags)
124 {
125         struct pcb *res;
126         struct savefpu_ymm *sf;
127
128         res = malloc(cpu_max_ext_state_size, M_DEVBUF, flags);
129         if (use_xsave) {
130                 sf = (struct savefpu_ymm *)res;
131                 bzero(&sf->sv_xstate.sx_hd, sizeof(sf->sv_xstate.sx_hd));
132                 sf->sv_xstate.sx_hd.xstate_bv = xsave_mask;
133         }
134         return (res);
135 }
136
137 /*
138  * Finish a fork operation, with process p2 nearly set up.
139  * Copy and update the pcb, set up the stack so that the child
140  * ready to run and return to user mode.
141  */
142 void
143 cpu_fork(td1, p2, td2, flags)
144         register struct thread *td1;
145         register struct proc *p2;
146         struct thread *td2;
147         int flags;
148 {
149         register struct proc *p1;
150         struct pcb *pcb2;
151         struct mdproc *mdp1, *mdp2;
152         struct proc_ldt *pldt;
153         pmap_t pmap2;
154
155         p1 = td1->td_proc;
156         if ((flags & RFPROC) == 0) {
157                 if ((flags & RFMEM) == 0) {
158                         /* unshare user LDT */
159                         mdp1 = &p1->p_md;
160                         mtx_lock(&dt_lock);
161                         if ((pldt = mdp1->md_ldt) != NULL &&
162                             pldt->ldt_refcnt > 1 &&
163                             user_ldt_alloc(p1, 1) == NULL)
164                                 panic("could not copy LDT");
165                         mtx_unlock(&dt_lock);
166                 }
167                 return;
168         }
169
170         /* Ensure that td1's pcb is up to date. */
171         fpuexit(td1);
172
173         /* Point the pcb to the top of the stack */
174         pcb2 = get_pcb_td(td2);
175         td2->td_pcb = pcb2;
176
177         /* Copy td1's pcb */
178         bcopy(td1->td_pcb, pcb2, sizeof(*pcb2));
179
180         /* Properly initialize pcb_save */
181         pcb2->pcb_save = get_pcb_user_save_pcb(pcb2);
182         bcopy(get_pcb_user_save_td(td1), get_pcb_user_save_pcb(pcb2),
183             cpu_max_ext_state_size);
184
185         /* Point mdproc and then copy over td1's contents */
186         mdp2 = &p2->p_md;
187         bcopy(&p1->p_md, mdp2, sizeof(*mdp2));
188
189         /*
190          * Create a new fresh stack for the new process.
191          * Copy the trap frame for the return to user mode as if from a
192          * syscall.  This copies most of the user mode register values.
193          */
194         td2->td_frame = (struct trapframe *)td2->td_pcb - 1;
195         bcopy(td1->td_frame, td2->td_frame, sizeof(struct trapframe));
196
197         td2->td_frame->tf_rax = 0;              /* Child returns zero */
198         td2->td_frame->tf_rflags &= ~PSL_C;     /* success */
199         td2->td_frame->tf_rdx = 1;
200
201         /*
202          * If the parent process has the trap bit set (i.e. a debugger had
203          * single stepped the process to the system call), we need to clear
204          * the trap flag from the new frame unless the debugger had set PF_FORK
205          * on the parent.  Otherwise, the child will receive a (likely
206          * unexpected) SIGTRAP when it executes the first instruction after
207          * returning  to userland.
208          */
209         if ((p1->p_pfsflags & PF_FORK) == 0)
210                 td2->td_frame->tf_rflags &= ~PSL_T;
211
212         /*
213          * Set registers for trampoline to user mode.  Leave space for the
214          * return address on stack.  These are the kernel mode register values.
215          */
216         pmap2 = vmspace_pmap(p2->p_vmspace);
217         pcb2->pcb_cr3 = DMAP_TO_PHYS((vm_offset_t)pmap2->pm_pml4);
218         pcb2->pcb_r12 = (register_t)fork_return;        /* fork_trampoline argument */
219         pcb2->pcb_rbp = 0;
220         pcb2->pcb_rsp = (register_t)td2->td_frame - sizeof(void *);
221         pcb2->pcb_rbx = (register_t)td2;                /* fork_trampoline argument */
222         pcb2->pcb_rip = (register_t)fork_trampoline;
223         /*-
224          * pcb2->pcb_dr*:       cloned above.
225          * pcb2->pcb_savefpu:   cloned above.
226          * pcb2->pcb_flags:     cloned above.
227          * pcb2->pcb_onfault:   cloned above (always NULL here?).
228          * pcb2->pcb_[fg]sbase: cloned above
229          */
230
231         /* Setup to release spin count in fork_exit(). */
232         td2->td_md.md_spinlock_count = 1;
233         td2->td_md.md_saved_flags = PSL_KERNEL | PSL_I;
234
235         /* As an i386, do not copy io permission bitmap. */
236         pcb2->pcb_tssp = NULL;
237
238         /* New segment registers. */
239         set_pcb_flags(pcb2, PCB_FULL_IRET);
240
241         /* Copy the LDT, if necessary. */
242         mdp1 = &td1->td_proc->p_md;
243         mdp2 = &p2->p_md;
244         mtx_lock(&dt_lock);
245         if (mdp1->md_ldt != NULL) {
246                 if (flags & RFMEM) {
247                         mdp1->md_ldt->ldt_refcnt++;
248                         mdp2->md_ldt = mdp1->md_ldt;
249                         bcopy(&mdp1->md_ldt_sd, &mdp2->md_ldt_sd, sizeof(struct
250                             system_segment_descriptor));
251                 } else {
252                         mdp2->md_ldt = NULL;
253                         mdp2->md_ldt = user_ldt_alloc(p2, 0);
254                         if (mdp2->md_ldt == NULL)
255                                 panic("could not copy LDT");
256                         amd64_set_ldt_data(td2, 0, max_ldt_segment,
257                             (struct user_segment_descriptor *)
258                             mdp1->md_ldt->ldt_base);
259                 }
260         } else
261                 mdp2->md_ldt = NULL;
262         mtx_unlock(&dt_lock);
263
264         /*
265          * Now, cpu_switch() can schedule the new process.
266          * pcb_rsp is loaded pointing to the cpu_switch() stack frame
267          * containing the return address when exiting cpu_switch.
268          * This will normally be to fork_trampoline(), which will have
269          * %ebx loaded with the new proc's pointer.  fork_trampoline()
270          * will set up a stack to call fork_return(p, frame); to complete
271          * the return to user-mode.
272          */
273 }
274
275 /*
276  * Intercept the return address from a freshly forked process that has NOT
277  * been scheduled yet.
278  *
279  * This is needed to make kernel threads stay in kernel mode.
280  */
281 void
282 cpu_set_fork_handler(td, func, arg)
283         struct thread *td;
284         void (*func)(void *);
285         void *arg;
286 {
287         /*
288          * Note that the trap frame follows the args, so the function
289          * is really called like this:  func(arg, frame);
290          */
291         td->td_pcb->pcb_r12 = (long) func;      /* function */
292         td->td_pcb->pcb_rbx = (long) arg;       /* first arg */
293 }
294
295 void
296 cpu_exit(struct thread *td)
297 {
298
299         /*
300          * If this process has a custom LDT, release it.
301          */
302         mtx_lock(&dt_lock);
303         if (td->td_proc->p_md.md_ldt != 0)
304                 user_ldt_free(td);
305         else
306                 mtx_unlock(&dt_lock);
307 }
308
309 void
310 cpu_thread_exit(struct thread *td)
311 {
312         struct pcb *pcb;
313
314         critical_enter();
315         if (td == PCPU_GET(fpcurthread))
316                 fpudrop();
317         critical_exit();
318
319         pcb = td->td_pcb;
320
321         /* Disable any hardware breakpoints. */
322         if (pcb->pcb_flags & PCB_DBREGS) {
323                 reset_dbregs();
324                 clear_pcb_flags(pcb, PCB_DBREGS);
325         }
326 }
327
328 void
329 cpu_thread_clean(struct thread *td)
330 {
331         struct pcb *pcb;
332
333         pcb = td->td_pcb;
334
335         /*
336          * Clean TSS/iomap
337          */
338         if (pcb->pcb_tssp != NULL) {
339                 kmem_free(kernel_map, (vm_offset_t)pcb->pcb_tssp,
340                     ctob(IOPAGES + 1));
341                 pcb->pcb_tssp = NULL;
342         }
343 }
344
345 void
346 cpu_thread_swapin(struct thread *td)
347 {
348 }
349
350 void
351 cpu_thread_swapout(struct thread *td)
352 {
353 }
354
355 void
356 cpu_thread_alloc(struct thread *td)
357 {
358         struct pcb *pcb;
359         struct xstate_hdr *xhdr;
360
361         td->td_pcb = pcb = get_pcb_td(td);
362         td->td_frame = (struct trapframe *)pcb - 1;
363         pcb->pcb_save = get_pcb_user_save_pcb(pcb);
364         if (use_xsave) {
365                 xhdr = (struct xstate_hdr *)(pcb->pcb_save + 1);
366                 bzero(xhdr, sizeof(*xhdr));
367                 xhdr->xstate_bv = xsave_mask;
368         }
369 }
370
371 void
372 cpu_thread_free(struct thread *td)
373 {
374
375         cpu_thread_clean(td);
376 }
377
378 void
379 cpu_set_syscall_retval(struct thread *td, int error)
380 {
381
382         switch (error) {
383         case 0:
384                 td->td_frame->tf_rax = td->td_retval[0];
385                 td->td_frame->tf_rdx = td->td_retval[1];
386                 td->td_frame->tf_rflags &= ~PSL_C;
387                 break;
388
389         case ERESTART:
390                 /*
391                  * Reconstruct pc, we know that 'syscall' is 2 bytes,
392                  * lcall $X,y is 7 bytes, int 0x80 is 2 bytes.
393                  * We saved this in tf_err.
394                  * %r10 (which was holding the value of %rcx) is restored
395                  * for the next iteration.
396                  * %r10 restore is only required for freebsd/amd64 processes,
397                  * but shall be innocent for any ia32 ABI.
398                  *
399                  * Require full context restore to get the arguments
400                  * in the registers reloaded at return to usermode.
401                  */
402                 td->td_frame->tf_rip -= td->td_frame->tf_err;
403                 td->td_frame->tf_r10 = td->td_frame->tf_rcx;
404                 set_pcb_flags(td->td_pcb, PCB_FULL_IRET);
405                 break;
406
407         case EJUSTRETURN:
408                 break;
409
410         default:
411                 if (td->td_proc->p_sysent->sv_errsize) {
412                         if (error >= td->td_proc->p_sysent->sv_errsize)
413                                 error = -1;     /* XXX */
414                         else
415                                 error = td->td_proc->p_sysent->sv_errtbl[error];
416                 }
417                 td->td_frame->tf_rax = error;
418                 td->td_frame->tf_rflags |= PSL_C;
419                 break;
420         }
421 }
422
423 /*
424  * Initialize machine state (pcb and trap frame) for a new thread about to
425  * upcall. Put enough state in the new thread's PCB to get it to go back 
426  * userret(), where we can intercept it again to set the return (upcall)
427  * Address and stack, along with those from upcals that are from other sources
428  * such as those generated in thread_userret() itself.
429  */
430 void
431 cpu_set_upcall(struct thread *td, struct thread *td0)
432 {
433         struct pcb *pcb2;
434
435         /* Point the pcb to the top of the stack. */
436         pcb2 = td->td_pcb;
437
438         /*
439          * Copy the upcall pcb.  This loads kernel regs.
440          * Those not loaded individually below get their default
441          * values here.
442          */
443         bcopy(td0->td_pcb, pcb2, sizeof(*pcb2));
444         clear_pcb_flags(pcb2, PCB_FPUINITDONE | PCB_USERFPUINITDONE);
445         pcb2->pcb_save = get_pcb_user_save_pcb(pcb2);
446         bcopy(get_pcb_user_save_td(td0), pcb2->pcb_save,
447             cpu_max_ext_state_size);
448         set_pcb_flags(pcb2, PCB_FULL_IRET);
449
450         /*
451          * Create a new fresh stack for the new thread.
452          */
453         bcopy(td0->td_frame, td->td_frame, sizeof(struct trapframe));
454
455         /* If the current thread has the trap bit set (i.e. a debugger had
456          * single stepped the process to the system call), we need to clear
457          * the trap flag from the new frame. Otherwise, the new thread will
458          * receive a (likely unexpected) SIGTRAP when it executes the first
459          * instruction after returning to userland.
460          */
461         td->td_frame->tf_rflags &= ~PSL_T;
462
463         /*
464          * Set registers for trampoline to user mode.  Leave space for the
465          * return address on stack.  These are the kernel mode register values.
466          */
467         pcb2->pcb_r12 = (register_t)fork_return;            /* trampoline arg */
468         pcb2->pcb_rbp = 0;
469         pcb2->pcb_rsp = (register_t)td->td_frame - sizeof(void *);      /* trampoline arg */
470         pcb2->pcb_rbx = (register_t)td;                     /* trampoline arg */
471         pcb2->pcb_rip = (register_t)fork_trampoline;
472         /*
473          * If we didn't copy the pcb, we'd need to do the following registers:
474          * pcb2->pcb_cr3:       cloned above.
475          * pcb2->pcb_dr*:       cloned above.
476          * pcb2->pcb_savefpu:   cloned above.
477          * pcb2->pcb_onfault:   cloned above (always NULL here?).
478          * pcb2->pcb_[fg]sbase: cloned above
479          */
480
481         /* Setup to release spin count in fork_exit(). */
482         td->td_md.md_spinlock_count = 1;
483         td->td_md.md_saved_flags = PSL_KERNEL | PSL_I;
484 }
485
486 /*
487  * Set that machine state for performing an upcall that has to
488  * be done in thread_userret() so that those upcalls generated
489  * in thread_userret() itself can be done as well.
490  */
491 void
492 cpu_set_upcall_kse(struct thread *td, void (*entry)(void *), void *arg,
493         stack_t *stack)
494 {
495
496         /* 
497          * Do any extra cleaning that needs to be done.
498          * The thread may have optional components
499          * that are not present in a fresh thread.
500          * This may be a recycled thread so make it look
501          * as though it's newly allocated.
502          */
503         cpu_thread_clean(td);
504
505 #ifdef COMPAT_FREEBSD32
506         if (SV_PROC_FLAG(td->td_proc, SV_ILP32)) {
507                 /*
508                  * Set the trap frame to point at the beginning of the uts
509                  * function.
510                  */
511                 td->td_frame->tf_rbp = 0;
512                 td->td_frame->tf_rsp =
513                    (((uintptr_t)stack->ss_sp + stack->ss_size - 4) & ~0x0f) - 4;
514                 td->td_frame->tf_rip = (uintptr_t)entry;
515
516                 /*
517                  * Pass the address of the mailbox for this kse to the uts
518                  * function as a parameter on the stack.
519                  */
520                 suword32((void *)(td->td_frame->tf_rsp + sizeof(int32_t)),
521                     (uint32_t)(uintptr_t)arg);
522
523                 return;
524         }
525 #endif
526
527         /*
528          * Set the trap frame to point at the beginning of the uts
529          * function.
530          */
531         td->td_frame->tf_rbp = 0;
532         td->td_frame->tf_rsp =
533             ((register_t)stack->ss_sp + stack->ss_size) & ~0x0f;
534         td->td_frame->tf_rsp -= 8;
535         td->td_frame->tf_rip = (register_t)entry;
536         td->td_frame->tf_ds = _udatasel;
537         td->td_frame->tf_es = _udatasel;
538         td->td_frame->tf_fs = _ufssel;
539         td->td_frame->tf_gs = _ugssel;
540         td->td_frame->tf_flags = TF_HASSEGS;
541
542         /*
543          * Pass the address of the mailbox for this kse to the uts
544          * function as a parameter on the stack.
545          */
546         td->td_frame->tf_rdi = (register_t)arg;
547 }
548
549 int
550 cpu_set_user_tls(struct thread *td, void *tls_base)
551 {
552         struct pcb *pcb;
553
554         if ((u_int64_t)tls_base >= VM_MAXUSER_ADDRESS)
555                 return (EINVAL);
556
557         pcb = td->td_pcb;
558 #ifdef COMPAT_FREEBSD32
559         if (SV_PROC_FLAG(td->td_proc, SV_ILP32)) {
560                 pcb->pcb_gsbase = (register_t)tls_base;
561                 return (0);
562         }
563 #endif
564         pcb->pcb_fsbase = (register_t)tls_base;
565         set_pcb_flags(pcb, PCB_FULL_IRET);
566         return (0);
567 }
568
569 #ifdef SMP
570 static void
571 cpu_reset_proxy()
572 {
573
574         cpu_reset_proxy_active = 1;
575         while (cpu_reset_proxy_active == 1)
576                 ;       /* Wait for other cpu to see that we've started */
577         stop_cpus((1<<cpu_reset_proxyid));
578         printf("cpu_reset_proxy: Stopped CPU %d\n", cpu_reset_proxyid);
579         DELAY(1000000);
580         cpu_reset_real();
581 }
582 #endif
583
584 void
585 cpu_reset()
586 {
587 #ifdef SMP
588         cpumask_t map;
589         u_int cnt;
590
591         if (smp_active) {
592                 map = PCPU_GET(other_cpus) & ~stopped_cpus;
593                 if (map != 0) {
594                         printf("cpu_reset: Stopping other CPUs\n");
595                         stop_cpus(map);
596                 }
597
598                 if (PCPU_GET(cpuid) != 0) {
599                         cpu_reset_proxyid = PCPU_GET(cpuid);
600                         cpustop_restartfunc = cpu_reset_proxy;
601                         cpu_reset_proxy_active = 0;
602                         printf("cpu_reset: Restarting BSP\n");
603
604                         /* Restart CPU #0. */
605                         atomic_store_rel_int(&started_cpus, 1 << 0);
606
607                         cnt = 0;
608                         while (cpu_reset_proxy_active == 0 && cnt < 10000000)
609                                 cnt++;  /* Wait for BSP to announce restart */
610                         if (cpu_reset_proxy_active == 0)
611                                 printf("cpu_reset: Failed to restart BSP\n");
612                         enable_intr();
613                         cpu_reset_proxy_active = 2;
614
615                         while (1);
616                         /* NOTREACHED */
617                 }
618
619                 DELAY(1000000);
620         }
621 #endif
622         cpu_reset_real();
623         /* NOTREACHED */
624 }
625
626 static void
627 cpu_reset_real()
628 {
629         struct region_descriptor null_idt;
630         int b;
631
632         disable_intr();
633
634         /*
635          * Attempt to do a CPU reset via the keyboard controller,
636          * do not turn off GateA20, as any machine that fails
637          * to do the reset here would then end up in no man's land.
638          */
639         outb(IO_KBD + 4, 0xFE);
640         DELAY(500000);  /* wait 0.5 sec to see if that did it */
641
642         /*
643          * Attempt to force a reset via the Reset Control register at
644          * I/O port 0xcf9.  Bit 2 forces a system reset when it
645          * transitions from 0 to 1.  Bit 1 selects the type of reset
646          * to attempt: 0 selects a "soft" reset, and 1 selects a
647          * "hard" reset.  We try a "hard" reset.  The first write sets
648          * bit 1 to select a "hard" reset and clears bit 2.  The
649          * second write forces a 0 -> 1 transition in bit 2 to trigger
650          * a reset.
651          */
652         outb(0xcf9, 0x2);
653         outb(0xcf9, 0x6);
654         DELAY(500000);  /* wait 0.5 sec to see if that did it */
655
656         /*
657          * Attempt to force a reset via the Fast A20 and Init register
658          * at I/O port 0x92.  Bit 1 serves as an alternate A20 gate.
659          * Bit 0 asserts INIT# when set to 1.  We are careful to only
660          * preserve bit 1 while setting bit 0.  We also must clear bit
661          * 0 before setting it if it isn't already clear.
662          */
663         b = inb(0x92);
664         if (b != 0xff) {
665                 if ((b & 0x1) != 0)
666                         outb(0x92, b & 0xfe);
667                 outb(0x92, b | 0x1);
668                 DELAY(500000);  /* wait 0.5 sec to see if that did it */
669         }
670
671         printf("No known reset method worked, attempting CPU shutdown\n");
672         DELAY(1000000); /* wait 1 sec for printf to complete */
673
674         /* Wipe the IDT. */
675         null_idt.rd_limit = 0;
676         null_idt.rd_base = 0;
677         lidt(&null_idt);
678
679         /* "good night, sweet prince .... <THUNK!>" */
680         breakpoint();
681
682         /* NOTREACHED */
683         while(1);
684 }
685
686 /*
687  * Allocate an sf_buf for the given vm_page.  On this machine, however, there
688  * is no sf_buf object.  Instead, an opaque pointer to the given vm_page is
689  * returned.
690  */
691 struct sf_buf *
692 sf_buf_alloc(struct vm_page *m, int pri)
693 {
694
695         return ((struct sf_buf *)m);
696 }
697
698 /*
699  * Free the sf_buf.  In fact, do nothing because there are no resources
700  * associated with the sf_buf.
701  */
702 void
703 sf_buf_free(struct sf_buf *sf)
704 {
705 }
706
707 /*
708  * Software interrupt handler for queued VM system processing.
709  */   
710 void  
711 swi_vm(void *dummy) 
712 {     
713         if (busdma_swi_pending != 0)
714                 busdma_swi();
715 }
716
717 /*
718  * Tell whether this address is in some physical memory region.
719  * Currently used by the kernel coredump code in order to avoid
720  * dumping the ``ISA memory hole'' which could cause indefinite hangs,
721  * or other unpredictable behaviour.
722  */
723
724 int
725 is_physical_memory(vm_paddr_t addr)
726 {
727
728 #ifdef DEV_ISA
729         /* The ISA ``memory hole''. */
730         if (addr >= 0xa0000 && addr < 0x100000)
731                 return 0;
732 #endif
733
734         /*
735          * stuff other tests for known memory-mapped devices (PCI?)
736          * here
737          */
738
739         return 1;
740 }