Rev 2131 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2131 | Rev 2307 | ||
---|---|---|---|
Line 70... | Line 70... | ||
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 | # Protected 32-bit. We want to reuse the code-seg descriptor, |
|
- | 76 | # the Default operand size must not be 1 when entering long mode |
|
- | 77 | ||
- | 78 | movl $0x80000000, %eax |
|
- | 79 | cpuid |
|
- | 80 | cmp $0x80000000, %eax # any function > 80000000h? |
|
- | 81 | jbe long_mode_unsupported |
|
- | 82 | movl $(AMD_CPUID_EXTENDED), %eax # Extended function code 80000001 |
|
- | 83 | cpuid |
|
- | 84 | bt $29, %edx # Test if long mode is supported. |
|
- | 85 | jc long_mode_supported |
|
- | 86 | ||
- | 87 | long_mode_unsupported: |
|
- | 88 | movl $long_mode_msg, %esi |
|
- | 89 | jmp error_halt |
|
- | 90 | ||
- | 91 | long_mode_supported: |
|
- | 92 | ||
75 | #ifdef CONFIG_FB |
93 | #ifdef CONFIG_FB |
76 | mov $vesa_init, %esi; |
94 | mov $vesa_init, %esi |
77 | mov $VESA_INIT_SEGMENT << 4, %edi |
95 | mov $VESA_INIT_SEGMENT << 4, %edi |
78 | mov $e_vesa_init - vesa_init, %ecx |
96 | mov $e_vesa_init - vesa_init, %ecx |
79 | cld |
97 | cld |
80 | rep movsb |
98 | rep movsb |
81 | 99 | ||
Line 90... | Line 108... | ||
90 | mov %di, KA2PA(vesa_width) |
108 | mov %di, KA2PA(vesa_width) |
91 | mov %bx, KA2PA(vesa_scanline) |
109 | mov %bx, KA2PA(vesa_scanline) |
92 | shr $16, %ebx |
110 | shr $16, %ebx |
93 | mov %bx, KA2PA(vesa_bpp) |
111 | mov %bx, KA2PA(vesa_bpp) |
94 | #endif |
112 | #endif |
95 | - | ||
96 | # Protected 32-bit. We want to reuse the code-seg descriptor, |
- | |
97 | # the Default operand size must not be 1 when entering long mode |
- | |
98 | - | ||
99 | movl $0x80000000, %eax |
- | |
100 | cpuid |
- | |
101 | cmp $0x80000000, %eax # any function > 80000000h? |
- | |
102 | jbe long_mode_unsupported |
- | |
103 | movl $(AMD_CPUID_EXTENDED), %eax # Extended function code 80000001 |
- | |
104 | cpuid |
- | |
105 | bt $29, %edx # Test if long mode is supported. |
- | |
106 | jc long_mode_supported |
- | |
107 | - | ||
108 | long_mode_unsupported: |
- | |
109 | cli |
- | |
110 | hlt |
- | |
111 | - | ||
112 | long_mode_supported: |
- | |
113 | 113 | ||
114 | # Enable 64-bit page transaltion entries - CR4.PAE = 1. |
114 | # Enable 64-bit page transaltion entries - CR4.PAE = 1. |
115 | # Paging is not enabled until after long mode is enabled |
115 | # Paging is not enabled until after long mode is enabled |
116 | 116 | ||
117 | movl %cr4, %eax |
117 | movl %cr4, %eax |
Line 301... | Line 301... | ||
301 | movl $0x0000fffc, %esp |
301 | movl $0x0000fffc, %esp |
302 | movl $0x0000fffc, %ebp |
302 | movl $0x0000fffc, %ebp |
303 | 303 | ||
304 | #define VESA_INFO_SIZE 1024 |
304 | #define VESA_INFO_SIZE 1024 |
305 | 305 | ||
- | 306 | #define VESA_MODE_ATTRIBUTES_OFFSET 0 |
|
306 | #define VESA_MODE_LIST_PTR_OFFSET 14 |
307 | #define VESA_MODE_LIST_PTR_OFFSET 14 |
- | 308 | #define VESA_MODE_SCANLINE_OFFSET 16 |
|
307 | #define VESA_MODE_WIDTH_OFFSET 18 |
309 | #define VESA_MODE_WIDTH_OFFSET 18 |
308 | #define VESA_MODE_HEIGHT_OFFSET 20 |
310 | #define VESA_MODE_HEIGHT_OFFSET 20 |
309 | #define VESA_MODE_BPP_OFFSET 25 |
311 | #define VESA_MODE_BPP_OFFSET 25 |
310 | #define VESA_MODE_SCANLINE_OFFSET 16 |
- | |
311 | #define VESA_MODE_PHADDR_OFFSET 40 |
312 | #define VESA_MODE_PHADDR_OFFSET 40 |
312 | 313 | ||
313 | #define VESA_END_OF_MODES 0xffff |
314 | #define VESA_END_OF_MODES 0xffff |
314 | 315 | ||
315 | #define VESA_OK 0x4f |
316 | #define VESA_OK 0x4f |
316 | 317 | ||
317 | #define VESA_GET_INFO 0x4f00 |
318 | #define VESA_GET_INFO 0x4f00 |
318 | #define VESA_GET_MODE_INFO 0x4f01 |
319 | #define VESA_GET_MODE_INFO 0x4f01 |
319 | #define VESA_SET_MODE 0x4f02 |
320 | #define VESA_SET_MODE 0x4f02 |
- | 321 | #define VESA_SET_PALETTE 0x4f09 |
|
320 | 322 | ||
321 | #define CONFIG_VESA_BPP_a 255 |
323 | #define CONFIG_VESA_BPP_a 255 |
322 | 324 | ||
323 | #if CONFIG_VESA_BPP == 24 |
325 | #if CONFIG_VESA_BPP == 24 |
324 | #undef CONFIG_VESA_BPP_a |
- | |
325 | #define CONFIG_VESA_BPP_a 32 |
326 | #define CONFIG_VESA_BPP_VARIANT 32 |
326 | #endif |
327 | #endif |
327 | 328 | ||
328 | mov $VESA_GET_INFO, %ax |
329 | mov $VESA_GET_INFO, %ax |
329 | mov $e_vesa_init - vesa_init, %di |
330 | mov $e_vesa_init - vesa_init, %di |
330 | push %di |
331 | push %di |
331 | int $0x10 |
332 | int $0x10 |
332 | 333 | ||
Line 337... | Line 338... | ||
337 | mov 2 + VESA_MODE_LIST_PTR_OFFSET(%di), %si |
338 | mov 2 + VESA_MODE_LIST_PTR_OFFSET(%di), %si |
338 | mov %si, %gs |
339 | mov %si, %gs |
339 | mov VESA_MODE_LIST_PTR_OFFSET(%di), %si |
340 | mov VESA_MODE_LIST_PTR_OFFSET(%di), %si |
340 | 341 | ||
341 | add $VESA_INFO_SIZE, %di |
342 | add $VESA_INFO_SIZE, %di |
342 | 343 | ||
343 | 1:# Try next mode |
344 | 1:# Try next mode |
344 | mov %gs:(%si), %cx |
345 | mov %gs:(%si), %cx |
345 | cmp $VESA_END_OF_MODES, %cx |
346 | cmp $VESA_END_OF_MODES, %cx |
346 | jz 0f |
347 | jz 0f |
347 | 348 | ||
Line 367... | Line 368... | ||
367 | cmp VESA_MODE_HEIGHT_OFFSET(%di), %ax |
368 | cmp VESA_MODE_HEIGHT_OFFSET(%di), %ax |
368 | jnz 1b |
369 | jnz 1b |
369 | 370 | ||
370 | mov $CONFIG_VESA_BPP, %al |
371 | mov $CONFIG_VESA_BPP, %al |
371 | cmp VESA_MODE_BPP_OFFSET(%di), %al |
372 | cmp VESA_MODE_BPP_OFFSET(%di), %al |
- | 373 | ||
- | 374 | #ifdef CONFIG_VESA_BPP_VARIANT |
|
372 | jz 2f |
375 | jz 2f |
373 | 376 | ||
374 | mov $CONFIG_VESA_BPP_a, %al |
377 | mov $CONFIG_VESA_BPP_VARIANT, %al |
375 | cmp VESA_MODE_BPP_OFFSET(%di), %al |
378 | cmp VESA_MODE_BPP_OFFSET(%di), %al |
- | 379 | #endif |
|
376 | jnz 1b |
380 | jnz 1b |
377 | 381 | ||
378 | 2: |
382 | 2: |
379 | 383 | ||
380 | mov %cx, %bx |
384 | mov %cx, %bx |
Line 384... | Line 388... | ||
384 | int $0x10 |
388 | int $0x10 |
385 | 389 | ||
386 | pop %di |
390 | pop %di |
387 | cmp $VESA_OK, %al |
391 | cmp $VESA_OK, %al |
388 | jnz 0f |
392 | jnz 0f |
- | 393 | ||
- | 394 | #if CONFIG_VESA_BPP == 8 |
|
- | 395 | ||
- | 396 | # Set 3:2:3 VGA palette |
|
- | 397 | ||
- | 398 | mov VESA_MODE_ATTRIBUTES_OFFSET(%di), %ax |
|
- | 399 | push %di |
|
- | 400 | mov $vga323 - vesa_init, %di |
|
- | 401 | mov $0x100, %ecx |
|
- | 402 | ||
- | 403 | bt $5, %ax # Test if VGA compatible registers are present |
|
- | 404 | jnc vga_compat |
|
- | 405 | ||
- | 406 | # Try VESA routine to set palette |
|
- | 407 | ||
- | 408 | mov $VESA_SET_PALETTE, %ax |
|
- | 409 | xor %bl, %bl |
|
- | 410 | xor %dx, %dx |
|
- | 411 | int $0x10 |
|
- | 412 | ||
- | 413 | jmp vga_not_compat |
|
- | 414 | ||
- | 415 | vga_compat: |
|
- | 416 | ||
- | 417 | # Try VGA registers to set palette |
|
- | 418 | ||
- | 419 | movw $0x3c6, %dx # Set palette mask |
|
- | 420 | movb $0xff, %al |
|
- | 421 | outb %al, %dx |
|
- | 422 | ||
- | 423 | movw $0x3c8, %dx # First index to set |
|
- | 424 | xor %al, %al |
|
- | 425 | outb %al, %dx |
|
- | 426 | ||
- | 427 | movw $0x3c9, %dx # Data port |
|
- | 428 | vga_loop: |
|
- | 429 | movb %es:2(%di), %al |
|
- | 430 | outb %al, %dx |
|
- | 431 | ||
- | 432 | movb %es:1(%di), %al |
|
- | 433 | outb %al, %dx |
|
- | 434 | ||
- | 435 | movb %es:(%di), %al |
|
- | 436 | outb %al, %dx |
|
- | 437 | ||
- | 438 | addw $4, %di |
|
- | 439 | loop vga_loop |
|
- | 440 | ||
- | 441 | vga_not_compat: |
|
- | 442 | ||
- | 443 | pop %di |
|
- | 444 | ||
- | 445 | #endif |
|
389 | 446 | ||
390 | mov VESA_MODE_PHADDR_OFFSET(%di), %esi |
447 | mov VESA_MODE_PHADDR_OFFSET(%di), %esi |
391 | mov VESA_MODE_WIDTH_OFFSET(%di), %ax |
448 | mov VESA_MODE_WIDTH_OFFSET(%di), %ax |
392 | shl $16, %eax |
449 | shl $16, %eax |
393 | mov VESA_MODE_HEIGHT_OFFSET(%di), %ax |
450 | mov VESA_MODE_HEIGHT_OFFSET(%di), %ax |
Line 425... | Line 482... | ||
425 | mov $0x0003, %ax |
482 | mov $0x0003, %ax |
426 | int $0x10 |
483 | int $0x10 |
427 | mov $0xffffffff, %edi # EGA text mode used, because of problems with VESA |
484 | mov $0xffffffff, %edi # EGA text mode used, because of problems with VESA |
428 | xor %ax, %ax |
485 | xor %ax, %ax |
429 | jz 8b # Force relative jump |
486 | jz 8b # Force relative jump |
430 | 487 | ||
- | 488 | vga323: |
|
- | 489 | #include "vga323.pal" |
|
431 | 490 | ||
432 | .code32 |
491 | .code32 |
433 | vesa_init_protect: |
492 | vesa_init_protect: |
434 | movw $gdtselector(KDATA_DES), %cx |
493 | movw $gdtselector(KDATA_DES), %cx |
435 | movw %cx, %es |
494 | movw %cx, %es |
Line 439... | Line 498... | ||
439 | # when _visible_ part of GS does not point to user-mode segment |
498 | # when _visible_ part of GS does not point to user-mode segment |
440 | movw $gdtselector(UDATA_DES), %cx |
499 | movw $gdtselector(UDATA_DES), %cx |
441 | movw %cx, %fs |
500 | movw %cx, %fs |
442 | movw %cx, %gs |
501 | movw %cx, %gs |
443 | 502 | ||
- | 503 | movl $START_STACK, %esp # initialize stack pointer |
|
- | 504 | ||
444 | jmpl $gdtselector(KTEXT32_DES), $vesa_meeting_point |
505 | jmpl $gdtselector(KTEXT32_DES), $vesa_meeting_point |
445 | 506 | ||
446 | .align 4 |
507 | .align 4 |
447 | e_vesa_init: |
508 | e_vesa_init: |
448 | #endif |
509 | #endif |
- | 510 | ||
- | 511 | # Print string from %esi to EGA display (in red) and halt |
|
- | 512 | error_halt: |
|
- | 513 | movl $0xb8000, %edi # base of EGA text mode memory |
|
- | 514 | xorl %eax, %eax |
|
- | 515 | ||
- | 516 | movw $0x3d4, %dx # read bits 8 - 15 of the cursor address |
|
- | 517 | movb $0xe, %al |
|
- | 518 | outb %al, %dx |
|
- | 519 | ||
- | 520 | movw $0x3d5, %dx |
|
- | 521 | inb %dx, %al |
|
- | 522 | shl $8, %ax |
|
- | 523 | ||
- | 524 | movw $0x3d4, %dx # read bits 0 - 7 of the cursor address |
|
- | 525 | movb $0xf, %al |
|
- | 526 | outb %al, %dx |
|
- | 527 | ||
- | 528 | movw $0x3d5, %dx |
|
- | 529 | inb %dx, %al |
|
- | 530 | ||
- | 531 | cmp $1920, %ax |
|
- | 532 | jbe cursor_ok |
|
- | 533 | movw $1920, %ax # sanity check for the cursor on the last line |
|
- | 534 | cursor_ok: |
|
- | 535 | ||
- | 536 | movw %ax, %bx |
|
- | 537 | shl $1, %eax |
|
- | 538 | addl %eax, %edi |
|
- | 539 | ||
- | 540 | movw $0x0c00, %ax # black background, light red foreground |
|
- | 541 | cld |
|
- | 542 | ||
- | 543 | ploop: |
|
- | 544 | lodsb |
|
- | 545 | cmp $0, %al |
|
- | 546 | je ploop_end |
|
- | 547 | stosw |
|
- | 548 | inc %bx |
|
- | 549 | jmp ploop |
|
- | 550 | ploop_end: |
|
- | 551 | ||
- | 552 | movw $0x3d4, %dx # write bits 8 - 15 of the cursor address |
|
- | 553 | movb $0xe, %al |
|
- | 554 | outb %al, %dx |
|
- | 555 | ||
- | 556 | movw $0x3d5, %dx |
|
- | 557 | movb %bh, %al |
|
- | 558 | outb %al, %dx |
|
- | 559 | ||
- | 560 | movw $0x3d4, %dx # write bits 0 - 7 of the cursor address |
|
- | 561 | movb $0xf, %al |
|
- | 562 | outb %al, %dx |
|
- | 563 | ||
- | 564 | movw $0x3d5, %dx |
|
- | 565 | movb %bl, %al |
|
- | 566 | outb %al, %dx |
|
- | 567 | ||
- | 568 | cli |
|
- | 569 | hlt |
|
449 | 570 | ||
450 | .section K_DATA_START, "aw", @progbits |
571 | .section K_DATA_START, "aw", @progbits |
451 | .align 4096 |
572 | .align 4096 |
452 | 573 | ||
453 | # Identical mapping of first 64MB and the same of -2GB -> 0 |
574 | # Identical mapping of first 64MB and the same of -2GB -> 0 |
Line 511... | Line 632... | ||
511 | grub_eax: |
632 | grub_eax: |
512 | .long 0 |
633 | .long 0 |
513 | 634 | ||
514 | grub_ebx: |
635 | grub_ebx: |
515 | .long 0 |
636 | .long 0 |
- | 637 | ||
- | 638 | long_mode_msg: |
|
- | 639 | .asciz "64 bit long mode not supported. System halted." |