arminline-assemblycortex-a

Cortex-A9 , Arm Compiler 5 (DS built int) , Read CNTFRQ register


I try to read CNTFRQ register with inline assembly code. I use the following:

  1. Arria V soc evaluation board
  2. Bare-Metal app
  3. Arm Compiler 5 (DS built in)

I encountered two issues:

  1. I tried to use "regular" syntax which I saw in other places as well and it didn't work.

     static uint32_t freq = 0;
     __asm volatile("mrc p15, 0, %0, c14, c0, 0" : "=r" (freq));
    

I don't know what is wrong with this syntax:

  1. I tried another syntax:

    __asm
    {
        mrc p15, 0, freq, c14, c0, 0
    }
    

Now the code compiles but I have two problems:


Solution

  • Although many compilers use GNU's inline assembly syntax (what you call "regular syntax"), the syntax of inline assembly is not standardized and many compilers use a different syntax.

    Obviously, your compiler is one of them.

    There is no volatile statement

    You must check the compiler manual for the correct syntax of inline assembly. Maybe the compiler always treats inline assembly the way GNU C/C++ would treat __asm volatile.

    When I execute this asm code via debugger it halts when it reaches the asm code and that's it

    The CNTFRQ register is not mentioned in the Cortex-A9 manual. Are you sure that this register exists on your CPU?