mov %eax, %cr0
# Jump to 64 bits:
- lgdt (GDT.PTR - KERNEL_VMA)
+ lgdt GDT.PTR - KERNEL_VMA
jmp $GDT.KERNEL_CODE, $.trampoline
.code64
.trampoline:
+ mov %esp, %esp
+
+ movq $GDT, GDT.PTR + 2
+ lgdt GDT.PTR # Reload GDT in higher half.
+ pushq $GDT.KERNEL_CODE
+ movabsq $.trampoline2, %rax
+ pushq %rax
+ lretq # Jump to new GDT.
+.trampoline2:
+
mov $GDT.KERNEL_DATA, %ax # Set the A-register to the data descriptor.
mov %ax, %ds # Set the data segment to the A-register.
mov %ax, %es # Set the extra segment to the A-register.
#include "interrupts.hpp"
os::idt<32> idt;
+extern "C" os::paging::PML4T PML4T;
extern "C" void kmain(unsigned long magic, os::phys_ptr<const multiboot2::info_start> info) {
os::assert(magic == 0x36D76289, "Incorrect magic number: wasn't booted with multiboot2.");
os::enable_interrupts(isr_info, idt);
}
- os::phys_ptr<os::paging::PML4T> PML4T = nullptr;
- asm ("movq $PML4T - 0xFFFFFFFF80000000,%0" : "=ri"(PML4T) : );
+ PML4T.contents[0].base_address()->contents[0].P(false);
+ PML4T.contents[0].base_address()->contents[1].P(false);
+ PML4T.contents[0].P(false);
os::print("Mapping:\n");
os::paging::print_mapping(PML4T);
// void os::paging::unmap(phys_ptr<PML4T> PLM4T, page* virt, std::uint64_t length) { }
// void os::paging::map(phys_ptr<PML4T> PLM4T, page* virt, std::uint64_t length, phys_ptr<page> phys) { }
-template<int order> void print_mapping(os::phys_ptr<os::paging::paging_table<order>> table, std::uint64_t virt_address, bool show_higher_half) {
+template<int order> void print_mapping(const os::paging::paging_table<order>& table, std::uint64_t virt_address, bool show_higher_half) {
for (std::size_t i = 0; i < (order == 3 && !show_higher_half ? 256 : 512); i++) {
- const auto& page = table->contents[i];
+ const auto& page = table.contents[i];
if (!page.P()) { continue; }
std::uint64_t new_virt = virt_address + i * (4096ul << (order * 9));
new_virt |= ((new_virt & 0x0000800000000000) != 0 ? 0xFFFF000000000000 : 0);
os::print(")\n");
} else {
if constexpr (order > 0) { // Will never be false when !page.is_page().
- print_mapping<order - 1>(page.base_address(), new_virt, show_higher_half);
+ print_mapping<order - 1>(*page.base_address(), new_virt, show_higher_half);
}
}
}
}
-void os::paging::print_mapping(phys_ptr<PML4T> PML4T, bool show_higher_half) {
+void os::paging::print_mapping(const PML4T& PML4T, bool show_higher_half) {
::print_mapping(PML4T, 0, show_higher_half);
}
void unmap(phys_ptr<PML4T> PLM4T, page* virt, std::uint64_t length);
void map(phys_ptr<PML4T> PLM4T, page* virt, std::uint64_t length, phys_ptr<page> phys);
-void print_mapping(phys_ptr<PML4T> PML4T, bool show_higher_half = false);
+void print_mapping(const PML4T& PML4T, bool show_higher_half = false);
class page_allocator_t;
extern page_allocator_t page_allocator;