+ if (top < fap) {
+ /* entire range below first_avail */
+ continue;
+ } else if ( (base < fap) &&
+ (top > fap)) {
+ /* spans first_avail */
+ pmptr->alloc = pmptr->base = fap;
+ pmptr->type = mptr->type;
+ pmptr->end = top;
+ } else {
+ /* entire range useable */
+ pmptr->alloc = pmptr->base = base;
+ pmptr->type = mptr->type;
+ pmptr->end = top;
+ }
+#endif
+ if (i386_ptob(pmptr->end) > avail_end ) {
+ avail_end = i386_ptob(pmptr->end);
+ }
+ avail_remaining += (pmptr->end - pmptr->base);
+ pmap_memory_region_count++;
+ pmptr++;
+ }
+#else /* non PAE follows */
+#define FOURGIG 0x0000000100000000ULL
+ for (i=0; i < args->memoryMapCount; i++,mptr++) {
+ ppnum_t base, top;
+
+ base = (ppnum_t) (mptr->base >> I386_PGSHIFT);
+ top = (ppnum_t) ((mptr->base + mptr->length) >> I386_PGSHIFT) - 1;
+
+ if (maxmem) {
+ if (base >= maxpg) break;
+ top = (top > maxpg)? maxpg : top;
+ }
+
+ if (kMemoryRangeUsable != mptr->type) continue;
+
+ // save other regions
+ if (kMemoryRangeNVS == mptr->type) {
+ // Mark this as a memory range (for hibernation),
+ // but don't count as usable memory
+ pmptr->base = base;
+ pmptr->end = ((mptr->base + mptr->length + I386_PGBYTES - 1) >> I386_PGSHIFT) - 1;
+ pmptr->alloc = pmptr->end;
+ pmptr->type = mptr->type;
+ kprintf("NVS region: 0x%x ->0x%x\n", pmptr->base, pmptr->end);
+ } else if (kMemoryRangeUsable != mptr->type) {
+ continue;
+ } else {
+ // Usable memory region
+ sane_size += (uint64_t)(mptr->length);
+ if (top < fap) {
+ /* entire range below first_avail */
+ /* salvage some low memory pages */
+ /* we use some very low memory at startup */
+ /* mark as already allocated here */
+ pmptr->base = 0x18; /* PAE and HIB use below this */
+ pmptr->alloc = pmptr->end = top; /* mark as already mapped */
+ pmptr->type = mptr->type;
+ } else if (mptr->base >= FOURGIG) {
+ /* entire range above 4GB (pre PAE) */
+ continue;
+ } else if ( (base < fap) &&
+ (top > fap)) {
+ /* spans first_avail */
+ /* put mem below first avail in table but
+ mark already allocated */
+ pmptr->base = base;
+ pmptr->alloc = pmptr->end = (fap - 1);
+ pmptr->type = mptr->type;
+ /* we bump these here inline so the accounting below works
+ correctly */
+ pmptr++;
+ pmap_memory_region_count++;
+ pmptr->alloc = pmptr->base = fap;
+ pmptr->type = mptr->type;
+ pmptr->end = top;
+ } else if ( (mptr->base < FOURGIG) &&
+ ((mptr->base+mptr->length) > FOURGIG) ) {
+ /* spans across 4GB (pre PAE) */
+ pmptr->alloc = pmptr->base = base;
+ pmptr->type = mptr->type;
+ pmptr->end = (FOURGIG >> I386_PGSHIFT) - 1;
+ } else {
+ /* entire range useable */
+ pmptr->alloc = pmptr->base = base;
+ pmptr->type = mptr->type;
+ pmptr->end = top;
+ }
+
+ if (i386_ptob(pmptr->end) > avail_end ) {
+ avail_end = i386_ptob(pmptr->end);
+ }
+
+ avail_remaining += (pmptr->end - pmptr->base);
+ pmap_memory_region_count++;
+ pmptr++;
+ }
+ }