2 * Copyright (c) 2001 Takanori Watanabe <takawata@jp.freebsd.org>
3 * Copyright (c) 2001 Mitsuru IWASAKI <iwasaki@jp.freebsd.org>
4 * Copyright (c) 2008-2012 Jung-uk Kim <jkim@FreeBSD.org>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 #include <machine/asmacros.h>
32 #include <machine/specialreg.h>
34 #include "acpi_wakedata.h"
37 #define WAKEUP_CTX(member) wakeup_ ## member - wakeup_ctx(%rsi)
39 ENTRY(acpi_restorecpu)
40 /* Switch to KPML4phys. */
49 movq WAKEUP_CTX(pcb), %rdi
51 /* Force kernel segment registers. */
61 movl $MSR_FSBASE, %ecx
62 movl PCB_FSBASE(%rdi), %eax
63 movl 4 + PCB_FSBASE(%rdi), %edx
65 movl $MSR_GSBASE, %ecx
66 movl PCB_GSBASE(%rdi), %eax
67 movl 4 + PCB_GSBASE(%rdi), %edx
69 movl $MSR_KGSBASE, %ecx
70 movl PCB_KGSBASE(%rdi), %eax
71 movl 4 + PCB_KGSBASE(%rdi), %edx
76 movl WAKEUP_CTX(efer), %eax
79 /* Restore fast syscall stuff. */
81 movl WAKEUP_CTX(star), %eax
82 movl 4 + WAKEUP_CTX(star), %edx
85 movl WAKEUP_CTX(lstar), %eax
86 movl 4 + WAKEUP_CTX(lstar), %edx
89 movl WAKEUP_CTX(cstar), %eax
90 movl 4 + WAKEUP_CTX(cstar), %edx
92 movl $MSR_SF_MASK, %ecx
93 movl WAKEUP_CTX(sfmask), %eax
96 /* Restore CR0 except for FPU mode. */
97 movq PCB_CR0(%rdi), %rax
98 andq $~(CR0_EM | CR0_TS), %rax
101 /* Restore CR2 and CR4. */
102 movq PCB_CR2(%rdi), %rax
104 movq PCB_CR4(%rdi), %rax
107 /* Restore descriptor tables. */
112 #define SDT_SYSBSY 11
114 /* Clear "task busy" bit and reload TR. */
116 andb $(~SDT_SYSBSY | SDT_SYSTSS), 5(%rax)
117 movw PCB_TR(%rdi), %ax
123 /* Restore debug registers. */
124 movq PCB_DR0(%rdi), %rax
126 movq PCB_DR1(%rdi), %rax
128 movq PCB_DR2(%rdi), %rax
130 movq PCB_DR3(%rdi), %rax
132 movq PCB_DR6(%rdi), %rax
134 movq PCB_DR7(%rdi), %rax
137 /* Restore FPU state. */
139 movq WAKEUP_CTX(fpusave), %rbx
140 movq WAKEUP_CTX(xsmask), %rax
154 movq PCB_CR0(%rdi), %rax
157 /* Restore other callee saved registers. */
158 movq PCB_R15(%rdi), %r15
159 movq PCB_R14(%rdi), %r14
160 movq PCB_R13(%rdi), %r13
161 movq PCB_R12(%rdi), %r12
162 movq PCB_RBP(%rdi), %rbp
163 movq PCB_RSP(%rdi), %rsp
164 movq PCB_RBX(%rdi), %rbx
166 /* Restore return address. */
167 movq PCB_RIP(%rdi), %rax
170 /* Indicate the CPU is resumed. */
172 movl %eax, WAKEUP_CTX(cpu)