- PMM uses bitmap allocator
- I have a higher half kernel; first four MB is identity mapped for kernel
Further I have the following algorithm for mapping a page:
- Get address to page directory
- Get free physical page for page table
- Create a new page directory entry with the physical page (index vaddr >> 22)
- Get address to page table (by OR'ing 0xFFC00000 with ((vaddr >> 22) << 12))
- Get free physical page for page table entry
- Create new page table entry (index vaddr >> 12) with the physical page
- Flush TLB wherever appropriate
This seems to work pretty well. Trying to modify a random address like 0x1234 page faults unless I map it first. However, I've run into a strange bug. Unless I add printf statements, my cr2 value shows ffc00004 (everytime); otherwise it shows the correct value. Example:
Code: Select all
pmm.map(0x1234);
*((int*) 0x1234) = 4;
printf("test\n");
pmm.map(0x2234);
*((int*) 0x2234) = 6;
pmm.map(0x12234);
*((int*) 0x12234) = 8;
*((int*) 0x11234) = 9;
The printf is from a third party library and it calls putc on my terminal object which is global, so it is strange that it "resolves" the problem. Any ideas?