Re: Reading power PC MPC 8260 program counter (Next Instruction address)



On 13.2.11 12:21 , David Brown wrote:
On 13/02/11 06:54, Scott Wood wrote:
On 2011-02-08, rajesha<rajesha@xxxxxxxxxxxxx> wrote:
Hello

Please can somebody let me know how to read power PC 8260 program counte
usin
C program (Using asm directive)

Thanks
Rajesh

Here's a straightforward answer to your question, ignoring questions
about
why you want to do this, if you don't trust the compiler/linker's
notion of
the address you're running at (assuming GCC):

asm("bl 1f; 1: mflr %0" : "=r" (addr) : : "lr");

addr now contains the address of the mflr instruction.

-Scott

Be careful that this will lose whatever was in lr before these
instructions. That is unlikely to be a problem in situations where this
sort of code is necessary - you probably only need it at a stage in
booting when normal function calls are not yet possible.


No problem, he's telling to the compiler with the last "lr" that he's
clobbering the link register contents.

--

Tauno Voipio
tauno voipio (at) iki fi

.



Relevant Pages