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) ENTRY(_start)
KERNEL_OFFSET = 0xFFFFFF8000000000;
KERNEL_START = 0x10000;
SECTIONS SECTIONS
{ {
.text : . = KERNEL_START + KERNEL_OFFSET;
.text : AT(ADDR(.text) - KERNEL_OFFSET)
{ {
*(.multiboot) *(.multiboot)
*(.text) *(.text)
} }
.rodata : AT(ADDR(.rodata) - KERNEL_OFFSET)
.bss :
{ {
*(.rodata*)
}
.data : AT(ADDR(.data) - KERNEL_OFFSET)
{
*(.data)
}
.bss : AT(ADDR(.bss) - KERNEL_OFFSET)
{
*(.COMMON)
*(.bss) *(.bss)
} }
} }

View File

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

View File

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

View File

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