From owner-freebsd-amd64@FreeBSD.ORG Mon Jun 25 23:25:19 2007 Return-Path: X-Original-To: freebsd-amd64@FreeBSD.org Delivered-To: freebsd-amd64@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 5D07816A421 for ; Mon, 25 Jun 2007 23:25:19 +0000 (UTC) (envelope-from jkim@FreeBSD.org) Received: from anuket.mj.niksun.com (gwnew.niksun.com [65.115.46.162]) by mx1.freebsd.org (Postfix) with ESMTP id 1532913C46E for ; Mon, 25 Jun 2007 23:25:18 +0000 (UTC) (envelope-from jkim@FreeBSD.org) Received: from niksun.com (anuket [10.70.0.5]) by anuket.mj.niksun.com (8.13.6/8.13.6) with ESMTP id l5PN72u2093084 for ; Mon, 25 Jun 2007 19:07:03 -0400 (EDT) (envelope-from jkim@FreeBSD.org) From: Jung-uk Kim (by way of Jung-uk Kim ) Date: Mon, 25 Jun 2007 19:06:53 -0400 User-Agent: KMail/1.6.2 To: freebsd-amd64@FreeBSD.org MIME-Version: 1.0 Content-Disposition: inline Content-Type: text/plain; charset="euc-kr" Content-Transfer-Encoding: 7bit Message-Id: <200706251906.55721.jkim@FreeBSD.org> X-Virus-Scanned: ClamAV 0.90.2/3523/Mon Jun 25 10:30:33 2007 on anuket.mj.niksun.com X-Virus-Status: Clean Cc: Subject: Re: The relation between %fs and fs base X-BeenThere: freebsd-amd64@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Porting FreeBSD to the AMD64 platform List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 25 Jun 2007 23:25:19 -0000 On Monday 25 June 2007 01:37 pm, jj shen wrote: > Hi, > > I want to access different TLS through both fs base and GDT > simultaneously. Let us call the two ways TLS_FSBASE and TLS_GDT > respectively. > > (1) Can I switch from TLS_FSBASE to TLS_GDT just by: "movl GDT_SEL, > %fs" (where GDT_SEL is the selector of GDT entry)? > Will this instruction destroy the content of the IA32_FS_BASE MSR? > > (2) When switching from TLS_GDT to TLS_FSBASE, can I just set %fs > to zero to indicate the fs base should be used, or must I invoke > the > *wrmsrl*instruction to reset IA32_FS_BASE once again? > > (3) What is the length of %fs? What I get by "movl %fs, %eax" in > %eax? In the programmer manual from AMD, it is said somewhere that > segment registers are still 16 bits as in x86, and it is also said > otherwhere that "segment loads into FS and GS load a standard > 32-bit base value in the hidden portion of the segment descriptor > register". > > (4) What is the content of %fs, a descriptor selector or a base > address smaller than 0xffffffff? > What is effect of "movl val, %fs", loading a GDT selector or a > 32-bit base address to %fs? > Seen from the citation above, I think *val *should be a 32-bit > base address; however seen from the implementation of Linux > *arch_prctl* system call, it is a GDT selector loaded into %fs. [Note: reposting to the right ML.] I don't know what you are trying to achieve but don't mess up with %fs and %gs on amd64 unless you are absolutely sure. It is deprecated and it won't work as you expected. The only way to get/set %fs and %gs properly on amd64 is via proper API, i.e., sysarch(2) with AMD64_{GET,SET}_{FS,GS}BASE. If you use the API, the MSRs will be properly saved and restored while switching contexts. However, it is very much discouraged as the manual page says, e. g., it will cause serious problem if the application is threaded, etc. In fact, the API should be only used by threading libraries. Jung-uk Kim