2 * Copyright (c) 2001 Takanori Watanabe <takawata@jp.freebsd.org>
3 * Copyright (c) 2001 Mitsuru IWASAKI <iwasaki@jp.freebsd.org>
4 * Copyright (c) 2008-2010 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
99 andq $~(CR0_EM | CR0_TS), %rax
102 /* Restore CR2 and CR4. */
103 movq PCB_CR2(%rdi), %rax
105 movq PCB_CR4(%rdi), %rax
108 /* Restore descriptor tables. */
113 #define SDT_SYSBSY 11
115 /* Clear "task busy" bit and reload TR. */
117 andb $(~SDT_SYSBSY | SDT_SYSTSS), 5(%rax)
118 movw PCB_TR(%rdi), %ax
124 /* Restore other callee saved registers. */
125 movq PCB_R15(%rdi), %r15
126 movq PCB_R14(%rdi), %r14
127 movq PCB_R13(%rdi), %r13
128 movq PCB_R12(%rdi), %r12
129 movq PCB_RBP(%rdi), %rbp
130 movq PCB_RSP(%rdi), %rsp
131 movq PCB_RBX(%rdi), %rbx
133 /* Restore debug registers. */
134 movq PCB_DR0(%rdi), %rax
136 movq PCB_DR1(%rdi), %rax
138 movq PCB_DR2(%rdi), %rax
140 movq PCB_DR3(%rdi), %rax
142 movq PCB_DR6(%rdi), %rax
144 movq PCB_DR7(%rdi), %rax
147 /* Restore FPU state. */
149 fxrstor PCB_USERFPU(%rdi)
154 /* Restore return address. */
155 movq PCB_RIP(%rdi), %rax
158 /* Indicate the CPU is resumed. */
160 movl %eax, WAKEUP_CTX(cpu)