Subversion Repositories HelenOS-historic

Rev

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

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