acpi_wakeup_low.S revision 1.3 1 /* $NetBSD: acpi_wakeup_low.S,v 1.3 2007/12/11 23:06:11 lukem Exp $ */
2
3 /*-
4 * Copyright (c) 2007 Joerg Sonnenberger <joerg (at) netbsd.org>
5 * Copyright (c) 2001 Takanori Watanabe <takawata (at) jp.freebsd.org>
6 * Copyright (c) 2001 Mitsuru IWASAKI <iwasaki (at) jp.freebsd.org>
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * SUCH DAMAGE.
29 */
30
31 #include <machine/asm.h>
32 __KERNEL_RCSID(0, "$NetBSD: acpi_wakeup_low.S,v 1.3 2007/12/11 23:06:11 lukem Exp $");
33
34 #include "assym.h"
35
36 .text
37 .p2align 2, 0x90
38 .globl acpi_md_sleep_exit
39 acpi_md_sleep_exit:
40 movw r_es,%ax
41 movw %ax,%es
42 movw r_fs,%ax
43 movw %ax,%fs
44 movw r_gs,%ax
45 movw %ax,%gs
46 movw r_ss,%ax
47 movw %ax,%ss
48
49 movl r_cr2,%eax
50 movl %eax,%cr2
51 movl r_cr4,%eax
52 movl %eax,%cr4
53 movl r_cr3,%eax
54 movl %eax,%cr3
55
56 jmp 1f
57 1:
58
59 lidt r_idt
60 lldt r_ldt
61
62 movl CPUVAR(GDT),%eax
63 movzwl r_tr,%edx
64 andl $~0x0200,4(%eax,%edx, 1)
65 ltr %dx
66
67 movl r_esp,%esp
68
69 movl r_ebx,%ebx
70 movl r_ecx,%ecx
71 movl r_edx,%edx
72 movl r_ebp,%ebp
73 movl r_esi,%esi
74 movl r_edi,%edi
75
76 pushl r_efl
77 popfl
78
79 movl ret_addr,%eax
80 movl %eax,(%esp)
81 xorl %eax,%eax
82
83 ret
84
85 .p2align 2, 0x90
86 .type acpi_md_sleep_prepare, @function
87 .globl acpi_md_sleep_prepare
88 acpi_md_sleep_prepare:
89 movw %ds,r_ds
90 movw %es,r_es
91 movw %fs,r_fs
92 movw %gs,r_gs
93 movw %ss,r_ss
94
95 movl %ebx,r_ebx
96 movl %ecx,r_ecx
97 movl %edx,r_edx
98 movl %ebp,r_ebp
99 movl %esi,r_esi
100 movl %edi,r_edi
101
102 movl %cr0,%eax
103 movl %eax,r_cr0
104 movl %cr2,%eax
105 movl %eax,r_cr2
106 movl %cr3,%eax
107 movl %eax,r_cr3
108 movl %cr4,%eax
109 movl %eax,r_cr4
110
111 pushfl
112 popl r_efl
113
114 movl %esp,r_esp
115
116 sgdt r_gdt
117 sidt r_idt
118 sldt r_ldt
119 str r_tr
120
121 movl (%esp),%eax
122 movl %eax,ret_addr
123 movl 4(%esp),%eax
124 pushl %eax
125 call acpi_md_sleep_enter
126 /* acpi_md_sleep_enter only returns on failure. */
127 popl %eax
128 movl $-1,%eax
129 ret
130
131 .data
132 .align 16
133 .globl acpi_wakeup_ds
134 acpi_wakeup_ds:
135 r_ds: .word 0
136 r_es: .word 0
137 r_fs: .word 0
138 r_gs: .word 0
139 r_ss: .word 0
140 r_tr: .word 0
141 r_ldt: .word 0
142
143 r_ebx: .long 0
144 r_ecx: .long 0
145 r_edx: .long 0
146 r_ebp: .long 0
147 r_esi: .long 0
148 r_edi: .long 0
149 r_esp: .long 0
150 r_efl: .long 0
151
152 .globl acpi_wakeup_cr0
153 acpi_wakeup_cr0:
154 r_cr0: .long 0
155 r_cr2: .long 0
156 r_cr3: .long 0
157 .globl acpi_wakeup_cr4
158 acpi_wakeup_cr4:
159 r_cr4: .long 0
160
161 .globl acpi_wakeup_gdt
162 acpi_wakeup_gdt:
163 r_gdt: .word 0
164 .long 0
165 r_idt: .word 0
166 .long 0
167
168 ret_addr: .long 0
169