From owner-freebsd-emulation@FreeBSD.ORG Wed Oct 10 13:33:18 2007 Return-Path: Delivered-To: freebsd-emulation@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 333C216A46C for ; Wed, 10 Oct 2007 13:33:18 +0000 (UTC) (envelope-from tijl@ulyssis.org) Received: from thumbler.kulnet.kuleuven.ac.be (thumbler.kulnet.kuleuven.ac.be [134.58.240.45]) by mx1.freebsd.org (Postfix) with ESMTP id C00DC13C469 for ; Wed, 10 Oct 2007 13:33:17 +0000 (UTC) (envelope-from tijl@ulyssis.org) Received: from localhost (localhost [127.0.0.1]) by thumbler.kulnet.kuleuven.ac.be (Postfix) with ESMTP id 200E2139867; Wed, 10 Oct 2007 15:33:16 +0200 (CEST) Received: from smtps02.kuleuven.be (smtpshost02.kulnet.kuleuven.be [134.58.240.75]) by thumbler.kulnet.kuleuven.ac.be (Postfix) with ESMTP id 0717113879F; Wed, 10 Oct 2007 15:33:08 +0200 (CEST) Received: from kalimero.kotnet.org (kalimero.kotnet.org [10.4.16.222]) by smtps02.kuleuven.be (Postfix) with ESMTP id B7A99F3863; Wed, 10 Oct 2007 15:33:07 +0200 (CEST) Received: from kalimero.kotnet.org (kalimero.kotnet.org [127.0.0.1]) by kalimero.kotnet.org (8.14.1/8.14.1) with ESMTP id l9ADX7oP004744; Wed, 10 Oct 2007 15:33:07 +0200 (CEST) (envelope-from tijl@ulyssis.org) X-Kuleuven: This mail passed the K.U.Leuven mailcluster From: Tijl Coosemans To: Mihai =?utf-8?q?Don=C8=9Bu?= Date: Wed, 10 Oct 2007 15:33:05 +0200 User-Agent: KMail/1.9.7 References: <200710082135.58099.mihai.dontu@gmail.com> <200710081841.35968.jkim@FreeBSD.org> <200710090348.52036.mihai.dontu@gmail.com> In-Reply-To: <200710090348.52036.mihai.dontu@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Message-Id: <200710101533.06287.tijl@ulyssis.org> X-Virus-Scanned: by KULeuven Antivirus Cluster Cc: freebsd-emulation@freebsd.org, freebsd-questions@freebsd.org, Jung-uk Kim Subject: Re: amd64_set_gsbase() X-BeenThere: freebsd-emulation@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Development of Emulators of other operating systems List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 10 Oct 2007 13:33:18 -0000 On Tuesday 09 October 2007 02:48:51 Mihai Don=C8=9Bu wrote: > I have *one* more question: maybe I don't fully understand the hole > BASE thing, but since the FreeBSD kernel does not preserve %gs and > %fs, what is the purpose of amd64_set_XXbase()? The %fs, %gs registers and fsbase and gsbase MSRs are separate registers. When you write %gs:offset, you actually get (gsbase+offset), so the actual value of %gs doesn't matter. There are two ways to set gsbase. One is by using the privileged instruction wrmsr to set gsbase directly (full 64bit base address), which is what amd64_set_gsbase() exposes to userland. The other is by loading a descriptor selector in %gs in which case gsbase will be set to the base address (only 32bit base address) of a descriptor entry in either the GDT or LDT. To get back to what you are trying to do, because %gs isn't preserved, I think you should avoid writing to it and instead strictly use amd64_set_gsbase(). But from what you've written, I'm guessing you're already doing this, so the next thing to try is to create threads with PTHREAD_SCOPE_SYSTEM or use libthr instead of libpthread, because if I'm not mistaken, PTHREAD_SCOPE_PROCESS in libpthread doesn't preserve gsbase either.