1 /* $NetBSD: acpi_wakecode.S,v 1.13 2009/08/24 02:15:46 jmcneill Exp $ */
4 * Copyright (c) 2002 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
34 * This code is derived from FreeBSD. Original copyrights:
36 * Copyright (c) 2001 Takanori Watanabe <takawata@jp.freebsd.org>
37 * Copyright (c) 2001 Mitsuru IWASAKI <iwasaki@jp.freebsd.org>
38 * All rights reserved.
40 * Redistribution and use in source and binary forms, with or without
41 * modification, are permitted provided that the following conditions
43 * 1. Redistributions of source code must retain the above copyright
44 * notice, this list of conditions and the following disclaimer.
45 * 2. Redistributions in binary form must reproduce the above copyright
46 * notice, this list of conditions and the following disclaimer in the
47 * documentation and/or other materials provided with the distribution.
49 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
50 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
51 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
52 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
53 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
54 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
55 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
56 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
57 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
58 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
61 * FreeBSD: src/sys/i386/acpica/acpi_wakecode.S,v 1.1 2001/07/20 06:07:31 takawata Exp
66 #include <machine/specialreg.h>
67 #include <machine/segments.h>
69 #define ACPI_WAKEUP_ADDR 0x3000
73 .org 0 /* ACPI spec says: cs==(phys>>8), ip==(phys&0x000F) */
80 /* Set up segment registers for real mode */
85 /* Small call stack */
92 /* Only beep on reset if machdep.acpi_beep_on_reset=1 */
93 cmpb $1,WAKEUP_beep_on_reset
104 /* Only reset the VBIOS if machdep.acpi_vbios_reset=1 */
105 cmpb $1,WAKEUP_vbios_reset
108 /* Kick the VBIOS. */
115 /* If we need to restore a VESA VBE mode, do it now */
116 cmpb $0,WAKEUP_vesa_modenum
118 movw WAKEUP_vesa_modenum,%bx
128 /* Disable beep again if machdep.acpi_beep_on_reset=1 */
129 cmpb $1,WAKEUP_beep_on_reset
136 /* Load GDT while non-paging */
139 /* Enable protected mode */
144 /* Switch to protected mode by intersegmental jump */
145 ljmpl $0x8,$wakeup_32 + ACPI_WAKEUP_ADDR
152 * Switched to protected mode w/o paging
156 /* Set up segment registers for protected mode */
157 movw $GSEL(GDATA_SEL,SEL_KPL),%ax
160 /* Restore PSE and other settings before enabling paging. */
161 movl WAKEUP_r_cr4 + ACPI_WAKEUP_ADDR,%eax
164 /* Enable paging (assumes identical mapping) */
165 movl WAKEUP_r_cr3 + ACPI_WAKEUP_ADDR,%eax
168 orl $(CR0_PE|CR0_PG|CR0_NE|CR0_TS|CR0_EM|CR0_MP|CR0_WP),%eax
171 /* Flush the prefetch queue */
178 /* Restore registers */
179 movl WAKEUP_curcpu + ACPI_WAKEUP_ADDR,%edx
180 movl WAKEUP_restorecpu + ACPI_WAKEUP_ADDR,%ebx
187 .long tmp_gdtable + ACPI_WAKEUP_ADDR
196 .byte 0, 0x9f, 0xcf, 0
199 .byte 0, 0x93, 0xcf, 0
203 WAKEUP_r_cr3: .long 0
205 WAKEUP_r_cr4: .long 0
207 .global WAKEUP_curcpu
208 WAKEUP_curcpu: .long 0
209 .global WAKEUP_restorecpu
210 WAKEUP_restorecpu: .long 0
212 .global WAKEUP_vbios_reset
213 WAKEUP_vbios_reset: .byte 0
214 .global WAKEUP_vesa_modenum
215 WAKEUP_vesa_modenum: .word 0
216 .global WAKEUP_beep_on_reset
217 WAKEUP_beep_on_reset: .byte 0