This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Is a DMB required between loading BASEPRI and storing BASEPRI_MAX?

Hi,

I have a question regarding BASEPRI, BASEPRI_MAX, and DMBs as they relate to both the V7-M and V7E-M architectures.

Let's say I have the following assembly,

// stuff
mrs r0, BASEPRI
msr BASEPRI_MAX, #3
// more stuff

Is it necessary to put a DMB between the two instructions so that the processor doesn't reorder the memory accesses? After reading Chris Shore's article here and reading through the data sheet of the MCU that I'm working with, my understanding is that a DMB isn't necessary because the special registers are  'strongly-ordered' memory (or are they 'device memory'? Was a little confused about this). That being said, here's where my confusion comes in - BASEPRI and BASEPRI_MAX have different encodings in their system instructions (section B5.1.1 of the ARM v7-M Architecture Reference Manual [ARM DDI 0403E.b ID120114]). For a mrs instruction, BASEPRI_MAX is aliased to BASEPRI, however, this is not the case for a msr instruction. So, if the system instructions are different, does this imply that the processor treats the two instructions above as independent, and is therefore free to execute them in any order it pleases?

Thanks!

Parents
  • There is no need to add memory barrier instruction between these two instructions. Special register accesses with MRS and MSR are always in order. (In the case of a longer pipeline design like Cortex-M7, it could means it take multiple clock cycles as they cannot be dual issued).

    BASEPRI and BASEPRI_MAX are actually same register, but when BASEPRI_MAX is specified, the update of BASEPRI is conditional: only when the new level is higher priority (smaller number) then current level.

Reply
  • There is no need to add memory barrier instruction between these two instructions. Special register accesses with MRS and MSR are always in order. (In the case of a longer pipeline design like Cortex-M7, it could means it take multiple clock cycles as they cannot be dual issued).

    BASEPRI and BASEPRI_MAX are actually same register, but when BASEPRI_MAX is specified, the update of BASEPRI is conditional: only when the new level is higher priority (smaller number) then current level.

Children