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.

How to enterd Privileged Mode ?

Other Parts Discussed in Thread: HALCOGEN

I am reading "Safety Manual for TMS570LS31x and TMS570LS21 x Hercules ARMR-Based Safety Critical Microcontrollers (Literature Number: SPNU511D)".

I understood,this device has registers that can be accessed only in privileged mode.

But I don't know how to enter the privileged mode.

How to enter privileged mode ? By the register setting ?

BestRegards,

Arriy

  • Hello Arrly,

      The HalCoGen generates the device startup file where it will put the device into SYSTEM privileged mode. In the sys_core.asm you will find the _coreInitRegisters_() function where the core registers are initialized in different CPU operating modes. The _coreInitRegisters_() is called in the sys_startup.c in the very beginning. For further information about privileged mode please refer to the Cortex-R4F TRM and look under 2.3 Operating modes section.

    ;-------------------------------------------------------------------------------
    ; Initialize CPU Registers
    ; SourceId : CORE_SourceId_001
    ; DesignId : CORE_DesignId_001
    ; Requirements: HL_SR477, HL_SR476, HL_SR492
    
        .def     _coreInitRegisters_
        .asmfunc
    
    
    _coreInitRegisters_
    
    
        ; After reset, the CPU is in the Supervisor mode (M = 10011)
            mov r0, lr
            mov r1, #0x0000
            mov r2, #0x0000
            mov r3, #0x0000
            mov r4, #0x0000
            mov r5, #0x0000
            mov r6, #0x0000
            mov r7, #0x0000
            mov r8, #0x0000
            mov r9, #0x0000
            mov r10, #0x0000
            mov r11, #0x0000
            mov r12, #0x0000
            mov r13, #0x0000
            mrs r1, cpsr
            msr spsr_cxsf, r1
            ; Switch to FIQ mode (M = 10001)
            cps #17
            mov lr, r0
            mov r8, #0x0000
            mov r9, #0x0000
            mov r10, #0x0000
            mov r11, #0x0000
            mov r12, #0x0000
            mrs r1, cpsr
            msr spsr_cxsf, r1
            ; Switch to IRQ mode (M = 10010)
            cps #18
            mov lr, r0
            mrs r1,cpsr
            msr spsr_cxsf, r1
            ; Switch to Abort mode (M = 10111)
            cps #23
            mov lr, r0
            mrs r1,cpsr
            msr spsr_cxsf, r1
            ; Switch to Undefined Instruction Mode (M = 11011)
            cps #27
            mov lr, r0
            mrs r1,cpsr
            msr spsr_cxsf, r1
            ; Switch to System Mode ( Shares User Mode registers ) (M = 11111)
            cps #31
            mov lr, r0
            mrs r1,cpsr
            msr spsr_cxsf, r1
    
    
            mrc   p15,     #0x00,      r2,       c1, c0, #0x02
            orr   r2,      r2,         #0xF00000
            mcr   p15,     #0x00,      r2,       c1, c0, #0x02
            mov   r2,      #0x40000000
            fmxr  fpexc,   r2
    
            fmdrr d0,         r1,     r1
            fmdrr d1,         r1,     r1
            fmdrr d2,         r1,     r1
            fmdrr d3,         r1,     r1
            fmdrr d4,         r1,     r1
            fmdrr d5,         r1,     r1
            fmdrr d6,         r1,     r1
            fmdrr d7,         r1,     r1
            fmdrr d8,         r1,     r1
            fmdrr d9,         r1,     r1
            fmdrr d10,        r1,     r1
            fmdrr d11,        r1,     r1
            fmdrr d12,        r1,     r1
            fmdrr d13,        r1,     r1
            fmdrr d14,        r1,     r1
            fmdrr d15,        r1,     r1
            bl    next1
    next1
            bl    next2
    next2
            bl    next3
    next3
            bl    next4
    next4
            bx    r0
    
        .endasmfunc
    

  • Also you will likely need to run certain tasks in USER mode to restrict their access to critical memory areas.
    Once you enter User mode you cannot simply switch to System or Supervisor mode like is shown above.

    From user mode, an exception is required to enter privilege again thus giving a controlled entry point back from User to Privilege.

    There are two ways software can initiate this: (a) using an SVC call, which will put you into the SWI handler and into supervisor mode, (b) using the System Software Interrupt of the system module (SSI) which will generate an IRQ interrupt for you and put you into the IRQ mode.