diff --git a/Architecture/amd64/Bootstrap/Multiboot2/Detection.asm b/Architecture/amd64/Bootstrap/Multiboot2/Detection.asm index ee6166a7..f0ba7021 100644 --- a/Architecture/amd64/Bootstrap/Multiboot2/Detection.asm +++ b/Architecture/amd64/Bootstrap/Multiboot2/Detection.asm @@ -16,7 +16,7 @@ DetectCPUID: jz .NoCPUID ret .NoCPUID: - mov word [0xb8F00], 0xF00F ; . + ; mov word [0xb8F00], 0xF00F ; . .Loop: cli hlt @@ -34,7 +34,7 @@ Detect64Bit: jz .NoLongMode ret .NoLongMode: - mov word [0xb8F00], 0xF00A ; . + ; mov word [0xb8F00], 0xF00A ; . .Loop: cli hlt diff --git a/Architecture/amd64/Bootstrap/Multiboot2/Entry.asm b/Architecture/amd64/Bootstrap/Multiboot2/Entry.asm index 6c7c0d95..7a169234 100644 --- a/Architecture/amd64/Bootstrap/Multiboot2/Entry.asm +++ b/Architecture/amd64/Bootstrap/Multiboot2/Entry.asm @@ -29,7 +29,7 @@ MB2_HeaderInfo: section .bootstrap.text MB2_start: cli - mov word [0xb8F00], 0x072E ; . + ; mov word [0xb8F00], 0x072E ; . mov [MB2_HeaderMagic], eax mov [MB2_HeaderInfo], ebx @@ -37,7 +37,7 @@ MB2_start: call DetectCPUID call Detect64Bit - mov word [0xb8F02], 0x072E ; . + ; mov word [0xb8F02], 0x072E ; . mov ecx, cr0 and ecx, 0x7fffffff ; Clear PG @@ -56,7 +56,7 @@ MB2_start: mov edi, BootPageTable mov cr3, edi - mov word [0xb8F04], 0x072E ; . + ; mov word [0xb8F04], 0x072E ; . ; Enable long mode mov ecx, 0xC0000080 ; EFER @@ -84,7 +84,7 @@ MB2_start: [bits 64] HigherHalfStart: cli - mov word [0xb8F06], 0x072E ; . + ; mov word [0xb8F06], 0x072E ; . call UpdatePageTable64 ; Load the new page table @@ -98,7 +98,7 @@ HigherHalfStart: mov gs, ax mov ss, ax - mov word [0xb8F08], 0x072E ; . + ; mov word [0xb8F08], 0x072E ; . mov rsp, (KernelStack + KERNEL_STACK_SIZE) mov rbp, (KernelStack + KERNEL_STACK_SIZE) diff --git a/Architecture/amd64/Bootstrap/Multiboot2/Header.asm b/Architecture/amd64/Bootstrap/Multiboot2/Header.asm index b05828df..844b61d7 100644 --- a/Architecture/amd64/Bootstrap/Multiboot2/Header.asm +++ b/Architecture/amd64/Bootstrap/Multiboot2/Header.asm @@ -1,3 +1,5 @@ +extern MB2_start + [bits 32] section .multiboot2 align 4096 @@ -34,6 +36,22 @@ MB2_INFO_REQUEST_TAG_START: dd 21 ; Load Base Address MB2_INFO_REQUEST_TAG_END: align 8 +MB2_ENTRY_TAG: + dw 3 + dw 0 + dd MB2_ENTRY_TAG_END - MB2_ENTRY_TAG + dd MB2_start +MB2_ENTRY_TAG_END: +align 8 +MB2_FRAMEBUFFER_TAG_START: + dw 5 + dw 1 + dd MB2_FRAMEBUFFER_TAG_END - MB2_FRAMEBUFFER_TAG_START + dd 1280 ; Width + dd 720 ; Height + dd 32 ; Depth +MB2_FRAMEBUFFER_TAG_END: +align 8 MB2_TAG_START: dw 0 dw 0 diff --git a/Architecture/amd64/Bootstrap/Multiboot2/MB2MemoryMapper.cpp b/Architecture/amd64/Bootstrap/Multiboot2/MB2MemoryMapper.cpp index a128b496..fb3b16b0 100644 --- a/Architecture/amd64/Bootstrap/Multiboot2/MB2MemoryMapper.cpp +++ b/Architecture/amd64/Bootstrap/Multiboot2/MB2MemoryMapper.cpp @@ -259,6 +259,10 @@ __always_inline inline SafeFunction NIF void Map(void *VirtualAddress, void *Phy EXTERNC __attribute__((section(".bootstrap.text"))) SafeFunction NIF __attribute__((section(".bootstrap.text"))) void UpdatePageTable64() { + /* + TODO: this code corrupts the page table + */ + BPTable = (PageTable4 *)BootPageTable; // for (size_t i = 0; i < 0x10000000; i += 0x1000) diff --git a/Architecture/amd64/Bootstrap/Multiboot2/PageTable.asm b/Architecture/amd64/Bootstrap/Multiboot2/PageTable.asm index eba5546c..11982e26 100644 --- a/Architecture/amd64/Bootstrap/Multiboot2/PageTable.asm +++ b/Architecture/amd64/Bootstrap/Multiboot2/PageTable.asm @@ -1,7 +1,7 @@ -PAGE_TABLE_SIZE equ 0x4 ; 1GB +PAGE_TABLE_SIZE equ 0x8 ; 2GB [bits 32] -section .bootstrap.data +section .bootstrap.bss align 0x1000 global BootPageTable BootPageTable: diff --git a/Architecture/amd64/linker.ld b/Architecture/amd64/linker.ld index 96e0e549..9a938bae 100644 --- a/Architecture/amd64/linker.ld +++ b/Architecture/amd64/linker.ld @@ -4,7 +4,7 @@ OUTPUT_ARCH(i386:x86-64) KERNEL_LMA = 16M; KERNEL_VMA = 0xFFFFFFFF80000000; -ENTRY(MB2_start) +ENTRY(_start) SECTIONS { diff --git a/Core/Memory/PhysicalMemoryManager.cpp b/Core/Memory/PhysicalMemoryManager.cpp index 0da3ab13..21424d73 100644 --- a/Core/Memory/PhysicalMemoryManager.cpp +++ b/Core/Memory/PhysicalMemoryManager.cpp @@ -7,6 +7,8 @@ #include "../../kernel.h" +extern "C" char BootPageTable[]; // 0x10000 in length + namespace Memory { uint64_t Physical::GetTotalMemory() @@ -371,8 +373,10 @@ namespace Memory for (uint64_t i = 0; i < Info->Memory.Entries; i++) if (Info->Memory.Entry[i].Type != Usable) this->ReservePages((void *)Info->Memory.Entry[i].BaseAddress, Info->Memory.Entry[i].Length / PAGE_SIZE + 1); - trace("Locking bitmap pages..."); + this->ReservePages(0, 0x100); + this->ReservePages(BootPageTable, TO_PAGES(0x10000)); + trace("Locking bitmap pages..."); this->LockPages(PageBitmap.Buffer, PageBitmap.Size / PAGE_SIZE + 1); }