max wrote:PatSanf wrote:I'm hoping that what I now have will meet all of the physical memory manager requirements that I need to implement before writing a virtual memory manager for paging. The only thing I think I might be iffy on is the assumption that I'll have at least 4MB of memory available immediately after the kernel. I'm guessing that this is a safe assumption to make. If it isn't, then I can correct it by looping over the memory map to find a guaranteed area large enough for the stack, or putting a line reading ". = . + 4M" in my linker script to eliminate the assumption (I think). What do you guys think of my assumption, possible solutions if it causes a problem, and code?
Don't assume. Read the memory map, exclude the area that your kernel needs and find a free space by doing so.
Here's what I've done.
I now have the stack being placed in the first free region of high memory, not occupied by the kernel, that's large enough.
What I do is:
* Figure out how much memory the system has, in MB. Use that to figure out how many 4KB chunks of memory I'll need to store addresses for (theoretical maximum).
* Go through each region of the memory map.
* If it's a free region in high memory
* Figure out where it starts and ends
* If the base address goes to a memory address that's occupied by the kernel, then advance it until isn't (on a copy so I don't overwrite the memory map).
* Advance the address to the next 4K aligned address.
* Make sure there's enough space for the stack in the region from that point, and if there is
* Put the stack in there.
To populate the stack I then:
* Go through each region of the memory map.
* If it's free, and if it's in high memory then
* Figure out where the first 4K aligned address in the free region is
* Make sure it isn't an address occupied by the stack, or the kernel
* Push it to the stack.
* Advance the counter by 4096, push it to the stack, and repeat until I've pushed all the addresses onto the stack.
You can see these changes here:
https://github.com/PSanf2/POS_C9/blob/m ... _manager.c
What's your opinion of that? Think it will serve my purposes?
max wrote:PatSanf wrote:I am getting curious about memory mapping. If I don't have the addresses that the kernel occupies on the stack will I be able to properly identity map the memory, or is that something I only need to worry about with a higher half kernel?
That does not matter. Read about paging and you'll find out.
Believe me, I have been.
What I'm mainly worried about is making sure the instruction pointer doesn't get screwed up. I read somewhere that you need to make sure the virtual memory address maps to the physical memory address for the kernel, or something relating to the instruction pointer will get messed up as soon as you enable paging and bugger the system.