]>
Commit | Line | Data |
---|---|---|
1c79356b | 1 | /* |
91447636 | 2 | * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved. |
1c79356b | 3 | * |
8ad349bb | 4 | * @APPLE_LICENSE_OSREFERENCE_HEADER_START@ |
1c79356b | 5 | * |
8ad349bb A |
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 | |
14 | * agreement. | |
15 | * | |
16 | * Please obtain a copy of the License at | |
17 | * http://www.opensource.apple.com/apsl/ and read it before using this | |
18 | * file. | |
19 | * | |
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. | |
27 | * | |
28 | * @APPLE_LICENSE_OSREFERENCE_HEADER_END@ | |
1c79356b A |
29 | */ |
30 | /* | |
31 | * @OSF_COPYRIGHT@ | |
32 | */ | |
33 | /* | |
34 | * Mach Operating System | |
35 | * Copyright (c) 1991,1990,1989 Carnegie Mellon University | |
36 | * All Rights Reserved. | |
37 | * | |
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. | |
43 | * | |
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. | |
47 | * | |
48 | * Carnegie Mellon requests users of this software to return to | |
49 | * | |
50 | * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU | |
51 | * School of Computer Science | |
52 | * Carnegie Mellon University | |
53 | * Pittsburgh PA 15213-3890 | |
54 | * | |
55 | * any improvements or extensions that they make and grant Carnegie Mellon | |
56 | * the rights to redistribute these changes. | |
57 | */ | |
1c79356b | 58 | |
91447636 A |
59 | #include <mach_rt.h> |
60 | #include <mach_debug.h> | |
61 | #include <mach_ldebug.h> | |
62 | ||
63 | #include <sys/kdebug.h> | |
64 | ||
65 | #include <mach/kern_return.h> | |
66 | #include <mach/thread_status.h> | |
1c79356b | 67 | #include <mach/vm_param.h> |
91447636 A |
68 | |
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> | |
1c79356b | 74 | #include <kern/misc_protos.h> |
91447636 A |
75 | #include <kern/assert.h> |
76 | #include <kern/spl.h> | |
77 | #include <ipc/ipc_port.h> | |
78 | #include <vm/vm_kern.h> | |
79 | #include <vm/vm_map.h> | |
80 | #include <vm/pmap.h> | |
81 | ||
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> | |
87 | #include <i386/seg.h> | |
88 | #include <i386/tss.h> | |
89 | #include <i386/user_ldt.h> | |
90 | #include <i386/fpu.h> | |
91 | #include <i386/iopb_entries.h> | |
92 | #include <i386/misc_protos.h> | |
1c79356b A |
93 | |
94 | /* | |
95 | * pmap_zero_page zeros the specified (machine independent) page. | |
96 | */ | |
97 | void | |
98 | pmap_zero_page( | |
55e303ae | 99 | ppnum_t pn) |
1c79356b | 100 | { |
55e303ae | 101 | assert(pn != vm_page_fictitious_addr); |
91447636 | 102 | bzero_phys((addr64_t)i386_ptob(pn), PAGE_SIZE); |
1c79356b A |
103 | } |
104 | ||
105 | /* | |
106 | * pmap_zero_part_page | |
107 | * zeros the specified (machine independent) part of a page. | |
108 | */ | |
109 | void | |
110 | pmap_zero_part_page( | |
55e303ae | 111 | ppnum_t pn, |
1c79356b A |
112 | vm_offset_t offset, |
113 | vm_size_t len) | |
114 | { | |
55e303ae | 115 | assert(pn != vm_page_fictitious_addr); |
1c79356b | 116 | assert(offset + len <= PAGE_SIZE); |
91447636 | 117 | bzero_phys((addr64_t)(i386_ptob(pn) + offset), len); |
1c79356b A |
118 | } |
119 | ||
120 | /* | |
121 | * pmap_copy_page copies the specified (machine independent) pages. | |
122 | */ | |
123 | void | |
124 | pmap_copy_part_page( | |
55e303ae | 125 | ppnum_t psrc, |
1c79356b | 126 | vm_offset_t src_offset, |
55e303ae | 127 | ppnum_t pdst, |
1c79356b A |
128 | vm_offset_t dst_offset, |
129 | vm_size_t len) | |
130 | { | |
5d5c5d0d A |
131 | pmap_paddr_t src, dst; |
132 | ||
55e303ae A |
133 | assert(psrc != vm_page_fictitious_addr); |
134 | assert(pdst != vm_page_fictitious_addr); | |
5d5c5d0d A |
135 | |
136 | src = i386_ptob(psrc); | |
137 | dst = i386_ptob(pdst); | |
138 | ||
139 | assert((((uint32_t)dst & PAGE_MASK) + dst_offset + len) <= PAGE_SIZE); | |
140 | assert((((uint32_t)src & PAGE_MASK) + src_offset + len) <= PAGE_SIZE); | |
141 | ||
91447636 A |
142 | bcopy_phys((addr64_t)src + (src_offset & INTEL_OFFMASK), |
143 | (addr64_t)dst + (dst_offset & INTEL_OFFMASK), | |
144 | len); | |
1c79356b A |
145 | } |
146 | ||
147 | /* | |
148 | * pmap_copy_part_lpage copies part of a virtually addressed page | |
149 | * to a physically addressed page. | |
150 | */ | |
151 | void | |
152 | pmap_copy_part_lpage( | |
55e303ae A |
153 | vm_offset_t src, |
154 | ppnum_t pdst, | |
1c79356b A |
155 | vm_offset_t dst_offset, |
156 | vm_size_t len) | |
157 | { | |
5d5c5d0d | 158 | mapwindow_t *map; |
55e303ae | 159 | |
55e303ae | 160 | assert(pdst != vm_page_fictitious_addr); |
5d5c5d0d A |
161 | assert((dst_offset + len) <= PAGE_SIZE); |
162 | ||
163 | mp_disable_preemption(); | |
164 | ||
165 | map = pmap_get_mapwindow(INTEL_PTE_VALID | INTEL_PTE_RW | (i386_ptob(pdst) & PG_FRAME) | | |
166 | INTEL_PTE_REF | INTEL_PTE_MOD); | |
167 | if (map == 0) { | |
168 | panic("pmap_copy_part_lpage"); | |
169 | } | |
170 | invlpg((uintptr_t)map->prv_CADDR); | |
171 | ||
172 | memcpy((void *) (map->prv_CADDR + (dst_offset & INTEL_OFFMASK)), (void *) src, len); | |
173 | *map->prv_CMAP = 0; | |
174 | ||
175 | mp_enable_preemption(); | |
1c79356b A |
176 | } |
177 | ||
178 | /* | |
179 | * pmap_copy_part_rpage copies part of a physically addressed page | |
180 | * to a virtually addressed page. | |
181 | */ | |
182 | void | |
183 | pmap_copy_part_rpage( | |
55e303ae | 184 | ppnum_t psrc, |
1c79356b A |
185 | vm_offset_t src_offset, |
186 | vm_offset_t dst, | |
187 | vm_size_t len) | |
188 | { | |
5d5c5d0d | 189 | mapwindow_t *map; |
55e303ae A |
190 | |
191 | assert(psrc != vm_page_fictitious_addr); | |
5d5c5d0d A |
192 | assert((src_offset + len) <= PAGE_SIZE); |
193 | ||
194 | mp_disable_preemption(); | |
195 | ||
196 | map = pmap_get_mapwindow(INTEL_PTE_VALID | INTEL_PTE_RW | (i386_ptob(psrc) & PG_FRAME) | | |
197 | INTEL_PTE_REF); | |
198 | if (map == 0) { | |
199 | panic("pmap_copy_part_rpage"); | |
200 | } | |
201 | invlpg((uintptr_t) map->prv_CADDR); | |
202 | ||
203 | memcpy((void *) dst, (void *) (map->prv_CADDR + (src_offset & INTEL_OFFMASK)), len); | |
204 | *map->prv_CMAP = 0; | |
205 | ||
206 | mp_enable_preemption(); | |
1c79356b A |
207 | } |
208 | ||
209 | /* | |
210 | * kvtophys(addr) | |
211 | * | |
212 | * Convert a kernel virtual address to a physical address | |
213 | */ | |
5d5c5d0d | 214 | addr64_t |
1c79356b A |
215 | kvtophys( |
216 | vm_offset_t addr) | |
217 | { | |
91447636 A |
218 | pt_entry_t *ptep; |
219 | pmap_paddr_t pa; | |
220 | ||
5d5c5d0d A |
221 | if ((ptep = pmap_pte(kernel_pmap, (vm_map_offset_t)addr)) == PT_ENTRY_NULL) { |
222 | pa = 0; | |
91447636 | 223 | } else { |
5d5c5d0d | 224 | pa = pte_to_pa(*ptep) | (addr & INTEL_OFFMASK); |
91447636 | 225 | } |
5d5c5d0d A |
226 | |
227 | return ((addr64_t)pa); | |
1c79356b | 228 | } |
5d5c5d0d | 229 |