1/* $NetBSD: acpi_wakecode.S,v 1.5 2005/12/11 12:17:40 christos 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/asm.h> 74#include <machine/specialreg.h> 75#include <machine/param.h> 76#include <machine/segments.h> 77 78 .code16 79 .org 0 /* ACPI spec says: cs==(phys>>8), ip==(phys&0x000F) */ 80wakeup_16: 81 nop 82 cli 83 cld 84 85 /* Set up segment registers for real mode */ 86 movw %cs,%ax 87 movw %ax,%ds 88 movw %ax,%ss 89 90 /* The following needs to be configurable */ 91#ifdef notyet 92 /* Kick the VBIOS. */ 93 movw $0x1000, %sp /* Small call stack. */ 94 lcall $0xc000,$3 95 96 movw %cs,%ax 97 movw %ax,%ds 98 movw %ax,%ss 99#endif 100 101 /* Get physical address of the code */ 102 xorl %esi,%esi 103 movw %cs,%si 104 shll $4,%esi 105 106 /* Fill 16->32 address */ 107 movl %esi,%eax 108 addl $wakeup_32,%eax 109 movl %eax,wakeup_sw32+2 110 jmp 1f /* flush prefetch queue */ 1111: jmp 1f 1121: 113 114 /* Load GDT while non-paging */ 115 movl %esi,%eax 116 addl $tmp_gdtable,%eax 117 movl %eax,tmp_gdt+2 118 lgdt tmp_gdt 119 120 /* Enable protected mode */ 121 mov %cr0,%eax 122 orl $(CR0_PE),%eax 123 mov %eax,%cr0 124 125wakeup_sw32: 126 /* Switch to protected mode by intersegmental jump */ 127 ljmpl $0x8,$0x12345678 /* Code location, to be replaced */ 128 129 130 .code32 131 .align 16 132wakeup_32: 133 /* 134 * Switched to protected mode w/o paging 135 */ 136 137 nop 138 /* Set up segment registers for protected mode */ 139 movw $GSEL(GDATA_SEL,SEL_KPL),%ax 140 movw %ax,%ds 141 movw %ax,%es 142 movw %ax,%gs 143 movw %ax,%ss 144 movw %ax,%fs 145 146 /* Fixup TSS type field; 386 busy TSS (11) -> 386 available TSS (9) */ 147#define TSS_TYPEFIX_MASK 0xf9 148 movl physical_gdt+2(%esi),%ebx 149 movzxw previous_tr(%esi),%ecx 150 leal (%ebx,%ecx),%eax /* get TSS segment descriptor */ 151 andb $TSS_TYPEFIX_MASK,5(%eax) 152 153 /* Enable paging (assumes identical mapping) */ 154 movl previous_cr3(%esi),%eax 155 movl %eax,%cr3 156 movl previous_cr0(%esi),%eax 157 movl %eax,%cr0 158 159 /* Flush the prefetch queue */ 160 jmp 1f 1611: jmp 1f 1621: 163 164 /* Restore registers */ 165 lgdt previous_gdt(%esi) 166 lidt previous_idt(%esi) 167 lldt previous_ldt(%esi) 168 ltr previous_tr(%esi) 169 170 mov previous_cr2(%esi),%eax 171 mov %eax,%cr2 172 mov previous_cr4(%esi),%eax 173 mov %eax,%cr4 174 175 movw previous_es(%esi),%ax 176 movw %ax,%es 177 movw previous_fs(%esi),%ax 178 movw %ax,%fs 179 movw previous_gs(%esi),%ax 180 movw %ax,%gs 181 movw previous_ss(%esi),%ax 182 movw %ax,%ss 183 movl where_to_recover(%esi),%ebx 184 movw previous_ds(%esi),%ax 185 movw %ax,%ds 186 jmp *%ebx 187 188 189 .align 8 190tmp_gdt: 191 .word 0xffff 192 .long 0 193 194 .align 8, 0 195tmp_gdtable: 196 /* null */ 197 .word 0, 0 198 .byte 0, 0, 0, 0 199 /* code */ 200 .word 0xffff, 0 201 .byte 0, 0x9f, 0xcf, 0 202 /* data */ 203 .word 0xffff, 0 204 .byte 0, 0x93, 0xcf, 0 205 206 .align 16, 0 207physical_gdt: .word 0 208 .long 0 209previous_cr2: .long 0 210previous_cr3: .long 0 211previous_cr4: .long 0 212previous_cr0: .long 0 213previous_tr: .word 0 214previous_gdt: .word 0 215 .long 0 216previous_ldt: .word 0 217previous_idt: .word 0 218 .long 0 219previous_ds: .word 0 220previous_es: .word 0 221previous_fs: .word 0 222previous_gs: .word 0 223previous_ss: .word 0 224where_to_recover: .long 0 225