setup.c
来自「xen虚拟机源代码安装包」· C语言 代码 · 共 1,123 行 · 第 1/3 页
C
1,123 行
if ( !initial_images_start ) EARLY_FAIL("Not enough memory to relocate the dom0 kernel image.\n"); reserve_e820_ram(&boot_e820, initial_images_start, initial_images_end); /* Initialise Xen heap and boot heap. */ xenheap_phys_start = init_boot_allocator(__pa(&_end)); xenheap_phys_end = opt_xenheap_megabytes << 20;#if defined(CONFIG_X86_64) if ( !xen_phys_start ) EARLY_FAIL("Not enough memory to relocate Xen.\n"); xenheap_phys_end += xen_phys_start; reserve_e820_ram(&boot_e820, xen_phys_start, xen_phys_start + (opt_xenheap_megabytes<<20));#endif /* Late kexec reservation (dynamic start address). */ kexec_reserve_area(&boot_e820); /* * With the boot allocator now initialised, we can walk every RAM region * and map it in its entirety (on x86/64, at least) and notify it to the * boot allocator. */ for ( i = 0; i < boot_e820.nr_map; i++ ) { uint64_t s, e, map_s, map_e, mask = PAGE_SIZE - 1; /* Only page alignment required now. */ s = (boot_e820.map[i].addr + mask) & ~mask; e = (boot_e820.map[i].addr + boot_e820.map[i].size) & ~mask;#if defined(CONFIG_X86_32) s = max_t(uint64_t, s, xenheap_phys_end);#else s = max_t(uint64_t, s, 1<<20);#endif if ( (boot_e820.map[i].type != E820_RAM) || (s >= e) ) continue; /* Need to create mappings above 16MB. */ map_s = max_t(uint64_t, s, 16<<20); map_e = e;#if defined(CONFIG_X86_32) /* mappings are truncated on x86_32 */ map_e = min_t(uint64_t, map_e, BOOTSTRAP_DIRECTMAP_END);#endif /* Pass mapped memory to allocator /before/ creating new mappings. */ init_boot_pages(s, min_t(uint64_t, map_s, e)); /* Create new mappings /before/ passing memory to the allocator. */ if ( map_s < map_e ) map_pages_to_xen( (unsigned long)maddr_to_bootstrap_virt(map_s), map_s >> PAGE_SHIFT, (map_e-map_s) >> PAGE_SHIFT, PAGE_HYPERVISOR); /* Pass remainder of this memory chunk to the allocator. */ init_boot_pages(map_s, e); } memguard_init(); nr_pages = 0; for ( i = 0; i < e820.nr_map; i++ ) if ( e820.map[i].type == E820_RAM ) nr_pages += e820.map[i].size >> PAGE_SHIFT; printk("System RAM: %luMB (%lukB)\n", nr_pages >> (20 - PAGE_SHIFT), nr_pages << (PAGE_SHIFT - 10)); total_pages = nr_pages; /* Sanity check for unwanted bloat of certain hypercall structures. */ BUILD_BUG_ON(sizeof(((struct xen_platform_op *)0)->u) != sizeof(((struct xen_platform_op *)0)->u.pad)); BUILD_BUG_ON(sizeof(((struct xen_domctl *)0)->u) != sizeof(((struct xen_domctl *)0)->u.pad)); BUILD_BUG_ON(sizeof(((struct xen_sysctl *)0)->u) != sizeof(((struct xen_sysctl *)0)->u.pad)); BUILD_BUG_ON(sizeof(start_info_t) > PAGE_SIZE); BUILD_BUG_ON(sizeof(shared_info_t) > PAGE_SIZE); BUILD_BUG_ON(sizeof(struct vcpu_info) != 64);#ifdef CONFIG_COMPAT BUILD_BUG_ON(sizeof(((struct compat_platform_op *)0)->u) != sizeof(((struct compat_platform_op *)0)->u.pad)); BUILD_BUG_ON(sizeof(start_info_compat_t) > PAGE_SIZE); BUILD_BUG_ON(sizeof(struct compat_vcpu_info) != 64);#endif /* Check definitions in public headers match internal defs. */ BUILD_BUG_ON(__HYPERVISOR_VIRT_START != HYPERVISOR_VIRT_START);#ifdef HYPERVISOR_VIRT_END BUILD_BUG_ON(__HYPERVISOR_VIRT_END != HYPERVISOR_VIRT_END);#endif BUILD_BUG_ON(MACH2PHYS_VIRT_START != RO_MPT_VIRT_START); BUILD_BUG_ON(MACH2PHYS_VIRT_END != RO_MPT_VIRT_END); init_frametable(); acpi_boot_table_init(); acpi_numa_init(); numa_initmem_init(0, max_page); /* Initialise the Xen heap, skipping RAM holes. */ init_xenheap_pages(xenheap_phys_start, xenheap_phys_end); nr_pages = (xenheap_phys_end - xenheap_phys_start) >> PAGE_SHIFT;#ifdef __x86_64__ init_xenheap_pages(xen_phys_start, __pa(&_start)); nr_pages += (__pa(&_start) - xen_phys_start) >> PAGE_SHIFT; vesa_init();#endif xenheap_phys_start = xen_phys_start; printk("Xen heap: %luMB (%lukB)\n", nr_pages >> (20 - PAGE_SHIFT), nr_pages << (PAGE_SHIFT - 10)); end_boot_allocator(); early_boot = 0; softirq_init(); early_cpu_init(); paging_init(); tboot_probe(); /* Unmap the first page of CPU0's stack. */ memguard_guard_stack(cpu0_stack); open_softirq(NEW_TLBFLUSH_CLOCK_PERIOD_SOFTIRQ, new_tlbflush_clock_period); if ( opt_watchdog ) nmi_watchdog = NMI_LOCAL_APIC; sort_exception_tables(); find_smp_config(); dmi_scan_machine(); generic_apic_probe(); if ( x2apic_is_available() ) enable_x2apic(); acpi_boot_init(); init_cpu_to_node(); if ( smp_found_config ) get_smp_config();#ifdef CONFIG_X86_64 /* Low mappings were only needed for some BIOS table parsing. */ zap_low_mappings();#endif init_apic_mappings(); init_IRQ(); percpu_init_areas(); xsm_init(&initrdidx, mbi, initial_images_start); init_idle_domain(); trap_init(); rcu_init(); timer_init(); early_time_init(); arch_init_memory(); identify_cpu(&boot_cpu_data); if ( cpu_has_fxsr ) set_in_cr4(X86_CR4_OSFXSR); if ( cpu_has_xmm ) set_in_cr4(X86_CR4_OSXMMEXCPT);#ifdef CONFIG_X86_64 vesa_mtrr_init();#endif if ( opt_nosmp ) max_cpus = 0; smp_prepare_cpus(max_cpus); /* * Initialise higher-level timer functions. We do this fairly late * (post-SMP) because the time bases and scale factors need to be updated * regularly, and SMP initialisation can cause a long delay with * interrupts not yet enabled. */ init_xen_time(); initialize_keytable(); serial_init_postirq(); BUG_ON(!local_irq_is_enabled()); for_each_present_cpu ( i ) { if ( num_online_cpus() >= max_cpus ) break; if ( !cpu_online(i) ) { rcu_online_cpu(i); __cpu_up(i); } /* Set up cpu_to_node[]. */ srat_detect_node(i); /* Set up node_to_cpumask based on cpu_to_node[]. */ numa_add_cpu(i); } printk("Brought up %ld CPUs\n", (long)num_online_cpus()); smp_cpus_done(max_cpus); initialise_gdb(); /* could be moved earlier */ do_initcalls(); if ( opt_watchdog ) watchdog_enable(); /* Create initial domain 0. */ dom0 = domain_create(0, 0, DOM0_SSIDREF); if ( (dom0 == NULL) || (alloc_vcpu(dom0, 0, 0) == NULL) ) panic("Error creating domain 0\n"); dom0->is_privileged = 1; dom0->target = NULL; /* Grab the DOM0 command line. */ cmdline = (char *)(mod[0].string ? __va(mod[0].string) : NULL); if ( (cmdline != NULL) || (kextra != NULL) ) { static char dom0_cmdline[MAX_GUEST_CMDLINE]; cmdline = cmdline_cook(cmdline); safe_strcpy(dom0_cmdline, cmdline); if ( kextra != NULL ) /* kextra always includes exactly one leading space. */ safe_strcat(dom0_cmdline, kextra); /* Append any extra parameters. */ if ( skip_ioapic_setup && !strstr(dom0_cmdline, "noapic") ) safe_strcat(dom0_cmdline, " noapic"); if ( acpi_skip_timer_override && !strstr(dom0_cmdline, "acpi_skip_timer_override") ) safe_strcat(dom0_cmdline, " acpi_skip_timer_override"); if ( (strlen(acpi_param) == 0) && acpi_disabled ) { printk("ACPI is disabled, notifying Domain 0 (acpi=off)\n"); safe_strcpy(acpi_param, "off"); } if ( (strlen(acpi_param) != 0) && !strstr(dom0_cmdline, "acpi=") ) { safe_strcat(dom0_cmdline, " acpi="); safe_strcat(dom0_cmdline, acpi_param); } cmdline = dom0_cmdline; } if ( (initrdidx > 0) && (initrdidx < mbi->mods_count) ) { _initrd_start = initial_images_start + (mod[initrdidx].mod_start - mod[0].mod_start); _initrd_len = mod[initrdidx].mod_end - mod[initrdidx].mod_start; } if ( xen_cpuidle ) xen_processor_pmbits |= XEN_PROCESSOR_PM_CX; /* * We're going to setup domain0 using the module(s) that we stashed safely * above our heap. The second module, if present, is an initrd ramdisk. */ if ( construct_dom0(dom0, initial_images_start, mod[0].mod_end-mod[0].mod_start, _initrd_start, _initrd_len, cmdline) != 0) panic("Could not set up DOM0 guest OS\n"); /* Scrub RAM that is still free and so may go to an unprivileged domain. */ scrub_heap_pages(); init_trace_bufs(); console_endboot(); /* Hide UART from DOM0 if we're using it */ serial_endboot(); domain_unpause_by_systemcontroller(dom0); reset_stack_and_jump(init_done);}void arch_get_xen_caps(xen_capabilities_info_t *info){ /* Interface name is always xen-3.0-* for Xen-3.x. */ int major = 3, minor = 0; char s[32]; (*info)[0] = '\0';#if defined(CONFIG_X86_32) snprintf(s, sizeof(s), "xen-%d.%d-x86_32p ", major, minor); safe_strcat(*info, s); if ( hvm_enabled ) { snprintf(s, sizeof(s), "hvm-%d.%d-x86_32 ", major, minor); safe_strcat(*info, s); snprintf(s, sizeof(s), "hvm-%d.%d-x86_32p ", major, minor); safe_strcat(*info, s); }#elif defined(CONFIG_X86_64) snprintf(s, sizeof(s), "xen-%d.%d-x86_64 ", major, minor); safe_strcat(*info, s);#ifdef CONFIG_COMPAT snprintf(s, sizeof(s), "xen-%d.%d-x86_32p ", major, minor); safe_strcat(*info, s);#endif if ( hvm_enabled ) { snprintf(s, sizeof(s), "hvm-%d.%d-x86_32 ", major, minor); safe_strcat(*info, s); snprintf(s, sizeof(s), "hvm-%d.%d-x86_32p ", major, minor); safe_strcat(*info, s); snprintf(s, sizeof(s), "hvm-%d.%d-x86_64 ", major, minor); safe_strcat(*info, s); }#endif}int xen_in_range(paddr_t start, paddr_t end){ start = max_t(paddr_t, start, xenheap_phys_start); end = min_t(paddr_t, end, xenheap_phys_end); return start < end; }/* * Local variables: * mode: C * c-set-style: "BSD" * c-basic-offset: 4 * tab-width: 4 * indent-tabs-mode: nil * End: */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?