Subject: Re: vtopte() problems
To: ycchang <ycchang@cirx.org>
From: Stephan Uphoff <ups@stups.com>
List: tech-kern
Date: 05/20/2003 14:48:56
You probably overlooked that PTE_BASE is of type (pt_entry_t *).

as such 

	 (PTE_BASE + i386_btop(va));
is equal to

	(pt_entry_t *)	( ((char *) PTE_BASE) +  sizeof(pt_entry_t) * i386_btop(va))


ycchang wrote:
> Hi all,
> 
> 
> I am a kernel newbie of NetBSD.When I am trying to trace the kernel code =
> of NetBSD, I have some problems about the definition of vtopte()
> 
> /* /usr/include/machine/pmap.h */
> line 462:
> static __inline pt_entry_t * __attribute__((__unused__))
> vtopte(vaddr_t va)
> {
> 
>         KASSERT(va < (PDSLOT_KERN << PDSHIFT));
> 
>         return (PTE_BASE + i386_btop(va));
> }
> =20
>  this inline funtion returns PTE_BASE + i386_btop(va) , where PTE_BASE =
> =3D 0xbfc00000 and
>   i386_btop(va) is defined as ((unsigned)(x) >> PGSHIFT). That is to say =
> it gets the VA of PTE=20
>   corresponding to a VA.=20
> 
>  But in pmap.h , the comments say
> 
> /
>  ....
>   when the pmap code wants to find the
>  * PTE for a virtual address, all it has to do is the following:
>  *
>  * address of PTE =3D (767 * 4MB) + (VA / NBPG) * sizeof(pt_entry_t)
>  *                =3D 0xbfc00000 + (VA / 4096) * 4
>  ....
> */
> 
> So , should vtopte() return PTE_BASE + i386_btop(va)*4?
> 
>        
>                                                                     
>                                    Regards,
>                                                              
>                                                ycchang
>