Page 1 of 1
Access physical memory with paging
Posted: Fri Jul 13, 2007 11:30 am
by liquid.silver
How do you access physical memory with paging enabled?
I know how paging works and I do have it working already, but I need to change a page structure and to change it, it must be mapped into somewhere, but I can only map anything if I can change the page structure... See my problem?
I only need to access the page structure temporarily, but many threads may be doing it at the same time too, so any solution?
Mapping
Posted: Fri Jul 13, 2007 12:04 pm
by Mark139
A really neat way to do this is to map the page directory to itself at the top of memory. I can't remeber the full details, but it's discussed in the forum in a few places.
You loose a little virtual memory space and it may drive you a little crazy thinking about it, but once setup it's an elegant solution
Posted: Fri Jul 13, 2007 12:12 pm
by liquid.silver
Where would I map it? I don't want to map it to the beginning of each page cause I want memory overlapping borders of pages to be continuous.
But thanx, the principle has definitely given me a few ideas.
Posted: Fri Jul 13, 2007 12:46 pm
by frank
The way that most people access the page directory and the page tables is to map the last page directory entry to the page directory (so that the CPU thinks that the page directory is also the page table for the last 4mb of address space. That way you can access all of the page tables and the page directory from the last 4mb of space.
0xFFC00000 - 0xFFFFEFFF = the page tables
0xFFFFF000 - 0xFFFFFFFF = the page directory
Posted: Fri Jul 13, 2007 6:33 pm
by liquid.silver
frank wrote:The way that most people access the page directory and the page tables is to map the last page directory entry to the page directory (so that the CPU thinks that the page directory is also the page table for the last 4mb of address space. That way you can access all of the page tables and the page directory from the last 4mb of space.
0xFFC00000 - 0xFFFFEFFF = the page tables
0xFFFFF000 - 0xFFFFFFFF = the page directory
Ah i think i see. Then you say "so that the CPU thinks...", I presume you mean to simplify the algorithm? Is that space not reserved for anything? I presume that 0xFFC00000 is the page table for virtual address 0x00000000?
Would the page directory be mapped into itself in the last PDE or what? It's quite late here and I've been drinking, so probably missing something... but could you please clarify. This method seems like a very good way of doing it though. Thanx
Posted: Fri Jul 13, 2007 8:55 pm
by frank
liquid.silver wrote:
Ah i think i see. Then you say "so that the CPU thinks...", I presume you mean to simplify the algorithm? Is that space not reserved for anything? I presume that 0xFFC00000 is the page table for virtual address 0x00000000?
Yes 0xFFC00000 is the page table entry for virtual address 0 and 0xFFC00004 is the page table entry for virtual address 0x1000 and so on.
liquid.silver wrote:
Would the page directory be mapped into itself in the last PDE or what? It's quite late here and I've been drinking, so probably missing something... but could you please clarify. This method seems like a very good way of doing it though. Thanx
Yes. That's exactly right.
Posted: Fri Jul 13, 2007 11:46 pm
by liquid.silver
Okay got it. Thanx.
Off to implement it...