acpi_wakecode.S revision 1.11 1 /* $NetBSD: acpi_wakecode.S,v 1.11 2007/12/18 07:17:11 joerg 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 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39
40 /*
41 * This code is derived from FreeBSD. Original copyrights:
42 *
43 * Copyright (c) 2001 Takanori Watanabe <takawata (at) jp.freebsd.org>
44 * Copyright (c) 2001 Mitsuru IWASAKI <iwasaki (at) jp.freebsd.org>
45 * All rights reserved.
46 *
47 * Redistribution and use in source and binary forms, with or without
48 * modification, are permitted provided that the following conditions
49 * are met:
50 * 1. Redistributions of source code must retain the above copyright
51 * notice, this list of conditions and the following disclaimer.
52 * 2. Redistributions in binary form must reproduce the above copyright
53 * notice, this list of conditions and the following disclaimer in the
54 * documentation and/or other materials provided with the distribution.
55 *
56 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
57 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
58 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
59 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
60 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
61 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
62 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
63 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
64 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
65 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
66 * SUCH DAMAGE.
67 *
68 * FreeBSD: src/sys/i386/acpica/acpi_wakecode.S,v 1.1 2001/07/20 06:07:31 takawata Exp
69 */
70
71 #define _LOCORE
72
73 #include <machine/specialreg.h>
74 #include <machine/segments.h>
75
76 #define ACPI_WAKEUP_ADDR 0x3000
77
78 .text
79 .code16
80 .org 0 /* ACPI spec says: cs==(phys>>8), ip==(phys&0x000F) */
81 .globl wakeup_16
82 wakeup_16:
83 nop
84 cli
85 cld
86
87 /* Set up segment registers for real mode */
88 movw %cs,%ax
89 movw %ax,%ds
90 movw %ax,%ss
91
92 /* Small call stack */
93 mov $0x1000,%sp
94
95 /* Clear flags */
96 pushl $0
97 popfl
98
99 /* Only beep on reset if machdep.acpi_beep_on_reset=1 */
100 cmpb $1,WAKEUP_beep_on_reset
101 jne 1f
102 movb $0xc0,%al
103 outb %al,$0x42
104 movb $0x04,%al
105 outb %al,$0x42
106 inb $0x61,%al
107 orb $0x3,%al
108 outb %al,$0x61
109 1:
110
111 /* Only reset the VBIOS if machdep.acpi_vbios_reset=1 */
112 cmpb $1,WAKEUP_vbios_reset
113 jne 1f
114
115 /* Kick the VBIOS. */
116 lcall $0xc000,$3
117
118 movw %cs,%ax
119 movw %ax,%ds
120 movw %ax,%ss
121 1:
122
123 /* Disable beep again if machdep.acpi_beep_on_reset=1 */
124 cmpb $1,WAKEUP_beep_on_reset
125 jne 1f
126 inb $0x61,%al
127 andb $0xfc,%al
128 outb %al,$0x61
129 1:
130
131 /* Load GDT while non-paging */
132 lgdt tmp_gdt
133
134 /* Enable protected mode */
135 mov %cr0,%eax
136 orl $(CR0_PE),%eax
137 mov %eax,%cr0
138
139 /* Switch to protected mode by intersegmental jump */
140 ljmpl $0x8,$wakeup_32 + ACPI_WAKEUP_ADDR
141
142
143 .code32
144 .align 16
145 wakeup_32:
146 /*
147 * Switched to protected mode w/o paging
148 */
149
150 nop
151 /* Set up segment registers for protected mode */
152 movw $GSEL(GDATA_SEL,SEL_KPL),%ax
153 movw %ax,%ds
154
155 /* Restore PSE and other settings before enabling paging. */
156 movl WAKEUP_r_cr4 + ACPI_WAKEUP_ADDR,%eax
157 movl %eax,%cr4
158
159 /* Enable paging (assumes identical mapping) */
160 movl WAKEUP_r_cr3 + ACPI_WAKEUP_ADDR,%eax
161 movl %eax,%cr3
162 movl %cr0,%eax
163 orl $(CR0_PE|CR0_PG|CR0_NE|CR0_TS|CR0_EM|CR0_MP|CR0_WP),%eax
164 movl %eax,%cr0
165
166 /* Flush the prefetch queue */
167 jmp 1f
168 1: jmp 1f
169 1:
170
171 nop
172
173 /* Restore registers */
174 movl WAKEUP_curcpu + ACPI_WAKEUP_ADDR,%edx
175 movl WAKEUP_restorecpu + ACPI_WAKEUP_ADDR,%ebx
176
177 jmp *%ebx
178
179 .align 8
180 tmp_gdt:
181 .word 0xffff
182 .long tmp_gdtable + ACPI_WAKEUP_ADDR
183
184 .align 8, 0
185 tmp_gdtable:
186 /* null */
187 .word 0, 0
188 .byte 0, 0, 0, 0
189 /* code */
190 .word 0xffff, 0
191 .byte 0, 0x9f, 0xcf, 0
192 /* data */
193 .word 0xffff, 0
194 .byte 0, 0x93, 0xcf, 0
195
196 .align 16, 0
197 .global WAKEUP_r_cr3
198 WAKEUP_r_cr3: .long 0
199 .global WAKEUP_r_cr4
200 WAKEUP_r_cr4: .long 0
201
202 .global WAKEUP_curcpu
203 WAKEUP_curcpu: .long 0
204 .global WAKEUP_restorecpu
205 WAKEUP_restorecpu: .long 0
206
207 .global WAKEUP_vbios_reset
208 WAKEUP_vbios_reset: .byte 0
209 .global WAKEUP_beep_on_reset
210 WAKEUP_beep_on_reset: .byte 0
211