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