]>
git.saurik.com Git - apple/xnu.git/blob - osfmk/kdp/ml/ppc/kdp_vm.c
dad44c78c7402441f203ae6158b810148c51ef3b
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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.
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
20 * @APPLE_LICENSE_HEADER_END@
22 #include <mach/mach_types.h>
23 #include <mach/vm_attributes.h>
24 #include <mach/vm_param.h>
28 #include <ppc/proc_reg.h>
29 #include <ppc/machparam.h>
32 #include <ppc/pmap_internals.h>
33 #include <ppc/mappings.h>
36 boolean_t kdp_trans_off
=0;
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(pmap_t pmap
, 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);
47 extern vm_offset_t
kvtophys(vm_offset_t
);
53 vm_offset_t
kdp_vtophys(
58 register vm_offset_t pa
;
60 pa
= LRA(pmap
->space
,(void *)va
);
65 mp
= hw_lock_phys_vir(pmap
->space
, va
);
66 if((unsigned int)mp
&1) {
70 if(!mp
) { /* If it was not a normal page */
71 pa
= hw_cvp_blk(pmap
, va
); /* Try to convert odd-sized page (returns 0 if not found) */
72 return pa
; /* Return physical address */
78 pa
= (vm_offset_t
)((mp
->PTEr
& -PAGE_SIZE
) | ((unsigned int)va
& (PAGE_SIZE
-1)));
80 pa
= (vm_offset_t
)((mp
->physent
->pte1
& -PAGE_SIZE
) | ((unsigned int)va
& (PAGE_SIZE
-1)));
81 hw_unlock_bit((unsigned int *)&mp
->physent
->phys_link
, PHYS_LOCK
);
102 unsigned kdp_vm_read(
107 vm_offset_t cur_virt_src
, cur_virt_dst
;
108 vm_offset_t cur_phys_src
;
112 #ifdef KDP_VM_READ_DEBUG
113 kprintf("kdp_vm_read1: src %x dst %x len %x - %08X %08X\n", src
, dst
, len
, ((unsigned long *)src
)[0], ((unsigned long *)src
)[1]);
116 cur_virt_src
= (vm_offset_t
) ((int)src
& 0x0fffffff);
117 cur_virt_dst
= (vm_offset_t
)dst
;
121 cur_phys_src
= cur_virt_src
;
122 cnt
= ((cur_virt_src
+ NBPG
) & (-NBPG
)) - cur_virt_src
;
123 if (cnt
> resid
) cnt
= resid
;
124 msr
= kdp_xlate_off();
125 kdp_bcopy((unsigned char *)cur_phys_src
,
126 (unsigned char *)cur_virt_dst
, cnt
);
127 kdp_xlate_restore(msr
);
133 cur_virt_src
= (vm_offset_t
)src
;
134 cur_virt_dst
= (vm_offset_t
)dst
;
140 kdp_vtophys(kdp_pmap
,trunc_page(cur_virt_src
))) == 0)
142 cur_phys_src
+= (cur_virt_src
& PAGE_MASK
);
144 if ((cur_phys_src
= kdp_vtophys(kernel_pmap
,cur_virt_src
)) == 0)
148 cnt
= ((cur_virt_src
+ NBPG
) & (-NBPG
)) - cur_virt_src
;
149 if (cnt
> resid
) cnt
= resid
;
151 #ifdef KDP_VM_READ_DEBUG
152 kprintf("kdp_vm_read2: pmap %x, virt %x, phys %x\n",
153 kdp_pmap
, cur_virt_src
, cur_phys_src
);
155 msr
= kdp_xlate_off();
156 kdp_bcopy((unsigned char *)cur_phys_src
,
157 (unsigned char *)cur_virt_dst
, cnt
);
158 kdp_xlate_restore(msr
);
160 kdp_bcopy((unsigned char *)cur_virt_src
,
161 (unsigned char *)cur_virt_dst
, cnt
);
169 #ifdef KDP_VM_READ_DEBUG
170 kprintf("kdp_vm_read: ret %08X\n", len
-resid
);
178 unsigned kdp_vm_write(
183 vm_offset_t cur_virt_src
, cur_virt_dst
;
184 vm_offset_t cur_phys_src
, cur_phys_dst
;
185 unsigned resid
, cnt
, cnt_src
, cnt_dst
;
188 #ifdef KDP_VM_WRITE_DEBUG
189 printf("kdp_vm_write: src %x dst %x len %x - %08X %08X\n", src
, dst
, len
, ((unsigned long *)src
)[0], ((unsigned long *)src
)[1]);
192 cur_virt_src
= (vm_offset_t
)src
;
193 cur_virt_dst
= (vm_offset_t
)dst
;
197 if ((cur_phys_dst
= kdp_vtophys(kernel_pmap
, cur_virt_dst
)) == 0)
199 if ((cur_phys_src
= kdp_vtophys(kernel_pmap
, cur_virt_src
)) == 0)
202 cnt_src
= ((cur_phys_src
+ NBPG
) & (-NBPG
)) - cur_phys_src
;
203 cnt_dst
= ((cur_phys_dst
+ NBPG
) & (-NBPG
)) - cur_phys_dst
;
205 if (cnt_src
> cnt_dst
)
212 msr
= kdp_xlate_off();
213 kdp_bcopy((unsigned char *)cur_virt_src
, (unsigned char *)cur_phys_dst
, cnt
);
214 kdp_flush_cache(cur_phys_dst
, cnt
);
215 kdp_xlate_restore(msr
);