Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 7 Dec 1998 21:33:55 -0500 (EST)
From:      zhihuizhang <bf20761@binghamton.edu>
To:        Doug Rabson <dfr@nlsystems.com>
Cc:        hackers <freebsd-hackers@FreeBSD.ORG>
Subject:   Re: Definition of kstack and PTDpde in locore.s
Message-ID:  <Pine.SOL.L3.93.981207205130.10107A-100000@bingsun1>
In-Reply-To: <Pine.BSF.4.01.9812071001400.448-100000@herring.nlsystems.com>

next in thread | previous in thread | raw e-mail | index | archive | help

On Mon, 7 Dec 1998, Doug Rabson wrote:

> > So far, it is fine for me.  Yesterday, I came across the symbol kstack
> > which is defined similary via the .set directive in locore.s.  However, in
> > pmap.c, I find the following usage:
> > 
> >  m = pmap_allocpte(pmap, (vm_offset_t) kstack);   
> > 

> Is this in the 2.2 source tree?  We used to put the kernel stack of all
> processes at the same virtual address (traditionally the struct user for
> each process which includes the stack was always mapped in the same 
> place and could be accessed using the global variable 'u').  I think 
> that with the definition: 
> 
> .set _kstack, USRSTACK 
> 
> then from C,you could have:  
> 
> extern char kstack[];  
> 
> assert(&kstack[0] == (char*)USRSTACK);  
> 

This seems to me that the VALUE of kstack (which is a fixed address in
user virtual address space) is USRSTACK.  But what is the address of
kstack, i.e., where is kstack itself stored?

> i.e. to find the top of the kernel stack, take the address of kstack.  
>

Yes.  I am looking into the 2.2.x source code.  The KVA for UPAGES of each
process is different, each consuming UPAGES of KVA.  This explains why the
size of u_map is set to be maxproc * UPAGES * page_size. (u_map is a
submap of kern_map). These U areas at the same time also occupy the same
size of VA in its process's virtual adderss space.  I guess this double
mapping of U pages is for (1) allow kernel access to the U pages of all
active processes at any time; (2) No need to  save and restore address
mapping information during a context switch.

While these topics are not easy to understand, my question is really a
simpler one - a question of mixed GAS (assembly) and C programming.

If the virtual address of the kernel stack in each process's address space
(not in kernel) is the same as USRSTACK.  Then according to the usage of
pmap_allocpte()  above, the value of kstack should be USRSTACK, not its
address. 

But you said that PTDpde's address (not its value) is defined by .set
directive in locore.s.  This expains why (unsigned) PTDpde & PG_FRAME
gives the physical address of the page directory page. So the address of
kstack must be USRSTACK (not its value), since they are defined in the
SAME way.   Could you please explain this discrepancy for me?

Thanks very much for your help.









To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.SOL.L3.93.981207205130.10107A-100000>