]>
git.saurik.com Git - apple/xnu.git/blob - osfmk/i386/phys.c
2 * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
26 * Mach Operating System
27 * Copyright (c) 1991,1990,1989 Carnegie Mellon University
28 * All Rights Reserved.
30 * Permission to use, copy, modify and distribute this software and its
31 * documentation is hereby granted, provided that both the copyright
32 * notice and this permission notice appear in all copies of the
33 * software, derivative works or modified versions, and any portions
34 * thereof, and that both notices appear in supporting documentation.
36 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
37 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
38 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
40 * Carnegie Mellon requests users of this software to return to
42 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
43 * School of Computer Science
44 * Carnegie Mellon University
45 * Pittsburgh PA 15213-3890
47 * any improvements or extensions that they make and grant Carnegie Mellon
48 * the rights to redistribute these changes.
52 #include <mach_debug.h>
53 #include <mach_ldebug.h>
55 #include <sys/kdebug.h>
57 #include <mach/kern_return.h>
58 #include <mach/thread_status.h>
59 #include <mach/vm_param.h>
61 #include <kern/counters.h>
62 #include <kern/mach_param.h>
63 #include <kern/task.h>
64 #include <kern/thread.h>
65 #include <kern/sched_prim.h>
66 #include <kern/misc_protos.h>
67 #include <kern/assert.h>
69 #include <ipc/ipc_port.h>
70 #include <vm/vm_kern.h>
71 #include <vm/vm_map.h>
74 #include <i386/cpu_data.h>
75 #include <i386/cpu_number.h>
76 #include <i386/thread.h>
77 #include <i386/eflags.h>
78 #include <i386/proc_reg.h>
81 #include <i386/user_ldt.h>
83 #include <i386/iopb_entries.h>
84 #include <i386/misc_protos.h>
87 * pmap_zero_page zeros the specified (machine independent) page.
93 assert(pn
!= vm_page_fictitious_addr
);
94 bzero_phys((addr64_t
)i386_ptob(pn
), PAGE_SIZE
);
99 * zeros the specified (machine independent) part of a page.
107 assert(pn
!= vm_page_fictitious_addr
);
108 assert(offset
+ len
<= PAGE_SIZE
);
109 bzero_phys((addr64_t
)(i386_ptob(pn
) + offset
), len
);
113 * pmap_copy_page copies the specified (machine independent) pages.
118 vm_offset_t src_offset
,
120 vm_offset_t dst_offset
,
123 pmap_paddr_t src
, dst
;
125 assert(psrc
!= vm_page_fictitious_addr
);
126 assert(pdst
!= vm_page_fictitious_addr
);
128 src
= i386_ptob(psrc
);
129 dst
= i386_ptob(pdst
);
131 assert((((uint32_t)dst
& PAGE_MASK
) + dst_offset
+ len
) <= PAGE_SIZE
);
132 assert((((uint32_t)src
& PAGE_MASK
) + src_offset
+ len
) <= PAGE_SIZE
);
134 bcopy_phys((addr64_t
)src
+ (src_offset
& INTEL_OFFMASK
),
135 (addr64_t
)dst
+ (dst_offset
& INTEL_OFFMASK
),
140 * pmap_copy_part_lpage copies part of a virtually addressed page
141 * to a physically addressed page.
144 pmap_copy_part_lpage(
147 vm_offset_t dst_offset
,
152 assert(pdst
!= vm_page_fictitious_addr
);
153 assert((dst_offset
+ len
) <= PAGE_SIZE
);
155 mp_disable_preemption();
157 map
= pmap_get_mapwindow(INTEL_PTE_VALID
| INTEL_PTE_RW
| (i386_ptob(pdst
) & PG_FRAME
) |
158 INTEL_PTE_REF
| INTEL_PTE_MOD
);
160 panic("pmap_copy_part_lpage");
162 invlpg((uintptr_t)map
->prv_CADDR
);
164 memcpy((void *) (map
->prv_CADDR
+ (dst_offset
& INTEL_OFFMASK
)), (void *) src
, len
);
167 mp_enable_preemption();
171 * pmap_copy_part_rpage copies part of a physically addressed page
172 * to a virtually addressed page.
175 pmap_copy_part_rpage(
177 vm_offset_t src_offset
,
183 assert(psrc
!= vm_page_fictitious_addr
);
184 assert((src_offset
+ len
) <= PAGE_SIZE
);
186 mp_disable_preemption();
188 map
= pmap_get_mapwindow(INTEL_PTE_VALID
| INTEL_PTE_RW
| (i386_ptob(psrc
) & PG_FRAME
) |
191 panic("pmap_copy_part_rpage");
193 invlpg((uintptr_t) map
->prv_CADDR
);
195 memcpy((void *) dst
, (void *) (map
->prv_CADDR
+ (src_offset
& INTEL_OFFMASK
)), len
);
198 mp_enable_preemption();
204 * Convert a kernel virtual address to a physical address
213 mp_disable_preemption();
214 if ((ptep
= pmap_pte(kernel_pmap
, (vm_map_offset_t
)addr
)) == PT_ENTRY_NULL
) {
217 pa
= pte_to_pa(*ptep
) | (addr
& INTEL_OFFMASK
);
219 mp_enable_preemption_no_check();
220 return ((addr64_t
)pa
);