acpi_wakeup_low.S revision 1.2 1 /* $NetBSD: acpi_wakeup_low.S,v 1.2 2007/12/09 20:27:42 jmcneill Exp $ */
2
3 /*-
4 * Copyright (c) 2007 Joerg Sonnenberger <joerg (at) netbsd.org>
5 * Copyright (c) 2001 Takanori Watanabe <takawata (at) jp.freebsd.org>
6 * Copyright (c) 2001 Mitsuru IWASAKI <iwasaki (at) jp.freebsd.org>
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * SUCH DAMAGE.
29 */
30
31 #include "assym.h"
32 #include <machine/asm.h>
33 #include <machine/specialreg.h>
34
35 .text
36 .p2align 2, 0x90
37 .globl acpi_md_sleep_exit
38 acpi_md_sleep_exit:
39 lgdt r_gdt
40
41 xorw %ax,%ax
42 movw %ax,%fs
43 movw %ax,%gs
44
45 movl $MSR_EFER,%ecx
46 movl r_msr_efer,%eax
47 wrmsr
48
49 movl $MSR_FSBASE,%ecx
50 movl r_fs_base_l,%eax
51 movl r_fs_base_h,%edx
52 wrmsr
53
54 movl $MSR_GSBASE,%ecx
55 movl r_gs_base_l,%eax
56 movl r_gs_base_h,%edx
57 wrmsr
58
59 movl $MSR_KERNELGSBASE,%ecx
60 movl r_gs_kernelbase_l,%eax
61 movl r_gs_kernelbase_h,%edx
62 wrmsr
63
64 movq r_cr8,%rax
65 movq %rax,%cr8
66 movq r_cr4,%rax
67 movq %rax,%cr4
68 movq r_cr3,%rax
69 movq %rax,%cr3
70 movq r_cr2,%rax
71 movq %rax,%cr2
72 movq r_cr0,%rax
73 movq %rax,%cr0
74
75 jmp 1f
76 1:
77
78 movq CPUVAR(GDT),%rax
79 movq %rax, r_save_gdt
80 movzwq r_tr,%rdx
81 andq $~0x0200,4(%rax,%rdx, 1)
82
83 ltr %dx
84 lldt r_ldt
85 lidt r_idt
86
87 movq r_rsp,%rsp
88
89 movq r_rbx,%rbx
90 movq r_rbp,%rbp
91 movq r_r12,%r12
92 movq r_r13,%r13
93 movq r_r14,%r14
94 movq r_r15,%r15
95
96 movq ret_addr,%rax
97 movq %rax,(%rsp)
98 xorq %rax,%rax
99
100 pushq r_rfl
101 popfq
102 ret
103
104 .p2align 2, 0x90
105 .type acpi_md_sleep_prepare, @function
106 .globl acpi_md_sleep_prepare
107 acpi_md_sleep_prepare:
108 movq %rbx,r_rbx
109 movq %rbp,r_rbp
110 movq %r12,r_r12
111 movq %r13,r_r13
112 movq %r14,r_r14
113 movq %r15,r_r15
114
115 movq %cr0,%rax
116 movq %rax,r_cr0
117 movq %cr2,%rax
118 movq %rax,r_cr2
119 movq %cr3,%rax
120 movq %rax,r_cr3
121 movq %cr4,%rax
122 movq %rax,r_cr4
123 movq %cr8,%rax
124 movq %rax,r_cr8
125
126 pushfq
127 popq r_rfl
128
129 movq %rsp,r_rsp
130
131 movl $MSR_FSBASE,%ecx
132 rdmsr
133 movl %eax,r_fs_base_l
134 movl %edx,r_fs_base_h
135
136 movl $MSR_GSBASE,%ecx
137 rdmsr
138 movl %eax,r_gs_base_l
139 movl %edx,r_gs_base_h
140
141 movl $MSR_KERNELGSBASE,%ecx
142 rdmsr
143 movl %eax,r_gs_kernelbase_l
144 movl %edx,r_gs_kernelbase_h
145
146 movl $MSR_EFER,%ecx
147 rdmsr
148 movl %eax,r_msr_efer
149
150 sgdt r_gdt
151 sidt r_idt
152 sldt r_ldt
153 str r_tr
154
155 movq (%rsp),%rax
156 movq %rax,ret_addr
157
158 call acpi_md_sleep_enter
159 /* acpi_md_sleep_enter only returns on failure. */
160 movl $-1,%eax
161 ret
162
163 .data
164 .align 16
165
166 r_tr: .word 0
167 r_ldt: .word 0
168
169 r_fs_base_l:
170 .long 0
171 r_fs_base_h:
172 .long 0
173 r_gs_base_l:
174 .long 0
175 r_gs_base_h:
176 .long 0
177 r_gs_kernelbase_l:
178 .long 0
179 r_gs_kernelbase_h:
180 .long 0
181 r_msr_efer:
182 .long 0
183 r_rbx: .quad 0
184 r_rbp: .quad 0
185 r_rsp: .quad 0
186 r_r12: .quad 0
187 r_r13: .quad 0
188 r_r14: .quad 0
189 r_r15: .quad 0
190 r_rfl: .quad 0
191
192 r_cr0: .quad 0
193 r_cr2: .quad 0
194 r_cr3: .quad 0
195 r_cr4: .quad 0
196 r_cr8: .quad 0
197
198 r_gdt: .word 0
199 .quad 0
200 r_idt: .word 0
201 .quad 0
202
203 ret_addr: .quad 0
204 r_save_gdt: .quad 0
205