acpi_wakecode.S revision 1.3
1/* $NetBSD: acpi_wakecode.S,v 1.3 2004/04/10 11:50:55 kochi 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 * 3. All advertising materials mentioning features or use of this software 19 * must display the following acknowledgement: 20 * This product includes software developed by the NetBSD 21 * Foundation, Inc. and its contributors. 22 * 4. Neither the name of The NetBSD Foundation nor the names of its 23 * contributors may be used to endorse or promote products derived 24 * from this software without specific prior written permission. 25 * 26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 * POSSIBILITY OF SUCH DAMAGE. 37 */ 38 39 40/* 41 * This code is derived from FreeBSD. Original copyrights: 42 * 43 * Copyright (c) 2001 Takanori Watanabe <takawata@jp.freebsd.org> 44 * Copyright (c) 2001 Mitsuru IWASAKI <iwasaki@jp.freebsd.org> 45 * All rights reserved. 46 * 47 * Redistribution and use in source and binary forms, with or without 48 * modification, are permitted provided that the following conditions 49 * are met: 50 * 1. Redistributions of source code must retain the above copyright 51 * notice, this list of conditions and the following disclaimer. 52 * 2. Redistributions in binary form must reproduce the above copyright 53 * notice, this list of conditions and the following disclaimer in the 54 * documentation and/or other materials provided with the distribution. 55 * 56 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 57 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 58 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 59 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 60 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 61 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 62 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 63 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 64 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 65 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 66 * SUCH DAMAGE. 67 * 68 * FreeBSD: src/sys/i386/acpica/acpi_wakecode.S,v 1.1 2001/07/20 06:07:31 takawata Exp 69 */ 70 71#define LOCORE 72 73#include <machine/specialreg.h> 74#include <machine/param.h> 75#include <machine/segments.h> 76 77 .code16 78 .org 0 /* ACPI spec says: cs==(phys>>8), ip==(phys&0x000F) */ 79wakeup_16: 80 nop 81 cli 82 83 /* Set up segment registers for real mode */ 84 movw %cs,%ax 85 movw %ax,%ds 86 movw %ax,%ss 87 88 /* Get physical address of the code */ 89 xorl %esi,%esi 90 movw %cs,%si 91 shll $4,%esi 92 93 /* Fill 16->32 address */ 94 movl %esi,%eax 95 addl $wakeup_32,%eax 96 movl %eax,wakeup_sw32+2 97 jmp 1f /* flush prefetch queue */ 981: jmp 1f 991: 100 101 /* Load GDT while non-paging */ 102 movl %esi,%eax 103 addl $tmp_gdtable,%eax 104 movl %eax,tmp_gdt+2 105 lgdt tmp_gdt 106 107 /* Enable protected mode */ 108 mov %cr0,%eax 109 orl $(CR0_PE),%eax 110 mov %eax,%cr0 111 112wakeup_sw32: 113 /* Switch to protected mode by intersegmental jump */ 114 ljmpl $0x8,$0x12345678 /* Code location, to be replaced */ 115 116 117 .code32 118 .align 16 119wakeup_32: 120 /* 121 * Switched to protected mode w/o paging 122 */ 123 124 nop 125 /* Set up segment registers for protected mode */ 126 movw $GSEL(GDATA_SEL,SEL_KPL),%ax 127 movw %ax,%ds 128 movw %ax,%es 129 movw %ax,%gs 130 movw %ax,%ss 131 movw %ax,%fs 132 133 /* Fixup TSS type field; 386 busy TSS (11) -> 386 available TSS (9) */ 134#define TSS_TYPEFIX_MASK 0xf9 135 movl physical_gdt+2(%esi),%ebx 136 movzxw previous_tr(%esi),%ecx 137 leal (%ebx,%ecx),%eax /* get TSS segment descriptor */ 138 andb $TSS_TYPEFIX_MASK,5(%eax) 139 140 /* Enable paging (assumes identical mapping) */ 141 movl previous_cr3(%esi),%eax 142 movl %eax,%cr3 143 movl previous_cr0(%esi),%eax 144 movl %eax,%cr0 145 146 /* Flush the prefetch queue */ 147 jmp 1f 1481: jmp 1f 1491: 150 151 /* Restore registers */ 152 lgdt previous_gdt(%esi) 153 lidt previous_idt(%esi) 154 lldt previous_ldt(%esi) 155 ltr previous_tr(%esi) 156 157 mov previous_cr2(%esi),%eax 158 mov %eax,%cr2 159 mov previous_cr4(%esi),%eax 160 mov %eax,%cr4 161 162 movw previous_es(%esi),%ax 163 movw %ax,%es 164 movw previous_fs(%esi),%ax 165 movw %ax,%fs 166 movw previous_gs(%esi),%ax 167 movw %ax,%gs 168 movw previous_ss(%esi),%ax 169 movw %ax,%ss 170 movl where_to_recover(%esi),%ebx 171 movw previous_ds(%esi),%ax 172 movw %ax,%ds 173 jmp *%ebx 174 175 176 .align 8 177tmp_gdt: 178 .word 0xffff 179 .long 0 180 181 .align 8, 0 182tmp_gdtable: 183 /* null */ 184 .word 0, 0 185 .byte 0, 0, 0, 0 186 /* code */ 187 .word 0xffff, 0 188 .byte 0, 0x9f, 0xcf, 0 189 /* data */ 190 .word 0xffff, 0 191 .byte 0, 0x93, 0xcf, 0 192 193 .align 16, 0 194physical_gdt: .word 0 195 .long 0 196previous_cr2: .long 0 197previous_cr3: .long 0 198previous_cr4: .long 0 199previous_cr0: .long 0 200previous_tr: .word 0 201previous_gdt: .word 0 202 .long 0 203previous_ldt: .word 0 204previous_idt: .word 0 205 .long 0 206previous_ds: .word 0 207previous_es: .word 0 208previous_fs: .word 0 209previous_gs: .word 0 210previous_ss: .word 0 211where_to_recover: .long 0 212