]> git.saurik.com Git - apple/xnu.git/blob - osfmk/i386/i386_init.c
73a30a22b93b387fb33ccc94a0bdef13df3316db
[apple/xnu.git] / osfmk / i386 / i386_init.c
1 /*
2 * Copyright (c) 2003-2016 Apple Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28 /*
29 * @OSF_COPYRIGHT@
30 */
31 /*
32 * Mach Operating System
33 * Copyright (c) 1991,1990,1989, 1988 Carnegie Mellon University
34 * All Rights Reserved.
35 *
36 * Permission to use, copy, modify and distribute this software and its
37 * documentation is hereby granted, provided that both the copyright
38 * notice and this permission notice appear in all copies of the
39 * software, derivative works or modified versions, and any portions
40 * thereof, and that both notices appear in supporting documentation.
41 *
42 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
43 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
44 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
45 *
46 * Carnegie Mellon requests users of this software to return to
47 *
48 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
49 * School of Computer Science
50 * Carnegie Mellon University
51 * Pittsburgh PA 15213-3890
52 *
53 * any improvements or extensions that they make and grant Carnegie Mellon
54 * the rights to redistribute these changes.
55 */
56
57
58 #include <mach/i386/vm_param.h>
59
60 #include <string.h>
61 #include <mach/vm_param.h>
62 #include <mach/vm_prot.h>
63 #include <mach/machine.h>
64 #include <mach/time_value.h>
65 #include <kern/spl.h>
66 #include <kern/assert.h>
67 #include <kern/debug.h>
68 #include <kern/misc_protos.h>
69 #include <kern/startup.h>
70 #include <kern/clock.h>
71 #include <kern/pms.h>
72 #include <kern/xpr.h>
73 #include <kern/cpu_data.h>
74 #include <kern/processor.h>
75 #include <sys/kdebug.h>
76 #include <console/serial_protos.h>
77 #include <vm/vm_page.h>
78 #include <vm/pmap.h>
79 #include <vm/vm_kern.h>
80 #include <machine/pal_routines.h>
81 #include <i386/fpu.h>
82 #include <i386/pmap.h>
83 #include <i386/misc_protos.h>
84 #include <i386/cpu_threads.h>
85 #include <i386/cpuid.h>
86 #include <i386/lapic.h>
87 #include <i386/mp.h>
88 #include <i386/mp_desc.h>
89 #if CONFIG_MTRR
90 #include <i386/mtrr.h>
91 #endif
92 #include <i386/machine_routines.h>
93 #if CONFIG_MCA
94 #include <i386/machine_check.h>
95 #endif
96 #include <i386/ucode.h>
97 #include <i386/postcode.h>
98 #include <i386/Diagnostics.h>
99 #include <i386/pmCPU.h>
100 #include <i386/tsc.h>
101 #include <i386/locks.h> /* LcksOpts */
102 #if DEBUG
103 #include <machine/pal_routines.h>
104 #endif
105
106 #if MONOTONIC
107 #include <kern/monotonic.h>
108 #endif /* MONOTONIC */
109
110 #include <san/kasan.h>
111
112 #if DEBUG
113 #define DBG(x...) kprintf(x)
114 #else
115 #define DBG(x...)
116 #endif
117
118 int debug_task;
119
120 static boot_args *kernelBootArgs;
121
122 extern int disableConsoleOutput;
123 extern const char version[];
124 extern const char version_variant[];
125 extern int nx_enabled;
126
127 /*
128 * Set initial values so that ml_phys_* routines can use the booter's ID mapping
129 * to touch physical space before the kernel's physical aperture exists.
130 */
131 uint64_t physmap_base = 0;
132 uint64_t physmap_max = 4*GB;
133
134 pd_entry_t *KPTphys;
135 pd_entry_t *IdlePTD;
136 pdpt_entry_t *IdlePDPT;
137 pml4_entry_t *IdlePML4;
138
139 char *physfree;
140
141 /*
142 * Note: ALLOCPAGES() can only be used safely within Idle_PTs_init()
143 * due to the mutation of physfree.
144 */
145 static void *
146 ALLOCPAGES(int npages)
147 {
148 uintptr_t tmp = (uintptr_t)physfree;
149 bzero(physfree, npages * PAGE_SIZE);
150 physfree += npages * PAGE_SIZE;
151 tmp += VM_MIN_KERNEL_ADDRESS & ~LOW_4GB_MASK;
152 return (void *)tmp;
153 }
154
155 static void
156 fillkpt(pt_entry_t *base, int prot, uintptr_t src, int index, int count)
157 {
158 int i;
159 for (i=0; i<count; i++) {
160 base[index] = src | prot | INTEL_PTE_VALID;
161 src += PAGE_SIZE;
162 index++;
163 }
164 }
165
166 extern pmap_paddr_t first_avail;
167
168 int break_kprintf = 0;
169
170 uint64_t
171 x86_64_pre_sleep(void)
172 {
173 IdlePML4[0] = IdlePML4[KERNEL_PML4_INDEX];
174 uint64_t oldcr3 = get_cr3_raw();
175 set_cr3_raw((uint32_t) (uintptr_t)ID_MAP_VTOP(IdlePML4));
176 return oldcr3;
177 }
178
179 void
180 x86_64_post_sleep(uint64_t new_cr3)
181 {
182 IdlePML4[0] = 0;
183 set_cr3_raw((uint32_t) new_cr3);
184 }
185
186
187
188
189 // Set up the physical mapping - NPHYSMAP GB of memory mapped at a high address
190 // NPHYSMAP is determined by the maximum supported RAM size plus 4GB to account
191 // the PCI hole (which is less 4GB but not more).
192
193 /* Compile-time guard: NPHYSMAP is capped to 256GiB, accounting for
194 * randomisation
195 */
196 extern int maxphymapsupported[NPHYSMAP <= (PTE_PER_PAGE/2) ? 1 : -1];
197
198 static void
199 physmap_init(void)
200 {
201 pt_entry_t *physmapL3 = ALLOCPAGES(1);
202 struct {
203 pt_entry_t entries[PTE_PER_PAGE];
204 } * physmapL2 = ALLOCPAGES(NPHYSMAP);
205
206 uint64_t i;
207 uint8_t phys_random_L3 = early_random() & 0xFF;
208
209 /* We assume NX support. Mark all levels of the PHYSMAP NX
210 * to avoid granting executability via a single bit flip.
211 */
212 #if DEVELOPMENT || DEBUG
213 uint32_t reg[4];
214 do_cpuid(0x80000000, reg);
215 if (reg[eax] >= 0x80000001) {
216 do_cpuid(0x80000001, reg);
217 assert(reg[edx] & CPUID_EXTFEATURE_XD);
218 }
219 #endif /* DEVELOPMENT || DEBUG */
220
221 for(i = 0; i < NPHYSMAP; i++) {
222 physmapL3[i + phys_random_L3] =
223 ((uintptr_t)ID_MAP_VTOP(&physmapL2[i]))
224 | INTEL_PTE_VALID
225 | INTEL_PTE_NX
226 | INTEL_PTE_WRITE;
227
228 uint64_t j;
229 for(j = 0; j < PTE_PER_PAGE; j++) {
230 physmapL2[i].entries[j] =
231 ((i * PTE_PER_PAGE + j) << PDSHIFT)
232 | INTEL_PTE_PS
233 | INTEL_PTE_VALID
234 | INTEL_PTE_NX
235 | INTEL_PTE_WRITE;
236 }
237 }
238
239 IdlePML4[KERNEL_PHYSMAP_PML4_INDEX] =
240 ((uintptr_t)ID_MAP_VTOP(physmapL3))
241 | INTEL_PTE_VALID
242 | INTEL_PTE_NX
243 | INTEL_PTE_WRITE;
244
245 physmap_base = KVADDR(KERNEL_PHYSMAP_PML4_INDEX, phys_random_L3, 0, 0);
246 physmap_max = physmap_base + NPHYSMAP * GB;
247 DBG("Physical address map base: 0x%qx\n", physmap_base);
248 DBG("Physical map idlepml4[%d]: 0x%llx\n",
249 KERNEL_PHYSMAP_PML4_INDEX, IdlePML4[KERNEL_PHYSMAP_PML4_INDEX]);
250 }
251
252 static void
253 descriptor_alias_init()
254 {
255 vm_offset_t master_gdt_phys;
256 vm_offset_t master_gdt_alias_phys;
257 vm_offset_t master_idt_phys;
258 vm_offset_t master_idt_alias_phys;
259
260 assert(((vm_offset_t)master_gdt & PAGE_MASK) == 0);
261 assert(((vm_offset_t)master_idt64 & PAGE_MASK) == 0);
262
263 master_gdt_phys = (vm_offset_t) ID_MAP_VTOP(master_gdt);
264 master_idt_phys = (vm_offset_t) ID_MAP_VTOP(master_idt64);
265 master_gdt_alias_phys = (vm_offset_t) ID_MAP_VTOP(MASTER_GDT_ALIAS);
266 master_idt_alias_phys = (vm_offset_t) ID_MAP_VTOP(MASTER_IDT_ALIAS);
267
268 DBG("master_gdt_phys: %p\n", (void *) master_gdt_phys);
269 DBG("master_idt_phys: %p\n", (void *) master_idt_phys);
270 DBG("master_gdt_alias_phys: %p\n", (void *) master_gdt_alias_phys);
271 DBG("master_idt_alias_phys: %p\n", (void *) master_idt_alias_phys);
272
273 KPTphys[atop_kernel(master_gdt_alias_phys)] = master_gdt_phys |
274 INTEL_PTE_VALID | INTEL_PTE_NX | INTEL_PTE_WRITE;
275 KPTphys[atop_kernel(master_idt_alias_phys)] = master_idt_phys |
276 INTEL_PTE_VALID | INTEL_PTE_NX; /* read-only */
277 }
278
279 static void
280 Idle_PTs_init(void)
281 {
282 /* Allocate the "idle" kernel page tables: */
283 KPTphys = ALLOCPAGES(NKPT); /* level 1 */
284 IdlePTD = ALLOCPAGES(NPGPTD); /* level 2 */
285 IdlePDPT = ALLOCPAGES(1); /* level 3 */
286 IdlePML4 = ALLOCPAGES(1); /* level 4 */
287
288 // Fill the lowest level with everything up to physfree
289 fillkpt(KPTphys,
290 INTEL_PTE_WRITE, 0, 0, (int)(((uintptr_t)physfree) >> PAGE_SHIFT));
291
292 /* IdlePTD */
293 fillkpt(IdlePTD,
294 INTEL_PTE_WRITE, (uintptr_t)ID_MAP_VTOP(KPTphys), 0, NKPT);
295
296 // IdlePDPT entries
297 fillkpt(IdlePDPT,
298 INTEL_PTE_WRITE, (uintptr_t)ID_MAP_VTOP(IdlePTD), 0, NPGPTD);
299
300 // IdlePML4 single entry for kernel space.
301 fillkpt(IdlePML4 + KERNEL_PML4_INDEX,
302 INTEL_PTE_WRITE, (uintptr_t)ID_MAP_VTOP(IdlePDPT), 0, 1);
303
304 postcode(VSTART_PHYSMAP_INIT);
305
306 physmap_init();
307
308 postcode(VSTART_DESC_ALIAS_INIT);
309
310 descriptor_alias_init();
311
312 postcode(VSTART_SET_CR3);
313
314 // Switch to the page tables..
315 set_cr3_raw((uintptr_t)ID_MAP_VTOP(IdlePML4));
316
317 }
318
319 extern void vstart_trap_handler;
320
321 #define BOOT_TRAP_VECTOR(t) \
322 [t] = { \
323 (uintptr_t) &vstart_trap_handler, \
324 KERNEL64_CS, \
325 0, \
326 ACC_P|ACC_PL_K|ACC_INTR_GATE, \
327 0 \
328 },
329
330 /* Recursive macro to iterate 0..31 */
331 #define L0(x,n) x(n)
332 #define L1(x,n) L0(x,n-1) L0(x,n)
333 #define L2(x,n) L1(x,n-2) L1(x,n)
334 #define L3(x,n) L2(x,n-4) L2(x,n)
335 #define L4(x,n) L3(x,n-8) L3(x,n)
336 #define L5(x,n) L4(x,n-16) L4(x,n)
337 #define FOR_0_TO_31(x) L5(x,31)
338
339 /*
340 * Bootstrap IDT. Active only during early startup.
341 * Only the trap vectors are defined since interrupts are masked.
342 * All traps point to a common handler.
343 */
344 struct fake_descriptor64 master_boot_idt64[IDTSZ]
345 __attribute__((section("__HIB,__desc")))
346 __attribute__((aligned(PAGE_SIZE))) = {
347 FOR_0_TO_31(BOOT_TRAP_VECTOR)
348 };
349
350 static void
351 vstart_idt_init(void)
352 {
353 x86_64_desc_register_t vstart_idt = {
354 sizeof(master_boot_idt64),
355 master_boot_idt64 };
356
357 fix_desc64(master_boot_idt64, 32);
358 lidt((void *)&vstart_idt);
359 }
360
361 /*
362 * vstart() is called in the natural mode (64bit for K64, 32 for K32)
363 * on a set of bootstrap pagetables which use large, 2MB pages to map
364 * all of physical memory in both. See idle_pt.c for details.
365 *
366 * In K64 this identity mapping is mirrored the top and bottom 512GB
367 * slots of PML4.
368 *
369 * The bootstrap processor called with argument boot_args_start pointing to
370 * the boot-args block. The kernel's (4K page) page tables are allocated and
371 * initialized before switching to these.
372 *
373 * Non-bootstrap processors are called with argument boot_args_start NULL.
374 * These processors switch immediately to the existing kernel page tables.
375 */
376 __attribute__((noreturn))
377 void
378 vstart(vm_offset_t boot_args_start)
379 {
380 boolean_t is_boot_cpu = !(boot_args_start == 0);
381 int cpu = 0;
382 uint32_t lphysfree;
383
384 postcode(VSTART_ENTRY);
385
386 if (is_boot_cpu) {
387 /*
388 * Set-up temporary trap handlers during page-table set-up.
389 */
390 vstart_idt_init();
391 postcode(VSTART_IDT_INIT);
392
393 /*
394 * Get startup parameters.
395 */
396 kernelBootArgs = (boot_args *)boot_args_start;
397 lphysfree = kernelBootArgs->kaddr + kernelBootArgs->ksize;
398 physfree = (void *)(uintptr_t)((lphysfree + PAGE_SIZE - 1) &~ (PAGE_SIZE - 1));
399
400 #if DEVELOPMENT || DEBUG
401 pal_serial_init();
402 #endif
403 DBG("revision 0x%x\n", kernelBootArgs->Revision);
404 DBG("version 0x%x\n", kernelBootArgs->Version);
405 DBG("command line %s\n", kernelBootArgs->CommandLine);
406 DBG("memory map 0x%x\n", kernelBootArgs->MemoryMap);
407 DBG("memory map sz 0x%x\n", kernelBootArgs->MemoryMapSize);
408 DBG("kaddr 0x%x\n", kernelBootArgs->kaddr);
409 DBG("ksize 0x%x\n", kernelBootArgs->ksize);
410 DBG("physfree %p\n", physfree);
411 DBG("bootargs: %p, &ksize: %p &kaddr: %p\n",
412 kernelBootArgs,
413 &kernelBootArgs->ksize,
414 &kernelBootArgs->kaddr);
415 DBG("SMBIOS mem sz 0x%llx\n", kernelBootArgs->PhysicalMemorySize);
416
417 /*
418 * Setup boot args given the physical start address.
419 * Note: PE_init_platform needs to be called before Idle_PTs_init
420 * because access to the DeviceTree is required to read the
421 * random seed before generating a random physical map slide.
422 */
423 kernelBootArgs = (boot_args *)
424 ml_static_ptovirt(boot_args_start);
425 DBG("i386_init(0x%lx) kernelBootArgs=%p\n",
426 (unsigned long)boot_args_start, kernelBootArgs);
427
428 #if KASAN
429 kasan_reserve_memory(kernelBootArgs);
430 #endif
431
432 PE_init_platform(FALSE, kernelBootArgs);
433 postcode(PE_INIT_PLATFORM_D);
434
435 Idle_PTs_init();
436 postcode(VSTART_IDLE_PTS_INIT);
437
438 #if KASAN
439 /* Init kasan and map whatever was stolen from physfree */
440 kasan_init();
441 kasan_notify_stolen((uintptr_t)ml_static_ptovirt((vm_offset_t)physfree));
442 #endif
443
444 #if MONOTONIC
445 mt_init();
446 #endif /* MONOTONIC */
447
448 first_avail = (vm_offset_t)ID_MAP_VTOP(physfree);
449
450 cpu_data_alloc(TRUE);
451
452 cpu_desc_init(cpu_datap(0));
453 postcode(VSTART_CPU_DESC_INIT);
454 cpu_desc_load(cpu_datap(0));
455
456 postcode(VSTART_CPU_MODE_INIT);
457 cpu_syscall_init(cpu_datap(0)); /* cpu_syscall_init() will be
458 * invoked on the APs
459 * via i386_init_slave()
460 */
461 } else {
462 /* Switch to kernel's page tables (from the Boot PTs) */
463 set_cr3_raw((uintptr_t)ID_MAP_VTOP(IdlePML4));
464 /* Find our logical cpu number */
465 cpu = lapic_to_cpu[(LAPIC_READ(ID)>>LAPIC_ID_SHIFT) & LAPIC_ID_MASK];
466 DBG("CPU: %d, GSBASE initial value: 0x%llx\n", cpu, rdmsr64(MSR_IA32_GS_BASE));
467 cpu_desc_load(cpu_datap(cpu));
468 }
469
470 postcode(VSTART_EXIT);
471 x86_init_wrapper(is_boot_cpu ? (uintptr_t) i386_init
472 : (uintptr_t) i386_init_slave,
473 cpu_datap(cpu)->cpu_int_stack_top);
474 }
475
476 void
477 pstate_trace(void)
478 {
479 }
480
481 /*
482 * Cpu initialization. Running virtual, but without MACH VM
483 * set up.
484 */
485 void
486 i386_init(void)
487 {
488 unsigned int maxmem;
489 uint64_t maxmemtouse;
490 unsigned int cpus = 0;
491 boolean_t fidn;
492 boolean_t IA32e = TRUE;
493
494 postcode(I386_INIT_ENTRY);
495
496 pal_i386_init();
497 tsc_init();
498 rtclock_early_init(); /* mach_absolute_time() now functionsl */
499
500 kernel_debug_string_early("i386_init");
501 pstate_trace();
502
503 #if CONFIG_MCA
504 /* Initialize machine-check handling */
505 mca_cpu_init();
506 #endif
507
508 master_cpu = 0;
509 cpu_init();
510
511 postcode(CPU_INIT_D);
512
513 printf_init(); /* Init this in case we need debugger */
514 panic_init(); /* Init this in case we need debugger */
515
516 /* setup debugging output if one has been chosen */
517 kernel_debug_string_early("PE_init_kprintf");
518 PE_init_kprintf(FALSE);
519
520 kernel_debug_string_early("kernel_early_bootstrap");
521 kernel_early_bootstrap();
522
523 if (!PE_parse_boot_argn("diag", &dgWork.dgFlags, sizeof (dgWork.dgFlags)))
524 dgWork.dgFlags = 0;
525
526 serialmode = 0;
527 if (PE_parse_boot_argn("serial", &serialmode, sizeof(serialmode))) {
528 /* We want a serial keyboard and/or console */
529 kprintf("Serial mode specified: %08X\n", serialmode);
530 int force_sync = serialmode & SERIALMODE_SYNCDRAIN;
531 if (force_sync || PE_parse_boot_argn("drain_uart_sync", &force_sync, sizeof(force_sync))) {
532 if (force_sync) {
533 serialmode |= SERIALMODE_SYNCDRAIN;
534 kprintf(
535 "WARNING: Forcing uart driver to output synchronously."
536 "printf()s/IOLogs will impact kernel performance.\n"
537 "You are advised to avoid using 'drain_uart_sync' boot-arg.\n");
538 }
539 }
540 }
541 if (serialmode & SERIALMODE_OUTPUT) {
542 (void)switch_to_serial_console();
543 disableConsoleOutput = FALSE; /* Allow printfs to happen */
544 }
545
546 /* setup console output */
547 kernel_debug_string_early("PE_init_printf");
548 PE_init_printf(FALSE);
549
550 kprintf("version_variant = %s\n", version_variant);
551 kprintf("version = %s\n", version);
552
553 if (!PE_parse_boot_argn("maxmem", &maxmem, sizeof (maxmem)))
554 maxmemtouse = 0;
555 else
556 maxmemtouse = ((uint64_t)maxmem) * MB;
557
558 if (PE_parse_boot_argn("cpus", &cpus, sizeof (cpus))) {
559 if ((0 < cpus) && (cpus < max_ncpus))
560 max_ncpus = cpus;
561 }
562
563 /*
564 * debug support for > 4G systems
565 */
566 PE_parse_boot_argn("himemory_mode", &vm_himemory_mode, sizeof (vm_himemory_mode));
567 if (vm_himemory_mode != 0)
568 kprintf("himemory_mode: %d\n", vm_himemory_mode);
569
570 if (!PE_parse_boot_argn("immediate_NMI", &fidn, sizeof (fidn)))
571 force_immediate_debugger_NMI = FALSE;
572 else
573 force_immediate_debugger_NMI = fidn;
574
575 #if DEBUG
576 nanoseconds_to_absolutetime(URGENCY_NOTIFICATION_ASSERT_NS, &urgency_notification_assert_abstime_threshold);
577 #endif
578 PE_parse_boot_argn("urgency_notification_abstime",
579 &urgency_notification_assert_abstime_threshold,
580 sizeof(urgency_notification_assert_abstime_threshold));
581
582 if (!(cpuid_extfeatures() & CPUID_EXTFEATURE_XD))
583 nx_enabled = 0;
584
585 /*
586 * VM initialization, after this we're using page tables...
587 * Thn maximum number of cpus must be set beforehand.
588 */
589 kernel_debug_string_early("i386_vm_init");
590 i386_vm_init(maxmemtouse, IA32e, kernelBootArgs);
591
592 /* create the console for verbose or pretty mode */
593 /* Note: doing this prior to tsc_init() allows for graceful panic! */
594 PE_init_platform(TRUE, kernelBootArgs);
595 PE_create_console();
596
597 kernel_debug_string_early("power_management_init");
598 power_management_init();
599 processor_bootstrap();
600 thread_bootstrap();
601
602 pstate_trace();
603 kernel_debug_string_early("machine_startup");
604 machine_startup();
605 pstate_trace();
606 }
607
608 static void
609 do_init_slave(boolean_t fast_restart)
610 {
611 void *init_param = FULL_SLAVE_INIT;
612
613 postcode(I386_INIT_SLAVE);
614
615 if (!fast_restart) {
616 /* Ensure that caching and write-through are enabled */
617 set_cr0(get_cr0() & ~(CR0_NW|CR0_CD));
618
619 DBG("i386_init_slave() CPU%d: phys (%d) active.\n",
620 get_cpu_number(), get_cpu_phys_number());
621
622 assert(!ml_get_interrupts_enabled());
623
624 cpu_syscall_init(current_cpu_datap());
625 pmap_cpu_init();
626
627 #if CONFIG_MCA
628 mca_cpu_init();
629 #endif
630
631 LAPIC_INIT();
632 lapic_configure();
633 LAPIC_DUMP();
634 LAPIC_CPU_MAP_DUMP();
635
636 init_fpu();
637
638 #if CONFIG_MTRR
639 mtrr_update_cpu();
640 #endif
641 /* update CPU microcode */
642 ucode_update_wake();
643 } else
644 init_param = FAST_SLAVE_INIT;
645
646 #if CONFIG_VMX
647 /* resume VT operation */
648 vmx_resume(FALSE);
649 #endif
650
651 #if CONFIG_MTRR
652 if (!fast_restart)
653 pat_init();
654 #endif
655
656 cpu_thread_init(); /* not strictly necessary */
657
658 cpu_init(); /* Sets cpu_running which starter cpu waits for */
659 slave_main(init_param);
660
661 panic("do_init_slave() returned from slave_main()");
662 }
663
664 /*
665 * i386_init_slave() is called from pstart.
666 * We're in the cpu's interrupt stack with interrupts disabled.
667 * At this point we are in legacy mode. We need to switch on IA32e
668 * if the mode is set to 64-bits.
669 */
670 void
671 i386_init_slave(void)
672 {
673 do_init_slave(FALSE);
674 }
675
676 /*
677 * i386_init_slave_fast() is called from pmCPUHalt.
678 * We're running on the idle thread and need to fix up
679 * some accounting and get it so that the scheduler sees this
680 * CPU again.
681 */
682 void
683 i386_init_slave_fast(void)
684 {
685 do_init_slave(TRUE);
686 }
687
688