Subversion Repositories HelenOS

Rev

Rev 4127 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4127 Rev 4195
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
#include <arch/boot/boot.h>
30
#include <arch/boot/boot.h>
31
#include <arch/boot/memmap.h>
31
#include <arch/boot/memmap.h>
32
#include <arch/mm/page.h>
32
#include <arch/mm/page.h>
33
#include <arch/pm.h>
33
#include <arch/pm.h>
-
 
34
#include <arch/cpuid.h>
34
 
35
 
35
#define START_STACK (BOOT_OFFSET - BOOT_STACK_SIZE)
36
#define START_STACK (BOOT_OFFSET - BOOT_STACK_SIZE)
36
 
37
 
37
.section K_TEXT_START, "ax"
38
.section K_TEXT_START, "ax"
38
 
39
 
39
.code32
40
.code32
40
.align 4
41
.align 4
41
.global multiboot_image_start
42
.global multiboot_image_start
42
multiboot_header:
43
multiboot_header:
43
	.long MULTIBOOT_HEADER_MAGIC
44
	.long MULTIBOOT_HEADER_MAGIC
44
	.long MULTIBOOT_HEADER_FLAGS
45
	.long MULTIBOOT_HEADER_FLAGS
45
	.long -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS)  # checksum
46
	.long -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS)  # checksum
46
	.long multiboot_header
47
	.long multiboot_header
47
	.long unmapped_ktext_start
48
	.long unmapped_ktext_start
48
	.long 0
49
	.long 0
49
	.long 0
50
	.long 0
50
	.long multiboot_image_start
51
	.long multiboot_image_start
51
 
52
 
52
multiboot_image_start:
53
multiboot_image_start:
53
	cld
54
	cld
54
	movl $START_STACK, %esp     # initialize stack pointer
55
	movl $START_STACK, %esp     # initialize stack pointer
55
	lgdt KA2PA(bootstrap_gdtr)  # initialize Global Descriptor Table register
56
	lgdt KA2PA(bootstrap_gdtr)  # initialize Global Descriptor Table register
56
	
57
	
57
	movw $gdtselector(KDATA_DES), %cx
58
	movw $gdtselector(KDATA_DES), %cx
58
	movw %cx, %es
59
	movw %cx, %es
59
	movw %cx, %fs
60
	movw %cx, %fs
60
	movw %cx, %gs
61
	movw %cx, %gs
61
	movw %cx, %ds               # kernel data + stack
62
	movw %cx, %ds               # kernel data + stack
62
	movw %cx, %ss
63
	movw %cx, %ss
63
	
64
	
64
	jmpl $gdtselector(KTEXT_DES), $multiboot_meeting_point
65
	jmpl $gdtselector(KTEXT_DES), $multiboot_meeting_point
65
	multiboot_meeting_point:
66
	multiboot_meeting_point:
66
	
67
	
67
	movl %eax, grub_eax         # save parameters from GRUB
68
	movl %eax, grub_eax         # save parameters from GRUB
68
	movl %ebx, grub_ebx
69
	movl %ebx, grub_ebx
69
	
70
	
70
	xorl %eax, %eax
71
	movl $(INTEL_CPUID_LEVEL), %eax
71
	cpuid
72
	cpuid
72
	cmp $0x0, %eax              # any function > 0?
73
	cmp $0x0, %eax              # any function > 0?
73
	jbe pse_unsupported
74
	jbe pse_unsupported
-
 
75
	
74
	movl $0x1, %eax             # basic function code 1
76
	movl $(INTEL_CPUID_STANDARD), %eax
75
	cpuid
77
	cpuid
76
	bt $3, %edx                 # test if PSE is supported
78
	bt $(INTEL_PSE), %edx
77
	jc pse_supported
79
	jc pse_supported
78
	
80
	
79
	pse_unsupported:
81
	pse_unsupported:
80
		movl $pse_msg, %esi
82
		movl $pse_msg, %esi
81
		jmp error_halt
83
		jmp error_halt
82
	
84
	
83
	pse_supported:
85
	pse_supported:
-
 
86
	
-
 
87
	bt $(INTEL_SEP), %edx
-
 
88
	jc sep_supported
-
 
89
	
-
 
90
		movl $sep_msg, %esi
-
 
91
		jmp error_halt
-
 
92
	
-
 
93
	sep_supported:
84
 
94
 
85
#include "vesa_prot.inc"
95
#include "vesa_prot.inc"
86
 
96
 
87
	# map kernel and turn paging on
97
	# map kernel and turn paging on
88
	call map_kernel
98
	call map_kernel
89
	
99
	
90
	# call arch_pre_main(grub_eax, grub_ebx)
100
	# call arch_pre_main(grub_eax, grub_ebx)
91
	pushl grub_ebx
101
	pushl grub_ebx
92
	pushl grub_eax
102
	pushl grub_eax
93
	call arch_pre_main
103
	call arch_pre_main
94
	
104
	
95
	call main_bsp
105
	call main_bsp
96
	
106
	
97
	# not reached
107
	# not reached
98
	cli
108
	cli
99
	hlt0:
109
	hlt0:
100
		hlt
110
		hlt
101
		jmp hlt0
111
		jmp hlt0
102
 
112
 
103
.global map_kernel
113
.global map_kernel
104
map_kernel:
114
map_kernel:
105
	#
115
	#
106
	# Here we setup mapping for both the unmapped and mapped sections of the kernel.
116
	# Here we setup mapping for both the unmapped and mapped sections of the kernel.
107
	# For simplicity, we map the entire 4G space.
117
	# For simplicity, we map the entire 4G space.
108
	#
118
	#
109
	movl %cr4, %ecx
119
	movl %cr4, %ecx
110
	orl $(1 << 4), %ecx                 # turn PSE on
120
	orl $(1 << 4), %ecx                 # turn PSE on
111
	andl $(~(1 << 5)), %ecx             # turn PAE off
121
	andl $(~(1 << 5)), %ecx             # turn PAE off
112
	movl %ecx, %cr4
122
	movl %ecx, %cr4
113
	
123
	
114
	movl $(page_directory + 0), %esi
124
	movl $(page_directory + 0), %esi
115
	movl $(page_directory + 2048), %edi
125
	movl $(page_directory + 2048), %edi
116
	xorl %ecx, %ecx
126
	xorl %ecx, %ecx
117
	xorl %ebx, %ebx
127
	xorl %ebx, %ebx
118
	
128
	
119
	floop:
129
	floop:
120
		movl $((1 << 7) | (1 << 1) | (1 << 0)), %eax
130
		movl $((1 << 7) | (1 << 1) | (1 << 0)), %eax
121
		orl %ebx, %eax
131
		orl %ebx, %eax
122
		movl %eax, (%esi, %ecx, 4)      # mapping 0x00000000 + %ecx * 4M => 0x00000000 + %ecx * 4M
132
		movl %eax, (%esi, %ecx, 4)      # mapping 0x00000000 + %ecx * 4M => 0x00000000 + %ecx * 4M
123
		movl %eax, (%edi, %ecx, 4)      # mapping 0x80000000 + %ecx * 4M => 0x00000000 + %ecx * 4M
133
		movl %eax, (%edi, %ecx, 4)      # mapping 0x80000000 + %ecx * 4M => 0x00000000 + %ecx * 4M
124
		addl $(4 * 1024 * 1024), %ebx
134
		addl $(4 * 1024 * 1024), %ebx
125
		
135
		
126
		incl %ecx
136
		incl %ecx
127
		cmpl $512, %ecx
137
		cmpl $512, %ecx
128
		jl floop
138
		jl floop
129
	
139
	
130
	movl %esi, %cr3
140
	movl %esi, %cr3
131
	
141
	
132
	movl %cr0, %ebx
142
	movl %cr0, %ebx
133
	orl $(1 << 31), %ebx                # turn paging on
143
	orl $(1 << 31), %ebx                # turn paging on
134
	movl %ebx, %cr0
144
	movl %ebx, %cr0
135
	ret
145
	ret
136
 
146
 
137
# Print string from %esi to EGA display (in red) and halt
147
# Print string from %esi to EGA display (in red) and halt
138
error_halt:
148
error_halt:
139
	movl $0xb8000, %edi         # base of EGA text mode memory
149
	movl $0xb8000, %edi         # base of EGA text mode memory
140
	xorl %eax, %eax
150
	xorl %eax, %eax
141
	
151
	
142
	movw $0x3d4, %dx            # read bits 8 - 15 of the cursor address
152
	movw $0x3d4, %dx            # read bits 8 - 15 of the cursor address
143
	movb $0xe, %al
153
	movb $0xe, %al
144
	outb %al, %dx
154
	outb %al, %dx
145
	
155
	
146
	movw $0x3d5, %dx
156
	movw $0x3d5, %dx
147
	inb %dx, %al
157
	inb %dx, %al
148
	shl $8, %ax
158
	shl $8, %ax
149
	
159
	
150
	movw $0x3d4, %dx            # read bits 0 - 7 of the cursor address
160
	movw $0x3d4, %dx            # read bits 0 - 7 of the cursor address
151
	movb $0xf, %al
161
	movb $0xf, %al
152
	outb %al, %dx
162
	outb %al, %dx
153
	
163
	
154
	movw $0x3d5, %dx
164
	movw $0x3d5, %dx
155
	inb %dx, %al
165
	inb %dx, %al
156
	
166
	
157
	cmp $1920, %ax
167
	cmp $1920, %ax
158
	jbe cursor_ok
168
	jbe cursor_ok
159
	
169
	
160
		movw $1920, %ax         # sanity check for the cursor on the last line
170
		movw $1920, %ax         # sanity check for the cursor on the last line
161
	
171
	
162
	cursor_ok:
172
	cursor_ok:
163
	
173
	
164
	movw %ax, %bx
174
	movw %ax, %bx
165
	shl $1, %eax
175
	shl $1, %eax
166
	addl %eax, %edi
176
	addl %eax, %edi
167
	
177
	
168
	movw $0x0c00, %ax           # black background, light red foreground
178
	movw $0x0c00, %ax           # black background, light red foreground
169
	
179
	
170
	ploop:
180
	ploop:
171
		lodsb
181
		lodsb
172
		cmp $0, %al
182
		cmp $0, %al
173
		je ploop_end
183
		je ploop_end
174
		stosw
184
		stosw
175
		inc %bx
185
		inc %bx
176
		jmp ploop
186
		jmp ploop
177
	ploop_end:
187
	ploop_end:
178
	
188
	
179
	movw $0x3d4, %dx            # write bits 8 - 15 of the cursor address
189
	movw $0x3d4, %dx            # write bits 8 - 15 of the cursor address
180
	movb $0xe, %al
190
	movb $0xe, %al
181
	outb %al, %dx
191
	outb %al, %dx
182
	
192
	
183
	movw $0x3d5, %dx
193
	movw $0x3d5, %dx
184
	movb %bh, %al
194
	movb %bh, %al
185
	outb %al, %dx
195
	outb %al, %dx
186
	
196
	
187
	movw $0x3d4, %dx            # write bits 0 - 7 of the cursor address
197
	movw $0x3d4, %dx            # write bits 0 - 7 of the cursor address
188
	movb $0xf, %al
198
	movb $0xf, %al
189
	outb %al, %dx
199
	outb %al, %dx
190
	
200
	
191
	movw $0x3d5, %dx
201
	movw $0x3d5, %dx
192
	movb %bl, %al
202
	movb %bl, %al
193
	outb %al, %dx
203
	outb %al, %dx
194
	
204
	
195
	cli
205
	cli
196
	hlt1:
206
	hlt1:
197
		hlt
207
		hlt
198
		jmp hlt1
208
		jmp hlt1
199
 
209
 
200
#include "vesa_real.inc"
210
#include "vesa_real.inc"
201
 
211
 
202
.section K_DATA_START, "aw", @progbits
212
.section K_DATA_START, "aw", @progbits
203
 
213
 
204
.align 4096
214
.align 4096
205
page_directory:
215
page_directory:
206
	.space 4096, 0
216
	.space 4096, 0
207
 
217
 
208
grub_eax:
218
grub_eax:
209
	.long 0
219
	.long 0
210
 
220
 
211
grub_ebx:
221
grub_ebx:
212
	.long 0
222
	.long 0
213
 
223
 
214
pse_msg:
224
pse_msg:
215
	.asciz "Page Size Extension not supported. System halted."
225
	.asciz "Page Size Extension not supported. System halted."
-
 
226
 
-
 
227
sep_msg:
-
 
228
	.asciz "SYSENTER/SYSEXIT not supported. System halted."
216
 
229