The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/amd64/amd64/vm_machdep.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

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

Cache object: 2584de49cebd22ab0cd0bdcace8d6d1f


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.