program counter access - control?

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

program counter access - control?

1,292 Views
eyupozer
Contributor III

Hi everyone,

I'm using MPC5746C MCU with S2 S32 Design Studio Version: 2017.R1 at my project.

I need to reach and control the program counter but I've not found any way to reach register address or any function related it.

Is it possible to manage the program counter from outside command?

PC could be seen in Register editor and It could be controlled there. But I want to control from the program, what is the PC variable name or structure address of General Register?

Thanks.

pastedImage_1.png

3 Replies

1,064 Views
martin_kovar
NXP Employee
NXP Employee

Hello,

because Program Counter is neither memory mapped register nor special purpose register, it is not possible to access it from application.

But you can use branch instruction instead of PC modification and this has the same effect.

Regards,

Martin

1,064 Views
eyupozer
Contributor III

Hello Martin,

Thanks for your quick support,

I used "e_bl" command set like that: __asm__("e_bl FunctionNameText");

this command is working properly but the e_bl command can be used only the function name text base.

I want to branch directly, a specific address in the memory and return again to the first branch point.

Is it possible? Which command set can be used for this?

0 Kudos

1,064 Views
martin_kovar
NXP Employee
NXP Employee

Hello,

instead of __asm__("e_bl FunctionNameText"); you can use following sequence:

Load address to register r6. Two instructions must be used, if you want load 32-bit address. Sequence below loads address 0x01001000 into r6 register.

asm("e_lis %r6, 0x100");
asm("e_or2i %r6, 0x1000");

Move address from r6 to link register. Link register is SPR8 register, so instruction mtspr is used.
asm("mtspr 8, %r6");

Last step is branch to link register. If you want return back, use se_blrl or se_blr in case you do not want to branch back.
asm("se_blrl");

Regards,

Martin