Re: Virtual Memory manager
Posted: Mon Nov 05, 2018 5:12 pm
I think I understood somewhat.
Now, the implementation for me can actually be a problem, because of how i've set it up before. Sorry if I didn't explain it well. I clarify my intentions, so you can help me better, if you want. I want to enable 4KB paging, not 4MB. I guess I copied the code for BootPageDirectory without a really understanding of what it does. I've managed something, but I cannot get that well. I mean, I got that but I can't change that to use 4KB pages. Here you are the mess I did:
I will then delete this page directory as the tutorial I followed suggested:
Said this, I want to talk about PAE a little. I'd like to activate PAE to make virtual space larger, and maybe expandable to 64 bit one day. But I read that I should change my target, from i686 to... what? It isn't x86_64 nor x86 (at this point)! Then should I change something in the bootloader, the GDT (the most likely) or the PMM I already set up? Is the VGA memory always at 0xC00B8000 (with the kernel's offset being at 0xC00000000)?
Now, the implementation for me can actually be a problem, because of how i've set it up before. Sorry if I didn't explain it well. I clarify my intentions, so you can help me better, if you want. I want to enable 4KB paging, not 4MB. I guess I copied the code for BootPageDirectory without a really understanding of what it does. I've managed something, but I cannot get that well. I mean, I got that but I can't change that to use 4KB pages. Here you are the mess I did:
Code: Select all
.set KERNEL_PAGE_NUMBER, bffffc00 # maybe (0xC00000000 >> 12) could be right?
BootPageDirectory:
.fill 0x4000, 4, 0x3 # identity map first 1MB
.fill KERNEL_PAGE_NUMBER - 1, 4, 0
.fill 0x4000, 4, 0x3 # identity map kernel's 1MB
.fill 0x400 - KERNEL_PAGE_NUMBER - 1, 4, 0 # Here idk what to do
Code: Select all
movl $0, (BootPageDirectory)
invlpg (0)
Yeah... hmm. The higher half should be there, but I think that if I enable PAE, I can theoretically move the kernel offset at more than 3GB, no? Otherwise I can map an entire page table to it and expect to not overflow, I guess. And well, the processes should get as much space as they can, I think.eryjus wrote: Virtual memory layout map
There is no coding involved here. This is the part of OS development which becomes a research project. Put pencil to paper and come up with an overall virtual memory layout design. This will have nothing to do with the physical memory -- at least not once you have completed initialization. You sound like you want your kernel to live in the upper virtual memory address space. That's fine. What is the address range? This also implies that the user code will live in the lower range. What is that range? Keep in mind that this is a plan and each process can have the same address range if they have different paging tables because they can have different cr3 values which will be replaced on a task swap. Let that sink in... it is a key concept.
This virtual memory map will become part of your OS plan. Take the time to document it and put is some place you can refer to it regularly. You will do so while you build out your kernel and get the rest of the system.
The only difference between this and the PMM is that this returns an already mapped pointer? Can those (malloc() and free()) functions be system calls?eryjus wrote: Kernel Heap
Yes, like any other program, your kernel will occasionally need to malloc() some memory. This will also be somewhere in your kernel space. You will start with a small amount at boot and then add more as you need it by calling your AllocFrame() function to get some physical memory and then your recursive mapping setup to add the page into the proper location of the proper Page Table. You will need to write a heap manager for this. Of course, you do not want to leak memory so you will need a free() function as well.