2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_OSREFERENCE_HEADER_START@
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
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
32 #include <i386/proc_reg.h>
33 #include <i386/postcode.h>
34 #include <i386/acpi.h>
40 .align 12 /* Page align for single bcopy_phys() */
42 #define LJMP(segment, address) \
44 .long address - EXT(acpi_wake_start) ;\
47 #define PA(addr) (addr)
52 * The code from acpi_wake_start to acpi_wake_end is copied to
53 * memory below 1MB. The firmware waking vector is updated to
54 * point at acpi_wake_start in low memory before sleeping.
57 ENTRY(acpi_wake_start)
59 * CPU woke up from sleep, and is back in real mode.
60 * Initialize it just enough to get back to protected mode.
64 POSTCODE(ACPI_WAKE_START_ENTRY)
66 /* set up DS to match CS */
71 * Must initialize GDTR before entering protected mode.
72 * Use a temporary GDT that is 0 based, 4GB limit, code and data.
73 * Restoring the actual GDT will come later.
77 lgdt EXT(acpi_gdtr) - EXT(acpi_wake_start)
79 /* set CR0.PE to enter protected mode */
86 * Make intra-segment jump to flush pipeline and reload CS register.
87 * If GDT is bogus, it will blow up here.
90 LJMP(0x8, acpi_wake_prot + ACPI_WAKE_ADDR)
94 /* protected mode, paging disabled */
96 /* setup the protected mode segment registers */
104 /* jump back to the sleep function in the kernel */
105 movl PA(saved_eip), %eax
108 /* Segment Descriptor
111 * ------------------------------------------------------------
112 * | | |B| |A| | | |1|0|E|W|A| |
113 * | BASE 31..24 |G|/|0|V| LIMIT |P|DPL| TYPE | BASE 23:16 |
114 * | | |D| |L| 19..16| | |1|1|C|R|A| |
115 * ------------------------------------------------------------
117 * | BASE 15..0 | LIMIT 15..0 |
119 * ------------------------------------------------------------
122 .word 0, 0 /* 0x0 : null */
125 .word 0xffff, 0x0000 /* 0x8 : code */
126 .byte 0, 0x9e, 0xcf, 0
128 .word 0xffff, 0x0000 /* 0x10 : data */
129 .byte 0, 0x92, 0xcf, 0
132 .word 24 /* limit (8*3 segs) */
133 .long EXT(acpi_gdt) - EXT(acpi_wake_start) + ACPI_WAKE_ADDR
139 * acpi_sleep_cpu(acpi_sleep_callback func, void * refcon)
141 * Save CPU state before platform sleep. Restore CPU state
145 ENTRY(acpi_sleep_cpu)
152 /* save general purpose registers */
156 /* make sure tlb is flushed */
160 /* save control registers */
170 /* save segment registers */
176 /* save descriptor table registers */
183 * When system wakes up, the real mode wake handler will revert to
184 * protected mode, then jump to the address stored at saved_eip.
186 movl $(PA(wake_prot)), saved_eip
189 * Call ACPI function provided by the caller to sleep the platform.
190 * This call will not return on success.
197 /* sleep failed, no cpu context lost */
201 /* protected mode, paging disabled */
202 POSTCODE(ACPI_WAKE_PROT_ENTRY)
204 movl PA(saved_cr3), %ebx
205 movl PA(saved_cr4), %ecx
207 * restore cr3, PAE and NXE states in an orderly fashion
212 movl $(MSR_IA32_EFER), %ecx /* MSR number in ecx */
213 rdmsr /* MSR value return in edx: eax */
214 orl $(MSR_IA32_EFER_NXE), %eax /* Set NXE bit in low 32-bits */
215 wrmsr /* Update Extended Feature Enable reg */
217 /* restore kernel GDT */
220 movl PA(saved_cr2), %eax
223 /* restore CR0, paging enabled */
224 movl PA(saved_cr0), %eax
227 /* switch to kernel code segment */
228 ljmpl $(KERNEL_CS), $wake_paged
232 /* protected mode, paging enabled */
233 POSTCODE(ACPI_WAKE_PAGED_ENTRY)
235 /* switch to kernel data segment */
236 movw $(KERNEL_DS), %ax
239 /* restore local and interrupt descriptor tables */
243 /* restore segment registers */
250 * Restore task register. Before doing this, clear the busy flag
251 * in the TSS descriptor set by the CPU.
253 movl $saved_gdt, %eax
254 movl 2(%eax), %edx /* GDT base, skip limit word */
255 movl $(KERNEL_TSS), %eax /* TSS segment selector */
256 movb $(K_TSS), 5(%edx, %eax) /* clear busy flag */
257 ltr saved_tr /* restore TR */
261 /* restore general purpose registers */
272 .section __HIB, __text
275 .globl EXT(acpi_wake_prot_entry)
276 ENTRY(acpi_wake_prot_entry)
277 /* protected mode, paging enabled */
279 POSTCODE(ACPI_WAKE_PAGED_ENTRY)
281 /* restore kernel GDT */
286 /* restore control registers */
296 /* restore real PDE base */
303 /* switch to kernel data segment */
304 movw $(KERNEL_DS), %ax
308 /* restore local and interrupt descriptor tables */
313 /* restore segment registers */
321 * Restore task register. Before doing this, clear the busy flag
322 * in the TSS descriptor set by the CPU.
324 movl $saved_gdt, %eax
325 movl 2(%eax), %edx /* GDT base, skip limit word */
326 movl $(KERNEL_TSS), %eax /* TSS segment selector */
327 movb $(K_TSS), 5(%edx, %eax) /* clear busy flag */
328 ltr saved_tr /* restore TR */
330 /* restore general purpose registers */
337 /* make sure interrupts are disabled */
347 .section __HIB, __data
352 * CPU registers saved across sleep/wake.