qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] Re: Question on implementatio of GETPC()


From: Jan Kiszka
Subject: [Qemu-devel] Re: Question on implementatio of GETPC()
Date: Wed, 28 Apr 2010 12:41:15 +0200
User-agent: Mozilla/5.0 (X11; U; Linux i686 (x86_64); de; rv:1.8.1.12) Gecko/20080226 SUSE/2.0.0.12-1.1 Thunderbird/2.0.0.12 Mnenhy/0.7.5.666

Jun Koi wrote:
> On Wed, Apr 28, 2010 at 5:12 PM, Jan Kiszka <address@hidden> 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 <relative address>
>>> <next-insn>
>>> ....
>>>
>>> When we call GETPC, we get the address of <next-insn>, 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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]