[boot] Fix a bug with address-index translation
When `page_entry_iterator` became a template and changed its static shifts translating virtual address to table indices into a for loop, that loop was getting the indices backwards (ie, PML4E index was really the PTE index, and so on). Tags: paging
This commit is contained in:
@@ -59,14 +59,14 @@ load(
|
||||
void *data_start = offset_ptr<void>(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<uintptr_t>(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<kernel::entrypoint>(header->entrypoint);
|
||||
}
|
||||
|
||||
|
||||
@@ -71,11 +71,20 @@ public:
|
||||
{
|
||||
m_table[0] = pml4;
|
||||
for (unsigned i = 0; i < D; ++i) {
|
||||
m_index[i] = static_cast<uint16_t>((virt >> (12 + 9*i)) & 0x1ff);
|
||||
m_index[i] = static_cast<uint16_t>((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<uintptr_t>(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) {
|
||||
|
||||
Reference in New Issue
Block a user