Subversion Repositories HelenOS-historic

Rev

Rev 534 | Rev 809 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
277 palkovsky 1
#
2
# Copyright (C) 2001-2004 Jakub Jermar
696 decky 3
# Copyright (C) 2005-2006 Martin Decky
277 palkovsky 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
 
34
#include <arch/boot/boot.h>
696 decky 35
#include <arch/boot/memmap.h>
36
#include <arch/mm/page.h>
277 palkovsky 37
#include <arch/pm.h>
38
#include <arch/cpu.h>
39
#include <arch/cpuid.h>
40
 
696 decky 41
.section K_TEXT_START, "ax"
42
 
458 decky 43
#ifdef CONFIG_SMP
277 palkovsky 44
 
696 decky 45
.global unmapped_ap_boot
277 palkovsky 46
 
47
# This piece of code is real-mode and is meant to be alligned at 4K boundary.
48
# The requirement for such an alignment comes from MP Specification's STARTUP IPI
49
# requirements.
50
 
51
.align 4096
696 decky 52
unmapped_ap_boot:
277 palkovsky 53
.code16
54
	cli
55
	xorw %ax, %ax
56
	movw %ax, %ds
57
 
696 decky 58
	lgdt ap_gdtr		# initialize Global Descriptor Table register
277 palkovsky 59
 
60
	movl %cr0, %eax
61
	orl $1, %eax
696 decky 62
	movl %eax, %cr0				# switch to protected mode
63
	jmpl $gdtselector(KTEXT32_DES), $jump_to_kernel - BOOT_OFFSET + AP_BOOT_OFFSET
277 palkovsky 64
 
696 decky 65
jump_to_kernel:
66
.code32
277 palkovsky 67
	movw $gdtselector(KDATA_DES), %ax
68
	movw %ax, %ds
696 decky 69
	movw %ax, %es
277 palkovsky 70
	movw %ax, %ss
71
 
72
	# Enable 64-bit page transaltion entries - CR4.PAE = 1.
73
	# Paging is not enabled until after long mode is enabled
696 decky 74
 
277 palkovsky 75
	movl %cr4, %eax
76
	btsl $5, %eax
77
	movl %eax, %cr4
78
 
696 decky 79
	leal ptl_0, %eax
277 palkovsky 80
	movl %eax, %cr3
81
 
82
	# Enable long mode
83
	movl $EFER_MSR_NUM, %ecx   # EFER MSR number
84
	rdmsr                   # Read EFER
85
	btsl $AMD_LME_FLAG, %eax            # Set LME=1
86
	wrmsr                   # Write EFER
87
 
88
	# Enable paging to activate long mode (set CR0.PG=1)
89
	movl %cr0, %eax
90
	btsl $31, %eax
91
	movl %eax, %cr0
92
 
93
	# At this point we are in compatibility mode
696 decky 94
	jmpl $gdtselector(KTEXT_DES), $start64 - BOOT_OFFSET + AP_BOOT_OFFSET
277 palkovsky 95
 
96
.code64
97
start64:
282 palkovsky 98
	movq (ctx), %rsp
696 decky 99
	call main_ap - AP_BOOT_OFFSET + BOOT_OFFSET   # never returns
100
 
458 decky 101
#endif /* CONFIG_SMP */
696 decky 102
 
103
.section K_DATA_START, "ax"
104
 
105
#ifdef CONFIG_SMP
106
 
107
.global unmapped_ap_gdtr
108
 
109
unmapped_ap_gdtr:
110
	.word 0
111
	.long 0
112
 
113
#endif /* CONFIG_SMP */