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
Kernel memory management
Kernel memory management
Keyboard not found!
Press F1 to run setup.
Press F2 to continue.
Press F1 to run setup.
Press F2 to continue.
Re: Kernel memory management
Use a low-level dumb allocator to cut-off a piece of boot memory and use that in initializing the page directory and other structures.
I just pass an address of memory region to the memory allocator and let it initialize there - since it knows how much space it has taken it can mark it as _Used_ afterwards.
I just pass an address of memory region to the memory allocator and let it initialize there - since it knows how much space it has taken it can mark it as _Used_ afterwards.
Learn to read.
- eryjus
- Member
- Posts: 286
- Joined: Fri Oct 21, 2011 9:47 pm
- Libera.chat IRC: eryjus
- Location: Tustin, CA USA
Re: Kernel memory management
You might consider doing your first initialization outside your routines at a common location for your kernel and then let initialize your 3 handlers to that state when you "put it in charge".
Adam
The name is fitting: Century Hobby OS -- At this rate, it's gonna take me that long!
Read about my mistakes and missteps with this iteration: Journal
"Sometimes things just don't make sense until you figure them out." -- Phil Stahlheber
The name is fitting: Century Hobby OS -- At this rate, it's gonna take me that long!
Read about my mistakes and missteps with this iteration: Journal
"Sometimes things just don't make sense until you figure them out." -- Phil Stahlheber
Re: Kernel memory management
You don't need to allocate memory, as such (i.e. using a memory allocator) for this purpose. Just mark some RAM pages as in use and use them.