This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Change from the privileged mode to user mode

At the end of the start-up I would like to change from the privileged mode to user mode. I use the following code:
          mrs r0, CPSR      ; take a copy of the CPSR
          bic r0, r0, #0x1F ; clear the mode bits
          orr r0, r0, #0x10 ; select new mode
          msr CPSR_c, r0    ; write back the modified CPSR

As the last line is executed, I get a Data Abort Interrupt!

What happens with the stack pointer as I change the mode? In privileged mode the SP starts at 0x08001100, but in user mode at 0x08001000.

  • HI Daniel,

    We received your post.  I'll ask one of our experts on start-up/initialization to follow up with you.

  • Hi Daniel,

    There is a simpler way to change the processor's operating mode. Use the CPS (Change Processor State) instruction. For example, to change to user mode from a privileged mode,

    CPS #0x10

    This instruction executes in a single cycle versus the 5 cycles taken by the MSR (plus those taken for the complete read-modify sequence). This is also safer as it won't affect other bits in the CPSR which is possible using the read-modify-write sequence.

    As for the cause of the data abort, there is nothing in the above instruction sequence that would cause a data abort. Can you check the link register (R14_abt) contents while the CPU is in the abort handler?

    There is a separate stack pointer for each of the CPU modes with one exception: the System mode and the User mode use the same stack and hence the same stack pointer.

    Regards,

    Sunil

  • Hi Sunil

    I replaced my swap from privileged to user mode with:
      asm(" CPS #0x10");

    I get a data abort: R14_ABT = 0x0000BF18.

    Thanks Daniel

  • Hi Daniel,

    I would need to see the code at addresses 0xBF10 through 0xBF20 with explanation for where the code is trying to read from or write to. Only then can I discern the cause of the data abort.

    Regards, Sunil

  • Hi Daniel,

    I would need to see the code at addresses 0xBF10 through 0xBF20 with explanation for where the code is trying to read from or write to. Only then can I discern the cause of the data abort. You could also include a screen shot that shows the disassembly along with the source code near this address as well as the CPU registers.

    Regards, Sunil

  • This post is being closed for lack of information necessary to help with the debug. Please start a new thread if you are still having problems with the data abort.

    Regards, Sunil