Date: Tue, 8 Dec 1998 09:24:30 +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.9812080919551.448-100000@herring.nlsystems.com> In-Reply-To: <Pine.SOL.L3.93.981207205130.10107A-100000@bingsun1>
next in thread | previous in thread | raw e-mail | index | archive | help
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.4.01.9812080919551.448-100000>