diff --git a/src/kernel/Link.ld b/src/kernel/Link.ld index 37b3e28..2fa7802 100644 --- a/src/kernel/Link.ld +++ b/src/kernel/Link.ld @@ -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) } } diff --git a/src/kernel/boot/boot.S b/src/kernel/boot/boot.S index 2c4fd34..54ca899 100644 --- a/src/kernel/boot/boot.S +++ b/src/kernel/boot/boot.S @@ -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 $ diff --git a/src/kernel/boot/boot_PT.S b/src/kernel/boot/boot_PT.S index d1003d0..cd94231 100644 --- a/src/kernel/boot/boot_PT.S +++ b/src/kernel/boot/boot_PT.S @@ -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 diff --git a/src/kernel/include/memory.h b/src/kernel/include/memory.h index 31b09e8..fee7398 100644 --- a/src/kernel/include/memory.h +++ b/src/kernel/include/memory.h @@ -1,4 +1,6 @@ #pragma once +#define KERNEL_OFFSET 0xFFFFFF8000000000 +#define V2P(a) ((a) - KERNEL_OFFSET) #define PAGE_PRESENT 0x001 #define PAGE_WRITE 0x002