TSS_END:
.set TSS_SIZE, TSS_END - TSS
.align 0x1000
+PML4T: .quad PDPT_low - KERNEL_VMA + 3
+ .skip 0x1000 - 16
+ .quad PDPT_high - KERNEL_VMA + 3
PDPT_low: .quad 0x83
.quad 0x83 + 1024 * 1024 * 1024
.skip 0x1000 - 16
.section .bss
.align 0x1000
-PML4T: .skip 0x1000
phys_mem_map: .skip 0x1000 * 128 - 8
.align 16
stack_bottom:
.section .bootstrap_text
.code32
-.globl _start
-_start:
- cli
- mov $stack_top - KERNEL_VMA, %esp
- # Save multiboot info:
- push $0 # /
- push %eax # \ magic
- push $0 # /
- push %ebx # \ info structure
+halt: hlt
+ jmp halt
- # Check if cpuid is supported:
+check_cpuid_support:
pushfl
pop %eax
mov %eax, %ecx
push %ecx
popfl
xor %ecx, %eax
- jnz .has_cpuid
- 1: hlt
- jmp 1b
- .has_cpuid:
+ jz halt # No cpuid.
+ ret
- # Check is long mode is supported:
+check_long_mode_support:
mov $0x80000000, %eax
cpuid
cmp $0x80000001, %eax
- jb .no_long_mode
+ jb halt # No ability to check for long mode.
mov $0x80000001, %eax
cpuid
# Long mode:
test $1 << 29, %edx
- jz .no_long_mode
+ jz halt # No long mode.
# 1GiB pages:
test $1 << 26, %edx
- jz .no_long_mode
- jmp .has_long_mode
- .no_long_mode:
- 1: hlt
- jmp 1b
- .has_long_mode:
+ jz halt # No 1GiB pages.
+ ret
+
+.globl _start
+_start:
+ cli
+ mov $stack_top - KERNEL_VMA, %esp
+
+ # Save multiboot info:
+ push $0 # /
+ push %eax # \ magic
+ push $0 # /
+ push %ebx # \ info structure
+
+ call check_cpuid_support
+ call check_long_mode_support
# Disable 32-bit paging:
mov %cr0, %eax
# Setup 64-bit paging:
mov $PML4T - KERNEL_VMA, %eax
mov %eax, %cr3
- mov $PDPT_low - KERNEL_VMA + 3, %eax
- mov %eax, PML4T - KERNEL_VMA + 0 * 8
- mov $PDPT_high - KERNEL_VMA + 3, %eax
- mov %eax, PML4T - KERNEL_VMA + 511 * 8
# Enable PAE paging:
mov %cr4, %eax
call _fini
cli
-1: hlt
- jmp 1b
+ jmp halt