]> git.saurik.com Git - apple/xnu.git/blobdiff - osfmk/ppc/db_interface.c
xnu-792.17.14.tar.gz
[apple/xnu.git] / osfmk / ppc / db_interface.c
index 3961ece7822f6a3fbac3c48ed2fb87705de434fd..f7c735697670263c111f570271e6e902e3787249 100644 (file)
@@ -1,16 +1,19 @@
 /*
 /*
- * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved.
  *
  *
- * @APPLE_LICENSE_HEADER_START@
- * 
- * Copyright (c) 1999-2003 Apple Computer, Inc.  All Rights Reserved.
+ * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
  * 
  * 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
  * 
  * 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. Please obtain a copy of the License at
- * http://www.opensource.apple.com/apsl/ and read it before using this
- * file.
+ * 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.
+ * 
+ * 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
  * 
  * The Original Code and all software distributed under the License are
  * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
  * Please see the License for the specific language governing rights and
  * limitations under the License.
  * 
  * 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_COPYRIGHT@
  */
 
  */
 /*
  * @OSF_COPYRIGHT@
  */
 
-#include <cpus.h>
 #include <platforms.h>
 #include <time_stamp.h>
 #include <mach_mp_debug.h>
 #include <platforms.h>
 #include <time_stamp.h>
 #include <mach_mp_debug.h>
 #include <vm/pmap.h>
 
 #include <ppc/mem.h>
 #include <vm/pmap.h>
 
 #include <ppc/mem.h>
-#include <ppc/thread.h>
 #include <ppc/db_machdep.h>
 #include <ppc/trap.h>
 #include <ppc/setjmp.h>
 #include <ppc/pmap.h>
 #include <ppc/misc_protos.h>
 #include <ppc/db_machdep.h>
 #include <ppc/trap.h>
 #include <ppc/setjmp.h>
 #include <ppc/pmap.h>
 #include <ppc/misc_protos.h>
+#include <ppc/cpu_internal.h>
 #include <ppc/exception.h>
 #include <ppc/db_machdep.h>
 #include <ppc/mappings.h>
 #include <ppc/exception.h>
 #include <ppc/db_machdep.h>
 #include <ppc/mappings.h>
@@ -57,6 +59,8 @@
 #include <kern/thread.h>
 #include <kern/task.h>
 #include <kern/debug.h>
 #include <kern/thread.h>
 #include <kern/task.h>
 #include <kern/debug.h>
+#include <pexpert/pexpert.h>
+#include <IOKit/IOPlatformExpert.h>
 
 #include <ddb/db_command.h>
 #include <ddb/db_task_thread.h>
 
 #include <ddb/db_command.h>
 #include <ddb/db_task_thread.h>
@@ -72,7 +76,6 @@ struct         savearea *ppc_last_saved_statep;
 struct  savearea ppc_nested_saved_state;
 unsigned ppc_last_kdb_sp;
 
 struct  savearea ppc_nested_saved_state;
 unsigned ppc_last_kdb_sp;
 
-extern int debugger_active[NCPUS];             /* Debugger active on CPU */
 extern int debugger_cpu;                               /* Current cpu running debugger */
 
 int            db_all_set_up = 0;
 extern int debugger_cpu;                               /* Current cpu running debugger */
 
 int            db_all_set_up = 0;
@@ -118,11 +121,6 @@ extern void        kdbprinttrap(
                        int                     code,
                        int                     *pc,
                        int                     sp);
                        int                     code,
                        int                     *pc,
                        int                     sp);
-extern int     db_user_to_kernel_address(
-                       task_t                  task,
-                       vm_offset_t             addr,
-                       unsigned                *kaddr,
-                       int                     flag);
 extern void    db_write_bytes_user_space(
                        vm_offset_t             addr,
                        int                     size,
 extern void    db_write_bytes_user_space(
                        vm_offset_t             addr,
                        int                     size,
@@ -151,8 +149,6 @@ void kdp_register_send_receive(void) {}
 #endif
 
 extern jmp_buf_t *db_recover;
 #endif
 
 extern jmp_buf_t *db_recover;
-spl_t  saved_ipl[NCPUS];       /* just to know what IPL was before trap */
-struct savearea *saved_state[NCPUS];
 
 /*
  *  kdb_trap - field a TRACE or BPT trap
 
 /*
  *  kdb_trap - field a TRACE or BPT trap
@@ -185,7 +181,7 @@ kdb_trap(
                        db_printf("type %d", type);
                    else
                        db_printf("%s", trap_type[type]);
                        db_printf("type %d", type);
                    else
                        db_printf("%s", trap_type[type]);
-                   db_printf(" trap, pc = %x\n",
+                   db_printf(" trap, pc = %llx\n",
                              regs->save_srr0);
                    db_error("");
                    /*NOTREACHED*/
                              regs->save_srr0);
                    db_error("");
                    /*NOTREACHED*/
@@ -193,7 +189,7 @@ kdb_trap(
                kdbprinttrap(type, code, (int *)&regs->save_srr0, regs->save_r1);
        }
 
                kdbprinttrap(type, code, (int *)&regs->save_srr0, regs->save_r1);
        }
 
-       saved_state[cpu_number()] = regs;
+       getPerProc()->db_saved_state = regs;
 
        ppc_last_saved_statep = regs;
        ppc_last_kdb_sp = (unsigned) &type;
 
        ppc_last_saved_statep = regs;
        ppc_last_kdb_sp = (unsigned) &type;
@@ -217,13 +213,13 @@ kdb_trap(
            (db_get_task_value(regs->save_srr0,
                               BKPT_SIZE,
                               FALSE,
            (db_get_task_value(regs->save_srr0,
                               BKPT_SIZE,
                               FALSE,
-                              db_target_space(current_act(),
+                              db_target_space(current_thread(),
                                               trap_from_user))
                              == BKPT_INST))
            regs->save_srr0 += BKPT_SIZE;
 
 kdb_exit:
                                               trap_from_user))
                              == BKPT_INST))
            regs->save_srr0 += BKPT_SIZE;
 
 kdb_exit:
-       saved_state[cpu_number()] = 0;
+       getPerProc()->db_saved_state = 0;
        switch_to_old_console(previous_console_device);
 
 }
        switch_to_old_console(previous_console_device);
 
 }
@@ -253,68 +249,22 @@ kdbprinttrap(
 /*
  *
  */
 /*
  *
  */
-vm_offset_t db_vtophys(
+addr64_t db_vtophys(
        pmap_t pmap,
        vm_offset_t va)
 {
        pmap_t pmap,
        vm_offset_t va)
 {
-       register mapping        *mp;
-       register vm_offset_t    pa;
-
-       pa = (vm_offset_t)LRA(pmap->space,(void *)va);
+       ppnum_t pp;
+       addr64_t pa;
 
 
-       if (pa != 0)
-               return(pa);
+       pp = pmap_find_phys(pmap, (addr64_t)va);
 
 
-       mp = hw_lock_phys_vir(pmap->space, va);
-       if((unsigned int)mp&1) {
-               return 0;
-       }
-
-       if(!mp) {                                                               /* If it was not a normal page */
-               pa = hw_cvp_blk(pmap, va);                      /* Try to convert odd-sized page (returns 0 if not found) */
-               return pa;                                                      /* Return physical address */
-       }
-
-       mp = hw_cpv(mp);                                                /* Convert to virtual address */
-
-       if(!mp->physent) {
-               pa = (vm_offset_t)((mp->PTEr & -PAGE_SIZE) | ((unsigned int)va & (PAGE_SIZE-1)));
-       } else {
-               pa = (vm_offset_t)((mp->physent->pte1 & -PAGE_SIZE) | ((unsigned int)va & (PAGE_SIZE-1)));
-               hw_unlock_bit((unsigned int *)&mp->physent->phys_link, PHYS_LOCK);
-       }
+       if (pp == 0) return(0);                                 /* Couldn't find it */
+       
+       pa = ((addr64_t)pp << 12) | (addr64_t)(va & 0xFFF);     /* Get physical address */
 
        return(pa);
 }
 
 
        return(pa);
 }
 
-int
-db_user_to_kernel_address(
-       task_t          task,
-       vm_offset_t     addr,
-       unsigned        *kaddr,
-       int             flag)
-{
-       unsigned int    sr_val, raddr;
-
-       raddr = (unsigned int)db_vtophys(task->map->pmap, trunc_page(addr));    /* Get the real address */
-
-       if (!raddr) {
-           if (flag) {
-               db_printf("\nno memory is assigned to address %08x\n", addr);
-               db_error(0);
-               /* NOTREACHED */
-           }
-           return -1;
-       }
-       sr_val = SEG_REG_PROT | task->map->pmap->space
-                | ((addr >> 8) & 0x00F00000);
-               
-       mtsr(SR_COPYIN_NUM, sr_val);
-       sync();
-       *kaddr = (addr & 0x0fffffff) | (SR_COPYIN_NUM << 28);
-       return(0);
-}
-       
 /*
  * Read bytes from task address space for debugger.
  */
 /*
  * Read bytes from task address space for debugger.
  */
@@ -326,8 +276,8 @@ db_read_bytes(
        task_t          task)
 {
        int             n,max;
        task_t          task)
 {
        int             n,max;
-       unsigned        phys_dst;
-       unsigned        phys_src;
+       addr64_t        phys_dst;
+       addr64_t        phys_src;
        pmap_t  pmap;
        
        while (size > 0) {
        pmap_t  pmap;
        
        while (size > 0) {
@@ -336,16 +286,15 @@ db_read_bytes(
                else
                        pmap = kernel_pmap;
 
                else
                        pmap = kernel_pmap;
 
-               phys_src = (unsigned int)db_vtophys(pmap, trunc_page(addr));  
+               phys_src = db_vtophys(pmap, (vm_offset_t)addr);  
                if (phys_src == 0) {
                        db_printf("\nno memory is assigned to src address %08x\n",
                                  addr);
                        db_error(0);
                        /* NOTREACHED */
                }
                if (phys_src == 0) {
                        db_printf("\nno memory is assigned to src address %08x\n",
                                  addr);
                        db_error(0);
                        /* NOTREACHED */
                }
-               phys_src = phys_src| (addr & page_mask);
 
 
-               phys_dst = (unsigned int)db_vtophys(kernel_pmap, trunc_page(data)); 
+               phys_dst = db_vtophys(kernel_pmap, (vm_offset_t)data); 
                if (phys_dst == 0) {
                        db_printf("\nno memory is assigned to dst address %08x\n",
                                  data);
                if (phys_dst == 0) {
                        db_printf("\nno memory is assigned to dst address %08x\n",
                                  data);
@@ -353,22 +302,20 @@ db_read_bytes(
                        /* NOTREACHED */
                }
                
                        /* NOTREACHED */
                }
                
-               phys_dst = phys_dst | (((vm_offset_t) data) & page_mask);
-
                /* don't over-run any page boundaries - check src range */
                /* don't over-run any page boundaries - check src range */
-               max = ppc_round_page(phys_src) - phys_src;
+               max = round_page_64(phys_src + 1) - phys_src;
                if (max > size)
                        max = size;
                /* Check destination won't run over boundary either */
                if (max > size)
                        max = size;
                /* Check destination won't run over boundary either */
-               n = ppc_round_page(phys_dst) - phys_dst;
-               if (n < max)
-                       max = n;
+               n = round_page_64(phys_dst + 1) - phys_dst;
+               
+               if (n < max) max = n;
                size -= max;
                addr += max;
                phys_copy(phys_src, phys_dst, max);
 
                /* resync I+D caches */
                size -= max;
                addr += max;
                phys_copy(phys_src, phys_dst, max);
 
                /* resync I+D caches */
-               sync_cache(phys_dst, max);
+               sync_cache64(phys_dst, max);
 
                phys_src += max;
                phys_dst += max;
 
                phys_src += max;
                phys_dst += max;
@@ -386,13 +333,13 @@ db_write_bytes(
        task_t          task)
 {
        int             n,max;
        task_t          task)
 {
        int             n,max;
-       unsigned        phys_dst;
-       unsigned        phys_src;
+       addr64_t        phys_dst;
+       addr64_t        phys_src;
        pmap_t  pmap;
        
        while (size > 0) {
 
        pmap_t  pmap;
        
        while (size > 0) {
 
-               phys_src = (unsigned int)db_vtophys(kernel_pmap, trunc_page(data)); 
+               phys_src = db_vtophys(kernel_pmap, (vm_offset_t)data); 
                if (phys_src == 0) {
                        db_printf("\nno memory is assigned to src address %08x\n",
                                  data);
                if (phys_src == 0) {
                        db_printf("\nno memory is assigned to src address %08x\n",
                                  data);
@@ -400,27 +347,24 @@ db_write_bytes(
                        /* NOTREACHED */
                }
                
                        /* NOTREACHED */
                }
                
-               phys_src = phys_src | (((vm_offset_t) data) & page_mask);
-
                /* space stays as kernel space unless in another task */
                if (task == NULL) pmap = kernel_pmap;
                else pmap = task->map->pmap;
 
                /* space stays as kernel space unless in another task */
                if (task == NULL) pmap = kernel_pmap;
                else pmap = task->map->pmap;
 
-               phys_dst = (unsigned int)db_vtophys(pmap, trunc_page(addr));  
+               phys_dst = db_vtophys(pmap, (vm_offset_t)addr);  
                if (phys_dst == 0) {
                        db_printf("\nno memory is assigned to dst address %08x\n",
                                  addr);
                        db_error(0);
                        /* NOTREACHED */
                }
                if (phys_dst == 0) {
                        db_printf("\nno memory is assigned to dst address %08x\n",
                                  addr);
                        db_error(0);
                        /* NOTREACHED */
                }
-               phys_dst = phys_dst| (addr & page_mask);
 
                /* don't over-run any page boundaries - check src range */
 
                /* don't over-run any page boundaries - check src range */
-               max = ppc_round_page(phys_src) - phys_src;
+               max = round_page_64(phys_src + 1) - phys_src;
                if (max > size)
                        max = size;
                /* Check destination won't run over boundary either */
                if (max > size)
                        max = size;
                /* Check destination won't run over boundary either */
-               n = ppc_round_page(phys_dst) - phys_dst;
+               n = round_page_64(phys_dst + 1) - phys_dst;
                if (n < max)
                        max = n;
                size -= max;
                if (n < max)
                        max = n;
                size -= max;
@@ -428,7 +372,7 @@ db_write_bytes(
                phys_copy(phys_src, phys_dst, max);
 
                /* resync I+D caches */
                phys_copy(phys_src, phys_dst, max);
 
                /* resync I+D caches */
-               sync_cache(phys_dst, max);
+               sync_cache64(phys_dst, max);
 
                phys_src += max;
                phys_dst += max;
 
                phys_src += max;
                phys_dst += max;
@@ -445,18 +389,16 @@ db_check_access(
        unsigned int    kern_addr;
 
        if (task == kernel_task || task == TASK_NULL) {
        unsigned int    kern_addr;
 
        if (task == kernel_task || task == TASK_NULL) {
-           if (kernel_task == TASK_NULL)
-               return(TRUE);
+           if (kernel_task == TASK_NULL)  return(TRUE);
            task = kernel_task;
        } else if (task == TASK_NULL) {
            task = kernel_task;
        } else if (task == TASK_NULL) {
-           if (current_act() == THR_ACT_NULL)
-               return(FALSE);
-           task = current_act()->task;
+           if (current_thread() == THR_ACT_NULL) return(FALSE);
+           task = current_thread()->task;
        }
        }
+
        while (size > 0) {
        while (size > 0) {
-           if (db_user_to_kernel_address(task, addr, &kern_addr, 0) < 0)
-               return(FALSE);
-           n = ppc_trunc_page(addr+PPC_PGBYTES) - addr;
+               if(!pmap_find_phys(task->map->pmap, (addr64_t)addr)) return (FALSE);    /* Fail if page not mapped */
+           n = trunc_page_32(addr+PPC_PGBYTES) - addr;
            if (n > size)
                n = size;
            size -= n;
            if (n > size)
                n = size;
            size -= n;
@@ -472,19 +414,19 @@ db_phys_eq(
        task_t          task2,
        vm_offset_t     addr2)
 {
        task_t          task2,
        vm_offset_t     addr2)
 {
-       vm_offset_t     physa, physb;
+       addr64_t        physa, physb;
 
        if ((addr1 & (PPC_PGBYTES-1)) != (addr2 & (PPC_PGBYTES-1)))     /* Is byte displacement the same? */
                return FALSE;
 
        if (task1 == TASK_NULL) {                                               /* See if there is a task active */
 
        if ((addr1 & (PPC_PGBYTES-1)) != (addr2 & (PPC_PGBYTES-1)))     /* Is byte displacement the same? */
                return FALSE;
 
        if (task1 == TASK_NULL) {                                               /* See if there is a task active */
-               if (current_act() == THR_ACT_NULL)                      /* See if there is a current task */
+               if (current_thread() == THR_ACT_NULL)           /* See if there is a current task */
                        return FALSE;
                        return FALSE;
-               task1 = current_act()->task;                            /* If so, use that one */
+               task1 = current_thread()->task;                         /* If so, use that one */
        }
        
        }
        
-       if(!(physa = db_vtophys(task1->map->pmap, trunc_page(addr1)))) return FALSE;    /* Get real address of the first */
-       if(!(physb = db_vtophys(task2->map->pmap, trunc_page(addr2)))) return FALSE;    /* Get real address of the second */
+       if(!(physa = db_vtophys(task1->map->pmap, (vm_offset_t)trunc_page_32(addr1)))) return FALSE;    /* Get real address of the first */
+       if(!(physb = db_vtophys(task2->map->pmap, (vm_offset_t)trunc_page_32(addr2)))) return FALSE;    /* Get real address of the second */
        
        return (physa == physb);                                                /* Check if they are equal, then return... */
 }
        
        return (physa == physb);                                                /* Check if they are equal, then return... */
 }
@@ -492,6 +434,16 @@ db_phys_eq(
 #define DB_USER_STACK_ADDR             (0xc0000000)
 #define DB_NAME_SEARCH_LIMIT           (DB_USER_STACK_ADDR-(PPC_PGBYTES*3))
 
 #define DB_USER_STACK_ADDR             (0xc0000000)
 #define DB_NAME_SEARCH_LIMIT           (DB_USER_STACK_ADDR-(PPC_PGBYTES*3))
 
+boolean_t      db_phys_cmp(
+                               vm_offset_t a1, 
+                               vm_offset_t a2, 
+                               vm_size_t s1) {
+
+       db_printf("db_phys_cmp: not implemented\n");
+       return 0;
+}
+
+
 int
 db_search_null(
        task_t          task,
 int
 db_search_null(
        task_t          task,
@@ -503,65 +455,37 @@ db_search_null(
        register unsigned vaddr;
        register unsigned *kaddr;
 
        register unsigned vaddr;
        register unsigned *kaddr;
 
-       kaddr = (unsigned *)*skaddr;
-       for (vaddr = *svaddr; vaddr > evaddr; ) {
-           if (vaddr % PPC_PGBYTES == 0) {
-               vaddr -= sizeof(unsigned);
-               if (db_user_to_kernel_address(task, vaddr, skaddr, 0) < 0)
-                   return(-1);
-               kaddr = (unsigned *)*skaddr;
-           } else {
-               vaddr -= sizeof(unsigned);
-               kaddr--;
-           }
-           if ((*kaddr == 0) ^ (flag  == 0)) {
-               *svaddr = vaddr;
-               *skaddr = (unsigned)kaddr;
-               return(0);
-           }
-       }
+       db_printf("db_search_null: not implemented\n");
+
        return(-1);
 }
 
        return(-1);
 }
 
+unsigned char *getProcName(struct proc *proc);
+
 void
 db_task_name(
        task_t          task)
 {
 void
 db_task_name(
        task_t          task)
 {
-       register char *p;
+       register unsigned char *p;
        register int n;
        unsigned int vaddr, kaddr;
        register int n;
        unsigned int vaddr, kaddr;
+       unsigned char tname[33];
+       int i;
 
 
-       vaddr = DB_USER_STACK_ADDR;
-       kaddr = 0;
-
-       /*
-        * skip nulls at the end
-        */
-       if (db_search_null(task, &vaddr, DB_NAME_SEARCH_LIMIT, &kaddr, 0) < 0) {
-           db_printf(DB_NULL_TASK_NAME);
-           return;
-       }
-       /*
-        * search start of args
-        */
-       if (db_search_null(task, &vaddr, DB_NAME_SEARCH_LIMIT, &kaddr, 1) < 0) {
-           db_printf(DB_NULL_TASK_NAME);
-           return;
-       }
-
-       n = DB_TASK_NAME_LEN-1;
-       p = (char *)kaddr + sizeof(unsigned);
-       for (vaddr += sizeof(int); vaddr < DB_USER_STACK_ADDR && n > 0; 
-                                                       vaddr++, p++, n--) {
-           if (vaddr % PPC_PGBYTES == 0) {
-               if (db_user_to_kernel_address(task, vaddr, &kaddr, 0) <0)
-                       return;
-               p = (char*)kaddr;
-           }
-           db_printf("%c", (*p < ' ' || *p > '~')? ' ': *p);
+       p = 0;
+       tname[0] = 0;
+       
+       if(task->bsd_info) p = getProcName((struct proc *)(task->bsd_info));    /* Point to task name */
+       
+       if(p) {
+               for(i = 0; i < 32; i++) {                       /* Move no more than 32 bytes */
+                       tname[i] = p[i];
+                       if(p[i] == 0) break;
+               }
+               tname[i] = 0;
+               db_printf("%s", tname);
        }
        }
-       while (n-- >= 0)        /* compare with >= 0 for one more space */
-           db_printf(" ");
+       else db_printf("no name");
 }
 
 void
 }
 
 void
@@ -623,7 +547,7 @@ kdb_on(
        int             cpu)
 {
        KDB_SAVE_CTXT();
        int             cpu)
 {
        KDB_SAVE_CTXT();
-       if (cpu < 0 || cpu >= NCPUS || !debugger_active[cpu])
+       if (cpu < 0 || cpu >= real_ncpus || !PerProcTable[cpu].ppe_vaddr->debugger_active)
                return;
        db_set_breakpoints();
        db_set_watchpoints();
                return;
        db_set_breakpoints();
        db_set_watchpoints();
@@ -642,6 +566,9 @@ kdb_on(
 /*
  * system reboot
  */
 /*
  * system reboot
  */
+
+extern int (*PE_halt_restart)(unsigned int type);
+
 void db_reboot(
        db_expr_t       addr,
        boolean_t       have_addr,
 void db_reboot(
        db_expr_t       addr,
        boolean_t       have_addr,
@@ -658,7 +585,11 @@ void db_reboot(
                if (c == 'h')   /* halt */
                        reboot = FALSE;
        }
                if (c == 'h')   /* halt */
                        reboot = FALSE;
        }
-       halt_all_cpus(reboot);
+       if(!reboot) halt_all_cpus(FALSE);       /* If no reboot, try to be clean about it */
+
+       if (PE_halt_restart) return (*PE_halt_restart)(kPERestartCPU);
+       db_printf("Sorry, system can't reboot automatically yet...  You need to do it by hand...\n");
+
 }
 
 /*
 }
 
 /*