From owner-freebsd-hackers Tue Dec 8 01:24:30 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id BAA04224 for freebsd-hackers-outgoing; Tue, 8 Dec 1998 01:24:30 -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 BAA04217 for ; Tue, 8 Dec 1998 01:24:25 -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 JAA09822; Tue, 8 Dec 1998 09:24:30 GMT Date: Tue, 8 Dec 1998 09:24:30 +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 Mon, 7 Dec 1998, zhihuizhang wrote: > > 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. The '.set' directive is setting the address of kstack to USRSTACK. In C, you can declare kstack in various different ways. One way is: char kstack; ... p = &kstack; /* p == USRSTACK */ another is: char kstack[]; ... p = &kstack[0]; /* p == USRSTACK */ The assembly language symbol for a global array or a global char (or anything) is the address where the array or char is to be stored. -- 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