1 1.8 maxv /* $NetBSD: acpi_wakeup_low.S,v 1.8 2016/08/06 14:54:25 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.3 lukem #include <machine/asm.h> 32 1.8 maxv __KERNEL_RCSID(0, "$NetBSD: acpi_wakeup_low.S,v 1.8 2016/08/06 14:54:25 maxv Exp $"); 33 1.3 lukem 34 1.2 jmcneill #include "assym.h" 35 1.4 joerg #include <machine/segments.h> 36 1.7 maxv #include <machine/specialreg.h> 37 1.2 jmcneill 38 1.2 jmcneill .text 39 1.2 jmcneill .p2align 2, 0x90 40 1.2 jmcneill .globl acpi_md_sleep_exit 41 1.2 jmcneill acpi_md_sleep_exit: 42 1.4 joerg lgdt ACPI_SUSPEND_GDT(%edx) 43 1.4 joerg 44 1.4 joerg /* Reload fixed descriptors for new GDT */ 45 1.4 joerg movw $GSEL(GDATA_SEL, SEL_KPL),%ax 46 1.4 joerg movw %ax,%ds 47 1.2 jmcneill movw %ax,%es 48 1.4 joerg movw %ax,%ss 49 1.4 joerg 50 1.4 joerg movw ACPI_SUSPEND_FS(%edx),%ax 51 1.2 jmcneill movw %ax,%fs 52 1.4 joerg movw ACPI_SUSPEND_GS(%edx),%ax 53 1.2 jmcneill movw %ax,%gs 54 1.2 jmcneill 55 1.7 maxv movl $MSR_EFER,%ecx 56 1.7 maxv movl ACPI_SUSPEND_EFER(%edx),%eax 57 1.7 maxv movl %edx,%esi 58 1.7 maxv movl $0,%edx 59 1.7 maxv wrmsr 60 1.7 maxv movl %esi,%edx 61 1.7 maxv 62 1.4 joerg movl ACPI_SUSPEND_CR2(%edx),%eax 63 1.2 jmcneill movl %eax,%cr2 64 1.4 joerg movl ACPI_SUSPEND_CR4(%edx),%eax 65 1.2 jmcneill movl %eax,%cr4 66 1.4 joerg movl ACPI_SUSPEND_CR3(%edx),%eax 67 1.2 jmcneill movl %eax,%cr3 68 1.2 jmcneill 69 1.6 maxv jmp 1f 70 1.2 jmcneill 1: 71 1.2 jmcneill 72 1.4 joerg lidt ACPI_SUSPEND_IDT(%edx) 73 1.4 joerg lldt ACPI_SUSPEND_LDT(%edx) 74 1.2 jmcneill 75 1.2 jmcneill movl CPUVAR(GDT),%eax 76 1.4 joerg movzwl ACPI_SUSPEND_TR(%edx),%ecx 77 1.4 joerg andl $~0x0200,4(%eax,%ecx, 1) 78 1.4 joerg ltr %cx 79 1.4 joerg 80 1.5 ad movl ACPI_SUSPEND_REG+(0*4)(%edx),%ebx 81 1.5 ad movl ACPI_SUSPEND_REG+(1*4)(%edx),%esi 82 1.5 ad movl ACPI_SUSPEND_REG+(2*4)(%edx),%edi 83 1.5 ad movl ACPI_SUSPEND_REG+(3*4)(%edx),%ebp 84 1.5 ad movl ACPI_SUSPEND_REG+(4*4)(%edx),%esp 85 1.2 jmcneill 86 1.5 ad pushl ACPI_SUSPEND_REG+(5*4)(%edx) 87 1.2 jmcneill popfl 88 1.2 jmcneill 89 1.2 jmcneill xorl %eax,%eax 90 1.2 jmcneill 91 1.2 jmcneill ret 92 1.2 jmcneill 93 1.2 jmcneill .p2align 2, 0x90 94 1.2 jmcneill .type acpi_md_sleep_prepare, @function 95 1.2 jmcneill .globl acpi_md_sleep_prepare 96 1.2 jmcneill acpi_md_sleep_prepare: 97 1.4 joerg movl CPUVAR(SELF),%edx 98 1.4 joerg movw %fs,ACPI_SUSPEND_FS(%edx) 99 1.4 joerg movw %gs,ACPI_SUSPEND_GS(%edx) 100 1.4 joerg 101 1.5 ad movl %ebx,ACPI_SUSPEND_REG+(0*4)(%edx) 102 1.5 ad movl %esi,ACPI_SUSPEND_REG+(1*4)(%edx) 103 1.5 ad movl %edi,ACPI_SUSPEND_REG+(2*4)(%edx) 104 1.5 ad movl %ebp,ACPI_SUSPEND_REG+(3*4)(%edx) 105 1.5 ad movl %esp,ACPI_SUSPEND_REG+(4*4)(%edx) 106 1.2 jmcneill 107 1.7 maxv movl $MSR_EFER,%ecx 108 1.8 maxv pushl %edx 109 1.8 maxv rdmsr /* overwrites %edx */ 110 1.8 maxv popl %edx 111 1.7 maxv movl %eax,ACPI_SUSPEND_EFER(%edx) 112 1.7 maxv 113 1.2 jmcneill movl %cr0,%eax 114 1.4 joerg movl %eax,ACPI_SUSPEND_CR0(%edx) 115 1.2 jmcneill movl %cr2,%eax 116 1.4 joerg movl %eax,ACPI_SUSPEND_CR2(%edx) 117 1.2 jmcneill movl %cr3,%eax 118 1.4 joerg movl %eax,ACPI_SUSPEND_CR3(%edx) 119 1.2 jmcneill movl %cr4,%eax 120 1.4 joerg movl %eax,ACPI_SUSPEND_CR4(%edx) 121 1.2 jmcneill 122 1.2 jmcneill pushfl 123 1.5 ad popl ACPI_SUSPEND_REG+(5*4)(%edx) 124 1.2 jmcneill 125 1.4 joerg sgdt ACPI_SUSPEND_GDT(%edx) 126 1.4 joerg sidt ACPI_SUSPEND_IDT(%edx) 127 1.4 joerg sldt ACPI_SUSPEND_LDT(%edx) 128 1.4 joerg str ACPI_SUSPEND_TR(%edx) 129 1.2 jmcneill 130 1.2 jmcneill movl 4(%esp),%eax 131 1.2 jmcneill pushl %eax 132 1.2 jmcneill call acpi_md_sleep_enter 133 1.2 jmcneill /* acpi_md_sleep_enter only returns on failure. */ 134 1.2 jmcneill popl %eax 135 1.2 jmcneill movl $-1,%eax 136 1.2 jmcneill ret 137