WiiRd forum

Wii & Gamecube Hacking => Wii Game hacking help => Topic started by: live2play on March 17, 2010, 06:10:59 PM

Title: Determine address of calling routine
Post by: live2play on March 17, 2010, 06:10:59 PM
I know that the CTR register holds the address of the instruction to execute on a bctrl, but how do you find the address of the instruction that called the routine you're currently in.  For instance, if I set an execute breakpoint at an address and it triggers, how do I determine the address of the instruction that executed the instruction at my breakpoint?
Title: Re: Determine address of calling routine
Post by: dcx2 on March 17, 2010, 07:20:52 PM
Look at the Link Register.  It connects you back to the caller.  Be careful if the Link Register was pushed onto the stack.

http://wiird.l0nk.org/forum/index.php/topic,5080.0.html (http://wiird.l0nk.org/forum/index.php/topic,5080.0.html)
Title: Re: Determine address of calling routine
Post by: live2play on March 17, 2010, 07:46:50 PM
Thanks for the link to the tutorial.  So, LR holds the address?
Title: Re: Determine address of calling routine
Post by: dcx2 on March 17, 2010, 08:04:29 PM
I go into great detail in the tutorial.  LR usually holds the address, but at the beginning and end of functions it can be pushed on the stack, because another function might over-write the LR.  Sometimes you need to find the beginning or end of the function you want to find the caller of, so you can see the LR before it goes on or after it comes off the stack.