1/* $NetBSD: acpi_wakecode.S,v 1.14 2009/08/24 10:16:12 jmcneill Exp $ */ 2 3/*- 4 * Copyright (c) 2002 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Takuya SHIOZAKI. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32 33/* 34 * This code is derived from FreeBSD. Original copyrights: 35 * 36 * Copyright (c) 2001 Takanori Watanabe <takawata@jp.freebsd.org> 37 * Copyright (c) 2001 Mitsuru IWASAKI <iwasaki@jp.freebsd.org> 38 * All rights reserved. 39 * 40 * Redistribution and use in source and binary forms, with or without 41 * modification, are permitted provided that the following conditions 42 * are met: 43 * 1. Redistributions of source code must retain the above copyright 44 * notice, this list of conditions and the following disclaimer. 45 * 2. Redistributions in binary form must reproduce the above copyright 46 * notice, this list of conditions and the following disclaimer in the 47 * documentation and/or other materials provided with the distribution. 48 * 49 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 50 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 51 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 52 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 53 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 54 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 55 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 56 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 57 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 58 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 59 * SUCH DAMAGE. 60 * 61 * FreeBSD: src/sys/i386/acpica/acpi_wakecode.S,v 1.1 2001/07/20 06:07:31 takawata Exp 62 */ 63 64#define _LOCORE 65 66#include <machine/specialreg.h> 67#include <machine/segments.h> 68 69#define ACPI_WAKEUP_ADDR 0x3000 70 71 .text 72 .code16 73 .org 0 /* ACPI spec says: cs==(phys>>8), ip==(phys&0x000F) */ 74 .globl wakeup_16 75wakeup_16: 76 nop 77 cli 78 cld 79 80 /* Set up segment registers for real mode */ 81 movw %cs,%ax 82 movw %ax,%ds 83 movw %ax,%ss 84 85 /* Small call stack */ 86 mov $0x1000,%sp 87 88 /* Clear flags */ 89 pushl $0 90 popfl 91 92 /* Only beep on reset if machdep.acpi_beep_on_reset=1 */ 93 cmpb $1,WAKEUP_beep_on_reset 94 jne 1f 95 movb $0xc0,%al 96 outb %al,$0x42 97 movb $0x04,%al 98 outb %al,$0x42 99 inb $0x61,%al 100 orb $0x3,%al 101 outb %al,$0x61 1021: 103 104 /* Only reset the VBIOS if machdep.acpi_vbios_reset=1 */ 105 cmpb $1,WAKEUP_vbios_reset 106 jne 1f 107 108 /* Kick the VBIOS. */ 109 lcall $0xc000,$3 110 111 movw %cs,%ax 112 movw %ax,%ds 113 movw %ax,%ss 114 115 /* If we need to restore a VESA VBE mode, do it now */ 116 cmpb $0,WAKEUP_vesa_modenum 117 je 1f 118 movw WAKEUP_vesa_modenum,%bx 119 orw $0x4000,%bx 120 movw $0x4f02,%ax 121 int $0x10 122 123 movw %cs,%ax 124 movw %ax,%ds 125 movw %ax,%ss 1261: 127 128 /* Disable beep again if machdep.acpi_beep_on_reset=1 */ 129 cmpb $1,WAKEUP_beep_on_reset 130 jne 1f 131 inb $0x61,%al 132 andb $0xfc,%al 133 outb %al,$0x61 1341: 135 136 /* Load GDT while non-paging */ 137 lgdt tmp_gdt 138 139 /* Enable protected mode */ 140 mov %cr0,%eax 141 orl $(CR0_PE),%eax 142 mov %eax,%cr0 143 144 /* Switch to protected mode by intersegmental jump */ 145 ljmpl $0x8,$wakeup_32 + ACPI_WAKEUP_ADDR 146 147 148 .code32 149 .align 16 150wakeup_32: 151 /* 152 * Switched to protected mode w/o paging 153 */ 154 155 nop 156 /* Set up segment registers for protected mode */ 157 movw $GSEL(GDATA_SEL,SEL_KPL),%ax 158 movw %ax,%ds 159 160 /* Restore PSE and other settings before enabling paging. */ 161 movl WAKEUP_r_cr4 + ACPI_WAKEUP_ADDR,%eax 162 movl %eax,%cr4 163 164 /* Enable paging (assumes identical mapping) */ 165 movl WAKEUP_r_cr3 + ACPI_WAKEUP_ADDR,%eax 166 movl %eax,%cr3 167 movl %cr0,%eax 168 orl $(CR0_PE|CR0_PG|CR0_NE|CR0_TS|CR0_EM|CR0_MP|CR0_WP),%eax 169 movl %eax,%cr0 170 171 /* Flush the prefetch queue */ 172 jmp 1f 1731: jmp 1f 1741: 175 176 nop 177 178 /* Restore registers */ 179 movl WAKEUP_curcpu + ACPI_WAKEUP_ADDR,%edx 180 movl WAKEUP_restorecpu + ACPI_WAKEUP_ADDR,%ebx 181 182 jmp *%ebx 183 184 .align 8 185tmp_gdt: 186 .word 0xffff 187 .long tmp_gdtable + ACPI_WAKEUP_ADDR 188 189 .align 8, 0 190tmp_gdtable: 191 /* null */ 192 .word 0, 0 193 .byte 0, 0, 0, 0 194 /* code */ 195 .word 0xffff, 0 196 .byte 0, 0x9f, 0xcf, 0 197 /* data */ 198 .word 0xffff, 0 199 .byte 0, 0x93, 0xcf, 0 200 201 .align 16, 0 202 .global WAKEUP_r_cr3 203WAKEUP_r_cr3: .long 0 204 .global WAKEUP_r_cr4 205WAKEUP_r_cr4: .long 0 206 207 .global WAKEUP_curcpu 208WAKEUP_curcpu: .long 0 209 .global WAKEUP_restorecpu 210WAKEUP_restorecpu: .long 0 211 212 .global WAKEUP_vbios_reset 213WAKEUP_vbios_reset: .byte 0 214 .global WAKEUP_vesa_modenum 215WAKEUP_vesa_modenum: .word 0 216 .global WAKEUP_beep_on_reset 217WAKEUP_beep_on_reset: .byte 0 218