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