/*
- * Copyright (c) 2000-2005 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2000-2006 Apple Computer, Inc. All rights reserved.
*
* @APPLE_OSREFERENCE_LICENSE_HEADER_START@
*
void mapping_verify(void);
void mapping_phys_unused(ppnum_t pa);
-int nx_enabled = 0; /* enable no-execute protection */
+int nx_enabled = 1; /* enable no-execute protection */
+int allow_data_exec = VM_ABI_32; /* 32-bit apps may execute data by default, 64-bit apps may not */
+int allow_stack_exec = VM_ABI_32; /* 32-bit apps may execute from the stack by default, 64-bit apps may not */
/*
* ppc_prot translates Mach's representation of protections to that of the PPC hardware.
case mapRtNotFnd:
return (nextva | 1); /* Nothing found to unmap */
default:
- panic("mapping_remove: hw_rem_map failed - pmap = %08X, va = %016llX, code = %08X\n",
+ panic("mapping_remove: hw_rem_map failed - pmap = %p, va = %016llX, code = %p\n",
pmap, va, mp);
break;
}
case mapRtEmpty: /* No guest mappings left to scrub */
break;
default:
- panic("mapping_remove: hw_scrub_guest failed - physent = %08X, code = %08X\n",
+ panic("mapping_remove: hw_scrub_guest failed - physent = %p, code = %p\n",
physent, mp); /* Cry havoc, cry wrack,
at least we die with harness on our backs */
break;
pcf = (flags & mmFlgPcfg) >> 24; /* Get the physical page config index */
if(!(pPcfg[pcf].pcfFlags)) { /* Validate requested physical page configuration */
- panic("mapping_make: invalid physical page configuration request - pmap = %08X, va = %016llX, cfg = %d\n",
+ panic("mapping_make: invalid physical page configuration request - pmap = %p, va = %016llX, cfg = %d\n",
pmap, va, pcf);
}
psmask = (1ULL << pPcfg[pcf].pcfPSize) - 1; /* Mask to isolate any offset into a page */
if(va & psmask) { /* Make sure we are page aligned on virtual */
- panic("mapping_make: attempt to map unaligned vaddr - pmap = %08X, va = %016llX, cfg = %d\n",
+ panic("mapping_make: attempt to map unaligned vaddr - pmap = %p, va = %016llX, cfg = %d\n",
pmap, va, pcf);
}
if(((addr64_t)pa << 12) & psmask) { /* Make sure we are page aligned on physical */
- panic("mapping_make: attempt to map unaligned paddr - pmap = %08X, pa = %016llX, cfg = %d\n",
+ panic("mapping_make: attempt to map unaligned paddr - pmap = %p, pa = %08X, cfg = %d\n",
pmap, pa, pcf);
}
return (colladdr | mapRtSmash); /* Return colliding address, with some dirt added to avoid
confusion if effective address is 0 */
default:
- panic("mapping_make: hw_add_map failed - collision addr = %016llX, code = %02X, pmap = %08X, va = %016llX, mapping = %08X\n",
+ panic("mapping_make: hw_add_map failed - collision addr = %016llX, code = %02X, pmap = %p, va = %016llX, mapping = %p\n",
colladdr, rc, pmap, va, mp); /* Die dead */
}
mp = hw_find_map(curpmap, curva, nextva); /* Find the mapping for this address */
if((unsigned int)mp == mapRtBadLk) { /* Did we lock up ok? */
- panic("mapping_find: pmap lock failure - rc = %08X, pmap = %08X\n", mp, curpmap); /* Die... */
+ panic("mapping_find: pmap lock failure - rc = %p, pmap = %p\n", mp, curpmap); /* Die... */
}
if(!mp || ((mp->mpFlags & mpType) < mpMinSpecial) || !full) break; /* Are we done looking? */
if((mp->mpFlags & mpType) != mpNest) { /* Don't chain through anything other than a nested pmap */
mapping_drop_busy(mp); /* We have everything we need from the mapping */
- mp = 0; /* Set not found */
+ mp = NULL; /* Set not found */
break;
}
if(nestdepth++ > 64) { /* Have we nested too far down? */
- panic("mapping_find: too many nested pmaps - va = %016llX, curva = %016llX, pmap = %08X, curpmap = %08X\n",
+ panic("mapping_find: too many nested pmaps - va = %016llX, curva = %016llX, pmap = %p, curpmap = %p\n",
va, curva, pmap, curpmap);
}
break;
default:
- panic("mapping_protect: hw_protect failed - rc = %d, pmap = %08X, va = %016llX\n", ret, pmap, va);
+ panic("mapping_protect: hw_protect failed - rc = %d, pmap = %p, va = %016llX\n", ret, pmap, va);
}
* the reference bit.
*/
-phys_entry_t *mapping_phys_lookup(ppnum_t pp, unsigned int *pindex) { /* Finds the physical entry for the page */
-
- int i;
+phys_entry_t *
+mapping_phys_lookup(ppnum_t pp, unsigned int *pindex)
+{ /* Finds the physical entry for the page */
+ unsigned int i;
for(i = 0; i < pmap_mem_regions_count; i++) { /* Walk through the list */
if(!(unsigned int)pmap_mem_regions[i].mrPhysTab) continue; /* Skip any empty lists */
}
mbn = mapCtl.mapcrel; /* Get first pending release block */
- mapCtl.mapcrel = 0; /* Dequeue them */
+ mapCtl.mapcrel = NULL; /* Dequeue them */
mapCtl.mapcreln = 0; /* Set count to 0 */
hw_lock_unlock((hw_lock_t)&mapCtl.mapclock); /* Unlock our stuff */
if(mapCtl.mapcnext == mb) { /* Are we first on the list? */
mapCtl.mapcnext = mb->nextblok; /* Unchain us */
- if(!((unsigned int)mapCtl.mapcnext)) mapCtl.mapclast = 0; /* If last, remove last */
+ if(!((unsigned int)mapCtl.mapcnext)) mapCtl.mapclast = NULL; /* If last, remove last */
}
else { /* We're not first */
for(mbn = mapCtl.mapcnext; mbn != 0; mbn = mbn->nextblok) { /* Search for our block */
if(mbn->nextblok == mb) break; /* Is the next one our's? */
}
- if(!mbn) panic("mapping_free: attempt to release mapping block (%08X) not on list\n", mp);
+ if(!mbn) panic("mapping_free: attempt to release mapping block (%p) not on list\n", mp);
mbn->nextblok = mb->nextblok; /* Dequeue us */
if(mapCtl.mapclast == mb) mapCtl.mapclast = mbn; /* If last, make our predecessor last */
}
case mapRtNotFnd:
break;
default:
- panic("mapping_alloc: hw_purge_map failed - pmap = %08X, va = %16llX, code = %08X\n", ckpmap, va, mp);
+ panic("mapping_alloc: hw_purge_map failed - pmap = %p, va = %16llX, code = %p\n", ckpmap, va, mp);
break;
}
- if (mapRtNotFnd == ((unsigned int)mp & mapRetCode))
+ if (mapRtNotFnd == ((unsigned int)mp & mapRetCode)) {
if (do_rescan)
do_rescan = FALSE;
else
break;
+ }
va = nextva;
}
if ( !big ) { /* if we need a small (64-byte) mapping */
if(!(mindx = mapalc1(mb))) /* Allocate a 1-bit slot */
- panic("mapping_alloc - empty mapping block detected at %08X\n", mb);
+ panic("mapping_alloc - empty mapping block detected at %p\n", mb);
}
if(mindx < 0) { /* Did we just take the last one */
mindx = -mindx; /* Make positive */
mapCtl.mapcnext = mb->nextblok; /* Remove us from the list */
- if(!((unsigned int)mapCtl.mapcnext)) mapCtl.mapclast = 0; /* Removed the last one */
+ if(!((unsigned int)mapCtl.mapcnext)) mapCtl.mapclast = NULL; /* Removed the last one */
}
mapCtl.mapcfree--; /* Decrement free count */
}
else { /* Add to the free list */
- mb->nextblok = 0; /* We always add to the end */
+ mb->nextblok = NULL; /* We always add to the end */
mapCtl.mapcfree += MAPPERBLOK; /* Bump count */
if(!((unsigned int)mapCtl.mapcnext)) { /* First entry on list? */
}
+/*
+ * kvtophys64(addr)
+ *
+ * Convert a kernel virtual address to a 64-bit physical address
+ */
+vm_map_offset_t kvtophys64(vm_map_offset_t va) {
+
+ ppnum_t pa = pmap_find_phys(kernel_pmap, (addr64_t)va);
+
+ if (!pa)
+ return 0;
+ return (((vm_map_offset_t)pa) << 12) | (va & 0xfff);
+
+}
+
/*
* void ignore_zero_fault(boolean_t) - Sets up to ignore or honor any fault on
* page 0 access for the current thread.
}
/*
- * nop in current ppc implementation
+ * no-op in current ppc implementation
*/
-void inval_copy_windows(__unused thread_t t)
+void inval_copy_windows(__unused thread_t th)
{
}
*
*/
-kern_return_t hw_copypv_32(addr64_t source, addr64_t sink, unsigned int size, int which) {
-
+kern_return_t
+hw_copypv_32(addr64_t source, addr64_t sink, unsigned int size, int which)
+{
vm_map_t map;
kern_return_t ret;
- addr64_t nextva, vaddr, paddr;
- register mapping_t *mp;
+ addr64_t nextva, vaddr = 0, paddr;
+ mapping_t *mp = NULL;
spl_t s;
unsigned int lop, csize;
int needtran, bothphys;
unsigned int pindex;
phys_entry_t *physent;
- vm_prot_t prot;
+ vm_prot_t prot = 0;
int orig_which;
orig_which = which;
mp = mapping_find(map->pmap, vaddr, &nextva, 1); /* Find and busy the mapping */
if(!mp) { /* Was it there? */
if(getPerProc()->istackptr == 0)
- panic("copypv: No vaild mapping on memory %s %x", "RD", vaddr);
+ panic("copypv: No vaild mapping on memory %s %16llx", "RD", vaddr);
splx(s); /* Restore the interrupt level */
ret = vm_fault(map, vm_map_trunc_page(vaddr), prot, FALSE, THREAD_UNINT, NULL, 0); /* Didn't find it, try to fault it in... */
mapping_drop_busy(mp); /* Go ahead and release the mapping for now */
if(getPerProc()->istackptr == 0)
- panic("copypv: No vaild mapping on memory %s %x", "RDWR", vaddr);
+ panic("copypv: No vaild mapping on memory %s %16llx", "RDWR", vaddr);
splx(s); /* Restore the interrupt level */
ret = vm_fault(map, vm_map_trunc_page(vaddr), VM_PROT_READ | VM_PROT_WRITE, FALSE, THREAD_UNINT, NULL, 0); /* check for a COW area */
s = splhigh(); /* Don't bother from now on */
- mbn = 0; /* Start with none */
+ mbn = NULL; /* Start with none */
for(mb = mapCtl.mapcnext; mb; mb = mb->nextblok) { /* Walk the free chain */
if((mappingblok_t *)(mb->mapblokflags & 0x7FFFFFFF) != mb) { /* Is tag ok? */
- panic("mapping_verify: flags tag bad, free chain; mb = %08X, tag = %08X\n", mb, mb->mapblokflags);
+ panic("mapping_verify: flags tag bad, free chain; mb = %p, tag = %08X\n", mb, mb->mapblokflags);
}
mbn = mb; /* Remember the last one */
}
if(mapCtl.mapcnext && (mapCtl.mapclast != mbn)) { /* Do we point to the last one? */
- panic("mapping_verify: last pointer bad; mb = %08X, mapclast = %08X\n", mb, mapCtl.mapclast);
+ panic("mapping_verify: last pointer bad; mb = %p, mapclast = %p\n", mb, mapCtl.mapclast);
}
relncnt = 0; /* Clear count */
if(!(physent->ppLink & ~(ppLock | ppFlags))) return; /* No one else is here */
- panic("mapping_phys_unused: physical page (%08X) in use, physent = %08X\n", pa, physent);
+ panic("mapping_phys_unused: physical page (%08X) in use, physent = %p\n", pa, physent);
}
-void mapping_hibernate_flush(void)
+void
+mapping_hibernate_flush(void)
{
- int bank;
- unsigned int page;
+ unsigned int page, bank;
struct phys_entry * entry;
for (bank = 0; bank < pmap_mem_regions_count; bank++)