xv6 uses 3 level page table. The question is in pte value!
I'm printing a pagetable. And I keep noticing that my output's page table address
in the beginning (...87f49000) is different from the second line pte (...21fd1401).
I thought they sould be the same. Some say it is normal to have different pte value because os scheduling differs as time changes.
Am I missing something so that my page table turn out to be ugly? I just want the first two page table pte to be the same!
I was expecting an output like this (pte values are the same):
My code (It's not important.):
static int level = 0;
static int print_end = 0;
static uint64 vadd_lv0 = 0;
static uint64 vadd_lv1 = 0;
static uint64 vadd_lv2 = 0;
static pte_t pte = 0;
void vmprint(pagetable_t pagetable) {
if (level == 0){
printf("page table %p\n", pagetable);
print_end = 0;
pte = pagetable;
}
// iterate 512 PTEs
for (uint64 i = 0; i < 512; i++) {
uint64 va = 0;
switch(level){
case 0:
vadd_lv0 = i<<30;
va = vadd_lv0;
break;
case 1:
vadd_lv1 = i<<21;
va = vadd_lv0+vadd_lv1;
break;
case 2:
vadd_lv2 = i<<12;
va = vadd_lv0+vadd_lv1+vadd_lv2;
break;
}
pte_t t = pagetable[i];
if (t & PTE_V) {
uint64 pa = PTE2PA(t);
if (level==0 && i==255)
print_end = 1;
if (level != 0 && !print_end){
printf("|");
}else if (level!=0){
printf(" ");
}
for (int j = 0; j < (level-1)*4+3; j++) printf(" ");
printf("+-- %d: pte=%p va=%p pa=%p",i, t, va, pa);
printf((t&PTE_V)?" V":"");
printf((t&PTE_R)?" R":"");
printf((t&PTE_W)?" W":"");
printf((t&PTE_X)?" X":"");
printf((t&PTE_U)?" U":"");
printf((t&PTE_D)?" D":"");
printf("\n");
// PTE without any WRX bit set points to low-level page table
if ((t & (PTE_W|PTE_R|PTE_X)) == 0){
level++;
vmprint((pagetable_t)pa);
level--;
}
}
}
}
Shouldn't print the address store by the pte, but to print out the address of pte.