]>
git.saurik.com Git - apple/xnu.git/blob - osfmk/kdp/ml/ppc/kdp_vm.c
e7a5e1333f0f8f8071d578a71139a7d47aa24025
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
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
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.
23 * @APPLE_LICENSE_HEADER_END@
25 #include <mach/mach_types.h>
26 #include <mach/vm_attributes.h>
27 #include <mach/vm_param.h>
31 #include <ppc/proc_reg.h>
32 #include <ppc/machparam.h>
35 #include <ppc/pmap_internals.h>
36 #include <ppc/mappings.h>
39 boolean_t kdp_trans_off
=0;
41 unsigned kdp_xlate_off(void);
42 void kdp_xlate_restore(unsigned);
43 void kdp_flush_cache(vm_offset_t
, unsigned);
44 vm_offset_t
kdp_vtophys(pmap_t pmap
, vm_offset_t vaddr
);
45 void kdp_bcopy( unsigned char *, unsigned char *, unsigned);
46 void kdp_pmemcpy( vm_offset_t
, vm_offset_t
, unsigned);
47 unsigned kdp_vm_read( caddr_t
, caddr_t
, unsigned);
48 unsigned kdp_vm_write( caddr_t
, caddr_t
, unsigned);
50 extern vm_offset_t
kvtophys(vm_offset_t
);
51 extern vm_offset_t mem_actual
;
56 vm_offset_t
kdp_vtophys(
61 register vm_offset_t pa
;
63 pa
= (vm_offset_t
)LRA(pmap
->space
,(void *)va
);
68 mp
= hw_lock_phys_vir(pmap
->space
, va
);
69 if((unsigned int)mp
&1) {
73 if(!mp
) { /* If it was not a normal page */
74 pa
= hw_cvp_blk(pmap
, va
); /* Try to convert odd-sized page (returns 0 if not found) */
75 return pa
; /* Return physical address */
81 pa
= (vm_offset_t
)((mp
->PTEr
& -PAGE_SIZE
) | ((unsigned int)va
& (PAGE_SIZE
-1)));
83 pa
= (vm_offset_t
)((mp
->physent
->pte1
& -PAGE_SIZE
) | ((unsigned int)va
& (PAGE_SIZE
-1)));
84 hw_unlock_bit((unsigned int *)&mp
->physent
->phys_link
, PHYS_LOCK
);
105 unsigned kdp_vm_read(
110 vm_offset_t cur_virt_src
, cur_virt_dst
;
111 vm_offset_t cur_phys_src
;
115 #ifdef KDP_VM_READ_DEBUG
116 kprintf("kdp_vm_read1: src %x dst %x len %x - %08X %08X\n", src
, dst
, len
, ((unsigned long *)src
)[0], ((unsigned long *)src
)[1]);
119 cur_virt_src
= (vm_offset_t
)src
;
120 if((vm_offset_t
)src
>= mem_actual
) return 0; /* Can't read where there's not any memory */
121 cur_virt_dst
= (vm_offset_t
)dst
;
122 resid
= (mem_actual
- (vm_offset_t
)src
) > len
? len
: (mem_actual
- (vm_offset_t
)src
);
125 cur_phys_src
= cur_virt_src
;
126 cnt
= ((cur_virt_src
+ NBPG
) & (-NBPG
)) - cur_virt_src
;
127 if (cnt
> resid
) cnt
= resid
;
128 msr
= kdp_xlate_off();
129 kdp_bcopy((unsigned char *)cur_phys_src
,
130 (unsigned char *)cur_virt_dst
, cnt
);
131 kdp_xlate_restore(msr
);
137 cur_virt_src
= (vm_offset_t
)src
;
138 cur_virt_dst
= (vm_offset_t
)dst
;
144 kdp_vtophys(kdp_pmap
,trunc_page(cur_virt_src
))) == 0)
146 cur_phys_src
+= (cur_virt_src
& PAGE_MASK
);
148 if ((cur_phys_src
= kdp_vtophys(kernel_pmap
,cur_virt_src
)) == 0)
152 cnt
= ((cur_virt_src
+ NBPG
) & (-NBPG
)) - cur_virt_src
;
153 if (cnt
> resid
) cnt
= resid
;
155 #ifdef KDP_VM_READ_DEBUG
156 kprintf("kdp_vm_read2: pmap %x, virt %x, phys %x\n",
157 kdp_pmap
, cur_virt_src
, cur_phys_src
);
159 msr
= kdp_xlate_off();
160 kdp_bcopy((unsigned char *)cur_phys_src
,
161 (unsigned char *)cur_virt_dst
, cnt
);
162 kdp_xlate_restore(msr
);
164 kdp_bcopy((unsigned char *)cur_virt_src
,
165 (unsigned char *)cur_virt_dst
, cnt
);
173 #ifdef KDP_VM_READ_DEBUG
174 kprintf("kdp_vm_read: ret %08X\n", len
-resid
);
182 unsigned kdp_vm_write(
187 vm_offset_t cur_virt_src
, cur_virt_dst
;
188 vm_offset_t cur_phys_src
, cur_phys_dst
;
189 unsigned resid
, cnt
, cnt_src
, cnt_dst
;
192 #ifdef KDP_VM_WRITE_DEBUG
193 printf("kdp_vm_write: src %x dst %x len %x - %08X %08X\n", src
, dst
, len
, ((unsigned long *)src
)[0], ((unsigned long *)src
)[1]);
196 cur_virt_src
= (vm_offset_t
)src
;
197 cur_virt_dst
= (vm_offset_t
)dst
;
201 if ((cur_phys_dst
= kdp_vtophys(kernel_pmap
, cur_virt_dst
)) == 0)
203 if ((cur_phys_src
= kdp_vtophys(kernel_pmap
, cur_virt_src
)) == 0)
206 cnt_src
= ((cur_phys_src
+ NBPG
) & (-NBPG
)) - cur_phys_src
;
207 cnt_dst
= ((cur_phys_dst
+ NBPG
) & (-NBPG
)) - cur_phys_dst
;
209 if (cnt_src
> cnt_dst
)
216 msr
= kdp_xlate_off();
217 kdp_bcopy((unsigned char *)cur_virt_src
, (unsigned char *)cur_phys_dst
, cnt
);
218 kdp_flush_cache(cur_phys_dst
, cnt
);
219 kdp_xlate_restore(msr
);