]>
git.saurik.com Git - apple/xnu.git/blob - osfmk/i386/phys.c
ad2316fe7e19f7aca4a6c8febacb9061f31aef3d
2 * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_OSREFERENCE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
34 * Mach Operating System
35 * Copyright (c) 1991,1990,1989 Carnegie Mellon University
36 * All Rights Reserved.
38 * Permission to use, copy, modify and distribute this software and its
39 * documentation is hereby granted, provided that both the copyright
40 * notice and this permission notice appear in all copies of the
41 * software, derivative works or modified versions, and any portions
42 * thereof, and that both notices appear in supporting documentation.
44 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
45 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
46 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
48 * Carnegie Mellon requests users of this software to return to
50 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
51 * School of Computer Science
52 * Carnegie Mellon University
53 * Pittsburgh PA 15213-3890
55 * any improvements or extensions that they make and grant Carnegie Mellon
56 * the rights to redistribute these changes.
60 #include <mach_debug.h>
61 #include <mach_ldebug.h>
63 #include <sys/kdebug.h>
65 #include <mach/kern_return.h>
66 #include <mach/thread_status.h>
67 #include <mach/vm_param.h>
69 #include <kern/counters.h>
70 #include <kern/mach_param.h>
71 #include <kern/task.h>
72 #include <kern/thread.h>
73 #include <kern/sched_prim.h>
74 #include <kern/misc_protos.h>
75 #include <kern/assert.h>
77 #include <ipc/ipc_port.h>
78 #include <vm/vm_kern.h>
79 #include <vm/vm_map.h>
82 #include <i386/cpu_data.h>
83 #include <i386/cpu_number.h>
84 #include <i386/thread.h>
85 #include <i386/eflags.h>
86 #include <i386/proc_reg.h>
89 #include <i386/user_ldt.h>
91 #include <i386/iopb_entries.h>
92 #include <i386/misc_protos.h>
95 * pmap_zero_page zeros the specified (machine independent) page.
101 assert(pn
!= vm_page_fictitious_addr
);
102 bzero_phys((addr64_t
)i386_ptob(pn
), PAGE_SIZE
);
106 * pmap_zero_part_page
107 * zeros the specified (machine independent) part of a page.
115 assert(pn
!= vm_page_fictitious_addr
);
116 assert(offset
+ len
<= PAGE_SIZE
);
117 bzero_phys((addr64_t
)(i386_ptob(pn
) + offset
), len
);
121 * pmap_copy_page copies the specified (machine independent) pages.
126 vm_offset_t src_offset
,
128 vm_offset_t dst_offset
,
131 pmap_paddr_t src
, dst
;
133 assert(psrc
!= vm_page_fictitious_addr
);
134 assert(pdst
!= vm_page_fictitious_addr
);
136 src
= i386_ptob(psrc
);
137 dst
= i386_ptob(pdst
);
139 assert((((uint32_t)dst
& PAGE_MASK
) + dst_offset
+ len
) <= PAGE_SIZE
);
140 assert((((uint32_t)src
& PAGE_MASK
) + src_offset
+ len
) <= PAGE_SIZE
);
142 bcopy_phys((addr64_t
)src
+ (src_offset
& INTEL_OFFMASK
),
143 (addr64_t
)dst
+ (dst_offset
& INTEL_OFFMASK
),
148 * pmap_copy_part_lpage copies part of a virtually addressed page
149 * to a physically addressed page.
152 pmap_copy_part_lpage(
155 vm_offset_t dst_offset
,
160 assert(pdst
!= vm_page_fictitious_addr
);
161 assert((dst_offset
+ len
) <= PAGE_SIZE
);
163 mp_disable_preemption();
165 map
= pmap_get_mapwindow(INTEL_PTE_VALID
| INTEL_PTE_RW
| (i386_ptob(pdst
) & PG_FRAME
) |
166 INTEL_PTE_REF
| INTEL_PTE_MOD
);
168 panic("pmap_copy_part_lpage");
170 invlpg((uintptr_t)map
->prv_CADDR
);
172 memcpy((void *) (map
->prv_CADDR
+ (dst_offset
& INTEL_OFFMASK
)), (void *) src
, len
);
175 mp_enable_preemption();
179 * pmap_copy_part_rpage copies part of a physically addressed page
180 * to a virtually addressed page.
183 pmap_copy_part_rpage(
185 vm_offset_t src_offset
,
191 assert(psrc
!= vm_page_fictitious_addr
);
192 assert((src_offset
+ len
) <= PAGE_SIZE
);
194 mp_disable_preemption();
196 map
= pmap_get_mapwindow(INTEL_PTE_VALID
| INTEL_PTE_RW
| (i386_ptob(psrc
) & PG_FRAME
) |
199 panic("pmap_copy_part_rpage");
201 invlpg((uintptr_t) map
->prv_CADDR
);
203 memcpy((void *) dst
, (void *) (map
->prv_CADDR
+ (src_offset
& INTEL_OFFMASK
)), len
);
206 mp_enable_preemption();
212 * Convert a kernel virtual address to a physical address
221 if ((ptep
= pmap_pte(kernel_pmap
, (vm_map_offset_t
)addr
)) == PT_ENTRY_NULL
) {
224 pa
= pte_to_pa(*ptep
) | (addr
& INTEL_OFFMASK
);
227 return ((addr64_t
)pa
);