From dd7636e9066a0111c4ec8cabbfe041b2919bd9f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Lov=C3=A9n?= Date: Sun, 12 Nov 2017 00:22:51 +0100 Subject: [PATCH] Simplest possible long-mode entry --- src/kernel/boot/boot.S | 29 +++++++++++++++++++++++++++++ src/kernel/boot/boot_pagedir.S | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 src/kernel/boot/boot_pagedir.S diff --git a/src/kernel/boot/boot.S b/src/kernel/boot/boot.S index bacebc8..4be4593 100644 --- a/src/kernel/boot/boot.S +++ b/src/kernel/boot/boot.S @@ -53,4 +53,33 @@ mov esp, offset BootStack call check_cpuid call check_longmode +mov eax, cr4 +or eax, 1<<5 +mov cr4, eax + +mov eax, offset BootP4 +mov cr3, eax + +mov ecx, 0x0C0000080 +rdmsr +or eax, 1<<8 +wrmsr + +mov eax, cr0 +or eax, 1<<31 +mov cr0, eax + +lgdt [BootGDTp] + +mov eax, 0x10 +mov ss, eax +mov ds, eax +mov es, eax + +.extern long_mode_start + jmp 0x8:long_mode_start + +.code64 +long_mode_start: + jmp $ diff --git a/src/kernel/boot/boot_pagedir.S b/src/kernel/boot/boot_pagedir.S new file mode 100644 index 0000000..6284ac5 --- /dev/null +++ b/src/kernel/boot/boot_pagedir.S @@ -0,0 +1,33 @@ +.intel_syntax noprefix + +.section .data +.align 0x1000 +.global BootP4 +BootP4: + .quad offset BootP3 + 0x3 + .rept 511 + .quad 0x0 + .endr +BootP3: + .quad offset BootP2 + 0x3 + .rept 511 + .quad 0x0 + .endr +BootP2: + .set i, 0 + .rept 512 + .quad (i << 21 ) + 0x83 + .set i, (i+1) + .endr + +.section .rodata +.align 0x1000 +.global BootGDT +.global BootGDTp +BootGDT: + .quad 0 + .quad ((1<<47) + (1<<44) + (1<<41) + (1<<43) + (1<<53)) + .quad ((1<<47) + (1<<44) + (1<<41)) +BootGDTp: + .short 3*8-1 + .quad offset BootGDT