Subversion Repositories HelenOS

Rev

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

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