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

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 4b0206c was 3b0f1b9a, checked in by Jakub Jermar <jakub@…>, 9 years ago

amd64: use asmtool.h macros for defining symbols

  • Property mode set to 100644
File size: 3.2 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>
[42edee68]41
42.section K_TEXT_START, "ax"
[946b630]43
[5f85c91]44#ifdef CONFIG_SMP
[946b630]45
46# This piece of code is real-mode and is meant to be alligned at 4K boundary.
[19077a5]47# The requirement for such an alignment comes from MP Specification's STARTUP
48# IPI requirements.
[946b630]49
50.align 4096
[3b0f1b9a]51SYMBOL(unmapped_ap_boot)
[946b630]52.code16
53 cli
54 xorw %ax, %ax
55 movw %ax, %ds
[a1f60f3]56
57 lgdtl ap_gdtr # initialize Global Descriptor Table register
[946b630]58
59 movl %cr0, %eax
60 orl $1, %eax
[a1f60f3]61 movl %eax, %cr0 # switch to protected mode
[1d3d2cf]62 jmpl $GDT_SELECTOR(KTEXT32_DES), $jump_to_kernel - BOOT_OFFSET + AP_BOOT_OFFSET
[a1f60f3]63
[42edee68]64jump_to_kernel:
65.code32
[1d3d2cf]66 movw $GDT_SELECTOR(KDATA_DES), %ax
[946b630]67 movw %ax, %ds
[42edee68]68 movw %ax, %es
[946b630]69 movw %ax, %ss
[1d3d2cf]70 movw $GDT_SELECTOR(UDATA_DES), %ax
[4fdf3cc]71 movw %ax, %gs
[946b630]72
[a1f60f3]73 # Enable 64-bit page transaltion entries (CR4.PAE = 1).
[946b630]74 # Paging is not enabled until after long mode is enabled
[42edee68]75
[946b630]76 movl %cr4, %eax
77 btsl $5, %eax
78 movl %eax, %cr4
[a1f60f3]79
[42edee68]80 leal ptl_0, %eax
[946b630]81 movl %eax, %cr3
82
83 # Enable long mode
[a1f60f3]84 movl $EFER_MSR_NUM, %ecx # EFER MSR number
85 rdmsr # Read EFER
86 btsl $AMD_LME_FLAG, %eax # Set LME=1
87 wrmsr # Write EFER
[946b630]88
[a1f60f3]89 # Enable paging to activate long mode (set CR0.PG = 1)
[946b630]90 movl %cr0, %eax
91 btsl $31, %eax
92 movl %eax, %cr0
93
94 # At this point we are in compatibility mode
[1d3d2cf]95 jmpl $GDT_SELECTOR(KTEXT_DES), $start64 - BOOT_OFFSET + AP_BOOT_OFFSET
[946b630]96
97.code64
98start64:
[a1f60f3]99 movabsq $ctx, %rsp
100 movq (%rsp), %rsp
101
[304342e]102 pushq $0
103 movq %rsp, %rbp
[a1f60f3]104
105 movabsq $main_ap, %rax
106 callq *%rax # never returns
[42edee68]107
108#endif /* CONFIG_SMP */
109
[4e09712]110.section K_DATA_START, "aw", @progbits
[42edee68]111
112#ifdef CONFIG_SMP
113
[3b0f1b9a]114SYMBOL(unmapped_ap_gdtr)
[42edee68]115 .word 0
116 .long 0
117
[5f85c91]118#endif /* CONFIG_SMP */
Note: See TracBrowser for help on using the repository browser.