WinExperements wrote:Code: Select all
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: Select all
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).