]>
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 vm_offset_t src
, dst
;
124 assert(psrc
!= vm_page_fictitious_addr
);
125 assert(pdst
!= vm_page_fictitious_addr
);
126 src
= (vm_offset_t
)i386_ptob(psrc
);
127 dst
= (vm_offset_t
)i386_ptob(pdst
);
128 assert(((dst
& PAGE_MASK
) + dst_offset
+ len
) <= PAGE_SIZE
);
129 assert(((src
& PAGE_MASK
) + src_offset
+ len
) <= PAGE_SIZE
);
130 bcopy_phys((addr64_t
)src
+ (src_offset
& INTEL_OFFMASK
),
131 (addr64_t
)dst
+ (dst_offset
& INTEL_OFFMASK
),
136 * pmap_copy_part_lpage copies part of a virtually addressed page
137 * to a physically addressed page.
140 pmap_copy_part_lpage(
143 vm_offset_t dst_offset
,
147 thread_t thr_act
= current_thread();
149 assert(pdst
!= vm_page_fictitious_addr
);
150 ptep
= pmap_pte(thr_act
->map
->pmap
, i386_ptob(pdst
));
152 panic("pmap_copy_part_lpage ptep");
153 assert(((pdst
& PAGE_MASK
) + dst_offset
+ len
) <= PAGE_SIZE
);
154 if (*(pt_entry_t
*) CM2
)
155 panic("pmap_copy_part_lpage");
156 *(int *) CM2
= INTEL_PTE_VALID
| INTEL_PTE_RW
| (*ptep
& PG_FRAME
) |
157 INTEL_PTE_REF
| INTEL_PTE_MOD
;
158 invlpg((unsigned int) CA2
);
159 memcpy((void *) (CA2
+ (dst_offset
& INTEL_OFFMASK
)), (void *) src
, len
);
160 *(pt_entry_t
*) CM2
= 0;
164 * pmap_copy_part_rpage copies part of a physically addressed page
165 * to a virtually addressed page.
168 pmap_copy_part_rpage(
170 vm_offset_t src_offset
,
175 thread_t thr_act
= current_thread();
177 assert(psrc
!= vm_page_fictitious_addr
);
178 ptep
= pmap_pte(thr_act
->map
->pmap
, i386_ptob(psrc
));
180 panic("pmap_copy_part_rpage ptep");
181 assert(((psrc
& PAGE_MASK
) + src_offset
+ len
) <= PAGE_SIZE
);
182 if (*(pt_entry_t
*) CM2
)
183 panic("pmap_copy_part_rpage");
184 *(pt_entry_t
*) CM2
= INTEL_PTE_VALID
| INTEL_PTE_RW
| (*ptep
& PG_FRAME
) |
186 invlpg((unsigned int) CA2
);
187 memcpy((void *) dst
, (void *) (CA2
+ (src_offset
& INTEL_OFFMASK
)), len
);
188 *(pt_entry_t
*) CM2
= 0;
194 * Convert a kernel virtual address to a physical address
203 if ((ptep
= pmap_pte(kernel_pmap
, addr
)) == PT_ENTRY_NULL
) {
206 pa
= pte_to_pa(*ptep
) | (addr
& INTEL_OFFMASK
);
209 kprintf("kvtophys ret 0!\n");