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