AnsweredAssumed Answered

'call' with page 0 is currently dangerous; how change default call page?

Question asked by Jacob Egner on Jun 23, 2011
Latest reply on Mar 11, 2013 by Radek Sestak

I am developing for the MC9S12XDT512 and I noticed some call/ppage behavior that seems to be dangerous in some cases.

 

I am using a banked memory model, so almost all functions are called using the 'call' instruction.  Unfortunately, it seems if the 'call' is to a function outside of the banked flash window (0x8000..0xbfff), then codewarrior generates 0x00 as the page operand of the 'call' instruction.  There is no flash page 0x00.  0xe0 is the lowest flash page.  So, if you call a subroutine in unbanked flash, you dangerously have ppage set to 0x00 and the banked flash window is invalid.

 

This is usually not a problem, but if your execution of code gets close to the banked flash window while ppage is 0x00, the PC register changes to a weird address, which means your program is broken.  I have done experiments that confirmed that the problem only occurs when ppage is set to an invalid value and when you are executing code within a few bytes of the flashed bank window.

 

How can I change the behavior of code generation for 'call' instructions so that ppage is never set to 0x00?

 

Thanks.

Outcomes