Subversion Repositories HelenOS

Rev

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

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