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

next in thread | previous in thread | raw e-mail | index | archive | help
On Sun, 6 Dec 1998, zhihuizhang wrote:

> 
> Hi, Back in August, I posted a question about whether .set _xx, 30 in
> assembly defines the value of xx or the address of xx (xx is the
> counterpart of _xx in C). The response I got is that the address of xx is
> 30. (note that xx without preceding "_" is used in C). 
> 
> So the address of PTDpde is PTD + (PTDI * PAGE_SIZE) (see locore.s).  This
> explains why the statement (unsigned)PTDpde & PG_FRAME gives the
> "physical" address of the page directory page of the current address
> space.  We often use the following condition in pmap.c to see if the given
> pmap uses the same page directory page as the curent address space. 
> 
>   if ((((unsigned)pmap->pm_pdir[PTDPTDI]) & PG_FRAME) ==
>                         (((unsigned) PTDpde) & PG_FRAME)) { ... }    
> 
> 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);   
> 
> So kstack must be a virtual address (I means its value).  However,
> according to my undestanding derived from PTDpde, the kstack should be
> stored at the fixed virtual address (VADDR(KSTKPTDI, KSTKPTE)), its value
> is another thing (should be initialized some where).  But the
> pmap_allocpte() statement clearly requires kstack's value and, I guess the
> kernel stack for each process should be at the same VA.  So, what does the
> following statement do (in locore.s): 
> 
>    .set    _kstack,USRSTACK (note: USRSTACK = VADDR(KSTKPTDI, KSTKPTEOFF))
> 
> Does it give the address of kstack or value of kstack?  The GAS only says
> it gives the value of the symbol.
> 
> I really have problem with mixed assembly and C programming when they
> reference the same symbols (one with the preceding "_" and one without
> "_").  I hope some one can clarify these stuff for me.
> 
> Thanks a lot.

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);

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

For the 3.0 line, the virtual address of the struct user is different for
each process which makes some things easier (debugging and probably SMP I 
guess) at the expense of using two pages of the kernel's virtual address
space per process.

--
Doug Rabson				Mail:  dfr@nlsystems.com
Nonlinear Systems Ltd.			Phone: +44 181 442 9037



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.BSF.4.01.9812071001400.448-100000>