From: Amelia Coutard Date: Thu, 12 May 2022 10:33:10 +0000 (+0200) Subject: Refactored boot.s a bit X-Git-Url: https://git.ameliathe1st.gay/?a=commitdiff_plain;h=3d482e05b061428021baff4169d250677cfdee37;p=voyage-au-centre-des-fichiers.git Refactored boot.s a bit --- diff --git a/src/boot.S b/src/boot.S index f113d37..c156d36 100644 --- a/src/boot.S +++ b/src/boot.S @@ -85,6 +85,9 @@ TSS: 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 @@ -94,7 +97,6 @@ PDPT_high: .skip 0x1000 - 16 .section .bss .align 0x1000 -PML4T: .skip 0x1000 phys_mem_map: .skip 0x1000 * 128 - 8 .align 16 stack_bottom: @@ -103,18 +105,11 @@ stack_top: .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 @@ -126,29 +121,37 @@ _start: 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 @@ -158,10 +161,6 @@ _start: # 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 @@ -245,5 +244,4 @@ _start: call _fini cli -1: hlt - jmp 1b + jmp halt