We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hi I am trying to reinitialize the sp and pc registers in my bootloader code (cortex m3) and I am getting a warning and a error from the code below. I have tried r13 and r15 as well and get the same errors.
I don't understand the warning at all. But the stack pointer should be a valid name.
Could someone please tell me what I am missing here?
Thanks
SoftBoot.cpp(108): warning: #1267-D: Implicit physical register R1 should be defined as a variable
SoftBoot.cpp(108): error: #20: identifier "sp" is undefined
void startboot(void) { __asm volatile ( "movs r1, #0x00 \n" "ldr sp, [r1,#0x00] ; Load new stack pointer address \n" "ldr pc, [r1,#0x04] ; Load new program counter address \n" ); }
Inline assembler, always a joy.. Avoid the stress and non-portability, put it in startup.s
Pretty sure loading PC directly is not kosher. Want to load into R0, then BX R0
Doing a little LMGTFY and Please read the manual yields
infocenter.arm.com/.../index.jsp
"The pc (r15), lr (r14), and sp (r13) registers cannot be accessed at all. An error message is generated when these registers are accessed."
Thank you for your response but not the rude Please read the manual.
I did research using Google and forums including this one all morning before posting the question here. The link you Googled for me does not apply to my scenario since I am not passing a parameter. The warning about R0 needing a variable declared before reading (I am writing first) does not apply either.
I have been able to use a table of assembly language instructions to implement/execute what I posted and was able to use LDR to set pc register without error. I wanted to get away from doing it that way and use the code I posted as it is easier to maintain.
If anyone else has an idea as to why the uVision compiler does not know what the sp register is in this context, I would appreciate your practical comments without being rude/insulting.
Not a fan of inline assembler, never have been, and always do the relatively small amount of assembly necessary for ARM in assembly language. Why not try it yourself? Assembly language can give you far more control over requirements such as this.
Thank you for the suggestion. I have already written a few critical sections in assembly including this one. I was just looking to take that assembly and making is a little more maintainable by including in with the C code.
Most people consider it more maintainable by separating assembler and C. Especially since the optimizer in the compiler will not leave inlined assembler as "don't touch" blocks but will mix and match and potentially rewrite the inlined assembler before producing the final code output.