Subversion Repositories HelenOS

Rev

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

Rev 1063 Rev 1289
1
#
1
#
2
# Copyright (C) 2005 Ondrej Palkovsky
2
# Copyright (C) 2005 Ondrej Palkovsky
3
# Copyright (C) 2006 Martin Decky
3
# Copyright (C) 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/mm/ptl.h>
33
#include <arch/mm/ptl.h>
34
#include <arch/pm.h>
34
#include <arch/pm.h>
35
#include <arch/cpu.h>
35
#include <arch/cpu.h>
36
#include <arch/cpuid.h>
36
#include <arch/cpuid.h>
37
 
37
 
38
#define START_STACK	(BOOT_OFFSET - BOOT_STACK_SIZE)
38
#define START_STACK	(BOOT_OFFSET - BOOT_STACK_SIZE)
39
	
39
	
40
.section K_TEXT_START, "ax"
40
.section K_TEXT_START, "ax"
41
 
41
 
42
.code32
42
.code32
43
.align 4
43
.align 4
44
.global multiboot_image_start
44
.global multiboot_image_start
45
multiboot_header:
45
multiboot_header:
46
	.long MULTIBOOT_HEADER_MAGIC
46
	.long MULTIBOOT_HEADER_MAGIC
47
	.long MULTIBOOT_HEADER_FLAGS
47
	.long MULTIBOOT_HEADER_FLAGS
48
	.long -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS)	# checksum
48
	.long -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS)	# checksum
49
	.long multiboot_header
49
	.long multiboot_header
50
	.long unmapped_ktext_start
50
	.long unmapped_ktext_start
51
	.long 0
51
	.long 0
52
	.long 0
52
	.long 0
53
	.long multiboot_image_start
53
	.long multiboot_image_start
54
 
54
 
55
multiboot_image_start:
55
multiboot_image_start:
56
	movl $START_STACK, %esp			# initialize stack pointer
56
	movl $START_STACK, %esp			# initialize stack pointer
57
	lgdt bootstrap_gdtr				# initialize Global Descriptor Table register
57
	lgdt bootstrap_gdtr				# initialize Global Descriptor Table register
58
 
58
 
59
	movw $gdtselector(KDATA_DES), %cx
59
	movw $gdtselector(KDATA_DES), %cx
60
	movw %cx, %es
60
	movw %cx, %es
61
	movw %cx, %ds							# kernel data + stack
61
	movw %cx, %ds							# kernel data + stack
62
	movw %cx, %ss
62
	movw %cx, %ss
63
	# Simics seems to remove hidden part of GS on entering user mode
63
	# Simics seems to remove hidden part of GS on entering user mode
64
	#  when _visible_ part of GS does not point to user-mode segment
64
	#  when _visible_ part of GS does not point to user-mode segment
65
	movw $gdtselector(UDATA_DES), %cx
65
	movw $gdtselector(UDATA_DES), %cx
66
	movw %cx, %fs
66
	movw %cx, %fs
67
	movw %cx, %gs
67
	movw %cx, %gs
68
	
68
	
69
	jmpl $gdtselector(KTEXT32_DES), $multiboot_meeting_point
69
	jmpl $gdtselector(KTEXT32_DES), $multiboot_meeting_point
70
	multiboot_meeting_point:
70
	multiboot_meeting_point:
71
	
71
	
72
	movl %eax, grub_eax							# save parameters from GRUB
72
	movl %eax, grub_eax							# save parameters from GRUB
73
	movl %ebx, grub_ebx
73
	movl %ebx, grub_ebx
74
	
74
	
-
 
75
#ifdef CONFIG_FB
-
 
76
	mov $vesa_init,%esi;
-
 
77
	mov $VESA_INIT_SEGMENT<<4,%edi;
-
 
78
	mov $e_vesa_init-vesa_init,%ecx;
-
 
79
	cld;
-
 
80
	rep movsb;
-
 
81
 
-
 
82
	mov $VESA_INIT_SEGMENT<<4,%edi;
-
 
83
	call *%edi;
-
 
84
	mov %esi,KA2PA(vesa_ph_addr);
-
 
85
	mov %di,KA2PA(vesa_height);
-
 
86
	shr $16,%edi;
-
 
87
	mov %di,KA2PA(vesa_width);
-
 
88
	mov %bx,KA2PA(vesa_scanline);
-
 
89
	shr $16,%ebx;
-
 
90
	mov %bx,KA2PA(vesa_bpp);
-
 
91
#endif	
-
 
92
 
75
	# Protected 32-bit. We want to reuse the code-seg descriptor,
93
	# Protected 32-bit. We want to reuse the code-seg descriptor,
76
	# the Default operand size must not be 1 when entering long mode
94
	# the Default operand size must not be 1 when entering long mode
77
	
95
	
78
	movl $0x80000000, %eax  
96
	movl $0x80000000, %eax  
79
 	cpuid
97
 	cpuid
80
 	cmp $0x80000000, %eax						# any function > 80000000h?
98
 	cmp $0x80000000, %eax						# any function > 80000000h?
81
	jbe long_mode_unsupported
99
	jbe long_mode_unsupported
82
	movl $(AMD_CPUID_EXTENDED), %eax			# Extended function code 80000001
100
	movl $(AMD_CPUID_EXTENDED), %eax			# Extended function code 80000001
83
	cpuid
101
	cpuid
84
	bt $29, %edx								# Test if long mode is supported.
102
	bt $29, %edx								# Test if long mode is supported.
85
 	jc long_mode_supported
103
 	jc long_mode_supported
86
 
104
 
87
	long_mode_unsupported:
105
	long_mode_unsupported:
88
		cli
106
		cli
89
		hlt
107
		hlt
90
	
108
	
91
	long_mode_supported:
109
	long_mode_supported:
92
	
110
	
93
	# Enable 64-bit page transaltion entries - CR4.PAE = 1.
111
	# Enable 64-bit page transaltion entries - CR4.PAE = 1.
94
	# Paging is not enabled until after long mode is enabled
112
	# Paging is not enabled until after long mode is enabled
95
	
113
	
96
	movl %cr4, %eax
114
	movl %cr4, %eax
97
	btsl $5, %eax
115
	btsl $5, %eax
98
	movl %eax, %cr4
116
	movl %eax, %cr4
99
 
117
 
100
	# Set up paging tables
118
	# Set up paging tables
101
	
119
	
102
	leal ptl_0, %eax
120
	leal ptl_0, %eax
103
	movl %eax, %cr3
121
	movl %eax, %cr3
104
	
122
	
105
	# Enable long mode
123
	# Enable long mode
106
	
124
	
107
	movl $EFER_MSR_NUM, %ecx	# EFER MSR number
125
	movl $EFER_MSR_NUM, %ecx	# EFER MSR number
108
	rdmsr						# Read EFER
126
	rdmsr						# Read EFER
109
	btsl $AMD_LME_FLAG, %eax	# Set LME=1
127
	btsl $AMD_LME_FLAG, %eax	# Set LME=1
110
	wrmsr						# Write EFER
128
	wrmsr						# Write EFER
111
	
129
	
112
	# Enable paging to activate long mode (set CR0.PG=1)
130
	# Enable paging to activate long mode (set CR0.PG=1)
113
	
131
	
114
	movl %cr0, %eax
132
	movl %cr0, %eax
115
	btsl $31, %eax
133
	btsl $31, %eax
116
	movl %eax, %cr0
134
	movl %eax, %cr0
117
	
135
	
118
	# At this point we are in compatibility mode
136
	# At this point we are in compatibility mode
119
	
137
	
120
	jmpl $gdtselector(KTEXT_DES), $start64
138
	jmpl $gdtselector(KTEXT_DES), $start64
121
 
139
 
122
.code64
140
.code64
123
start64:
141
start64:
124
	movq $(PA2KA(START_STACK)), %rsp
142
	movq $(PA2KA(START_STACK)), %rsp
125
	movl grub_eax, %eax
143
	movl grub_eax, %eax
126
	movl grub_ebx, %ebx
144
	movl grub_ebx, %ebx
127
	
145
	
128
	cmpl $MULTIBOOT_LOADER_MAGIC, %eax				# compare GRUB signature
146
	cmpl $MULTIBOOT_LOADER_MAGIC, %eax				# compare GRUB signature
129
	je valid_boot
147
	je valid_boot
130
		
148
		
131
		xorl %ecx, %ecx							# no memory size or map available
149
		xorl %ecx, %ecx							# no memory size or map available
132
		movl %ecx, e801memorysize
150
		movl %ecx, e801memorysize
133
		movl %ecx, e820counter
151
		movl %ecx, e820counter
134
		
152
		
135
		jmp invalid_boot
153
		jmp invalid_boot
136
		
154
		
137
	valid_boot:
155
	valid_boot:
138
		
156
		
139
		movl (%ebx), %eax						# ebx = physical address of struct multiboot_info
157
		movl (%ebx), %eax						# ebx = physical address of struct multiboot_info
140
		
158
		
141
		bt $0, %eax								# mbi->flags[0] (mem_lower, mem_upper valid)
159
		bt $0, %eax								# mbi->flags[0] (mem_lower, mem_upper valid)
142
		jc mem_valid
160
		jc mem_valid
143
			
161
			
144
			xorl %ecx, %ecx
162
			xorl %ecx, %ecx
145
			jmp mem_invalid
163
			jmp mem_invalid
146
			
164
			
147
		mem_valid:
165
		mem_valid:
148
		movl 4(%ebx), %ecx						# mbi->mem_lower
166
		movl 4(%ebx), %ecx						# mbi->mem_lower
149
		addl 8(%ebx), %ecx						# mbi->mem_upper
167
		addl 8(%ebx), %ecx						# mbi->mem_upper
150
		
168
		
151
		mem_invalid:
169
		mem_invalid:
152
		movl %ecx, e801memorysize
170
		movl %ecx, e801memorysize
153
		
171
		
154
		bt $3, %eax								# mbi->flags[3] (mods_count, mods_addr valid)
172
		bt $3, %eax								# mbi->flags[3] (mods_count, mods_addr valid)
155
		jc mods_valid
173
		jc mods_valid
156
			
174
			
157
			xorq %rcx, %rcx
175
			xorq %rcx, %rcx
158
			movq %rcx, init
176
			movq %rcx, init
159
			jmp mods_end
177
			jmp mods_end
160
		
178
		
161
		mods_valid:
179
		mods_valid:
162
		
180
		
163
		xorq %rcx, %rcx
181
		xorq %rcx, %rcx
164
		movl 20(%ebx), %ecx						# mbi->mods_count
182
		movl 20(%ebx), %ecx						# mbi->mods_count
165
		movq %rcx, init
183
		movq %rcx, init
166
		
184
		
167
		cmpl $0, %ecx
185
		cmpl $0, %ecx
168
		je mods_end
186
		je mods_end
169
		
187
		
170
		movl 24(%ebx), %esi						# mbi->mods_addr
188
		movl 24(%ebx), %esi						# mbi->mods_addr
171
		movq $init, %rdi
189
		movq $init, %rdi
172
		
190
		
173
		mods_loop:
191
		mods_loop:
174
			
192
			
175
			xorq %rdx, %rdx
193
			xorq %rdx, %rdx
176
			movl 0(%esi), %edx					# mods->mod_start
194
			movl 0(%esi), %edx					# mods->mod_start
177
			movq $0xffff800000000000, %r10
195
			movq $0xffff800000000000, %r10
178
			addq %r10, %rdx
196
			addq %r10, %rdx
179
			movq %rdx, 8(%rdi)
197
			movq %rdx, 8(%rdi)
180
			
198
			
181
			xorq %rdx, %rdx
199
			xorq %rdx, %rdx
182
			movl 4(%esi), %edx
200
			movl 4(%esi), %edx
183
			subl 0(%esi), %edx					# mods->mod_end - mods->mod_start
201
			subl 0(%esi), %edx					# mods->mod_end - mods->mod_start
184
			movq %rdx, 16(%rdi)
202
			movq %rdx, 16(%rdi)
185
			
203
			
186
			addl $16, %esi
204
			addl $16, %esi
187
			addq $16, %rdi
205
			addq $16, %rdi
188
			
206
			
189
			loop mods_loop
207
			loop mods_loop
190
			
208
			
191
		mods_end:
209
		mods_end:
192
		
210
		
193
		bt $6, %eax								# mbi->flags[6] (mmap_length, mmap_addr valid)	
211
		bt $6, %eax								# mbi->flags[6] (mmap_length, mmap_addr valid)	
194
		jc mmap_valid
212
		jc mmap_valid
195
			
213
			
196
			xorl %edx, %edx
214
			xorl %edx, %edx
197
			jmp mmap_invalid
215
			jmp mmap_invalid
198
			
216
			
199
		mmap_valid:
217
		mmap_valid:
200
		movl 44(%ebx), %ecx						# mbi->mmap_length
218
		movl 44(%ebx), %ecx						# mbi->mmap_length
201
		movl 48(%ebx), %esi						# mbi->mmap_addr
219
		movl 48(%ebx), %esi						# mbi->mmap_addr
202
		movq $e820table, %rdi
220
		movq $e820table, %rdi
203
		xorl %edx, %edx
221
		xorl %edx, %edx
204
		
222
		
205
		mmap_loop:
223
		mmap_loop:
206
			cmpl $0, %ecx
224
			cmpl $0, %ecx
207
			jle mmap_end
225
			jle mmap_end
208
			
226
			
209
			movl 4(%esi), %eax					# mmap->base_addr_low
227
			movl 4(%esi), %eax					# mmap->base_addr_low
210
			movl %eax, (%rdi)
228
			movl %eax, (%rdi)
211
			
229
			
212
			movl 8(%esi), %eax					# mmap->base_addr_high
230
			movl 8(%esi), %eax					# mmap->base_addr_high
213
			movl %eax, 4(%rdi)
231
			movl %eax, 4(%rdi)
214
			
232
			
215
			movl 12(%esi), %eax					# mmap->length_low
233
			movl 12(%esi), %eax					# mmap->length_low
216
			movl %eax, 8(%rdi)
234
			movl %eax, 8(%rdi)
217
			
235
			
218
			movl 16(%esi), %eax					# mmap->length_high
236
			movl 16(%esi), %eax					# mmap->length_high
219
			movl %eax, 12(%rdi)
237
			movl %eax, 12(%rdi)
220
			
238
			
221
			movl 20(%esi), %eax					# mmap->type
239
			movl 20(%esi), %eax					# mmap->type
222
			movl %eax, 16(%rdi)
240
			movl %eax, 16(%rdi)
223
			
241
			
224
			movl (%esi), %eax					# mmap->size
242
			movl (%esi), %eax					# mmap->size
225
			addl $0x4, %eax
243
			addl $0x4, %eax
226
			addl %eax, %esi
244
			addl %eax, %esi
227
			subl %eax, %ecx
245
			subl %eax, %ecx
228
			addq $MEMMAP_E820_RECORD_SIZE, %rdi
246
			addq $MEMMAP_E820_RECORD_SIZE, %rdi
229
			incl %edx
247
			incl %edx
230
			jmp mmap_loop
248
			jmp mmap_loop
231
		
249
		
232
		mmap_end:
250
		mmap_end:
233
		
251
		
234
		mmap_invalid:
252
		mmap_invalid:
235
		movl %edx, e820counter
253
		movl %edx, e820counter
236
		
254
		
237
	invalid_boot:
255
	invalid_boot:
238
	
256
	
239
#ifdef CONFIG_SMP
257
#ifdef CONFIG_SMP
240
	
258
	
241
	# copy AP bootstrap routines below 1 MB
259
	# copy AP bootstrap routines below 1 MB
242
	
260
	
243
	movq $BOOT_OFFSET, %rsi
261
	movq $BOOT_OFFSET, %rsi
244
	movq $AP_BOOT_OFFSET, %rdi
262
	movq $AP_BOOT_OFFSET, %rdi
245
	movq $_hardcoded_unmapped_size, %rcx
263
	movq $_hardcoded_unmapped_size, %rcx
246
	cld
264
	cld
247
	rep movsb
265
	rep movsb
248
	
266
	
249
#endif
267
#endif
250
	
268
	
251
	call main_bsp   # never returns
269
	call main_bsp   # never returns
252
	
270
	
253
	cli
271
	cli
254
	hlt
272
	hlt
-
 
273
 
-
 
274
#ifdef CONFIG_FB
-
 
275
.code32
-
 
276
vesa_init:
-
 
277
	jmp $gdtselector(VESA_INIT_DES),$vesa_init_real-vesa_init;
-
 
278
.code16
-
 
279
vesa_init_real:	
-
 
280
 
-
 
281
	mov %cr0,%eax;
-
 
282
	and $~1,%eax;
-
 
283
	mov %eax,%cr0;
-
 
284
 
-
 
285
 
-
 
286
	jmp $VESA_INIT_SEGMENT,$vesa_init_real2-vesa_init;
-
 
287
 
-
 
288
vesa_init_real2:	
-
 
289
 
-
 
290
 
-
 
291
	mov %esp,%ebp;
-
 
292
	mov %ss,%cx;
-
 
293
	mov $VESA_INIT_SEGMENT,%bx;
-
 
294
	mov %bx,%ss;
-
 
295
	mov $0x0000fffc,%esp;
-
 
296
	push %ds;
-
 
297
	push %es;
-
 
298
	push %fs;
-
 
299
	push %gs;
-
 
300
	push %ebp;
-
 
301
	push %cx;
-
 
302
 
-
 
303
	mov %bx,%ds;
-
 
304
	mov %bx,%es;
-
 
305
	mov %bx,%fs;
-
 
306
	mov %bx,%gs;
-
 
307
 
-
 
308
	
-
 
309
	mov $vesa_idt-vesa_init,%ebx;
-
 
310
	lidtl (%ebx);
-
 
311
 
-
 
312
#define VESA_INFO_SIZE 1024
-
 
313
 
-
 
314
#define VESA_MODE_LIST_PTR_OFFSET 14 
-
 
315
#define VESA_MODE_WIDTH_OFFSET 18
-
 
316
#define VESA_MODE_HEIGHT_OFFSET 20
-
 
317
#define VESA_MODE_BPP_OFFSET 25
-
 
318
#define VESA_MODE_SCANLINE_OFFSET 16
-
 
319
#define VESA_MODE_PHADDR_OFFSET 40
-
 
320
 
-
 
321
#define VESA_END_OF_MODES 0xffff 
-
 
322
 
-
 
323
#define VESA_OK 0x4f 
-
 
324
 
-
 
325
#define VESA_GET_INFO 0x4f00 
-
 
326
#define VESA_GET_MODE_INFO 0x4f01
-
 
327
#define VESA_SET_MODE 0x4f02
-
 
328
 
-
 
329
#define CONFIG_VESA_BPP_a 255
-
 
330
 
-
 
331
#if CONFIG_VESA_BPP==24
-
 
332
#undef CONFIG_VESA_BPP_a
-
 
333
#define CONFIG_VESA_BPP_a 32
-
 
334
#endif
-
 
335
 
-
 
336
 
-
 
337
	mov $VESA_GET_INFO,%ax;
-
 
338
	mov $e_vesa_init-vesa_init,%di
-
 
339
	push %di;
-
 
340
	int $0x10;	
-
 
341
	pop %di;
-
 
342
	cmp $VESA_OK,%al;
-
 
343
	jnz 0f;
-
 
344
	mov 2+VESA_MODE_LIST_PTR_OFFSET(%di),%si;
-
 
345
	mov %si,%gs;
-
 
346
	mov VESA_MODE_LIST_PTR_OFFSET(%di),%si;
-
 
347
 
-
 
348
	add $VESA_INFO_SIZE,%di;
-
 
349
 
-
 
350
1:# Try next mode
-
 
351
	mov %gs:(%si),%cx;
-
 
352
	cmp $VESA_END_OF_MODES,%cx;
-
 
353
	jz 0f;
-
 
354
	inc %si;
-
 
355
	inc %si;
-
 
356
	push %cx;
-
 
357
	push %di;
-
 
358
	push %si;
-
 
359
	mov $VESA_GET_MODE_INFO,%ax;
-
 
360
	int $0x10;
-
 
361
	pop %si;
-
 
362
	pop %di;
-
 
363
	pop %cx;
-
 
364
	cmp $VESA_OK,%al;
-
 
365
	jnz 0f;
-
 
366
 
-
 
367
 
-
 
368
	mov $CONFIG_VESA_WIDTH,%ax;
-
 
369
	cmp VESA_MODE_WIDTH_OFFSET(%di),%ax;
-
 
370
	jnz 1b;
-
 
371
	mov $CONFIG_VESA_HEIGHT,%ax;
-
 
372
	cmp VESA_MODE_HEIGHT_OFFSET(%di),%ax;
-
 
373
	jnz 1b;
-
 
374
	mov $CONFIG_VESA_BPP,%al;
-
 
375
	cmp VESA_MODE_BPP_OFFSET(%di),%al;
-
 
376
	jz 2f;
-
 
377
	mov $CONFIG_VESA_BPP_a,%al;
-
 
378
	cmp VESA_MODE_BPP_OFFSET(%di),%al;
-
 
379
	jnz 1b;
-
 
380
 
-
 
381
2:
-
 
382
 
-
 
383
	mov %cx,%bx;
-
 
384
	or $0xC000,%bx;
-
 
385
	push %di;
-
 
386
	mov $VESA_SET_MODE,%ax;
-
 
387
	int $0x10;
-
 
388
	pop %di;
-
 
389
	cmp $VESA_OK,%al;
-
 
390
	jnz 0f;
-
 
391
	
-
 
392
	mov VESA_MODE_PHADDR_OFFSET(%di),%esi;
-
 
393
	mov VESA_MODE_WIDTH_OFFSET(%di),%ax;
-
 
394
	shl $16,%eax;
-
 
395
	mov VESA_MODE_HEIGHT_OFFSET(%di),%ax;
-
 
396
	mov VESA_MODE_BPP_OFFSET(%di),%bl;
-
 
397
	xor %bh,%bh;
-
 
398
	shl $16,%ebx;
-
 
399
	mov VESA_MODE_SCANLINE_OFFSET(%di),%bx;
-
 
400
	mov %eax,%edi; 
-
 
401
	
-
 
402
	
-
 
403
 
-
 
404
8:	
-
 
405
 
-
 
406
	mov %cr0,%eax;
-
 
407
	or $1,%eax;
-
 
408
	mov %eax,%cr0;
-
 
409
 
-
 
410
	jmp 9f;
-
 
411
9:
-
 
412
 
-
 
413
	pop %cx;
-
 
414
	pop %ebp;
-
 
415
	pop %gs;
-
 
416
	pop %fs;
-
 
417
	pop %es;
-
 
418
	pop %ds;
-
 
419
	mov %cx,%ss;
-
 
420
	mov %ebp,%esp;
-
 
421
 
-
 
422
	ljmpl $gdtselector(KTEXT32_DES),$(vesa_init_protect-vesa_init+VESA_INIT_SEGMENT<<4);
-
 
423
 
-
 
424
vesa_init_protect:	
-
 
425
.code32
-
 
426
	ret;
-
 
427
 
-
 
428
0:	#Error no Prefered mode found
-
 
429
 
-
 
430
	mov $0x111,%cx;
-
 
431
	push %di;
-
 
432
	push %cx;
-
 
433
	mov $VESA_GET_MODE_INFO,%ax;
-
 
434
	int $0x10;
-
 
435
	pop %cx;
-
 
436
	pop %di;
-
 
437
	cmp $VESA_OK,%al;
-
 
438
	jnz 1f;
-
 
439
	jmp 2b;
-
 
440
 
-
 
441
1:mov $0x0003,%ax;
-
 
442
	int $0x10;
-
 
443
	mov $0xffffffff,%edi; /* EGA text mode used, because of problems with VESA */
-
 
444
	jmp 8;
-
 
445
 
-
 
446
 
-
 
447
vesa_idt:
-
 
448
.word 0x03ff
-
 
449
.long 0
-
 
450
.align 4
-
 
451
e_vesa_init:
-
 
452
#endif	
-
 
453
 
-
 
454
 
255
				
455
				
256
.section K_DATA_START, "aw", @progbits
456
.section K_DATA_START, "aw", @progbits
257
.align 4096
457
.align 4096
258
 
458
 
259
# Identical mapping of first 64MB and the same of -2GB -> 0	
459
# Identical mapping of first 64MB and the same of -2GB -> 0	
260
.global ptl_2
460
.global ptl_2
261
ptl_2:	
461
ptl_2:	
262
	.quad 0x0 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE)
462
	.quad 0x0 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE)
263
	.quad 0x200000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE)
463
	.quad 0x200000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE)
264
	.quad 0x400000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE)
464
	.quad 0x400000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE)
265
	.quad 0x600000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE)
465
	.quad 0x600000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE)
266
	.quad 0x800000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE)
466
	.quad 0x800000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE)
267
	.quad 0xa00000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE)
467
	.quad 0xa00000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE)
268
	.quad 0xc00000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE)
468
	.quad 0xc00000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE)
269
	.quad 0xe00000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE)
469
	.quad 0xe00000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE)
270
	.quad 0x1000000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE)
470
	.quad 0x1000000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE)
271
	.quad 0x1200000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE)
471
	.quad 0x1200000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE)
272
	.quad 0x1400000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE)
472
	.quad 0x1400000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE)
273
	.quad 0x1600000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE)
473
	.quad 0x1600000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE)
274
	.quad 0x1800000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE)
474
	.quad 0x1800000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE)
275
	.quad 0x1a00000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE)
475
	.quad 0x1a00000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE)
276
	.quad 0x1c00000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE)
476
	.quad 0x1c00000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE)
277
	.quad 0x1e00000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE)
477
	.quad 0x1e00000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE)
278
	.quad 0x2000000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE)
478
	.quad 0x2000000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE)
279
	.quad 0x2200000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE)
479
	.quad 0x2200000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE)
280
	.quad 0x2400000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE)
480
	.quad 0x2400000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE)
281
	.quad 0x2600000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE)
481
	.quad 0x2600000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE)
282
	.quad 0x2800000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE)
482
	.quad 0x2800000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE)
283
	.quad 0x2a00000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE)
483
	.quad 0x2a00000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE)
284
	.quad 0x2c00000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE)
484
	.quad 0x2c00000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE)
285
	.quad 0x2e00000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE)
485
	.quad 0x2e00000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE)
286
	.quad 0x3000000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE)
486
	.quad 0x3000000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE)
287
	.quad 0x3200000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE)
487
	.quad 0x3200000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE)
288
	.quad 0x3400000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE)
488
	.quad 0x3400000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE)
289
	.quad 0x3600000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE)
489
	.quad 0x3600000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE)
290
	.quad 0x3800000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE)
490
	.quad 0x3800000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE)
291
	.quad 0x3a00000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE)
491
	.quad 0x3a00000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE)
292
	.quad 0x3c00000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE)
492
	.quad 0x3c00000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE)
293
	.quad 0x3e00000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE)
493
	.quad 0x3e00000 | (PTL_WRITABLE | PTL_PRESENT | PTL_2MB_PAGE)
294
	
494
	
295
.align 4096
495
.align 4096
296
.global ptl_1
496
.global ptl_1
297
ptl_1:
497
ptl_1:
298
	.quad ptl_2 + (PTL_WRITABLE | PTL_PRESENT)
498
	.quad ptl_2 + (PTL_WRITABLE | PTL_PRESENT)
299
	.fill 509,8,0
499
	.fill 509,8,0
300
	.quad ptl_2 + (PTL_WRITABLE | PTL_PRESENT)
500
	.quad ptl_2 + (PTL_WRITABLE | PTL_PRESENT)
301
	.fill 1,8,0
501
	.fill 1,8,0
302
	
502
	
303
.align 4096
503
.align 4096
304
.global ptl_0
504
.global ptl_0
305
ptl_0:
505
ptl_0:
306
	.quad ptl_1 + (PTL_WRITABLE | PTL_PRESENT)
506
	.quad ptl_1 + (PTL_WRITABLE | PTL_PRESENT)
307
	.fill 255,8,0
507
	.fill 255,8,0
308
	.quad ptl_1 + (PTL_WRITABLE | PTL_PRESENT)
508
	.quad ptl_1 + (PTL_WRITABLE | PTL_PRESENT)
309
	.fill 254,8,0
509
	.fill 254,8,0
310
	.quad ptl_1 + (PTL_WRITABLE | PTL_PRESENT)
510
	.quad ptl_1 + (PTL_WRITABLE | PTL_PRESENT)
311
 
511
 
312
.global bootstrap_gdtr
512
.global bootstrap_gdtr
313
bootstrap_gdtr:
513
bootstrap_gdtr:
314
	.word gdtselector(GDT_ITEMS)
514
	.word gdtselector(GDT_ITEMS)
315
	.long KA2PA(gdt)
515
	.long KA2PA(gdt)
316
 
516
 
317
grub_eax:
517
grub_eax:
318
	.long 0
518
	.long 0
319
 
519
 
320
grub_ebx:
520
grub_ebx:
321
	.long 0
521
	.long 0
322
 
522