mirror of
https://github.com/wichtounet/thor-os.git
synced 2025-09-17 16:51:33 -04:00
Finalize buddy system for physical allocator
This commit is contained in:
parent
c207fc8892
commit
da9f0470ee
@ -36,12 +36,13 @@ 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 physical_address = current_mmap_entry_position;
|
auto physical_address = current_mmap_entry_position;
|
||||||
|
|
||||||
allocated_memory += size;
|
allocated_memory += pages * paging::PAGE_SIZE;
|
||||||
current_mmap_entry_position += size;
|
current_mmap_entry_position += pages * paging::PAGE_SIZE;
|
||||||
|
|
||||||
auto pages = size / paging::PAGE_SIZE + 1;
|
|
||||||
auto virtual_address = virtual_allocator::allocate(pages);
|
auto virtual_address = virtual_allocator::allocate(pages);
|
||||||
|
|
||||||
thor_assert(paging::map_pages(virtual_address, physical_address, pages), "Impossible to map pages for the physical allocator");
|
thor_assert(paging::map_pages(virtual_address, physical_address, pages), "Impossible to map pages for the physical allocator");
|
||||||
@ -93,6 +94,12 @@ void physical_allocator::init(){
|
|||||||
auto size = current_mmap_entry->size;
|
auto size = current_mmap_entry->size;
|
||||||
auto managed_space = size - (current_mmap_entry_position - current_mmap_entry->base);
|
auto managed_space = size - (current_mmap_entry_position - current_mmap_entry->base);
|
||||||
|
|
||||||
|
//Make sure to start with an aligned address
|
||||||
|
if((current_mmap_entry_position % paging::PAGE_SIZE) != 0){
|
||||||
|
allocated_memory += current_mmap_entry_position % paging::PAGE_SIZE;
|
||||||
|
current_mmap_entry_position = current_mmap_entry_position + current_mmap_entry_position % paging::PAGE_SIZE;
|
||||||
|
}
|
||||||
|
|
||||||
auto data_bitmap_1 = create_array(managed_space, 1);
|
auto data_bitmap_1 = create_array(managed_space, 1);
|
||||||
auto data_bitmap_2 = create_array(managed_space, 2);
|
auto data_bitmap_2 = create_array(managed_space, 2);
|
||||||
auto data_bitmap_4 = create_array(managed_space, 4);
|
auto data_bitmap_4 = create_array(managed_space, 4);
|
||||||
@ -116,6 +123,8 @@ void physical_allocator::init(){
|
|||||||
allocator.init<6>(array_size(managed_space, 64), data_bitmap_64);
|
allocator.init<6>(array_size(managed_space, 64), data_bitmap_64);
|
||||||
allocator.init<7>(array_size(managed_space, 128), data_bitmap_128);
|
allocator.init<7>(array_size(managed_space, 128), data_bitmap_128);
|
||||||
|
|
||||||
|
allocator.init();
|
||||||
|
|
||||||
//TODO The current system uses more memory than necessary,
|
//TODO The current system uses more memory than necessary,
|
||||||
//because it also tries to index memory that is used for the
|
//because it also tries to index memory that is used for the
|
||||||
//buddy system.
|
//buddy system.
|
||||||
@ -128,7 +137,11 @@ size_t physical_allocator::allocate(size_t blocks){
|
|||||||
|
|
||||||
allocated_memory += buddy_type::level_size(blocks) * unit;
|
allocated_memory += buddy_type::level_size(blocks) * unit;
|
||||||
|
|
||||||
return allocator.allocate(blocks);
|
auto block = allocator.allocate(blocks);
|
||||||
|
|
||||||
|
k_print_line(block);
|
||||||
|
|
||||||
|
return block;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t physical_allocator::available(){
|
size_t physical_allocator::available(){
|
||||||
|
Loading…
x
Reference in New Issue
Block a user