63,9 → 63,24 |
jmpl $selector(KTEXT_DES), $multiboot_meeting_point |
multiboot_meeting_point: |
|
pushl %ebx # save parameters from GRUB |
pushl %eax |
movl %eax, grub_eax # save parameters from GRUB |
movl %ebx, grub_ebx |
|
xorl %eax, %eax |
cpuid |
cmp $0x0, %eax # any function > 0? |
jbe pse_unsupported |
movl $0x1, %eax # Basic function code 1 |
cpuid |
bt $3, %edx # Test if PSE is supported |
jc pse_supported |
|
pse_unsupported: |
movl $pse_msg, %esi |
jmp error_halt |
|
pse_supported: |
|
#ifdef CONFIG_FB |
mov $vesa_init, %esi |
mov $VESA_INIT_SEGMENT << 4, %edi |
89,8 → 104,8 |
|
call map_kernel # map kernel and turn paging on |
|
popl %eax |
popl %ebx |
movl grub_eax, %eax |
movl grub_ebx, %ebx |
cmpl $MULTIBOOT_LOADER_MAGIC, %eax # compare GRUB signature |
je valid_boot |
|
209,7 → 224,7 |
rep movsb |
|
#endif |
|
|
call main_bsp # never returns |
|
cli |
222,19 → 237,20 |
# For simplicity, we map the entire 4G space. |
# |
movl %cr4, %ecx |
orl $(1<<4), %ecx |
movl %ecx, %cr4 # turn PSE on |
orl $(1 << 4), %ecx # turn PSE on |
andl $(~(1 << 5)), %ecx # turn PAE off |
movl %ecx, %cr4 |
|
movl $(page_directory+0), %esi |
movl $(page_directory+2048), %edi |
movl $(page_directory + 0), %esi |
movl $(page_directory + 2048), %edi |
xorl %ecx, %ecx |
xorl %ebx, %ebx |
0: |
movl $((1<<7)|(1<<0)), %eax |
movl $((1 << 7) | (1 << 1) | (1 << 0)), %eax |
orl %ebx, %eax |
movl %eax, (%esi,%ecx,4) # mapping 0x00000000+%ecx*4M => 0x00000000+%ecx*4M |
movl %eax, (%edi,%ecx,4) # mapping 0x80000000+%ecx*4M => 0x00000000+%ecx*4M |
addl $(4*1024*1024), %ebx |
movl %eax, (%esi, %ecx, 4) # mapping 0x00000000 + %ecx * 4M => 0x00000000 + %ecx * 4M |
movl %eax, (%edi, %ecx, 4) # mapping 0x80000000 + %ecx * 4M => 0x00000000 + %ecx * 4M |
addl $(4 * 1024 * 1024), %ebx |
|
incl %ecx |
cmpl $512, %ecx |
242,12 → 258,71 |
|
movl %esi, %cr3 |
|
# turn paging on |
movl %cr0, %ebx |
orl $(1<<31), %ebx |
orl $(1 << 31), %ebx # turn paging on |
movl %ebx, %cr0 |
ret |
|
# Print string from %esi to EGA display (in red) and halt |
error_halt: |
movl $0xb8000, %edi # base of EGA text mode memory |
xorl %eax, %eax |
|
movw $0x3d4, %dx # read bits 8 - 15 of the cursor address |
movb $0xe, %al |
outb %al, %dx |
|
movw $0x3d5, %dx |
inb %dx, %al |
shl $8, %ax |
|
movw $0x3d4, %dx # read bits 0 - 7 of the cursor address |
movb $0xf, %al |
outb %al, %dx |
|
movw $0x3d5, %dx |
inb %dx, %al |
|
cmp $1920, %ax |
jbe cursor_ok |
movw $1920, %ax # sanity check for the cursor on the last line |
cursor_ok: |
|
movw %ax, %bx |
shl $1, %eax |
addl %eax, %edi |
|
movw $0x0c00, %ax # black background, light red foreground |
cld |
|
ploop: |
lodsb |
cmp $0, %al |
je ploop_end |
stosw |
inc %bx |
jmp ploop |
ploop_end: |
|
movw $0x3d4, %dx # write bits 8 - 15 of the cursor address |
movb $0xe, %al |
outb %al, %dx |
|
movw $0x3d5, %dx |
movb %bh, %al |
outb %al, %dx |
|
movw $0x3d4, %dx # write bits 0 - 7 of the cursor address |
movb $0xf, %al |
outb %al, %dx |
|
movw $0x3d5, %dx |
movb %bl, %al |
outb %al, %dx |
|
cli |
hlt |
|
#ifdef CONFIG_FB |
vesa_init: |
jmp $selector(VESA_INIT_DES), $vesa_init_real - vesa_init |
278,11 → 353,12 |
|
#define VESA_INFO_SIZE 1024 |
|
#define VESA_MODE_ATTRIBUTES_OFFSET 0 |
#define VESA_MODE_LIST_PTR_OFFSET 14 |
#define VESA_MODE_SCANLINE_OFFSET 16 |
#define VESA_MODE_WIDTH_OFFSET 18 |
#define VESA_MODE_HEIGHT_OFFSET 20 |
#define VESA_MODE_BPP_OFFSET 25 |
#define VESA_MODE_SCANLINE_OFFSET 16 |
#define VESA_MODE_PHADDR_OFFSET 40 |
|
#define VESA_END_OF_MODES 0xffff |
292,12 → 368,10 |
#define VESA_GET_INFO 0x4f00 |
#define VESA_GET_MODE_INFO 0x4f01 |
#define VESA_SET_MODE 0x4f02 |
#define VESA_SET_PALETTE 0x4f09 |
|
#define CONFIG_VESA_BPP_a 255 |
|
#if CONFIG_VESA_BPP == 24 |
#undef CONFIG_VESA_BPP_a |
#define CONFIG_VESA_BPP_a 32 |
#define CONFIG_VESA_BPP_VARIANT 32 |
#endif |
|
mov $VESA_GET_INFO, %ax |
338,18 → 412,21 |
cmp VESA_MODE_WIDTH_OFFSET(%di), %ax |
jnz 1b |
|
mov $CONFIG_VESA_HEIGHT,%ax |
mov $CONFIG_VESA_HEIGHT, %ax |
cmp VESA_MODE_HEIGHT_OFFSET(%di), %ax |
jnz 1b |
|
mov $CONFIG_VESA_BPP, %al |
cmp VESA_MODE_BPP_OFFSET(%di), %al |
|
#ifdef CONFIG_VESA_BPP_VARIANT |
jz 2f |
|
mov $CONFIG_VESA_BPP_a, %al |
mov $CONFIG_VESA_BPP_VARIANT, %al |
cmp VESA_MODE_BPP_OFFSET(%di), %al |
#endif |
jnz 1b |
|
|
2: |
|
mov %cx, %bx |
361,7 → 438,60 |
pop %di |
cmp $VESA_OK, %al |
jnz 0f |
|
#if CONFIG_VESA_BPP == 8 |
|
# Set 3:2:3 VGA palette |
|
mov VESA_MODE_ATTRIBUTES_OFFSET(%di), %ax |
push %di |
mov $vga323 - vesa_init, %di |
mov $0x100, %ecx |
|
bt $5, %ax # Test if VGA compatible registers are present |
jnc vga_compat |
|
# Try VESA routine to set palette |
|
mov $VESA_SET_PALETTE, %ax |
xor %bl, %bl |
xor %dx, %dx |
int $0x10 |
|
jmp vga_not_compat |
|
vga_compat: |
|
# Try VGA registers to set palette |
|
movw $0x3c6, %dx # Set palette mask |
movb $0xff, %al |
outb %al, %dx |
|
movw $0x3c8, %dx # First index to set |
xor %al, %al |
outb %al, %dx |
|
movw $0x3c9, %dx # Data port |
vga_loop: |
movb %es:2(%di), %al |
outb %al, %dx |
|
movb %es:1(%di), %al |
outb %al, %dx |
|
movb %es:(%di), %al |
outb %al, %dx |
|
addw $4, %di |
loop vga_loop |
|
vga_not_compat: |
|
pop %di |
|
#endif |
|
mov VESA_MODE_PHADDR_OFFSET(%di), %esi |
mov VESA_MODE_WIDTH_OFFSET(%di), %ax |
shl $16, %eax |
402,12 → 532,12 |
mov $0xffffffff, %edi # EGA text mode used, because of problems with VESA |
xor %ax, %ax |
jz 8b # Force relative jump |
|
|
vga323: |
#include "vga323.pal" |
|
.code32 |
vesa_init_protect: |
popl %esp |
|
movw $selector(KDATA_DES), %cx |
movw %cx, %es |
movw %cx, %fs |
415,6 → 545,8 |
movw %cx, %ds # kernel data + stack |
movw %cx, %ss |
|
movl $START_STACK, %esp # initialize stack pointer |
|
jmpl $selector(KTEXT_DES), $vesa_meeting_point |
|
.align 4 |
426,3 → 558,12 |
.align 4096 |
page_directory: |
.space 4096, 0 |
|
grub_eax: |
.long 0 |
|
grub_ebx: |
.long 0 |
|
pse_msg: |
.asciz "Page Size Extension not supported. System halted." |