* the rights to redistribute these changes.
*/
-#include <platforms.h>
#include <mach/i386/vm_param.h>
vm_offset_t vm_kernel_stext;
vm_offset_t vm_kernel_etext;
vm_offset_t vm_kernel_slide;
+vm_offset_t vm_kernel_slid_base;
+vm_offset_t vm_kernel_slid_top;
+vm_offset_t vm_hib_base;
vm_offset_t vm_kext_base = VM_MIN_KERNEL_AND_KEXT_ADDRESS;
vm_offset_t vm_kext_top = VM_MIN_KERNEL_ADDRESS;
+vm_offset_t vm_prelink_stext;
+vm_offset_t vm_prelink_etext;
+vm_offset_t vm_prelink_sinfo;
+vm_offset_t vm_prelink_einfo;
+vm_offset_t vm_slinkedit;
+vm_offset_t vm_elinkedit;
+
#define MAXLORESERVE (32 * 1024 * 1024)
ppnum_t max_ppnum = 0;
static pmap_paddr_t avail_remaining;
vm_offset_t static_memory_end = 0;
-vm_offset_t sHIB, eHIB, stext, etext, sdata, edata, sconstdata, econstdata, end;
+vm_offset_t sHIB, eHIB, stext, etext, sdata, edata, end, sconst, econst;
/*
* _mh_execute_header is the mach_header for the currently executing kernel
vm_offset_t segTEXTB; unsigned long segSizeTEXT;
vm_offset_t segDATAB; unsigned long segSizeDATA;
vm_offset_t segLINKB; unsigned long segSizeLINK;
-vm_offset_t segPRELINKB; unsigned long segSizePRELINK;
+vm_offset_t segPRELINKTEXTB; unsigned long segSizePRELINKTEXT;
+vm_offset_t segPRELINKINFOB; unsigned long segSizePRELINKINFO;
vm_offset_t segHIBB; unsigned long segSizeHIB;
-vm_offset_t sectCONSTB; unsigned long sectSizeConst;
-
-boolean_t doconstro_override = FALSE;
+unsigned long segSizeConst;
static kernel_segment_command_t *segTEXT, *segDATA;
static kernel_section_t *cursectTEXT, *lastsectTEXT;
-static kernel_section_t *sectDCONST;
+static kernel_segment_command_t *segCONST;
extern uint64_t firmware_Conventional_bytes;
extern uint64_t firmware_RuntimeServices_bytes;
vm_kernel_base_page = i386_btop(args->kaddr);
vm_offset_t base_address;
vm_offset_t static_base_address;
-
+
/*
* Establish the KASLR parameters.
*/
"__LINKEDIT", &segSizeLINK);
segHIBB = (vm_offset_t) getsegdatafromheader(&_mh_execute_header,
"__HIB", &segSizeHIB);
- segPRELINKB = (vm_offset_t) getsegdatafromheader(&_mh_execute_header,
- "__PRELINK_TEXT", &segSizePRELINK);
+ segPRELINKTEXTB = (vm_offset_t) getsegdatafromheader(&_mh_execute_header,
+ "__PRELINK_TEXT", &segSizePRELINKTEXT);
+ segPRELINKINFOB = (vm_offset_t) getsegdatafromheader(&_mh_execute_header,
+ "__PRELINK_INFO", &segSizePRELINKINFO);
segTEXT = getsegbynamefromheader(&_mh_execute_header,
"__TEXT");
segDATA = getsegbynamefromheader(&_mh_execute_header,
"__DATA");
- sectDCONST = getsectbynamefromheader(&_mh_execute_header,
- "__DATA", "__const");
+ segCONST = getsegbynamefromheader(&_mh_execute_header,
+ "__CONST");
cursectTEXT = lastsectTEXT = firstsect(segTEXT);
/* Discover the last TEXT section within the TEXT segment */
while ((cursectTEXT = nextsect(segTEXT, cursectTEXT)) != NULL) {
sHIB = segHIBB;
eHIB = segHIBB + segSizeHIB;
+ vm_hib_base = sHIB;
/* Zero-padded from ehib to stext if text is 2M-aligned */
stext = segTEXTB;
lowGlo.lgStext = stext;
sdata = segDATAB;
edata = segDATAB + segSizeDATA;
- sectCONSTB = (vm_offset_t) sectDCONST->addr;
- sectSizeConst = sectDCONST->size;
- sconstdata = sectCONSTB;
- econstdata = sectCONSTB + sectSizeConst;
-
- if (sectSizeConst & PAGE_MASK) {
- kernel_section_t *ns = nextsect(segDATA, sectDCONST);
- if (ns && !(ns->addr & PAGE_MASK))
- doconstro_override = TRUE;
- } else
- doconstro_override = TRUE;
+ sconst = segCONST->vmaddr;
+ segSizeConst = segCONST->vmsize;
+ econst = sconst + segSizeConst;
+ assert(((sconst|econst) & PAGE_MASK) == 0);
+
DBG("segTEXTB = %p\n", (void *) segTEXTB);
DBG("segDATAB = %p\n", (void *) segDATAB);
DBG("segLINKB = %p\n", (void *) segLINKB);
DBG("segHIBB = %p\n", (void *) segHIBB);
- DBG("segPRELINKB = %p\n", (void *) segPRELINKB);
+ DBG("segPRELINKTEXTB = %p\n", (void *) segPRELINKTEXTB);
+ DBG("segPRELINKINFOB = %p\n", (void *) segPRELINKINFOB);
DBG("sHIB = %p\n", (void *) sHIB);
DBG("eHIB = %p\n", (void *) eHIB);
DBG("stext = %p\n", (void *) stext);
DBG("etext = %p\n", (void *) etext);
DBG("sdata = %p\n", (void *) sdata);
DBG("edata = %p\n", (void *) edata);
- DBG("sconstdata = %p\n", (void *) sconstdata);
- DBG("econstdata = %p\n", (void *) econstdata);
+ DBG("sconst = %p\n", (void *) sconst);
+ DBG("econst = %p\n", (void *) econst);
DBG("kernel_top = %p\n", (void *) &last_kernel_symbol);
vm_kernel_base = sHIB;
vm_kernel_top = (vm_offset_t) &last_kernel_symbol;
vm_kernel_stext = stext;
vm_kernel_etext = etext;
+ vm_prelink_stext = segPRELINKTEXTB;
+ vm_prelink_etext = segPRELINKTEXTB + segSizePRELINKTEXT;
+ vm_prelink_sinfo = segPRELINKINFOB;
+ vm_prelink_einfo = segPRELINKINFOB + segSizePRELINKINFO;
+ vm_slinkedit = segLINKB;
+ vm_elinkedit = segLINKB + segSizePRELINKTEXT;
+ vm_kernel_slid_base = vm_kext_base;
+ vm_kernel_slid_top = vm_elinkedit;
vm_set_page_size();
* sane_size should reflect the total amount of physical
* RAM in the system, not just the amount that is
* available for the OS to use.
- * FIXME:Consider deriving this value from SMBIOS tables
+ * We now get this value from SMBIOS tables
* rather than reverse engineering the memory map.
- * Alternatively, see
- * <rdar://problem/4642773> Memory map should
- * describe all memory
- * Firmware on some systems guarantees that the memory
- * map is complete via the "RomReservedMemoryTracked"
- * feature field--consult that where possible to
- * avoid the "round up to 128M" workaround below.
+ * But the legacy computation of "sane_size" is kept
+ * for diagnostic information.
*/
case kEfiRuntimeServicesCode:
#endif
avail_start = first_avail;
- mem_actual = sane_size;
+ mem_actual = args->PhysicalMemorySize;
/*
- * For user visible memory size, round up to 128 Mb - accounting for the various stolen memory
- * not reported by EFI.
+ * For user visible memory size, round up to 128 Mb
+ * - accounting for the various stolen memory not reported by EFI.
+ * This is maintained for historical, comparison purposes but
+ * we now use the memory size reported by EFI/Booter.
*/
-
sane_size = (sane_size + 128 * MB - 1) & ~((uint64_t)(128 * MB - 1));
+ if (sane_size != mem_actual)
+ printf("mem_actual: 0x%llx\n legacy sane_size: 0x%llx\n",
+ mem_actual, sane_size);
+ sane_size = mem_actual;
/*
* We cap at KERNEL_MAXMEM bytes (currently 32GB for K32, 96GB for K64).