acpi_wakecode.S revision 1.1 1 /* $NetBSD: acpi_wakecode.S,v 1.1 2002/06/18 07:25:13 tshiozak 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/param.h>
75
76 .code16
77 .org 0 /* ACPI spec says: cs==(phys>>8), ip==(phys&0x000F) */
78 wakeup_16:
79 nop
80 cli
81
82 /* Set up segment registers for real mode */
83 movw %cs,%ax
84 movw %ax,%ds
85 movw %ax,%ss
86
87 /* Get physical address of the code */
88 xorl %esi,%esi
89 movw %cs,%si
90 shll $4,%esi
91
92 /* Fill 16->32 address */
93 movl %esi,%eax
94 addl $wakeup_32,%eax
95 movl %eax,wakeup_sw32+2
96 jmp 1f /* flush prefetch queue */
97 1: jmp 1f
98 1:
99
100 /* Load GDT while non-paging */
101 movl %esi,%eax
102 addl $tmp_gdtable,%eax
103 movl %eax,tmp_gdt+2
104 lgdt tmp_gdt
105
106 /* Enable protected mode */
107 mov %cr0,%eax
108 orl $(CR0_PE),%eax
109 mov %eax,%cr0
110
111 wakeup_sw32:
112 /* Switch to protected mode by intersegmental jump */
113 ljmpl $0x8,$0x12345678 /* Code location, to be replaced */
114
115
116 .code32
117 .align 16
118 wakeup_32:
119 /*
120 * Switched to protected mode w/o paging
121 */
122
123 nop
124 /* Set up segment registers for protected mode */
125 movw $0x10,%ax /* KDSEL to segment registers */
126 movw %ax,%ds
127 movw %ax,%es
128 movw %ax,%gs
129 movw %ax,%ss
130 movw %ax,%fs
131
132 /* Fixup TSS type field; 386 busy TSS (11) -> 386 available TSS (9) */
133 #define TSS_TYPEFIX_MASK 0xf9
134 movl physical_gdt+2(%esi),%ebx
135 movzxw previous_tr(%esi),%ecx
136 leal (%ebx,%ecx),%eax /* get TSS segment descriptor */
137 andb $TSS_TYPEFIX_MASK,5(%eax)
138
139 /* Enable paging (assumes identical mapping) */
140 movl previous_cr3(%esi),%eax
141 movl %eax,%cr3
142 movl previous_cr0(%esi),%eax
143 movl %eax,%cr0
144
145 /* Flush the prefetch queue */
146 jmp 1f
147 1: jmp 1f
148 1:
149
150 /* Restore registers */
151 lgdt previous_gdt(%esi)
152 lidt previous_idt(%esi)
153 lldt previous_ldt(%esi)
154 ltr previous_tr(%esi)
155
156 mov previous_cr2(%esi),%eax
157 mov %eax,%cr2
158 mov previous_cr4(%esi),%eax
159 mov %eax,%cr4
160
161 movw previous_es(%esi),%ax
162 movw %ax,%es
163 movw previous_fs(%esi),%ax
164 movw %ax,%fs
165 movw previous_gs(%esi),%ax
166 movw %ax,%gs
167 movw previous_ss(%esi),%ax
168 movw %ax,%ss
169 movl where_to_recover(%esi),%ebx
170 movw previous_ds(%esi),%ax
171 movw %ax,%ds
172 jmp *%ebx
173
174
175 .align 8
176 tmp_gdt:
177 .word 0xffff
178 .long 0
179
180 .align 8, 0
181 tmp_gdtable:
182 /* null */
183 .word 0, 0
184 .byte 0, 0, 0, 0
185 /* code */
186 .word 0xffff, 0
187 .byte 0, 0x9f, 0xcf, 0
188 /* data */
189 .word 0xffff, 0
190 .byte 0, 0x93, 0xcf, 0
191
192 .align 16, 0
193 physical_gdt: .word 0
194 .long 0
195 previous_cr2: .long 0
196 previous_cr3: .long 0
197 previous_cr4: .long 0
198 previous_cr0: .long 0
199 previous_tr: .word 0
200 previous_gdt: .word 0
201 .long 0
202 previous_ldt: .word 0
203 previous_idt: .word 0
204 .long 0
205 previous_ds: .word 0
206 previous_es: .word 0
207 previous_fs: .word 0
208 previous_gs: .word 0
209 previous_ss: .word 0
210 where_to_recover: .long 0
211