ia64/xen-unstable

annotate xen/arch/x86/setup.c @ 5011:9263f821935a

bitkeeper revision 1.1466.1.1 (428cceb2sTCzL9rItLSMlnmH9XrnTQ)

Ensure correct alignment of CPU0 stack -- it must be aligned on a
2^STACK_ORDER page boundary. This requirement is now also checked
at run-time, and a clear fatal error given if it is not satisfied.
This bug affected both x86/32 and x86/64.
Signed-off-by: Keir Fraser <keir@xensource.com>
author kaf24@firebug.cl.cam.ac.uk
date Thu May 19 17:36:50 2005 +0000 (2005-05-19)
parents ba07574a5b6f
children d1e3efb12a27
rev   line source
kaf24@1452 1
kaf24@1452 2 #include <xen/config.h>
kaf24@1452 3 #include <xen/init.h>
kaf24@1452 4 #include <xen/lib.h>
kaf24@1452 5 #include <xen/sched.h>
kaf24@1452 6 #include <xen/serial.h>
kaf24@1506 7 #include <xen/softirq.h>
kaf24@1452 8 #include <xen/acpi.h>
kaf24@3338 9 #include <xen/console.h>
iap10@4287 10 #include <xen/serial.h>
kaf24@3338 11 #include <xen/trace.h>
kaf24@3338 12 #include <xen/multiboot.h>
kaf24@1452 13 #include <asm/bitops.h>
kaf24@1452 14 #include <asm/smp.h>
kaf24@1452 15 #include <asm/processor.h>
kaf24@1452 16 #include <asm/mpspec.h>
kaf24@1452 17 #include <asm/apic.h>
kaf24@1452 18 #include <asm/desc.h>
kaf24@1452 19 #include <asm/domain_page.h>
kaf24@3338 20 #include <asm/shadow.h>
kaf24@3344 21 #include <asm/e820.h>
kaf24@3338 22
kaf24@3338 23 /*
kaf24@3338 24 * opt_xenheap_megabytes: Size of Xen heap in megabytes, excluding the
kaf24@3338 25 * pfn_info table and allocation bitmap.
kaf24@3338 26 */
kaf24@3338 27 static unsigned int opt_xenheap_megabytes = XENHEAP_DEFAULT_MB;
kaf24@4950 28 #if defined(CONFIG_X86_64)
kaf24@3338 29 integer_param("xenheap_megabytes", opt_xenheap_megabytes);
kaf24@3354 30 #endif
kaf24@1452 31
kaf24@3334 32 /* opt_noht: If true, Hyperthreading is ignored. */
kaf24@3334 33 int opt_noht = 0;
kaf24@3334 34 boolean_param("noht", opt_noht);
kaf24@3334 35
kaf24@3334 36 /* opt_watchdog: If true, run a watchdog NMI on each processor. */
kaf24@3334 37 static int opt_watchdog = 0;
kaf24@3334 38 boolean_param("watchdog", opt_watchdog);
kaf24@3334 39
kaf24@4850 40 /* **** Linux config option: propagated to domain0. */
kaf24@4850 41 /* "acpi=off": Sisables both ACPI table parsing and interpreter. */
kaf24@4850 42 /* "acpi=force": Override the disable blacklist. */
kaf24@4850 43 /* "acpi=strict": Disables out-of-spec workarounds. */
kaf24@4850 44 /* "acpi=ht": Limit ACPI just to boot-time to enable HT. */
kaf24@4850 45 /* "acpi=noirq": Disables ACPI interrupt routing. */
kaf24@4850 46 static void parse_acpi_param(char *s);
kaf24@4850 47 custom_param("acpi", parse_acpi_param);
kaf24@4850 48
kaf24@4850 49 /* **** Linux config option: propagated to domain0. */
kaf24@4850 50 /* acpi_skip_timer_override: Skip IRQ0 overrides. */
kaf24@4850 51 extern int acpi_skip_timer_override;
kaf24@4850 52 boolean_param("acpi_skip_timer_override", acpi_skip_timer_override);
kaf24@4850 53
kaf24@4850 54 /* **** Linux config option: propagated to domain0. */
kaf24@4850 55 /* noapic: Disable IOAPIC setup. */
kaf24@4850 56 extern int skip_ioapic_setup;
kaf24@4850 57 boolean_param("noapic", skip_ioapic_setup);
kaf24@4850 58
kaf24@3594 59 int early_boot = 1;
kaf24@3594 60
kaf24@5003 61 /* Limits of Xen heap, used to initialise the allocator. */
kaf24@5003 62 unsigned long xenheap_phys_start, xenheap_phys_end;
kaf24@3338 63
kaf24@2298 64 extern void arch_init_memory(void);
kaf24@1589 65 extern void init_IRQ(void);
kaf24@1589 66 extern void trap_init(void);
kaf24@1589 67 extern void time_init(void);
kaf24@1589 68 extern void ac_timer_init(void);
kaf24@1589 69 extern void initialize_keytable();
kaf24@1589 70 extern int do_timer_lists_from_pit;
kaf24@1589 71
kaf24@5011 72 extern unsigned long cpu0_stack[];
kaf24@5011 73
kaf24@1480 74 struct cpuinfo_x86 boot_cpu_data = { 0, 0, 0, 0, -1 };
kaf24@1452 75
kaf24@4950 76 #if defined(CONFIG_X86_64)
kaf24@1670 77 unsigned long mmu_cr4_features = X86_CR4_PSE | X86_CR4_PGE | X86_CR4_PAE;
kaf24@1670 78 #else
kaf24@1452 79 unsigned long mmu_cr4_features = X86_CR4_PSE | X86_CR4_PGE;
kaf24@1670 80 #endif
kaf24@1452 81 EXPORT_SYMBOL(mmu_cr4_features);
kaf24@1452 82
kaf24@1452 83 unsigned long wait_init_idle;
kaf24@1452 84
cl349@2919 85 struct exec_domain *idle_task[NR_CPUS] = { &idle0_exec_domain };
kaf24@1452 86
kaf24@4818 87 int acpi_disabled;
kaf24@1452 88
kaf24@1452 89 int phys_proc_id[NR_CPUS];
kaf24@1452 90 int logical_proc_id[NR_CPUS];
kaf24@1452 91
kaf24@3623 92 /* Standard macro to see if a specific flag is changeable. */
kaf24@3623 93 static inline int flag_is_changeable_p(unsigned long flag)
kaf24@1452 94 {
kaf24@3623 95 unsigned long f1, f2;
kaf24@1452 96
kaf24@3623 97 asm("pushf\n\t"
kaf24@3623 98 "pushf\n\t"
kaf24@3623 99 "pop %0\n\t"
kaf24@3623 100 "mov %0,%1\n\t"
kaf24@3623 101 "xor %2,%0\n\t"
kaf24@3623 102 "push %0\n\t"
kaf24@3623 103 "popf\n\t"
kaf24@3623 104 "pushf\n\t"
kaf24@3623 105 "pop %0\n\t"
kaf24@3623 106 "popf\n\t"
kaf24@1452 107 : "=&r" (f1), "=&r" (f2)
kaf24@1452 108 : "ir" (flag));
kaf24@1452 109
kaf24@1452 110 return ((f1^f2) & flag) != 0;
kaf24@1452 111 }
kaf24@1452 112
kaf24@1452 113 /* Probe for the CPUID instruction */
kaf24@1452 114 static int __init have_cpuid_p(void)
kaf24@1452 115 {
kaf24@1452 116 return flag_is_changeable_p(X86_EFLAGS_ID);
kaf24@1452 117 }
kaf24@1452 118
kaf24@1452 119 void __init get_cpu_vendor(struct cpuinfo_x86 *c)
kaf24@1452 120 {
kaf24@1452 121 char *v = c->x86_vendor_id;
kaf24@1452 122
kaf24@1452 123 if (!strcmp(v, "GenuineIntel"))
kaf24@1452 124 c->x86_vendor = X86_VENDOR_INTEL;
kaf24@1452 125 else if (!strcmp(v, "AuthenticAMD"))
kaf24@1452 126 c->x86_vendor = X86_VENDOR_AMD;
kaf24@1452 127 else if (!strcmp(v, "CyrixInstead"))
kaf24@1452 128 c->x86_vendor = X86_VENDOR_CYRIX;
kaf24@1452 129 else if (!strcmp(v, "UMC UMC UMC "))
kaf24@1452 130 c->x86_vendor = X86_VENDOR_UMC;
kaf24@1452 131 else if (!strcmp(v, "CentaurHauls"))
kaf24@1452 132 c->x86_vendor = X86_VENDOR_CENTAUR;
kaf24@1452 133 else if (!strcmp(v, "NexGenDriven"))
kaf24@1452 134 c->x86_vendor = X86_VENDOR_NEXGEN;
kaf24@1452 135 else if (!strcmp(v, "RiseRiseRise"))
kaf24@1452 136 c->x86_vendor = X86_VENDOR_RISE;
kaf24@1452 137 else if (!strcmp(v, "GenuineTMx86") ||
kaf24@1452 138 !strcmp(v, "TransmetaCPU"))
kaf24@1452 139 c->x86_vendor = X86_VENDOR_TRANSMETA;
kaf24@1452 140 else
kaf24@1452 141 c->x86_vendor = X86_VENDOR_UNKNOWN;
kaf24@1452 142 }
kaf24@1452 143
kaf24@1452 144 static void __init init_intel(struct cpuinfo_x86 *c)
kaf24@1452 145 {
kaf24@1452 146 /* SEP CPUID bug: Pentium Pro reports SEP but doesn't have it */
kaf24@1452 147 if ( c->x86 == 6 && c->x86_model < 3 && c->x86_mask < 3 )
kaf24@1452 148 clear_bit(X86_FEATURE_SEP, &c->x86_capability);
kaf24@1452 149
kaf24@1452 150 #ifdef CONFIG_SMP
kaf24@1452 151 if ( test_bit(X86_FEATURE_HT, &c->x86_capability) )
kaf24@1452 152 {
kaf24@1452 153 u32 eax, ebx, ecx, edx;
kaf24@1452 154 int initial_apic_id, siblings, cpu = smp_processor_id();
kaf24@1452 155
kaf24@1452 156 cpuid(1, &eax, &ebx, &ecx, &edx);
cl349@2703 157 ht_per_core = siblings = (ebx & 0xff0000) >> 16;
cl349@2703 158
cl349@2703 159 if ( opt_noht )
cl349@2703 160 clear_bit(X86_FEATURE_HT, &c->x86_capability[0]);
cl349@2703 161
kaf24@1452 162 if ( siblings <= 1 )
kaf24@1452 163 {
kaf24@1452 164 printk(KERN_INFO "CPU#%d: Hyper-Threading is disabled\n", cpu);
kaf24@1452 165 }
kaf24@1452 166 else if ( siblings > 2 )
kaf24@1452 167 {
kaf24@1452 168 panic("We don't support more than two logical CPUs per package!");
kaf24@1452 169 }
kaf24@1452 170 else
kaf24@1452 171 {
kaf24@1452 172 initial_apic_id = ebx >> 24 & 0xff;
kaf24@1452 173 phys_proc_id[cpu] = initial_apic_id >> 1;
kaf24@1452 174 logical_proc_id[cpu] = initial_apic_id & 1;
kaf24@1452 175 printk(KERN_INFO "CPU#%d: Physical ID: %d, Logical ID: %d\n",
kaf24@1452 176 cpu, phys_proc_id[cpu], logical_proc_id[cpu]);
kaf24@1452 177 }
kaf24@1452 178 }
kaf24@1452 179 #endif
iap10@3290 180
iap10@3290 181 #ifdef CONFIG_VMX
iap10@3290 182 start_vmx();
iap10@3290 183 #endif
iap10@3290 184
kaf24@1452 185 }
kaf24@1452 186
kaf24@1452 187 static void __init init_amd(struct cpuinfo_x86 *c)
kaf24@1452 188 {
kaf24@1452 189 /* Bit 31 in normal CPUID used for nonstandard 3DNow ID;
kaf24@1452 190 3DNow is IDd by bit 31 in extended CPUID (1*32+31) anyway */
kaf24@1452 191 clear_bit(0*32+31, &c->x86_capability);
kaf24@1452 192
kaf24@1452 193 switch(c->x86)
kaf24@1452 194 {
kaf24@1452 195 case 5:
kaf24@1452 196 panic("AMD K6 is not supported.\n");
kaf24@1452 197 case 6: /* An Athlon/Duron. We can trust the BIOS probably */
kaf24@1452 198 break;
kaf24@1452 199 }
kaf24@1452 200 }
kaf24@1452 201
kaf24@1452 202 /*
kaf24@1452 203 * This does the hard work of actually picking apart the CPU stuff...
kaf24@1452 204 */
kaf24@1452 205 void __init identify_cpu(struct cpuinfo_x86 *c)
kaf24@1452 206 {
riel@3992 207 int i, cpu = smp_processor_id();
riel@3992 208 u32 xlvl, tfms, junk;
kaf24@1452 209
kaf24@1452 210 phys_proc_id[cpu] = cpu;
kaf24@1452 211 logical_proc_id[cpu] = 0;
kaf24@1452 212
kaf24@1452 213 c->x86_vendor = X86_VENDOR_UNKNOWN;
kaf24@1452 214 c->cpuid_level = -1; /* CPUID not detected */
kaf24@1452 215 c->x86_model = c->x86_mask = 0; /* So far unknown... */
kaf24@1452 216 c->x86_vendor_id[0] = '\0'; /* Unset */
kaf24@1452 217 memset(&c->x86_capability, 0, sizeof c->x86_capability);
kaf24@1452 218
kaf24@1452 219 if ( !have_cpuid_p() )
kaf24@1452 220 panic("Ancient processors not supported\n");
kaf24@1452 221
kaf24@1452 222 /* Get vendor name */
riel@3992 223 cpuid(0x00000000, (unsigned int *)&c->cpuid_level,
riel@3992 224 (unsigned int *)&c->x86_vendor_id[0],
riel@3992 225 (unsigned int *)&c->x86_vendor_id[8],
riel@3992 226 (unsigned int *)&c->x86_vendor_id[4]);
kaf24@1452 227
kaf24@1452 228 get_cpu_vendor(c);
kaf24@1452 229
kaf24@1452 230 if ( c->cpuid_level == 0 )
kaf24@1452 231 panic("Decrepit CPUID not supported\n");
kaf24@1452 232
kaf24@1452 233 cpuid(0x00000001, &tfms, &junk, &junk,
kaf24@1452 234 &c->x86_capability[0]);
kaf24@1452 235 c->x86 = (tfms >> 8) & 15;
kaf24@1452 236 c->x86_model = (tfms >> 4) & 15;
kaf24@1452 237 c->x86_mask = tfms & 15;
kaf24@1452 238
kaf24@1452 239 /* AMD-defined flags: level 0x80000001 */
kaf24@1452 240 xlvl = cpuid_eax(0x80000000);
kaf24@1452 241 if ( (xlvl & 0xffff0000) == 0x80000000 ) {
kaf24@1452 242 if ( xlvl >= 0x80000001 )
kaf24@1452 243 c->x86_capability[1] = cpuid_edx(0x80000001);
kaf24@1452 244 }
kaf24@1452 245
kaf24@1452 246 /* Transmeta-defined flags: level 0x80860001 */
kaf24@1452 247 xlvl = cpuid_eax(0x80860000);
kaf24@1452 248 if ( (xlvl & 0xffff0000) == 0x80860000 ) {
kaf24@1452 249 if ( xlvl >= 0x80860001 )
kaf24@1452 250 c->x86_capability[2] = cpuid_edx(0x80860001);
kaf24@1452 251 }
kaf24@1452 252
kaf24@1452 253 printk("CPU%d: Before vendor init, caps: %08x %08x %08x, vendor = %d\n",
kaf24@1452 254 smp_processor_id(),
kaf24@1452 255 c->x86_capability[0],
kaf24@1452 256 c->x86_capability[1],
kaf24@1452 257 c->x86_capability[2],
kaf24@1452 258 c->x86_vendor);
kaf24@1452 259
kaf24@1452 260 switch ( c->x86_vendor ) {
kaf24@1452 261 case X86_VENDOR_INTEL:
kaf24@1452 262 init_intel(c);
kaf24@1452 263 break;
kaf24@1452 264 case X86_VENDOR_AMD:
kaf24@1452 265 init_amd(c);
kaf24@1452 266 break;
kaf24@1452 267 case X86_VENDOR_UNKNOWN: /* Connectix Virtual PC reports this */
kaf24@1452 268 break;
kaf24@1452 269 case X86_VENDOR_CENTAUR:
kaf24@1452 270 break;
kaf24@1452 271 default:
kaf24@1452 272 printk("Unknown CPU identifier (%d): continuing anyway, "
kaf24@1452 273 "but might fail.\n", c->x86_vendor);
kaf24@1452 274 }
kaf24@1452 275
kaf24@1452 276 printk("CPU caps: %08x %08x %08x %08x\n",
kaf24@1452 277 c->x86_capability[0],
kaf24@1452 278 c->x86_capability[1],
kaf24@1452 279 c->x86_capability[2],
kaf24@1452 280 c->x86_capability[3]);
kaf24@1452 281
kaf24@1452 282 /*
kaf24@1452 283 * On SMP, boot_cpu_data holds the common feature set between
kaf24@1452 284 * all CPUs; so make sure that we indicate which features are
kaf24@1452 285 * common between the CPUs. The first time this routine gets
kaf24@1452 286 * executed, c == &boot_cpu_data.
kaf24@1452 287 */
kaf24@1452 288 if ( c != &boot_cpu_data ) {
kaf24@1452 289 /* AND the already accumulated flags with these */
kaf24@1452 290 for ( i = 0 ; i < NCAPINTS ; i++ )
kaf24@1452 291 boot_cpu_data.x86_capability[i] &= c->x86_capability[i];
kaf24@1452 292 }
kaf24@1452 293 }
kaf24@1452 294
kaf24@1452 295
kaf24@1452 296 unsigned long cpu_initialized;
kaf24@1452 297 void __init cpu_init(void)
kaf24@1452 298 {
kaf24@1452 299 int nr = smp_processor_id();
kaf24@3623 300 struct tss_struct *t = &init_tss[nr];
kaf24@4972 301 char gdt_load[10];
kaf24@1452 302
kaf24@1452 303 if ( test_and_set_bit(nr, &cpu_initialized) )
kaf24@1452 304 panic("CPU#%d already initialized!!!\n", nr);
kaf24@1452 305 printk("Initializing CPU#%d\n", nr);
kaf24@1452 306
kaf24@4972 307 *(unsigned short *)(&gdt_load[0]) = LAST_RESERVED_GDT_BYTE;
kaf24@4972 308 *(unsigned long *)(&gdt_load[2]) = GDT_VIRT_START(current);
kaf24@4972 309 __asm__ __volatile__ ( "lgdt %0" : "=m" (gdt_load) );
kaf24@1452 310
kaf24@1452 311 /* No nested task. */
kaf24@3623 312 __asm__ __volatile__ ( "pushf ; andw $0xbfff,(%"__OP"sp) ; popf" );
kaf24@1452 313
kaf24@1452 314 /* Ensure FPU gets initialised for each domain. */
kaf24@1452 315 stts();
kaf24@1452 316
kaf24@1452 317 /* Set up and load the per-CPU TSS and LDT. */
kaf24@3623 318 t->bitmap = IOBMP_INVALID_OFFSET;
kaf24@4950 319 #if defined(CONFIG_X86_32)
kaf24@1452 320 t->ss0 = __HYPERVISOR_DS;
kaf24@3761 321 t->esp0 = get_stack_bottom();
kaf24@4950 322 #elif defined(CONFIG_X86_64)
kaf24@4986 323 /* Bottom-of-stack must be 16-byte aligned or CPU will force it! :-o */
kaf24@4986 324 BUG_ON((get_stack_bottom() & 15) != 0);
kaf24@3761 325 t->rsp0 = get_stack_bottom();
kaf24@3623 326 #endif
kaf24@1452 327 set_tss_desc(nr,t);
kaf24@1452 328 load_TR(nr);
kaf24@3623 329 __asm__ __volatile__ ( "lldt %%ax" : : "a" (0) );
kaf24@1452 330
kaf24@1452 331 /* Clear all 6 debug registers. */
kaf24@3623 332 #define CD(register) __asm__ ( "mov %0,%%db" #register : : "r" (0UL) );
kaf24@1452 333 CD(0); CD(1); CD(2); CD(3); /* no db4 and db5 */; CD(6); CD(7);
kaf24@1452 334 #undef CD
kaf24@1452 335
kaf24@1452 336 /* Install correct page table. */
kaf24@3677 337 write_ptbase(current);
kaf24@1452 338
kaf24@1452 339 init_idle_task();
kaf24@1452 340 }
kaf24@1452 341
kaf24@4850 342 int acpi_force;
kaf24@4850 343 char acpi_param[10] = "";
kaf24@4850 344 static void parse_acpi_param(char *s)
kaf24@4850 345 {
kaf24@4850 346 /* Save the parameter so it can be propagated to domain0. */
kaf24@4850 347 strncpy(acpi_param, s, sizeof(acpi_param));
kaf24@4850 348 acpi_param[sizeof(acpi_param)-1] = '\0';
kaf24@4850 349
kaf24@4850 350 /* Interpret the parameter for use within Xen. */
kaf24@4850 351 if ( !strcmp(s, "off") )
kaf24@4850 352 {
kaf24@4850 353 disable_acpi();
kaf24@4850 354 }
kaf24@4850 355 else if ( !strcmp(s, "force") )
kaf24@4850 356 {
kaf24@4850 357 acpi_force = 1;
kaf24@4850 358 acpi_ht = 1;
kaf24@4850 359 acpi_disabled = 0;
kaf24@4850 360 }
kaf24@4850 361 else if ( !strcmp(s, "strict") )
kaf24@4850 362 {
kaf24@4850 363 acpi_strict = 1;
kaf24@4850 364 }
kaf24@4850 365 else if ( !strcmp(s, "ht") )
kaf24@4850 366 {
kaf24@4850 367 if ( !acpi_force )
kaf24@4850 368 disable_acpi();
kaf24@4850 369 acpi_ht = 1;
kaf24@4850 370 }
kaf24@4850 371 else if ( !strcmp(s, "noirq") )
kaf24@4850 372 {
kaf24@4850 373 acpi_noirq_set();
kaf24@4850 374 }
kaf24@4850 375 }
kaf24@4850 376
kaf24@1452 377 static void __init do_initcalls(void)
kaf24@1452 378 {
kaf24@1452 379 initcall_t *call;
kaf24@1452 380 for ( call = &__initcall_start; call < &__initcall_end; call++ )
kaf24@1452 381 (*call)();
kaf24@1452 382 }
kaf24@1452 383
kaf24@3338 384 static void __init start_of_day(void)
kaf24@1452 385 {
kaf24@1452 386 /* Unmap the first page of CPU0's stack. */
kaf24@3686 387 memguard_guard_stack(cpu0_stack);
kaf24@1452 388
kaf24@1505 389 open_softirq(NEW_TLBFLUSH_CLOCK_PERIOD_SOFTIRQ, new_tlbflush_clock_period);
kaf24@1452 390
kaf24@1452 391 if ( opt_watchdog )
kaf24@1452 392 nmi_watchdog = NMI_LOCAL_APIC;
kaf24@1452 393
kaf24@3120 394 sort_exception_tables();
kaf24@3120 395
kaf24@3272 396 arch_do_createdomain(current);
kaf24@4972 397
kaf24@4972 398 /* Map default GDT into their final position in the idle page table. */
kaf24@5003 399 map_pages_to_xen(
kaf24@4972 400 GDT_VIRT_START(current) + FIRST_RESERVED_GDT_BYTE,
kaf24@5004 401 virt_to_phys(gdt_table) >> PAGE_SHIFT, 1, PAGE_HYPERVISOR);
kaf24@3272 402
kaf24@4972 403 /* Process CPU type information. */
kaf24@4972 404 identify_cpu(&boot_cpu_data);
kaf24@4972 405 if ( cpu_has_fxsr )
kaf24@4972 406 set_in_cr4(X86_CR4_OSFXSR);
kaf24@4972 407 if ( cpu_has_xmm )
kaf24@4972 408 set_in_cr4(X86_CR4_OSXMMEXCPT);
kaf24@4850 409
kaf24@4850 410 find_smp_config();
kaf24@4850 411
kaf24@4850 412 smp_alloc_memory();
kaf24@4850 413
kaf24@4850 414 paging_init();
kaf24@4850 415
kaf24@4850 416 acpi_boot_table_init();
kaf24@4850 417 acpi_boot_init();
kaf24@4850 418
kaf24@1452 419 if ( smp_found_config )
kaf24@1452 420 get_smp_config();
kaf24@4850 421
kaf24@4850 422 init_apic_mappings();
kaf24@4850 423
kaf24@1452 424 scheduler_init();
kaf24@4850 425
kaf24@4850 426 init_IRQ();
kaf24@4850 427
kaf24@1452 428 trap_init();
kaf24@4850 429
kaf24@4850 430 time_init();
kaf24@1452 431
kaf24@2298 432 arch_init_memory();
kaf24@2298 433
kaf24@4850 434 smp_boot_cpus();
kaf24@1452 435
kaf24@1452 436 __sti();
kaf24@1452 437
kaf24@4850 438 initialize_keytable();
kaf24@1452 439
kaf24@1452 440 serial_init_stage2();
kaf24@1452 441
kaf24@1452 442 if ( !cpu_has_apic )
kaf24@1452 443 {
kaf24@1452 444 do_timer_lists_from_pit = 1;
kaf24@1452 445 if ( smp_num_cpus != 1 )
kaf24@1452 446 panic("We need local APICs on SMP machines!");
kaf24@1452 447 }
kaf24@1452 448
kaf24@1452 449 ac_timer_init(); /* init accurate timers */
kaf24@1452 450 init_xen_time(); /* initialise the time */
kaf24@1452 451 schedulers_start(); /* start scheduler for each CPU */
kaf24@1452 452
kaf24@1452 453 check_nmi_watchdog();
kaf24@1452 454
kaf24@1452 455 do_initcalls();
kaf24@1452 456
kaf24@1452 457 wait_init_idle = cpu_online_map;
kaf24@1452 458 clear_bit(smp_processor_id(), &wait_init_idle);
kaf24@1452 459 smp_threads_ready = 1;
kaf24@1452 460 smp_commence(); /* Tell other CPUs that state of the world is stable. */
kaf24@2344 461 while ( wait_init_idle != 0 )
kaf24@1452 462 cpu_relax();
kaf24@1452 463
kaf24@4926 464 watchdog_enable();
kaf24@4926 465
kaf24@4950 466 #ifdef CONFIG_X86_64 /* x86_32 uses low mappings when building DOM0. */
kaf24@3630 467 zap_low_mappings();
kaf24@3630 468 #endif
kaf24@1452 469 }
kaf24@3338 470
kaf24@5011 471 #define EARLY_FAIL() for ( ; ; ) __asm__ __volatile__ ( "hlt" )
kaf24@5011 472
kaf24@3338 473 void __init __start_xen(multiboot_info_t *mbi)
kaf24@3338 474 {
riel@3992 475 char *cmdline;
kaf24@3338 476 module_t *mod = (module_t *)__va(mbi->mods_addr);
kaf24@3354 477 unsigned long firsthole_start, nr_pages;
kaf24@3338 478 unsigned long initial_images_start, initial_images_end;
kaf24@3344 479 struct e820entry e820_raw[E820MAX];
kaf24@3354 480 int i, e820_raw_nr = 0, bytes = 0;
kaf24@3338 481
kaf24@3338 482 /* Parse the command-line options. */
kaf24@3344 483 if ( (mbi->flags & MBI_CMDLINE) && (mbi->cmdline != 0) )
kaf24@3344 484 cmdline_parse(__va(mbi->cmdline));
kaf24@3338 485
kaf24@3338 486 /* Must do this early -- e.g., spinlocks rely on get_current(). */
kaf24@3340 487 set_current(&idle0_exec_domain);
kaf24@4986 488 set_processor_id(0);
kaf24@3338 489
kaf24@3338 490 /* We initialise the serial devices very early so we can get debugging. */
kaf24@3338 491 serial_init_stage1();
kaf24@3338 492
kaf24@3338 493 init_console();
kaf24@3338 494
kaf24@3344 495 /* Check that we have at least one Multiboot module. */
kaf24@3344 496 if ( !(mbi->flags & MBI_MODULES) || (mbi->mods_count == 0) )
kaf24@3338 497 {
kaf24@3344 498 printk("FATAL ERROR: Require at least one Multiboot module.\n");
kaf24@5011 499 EARLY_FAIL();
kaf24@5011 500 }
kaf24@5011 501
kaf24@5011 502 if ( ((unsigned long)cpu0_stack & (STACK_SIZE-1)) != 0 )
kaf24@5011 503 {
kaf24@5011 504 printk("FATAL ERROR: Misaligned CPU0 stack.\n");
kaf24@5011 505 EARLY_FAIL();
kaf24@3338 506 }
kaf24@3338 507
kaf24@3338 508 xenheap_phys_end = opt_xenheap_megabytes << 20;
kaf24@3338 509
kaf24@3344 510 if ( mbi->flags & MBI_MEMMAP )
kaf24@3344 511 {
kaf24@3344 512 while ( bytes < mbi->mmap_length )
kaf24@3344 513 {
kaf24@3344 514 memory_map_t *map = __va(mbi->mmap_addr + bytes);
kaf24@3344 515 e820_raw[e820_raw_nr].addr =
kaf24@3344 516 ((u64)map->base_addr_high << 32) | (u64)map->base_addr_low;
kaf24@3344 517 e820_raw[e820_raw_nr].size =
kaf24@3344 518 ((u64)map->length_high << 32) | (u64)map->length_low;
kaf24@3344 519 e820_raw[e820_raw_nr].type =
kaf24@3346 520 (map->type > E820_SHARED_PAGE) ? E820_RESERVED : map->type;
kaf24@3344 521 e820_raw_nr++;
kaf24@3344 522 bytes += map->size + 4;
kaf24@3344 523 }
kaf24@3344 524 }
kaf24@3344 525 else if ( mbi->flags & MBI_MEMLIMITS )
kaf24@3344 526 {
kaf24@3344 527 e820_raw[0].addr = 0;
kaf24@3344 528 e820_raw[0].size = mbi->mem_lower << 10;
kaf24@3344 529 e820_raw[0].type = E820_RAM;
kaf24@3354 530 e820_raw[1].addr = 0x100000;
kaf24@3354 531 e820_raw[1].size = mbi->mem_upper << 10;
kaf24@3354 532 e820_raw[1].type = E820_RAM;
kaf24@3344 533 e820_raw_nr = 2;
kaf24@3344 534 }
kaf24@3344 535 else
kaf24@3344 536 {
kaf24@3344 537 printk("FATAL ERROR: Bootloader provided no memory information.\n");
kaf24@3344 538 for ( ; ; ) ;
kaf24@3344 539 }
kaf24@3344 540
kaf24@4950 541 max_page = init_e820(e820_raw, &e820_raw_nr);
kaf24@3338 542
kaf24@3354 543 /* Find the first high-memory RAM hole. */
kaf24@3354 544 for ( i = 0; i < e820.nr_map; i++ )
kaf24@3354 545 if ( (e820.map[i].type == E820_RAM) &&
kaf24@3354 546 (e820.map[i].addr >= 0x100000) )
kaf24@3354 547 break;
kaf24@3354 548 firsthole_start = e820.map[i].addr + e820.map[i].size;
kaf24@3338 549
kaf24@3354 550 /* Relocate the Multiboot modules. */
kaf24@3354 551 initial_images_start = xenheap_phys_end;
kaf24@3338 552 initial_images_end = initial_images_start +
kaf24@3338 553 (mod[mbi->mods_count-1].mod_end - mod[0].mod_start);
kaf24@3354 554 if ( initial_images_end > firsthole_start )
kaf24@3338 555 {
kaf24@3338 556 printk("Not enough memory to stash the DOM0 kernel image.\n");
kaf24@3338 557 for ( ; ; ) ;
kaf24@3338 558 }
kaf24@4950 559 #if defined(CONFIG_X86_32)
kaf24@3338 560 memmove((void *)initial_images_start, /* use low mapping */
kaf24@3338 561 (void *)mod[0].mod_start, /* use low mapping */
kaf24@3338 562 mod[mbi->mods_count-1].mod_end - mod[0].mod_start);
kaf24@4950 563 #elif defined(CONFIG_X86_64)
kaf24@3338 564 memmove(__va(initial_images_start),
kaf24@3338 565 __va(mod[0].mod_start),
kaf24@3338 566 mod[mbi->mods_count-1].mod_end - mod[0].mod_start);
kaf24@3338 567 #endif
kaf24@3338 568
kaf24@3354 569 /* Initialise boot-time allocator with all RAM situated after modules. */
kaf24@5003 570 xenheap_phys_start = init_boot_allocator(__pa(&_end));
kaf24@3354 571 nr_pages = 0;
kaf24@3354 572 for ( i = 0; i < e820.nr_map; i++ )
kaf24@3354 573 {
kaf24@3354 574 if ( e820.map[i].type != E820_RAM )
kaf24@3354 575 continue;
kaf24@3354 576 nr_pages += e820.map[i].size >> PAGE_SHIFT;
kaf24@3354 577 if ( (e820.map[i].addr + e820.map[i].size) >= initial_images_end )
kaf24@3354 578 init_boot_pages((e820.map[i].addr < initial_images_end) ?
kaf24@3354 579 initial_images_end : e820.map[i].addr,
kaf24@3354 580 e820.map[i].addr + e820.map[i].size);
kaf24@5003 581 #if defined (CONFIG_X86_64)
kaf24@5003 582 /*
kaf24@5003 583 * x86/64 maps all registered RAM. Points to note:
kaf24@5003 584 * 1. The initial pagetable already maps low 64MB, so skip that.
kaf24@5003 585 * 2. We must map *only* RAM areas, taking care to avoid I/O holes.
kaf24@5003 586 * Failure to do this can cause coherency problems and deadlocks
kaf24@5003 587 * due to cache-attribute mismatches (e.g., AMD/AGP Linux bug).
kaf24@5003 588 */
kaf24@5003 589 {
kaf24@5004 590 /* Calculate page-frame range, discarding partial frames. */
kaf24@5004 591 unsigned long start, end;
kaf24@5005 592 start = PFN_UP(e820.map[i].addr);
kaf24@5005 593 end = PFN_DOWN(e820.map[i].addr + e820.map[i].size);
kaf24@5004 594 /* Clip the range to above 64MB. */
kaf24@5004 595 if ( end < (64UL << (20-PAGE_SHIFT)) )
kaf24@5004 596 continue;
kaf24@5004 597 if ( start < (64UL << (20-PAGE_SHIFT)) )
kaf24@5004 598 start = 64UL << (20-PAGE_SHIFT);
kaf24@5004 599 /* Request the mapping. */
kaf24@5003 600 map_pages_to_xen(
kaf24@5004 601 PAGE_OFFSET + (start << PAGE_SHIFT),
kaf24@5004 602 start, end-start, PAGE_HYPERVISOR);
kaf24@5003 603 }
kaf24@5003 604 #endif
kaf24@3354 605 }
kaf24@3354 606
kaf24@5003 607 memguard_init();
kaf24@4950 608
kaf24@3354 609 printk("System RAM: %luMB (%lukB)\n",
kaf24@3354 610 nr_pages >> (20 - PAGE_SHIFT),
kaf24@3354 611 nr_pages << (PAGE_SHIFT - 10));
kaf24@3354 612
kaf24@3354 613 init_frametable();
kaf24@3338 614
kaf24@3354 615 end_boot_allocator();
kaf24@3354 616
kaf24@5003 617 init_xenheap_pages(xenheap_phys_start, xenheap_phys_end);
kaf24@3354 618 printk("Xen heap: %luMB (%lukB)\n",
kaf24@5003 619 (xenheap_phys_end-xenheap_phys_start) >> 20,
kaf24@5003 620 (xenheap_phys_end-xenheap_phys_start) >> 10);
kaf24@3338 621
kaf24@3594 622 early_boot = 0;
kaf24@3338 623
kaf24@3338 624 start_of_day();
kaf24@3338 625
kaf24@3338 626 grant_table_init();
kaf24@3338 627
kaf24@3338 628 shadow_mode_init();
kaf24@3338 629
kaf24@3338 630 /* Create initial domain 0. */
kaf24@3338 631 dom0 = do_createdomain(0, 0);
kaf24@3338 632 if ( dom0 == NULL )
kaf24@3338 633 panic("Error creating domain 0\n");
kaf24@3338 634
kaf24@4877 635 set_bit(_DOMF_privileged, &dom0->domain_flags);
kaf24@3338 636
kaf24@4850 637 /* Grab the DOM0 command line. */
riel@3992 638 cmdline = (char *)(mod[0].string ? __va(mod[0].string) : NULL);
kaf24@3338 639 if ( cmdline != NULL )
kaf24@3338 640 {
kaf24@4850 641 static char dom0_cmdline[256];
kaf24@4850 642
kaf24@4850 643 /* Skip past the image name. */
kaf24@3338 644 while ( *cmdline == ' ' ) cmdline++;
kaf24@3338 645 if ( (cmdline = strchr(cmdline, ' ')) != NULL )
kaf24@3338 646 while ( *cmdline == ' ' ) cmdline++;
kaf24@4850 647
kaf24@4850 648 /* Copy the command line to a local buffer. */
kaf24@4850 649 strcpy(dom0_cmdline, cmdline);
kaf24@4850 650 cmdline = dom0_cmdline;
kaf24@4850 651
kaf24@4850 652 /* Append any extra parameters. */
kaf24@4850 653 if ( skip_ioapic_setup && !strstr(cmdline, "noapic") )
kaf24@4850 654 strcat(cmdline, " noapic");
kaf24@4850 655 if ( acpi_skip_timer_override &&
kaf24@4850 656 !strstr(cmdline, "acpi_skip_timer_override") )
kaf24@4850 657 strcat(cmdline, " acpi_skip_timer_override");
kaf24@4850 658 if ( (strlen(acpi_param) != 0) && !strstr(cmdline, "acpi=") )
kaf24@4850 659 {
kaf24@4850 660 strcat(cmdline, " acpi=");
kaf24@4850 661 strcat(cmdline, acpi_param);
kaf24@4850 662 }
kaf24@4888 663 if ( !strstr(cmdline, "apic=") )
kaf24@4888 664 {
kaf24@4888 665 if ( apic_verbosity == APIC_VERBOSE )
kaf24@4888 666 strcat(cmdline, " apic=verbose");
kaf24@4888 667 else if ( apic_verbosity == APIC_DEBUG )
kaf24@4888 668 strcat(cmdline, " apic=debug");
kaf24@4888 669 }
kaf24@3338 670 }
kaf24@3338 671
kaf24@3338 672 /*
kaf24@3338 673 * We're going to setup domain0 using the module(s) that we stashed safely
kaf24@3338 674 * above our heap. The second module, if present, is an initrd ramdisk.
kaf24@3338 675 */
kaf24@3935 676 if ( construct_dom0(dom0,
kaf24@3635 677 initial_images_start,
kaf24@3338 678 mod[0].mod_end-mod[0].mod_start,
kaf24@3338 679 (mbi->mods_count == 1) ? 0 :
kaf24@3635 680 initial_images_start +
kaf24@3338 681 (mod[1].mod_start-mod[0].mod_start),
kaf24@3338 682 (mbi->mods_count == 1) ? 0 :
kaf24@3338 683 mod[mbi->mods_count-1].mod_end - mod[1].mod_start,
kaf24@3338 684 cmdline) != 0)
kaf24@3338 685 panic("Could not set up DOM0 guest OS\n");
kaf24@3338 686
kaf24@3935 687 /* Scrub RAM that is still free and so may go to an unprivileged domain. */
kaf24@3338 688 scrub_heap_pages();
kaf24@3338 689
kaf24@3338 690 init_trace_bufs();
kaf24@3338 691
kaf24@3338 692 /* Give up the VGA console if DOM0 is configured to grab it. */
kaf24@3338 693 console_endboot(cmdline && strstr(cmdline, "tty0"));
kaf24@3338 694
iap10@4287 695 /* Hide UART from DOM0 if we're using it */
iap10@4287 696 serial_endboot();
iap10@4287 697
kaf24@3340 698 domain_unpause_by_systemcontroller(current->domain);
kaf24@3338 699 domain_unpause_by_systemcontroller(dom0);
kaf24@3338 700 startup_cpu_idle_loop();
kaf24@3338 701 }
kaf24@3914 702
kaf24@3914 703 /*
kaf24@3914 704 * Local variables:
kaf24@3914 705 * mode: C
kaf24@3914 706 * c-set-style: "BSD"
kaf24@3914 707 * c-basic-offset: 4
kaf24@3914 708 * tab-width: 4
kaf24@3914 709 * indent-tabs-mode: nil
kaf24@3988 710 * End:
kaf24@3914 711 */