usr/src/uts/i86pc/ml/mpcore.s
author Kuriakose Kuruvilla <kuriakose.kuruvilla@oracle.com>
Mon, 16 Aug 2010 22:47:01 -0700
changeset 13136 67d1861e02c1
parent 12826 fca99d9e3f2f
permissions -rw-r--r--
6970888 panic BAD TRAP: type=d (#gp General protection) due to incorrect use of x86_featureset
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
     1
/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
     2
 * CDDL HEADER START
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
     3
 *
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
     4
 * The contents of this file are subject to the terms of the
2985
78b075f897aa 6480953 system seems hung,invisible panic, on debug kernel, never gets to mp_startup
dmick
parents: 1217
diff changeset
     5
 * Common Development and Distribution License (the "License").
78b075f897aa 6480953 system seems hung,invisible panic, on debug kernel, never gets to mp_startup
dmick
parents: 1217
diff changeset
     6
 * You may not use this file except in compliance with the License.
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
     7
 *
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
     8
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
     9
 * or http://www.opensolaris.org/os/licensing.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    10
 * See the License for the specific language governing permissions
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    11
 * and limitations under the License.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    12
 *
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    13
 * When distributing Covered Code, include this CDDL HEADER in each
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    14
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    15
 * If applicable, add the following below this CDDL HEADER, with the
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    16
 * fields enclosed by brackets "[]" replaced with your own identifying
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    17
 * information: Portions Copyright [yyyy] [name of copyright owner]
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    18
 *
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    19
 * CDDL HEADER END
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    20
 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    21
/*
12826
fca99d9e3f2f 6812663 Running out of bits in x86_feature
Kuriakose Kuruvilla <kuriakose.kuruvilla@oracle.com>
parents: 12004
diff changeset
    22
 * Copyright (c) 1992, 2010, Oracle and/or its affiliates. All rights reserved.
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    23
 */
12004
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
    24
/*
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
    25
 * Copyright (c) 2010, Intel Corporation.
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
    26
 * All rights reserved.
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
    27
 */
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    28
	
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    29
#include <sys/asm_linkage.h>
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    30
#include <sys/asm_misc.h>
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    31
#include <sys/regset.h>
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    32
#include <sys/privregs.h>
3446
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 2985
diff changeset
    33
#include <sys/x86_archext.h>
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    34
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    35
#if !defined(__lint)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    36
#include <sys/segments.h>
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    37
#include "assym.h"
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    38
#endif
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    39
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    40
/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    41
 *	Our assumptions:
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    42
 *		- We are running in real mode.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    43
 *		- Interrupts are disabled.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    44
 *		- Selectors are equal (cs == ds == ss) for all real mode code
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    45
 *		- The GDT, IDT, ktss and page directory has been built for us
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    46
 *
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    47
 *	Our actions:
12004
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
    48
 *	Start CPU:
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    49
 *		- We start using our GDT by loading correct values in the
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    50
 *		  selector registers (cs=KCS_SEL, ds=es=ss=KDS_SEL, fs=KFS_SEL,
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    51
 *		  gs=KGS_SEL).
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    52
 *		- We change over to using our IDT.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    53
 *		- We load the default LDT into the hardware LDT register.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    54
 *		- We load the default TSS into the hardware task register.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    55
 *		- call mp_startup(void) indirectly through the T_PC
12004
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
    56
 *	Stop CPU:
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
    57
 *		- Put CPU into halted state with interrupts disabled
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    58
 *
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    59
 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    60
3446
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 2985
diff changeset
    61
#if defined(__lint)
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    62
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    63
void
12004
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
    64
real_mode_start_cpu(void)
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
    65
{}
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
    66
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
    67
void
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
    68
real_mode_stop_cpu_stage1(void)
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
    69
{}
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
    70
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
    71
void
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
    72
real_mode_stop_cpu_stage2(void)
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    73
{}
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    74
3446
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 2985
diff changeset
    75
#else	/* __lint */
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    76
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    77
#if defined(__amd64)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    78
12004
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
    79
	ENTRY_NP(real_mode_start_cpu)
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    80
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    81
#if !defined(__GNUC_AS__)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    82
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    83
	/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    84
	 * For vulcan as we need to do a .code32 and mentally invert the
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    85
	 * meaning of the addr16 and data16 prefixes to get 32-bit access when
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    86
	 * generating code to be executed in 16-bit mode (sigh...)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    87
	 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    88
	.code32
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    89
	cli
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    90
	movw		%cs, %ax
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    91
	movw		%ax, %ds	/* load cs into ds */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    92
	movw		%ax, %ss	/* and into ss */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    93
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    94
	/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    95
	 * Helps in debugging by giving us the fault address.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    96
	 *
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    97
	 * Remember to patch a hlt (0xf4) at cmntrap to get a good stack.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    98
	 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
    99
	D16 movl	$0xffc, %esp
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   100
	movl		%cr0, %eax
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   101
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   102
	/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   103
	 * Enable protected-mode, write protect, and alignment mask
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   104
	 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   105
	D16 orl		$[CR0_PE|CR0_WP|CR0_AM], %eax
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   106
	movl		%eax, %cr0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   107
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   108
	/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   109
	 * Do a jmp immediately after writing to cr0 when enabling protected
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   110
	 * mode to clear the real mode prefetch queue (per Intel's docs)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   111
	 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   112
	jmp		pestart
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   113
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   114
pestart:
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   115
	/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   116
 	 * 16-bit protected mode is now active, so prepare to turn on long
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   117
	 * mode.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   118
	 *
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   119
	 * Note that we currently assume that if we're attempting to run a
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   120
	 * kernel compiled with (__amd64) #defined, the target CPU has long
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   121
	 * mode support.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   122
	 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   123
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   124
#if 0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   125
	/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   126
	 * If there's a chance this might not be true, the following test should
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   127
	 * be done, with the no_long_mode branch then doing something
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   128
	 * appropriate:
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   129
	 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   130
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   131
	D16 movl	$0x80000000, %eax	/* get largest extended CPUID */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   132
	cpuid
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   133
	D16 cmpl	$0x80000000, %eax	/* check if > 0x80000000 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   134
	jbe		no_long_mode		/* nope, no long mode */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   135
	D16 movl	$0x80000001, %eax	
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   136
	cpuid					/* get extended feature flags */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   137
	btl		$29, %edx		/* check for long mode */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   138
	jnc		no_long_mode		/* long mode not supported */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   139
#endif
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   140
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   141
	/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   142
 	 * Add any initial cr4 bits
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   143
	 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   144
	movl		%cr4, %eax
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   145
	A16 D16 orl	CR4OFF, %eax
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   146
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   147
	/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   148
	 * Enable PAE mode (CR4.PAE)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   149
	 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   150
	D16 orl		$CR4_PAE, %eax
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   151
	movl		%eax, %cr4
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   152
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   153
	/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   154
	 * Point cr3 to the 64-bit long mode page tables.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   155
	 *
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   156
	 * Note that these MUST exist in 32-bit space, as we don't have
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   157
	 * a way to load %cr3 with a 64-bit base address for the page tables
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   158
	 * until the CPU is actually executing in 64-bit long mode.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   159
	 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   160
	A16 D16 movl	CR3OFF, %eax
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   161
	movl		%eax, %cr3
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   162
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   163
	/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   164
	 * Set long mode enable in EFER (EFER.LME = 1)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   165
	 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   166
	D16 movl	$MSR_AMD_EFER, %ecx
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   167
	rdmsr
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   168
	D16 orl		$AMD_EFER_LME, %eax
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   169
	wrmsr
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   170
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   171
	/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   172
	 * Finally, turn on paging (CR0.PG = 1) to activate long mode.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   173
	 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   174
	movl		%cr0, %eax
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   175
	D16 orl		$CR0_PG, %eax
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   176
	movl		%eax, %cr0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   177
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   178
	/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   179
	 * The instruction after enabling paging in CR0 MUST be a branch.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   180
	 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   181
	jmp		long_mode_active
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   182
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   183
long_mode_active:
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   184
	/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   185
	 * Long mode is now active but since we're still running with the
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   186
	 * original 16-bit CS we're actually in 16-bit compatability mode.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   187
	 *
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   188
	 * We have to load an intermediate GDT and IDT here that we know are
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   189
	 * in 32-bit space before we can use the kernel's GDT and IDT, which
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   190
	 * may be in the 64-bit address space, and since we're in compatability
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   191
	 * mode, we only have access to 16 and 32-bit instructions at the
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   192
	 * moment.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   193
	 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   194
	A16 D16 lgdt	TEMPGDTOFF	/* load temporary GDT */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   195
	A16 D16 lidt	TEMPIDTOFF	/* load temporary IDT */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   196
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   197
	/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   198
 	 * Do a far transfer to 64-bit mode.  Set the CS selector to a 64-bit
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   199
	 * long mode selector (CS.L=1) in the temporary 32-bit GDT and jump
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   200
	 * to the real mode platter address of long_mode 64 as until the 64-bit
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   201
	 * CS is in place we don't have access to 64-bit instructions and thus
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   202
	 * can't reference a 64-bit %rip.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   203
	 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   204
	D16 	pushl 	$TEMP_CS64_SEL
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   205
	A16 D16 pushl	LM64OFF
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   206
	D16 lret
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   207
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   208
	.globl	long_mode_64
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   209
long_mode_64:
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   210
	.code64
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   211
	/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   212
	 * We are now running in long mode with a 64-bit CS (EFER.LMA=1,
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   213
	 * CS.L=1) so we now have access to 64-bit instructions.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   214
	 *
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   215
	 * First, set the 64-bit GDT base.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   216
	 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   217
	.globl	rm_platter_pa
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   218
	movl	rm_platter_pa, %eax
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   219
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   220
	lgdtq	GDTROFF(%rax)		/* load 64-bit GDT */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   221
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   222
	/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   223
	 * Save the CPU number in %r11; get the value here since it's saved in
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   224
	 * the real mode platter.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   225
	 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   226
	movl	CPUNOFF(%rax), %r11d
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   227
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   228
	/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   229
	 * Add rm_platter_pa to %rsp to point it to the same location as seen
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   230
	 * from 64-bit mode.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   231
	 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   232
	addq	%rax, %rsp
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   233
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   234
	/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   235
	 * Now do an lretq to load CS with the appropriate selector for the
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   236
	 * kernel's 64-bit GDT and to start executing 64-bit setup code at the
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   237
	 * virtual address where boot originally loaded this code rather than
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   238
	 * the copy in the real mode platter's rm_code array as we've been
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   239
	 * doing so far.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   240
	 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   241
	pushq	$KCS_SEL
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   242
	pushq	$kernel_cs_code
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   243
	lretq
12004
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   244
	.globl real_mode_start_cpu_end
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   245
real_mode_start_cpu_end:
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   246
	nop
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   247
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   248
kernel_cs_code:
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   249
	/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   250
	 * Complete the balance of the setup we need to before executing
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   251
	 * 64-bit kernel code (namely init rsp, TSS, LGDT, FS and GS).
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   252
	 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   253
	.globl	rm_platter_va
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   254
	movq	rm_platter_va, %rax
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   255
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   256
	lidtq	IDTROFF(%rax)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   257
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   258
	movw	$KDS_SEL, %ax
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   259
	movw	%ax, %ds
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   260
	movw	%ax, %es
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   261
	movw	%ax, %ss
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   262
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   263
	movw	$KTSS_SEL, %ax		/* setup kernel TSS */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   264
	ltr	%ax
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   265
1217
f95ffdc997b7 6219276 need per-process equivalent of device context
rab
parents: 545
diff changeset
   266
	xorw	%ax, %ax		/* clear LDTR */
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   267
	lldt	%ax
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   268
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   269
	/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   270
	 * Set GS to the address of the per-cpu structure as contained in
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   271
	 * cpu[cpu_number].
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   272
	 *
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   273
	 * Unfortunately there's no way to set the 64-bit gsbase with a mov,
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   274
	 * so we have to stuff the low 32 bits in %eax and the high 32 bits in
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   275
	 * %edx, then call wrmsr.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   276
	 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   277
	leaq	cpu(%rip), %rdi
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   278
	movl	(%rdi, %r11, 8), %eax
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   279
	movl	4(%rdi, %r11, 8), %edx
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   280
	movl	$MSR_AMD_GSBASE, %ecx
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   281
	wrmsr
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   282
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   283
	/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   284
	 * Init FS and KernelGSBase.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   285
	 *
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   286
	 * Based on code in mlsetup(), set them both to 8G (which shouldn't be
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   287
	 * valid until some 64-bit processes run); this will then cause an
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   288
	 * exception in any code that tries to index off them before they are
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   289
	 * properly setup.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   290
	 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   291
	xorl	%eax, %eax		/* low 32 bits = 0 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   292
	movl	$2, %edx		/* high 32 bits = 2 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   293
	movl	$MSR_AMD_FSBASE, %ecx
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   294
	wrmsr
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   295
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   296
	movl	$MSR_AMD_KGSBASE, %ecx
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   297
	wrmsr
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   298
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   299
	/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   300
	 * Init %rsp to the exception stack set in tss_ist1 and create a legal
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   301
	 * AMD64 ABI stack frame
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   302
	 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   303
	movq	%gs:CPU_TSS, %rax
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   304
	movq	TSS_IST1(%rax), %rsp
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   305
	pushq	$0		/* null return address */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   306
	pushq	$0		/* null frame pointer terminates stack trace */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   307
	movq	%rsp, %rbp	/* stack aligned on 16-byte boundary */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   308
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   309
	movq	%cr0, %rax
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   310
	andq    $-1![CR0_TS|CR0_EM], %rax	/* clr emulate math chip bit */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   311
	orq     $[CR0_MP|CR0_NE], %rax
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   312
	movq    %rax, %cr0			/* set machine status word */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   313
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   314
	/*
3446
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 2985
diff changeset
   315
	 * Before going any further, enable usage of page table NX bit if 
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 2985
diff changeset
   316
	 * that's how our page tables are set up.
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   317
	 */
13136
67d1861e02c1 6970888 panic BAD TRAP: type=d (#gp General protection) due to incorrect use of x86_featureset
Kuriakose Kuruvilla <kuriakose.kuruvilla@oracle.com>
parents: 12826
diff changeset
   318
	bt	$X86FSET_NX, x86_featureset(%rip)
12826
fca99d9e3f2f 6812663 Running out of bits in x86_feature
Kuriakose Kuruvilla <kuriakose.kuruvilla@oracle.com>
parents: 12004
diff changeset
   319
	jnc	1f
3446
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 2985
diff changeset
   320
	movl	$MSR_AMD_EFER, %ecx
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 2985
diff changeset
   321
	rdmsr
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 2985
diff changeset
   322
	orl	$AMD_EFER_NXE, %eax
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 2985
diff changeset
   323
	wrmsr
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 2985
diff changeset
   324
1:
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   325
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   326
	/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   327
	 * Complete the rest of the setup and call mp_startup().
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   328
	 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   329
	movq	%gs:CPU_THREAD, %rax	/* get thread ptr */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   330
	call	*T_PC(%rax)		/* call mp_startup */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   331
	/* not reached */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   332
	int	$20			/* whoops, returned somehow! */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   333
#else	/* __GNUC_AS__ */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   334
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   335
	/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   336
	 * NOTE:  The GNU assembler automatically does the right thing to
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   337
	 *	  generate data size operand prefixes based on the code size
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   338
	 *	  generation mode (e.g. .code16, .code32, .code64) and as such
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   339
	 *	  prefixes need not be used on instructions EXCEPT in the case
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   340
	 *	  of address prefixes for code for which the reference is not
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   341
	 *	  automatically of the default operand size.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   342
	 */      
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   343
	.code16
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   344
	cli
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   345
	movw		%cs, %ax
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   346
	movw		%ax, %ds	/* load cs into ds */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   347
	movw		%ax, %ss	/* and into ss */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   348
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   349
	/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   350
	 * Helps in debugging by giving us the fault address.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   351
	 *
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   352
	 * Remember to patch a hlt (0xf4) at cmntrap to get a good stack.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   353
	 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   354
	movl		$0xffc, %esp
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   355
	movl		%cr0, %eax
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   356
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   357
	/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   358
	 * Enable protected-mode, write protect, and alignment mask
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   359
	 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   360
	orl		$(CR0_PE|CR0_WP|CR0_AM), %eax
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   361
	movl		%eax, %cr0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   362
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   363
	/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   364
	 * Do a jmp immediately after writing to cr0 when enabling protected
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   365
	 * mode to clear the real mode prefetch queue (per Intel's docs)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   366
	 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   367
	jmp		pestart
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   368
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   369
pestart:
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   370
	/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   371
 	 * 16-bit protected mode is now active, so prepare to turn on long
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   372
	 * mode.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   373
	 *
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   374
	 * Note that we currently assume that if we're attempting to run a
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   375
	 * kernel compiled with (__amd64) #defined, the target CPU has long
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   376
	 * mode support.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   377
	 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   378
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   379
#if 0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   380
	/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   381
	 * If there's a chance this might not be true, the following test should
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   382
	 * be done, with the no_long_mode branch then doing something
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   383
	 * appropriate:
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   384
	 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   385
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   386
	movl		$0x80000000, %eax	/* get largest extended CPUID */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   387
	cpuid
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   388
	cmpl		$0x80000000, %eax	/* check if > 0x80000000 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   389
	jbe		no_long_mode		/* nope, no long mode */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   390
	movl		$0x80000001, %eax	
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   391
	cpuid					/* get extended feature flags */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   392
	btl		$29, %edx		/* check for long mode */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   393
	jnc		no_long_mode		/* long mode not supported */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   394
#endif
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   395
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   396
	/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   397
 	 * Add any initial cr4 bits
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   398
	 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   399
	movl		%cr4, %eax
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   400
	addr32 orl	CR4OFF, %eax
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   401
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   402
	/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   403
	 * Enable PAE mode (CR4.PAE)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   404
	 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   405
	orl		$CR4_PAE, %eax
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   406
	movl		%eax, %cr4
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   407
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   408
	/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   409
	 * Point cr3 to the 64-bit long mode page tables.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   410
	 *
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   411
	 * Note that these MUST exist in 32-bit space, as we don't have
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   412
	 * a way to load %cr3 with a 64-bit base address for the page tables
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   413
	 * until the CPU is actually executing in 64-bit long mode.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   414
	 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   415
	addr32 movl	CR3OFF, %eax
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   416
	movl		%eax, %cr3
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   417
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   418
	/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   419
	 * Set long mode enable in EFER (EFER.LME = 1)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   420
	 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   421
	movl	$MSR_AMD_EFER, %ecx
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   422
	rdmsr
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   423
	orl	$AMD_EFER_LME, %eax
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   424
	wrmsr
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   425
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   426
	/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   427
	 * Finally, turn on paging (CR0.PG = 1) to activate long mode.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   428
	 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   429
	movl	%cr0, %eax
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   430
	orl	$CR0_PG, %eax
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   431
	movl	%eax, %cr0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   432
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   433
	/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   434
	 * The instruction after enabling paging in CR0 MUST be a branch.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   435
	 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   436
	jmp	long_mode_active
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   437
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   438
long_mode_active:
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   439
	/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   440
	 * Long mode is now active but since we're still running with the
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   441
	 * original 16-bit CS we're actually in 16-bit compatability mode.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   442
	 *
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   443
	 * We have to load an intermediate GDT and IDT here that we know are
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   444
	 * in 32-bit space before we can use the kernel's GDT and IDT, which
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   445
	 * may be in the 64-bit address space, and since we're in compatability
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   446
	 * mode, we only have access to 16 and 32-bit instructions at the
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   447
	 * moment.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   448
	 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   449
	addr32 lgdtl	TEMPGDTOFF	/* load temporary GDT */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   450
	addr32 lidtl	TEMPIDTOFF	/* load temporary IDT */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   451
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   452
	/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   453
 	 * Do a far transfer to 64-bit mode.  Set the CS selector to a 64-bit
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   454
	 * long mode selector (CS.L=1) in the temporary 32-bit GDT and jump
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   455
	 * to the real mode platter address of long_mode 64 as until the 64-bit
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   456
	 * CS is in place we don't have access to 64-bit instructions and thus
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   457
	 * can't reference a 64-bit %rip.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   458
	 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   459
	pushl 		$TEMP_CS64_SEL
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   460
	addr32 pushl	LM64OFF
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   461
	lretl
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   462
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   463
	.globl	long_mode_64
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   464
long_mode_64:
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   465
	.code64
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   466
	/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   467
	 * We are now running in long mode with a 64-bit CS (EFER.LMA=1,
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   468
	 * CS.L=1) so we now have access to 64-bit instructions.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   469
	 *
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   470
	 * First, set the 64-bit GDT base.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   471
	 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   472
	.globl	rm_platter_pa
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   473
	movl	rm_platter_pa, %eax
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   474
	lgdtq	GDTROFF(%rax)		/* load 64-bit GDT */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   475
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   476
	/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   477
	 * Save the CPU number in %r11; get the value here since it's saved in
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   478
	 * the real mode platter.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   479
	 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   480
	movl	CPUNOFF(%rax), %r11d
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   481
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   482
	/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   483
	 * Add rm_platter_pa to %rsp to point it to the same location as seen
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   484
	 * from 64-bit mode.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   485
	 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   486
	addq	%rax, %rsp
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   487
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   488
	/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   489
	 * Now do an lretq to load CS with the appropriate selector for the
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   490
	 * kernel's 64-bit GDT and to start executing 64-bit setup code at the
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   491
	 * virtual address where boot originally loaded this code rather than
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   492
	 * the copy in the real mode platter's rm_code array as we've been
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   493
	 * doing so far.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   494
	 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   495
	pushq	$KCS_SEL
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   496
	pushq	$kernel_cs_code
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   497
	lretq
12004
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   498
	.globl real_mode_start_cpu_end
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   499
real_mode_start_cpu_end:
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   500
	nop
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   501
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   502
kernel_cs_code:
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   503
	/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   504
	 * Complete the balance of the setup we need to before executing
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   505
	 * 64-bit kernel code (namely init rsp, TSS, LGDT, FS and GS).
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   506
	 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   507
	.globl	rm_platter_va
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   508
	movq	rm_platter_va, %rax
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   509
	lidtq	IDTROFF(%rax)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   510
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   511
	movw	$KDS_SEL, %ax
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   512
	movw	%ax, %ds
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   513
	movw	%ax, %es
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   514
	movw	%ax, %ss
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   515
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   516
	movw	$KTSS_SEL, %ax		/* setup kernel TSS */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   517
	ltr	%ax
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   518
1217
f95ffdc997b7 6219276 need per-process equivalent of device context
rab
parents: 545
diff changeset
   519
	xorw	%ax, %ax		/* clear LDTR */
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   520
	lldt	%ax
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   521
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   522
	/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   523
	 * Set GS to the address of the per-cpu structure as contained in
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   524
	 * cpu[cpu_number].
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   525
	 *
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   526
	 * Unfortunately there's no way to set the 64-bit gsbase with a mov,
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   527
	 * so we have to stuff the low 32 bits in %eax and the high 32 bits in
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   528
	 * %edx, then call wrmsr.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   529
	 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   530
	leaq	cpu(%rip), %rdi
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   531
	movl	(%rdi, %r11, 8), %eax
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   532
	movl	4(%rdi, %r11, 8), %edx
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   533
	movl	$MSR_AMD_GSBASE, %ecx
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   534
	wrmsr
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   535
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   536
	/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   537
	 * Init FS and KernelGSBase.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   538
	 *
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   539
	 * Based on code in mlsetup(), set them both to 8G (which shouldn't be
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   540
	 * valid until some 64-bit processes run); this will then cause an
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   541
	 * exception in any code that tries to index off them before they are
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   542
	 * properly setup.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   543
	 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   544
	xorl	%eax, %eax		/* low 32 bits = 0 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   545
	movl	$2, %edx		/* high 32 bits = 2 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   546
	movl	$MSR_AMD_FSBASE, %ecx
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   547
	wrmsr
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   548
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   549
	movl	$MSR_AMD_KGSBASE, %ecx
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   550
	wrmsr
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   551
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   552
	/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   553
	 * Init %rsp to the exception stack set in tss_ist1 and create a legal
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   554
	 * AMD64 ABI stack frame
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   555
	 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   556
	movq	%gs:CPU_TSS, %rax
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   557
	movq	TSS_IST1(%rax), %rsp
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   558
	pushq	$0		/* null return address */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   559
	pushq	$0		/* null frame pointer terminates stack trace */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   560
	movq	%rsp, %rbp	/* stack aligned on 16-byte boundary */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   561
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   562
	movq	%cr0, %rax
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   563
	andq    $~(CR0_TS|CR0_EM), %rax	/* clear emulate math chip bit */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   564
	orq     $(CR0_MP|CR0_NE), %rax
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   565
	movq    %rax, %cr0		/* set machine status word */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   566
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   567
	/*
3446
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 2985
diff changeset
   568
	 * Before going any further, enable usage of page table NX bit if 
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 2985
diff changeset
   569
	 * that's how our page tables are set up.
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   570
	 */
13136
67d1861e02c1 6970888 panic BAD TRAP: type=d (#gp General protection) due to incorrect use of x86_featureset
Kuriakose Kuruvilla <kuriakose.kuruvilla@oracle.com>
parents: 12826
diff changeset
   571
	bt	$X86FSET_NX, x86_featureset(%rip)
12826
fca99d9e3f2f 6812663 Running out of bits in x86_feature
Kuriakose Kuruvilla <kuriakose.kuruvilla@oracle.com>
parents: 12004
diff changeset
   572
	jnc	1f
3446
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 2985
diff changeset
   573
	movl	$MSR_AMD_EFER, %ecx
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 2985
diff changeset
   574
	rdmsr
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 2985
diff changeset
   575
	orl	$AMD_EFER_NXE, %eax
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 2985
diff changeset
   576
	wrmsr
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 2985
diff changeset
   577
1:
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   578
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   579
	/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   580
	 * Complete the rest of the setup and call mp_startup().
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   581
	 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   582
	movq	%gs:CPU_THREAD, %rax	/* get thread ptr */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   583
	call	*T_PC(%rax)		/* call mp_startup */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   584
	/* not reached */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   585
	int	$20			/* whoops, returned somehow! */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   586
#endif	/* !__GNUC_AS__ */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   587
12004
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   588
	SET_SIZE(real_mode_start_cpu)
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   589
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   590
#elif defined(__i386)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   591
12004
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   592
	ENTRY_NP(real_mode_start_cpu)
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   593
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   594
#if !defined(__GNUC_AS__)
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   595
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   596
	cli
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   597
	D16 movw	%cs, %eax
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   598
	movw		%eax, %ds	/* load cs into ds */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   599
	movw		%eax, %ss	/* and into ss */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   600
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   601
	/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   602
	 * Helps in debugging by giving us the fault address.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   603
	 *
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   604
	 * Remember to patch a hlt (0xf4) at cmntrap to get a good stack.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   605
	 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   606
	D16 movl	$0xffc, %esp
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   607
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   608
 	D16 A16 lgdt	%cs:GDTROFF
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   609
 	D16 A16 lidt	%cs:IDTROFF
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   610
	D16 A16 movl	%cs:CR4OFF, %eax	/* set up CR4, if desired */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   611
	D16 andl	%eax, %eax
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   612
	D16 A16 je	no_cr4
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   613
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   614
	D16 movl	%eax, %ecx
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   615
	D16 movl	%cr4, %eax
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   616
	D16 orl		%ecx, %eax
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   617
	D16 movl	%eax, %cr4
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   618
no_cr4:
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   619
	D16 A16 movl	%cs:CR3OFF, %eax
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   620
	A16 movl	%eax, %cr3
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   621
	movl		%cr0, %eax
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   622
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   623
	/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   624
	 * Enable protected-mode, paging, write protect, and alignment mask
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   625
	 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   626
	D16 orl		$[CR0_PG|CR0_PE|CR0_WP|CR0_AM], %eax
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   627
	movl		%eax, %cr0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   628
	jmp		pestart
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   629
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   630
pestart:
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   631
	D16 pushl	$KCS_SEL
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   632
	D16 pushl	$kernel_cs_code
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   633
	D16 lret
12004
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   634
	.globl real_mode_start_cpu_end
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   635
real_mode_start_cpu_end:
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   636
	nop
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   637
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   638
	.globl	kernel_cs_code
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   639
kernel_cs_code:
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   640
	/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   641
	 * At this point we are with kernel's cs and proper eip.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   642
	 *
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   643
	 * We will be executing not from the copy in real mode platter,
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   644
	 * but from the original code where boot loaded us.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   645
	 *
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   646
	 * By this time GDT and IDT are loaded as is cr3.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   647
	 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   648
	movw	$KFS_SEL,%eax
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   649
	movw	%eax,%fs
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   650
	movw	$KGS_SEL,%eax
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   651
	movw	%eax,%gs
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   652
	movw	$KDS_SEL,%eax
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   653
	movw	%eax,%ds
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   654
	movw	%eax,%es
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   655
	movl	%gs:CPU_TSS,%esi
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   656
	movw	%eax,%ss
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   657
	movl	TSS_ESP0(%esi),%esp
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   658
	movw	$KTSS_SEL,%ax
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   659
	ltr	%ax
1217
f95ffdc997b7 6219276 need per-process equivalent of device context
rab
parents: 545
diff changeset
   660
	xorw	%ax, %ax		/* clear LDTR */
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   661
	lldt	%ax
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   662
	movl	%cr0,%edx
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   663
	andl    $-1![CR0_TS|CR0_EM],%edx  /* clear emulate math chip bit */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   664
	orl     $[CR0_MP|CR0_NE],%edx
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   665
	movl    %edx,%cr0		  /* set machine status word */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   666
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   667
	/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   668
	 * Before going any further, enable usage of page table NX bit if 
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   669
	 * that's how our page tables are set up.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   670
	 */
12826
fca99d9e3f2f 6812663 Running out of bits in x86_feature
Kuriakose Kuruvilla <kuriakose.kuruvilla@oracle.com>
parents: 12004
diff changeset
   671
	bt	$X86FSET_NX, x86_featureset
fca99d9e3f2f 6812663 Running out of bits in x86_feature
Kuriakose Kuruvilla <kuriakose.kuruvilla@oracle.com>
parents: 12004
diff changeset
   672
	jnc	1f
3446
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 2985
diff changeset
   673
	movl	%cr4, %ecx
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 2985
diff changeset
   674
	andl	$CR4_PAE, %ecx
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 2985
diff changeset
   675
	jz	1f
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 2985
diff changeset
   676
	movl	$MSR_AMD_EFER, %ecx
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 2985
diff changeset
   677
	rdmsr
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 2985
diff changeset
   678
	orl	$AMD_EFER_NXE, %eax
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 2985
diff changeset
   679
	wrmsr
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 2985
diff changeset
   680
1:
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   681
	movl	%gs:CPU_THREAD, %eax	/* get thread ptr */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   682
	call	*T_PC(%eax)		/* call mp_startup */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   683
	/* not reached */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   684
	int	$20			/* whoops, returned somehow! */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   685
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   686
#else
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   687
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   688
	cli
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   689
	mov		%cs, %ax
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   690
	mov		%eax, %ds	/* load cs into ds */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   691
	mov		%eax, %ss	/* and into ss */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   692
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   693
	/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   694
	 * Helps in debugging by giving us the fault address.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   695
	 *
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   696
	 * Remember to patch a hlt (0xf4) at cmntrap to get a good stack.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   697
	 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   698
	D16 mov		$0xffc, %esp
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   699
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   700
	D16 A16 lgdtl	%cs:GDTROFF
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   701
	D16 A16 lidtl	%cs:IDTROFF
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   702
	D16 A16 mov	%cs:CR4OFF, %eax	/* set up CR4, if desired */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   703
	D16 and		%eax, %eax
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   704
	D16 A16 je	no_cr4
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   705
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   706
	D16 mov		%eax, %ecx
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   707
	D16 mov		%cr4, %eax
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   708
	D16 or		%ecx, %eax
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   709
	D16 mov		%eax, %cr4
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   710
no_cr4:
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   711
	D16 A16 mov	%cs:CR3OFF, %eax
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   712
	A16 mov		%eax, %cr3
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   713
	mov		%cr0, %eax
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   714
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   715
	/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   716
	 * Enable protected-mode, paging, write protect, and alignment mask
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   717
	 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   718
	D16 or		$(CR0_PG|CR0_PE|CR0_WP|CR0_AM), %eax
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   719
	mov		%eax, %cr0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   720
	jmp		pestart
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   721
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   722
pestart:
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   723
	D16 pushl	$KCS_SEL
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   724
	D16 pushl	$kernel_cs_code
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   725
	D16 lret
12004
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   726
	.globl real_mode_start_cpu_end
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   727
real_mode_start_cpu_end:
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   728
	nop
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   729
	.globl	kernel_cs_code
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   730
kernel_cs_code:
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   731
	/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   732
	 * At this point we are with kernel's cs and proper eip.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   733
	 *
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   734
	 * We will be executing not from the copy in real mode platter,
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   735
	 * but from the original code where boot loaded us.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   736
	 *
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   737
	 * By this time GDT and IDT are loaded as is cr3.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   738
	 */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   739
	mov	$KFS_SEL, %ax
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   740
	mov	%eax, %fs
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   741
	mov	$KGS_SEL, %ax
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   742
	mov	%eax, %gs
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   743
	mov	$KDS_SEL, %ax
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   744
	mov	%eax, %ds
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   745
	mov	%eax, %es
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   746
	mov	%gs:CPU_TSS, %esi
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   747
	mov	%eax, %ss
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   748
	mov	TSS_ESP0(%esi), %esp
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   749
	mov	$(KTSS_SEL), %ax
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   750
	ltr	%ax
1217
f95ffdc997b7 6219276 need per-process equivalent of device context
rab
parents: 545
diff changeset
   751
	xorw	%ax, %ax		/* clear LDTR */
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   752
	lldt	%ax
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   753
	mov	%cr0, %edx
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   754
	and	$~(CR0_TS|CR0_EM), %edx	/* clear emulate math chip bit */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   755
	or	$(CR0_MP|CR0_NE), %edx
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   756
	mov	%edx, %cr0		/* set machine status word */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   757
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   758
	/*
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   759
	 * Before going any farther, enable usage of page table NX bit if 
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   760
	 * that's how our page tables are set up.
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   761
	 */
12826
fca99d9e3f2f 6812663 Running out of bits in x86_feature
Kuriakose Kuruvilla <kuriakose.kuruvilla@oracle.com>
parents: 12004
diff changeset
   762
	bt	$X86FSET_NX, x86_featureset
fca99d9e3f2f 6812663 Running out of bits in x86_feature
Kuriakose Kuruvilla <kuriakose.kuruvilla@oracle.com>
parents: 12004
diff changeset
   763
	jnc	1f
3446
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 2985
diff changeset
   764
	movl	%cr4, %ecx
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 2985
diff changeset
   765
	andl	$CR4_PAE, %ecx
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 2985
diff changeset
   766
	jz	1f
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 2985
diff changeset
   767
	movl	$MSR_AMD_EFER, %ecx
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 2985
diff changeset
   768
	rdmsr
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 2985
diff changeset
   769
	orl	$AMD_EFER_NXE, %eax
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 2985
diff changeset
   770
	wrmsr
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 2985
diff changeset
   771
1:
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   772
	mov	%gs:CPU_THREAD, %eax	/* get thread ptr */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   773
	call	*T_PC(%eax)		/* call mp_startup */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   774
	/* not reached */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   775
	int	$20			/* whoops, returned somehow! */
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   776
#endif
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   777
12004
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   778
	SET_SIZE(real_mode_start_cpu)
0
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   779
68f95e015346 OpenSolaris Launch
stevel@tonic-gate
parents:
diff changeset
   780
#endif	/* __amd64 */
12004
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   781
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   782
#if defined(__amd64)
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   783
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   784
	ENTRY_NP(real_mode_stop_cpu_stage1)
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   785
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   786
#if !defined(__GNUC_AS__)
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   787
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   788
	/*
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   789
	 * For vulcan as we need to do a .code32 and mentally invert the
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   790
	 * meaning of the addr16 and data16 prefixes to get 32-bit access when
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   791
	 * generating code to be executed in 16-bit mode (sigh...)
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   792
	 */
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   793
	.code32
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   794
	cli
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   795
	movw		%cs, %ax
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   796
	movw		%ax, %ds	/* load cs into ds */
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   797
	movw		%ax, %ss	/* and into ss */
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   798
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   799
	/*
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   800
	 * Jump to the stage 2 code in the rm_platter_va->rm_cpu_halt_code
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   801
	 */
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   802
	movw		$CPUHALTCODEOFF, %ax
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   803
	.byte		0xff, 0xe0	/* jmp *%ax */
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   804
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   805
#else	/* __GNUC_AS__ */
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   806
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   807
	/*
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   808
	 * NOTE:  The GNU assembler automatically does the right thing to
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   809
	 *	  generate data size operand prefixes based on the code size
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   810
	 *	  generation mode (e.g. .code16, .code32, .code64) and as such
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   811
	 *	  prefixes need not be used on instructions EXCEPT in the case
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   812
	 *	  of address prefixes for code for which the reference is not
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   813
	 *	  automatically of the default operand size.
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   814
	 */      
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   815
	.code16
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   816
	cli
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   817
	movw		%cs, %ax
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   818
	movw		%ax, %ds	/* load cs into ds */
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   819
	movw		%ax, %ss	/* and into ss */
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   820
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   821
	/*
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   822
	 * Jump to the stage 2 code in the rm_platter_va->rm_cpu_halt_code
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   823
	 */
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   824
	movw		$CPUHALTCODEOFF, %ax
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   825
	jmp		*%ax
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   826
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   827
#endif	/* !__GNUC_AS__ */
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   828
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   829
	.globl real_mode_stop_cpu_stage1_end
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   830
real_mode_stop_cpu_stage1_end:
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   831
	nop
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   832
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   833
	SET_SIZE(real_mode_stop_cpu_stage1)
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   834
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   835
#elif defined(__i386)
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   836
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   837
	ENTRY_NP(real_mode_stop_cpu_stage1)
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   838
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   839
#if !defined(__GNUC_AS__)
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   840
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   841
	cli
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   842
	D16 movw	%cs, %eax
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   843
	movw		%eax, %ds	/* load cs into ds */
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   844
	movw		%eax, %ss	/* and into ss */
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   845
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   846
	/*
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   847
	 * Jump to the stage 2 code in the rm_platter_va->rm_cpu_halt_code
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   848
	 */
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   849
	movw		$CPUHALTCODEOFF, %ax
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   850
	.byte		0xff, 0xe0	/* jmp *%ax */
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   851
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   852
#else	/* __GNUC_AS__ */
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   853
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   854
	cli
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   855
	mov		%cs, %ax
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   856
	mov		%eax, %ds	/* load cs into ds */
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   857
	mov		%eax, %ss	/* and into ss */
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   858
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   859
	/*
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   860
	 * Jump to the stage 2 code in the rm_platter_va->rm_cpu_halt_code
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   861
	 */
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   862
	movw		$CPUHALTCODEOFF, %ax
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   863
	jmp		*%ax
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   864
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   865
#endif	/* !__GNUC_AS__ */
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   866
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   867
	.globl real_mode_stop_cpu_stage1_end
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   868
real_mode_stop_cpu_stage1_end:
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   869
	nop
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   870
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   871
	SET_SIZE(real_mode_stop_cpu_stage1)
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   872
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   873
#endif	/* __amd64 */
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   874
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   875
	ENTRY_NP(real_mode_stop_cpu_stage2)
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   876
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   877
	movw		$0xdead, %ax
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   878
	movw		%ax, CPUHALTEDOFF
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   879
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   880
real_mode_stop_cpu_loop:
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   881
	/*
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   882
	 * Put CPU into halted state.
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   883
	 * Only INIT, SMI, NMI could break the loop.
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   884
	 */
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   885
	hlt
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   886
	jmp		real_mode_stop_cpu_loop
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   887
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   888
	.globl real_mode_stop_cpu_stage2_end
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   889
real_mode_stop_cpu_stage2_end:
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   890
	nop
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   891
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   892
	SET_SIZE(real_mode_stop_cpu_stage2)
93f274d4a367 PSARC/2009/104 Hot-Plug Support for ACPI-based Systems
Gerry Liu <jiang.liu@intel.com>
parents: 3446
diff changeset
   893
3446
5903aece022d PSARC 2006/469 EOF and removal of eeprom -I
mrj
parents: 2985
diff changeset
   894
#endif	/* __lint */