enrico_granata wrote:maybe this is too stupid..
Nothing's too stupid
enrico_granata wrote:: cry :
Aww.. it's okay, we were all in this position once aswell.
enrico_granata wrote:
I would like to setup paging in such a way that all addresses that exist in physical memory reference themselves as linear addresses and all addressed beyond the end of physical memory cause a page fault
Is this possible? And if so, would it make my paging transparent (example, address 0xABCDEF goes to physical address 0xABCDEF if physical RAM is big enough, otherwise it just causes a page fault)?
What you need to do is the following:
Code: Select all
- Find out how much memory you have.
- Allocate 4kb somewhere in memory to story the page directory.
- Loop from 0 to the amount of memory you have in 4096 byte increments
- Is the current page table full? (Or does not one exist?)
- Yes
- Allocate 4kb in memory for the page table.
- Set the next position in the page directory to this table's location.
- Set the page directory entry bit for so the MMU knows it exists.
- Set the next page table entry to the location of the memory pointer (the one that is incrementing through the memory).
- Move the page directory's address to CR3.
- Set the paging bit in CR0 to true.
EDIT: In code tags so it doesn't mess up the formatting.
To link a 4kb memory address to an entry, use the following: (make sure entries, page table/directory locations are aligned to the nearest 4KB)
Where m_pageTable points to the area in memory where your page table exists (each entry it 4 bytes long, 1 int = 4 kbytes, so make it a pointer to an int). The "| 131" does a binary OR to enable bits 1 and 0 (meaning supervisor, r/w, present) of the entry.
In C/C++, to enable the paging bit of CR0 use:
Code: Select all
write_cr0(read_cr0() | 0x80000000);
In this example, write_cr0 sets the value of cr0 to the parameter in assembly, and read_cr0 returns the value of cr0.