]> git.saurik.com Git - apple/xnu.git/blob - osfmk/kdp/ml/ppc/kdp_vm.c
ddb002b8c63c2aab3981d5bc454ce89170fb65ab
[apple/xnu.git] / osfmk / kdp / ml / ppc / kdp_vm.c
1 /*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
7 *
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
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
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.
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>
35 #include <ppc/mappings.h>
36
37 pmap_t kdp_pmap=0;
38 boolean_t kdp_trans_off=0;
39 boolean_t kdp_read_io =0;
40
41 unsigned kdp_vm_read( caddr_t, caddr_t, unsigned);
42 unsigned kdp_vm_write( caddr_t, caddr_t, unsigned);
43
44
45 /*
46 *
47 */
48 addr64_t kdp_vtophys(
49 pmap_t pmap,
50 addr64_t va)
51 {
52 addr64_t pa;
53 ppnum_t pp;
54
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 */
59 return(pa);
60 }
61
62 /*
63 *
64 */
65 unsigned kdp_vm_read(
66 caddr_t src,
67 caddr_t dst,
68 unsigned len)
69 {
70 addr64_t cur_virt_src, cur_virt_dst;
71 addr64_t cur_phys_src;
72 unsigned resid, cnt;
73 unsigned int dummy;
74 pmap_t pmap;
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
79
80 cur_virt_src = (addr64_t)((unsigned int)src);
81 cur_virt_dst = (addr64_t)((unsigned int)dst);
82
83 if (kdp_trans_off) {
84
85
86 resid = len; /* Get the length to copy */
87
88 while (resid != 0) {
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
95 if (cnt > resid) cnt = resid;
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;
101 resid -= cnt;
102 }
103
104 } else {
105
106 resid = len;
107
108 if(kdp_pmap) pmap = kdp_pmap; /* If special pmap, use it */
109 else pmap = kernel_pmap; /* otherwise, use kernel's */
110
111 while (resid != 0) {
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 */
118 if (cnt > resid) cnt = resid;
119
120 #ifdef KDP_VM_READ_DEBUG
121 kprintf("kdp_vm_read2: pmap %08X, virt %016LLX, phys %016LLX\n",
122 pmap, cur_virt_src, cur_phys_src);
123 #endif
124
125 bcopy_phys(cur_phys_src, cur_virt_dst, cnt); /* Copy stuff over */
126
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
136 return (len - resid);
137 }
138
139 /*
140 *
141 */
142 unsigned kdp_vm_write(
143 caddr_t src,
144 caddr_t dst,
145 unsigned len)
146 {
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;
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
155 cur_virt_src = (addr64_t)((unsigned int)src);
156 cur_virt_dst = (addr64_t)((unsigned int)dst);
157
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
176 bcopy_phys(cur_phys_src, cur_phys_dst, cnt); /* Copy stuff over */
177 sync_cache64(cur_phys_dst, cnt); /* Sync caches */
178
179 cur_virt_src +=cnt;
180 cur_virt_dst +=cnt;
181 resid -= cnt;
182 }
183 exit:
184 return (len - resid);
185 }
186