]>
git.saurik.com Git - apple/xnu.git/blob - osfmk/kdp/ml/ppc/kdp_vm.c
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
);
48 extern vm_offset_t mem_actual
;
53 vm_offset_t
kdp_vtophys(
58 register vm_offset_t pa
;
60 pa
= (vm_offset_t
)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
)src
;
117 if((vm_offset_t
)src
>= mem_actual
) return 0; /* Can't read where there's not any memory */
118 cur_virt_dst
= (vm_offset_t
)dst
;
119 resid
= (mem_actual
- (vm_offset_t
)src
) > len
? len
: (mem_actual
- (vm_offset_t
)src
);
122 cur_phys_src
= cur_virt_src
;
123 cnt
= ((cur_virt_src
+ NBPG
) & (-NBPG
)) - cur_virt_src
;
124 if (cnt
> resid
) cnt
= resid
;
125 msr
= kdp_xlate_off();
126 kdp_bcopy((unsigned char *)cur_phys_src
,
127 (unsigned char *)cur_virt_dst
, cnt
);
128 kdp_xlate_restore(msr
);
134 cur_virt_src
= (vm_offset_t
)src
;
135 cur_virt_dst
= (vm_offset_t
)dst
;
141 kdp_vtophys(kdp_pmap
,trunc_page(cur_virt_src
))) == 0)
143 cur_phys_src
+= (cur_virt_src
& PAGE_MASK
);
145 if ((cur_phys_src
= kdp_vtophys(kernel_pmap
,cur_virt_src
)) == 0)
149 cnt
= ((cur_virt_src
+ NBPG
) & (-NBPG
)) - cur_virt_src
;
150 if (cnt
> resid
) cnt
= resid
;
152 #ifdef KDP_VM_READ_DEBUG
153 kprintf("kdp_vm_read2: pmap %x, virt %x, phys %x\n",
154 kdp_pmap
, cur_virt_src
, cur_phys_src
);
156 msr
= kdp_xlate_off();
157 kdp_bcopy((unsigned char *)cur_phys_src
,
158 (unsigned char *)cur_virt_dst
, cnt
);
159 kdp_xlate_restore(msr
);
161 kdp_bcopy((unsigned char *)cur_virt_src
,
162 (unsigned char *)cur_virt_dst
, cnt
);
170 #ifdef KDP_VM_READ_DEBUG
171 kprintf("kdp_vm_read: ret %08X\n", len
-resid
);
179 unsigned kdp_vm_write(
184 vm_offset_t cur_virt_src
, cur_virt_dst
;
185 vm_offset_t cur_phys_src
, cur_phys_dst
;
186 unsigned resid
, cnt
, cnt_src
, cnt_dst
;
189 #ifdef KDP_VM_WRITE_DEBUG
190 printf("kdp_vm_write: src %x dst %x len %x - %08X %08X\n", src
, dst
, len
, ((unsigned long *)src
)[0], ((unsigned long *)src
)[1]);
193 cur_virt_src
= (vm_offset_t
)src
;
194 cur_virt_dst
= (vm_offset_t
)dst
;
198 if ((cur_phys_dst
= kdp_vtophys(kernel_pmap
, cur_virt_dst
)) == 0)
200 if ((cur_phys_src
= kdp_vtophys(kernel_pmap
, cur_virt_src
)) == 0)
203 cnt_src
= ((cur_phys_src
+ NBPG
) & (-NBPG
)) - cur_phys_src
;
204 cnt_dst
= ((cur_phys_dst
+ NBPG
) & (-NBPG
)) - cur_phys_dst
;
206 if (cnt_src
> cnt_dst
)
213 msr
= kdp_xlate_off();
214 kdp_bcopy((unsigned char *)cur_virt_src
, (unsigned char *)cur_phys_dst
, cnt
);
215 kdp_flush_cache(cur_phys_dst
, cnt
);
216 kdp_xlate_restore(msr
);