What does mrc p15 do in ARM inline assembly, and how does GNU C inline asm syntax work?

前端 未结 2 492
孤独总比滥情好
孤独总比滥情好 2020-12-22 13:30

what does this line in assembly arm does?

mrc p15, 0, %0, c9, c13, 0\" : : \"r\" (counter)

who is p15 isn\'t it should be

2条回答
  •  执念已碎
    2020-12-22 13:35

    Whilst MRC is a generic co-processor inter-op instruction, cp15 is the control processor - which all modern ARM CPUs have and this has been used by ARM was a means of extending the instruction set for on-chip units such as the cache, MMU, performance monitoring and lots else besides.

    Taking your instruction a bit at a time:

    mrc p15, 0, %0, c9, c13, 0" : : "r" (counter)

    According to the ARM Cortex A7 MPCore Reference the instruction format is:

    MRC{cond} P15, , , , ,

    And on Page 4-11 this is described as a transfer of a CPU register to the performance monitor count register (I guess count=0 and this is a reset of the performance counter).

    As for the syntax of inline assembler. refer to this for a x86 overview - which is probably similar to ARM.

    The : : "r" (counter) means that the instruction has:

    • No output in a register that needs to end up in a local variable
    • Takes input from variable counter, and the register this is in should be used as %0.
    • There are no side effects the compiler ought to be aware of (clobbers)

提交回复
热议问题