acpi_wakeup_low.S revision 1.6 1 1.6 maxv /* $NetBSD: acpi_wakeup_low.S,v 1.6 2017/09/23 10:18:49 maxv Exp $ */
2 1.2 jmcneill
3 1.2 jmcneill /*-
4 1.2 jmcneill * Copyright (c) 2007 Joerg Sonnenberger <joerg (at) netbsd.org>
5 1.2 jmcneill * Copyright (c) 2001 Takanori Watanabe <takawata (at) jp.freebsd.org>
6 1.2 jmcneill * Copyright (c) 2001 Mitsuru IWASAKI <iwasaki (at) jp.freebsd.org>
7 1.2 jmcneill * All rights reserved.
8 1.2 jmcneill *
9 1.2 jmcneill * Redistribution and use in source and binary forms, with or without
10 1.2 jmcneill * modification, are permitted provided that the following conditions
11 1.2 jmcneill * are met:
12 1.2 jmcneill * 1. Redistributions of source code must retain the above copyright
13 1.2 jmcneill * notice, this list of conditions and the following disclaimer.
14 1.2 jmcneill * 2. Redistributions in binary form must reproduce the above copyright
15 1.2 jmcneill * notice, this list of conditions and the following disclaimer in the
16 1.2 jmcneill * documentation and/or other materials provided with the distribution.
17 1.2 jmcneill *
18 1.2 jmcneill * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19 1.2 jmcneill * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 1.2 jmcneill * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 1.2 jmcneill * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22 1.2 jmcneill * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 1.2 jmcneill * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 1.2 jmcneill * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 1.2 jmcneill * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 1.2 jmcneill * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 1.2 jmcneill * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 1.2 jmcneill * SUCH DAMAGE.
29 1.2 jmcneill */
30 1.2 jmcneill
31 1.2 jmcneill #include "assym.h"
32 1.2 jmcneill #include <machine/asm.h>
33 1.3 joerg #include <machine/segments.h>
34 1.2 jmcneill #include <machine/specialreg.h>
35 1.2 jmcneill
36 1.2 jmcneill .text
37 1.2 jmcneill .p2align 2, 0x90
38 1.2 jmcneill .globl acpi_md_sleep_exit
39 1.2 jmcneill acpi_md_sleep_exit:
40 1.3 joerg lgdt ACPI_SUSPEND_GDT(%r8)
41 1.2 jmcneill
42 1.3 joerg /* Reload fixed descriptors for new GDT */
43 1.3 joerg movw $GSEL(GDATA_SEL, SEL_KPL),%ax
44 1.3 joerg movw %ax,%ds
45 1.3 joerg movw %ax,%es
46 1.3 joerg movw %ax,%ss
47 1.3 joerg
48 1.3 joerg /* FS and GS are driven by MSRs, so use NULL for them */
49 1.2 jmcneill xorw %ax,%ax
50 1.2 jmcneill movw %ax,%fs
51 1.2 jmcneill movw %ax,%gs
52 1.2 jmcneill
53 1.2 jmcneill movl $MSR_EFER,%ecx
54 1.4 ad movl ACPI_SUSPEND_EFER(%r8),%eax
55 1.6 maxv movl $0,%edx
56 1.2 jmcneill wrmsr
57 1.2 jmcneill
58 1.2 jmcneill movl $MSR_FSBASE,%ecx
59 1.4 ad movl ACPI_SUSPEND_FS(%r8),%eax
60 1.4 ad movl ACPI_SUSPEND_FS+4(%r8),%edx
61 1.2 jmcneill wrmsr
62 1.2 jmcneill
63 1.2 jmcneill movl $MSR_GSBASE,%ecx
64 1.4 ad movl ACPI_SUSPEND_GS(%r8),%eax
65 1.4 ad movl ACPI_SUSPEND_GS+4(%r8),%edx
66 1.2 jmcneill wrmsr
67 1.2 jmcneill
68 1.2 jmcneill movl $MSR_KERNELGSBASE,%ecx
69 1.4 ad movl ACPI_SUSPEND_KGS(%r8),%eax
70 1.4 ad movl ACPI_SUSPEND_KGS+4(%r8),%edx
71 1.2 jmcneill wrmsr
72 1.2 jmcneill
73 1.3 joerg movq ACPI_SUSPEND_CR8(%r8),%rax
74 1.2 jmcneill movq %rax,%cr8
75 1.3 joerg movq ACPI_SUSPEND_CR4(%r8),%rax
76 1.2 jmcneill movq %rax,%cr4
77 1.3 joerg movq ACPI_SUSPEND_CR3(%r8),%rax
78 1.2 jmcneill movq %rax,%cr3
79 1.3 joerg movq ACPI_SUSPEND_CR2(%r8),%rax
80 1.2 jmcneill movq %rax,%cr2
81 1.3 joerg movq ACPI_SUSPEND_CR0(%r8),%rax
82 1.2 jmcneill movq %rax,%cr0
83 1.2 jmcneill
84 1.5 maxv jmp 1f
85 1.2 jmcneill 1:
86 1.2 jmcneill
87 1.2 jmcneill movq CPUVAR(GDT),%rax
88 1.3 joerg movzwq ACPI_SUSPEND_TR(%r8),%rdx
89 1.2 jmcneill andq $~0x0200,4(%rax,%rdx, 1)
90 1.2 jmcneill
91 1.2 jmcneill ltr %dx
92 1.5 maxv lldt ACPI_SUSPEND_LDT(%r8)
93 1.3 joerg lidt ACPI_SUSPEND_IDT(%r8)
94 1.2 jmcneill
95 1.4 ad movq ACPI_SUSPEND_REG+(0*8)(%r8),%rsp
96 1.4 ad movq ACPI_SUSPEND_REG+(1*8)(%r8),%rbx
97 1.4 ad movq ACPI_SUSPEND_REG+(2*8)(%r8),%rbp
98 1.4 ad movq ACPI_SUSPEND_REG+(3*8)(%r8),%r12
99 1.4 ad movq ACPI_SUSPEND_REG+(4*8)(%r8),%r13
100 1.4 ad movq ACPI_SUSPEND_REG+(5*8)(%r8),%r14
101 1.4 ad movq ACPI_SUSPEND_REG+(6*8)(%r8),%r15
102 1.2 jmcneill
103 1.2 jmcneill xorq %rax,%rax
104 1.2 jmcneill
105 1.4 ad pushq ACPI_SUSPEND_REG+(7*8)(%r8)
106 1.2 jmcneill popfq
107 1.2 jmcneill ret
108 1.2 jmcneill
109 1.2 jmcneill .p2align 2, 0x90
110 1.2 jmcneill .type acpi_md_sleep_prepare, @function
111 1.2 jmcneill .globl acpi_md_sleep_prepare
112 1.2 jmcneill acpi_md_sleep_prepare:
113 1.3 joerg movq CPUVAR(SELF),%r8
114 1.4 ad movq %rbx,ACPI_SUSPEND_REG+(1*8)(%r8)
115 1.4 ad movq %rbp,ACPI_SUSPEND_REG+(2*8)(%r8)
116 1.4 ad movq %r12,ACPI_SUSPEND_REG+(3*8)(%r8)
117 1.4 ad movq %r13,ACPI_SUSPEND_REG+(4*8)(%r8)
118 1.4 ad movq %r14,ACPI_SUSPEND_REG+(5*8)(%r8)
119 1.4 ad movq %r15,ACPI_SUSPEND_REG+(6*8)(%r8)
120 1.2 jmcneill
121 1.2 jmcneill movq %cr0,%rax
122 1.3 joerg movq %rax,ACPI_SUSPEND_CR0(%r8)
123 1.2 jmcneill movq %cr2,%rax
124 1.3 joerg movq %rax,ACPI_SUSPEND_CR2(%r8)
125 1.2 jmcneill movq %cr3,%rax
126 1.3 joerg movq %rax,ACPI_SUSPEND_CR3(%r8)
127 1.2 jmcneill movq %cr4,%rax
128 1.3 joerg movq %rax,ACPI_SUSPEND_CR4(%r8)
129 1.2 jmcneill movq %cr8,%rax
130 1.3 joerg movq %rax,ACPI_SUSPEND_CR8(%r8)
131 1.2 jmcneill
132 1.2 jmcneill pushfq
133 1.4 ad popq ACPI_SUSPEND_REG+(7*8)(%r8)
134 1.2 jmcneill
135 1.4 ad movq %rsp,ACPI_SUSPEND_REG+(0*8)(%r8)
136 1.2 jmcneill
137 1.2 jmcneill movl $MSR_FSBASE,%ecx
138 1.2 jmcneill rdmsr
139 1.4 ad movl %eax,ACPI_SUSPEND_FS(%r8)
140 1.4 ad movl %edx,ACPI_SUSPEND_FS+4(%r8)
141 1.2 jmcneill
142 1.2 jmcneill movl $MSR_GSBASE,%ecx
143 1.2 jmcneill rdmsr
144 1.4 ad movl %eax,ACPI_SUSPEND_GS(%r8)
145 1.4 ad movl %edx,ACPI_SUSPEND_GS+4(%r8)
146 1.2 jmcneill
147 1.2 jmcneill movl $MSR_KERNELGSBASE,%ecx
148 1.2 jmcneill rdmsr
149 1.4 ad movl %eax,ACPI_SUSPEND_KGS(%r8)
150 1.4 ad movl %edx,ACPI_SUSPEND_KGS+4(%r8)
151 1.2 jmcneill
152 1.2 jmcneill movl $MSR_EFER,%ecx
153 1.2 jmcneill rdmsr
154 1.4 ad movl %eax,ACPI_SUSPEND_EFER(%r8)
155 1.2 jmcneill
156 1.3 joerg sgdt ACPI_SUSPEND_GDT(%r8)
157 1.3 joerg sidt ACPI_SUSPEND_IDT(%r8)
158 1.3 joerg sldt ACPI_SUSPEND_LDT(%r8)
159 1.3 joerg str ACPI_SUSPEND_TR(%r8)
160 1.2 jmcneill
161 1.2 jmcneill call acpi_md_sleep_enter
162 1.2 jmcneill /* acpi_md_sleep_enter only returns on failure. */
163 1.2 jmcneill movl $-1,%eax
164 1.2 jmcneill ret
165