Hello,
I need help figuring out how to record the current state of the processor registers so they can later be restored at the specific location in code. This will act like a warm reset but starting after initializing all my devices. Below are the functions used on the ARM9 processor. I need to do the same with the Cortext M7 processor. I am using Keilv5 with RTX5 RTOS in my project. Any examples or tips would be appreciated.
Will I also need to clear the stack?
//Record current state of processor registers. These registers can be restored at any
//time using the popcregs routine and should cause the program to the spot in code that
//the pushcregs was called.
__asm void pushcregs(PROC_STATE *regs)
{
STMIA R0!,{R0-R15} //save register values in data structure
STMDB SP!,{R0-R1} //Save R0 & R1 on stack
MRS R1,CPSR //move contents of CPSR to R1
STMIA R0!,{R1} //save PSR in data structure
MRS R1,SPSR //Move contents of saved PSR to R1
STMIA R0!,{R1} //save contents in data structure
LDMIA SP!,{R0-R1} //restore registers R0 & R1
BX LR //return
}
__asm void popcregs(PROC_STATE *regs)
{
LDR R1,[R0,#(17*4)] //point to end of data structure
MSR SPSR_c,R1 //restore SPSR
LDR R1,[R0,#(16*4)] //load CPSR into R1
MSR CPSR_c,R1 //restore CPSR
ADD R0,R0,#4 //do not restore PC
LDMIA R0!,{R1-R14} //restore R1 thru R14
BX LR //return to top of program
}