Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 | /* * Copyright (c) 2000-2012 Apple 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 * 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 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, * 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_OSREFERENCE_LICENSE_HEADER_END@ */ /* * @OSF_COPYRIGHT@ */ /* * Mach Operating System * Copyright (c) 1991,1990,1989 Carnegie Mellon University * All Rights Reserved. * * Permission to use, copy, modify and distribute this software and its * documentation is hereby granted, provided that both the copyright * notice and this permission notice appear in all copies of the * software, derivative works or modified versions, and any portions * thereof, and that both notices appear in supporting documentation. * * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. * * Carnegie Mellon requests users of this software to return to * * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU * School of Computer Science * Carnegie Mellon University * Pittsburgh PA 15213-3890 * * any improvements or extensions that they make and grant Carnegie Mellon * the rights to redistribute these changes. */ #include <mach_ldebug.h> #include <sys/kdebug.h> #include <mach/kern_return.h> #include <mach/thread_status.h> #include <mach/vm_param.h> #include <kern/mach_param.h> #include <kern/task.h> #include <kern/thread.h> #include <kern/sched_prim.h> #include <kern/misc_protos.h> #include <kern/assert.h> #include <kern/spl.h> #include <ipc/ipc_port.h> #include <vm/vm_kern.h> #include <vm/vm_map.h> #include <vm/pmap.h> #include <i386/cpu_data.h> #include <i386/cpu_number.h> #include <i386/thread.h> #include <i386/eflags.h> #include <i386/proc_reg.h> #include <i386/seg.h> #include <i386/tss.h> #include <i386/user_ldt.h> #include <i386/fpu.h> #include <i386/misc_protos.h> /* * pmap_zero_page zeros the specified (machine independent) page. */ void pmap_zero_page( ppnum_t pn) { assert(pn != vm_page_fictitious_addr); assert(pn != vm_page_guard_addr); bzero_phys((addr64_t)i386_ptob(pn), PAGE_SIZE); } void pmap_zero_page_with_options( ppnum_t pn, __unused int options) { pmap_zero_page(pn); } /* * pmap_zero_part_page * zeros the specified (machine independent) part of a page. */ void pmap_zero_part_page( ppnum_t pn, vm_offset_t offset, vm_size_t len) { assert(pn != vm_page_fictitious_addr); assert(pn != vm_page_guard_addr); assert(offset + len <= PAGE_SIZE); bzero_phys((addr64_t)(i386_ptob(pn) + offset), (uint32_t)len); } /* * pmap_copy_page copies the specified (machine independent) pages. */ void pmap_copy_part_page( ppnum_t psrc, vm_offset_t src_offset, ppnum_t pdst, vm_offset_t dst_offset, vm_size_t len) { pmap_paddr_t src, dst; assert(psrc != vm_page_fictitious_addr); assert(pdst != vm_page_fictitious_addr); assert(psrc != vm_page_guard_addr); assert(pdst != vm_page_guard_addr); src = i386_ptob(psrc); dst = i386_ptob(pdst); assert((((uintptr_t)dst & PAGE_MASK) + dst_offset + len) <= PAGE_SIZE); assert((((uintptr_t)src & PAGE_MASK) + src_offset + len) <= PAGE_SIZE); bcopy_phys((addr64_t)src + (src_offset & INTEL_OFFMASK), (addr64_t)dst + (dst_offset & INTEL_OFFMASK), len); } /* * pmap_copy_part_lpage copies part of a virtually addressed page * to a physically addressed page. */ void pmap_copy_part_lpage( __unused vm_offset_t src, __unused ppnum_t pdst, __unused vm_offset_t dst_offset, __unused vm_size_t len) { assert(pdst != vm_page_fictitious_addr); assert(pdst != vm_page_guard_addr); assert((dst_offset + len) <= PAGE_SIZE); } /* * pmap_copy_part_rpage copies part of a physically addressed page * to a virtually addressed page. */ void pmap_copy_part_rpage( __unused ppnum_t psrc, __unused vm_offset_t src_offset, __unused vm_offset_t dst, __unused vm_size_t len) { assert(psrc != vm_page_fictitious_addr); assert(psrc != vm_page_guard_addr); assert((src_offset + len) <= PAGE_SIZE); } /* * kvtophys(addr) * * Convert a kernel virtual address to a physical address */ addr64_t kvtophys( vm_offset_t addr) { pmap_paddr_t pa; pa = ((pmap_paddr_t)pmap_find_phys(kernel_pmap, addr)) << INTEL_PGSHIFT; if (pa) { pa |= (addr & INTEL_OFFMASK); } return (addr64_t)pa; } extern pt_entry_t *debugger_ptep; extern vm_offset_t debugger_window_kva; extern int _bcopy(const void *, void *, vm_size_t); extern int _bcopy2(const void *, void *); extern int _bcopy4(const void *, void *); extern int _bcopy8(const void *, void *); __private_extern__ int ml_copy_phys(addr64_t src64, addr64_t dst64, vm_size_t bytes) { void *src, *dst; int err = 0; mp_disable_preemption(); addr64_t debug_pa = 0; /* If either destination or source are outside the * physical map, establish a physical window onto the target frame. */ assert(physmap_enclosed(src64) || physmap_enclosed(dst64)); if (physmap_enclosed(src64) == FALSE) { src = (void *)(debugger_window_kva | (src64 & INTEL_OFFMASK)); dst = PHYSMAP_PTOV(dst64); debug_pa = src64 & PG_FRAME; } else if (physmap_enclosed(dst64) == FALSE) { src = PHYSMAP_PTOV(src64); dst = (void *)(debugger_window_kva | (dst64 & INTEL_OFFMASK)); debug_pa = dst64 & PG_FRAME; } else { src = PHYSMAP_PTOV(src64); dst = PHYSMAP_PTOV(dst64); } /* DRK: debugger only routine, we don't bother checking for an * identical mapping. */ if (debug_pa) { if (debugger_window_kva == 0) { panic("%s: invoked in non-debug mode", __FUNCTION__); } /* Establish a cache-inhibited physical window; some platforms * may not cover arbitrary ranges with MTRRs */ pmap_store_pte(FALSE, debugger_ptep, debug_pa | INTEL_PTE_NCACHE | INTEL_PTE_RW | INTEL_PTE_REF | INTEL_PTE_MOD | INTEL_PTE_VALID); pmap_tlbi_range(0, ~0ULL, true, 0); #if DEBUG kprintf("Remapping debugger physical window at %p to 0x%llx\n", (void *)debugger_window_kva, debug_pa); #endif } /* ensure we stay within a page */ if (((((uint32_t)src64 & (I386_PGBYTES - 1)) + bytes) > I386_PGBYTES) || ((((uint32_t)dst64 & (I386_PGBYTES - 1)) + bytes) > I386_PGBYTES)) { panic("ml_copy_phys spans pages, src: 0x%llx, dst: 0x%llx", src64, dst64); } /* * For device register access from the debugger, * 2-byte/16-bit, 4-byte/32-bit and 8-byte/64-bit copies are handled * by assembly routines ensuring the required access widths. * 1-byte and other copies are handled by the regular _bcopy. */ switch (bytes) { case 2: err = _bcopy2(src, dst); break; case 4: err = _bcopy4(src, dst); break; case 8: err = _bcopy8(src, dst); break; case 1: default: err = _bcopy(src, dst, bytes); break; } mp_enable_preemption(); return err; } |