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