Subversion Repositories HelenOS

Rev

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

Rev Author Line No. Line
164 palkovsky 1
#
2
# Copyright (C) 2001-2004 Jakub Jermar
3
# All rights reserved.
4
#
5
# Redistribution and use in source and binary forms, with or without
6
# modification, are permitted provided that the following conditions
7
# are met:
8
#
9
# - Redistributions of source code must retain the above copyright
10
#   notice, this list of conditions and the following disclaimer.
11
# - Redistributions in binary form must reproduce the above copyright
12
#   notice, this list of conditions and the following disclaimer in the
13
#   documentation and/or other materials provided with the distribution.
14
# - The name of the author may not be used to endorse or promote products
15
#   derived from this software without specific prior written permission.
16
#
17
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20
# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
#
28
 
188 palkovsky 29
#include <arch/mm/ptl.h>
164 palkovsky 30
 
188 palkovsky 31
#define START_STACK     0x7c00	
32
#define START_STACK_64  $0xffffffff80007c00
33
 
164 palkovsky 34
#
35
# This is where we require any SPARTAN-kernel-compatible boot loader
36
# to pass control in real mode.
37
#
38
# Protected mode tables are statically initialised during compile
39
# time. So we can just load the respective table registers and
40
# switch to protected mode.
41
#
188 palkovsky 42
.section K_TEXT_START
43
.code16
44
.global kernel_image_start
164 palkovsky 45
kernel_image_start:
178 palkovsky 46
	cli
47
	xorw %ax,%ax
48
	movw %ax,%ds
49
	movw %ax,%ss            # initialize stack segment register
188 palkovsky 50
	movl START_STACK,%esp	# initialize stack pointer
178 palkovsky 51
 
188 palkovsky 52
#	call memmap_arch_init
178 palkovsky 53
 
54
	mov $0x80000000, %eax  
55
	cpuid
56
	cmp $0x80000000, %eax 	# any function > 80000000h?
57
	jbe no_long_mode
58
	mov $0x80000001, %eax	# Extended function code 80000001
59
	cpuid
60
	bt $29, %edx 		# Test if long mode is supported.
61
	jnc no_long_mode
164 palkovsky 62
 
188 palkovsky 63
	# Load gdtr, idtr
64
	lgdt gdtr_inst
65
	lidt idtr_inst
66
 
67
	movl %cr0,%eax
68
	orl $0x1,%eax
69
	movl %eax,%cr0			# switch to protected mode
164 palkovsky 70
 
188 palkovsky 71
	jmpl $40, $now_in_prot
164 palkovsky 72
 
188 palkovsky 73
no_long_mode:
74
1:
75
	jmp 1b
76
 
77
# Protected 16-bit. We want to reuse the code-seg descriptor,
78
# the Default operand size must not be 1 when entering long mode	
79
now_in_prot:  
80
	# Set up stack & data descriptors
81
	movw $16, %ax
82
	movw %ax, %ds
83
	movw %ax, %fs
84
	movw %ax, %gs
85
	movw %ax, %ss
86
 
87
	# Enable 64-bit page transaltion entries - CR4.PAE = 1.
88
	# Paging is not enabled until after long mode is enabled
89
	movl %cr4, %eax
90
	btsl $5, %eax
91
	movl %eax, %cr4
92
 
93
	# Set up paging tables
94
	leal ptl_0, %eax
95
	movl %eax, %cr3
96
 
97
	# Enable long mode
98
	movl $0xc0000080, %ecx   # EFER MSR number
99
	rdmsr                   # Read EFER
100
	btsl $8, %eax            # Set LME=1
101
	wrmsr                   # Write EFER
178 palkovsky 102
 
188 palkovsky 103
	# Enable paging to activate long mode (set CR0.PG=1)
104
	movl %cr0, %eax
105
	btsl $31, %eax
106
	movl %eax, %cr0
107
 
108
	# At this point we are in compatibility mode
109
	jmpl $8, $start64
164 palkovsky 110
 
188 palkovsky 111
.code64
112
start64:
113
	movq START_STACK_64, %rsp
178 palkovsky 114
 
188 palkovsky 115
	lidt idtr_inst
178 palkovsky 116
 
188 palkovsky 117
	call main_bsp   # never returns
178 palkovsky 118
1:
119
	jmp 1b
120
 
121
 
188 palkovsky 122
.section K_DATA_START
164 palkovsky 123
.align 4096
188 palkovsky 124
.global ptl_2
125
ptl_2:	
126
	.quad 0x0 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE)
127
	.quad 0x200000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE)
128
	.quad 0x400000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE)
129
	.quad 0x600000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE)
130
	.quad 0x800000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE)
131
	.quad 0xa00000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE)
132
	.quad 0xc00000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE)
133
	.quad 0xe00000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE)
134
 
135
.align 4096
136
.global ptl_1
137
ptl_1:
138
	.quad ptl_2 + (PTL_WRITABLE | PTL_PRESENT)
139
	.fill 509,8,0
140
	.quad ptl_2 + (PTL_WRITABLE | PTL_PRESENT)
141
	.fill 2,8,0
142
 
143
.align 4096
144
.global ptl_0
145
ptl_0:
146
	.quad ptl_1 + (PTL_WRITABLE | PTL_PRESENT)
147
	.fill 510,8,0
148
	.quad ptl_1 + (PTL_WRITABLE | PTL_PRESENT)
178 palkovsky 149
 
188 palkovsky 150
.global gdtr_inst				
151
gdtr_inst:
152
	.word 7*8  # GDT_ITEMS * 8
153
	.long gdt + 0x80000000
154
 
155
.global idtr_inst
156
idtr_inst:
157
	.word 0
158
	.long idt + 0x80000000