Subversion Repositories HelenOS

Rev

Rev 1787 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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