From 4f9a4292e5ccdd5055cd5b55d0eedbb6db2ac183 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20Lov=C3=A9n?= Date: Wed, 15 Nov 2017 20:37:22 +0100 Subject: [PATCH] Some simplification and commenting --- src/kernel/boot/boot.S | 73 ++++++++++++++++++++++----------------- src/kernel/boot/boot_PT.S | 12 ++----- 2 files changed, 45 insertions(+), 40 deletions(-) diff --git a/src/kernel/boot/boot.S b/src/kernel/boot/boot.S index 244c953..cc0383f 100644 --- a/src/kernel/boot/boot.S +++ b/src/kernel/boot/boot.S @@ -12,19 +12,32 @@ BootStack: .code32 error: // Print "ERR!" in upper left corner - mov [0xb8000], dword ptr 0x4f524f45 - mov [0xb8004], dword ptr 0x4f214f52 + mov [0xb8000], dword ptr 0x4f004f00 + mov [0xb8004], dword ptr 0x4f004f00 + mov [0xb8000], byte ptr 'E' + mov [0xb8002], byte ptr 'R' + mov [0xb8004], byte ptr 'R' + mov [0xb8006], byte ptr '!' jmp $ check_cpuid: + // Save EFLAGS pushfd + + // Try to modify EFLAGS.ID pushfd - xor dword ptr[esp], 1<<21 + xor dword ptr [esp], 1<<21 popfd + + //Read EFLAGS into eax pushfd pop eax - xor eax, [esp] + + // Restore original EFLAGS popfd + + // Check if EFLAGS.ID was modified + xor eax, [esp+4] and eax, 1<<21 jz error ret @@ -47,43 +60,41 @@ check_longmode: .global _start _start: -cli + cli -mov esp, offset BootStack + mov esp, offset BootStack -call check_cpuid -call check_longmode + call check_cpuid + call check_longmode -mov eax, cr4 -or eax, 1<<5 -mov cr4, eax + mov eax, cr4 + or eax, 1<<5 + mov cr4, eax -mov eax, offset BootP4 -mov cr3, eax + mov eax, offset BootP4 + mov cr3, eax -mov ecx, 0x0C0000080 -rdmsr -or eax, 1<<8 -wrmsr + mov ecx, 0x0C0000080 + rdmsr + or eax, 1<<8 + wrmsr -mov eax, cr0 -or eax, 1<<31 -mov cr0, eax + mov eax, cr0 + or eax, 1<<31 + mov cr0, eax -lgdt [BootGDTp] + lgdt [BootGDTp] - -.extern long_mode_start jmp 0x8:long_mode_start .code64 -long_mode_start: + long_mode_start: -mov eax, 0x0 -mov ss, eax -mov ds, eax -mov es, eax -mov fs, eax -mov gs, eax + mov eax, 0x0 + mov ss, eax + mov ds, eax + mov es, eax + mov fs, eax + mov gs, eax -jmp $ + jmp $ diff --git a/src/kernel/boot/boot_PT.S b/src/kernel/boot/boot_PT.S index d9ed9f2..da0c92f 100644 --- a/src/kernel/boot/boot_PT.S +++ b/src/kernel/boot/boot_PT.S @@ -7,16 +7,10 @@ BootP4: .quad offset BootP3 + (PAGE_PRESENT | PAGE_WRITE) .rept ENTRIES_PER_PT - 1 - .quad 0x0 + .quad 0 .endr BootP3: - .quad offset BootP2 + (PAGE_PRESENT | PAGE_WRITE) + .quad 0 + (PAGE_PRESENT | PAGE_WRITE | PAGE_HUGE) .rept ENTRIES_PER_PT - 1 - .quad 0x0 - .endr -BootP2: - .set i, 0 - .rept ENTRIES_PER_PT - .quad (i << 21 ) + (PAGE_PRESENT | PAGE_WRITE | PAGE_HUGE) - .set i, (i+1) + .quad 0 .endr