How to read S12X Program counter and XGPC?

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

How to read S12X Program counter and XGPC?

1,975 Views
Xbot
Contributor II
Hi all,
 
I am implementing a code that would copy all the necessary register values to the NVM when an access violation occur then followed by a COP reset. The registers include the Global clock, gpage, and PC.
 
My question is how do i read the s12x PC? is executing firmware command the only way? also, is this true for XGPC?
 
thnx,
Labels (1)
0 Kudos
Reply
2 Replies

988 Views
MJW
NXP Employee
NXP Employee
Hello,

reading the current PC from the S12X CPU can be done (using "bsr" for example). But in the case of an access violation, this is probably not that useful since it points to whatever instruction the CPU executes next. This means that after an access violation occurred, the PC points to code from the MPU ISR, but not the code where the access violation actually occurred.

To know where the access violation originated, one needs to read the return-address from the exception stack-frame which has been generated on entry to the MPU ISR. However, the address from the stack-frame does not point to the exact place where the access violation occurred. It contains the PC of the instruction after the point where the problem occcured (or, in some circumstances, even the PC after the next one). Together with the status address from the MPU, this is a starting point for debugging (i.e. disassemble the code before the Return-PC to identify the correct instruction).

MJW

0 Kudos
Reply

988 Views
Xbot
Contributor II
hi,
 
thank you for the very excellent explaination.
 
By the way, what does the "bsr" return after i execute it? I am by theway, using ansi C. probably i'll just use -- asm("bsr");
 
thnx,
0 Kudos
Reply