]> git.saurik.com Git - apple/xnu.git/blobdiff - osfmk/i386/Diagnostics.c
xnu-2050.18.24.tar.gz
[apple/xnu.git] / osfmk / i386 / Diagnostics.c
index eae3c6e666b19dff05e982aed7041fbac1e47958..ddbb4b8ec3acd7ed665bb86793579b0fd200f6ec 100644 (file)
@@ -1,23 +1,29 @@
 /*
- * Copyright (c) 2005 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2005-2008 Apple Inc. All rights reserved.
  *
- * @APPLE_LICENSE_HEADER_START@
+ * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
  * 
- * The contents of this file constitute Original Code as defined in and
- * are subject to the Apple Public Source License Version 1.1 (the
- * "License").  You may not use this file except in compliance with the
- * License.  Please obtain a copy of the License at
- * http://www.apple.com/publicsource and read it before using this file.
+ * This file contains Original Code and/or Modifications of Original Code
+ * as defined in and that are subject to the Apple Public Source License
+ * Version 2.0 (the 'License'). You may not use this file except in
+ * compliance with the License. The rights granted to you under the License
+ * may not be used to create, or enable the creation or redistribution of,
+ * unlawful or unlicensed copies of an Apple operating system, or to
+ * circumvent, violate, or enable the circumvention or violation of, any
+ * terms of an Apple operating system software license agreement.
  * 
- * This Original Code and all software distributed under the License are
- * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * Please obtain a copy of the License at
+ * http://www.opensource.apple.com/apsl/ and read it before using this file.
+ * 
+ * The Original Code and all software distributed under the License are
+ * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
  * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT.  Please see the
- * License for the specific language governing rights and limitations
- * under the License.
+ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
+ * Please see the License for the specific language governing rights and
+ * limitations under the License.
  * 
- * @APPLE_LICENSE_HEADER_END@
+ * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
  */
 /*
  * @OSF_FREE_COPYRIGHT@
@@ -30,9 +36,8 @@
  *     Author: Bill Angell, Apple
  *     Date:   10/auht-five
  *
- *     Random diagnostics
+ *     Random diagnostics, augmented Derek Kumar 2011
  *
- *     Try to keep the x86 selectors in-sync with the ppc selectors.
  *
  */
 
 #include <i386/mp.h>
 #include <i386/pmCPU.h>
 #include <i386/tsc.h>
-#include <i386/hpet.h>
 #include <mach/i386/syscall_sw.h>
-
-extern uint64_t lastNapClear;
+#include <kern/kalloc.h>
 
 diagWork        dgWork;
-uint64_t        lastNapClear = 0ULL;
 uint64_t        lastRuptClear = 0ULL;
 
-typedef struct pmdata {
-       uint64_t        pmNapDur;       /* Time since last query */
-       pmStats_t       pmd;    /* Powermanagement statistics */
-}               pmdata;
-
-
-
 int 
-diagCall64(__unused x86_saved_state_t * regs)
+diagCall64(x86_saved_state_t * state)
 {
-        panic("diagCall not yet supported for 64 bit tasks\n");
-}
-
-
-int 
-diagCall(x86_saved_state_t * state)
-{
-
-       uint32_t        stk, curpos, i, j;
-       uint32_t        selector, data;
-       int             err;
+       uint64_t        curpos, i, j;
+       uint64_t        selector, data;
        uint64_t        currNap, durNap;
-       x86_saved_state32_t     *regs;
+       x86_saved_state64_t     *regs;
 
-       assert(is_saved_state32(state));
-       regs = saved_state32(state);
+       assert(is_saved_state64(state));
+       regs = saved_state64(state);
 
        if (!(dgWork.dgFlags & enaDiagSCs))
                return 0;       /* If not enabled, cause an exception */
 
-       stk = regs->uesp;       /* Point to the stack */
-       err = copyin((user_addr_t) (stk + 4), (char *) &selector, sizeof(uint32_t));    /* Get the selector */
-       if (err) {
-               return 0;       /* Failed to fetch stack */
-       }
-       switch (selector) {     /* Select the routine */
+       selector = regs->rdi;
 
+       switch (selector) {     /* Select the routine */
        case dgRuptStat:        /* Suck Interruption statistics */
+               (void) ml_set_interrupts_enabled(TRUE);
+               data = regs->rsi; /* Get the number of processors */
 
-               err = copyin((user_addr_t) (stk + 8), (char *) &data, sizeof(uint32_t));        /* Get the selector */
-
-               if (data == 0) {/* If number of processors is 0, clear all
-                                * counts */
+               if (data == 0) { /* If no location is specified for data, clear all
+                                 * counts
+                                 */
                        for (i = 0; i < real_ncpus; i++) {      /* Cycle through
                                                                 * processors */
                                for (j = 0; j < 256; j++)
@@ -124,7 +107,6 @@ diagCall(x86_saved_state_t * state)
                        lastRuptClear = mach_absolute_time();   /* Get the time of clear */
                        return 1;       /* Normal return */
                }
-               err = copyin((user_addr_t) (stk + 8), (char *) &data, sizeof(uint32_t));        /* Get the selector */
 
                (void) copyout((char *) &real_ncpus, data, sizeof(real_ncpus)); /* Copy out number of
                                                                                 * processors */
@@ -148,12 +130,30 @@ diagCall(x86_saved_state_t * state)
                        curpos = curpos + (256 * sizeof(uint32_t) + 8); /* Point to next out put
                                                                         * slot */
                }
-
+               return 1;
                break;
+#if    DEBUG
+       case dgGzallocTest:
+       {
+               (void) ml_set_interrupts_enabled(TRUE);
+               unsigned *ptr = (unsigned *)kalloc(1024);
+               kfree(ptr, 1024);
+               *ptr = 0x42;
+       }
+               break;
+#endif
+
+#if    defined(__x86_64__)             
+       case    dgPermCheck:
+       {
+               (void) ml_set_interrupts_enabled(TRUE);
+               return pmap_permissions_verify(kernel_pmap, kernel_map, 0, ~0ULL);
+       }
+               break;
+#endif /* __x86_64__*/
 
        default:                /* Handle invalid ones */
                return 0;       /* Return an exception */
-
        }
 
        return 1;               /* Normal non-ast check return */