I need to get the value of PGD and its contents. I was able to get the address of PGD from CR3 register but I am not able to print the entries in PGD. Please look at my code and help me out.
unsigned int *memptr,mem1,*mem2ptr,i=255;
asm volatile ("\tmovl %%cr3, %%eax\n\t"
"movl %%eax, %0\n\t"
printk(KERN_INFO "\nvalue of cr3: %x",mem1);
memptr=(void *)mem1; //cr3 value in memptr
mem2ptr=&i; //mem2ptr given an address(known)
printk(KERN_INFO "\nCR3 value is %x\n",memptr);
printk(KERN_INFO "\nEntry 0 in CR3:%x",*memptr);
printk(KERN_INFO "\nValue of i:%d\n",i);
printk(KERN_INFO "Entry in 0th entry of pgd:%x",*mem2ptr);
printk(KERN_INFO "Value of i:%x",i);
From the code above, I am able to print 'memptr' which is the address of PDG (content of CR3), but I am not able to print the value of *memptr(0th entry of PGD). Please help me out how I can do it.
Also that, the line "memcpy(em2ptr,memptr,4) doesn't work. I have no idea why it is not working.
For both the problems above, I guess I am not able to access the address of CR3 and print its contents. But again, I'm not sure what's wrong. Please let me know. Thanks in advance.