Subversion Repositories HelenOS-historic

Rev

Rev 1291 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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