Annotation of sys/arch/amd64/amd64/mptramp.S, Revision 1.1
1.1 ! nbrk 1: /* $OpenBSD: mptramp.S,v 1.3 2005/07/26 08:38:29 art Exp $ */
! 2: /* $NetBSD: mptramp.S,v 1.1 2003/04/26 18:39:30 fvdl Exp $ */
! 3:
! 4: /*-
! 5: * Copyright (c) 2000 The NetBSD Foundation, Inc.
! 6: * All rights reserved.
! 7: *
! 8: * This code is derived from software contributed to The NetBSD Foundation
! 9: * by RedBack Networks Inc.
! 10: *
! 11: * Author: Bill Sommerfeld
! 12: *
! 13: * Redistribution and use in source and binary forms, with or without
! 14: * modification, are permitted provided that the following conditions
! 15: * are met:
! 16: * 1. Redistributions of source code must retain the above copyright
! 17: * notice, this list of conditions and the following disclaimer.
! 18: * 2. Redistributions in binary form must reproduce the above copyright
! 19: * notice, this list of conditions and the following disclaimer in the
! 20: * documentation and/or other materials provided with the distribution.
! 21: * 3. All advertising materials mentioning features or use of this software
! 22: * must display the following acknowledgement:
! 23: * This product includes software developed by the NetBSD
! 24: * Foundation, Inc. and its contributors.
! 25: * 4. Neither the name of The NetBSD Foundation nor the names of its
! 26: * contributors may be used to endorse or promote products derived
! 27: * from this software without specific prior written permission.
! 28: *
! 29: * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
! 30: * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
! 31: * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
! 32: * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
! 33: * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
! 34: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
! 35: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
! 36: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
! 37: * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
! 38: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
! 39: * POSSIBILITY OF SUCH DAMAGE.
! 40: */
! 41:
! 42: /*
! 43: * Copyright (c) 1999 Stefan Grefen
! 44: *
! 45: * Redistribution and use in source and binary forms, with or without
! 46: * modification, are permitted provided that the following conditions
! 47: * are met:
! 48: * 1. Redistributions of source code must retain the above copyright
! 49: * notice, this list of conditions and the following disclaimer.
! 50: * 2. Redistributions in binary form must reproduce the above copyright
! 51: * notice, this list of conditions and the following disclaimer in the
! 52: * documentation and/or other materials provided with the distribution.
! 53: * 3. All advertising materials mentioning features or use of this software
! 54: * must display the following acknowledgement:
! 55: * This product includes software developed by the NetBSD
! 56: * Foundation, Inc. and its contributors.
! 57: * 4. Neither the name of The NetBSD Foundation nor the names of its
! 58: * contributors may be used to endorse or promote products derived
! 59: * from this software without specific prior written permission.
! 60: *
! 61: * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY
! 62: * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
! 63: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
! 64: * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR AND CONTRIBUTORS BE LIABLE
! 65: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
! 66: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
! 67: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
! 68: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
! 69: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
! 70: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
! 71: * SUCH DAMAGE.
! 72: */
! 73: /*
! 74: * MP startup ...
! 75: * the stuff from cpu_spinup_trampoline to mp_startup
! 76: * is copied into the first 640 KB
! 77: *
! 78: * We startup the processors now when the kthreads become ready.
! 79: * The steps are:
! 80: * 1) Get the processors running kernel-code from a special
! 81: * page-table and stack page, do chip identification.
! 82: * 2) halt the processors waiting for them to be enabled
! 83: * by a idle-thread
! 84: */
! 85:
! 86: #include "assym.h"
! 87: #include <machine/param.h>
! 88: #include <machine/asm.h>
! 89: #include <machine/specialreg.h>
! 90: #include <machine/segments.h>
! 91: #include <machine/mpbiosvar.h>
! 92: #include <machine/i82489reg.h>
! 93: #include <machine/gdt.h>
! 94:
! 95: #define _RELOC(x) ((x) - KERNBASE)
! 96: #define RELOC(x) _RELOC(_C_LABEL(x))
! 97:
! 98: #define _TRMP_LABEL(a) a = . - _C_LABEL(cpu_spinup_trampoline) + MP_TRAMPOLINE
! 99:
! 100: .globl _C_LABEL(mpidle)
! 101: .global _C_LABEL(cpu_spinup_trampoline)
! 102: .global _C_LABEL(cpu_spinup_trampoline_end)
! 103: .global _C_LABEL(cpu_hatch)
! 104: .global _C_LABEL(local_apic)
! 105: .global _C_LABEL(mp_pdirpa)
! 106:
! 107: .global gdt64
! 108:
! 109: #define HALT 1: jmp 1b
! 110:
! 111: .text
! 112: .align 4,0x0
! 113: .code16
! 114: _C_LABEL(cpu_spinup_trampoline):
! 115: cli
! 116: xorw %ax,%ax
! 117: movw %ax, %ds
! 118: movw %ax, %es
! 119: movw %ax, %ss
! 120: data32 addr32 lgdt (mptramp_gdt32_desc) # load flat descriptor table
! 121: movl %cr0, %eax # get cr0
! 122: orl $0x1, %eax # enable protected mode
! 123: movl %eax, %cr0 # doit
! 124: ljmpl $0x8, $mp_startup
! 125:
! 126: _TRMP_LABEL(mp_startup)
! 127: .code32
! 128:
! 129: movl $0x10, %eax # data segment
! 130: movw %ax, %ds
! 131: movw %ax, %ss
! 132: movw %ax, %es
! 133: movw %ax, %fs
! 134: movw %ax, %gs
! 135:
! 136: movl $ (MP_TRAMPOLINE+NBPG-16),%esp # bootstrap stack end,
! 137: # with scratch space..
! 138:
! 139: /* First, reset the PSL. */
! 140: pushl $PSL_MBO
! 141: popfl
! 142:
! 143: movl %cr4,%eax
! 144: orl $(CR4_DEFAULT),%eax
! 145: movl %eax,%cr4
! 146:
! 147: movl $MSR_EFER,%ecx
! 148: rdmsr
! 149: movl %edx, %edi # %edx is needed by wrmsr below
! 150:
! 151: # Check if we need to enable NXE
! 152: movl $0x80000001, %eax
! 153: cpuid
! 154: andl $CPUID_NXE, %edx
! 155: xorl %eax,%eax
! 156: testl %edx, %edx
! 157: jz 1f
! 158: orl $EFER_NXE, %eax
! 159: 1:
! 160: orl $(EFER_LME|EFER_SCE), %eax
! 161:
! 162: movl %edi, %edx # Restore saved %edx
! 163: movl $MSR_EFER,%ecx
! 164: wrmsr
! 165:
! 166: movl $mp_tramp_pdirpa, %ecx
! 167: movl (%ecx), %ecx
! 168: movl %ecx,%cr3 # load ptd addr into mmu
! 169:
! 170: movl $GSEL(GDATA_SEL, SEL_KPL),%eax #switch to new segment
! 171: movl %eax,%ds
! 172: movl %eax,%es
! 173: movl %eax,%ss
! 174:
! 175: movl $mptramp_gdt64_desc,%eax
! 176: lgdt (%eax)
! 177: movl $mptramp_jmp64,%eax
! 178:
! 179: movl %cr0,%ecx # get control word
! 180: orl $(CR0_PE|CR0_PG|CR0_NE|CR0_TS|CR0_MP|CR0_WP),%ecx
! 181: movl %ecx, %cr0
! 182:
! 183: ljmp *(%eax)
! 184:
! 185: _TRMP_LABEL(mptramp_jmp64)
! 186: .long mptramp_longmode
! 187: .word GSEL(GCODE_SEL, SEL_KPL)
! 188:
! 189: _TRMP_LABEL(mptramp_gdt32)
! 190: .quad 0x0000000000000000
! 191: .quad 0x00cf9f000000ffff
! 192: .quad 0x00cf93000000ffff
! 193: _TRMP_LABEL(mptramp_gdt32_desc)
! 194: .word 0x17
! 195: .long mptramp_gdt32
! 196:
! 197: _TRMP_LABEL(mptramp_gdt64)
! 198: .quad 0x0000000000000000
! 199: .quad 0x00af9a000000ffff
! 200: .quad 0x00cf92000000ffff
! 201: _TRMP_LABEL(mptramp_gdt64_desc)
! 202: .word 0x17
! 203: .long mptramp_gdt64
! 204:
! 205: .global mp_pdirpa
! 206: _TRMP_LABEL(mp_pdirpa)
! 207: _TRMP_LABEL(mp_tramp_pdirpa)
! 208: .long 0
! 209:
! 210: _TRMP_LABEL(mptramp_longmode)
! 211: .code64
! 212: movabsq $_C_LABEL(cpu_spinup_trampoline_end),%rax
! 213: jmp *%rax
! 214:
! 215:
! 216:
! 217: _C_LABEL(cpu_spinup_trampoline_end): #end of code copied to MP_TRAMPOLINE
! 218: movl _C_LABEL(local_apic)+LAPIC_ID,%ecx
! 219: shrl $LAPIC_ID_SHIFT,%ecx
! 220: movq _C_LABEL(cpu_info)(,%rcx,8),%rdi
! 221:
! 222: movq CPU_INFO_IDLE_PCB(%rdi),%rsi
! 223:
! 224: movq PCB_RSP(%rsi),%rsp
! 225: movq PCB_RBP(%rsi),%rbp
! 226:
! 227: movq CPU_INFO_GDT(%rdi),%rax
! 228: movw $(MAXGDTSIZ-1),-10(%rsp)
! 229: movq %rax,-8(%rsp)
! 230: lgdt -10(%rsp)
! 231:
! 232: /* Switch address space. */
! 233: movq PCB_CR3(%rsi),%rax
! 234: movq %rax,%cr3
! 235: movl PCB_CR0(%rsi),%eax
! 236: movq %rax,%cr0
! 237: call _C_LABEL(cpu_hatch)
! 238: xorq %r13,%r13
! 239: jmp _C_LABEL(mpidle)
CVSweb