Hi, I found an exellent reference on understanding the Linux MM module, I am sure many of you will be knowing of it. Check out Bruce Perens' Understanding the linux virtual memory manager. Available free for download at http://kerneltrap.org/node/3790 I have never read it much hence am unable to reply to the original poster. Regards, On Mon, 28 Mar 2005 10:53:30 +0530, Thekkedath Gopakumar-agt026 <gopakumar.t@xxxxxxxxxxxx> wrote: > > From: kernelnewbies-bounce@xxxxxxxxxxxx > [mailto:kernelnewbies-bounce@xxxxxxxxxxxx]On Behalf Of P.F. Tsai > > >I have problems about converting virtual address into physical address and > >reverse. I supply a kernel function to grab cr3 value, but how do I READ > >the content from the address located by cr3 to load the GDT and access the > >entry in it ? > > CR3 register holds the physical address of current process's PGD. It is the > GDTR > register which holds the address of GDT. > > > >static unsigned long v2p(unsigned long va) > >{ > > pgd_t *pgd; > >pmd_t *pmd; > > pte_t *ptep, pte; > > struct page *page; > >unsigned long pa; > >pgd = pgd_offset(tsk->mm, va); /* what is tsk->mm */ > >pmd = pmd_offset(pgd,va); > >pte = pte_offset(pte,va); > >pte = *ptep; > >page = pte_page(pte); /* aha, we have the pa of the page */ > >pa = (pte_val(*ptep) & PTE_PHYS_MASK) | (va&(PAGE_SIZE-1); > >return pa; > >} > > The above function traverses the Page Directory and Page Table to get the > physical > address, but I do not know how safe it will be if you supply a non existant > address > to it. > > Linux kernel provides you with functions like virt_to_phys and friends to > convert > a kernel mode virtual address to physical address and vice versa. > > For your case, may be after you get the physical address of GDT from GDTR, > you can use 'ioremap' to get the mapped kernel mode virtual address and > access > GDTR entries with it. Do note that the code you are writing is extremely > prone to > corrupt the system (if you alter the GDT values). I am assuming that you > are > doing this for getting a better understanding of the system. > > > -- > Kernelnewbies: Help each other learn about the Linux kernel. > Archive: http://mail.nl.linux.org/kernelnewbies/ > FAQ: http://kernelnewbies.org/faq/ > > -- Devesh Agrawal ============== The program is absolutely right; therefore the computer must be wrong. ----------------- How an engineer writes a program: Start by debugging an empty file... ---------------------- Systems programmers are the high priests of a low cult. - R. S. Barton -- Kernelnewbies: Help each other learn about the Linux kernel. Archive: http://mail.nl.linux.org/kernelnewbies/ FAQ: http://kernelnewbies.org/faq/