1 /* $NetBSD: acpi_wakecode.S,v 1.9 2009/08/24 10:16:12 jmcneill Exp $ */
4 * Copyright (c) 2007 Joerg Sonnenberger <joerg@netbsd.org>
6 * Copyright (c) 2002 The NetBSD Foundation, Inc.
9 * This code is derived from software contributed to The NetBSD Foundation
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
21 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
22 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
23 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
25 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
36 * This code is derived from FreeBSD. Original copyrights:
38 * Copyright (c) 2001 Takanori Watanabe <takawata@jp.freebsd.org>
39 * Copyright (c) 2001 Mitsuru IWASAKI <iwasaki@jp.freebsd.org>
40 * All rights reserved.
42 * Redistribution and use in source and binary forms, with or without
43 * modification, are permitted provided that the following conditions
45 * 1. Redistributions of source code must retain the above copyright
46 * notice, this list of conditions and the following disclaimer.
47 * 2. Redistributions in binary form must reproduce the above copyright
48 * notice, this list of conditions and the following disclaimer in the
49 * documentation and/or other materials provided with the distribution.
51 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
52 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
53 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
54 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
55 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
56 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
57 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
58 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
59 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
60 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
63 * FreeBSD: src/sys/i386/acpica/acpi_wakecode.S,v 1.1 2001/07/20 06:07:31 takawata Exp
68 #include <machine/psl.h>
69 #include <machine/segments.h>
70 #include <machine/specialreg.h>
72 #define ACPI_WAKEUP_ADDR 0x3000
76 .org 0 /* ACPI spec says: cs==(phys>>8), ip==(phys&0x000F) */
83 /* Set up segment registers for real mode */
88 /* Small call stack */
95 /* Only beep on reset if machdep.acpi_beep_on_reset=1 */
96 cmpb $1,WAKEUP_beep_on_reset
107 /* Only reset the VBIOS if machdep.acpi_vbios_reset=1 */
108 cmpb $1,WAKEUP_vbios_reset
111 /* Kick the VBIOS. */
114 /* Reset registers in case the VBIOS changed them. */
119 /* If we need to restore a VESA VBE mode, do it now */
120 cmpb $0,WAKEUP_vesa_modenum
122 movw WAKEUP_vesa_modenum,%bx
132 /* Disable beep again if machdep.acpi_beep_on_reset=1 */
133 cmpb $1,WAKEUP_beep_on_reset
140 /* Load temporary 32bit GDT */
141 data32 addr32 lgdt tmp_gdt
143 /* Enable protected mode w/o paging */
150 * Switch to protected mode by intersegmental jump.
151 * Target and everything else has to compensate for the new origin
152 * as this is using the flat memory model now.
155 ljmpl $0x8,$wakeup_32 + ACPI_WAKEUP_ADDR
161 * Switched to protected mode w/o paging
165 /* Set up segment registers and initial stack for protected mode */
170 movl $(ACPI_WAKEUP_ADDR + 4096),%esp
172 /* First, reset the PSL. */
176 /* Enable PAE and potentially PSE */
177 movl $(CR4_PAE|CR4_OSFXSR|CR4_OSXMMEXCPT|CR4_PSE),%eax
181 * First switch to Long Mode. Do not restore the original
182 * MSR EFER value directly, as enabling the NX bit without
183 * paging will result in a GPF on AMD CPUs.
185 * Load the correct MSR EFER value now to not depend on the
186 * data segment register directly after switching to Long Mode.
187 * After this point, no instruction is allowed to clobber %ebx.
189 movl WAKEUP_efer + ACPI_WAKEUP_ADDR,%ebx
195 /* Load temporary PML4, code will switch to full PML4 later */
196 movl WAKEUP_r_cr3 + ACPI_WAKEUP_ADDR,%eax
201 orl $(CR0_PE|CR0_PG|CR0_NE|CR0_TS|CR0_MP|CR0_WP),%eax
203 /* Flush prefetch queue */
206 /* Switch to temporary 64bit GDT */
207 lgdt tmp_gdt64 + ACPI_WAKEUP_ADDR
209 /* Switch to long mode using intersegmental jump. */
210 ljmp $0x8, $wakeup_64 + ACPI_WAKEUP_ADDR
216 * Load the normal system value of MSR EFER. This includes
217 * enabling the SYSCALL extension and NXE (if supported).
223 /* Reload data segment with default value */
224 movw $GSEL(GDATA_SEL, SEL_KPL),%ax
227 movq WAKEUP_curcpu + ACPI_WAKEUP_ADDR,%r8
228 movq WAKEUP_restorecpu + ACPI_WAKEUP_ADDR,%rbx
230 /* Continue with wakeup in the high-level wakeup code */
236 .long tmp_gdtable + ACPI_WAKEUP_ADDR
245 .byte 0, 0x9f, 0xcf, 0
248 .byte 0, 0x93, 0xcf, 0
252 .long tmp_gdtable64 + ACPI_WAKEUP_ADDR
255 .quad 0x0000000000000000
256 .quad 0x00af9a000000ffff
257 .quad 0x00cf92000000ffff
261 WAKEUP_r_cr3: .quad 0
263 .global WAKEUP_restorecpu
264 WAKEUP_restorecpu: .quad 0
266 .global WAKEUP_vbios_reset
267 WAKEUP_vbios_reset: .byte 0
268 .global WAKEUP_vesa_modenum
269 WAKEUP_vesa_modenum: .word 0
270 .global WAKEUP_beep_on_reset
271 WAKEUP_beep_on_reset: .byte 0
273 .global WAKEUP_curcpu
274 WAKEUP_curcpu: .quad 0