kernel - Misc fixes and debugging
[dragonfly.git] / sys / platform / pc64 / x86_64 / vm_machdep.c
index 8165d8d..0a3797d 100644 (file)
@@ -72,6 +72,7 @@
 #include <vm/vm_extern.h>
 
 #include <sys/thread2.h>
+#include <sys/mplock2.h>
 
 #include <bus/isa/isa.h>
 
@@ -200,7 +201,8 @@ cpu_prepare_lwp(struct lwp *lp, struct lwp_params *params)
        regs->tf_rip = (long)params->func;
        regs->tf_rsp = (long)params->stack;
        /* Set up argument for function call */
-       regs->tf_rdi = (long)params->arg; /* JG Can this be in userspace addresses? */
+       regs->tf_rdi = (long)params->arg;
+
        /*
         * Set up fake return address.  As the lwp function may never return,
         * we simply copy out a NULL pointer and force the lwp to receive
@@ -251,13 +253,17 @@ cpu_lwp_exit(void)
 {
        struct thread *td = curthread;
        struct pcb *pcb;
+
        npxexit();
        pcb = td->td_pcb;
-       KKASSERT(pcb->pcb_ext == NULL); /* Some i386 functionality was dropped */
+
+       /* Some i386 functionality was dropped */
+       KKASSERT(pcb->pcb_ext == NULL);
+
+       /*
+        * disable all hardware breakpoints
+        */
         if (pcb->pcb_flags & PCB_DBREGS) {
-                /*
-                 * disable all hardware breakpoints
-                 */
                 reset_dbregs();
                 pcb->pcb_flags &= ~PCB_DBREGS;
         }
@@ -289,17 +295,6 @@ cpu_thread_exit(void)
        panic("cpu_thread_exit: lwkt_switch() unexpectedly returned");
 }
 
-/*
- * Process Reaper.  Called after the caller has acquired the thread's
- * rwlock and removed it from the reap list.
- */
-void
-cpu_proc_wait(struct proc *p)
-{
-       /* drop per-process resources */
-       pmap_dispose_proc(p);
-}
-
 void
 cpu_reset(void)
 {
@@ -346,18 +341,22 @@ kvtop(void *addr)
        return (pa);
 }
 
-int
-grow_stack(struct proc *p, vm_offset_t sp)
+static void
+swi_vm(void *arg, void *frame)
 {
-       int rv;
-
-       rv = vm_map_growstack (p, sp);
-       if (rv != KERN_SUCCESS)
-               return (0);
+       if (busdma_swi_pending != 0)
+               busdma_swi();
+}
 
-       return (1);
+static void
+swi_vm_setup(void *arg)
+{
+       register_swi(SWI_VM, swi_vm, NULL, "swi_vm", NULL, 0);
 }
 
+SYSINIT(vm_setup, SI_BOOT2_MACHDEP, SI_ORDER_ANY, swi_vm_setup, NULL);
+
+
 /*
  * Tell whether this address is in some physical memory region.
  * Currently used by the kernel coredump code in order to avoid
@@ -412,3 +411,68 @@ kvm_access_check(vm_offset_t saddr, vm_offset_t eaddr, int prot)
        return 0;
 }
 
+#if 0
+
+void _test_frame_enter(struct trapframe *frame);
+void _test_frame_exit(struct trapframe *frame);
+
+void
+_test_frame_enter(struct trapframe *frame)
+{
+       thread_t td = curthread;
+
+       if (ISPL(frame->tf_cs) == SEL_UPL) {
+               KKASSERT(td->td_lwp);
+                KASSERT(td->td_lwp->lwp_md.md_regs == frame,
+                        ("_test_frame_exit: Frame mismatch %p %p",
+                       td->td_lwp->lwp_md.md_regs, frame));
+           td->td_lwp->lwp_saveusp = (void *)frame->tf_rsp;
+           td->td_lwp->lwp_saveupc = (void *)frame->tf_rip;
+       }
+       if ((char *)frame < td->td_kstack ||
+           (char *)frame > td->td_kstack + td->td_kstack_size) {
+               panic("_test_frame_exit: frame not on kstack %p kstack=%p\n",
+                       frame, td->td_kstack);
+       }
+}
+
+void
+_test_frame_exit(struct trapframe *frame)
+{
+       thread_t td = curthread;
+
+       if (ISPL(frame->tf_cs) == SEL_UPL) {
+               KKASSERT(td->td_lwp);
+                KASSERT(td->td_lwp->lwp_md.md_regs == frame,
+                        ("_test_frame_exit: Frame mismatch %p %p",
+                       td->td_lwp->lwp_md.md_regs, frame));
+               if (td->td_lwp->lwp_saveusp != (void *)frame->tf_rsp) {
+                       kprintf("_test_frame_exit: %s:%d usp mismatch %p/%p\n",
+                               td->td_comm, td->td_proc->p_pid,
+                               td->td_lwp->lwp_saveusp,
+                               (void *)frame->tf_rsp);
+               }
+               if (td->td_lwp->lwp_saveupc != (void *)frame->tf_rip) {
+                       kprintf("_test_frame_exit: %s:%d upc mismatch %p/%p\n",
+                               td->td_comm, td->td_proc->p_pid,
+                               td->td_lwp->lwp_saveupc,
+                               (void *)frame->tf_rip);
+               }
+
+               /*
+                * adulterate the fields to catch entries that
+                * don't run through test_frame_enter
+                */
+               td->td_lwp->lwp_saveusp =
+                       (void *)~(intptr_t)td->td_lwp->lwp_saveusp;
+               td->td_lwp->lwp_saveupc =
+                       (void *)~(intptr_t)td->td_lwp->lwp_saveupc;
+       }
+       if ((char *)frame < td->td_kstack ||
+           (char *)frame > td->td_kstack + td->td_kstack_size) {
+               panic("_test_frame_exit: frame not on kstack %p kstack=%p\n",
+                       frame, td->td_kstack);
+       }
+}
+
+#endif