AnsweredAssumed Answered

Accessing MSR when switched to PSR

Question asked by o.l.001 on Mar 17, 2014
Latest reply on Mar 22, 2014 by o.l.001

AREA StackSwitch, CODE, READONLY

 

IMPORT PrintHex

EXPORT Start

EXPORT Reset_Handler

stack_base DCD 0x28000

 

THUMB

PRESERVE8

 

ENTRY

Reset_Handler

Start

MOV r0, #0xf00d

PUSH {r0}

MOV r0, #0

BL Mode_Switch

POP {r0}

BL PrintHex ; TASK 1: Fix the program so that this prints 0xf00d

; ** by only making changes inside Mode_Switch

; and ensuring that you are still in process

; mode when you

; get here **  B Finish

 

 

Mode_Switch

MOV r0, #0x2 ; set stack to PSP

MSR CONTROL, r0 ; do it

ISB ; wait for it to be done

 

BX lr ; and return safely

 

; ================

; End your program

; ================

Finish

 

B Finish

 

END ; Mark end of file

 

 

Hi, I'm currently learning how to use the ARM STM32F4 Discovery board and I've come across a problem I'm not sure how to solve. The code above doesn't actually do what is expected since we switch stacks and then POP r0 (from the wrong stack) which isn't what we want.

I cannot switch back to the stack like in MODE_SWITCH and I don't want to copy the value into a register before I make the switch to the other stack. How do I use MSR or MRS (presuming I am in privileged mode at this point) to get r0 from the other register so I can pop the correct value?

I've spent a while looking through the documentation and experimenting but I can't seem to get it work.

thanks!

Outcomes