From owner-freebsd-hackers Mon Dec 7 02:37:19 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id CAA13253 for freebsd-hackers-outgoing; Mon, 7 Dec 1998 02:37:19 -0800 (PST) (envelope-from owner-freebsd-hackers@FreeBSD.ORG) Received: from nlsystems.com (nlsys.demon.co.uk [158.152.125.33]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id CAA13248 for ; Mon, 7 Dec 1998 02:37:16 -0800 (PST) (envelope-from dfr@nlsystems.com) Received: from herring.nlsystems.com (herring.nlsystems.com [10.0.0.2]) by nlsystems.com (8.9.1/8.8.5) with SMTP id KAA06405; Mon, 7 Dec 1998 10:07:51 GMT Date: Mon, 7 Dec 1998 10:07:51 +0000 (GMT) From: Doug Rabson To: zhihuizhang cc: hackers Subject: Re: Definition of kstack and PTDpde in locore.s In-Reply-To: Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG 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