X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/1c79356b52d46aa6b508fb032f5ae709b1f2897b..ff6e181ae92fc6f1e89841290f461d1f2f9badd9:/osfmk/i386/phys.c diff --git a/osfmk/i386/phys.c b/osfmk/i386/phys.c index f5060f2b9..442e13035 100644 --- a/osfmk/i386/phys.c +++ b/osfmk/i386/phys.c @@ -1,21 +1,22 @@ /* - * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. + * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved. * * @APPLE_LICENSE_HEADER_START@ * - * The contents of this file constitute Original Code as defined in and - * are subject to the Apple Public Source License Version 1.1 (the - * "License"). You may not use this file except in compliance with the - * License. Please obtain a copy of the License at - * http://www.apple.com/publicsource and read it before using this file. + * This file contains Original Code and/or Modifications of Original Code + * as defined in and that are subject to the Apple Public Source License + * Version 2.0 (the 'License'). You may not use this file except in + * compliance with the License. Please obtain a copy of the License at + * http://www.opensource.apple.com/apsl/ and read it before using this + * file. * - * This Original Code and all software distributed under the License are - * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * The Original Code and all software distributed under the License are + * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the - * License for the specific language governing rights and limitations - * under the License. + * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. + * Please see the License for the specific language governing rights and + * limitations under the License. * * @APPLE_LICENSE_HEADER_END@ */ @@ -47,23 +48,51 @@ * any improvements or extensions that they make and grant Carnegie Mellon * the rights to redistribute these changes. */ -#include +#include +#include +#include + +#include + +#include +#include #include -#include -#include -#include + +#include +#include +#include +#include +#include #include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include /* * pmap_zero_page zeros the specified (machine independent) page. */ void pmap_zero_page( - vm_offset_t p) + ppnum_t pn) { - assert(p != vm_page_fictitious_addr); - bzero((char *)phystokv(p), PAGE_SIZE); + assert(pn != vm_page_fictitious_addr); + bzero_phys((addr64_t)i386_ptob(pn), PAGE_SIZE); } /* @@ -72,28 +101,13 @@ pmap_zero_page( */ void pmap_zero_part_page( - vm_offset_t p, + ppnum_t pn, vm_offset_t offset, vm_size_t len) { - assert(p != vm_page_fictitious_addr); + assert(pn != vm_page_fictitious_addr); assert(offset + len <= PAGE_SIZE); - - bzero((char *)phystokv(p) + offset, len); -} - -/* - * pmap_copy_page copies the specified (machine independent) pages. - */ -void -pmap_copy_page( - vm_offset_t src, - vm_offset_t dst) -{ - assert(src != vm_page_fictitious_addr); - assert(dst != vm_page_fictitious_addr); - - memcpy((void *)phystokv(dst), (void *)phystokv(src), PAGE_SIZE); + bzero_phys((addr64_t)(i386_ptob(pn) + offset), len); } /* @@ -101,19 +115,22 @@ pmap_copy_page( */ void pmap_copy_part_page( - vm_offset_t src, + ppnum_t psrc, vm_offset_t src_offset, - vm_offset_t dst, + ppnum_t pdst, vm_offset_t dst_offset, vm_size_t len) { - assert(src != vm_page_fictitious_addr); - assert(dst != vm_page_fictitious_addr); + vm_offset_t src, dst; + assert(psrc != vm_page_fictitious_addr); + assert(pdst != vm_page_fictitious_addr); + src = (vm_offset_t)i386_ptob(psrc); + dst = (vm_offset_t)i386_ptob(pdst); assert(((dst & PAGE_MASK) + dst_offset + len) <= PAGE_SIZE); assert(((src & PAGE_MASK) + src_offset + len) <= PAGE_SIZE); - - memcpy((void *)(phystokv(dst) + dst_offset), - (void *)(phystokv(src) + src_offset), len); + bcopy_phys((addr64_t)src + (src_offset & INTEL_OFFMASK), + (addr64_t)dst + (dst_offset & INTEL_OFFMASK), + len); } /* @@ -122,16 +139,26 @@ pmap_copy_part_page( */ void pmap_copy_part_lpage( - vm_offset_t src, - vm_offset_t dst, + vm_offset_t src, + ppnum_t pdst, vm_offset_t dst_offset, vm_size_t len) { - assert(src != vm_page_fictitious_addr); - assert(dst != vm_page_fictitious_addr); - assert(((dst & PAGE_MASK) + dst_offset + len) <= PAGE_SIZE); + pt_entry_t *ptep; + thread_t thr_act = current_thread(); - memcpy((void *)(phystokv(dst) + dst_offset), (void *)src, len); + assert(pdst != vm_page_fictitious_addr); + ptep = pmap_pte(thr_act->map->pmap, i386_ptob(pdst)); + if (0 == ptep) + panic("pmap_copy_part_lpage ptep"); + assert(((pdst & PAGE_MASK) + dst_offset + len) <= PAGE_SIZE); + if (*(pt_entry_t *) CM2) + panic("pmap_copy_part_lpage"); + *(int *) CM2 = INTEL_PTE_VALID | INTEL_PTE_RW | (*ptep & PG_FRAME) | + INTEL_PTE_REF | INTEL_PTE_MOD; + invlpg((unsigned int) CA2); + memcpy((void *) (CA2 + (dst_offset & INTEL_OFFMASK)), (void *) src, len); + *(pt_entry_t *) CM2 = 0; } /* @@ -140,16 +167,26 @@ pmap_copy_part_lpage( */ void pmap_copy_part_rpage( - vm_offset_t src, + ppnum_t psrc, vm_offset_t src_offset, vm_offset_t dst, vm_size_t len) { - assert(src != vm_page_fictitious_addr); - assert(dst != vm_page_fictitious_addr); - assert(((src & PAGE_MASK) + src_offset + len) <= PAGE_SIZE); + pt_entry_t *ptep; + thread_t thr_act = current_thread(); - memcpy((void *)dst, (void *)(phystokv(src) + src_offset), len); + assert(psrc != vm_page_fictitious_addr); + ptep = pmap_pte(thr_act->map->pmap, i386_ptob(psrc)); + if (0 == ptep) + panic("pmap_copy_part_rpage ptep"); + assert(((psrc & PAGE_MASK) + src_offset + len) <= PAGE_SIZE); + if (*(pt_entry_t *) CM2) + panic("pmap_copy_part_rpage"); + *(pt_entry_t *) CM2 = INTEL_PTE_VALID | INTEL_PTE_RW | (*ptep & PG_FRAME) | + INTEL_PTE_REF; + invlpg((unsigned int) CA2); + memcpy((void *) dst, (void *) (CA2 + (src_offset & INTEL_OFFMASK)), len); + *(pt_entry_t *) CM2 = 0; } /* @@ -161,9 +198,15 @@ vm_offset_t kvtophys( vm_offset_t addr) { - pt_entry_t *pte; + pt_entry_t *ptep; + pmap_paddr_t pa; - if ((pte = pmap_pte(kernel_pmap, addr)) == PT_ENTRY_NULL) - return 0; - return i386_trunc_page(*pte) | (addr & INTEL_OFFMASK); + if ((ptep = pmap_pte(kernel_pmap, addr)) == PT_ENTRY_NULL) { + pa = 0; + } else { + pa = pte_to_pa(*ptep) | (addr & INTEL_OFFMASK); + } + if (0 == pa) + kprintf("kvtophys ret 0!\n"); + return (pa); }