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