1/* $NetBSD: acpi_wakecode.S,v 1.12 2008/04/28 20:23:23 martin 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 1141: 115 116 /* Disable beep again if machdep.acpi_beep_on_reset=1 */ 117 cmpb $1,WAKEUP_beep_on_reset 118 jne 1f 119 inb $0x61,%al 120 andb $0xfc,%al 121 outb %al,$0x61 1221: 123 124 /* Load GDT while non-paging */ 125 lgdt tmp_gdt 126 127 /* Enable protected mode */ 128 mov %cr0,%eax 129 orl $(CR0_PE),%eax 130 mov %eax,%cr0 131 132 /* Switch to protected mode by intersegmental jump */ 133 ljmpl $0x8,$wakeup_32 + ACPI_WAKEUP_ADDR 134 135 136 .code32 137 .align 16 138wakeup_32: 139 /* 140 * Switched to protected mode w/o paging 141 */ 142 143 nop 144 /* Set up segment registers for protected mode */ 145 movw $GSEL(GDATA_SEL,SEL_KPL),%ax 146 movw %ax,%ds 147 148 /* Restore PSE and other settings before enabling paging. */ 149 movl WAKEUP_r_cr4 + ACPI_WAKEUP_ADDR,%eax 150 movl %eax,%cr4 151 152 /* Enable paging (assumes identical mapping) */ 153 movl WAKEUP_r_cr3 + ACPI_WAKEUP_ADDR,%eax 154 movl %eax,%cr3 155 movl %cr0,%eax 156 orl $(CR0_PE|CR0_PG|CR0_NE|CR0_TS|CR0_EM|CR0_MP|CR0_WP),%eax 157 movl %eax,%cr0 158 159 /* Flush the prefetch queue */ 160 jmp 1f 1611: jmp 1f 1621: 163 164 nop 165 166 /* Restore registers */ 167 movl WAKEUP_curcpu + ACPI_WAKEUP_ADDR,%edx 168 movl WAKEUP_restorecpu + ACPI_WAKEUP_ADDR,%ebx 169 170 jmp *%ebx 171 172 .align 8 173tmp_gdt: 174 .word 0xffff 175 .long tmp_gdtable + ACPI_WAKEUP_ADDR 176 177 .align 8, 0 178tmp_gdtable: 179 /* null */ 180 .word 0, 0 181 .byte 0, 0, 0, 0 182 /* code */ 183 .word 0xffff, 0 184 .byte 0, 0x9f, 0xcf, 0 185 /* data */ 186 .word 0xffff, 0 187 .byte 0, 0x93, 0xcf, 0 188 189 .align 16, 0 190 .global WAKEUP_r_cr3 191WAKEUP_r_cr3: .long 0 192 .global WAKEUP_r_cr4 193WAKEUP_r_cr4: .long 0 194 195 .global WAKEUP_curcpu 196WAKEUP_curcpu: .long 0 197 .global WAKEUP_restorecpu 198WAKEUP_restorecpu: .long 0 199 200 .global WAKEUP_vbios_reset 201WAKEUP_vbios_reset: .byte 0 202 .global WAKEUP_beep_on_reset 203WAKEUP_beep_on_reset: .byte 0 204