- current_cpu_datap()->cpu_hibernate = 0;
- did_hibernate = TRUE;
-
- } else {
- did_hibernate = FALSE;
- }
-
- /* Re-enable 64-bit mode if necessary. */
- if (cpu_mode_is64bit()) {
- cpu_IA32e_enable(current_cpu_datap());
- cpu_desc_load64(current_cpu_datap());
- kprintf("acpi_sleep_kernel 64-bit mode re-enabled\n");
- fast_syscall_init64();
- } else {
- fast_syscall_init();
- }
-
- /* restore MTRR settings */
- mtrr_update_cpu();
-
- /* set up PAT following boot processor power up */
- pat_init();
-
- if (did_hibernate) {
- hibernate_machine_init();
- }
-
- /* re-enable and re-init local apic */
- if (lapic_probe())
- lapic_init();
-
- /* Restore HPET state */
- hpet_restore();
-
- /* let the realtime clock reset */
- rtc_sleep_wakeup();
-
- fpinit();
- clear_fpu();
-
- if (did_hibernate) {
- enable_preemption();
- }
+
+ /* Re-enable mode (including 64-bit if applicable) */
+ cpu_mode_init(current_cpu_datap());
+
+#if CONFIG_MCA
+ /* Re-enable machine check handling */
+ mca_cpu_init();
+#endif
+
+#if CONFIG_MTRR
+ /* restore MTRR settings */
+ mtrr_update_cpu();
+#endif
+
+ /* update CPU microcode */
+ ucode_update_wake();
+
+#if CONFIG_VMX
+ /*
+ * Restore VT mode
+ */
+ vmx_resume();
+#endif
+
+#if CONFIG_MTRR
+ /* set up PAT following boot processor power up */
+ pat_init();
+#endif
+
+ /*
+ * Go through all of the CPUs and mark them as requiring
+ * a full restart.
+ */
+ pmMarkAllCPUsOff();
+
+ ml_get_timebase(&now);
+
+ /* re-enable and re-init local apic (prior to starting timers) */
+ if (lapic_probe())
+ lapic_configure();
+
+ /* let the realtime clock reset */
+ rtc_sleep_wakeup(acpi_sleep_abstime);
+
+ kdebug_enable = save_kdebug_enable;
+
+ if (did_hibernate) {
+
+ my_tsc = (now >> 32) | (now << 32);
+ my_abs = tmrCvt(my_tsc, tscFCvtt2n);
+
+ KERNEL_DEBUG_CONSTANT(IOKDBG_CODE(DBG_HIBERNATE, 2) | DBG_FUNC_START,
+ (uint32_t)(my_abs >> 32), (uint32_t)my_abs, 0, 0, 0);
+ hibernate_machine_init();
+ KERNEL_DEBUG_CONSTANT(IOKDBG_CODE(DBG_HIBERNATE, 2) | DBG_FUNC_END, 0, 0, 0, 0, 0);
+
+ current_cpu_datap()->cpu_hibernate = 0;
+
+ KERNEL_DEBUG_CONSTANT(IOKDBG_CODE(DBG_HIBERNATE, 0) | DBG_FUNC_END, 0, 0, 0, 0, 0);
+ } else
+ KERNEL_DEBUG_CONSTANT(IOKDBG_CODE(DBG_HIBERNATE, 0) | DBG_FUNC_END, 0, 0, 0, 0, 0);
+
+ /* Restore power management register state */
+ pmCPUMarkRunning(current_cpu_datap());
+
+ /* Restore power management timer state */
+ pmTimerRestore();
+
+ /* Restart timer interrupts */
+ rtc_timer_start();
+
+ /* Reconfigure FP/SIMD unit */
+ init_fpu();
+
+#if HIBERNATION
+#ifdef __i386__
+ /* The image is written out using the copy engine, which disables
+ * preemption. Since the copy engine writes out the page which contains
+ * the preemption variable when it is disabled, we need to explicitly
+ * enable it here */
+ if (did_hibernate)
+ enable_preemption();
+#endif
+
+ kprintf("ret from acpi_sleep_cpu hib=%d\n", did_hibernate);
+#endif
+
+#if CONFIG_SLEEP
+ /* Becase we don't save the bootstrap page, and we share it
+ * between sleep and mp slave init, we need to recreate it
+ * after coming back from sleep or hibernate */
+ install_real_mode_bootstrap(slave_pstart);
+#endif
+}
+
+extern char real_mode_bootstrap_end[];
+extern char real_mode_bootstrap_base[];
+
+void
+install_real_mode_bootstrap(void *prot_entry)
+{
+ /*
+ * Copy the boot entry code to the real-mode vector area REAL_MODE_BOOTSTRAP_OFFSET.
+ * This is in page 1 which has been reserved for this purpose by
+ * machine_startup() from the boot processor.
+ * The slave boot code is responsible for switching to protected
+ * mode and then jumping to the common startup, _start().
+ */
+ bcopy_phys(kvtophys((vm_offset_t) real_mode_bootstrap_base),
+ (addr64_t) REAL_MODE_BOOTSTRAP_OFFSET,
+ real_mode_bootstrap_end-real_mode_bootstrap_base);
+
+ /*
+ * Set the location at the base of the stack to point to the
+ * common startup entry.
+ */
+ ml_phys_write_word(
+ PROT_MODE_START+REAL_MODE_BOOTSTRAP_OFFSET,
+ (unsigned int)kvtophys((vm_offset_t)prot_entry));
+
+ /* Flush caches */
+ __asm__("wbinvd");