Kernel memory management
Posted: Sat Apr 29, 2017 6:05 am
Hello forum, my kernel memory manager has some conceptical problems.
My kernel memory manager has 3 layers:
-> Firstly the physical memory manager. It manages free / used frames and it has two functions:
* uintptr_t alloc_frame()
* void free_frame(uintptr_t frame_address)
-> Then the virtual memory manager. It manages the virtual addresses, allocates and uses physical frames if needed. It has two functions:
* void map_memory(uint32_t* page_directory, uint32_t address, uint32_t size, bool rw, bool user)
* void unmap_memory(uint32_t* page_directory, uint32_t address, uint32_t size)
-> Then I have dynamic memory manager, uses virtual memory to allocate some data. It is a simple first fit heap allocator. It has four functions:
* void* kmalloc(size_t size)
* void* kvalloc(size_t size)
* void* kmemalign(uint32_t align, size_t size)
* void kfree(void* ptr)
Now where my conceptical problems in:
I need to allocate some memory to prepare kernel page directory and kernel page tables to initialize paging, but the memory allocator needs paging is already initialized as it uses virtual memory allocator.
More clearly, I need to use heap allocator to initialize and enable paging, but paging needs to be already enabled to use heap allocator.
It is like the chicken or egg problem.
I'm out of ideas.
Thanks in advance
My kernel memory manager has 3 layers:
-> Firstly the physical memory manager. It manages free / used frames and it has two functions:
* uintptr_t alloc_frame()
* void free_frame(uintptr_t frame_address)
-> Then the virtual memory manager. It manages the virtual addresses, allocates and uses physical frames if needed. It has two functions:
* void map_memory(uint32_t* page_directory, uint32_t address, uint32_t size, bool rw, bool user)
* void unmap_memory(uint32_t* page_directory, uint32_t address, uint32_t size)
-> Then I have dynamic memory manager, uses virtual memory to allocate some data. It is a simple first fit heap allocator. It has four functions:
* void* kmalloc(size_t size)
* void* kvalloc(size_t size)
* void* kmemalign(uint32_t align, size_t size)
* void kfree(void* ptr)
Now where my conceptical problems in:
I need to allocate some memory to prepare kernel page directory and kernel page tables to initialize paging, but the memory allocator needs paging is already initialized as it uses virtual memory allocator.
More clearly, I need to use heap allocator to initialize and enable paging, but paging needs to be already enabled to use heap allocator.
It is like the chicken or egg problem.
I'm out of ideas.
Thanks in advance