From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1O74hs-00057C-Jy for qemu-devel@nongnu.org; Wed, 28 Apr 2010 06:41:28 -0400 Received: from [140.186.70.92] (port=36062 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1O74ho-00054m-1q for qemu-devel@nongnu.org; Wed, 28 Apr 2010 06:41:27 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1O74hj-0004Xt-SY for qemu-devel@nongnu.org; Wed, 28 Apr 2010 06:41:23 -0400 Received: from david.siemens.de ([192.35.17.14]:17706) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1O74hj-0004Wr-HZ for qemu-devel@nongnu.org; Wed, 28 Apr 2010 06:41:19 -0400 Message-ID: <4BD810CB.4060009@siemens.com> Date: Wed, 28 Apr 2010 12:41:15 +0200 From: Jan Kiszka MIME-Version: 1.0 References: <4BD7EDFA.9010102@siemens.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Subject: [Qemu-devel] Re: Question on implementatio of GETPC() List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Jun Koi Cc: "qemu-devel@nongnu.org" Jun Koi wrote: > On Wed, Apr 28, 2010 at 5:12 PM, Jan Kiszka wrote: >> Jun Koi wrote: >>> Hi, >>> >>> In x86, GETPC() is implemented as below: >>> >>> # define GETPC() ((void *)((unsigned long)__builtin_return_address(0) - 1)) >>> >>> As I understand, it gets the returned address on the stack, then >>> subtract 1 to get back to the above address. >>> >>> Imagine we have code like this (pseudo asm code): >>> >>> .... >>> CALL >>> >>> .... >>> >>> When we call GETPC, we get the address of , and subtract 1. >>> But the problem is that the CALL insn is more than 1 byte, so how can >>> GETPC() gives us the address of the CALL insn above? >>> >>> I guess I must misunderstood something here .... >> IIRC, the result of GETPC is used for a range check. So you just have to >> ensure that it points somewhere into the translated code sequence of the >> current target instruction. >> > > Hmm if I am not wrong, the GETPC address is really used as jump target > of some code (such as when handling page fault), so that must be > accurate. That won't work. GETPC could - at best - point to a host instruction that raised the fault. But for proper fault handling, we need the guest instruction pointer. So QEMU does a reverse mapping of the host address, often via re-translating the code block as it may contain more than one guest instruction. Jan -- Siemens AG, Corporate Technology, CT T DE IT 1 Corporate Competence Center Embedded Linux