]>
git.saurik.com Git - apple/xnu.git/blob - osfmk/i386/phys.c
9bee4543500fd62e96429a8265730c2d7f825b5b
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 vm_offset_t src
, dst
;
132 assert(psrc
!= vm_page_fictitious_addr
);
133 assert(pdst
!= vm_page_fictitious_addr
);
134 src
= (vm_offset_t
)i386_ptob(psrc
);
135 dst
= (vm_offset_t
)i386_ptob(pdst
);
136 assert(((dst
& PAGE_MASK
) + dst_offset
+ len
) <= PAGE_SIZE
);
137 assert(((src
& PAGE_MASK
) + src_offset
+ len
) <= PAGE_SIZE
);
138 bcopy_phys((addr64_t
)src
+ (src_offset
& INTEL_OFFMASK
),
139 (addr64_t
)dst
+ (dst_offset
& INTEL_OFFMASK
),
144 * pmap_copy_part_lpage copies part of a virtually addressed page
145 * to a physically addressed page.
148 pmap_copy_part_lpage(
151 vm_offset_t dst_offset
,
155 thread_t thr_act
= current_thread();
157 assert(pdst
!= vm_page_fictitious_addr
);
158 ptep
= pmap_pte(thr_act
->map
->pmap
, i386_ptob(pdst
));
160 panic("pmap_copy_part_lpage ptep");
161 assert(((pdst
& PAGE_MASK
) + dst_offset
+ len
) <= PAGE_SIZE
);
162 if (*(pt_entry_t
*) CM2
)
163 panic("pmap_copy_part_lpage");
164 *(int *) CM2
= INTEL_PTE_VALID
| INTEL_PTE_RW
| (*ptep
& PG_FRAME
) |
165 INTEL_PTE_REF
| INTEL_PTE_MOD
;
166 invlpg((unsigned int) CA2
);
167 memcpy((void *) (CA2
+ (dst_offset
& INTEL_OFFMASK
)), (void *) src
, len
);
168 *(pt_entry_t
*) CM2
= 0;
172 * pmap_copy_part_rpage copies part of a physically addressed page
173 * to a virtually addressed page.
176 pmap_copy_part_rpage(
178 vm_offset_t src_offset
,
183 thread_t thr_act
= current_thread();
185 assert(psrc
!= vm_page_fictitious_addr
);
186 ptep
= pmap_pte(thr_act
->map
->pmap
, i386_ptob(psrc
));
188 panic("pmap_copy_part_rpage ptep");
189 assert(((psrc
& PAGE_MASK
) + src_offset
+ len
) <= PAGE_SIZE
);
190 if (*(pt_entry_t
*) CM2
)
191 panic("pmap_copy_part_rpage");
192 *(pt_entry_t
*) CM2
= INTEL_PTE_VALID
| INTEL_PTE_RW
| (*ptep
& PG_FRAME
) |
194 invlpg((unsigned int) CA2
);
195 memcpy((void *) dst
, (void *) (CA2
+ (src_offset
& INTEL_OFFMASK
)), len
);
196 *(pt_entry_t
*) CM2
= 0;
202 * Convert a kernel virtual address to a physical address
211 if ((ptep
= pmap_pte(kernel_pmap
, addr
)) == PT_ENTRY_NULL
) {
214 pa
= pte_to_pa(*ptep
) | (addr
& INTEL_OFFMASK
);
217 kprintf("kvtophys ret 0!\n");