source: mainline/kernel/arch/amd64/src/smp/ap.S

Last change on this file was 65f3117, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 2 years ago

Make bootstrap stack statically, rather than dynamically allocated

With aligment requirements being part of the language now, it is
simple to allocate the extra stack area in kernel data, and we
don't need to go to so much trouble with manual allocation.
It also makes it slightly more straightforward to use the stack
from assembly, without having to dig through a saved context
structure.

  • Property mode set to 100644
File size: 3.3 KB
RevLine 
[946b630]1#
[19077a5]2# Copyright (c) 2008 Jakub Jermar
[df4ed85]3# Copyright (c) 2005-2006 Martin Decky
[946b630]4# All rights reserved.
5#
6# Redistribution and use in source and binary forms, with or without
7# modification, are permitted provided that the following conditions
8# are met:
9#
10# - Redistributions of source code must retain the above copyright
11# notice, this list of conditions and the following disclaimer.
12# - Redistributions in binary form must reproduce the above copyright
13# notice, this list of conditions and the following disclaimer in the
14# documentation and/or other materials provided with the distribution.
15# - The name of the author may not be used to endorse or promote products
16# derived from this software without specific prior written permission.
17#
18# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28#
29
30#
31# Init code for application processors.
32#
33
[3b0f1b9a]34#include <abi/asmtool.h>
[946b630]35#include <arch/boot/boot.h>
[42edee68]36#include <arch/boot/memmap.h>
37#include <arch/mm/page.h>
[946b630]38#include <arch/pm.h>
39#include <arch/cpu.h>
40#include <arch/cpuid.h>
[4928165]41#include <arch/context_struct.h>
[42edee68]42
43.section K_TEXT_START, "ax"
[946b630]44
[5f85c91]45#ifdef CONFIG_SMP
[946b630]46
47# This piece of code is real-mode and is meant to be alligned at 4K boundary.
[19077a5]48# The requirement for such an alignment comes from MP Specification's STARTUP
49# IPI requirements.
[946b630]50
51.align 4096
[3b0f1b9a]52SYMBOL(unmapped_ap_boot)
[946b630]53.code16
54 cli
55 xorw %ax, %ax
56 movw %ax, %ds
[a35b458]57
[a1f60f3]58 lgdtl ap_gdtr # initialize Global Descriptor Table register
[a35b458]59
[946b630]60 movl %cr0, %eax
[57c2a87]61 orl $CR0_PE, %eax
[a1f60f3]62 movl %eax, %cr0 # switch to protected mode
[1d3d2cf]63 jmpl $GDT_SELECTOR(KTEXT32_DES), $jump_to_kernel - BOOT_OFFSET + AP_BOOT_OFFSET
[a1f60f3]64
[42edee68]65jump_to_kernel:
66.code32
[1d3d2cf]67 movw $GDT_SELECTOR(KDATA_DES), %ax
[946b630]68 movw %ax, %ds
[42edee68]69 movw %ax, %es
[946b630]70 movw %ax, %ss
[1d3d2cf]71 movw $GDT_SELECTOR(UDATA_DES), %ax
[4fdf3cc]72 movw %ax, %gs
[a35b458]73
[d4eba6d]74 # Enable 64-bit page translation entries (CR4.PAE = 1).
[946b630]75 # Paging is not enabled until after long mode is enabled
[a35b458]76
[946b630]77 movl %cr4, %eax
[811770c]78 orl $CR4_PAE, %eax
[946b630]79 movl %eax, %cr4
[a35b458]80
[42edee68]81 leal ptl_0, %eax
[946b630]82 movl %eax, %cr3
[a35b458]83
[946b630]84 # Enable long mode
[811770c]85 movl $AMD_MSR_EFER, %ecx # EFER MSR number
[a1f60f3]86 rdmsr # Read EFER
[811770c]87 orl $AMD_LME, %eax # Set LME=1
[a1f60f3]88 wrmsr # Write EFER
[a35b458]89
[a1f60f3]90 # Enable paging to activate long mode (set CR0.PG = 1)
[946b630]91 movl %cr0, %eax
[811770c]92 orl $CR0_PG, %eax
[946b630]93 movl %eax, %cr0
[a35b458]94
[946b630]95 # At this point we are in compatibility mode
[1d3d2cf]96 jmpl $GDT_SELECTOR(KTEXT_DES), $start64 - BOOT_OFFSET + AP_BOOT_OFFSET
[946b630]97
98.code64
99start64:
[65f3117]100 movabsq $bootstrap_stack_top, %rsp
101 movq (%rsp), %rsp
[a35b458]102
[65f3117]103 pushq $0
[304342e]104 pushq $0
105 movq %rsp, %rbp
[a35b458]106
[a1f60f3]107 movabsq $main_ap, %rax
108 callq *%rax # never returns
[42edee68]109
110#endif /* CONFIG_SMP */
111
[4e09712]112.section K_DATA_START, "aw", @progbits
[42edee68]113
114#ifdef CONFIG_SMP
115
[3b0f1b9a]116SYMBOL(unmapped_ap_gdtr)
[42edee68]117 .word 0
118 .long 0
119
[5f85c91]120#endif /* CONFIG_SMP */
Note: See TracBrowser for help on using the repository browser.