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