nullplan wrote:
WinExperements wrote:
Code:
void vmm_map(int *ptable,int phys,int virt) {
write_serialString("I got: ");
write_serialHex((int)ptable);
write_serialString("\r\n");
ptable[PAGE_TABLE_INDEX(virt)] = (phys) | 0x7;
// update pointer
}
That looks wrong because you have at the least two levels of page tables. Actually, with the types given here, it can only be 32-bit mode without PAE. So something closer to correct might be:
Code:
void vmm_map(uint32_t *ptable, uint32_t phys, uint32_t virt) {
ptable += virt >> 22;
if (!(*ptable & 1))
*ptable = page_zalloc_or_die() | 7;
ptable = (uint32_t*)(*ptable & 0xfffff000);
ptable[(virt >> 12) & 0x3ff] = phys | 7;
}
Still not great, but some crucial improvements: First of all, if you want all those variables to be 32-bit types, make them 32-bit types. "int" can be anything. Even better would be to make dedicated types for physical addresses, which reduces the amount of work you have to do if you ever support PAE.
I am assuming an identity paged system up there. If you do not have that, the line where we move from page directory to page table must be changed accordingly. The page directory only tells you the physical address, and how you map it such that you can access it is for you to know.
Future improvements: You may want to have this function be capable of returning error, so you don't need to panic if you are out of memory. As I said, some more specific types would be great. Maybe don't assume the attributes but get them from parameters (at least whether the actual page at the end is writable or supervisor-only ought to be in there).
I write something like you post, but still i receive the #PF, can be that i incorrectly allocated the page table?
And it's how i manually fill the page table:
Code:
for (int i = terminal_getBufferAddress(); i < (terminal_getBufferAddress()+terminal_getBufferSize())+4096; i+=4096) {
fr_pdir[PAGE_TABLE_INDEX(i)] = (i) | 7;
}
kdirectory[PAGE_DIRECTORY_INDEX(terminal_getBufferAddress())] = ((unsigned int)fr_pdir) | 7;
Defines and macroses used:
Code:
int fr_pdir[1024] __attribute__((aligned(4096))); // framebuffer
#define PAGE_DIRECTORY_INDEX(x) (((x) >> 22) & 0x3ff)
#define PAGE_TABLE_INDEX(x) (((x) >> 12) & 0x3ff)
EDIT: If i trying to use allocated page table and use it for manual filling it shows me the #PF, it seems like problem in my page allocator or no?