|
|
1.1 root 1: /*
2: * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3: *
4: * @APPLE_LICENSE_HEADER_START@
5: *
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.
11: *
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
18: * under the License.
19: *
20: * @APPLE_LICENSE_HEADER_END@
21: */
22: #include <mach/mach_types.h>
23: #include <mach/vm_attributes.h>
24: #include <mach/vm_param.h>
25:
26: #include <vm/pmap.h>
27:
28: #include <ppc/proc_reg.h>
29: #include <ppc/machparam.h>
30: #include <ppc/mem.h>
31: #include <ppc/pmap.h>
32: #include <ppc/pmap_internals.h>
33: #include <ppc/mappings.h>
34:
35: pmap_t kdp_pmap=0;
36: boolean_t kdp_trans_off=0;
37:
38: unsigned kdp_xlate_off(void);
39: void kdp_xlate_restore(unsigned);
40: void kdp_flush_cache(vm_offset_t, unsigned);
41: vm_offset_t kdp_vtophys(space_t space, vm_offset_t vaddr);
42: void kdp_bcopy( unsigned char *, unsigned char *, unsigned);
43: void kdp_pmemcpy( vm_offset_t , vm_offset_t, unsigned);
44: unsigned kdp_vm_read( caddr_t, caddr_t, unsigned);
45: unsigned kdp_vm_write( caddr_t, caddr_t, unsigned);
46:
47: extern vm_offset_t kvtophys(vm_offset_t);
48:
49:
50: /*
51: *
52: */
53: vm_offset_t kdp_vtophys(
54: space_t space,
55: vm_offset_t va)
56: {
57: register mapping *mp;
58: register vm_offset_t pa;
59:
60: pa = LRA(space,(void *)va);
61:
62: if (pa != 0)
63: return(pa);
64:
65: mp = hw_lock_phys_vir(space, va);
66: if((unsigned int)mp&1) {
67: return 0;
68: }
69:
70: if(!mp) {
71: return 0;
72: }
73:
74: mp = hw_cpv(mp);
75:
76: if(!mp->physent) {
77: pa = (vm_offset_t)((mp->PTEr & -PAGE_SIZE) | ((unsigned int)va & (PAGE_SIZE-1)));
78: } else {
79: pa = (vm_offset_t)((mp->physent->pte1 & -PAGE_SIZE) | ((unsigned int)va & (PAGE_SIZE-1)));
80: hw_unlock_bit((unsigned int *)&mp->physent->phys_link, PHYS_LOCK);
81: }
82:
83: return(pa);
84: }
85:
86: /*
87: *
88: */
89: void kdp_bcopy(
90: unsigned char *src,
91: unsigned char *dst,
92: unsigned cnt)
93: {
94: while (cnt--)
95: *dst++ = *src++;
96: }
97:
98: /*
99: *
100: */
101: unsigned kdp_vm_read(
102: caddr_t src,
103: caddr_t dst,
104: unsigned len)
105: {
106: vm_offset_t cur_virt_src, cur_virt_dst;
107: vm_offset_t cur_phys_src;
108: unsigned resid, cnt;
109: unsigned msr;
110:
111: #ifdef KDP_VM_READ_DEBUG
112: kprintf("kdp_vm_read1: src %x dst %x len %x - %08X %08X\n", src, dst, len, ((unsigned long *)src)[0], ((unsigned long *)src)[1]);
113: #endif
114: if (kdp_trans_off) {
115: cur_virt_src = (vm_offset_t) ((int)src & 0x0fffffff);
116: cur_virt_dst = (vm_offset_t)dst;
117: resid = len;
118:
119: while (resid != 0) {
120: cur_phys_src = cur_virt_src;
121: cnt = ((cur_virt_src + NBPG) & (-NBPG)) - cur_virt_src;
122: if (cnt > resid) cnt = resid;
123: msr = kdp_xlate_off();
124: kdp_bcopy((unsigned char *)cur_phys_src,
125: (unsigned char *)cur_virt_dst, cnt);
126: kdp_xlate_restore(msr);
127: cur_virt_src +=cnt;
128: cur_virt_dst +=cnt;
129: resid -= cnt;
130: }
131: } else {
132: cur_virt_src = (vm_offset_t)src;
133: cur_virt_dst = (vm_offset_t)dst;
134: resid = len;
135:
136: while (resid != 0) {
137: if (kdp_pmap) {
138: if ((cur_phys_src =
139: kdp_vtophys(kdp_pmap->space,trunc_page(cur_virt_src))) ==0)
140: goto exit;
141: cur_phys_src += (cur_virt_src & PAGE_MASK);
142: } else {
143: if ((cur_phys_src = kdp_vtophys(PPC_SID_KERNEL,cur_virt_src)) == 0)
144: goto exit;
145: }
146:
147: cnt = ((cur_virt_src + NBPG) & (-NBPG)) - cur_virt_src;
148: if (cnt > resid) cnt = resid;
149: if (kdp_pmap) {
150: #ifdef KDP_VM_READ_DEBUG
151: kprintf("kdp_vm_read2: pmap %x, virt %x, phys %x\n",
152: kdp_pmap, cur_virt_src, cur_phys_src);
153: #endif
154: msr = kdp_xlate_off();
155: kdp_bcopy((unsigned char *)cur_phys_src,
156: (unsigned char *)cur_virt_dst, cnt);
157: kdp_xlate_restore(msr);
158: } else {
159: kdp_bcopy((unsigned char *)cur_virt_src,
160: (unsigned char *)cur_virt_dst, cnt);
161: }
162: cur_virt_src +=cnt;
163: cur_virt_dst +=cnt;
164: resid -= cnt;
165: }
166: }
167: exit:
168: #ifdef KDP_VM_READ_DEBUG
169: kprintf("kdp_vm_read: ret %08X\n", len-resid);
170: #endif
171: return (len-resid);
172: }
173:
174: /*
175: *
176: */
177: unsigned kdp_vm_write(
178: caddr_t src,
179: caddr_t dst,
180: unsigned len)
181: {
182: vm_offset_t cur_virt_src, cur_virt_dst;
183: vm_offset_t cur_phys_src, cur_phys_dst;
184: unsigned resid, cnt, cnt_src, cnt_dst;
185: unsigned msr;
186:
187: #ifdef KDP_VM_WRITE_DEBUG
188: printf("kdp_vm_write: src %x dst %x len %x - %08X %08X\n", src, dst, len, ((unsigned long *)src)[0], ((unsigned long *)src)[1]);
189: #endif
190:
191: cur_virt_src = (vm_offset_t)src;
192: cur_virt_dst = (vm_offset_t)dst;
193: resid = len;
194:
195: while (resid != 0) {
196: if ((cur_phys_dst = kdp_vtophys(PPC_SID_KERNEL,cur_virt_dst)) == 0)
197: goto exit;
198: if ((cur_phys_src = kdp_vtophys(PPC_SID_KERNEL,cur_virt_src)) == 0)
199: goto exit;
200:
201: cnt_src = ((cur_phys_src + NBPG) & (-NBPG)) - cur_phys_src;
202: cnt_dst = ((cur_phys_dst + NBPG) & (-NBPG)) - cur_phys_dst;
203:
204: if (cnt_src > cnt_dst)
205: cnt = cnt_dst;
206: else
207: cnt = cnt_src;
208: if (cnt > resid)
209: cnt = resid;
210:
211: msr = kdp_xlate_off();
212: kdp_bcopy((unsigned char *)cur_virt_src, (unsigned char *)cur_phys_dst, cnt);
213: kdp_flush_cache(cur_phys_dst, cnt);
214: kdp_xlate_restore(msr);
215:
216: cur_virt_src +=cnt;
217: cur_virt_dst +=cnt;
218: resid -= cnt;
219: }
220: exit:
221: return (len-resid);
222: }
223:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.