mirror of
https://github.com/wichtounet/thor-os.git
synced 2025-09-15 15:37:51 -04:00
Make better use of paging::pages
This commit is contained in:
parent
7b6eb8c049
commit
625f062f22
@ -15,7 +15,7 @@ void* mmap_phys(size_t phys, size_t size){
|
|||||||
auto aligned_phys = phys - offset;
|
auto aligned_phys = phys - offset;
|
||||||
|
|
||||||
auto real_length = offset + size;
|
auto real_length = offset + size;
|
||||||
auto pages = real_length / paging::PAGE_SIZE + (real_length % paging::PAGE_SIZE == 0) ? 0 : 1;
|
auto pages = paging::pages(real_length);
|
||||||
|
|
||||||
// Allocate pages of virtual memory
|
// Allocate pages of virtual memory
|
||||||
|
|
||||||
@ -43,7 +43,7 @@ bool munmap_phys(void* virt_ptr, size_t size){
|
|||||||
auto aligned_virt = virt - offset;
|
auto aligned_virt = virt - offset;
|
||||||
|
|
||||||
auto real_length = offset + size;
|
auto real_length = offset + size;
|
||||||
auto pages = real_length / paging::PAGE_SIZE + (real_length % paging::PAGE_SIZE == 0) ? 0 : 1;
|
auto pages = paging::pages(real_length);
|
||||||
|
|
||||||
// Release the virtual memory
|
// Release the virtual memory
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ size_t array_size(size_t managed_space, size_t block){
|
|||||||
|
|
||||||
uint64_t* create_array(size_t managed_space, size_t block){
|
uint64_t* create_array(size_t managed_space, size_t block){
|
||||||
auto size = array_size(managed_space, block) * sizeof(uint64_t);
|
auto size = array_size(managed_space, block) * sizeof(uint64_t);
|
||||||
auto pages = size % paging::PAGE_SIZE == 0 ? size / paging::PAGE_SIZE : size / paging::PAGE_SIZE + 1;
|
auto pages = paging::pages(size);
|
||||||
|
|
||||||
auto physical_address = current_mmap_entry_position;
|
auto physical_address = current_mmap_entry_position;
|
||||||
|
|
||||||
|
@ -361,13 +361,7 @@ bool allocate_user_memory(scheduler::process_t& process, size_t address, size_t
|
|||||||
auto left_padding = address - first_page;
|
auto left_padding = address - first_page;
|
||||||
|
|
||||||
auto bytes = left_padding + size;
|
auto bytes = left_padding + size;
|
||||||
|
auto pages = paging::pages(bytes);
|
||||||
//Make sure only complete pages are allocated
|
|
||||||
if(bytes % paging::PAGE_SIZE != 0){
|
|
||||||
bytes += paging::PAGE_SIZE - (bytes % paging::PAGE_SIZE);
|
|
||||||
}
|
|
||||||
|
|
||||||
auto pages = bytes / paging::PAGE_SIZE;
|
|
||||||
|
|
||||||
//2. Get enough physical memory
|
//2. Get enough physical memory
|
||||||
auto physical_memory = physical_allocator::allocate(pages);
|
auto physical_memory = physical_allocator::allocate(pages);
|
||||||
|
@ -239,7 +239,7 @@ void* AcpiOsMapMemory(ACPI_PHYSICAL_ADDRESS phys, ACPI_SIZE length){
|
|||||||
auto offset = phys % paging::PAGE_SIZE;
|
auto offset = phys % paging::PAGE_SIZE;
|
||||||
|
|
||||||
auto real_length = offset + length;
|
auto real_length = offset + length;
|
||||||
size_t pages = real_length / paging::PAGE_SIZE + (real_length % paging::PAGE_SIZE == 0 ? 0 : 1);
|
auto pages = paging::pages(real_length);
|
||||||
|
|
||||||
auto virt_aligned = virtual_allocator::allocate(pages);
|
auto virt_aligned = virtual_allocator::allocate(pages);
|
||||||
|
|
||||||
@ -266,7 +266,7 @@ void AcpiOsUnmapMemory(void* virt_raw, ACPI_SIZE length){
|
|||||||
|
|
||||||
auto offset = virt % paging::PAGE_SIZE;
|
auto offset = virt % paging::PAGE_SIZE;
|
||||||
auto real_length = offset + length;
|
auto real_length = offset + length;
|
||||||
size_t pages = real_length / paging::PAGE_SIZE + (real_length % paging::PAGE_SIZE == 0 ? 0 : 1);
|
auto pages = paging::pages(real_length);
|
||||||
|
|
||||||
auto virt_aligned = virt - offset;
|
auto virt_aligned = virt - offset;
|
||||||
|
|
||||||
|
@ -59,12 +59,7 @@ bool vesa::init(){
|
|||||||
auto left_padding = static_cast<uintptr_t>(physical) - first_page;
|
auto left_padding = static_cast<uintptr_t>(physical) - first_page;
|
||||||
|
|
||||||
auto bytes = left_padding + total_size;
|
auto bytes = left_padding + total_size;
|
||||||
|
auto pages = paging::pages(bytes);
|
||||||
//Make sure only complete pages are allocated
|
|
||||||
if(bytes % paging::PAGE_SIZE != 0){
|
|
||||||
bytes += paging::PAGE_SIZE - (bytes % paging::PAGE_SIZE); }
|
|
||||||
|
|
||||||
auto pages = bytes / paging::PAGE_SIZE;
|
|
||||||
|
|
||||||
auto virt = virtual_allocator::allocate(pages);
|
auto virt = virtual_allocator::allocate(pages);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user