Modifying ISR return address ? (Cortex M0)

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Modifying ISR return address ? (Cortex M0)

1,901 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by ArneB on Fri May 18 04:38:57 MST 2012
How can I modify the return address of a Cortex M0 Interrupt Service Routine ?

I know, it's a very ugly and not recommended programming style (shame on me... ;)), nevertheless due to very tight timing and other special requirements in my application I would like to jump to a different program location and not to the originating program counter.
As far as I understand the ISR push its program counter (PC) onto the stack. After the ISR finishes, it pops it back to the PC. Does anybody know, how i can modify this sequence in LPCXpresso ?
0 Kudos
Reply
7 Replies

1,887 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Sat May 19 15:43:30 MST 2012

Quote: atomicdog
I believe you need to modify the Link register (LR).




Quote: atomicdog
I believe you need to modify the Link register (LR).



Yes :)

LR  is pushed on stack, so you can change it in ISR after reading SP and  adding 0x18 (of course before ISR is pushing registers on stack).  Writing back a new uint32 and function is returning to this address :eek:
0 Kudos
Reply

1,887 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by atomicdog on Sat May 19 15:05:33 MST 2012

Quote: ArneB
How can I modify the return address of a Cortex M0 Interrupt Service Routine ?

I know, it's a very ugly and not recommended programming style (shame on me... ;)), nevertheless due to very tight timing and other special requirements in my application I would like to jump to a different program location and not to the originating program counter.
As far as I understand the ISR push its program counter (PC) onto the stack. After the ISR finishes, it pops it back to the PC. Does anybody know, how i can modify this sequence in LPCXpresso ?

I believe you need to modify the Link register (LR).
0 Kudos
Reply

1,887 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by OXO on Sat May 19 04:31:59 MST 2012
+1

In over 30 years of embedded system design, I've never needed to do this.
0 Kudos
Reply

1,887 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by gbm on Fri May 18 11:54:31 MST 2012
If your main task is so unimportant that it may be aborted any time, maybe you don't need it at all ;).
I don't believe there is any real need for doing what you are planning to do. I would advise to rethink your design.
0 Kudos
Reply

1,887 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by ArneB on Fri May 18 09:13:28 MST 2012
@gbm: I know it is really a dirty hack (i have done it the last time with the 6510 CPU in my C64... *sigh* long time ago...), but i have a very unusual and non-standard application. And for this special case modifying the ISR return address is the best solution resulting in the best/needed performance - believe me... :)
0 Kudos
Reply

1,887 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by gbm on Fri May 18 08:55:02 MST 2012
Don't do that. Looks like you have some bad conceptual error in your program.
0 Kudos
Reply

1,887 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Fri May 18 06:21:21 MST 2012
Wild guess: SP - 0x18 (which means SP + 0x18, since it's counting down):eek:
0 Kudos
Reply