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