mirror of
https://github.com/wichtounet/thor-os.git
synced 2025-09-15 15:37:51 -04:00
Fix paging
This commit is contained in:
parent
82d577594d
commit
35f55cdbfa
@ -223,6 +223,7 @@ ACPI_PHYSICAL_ADDRESS AcpiOsGetRootPointer(){
|
|||||||
ACPI_PHYSICAL_ADDRESS root_pointer;
|
ACPI_PHYSICAL_ADDRESS root_pointer;
|
||||||
root_pointer = 0;
|
root_pointer = 0;
|
||||||
AcpiFindRootPointer(&root_pointer);
|
AcpiFindRootPointer(&root_pointer);
|
||||||
|
logging::logf(logging::log_level::TRACE, "acpica: Root pointer at physical address %h\n", size_t(root_pointer));
|
||||||
return root_pointer;
|
return root_pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -232,34 +233,40 @@ ACPI_PHYSICAL_ADDRESS AcpiOsGetRootPointer(){
|
|||||||
* \brief Map physical memory to a virtual address
|
* \brief Map physical memory to a virtual address
|
||||||
*/
|
*/
|
||||||
void* AcpiOsMapMemory(ACPI_PHYSICAL_ADDRESS phys, ACPI_SIZE length){
|
void* AcpiOsMapMemory(ACPI_PHYSICAL_ADDRESS phys, ACPI_SIZE length){
|
||||||
size_t pages = (length + paging::PAGE_SIZE - 1) & ~(paging::PAGE_SIZE - 1);
|
auto offset = phys % paging::PAGE_SIZE;
|
||||||
|
|
||||||
auto virt = virtual_allocator::allocate(pages);
|
auto real_length = offset + length;
|
||||||
|
size_t pages = real_length / paging::PAGE_SIZE + (real_length % paging::PAGE_SIZE == 0 ? 0 : 1);
|
||||||
|
|
||||||
if(!virt){
|
auto virt_aligned = virtual_allocator::allocate(pages);
|
||||||
|
|
||||||
|
if(!virt_aligned){
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto phys_aligned = phys - (phys & ~(paging::PAGE_SIZE - 1));
|
auto phys_aligned = phys - offset;
|
||||||
|
|
||||||
if(!paging::map_pages(virt, phys_aligned, pages)){
|
if(!paging::map_pages(virt_aligned, phys_aligned, pages)){
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
return reinterpret_cast<void*>(virt + (phys & ~(paging::PAGE_SIZE - 1)));
|
return reinterpret_cast<void*>(virt_aligned + offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Unmap physical memory from a virtual address
|
* \brief Unmap physical memory from a virtual address
|
||||||
*/
|
*/
|
||||||
void AcpiOsUnmapMemory(void* virt_aligned_raw, ACPI_SIZE length){
|
void AcpiOsUnmapMemory(void* virt_raw, ACPI_SIZE length){
|
||||||
size_t pages = (length + paging::PAGE_SIZE - 1) & ~(paging::PAGE_SIZE - 1);
|
auto virt = reinterpret_cast<size_t>(virt_raw);
|
||||||
|
|
||||||
auto virt_aligned = reinterpret_cast<size_t>(virt_aligned_raw);
|
auto offset = virt % paging::PAGE_SIZE;
|
||||||
auto virt = virt_aligned - (virt_aligned & ~(paging::PAGE_SIZE - 1));
|
auto real_length = offset + length;
|
||||||
|
size_t pages = real_length / paging::PAGE_SIZE + (real_length % paging::PAGE_SIZE == 0 ? 0 : 1);
|
||||||
|
|
||||||
paging::unmap_pages(virt, pages);
|
auto virt_aligned = virt - offset;
|
||||||
virtual_allocator::free(virt, pages);
|
|
||||||
|
paging::unmap_pages(virt_aligned, pages);
|
||||||
|
virtual_allocator::free(virt_aligned, pages);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Concurrency
|
// Concurrency
|
||||||
|
Loading…
x
Reference in New Issue
Block a user