Home | History | Annotate | Line # | Download | only in acpi
acpi_wakeup_low.S revision 1.5
      1  1.5      maxv /*	$NetBSD: acpi_wakeup_low.S,v 1.5 2016/07/24 13:04:58 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.2  jmcneill 	wrmsr
     56  1.2  jmcneill 
     57  1.2  jmcneill 	movl	$MSR_FSBASE,%ecx
     58  1.4        ad 	movl	ACPI_SUSPEND_FS(%r8),%eax
     59  1.4        ad 	movl	ACPI_SUSPEND_FS+4(%r8),%edx
     60  1.2  jmcneill 	wrmsr
     61  1.2  jmcneill 
     62  1.2  jmcneill 	movl	$MSR_GSBASE,%ecx
     63  1.4        ad 	movl	ACPI_SUSPEND_GS(%r8),%eax
     64  1.4        ad 	movl	ACPI_SUSPEND_GS+4(%r8),%edx
     65  1.2  jmcneill 	wrmsr
     66  1.2  jmcneill 
     67  1.2  jmcneill 	movl	$MSR_KERNELGSBASE,%ecx
     68  1.4        ad 	movl	ACPI_SUSPEND_KGS(%r8),%eax
     69  1.4        ad 	movl	ACPI_SUSPEND_KGS+4(%r8),%edx
     70  1.2  jmcneill 	wrmsr
     71  1.2  jmcneill 
     72  1.3     joerg 	movq	ACPI_SUSPEND_CR8(%r8),%rax
     73  1.2  jmcneill 	movq	%rax,%cr8
     74  1.3     joerg 	movq	ACPI_SUSPEND_CR4(%r8),%rax
     75  1.2  jmcneill 	movq	%rax,%cr4
     76  1.3     joerg 	movq	ACPI_SUSPEND_CR3(%r8),%rax
     77  1.2  jmcneill 	movq	%rax,%cr3
     78  1.3     joerg 	movq	ACPI_SUSPEND_CR2(%r8),%rax
     79  1.2  jmcneill 	movq	%rax,%cr2
     80  1.3     joerg 	movq	ACPI_SUSPEND_CR0(%r8),%rax
     81  1.2  jmcneill 	movq	%rax,%cr0
     82  1.2  jmcneill 
     83  1.5      maxv 	jmp	1f
     84  1.2  jmcneill 1:
     85  1.2  jmcneill 
     86  1.2  jmcneill 	movq	CPUVAR(GDT),%rax
     87  1.3     joerg 	movzwq	ACPI_SUSPEND_TR(%r8),%rdx
     88  1.2  jmcneill 	andq	$~0x0200,4(%rax,%rdx, 1)
     89  1.2  jmcneill 
     90  1.2  jmcneill 	ltr	%dx
     91  1.5      maxv 	lldt	ACPI_SUSPEND_LDT(%r8)
     92  1.3     joerg 	lidt	ACPI_SUSPEND_IDT(%r8)
     93  1.2  jmcneill 
     94  1.4        ad 	movq	ACPI_SUSPEND_REG+(0*8)(%r8),%rsp
     95  1.4        ad 	movq	ACPI_SUSPEND_REG+(1*8)(%r8),%rbx
     96  1.4        ad 	movq	ACPI_SUSPEND_REG+(2*8)(%r8),%rbp
     97  1.4        ad 	movq	ACPI_SUSPEND_REG+(3*8)(%r8),%r12
     98  1.4        ad 	movq	ACPI_SUSPEND_REG+(4*8)(%r8),%r13
     99  1.4        ad 	movq	ACPI_SUSPEND_REG+(5*8)(%r8),%r14
    100  1.4        ad 	movq	ACPI_SUSPEND_REG+(6*8)(%r8),%r15
    101  1.2  jmcneill 
    102  1.2  jmcneill 	xorq	%rax,%rax
    103  1.2  jmcneill 
    104  1.4        ad 	pushq	ACPI_SUSPEND_REG+(7*8)(%r8)
    105  1.2  jmcneill 	popfq
    106  1.2  jmcneill 	ret
    107  1.2  jmcneill 
    108  1.2  jmcneill 	.p2align 2, 0x90
    109  1.2  jmcneill 	.type acpi_md_sleep_prepare, @function
    110  1.2  jmcneill 	.globl acpi_md_sleep_prepare
    111  1.2  jmcneill acpi_md_sleep_prepare:
    112  1.3     joerg 	movq	CPUVAR(SELF),%r8
    113  1.4        ad 	movq	%rbx,ACPI_SUSPEND_REG+(1*8)(%r8)
    114  1.4        ad 	movq	%rbp,ACPI_SUSPEND_REG+(2*8)(%r8)
    115  1.4        ad 	movq	%r12,ACPI_SUSPEND_REG+(3*8)(%r8)
    116  1.4        ad 	movq	%r13,ACPI_SUSPEND_REG+(4*8)(%r8)
    117  1.4        ad 	movq	%r14,ACPI_SUSPEND_REG+(5*8)(%r8)
    118  1.4        ad 	movq	%r15,ACPI_SUSPEND_REG+(6*8)(%r8)
    119  1.2  jmcneill 
    120  1.2  jmcneill 	movq	%cr0,%rax
    121  1.3     joerg 	movq	%rax,ACPI_SUSPEND_CR0(%r8)
    122  1.2  jmcneill 	movq	%cr2,%rax
    123  1.3     joerg 	movq	%rax,ACPI_SUSPEND_CR2(%r8)
    124  1.2  jmcneill 	movq	%cr3,%rax
    125  1.3     joerg 	movq	%rax,ACPI_SUSPEND_CR3(%r8)
    126  1.2  jmcneill 	movq	%cr4,%rax
    127  1.3     joerg 	movq	%rax,ACPI_SUSPEND_CR4(%r8)
    128  1.2  jmcneill 	movq	%cr8,%rax
    129  1.3     joerg 	movq	%rax,ACPI_SUSPEND_CR8(%r8)
    130  1.2  jmcneill 
    131  1.2  jmcneill 	pushfq
    132  1.4        ad 	popq	ACPI_SUSPEND_REG+(7*8)(%r8)
    133  1.2  jmcneill 
    134  1.4        ad 	movq	%rsp,ACPI_SUSPEND_REG+(0*8)(%r8)
    135  1.2  jmcneill 
    136  1.2  jmcneill 	movl	$MSR_FSBASE,%ecx
    137  1.2  jmcneill 	rdmsr
    138  1.4        ad 	movl	%eax,ACPI_SUSPEND_FS(%r8)
    139  1.4        ad 	movl	%edx,ACPI_SUSPEND_FS+4(%r8)
    140  1.2  jmcneill 
    141  1.2  jmcneill 	movl	$MSR_GSBASE,%ecx
    142  1.2  jmcneill 	rdmsr
    143  1.4        ad 	movl	%eax,ACPI_SUSPEND_GS(%r8)
    144  1.4        ad 	movl	%edx,ACPI_SUSPEND_GS+4(%r8)
    145  1.2  jmcneill 
    146  1.2  jmcneill 	movl	$MSR_KERNELGSBASE,%ecx
    147  1.2  jmcneill 	rdmsr
    148  1.4        ad 	movl	%eax,ACPI_SUSPEND_KGS(%r8)
    149  1.4        ad 	movl	%edx,ACPI_SUSPEND_KGS+4(%r8)
    150  1.2  jmcneill 
    151  1.2  jmcneill 	movl	$MSR_EFER,%ecx
    152  1.2  jmcneill 	rdmsr
    153  1.4        ad 	movl	%eax,ACPI_SUSPEND_EFER(%r8)
    154  1.2  jmcneill 
    155  1.3     joerg 	sgdt	ACPI_SUSPEND_GDT(%r8)
    156  1.3     joerg 	sidt	ACPI_SUSPEND_IDT(%r8)
    157  1.3     joerg 	sldt	ACPI_SUSPEND_LDT(%r8)
    158  1.3     joerg 	str	ACPI_SUSPEND_TR(%r8)
    159  1.2  jmcneill 
    160  1.2  jmcneill 	call	acpi_md_sleep_enter
    161  1.2  jmcneill 	/* acpi_md_sleep_enter only returns on failure. */
    162  1.2  jmcneill 	movl	$-1,%eax
    163  1.2  jmcneill 	ret
    164