/* * Simple memory allocator, allocates aligned physical memory. * Note that startup_kernel() only allocates memory, never frees. * Memory usage just grows in an upward direction. */ static void * do_mem_alloc(uint32_t size, uint32_t align) { uint_t i; uint64_t best; uint64_t start; uint64_t end; /* * make sure size is a multiple of pagesize */ size = RNDUP(size, MMU_PAGESIZE); next_avail_addr = RNDUP(next_avail_addr, align); /* * XXPV fixme joe * * a really large bootarchive that causes you to run out of memory * may cause this to blow up */ /* LINTED E_UNEXPECTED_UINT_PROMOTION */ best = (uint64_t)-size; for (i = 0; i < memlists_used; ++i) { start = memlists[i].addr; #if defined(__xpv) start += mfn_base; #endif end = start + memlists[i].size; /* * did we find the desired address? */ if (start <= next_avail_addr && next_avail_addr + size <= end) { best = next_avail_addr; goto done; } /* * if not is this address the best so far? */ if (start > next_avail_addr && start < best && RNDUP(start, align) + size <= end) best = RNDUP(start, align); } /* * We didn't find exactly the address we wanted, due to going off the * end of a memory region. Return the best found memory address. */ done: next_avail_addr = best + size; #if defined(__xpv) if (next_avail_addr > scratch_end) dboot_panic("Out of mem next_avail: 0x%lx, scratch_end: " "0x%lx", (ulong_t)next_avail_addr, (ulong_t)scratch_end); #endif (void) memset((void *)(uintptr_t)best, 0, size); return ((void *)(uintptr_t)best); }
/* * Add a mapping for the machine page at the given virtual address. */ static void map_ma_at_va(maddr_t ma, native_ptr_t va, uint_t level) { x86pte_t *ptep; x86pte_t pteval; pteval = ma | pte_bits; if (level > 0) pteval |= PT_PAGESIZE; if (va >= target_kernel_text && pge_support) pteval |= PT_GLOBAL; if (map_debug && ma != va) dboot_printf("mapping ma=0x%" PRIx64 " va=0x%" PRIx64 " pte=0x%" PRIx64 " l=%d\n", (uint64_t)ma, (uint64_t)va, pteval, level); #if defined(__xpv) /* * see if we can avoid find_pte() on the hypervisor */ if (HYPERVISOR_update_va_mapping(va, pteval, UVMF_INVLPG | UVMF_LOCAL) == 0) return; #endif /* * Find the pte that will map this address. This creates any * missing intermediate level page tables */ ptep = find_pte(va, NULL, level, 0); /* * When paravirtualized, we must use hypervisor calls to modify the * PTE, since paging is active. On real hardware we just write to * the pagetables which aren't in use yet. */ #if defined(__xpv) ptep = ptep; /* shut lint up */ if (HYPERVISOR_update_va_mapping(va, pteval, UVMF_INVLPG | UVMF_LOCAL)) dboot_panic("mmu_update failed-map_pa_at_va va=0x%" PRIx64 " l=%d ma=0x%" PRIx64 ", pte=0x%" PRIx64 "", (uint64_t)va, level, (uint64_t)ma, pteval); #else if (va < 1024 * 1024) pteval |= PT_NOCACHE; /* for video RAM */ if (pae_support) *ptep = pteval; else *((x86pte32_t *)ptep) = (x86pte32_t)pteval; #endif }
static void * getehdr(void) { uchar_t *ident; void *hdr = NULL; ident = PGETBYTES(0); if (ident == NULL) dboot_panic("Cannot read kernel ELF header"); if (ident[EI_MAG0] != ELFMAG0 || ident[EI_MAG1] != ELFMAG1 || ident[EI_MAG2] != ELFMAG2 || ident[EI_MAG3] != ELFMAG3) dboot_panic("not an ELF file!"); if (ident[EI_CLASS] == ELFCLASS32) hdr = PGETBYTES(0); else if (ident[EI_CLASS] == ELFCLASS64) hdr = PGETBYTES(0); else dboot_panic("Unknown ELF class"); return (hdr); }
static void exclude_from_pci(uint64_t start, uint64_t end) { int i; int j; struct boot_memlist *ml; for (i = 0; i < pcimemlists_used; ++i) { ml = &pcimemlists[i]; /* delete the entire range? */ if (start <= ml->addr && ml->addr + ml->size <= end) { --pcimemlists_used; for (j = i; j < pcimemlists_used; ++j) pcimemlists[j] = pcimemlists[j + 1]; --i; /* to revisit the new one at this index */ } /* split a range? */ else if (ml->addr < start && end < ml->addr + ml->size) { ++pcimemlists_used; if (pcimemlists_used > MAX_MEMLIST) dboot_panic("too many pcimemlists"); for (j = pcimemlists_used - 1; j > i; --j) pcimemlists[j] = pcimemlists[j - 1]; ml->size = start - ml->addr; ++ml; ml->size = (ml->addr + ml->size) - end; ml->addr = end; ++i; /* skip on to next one */ } /* cut memory off the start? */ else if (ml->addr < end && end < ml->addr + ml->size) { ml->size -= end - ml->addr; ml->addr = end; } /* cut memory off the end? */ else if (ml->addr <= start && start < ml->addr + ml->size) { ml->size = start - ml->addr; } } }
/* * From a pseudo-physical address, find the corresponding machine address. */ maddr_t pa_to_ma(paddr_t pa) { pfn_t pfn; ulong_t mfn; pfn = mmu_btop(pa - mfn_base); if (pa < mfn_base || pfn >= xen_info->nr_pages) dboot_panic("pa_to_ma(): illegal address 0x%lx", (ulong_t)pa); mfn = ((ulong_t *)xen_info->mfn_list)[pfn]; #ifdef DEBUG if (mfn_to_pfn_mapping[mfn] != pfn) dboot_printf("pa_to_ma(pfn=%lx) got %lx ma_to_pa() says %lx\n", pfn, mfn, mfn_to_pfn_mapping[mfn]); #endif return (mfn_to_ma(mfn) | (pa & MMU_PAGEOFFSET)); }
paddr_t make_ptable(x86pte_t *pteval, uint_t level) { paddr_t new_table = (paddr_t)(uintptr_t)mem_alloc(MMU_PAGESIZE); if (level == top_level && level == 2) *pteval = pa_to_ma((uintptr_t)new_table) | PT_VALID; else *pteval = pa_to_ma((uintptr_t)new_table) | ptp_bits; #ifdef __xpv /* Remove write permission to the new page table. */ if (HYPERVISOR_update_va_mapping(new_table, *pteval & ~(x86pte_t)PT_WRITABLE, UVMF_INVLPG | UVMF_LOCAL)) dboot_panic("HYP_update_va_mapping error"); #endif if (map_debug) dboot_printf("new page table lvl=%d paddr=0x%lx ptp=0x%" PRIx64 "\n", level, (ulong_t)new_table, *pteval); return (new_table); }
/*ARGSUSED*/ void set_pteval(paddr_t table, uint_t index, uint_t level, x86pte_t pteval) { #ifdef __xpv mmu_update_t t; maddr_t mtable = pa_to_ma(table); int retcnt; t.ptr = (mtable + index * pte_size) | MMU_NORMAL_PT_UPDATE; t.val = pteval; if (HYPERVISOR_mmu_update(&t, 1, &retcnt, DOMID_SELF) || retcnt != 1) dboot_panic("HYPERVISOR_mmu_update() failed"); #else /* __xpv */ uintptr_t tab_addr = (uintptr_t)table; if (pae_support) ((x86pte_t *)tab_addr)[index] = pteval; else ((x86pte32_t *)tab_addr)[index] = (x86pte32_t)pteval; if (level == top_level && level == 2) reload_cr3(); #endif /* __xpv */ }
/* * parse the elf file for program information */ int dboot_elfload64(uintptr_t file_image) { Elf64_Ehdr *eh; Elf64_Phdr *phdr; Elf64_Shdr *shdr; caddr_t allphdrs, sechdrs; int i; paddr_t src; paddr_t dst; paddr_t next_addr; elf_file = (caddr_t)file_image; allphdrs = NULL; eh = getehdr(); if (eh == NULL) dboot_panic("getehdr() failed"); if (eh->e_type != ET_EXEC) dboot_panic("not ET_EXEC, e_type = 0x%x", eh->e_type); if (eh->e_phnum == 0 || eh->e_phoff == 0) dboot_panic("no program headers"); /* * Get the program headers. */ allphdrs = PGETBYTES(eh->e_phoff); if (allphdrs == NULL) dboot_panic("Failed to get program headers e_phnum = %d", eh->e_phnum); /* * Get the section headers. */ sechdrs = PGETBYTES(eh->e_shoff); if (sechdrs == NULL) dboot_panic("Failed to get section headers e_shnum = %d", eh->e_shnum); /* * Next look for interesting program headers. */ for (i = 0; i < eh->e_phnum; i++) { /*LINTED [ELF program header alignment]*/ phdr = (Elf64_Phdr *)(allphdrs + eh->e_phentsize * i); /* * Dynamically-linked executable. * Complain. */ if (phdr->p_type == PT_INTERP) { dboot_printf("warning: PT_INTERP section\n"); continue; } /* * at this point we only care about PT_LOAD segments */ if (phdr->p_type != PT_LOAD) continue; if (phdr->p_flags == (PF_R | PF_W) && phdr->p_vaddr == 0) { dboot_printf("warning: krtld reloc info?\n"); continue; } /* * If memory size is zero just ignore this header. */ if (phdr->p_memsz == 0) continue; /* * If load address 1:1 then ignore this header. */ if (phdr->p_paddr == phdr->p_vaddr) { if (prom_debug) dboot_printf("Skipping PT_LOAD segment for " "paddr = 0x%lx\n", (ulong_t)phdr->p_paddr); continue; } /* * copy the data to kernel area */ if (phdr->p_paddr != FOUR_MEG && phdr->p_paddr != 2 * FOUR_MEG) dboot_panic("Bad paddr for kernel nucleus segment"); src = (uintptr_t)PGETBYTES(phdr->p_offset); dst = ktext_phys + phdr->p_paddr - FOUR_MEG; if (prom_debug) dboot_printf("copying %ld bytes from ELF offset 0x%lx " "to physaddr 0x%lx (va=0x%lx)\n", (ulong_t)phdr->p_filesz, (ulong_t)phdr->p_offset, (ulong_t)dst, (ulong_t)phdr->p_vaddr); (void) memcpy((void *)(uintptr_t)dst, (void *)(uintptr_t)src, (size_t)phdr->p_filesz); next_addr = dst + phdr->p_filesz; } /* * Next look for bss */ for (i = 0; i < eh->e_shnum; i++) { shdr = (Elf64_Shdr *)(sechdrs + eh->e_shentsize * i); /* zero out bss */ if (shdr->sh_type == SHT_NOBITS) { if (prom_debug) dboot_printf("zeroing BSS %ld bytes from " "physaddr 0x%llx (end=0x%llx)\n", (ulong_t)shdr->sh_size, (long long unsigned)next_addr, next_addr + shdr->sh_size); (void) memset((void *)(uintptr_t)next_addr, 0, shdr->sh_size); break; } } /* * Ignore the intepreter (or should we die if there is one??) */ return (0); }
/* * Walk through the module information finding the last used address. * The first available address will become the top level page table. * * We then build the phys_install memlist from the multiboot information. */ static void init_mem_alloc(void) { mb_memory_map_t *mmap; mb_module_t *mod; uint64_t start; uint64_t end; uint64_t page_offset = MMU_PAGEOFFSET; /* needs to be 64 bits */ extern char _end[]; int i; DBG_MSG("Entered init_mem_alloc()\n"); DBG((uintptr_t)mb_info); if (mb_info->mods_count > MAX_MODULES) { dboot_panic("Too many modules (%d) -- the maximum is %d.", mb_info->mods_count, MAX_MODULES); } /* * search the modules to find the last used address * we'll build the module list while we're walking through here */ DBG_MSG("\nFinding Modules\n"); check_higher((paddr_t)&_end); for (mod = (mb_module_t *)(mb_info->mods_addr), i = 0; i < mb_info->mods_count; ++mod, ++i) { if (prom_debug) { dboot_printf("\tmodule #%d: %s at: 0x%lx, len 0x%lx\n", i, (char *)(mod->mod_name), (ulong_t)mod->mod_start, (ulong_t)mod->mod_end); } modules[i].bm_addr = mod->mod_start; if (mod->mod_start > mod->mod_end) { dboot_panic("module[%d]: Invalid module start address " "(0x%llx)", i, (uint64_t)mod->mod_start); } modules[i].bm_size = mod->mod_end - mod->mod_start; check_higher(mod->mod_end); } bi->bi_modules = (native_ptr_t)modules; DBG(bi->bi_modules); bi->bi_module_cnt = mb_info->mods_count; DBG(bi->bi_module_cnt); /* * Walk through the memory map from multiboot and build our memlist * structures. Note these will have native format pointers. */ DBG_MSG("\nFinding Memory Map\n"); DBG(mb_info->flags); max_mem = 0; if (mb_info->flags & 0x40) { int cnt = 0; DBG(mb_info->mmap_addr); DBG(mb_info->mmap_length); check_higher(mb_info->mmap_addr + mb_info->mmap_length); for (mmap = (mb_memory_map_t *)mb_info->mmap_addr; (uint32_t)mmap < mb_info->mmap_addr + mb_info->mmap_length; mmap = (mb_memory_map_t *)((uint32_t)mmap + mmap->size + sizeof (mmap->size))) { ++cnt; start = ((uint64_t)mmap->base_addr_high << 32) + mmap->base_addr_low; end = start + ((uint64_t)mmap->length_high << 32) + mmap->length_low; if (prom_debug) dboot_printf("\ttype: %d %" PRIx64 "..%" PRIx64 "\n", mmap->type, start, end); /* * page align start and end */ start = (start + page_offset) & ~page_offset; end &= ~page_offset; if (end <= start) continue; /* * only type 1 is usable RAM */ switch (mmap->type) { case 1: if (end > max_mem) max_mem = end; memlists[memlists_used].addr = start; memlists[memlists_used].size = end - start; ++memlists_used; if (memlists_used > MAX_MEMLIST) dboot_panic("too many memlists"); break; case 2: rsvdmemlists[rsvdmemlists_used].addr = start; rsvdmemlists[rsvdmemlists_used].size = end - start; ++rsvdmemlists_used; if (rsvdmemlists_used > MAX_MEMLIST) dboot_panic("too many rsvdmemlists"); break; default: continue; } } build_pcimemlists((mb_memory_map_t *)mb_info->mmap_addr, cnt); } else if (mb_info->flags & 0x01) { DBG(mb_info->mem_lower); memlists[memlists_used].addr = 0; memlists[memlists_used].size = mb_info->mem_lower * 1024; ++memlists_used; DBG(mb_info->mem_upper); memlists[memlists_used].addr = 1024 * 1024; memlists[memlists_used].size = mb_info->mem_upper * 1024; ++memlists_used; /* * Old platform - assume I/O space at the end of memory. */ pcimemlists[0].addr = (mb_info->mem_upper * 1024) + (1024 * 1024); pcimemlists[0].size = pci_hi_limit - pcimemlists[0].addr; pcimemlists[0].next = 0; pcimemlists[0].prev = 0; bi->bi_pcimem = (native_ptr_t)pcimemlists; DBG(bi->bi_pcimem); } else { dboot_panic("No memory info from boot loader!!!"); } check_higher(bi->bi_cmdline); /* * finish processing the physinstall list */ sort_physinstall(); /* * build bios reserved mem lists */ build_rsvdmemlists(); }
static void init_mem_alloc(void) { int local; /* variables needed to find start region */ paddr_t scratch_start; xen_memory_map_t map; DBG_MSG("Entered init_mem_alloc()\n"); /* * Free memory follows the stack. There's at least 512KB of scratch * space, rounded up to at least 2Mb alignment. That should be enough * for the page tables we'll need to build. The nucleus memory is * allocated last and will be outside the addressible range. We'll * switch to new page tables before we unpack the kernel */ scratch_start = RNDUP((paddr_t)(uintptr_t)&local, MMU_PAGESIZE); DBG(scratch_start); scratch_end = RNDUP((paddr_t)scratch_start + 512 * 1024, TWO_MEG); DBG(scratch_end); /* * For paranoia, leave some space between hypervisor data and ours. * Use 500 instead of 512. */ next_avail_addr = scratch_end - 500 * 1024; DBG(next_avail_addr); /* * The domain builder gives us at most 1 module */ DBG(xen_info->mod_len); if (xen_info->mod_len > 0) { DBG(xen_info->mod_start); modules[0].bm_addr = xen_info->mod_start; modules[0].bm_size = xen_info->mod_len; bi->bi_module_cnt = 1; bi->bi_modules = (native_ptr_t)modules; } else { bi->bi_module_cnt = 0; bi->bi_modules = NULL; } DBG(bi->bi_module_cnt); DBG(bi->bi_modules); DBG(xen_info->mfn_list); DBG(xen_info->nr_pages); max_mem = (paddr_t)xen_info->nr_pages << MMU_PAGESHIFT; DBG(max_mem); /* * Using pseudo-physical addresses, so only 1 memlist element */ memlists[0].addr = 0; DBG(memlists[0].addr); memlists[0].size = max_mem; DBG(memlists[0].size); memlists_used = 1; DBG(memlists_used); /* * finish building physinstall list */ sort_physinstall(); /* * build bios reserved memlists */ build_rsvdmemlists(); if (DOMAIN_IS_INITDOMAIN(xen_info)) { /* * build PCI Memory list */ map.nr_entries = MAXMAPS; /*LINTED: constant in conditional context*/ set_xen_guest_handle(map.buffer, map_buffer); if (HYPERVISOR_memory_op(XENMEM_machine_memory_map, &map) != 0) dboot_panic("getting XENMEM_machine_memory_map failed"); build_pcimemlists(map_buffer, map.nr_entries); } }
/*ARGSUSED*/ void startup_kernel(void) { char *cmdline; uintptr_t addr; #if defined(__xpv) physdev_set_iopl_t set_iopl; #endif /* __xpv */ /* * At this point we are executing in a 32 bit real mode. */ #if defined(__xpv) cmdline = (char *)xen_info->cmd_line; #else /* __xpv */ cmdline = (char *)mb_info->cmdline; #endif /* __xpv */ prom_debug = (strstr(cmdline, "prom_debug") != NULL); map_debug = (strstr(cmdline, "map_debug") != NULL); #if defined(__xpv) /* * For dom0, before we initialize the console subsystem we'll * need to enable io operations, so set I/O priveldge level to 1. */ if (DOMAIN_IS_INITDOMAIN(xen_info)) { set_iopl.iopl = 1; (void) HYPERVISOR_physdev_op(PHYSDEVOP_set_iopl, &set_iopl); } #endif /* __xpv */ bcons_init(cmdline); DBG_MSG("\n\nSolaris prekernel set: "); DBG_MSG(cmdline); DBG_MSG("\n"); if (strstr(cmdline, "multiboot") != NULL) { dboot_panic(NO_MULTIBOOT); } /* * boot info must be 16 byte aligned for 64 bit kernel ABI */ addr = (uintptr_t)boot_info; addr = (addr + 0xf) & ~0xf; bi = (struct xboot_info *)addr; DBG((uintptr_t)bi); bi->bi_cmdline = (native_ptr_t)(uintptr_t)cmdline; /* * Need correct target_kernel_text value */ #if defined(_BOOT_TARGET_amd64) target_kernel_text = KERNEL_TEXT_amd64; #elif defined(__xpv) target_kernel_text = KERNEL_TEXT_i386_xpv; #else target_kernel_text = KERNEL_TEXT_i386; #endif DBG(target_kernel_text); #if defined(__xpv) /* * XXPV Derive this stuff from CPUID / what the hypervisor has enabled */ #if defined(_BOOT_TARGET_amd64) /* * 64-bit hypervisor. */ amd64_support = 1; pae_support = 1; #else /* _BOOT_TARGET_amd64 */ /* * See if we are running on a PAE Hypervisor */ { xen_capabilities_info_t caps; if (HYPERVISOR_xen_version(XENVER_capabilities, &caps) != 0) dboot_panic("HYPERVISOR_xen_version(caps) failed"); caps[sizeof (caps) - 1] = 0; if (prom_debug) dboot_printf("xen capabilities %s\n", caps); if (strstr(caps, "x86_32p") != NULL) pae_support = 1; } #endif /* _BOOT_TARGET_amd64 */ { xen_platform_parameters_t p; if (HYPERVISOR_xen_version(XENVER_platform_parameters, &p) != 0) dboot_panic("HYPERVISOR_xen_version(parms) failed"); DBG(p.virt_start); mfn_to_pfn_mapping = (pfn_t *)(xen_virt_start = p.virt_start); } /* * The hypervisor loads stuff starting at 1Gig */ mfn_base = ONE_GIG; DBG(mfn_base); /* * enable writable page table mode for the hypervisor */ if (HYPERVISOR_vm_assist(VMASST_CMD_enable, VMASST_TYPE_writable_pagetables) < 0) dboot_panic("HYPERVISOR_vm_assist(writable_pagetables) failed"); /* * check for NX support */ if (pae_support) { uint32_t eax = 0x80000000; uint32_t edx = get_cpuid_edx(&eax); if (eax >= 0x80000001) { eax = 0x80000001; edx = get_cpuid_edx(&eax); if (edx & CPUID_AMD_EDX_NX) NX_support = 1; } } #if !defined(_BOOT_TARGET_amd64) /* * The 32-bit hypervisor uses segmentation to protect itself from * guests. This means when a guest attempts to install a flat 4GB * code or data descriptor the 32-bit hypervisor will protect itself * by silently shrinking the segment such that if the guest attempts * any access where the hypervisor lives a #gp fault is generated. * The problem is that some applications expect a full 4GB flat * segment for their current thread pointer and will use negative * offset segment wrap around to access data. TLS support in linux * brand is one example of this. * * The 32-bit hypervisor can catch the #gp fault in these cases * and emulate the access without passing the #gp fault to the guest * but only if VMASST_TYPE_4gb_segments is explicitly turned on. * Seems like this should have been the default. * Either way, we want the hypervisor -- and not Solaris -- to deal * to deal with emulating these accesses. */ if (HYPERVISOR_vm_assist(VMASST_CMD_enable, VMASST_TYPE_4gb_segments) < 0) dboot_panic("HYPERVISOR_vm_assist(4gb_segments) failed"); #endif /* !_BOOT_TARGET_amd64 */ #else /* __xpv */ /* * use cpuid to enable MMU features */ if (have_cpuid()) { uint32_t eax, edx; eax = 1; edx = get_cpuid_edx(&eax); if (edx & CPUID_INTC_EDX_PSE) largepage_support = 1; if (edx & CPUID_INTC_EDX_PGE) pge_support = 1; if (edx & CPUID_INTC_EDX_PAE) pae_support = 1; eax = 0x80000000; edx = get_cpuid_edx(&eax); if (eax >= 0x80000001) { eax = 0x80000001; edx = get_cpuid_edx(&eax); if (edx & CPUID_AMD_EDX_LM) amd64_support = 1; if (edx & CPUID_AMD_EDX_NX) NX_support = 1; } } else { dboot_printf("cpuid not supported\n"); } #endif /* __xpv */ #if defined(_BOOT_TARGET_amd64) if (amd64_support == 0) dboot_panic("long mode not supported, rebooting"); else if (pae_support == 0) dboot_panic("long mode, but no PAE; rebooting"); #else /* * Allow the command line to over-ride use of PAE for 32 bit. */ if (strstr(cmdline, "disablePAE=true") != NULL) { pae_support = 0; NX_support = 0; amd64_support = 0; } #endif /* * initialize the simple memory allocator */ init_mem_alloc(); #if !defined(__xpv) && !defined(_BOOT_TARGET_amd64) /* * disable PAE on 32 bit h/w w/o NX and < 4Gig of memory */ if (max_mem < FOUR_GIG && NX_support == 0) pae_support = 0; #endif /* * configure mmu information */ if (pae_support) { shift_amt = shift_amt_pae; ptes_per_table = 512; pte_size = 8; lpagesize = TWO_MEG; #if defined(_BOOT_TARGET_amd64) top_level = 3; #else top_level = 2; #endif } else { pae_support = 0; NX_support = 0; shift_amt = shift_amt_nopae; ptes_per_table = 1024; pte_size = 4; lpagesize = FOUR_MEG; top_level = 1; } DBG(pge_support); DBG(NX_support); DBG(largepage_support); DBG(amd64_support); DBG(top_level); DBG(pte_size); DBG(ptes_per_table); DBG(lpagesize); #if defined(__xpv) ktext_phys = ONE_GIG; /* from UNIX Mapfile */ #else ktext_phys = FOUR_MEG; /* from UNIX Mapfile */ #endif #if !defined(__xpv) && defined(_BOOT_TARGET_amd64) /* * For grub, copy kernel bits from the ELF64 file to final place. */ DBG_MSG("\nAllocating nucleus pages.\n"); ktext_phys = (uintptr_t)do_mem_alloc(ksize, FOUR_MEG); if (ktext_phys == 0) dboot_panic("failed to allocate aligned kernel memory"); if (dboot_elfload64(mb_header.load_addr) != 0) dboot_panic("failed to parse kernel ELF image, rebooting"); #endif DBG(ktext_phys); /* * Allocate page tables. */ build_page_tables(); /* * return to assembly code to switch to running kernel */ entry_addr_low = (uint32_t)target_kernel_text; DBG(entry_addr_low); bi->bi_use_largepage = largepage_support; bi->bi_use_pae = pae_support; bi->bi_use_pge = pge_support; bi->bi_use_nx = NX_support; #if defined(__xpv) bi->bi_next_paddr = next_avail_addr - mfn_base; DBG(bi->bi_next_paddr); bi->bi_next_vaddr = (native_ptr_t)next_avail_addr; DBG(bi->bi_next_vaddr); /* * unmap unused pages in start area to make them available for DMA */ while (next_avail_addr < scratch_end) { (void) HYPERVISOR_update_va_mapping(next_avail_addr, 0, UVMF_INVLPG | UVMF_LOCAL); next_avail_addr += MMU_PAGESIZE; } bi->bi_xen_start_info = (uintptr_t)xen_info; DBG((uintptr_t)HYPERVISOR_shared_info); bi->bi_shared_info = (native_ptr_t)HYPERVISOR_shared_info; bi->bi_top_page_table = (uintptr_t)top_page_table - mfn_base; #else /* __xpv */ bi->bi_next_paddr = next_avail_addr; DBG(bi->bi_next_paddr); bi->bi_next_vaddr = (uintptr_t)next_avail_addr; DBG(bi->bi_next_vaddr); bi->bi_mb_info = (uintptr_t)mb_info; bi->bi_top_page_table = (uintptr_t)top_page_table; #endif /* __xpv */ bi->bi_kseg_size = FOUR_MEG; DBG(bi->bi_kseg_size); #ifndef __xpv if (map_debug) dump_tables(); #endif DBG_MSG("\n\n*** DBOOT DONE -- back to asm to jump to kernel\n\n"); }