Home | History | Annotate | Line # | Download | only in acpi
acpi_wakecode.S revision 1.1.2.7
      1 /*	$NetBSD: acpi_wakecode.S,v 1.1.2.7 2007/09/25 23:29:40 joerg 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 (at) jp.freebsd.org>
     44  * Copyright (c) 2001 Mitsuru IWASAKI <iwasaki (at) 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/psl.h>
     74 #include <machine/specialreg.h>
     75 #include <machine/segments.h>
     76 
     77 #define	ACPI_WAKEUP_ADDR	0x3000
     78 
     79 	.text
     80 	.code16
     81 	.org 0	/* ACPI spec says: cs==(phys>>8), ip==(phys&0x000F) */
     82 	.globl wakeup_16
     83 wakeup_16:
     84 	nop
     85 	cli
     86 	cld
     87 
     88 	/* Set up segment registers for real mode */
     89 	movw	%cs,%ax
     90 	movw	%ax,%ds
     91 	movw	%ax,%ss
     92 
     93 	/* Small call stack */
     94 	mov	$0x1000,%sp
     95 
     96 	/* Clear flags */
     97 	pushl	$0
     98 	popfl
     99 
    100 	/* Only beep on reset if machdep.acpi_beep_on_reset=1 */
    101 	cmpb	$1,WAKEUP_beep_on_reset
    102 	jne	1f
    103 	movb	$0xc0,%al
    104 	outb	%al,$0x42
    105 	movb	$0x04,%al
    106 	outb	%al,$0x42
    107 	inb	$0x61,%al
    108 	orb	$0x3,%al
    109 	outb	%al,$0x61
    110 1:
    111 
    112 	/* Only reset the VBIOS if machdep.acpi_vbios_reset=1 */
    113 	cmpb	$1,WAKEUP_vbios_reset
    114 	jne	1f
    115 
    116 	/* Kick the VBIOS. */
    117 	lcall	$0xc000,$3
    118 
    119 	movw	%cs,%ax
    120 	movw	%ax,%ds
    121 	movw	%ax,%ss
    122 1:
    123 
    124 	/* Disable beep again if machdep.acpi_beep_on_reset=1 */
    125 	cmpb	$1,WAKEUP_beep_on_reset
    126 	jne	1f
    127 	inb	$0x61,%al
    128 	andb	$0xfc,%al
    129 	outb	%al,$0x61
    130 1:
    131 
    132 	data32 addr32 lgdt	tmp_gdt
    133 
    134 	/* Enable protected mode */
    135 	mov	%cr0,%eax
    136 	orl	$(CR0_PE),%eax
    137 	mov	%eax,%cr0
    138 
    139 wakeup_sw32:
    140 	/* Switch to protected mode by intersegmental jump */
    141 	ljmpl	$0x8,$wakeup_32 + ACPI_WAKEUP_ADDR
    142 
    143 	.code32
    144 	.align	16
    145 wakeup_32:
    146 	/*
    147 	 * Switched to protected mode w/o paging
    148 	 */
    149 
    150 	nop
    151 	/* Set up segment registers for protected mode */
    152 	movw	$0x10, %ax
    153 	movw	%ax,%ds
    154 	movw	%ax,%ss
    155 
    156 	movl	ACPI_WAKEUP_ADDR + 4096,%esp
    157 
    158 	/* First, reset the PSL. */
    159 	pushl	$PSL_MBO
    160 	popfl
    161 
    162 	movl	%cr4,%eax
    163 	orl	$(CR4_PAE|CR4_OSFXSR|CR4_OSXMMEXCPT),%eax
    164 	movl	%eax,%cr4
    165 
    166 	movl	$MSR_EFER,%ecx
    167 	rdmsr
    168 	xorl	%eax,%eax
    169 	orl	$(EFER_LME|EFER_SCE),%eax
    170 	wrmsr
    171 
    172 	movl	WAKEUP_r_cr3 + ACPI_WAKEUP_ADDR,%eax
    173 	movl	%eax,%cr3
    174 
    175 	movl	WAKEUP_r_cr0 + ACPI_WAKEUP_ADDR,%eax
    176         movl	%eax,%cr0
    177 	jmp	1f
    178 1:
    179 	lgdt	tmp_gdt64 + ACPI_WAKEUP_ADDR
    180 
    181 	ljmp	$0x8, $wakeup_64 + ACPI_WAKEUP_ADDR
    182 
    183 	.code64
    184 wakeup_64:
    185 
    186 	movw	$GSEL(GDATA_SEL, SEL_KPL),%ax 	#switch to new segment
    187 	movw	%ax,%ds
    188 	movw	%ax,%es
    189 	movw	%ax,%ss
    190 
    191 	movq	WAKEUP_restorecpu + ACPI_WAKEUP_ADDR,%rbx
    192 
    193 	lgdt	WAKEUP_r_gdt + ACPI_WAKEUP_ADDR
    194 
    195 	jmp	*%rbx
    196 
    197 	.align	8
    198 tmp_gdt:
    199 	.word	0xffff
    200 	.long	tmp_gdtable + ACPI_WAKEUP_ADDR
    201 
    202 	.align	8, 0
    203 tmp_gdtable:
    204 	/* null */
    205 	.word	0, 0
    206 	.byte	0, 0, 0, 0
    207 	/* code */
    208 	.word	0xffff, 0
    209 	.byte	0, 0x9f, 0xcf, 0
    210 	/* data */
    211 	.word	0xffff, 0
    212 	.byte	0, 0x93, 0xcf, 0
    213 
    214 tmp_gdt64:
    215 	.word 0xffff
    216 	.long tmp_gdtable64 + ACPI_WAKEUP_ADDR
    217 
    218 tmp_gdtable64:
    219 	.quad 0x0000000000000000
    220 	.quad 0x00af9a000000ffff
    221 	.quad 0x00cf92000000ffff
    222 
    223 	.align	16, 0
    224 	.global WAKEUP_r_cr0
    225 WAKEUP_r_cr0:		.quad 0
    226 	.global WAKEUP_r_cr3
    227 WAKEUP_r_cr3:		.quad 0
    228 
    229 	.global WAKEUP_r_gdt
    230 WAKEUP_r_gdt:		.word 0
    231 			.quad 0
    232 	.global WAKEUP_restorecpu
    233 WAKEUP_restorecpu:	.quad 0
    234 
    235 	.global WAKEUP_vbios_reset
    236 WAKEUP_vbios_reset:	.byte 0
    237 	.global WAKEUP_beep_on_reset
    238 WAKEUP_beep_on_reset:	.byte 0
    239