]>
Commit | Line | Data |
---|---|---|
1c79356b | 1 | /* |
91447636 | 2 | * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved. |
1c79356b | 3 | * |
6601e61a | 4 | * @APPLE_LICENSE_HEADER_START@ |
1c79356b | 5 | * |
6601e61a A |
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. | |
8f6c56a5 | 11 | * |
6601e61a A |
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 | |
8f6c56a5 A |
14 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
15 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
6601e61a A |
16 | * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the |
17 | * License for the specific language governing rights and limitations | |
18 | * under the License. | |
8f6c56a5 | 19 | * |
6601e61a | 20 | * @APPLE_LICENSE_HEADER_END@ |
1c79356b A |
21 | */ |
22 | /* | |
23 | * @OSF_COPYRIGHT@ | |
24 | */ | |
25 | /* | |
26 | * Mach Operating System | |
27 | * Copyright (c) 1991,1990,1989 Carnegie Mellon University | |
28 | * All Rights Reserved. | |
29 | * | |
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. | |
35 | * | |
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. | |
39 | * | |
40 | * Carnegie Mellon requests users of this software to return to | |
41 | * | |
42 | * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU | |
43 | * School of Computer Science | |
44 | * Carnegie Mellon University | |
45 | * Pittsburgh PA 15213-3890 | |
46 | * | |
47 | * any improvements or extensions that they make and grant Carnegie Mellon | |
48 | * the rights to redistribute these changes. | |
49 | */ | |
1c79356b | 50 | |
91447636 A |
51 | #include <mach_rt.h> |
52 | #include <mach_debug.h> | |
53 | #include <mach_ldebug.h> | |
54 | ||
55 | #include <sys/kdebug.h> | |
56 | ||
57 | #include <mach/kern_return.h> | |
58 | #include <mach/thread_status.h> | |
1c79356b | 59 | #include <mach/vm_param.h> |
91447636 A |
60 | |
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> | |
1c79356b | 66 | #include <kern/misc_protos.h> |
91447636 A |
67 | #include <kern/assert.h> |
68 | #include <kern/spl.h> | |
69 | #include <ipc/ipc_port.h> | |
70 | #include <vm/vm_kern.h> | |
71 | #include <vm/vm_map.h> | |
72 | #include <vm/pmap.h> | |
73 | ||
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> | |
79 | #include <i386/seg.h> | |
80 | #include <i386/tss.h> | |
81 | #include <i386/user_ldt.h> | |
82 | #include <i386/fpu.h> | |
83 | #include <i386/iopb_entries.h> | |
84 | #include <i386/misc_protos.h> | |
1c79356b A |
85 | |
86 | /* | |
87 | * pmap_zero_page zeros the specified (machine independent) page. | |
88 | */ | |
89 | void | |
90 | pmap_zero_page( | |
55e303ae | 91 | ppnum_t pn) |
1c79356b | 92 | { |
55e303ae | 93 | assert(pn != vm_page_fictitious_addr); |
91447636 | 94 | bzero_phys((addr64_t)i386_ptob(pn), PAGE_SIZE); |
1c79356b A |
95 | } |
96 | ||
97 | /* | |
98 | * pmap_zero_part_page | |
99 | * zeros the specified (machine independent) part of a page. | |
100 | */ | |
101 | void | |
102 | pmap_zero_part_page( | |
55e303ae | 103 | ppnum_t pn, |
1c79356b A |
104 | vm_offset_t offset, |
105 | vm_size_t len) | |
106 | { | |
55e303ae | 107 | assert(pn != vm_page_fictitious_addr); |
1c79356b | 108 | assert(offset + len <= PAGE_SIZE); |
91447636 | 109 | bzero_phys((addr64_t)(i386_ptob(pn) + offset), len); |
1c79356b A |
110 | } |
111 | ||
112 | /* | |
113 | * pmap_copy_page copies the specified (machine independent) pages. | |
114 | */ | |
115 | void | |
116 | pmap_copy_part_page( | |
55e303ae | 117 | ppnum_t psrc, |
1c79356b | 118 | vm_offset_t src_offset, |
55e303ae | 119 | ppnum_t pdst, |
1c79356b A |
120 | vm_offset_t dst_offset, |
121 | vm_size_t len) | |
122 | { | |
6601e61a | 123 | vm_offset_t src, dst; |
55e303ae A |
124 | assert(psrc != vm_page_fictitious_addr); |
125 | assert(pdst != vm_page_fictitious_addr); | |
6601e61a A |
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); | |
91447636 A |
130 | bcopy_phys((addr64_t)src + (src_offset & INTEL_OFFMASK), |
131 | (addr64_t)dst + (dst_offset & INTEL_OFFMASK), | |
132 | len); | |
1c79356b A |
133 | } |
134 | ||
135 | /* | |
136 | * pmap_copy_part_lpage copies part of a virtually addressed page | |
137 | * to a physically addressed page. | |
138 | */ | |
139 | void | |
140 | pmap_copy_part_lpage( | |
55e303ae A |
141 | vm_offset_t src, |
142 | ppnum_t pdst, | |
1c79356b A |
143 | vm_offset_t dst_offset, |
144 | vm_size_t len) | |
145 | { | |
6601e61a A |
146 | pt_entry_t *ptep; |
147 | thread_t thr_act = current_thread(); | |
55e303ae | 148 | |
55e303ae | 149 | assert(pdst != vm_page_fictitious_addr); |
6601e61a A |
150 | ptep = pmap_pte(thr_act->map->pmap, i386_ptob(pdst)); |
151 | if (0 == ptep) | |
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; | |
1c79356b A |
161 | } |
162 | ||
163 | /* | |
164 | * pmap_copy_part_rpage copies part of a physically addressed page | |
165 | * to a virtually addressed page. | |
166 | */ | |
167 | void | |
168 | pmap_copy_part_rpage( | |
55e303ae | 169 | ppnum_t psrc, |
1c79356b A |
170 | vm_offset_t src_offset, |
171 | vm_offset_t dst, | |
172 | vm_size_t len) | |
173 | { | |
6601e61a A |
174 | pt_entry_t *ptep; |
175 | thread_t thr_act = current_thread(); | |
55e303ae A |
176 | |
177 | assert(psrc != vm_page_fictitious_addr); | |
6601e61a A |
178 | ptep = pmap_pte(thr_act->map->pmap, i386_ptob(psrc)); |
179 | if (0 == ptep) | |
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) | | |
185 | INTEL_PTE_REF; | |
186 | invlpg((unsigned int) CA2); | |
187 | memcpy((void *) dst, (void *) (CA2 + (src_offset & INTEL_OFFMASK)), len); | |
188 | *(pt_entry_t *) CM2 = 0; | |
1c79356b A |
189 | } |
190 | ||
191 | /* | |
192 | * kvtophys(addr) | |
193 | * | |
194 | * Convert a kernel virtual address to a physical address | |
195 | */ | |
6601e61a | 196 | vm_offset_t |
1c79356b A |
197 | kvtophys( |
198 | vm_offset_t addr) | |
199 | { | |
91447636 A |
200 | pt_entry_t *ptep; |
201 | pmap_paddr_t pa; | |
6601e61a A |
202 | |
203 | if ((ptep = pmap_pte(kernel_pmap, addr)) == PT_ENTRY_NULL) { | |
204 | pa = 0; | |
91447636 | 205 | } else { |
6601e61a | 206 | pa = pte_to_pa(*ptep) | (addr & INTEL_OFFMASK); |
91447636 | 207 | } |
6601e61a A |
208 | if (0 == pa) |
209 | kprintf("kvtophys ret 0!\n"); | |
210 | return (pa); | |
1c79356b | 211 | } |