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