acpi_wakecode.S revision 1.13 1 /* $NetBSD: acpi_wakecode.S,v 1.13 2009/08/24 02:15:46 jmcneill Exp $ */
2
3 /*-
4 * Copyright (c) 2002 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Takuya SHIOZAKI.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
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.
18 *
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.
30 */
31
32
33 /*
34 * This code is derived from FreeBSD. Original copyrights:
35 *
36 * Copyright (c) 2001 Takanori Watanabe <takawata (at) jp.freebsd.org>
37 * Copyright (c) 2001 Mitsuru IWASAKI <iwasaki (at) jp.freebsd.org>
38 * All rights reserved.
39 *
40 * Redistribution and use in source and binary forms, with or without
41 * modification, are permitted provided that the following conditions
42 * are met:
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.
48 *
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
59 * SUCH DAMAGE.
60 *
61 * FreeBSD: src/sys/i386/acpica/acpi_wakecode.S,v 1.1 2001/07/20 06:07:31 takawata Exp
62 */
63
64 #define _LOCORE
65
66 #include <machine/specialreg.h>
67 #include <machine/segments.h>
68
69 #define ACPI_WAKEUP_ADDR 0x3000
70
71 .text
72 .code16
73 .org 0 /* ACPI spec says: cs==(phys>>8), ip==(phys&0x000F) */
74 .globl wakeup_16
75 wakeup_16:
76 nop
77 cli
78 cld
79
80 /* Set up segment registers for real mode */
81 movw %cs,%ax
82 movw %ax,%ds
83 movw %ax,%ss
84
85 /* Small call stack */
86 mov $0x1000,%sp
87
88 /* Clear flags */
89 pushl $0
90 popfl
91
92 /* Only beep on reset if machdep.acpi_beep_on_reset=1 */
93 cmpb $1,WAKEUP_beep_on_reset
94 jne 1f
95 movb $0xc0,%al
96 outb %al,$0x42
97 movb $0x04,%al
98 outb %al,$0x42
99 inb $0x61,%al
100 orb $0x3,%al
101 outb %al,$0x61
102 1:
103
104 /* Only reset the VBIOS if machdep.acpi_vbios_reset=1 */
105 cmpb $1,WAKEUP_vbios_reset
106 jne 1f
107
108 /* Kick the VBIOS. */
109 lcall $0xc000,$3
110
111 movw %cs,%ax
112 movw %ax,%ds
113 movw %ax,%ss
114 1:
115
116 /* Disable beep again if machdep.acpi_beep_on_reset=1 */
117 cmpb $1,WAKEUP_beep_on_reset
118 jne 1f
119 inb $0x61,%al
120 andb $0xfc,%al
121 outb %al,$0x61
122 1:
123
124 /* If we need to restore a VESA VBE mode, do it now */
125 cmpb $0,WAKEUP_vesa_modenum
126 je 1f
127 movw WAKEUP_vesa_modenum,%bx
128 orw $0x4000,%bx
129 movw $0x4f02,%ax
130 int $0x10
131
132 /* paranoia */
133 movw %cs,%ax
134 movw %ax,%ds
135 movw %ax,%ss
136 1:
137
138 /* Load GDT while non-paging */
139 lgdt tmp_gdt
140
141 /* Enable protected mode */
142 mov %cr0,%eax
143 orl $(CR0_PE),%eax
144 mov %eax,%cr0
145
146 /* Switch to protected mode by intersegmental jump */
147 ljmpl $0x8,$wakeup_32 + ACPI_WAKEUP_ADDR
148
149
150 .code32
151 .align 16
152 wakeup_32:
153 /*
154 * Switched to protected mode w/o paging
155 */
156
157 nop
158 /* Set up segment registers for protected mode */
159 movw $GSEL(GDATA_SEL,SEL_KPL),%ax
160 movw %ax,%ds
161
162 /* Restore PSE and other settings before enabling paging. */
163 movl WAKEUP_r_cr4 + ACPI_WAKEUP_ADDR,%eax
164 movl %eax,%cr4
165
166 /* Enable paging (assumes identical mapping) */
167 movl WAKEUP_r_cr3 + ACPI_WAKEUP_ADDR,%eax
168 movl %eax,%cr3
169 movl %cr0,%eax
170 orl $(CR0_PE|CR0_PG|CR0_NE|CR0_TS|CR0_EM|CR0_MP|CR0_WP),%eax
171 movl %eax,%cr0
172
173 /* Flush the prefetch queue */
174 jmp 1f
175 1: jmp 1f
176 1:
177
178 nop
179
180 /* Restore registers */
181 movl WAKEUP_curcpu + ACPI_WAKEUP_ADDR,%edx
182 movl WAKEUP_restorecpu + ACPI_WAKEUP_ADDR,%ebx
183
184 jmp *%ebx
185
186 .align 8
187 tmp_gdt:
188 .word 0xffff
189 .long tmp_gdtable + ACPI_WAKEUP_ADDR
190
191 .align 8, 0
192 tmp_gdtable:
193 /* null */
194 .word 0, 0
195 .byte 0, 0, 0, 0
196 /* code */
197 .word 0xffff, 0
198 .byte 0, 0x9f, 0xcf, 0
199 /* data */
200 .word 0xffff, 0
201 .byte 0, 0x93, 0xcf, 0
202
203 .align 16, 0
204 .global WAKEUP_r_cr3
205 WAKEUP_r_cr3: .long 0
206 .global WAKEUP_r_cr4
207 WAKEUP_r_cr4: .long 0
208
209 .global WAKEUP_curcpu
210 WAKEUP_curcpu: .long 0
211 .global WAKEUP_restorecpu
212 WAKEUP_restorecpu: .long 0
213
214 .global WAKEUP_vbios_reset
215 WAKEUP_vbios_reset: .byte 0
216 .global WAKEUP_vesa_modenum
217 WAKEUP_vesa_modenum: .word 0
218 .global WAKEUP_beep_on_reset
219 WAKEUP_beep_on_reset: .byte 0
220