acpi_wakeup_low.S revision 1.6 1 /* $NetBSD: acpi_wakeup_low.S,v 1.6 2017/09/23 10:18:49 maxv 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/segments.h>
34 #include <machine/specialreg.h>
35
36 .text
37 .p2align 2, 0x90
38 .globl acpi_md_sleep_exit
39 acpi_md_sleep_exit:
40 lgdt ACPI_SUSPEND_GDT(%r8)
41
42 /* Reload fixed descriptors for new GDT */
43 movw $GSEL(GDATA_SEL, SEL_KPL),%ax
44 movw %ax,%ds
45 movw %ax,%es
46 movw %ax,%ss
47
48 /* FS and GS are driven by MSRs, so use NULL for them */
49 xorw %ax,%ax
50 movw %ax,%fs
51 movw %ax,%gs
52
53 movl $MSR_EFER,%ecx
54 movl ACPI_SUSPEND_EFER(%r8),%eax
55 movl $0,%edx
56 wrmsr
57
58 movl $MSR_FSBASE,%ecx
59 movl ACPI_SUSPEND_FS(%r8),%eax
60 movl ACPI_SUSPEND_FS+4(%r8),%edx
61 wrmsr
62
63 movl $MSR_GSBASE,%ecx
64 movl ACPI_SUSPEND_GS(%r8),%eax
65 movl ACPI_SUSPEND_GS+4(%r8),%edx
66 wrmsr
67
68 movl $MSR_KERNELGSBASE,%ecx
69 movl ACPI_SUSPEND_KGS(%r8),%eax
70 movl ACPI_SUSPEND_KGS+4(%r8),%edx
71 wrmsr
72
73 movq ACPI_SUSPEND_CR8(%r8),%rax
74 movq %rax,%cr8
75 movq ACPI_SUSPEND_CR4(%r8),%rax
76 movq %rax,%cr4
77 movq ACPI_SUSPEND_CR3(%r8),%rax
78 movq %rax,%cr3
79 movq ACPI_SUSPEND_CR2(%r8),%rax
80 movq %rax,%cr2
81 movq ACPI_SUSPEND_CR0(%r8),%rax
82 movq %rax,%cr0
83
84 jmp 1f
85 1:
86
87 movq CPUVAR(GDT),%rax
88 movzwq ACPI_SUSPEND_TR(%r8),%rdx
89 andq $~0x0200,4(%rax,%rdx, 1)
90
91 ltr %dx
92 lldt ACPI_SUSPEND_LDT(%r8)
93 lidt ACPI_SUSPEND_IDT(%r8)
94
95 movq ACPI_SUSPEND_REG+(0*8)(%r8),%rsp
96 movq ACPI_SUSPEND_REG+(1*8)(%r8),%rbx
97 movq ACPI_SUSPEND_REG+(2*8)(%r8),%rbp
98 movq ACPI_SUSPEND_REG+(3*8)(%r8),%r12
99 movq ACPI_SUSPEND_REG+(4*8)(%r8),%r13
100 movq ACPI_SUSPEND_REG+(5*8)(%r8),%r14
101 movq ACPI_SUSPEND_REG+(6*8)(%r8),%r15
102
103 xorq %rax,%rax
104
105 pushq ACPI_SUSPEND_REG+(7*8)(%r8)
106 popfq
107 ret
108
109 .p2align 2, 0x90
110 .type acpi_md_sleep_prepare, @function
111 .globl acpi_md_sleep_prepare
112 acpi_md_sleep_prepare:
113 movq CPUVAR(SELF),%r8
114 movq %rbx,ACPI_SUSPEND_REG+(1*8)(%r8)
115 movq %rbp,ACPI_SUSPEND_REG+(2*8)(%r8)
116 movq %r12,ACPI_SUSPEND_REG+(3*8)(%r8)
117 movq %r13,ACPI_SUSPEND_REG+(4*8)(%r8)
118 movq %r14,ACPI_SUSPEND_REG+(5*8)(%r8)
119 movq %r15,ACPI_SUSPEND_REG+(6*8)(%r8)
120
121 movq %cr0,%rax
122 movq %rax,ACPI_SUSPEND_CR0(%r8)
123 movq %cr2,%rax
124 movq %rax,ACPI_SUSPEND_CR2(%r8)
125 movq %cr3,%rax
126 movq %rax,ACPI_SUSPEND_CR3(%r8)
127 movq %cr4,%rax
128 movq %rax,ACPI_SUSPEND_CR4(%r8)
129 movq %cr8,%rax
130 movq %rax,ACPI_SUSPEND_CR8(%r8)
131
132 pushfq
133 popq ACPI_SUSPEND_REG+(7*8)(%r8)
134
135 movq %rsp,ACPI_SUSPEND_REG+(0*8)(%r8)
136
137 movl $MSR_FSBASE,%ecx
138 rdmsr
139 movl %eax,ACPI_SUSPEND_FS(%r8)
140 movl %edx,ACPI_SUSPEND_FS+4(%r8)
141
142 movl $MSR_GSBASE,%ecx
143 rdmsr
144 movl %eax,ACPI_SUSPEND_GS(%r8)
145 movl %edx,ACPI_SUSPEND_GS+4(%r8)
146
147 movl $MSR_KERNELGSBASE,%ecx
148 rdmsr
149 movl %eax,ACPI_SUSPEND_KGS(%r8)
150 movl %edx,ACPI_SUSPEND_KGS+4(%r8)
151
152 movl $MSR_EFER,%ecx
153 rdmsr
154 movl %eax,ACPI_SUSPEND_EFER(%r8)
155
156 sgdt ACPI_SUSPEND_GDT(%r8)
157 sidt ACPI_SUSPEND_IDT(%r8)
158 sldt ACPI_SUSPEND_LDT(%r8)
159 str ACPI_SUSPEND_TR(%r8)
160
161 call acpi_md_sleep_enter
162 /* acpi_md_sleep_enter only returns on failure. */
163 movl $-1,%eax
164 ret
165