]>
Commit | Line | Data |
---|---|---|
1c79356b A |
1 | /* |
2 | * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
d7e50217 | 6 | * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. |
1c79356b | 7 | * |
d7e50217 A |
8 | * This file contains Original Code and/or Modifications of Original Code |
9 | * as defined in and that are subject to the Apple Public Source License | |
10 | * Version 2.0 (the 'License'). You may not use this file except in | |
11 | * compliance with the License. Please obtain a copy of the License at | |
12 | * http://www.opensource.apple.com/apsl/ and read it before using this | |
13 | * file. | |
14 | * | |
15 | * The Original Code and all software distributed under the License are | |
16 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
1c79356b A |
17 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
18 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
d7e50217 A |
19 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. |
20 | * Please see the License for the specific language governing rights and | |
21 | * limitations under the License. | |
1c79356b A |
22 | * |
23 | * @APPLE_LICENSE_HEADER_END@ | |
24 | */ | |
25 | #include <mach/mach_types.h> | |
26 | #include <mach/vm_attributes.h> | |
27 | #include <mach/vm_param.h> | |
28 | ||
29 | #include <vm/pmap.h> | |
30 | ||
31 | #include <ppc/proc_reg.h> | |
32 | #include <ppc/machparam.h> | |
33 | #include <ppc/mem.h> | |
34 | #include <ppc/pmap.h> | |
1c79356b A |
35 | #include <ppc/mappings.h> |
36 | ||
37 | pmap_t kdp_pmap=0; | |
38 | boolean_t kdp_trans_off=0; | |
d7e50217 | 39 | boolean_t kdp_read_io =0; |
1c79356b | 40 | |
1c79356b A |
41 | unsigned kdp_vm_read( caddr_t, caddr_t, unsigned); |
42 | unsigned kdp_vm_write( caddr_t, caddr_t, unsigned); | |
43 | ||
1c79356b A |
44 | |
45 | /* | |
46 | * | |
47 | */ | |
d7e50217 | 48 | addr64_t kdp_vtophys( |
1c79356b | 49 | pmap_t pmap, |
d7e50217 | 50 | addr64_t va) |
1c79356b | 51 | { |
d7e50217 A |
52 | addr64_t pa; |
53 | ppnum_t pp; | |
1c79356b | 54 | |
d7e50217 A |
55 | pp = pmap_find_phys(pmap, va); /* Get the page number */ |
56 | if(!pp) return 0; /* Just return if no translation */ | |
57 | ||
58 | pa = ((addr64_t)pp << 12) | (va & 0x0000000000000FFFULL); /* Shove in the page offset */ | |
1c79356b A |
59 | return(pa); |
60 | } | |
61 | ||
1c79356b A |
62 | /* |
63 | * | |
64 | */ | |
65 | unsigned kdp_vm_read( | |
66 | caddr_t src, | |
67 | caddr_t dst, | |
68 | unsigned len) | |
69 | { | |
d7e50217 A |
70 | addr64_t cur_virt_src, cur_virt_dst; |
71 | addr64_t cur_phys_src; | |
1c79356b | 72 | unsigned resid, cnt; |
d7e50217 A |
73 | unsigned int dummy; |
74 | pmap_t pmap; | |
1c79356b A |
75 | |
76 | #ifdef KDP_VM_READ_DEBUG | |
77 | kprintf("kdp_vm_read1: src %x dst %x len %x - %08X %08X\n", src, dst, len, ((unsigned long *)src)[0], ((unsigned long *)src)[1]); | |
78 | #endif | |
d7e50217 A |
79 | |
80 | cur_virt_src = (addr64_t)((unsigned int)src); | |
81 | cur_virt_dst = (addr64_t)((unsigned int)dst); | |
82 | ||
1c79356b | 83 | if (kdp_trans_off) { |
d7e50217 A |
84 | |
85 | ||
86 | resid = len; /* Get the length to copy */ | |
1c79356b A |
87 | |
88 | while (resid != 0) { | |
d7e50217 A |
89 | |
90 | if(kdp_read_io == 0) | |
91 | if(!mapping_phys_lookup((ppnum_t)(cur_virt_src >> 12), &dummy)) return 0; /* Can't read where there's not any memory */ | |
92 | ||
93 | cnt = 4096 - (cur_virt_src & 0xFFF); /* Get length left on page */ | |
94 | ||
1c79356b | 95 | if (cnt > resid) cnt = resid; |
d7e50217 A |
96 | |
97 | bcopy_phys(cur_virt_src, cur_virt_dst, cnt); /* Copy stuff over */ | |
98 | ||
99 | cur_virt_src += cnt; | |
100 | cur_virt_dst += cnt; | |
1c79356b A |
101 | resid -= cnt; |
102 | } | |
d7e50217 | 103 | |
1c79356b | 104 | } else { |
d7e50217 | 105 | |
1c79356b A |
106 | resid = len; |
107 | ||
d7e50217 A |
108 | if(kdp_pmap) pmap = kdp_pmap; /* If special pmap, use it */ |
109 | else pmap = kernel_pmap; /* otherwise, use kernel's */ | |
110 | ||
1c79356b | 111 | while (resid != 0) { |
d7e50217 A |
112 | |
113 | if((cur_phys_src = kdp_vtophys(pmap, cur_virt_src)) == 0) goto exit; | |
114 | if(kdp_read_io == 0) | |
115 | if(!mapping_phys_lookup((ppnum_t)(cur_phys_src >> 12), &dummy)) goto exit; /* Can't read where there's not any memory */ | |
116 | ||
117 | cnt = 4096 - (cur_virt_src & 0xFFF); /* Get length left on page */ | |
1c79356b | 118 | if (cnt > resid) cnt = resid; |
d7e50217 | 119 | |
1c79356b | 120 | #ifdef KDP_VM_READ_DEBUG |
d7e50217 A |
121 | kprintf("kdp_vm_read2: pmap %08X, virt %016LLX, phys %016LLX\n", |
122 | pmap, cur_virt_src, cur_phys_src); | |
1c79356b | 123 | #endif |
d7e50217 A |
124 | |
125 | bcopy_phys(cur_phys_src, cur_virt_dst, cnt); /* Copy stuff over */ | |
126 | ||
1c79356b A |
127 | cur_virt_src +=cnt; |
128 | cur_virt_dst +=cnt; | |
129 | resid -= cnt; | |
130 | } | |
131 | } | |
132 | exit: | |
133 | #ifdef KDP_VM_READ_DEBUG | |
134 | kprintf("kdp_vm_read: ret %08X\n", len-resid); | |
135 | #endif | |
d7e50217 | 136 | return (len - resid); |
1c79356b A |
137 | } |
138 | ||
139 | /* | |
140 | * | |
141 | */ | |
142 | unsigned kdp_vm_write( | |
143 | caddr_t src, | |
144 | caddr_t dst, | |
145 | unsigned len) | |
146 | { | |
d7e50217 A |
147 | addr64_t cur_virt_src, cur_virt_dst; |
148 | addr64_t cur_phys_src, cur_phys_dst; | |
149 | unsigned resid, cnt, cnt_src, cnt_dst; | |
1c79356b A |
150 | |
151 | #ifdef KDP_VM_WRITE_DEBUG | |
152 | printf("kdp_vm_write: src %x dst %x len %x - %08X %08X\n", src, dst, len, ((unsigned long *)src)[0], ((unsigned long *)src)[1]); | |
153 | #endif | |
154 | ||
d7e50217 A |
155 | cur_virt_src = (addr64_t)((unsigned int)src); |
156 | cur_virt_dst = (addr64_t)((unsigned int)dst); | |
157 | ||
1c79356b A |
158 | resid = len; |
159 | ||
160 | while (resid != 0) { | |
161 | if ((cur_phys_dst = kdp_vtophys(kernel_pmap, cur_virt_dst)) == 0) | |
162 | goto exit; | |
163 | if ((cur_phys_src = kdp_vtophys(kernel_pmap, cur_virt_src)) == 0) | |
164 | goto exit; | |
165 | ||
166 | cnt_src = ((cur_phys_src + NBPG) & (-NBPG)) - cur_phys_src; | |
167 | cnt_dst = ((cur_phys_dst + NBPG) & (-NBPG)) - cur_phys_dst; | |
168 | ||
169 | if (cnt_src > cnt_dst) | |
170 | cnt = cnt_dst; | |
171 | else | |
172 | cnt = cnt_src; | |
173 | if (cnt > resid) | |
174 | cnt = resid; | |
175 | ||
d7e50217 A |
176 | bcopy_phys(cur_phys_src, cur_phys_dst, cnt); /* Copy stuff over */ |
177 | sync_cache64(cur_phys_dst, cnt); /* Sync caches */ | |
1c79356b A |
178 | |
179 | cur_virt_src +=cnt; | |
180 | cur_virt_dst +=cnt; | |
181 | resid -= cnt; | |
182 | } | |
183 | exit: | |
d7e50217 | 184 | return (len - resid); |
1c79356b A |
185 | } |
186 |