Home | History | Annotate | Line # | Download | only in acpi
acpi_wakecode.S revision 1.1.2.8
      1  1.1.2.8     joerg /*	$NetBSD: acpi_wakecode.S,v 1.1.2.8 2007/09/26 00:42:20 joerg Exp $	*/
      2  1.1.2.1  jmcneill 
      3  1.1.2.1  jmcneill /*-
      4  1.1.2.5     joerg  * Copyright (c) 2002 The NetBSD Foundation, Inc.
      5  1.1.2.1  jmcneill  * All rights reserved.
      6  1.1.2.1  jmcneill  *
      7  1.1.2.1  jmcneill  * This code is derived from software contributed to The NetBSD Foundation
      8  1.1.2.5     joerg  * by Takuya SHIOZAKI.
      9  1.1.2.1  jmcneill  *
     10  1.1.2.1  jmcneill  * Redistribution and use in source and binary forms, with or without
     11  1.1.2.1  jmcneill  * modification, are permitted provided that the following conditions
     12  1.1.2.1  jmcneill  * are met:
     13  1.1.2.1  jmcneill  * 1. Redistributions of source code must retain the above copyright
     14  1.1.2.1  jmcneill  *    notice, this list of conditions and the following disclaimer.
     15  1.1.2.1  jmcneill  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.1.2.1  jmcneill  *    notice, this list of conditions and the following disclaimer in the
     17  1.1.2.1  jmcneill  *    documentation and/or other materials provided with the distribution.
     18  1.1.2.1  jmcneill  * 3. All advertising materials mentioning features or use of this software
     19  1.1.2.1  jmcneill  *    must display the following acknowledgement:
     20  1.1.2.1  jmcneill  *	  This product includes software developed by the NetBSD
     21  1.1.2.1  jmcneill  *	  Foundation, Inc. and its contributors.
     22  1.1.2.1  jmcneill  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  1.1.2.1  jmcneill  *    contributors may be used to endorse or promote products derived
     24  1.1.2.1  jmcneill  *    from this software without specific prior written permission.
     25  1.1.2.1  jmcneill  *
     26  1.1.2.1  jmcneill  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  1.1.2.1  jmcneill  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  1.1.2.1  jmcneill  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  1.1.2.1  jmcneill  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  1.1.2.1  jmcneill  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  1.1.2.1  jmcneill  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  1.1.2.1  jmcneill  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  1.1.2.1  jmcneill  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  1.1.2.1  jmcneill  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  1.1.2.1  jmcneill  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  1.1.2.1  jmcneill  * POSSIBILITY OF SUCH DAMAGE.
     37  1.1.2.1  jmcneill  */
     38  1.1.2.1  jmcneill 
     39  1.1.2.1  jmcneill 
     40  1.1.2.1  jmcneill /*
     41  1.1.2.1  jmcneill  * This code is derived from FreeBSD.  Original copyrights:
     42  1.1.2.1  jmcneill  *
     43  1.1.2.1  jmcneill  * Copyright (c) 2001 Takanori Watanabe <takawata (at) jp.freebsd.org>
     44  1.1.2.1  jmcneill  * Copyright (c) 2001 Mitsuru IWASAKI <iwasaki (at) jp.freebsd.org>
     45  1.1.2.1  jmcneill  * All rights reserved.
     46  1.1.2.1  jmcneill  *
     47  1.1.2.1  jmcneill  * Redistribution and use in source and binary forms, with or without
     48  1.1.2.1  jmcneill  * modification, are permitted provided that the following conditions
     49  1.1.2.1  jmcneill  * are met:
     50  1.1.2.1  jmcneill  * 1. Redistributions of source code must retain the above copyright
     51  1.1.2.1  jmcneill  *    notice, this list of conditions and the following disclaimer.
     52  1.1.2.1  jmcneill  * 2. Redistributions in binary form must reproduce the above copyright
     53  1.1.2.1  jmcneill  *    notice, this list of conditions and the following disclaimer in the
     54  1.1.2.1  jmcneill  *    documentation and/or other materials provided with the distribution.
     55  1.1.2.1  jmcneill  *
     56  1.1.2.1  jmcneill  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     57  1.1.2.1  jmcneill  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     58  1.1.2.1  jmcneill  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     59  1.1.2.1  jmcneill  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     60  1.1.2.1  jmcneill  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     61  1.1.2.1  jmcneill  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     62  1.1.2.1  jmcneill  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     63  1.1.2.1  jmcneill  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     64  1.1.2.1  jmcneill  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     65  1.1.2.1  jmcneill  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     66  1.1.2.1  jmcneill  * SUCH DAMAGE.
     67  1.1.2.1  jmcneill  *
     68  1.1.2.1  jmcneill  *	FreeBSD: src/sys/i386/acpica/acpi_wakecode.S,v 1.1 2001/07/20 06:07:31 takawata Exp
     69  1.1.2.1  jmcneill  */
     70  1.1.2.1  jmcneill 
     71  1.1.2.1  jmcneill #define _LOCORE
     72  1.1.2.1  jmcneill 
     73  1.1.2.5     joerg #include <machine/psl.h>
     74  1.1.2.1  jmcneill #include <machine/specialreg.h>
     75  1.1.2.1  jmcneill #include <machine/segments.h>
     76  1.1.2.1  jmcneill 
     77  1.1.2.6     joerg #define	ACPI_WAKEUP_ADDR	0x3000
     78  1.1.2.6     joerg 
     79  1.1.2.1  jmcneill 	.text
     80  1.1.2.1  jmcneill 	.code16
     81  1.1.2.5     joerg 	.org 0	/* ACPI spec says: cs==(phys>>8), ip==(phys&0x000F) */
     82  1.1.2.3  jmcneill 	.globl wakeup_16
     83  1.1.2.1  jmcneill wakeup_16:
     84  1.1.2.1  jmcneill 	nop
     85  1.1.2.1  jmcneill 	cli
     86  1.1.2.1  jmcneill 	cld
     87  1.1.2.1  jmcneill 
     88  1.1.2.1  jmcneill 	/* Set up segment registers for real mode */
     89  1.1.2.5     joerg 	movw	%cs,%ax
     90  1.1.2.5     joerg 	movw	%ax,%ds
     91  1.1.2.5     joerg 	movw	%ax,%ss
     92  1.1.2.1  jmcneill 
     93  1.1.2.5     joerg 	/* Small call stack */
     94  1.1.2.5     joerg 	mov	$0x1000,%sp
     95  1.1.2.1  jmcneill 
     96  1.1.2.1  jmcneill 	/* Clear flags */
     97  1.1.2.1  jmcneill 	pushl	$0
     98  1.1.2.1  jmcneill 	popfl
     99  1.1.2.1  jmcneill 
    100  1.1.2.1  jmcneill 	/* Only beep on reset if machdep.acpi_beep_on_reset=1 */
    101  1.1.2.5     joerg 	cmpb	$1,WAKEUP_beep_on_reset
    102  1.1.2.5     joerg 	jne	1f
    103  1.1.2.5     joerg 	movb	$0xc0,%al
    104  1.1.2.5     joerg 	outb	%al,$0x42
    105  1.1.2.5     joerg 	movb	$0x04,%al
    106  1.1.2.5     joerg 	outb	%al,$0x42
    107  1.1.2.5     joerg 	inb	$0x61,%al
    108  1.1.2.5     joerg 	orb	$0x3,%al
    109  1.1.2.5     joerg 	outb	%al,$0x61
    110  1.1.2.5     joerg 1:
    111  1.1.2.1  jmcneill 
    112  1.1.2.1  jmcneill 	/* Only reset the VBIOS if machdep.acpi_vbios_reset=1 */
    113  1.1.2.5     joerg 	cmpb	$1,WAKEUP_vbios_reset
    114  1.1.2.5     joerg 	jne	1f
    115  1.1.2.1  jmcneill 
    116  1.1.2.1  jmcneill 	/* Kick the VBIOS. */
    117  1.1.2.5     joerg 	lcall	$0xc000,$3
    118  1.1.2.1  jmcneill 
    119  1.1.2.8     joerg 	/* Reset registers in case the VBIOS changed them. */
    120  1.1.2.5     joerg 	movw	%cs,%ax
    121  1.1.2.5     joerg 	movw	%ax,%ds
    122  1.1.2.5     joerg 	movw	%ax,%ss
    123  1.1.2.5     joerg 1:
    124  1.1.2.1  jmcneill 
    125  1.1.2.5     joerg 	/* Disable beep again if machdep.acpi_beep_on_reset=1 */
    126  1.1.2.5     joerg 	cmpb	$1,WAKEUP_beep_on_reset
    127  1.1.2.5     joerg 	jne	1f
    128  1.1.2.5     joerg 	inb	$0x61,%al
    129  1.1.2.5     joerg 	andb	$0xfc,%al
    130  1.1.2.5     joerg 	outb	%al,$0x61
    131  1.1.2.5     joerg 1:
    132  1.1.2.1  jmcneill 
    133  1.1.2.8     joerg 	/* Load temporary 32bit GDT */
    134  1.1.2.5     joerg 	data32 addr32 lgdt	tmp_gdt
    135  1.1.2.3  jmcneill 
    136  1.1.2.8     joerg 	/* Enable protected mode w/o paging */
    137  1.1.2.5     joerg 	mov	%cr0,%eax
    138  1.1.2.5     joerg 	orl	$(CR0_PE),%eax
    139  1.1.2.5     joerg 	mov	%eax,%cr0
    140  1.1.2.1  jmcneill 
    141  1.1.2.5     joerg wakeup_sw32:
    142  1.1.2.8     joerg 	/*
    143  1.1.2.8     joerg 	 * Switch to protected mode by intersegmental jump.
    144  1.1.2.8     joerg 	 * Target and everything else has to compensate for the new origin
    145  1.1.2.8     joerg 	 * as this is using the flat memory model now.
    146  1.1.2.8     joerg 	 */
    147  1.1.2.8     joerg 
    148  1.1.2.6     joerg 	ljmpl	$0x8,$wakeup_32 + ACPI_WAKEUP_ADDR
    149  1.1.2.1  jmcneill 
    150  1.1.2.1  jmcneill 	.code32
    151  1.1.2.5     joerg 	.align	16
    152  1.1.2.1  jmcneill wakeup_32:
    153  1.1.2.5     joerg 	/*
    154  1.1.2.5     joerg 	 * Switched to protected mode w/o paging
    155  1.1.2.5     joerg 	 */
    156  1.1.2.1  jmcneill 
    157  1.1.2.3  jmcneill 	nop
    158  1.1.2.8     joerg 	/* Set up segment registers and initial stack for protected mode */
    159  1.1.2.6     joerg 	movw	$0x10, %ax
    160  1.1.2.5     joerg 	movw	%ax,%ds
    161  1.1.2.7     joerg 	movw	%ax,%ss
    162  1.1.2.5     joerg 
    163  1.1.2.6     joerg 	movl	ACPI_WAKEUP_ADDR + 4096,%esp
    164  1.1.2.1  jmcneill 
    165  1.1.2.5     joerg 	/* First, reset the PSL. */
    166  1.1.2.1  jmcneill 	pushl	$PSL_MBO
    167  1.1.2.1  jmcneill 	popfl
    168  1.1.2.1  jmcneill 
    169  1.1.2.8     joerg 	/* Enable PAE */
    170  1.1.2.5     joerg 	movl	%cr4,%eax
    171  1.1.2.5     joerg 	orl	$(CR4_PAE|CR4_OSFXSR|CR4_OSXMMEXCPT),%eax
    172  1.1.2.5     joerg 	movl	%eax,%cr4
    173  1.1.2.1  jmcneill 
    174  1.1.2.8     joerg 	/* Enable SYSCALL extension and Long Mode */
    175  1.1.2.5     joerg 	movl	$MSR_EFER,%ecx
    176  1.1.2.1  jmcneill 	rdmsr
    177  1.1.2.5     joerg 	xorl	%eax,%eax
    178  1.1.2.5     joerg 	orl	$(EFER_LME|EFER_SCE),%eax
    179  1.1.2.1  jmcneill 	wrmsr
    180  1.1.2.1  jmcneill 
    181  1.1.2.8     joerg 	/* Load temporary PML4, code will switch to full PML4 later */
    182  1.1.2.6     joerg 	movl	WAKEUP_r_cr3 + ACPI_WAKEUP_ADDR,%eax
    183  1.1.2.5     joerg 	movl	%eax,%cr3
    184  1.1.2.1  jmcneill 
    185  1.1.2.8     joerg 	/* Reload cr0 with normal values, activating paging effectively */
    186  1.1.2.6     joerg 	movl	WAKEUP_r_cr0 + ACPI_WAKEUP_ADDR,%eax
    187  1.1.2.5     joerg         movl	%eax,%cr0
    188  1.1.2.8     joerg 	/* Flush prefetch queue */
    189  1.1.2.5     joerg 	jmp	1f
    190  1.1.2.5     joerg 1:
    191  1.1.2.8     joerg 	/* Switch to temporary 64bit GDT */
    192  1.1.2.6     joerg 	lgdt	tmp_gdt64 + ACPI_WAKEUP_ADDR
    193  1.1.2.5     joerg 
    194  1.1.2.8     joerg 	/* Switch to long mode using intersegmental jump. */
    195  1.1.2.6     joerg 	ljmp	$0x8, $wakeup_64 + ACPI_WAKEUP_ADDR
    196  1.1.2.1  jmcneill 
    197  1.1.2.1  jmcneill 	.code64
    198  1.1.2.1  jmcneill wakeup_64:
    199  1.1.2.1  jmcneill 
    200  1.1.2.8     joerg 	/* Reload normal segment registers with correct values */
    201  1.1.2.8     joerg 	movw	$GSEL(GDATA_SEL, SEL_KPL),%ax
    202  1.1.2.5     joerg 	movw	%ax,%ds
    203  1.1.2.6     joerg 	movw	%ax,%es
    204  1.1.2.6     joerg 	movw	%ax,%ss
    205  1.1.2.1  jmcneill 
    206  1.1.2.6     joerg 	movq	WAKEUP_restorecpu + ACPI_WAKEUP_ADDR,%rbx
    207  1.1.2.1  jmcneill 
    208  1.1.2.8     joerg 	/* Switch to the normal kernel GDT */
    209  1.1.2.6     joerg 	lgdt	WAKEUP_r_gdt + ACPI_WAKEUP_ADDR
    210  1.1.2.5     joerg 
    211  1.1.2.8     joerg 	/* Continue with wakeup in the high-level wakeup code */
    212  1.1.2.5     joerg 	jmp	*%rbx
    213  1.1.2.5     joerg 
    214  1.1.2.5     joerg 	.align	8
    215  1.1.2.1  jmcneill tmp_gdt:
    216  1.1.2.1  jmcneill 	.word	0xffff
    217  1.1.2.6     joerg 	.long	tmp_gdtable + ACPI_WAKEUP_ADDR
    218  1.1.2.1  jmcneill 
    219  1.1.2.5     joerg 	.align	8, 0
    220  1.1.2.1  jmcneill tmp_gdtable:
    221  1.1.2.1  jmcneill 	/* null */
    222  1.1.2.1  jmcneill 	.word	0, 0
    223  1.1.2.1  jmcneill 	.byte	0, 0, 0, 0
    224  1.1.2.1  jmcneill 	/* code */
    225  1.1.2.1  jmcneill 	.word	0xffff, 0
    226  1.1.2.1  jmcneill 	.byte	0, 0x9f, 0xcf, 0
    227  1.1.2.1  jmcneill 	/* data */
    228  1.1.2.1  jmcneill 	.word	0xffff, 0
    229  1.1.2.1  jmcneill 	.byte	0, 0x93, 0xcf, 0
    230  1.1.2.1  jmcneill 
    231  1.1.2.1  jmcneill tmp_gdt64:
    232  1.1.2.5     joerg 	.word 0xffff
    233  1.1.2.6     joerg 	.long tmp_gdtable64 + ACPI_WAKEUP_ADDR
    234  1.1.2.1  jmcneill 
    235  1.1.2.1  jmcneill tmp_gdtable64:
    236  1.1.2.5     joerg 	.quad 0x0000000000000000
    237  1.1.2.5     joerg 	.quad 0x00af9a000000ffff
    238  1.1.2.5     joerg 	.quad 0x00cf92000000ffff
    239  1.1.2.5     joerg 
    240  1.1.2.1  jmcneill 	.align	16, 0
    241  1.1.2.5     joerg 	.global WAKEUP_r_cr0
    242  1.1.2.5     joerg WAKEUP_r_cr0:		.quad 0
    243  1.1.2.5     joerg 	.global WAKEUP_r_cr3
    244  1.1.2.5     joerg WAKEUP_r_cr3:		.quad 0
    245  1.1.2.5     joerg 
    246  1.1.2.5     joerg 	.global WAKEUP_r_gdt
    247  1.1.2.5     joerg WAKEUP_r_gdt:		.word 0
    248  1.1.2.1  jmcneill 			.quad 0
    249  1.1.2.5     joerg 	.global WAKEUP_restorecpu
    250  1.1.2.5     joerg WAKEUP_restorecpu:	.quad 0
    251  1.1.2.5     joerg 
    252  1.1.2.3  jmcneill 	.global WAKEUP_vbios_reset
    253  1.1.2.5     joerg WAKEUP_vbios_reset:	.byte 0
    254  1.1.2.5     joerg 	.global WAKEUP_beep_on_reset
    255  1.1.2.5     joerg WAKEUP_beep_on_reset:	.byte 0
    256