unified comment fontcase

This commit is contained in:
Steffen Vogel 2014-01-09 13:41:22 +01:00
parent 88a2e573c6
commit 269bffc208

View file

@ -81,11 +81,11 @@ GDT64: ; Global Descriptor Table (64-bit).
dw $ - GDT64 - 1 ; Limit. dw $ - GDT64 - 1 ; Limit.
dq GDT64 ; Base. dq GDT64 ; Base.
times 256 DD 0 ; stack for booting times 256 DD 0 ; Stack for booting
startup_stack: startup_stack:
SECTION .data SECTION .data
; create default page tables for the 64bit kernel ; Create default page tables for the 64bit kernel
global boot_pml4 global boot_pml4
ALIGN 4096 ; of course, the page tables have to be page aligned ALIGN 4096 ; of course, the page tables have to be page aligned
@ -102,37 +102,37 @@ ALIGN 8
%if MAX_CORES > 1 %if MAX_CORES > 1
global smp_entry global smp_entry
smp_entry: smp_entry:
; initialize cpu features ; Initialize cpu features
call cpu_init call cpu_init
; initialize cr3 register ; Initialize cr3 register
mov edi, boot_pml4 mov edi, boot_pml4
mov cr3, edi mov cr3, edi
; enable PAE ; Enable PAE
mov eax, cr4 mov eax, cr4
or eax, 1 << 5 or eax, 1 << 5
mov cr4, eax mov cr4, eax
; enable longmode (compatibility mode) ; Enable longmode (compatibility mode)
mov ecx, 0xC0000080 mov ecx, 0xC0000080
rdmsr rdmsr
or eax, 1 << 8 or eax, 1 << 8
wrmsr wrmsr
; enable paging ; Enable paging
mov eax, cr0 mov eax, cr0
or eax, 1 << 31 | 1 << 0 ; Set the PG-bit, which is the 31nd bit, and the PE-bit, which is the 0th bit. or eax, 1 << 31 | 1 << 0 ; Set the PG-bit, which is the 31nd bit, and the PE-bit, which is the 0th bit.
mov cr0, eax ; According to the multiboot spec the PE-bit has to be set by bootloader already! mov cr0, eax ; According to the multiboot spec the PE-bit has to be set by bootloader already!
; jump to 64-bit longmode ; Jump to 64-bit longmode
mov edi, [esp+4] ; set argumet for smp_start mov edi, [esp+4] ; Set argumet for smp_start
lgdt [GDT64.Pointer] ; Load the 64-bit global descriptor table. lgdt [GDT64.Pointer] ; Load the 64-bit global descriptor table.
jmp GDT64.Code:smp_start64 ; Set the code segment and enter 64-bit long mode. jmp GDT64.Code:smp_start64 ; Set the code segment and enter 64-bit long mode.
jmp $ ; endless loop jmp $ ; endless loop
%endif %endif
; search MP Floating Pointer Structure ; Search MP Floating Pointer Structure
search_mps: search_mps:
push ebp push ebp
mov ebp, esp mov ebp, esp
@ -164,7 +164,7 @@ search_mps:
ret ret
check_longmode: check_longmode:
; check for cpuid instruction ; Check for cpuid instruction
pushfd pushfd
pop eax pop eax
mov ecx, eax mov ecx, eax
@ -177,12 +177,12 @@ check_longmode:
popfd popfd
xor eax, ecx xor eax, ecx
jz .unsupported jz .unsupported
; check for extended cpu features (cpuid > 0x80000000) ; Check for extended cpu features (cpuid > 0x80000000)
mov eax, 0x80000000 mov eax, 0x80000000
cpuid cpuid
cmp eax, 0x80000001 cmp eax, 0x80000001
jb .unsupported ; It is less, there is no long mode. jb .unsupported ; It is less, there is no long mode.
; check if longmode is supported ; Check if longmode is supported
mov eax, 0x80000001 mov eax, 0x80000001
cpuid cpuid
test edx, 1 << 29 ; Test if the LM-bit, which is bit 29, is set in the D-register. test edx, 1 << 29 ; Test if the LM-bit, which is bit 29, is set in the D-register.
@ -201,7 +201,7 @@ check_lapic:
and edx, 0x200 and edx, 0x200
cmp edx, 0 cmp edx, 0
je .unsupported je .unsupported
; map lapic at 0xFEE00000 below the kernel ; Map lapic at 0xFEE00000 below the kernel
mov edi, kernel_start - 0x1000 mov edi, kernel_start - 0x1000
shr edi, 9 ; (edi >> 12) * 8 shr edi, 9 ; (edi >> 12) * 8
add edi, boot_pgt add edi, boot_pgt
@ -217,12 +217,12 @@ check_lapic:
cpu_init: cpu_init:
mov eax, cr0 mov eax, cr0
; enable caching, disable paging and fpu emulation ; Enable caching, disable paging and fpu emulation
and eax, 0x1ffffffb and eax, 0x1ffffffb
; ...and turn on FPU exceptions ; ...and turn on FPU exceptions
or eax, 0x22 or eax, 0x22
mov cr0, eax mov cr0, eax
; clears the current pgd entry ; Clear the current pgd entry
xor eax, eax xor eax, eax
mov cr3, eax mov cr3, eax
; at this stage, we disable the SSE support ; at this stage, we disable the SSE support
@ -231,18 +231,20 @@ cpu_init:
mov cr4, eax mov cr4, eax
ret ret
; identity map a single page at address eax ; Identity map a single page at address eax
identity_page: identity_page:
push edi push edi
push ebx push ebx
and eax, 0xFFFFF000
mov edi, eax mov edi, eax
and edi, 0xFFFFF000 ; page align in lower half
shr edi, 9 ; (edi >> 12) * 8 (index for boot_pgt) shr edi, 9 ; (edi >> 12) * 8 (index for boot_pgt)
add edi, boot_pgt add edi, boot_pgt
mov ebx, eax mov ebx, eax
and ebx, 0xFFFFF000 ; page align lower half
or ebx, 0x113 ; set present, global, writable and cache disable bits or ebx, 0x113 ; set present, global, writable and cache disable bits
mov DWORD [edi], ebx mov DWORD [edi], ebx
mov DWORD [edi+4], 0x80000000 ; set execution disable bit in higher half
pop ebx pop ebx
pop edi pop edi
@ -251,16 +253,16 @@ identity_page:
ALIGN 4 ALIGN 4
stublet: stublet:
mov esp, startup_stack-4 mov esp, startup_stack-4
; save pointer to the Multiboot structure ; Save pointer to the Multiboot structure
push ebx push ebx
; initialize cpu features ; Initialize cpu features
call cpu_init call cpu_init
; check if longmode is supported ; Check if longmode is supported
call check_longmode call check_longmode
; check if lapic is available ; Check if lapic is available
call check_lapic call check_lapic
; find MP Floating Pointer structure ; Find MP Floating Pointer structure
push DWORD 0x100000 push DWORD 0x100000
push DWORD 0xF0000 push DWORD 0xF0000
call search_mps call search_mps
@ -278,22 +280,22 @@ stublet:
je map_kernel je map_kernel
map_mps: map_mps:
; map MP Floating Pointer structure ; Map MP Floating Pointer structure
mov DWORD [apic_mp], eax mov DWORD [apic_mp], eax
call identity_page call identity_page
; map MP Configuration table ; Map MP Configuration table
mov eax, [apic_mp+4] mov eax, [eax+4] ; Offset for physical address of MP table
call identity_page call identity_page
%ifdef CONFIG_VGA %ifdef CONFIG_VGA
; map VGA textmode plane ; Map VGA textmode plane
mov eax, 0xB8000 mov eax, 0xB8000
call identity_page call identity_page
%endif %endif
; map Multiboot structure ; Map Multiboot structure
mov eax, [esp] ; pointer is still on the stack mov eax, [esp] ; Pointer is still on the stack
call identity_page call identity_page
map_kernel: map_kernel:
@ -317,67 +319,67 @@ init_paging:
mov cr3, edi mov cr3, edi
mov DWORD [edi], boot_pdpt mov DWORD [edi], boot_pdpt
or DWORD [edi], 0x07 ; set present, user and writable flags or DWORD [edi], 0x03 ; Set present and writable flags
mov edi, boot_pdpt mov edi, boot_pdpt
mov DWORD [edi], boot_pgd mov DWORD [edi], boot_pgd
or DWORD [edi], 0x03 ; set present and writable flags or DWORD [edi], 0x03 ; Set present and writable flags
mov edi, boot_pgd mov edi, boot_pgd
mov ebx, boot_pgt mov ebx, boot_pgt
mov ecx, PAGE_MAP_ENTRIES ; map all boot_pgt to the kernel space mov ecx, PAGE_MAP_ENTRIES ; Map all boot_pgt to the kernel space
.l1: .l1:
mov DWORD [edi], ebx mov DWORD [edi], ebx
or DWORD [edi], 0x03 ; set present and writable flags or DWORD [edi], 0x03 ; Set present and writable flags
add edi, 8 add edi, 8
add ebx, 0x1000 add ebx, 0x1000
loop .l1 loop .l1
; enable PAE ; Enable PAE
mov eax, cr4 mov eax, cr4
or eax, 1 << 5 or eax, 1 << 5
mov cr4, eax mov cr4, eax
; enable longmode (compatibility mode) ; Enable longmode (compatibility mode)
mov ecx, 0xC0000080 mov ecx, 0xC0000080
rdmsr rdmsr
or eax, 1 << 8 or eax, 1 << 8 ; IA32_EFER.LME = 1
wrmsr wrmsr
; enable paging ; Enable paging
mov eax, cr0 mov eax, cr0
or eax, 1 << 31 | 1 << 0 ; Set the PG-bit, which is the 31nd bit, and the PE-bit, which is the 0th bit. or eax, 1 << 31 | 1 << 0 ; Set the PG-bit, which is the 31nd bit, and the PE-bit, which is the 0th bit.
mov cr0, eax mov cr0, eax
; jump to 64-bit longmode ; Jump to 64-bit longmode
pop ebx ; restore pointer to multiboot structure pop ebx ; Restore pointer to multiboot structure
lgdt [GDT64.Pointer] ; Load the 64-bit global descriptor table. lgdt [GDT64.Pointer] ; Load the 64-bit global descriptor table.
jmp GDT64.Code:start64 ; Set the code segment and enter 64-bit long mode. jmp GDT64.Code:start64 ; Set the code segment and enter 64-bit long mode.
[BITS 64] [BITS 64]
start64: start64:
; initialize segment registers ; Initialize segment registers
mov ax, GDT64.Data mov ax, GDT64.Data
mov ds, ax mov ds, ax
mov es, ax mov es, ax
mov fs, ax mov fs, ax
mov gs, ax mov gs, ax
mov ss, ax mov ss, ax
; set default stack pointer ; Set default stack pointer
mov rsp, boot_stack mov rsp, boot_stack
add rsp, KERNEL_STACK_SIZE-16 add rsp, KERNEL_STACK_SIZE-16
; interpret multiboot information ; Interpret multiboot information
extern multiboot_init extern multiboot_init
mov rdi, rbx mov rdi, rbx
call multiboot_init call multiboot_init
; jump to the boot processors's C code ; Jump to the boot processors's C code
extern main extern main
call main call main
jmp $ jmp $
%if MAX_CORES > 1 %if MAX_CORES > 1
smp_start64: smp_start64:
; initialize segment registers ; Initialize segment registers
mov ax, GDT64.Data mov ax, GDT64.Data
mov ds, ax mov ds, ax
mov es, ax mov es, ax
@ -385,7 +387,7 @@ smp_start64:
mov gs, ax mov gs, ax
mov ss, ax mov ss, ax
; jump to the boot processors's C code ; Jump to the boot processors's C code
extern smp_start extern smp_start
call smp_start call smp_start
jmp $ jmp $