#include <mach_rt.h>
#include <mach_debug.h>
#include <mach_ldebug.h>
#include <sys/kdebug.h>
#include <mach/kern_return.h>
#include <mach/thread_status.h>
#include <mach/vm_param.h>
#include <kern/counters.h>
#include <kern/mach_param.h>
#include <kern/task.h>
#include <kern/thread.h>
#include <kern/sched_prim.h>
#include <kern/misc_protos.h>
#include <kern/assert.h>
#include <kern/spl.h>
#include <ipc/ipc_port.h>
#include <vm/vm_kern.h>
#include <vm/vm_map.h>
#include <vm/pmap.h>
#include <i386/cpu_data.h>
#include <i386/cpu_number.h>
#include <i386/thread.h>
#include <i386/eflags.h>
#include <i386/proc_reg.h>
#include <i386/seg.h>
#include <i386/tss.h>
#include <i386/user_ldt.h>
#include <i386/fpu.h>
#include <i386/misc_protos.h>
void
pmap_zero_page(
ppnum_t pn)
{
assert(pn != vm_page_fictitious_addr);
assert(pn != vm_page_guard_addr);
bzero_phys((addr64_t)i386_ptob(pn), PAGE_SIZE);
}
void
pmap_zero_part_page(
ppnum_t pn,
vm_offset_t offset,
vm_size_t len)
{
assert(pn != vm_page_fictitious_addr);
assert(pn != vm_page_guard_addr);
assert(offset + len <= PAGE_SIZE);
bzero_phys((addr64_t)(i386_ptob(pn) + offset), (uint32_t)len);
}
void
pmap_copy_part_page(
ppnum_t psrc,
vm_offset_t src_offset,
ppnum_t pdst,
vm_offset_t dst_offset,
vm_size_t len)
{
pmap_paddr_t src, dst;
assert(psrc != vm_page_fictitious_addr);
assert(pdst != vm_page_fictitious_addr);
assert(psrc != vm_page_guard_addr);
assert(pdst != vm_page_guard_addr);
src = i386_ptob(psrc);
dst = i386_ptob(pdst);
assert((((uintptr_t)dst & PAGE_MASK) + dst_offset + len) <= PAGE_SIZE);
assert((((uintptr_t)src & PAGE_MASK) + src_offset + len) <= PAGE_SIZE);
bcopy_phys((addr64_t)src + (src_offset & INTEL_OFFMASK),
(addr64_t)dst + (dst_offset & INTEL_OFFMASK),
len);
}
void
pmap_copy_part_lpage(
__unused vm_offset_t src,
__unused ppnum_t pdst,
__unused vm_offset_t dst_offset,
__unused vm_size_t len)
{
#ifdef __i386__
mapwindow_t *map;
#endif
assert(pdst != vm_page_fictitious_addr);
assert(pdst != vm_page_guard_addr);
assert((dst_offset + len) <= PAGE_SIZE);
#ifdef __i386__
mp_disable_preemption();
map = pmap_get_mapwindow(INTEL_PTE_VALID | INTEL_PTE_RW | (i386_ptob(pdst) & PG_FRAME) |
INTEL_PTE_REF | INTEL_PTE_MOD);
memcpy((void *) (map->prv_CADDR + (dst_offset & INTEL_OFFMASK)), (void *) src, len);
pmap_put_mapwindow(map);
mp_enable_preemption();
#endif
}
void
pmap_copy_part_rpage(
__unused ppnum_t psrc,
__unused vm_offset_t src_offset,
__unused vm_offset_t dst,
__unused vm_size_t len)
{
#ifdef __i386__
mapwindow_t *map;
#endif
assert(psrc != vm_page_fictitious_addr);
assert(psrc != vm_page_guard_addr);
assert((src_offset + len) <= PAGE_SIZE);
#ifdef __i386__
mp_disable_preemption();
map = pmap_get_mapwindow(INTEL_PTE_VALID | INTEL_PTE_RW | (i386_ptob(psrc) & PG_FRAME) |
INTEL_PTE_REF);
memcpy((void *) dst, (void *) (map->prv_CADDR + (src_offset & INTEL_OFFMASK)), len);
pmap_put_mapwindow(map);
mp_enable_preemption();
#endif
}
addr64_t
kvtophys(
vm_offset_t addr)
{
pmap_paddr_t pa;
pa = ((pmap_paddr_t)pmap_find_phys(kernel_pmap, addr)) << INTEL_PGSHIFT;
if (pa)
pa |= (addr & INTEL_OFFMASK);
return ((addr64_t)pa);
}
__private_extern__ void ml_copy_phys(addr64_t src64, addr64_t dst64, vm_size_t bytes) {
void *src, *dst;
mp_disable_preemption();
#if NCOPY_WINDOWS > 0
mapwindow_t *src_map, *dst_map;
src_map = pmap_get_mapwindow((pt_entry_t)(INTEL_PTE_VALID | ((pmap_paddr_t)src64 & PG_FRAME) | INTEL_PTE_REF));
dst_map = pmap_get_mapwindow((pt_entry_t)(INTEL_PTE_VALID | INTEL_PTE_RW | ((pmap_paddr_t)dst64 & PG_FRAME) | INTEL_PTE_REF | INTEL_PTE_MOD));
src = (void *) ((uintptr_t)src_map->prv_CADDR | ((uint32_t)src64 & INTEL_OFFMASK));
dst = (void *) ((uintptr_t)dst_map->prv_CADDR | ((uint32_t)dst64 & INTEL_OFFMASK));
#elif defined(__x86_64__)
src = PHYSMAP_PTOV(src64);
dst = PHYSMAP_PTOV(dst64);
#endif
if (((((uint32_t)src64 & (I386_PGBYTES-1)) + bytes) > I386_PGBYTES) || ((((uint32_t)dst64 & (I386_PGBYTES-1)) + bytes) > I386_PGBYTES) ) {
panic("ml_copy_phys spans pages, src: 0x%llx, dst: 0x%llx", src64, dst64);
}
switch (bytes) {
case 1:
*((uint8_t *) dst) = *((uint8_t *) src);
break;
case 2:
*((uint16_t *) dst) = *((uint16_t *) src);
break;
case 4:
*((uint32_t *) dst) = *((uint32_t *) src);
break;
case 8:
*((uint64_t *) dst) = *((uint64_t *) src);
break;
default:
bcopy(src, dst, bytes);
break;
}
#if NCOPY_WINDOWS > 0
pmap_put_mapwindow(src_map);
pmap_put_mapwindow(dst_map);
#endif
mp_enable_preemption();
}