2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_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 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.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
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.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
30 #include <i386/proc_reg.h>
31 #include <i386/postcode.h>
32 #include <i386/acpi.h>
38 .align 12 /* Page align for single bcopy_phys() */
40 #define PA(addr) (addr)
45 /* protected mode, paging disabled */
47 /* setup the protected mode segment registers */
55 /* jump back to the sleep function in the kernel */
56 movl PA(saved_eip), %eax
60 * acpi_sleep_cpu(acpi_sleep_callback func, void * refcon)
62 * Save CPU state before platform sleep. Restore CPU state
73 /* save general purpose registers */
77 /* make sure tlb is flushed */
81 /* save control registers */
91 /* save segment registers */
97 /* save descriptor table registers */
104 * When system wakes up, the real mode wake handler will revert to
105 * protected mode, then jump to the address stored at saved_eip.
107 movl $(PA(wake_prot)), saved_eip
110 * Call ACPI function provided by the caller to sleep the platform.
111 * This call will not return on success.
118 /* sleep failed, no cpu context lost */
122 /* protected mode, paging disabled */
123 POSTCODE(ACPI_WAKE_PROT_ENTRY)
125 movl PA(saved_cr3), %ebx
126 movl PA(saved_cr4), %ecx
128 * restore cr3, PAE and NXE states in an orderly fashion
133 movl $(MSR_IA32_EFER), %ecx /* MSR number in ecx */
134 rdmsr /* MSR value return in edx: eax */
135 orl $(MSR_IA32_EFER_NXE), %eax /* Set NXE bit in low 32-bits */
136 wrmsr /* Update Extended Feature Enable reg */
138 /* restore kernel GDT */
141 movl PA(saved_cr2), %eax
144 /* restore CR0, paging enabled */
145 movl PA(saved_cr0), %eax
148 /* switch to kernel code segment */
149 ljmpl $(KERNEL32_CS), $wake_paged
153 /* protected mode, paging enabled */
154 POSTCODE(ACPI_WAKE_PAGED_ENTRY)
156 /* switch to kernel data segment */
157 movw $(KERNEL_DS), %ax
160 /* restore local and interrupt descriptor tables */
164 /* restore segment registers */
171 * Restore task register. Before doing this, clear the busy flag
172 * in the TSS descriptor set by the CPU.
174 movl $saved_gdt, %eax
175 movl 2(%eax), %edx /* GDT base, skip limit word */
176 movl $(KERNEL_TSS), %eax /* TSS segment selector */
177 movb $(K_TSS), 5(%edx, %eax) /* clear busy flag */
178 ltr saved_tr /* restore TR */
182 /* restore general purpose registers */
193 .section __HIB, __text
196 .globl EXT(acpi_wake_prot_entry)
197 ENTRY(acpi_wake_prot_entry)
201 mov $EXT(IdlePDPT), %eax
202 mov EXT(IdlePTD), %ecx
203 or $(INTEL_PTE_VALID), %ecx
205 mov %ecx, (0*8+0)(%eax)
206 mov %edx, (0*8+4)(%eax)
207 add $(PAGE_SIZE), %ecx
208 mov %ecx, (1*8+0)(%eax)
209 mov %edx, (1*8+4)(%eax)
210 add $(PAGE_SIZE), %ecx
211 mov %ecx, (2*8+0)(%eax)
212 mov %edx, (2*8+4)(%eax)
213 add $(PAGE_SIZE), %ecx
214 mov %ecx, (3*8+0)(%eax)
215 mov %edx, (3*8+4)(%eax)
221 /* protected mode, paging enabled */
223 POSTCODE(ACPI_WAKE_PAGED_ENTRY)
225 /* restore kernel GDT */
230 /* restore control registers */
240 /* restore real PDE base */
247 /* switch to kernel data segment */
248 movw $(KERNEL_DS), %ax
252 /* restore local and interrupt descriptor tables */
257 /* restore segment registers */
265 * Restore task register. Before doing this, clear the busy flag
266 * in the TSS descriptor set by the CPU.
268 movl $saved_gdt, %eax
269 movl 2(%eax), %edx /* GDT base, skip limit word */
270 movl $(KERNEL_TSS), %eax /* TSS segment selector */
271 movb $(K_TSS), 5(%edx, %eax) /* clear busy flag */
272 ltr saved_tr /* restore TR */
274 /* restore general purpose registers */
281 /* make sure interrupts are disabled */
289 #endif /* CONFIG_SLEEP */
292 .section __SLEEP, __data
296 * CPU registers saved across sleep/wake.