johnsy2008 wrote:
I'm currently writing a memory manager for my OS and and have ran into a little trouble.(i followed 2 tutorials found
here and
here to set up paging and all went well! as far as i know....)
i read the tutorials and i think i understand........ but i have a few questions to make sure.
Those two tutorials are basically the same thing but regardless, It is good that you understand them. Paging is a more advanced concept. But before I go on I would like to point out that you should first write a physical memory manager before you write a virtual memory manager (paging). A physical memory manager just keeps track of the areas of physical memory that are either free or used. It doesn't actually access physical memory, it just keeps track of what it looks like. Start with
Memory_management and then see
Page_Frame_Allocation. Remember, a "page frame" is simply a chunk of memory of a predefined size (4kb is the default on x86 systems).
johnsy2008 wrote:
1) having setup paging in the above tutorials, is the kernel already paged?(as the tutorials page 4mb already and this is much bigger than my kernel) if not, does it need to be paged? and how do i do it?(I'm not asking for code, because i like a challenge but cant figure this out without a hint

so just a little guidance will help a lot).
Yes the kernel is paged. It appears in virtual memory at the same place that it actually is located in physical memory (grammar check?). This is called "Identity Mapping".
johnsy2008 wrote:
2) how can i go about allocating memory? at the moment i can find an empty page and mark it as used, but where do i go from here? having read several tutorials, they say to return the address of the page. how do i do this and what should i do from there? the whole virtual to physical memory mapping is making my head go into overdrive!
Your physical memory manager should be able to return a number to you that represents the starting address of a free piece of physical memory (henceforth referred to as a "page frame"). You then put that number into an index in the page table depending on which virtual page frame you would like to be translated to the physical page frame that your physical memory manager returned.
For example:
Let's say that your kernel needs to have a place to store dynamic data (it probably will sooner or later). For simplicity, you have set aside the memory from 0x10000000 to 0x1000FFFF (or whatever you choose) as the area where you will store this dynamic data. First you ask your physical memory manager for a number representing a free piece of physical memory:
Code: Select all
phys_address = phys_alloc(size_of_memory_needed);
You then tell you virtual memory manager that all memory access to the page frame at 0x10000000 should be translated to the physical page frame that we just found.
Code: Select all
virt_address = 0x10000000;
page_map(virt_address, phys_address);
Now it's your job to fill in those functions.
