Subversion Repositories HelenOS

Rev

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

Rev 1287 Rev 1288
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
 
34
 
35
#define START_STACK (BOOT_OFFSET - BOOT_STACK_SIZE)
35
#define START_STACK (BOOT_OFFSET - BOOT_STACK_SIZE)
36
 
36
 
37
 
-
 
38
 
-
 
39
 
-
 
40
 
-
 
41
 
-
 
42
 
-
 
43
 
-
 
44
 
-
 
45
.section K_TEXT_START, "ax"
37
.section K_TEXT_START, "ax"
46
 
38
 
47
KTEXT=8
39
KTEXT=8
48
KDATA=16
40
KDATA=16
49
 
41
 
50
.code32
42
.code32
51
.align 4
43
.align 4
52
.global multiboot_image_start
44
.global multiboot_image_start
53
multiboot_header:
45
multiboot_header:
54
	.long MULTIBOOT_HEADER_MAGIC
46
	.long MULTIBOOT_HEADER_MAGIC
55
	.long MULTIBOOT_HEADER_FLAGS
47
	.long MULTIBOOT_HEADER_FLAGS
56
	.long -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS)	# checksum
48
	.long -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS)	# checksum
57
	.long multiboot_header
49
	.long multiboot_header
58
	.long unmapped_ktext_start
50
	.long unmapped_ktext_start
59
	.long 0
51
	.long 0
60
	.long 0
52
	.long 0
61
	.long multiboot_image_start
53
	.long multiboot_image_start
62
	
54
	
63
multiboot_image_start:
55
multiboot_image_start:
64
	movl $START_STACK, %esp			# initialize stack pointer
56
	movl $START_STACK, %esp			# initialize stack pointer
65
	lgdt KA2PA(bootstrap_gdtr)		# initialize Global Descriptor Table register
57
	lgdt KA2PA(bootstrap_gdtr)		# initialize Global Descriptor Table register
66
 
58
 
67
	movw $KDATA, %cx
59
	movw $KDATA, %cx
68
	movw %cx, %es
60
	movw %cx, %es
69
	movw %cx, %gs
61
	movw %cx, %gs
70
	movw %cx, %fs
62
	movw %cx, %fs
71
	movw %cx, %ds					# kernel data + stack
63
	movw %cx, %ds					# kernel data + stack
72
	movw %cx, %ss
64
	movw %cx, %ss
73
	
65
	
74
	jmpl $KTEXT, $multiboot_meeting_point
66
	jmpl $KTEXT, $multiboot_meeting_point
75
	multiboot_meeting_point:
67
	multiboot_meeting_point:
76
	
68
	
77
	pushl %ebx							# save parameters from GRUB
69
	pushl %ebx							# save parameters from GRUB
78
	pushl %eax
70
	pushl %eax
79
 
71
 
80
#ifdef CONFIG_FB
72
#ifdef CONFIG_FB
81
	mov $vesa_init,%esi;
73
	mov $vesa_init,%esi;
82
	mov $VESA_INIT_SEGMENT<<4,%edi;
74
	mov $VESA_INIT_SEGMENT<<4,%edi;
83
	mov $e_vesa_init-vesa_init,%ecx;
75
	mov $e_vesa_init-vesa_init,%ecx;
84
	cld;
76
	cld;
85
	rep movsb;
77
	rep movsb;
86
 
78
 
87
	mov $VESA_INIT_SEGMENT<<4,%edi;
79
	mov $VESA_INIT_SEGMENT<<4,%edi;
88
	call *%edi;
80
	call *%edi;
89
	mov %esi,KA2PA(vesa_ph_addr);
81
	mov %esi,KA2PA(vesa_ph_addr);
90
	mov %di,KA2PA(vesa_height);
82
	mov %di,KA2PA(vesa_height);
91
	shr $16,%edi;
83
	shr $16,%edi;
92
	mov %di,KA2PA(vesa_width);
84
	mov %di,KA2PA(vesa_width);
93
	mov %bx,KA2PA(vesa_scanline);
85
	mov %bx,KA2PA(vesa_scanline);
94
	shr $16,%ebx;
86
	shr $16,%ebx;
95
	mov %bx,KA2PA(vesa_bpp);
87
	mov %bx,KA2PA(vesa_bpp);
96
#endif	
88
#endif	
97
	
89
	
98
	call map_kernel							# map kernel and turn paging on
90
	call map_kernel							# map kernel and turn paging on
99
	
91
	
100
	popl %eax
92
	popl %eax
101
	popl %ebx
93
	popl %ebx
102
	cmpl $MULTIBOOT_LOADER_MAGIC, %eax				# compare GRUB signature
94
	cmpl $MULTIBOOT_LOADER_MAGIC, %eax				# compare GRUB signature
103
	je valid_boot
95
	je valid_boot
104
		
96
		
105
		xorl %ecx, %ecx							# no memory size or map available
97
		xorl %ecx, %ecx							# no memory size or map available
106
		movl %ecx, e801memorysize
98
		movl %ecx, e801memorysize
107
		movl %ecx, e820counter
99
		movl %ecx, e820counter
108
		
100
		
109
		jmp invalid_boot
101
		jmp invalid_boot
110
		
102
		
111
	valid_boot:
103
	valid_boot:
112
		
104
		
113
		movl (%ebx), %eax						# ebx = physical address of struct multiboot_info
105
		movl (%ebx), %eax						# ebx = physical address of struct multiboot_info
114
		
106
		
115
		bt $0, %eax								# mbi->flags[0] (mem_lower, mem_upper valid)
107
		bt $0, %eax								# mbi->flags[0] (mem_lower, mem_upper valid)
116
		jc mem_valid
108
		jc mem_valid
117
			
109
			
118
			xorl %ecx, %ecx
110
			xorl %ecx, %ecx
119
			jmp mem_invalid
111
			jmp mem_invalid
120
			
112
			
121
		mem_valid:
113
		mem_valid:
122
		movl 4(%ebx), %ecx						# mbi->mem_lower
114
		movl 4(%ebx), %ecx						# mbi->mem_lower
123
		addl 8(%ebx), %ecx						# mbi->mem_upper
115
		addl 8(%ebx), %ecx						# mbi->mem_upper
124
		
116
		
125
		mem_invalid:
117
		mem_invalid:
126
		movl %ecx, e801memorysize
118
		movl %ecx, e801memorysize
127
		
119
		
128
		bt $3, %eax								# mbi->flags[3] (mods_count, mods_addr valid)
120
		bt $3, %eax								# mbi->flags[3] (mods_count, mods_addr valid)
129
		jc mods_valid
121
		jc mods_valid
130
			
122
			
131
			xorl %ecx, %ecx
123
			xorl %ecx, %ecx
132
			movl %ecx, init
124
			movl %ecx, init
133
			jmp mods_end
125
			jmp mods_end
134
		
126
		
135
		mods_valid:
127
		mods_valid:
136
		
128
		
137
		movl 20(%ebx), %ecx						# mbi->mods_count
129
		movl 20(%ebx), %ecx						# mbi->mods_count
138
		movl %ecx, init
130
		movl %ecx, init
139
		
131
		
140
		cmpl $0, %ecx
132
		cmpl $0, %ecx
141
		je mods_end
133
		je mods_end
142
		
134
		
143
		movl 24(%ebx), %esi						# mbi->mods_addr
135
		movl 24(%ebx), %esi						# mbi->mods_addr
144
		movl $init, %edi
136
		movl $init, %edi
145
		
137
		
146
		mods_loop:
138
		mods_loop:
147
		
139
		
148
			movl 0(%esi), %edx					# mods->mod_start
140
			movl 0(%esi), %edx					# mods->mod_start
149
			addl $0x80000000, %edx
141
			addl $0x80000000, %edx
150
			movl %edx, 4(%edi)
142
			movl %edx, 4(%edi)
151
			
143
			
152
			movl 4(%esi), %edx
144
			movl 4(%esi), %edx
153
			subl 0(%esi), %edx					# mods->mod_end - mods->mod_start
145
			subl 0(%esi), %edx					# mods->mod_end - mods->mod_start
154
			movl %edx, 8(%edi)
146
			movl %edx, 8(%edi)
155
			
147
			
156
			addl $16, %esi
148
			addl $16, %esi
157
			addl $8	, %edi
149
			addl $8	, %edi
158
			
150
			
159
			loop mods_loop
151
			loop mods_loop
160
			
152
			
161
		mods_end:
153
		mods_end:
162
		
154
		
163
		bt $6, %eax								# mbi->flags[6] (mmap_length, mmap_addr valid)	
155
		bt $6, %eax								# mbi->flags[6] (mmap_length, mmap_addr valid)	
164
		jc mmap_valid
156
		jc mmap_valid
165
			
157
			
166
			xorl %edx, %edx
158
			xorl %edx, %edx
167
			jmp mmap_invalid
159
			jmp mmap_invalid
168
			
160
			
169
		mmap_valid:
161
		mmap_valid:
170
		movl 44(%ebx), %ecx						# mbi->mmap_length
162
		movl 44(%ebx), %ecx						# mbi->mmap_length
171
		movl 48(%ebx), %esi						# mbi->mmap_addr
163
		movl 48(%ebx), %esi						# mbi->mmap_addr
172
		movl $e820table, %edi
164
		movl $e820table, %edi
173
		xorl %edx, %edx
165
		xorl %edx, %edx
174
		
166
		
175
		mmap_loop:
167
		mmap_loop:
176
			cmpl $0, %ecx
168
			cmpl $0, %ecx
177
			jle mmap_end
169
			jle mmap_end
178
			
170
			
179
			movl 4(%esi), %eax					# mmap->base_addr_low
171
			movl 4(%esi), %eax					# mmap->base_addr_low
180
			movl %eax, (%edi)
172
			movl %eax, (%edi)
181
			
173
			
182
			movl 8(%esi), %eax					# mmap->base_addr_high
174
			movl 8(%esi), %eax					# mmap->base_addr_high
183
			movl %eax, 4(%edi)
175
			movl %eax, 4(%edi)
184
			
176
			
185
			movl 12(%esi), %eax					# mmap->length_low
177
			movl 12(%esi), %eax					# mmap->length_low
186
			movl %eax, 8(%edi)
178
			movl %eax, 8(%edi)
187
			
179
			
188
			movl 16(%esi), %eax					# mmap->length_high
180
			movl 16(%esi), %eax					# mmap->length_high
189
			movl %eax, 12(%edi)
181
			movl %eax, 12(%edi)
190
			
182
			
191
			movl 20(%esi), %eax					# mmap->type
183
			movl 20(%esi), %eax					# mmap->type
192
			movl %eax, 16(%edi)
184
			movl %eax, 16(%edi)
193
			
185
			
194
			movl (%esi), %eax					# mmap->size
186
			movl (%esi), %eax					# mmap->size
195
			addl $0x4, %eax
187
			addl $0x4, %eax
196
			addl %eax, %esi
188
			addl %eax, %esi
197
			subl %eax, %ecx
189
			subl %eax, %ecx
198
			addl $MEMMAP_E820_RECORD_SIZE, %edi
190
			addl $MEMMAP_E820_RECORD_SIZE, %edi
199
			incl %edx
191
			incl %edx
200
			jmp mmap_loop
192
			jmp mmap_loop
201
		
193
		
202
		mmap_end:
194
		mmap_end:
203
		
195
		
204
		mmap_invalid:
196
		mmap_invalid:
205
		movl %edx, e820counter
197
		movl %edx, e820counter
206
		
198
		
207
	invalid_boot:
199
	invalid_boot:
208
	
200
	
209
#ifdef CONFIG_SMP
201
#ifdef CONFIG_SMP
210
	
202
	
211
	# copy AP bootstrap routines below 1 MB
203
	# copy AP bootstrap routines below 1 MB
212
	
204
	
213
	movl $BOOT_OFFSET, %esi
205
	movl $BOOT_OFFSET, %esi
214
	movl $AP_BOOT_OFFSET, %edi
206
	movl $AP_BOOT_OFFSET, %edi
215
	movl $_hardcoded_unmapped_size, %ecx
207
	movl $_hardcoded_unmapped_size, %ecx
216
	cld
208
	cld
217
	rep movsb
209
	rep movsb
218
	
210
	
219
#endif
211
#endif
220
	
212
	
221
	call main_bsp								# never returns
213
	call main_bsp								# never returns
222
 
214
 
223
	cli
215
	cli
224
	hlt
216
	hlt
225
 
217
 
226
.global map_kernel
218
.global map_kernel
227
map_kernel:
219
map_kernel:
228
	#
220
	#
229
	# Here we setup mapping for both the unmapped and mapped sections of the kernel.
221
	# Here we setup mapping for both the unmapped and mapped sections of the kernel.
230
	# For simplicity, we map the entire 4G space.
222
	# For simplicity, we map the entire 4G space.
231
	#
223
	#
232
	movl %cr4, %ecx
224
	movl %cr4, %ecx
233
	orl $(1<<4), %ecx
225
	orl $(1<<4), %ecx
234
	movl %ecx, %cr4							# turn PSE on
226
	movl %ecx, %cr4							# turn PSE on
235
	
227
	
236
	movl $(page_directory+0), %esi
228
	movl $(page_directory+0), %esi
237
	movl $(page_directory+2048), %edi
229
	movl $(page_directory+2048), %edi
238
	xorl %ecx, %ecx
230
	xorl %ecx, %ecx
239
	xorl %ebx, %ebx
231
	xorl %ebx, %ebx
240
0:
232
0:
241
	movl $((1<<7)|(1<<0)), %eax
233
	movl $((1<<7)|(1<<0)), %eax
242
	orl %ebx, %eax
234
	orl %ebx, %eax
243
	movl %eax, (%esi,%ecx,4)					# mapping 0x00000000+%ecx*4M => 0x00000000+%ecx*4M
235
	movl %eax, (%esi,%ecx,4)					# mapping 0x00000000+%ecx*4M => 0x00000000+%ecx*4M
244
	movl %eax, (%edi,%ecx,4)					# mapping 0x80000000+%ecx*4M => 0x00000000+%ecx*4M
236
	movl %eax, (%edi,%ecx,4)					# mapping 0x80000000+%ecx*4M => 0x00000000+%ecx*4M
245
	addl $(4*1024*1024), %ebx
237
	addl $(4*1024*1024), %ebx
246
 
238
 
247
	incl %ecx
239
	incl %ecx
248
	cmpl $512, %ecx
240
	cmpl $512, %ecx
249
	jl 0b
241
	jl 0b
250
 
242
 
251
	movl %esi, %cr3
243
	movl %esi, %cr3
252
	
244
	
253
	# turn paging on
245
	# turn paging on
254
	movl %cr0, %ebx
246
	movl %cr0, %ebx
255
	orl $(1<<31), %ebx
247
	orl $(1<<31), %ebx
256
	movl %ebx, %cr0
248
	movl %ebx, %cr0
257
	ret
249
	ret
258
 
250
 
259
#ifdef CONFIG_FB
251
#ifdef CONFIG_FB
260
vesa_init:
252
vesa_init:
261
	jmp $selector(VESA_INIT_DES),$vesa_init_real-vesa_init;
253
	jmp $selector(VESA_INIT_DES),$vesa_init_real-vesa_init;
262
.code16
254
.code16
263
vesa_init_real:	
255
vesa_init_real:	
264
 
256
 
265
	mov %cr0,%eax;
257
	mov %cr0,%eax;
266
	and $~1,%eax;
258
	and $~1,%eax;
267
	mov %eax,%cr0;
259
	mov %eax,%cr0;
268
 
260
 
269
 
261
 
270
	jmp $VESA_INIT_SEGMENT,$vesa_init_real2-vesa_init;
262
	jmp $VESA_INIT_SEGMENT,$vesa_init_real2-vesa_init;
271
 
263
 
272
vesa_init_real2:	
264
vesa_init_real2:	
273
 
265
 
274
 
266
 
275
	mov %esp,%ebp;
267
	mov %esp,%ebp;
276
	mov %ss,%cx;
268
	mov %ss,%cx;
277
	mov $VESA_INIT_SEGMENT,%bx;
269
	mov $VESA_INIT_SEGMENT,%bx;
278
	mov %bx,%ss;
270
	mov %bx,%ss;
279
	mov $0x0000fffc,%esp;
271
	mov $0x0000fffc,%esp;
280
	push %ds;
272
	push %ds;
281
	push %es;
273
	push %es;
282
	push %fs;
274
	push %fs;
283
	push %gs;
275
	push %gs;
284
	push %ebp;
276
	push %ebp;
285
	push %cx;
277
	push %cx;
286
 
278
 
287
	mov %bx,%ds;
279
	mov %bx,%ds;
288
	mov %bx,%es;
280
	mov %bx,%es;
289
	mov %bx,%fs;
281
	mov %bx,%fs;
290
	mov %bx,%gs;
282
	mov %bx,%gs;
291
 
283
 
292
	
284
	
293
	mov $vesa_idt-vesa_init,%ebx;
285
	mov $vesa_idt-vesa_init,%ebx;
294
	lidtl (%ebx);
286
	lidtl (%ebx);
295
 
287
 
296
#define VESA_INFO_SIZE 1024
288
#define VESA_INFO_SIZE 1024
297
 
289
 
298
#define VESA_MODE_LIST_PTR_OFFSET 14 
290
#define VESA_MODE_LIST_PTR_OFFSET 14 
299
#define VESA_MODE_WIDTH_OFFSET 18
291
#define VESA_MODE_WIDTH_OFFSET 18
300
#define VESA_MODE_HEIGHT_OFFSET 20
292
#define VESA_MODE_HEIGHT_OFFSET 20
301
#define VESA_MODE_BPP_OFFSET 25
293
#define VESA_MODE_BPP_OFFSET 25
302
#define VESA_MODE_SCANLINE_OFFSET 16
294
#define VESA_MODE_SCANLINE_OFFSET 16
303
#define VESA_MODE_PHADDR_OFFSET 40
295
#define VESA_MODE_PHADDR_OFFSET 40
304
 
296
 
305
#define VESA_END_OF_MODES 0xffff 
297
#define VESA_END_OF_MODES 0xffff 
306
 
298
 
307
#define VESA_OK 0x4f 
299
#define VESA_OK 0x4f 
308
 
300
 
309
#define VESA_GET_INFO 0x4f00 
301
#define VESA_GET_INFO 0x4f00 
310
#define VESA_GET_MODE_INFO 0x4f01
302
#define VESA_GET_MODE_INFO 0x4f01
311
#define VESA_SET_MODE 0x4f02
303
#define VESA_SET_MODE 0x4f02
312
 
304
 
313
#define CONFIG_VESA_BPP_a 255
305
#define CONFIG_VESA_BPP_a 255
314
 
306
 
315
#if CONFIG_VESA_BPP==24
307
#if CONFIG_VESA_BPP==24
316
#undef CONFIG_VESA_BPP_a
308
#undef CONFIG_VESA_BPP_a
317
#define CONFIG_VESA_BPP_a 32
309
#define CONFIG_VESA_BPP_a 32
318
#endif
310
#endif
319
 
311
 
320
 
312
 
321
	mov $VESA_GET_INFO,%ax;
313
	mov $VESA_GET_INFO,%ax;
322
	mov $e_vesa_init-vesa_init,%di
314
	mov $e_vesa_init-vesa_init,%di
323
	push %di;
315
	push %di;
324
	int $0x10;	
316
	int $0x10;	
325
	pop %di;
317
	pop %di;
326
	cmp $VESA_OK,%al;
318
	cmp $VESA_OK,%al;
327
	jnz 0f;
319
	jnz 0f;
328
	mov 2+VESA_MODE_LIST_PTR_OFFSET(%di),%si;
320
	mov 2+VESA_MODE_LIST_PTR_OFFSET(%di),%si;
329
	mov %si,%gs;
321
	mov %si,%gs;
330
	mov VESA_MODE_LIST_PTR_OFFSET(%di),%si;
322
	mov VESA_MODE_LIST_PTR_OFFSET(%di),%si;
331
 
323
 
332
	add $VESA_INFO_SIZE,%di;
324
	add $VESA_INFO_SIZE,%di;
333
 
325
 
334
1:# Try next mode
326
1:# Try next mode
335
	mov %gs:(%si),%cx;
327
	mov %gs:(%si),%cx;
336
	cmp $VESA_END_OF_MODES,%cx;
328
	cmp $VESA_END_OF_MODES,%cx;
337
	jz 0f;
329
	jz 0f;
338
	inc %si;
330
	inc %si;
339
	inc %si;
331
	inc %si;
340
	push %cx;
332
	push %cx;
341
	push %di;
333
	push %di;
342
	push %si;
334
	push %si;
343
	mov $VESA_GET_MODE_INFO,%ax;
335
	mov $VESA_GET_MODE_INFO,%ax;
344
	int $0x10;
336
	int $0x10;
345
	pop %si;
337
	pop %si;
346
	pop %di;
338
	pop %di;
347
	pop %cx;
339
	pop %cx;
348
	cmp $VESA_OK,%al;
340
	cmp $VESA_OK,%al;
349
	jnz 0f;
341
	jnz 0f;
350
 
342
 
351
 
343
 
352
	mov $CONFIG_VESA_WIDTH,%ax;
344
	mov $CONFIG_VESA_WIDTH,%ax;
353
	cmp VESA_MODE_WIDTH_OFFSET(%di),%ax;
345
	cmp VESA_MODE_WIDTH_OFFSET(%di),%ax;
354
	jnz 1b;
346
	jnz 1b;
355
	mov $CONFIG_VESA_HEIGHT,%ax;
347
	mov $CONFIG_VESA_HEIGHT,%ax;
356
	cmp VESA_MODE_HEIGHT_OFFSET(%di),%ax;
348
	cmp VESA_MODE_HEIGHT_OFFSET(%di),%ax;
357
	jnz 1b;
349
	jnz 1b;
358
	mov $CONFIG_VESA_BPP,%al;
350
	mov $CONFIG_VESA_BPP,%al;
359
	cmp VESA_MODE_BPP_OFFSET(%di),%al;
351
	cmp VESA_MODE_BPP_OFFSET(%di),%al;
360
	jz 2f;
352
	jz 2f;
361
	mov $CONFIG_VESA_BPP_a,%al;
353
	mov $CONFIG_VESA_BPP_a,%al;
362
	cmp VESA_MODE_BPP_OFFSET(%di),%al;
354
	cmp VESA_MODE_BPP_OFFSET(%di),%al;
363
	jnz 1b;
355
	jnz 1b;
364
 
356
 
365
2:
357
2:
366
 
358
 
367
	mov %cx,%bx;
359
	mov %cx,%bx;
368
	or $0xC000,%bx;
360
	or $0xC000,%bx;
369
	push %di;
361
	push %di;
370
	mov $VESA_SET_MODE,%ax;
362
	mov $VESA_SET_MODE,%ax;
371
	int $0x10;
363
	int $0x10;
372
	pop %di;
364
	pop %di;
373
	cmp $VESA_OK,%al;
365
	cmp $VESA_OK,%al;
374
	jnz 0f;
366
	jnz 0f;
375
	
367
	
376
	mov VESA_MODE_PHADDR_OFFSET(%di),%esi;
368
	mov VESA_MODE_PHADDR_OFFSET(%di),%esi;
377
	mov VESA_MODE_WIDTH_OFFSET(%di),%ax;
369
	mov VESA_MODE_WIDTH_OFFSET(%di),%ax;
378
	shl $16,%eax;
370
	shl $16,%eax;
379
	mov VESA_MODE_HEIGHT_OFFSET(%di),%ax;
371
	mov VESA_MODE_HEIGHT_OFFSET(%di),%ax;
380
	mov VESA_MODE_BPP_OFFSET(%di),%bl;
372
	mov VESA_MODE_BPP_OFFSET(%di),%bl;
381
	xor %bh,%bh;
373
	xor %bh,%bh;
382
	shl $16,%ebx;
374
	shl $16,%ebx;
383
	mov VESA_MODE_SCANLINE_OFFSET(%di),%bx;
375
	mov VESA_MODE_SCANLINE_OFFSET(%di),%bx;
384
	mov %eax,%edi; 
376
	mov %eax,%edi; 
385
	
377
	
386
	
378
	
387
 
379
 
388
8:	
380
8:	
389
 
381
 
390
	mov %cr0,%eax;
382
	mov %cr0,%eax;
391
	or $1,%eax;
383
	or $1,%eax;
392
	mov %eax,%cr0;
384
	mov %eax,%cr0;
393
 
385
 
394
	jmp 9f;
386
	jmp 9f;
395
9:
387
9:
396
 
388
 
397
	pop %cx;
389
	pop %cx;
398
	pop %ebp;
390
	pop %ebp;
399
	pop %gs;
391
	pop %gs;
400
	pop %fs;
392
	pop %fs;
401
	pop %es;
393
	pop %es;
402
	pop %ds;
394
	pop %ds;
403
	mov %cx,%ss;
395
	mov %cx,%ss;
404
	mov %ebp,%esp;
396
	mov %ebp,%esp;
405
 
397
 
406
	ljmpl $KTEXT,$(vesa_init_protect-vesa_init+VESA_INIT_SEGMENT<<4);
398
	ljmpl $KTEXT,$(vesa_init_protect-vesa_init+VESA_INIT_SEGMENT<<4);
407
 
399
 
408
vesa_init_protect:	
400
vesa_init_protect:	
409
.code32
401
.code32
410
	ret;
402
	ret;
411
 
403
 
412
0:	#Error no Prefered mode found
404
0:	#Error no Prefered mode found
413
 
405
 
414
	mov $0x111,%cx;
406
	mov $0x111,%cx;
415
	push %di;
407
	push %di;
416
	push %cx;
408
	push %cx;
417
	mov $VESA_GET_MODE_INFO,%ax;
409
	mov $VESA_GET_MODE_INFO,%ax;
418
	int $0x10;
410
	int $0x10;
419
	pop %cx;
411
	pop %cx;
420
	pop %di;
412
	pop %di;
421
	cmp $VESA_OK,%al;
413
	cmp $VESA_OK,%al;
422
	jnz 1f;
414
	jnz 1f;
423
	jmp 2b;
415
	jmp 2b;
424
 
416
 
425
1:mov $0x0003,%ax;
417
1:mov $0x0003,%ax;
426
	int $0x10;
418
	int $0x10;
427
	mov $0xffffffff,%edi; /* EGA text mode used, because of problems with VESA */
419
	mov $0xffffffff,%edi; /* EGA text mode used, because of problems with VESA */
428
	jmp 8;
420
	jmp 8;
429
 
421
 
430
 
422
 
431
vesa_idt:
423
vesa_idt:
432
.word 0x03ff
424
.word 0x03ff
433
.long 0
425
.long 0
434
.align 4
426
.align 4
435
e_vesa_init:
427
e_vesa_init:
436
#endif	
428
#endif	
437
 
429
 
438
 
-
 
439
 
-
 
440
.section K_DATA_START, "aw", @progbits
430
.section K_DATA_START, "aw", @progbits
441
 
431
 
442
 
-
 
443
 
-
 
444
.align 4096
432
.align 4096
445
page_directory:
433
page_directory:
446
	.space 4096, 0
434
	.space 4096, 0
447
 
435