Rev 2131 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2131 | Rev 2307 | ||
---|---|---|---|
Line 61... | Line 61... | ||
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 | movl %eax, grub_eax # save parameters from GRUB |
- | 67 | movl %ebx, grub_ebx |
|
- | 68 | ||
67 | pushl %eax |
69 | xorl %eax, %eax |
- | 70 | cpuid |
|
- | 71 | cmp $0x0, %eax # any function > 0? |
|
- | 72 | jbe pse_unsupported |
|
- | 73 | movl $0x1, %eax # Basic function code 1 |
|
- | 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: |
|
68 | 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 |
Line 87... | Line 102... | ||
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 | movl grub_eax, %eax |
93 | popl %ebx |
108 | movl grub_ebx, %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 |
Line 207... | Line 222... | ||
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 | ||
Line 220... | Line 235... | ||
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 |
Line 276... | Line 351... | ||
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 | ||
- | 356 | #define VESA_MODE_ATTRIBUTES_OFFSET 0 |
|
281 | #define VESA_MODE_LIST_PTR_OFFSET 14 |
357 | #define VESA_MODE_LIST_PTR_OFFSET 14 |
- | 358 | #define VESA_MODE_SCANLINE_OFFSET 16 |
|
282 | #define VESA_MODE_WIDTH_OFFSET 18 |
359 | #define VESA_MODE_WIDTH_OFFSET 18 |
283 | #define VESA_MODE_HEIGHT_OFFSET 20 |
360 | #define VESA_MODE_HEIGHT_OFFSET 20 |
284 | #define VESA_MODE_BPP_OFFSET 25 |
361 | #define VESA_MODE_BPP_OFFSET 25 |
285 | #define VESA_MODE_SCANLINE_OFFSET 16 |
- | |
286 | #define VESA_MODE_PHADDR_OFFSET 40 |
362 | #define VESA_MODE_PHADDR_OFFSET 40 |
287 | 363 | ||
288 | #define VESA_END_OF_MODES 0xffff |
364 | #define VESA_END_OF_MODES 0xffff |
289 | 365 | ||
290 | #define VESA_OK 0x4f |
366 | #define VESA_OK 0x4f |
291 | 367 | ||
292 | #define VESA_GET_INFO 0x4f00 |
368 | #define VESA_GET_INFO 0x4f00 |
293 | #define VESA_GET_MODE_INFO 0x4f01 |
369 | #define VESA_GET_MODE_INFO 0x4f01 |
294 | #define VESA_SET_MODE 0x4f02 |
370 | #define VESA_SET_MODE 0x4f02 |
295 | - | ||
296 | #define CONFIG_VESA_BPP_a 255 |
371 | #define VESA_SET_PALETTE 0x4f09 |
297 | 372 | ||
298 | #if CONFIG_VESA_BPP == 24 |
373 | #if CONFIG_VESA_BPP == 24 |
299 | #undef CONFIG_VESA_BPP_a |
- | |
300 | #define CONFIG_VESA_BPP_a 32 |
374 | #define CONFIG_VESA_BPP_VARIANT 32 |
301 | #endif |
375 | #endif |
302 | 376 | ||
303 | mov $VESA_GET_INFO, %ax |
377 | mov $VESA_GET_INFO, %ax |
304 | mov $e_vesa_init - vesa_init, %di |
378 | mov $e_vesa_init - vesa_init, %di |
305 | push %di |
379 | push %di |
Line 336... | Line 410... | ||
336 | 410 | ||
337 | mov $CONFIG_VESA_WIDTH, %ax |
411 | mov $CONFIG_VESA_WIDTH, %ax |
338 | cmp VESA_MODE_WIDTH_OFFSET(%di), %ax |
412 | cmp VESA_MODE_WIDTH_OFFSET(%di), %ax |
339 | jnz 1b |
413 | jnz 1b |
340 | 414 | ||
341 | mov $CONFIG_VESA_HEIGHT,%ax |
415 | mov $CONFIG_VESA_HEIGHT, %ax |
342 | cmp VESA_MODE_HEIGHT_OFFSET(%di), %ax |
416 | cmp VESA_MODE_HEIGHT_OFFSET(%di), %ax |
343 | jnz 1b |
417 | jnz 1b |
344 | 418 | ||
345 | mov $CONFIG_VESA_BPP, %al |
419 | mov $CONFIG_VESA_BPP, %al |
346 | cmp VESA_MODE_BPP_OFFSET(%di), %al |
420 | cmp VESA_MODE_BPP_OFFSET(%di), %al |
- | 421 | ||
- | 422 | #ifdef CONFIG_VESA_BPP_VARIANT |
|
347 | jz 2f |
423 | jz 2f |
348 | 424 | ||
349 | mov $CONFIG_VESA_BPP_a, %al |
425 | mov $CONFIG_VESA_BPP_VARIANT, %al |
350 | cmp VESA_MODE_BPP_OFFSET(%di), %al |
426 | cmp VESA_MODE_BPP_OFFSET(%di), %al |
- | 427 | #endif |
|
351 | jnz 1b |
428 | jnz 1b |
352 | 429 | ||
353 | 2: |
430 | 2: |
354 | 431 | ||
355 | mov %cx, %bx |
432 | mov %cx, %bx |
356 | or $0xc000, %bx |
433 | or $0xc000, %bx |
357 | push %di |
434 | push %di |
Line 359... | Line 436... | ||
359 | int $0x10 |
436 | int $0x10 |
360 | 437 | ||
361 | pop %di |
438 | pop %di |
362 | cmp $VESA_OK, %al |
439 | cmp $VESA_OK, %al |
363 | jnz 0f |
440 | jnz 0f |
- | 441 | ||
- | 442 | #if CONFIG_VESA_BPP == 8 |
|
- | 443 | ||
- | 444 | # Set 3:2:3 VGA palette |
|
- | 445 | ||
- | 446 | mov VESA_MODE_ATTRIBUTES_OFFSET(%di), %ax |
|
- | 447 | push %di |
|
- | 448 | mov $vga323 - vesa_init, %di |
|
- | 449 | mov $0x100, %ecx |
|
- | 450 | ||
- | 451 | bt $5, %ax # Test if VGA compatible registers are present |
|
- | 452 | jnc vga_compat |
|
- | 453 | ||
- | 454 | # Try VESA routine to set palette |
|
- | 455 | ||
- | 456 | mov $VESA_SET_PALETTE, %ax |
|
- | 457 | xor %bl, %bl |
|
- | 458 | xor %dx, %dx |
|
- | 459 | int $0x10 |
|
- | 460 | ||
- | 461 | jmp vga_not_compat |
|
- | 462 | ||
- | 463 | vga_compat: |
|
- | 464 | ||
- | 465 | # Try VGA registers to set palette |
|
- | 466 | ||
- | 467 | movw $0x3c6, %dx # Set palette mask |
|
- | 468 | movb $0xff, %al |
|
- | 469 | outb %al, %dx |
|
- | 470 | ||
- | 471 | movw $0x3c8, %dx # First index to set |
|
- | 472 | xor %al, %al |
|
- | 473 | outb %al, %dx |
|
- | 474 | ||
- | 475 | movw $0x3c9, %dx # Data port |
|
- | 476 | vga_loop: |
|
- | 477 | movb %es:2(%di), %al |
|
- | 478 | outb %al, %dx |
|
- | 479 | ||
- | 480 | movb %es:1(%di), %al |
|
- | 481 | outb %al, %dx |
|
- | 482 | ||
- | 483 | movb %es:(%di), %al |
|
- | 484 | outb %al, %dx |
|
- | 485 | ||
- | 486 | addw $4, %di |
|
- | 487 | loop vga_loop |
|
- | 488 | ||
- | 489 | vga_not_compat: |
|
- | 490 | ||
- | 491 | pop %di |
|
- | 492 | ||
- | 493 | #endif |
|
364 | 494 | ||
365 | mov VESA_MODE_PHADDR_OFFSET(%di), %esi |
495 | mov VESA_MODE_PHADDR_OFFSET(%di), %esi |
366 | mov VESA_MODE_WIDTH_OFFSET(%di), %ax |
496 | mov VESA_MODE_WIDTH_OFFSET(%di), %ax |
367 | shl $16, %eax |
497 | shl $16, %eax |
368 | mov VESA_MODE_HEIGHT_OFFSET(%di), %ax |
498 | mov VESA_MODE_HEIGHT_OFFSET(%di), %ax |
Line 400... | Line 530... | ||
400 | mov $0x0003, %ax |
530 | mov $0x0003, %ax |
401 | int $0x10 |
531 | int $0x10 |
402 | mov $0xffffffff, %edi # EGA text mode used, because of problems with VESA |
532 | mov $0xffffffff, %edi # EGA text mode used, because of problems with VESA |
403 | xor %ax, %ax |
533 | xor %ax, %ax |
404 | jz 8b # Force relative jump |
534 | jz 8b # Force relative jump |
405 | 535 | ||
- | 536 | vga323: |
|
- | 537 | #include "vga323.pal" |
|
406 | 538 | ||
407 | .code32 |
539 | .code32 |
408 | vesa_init_protect: |
540 | vesa_init_protect: |
409 | popl %esp |
- | |
410 | - | ||
411 | movw $selector(KDATA_DES), %cx |
541 | movw $selector(KDATA_DES), %cx |
412 | movw %cx, %es |
542 | movw %cx, %es |
413 | movw %cx, %fs |
543 | movw %cx, %fs |
414 | movw %cx, %gs |
544 | movw %cx, %gs |
415 | movw %cx, %ds # kernel data + stack |
545 | movw %cx, %ds # kernel data + stack |
416 | movw %cx, %ss |
546 | movw %cx, %ss |
417 | 547 | ||
- | 548 | movl $START_STACK, %esp # initialize stack pointer |
|
- | 549 | ||
418 | jmpl $selector(KTEXT_DES), $vesa_meeting_point |
550 | jmpl $selector(KTEXT_DES), $vesa_meeting_point |
419 | 551 | ||
420 | .align 4 |
552 | .align 4 |
421 | e_vesa_init: |
553 | e_vesa_init: |
422 | #endif |
554 | #endif |
Line 424... | Line 556... | ||
424 | .section K_DATA_START, "aw", @progbits |
556 | .section K_DATA_START, "aw", @progbits |
425 | 557 | ||
426 | .align 4096 |
558 | .align 4096 |
427 | page_directory: |
559 | page_directory: |
428 | .space 4096, 0 |
560 | .space 4096, 0 |
- | 561 | ||
- | 562 | grub_eax: |
|
- | 563 | .long 0 |
|
- | 564 | ||
- | 565 | grub_ebx: |
|
- | 566 | .long 0 |
|
- | 567 | ||
- | 568 | pse_msg: |
|
- | 569 | .asciz "Page Size Extension not supported. System halted." |