From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1O72ee-0001SY-Ul for qemu-devel@nongnu.org; Wed, 28 Apr 2010 04:30:01 -0400 Received: from [140.186.70.92] (port=50762 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1O72ec-0001RB-Ql for qemu-devel@nongnu.org; Wed, 28 Apr 2010 04:29:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1O72eW-0006VM-K2 for qemu-devel@nongnu.org; Wed, 28 Apr 2010 04:29:57 -0400 Received: from mail-iw0-f196.google.com ([209.85.223.196]:34644) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1O72eW-0006V4-7Q for qemu-devel@nongnu.org; Wed, 28 Apr 2010 04:29:52 -0400 Received: by iwn34 with SMTP id 34so10475956iwn.23 for ; Wed, 28 Apr 2010 01:29:51 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: <4BD7EDFA.9010102@siemens.com> References: <4BD7EDFA.9010102@siemens.com> From: Jun Koi Date: Wed, 28 Apr 2010 17:29:31 +0900 Message-ID: Content-Type: text/plain; charset=ISO-8859-1 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: Jan Kiszka Cc: qemu-devel@nongnu.org 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. This is so confused to me! Thanks, J