简体   繁体   中英

Code execution in Stack in Cortex-M4

I am trying to copy code from code memory to stack and then use that code in stack for execution. I am using the following function

;Personal Function
IMPORT extfunc
EXPORT func
func
LDR R0,=extfunc;Function  in C 
LDR R1,=0x00000000;Counter for Counting instructions when i make code generic
PUSH {LR};For nested call       
ADD R3,SP,#0x00;move 
SUB SP,#0x10;As stack grows upwards, we just make space for 10 instructions for testing
ADD R5,SP,#0x0;Where we branch after copying
LOOP
LDR SP,[R0];Load in stack instruction
ADD R1,R1,#0x01;instruction count
ADD R0,#0x04;next C instruction address 
ADD SP,#0x04;next instruction address
CMP R1,#0x10;Copy 10 instructions
BLT LOOP
ADD R0,PC,#0x0C;Get ready for branching
ADD LR,R0,#0x00;LR prepared
ADD PC,R5,#0x00;GO
ADD SP,R3,#0x00;When we return restore the SP
POP {LR}
BX LR

but I get the following errors

startup_XMC4500.s(335): error: A1477E: This register combination results in UNPREDICTABLE behaviour

startup_XMC4500.s(336): error: A1477E: This register combination results in UNPREDICTABLE behaviour

Apparently you can't move PC to any arbitrary address calculated at run time, can anyone tell me a workaround to this problem?

事实证明,您不能通过添加具有某些值的寄存器并将其存储回去来操纵特殊寄存器,而必须使用显式加载或存储指令。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM