From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1O72O4-0001iK-AW for qemu-devel@nongnu.org; Wed, 28 Apr 2010 04:12:52 -0400 Received: from [140.186.70.92] (port=57672 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1O72O0-0001hJ-Qd for qemu-devel@nongnu.org; Wed, 28 Apr 2010 04:12:50 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1O72Nz-0003Ot-Ds for qemu-devel@nongnu.org; Wed, 28 Apr 2010 04:12:48 -0400 Received: from goliath.siemens.de ([192.35.17.28]:23810) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1O72Nz-0003OU-1D for qemu-devel@nongnu.org; Wed, 28 Apr 2010 04:12:47 -0400 Message-ID: <4BD7EDFA.9010102@siemens.com> Date: Wed, 28 Apr 2010 10:12:42 +0200 From: Jan Kiszka MIME-Version: 1.0 References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit 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: > 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. Jan -- Siemens AG, Corporate Technology, CT T DE IT 1 Corporate Competence Center Embedded Linux