Move the kernel to high memory

This commit is contained in:
Thomas Lovén 2017-11-17 19:49:42 +01:00
parent 8f8e03de10
commit 663668ff93
4 changed files with 31 additions and 11 deletions

View File

@ -1,15 +1,27 @@
ENTRY(_start)
KERNEL_OFFSET = 0xFFFFFF8000000000;
KERNEL_START = 0x10000;
SECTIONS
{
.text :
. = KERNEL_START + KERNEL_OFFSET;
.text : AT(ADDR(.text) - KERNEL_OFFSET)
{
*(.multiboot)
*(.text)
}
.bss :
.rodata : AT(ADDR(.rodata) - KERNEL_OFFSET)
{
*(.rodata*)
}
.data : AT(ADDR(.data) - KERNEL_OFFSET)
{
*(.data)
}
.bss : AT(ADDR(.bss) - KERNEL_OFFSET)
{
*(.COMMON)
*(.bss)
}
}

View File

@ -14,7 +14,7 @@ _start:
cli
//; Set up a known stack
mov esp, offset BootStack
mov esp, offset V2P(BootStack)
//; Set CR4.PAE
//; enabling Page Address Extension
@ -23,7 +23,7 @@ _start:
mov cr4, eax
//; Load a P4 page table
mov eax, offset BootP4
mov eax, offset V2P(BootP4)
mov cr3, eax
//; Set EFER.LME
@ -40,10 +40,10 @@ _start:
mov cr0, eax
//; Load a new GDT
lgdt [BootGDTp]
lgdt [V2P(BootGDTp)]
//; and update the code selector by a long jump
jmp 0x8:long_mode_start
jmp 0x8:V2P(long_mode_start)
.code64
long_mode_start:
@ -54,5 +54,10 @@ _start:
mov ds, eax
mov es, eax
movabs rax, offset upper_memory
jmp rax
upper_memory:
//; Loop infinitely
jmp $

View File

@ -5,17 +5,18 @@
.align PAGE_SIZE
.global BootP4
BootP4:
.quad offset BootP3 + (PAGE_PRESENT | PAGE_WRITE)
.rept ENTRIES_PER_PT - 1
.quad offset V2P(BootP3) + (PAGE_PRESENT | PAGE_WRITE)
.rept ENTRIES_PER_PT - 2
.quad 0
.endr
.quad offset V2P(BootP3) + (PAGE_PRESENT | PAGE_WRITE)
BootP3:
.quad offset BootP2 + (PAGE_PRESENT | PAGE_WRITE)
.quad offset V2P(BootP2) + (PAGE_PRESENT | PAGE_WRITE)
.rept ENTRIES_PER_PT - 1
.quad 0
.endr
BootP2:
.quad offset BootP1 + (PAGE_PRESENT | PAGE_WRITE)
.quad offset V2P(BootP1) + (PAGE_PRESENT | PAGE_WRITE)
.rept ENTRIES_PER_PT - 1
.quad 0
.endr

View File

@ -1,4 +1,6 @@
#pragma once
#define KERNEL_OFFSET 0xFFFFFF8000000000
#define V2P(a) ((a) - KERNEL_OFFSET)
#define PAGE_PRESENT 0x001
#define PAGE_WRITE 0x002