diff --git a/src/boot/loader.cpp b/src/boot/loader.cpp index 9455f50..edd27ce 100644 --- a/src/boot/loader.cpp +++ b/src/boot/loader.cpp @@ -59,14 +59,14 @@ load( void *data_start = offset_ptr(data, pheader->offset); bs->copy_mem(pages, data_start, pheader->mem_size); - console::print(L" Kernel section %d physical: 0x%lx\r\n", i, pages); - console::print(L" Kernel section %d virtual: 0x%lx\r\n", i, pheader->vaddr); + console::print(L" section %d phys: 0x%lx\r\n", i, pages); + console::print(L" section %d virt: 0x%lx\r\n", i, pheader->vaddr); // TODO: set appropriate RWX permissions paging::map_pages(pml4, args, reinterpret_cast(pages), pheader->vaddr, pheader->mem_size); } - console::print(L" Kernel entrypoint: 0x%lx\r\n", header->entrypoint); + console::print(L" entrypoint: 0x%lx\r\n", header->entrypoint); return reinterpret_cast(header->entrypoint); } diff --git a/src/boot/paging.cpp b/src/boot/paging.cpp index 1e5332f..056b720 100644 --- a/src/boot/paging.cpp +++ b/src/boot/paging.cpp @@ -71,11 +71,20 @@ public: { m_table[0] = pml4; for (unsigned i = 0; i < D; ++i) { - m_index[i] = static_cast((virt >> (12 + 9*i)) & 0x1ff); + m_index[i] = static_cast((virt >> (12 + 9*(3-i))) & 0x1ff); ensure_table(i); } } + uintptr_t vaddress() const { + uintptr_t address = 0; + for (unsigned i = 0; i < D; ++i) + address |= static_cast(m_index[i]) << (12 + 9*(3-i)); + if (address & (1ull<<47)) // canonicalize the address + address |= (0xffffull<<48); + return address; + } + void increment() { for (unsigned i = D - 1; i >= 0; --i) {