How the OS sees paging?

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
Khaoticmind
Member
Member
Posts: 29
Joined: Tue Nov 18, 2008 1:06 pm
Location: Brazil

How the OS sees paging?

Post by Khaoticmind »

First of all, i've not tried yet to implement my paging code, but reading the intel manuals and thinking a bit i got one question:
How the OS sees the memory after paging is enabled?

I mean... if I've my OS loaded at 0x0000, and then I enable paging, do i have to reserve some pages in the page table, so that the page where is my kernel won't be override?

Also, how does memory access work after paging has been enabled? I ask this because on the intel manuals it reads:
When paging is used, the processor divides the linear address space into fixed-size pages (of 4 KBytes, 2 MBytes, or 4 MBytes in length) that can be mapped into physical
memory and/or disk storage. When a program (or task) references a logical address in memory, the processor translates the address into a linear address and then uses its paging mechanism to translate the linear address into a corresponding physical address.
So... paging only works for programs/tasks? Or all access by the OS go throu the MMU as well?
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Re: How the OS sees paging?

Post by neon »

The kernel itself runs in its own address space (Kind of. But for the purpose of this post Im going to say it is for simplicity) and can be seen as a "process" so yes, all accesses by the OS goes through the MMU as well. This is why idenitity mapping the memory of the current excution code before actually enabling paging is required.
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
User avatar
Khaoticmind
Member
Member
Posts: 29
Joined: Tue Nov 18, 2008 1:06 pm
Location: Brazil

Re: How the OS sees paging?

Post by Khaoticmind »

neon wrote:The kernel itself runs in its own address space (Kind of. But for the purpose of this post Im going to say it is for simplicity) and can be seen as a "process" so yes, all accesses by the OS goes through the MMU as well. This is why idenitity mapping the memory of the current excution code before actually enabling paging is required.
And by identity mapping you mean "knowing where the kernel is and save keeps this address from being used by any other process, also make sure to map the virtual address to the physical address used by the kernel", right? :)

Also, in the "kernel used space" you also have stuff like stack and heap right?

Also #2, i imagine that you can't page out the memory management part of the kernel, for obvious chicken-and-egg reasons. So some pages will always be in the ram, right?
CodeCat
Member
Member
Posts: 158
Joined: Tue Sep 23, 2008 1:45 pm
Location: Eindhoven, Netherlands

Re: How the OS sees paging?

Post by CodeCat »

Identity means self. So identity mapping means that virtual addresses are mapped to themselves, i.e. to the same physical address.
User avatar
neon
Member
Member
Posts: 1567
Joined: Sun Feb 18, 2007 7:28 pm
Contact:

Re: How the OS sees paging?

Post by neon »

And by identity mapping you mean "knowing where the kernel is and save keeps this address from being used by any other process, also make sure to map the virtual address to the physical address used by the kernel", right?
no and yes :) rather, the first part of your sentence is wrong, the second part is right.
Also, in the "kernel used space" you also have stuff like stack and heap right?
For the kernel, yes.
So some pages will always be in the ram, right?
Correct. You can even page out certain portians of the kernel itself just so long as the memory management is not, and should never be, paged out.
OS Development Series | Wiki | os | ncc
char c[2]={"\x90\xC3"};int main(){void(*f)()=(void(__cdecl*)(void))(void*)&c;f();}
jal
Member
Member
Posts: 1385
Joined: Wed Oct 31, 2007 9:09 am

Re: How the OS sees paging?

Post by jal »

neon wrote:You can even page out certain portians of the kernel itself just so long as the memory management is not, and should never be, paged out.
Well, if your page fault handler can restore the memory management code, no problem there. I'm not saying this makes sense though :).


JAL
Post Reply